diff options
author | angiebird <angiebird@google.com> | 2019-11-08 20:23:03 -0800 |
---|---|---|
committer | angiebird <angiebird@google.com> | 2019-11-14 18:11:10 -0800 |
commit | b0e761f95b71450a8808497d840f59c00d97fe8b (patch) | |
tree | c429e82123a363221a8b533d9dc90c0f0c24efb9 /vp9/encoder | |
parent | ddd80abd3f634326ffa8190a095db0015ea83713 (diff) | |
download | libvpx-b0e761f95b71450a8808497d840f59c00d97fe8b.tar libvpx-b0e761f95b71450a8808497d840f59c00d97fe8b.tar.gz libvpx-b0e761f95b71450a8808497d840f59c00d97fe8b.tar.bz2 libvpx-b0e761f95b71450a8808497d840f59c00d97fe8b.zip |
Add vp9_update_compressor_with_img_fmt()
Add utility functions
vpx_img_chroma_subsampling
vpx_img_use_highbitdepth
Change-Id: I7b44fdc2cf67bbb49e161fdf778917b9ec0c8832
Diffstat (limited to 'vp9/encoder')
-rw-r--r-- | vp9/encoder/vp9_encoder.c | 137 | ||||
-rw-r--r-- | vp9/encoder/vp9_encoder.h | 1 |
2 files changed, 94 insertions, 44 deletions
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index 75ce37eae..1a894d53c 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -2171,6 +2171,99 @@ static void init_ref_frame_bufs(VP9_COMMON *cm) { } } +static void update_initial_width(VP9_COMP *cpi, int use_highbitdepth, + int subsampling_x, int subsampling_y) { + VP9_COMMON *const cm = &cpi->common; +#if !CONFIG_VP9_HIGHBITDEPTH + (void)use_highbitdepth; + assert(use_highbitdepth == 0); +#endif + + if (!cpi->initial_width || +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth != use_highbitdepth || +#endif + cm->subsampling_x != subsampling_x || + cm->subsampling_y != subsampling_y) { + cm->subsampling_x = subsampling_x; + cm->subsampling_y = subsampling_y; +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth = use_highbitdepth; +#endif + + cpi->initial_width = cm->width; + cpi->initial_height = cm->height; + cpi->initial_mbs = cm->MBs; + } +} + +// TODO(angiebird): Check whether we can move this function to vpx_image.c +static INLINE void vpx_img_chroma_subsampling(vpx_img_fmt_t fmt, + unsigned int *subsampling_x, + unsigned int *subsampling_y) { + switch (fmt) { + case VPX_IMG_FMT_I420: + case VPX_IMG_FMT_YV12: + case VPX_IMG_FMT_I422: + case VPX_IMG_FMT_I42016: + case VPX_IMG_FMT_I42216: *subsampling_x = 1; break; + default: *subsampling_x = 0; break; + } + + switch (fmt) { + case VPX_IMG_FMT_I420: + case VPX_IMG_FMT_I440: + case VPX_IMG_FMT_YV12: + case VPX_IMG_FMT_I42016: + case VPX_IMG_FMT_I44016: *subsampling_y = 1; break; + default: *subsampling_y = 0; break; + } +} + +// TODO(angiebird): Check whether we can move this function to vpx_image.c +static INLINE int vpx_img_use_highbitdepth(vpx_img_fmt_t fmt) { + return fmt & VPX_IMG_FMT_HIGHBITDEPTH; +} + +#if CONFIG_VP9_TEMPORAL_DENOISING +static void setup_denoiser_buffer(VP9_COMP *cpi) { + VP9_COMMON *const cm = &cpi->common; + if (cpi->oxcf.noise_sensitivity > 0 && + !cpi->denoiser.frame_buffer_initialized) { + if (vp9_denoiser_alloc(cm, &cpi->svc, &cpi->denoiser, cpi->use_svc, + cpi->oxcf.noise_sensitivity, cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth, +#endif + VP9_ENC_BORDER_IN_PIXELS)) + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate denoiser"); + } +} +#endif + +void vp9_update_compressor_with_img_fmt(VP9_COMP *cpi, vpx_img_fmt_t img_fmt) { + const VP9EncoderConfig *oxcf = &cpi->oxcf; + unsigned int subsampling_x, subsampling_y; + const int use_highbitdepth = vpx_img_use_highbitdepth(img_fmt); + vpx_img_chroma_subsampling(img_fmt, &subsampling_x, &subsampling_y); + + update_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); +#if CONFIG_VP9_TEMPORAL_DENOISING + setup_denoiser_buffer(cpi); +#endif + + assert(cpi->lookahead == NULL); + cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, subsampling_x, + subsampling_y, +#if CONFIG_VP9_HIGHBITDEPTH + use_highbitdepth, +#endif + oxcf->lag_in_frames); + alloc_raw_frame_buffers(cpi); +} + VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf, BufferPool *const pool) { unsigned int i; @@ -3609,24 +3702,6 @@ static void set_size_dependent_vars(VP9_COMP *cpi, int *q, int *bottom_index, #endif // CONFIG_VP9_POSTPROC } -#if CONFIG_VP9_TEMPORAL_DENOISING -static void setup_denoiser_buffer(VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - if (cpi->oxcf.noise_sensitivity > 0 && - !cpi->denoiser.frame_buffer_initialized) { - if (vp9_denoiser_alloc(cm, &cpi->svc, &cpi->denoiser, cpi->use_svc, - cpi->oxcf.noise_sensitivity, cm->width, cm->height, - cm->subsampling_x, cm->subsampling_y, -#if CONFIG_VP9_HIGHBITDEPTH - cm->use_highbitdepth, -#endif - VP9_ENC_BORDER_IN_PIXELS)) - vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, - "Failed to allocate denoiser"); - } -} -#endif - static void init_motion_estimation(VP9_COMP *cpi) { int y_stride = cpi->scaled_source.y_stride; @@ -5304,32 +5379,6 @@ static void Pass2Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, } #endif // !CONFIG_REALTIME_ONLY -static void update_initial_width(VP9_COMP *cpi, int use_highbitdepth, - int subsampling_x, int subsampling_y) { - VP9_COMMON *const cm = &cpi->common; -#if !CONFIG_VP9_HIGHBITDEPTH - (void)use_highbitdepth; - assert(use_highbitdepth == 0); -#endif - - if (!cpi->initial_width || -#if CONFIG_VP9_HIGHBITDEPTH - cm->use_highbitdepth != use_highbitdepth || -#endif - cm->subsampling_x != subsampling_x || - cm->subsampling_y != subsampling_y) { - cm->subsampling_x = subsampling_x; - cm->subsampling_y = subsampling_y; -#if CONFIG_VP9_HIGHBITDEPTH - cm->use_highbitdepth = use_highbitdepth; -#endif - - cpi->initial_width = cm->width; - cpi->initial_height = cm->height; - cpi->initial_mbs = cm->MBs; - } -} - int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, int64_t end_time) { diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index 2a7facaea..8b892a6d2 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -824,6 +824,7 @@ typedef struct VP9_COMP { void vp9_initialize_enc(void); +void vp9_update_compressor_with_img_fmt(VP9_COMP *cpi, vpx_img_fmt_t img_fmt); struct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf, BufferPool *const pool); void vp9_remove_compressor(VP9_COMP *cpi); |