#include "vp9/simple_encode.h"
namespace vp9 {
+namespace {
// TODO(angirbid): Find a better way to construct encode info
const int w = 352;
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.;
}
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();
}
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);
}
simple_encode.EndEncode();
}
+} // namespace
} // namespace vp9
#ifndef VPX_VP9_SIMPLE_ENCODE_H_
#define VPX_VP9_SIMPLE_ENCODE_H_
+
+#include <cstdio>
#include <memory>
#include <vector>
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;
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:
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_