shithub: libvpx

Download patch

ref: 90271b22016b89a115206a38ab4790a76cce3553
parent: e94000aa35c5beb8901952abb9c0d037d3c977f1
author: angiebird <angiebird@google.com>
date: Mon Oct 12 11:12:03 EDT 2020

Add vpx_rc_status_t

Let callback functions in vpx_ext_ratectrl.h
return vpx_rc_status_t

Bug: webm:1707

Change-Id: I4ebed47278b228740f6c73b07aa472787b2617d2

--- a/test/vp9_ext_ratectrl_test.cc
+++ b/test/vp9_ext_ratectrl_test.cc
@@ -27,8 +27,9 @@
   int coding_index;
 };
 
-int rc_create_model(void *priv, const vpx_rc_config_t *ratectrl_config,
-                    vpx_rc_model_t *rate_ctrl_model_pt) {
+vpx_rc_status_t rc_create_model(void *priv,
+                                const vpx_rc_config_t *ratectrl_config,
+                                vpx_rc_model_t *rate_ctrl_model_pt) {
   ToyRateCtrl *toy_rate_ctrl = new (std::nothrow) ToyRateCtrl;
   EXPECT_NE(toy_rate_ctrl, nullptr);
   toy_rate_ctrl->magic_number = kModelMagicNumber;
@@ -41,11 +42,12 @@
   EXPECT_EQ(ratectrl_config->target_bitrate_kbps, 24000);
   EXPECT_EQ(ratectrl_config->frame_rate_num, 30);
   EXPECT_EQ(ratectrl_config->frame_rate_den, 1);
-  return 0;
+  return vpx_rc_ok;
 }
 
-int rc_send_firstpass_stats(vpx_rc_model_t rate_ctrl_model,
-                            const vpx_rc_firstpass_stats_t *first_pass_stats) {
+vpx_rc_status_t rc_send_firstpass_stats(
+    vpx_rc_model_t rate_ctrl_model,
+    const vpx_rc_firstpass_stats_t *first_pass_stats) {
   const ToyRateCtrl *toy_rate_ctrl =
       static_cast<ToyRateCtrl *>(rate_ctrl_model);
   EXPECT_EQ(toy_rate_ctrl->magic_number, kModelMagicNumber);
@@ -53,10 +55,10 @@
   for (int i = 0; i < first_pass_stats->num_frames; ++i) {
     EXPECT_DOUBLE_EQ(first_pass_stats->frame_stats[i].frame, i);
   }
-  return 0;
+  return vpx_rc_ok;
 }
 
-int rc_get_encodeframe_decision(
+vpx_rc_status_t rc_get_encodeframe_decision(
     vpx_rc_model_t rate_ctrl_model,
     const vpx_rc_encodeframe_info_t *encode_frame_info,
     vpx_rc_encodeframe_decision_t *frame_decision) {
@@ -90,10 +92,10 @@
   } else {
     frame_decision->q_index = 100;
   }
-  return 0;
+  return vpx_rc_ok;
 }
 
-int rc_update_encodeframe_result(
+vpx_rc_status_t rc_update_encodeframe_result(
     vpx_rc_model_t rate_ctrl_model,
     const vpx_rc_encodeframe_result_t *encode_frame_result) {
   const ToyRateCtrl *toy_rate_ctrl =
@@ -105,14 +107,14 @@
   if (toy_rate_ctrl->coding_index == kLosslessCodingIndex) {
     EXPECT_EQ(encode_frame_result->sse, 0);
   }
-  return 0;
+  return vpx_rc_ok;
 }
 
-int rc_delete_model(vpx_rc_model_t rate_ctrl_model) {
+vpx_rc_status_t rc_delete_model(vpx_rc_model_t rate_ctrl_model) {
   ToyRateCtrl *toy_rate_ctrl = static_cast<ToyRateCtrl *>(rate_ctrl_model);
   EXPECT_EQ(toy_rate_ctrl->magic_number, kModelMagicNumber);
   delete toy_rate_ctrl;
-  return 0;
+  return vpx_rc_ok;
 }
 
 class ExtRateCtrlTest : public ::libvpx_test::EncoderTest,
--- a/vpx/vpx_ext_ratectrl.h
+++ b/vpx/vpx_ext_ratectrl.h
@@ -39,6 +39,11 @@
   int64_t pixel_count;
 } vpx_rc_encodeframe_result_t;
 
+typedef enum vpx_rc_status {
+  vpx_rc_ok = 0,
+  vpx_rc_error = 1,
+} vpx_rc_status_t;
+
 // This is a mirror of vp9's FIRSTPASS_STATS
 // Only spatial_layer_id is omitted
 typedef struct vpx_rc_frame_stats {
@@ -92,7 +97,7 @@
  * \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)(
+typedef vpx_rc_status_t (*vpx_rc_create_model_cb_fn_t)(
     void *priv, const vpx_rc_config_t *ratectrl_config,
     vpx_rc_model_t *rate_ctrl_model_pt);
 
@@ -105,7 +110,7 @@
  * \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)(
+typedef vpx_rc_status_t (*vpx_rc_send_firstpass_stats_cb_fn_t)(
     vpx_rc_model_t rate_ctrl_model,
     const vpx_rc_firstpass_stats_t *first_pass_stats);
 
@@ -118,7 +123,7 @@
  * \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)(
+typedef vpx_rc_status_t (*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);
@@ -131,7 +136,7 @@
  * \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)(
+typedef vpx_rc_status_t (*vpx_rc_update_encodeframe_result_cb_fn_t)(
     vpx_rc_model_t rate_ctrl_model,
     const vpx_rc_encodeframe_result_t *encode_frame_result);
 
@@ -142,7 +147,8 @@
  *
  * \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 vpx_rc_status_t (*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;