From 585eb34f8636a33e873c0506810d1c6a3aced898 Mon Sep 17 00:00:00 2001 From: angiebird Date: Tue, 19 Nov 2019 14:04:02 -0800 Subject: [PATCH] Cosmetic changes of SimpleEncode code Change-Id: Ied06630d605a4978711070778b92bfb731c32161 --- test/simple_encode_test.cc | 15 +++++++++------ vp9/encoder/vp9_encoder.h | 2 +- vp9/simple_encode.h | 33 ++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/test/simple_encode_test.cc b/test/simple_encode_test.cc index daca43801..82d096329 100644 --- a/test/simple_encode_test.cc +++ b/test/simple_encode_test.cc @@ -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(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 diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index 7c03ddeb8..0a8623efb 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -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; diff --git a/vp9/simple_encode.h b/vp9/simple_encode.h index c370e4306..3b62d4886 100644 --- a/vp9/simple_encode.h +++ b/vp9/simple_encode.h @@ -10,6 +10,8 @@ #ifndef VPX_VP9_SIMPLE_ENCODE_H_ #define VPX_VP9_SIMPLE_ENCODE_H_ + +#include #include #include @@ -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 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> 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_ptr; }; } // namespace vp9 -#endif // VPX_VP9_SIMPLE_ENCODE + +#endif // VPX_VP9_SIMPLE_ENCODE_H_ -- 2.40.0