diff options
-rw-r--r-- | vp9/simple_encode.cc | 59 | ||||
-rw-r--r-- | vp9/simple_encode.h | 2 |
2 files changed, 32 insertions, 29 deletions
diff --git a/vp9/simple_encode.cc b/vp9/simple_encode.cc index 458f136f4..c7bed7308 100644 --- a/vp9/simple_encode.cc +++ b/vp9/simple_encode.cc @@ -103,7 +103,7 @@ SimpleEncode::SimpleEncode(int frame_width, int frame_height, int frame_rate_num, int frame_rate_den, int target_bitrate, int num_frames, const char *infile_path) { - this->pimpl = std::unique_ptr<impl>(new impl()); + this->impl_ptr = std::unique_ptr<impl>(new impl()); this->frame_width = frame_width; this->frame_height = frame_height; this->frame_rate_num = frame_rate_num; @@ -112,15 +112,15 @@ SimpleEncode::SimpleEncode(int frame_width, int frame_height, this->num_frames = num_frames; // TODO(angirbid): Should we keep a file pointer here or keep the file_path? this->file = fopen(infile_path, "r"); - pimpl->cpi = NULL; - pimpl->img_fmt = VPX_IMG_FMT_I420; + impl_ptr->cpi = NULL; + impl_ptr->img_fmt = VPX_IMG_FMT_I420; } void SimpleEncode::ComputeFirstPassStats() { vpx_rational_t frame_rate = make_vpx_rational(frame_rate_num, frame_rate_den); const VP9EncoderConfig oxcf = vp9_get_encoder_config( frame_width, frame_height, frame_rate, target_bitrate, VPX_RC_FIRST_PASS); - VP9_COMP *cpi = init_encoder(&oxcf, pimpl->img_fmt); + VP9_COMP *cpi = init_encoder(&oxcf, impl_ptr->img_fmt); struct lookahead_ctx *lookahead = cpi->lookahead; int i; int use_highbitdepth = 0; @@ -128,9 +128,9 @@ void SimpleEncode::ComputeFirstPassStats() { use_highbitdepth = cpi->common.use_highbitdepth; #endif vpx_image_t img; - vpx_img_alloc(&img, pimpl->img_fmt, frame_width, frame_height, 1); + vpx_img_alloc(&img, impl_ptr->img_fmt, frame_width, frame_height, 1); rewind(file); - pimpl->first_pass_stats.clear(); + impl_ptr->first_pass_stats.clear(); for (i = 0; i < num_frames; ++i) { assert(!vp9_lookahead_full(lookahead)); if (img_read(&img, file)) { @@ -156,12 +156,12 @@ void SimpleEncode::ComputeFirstPassStats() { // compresses data assert(size == 0); } - pimpl->first_pass_stats.push_back(vp9_get_frame_stats(&cpi->twopass)); + impl_ptr->first_pass_stats.push_back(vp9_get_frame_stats(&cpi->twopass)); } } vp9_end_first_pass(cpi); // TODO(angiebird): Store the total_stats apart form first_pass_stats - pimpl->first_pass_stats.push_back(vp9_get_total_stats(&cpi->twopass)); + impl_ptr->first_pass_stats.push_back(vp9_get_total_stats(&cpi->twopass)); free_encoder(cpi); rewind(file); vpx_img_free(&img); @@ -176,11 +176,13 @@ std::vector<std::vector<double>> SimpleEncode::ObserveFirstPassStats() { // Note the last entry of first_pass_stats is the total_stats, we don't need // it. - for (size_t i = 0; i < pimpl->first_pass_stats.size() - 1; ++i) { - double *buf_start = reinterpret_cast<double *>(&pimpl->first_pass_stats[i]); + for (size_t i = 0; i < impl_ptr->first_pass_stats.size() - 1; ++i) { + double *buf_start = + reinterpret_cast<double *>(&impl_ptr->first_pass_stats[i]); // We use - 1 here because the last member in FIRSTPASS_STATS is not double - double *buf_end = - buf_start + sizeof(pimpl->first_pass_stats[i]) / sizeof(*buf_end) - 1; + double *buf_end = buf_start + + sizeof(impl_ptr->first_pass_stats[i]) / sizeof(*buf_end) - + 1; std::vector<double> this_stats(buf_start, buf_end); output_stats.push_back(this_stats); } @@ -188,31 +190,32 @@ std::vector<std::vector<double>> SimpleEncode::ObserveFirstPassStats() { } void SimpleEncode::StartEncode() { - assert(pimpl->first_pass_stats.size() > 0); + assert(impl_ptr->first_pass_stats.size() > 0); vpx_rational_t frame_rate = make_vpx_rational(frame_rate_num, frame_rate_den); VP9EncoderConfig oxcf = vp9_get_encoder_config( frame_width, frame_height, frame_rate, target_bitrate, VPX_RC_LAST_PASS); vpx_fixed_buf_t stats; - stats.buf = pimpl->first_pass_stats.data(); + stats.buf = impl_ptr->first_pass_stats.data(); stats.sz = - sizeof(pimpl->first_pass_stats[0]) * pimpl->first_pass_stats.size(); + sizeof(impl_ptr->first_pass_stats[0]) * impl_ptr->first_pass_stats.size(); vp9_set_first_pass_stats(&oxcf, &stats); - assert(pimpl->cpi == NULL); - pimpl->cpi = init_encoder(&oxcf, pimpl->img_fmt); - vpx_img_alloc(&pimpl->tmp_img, pimpl->img_fmt, frame_width, frame_height, 1); + assert(impl_ptr->cpi == NULL); + impl_ptr->cpi = init_encoder(&oxcf, impl_ptr->img_fmt); + vpx_img_alloc(&impl_ptr->tmp_img, impl_ptr->img_fmt, frame_width, + frame_height, 1); rewind(file); } void SimpleEncode::EndEncode() { - free_encoder(pimpl->cpi); - pimpl->cpi = nullptr; - vpx_img_free(&pimpl->tmp_img); + free_encoder(impl_ptr->cpi); + impl_ptr->cpi = nullptr; + vpx_img_free(&impl_ptr->tmp_img); rewind(file); } void SimpleEncode::EncodeFrame(EncodeFrameResult *encode_frame_result) { - VP9_COMP *cpi = pimpl->cpi; + VP9_COMP *cpi = impl_ptr->cpi; struct lookahead_ctx *lookahead = cpi->lookahead; int use_highbitdepth = 0; #if CONFIG_VP9_HIGHBITDEPTH @@ -226,14 +229,14 @@ void SimpleEncode::EncodeFrame(EncodeFrameResult *encode_frame_result) { while (!vp9_lookahead_full(lookahead)) { // TODO(angiebird): Check whether we can move this file read logics to // lookahead - if (img_read(&pimpl->tmp_img, file)) { + if (img_read(&impl_ptr->tmp_img, file)) { int next_show_idx = vp9_lookahead_next_show_idx(lookahead); int64_t ts_start = timebase_units_to_ticks(&cpi->oxcf.g_timebase_in_ts, next_show_idx); int64_t ts_end = timebase_units_to_ticks(&cpi->oxcf.g_timebase_in_ts, next_show_idx + 1); YV12_BUFFER_CONFIG sd; - image2yuvconfig(&pimpl->tmp_img, &sd); + image2yuvconfig(&impl_ptr->tmp_img, &sd); vp9_lookahead_push(lookahead, &sd, ts_start, ts_end, use_highbitdepth, 0); } else { break; @@ -263,14 +266,14 @@ void SimpleEncode::EncodeFrame(EncodeFrameResult *encode_frame_result) { void SimpleEncode::EncodeFrameWithQuantizeIndex( EncodeFrameResult *encode_frame_result, int quantize_index) { - encode_command_set_external_quantize_index(&pimpl->cpi->encode_command, + encode_command_set_external_quantize_index(&impl_ptr->cpi->encode_command, quantize_index); EncodeFrame(encode_frame_result); - encode_command_reset_external_quantize_index(&pimpl->cpi->encode_command); + encode_command_reset_external_quantize_index(&impl_ptr->cpi->encode_command); } int SimpleEncode::GetCodingFrameNum() { - assert(pimpl->first_pass_stats.size() - 1 > 0); + assert(impl_ptr->first_pass_stats.size() - 1 > 0); // These are the default settings for now. const int multi_layer_arf = 0; const int allow_alt_ref = 1; @@ -279,7 +282,7 @@ int SimpleEncode::GetCodingFrameNum() { frame_width, frame_height, frame_rate, target_bitrate, VPX_RC_LAST_PASS); FRAME_INFO frame_info = vp9_get_frame_info(&oxcf); FIRST_PASS_INFO first_pass_info; - fps_init_first_pass_info(&first_pass_info, pimpl->first_pass_stats.data(), + fps_init_first_pass_info(&first_pass_info, impl_ptr->first_pass_stats.data(), num_frames); return vp9_get_coding_frame_num(&oxcf, &frame_info, &first_pass_info, multi_layer_arf, allow_alt_ref); diff --git a/vp9/simple_encode.h b/vp9/simple_encode.h index 42048be62..c78e57093 100644 --- a/vp9/simple_encode.h +++ b/vp9/simple_encode.h @@ -81,7 +81,7 @@ class SimpleEncode { int target_bitrate; int num_frames; FILE *file; - std::unique_ptr<impl> pimpl; + std::unique_ptr<impl> impl_ptr; }; } // namespace vp9 |