Commit b989fd00 authored by Yaowu Xu's avatar Yaowu Xu

misc-fix: unify coding scheme of size in bytes

This commit merges the fixes that unify the coding scheme of size in
bytes including size of data in each tile, size of data in each frame
in a super frame.

Related tracking issues:
https://bugs.chromium.org/p/webm/issues/detail?id=1042
https://bugs.chromium.org/p/webm/issues/detail?id=1088
Original libvpx commits:
7460798b
d77a84bf
dec4405c

Change-Id: I7b7843d9a2e20977cf34ddfdd10c100dc978b122
parent c0b569a5
......@@ -102,9 +102,6 @@ struct aom_codec_alg_priv {
size_t pending_cx_data_sz;
int pending_frame_count;
size_t pending_frame_sizes[8];
#if !CONFIG_MISC_FIXES
size_t pending_frame_magnitude;
#endif
aom_image_t preview_img;
aom_enc_frame_flags_t next_frame_flags;
aom_postproc_cfg_t preview_ppcfg;
......@@ -791,36 +788,28 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
unsigned int mask;
int mag, index_sz;
int i, j;
#if CONFIG_MISC_FIXES
size_t max_frame_sz = 0;
#endif
assert(ctx->pending_frame_count);
assert(ctx->pending_frame_count <= 8);
// Add the number of frames to the marker byte
marker |= ctx->pending_frame_count - 1;
#if CONFIG_MISC_FIXES
for (i = 0; i < ctx->pending_frame_count - 1; i++) {
const size_t frame_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1;
max_frame_sz = frame_sz > max_frame_sz ? frame_sz : max_frame_sz;
}
#endif
// Choose the magnitude
for (mag = 0, mask = 0xff; mag < 4; mag++) {
#if CONFIG_MISC_FIXES
if (max_frame_sz <= mask) break;
#else
if (ctx->pending_frame_magnitude < mask) break;
#endif
mask <<= 8;
mask |= 0xff;
}
marker |= mag << 3;
// Write the index
index_sz = 2 + (mag + 1) * (ctx->pending_frame_count - CONFIG_MISC_FIXES);
index_sz = 2 + (mag + 1) * (ctx->pending_frame_count - 1);
if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) {
uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz;
#ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
......@@ -839,11 +828,11 @@ static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
#endif
*x++ = marker;
for (i = 0; i < ctx->pending_frame_count - CONFIG_MISC_FIXES; i++) {
for (i = 0; i < ctx->pending_frame_count - 1; i++) {
unsigned int this_sz;
assert(ctx->pending_frame_sizes[i] > 0);
this_sz = (unsigned int)ctx->pending_frame_sizes[i] - CONFIG_MISC_FIXES;
this_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1;
for (j = 0; j <= mag; j++) {
*x++ = this_sz & 0xff;
this_sz >>= 8;
......@@ -999,9 +988,6 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data;
ctx->pending_cx_data_sz += size;
ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
#if !CONFIG_MISC_FIXES
ctx->pending_frame_magnitude |= size;
#endif
cx_data += size;
cx_data_sz -= size;
......@@ -1017,9 +1003,6 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
ctx->pending_cx_data = NULL;
ctx->pending_cx_data_sz = 0;
ctx->pending_frame_count = 0;
#if !CONFIG_MISC_FIXES
ctx->pending_frame_magnitude = 0;
#endif
ctx->output_cx_pkt_cb.output_cx_pkt(
&pkt, ctx->output_cx_pkt_cb.user_priv);
}
......@@ -1035,9 +1018,6 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
if (ctx->pending_cx_data) {
ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
#if !CONFIG_MISC_FIXES
ctx->pending_frame_magnitude |= size;
#endif
ctx->pending_cx_data_sz += size;
// write the superframe only for the case when
if (!ctx->output_cx_pkt_cb.output_cx_pkt)
......@@ -1047,9 +1027,6 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
ctx->pending_cx_data = NULL;
ctx->pending_cx_data_sz = 0;
ctx->pending_frame_count = 0;
#if !CONFIG_MISC_FIXES
ctx->pending_frame_magnitude = 0;
#endif
} else {
pkt.data.frame.buf = cx_data;
pkt.data.frame.sz = size;
......
......@@ -1075,15 +1075,10 @@ static void setup_tile_info(AV1Decoder *pbi, struct aom_read_bit_buffer *rb) {
// rows
cm->log2_tile_rows = aom_rb_read_bit(rb);
if (cm->log2_tile_rows) cm->log2_tile_rows += aom_rb_read_bit(rb);
#if CONFIG_MISC_FIXES
// tile size magnitude
if (cm->log2_tile_rows > 0 || cm->log2_tile_cols > 0) {
cm->tile_sz_mag = aom_rb_read_literal(rb, 2);
}
#else
cm->tile_sz_mag = 3;
#endif
#if CONFIG_TILE_GROUPS
// Store an index to the location of the tile group information
pbi->tg_size_bit_offset = rb->bit_offset;
......@@ -1133,9 +1128,9 @@ static void get_tile_buffer(const uint8_t *const data_end,
if (decrypt_cb) {
uint8_t be_data[4];
decrypt_cb(decrypt_state, *data, be_data, tile_sz_mag + 1);
size = mem_get_varsize(be_data, tile_sz_mag) + CONFIG_MISC_FIXES;
size = mem_get_varsize(be_data, tile_sz_mag) + 1;
} else {
size = mem_get_varsize(*data, tile_sz_mag) + CONFIG_MISC_FIXES;
size = mem_get_varsize(*data, tile_sz_mag) + 1;
}
*data += tile_sz_mag + 1;
......
......@@ -497,9 +497,7 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
// an invalid bitstream and need to return an error.
uint8_t marker;
#if CONFIG_MISC_FIXES
size_t frame_sz_sum = 0;
#endif
assert(data_sz);
marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
......@@ -508,7 +506,7 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
if ((marker & 0xe0) == 0xc0) {
const uint32_t frames = (marker & 0x7) + 1;
const uint32_t mag = ((marker >> 3) & 0x3) + 1;
const size_t index_sz = 2 + mag * (frames - CONFIG_MISC_FIXES);
const size_t index_sz = 2 + mag * (frames - 1);
// This chunk is marked as having a superframe index but doesn't have
// enough data for it, thus it's an invalid superframe index.
......@@ -537,19 +535,15 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
x = clear_buffer;
}
for (i = 0; i < frames - CONFIG_MISC_FIXES; ++i) {
for (i = 0; i < frames - 1; ++i) {
uint32_t this_sz = 0;
for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
this_sz += CONFIG_MISC_FIXES;
this_sz += 1;
sizes[i] = this_sz;
#if CONFIG_MISC_FIXES
frame_sz_sum += this_sz;
#endif
}
#if CONFIG_MISC_FIXES
sizes[i] = data_sz - index_sz - frame_sz_sum;
#endif
*count = frames;
}
}
......
......@@ -1740,12 +1740,7 @@ static size_t encode_tiles(AV1_COMP *cpi, uint8_t *data_ptr,
unsigned int max_tile = 0;
#if CONFIG_TILE_GROUPS
const int n_log2_tiles = cm->log2_tile_rows + cm->log2_tile_cols;
#if CONFIG_MISC_FIXES
const int have_tiles = n_log2_tiles > 0;
#else
const int have_tiles = 0; // we have tiles, but we don't want to write a
// tile size marker in the header
#endif
size_t comp_hdr_size;
// Fixed size tile groups for the moment
......@@ -1825,7 +1820,7 @@ static size_t encode_tiles(AV1_COMP *cpi, uint8_t *data_ptr,
assert(tok == tok_end);
ans_write_init(&ans, data_ptr + total_size + 4 * !is_last_tile);
buf_ans_flush(buf_ans, &ans);
tile_size = ans_write_end(&ans) - CONFIG_MISC_FIXES;
tile_size = ans_write_end(&ans) - 1;
#else
aom_start_encode(&residual_bc, data_ptr + total_size + 4 * !is_last_tile);
......@@ -1833,7 +1828,7 @@ static size_t encode_tiles(AV1_COMP *cpi, uint8_t *data_ptr,
tok_end);
assert(tok == tok_end);
aom_stop_encode(&residual_bc);
tile_size = residual_bc.pos - CONFIG_MISC_FIXES;
tile_size = residual_bc.pos - 1;
#endif
assert(tile_size > 0);
if (!is_last_tile) {
......@@ -1842,7 +1837,7 @@ static size_t encode_tiles(AV1_COMP *cpi, uint8_t *data_ptr,
max_tile = max_tile > tile_size ? max_tile : tile_size;
total_size += 4;
}
total_size += tile_size + CONFIG_MISC_FIXES;
total_size += tile_size + 1;
}
}
#if CONFIG_TILE_GROUPS
......@@ -2309,7 +2304,6 @@ static size_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) {
#endif // CONFIG_ANS
}
#if CONFIG_MISC_FIXES
static int remux_tiles(uint8_t *dest, const int sz, const int n_tiles,
const int mag) {
int rpos = 0, wpos = 0, n;
......@@ -2342,7 +2336,6 @@ static int remux_tiles(uint8_t *dest, const int sz, const int n_tiles,
return wpos;
}
#endif
void av1_pack_bitstream(AV1_COMP *const cpi, uint8_t *dest, size_t *size) {
uint8_t *data = dest;
......@@ -2353,19 +2346,12 @@ void av1_pack_bitstream(AV1_COMP *const cpi, uint8_t *dest, size_t *size) {
size_t data_sz;
struct aom_write_bit_buffer wb = { data, 0 };
unsigned int max_tile;
#if CONFIG_MISC_FIXES || CONFIG_EXT_REFS
AV1_COMMON *const cm = &cpi->common;
#endif // CONFIG_MISC_FIXES || CONFIG_EXT_REFS
#if !CONFIG_TILE_GROUPS
size_t uncompressed_hdr_size;
#if CONFIG_MISC_FIXES
const int n_log2_tiles = cm->log2_tile_rows + cm->log2_tile_cols;
const int have_tiles = n_log2_tiles > 0;
#else
const int have_tiles = 0; // we have tiles, but we don't want to write a
// tile size marker in the header
#endif
#if CONFIG_BITSTREAM_DEBUG
bitstream_queue_reset_write();
......@@ -2395,7 +2381,6 @@ void av1_pack_bitstream(AV1_COMP *const cpi, uint8_t *dest, size_t *size) {
data_sz = encode_tiles(cpi, &wb, &max_tile);
#endif
#if !CONFIG_TILE_GROUPS
#if CONFIG_MISC_FIXES
/* A global size of tile lengths in a frame does not fit with tile
groups, as we may want to transmit a tile group as soon as encoded,
rather than buffering the frame.
......@@ -2417,8 +2402,6 @@ void av1_pack_bitstream(AV1_COMP *const cpi, uint8_t *dest, size_t *size) {
} else {
assert(n_log2_tiles == 0);
}
#endif
// TODO(jbb): Figure out what to do if first_part_size > 16 bits.
aom_wb_write_literal(&saved_wb, (int)first_part_size, 16);
#endif
......
......@@ -116,11 +116,11 @@ INSTANTIATE_TEST_CASE_P(
::testing::Values(
static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)),
::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood),
::testing::Values(CONFIG_MISC_FIXES))));
::testing::Values(1))));
#else
AV1_INSTANTIATE_TEST_CASE(
SuperframeTest,
::testing::Combine(::testing::Values(::libaom_test::kTwoPassGood),
::testing::Values(CONFIG_MISC_FIXES)));
::testing::Values(1)));
#endif
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment