Cosmetic changes of SimpleEncode code
authorangiebird <angiebird@google.com>
Tue, 19 Nov 2019 22:04:02 +0000 (14:04 -0800)
committerangiebird <angiebird@google.com>
Thu, 21 Nov 2019 18:54:23 +0000 (10:54 -0800)
Change-Id: Ied06630d605a4978711070778b92bfb731c32161

test/simple_encode_test.cc
vp9/encoder/vp9_encoder.h
vp9/simple_encode.h

index daca438..82d0963 100644 (file)
@@ -5,6 +5,7 @@
 #include "vp9/simple_encode.h"
 
 namespace vp9 {
+namespace {
 
 // TODO(angirbid): Find a better way to construct encode info
 const int w = 352;
@@ -15,8 +16,8 @@ const int target_bitrate = 1000;
 const int num_frames = 17;
 const char infile_path[] = "bus_352x288_420_f20_b8.yuv";
 
-static double get_bit_rate_in_kpbs(size_t bit_size, int num_frames,
-                                   int frame_rate_num, int frame_rate_den) {
+double GetBitrateInKbps(size_t bit_size, int num_frames, int frame_rate_num,
+                        int frame_rate_den) {
   return static_cast<double>(bit_size) / num_frames * frame_rate_num /
          frame_rate_den / 1000.;
 }
@@ -84,9 +85,10 @@ TEST(SimpleEncode, EncodeFrame) {
     total_data_bit_size += encode_frame_result.coding_data_bit_size;
   }
   EXPECT_EQ(num_alternate_refereces, ref_num_alternate_refereces);
-  double bitrate = get_bit_rate_in_kpbs(total_data_bit_size, num_frames,
-                                        frame_rate_num, frame_rate_den);
-  EXPECT_LE(fabs(target_bitrate - bitrate), 150);
+  const double bitrate = GetBitrateInKbps(total_data_bit_size, num_frames,
+                                          frame_rate_num, frame_rate_den);
+  const double off_target_threshold = 150;
+  EXPECT_LE(fabs(target_bitrate - bitrate), off_target_threshold);
   simple_encode.EndEncode();
 }
 
@@ -97,7 +99,7 @@ TEST(SimpleEncode, EncodeFrameWithQuantizeIndex) {
   int num_coding_frames = simple_encode.GetCodingFrameNum();
   simple_encode.StartEncode();
   for (int i = 0; i < num_coding_frames; ++i) {
-    int assigned_quantize_index = 100 + i;
+    const int assigned_quantize_index = 100 + i;
     EncodeFrameResult encode_frame_result;
     simple_encode.EncodeFrameWithQuantizeIndex(&encode_frame_result,
                                                assigned_quantize_index);
@@ -105,5 +107,6 @@ TEST(SimpleEncode, EncodeFrameWithQuantizeIndex) {
   }
   simple_encode.EndEncode();
 }
+}  // namespace
 
 }  // namespace vp9
index 7c03dde..0a8623e 100644 (file)
@@ -539,7 +539,7 @@ static INLINE void encode_command_reset_external_quantize_index(
   encode_command->use_external_quantize_index = 0;
   encode_command->external_quantize_index = -1;
 }
-#endif
+#endif  // CONFIG_RATE_CTRL
 
 typedef struct VP9_COMP {
   FRAME_INFO frame_info;
index c370e43..3b62d48 100644 (file)
@@ -10,6 +10,8 @@
 
 #ifndef VPX_VP9_SIMPLE_ENCODE_H_
 #define VPX_VP9_SIMPLE_ENCODE_H_
+
+#include <cstdio>
 #include <memory>
 #include <vector>
 
@@ -27,7 +29,7 @@ struct EncodeFrameResult {
   size_t coding_data_bit_size;
   size_t coding_data_byte_size;
   // The EncodeFrame will allocate a buffer, write the coding data into the
-  // buffer and give the ownership of the buffer to coding_data
+  // buffer and give the ownership of the buffer to coding_data.
   std::unique_ptr<unsigned char[]> coding_data;
   double psnr;
   uint64_t sse;
@@ -40,36 +42,36 @@ class SimpleEncode {
                int frame_rate_den, int target_bitrate, int num_frames,
                const char *infile_path);
   ~SimpleEncode();
-  SimpleEncode(SimpleEncode &&) = delete;
-  SimpleEncode &operator=(SimpleEncode &&) = delete;
+  SimpleEncode(SimpleEncode &) = delete;
+  SimpleEncode &operator=(const SimpleEncode &) = delete;
 
   // Makes encoder compute the first pass stats and store it internally for
-  // future encode
+  // future encode.
   void ComputeFirstPassStats();
 
-  // Outputs the first pass stats
+  // Outputs the first pass stats.
   std::vector<std::vector<double>> ObserveFirstPassStats();
 
-  // Initializes the encoder for actual encoding
-  // This funtion should be called after ComputeFirstPassStats()
+  // Initializes the encoder for actual encoding.
+  // This funtion should be called after ComputeFirstPassStats().
   void StartEncode();
 
-  // Frees the encoder
-  // This funtion should be called after StartEncode() or EncodeFrame()
+  // Frees the encoder.
+  // This funtion should be called after StartEncode() or EncodeFrame().
   void EndEncode();
 
   // Encodes a frame
-  // This funtion should be called after StartEncode() before EndEncode()
+  // This funtion should be called after StartEncode() and before EndEncode().
   void EncodeFrame(EncodeFrameResult *encode_frame_result);
 
-  // Encodes a frame with a specific quantize index
-  // This funtion should be called after StartEncode() before EndEncode()
+  // Encodes a frame with a specific quantize index.
+  // This funtion should be called after StartEncode() and before EndEncode().
   void EncodeFrameWithQuantizeIndex(EncodeFrameResult *encode_frame_result,
                                     int quantize_index);
 
   // Gets the number of coding frames for the video. The coding frames include
   // show frame and no show frame.
-  // This funtion should be called after ComputeFirstPassStats()
+  // This funtion should be called after ComputeFirstPassStats().
   int GetCodingFrameNum();
 
  private:
@@ -80,9 +82,10 @@ class SimpleEncode {
   int frame_rate_den;
   int target_bitrate;
   int num_frames;
-  FILE *file;
+  std::FILE *file;
   std::unique_ptr<impl> impl_ptr;
 };
 
 }  // namespace vp9
-#endif  // VPX_VP9_SIMPLE_ENCODE
+
+#endif  // VPX_VP9_SIMPLE_ENCODE_H_