L2E: Add control type for the external rate control API
authorCheng Chen <chengchen@google.com>
Fri, 13 May 2022 17:59:06 +0000 (10:59 -0700)
committerCheng Chen <chengchen@google.com>
Fri, 27 May 2022 21:36:13 +0000 (14:36 -0700)
Two control types are defined: QP and GOP control.
Now the API only supports the QP model.

Change-Id: Ib3a712964b9d2282c93993ee56e0558e4795fb46

test/vp9_ext_ratectrl_test.cc
vp9/encoder/vp9_ext_ratectrl.c
vpx/vpx_ext_ratectrl.h

index 60a350b..f6ce778 100644 (file)
@@ -176,6 +176,7 @@ class ExtRateCtrlTest : public ::libvpx_test::EncoderTest,
                           ::libvpx_test::Encoder *encoder) override {
     if (video->frame() == 0) {
       vpx_rc_funcs_t rc_funcs;
+      rc_funcs.rc_type = VPX_RC_QP;
       rc_funcs.create_model = rc_create_model;
       rc_funcs.send_firstpass_stats = rc_send_firstpass_stats;
       rc_funcs.get_encodeframe_decision = rc_get_encodeframe_decision;
index 9f0098a..67f5832 100644 (file)
@@ -143,7 +143,7 @@ vpx_codec_err_t vp9_extrc_get_encodeframe_decision(
   if (ext_ratectrl == NULL) {
     return VPX_CODEC_INVALID_PARAM;
   }
-  if (ext_ratectrl->ready) {
+  if (ext_ratectrl->ready && ext_ratectrl->funcs.rc_type == VPX_RC_QP) {
     vpx_rc_status_t rc_status;
     vpx_rc_encodeframe_info_t encode_frame_info;
     encode_frame_info.show_index = show_index;
@@ -172,7 +172,7 @@ vpx_codec_err_t vp9_extrc_update_encodeframe_result(
   if (ext_ratectrl == NULL) {
     return VPX_CODEC_INVALID_PARAM;
   }
-  if (ext_ratectrl->ready) {
+  if (ext_ratectrl->ready && ext_ratectrl->funcs.rc_type == VPX_RC_QP) {
     PSNR_STATS psnr;
     vpx_rc_status_t rc_status;
     vpx_rc_encodeframe_result_t encode_frame_result;
index a193e55..5b426b6 100644 (file)
@@ -25,7 +25,15 @@ extern "C" {
  * types, removing or reassigning enums, adding/removing/rearranging
  * fields to structures.
  */
-#define VPX_EXT_RATECTRL_ABI_VERSION (1)
+#define VPX_EXT_RATECTRL_ABI_VERSION (2)
+
+/*!\brief The control type of the inference API.
+ * In VPX_RC_QP mode, the external rate control model determines the
+ * quantization parameter (QP) for each frame.
+ * In VPX_RC_GOP mode, the external rate control model determines the
+ * group of picture (GOP) of the video sequence.
+ */
+typedef enum vpx_rc_type { VPX_RC_QP = 0, VPX_RC_GOP = 1 } vpx_rc_type_t;
 
 /*!\brief Abstract rate control model handler
  *
@@ -328,6 +336,10 @@ typedef vpx_rc_status_t (*vpx_rc_delete_model_cb_fn_t)(
  */
 typedef struct vpx_rc_funcs {
   /*!
+   * The rate control type of this API.
+   */
+  vpx_rc_type_t rc_type;
+  /*!
    * Create an external rate control model.
    */
   vpx_rc_create_model_cb_fn_t create_model;