| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 perc_encoding_rate_mismatch_ = 0.0f; | 259 perc_encoding_rate_mismatch_ = 0.0f; |
| 260 num_frames_to_hit_target_ = num_frames_to_hit_target; | 260 num_frames_to_hit_target_ = num_frames_to_hit_target; |
| 261 encoding_rate_within_target_ = false; | 261 encoding_rate_within_target_ = false; |
| 262 sum_key_frame_size_mismatch_ = 0.0; | 262 sum_key_frame_size_mismatch_ = 0.0; |
| 263 num_key_frames_ = 0; | 263 num_key_frames_ = 0; |
| 264 } | 264 } |
| 265 | 265 |
| 266 // For every encoded frame, update the rate control metrics. | 266 // For every encoded frame, update the rate control metrics. |
| 267 void UpdateRateControlMetrics(int frame_number) { | 267 void UpdateRateControlMetrics(int frame_number) { |
| 268 RTC_CHECK_GE(frame_number, 0); | 268 RTC_CHECK_GE(frame_number, 0); |
| 269 int tl_idx = TemporalLayerIndexForFrame(frame_number); | 269 |
| 270 FrameType frame_type = processor_->EncodedFrameType(frame_number); | 270 FrameType frame_type = stats_.stats_[frame_number].frame_type; |
| 271 float encoded_size_kbits = | 271 float encoded_size_kbits = |
| 272 processor_->EncodedFrameSize(frame_number) * 8.0f / 1000.0f; | 272 stats_.stats_[frame_number].encoded_frame_length_in_bytes * 8.0f / |
| 273 1000.0f; |
| 274 const int tl_idx = TemporalLayerIndexForFrame(frame_number); |
| 273 | 275 |
| 274 // Update layer data. | 276 // Update layer data. |
| 275 // Update rate mismatch relative to per-frame bandwidth for delta frames. | 277 // Update rate mismatch relative to per-frame bandwidth for delta frames. |
| 276 if (frame_type == kVideoFrameDelta) { | 278 if (frame_type == kVideoFrameDelta) { |
| 277 // TODO(marpan): Should we count dropped (zero size) frames in mismatch? | 279 // TODO(marpan): Should we count dropped (zero size) frames in mismatch? |
| 278 sum_frame_size_mismatch_[tl_idx] += | 280 sum_frame_size_mismatch_[tl_idx] += |
| 279 fabs(encoded_size_kbits - per_frame_bandwidth_[tl_idx]) / | 281 fabs(encoded_size_kbits - per_frame_bandwidth_[tl_idx]) / |
| 280 per_frame_bandwidth_[tl_idx]; | 282 per_frame_bandwidth_[tl_idx]; |
| 281 } else { | 283 } else { |
| 282 float target_size = (frame_number == 0) ? target_size_key_frame_initial_ | 284 float target_size = (frame_number == 0) ? target_size_key_frame_initial_ |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 ResetRateControlMetrics( | 485 ResetRateControlMetrics( |
| 484 rate_profile.frame_index_rate_update[update_index + 1]); | 486 rate_profile.frame_index_rate_update[update_index + 1]); |
| 485 | 487 |
| 486 if (config_.batch_mode) { | 488 if (config_.batch_mode) { |
| 487 // In batch mode, we calculate the metrics for all frames after all frames | 489 // In batch mode, we calculate the metrics for all frames after all frames |
| 488 // have been sent for encoding. | 490 // have been sent for encoding. |
| 489 | 491 |
| 490 // TODO(brandtr): Refactor "frame number accounting" so we don't have to | 492 // TODO(brandtr): Refactor "frame number accounting" so we don't have to |
| 491 // call ProcessFrame num_frames+1 times here. | 493 // call ProcessFrame num_frames+1 times here. |
| 492 for (frame_number = 0; frame_number <= num_frames; ++frame_number) { | 494 for (frame_number = 0; frame_number <= num_frames; ++frame_number) { |
| 493 EXPECT_TRUE(processor_->ProcessFrame(frame_number)); | 495 processor_->ProcessFrame(frame_number); |
| 494 } | 496 } |
| 495 | 497 |
| 496 for (frame_number = 0; frame_number < num_frames; ++frame_number) { | 498 for (frame_number = 0; frame_number < num_frames; ++frame_number) { |
| 497 const int tl_idx = TemporalLayerIndexForFrame(frame_number); | 499 const int tl_idx = TemporalLayerIndexForFrame(frame_number); |
| 498 ++num_frames_per_update_[tl_idx]; | 500 ++num_frames_per_update_[tl_idx]; |
| 499 ++num_frames_total_; | 501 ++num_frames_total_; |
| 500 UpdateRateControlMetrics(frame_number); | 502 UpdateRateControlMetrics(frame_number); |
| 501 } | 503 } |
| 502 } else { | 504 } else { |
| 503 // In online mode, we calculate the metrics for a given frame right after | 505 // In online mode, we calculate the metrics for a given frame right after |
| 504 // it has been sent for encoding. | 506 // it has been sent for encoding. |
| 505 | 507 |
| 506 if (config_.hw_codec) { | 508 if (config_.hw_codec) { |
| 507 LOG(LS_WARNING) << "HW codecs should mostly be run in batch mode, " | 509 LOG(LS_WARNING) << "HW codecs should mostly be run in batch mode, " |
| 508 "since they may be pipelining."; | 510 "since they may be pipelining."; |
| 509 } | 511 } |
| 510 | 512 |
| 511 while (frame_number < num_frames) { | 513 while (frame_number < num_frames) { |
| 512 EXPECT_TRUE(processor_->ProcessFrame(frame_number)); | 514 processor_->ProcessFrame(frame_number); |
| 513 VerifyQpParser(frame_number); | 515 VerifyQpParser(frame_number); |
| 514 const int tl_idx = TemporalLayerIndexForFrame(frame_number); | 516 const int tl_idx = TemporalLayerIndexForFrame(frame_number); |
| 515 ++num_frames_per_update_[tl_idx]; | 517 ++num_frames_per_update_[tl_idx]; |
| 516 ++num_frames_total_; | 518 ++num_frames_total_; |
| 517 UpdateRateControlMetrics(frame_number); | 519 UpdateRateControlMetrics(frame_number); |
| 518 | 520 |
| 519 ++frame_number; | 521 ++frame_number; |
| 520 | 522 |
| 521 // If we hit another/next update, verify stats for current state and | 523 // If we hit another/next update, verify stats for current state and |
| 522 // update layers and codec with new rates. | 524 // update layers and codec with new rates. |
| 523 if (frame_number == | 525 if (frame_number == |
| 524 rate_profile.frame_index_rate_update[update_index + 1]) { | 526 rate_profile.frame_index_rate_update[update_index + 1]) { |
| 525 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); | 527 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); |
| 526 | 528 |
| 527 // Update layer rates and the codec with new rates. | 529 // Update layer rates and the codec with new rates. |
| 528 ++update_index; | 530 ++update_index; |
| 529 bit_rate_ = rate_profile.target_bit_rate[update_index]; | 531 bit_rate_ = rate_profile.target_bit_rate[update_index]; |
| 530 frame_rate_ = rate_profile.input_frame_rate[update_index]; | 532 frame_rate_ = rate_profile.input_frame_rate[update_index]; |
| 531 SetTemporalLayerRates(); | 533 SetTemporalLayerRates(); |
| 532 ResetRateControlMetrics( | 534 ResetRateControlMetrics( |
| 533 rate_profile.frame_index_rate_update[update_index + 1]); | 535 rate_profile.frame_index_rate_update[update_index + 1]); |
| 534 processor_->SetRates(bit_rate_, frame_rate_); | 536 processor_->SetRates(bit_rate_, frame_rate_); |
| 535 } | 537 } |
| 536 } | 538 } |
| 537 // TODO(brandtr): Refactor "frame number accounting" so we don't have to | 539 // TODO(brandtr): Refactor "frame number accounting" so we don't have to |
| 538 // call ProcessFrame one extra time here. | 540 // call ProcessFrame one extra time here. |
| 539 EXPECT_TRUE(processor_->ProcessFrame(frame_number)); | 541 processor_->ProcessFrame(frame_number); |
| 540 } | 542 } |
| 541 | 543 |
| 542 // Verify rate control metrics for all frames (if in batch mode), or for all | 544 // Verify rate control metrics for all frames (if in batch mode), or for all |
| 543 // frames since the last rate update (if not in batch mode). | 545 // frames since the last rate update (if not in batch mode). |
| 544 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); | 546 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); |
| 545 EXPECT_EQ(num_frames, frame_number); | 547 EXPECT_EQ(num_frames, frame_number); |
| 546 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); | 548 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); |
| 547 | 549 |
| 548 // Release encoder and decoder to make sure they have finished processing. | 550 // Release encoder and decoder to make sure they have finished processing. |
| 549 processor_->Release(); | 551 processor_->Release(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 float target_size_key_frame_initial_; | 719 float target_size_key_frame_initial_; |
| 718 float target_size_key_frame_; | 720 float target_size_key_frame_; |
| 719 float sum_key_frame_size_mismatch_; | 721 float sum_key_frame_size_mismatch_; |
| 720 int num_key_frames_; | 722 int num_key_frames_; |
| 721 }; | 723 }; |
| 722 | 724 |
| 723 } // namespace test | 725 } // namespace test |
| 724 } // namespace webrtc | 726 } // namespace webrtc |
| 725 | 727 |
| 726 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES
T_H_ | 728 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES
T_H_ |
| OLD | NEW |