shithub: libvpx

Download patch

ref: a04f68148f2b78c4eb1f356c12952c716f67adf0
parent: da7c503fe585de1e1f613f289a24b31567fd7113
author: angiebird <angiebird@google.com>
date: Thu Sep 24 07:33:55 EDT 2020

Add codec control for external rate control lib

VP9E_SET_EXTERNAL_RATE_CONTROL
One can assign an external library using the control flag,
VP9E_SET_EXTERNAL_RATE_CONTROL.
The args alongside the control flag should be of type char**.
args[0]: char* points to the path of rate control library
args[1]: char* points to the config of the rate control library.

Change-Id: Iae47362cdfafa00614bac427884bffcf6944c583

--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -660,6 +660,12 @@
 static INLINE int get_num_unit_16x16(int size) { return (size + 15) >> 4; }
 #endif  // CONFIG_RATE_CTRL
 
+#define MAX_EXT_RATECTRL_BUF_SIZE 500
+typedef struct EXT_RATECTRL {
+  char library_path[MAX_EXT_RATECTRL_BUF_SIZE];
+  char config[MAX_EXT_RATECTRL_BUF_SIZE];
+} EXT_RATECTRL;
+
 typedef struct VP9_COMP {
   FRAME_INFO frame_info;
   QUANTS quants;
@@ -974,6 +980,7 @@
 
   RATE_QSTEP_MODEL rq_model[ENCODE_FRAME_TYPES];
 #endif
+  EXT_RATECTRL ext_ratectrl;
 } VP9_COMP;
 
 #if CONFIG_RATE_CTRL
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -1732,6 +1732,24 @@
   return VPX_CODEC_OK;
 }
 
+static vpx_codec_err_t ctrl_set_external_rate_control(vpx_codec_alg_priv_t *ctx,
+                                                      va_list args) {
+  EXT_RATECTRL *ext_ratectrl = &ctx->cpi->ext_ratectrl;
+  char **str_ptr = CAST(VP9E_SET_EXTERNAL_RATE_CONTROL, args);
+  const char *library_path = str_ptr[0];
+  const char *config = str_ptr[1];
+  if (strlen(library_path) >= MAX_EXT_RATECTRL_BUF_SIZE) {
+    return VPX_CODEC_ERROR;
+  }
+  if (strlen(config) >= MAX_EXT_RATECTRL_BUF_SIZE) {
+    return VPX_CODEC_ERROR;
+  }
+  snprintf(ext_ratectrl->library_path, MAX_EXT_RATECTRL_BUF_SIZE, "%s",
+           library_path);
+  snprintf(ext_ratectrl->config, MAX_EXT_RATECTRL_BUF_SIZE, "%s", config);
+  return VPX_CODEC_OK;
+}
+
 static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
   { VP8_COPY_REFERENCE, ctrl_copy_reference },
 
@@ -1784,6 +1802,7 @@
   { VP9E_SET_SVC_SPATIAL_LAYER_SYNC, ctrl_set_svc_spatial_layer_sync },
   { VP9E_SET_DELTA_Q_UV, ctrl_set_delta_q_uv },
   { VP9E_SET_DISABLE_LOOPFILTER, ctrl_set_disable_loopfilter },
+  { VP9E_SET_EXTERNAL_RATE_CONTROL, ctrl_set_external_rate_control },
 
   // Getters
   { VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer },
--- a/vpx/vp8cx.h
+++ b/vpx/vp8cx.h
@@ -701,6 +701,16 @@
    * Supported in codecs: VP9
    */
   VP9E_SET_DISABLE_LOOPFILTER,
+
+  /*!\brief Codec control function to enable external rate control library.
+   *
+   * args[0]: path of the rate control library
+   *
+   * args[1]: private config of the rate control library
+   *
+   * Supported in codecs: VP9
+   */
+  VP9E_SET_EXTERNAL_RATE_CONTROL,
 };
 
 /*!\brief vpx 1-D scaling mode
@@ -1056,6 +1066,10 @@
 
 VPX_CTRL_USE_TYPE(VP9E_SET_DISABLE_LOOPFILTER, int)
 #define VPX_CTRL_VP9E_SET_DISABLE_LOOPFILTER
+
+VPX_CTRL_USE_TYPE(VP9E_SET_EXTERNAL_RATE_CONTROL, char **)
+#define VPX_CTRL_VP9E_SET_EXTERNAL_RATE_CONTROL
+
 /*!\endcond */
 /*! @} - end defgroup vp8_encoder */
 #ifdef __cplusplus