From 20bca1350a16af4c3346cfbf7f8f6c181e21a9ca Mon Sep 17 00:00:00 2001 From: angiebird Date: Wed, 7 Oct 2020 15:29:51 -0700 Subject: [PATCH] Add vp9_extrc_init/create/delete Change-Id: I9fcb9f4cc5c565794229593fadde87286fcf0ffd --- vp9/encoder/vp9_encoder.c | 3 +++ vp9/encoder/vp9_encoder.h | 7 +------ vp9/encoder/vp9_ext_ratectrl.c | 32 ++++++++++++++++++++++++++++++++ vp9/encoder/vp9_ext_ratectrl.h | 30 ++++++++++++++++++++++++++++++ vp9/vp9_cx_iface.c | 19 ++++++++++++++++++- vp9/vp9cx.mk | 2 ++ vpx/vpx_ext_ratectrl.h | 2 ++ 7 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 vp9/encoder/vp9_ext_ratectrl.c create mode 100644 vp9/encoder/vp9_ext_ratectrl.h diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index e513cef..80bc435 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -2664,6 +2664,7 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, motion_vector_info_init(cpi); fp_motion_vector_info_init(cpi); #endif + vp9_extrc_init(&cpi->ext_ratectrl); return cpi; } @@ -2834,6 +2835,8 @@ void vp9_remove_compressor(VP9_COMP *cpi) { } #endif + vp9_extrc_delete(&cpi->ext_ratectrl); + vp9_remove_common(cm); vp9_free_ref_frame_buffers(cm->buffer_pool); #if CONFIG_VP9_POSTPROC diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index 28e0029..b35d566 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -39,6 +39,7 @@ #include "vp9/encoder/vp9_context_tree.h" #include "vp9/encoder/vp9_encodemb.h" #include "vp9/encoder/vp9_ethread.h" +#include "vp9/encoder/vp9_ext_ratectrl.h" #include "vp9/encoder/vp9_firstpass.h" #include "vp9/encoder/vp9_job_queue.h" #include "vp9/encoder/vp9_lookahead.h" @@ -661,12 +662,6 @@ static INLINE int get_num_unit_4x4(int size) { return (size + 3) >> 2; } static INLINE int get_num_unit_16x16(int size) { return (size + 15) >> 4; } #endif // CONFIG_RATE_CTRL -typedef struct EXT_RATECTRL { - int ready; - vpx_rc_model_t model; - vpx_rc_funcs_t funcs; -} EXT_RATECTRL; - typedef struct VP9_COMP { FRAME_INFO frame_info; QUANTS quants; diff --git a/vp9/encoder/vp9_ext_ratectrl.c b/vp9/encoder/vp9_ext_ratectrl.c new file mode 100644 index 0000000..5a1263b --- /dev/null +++ b/vp9/encoder/vp9_ext_ratectrl.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "vp9/encoder/vp9_ext_ratectrl.h" +#include "vp9/common/vp9_common.h" + +void vp9_extrc_init(EXT_RATECTRL *ext_ratectrl) { vp9_zero(*ext_ratectrl); } + +void vp9_extrc_create(vpx_rc_funcs_t funcs, vpx_rc_config_t ratectrl_config, + EXT_RATECTRL *ext_ratectrl) { + vp9_extrc_delete(ext_ratectrl); + ext_ratectrl->funcs = funcs; + ext_ratectrl->ratectrl_config = ratectrl_config; + ext_ratectrl->funcs.create_model(ext_ratectrl->funcs.priv, + &ext_ratectrl->ratectrl_config, + ext_ratectrl->model); + ext_ratectrl->ready = 1; +} + +void vp9_extrc_delete(EXT_RATECTRL *ext_ratectrl) { + if (ext_ratectrl->ready) { + ext_ratectrl->funcs.delete_model(ext_ratectrl->model); + } + vp9_extrc_init(ext_ratectrl); +} diff --git a/vp9/encoder/vp9_ext_ratectrl.h b/vp9/encoder/vp9_ext_ratectrl.h new file mode 100644 index 0000000..4505b0f --- /dev/null +++ b/vp9/encoder/vp9_ext_ratectrl.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_ +#define VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_ + +#include "vpx/vpx_ext_ratectrl.h" + +typedef struct EXT_RATECTRL { + int ready; + vpx_rc_model_t model; + vpx_rc_funcs_t funcs; + vpx_rc_config_t ratectrl_config; +} EXT_RATECTRL; + +void vp9_extrc_init(EXT_RATECTRL *ext_ratectrl); + +void vp9_extrc_create(vpx_rc_funcs_t funcs, vpx_rc_config_t ratectrl_config, + EXT_RATECTRL *ext_ratectrl); + +void vp9_extrc_delete(EXT_RATECTRL *ext_ratectrl); + +#endif // VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_ diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index 42847ed..aa13fc9 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -1735,7 +1735,24 @@ static vpx_codec_err_t ctrl_set_disable_loopfilter(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t ctrl_set_external_rate_control(vpx_codec_alg_priv_t *ctx, va_list args) { - ctx->cpi->ext_ratectrl.funcs = *CAST(VP9E_SET_EXTERNAL_RATE_CONTROL, args); + vpx_rc_funcs_t funcs = *CAST(VP9E_SET_EXTERNAL_RATE_CONTROL, args); + VP9_COMP *cpi = ctx->cpi; + EXT_RATECTRL *ext_ratectrl = &cpi->ext_ratectrl; + const VP9EncoderConfig *oxcf = &cpi->oxcf; + const FRAME_INFO *frame_info = &cpi->frame_info; + vpx_rc_config_t ratectrl_config; + + ratectrl_config.frame_width = frame_info->frame_width; + ratectrl_config.frame_height = frame_info->frame_height; + ratectrl_config.show_frame_count = cpi->twopass.first_pass_info.num_frames; + + // TODO(angiebird): Double check whether this is the proper way to set up + // target_bitrate and frame_rate. + ratectrl_config.target_bitrate_kbps = (int)(oxcf->target_bandwidth / 1000); + ratectrl_config.frame_rate_num = oxcf->g_timebase.den; + ratectrl_config.frame_rate_den = oxcf->g_timebase.num; + + vp9_extrc_create(funcs, ratectrl_config, ext_ratectrl); return VPX_CODEC_OK; } diff --git a/vp9/vp9cx.mk b/vp9/vp9cx.mk index 666f228..38e9916 100644 --- a/vp9/vp9cx.mk +++ b/vp9/vp9cx.mk @@ -96,6 +96,8 @@ VP9_CX_SRCS-yes += encoder/vp9_skin_detection.c VP9_CX_SRCS-yes += encoder/vp9_skin_detection.h VP9_CX_SRCS-yes += encoder/vp9_noise_estimate.c VP9_CX_SRCS-yes += encoder/vp9_noise_estimate.h +VP9_CX_SRCS-yes += encoder/vp9_ext_ratectrl.c +VP9_CX_SRCS-yes += encoder/vp9_ext_ratectrl.h ifeq ($(CONFIG_VP9_POSTPROC),yes) VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS) += common/vp9_postproc.h VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS) += common/vp9_postproc.c diff --git a/vpx/vpx_ext_ratectrl.h b/vpx/vpx_ext_ratectrl.h index 08e8470..3b00e11 100644 --- a/vpx/vpx_ext_ratectrl.h +++ b/vpx/vpx_ext_ratectrl.h @@ -45,6 +45,8 @@ typedef struct vpx_rc_config { int frame_height; int show_frame_count; int target_bitrate_kbps; + int frame_rate_num; + int frame_rate_den; } vpx_rc_config_t; /*!\brief Create an external rate control model callback prototype -- 2.7.4