]> granicus.if.org Git - libvpx/commitdiff
Add init version of EncodeFrameWithTargetFrameBits()
authorangiebird <angiebird@google.com>
Sat, 18 Jul 2020 01:43:06 +0000 (18:43 -0700)
committerangiebird <angiebird@google.com>
Mon, 20 Jul 2020 18:07:45 +0000 (11:07 -0700)
Will add a unit test in a followup CL.

Change-Id: I6a6354f307c427e1a352be7c6421927323eb5e1b

vp9/encoder/vp9_encoder.h
vp9/encoder/vp9_ratectrl.c
vp9/simple_encode.cc
vp9/simple_encode.h

index 7aa4bf7dcaf1381e757a49bb76fc0726ecc4c560..34ae0a09fbb72d489a1d7cc7c58bd51f4f8df04b 100644 (file)
@@ -563,16 +563,11 @@ static INLINE int gop_command_coding_frame_count(
 typedef struct ENCODE_COMMAND {
   int use_external_quantize_index;
   int external_quantize_index;
+  int use_external_target_frame_bits;
+  int target_frame_bits;
   GOP_COMMAND gop_command;
 } ENCODE_COMMAND;
 
-static INLINE void encode_command_init(ENCODE_COMMAND *encode_command) {
-  vp9_zero(*encode_command);
-  encode_command->use_external_quantize_index = 0;
-  encode_command->external_quantize_index = -1;
-  gop_command_off(&encode_command->gop_command);
-}
-
 static INLINE void encode_command_set_gop_command(
     ENCODE_COMMAND *encode_command, GOP_COMMAND gop_command) {
   encode_command->gop_command = gop_command;
@@ -590,6 +585,25 @@ static INLINE void encode_command_reset_external_quantize_index(
   encode_command->external_quantize_index = -1;
 }
 
+static INLINE void encode_command_set_target_frame_bits(
+    ENCODE_COMMAND *encode_command, int target_frame_bits) {
+  encode_command->use_external_target_frame_bits = 1;
+  encode_command->target_frame_bits = target_frame_bits;
+}
+
+static INLINE void encode_command_reset_target_frame_bits(
+    ENCODE_COMMAND *encode_command) {
+  encode_command->use_external_target_frame_bits = 0;
+  encode_command->target_frame_bits = -1;
+}
+
+static INLINE void encode_command_init(ENCODE_COMMAND *encode_command) {
+  vp9_zero(*encode_command);
+  encode_command_reset_external_quantize_index(encode_command);
+  encode_command_reset_target_frame_bits(encode_command);
+  gop_command_off(&encode_command->gop_command);
+}
+
 // Returns number of units in size of 4, if not multiple not a multiple of 4,
 // round it up. For example, size is 7, return 2.
 static INLINE int get_num_unit_4x4(int size) { return (size + 3) >> 2; }
index 2afa3618e85bcc200e9d46042de192f78adcd6b4..9bb8d45d2da2c7a85a47fdd84ca75712ac89557c 100644 (file)
@@ -1713,9 +1713,16 @@ void vp9_rc_set_frame_target(VP9_COMP *cpi, int target) {
 
   // Modify frame size target when down-scaling.
   if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC &&
-      rc->frame_size_selector != UNSCALED)
+      rc->frame_size_selector != UNSCALED) {
     rc->this_frame_target = (int)(rc->this_frame_target *
                                   rate_thresh_mult[rc->frame_size_selector]);
+  }
+
+#if CONFIG_RATE_CTRL
+  if (cpi->encode_command.use_external_target_frame_bits) {
+    rc->this_frame_target = cpi->encode_command.target_frame_bits;
+  }
+#endif
 
   // Target rate per SB64 (including partial SB64s.
   rc->sb64_target_rate = (int)(((int64_t)rc->this_frame_target * 64 * 64) /
index 1d7214ce586f7838fa73a0dbe9e5ddd5e61e7489..d083a44c2dc1e50ae3ef9c922f2757ca345e10f1 100644 (file)
@@ -1071,6 +1071,14 @@ void SimpleEncode::EncodeFrameWithQuantizeIndex(
   encode_command_reset_external_quantize_index(&impl_ptr_->cpi->encode_command);
 }
 
+void SimpleEncode::EncodeFrameWithTargetFrameBits(
+    EncodeFrameResult *encode_frame_result, int target_frame_bits) {
+  encode_command_set_target_frame_bits(&impl_ptr_->cpi->encode_command,
+                                       target_frame_bits);
+  EncodeFrame(encode_frame_result);
+  encode_command_reset_target_frame_bits(&impl_ptr_->cpi->encode_command);
+}
+
 static int GetCodingFrameNumFromGopMap(const std::vector<int> &gop_map) {
   int start_show_index = 0;
   int coding_frame_count = 0;
index 77197e7a239068a59462ce3c102ce9f6c242ecf6..ae36eb2c5536d39f1cc11123916bb2aa64889e34 100644 (file)
@@ -382,6 +382,12 @@ class SimpleEncode {
   void EncodeFrameWithQuantizeIndex(EncodeFrameResult *encode_frame_result,
                                     int quantize_index);
 
+  // Encode a frame with target frame bits usage.
+  // The encoder will find a quantize index to make the actual frame bits usage
+  // match the target.
+  void EncodeFrameWithTargetFrameBits(EncodeFrameResult *encode_frame_result,
+                                      int target_frame_bits);
+
   // Gets the number of coding frames for the video. The coding frames include
   // show frame and no show frame.
   // This function should be called after ComputeFirstPassStats().