]> granicus.if.org Git - libvpx/commitdiff
Add callback functions for external_rate_control
authorangiebird <angiebird@google.com>
Wed, 7 Oct 2020 22:29:51 +0000 (15:29 -0700)
committerangiebird <angiebird@google.com>
Sat, 10 Oct 2020 00:30:49 +0000 (17:30 -0700)
Change-Id: I20a1179a2131d2cd069dae9076aa2c18b80784f3

vp9/encoder/vp9_encoder.h
vp9/vp9_cx_iface.c
vpx/vp8cx.h
vpx/vpx_codec.mk
vpx/vpx_ext_ratectrl.h [new file with mode: 0644]

index 67574ec0eb2be904d79e373722b00597ac2c56c4..28e00299b0a2697f5f7fc1ce092e8f24344856eb 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "./vpx_config.h"
 #include "vpx/internal/vpx_codec_internal.h"
+#include "vpx/vpx_ext_ratectrl.h"
 #include "vpx/vp8cx.h"
 #if CONFIG_INTERNAL_STATS
 #include "vpx_dsp/ssim.h"
@@ -660,10 +661,10 @@ 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
 
-#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];
+  int ready;
+  vpx_rc_model_t model;
+  vpx_rc_funcs_t funcs;
 } EXT_RATECTRL;
 
 typedef struct VP9_COMP {
index 588290de0e89c2c5763978a13df250b720c5dc9c..42847edee46d4be8f3e66d49af6cc4ade4f2c22d 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "./vpx_config.h"
 #include "vpx/vpx_encoder.h"
+#include "vpx/vpx_ext_ratectrl.h"
 #include "vpx_dsp/psnr.h"
 #include "vpx_ports/vpx_once.h"
 #include "vpx_ports/static_assert.h"
@@ -1734,19 +1735,7 @@ 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) {
-  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);
+  ctx->cpi->ext_ratectrl.funcs = *CAST(VP9E_SET_EXTERNAL_RATE_CONTROL, args);
   return VPX_CODEC_OK;
 }
 
index 8b0b1af6eee8e48220fde4db1884f6c6197de483..37ad07d33d9acd842fe40e322f7f22e90fef6c73 100644 (file)
@@ -17,6 +17,7 @@
  */
 #include "./vp8.h"
 #include "./vpx_encoder.h"
+#include "./vpx_ext_ratectrl.h"
 
 /*!\file
  * \brief Provides definitions for using VP8 or VP9 encoder algorithm within the
@@ -1067,7 +1068,7 @@ VPX_CTRL_USE_TYPE(VP9E_SET_DISABLE_OVERSHOOT_MAXQ_CBR, int)
 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 **)
+VPX_CTRL_USE_TYPE(VP9E_SET_EXTERNAL_RATE_CONTROL, vpx_rc_funcs_t *)
 #define VPX_CTRL_VP9E_SET_EXTERNAL_RATE_CONTROL
 
 /*!\endcond */
index 4ed77ad6d9dffcba0c5e5b3818d18f2dd1c19b9e..67812f21b25c7766052e7ef51e4134f65b12ed3a 100644 (file)
@@ -39,3 +39,4 @@ API_SRCS-yes += vpx_codec.mk
 API_SRCS-yes += vpx_frame_buffer.h
 API_SRCS-yes += vpx_image.h
 API_SRCS-yes += vpx_integer.h
