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 |
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTEST_H _ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTEST_H _ |
12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTEST_H _ | 12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTEST_H _ |
13 | 13 |
14 #include <math.h> | 14 #include <math.h> |
15 | 15 |
16 #include <memory> | 16 #include <memory> |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "webrtc/base/checks.h" | |
19 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 20 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
20 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" | 21 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" |
21 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" | 22 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" |
22 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 23 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
23 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" | 24 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" |
24 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 25 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
25 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | 26 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
26 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 27 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
27 #include "webrtc/modules/video_coding/include/video_coding.h" | 28 #include "webrtc/modules/video_coding/include/video_coding.h" |
28 #include "webrtc/test/gtest.h" | 29 #include "webrtc/test/gtest.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 int max_num_dropped_frames; | 91 int max_num_dropped_frames; |
91 int max_key_frame_size_mismatch; | 92 int max_key_frame_size_mismatch; |
92 int max_delta_frame_size_mismatch; | 93 int max_delta_frame_size_mismatch; |
93 int max_encoding_rate_mismatch; | 94 int max_encoding_rate_mismatch; |
94 int max_time_hit_target; | 95 int max_time_hit_target; |
95 int num_spatial_resizes; | 96 int num_spatial_resizes; |
96 int num_key_frames; | 97 int num_key_frames; |
97 }; | 98 }; |
98 | 99 |
99 #if !defined(WEBRTC_IOS) | 100 #if !defined(WEBRTC_IOS) |
100 const int kNbrFramesShort = 100; // Some tests are run for shorter sequence. | 101 const int kNumFramesShort = 100; |
101 #endif | 102 #endif |
102 const int kNbrFramesLong = 299; | 103 const int kNumFramesLong = 299; |
103 | 104 |
104 // Parameters from VP8 wrapper, which control target size of key frames. | 105 // Parameters from VP8 wrapper, which control target size of key frames. |
105 const float kInitialBufferSize = 0.5f; | 106 const float kInitialBufferSize = 0.5f; |
106 const float kOptimalBufferSize = 0.6f; | 107 const float kOptimalBufferSize = 0.6f; |
107 const float kScaleKeyFrameSize = 0.5f; | 108 const float kScaleKeyFrameSize = 0.5f; |
108 | 109 |
109 // Integration test for video processor. Encodes+decodes a clip and | 110 // Integration test for video processor. Encodes+decodes a clip and |
110 // writes it to the output directory. After completion, quality metrics | 111 // writes it to the output directory. After completion, quality metrics |
111 // (PSNR and SSIM) and rate control metrics are computed to verify that the | 112 // (PSNR and SSIM) and rate control metrics are computed to verify that the |
112 // quality and encoder response is acceptable. The rate control tests allow us | 113 // quality and encoder response is acceptable. The rate control tests allow us |
113 // to verify the behavior for changing bitrate, changing frame rate, frame | 114 // to verify the behavior for changing bitrate, changing frame rate, frame |
114 // dropping/spatial resize, and temporal layers. The limits for the rate | 115 // dropping/spatial resize, and temporal layers. The limits for the rate |
115 // control metrics are set to be fairly conservative, so failure should only | 116 // control metrics are set to be fairly conservative, so failure should only |
116 // happen when some significant regression or breakdown occurs. | 117 // happen when some significant regression or breakdown occurs. |
117 class VideoProcessorIntegrationTest : public testing::Test { | 118 class VideoProcessorIntegrationTest : public testing::Test { |
118 protected: | 119 protected: |
119 std::unique_ptr<VideoEncoder> encoder_; | |
120 std::unique_ptr<VideoDecoder> decoder_; | |
121 std::unique_ptr<test::FrameReader> frame_reader_; | |
122 std::unique_ptr<test::FrameWriter> frame_writer_; | |
123 test::PacketReader packet_reader_; | |
124 std::unique_ptr<test::PacketManipulator> packet_manipulator_; | |
125 test::Stats stats_; | |
126 test::TestConfig config_; | |
127 VideoCodec codec_settings_; | |
128 std::unique_ptr<test::VideoProcessor> processor_; | |
129 TemporalLayersFactory tl_factory_; | |
130 | |
131 // Quantities defined/updated for every encoder rate update. | |
132 // Some quantities defined per temporal layer (at most 3 layers in this test). | |
133 int num_frames_per_update_[3]; | |
134 float sum_frame_size_mismatch_[3]; | |
135 float sum_encoded_frame_size_[3]; | |
136 float encoding_bitrate_[3]; | |
137 float per_frame_bandwidth_[3]; | |
138 float bit_rate_layer_[3]; | |
139 float frame_rate_layer_[3]; | |
140 int num_frames_total_; | |
141 float sum_encoded_frame_size_total_; | |
142 float encoding_bitrate_total_; | |
143 float perc_encoding_rate_mismatch_; | |
144 int num_frames_to_hit_target_; | |
145 bool encoding_rate_within_target_; | |
146 int bit_rate_; | |
147 int frame_rate_; | |
148 int layer_; | |
149 float target_size_key_frame_initial_; | |
150 float target_size_key_frame_; | |
151 float sum_key_frame_size_mismatch_; | |
152 int num_key_frames_; | |
153 float start_bitrate_; | |
154 | |
155 // Codec and network settings. | |
156 VideoCodecType codec_type_; | |
157 float packet_loss_; | |
158 int num_temporal_layers_; | |
159 int key_frame_interval_; | |
160 bool error_concealment_on_; | |
161 bool denoising_on_; | |
162 bool frame_dropper_on_; | |
163 bool spatial_resize_on_; | |
164 | |
165 VideoProcessorIntegrationTest() {} | 120 VideoProcessorIntegrationTest() {} |
166 virtual ~VideoProcessorIntegrationTest() {} | 121 virtual ~VideoProcessorIntegrationTest() {} |
167 | 122 |
168 void SetUpCodecConfig(const std::string& filename, | 123 void SetUpCodecConfig(const std::string& filename, |
169 int width, | 124 int width, |
170 int height, | 125 int height, |
171 bool verbose_logging) { | 126 bool verbose_logging) { |
172 if (codec_type_ == kVideoCodecH264) { | 127 if (codec_type_ == kVideoCodecH264) { |
173 encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264"))); | 128 encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264"))); |
174 decoder_.reset(H264Decoder::Create()); | 129 decoder_.reset(H264Decoder::Create()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 break; | 178 break; |
224 case kVideoCodecVP9: | 179 case kVideoCodecVP9: |
225 config_.codec_settings->VP9()->denoisingOn = denoising_on_; | 180 config_.codec_settings->VP9()->denoisingOn = denoising_on_; |
226 config_.codec_settings->VP9()->numberOfTemporalLayers = | 181 config_.codec_settings->VP9()->numberOfTemporalLayers = |
227 num_temporal_layers_; | 182 num_temporal_layers_; |
228 config_.codec_settings->VP9()->frameDroppingOn = frame_dropper_on_; | 183 config_.codec_settings->VP9()->frameDroppingOn = frame_dropper_on_; |
229 config_.codec_settings->VP9()->automaticResizeOn = spatial_resize_on_; | 184 config_.codec_settings->VP9()->automaticResizeOn = spatial_resize_on_; |
230 config_.codec_settings->VP9()->keyFrameInterval = kBaseKeyFrameInterval; | 185 config_.codec_settings->VP9()->keyFrameInterval = kBaseKeyFrameInterval; |
231 break; | 186 break; |
232 default: | 187 default: |
233 assert(false); | 188 RTC_NOTREACHED(); |
234 break; | 189 break; |
235 } | 190 } |
236 frame_reader_.reset(new test::FrameReaderImpl( | 191 frame_reader_.reset(new test::FrameReaderImpl( |
237 config_.input_filename, config_.codec_settings->width, | 192 config_.input_filename, config_.codec_settings->width, |
238 config_.codec_settings->height)); | 193 config_.codec_settings->height)); |
239 frame_writer_.reset(new test::FrameWriterImpl( | 194 frame_writer_.reset(new test::FrameWriterImpl( |
240 config_.output_filename, config_.frame_length_in_bytes)); | 195 config_.output_filename, config_.frame_length_in_bytes)); |
241 ASSERT_TRUE(frame_reader_->Init()); | 196 RTC_DCHECK(frame_reader_->Init()); |
åsapersson
2017/02/15 08:51:34
maybe RTC_CHECK
brandtr
2017/02/15 08:57:13
Done.
| |
242 ASSERT_TRUE(frame_writer_->Init()); | 197 RTC_DCHECK(frame_writer_->Init()); |
243 | 198 |
244 packet_manipulator_.reset(new test::PacketManipulatorImpl( | 199 packet_manipulator_.reset(new test::PacketManipulatorImpl( |
245 &packet_reader_, config_.networking_config, config_.verbose)); | 200 &packet_reader_, config_.networking_config, config_.verbose)); |
246 processor_.reset(new test::VideoProcessorImpl( | 201 processor_.reset(new test::VideoProcessorImpl( |
247 encoder_.get(), decoder_.get(), frame_reader_.get(), | 202 encoder_.get(), decoder_.get(), frame_reader_.get(), |
248 frame_writer_.get(), packet_manipulator_.get(), config_, &stats_)); | 203 frame_writer_.get(), packet_manipulator_.get(), config_, &stats_)); |
249 ASSERT_TRUE(processor_->Init()); | 204 RTC_DCHECK(processor_->Init()); |
åsapersson
2017/02/15 08:51:34
ditto
brandtr
2017/02/15 08:57:13
Done.
| |
250 } | 205 } |
251 | 206 |
252 // Reset quantities after each encoder update, update the target | 207 // Reset quantities after each encoder update, update the target |
253 // per-frame bandwidth. | 208 // per-frame bandwidth. |
254 void ResetRateControlMetrics(int num_frames) { | 209 void ResetRateControlMetrics(int num_frames) { |
255 for (int i = 0; i < num_temporal_layers_; i++) { | 210 for (int i = 0; i < num_temporal_layers_; i++) { |
256 num_frames_per_update_[i] = 0; | 211 num_frames_per_update_[i] = 0; |
257 sum_frame_size_mismatch_[i] = 0.0f; | 212 sum_frame_size_mismatch_[i] = 0.0f; |
258 sum_encoded_frame_size_[i] = 0.0f; | 213 sum_encoded_frame_size_[i] = 0.0f; |
259 encoding_bitrate_[i] = 0.0f; | 214 encoding_bitrate_[i] = 0.0f; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 // layer 1: 2 6 | 349 // layer 1: 2 6 |
395 // layer 2: 1 3 5 7 | 350 // layer 2: 1 3 5 7 |
396 if (frame_number % 4 == 0) { | 351 if (frame_number % 4 == 0) { |
397 layer_ = 0; | 352 layer_ = 0; |
398 } else if ((frame_number + 2) % 4 == 0) { | 353 } else if ((frame_number + 2) % 4 == 0) { |
399 layer_ = 1; | 354 layer_ = 1; |
400 } else if ((frame_number + 1) % 2 == 0) { | 355 } else if ((frame_number + 1) % 2 == 0) { |
401 layer_ = 2; | 356 layer_ = 2; |
402 } | 357 } |
403 } else { | 358 } else { |
404 assert(false); // Only up to 3 layers. | 359 RTC_NOTREACHED() << "Max 3 layers are supported."; |
405 } | 360 } |
406 } | 361 } |
407 | 362 |
408 // Set the bitrate and frame rate per layer, for up to 3 layers. | 363 // Set the bitrate and frame rate per layer, for up to 3 layers. |
409 void SetLayerRates() { | 364 void SetLayerRates() { |
410 assert(num_temporal_layers_ <= 3); | 365 RTC_DCHECK_LE(num_temporal_layers_, 3); |
411 for (int i = 0; i < num_temporal_layers_; i++) { | 366 for (int i = 0; i < num_temporal_layers_; i++) { |
412 float bit_rate_ratio = | 367 float bit_rate_ratio = |
413 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i]; | 368 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i]; |
414 if (i > 0) { | 369 if (i > 0) { |
415 float bit_rate_delta_ratio = | 370 float bit_rate_delta_ratio = |
416 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i] - | 371 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i] - |
417 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i - 1]; | 372 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i - 1]; |
418 bit_rate_layer_[i] = bit_rate_ * bit_rate_delta_ratio; | 373 bit_rate_layer_[i] = bit_rate_ * bit_rate_delta_ratio; |
419 } else { | 374 } else { |
420 bit_rate_layer_[i] = bit_rate_ * bit_rate_ratio; | 375 bit_rate_layer_[i] = bit_rate_ * bit_rate_ratio; |
(...skipping 24 matching lines...) Expand all Loading... | |
445 SetUpCodecConfig(process.filename, process.width, process.height, | 400 SetUpCodecConfig(process.filename, process.width, process.height, |
446 process.verbose_logging); | 401 process.verbose_logging); |
447 // Update the layers and the codec with the initial rates. | 402 // Update the layers and the codec with the initial rates. |
448 bit_rate_ = rate_profile.target_bit_rate[0]; | 403 bit_rate_ = rate_profile.target_bit_rate[0]; |
449 frame_rate_ = rate_profile.input_frame_rate[0]; | 404 frame_rate_ = rate_profile.input_frame_rate[0]; |
450 SetLayerRates(); | 405 SetLayerRates(); |
451 // Set the initial target size for key frame. | 406 // Set the initial target size for key frame. |
452 target_size_key_frame_initial_ = | 407 target_size_key_frame_initial_ = |
453 0.5 * kInitialBufferSize * bit_rate_layer_[0]; | 408 0.5 * kInitialBufferSize * bit_rate_layer_[0]; |
454 processor_->SetRates(bit_rate_, frame_rate_); | 409 processor_->SetRates(bit_rate_, frame_rate_); |
410 | |
455 // Process each frame, up to |num_frames|. | 411 // Process each frame, up to |num_frames|. |
456 int num_frames = rate_profile.num_frames; | 412 int num_frames = rate_profile.num_frames; |
457 int update_index = 0; | 413 int update_index = 0; |
458 ResetRateControlMetrics( | 414 ResetRateControlMetrics( |
459 rate_profile.frame_index_rate_update[update_index + 1]); | 415 rate_profile.frame_index_rate_update[update_index + 1]); |
460 int frame_number = 0; | 416 int frame_number = 0; |
461 FrameType frame_type = kVideoFrameDelta; | 417 FrameType frame_type = kVideoFrameDelta; |
462 while (processor_->ProcessFrame(frame_number) && | 418 while (processor_->ProcessFrame(frame_number) && |
463 frame_number < num_frames) { | 419 frame_number < num_frames) { |
464 // Get the layer index for the frame |frame_number|. | 420 // Get the layer index for the frame |frame_number|. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 rc_metrics[update_index].max_time_hit_target, | 456 rc_metrics[update_index].max_time_hit_target, |
501 rc_metrics[update_index].max_num_dropped_frames, | 457 rc_metrics[update_index].max_num_dropped_frames, |
502 rc_metrics[update_index].num_spatial_resizes, | 458 rc_metrics[update_index].num_spatial_resizes, |
503 rc_metrics[update_index].num_key_frames); | 459 rc_metrics[update_index].num_key_frames); |
504 EXPECT_EQ(num_frames, frame_number); | 460 EXPECT_EQ(num_frames, frame_number); |
505 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); | 461 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); |
506 | 462 |
507 // Release encoder and decoder to make sure they have finished processing: | 463 // Release encoder and decoder to make sure they have finished processing: |
508 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | 464 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
509 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); | 465 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
466 | |
510 // Close the files before we start using them for SSIM/PSNR calculations. | 467 // Close the files before we start using them for SSIM/PSNR calculations. |
511 frame_reader_->Close(); | 468 frame_reader_->Close(); |
512 frame_writer_->Close(); | 469 frame_writer_->Close(); |
513 | 470 |
514 // TODO(marpan): should compute these quality metrics per SetRates update. | 471 // TODO(marpan): should compute these quality metrics per SetRates update. |
515 test::QualityMetricsResult psnr_result, ssim_result; | 472 test::QualityMetricsResult psnr_result, ssim_result; |
516 EXPECT_EQ(0, test::I420MetricsFromFiles(config_.input_filename.c_str(), | 473 EXPECT_EQ(0, test::I420MetricsFromFiles(config_.input_filename.c_str(), |
517 config_.output_filename.c_str(), | 474 config_.output_filename.c_str(), |
518 config_.codec_settings->width, | 475 config_.codec_settings->width, |
519 config_.codec_settings->height, | 476 config_.codec_settings->height, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 rc_metrics[update_index].max_key_frame_size_mismatch = | 566 rc_metrics[update_index].max_key_frame_size_mismatch = |
610 max_key_frame_size_mismatch; | 567 max_key_frame_size_mismatch; |
611 rc_metrics[update_index].max_delta_frame_size_mismatch = | 568 rc_metrics[update_index].max_delta_frame_size_mismatch = |
612 max_delta_frame_size_mismatch; | 569 max_delta_frame_size_mismatch; |
613 rc_metrics[update_index].max_encoding_rate_mismatch = | 570 rc_metrics[update_index].max_encoding_rate_mismatch = |
614 max_encoding_rate_mismatch; | 571 max_encoding_rate_mismatch; |
615 rc_metrics[update_index].max_time_hit_target = max_time_hit_target; | 572 rc_metrics[update_index].max_time_hit_target = max_time_hit_target; |
616 rc_metrics[update_index].num_spatial_resizes = num_spatial_resizes; | 573 rc_metrics[update_index].num_spatial_resizes = num_spatial_resizes; |
617 rc_metrics[update_index].num_key_frames = num_key_frames; | 574 rc_metrics[update_index].num_key_frames = num_key_frames; |
618 } | 575 } |
576 | |
577 std::unique_ptr<VideoEncoder> encoder_; | |
578 std::unique_ptr<VideoDecoder> decoder_; | |
579 std::unique_ptr<test::FrameReader> frame_reader_; | |
580 std::unique_ptr<test::FrameWriter> frame_writer_; | |
581 test::PacketReader packet_reader_; | |
582 std::unique_ptr<test::PacketManipulator> packet_manipulator_; | |
583 test::Stats stats_; | |
584 test::TestConfig config_; | |
585 VideoCodec codec_settings_; | |
586 std::unique_ptr<test::VideoProcessor> processor_; | |
587 TemporalLayersFactory tl_factory_; | |
588 | |
589 // Quantities defined/updated for every encoder rate update. | |
590 // Some quantities defined per temporal layer (at most 3 layers in this test). | |
591 int num_frames_per_update_[3]; | |
592 float sum_frame_size_mismatch_[3]; | |
593 float sum_encoded_frame_size_[3]; | |
594 float encoding_bitrate_[3]; | |
595 float per_frame_bandwidth_[3]; | |
596 float bit_rate_layer_[3]; | |
597 float frame_rate_layer_[3]; | |
598 int num_frames_total_; | |
599 float sum_encoded_frame_size_total_; | |
600 float encoding_bitrate_total_; | |
601 float perc_encoding_rate_mismatch_; | |
602 int num_frames_to_hit_target_; | |
603 bool encoding_rate_within_target_; | |
604 int bit_rate_; | |
605 int frame_rate_; | |
606 int layer_; | |
607 float target_size_key_frame_initial_; | |
608 float target_size_key_frame_; | |
609 float sum_key_frame_size_mismatch_; | |
610 int num_key_frames_; | |
611 float start_bitrate_; | |
612 | |
613 // Codec and network settings. | |
614 VideoCodecType codec_type_; | |
615 float packet_loss_; | |
616 int num_temporal_layers_; | |
617 int key_frame_interval_; | |
618 bool error_concealment_on_; | |
619 bool denoising_on_; | |
620 bool frame_dropper_on_; | |
621 bool spatial_resize_on_; | |
619 }; | 622 }; |
620 | 623 |
621 } // namespace test | 624 } // namespace test |
622 } // namespace webrtc | 625 } // namespace webrtc |
623 | 626 |
624 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES T_H_ | 627 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES T_H_ |
OLD | NEW |