Merge "vp10: remove superframe size field for last frame in superframe."

This commit is contained in:
Ronald S. Bultje 2015-10-08 18:50:08 +00:00 committed by Gerrit Code Review
commit b60b15bc11
2 changed files with 38 additions and 4 deletions

View File

@ -459,6 +459,9 @@ vpx_codec_err_t vp10_parse_superframe_index(const uint8_t *data,
// 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);
@ -467,7 +470,7 @@ vpx_codec_err_t vp10_parse_superframe_index(const uint8_t *data,
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;
const size_t index_sz = 2 + mag * (frames - CONFIG_MISC_FIXES);
// This chunk is marked as having a superframe index but doesn't have
// enough data for it, thus it's an invalid superframe index.
@ -498,13 +501,19 @@ vpx_codec_err_t vp10_parse_superframe_index(const uint8_t *data,
x = clear_buffer;
}
for (i = 0; i < frames; ++i) {
for (i = 0; i < frames - CONFIG_MISC_FIXES; ++i) {
uint32_t this_sz = 0;
for (j = 0; j < mag; ++j)
this_sz |= (*x++) << (j * 8);
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;
}
}

View File

@ -91,7 +91,9 @@ struct vpx_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
vpx_image_t preview_img;
vpx_enc_frame_flags_t next_frame_flags;
vp8_postproc_cfg_t preview_ppcfg;
@ -781,24 +783,39 @@ static int write_superframe_index(vpx_codec_alg_priv_t *ctx) {
uint8_t marker = 0xc0;
unsigned int mask;
int mag, index_sz;
#if CONFIG_MISC_FIXES
int i;
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];
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;
index_sz = 2 + (mag + 1) * (ctx->pending_frame_count - CONFIG_MISC_FIXES);
if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) {
uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz;
int i, j;
@ -818,7 +835,7 @@ static int write_superframe_index(vpx_codec_alg_priv_t *ctx) {
#endif
*x++ = marker;
for (i = 0; i < ctx->pending_frame_count; i++) {
for (i = 0; i < ctx->pending_frame_count - CONFIG_MISC_FIXES; i++) {
unsigned int this_sz = (unsigned int)ctx->pending_frame_sizes[i];
for (j = 0; j <= mag; j++) {
@ -974,7 +991,9 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
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;
@ -991,7 +1010,9 @@ static vpx_codec_err_t encoder_encode(vpx_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);
}
@ -1008,7 +1029,9 @@ static vpx_codec_err_t encoder_encode(vpx_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)
@ -1018,7 +1041,9 @@ static vpx_codec_err_t encoder_encode(vpx_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;