Skip to content

Commit

Permalink
Use SPA_CHUNK_FLAG_CORRUPTED and SPA_META_HEADER_FLAG_CORRUPTED flags to
Browse files Browse the repository at this point in the history
determine corrupted buffers or corrupted buffer data. We used to only
rely on compositors setting chunk->size, but this doesn't make sense for
dmabufs where they have to make up arbitrary values. It also looks this
is not reliable and can cause glitches as we end up processing corrupted buffers.

The original patch is rebased with `observer_` related code removed
since our branch does not have that.

See: https://webrtc-review.googlesource.com/c/src/+/349881
Co-Authored-By: Jan Grulich <grulja@gmail.com>
  • Loading branch information
2 people authored and john-preston committed Jun 15, 2024
1 parent 1972188 commit c9cc439
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ void SharedScreenCastStreamPrivate::OnStreamProcess(void* data) {
return;
}

struct spa_meta_header* header =
static_cast<spa_meta_header*>(spa_buffer_find_meta_data(
buffer->buffer, SPA_META_Header, sizeof(*header)));
if (header && (header->flags & SPA_META_HEADER_FLAG_CORRUPTED)) {
RTC_LOG(LS_INFO) << "Dropping corrupted buffer";
// Queue buffer for reuse; it will not be processed further.
pw_stream_queue_buffer(that->pw_stream_, buffer);
return;
}

that->ProcessBuffer(buffer);

pw_stream_queue_buffer(that->pw_stream_, buffer);
Expand Down Expand Up @@ -640,7 +650,14 @@ void SharedScreenCastStreamPrivate::ProcessBuffer(pw_buffer* buffer) {
}
}

if (spa_buffer->datas[0].chunk->size == 0) {
if (spa_buffer->datas[0].chunk->flags & SPA_CHUNK_FLAG_CORRUPTED) {
RTC_LOG(LS_INFO) << "Dropping buffer with corrupted or missing data";
return;
}

if (spa_buffer->datas[0].type == SPA_DATA_MemFd &&
spa_buffer->datas[0].chunk->size == 0) {
RTC_LOG(LS_INFO) << "Dropping buffer with empty data";
return;
}

Expand Down

0 comments on commit c9cc439

Please sign in to comment.