diff options
author | John Koleszar <jkoleszar@google.com> | 2013-05-06 15:52:06 -0700 |
---|---|---|
committer | John Koleszar <jkoleszar@google.com> | 2013-05-09 17:50:12 -0700 |
commit | da58436f43095743d77f7ee84500fd22851317d8 (patch) | |
tree | 1583a075122a56b524823dba8f78a52aad4965bd /vp9/encoder | |
parent | 9e327dbb76540f128cde7367b85bca05aa5863e6 (diff) | |
download | libvpx-da58436f43095743d77f7ee84500fd22851317d8.tar libvpx-da58436f43095743d77f7ee84500fd22851317d8.tar.gz libvpx-da58436f43095743d77f7ee84500fd22851317d8.tar.bz2 libvpx-da58436f43095743d77f7ee84500fd22851317d8.zip |
Subsampling aware allocs and bitstream
Make framebuffer allocations according to the chroma subsamping
factors in use. A bit is placed in the raw part of the frame header for
each of the two subsampling factors. This will be moved in a future
commit to make them part of the TBD feature set bits, probably only set
on keyframes, etc.
Change-Id: I59ed38d3a3c0d4af3c7c277617de28d04a001853
Diffstat (limited to 'vp9/encoder')
-rw-r--r-- | vp9/encoder/vp9_bitstream.c | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_encodeframe.c | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_lookahead.c | 9 | ||||
-rw-r--r-- | vp9/encoder/vp9_lookahead.h | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_onyx_if.c | 82 |
6 files changed, 64 insertions, 35 deletions
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 20154d813..da0bb2128 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -1805,6 +1805,8 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) { int scaling = (pc->width != pc->display_width || pc->height != pc->display_height); int v = (oh.first_partition_length_in_bytes << 8) | + (pc->subsampling_y << 7) | + (pc->subsampling_x << 6) | (scaling << 5) | (oh.show_frame << 4) | (oh.version << 1) | diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 49e8ccefa..418f60edc 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -1423,7 +1423,7 @@ static void init_encode_frame_mb_context(VP9_COMP *cpi) { vp9_build_block_offsets(x); - vp9_setup_block_dptrs(&x->e_mbd); + vp9_setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); xd->mode_info_context->mbmi.mode = DC_PRED; xd->mode_info_context->mbmi.uv_mode = DC_PRED; diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 1e25a00a0..ff0725fd0 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -489,7 +489,7 @@ void vp9_first_pass(VP9_COMP *cpi) { vp9_build_block_offsets(x); - vp9_setup_block_dptrs(&x->e_mbd); + vp9_setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); vp9_frame_init_quantizer(cpi); diff --git a/vp9/encoder/vp9_lookahead.c b/vp9/encoder/vp9_lookahead.c index a89d2547e..708fe4549 100644 --- a/vp9/encoder/vp9_lookahead.c +++ b/vp9/encoder/vp9_lookahead.c @@ -46,7 +46,7 @@ void vp9_lookahead_destroy(struct lookahead_ctx *ctx) { unsigned int i; for (i = 0; i < ctx->max_sz; i++) - vp8_yv12_de_alloc_frame_buffer(&ctx->buf[i].img); + vp9_free_frame_buffer(&ctx->buf[i].img); free(ctx->buf); } free(ctx); @@ -56,6 +56,8 @@ void vp9_lookahead_destroy(struct lookahead_ctx *ctx) { struct lookahead_ctx * vp9_lookahead_init(unsigned int width, unsigned int height, + unsigned int subsampling_x, + unsigned int subsampling_y, unsigned int depth) { struct lookahead_ctx *ctx = NULL; @@ -71,8 +73,9 @@ struct lookahead_ctx * vp9_lookahead_init(unsigned int width, if (!ctx->buf) goto bail; for (i = 0; i < depth; i++) - if (vp8_yv12_alloc_frame_buffer(&ctx->buf[i].img, - width, height, VP9BORDERINPIXELS)) + if (vp9_alloc_frame_buffer(&ctx->buf[i].img, + width, height, subsampling_x, subsampling_y, + VP9BORDERINPIXELS)) goto bail; } return ctx; diff --git a/vp9/encoder/vp9_lookahead.h b/vp9/encoder/vp9_lookahead.h index 2406618b9..81baa2c6f 100644 --- a/vp9/encoder/vp9_lookahead.h +++ b/vp9/encoder/vp9_lookahead.h @@ -31,6 +31,8 @@ struct lookahead_ctx; */ struct lookahead_ctx *vp9_lookahead_init(unsigned int width, unsigned int height, + unsigned int subsampling_x, + unsigned int subsampling_y, unsigned int depth); diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index 782816f92..58f8fdb6f 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -313,9 +313,9 @@ static void dealloc_compressor_data(VP9_COMP *cpi) { vp9_free_frame_buffers(&cpi->common); - vp8_yv12_de_alloc_frame_buffer(&cpi->last_frame_uf); - vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source); - vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer); + vp9_free_frame_buffer(&cpi->last_frame_uf); + vp9_free_frame_buffer(&cpi->scaled_source); + vp9_free_frame_buffer(&cpi->alt_ref_buffer); vp9_lookahead_destroy(cpi->lookahead); vpx_free(cpi->tok); @@ -835,15 +835,19 @@ void vp9_set_speed_features(VP9_COMP *cpi) { } static void alloc_raw_frame_buffers(VP9_COMP *cpi) { + VP9_COMMON *cm = &cpi->common; + cpi->lookahead = vp9_lookahead_init(cpi->oxcf.width, cpi->oxcf.height, + cm->subsampling_x, cm->subsampling_y, cpi->oxcf.lag_in_frames); if (!cpi->lookahead) vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, "Failed to allocate lag buffers"); - if (vp8_yv12_alloc_frame_buffer(&cpi->alt_ref_buffer, - cpi->oxcf.width, cpi->oxcf.height, - VP9BORDERINPIXELS)) + if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, + cpi->oxcf.width, cpi->oxcf.height, + cm->subsampling_x, cm->subsampling_y, + VP9BORDERINPIXELS)) vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, "Failed to allocate altref buffer"); } @@ -873,13 +877,17 @@ void vp9_alloc_compressor_data(VP9_COMP *cpi) { vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, "Failed to allocate partition data"); - if (vp8_yv12_alloc_frame_buffer(&cpi->last_frame_uf, - cm->width, cm->height, VP9BORDERINPIXELS)) + if (vp9_alloc_frame_buffer(&cpi->last_frame_uf, + cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, + VP9BORDERINPIXELS)) vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, "Failed to allocate last frame buffer"); - if (vp8_yv12_alloc_frame_buffer(&cpi->scaled_source, - cm->width, cm->height, VP9BORDERINPIXELS)) + if (vp9_alloc_frame_buffer(&cpi->scaled_source, + cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, + VP9BORDERINPIXELS)) vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, "Failed to allocate scaled source buffer"); @@ -914,13 +922,17 @@ static void update_frame_size(VP9_COMP *cpi) { vp9_update_frame_size(cm); // Update size of buffers local to this frame - if (vp8_yv12_realloc_frame_buffer(&cpi->last_frame_uf, - cm->width, cm->height, VP9BORDERINPIXELS)) + if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, + cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, + VP9BORDERINPIXELS)) vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, "Failed to reallocate last frame buffer"); - if (vp8_yv12_realloc_frame_buffer(&cpi->scaled_source, - cm->width, cm->height, VP9BORDERINPIXELS)) + if (vp9_realloc_frame_buffer(&cpi->scaled_source, + cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, + VP9BORDERINPIXELS)) vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, "Failed to reallocate scaled source buffer"); @@ -1032,6 +1044,9 @@ static void init_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { cm->width = oxcf->width; cm->height = oxcf->height; + cm->subsampling_x = 0; + cm->subsampling_y = 0; + vp9_alloc_compressor_data(cpi); // change includes all joint functionality vp9_change_config(ptr, oxcf); @@ -1196,17 +1211,13 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { cm->sharpness_level = cpi->oxcf.Sharpness; - // Increasing the size of the frame beyond the first seen frame, or some - // otherwise signalled maximum size, is not supported. - // TODO(jkoleszar): exit gracefully. - if (!cpi->initial_width) { - alloc_raw_frame_buffers(cpi); - vp9_alloc_compressor_data(cpi); - cpi->initial_width = cm->width; - cpi->initial_height = cm->height; + if (cpi->initial_width) { + // Increasing the size of the frame beyond the first seen frame, or some + // otherwise signalled maximum size, is not supported. + // TODO(jkoleszar): exit gracefully. + assert(cm->width <= cpi->initial_width); + assert(cm->height <= cpi->initial_height); } - assert(cm->width <= cpi->initial_width); - assert(cm->height <= cpi->initial_height); update_frame_size(cpi); if (cpi->oxcf.fixed_q >= 0) { @@ -2492,9 +2503,10 @@ static void scale_references(VP9_COMP *cpi) { ref->y_crop_height != cm->height) { int new_fb = get_free_fb(cm); - vp8_yv12_realloc_frame_buffer(&cm->yv12_fb[new_fb], - cm->width, cm->height, - VP9BORDERINPIXELS); + vp9_realloc_frame_buffer(&cm->yv12_fb[new_fb], + cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, + VP9BORDERINPIXELS); scale_and_extend_frame(ref, &cm->yv12_fb[new_fb]); cpi->scaled_ref_idx[i] = new_fb; } else { @@ -3579,6 +3591,15 @@ int vp9_receive_raw_frame(VP9_PTR ptr, unsigned int frame_flags, struct vpx_usec_timer timer; int res = 0; + if (!cpi->initial_width) { + // TODO(jkoleszar): Support 1/4 subsampling? + cm->subsampling_x = sd->uv_width < sd->y_width; + cm->subsampling_y = sd->uv_height < sd->y_height; + alloc_raw_frame_buffers(cpi); + + cpi->initial_width = cm->width; + cpi->initial_height = cm->height; + } vpx_usec_timer_start(&timer); if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags, cpi->active_map_enabled ? cpi->active_map : NULL)) @@ -3843,9 +3864,10 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags, cm->frame_flags = *frame_flags; // Reset the frame pointers to the current frame size - vp8_yv12_realloc_frame_buffer(&cm->yv12_fb[cm->new_fb_idx], - cm->width, cm->height, - VP9BORDERINPIXELS); + vp9_realloc_frame_buffer(&cm->yv12_fb[cm->new_fb_idx], + cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, + VP9BORDERINPIXELS); // Calculate scaling factors for each of the 3 available references for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) { |