OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 while (frame_number < num_frames) { | 184 while (frame_number < num_frames) { |
185 // In order to not overwhelm the OpenMAX buffers in the Android | 185 // In order to not overwhelm the OpenMAX buffers in the Android |
186 // MediaCodec API, we roughly pace the frames here. The downside | 186 // MediaCodec API, we roughly pace the frames here. The downside |
187 // of this is that the encode run will be done in real-time. | 187 // of this is that the encode run will be done in real-time. |
188 // TODO(brandtr): Investigate if this is needed on iOS. | 188 // TODO(brandtr): Investigate if this is needed on iOS. |
189 if (config_.hw_codec) { | 189 if (config_.hw_codec) { |
190 SleepMs(rtc::kNumMillisecsPerSec / | 190 SleepMs(rtc::kNumMillisecsPerSec / |
191 rate_profile.input_frame_rate[rate_update_index]); | 191 rate_profile.input_frame_rate[rate_update_index]); |
192 } | 192 } |
193 | 193 |
194 task_queue.PostTask( | 194 task_queue.PostTask([this] { processor_->ProcessFrame(); }); |
195 [this, frame_number] { processor_->ProcessFrame(frame_number); }); | |
196 ++frame_number; | 195 ++frame_number; |
197 | 196 |
198 if (frame_number == | 197 if (frame_number == |
199 rate_profile.frame_index_rate_update[rate_update_index + 1]) { | 198 rate_profile.frame_index_rate_update[rate_update_index + 1]) { |
200 ++rate_update_index; | 199 ++rate_update_index; |
201 | 200 |
202 task_queue.PostTask([this, &rate_profile, rate_update_index] { | 201 task_queue.PostTask([this, &rate_profile, rate_update_index] { |
203 processor_->SetRates(rate_profile.target_bit_rate[rate_update_index], | 202 processor_->SetRates(rate_profile.target_bit_rate[rate_update_index], |
204 rate_profile.input_frame_rate[rate_update_index]); | 203 rate_profile.input_frame_rate[rate_update_index]); |
205 }); | 204 }); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 num_dropped_frames, | 237 num_dropped_frames, |
239 num_resize_actions); | 238 num_resize_actions); |
240 ++rate_update_index; | 239 ++rate_update_index; |
241 ResetRateControlMetrics(rate_update_index, rate_profile); | 240 ResetRateControlMetrics(rate_update_index, rate_profile); |
242 } | 241 } |
243 } | 242 } |
244 PrintAndMaybeVerifyRateControlMetrics(rate_update_index, rc_thresholds, | 243 PrintAndMaybeVerifyRateControlMetrics(rate_update_index, rc_thresholds, |
245 num_dropped_frames, num_resize_actions); | 244 num_dropped_frames, num_resize_actions); |
246 | 245 |
247 // Calculate and print other statistics. | 246 // Calculate and print other statistics. |
248 EXPECT_EQ(num_frames, static_cast<int>(stats_.stats_.size())); | 247 EXPECT_EQ(num_frames, static_cast<int>(stats_.size())); |
249 stats_.PrintSummary(); | 248 stats_.PrintSummary(); |
250 | 249 |
251 // Calculate and print image quality statistics. | 250 // Calculate and print image quality statistics. |
252 // TODO(marpan): Should compute these quality metrics per SetRates update. | 251 // TODO(marpan): Should compute these quality metrics per SetRates update. |
253 QualityMetricsResult psnr_result, ssim_result; | 252 QualityMetricsResult psnr_result, ssim_result; |
254 EXPECT_EQ(0, I420MetricsFromFiles(config_.input_filename.c_str(), | 253 EXPECT_EQ(0, I420MetricsFromFiles(config_.input_filename.c_str(), |
255 config_.output_filename.c_str(), | 254 config_.output_filename.c_str(), |
256 config_.codec_settings.width, | 255 config_.codec_settings.width, |
257 config_.codec_settings.height, &psnr_result, | 256 config_.codec_settings.height, &psnr_result, |
258 &ssim_result)); | 257 &ssim_result)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 406 } |
408 | 407 |
409 // For every encoded frame, update the rate control metrics. | 408 // For every encoded frame, update the rate control metrics. |
410 void VideoProcessorIntegrationTest::UpdateRateControlMetrics(int frame_number) { | 409 void VideoProcessorIntegrationTest::UpdateRateControlMetrics(int frame_number) { |
411 RTC_CHECK_GE(frame_number, 0); | 410 RTC_CHECK_GE(frame_number, 0); |
412 | 411 |
413 const int tl_idx = TemporalLayerIndexForFrame(frame_number); | 412 const int tl_idx = TemporalLayerIndexForFrame(frame_number); |
414 ++num_frames_per_update_[tl_idx]; | 413 ++num_frames_per_update_[tl_idx]; |
415 ++num_frames_total_; | 414 ++num_frames_total_; |
416 | 415 |
417 FrameType frame_type = stats_.stats_[frame_number].frame_type; | 416 const FrameStatistic* frame_stat = stats_.GetFrame(frame_number); |
| 417 FrameType frame_type = frame_stat->frame_type; |
418 float encoded_size_kbits = | 418 float encoded_size_kbits = |
419 stats_.stats_[frame_number].encoded_frame_length_in_bytes * 8.0f / | 419 frame_stat->encoded_frame_size_bytes * 8.0f / 1000.0f; |
420 1000.0f; | |
421 | 420 |
422 // Update layer data. | 421 // Update layer data. |
423 // Update rate mismatch relative to per-frame bandwidth for delta frames. | 422 // Update rate mismatch relative to per-frame bandwidth for delta frames. |
424 if (frame_type == kVideoFrameDelta) { | 423 if (frame_type == kVideoFrameDelta) { |
425 // TODO(marpan): Should we count dropped (zero size) frames in mismatch? | 424 // TODO(marpan): Should we count dropped (zero size) frames in mismatch? |
426 sum_frame_size_mismatch_[tl_idx] += | 425 sum_frame_size_mismatch_[tl_idx] += |
427 fabs(encoded_size_kbits - per_frame_bandwidth_[tl_idx]) / | 426 fabs(encoded_size_kbits - per_frame_bandwidth_[tl_idx]) / |
428 per_frame_bandwidth_[tl_idx]; | 427 per_frame_bandwidth_[tl_idx]; |
429 } else { | 428 } else { |
430 float target_size = (frame_number == 0) ? target_size_key_frame_initial_ | 429 float target_size = (frame_number == 0) ? target_size_key_frame_initial_ |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 perc_encoding_rate_mismatch_ = 0.0f; | 620 perc_encoding_rate_mismatch_ = 0.0f; |
622 num_frames_to_hit_target_ = | 621 num_frames_to_hit_target_ = |
623 rate_profile.frame_index_rate_update[rate_update_index + 1]; | 622 rate_profile.frame_index_rate_update[rate_update_index + 1]; |
624 encoding_rate_within_target_ = false; | 623 encoding_rate_within_target_ = false; |
625 sum_key_frame_size_mismatch_ = 0.0; | 624 sum_key_frame_size_mismatch_ = 0.0; |
626 num_key_frames_ = 0; | 625 num_key_frames_ = 0; |
627 } | 626 } |
628 | 627 |
629 } // namespace test | 628 } // namespace test |
630 } // namespace webrtc | 629 } // namespace webrtc |
OLD | NEW |