ref: 585eb34f8636a33e873c0506810d1c6a3aced898
parent: 93e2e701a9fd2b979ff9f3811146858a3d9f81b0
author: angiebird <[email protected]>
date: Tue Nov 19 09:04:02 EST 2019
Cosmetic changes of SimpleEncode code Change-Id: Ied06630d605a4978711070778b92bfb731c32161
--- 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 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 @@
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 @@
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 @@
}
simple_encode.EndEncode();
}
+} // namespace
} // namespace vp9
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -539,7 +539,7 @@
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;
--- 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 <cstdio>
#include <memory>
#include <vector>
@@ -27,7 +29,7 @@
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 @@
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 @@
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_