This is in simple_encode.cc
Unified · Split
| @@ -48,7 +48,7 @@ class SimpleEncode::impl { · 47 unmodified lines | ||
| 48 | 48 | VP9_COMP *cpi; |
| 49 | 49 | vpx_img_fmt_t img_fmt; |
| 50 | 50 | vpx_image_t tmp_img; |
| 51 | − std::vector<FIRSTPASS_STATS> frame_stats; | |
| 51 | + std::vector<FIRSTPASS_STATS> first_pass_stats; | |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | 54 | static VP9_COMP *init_encoder(const VP9EncoderConfig *oxcf, |
| @@ -102,7 +102,7 @@ void SimpleEncode::ComputeFirstPassStats() { · 47 unmodified lines | ||
| 102 | 102 | vpx_image_t img; |
| 103 | 103 | vpx_img_alloc(&img, pimpl->img_fmt, frame_width, frame_height, 1); |
| 104 | 104 | rewind(file); |
| 105 | − pimpl->frame_stats.clear(); | |
| 105 | + pimpl->first_pass_stats.clear(); | |
| 106 | 106 | for (i = 0; i < num_frames; ++i) { |
| 107 | 107 | assert(!vp9_lookahead_full(lookahead)); |
| 108 | 108 | if (img_read(&img, file)) { |
| @@ -127,12 +127,12 @@ void SimpleEncode::ComputeFirstPassStats() { · 18 unmodified lines | ||
| 127 | 127 | // compresses data |
| 128 | 128 | assert(size == 0); |
| 129 | 129 | } |
| 130 | − pimpl->frame_stats.push_back(vp9_get_frame_stats(&cpi->twopass)); | |
| 130 | + pimpl->first_pass_stats.push_back(vp9_get_frame_stats(&cpi->twopass)); | |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | vp9_end_first_pass(cpi); |
| 134 | − // TODO(angiebird): Store the total_stats apart form frame_stats | |
| 135 | − pimpl->frame_stats.push_back(vp9_get_total_stats(&cpi->twopass)); | |
| 134 | + // TODO(angiebird): Store the total_stats apart form first_pass_stats | |
| 135 | + pimpl->first_pass_stats.push_back(vp9_get_total_stats(&cpi->twopass)); | |
| 136 | 136 | free_encoder(cpi); |
| 137 | 137 | rewind(file); |
| 138 | 138 | vpx_img_free(&img); |
| @@ -142,15 +142,16 @@ std::vector<std::vector<double>> SimpleEncode::ObserveFirstPassStats() { · 3 unmodified lines | ||
| 142 | 142 | std::vector<std::vector<double>> output_stats; |
| 143 | 143 | // TODO(angiebird): This function make several assumptions of |
| 144 | 144 | // FIRSTPASS_STATS. 1) All elements in FIRSTPASS_STATS are double except the |
| 145 | − // last one. 2) The last entry of frame_stats is the total_stats. | |
| 145 | + // last one. 2) The last entry of first_pass_stats is the total_stats. | |
| 146 | 146 | // Change the code structure, so that we don't have to make these assumptions |
| 147 | 147 | |
| 148 | − // Note the last entry of frame_stats is the total_stats, we don't need it. | |
| 149 | − for (size_t i = 0; i < pimpl->frame_stats.size() - 1; ++i) { | |
| 150 | − double *buf_start = reinterpret_cast<double *>(&pimpl->frame_stats[i]); | |
| 148 | + // Note the last entry of first_pass_stats is the total_stats, we don't need | |
| 149 | + // it. | |
| 150 | + for (size_t i = 0; i < pimpl->first_pass_stats.size() - 1; ++i) { | |
| 151 | + double *buf_start = reinterpret_cast<double *>(&pimpl->first_pass_stats[i]); | |
| 151 | 152 | // We use - 1 here because the last member in FIRSTPASS_STATS is not double |
| 152 | 153 | double *buf_end = |
| 153 | − buf_start + sizeof(pimpl->frame_stats[i]) / sizeof(*buf_end) - 1; | |
| 154 | + buf_start + sizeof(pimpl->first_pass_stats[i]) / sizeof(*buf_end) - 1; | |
| 154 | 155 | std::vector<double> this_stats(buf_start, buf_end); |
| 155 | 156 | output_stats.push_back(this_stats); |
| 156 | 157 | } |
| @@ -158,13 +159,14 @@ std::vector<std::vector<double>> SimpleEncode::ObserveFirstPassStats() { · 1 unmodified line | ||
| 158 | 159 | } |
| 159 | 160 | |
| 160 | 161 | void SimpleEncode::StartEncode() { |
| 161 | − assert(pimpl->frame_stats.size() > 0); | |
| 162 | + assert(pimpl->first_pass_stats.size() > 0); | |
| 162 | 163 | vpx_rational_t frame_rate = make_vpx_rational(frame_rate_num, frame_rate_den); |
| 163 | 164 | VP9EncoderConfig oxcf = vp9_get_encoder_config( |
| 164 | 165 | frame_width, frame_height, frame_rate, target_bitrate, VPX_RC_LAST_PASS); |
| 165 | 166 | vpx_fixed_buf_t stats; |
| 166 | − stats.buf = pimpl->frame_stats.data(); | |
| 167 | − stats.sz = sizeof(pimpl->frame_stats[0]) * pimpl->frame_stats.size(); | |
| 167 | + stats.buf = pimpl->first_pass_stats.data(); | |
| 168 | + stats.sz = | |
| 169 | + sizeof(pimpl->first_pass_stats[0]) * pimpl->first_pass_stats.size(); | |
| 168 | 170 | |
| 169 | 171 | vp9_set_first_pass_stats(&oxcf, &stats); |
| 170 | 172 | assert(pimpl->cpi == NULL); |
| @@ -224,7 +226,7 @@ void SimpleEncode::EncodeFrame(char *cx_data, size_t *size, size_t max_size) { · 53 unmodified lines | ||
| 224 | 226 | } |
| 225 | 227 | |
| 226 | 228 | int SimpleEncode::GetCodingFrameNum() { |
| 227 | − assert(pimpl->frame_stats.size() - 1 > 0); | |
| 229 | + assert(pimpl->first_pass_stats.size() - 1 > 0); | |
| 228 | 230 | // These are the default settings for now. |
| 229 | 231 | const int multi_layer_arf = 0; |
| 230 | 232 | const int allow_alt_ref = 1; |
| @@ -233,7 +235,7 @@ int SimpleEncode::GetCodingFrameNum() { · 2 unmodified lines | ||
| 233 | 235 | frame_width, frame_height, frame_rate, target_bitrate, VPX_RC_LAST_PASS); |
| 234 | 236 | FRAME_INFO frame_info = vp9_get_frame_info(&oxcf); |
| 235 | 237 | FIRST_PASS_INFO first_pass_info; |
| 236 | − fps_init_first_pass_info(&first_pass_info, pimpl->frame_stats.data(), | |
| 238 | + fps_init_first_pass_info(&first_pass_info, pimpl->first_pass_stats.data(), | |
| 237 | 239 | num_frames); |
| 238 | 240 | return vp9_get_coding_frame_num(&oxcf, &frame_info, &first_pass_info, |
| 239 | 241 | multi_layer_arf, allow_alt_ref); |