+API_SRCS-yes += vpx_ext_ratectrl.h
diff --git a/vpx/vpx_ext_ratectrl.h b/vpx/vpx_ext_ratectrl.h
new file mode 100644 (file)
index 0000000..08e8470
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ *  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_VPX_VPX_EXT_RATECTRL_H_
+#define VPX_VPX_VPX_EXT_RATECTRL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "./vpx_integer.h"
+
+typedef void *vpx_rc_model_t;
+
+typedef struct vpx_rc_encodeframe_decision {
+  int q_index;
+} vpx_rc_encodeframe_decision_t;
+
+typedef struct vpx_rc_encodeframe_info {
+  int frame_type;
+  int show_index;
+  int coding_index;
+} vpx_rc_encodeframe_info_t;
+
+typedef struct vpx_rc_encodeframe_result {
+  int64_t sse;
+  int64_t bit_count;
+  int64_t pixel_count;
+} vpx_rc_encodeframe_result_t;
+
+typedef struct vpx_rc_firstpass_stats {
+  double (*frame_stats)[26];
+  int num_frames;
+} vpx_rc_firstpass_stats_t;
+
+typedef struct vpx_rc_config {
+  int frame_width;
+  int frame_height;
+  int show_frame_count;
+  int target_bitrate_kbps;
+} vpx_rc_config_t;
+
+/*!\brief Create an external rate control model callback prototype
+ *
+ * This callback is invoked by the encoder to create an external rate control
+ * model.
+ *
+ * \param[in]  priv               Callback's private data
+ * \param[in]  ratectrl_config    Pointer to vpx_rc_config_t
+ * \param[out] rate_ctrl_model_pt Pointer to vpx_rc_model_t
+ */
+typedef int (*vpx_rc_create_model_cb_fn_t)(
+    void *priv, const vpx_rc_config_t *ratectrl_config,
+    vpx_rc_model_t *rate_ctrl_model_pt);
+
+/*!\brief Send first pass stats to the external rate control model callback
+ * prototype
+ *
+ * This callback is invoked by the encoder to send first pass stats to the
+ * external rate control model.
+ *
+ * \param[in]  rate_ctrl_model    rate control model
+ * \param[in]  first_pass_stats   first pass stats
+ */
+typedef int (*vpx_rc_send_firstpass_stats_cb_fn_t)(
+    vpx_rc_model_t rate_ctrl_model,
+    const vpx_rc_firstpass_stats_t *first_pass_stats);
+
+/*!\brief Receive encode frame decision callback prototype
+ *
+ * This callback is invoked by the encoder to receive encode frame decision from
+ * the external rate control model.
+ *
+ * \param[in]  rate_ctrl_model    rate control model
+ * \param[in]  encode_frame_info  information of the coding frame
+ * \param[out] frame_decision     encode decision of the coding frame
+ */
+typedef int (*vpx_rc_get_encodeframe_decision_cb_fn_t)(
+    vpx_rc_model_t rate_ctrl_model,
+    const vpx_rc_encodeframe_info_t *encode_frame_info,
+    vpx_rc_encodeframe_decision_t *frame_decision);
+
+/*!\brief Update encode frame result callback prototype
+ *
+ * This callback is invoked by the encoder to update encode frame result to the
+ * external rate control model.
+ *
+ * \param[in]  rate_ctrl_model     rate control model
+ * \param[out] encode_frame_result encode result of the coding frame
+ */
+typedef int (*vpx_rc_update_encodeframe_result_cb_fn_t)(
+    vpx_rc_model_t rate_ctrl_model,
+    vpx_rc_encodeframe_result_t *encode_frame_result);
+
+/*!\brief Delete the external rate control model callback prototype
+ *
+ * This callback is invoked by the encoder to delete the external rate control
+ * model.
+ *
+ * \param[in]  rate_ctrl_model     rate control model
+ */
+typedef int (*vpx_rc_delete_model_cb_fn_t)(vpx_rc_model_t rate_ctrl_model);
+
+typedef struct vpx_rc_funcs {
+  vpx_rc_create_model_cb_fn_t create_model;
+  vpx_rc_send_firstpass_stats_cb_fn_t send_firstpass_stats;
+  vpx_rc_get_encodeframe_decision_cb_fn_t get_encodeframe_decision;
+  vpx_rc_update_encodeframe_result_cb_fn_t update_encodeframe_result;
+  vpx_rc_delete_model_cb_fn_t delete_model;
+  void *priv;
+} vpx_rc_funcs_t;
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+
+#endif  // VPX_VPX_VPX_EXT_RATECTRL_H_