Skip to content

Commit

Permalink
Fix error handling in vp9_pack_bitstream()
Browse files Browse the repository at this point in the history
In multi-threaded scenario, when the bitstream
buffer allocated is insufficient, the main thread
called 'longjmp' without waiting for the completion
of workers. In this patch, 'longjmp' is called by
the main thread after joining other worker threads.

This resolves the assertion failure as reported in
Bug: webm:1847

Bug: webm:1844

Change-Id: I399c76087b65e7b8d9a9fa4f12d784408243d648
  • Loading branch information
Deepa K G committed May 13, 2024
1 parent b1cf64c commit 611d9ba
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions vp9/encoder/vp9_bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr,
const int num_workers = cpi->num_workers;
size_t total_size = 0;
int tile_col = 0;
int error = 0;

const size_t buffer_alloc_size = encode_tiles_buffer_alloc_size(cpi);
if (!cpi->vp9_bitstream_worker_data ||
Expand Down Expand Up @@ -1049,9 +1050,10 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr,
int k;

if (!winterface->sync(worker)) {
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"encode_tiles_mt: worker had error");
error = 1;
continue;
}

tile_size = data->bit_writer.pos;

// Aggregate per-thread bitstream stats.
Expand All @@ -1064,21 +1066,25 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr,
// Prefix the size of the tile on all but the last.
if (tile_col != tile_cols || j < i - 1) {
if (data_size - total_size < 4) {
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"encode_tiles_mt: output buffer full");
error = 1;
continue;
}
mem_put_be32(data_ptr + total_size, tile_size);
total_size += 4;
}
if (j > 0) {
if (data_size - total_size < tile_size) {
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"encode_tiles_mt: output buffer full");
error = 1;
continue;
}
memcpy(data_ptr + total_size, data->dest, tile_size);
}
total_size += tile_size;
}
if (error) {
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"encode_tiles_mt: output buffer full");
}
}
return total_size;
}
Expand Down

0 comments on commit 611d9ba

Please sign in to comment.