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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "webrtc/test/testsupport/metrics/video_metrics.h" | 46 #include "webrtc/test/testsupport/metrics/video_metrics.h" |
47 #include "webrtc/test/testsupport/packet_reader.h" | 47 #include "webrtc/test/testsupport/packet_reader.h" |
48 #include "webrtc/typedefs.h" | 48 #include "webrtc/typedefs.h" |
49 | 49 |
50 namespace webrtc { | 50 namespace webrtc { |
51 namespace test { | 51 namespace test { |
52 // Maximum number of rate updates (i.e., calls to encoder to change bitrate | 52 // Maximum number of rate updates (i.e., calls to encoder to change bitrate |
53 // and/or frame rate) for the current tests. | 53 // and/or frame rate) for the current tests. |
54 const int kMaxNumRateUpdates = 3; | 54 const int kMaxNumRateUpdates = 3; |
55 | 55 |
| 56 // Maximum number of temporal layers to use in tests. |
| 57 const int kMaxNumTemporalLayers = 3; |
| 58 |
56 const int kPercTargetvsActualMismatch = 20; | 59 const int kPercTargetvsActualMismatch = 20; |
57 const int kBaseKeyFrameInterval = 3000; | 60 const int kBaseKeyFrameInterval = 3000; |
58 | 61 |
59 // Default sequence is foreman (CIF): may be better to use VGA for resize test. | 62 // Default sequence is foreman (CIF): may be better to use VGA for resize test. |
60 const int kCifWidth = 352; | 63 const int kCifWidth = 352; |
61 const int kCifHeight = 288; | 64 const int kCifHeight = 288; |
62 const char kFilenameForemanCif[] = "foreman_cif"; | 65 const char kFilenameForemanCif[] = "foreman_cif"; |
63 | 66 |
64 // Codec and network settings. | 67 // Codec and network settings. |
65 struct CodecParams { | 68 struct CodecParams { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 InitializeAndroidObjects(); | 153 InitializeAndroidObjects(); |
151 | 154 |
152 external_encoder_factory_.reset( | 155 external_encoder_factory_.reset( |
153 new webrtc_jni::MediaCodecVideoEncoderFactory()); | 156 new webrtc_jni::MediaCodecVideoEncoderFactory()); |
154 external_decoder_factory_.reset( | 157 external_decoder_factory_.reset( |
155 new webrtc_jni::MediaCodecVideoDecoderFactory()); | 158 new webrtc_jni::MediaCodecVideoDecoderFactory()); |
156 #endif | 159 #endif |
157 } | 160 } |
158 virtual ~VideoProcessorIntegrationTest() = default; | 161 virtual ~VideoProcessorIntegrationTest() = default; |
159 | 162 |
160 void SetUpCodecConfig(const CodecParams& process, | 163 void CreateEncoderAndDecoder(bool hw_codec, VideoCodecType codec_type) { |
161 const VisualizationParams* visualization_params) { | 164 if (hw_codec) { |
162 if (process.hw_codec) { | |
163 #if defined(WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED) | 165 #if defined(WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED) |
164 #if defined(WEBRTC_ANDROID) | 166 #if defined(WEBRTC_ANDROID) |
165 // In general, external codecs should be destroyed by the factories that | 167 // In general, external codecs should be destroyed by the factories that |
166 // allocated them. For the particular case of the Android | 168 // allocated them. For the particular case of the Android |
167 // MediaCodecVideo{En,De}coderFactory's, however, it turns out that it is | 169 // MediaCodecVideo{En,De}coderFactory's, however, it turns out that it is |
168 // fine for the std::unique_ptr to destroy the owned codec directly. | 170 // fine for the std::unique_ptr to destroy the owned codec directly. |
169 switch (process.codec_type) { | 171 switch (codec_type) { |
170 case kVideoCodecH264: | 172 case kVideoCodecH264: |
171 encoder_.reset(external_encoder_factory_->CreateVideoEncoder( | 173 encoder_.reset(external_encoder_factory_->CreateVideoEncoder( |
172 cricket::VideoCodec(cricket::kH264CodecName))); | 174 cricket::VideoCodec(cricket::kH264CodecName))); |
173 decoder_.reset( | 175 decoder_.reset( |
174 external_decoder_factory_->CreateVideoDecoder(kVideoCodecH264)); | 176 external_decoder_factory_->CreateVideoDecoder(kVideoCodecH264)); |
175 break; | 177 break; |
176 case kVideoCodecVP8: | 178 case kVideoCodecVP8: |
177 encoder_.reset(external_encoder_factory_->CreateVideoEncoder( | 179 encoder_.reset(external_encoder_factory_->CreateVideoEncoder( |
178 cricket::VideoCodec(cricket::kVp8CodecName))); | 180 cricket::VideoCodec(cricket::kVp8CodecName))); |
179 decoder_.reset( | 181 decoder_.reset( |
180 external_decoder_factory_->CreateVideoDecoder(kVideoCodecVP8)); | 182 external_decoder_factory_->CreateVideoDecoder(kVideoCodecVP8)); |
181 break; | 183 break; |
182 case kVideoCodecVP9: | 184 case kVideoCodecVP9: |
183 encoder_.reset(external_encoder_factory_->CreateVideoEncoder( | 185 encoder_.reset(external_encoder_factory_->CreateVideoEncoder( |
184 cricket::VideoCodec(cricket::kVp9CodecName))); | 186 cricket::VideoCodec(cricket::kVp9CodecName))); |
185 decoder_.reset( | 187 decoder_.reset( |
186 external_decoder_factory_->CreateVideoDecoder(kVideoCodecVP9)); | 188 external_decoder_factory_->CreateVideoDecoder(kVideoCodecVP9)); |
187 break; | 189 break; |
188 default: | 190 default: |
189 RTC_NOTREACHED(); | 191 RTC_NOTREACHED(); |
190 break; | 192 break; |
191 } | 193 } |
192 #elif defined(WEBRTC_IOS) | 194 #elif defined(WEBRTC_IOS) |
193 ASSERT_EQ(kVideoCodecH264, process.codec_type) | 195 ASSERT_EQ(kVideoCodecH264, codec_type) |
194 << "iOS HW codecs only support H264."; | 196 << "iOS HW codecs only support H264."; |
195 encoder_.reset(new H264VideoToolboxEncoder( | 197 encoder_.reset(new H264VideoToolboxEncoder( |
196 cricket::VideoCodec(cricket::kH264CodecName))); | 198 cricket::VideoCodec(cricket::kH264CodecName))); |
197 decoder_.reset(new H264VideoToolboxDecoder()); | 199 decoder_.reset(new H264VideoToolboxDecoder()); |
198 #else | 200 #else |
199 RTC_NOTREACHED() << "Only support HW codecs on Android and iOS."; | 201 RTC_NOTREACHED() << "Only support HW codecs on Android and iOS."; |
200 #endif | 202 #endif |
201 #endif // WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED | 203 #endif // WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED |
202 RTC_CHECK(encoder_) << "HW encoder not successfully created."; | 204 RTC_CHECK(encoder_) << "HW encoder not successfully created."; |
203 RTC_CHECK(decoder_) << "HW decoder not successfully created."; | 205 RTC_CHECK(decoder_) << "HW decoder not successfully created."; |
204 } else { | 206 return; |
205 // SW codecs. | |
206 switch (process.codec_type) { | |
207 case kVideoCodecH264: | |
208 encoder_.reset(H264Encoder::Create( | |
209 cricket::VideoCodec(cricket::kH264CodecName))); | |
210 decoder_.reset(H264Decoder::Create()); | |
211 break; | |
212 case kVideoCodecVP8: | |
213 encoder_.reset(VP8Encoder::Create()); | |
214 decoder_.reset(VP8Decoder::Create()); | |
215 break; | |
216 case kVideoCodecVP9: | |
217 encoder_.reset(VP9Encoder::Create()); | |
218 decoder_.reset(VP9Decoder::Create()); | |
219 break; | |
220 default: | |
221 RTC_NOTREACHED(); | |
222 break; | |
223 } | |
224 } | 207 } |
225 | 208 |
226 VideoCodingModule::Codec(process.codec_type, &codec_settings_); | 209 // SW codecs. |
| 210 switch (codec_type) { |
| 211 case kVideoCodecH264: |
| 212 encoder_.reset( |
| 213 H264Encoder::Create(cricket::VideoCodec(cricket::kH264CodecName))); |
| 214 decoder_.reset(H264Decoder::Create()); |
| 215 break; |
| 216 case kVideoCodecVP8: |
| 217 encoder_.reset(VP8Encoder::Create()); |
| 218 decoder_.reset(VP8Decoder::Create()); |
| 219 break; |
| 220 case kVideoCodecVP9: |
| 221 encoder_.reset(VP9Encoder::Create()); |
| 222 decoder_.reset(VP9Decoder::Create()); |
| 223 break; |
| 224 default: |
| 225 RTC_NOTREACHED(); |
| 226 break; |
| 227 } |
| 228 } |
| 229 |
| 230 void SetUpCodecConfig(const CodecParams& process, |
| 231 const VisualizationParams* visualization_params) { |
| 232 CreateEncoderAndDecoder(process.hw_codec, process.codec_type); |
227 | 233 |
228 // Configure input filename. | 234 // Configure input filename. |
229 config_.input_filename = test::ResourcePath(process.filename, "yuv"); | 235 config_.input_filename = test::ResourcePath(process.filename, "yuv"); |
230 if (process.verbose_logging) | 236 if (process.verbose_logging) |
231 printf("Filename: %s\n", process.filename.c_str()); | 237 printf("Filename: %s\n", process.filename.c_str()); |
232 // Generate an output filename in a safe way. | 238 // Generate an output filename in a safe way. |
233 config_.output_filename = test::TempFilename( | 239 config_.output_filename = test::TempFilename( |
234 test::OutputPath(), "videoprocessor_integrationtest"); | 240 test::OutputPath(), "videoprocessor_integrationtest"); |
| 241 |
235 config_.frame_length_in_bytes = | 242 config_.frame_length_in_bytes = |
236 CalcBufferSize(kI420, process.width, process.height); | 243 CalcBufferSize(kI420, process.width, process.height); |
237 config_.verbose = process.verbose_logging; | 244 config_.verbose = process.verbose_logging; |
238 config_.use_single_core = process.use_single_core; | 245 config_.use_single_core = process.use_single_core; |
239 // Key frame interval and packet loss are set for each test. | 246 // Key frame interval and packet loss are set for each test. |
240 config_.keyframe_interval = process.key_frame_interval; | 247 config_.keyframe_interval = process.key_frame_interval; |
241 config_.networking_config.packet_loss_probability = | 248 config_.networking_config.packet_loss_probability = |
242 packet_loss_probability_; | 249 packet_loss_probability_; |
243 | 250 |
244 // Configure codec settings. | 251 // Configure codec settings. |
| 252 VideoCodingModule::Codec(process.codec_type, &codec_settings_); |
245 config_.codec_settings = &codec_settings_; | 253 config_.codec_settings = &codec_settings_; |
246 config_.codec_settings->startBitrate = start_bitrate_; | 254 config_.codec_settings->startBitrate = start_bitrate_; |
247 config_.codec_settings->width = process.width; | 255 config_.codec_settings->width = process.width; |
248 config_.codec_settings->height = process.height; | 256 config_.codec_settings->height = process.height; |
249 | 257 |
250 // These features may be set depending on the test. | 258 // These features may be set depending on the test. |
251 switch (config_.codec_settings->codecType) { | 259 switch (config_.codec_settings->codecType) { |
252 case kVideoCodecH264: | 260 case kVideoCodecH264: |
253 config_.codec_settings->H264()->frameDroppingOn = | 261 config_.codec_settings->H264()->frameDroppingOn = |
254 process.frame_dropper_on; | 262 process.frame_dropper_on; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 100 * fabs(encoding_bitrate_total_ - bit_rate_) / bit_rate_; | 401 100 * fabs(encoding_bitrate_total_ - bit_rate_) / bit_rate_; |
394 if (perc_encoding_rate_mismatch_ < kPercTargetvsActualMismatch && | 402 if (perc_encoding_rate_mismatch_ < kPercTargetvsActualMismatch && |
395 !encoding_rate_within_target_) { | 403 !encoding_rate_within_target_) { |
396 num_frames_to_hit_target_ = num_frames_total_; | 404 num_frames_to_hit_target_ = num_frames_total_; |
397 encoding_rate_within_target_ = true; | 405 encoding_rate_within_target_ = true; |
398 } | 406 } |
399 } | 407 } |
400 | 408 |
401 // Verify expected behavior of rate control and print out data. | 409 // Verify expected behavior of rate control and print out data. |
402 void VerifyRateControlMetrics(int update_index, | 410 void VerifyRateControlMetrics(int update_index, |
403 int max_key_frame_size_mismatch, | 411 const RateControlThresholds& rc_expected) { |
404 int max_delta_frame_size_mismatch, | |
405 int max_encoding_rate_mismatch, | |
406 int max_time_hit_target, | |
407 int max_num_dropped_frames, | |
408 int num_spatial_resizes, | |
409 int num_key_frames) { | |
410 int num_dropped_frames = processor_->NumberDroppedFrames(); | 412 int num_dropped_frames = processor_->NumberDroppedFrames(); |
411 int num_resize_actions = processor_->NumberSpatialResizes(); | 413 int num_resize_actions = processor_->NumberSpatialResizes(); |
412 printf( | 414 printf( |
413 "For update #: %d,\n" | 415 "For update #: %d,\n" |
414 " Target Bitrate: %d,\n" | 416 " Target Bitrate: %d,\n" |
415 " Encoding bitrate: %f,\n" | 417 " Encoding bitrate: %f,\n" |
416 " Frame rate: %d \n", | 418 " Frame rate: %d \n", |
417 update_index, bit_rate_, encoding_bitrate_total_, frame_rate_); | 419 update_index, bit_rate_, encoding_bitrate_total_, frame_rate_); |
418 printf( | 420 printf( |
419 " Number of frames to approach target rate: %d, \n" | 421 " Number of frames to approach target rate: %d, \n" |
420 " Number of dropped frames: %d, \n" | 422 " Number of dropped frames: %d, \n" |
421 " Number of spatial resizes: %d, \n", | 423 " Number of spatial resizes: %d, \n", |
422 num_frames_to_hit_target_, num_dropped_frames, num_resize_actions); | 424 num_frames_to_hit_target_, num_dropped_frames, num_resize_actions); |
423 EXPECT_LE(perc_encoding_rate_mismatch_, max_encoding_rate_mismatch); | 425 EXPECT_LE(perc_encoding_rate_mismatch_, |
| 426 rc_expected.max_encoding_rate_mismatch); |
424 if (num_key_frames_ > 0) { | 427 if (num_key_frames_ > 0) { |
425 int perc_key_frame_size_mismatch = | 428 int perc_key_frame_size_mismatch = |
426 100 * sum_key_frame_size_mismatch_ / num_key_frames_; | 429 100 * sum_key_frame_size_mismatch_ / num_key_frames_; |
427 printf( | 430 printf( |
428 " Number of Key frames: %d \n" | 431 " Number of Key frames: %d \n" |
429 " Key frame rate mismatch: %d \n", | 432 " Key frame rate mismatch: %d \n", |
430 num_key_frames_, perc_key_frame_size_mismatch); | 433 num_key_frames_, perc_key_frame_size_mismatch); |
431 EXPECT_LE(perc_key_frame_size_mismatch, max_key_frame_size_mismatch); | 434 EXPECT_LE(perc_key_frame_size_mismatch, |
| 435 rc_expected.max_key_frame_size_mismatch); |
432 } | 436 } |
433 printf("\n"); | 437 printf("\n"); |
434 printf("Rates statistics for Layer data \n"); | 438 printf("Rates statistics for Layer data \n"); |
435 for (int i = 0; i < num_temporal_layers_; i++) { | 439 for (int i = 0; i < num_temporal_layers_; i++) { |
436 printf("Temporal layer #%d \n", i); | 440 printf("Temporal layer #%d \n", i); |
437 int perc_frame_size_mismatch = | 441 int perc_frame_size_mismatch = |
438 100 * sum_frame_size_mismatch_[i] / num_frames_per_update_[i]; | 442 100 * sum_frame_size_mismatch_[i] / num_frames_per_update_[i]; |
439 int perc_encoding_rate_mismatch = | 443 int perc_encoding_rate_mismatch = |
440 100 * fabs(encoding_bitrate_[i] - bit_rate_layer_[i]) / | 444 100 * fabs(encoding_bitrate_[i] - bit_rate_layer_[i]) / |
441 bit_rate_layer_[i]; | 445 bit_rate_layer_[i]; |
442 printf( | 446 printf( |
443 " Target Layer Bit rate: %f \n" | 447 " Target Layer Bit rate: %f \n" |
444 " Layer frame rate: %f, \n" | 448 " Layer frame rate: %f, \n" |
445 " Layer per frame bandwidth: %f, \n" | 449 " Layer per frame bandwidth: %f, \n" |
446 " Layer Encoding bit rate: %f, \n" | 450 " Layer Encoding bit rate: %f, \n" |
447 " Layer Percent frame size mismatch: %d, \n" | 451 " Layer Percent frame size mismatch: %d, \n" |
448 " Layer Percent encoding rate mismatch: %d, \n" | 452 " Layer Percent encoding rate mismatch: %d, \n" |
449 " Number of frame processed per layer: %d \n", | 453 " Number of frame processed per layer: %d \n", |
450 bit_rate_layer_[i], frame_rate_layer_[i], per_frame_bandwidth_[i], | 454 bit_rate_layer_[i], frame_rate_layer_[i], per_frame_bandwidth_[i], |
451 encoding_bitrate_[i], perc_frame_size_mismatch, | 455 encoding_bitrate_[i], perc_frame_size_mismatch, |
452 perc_encoding_rate_mismatch, num_frames_per_update_[i]); | 456 perc_encoding_rate_mismatch, num_frames_per_update_[i]); |
453 EXPECT_LE(perc_frame_size_mismatch, max_delta_frame_size_mismatch); | 457 EXPECT_LE(perc_frame_size_mismatch, |
454 EXPECT_LE(perc_encoding_rate_mismatch, max_encoding_rate_mismatch); | 458 rc_expected.max_delta_frame_size_mismatch); |
| 459 EXPECT_LE(perc_encoding_rate_mismatch, |
| 460 rc_expected.max_encoding_rate_mismatch); |
455 } | 461 } |
456 printf("\n"); | 462 printf("\n"); |
457 EXPECT_LE(num_frames_to_hit_target_, max_time_hit_target); | 463 EXPECT_LE(num_frames_to_hit_target_, rc_expected.max_time_hit_target); |
458 EXPECT_LE(num_dropped_frames, max_num_dropped_frames); | 464 EXPECT_LE(num_dropped_frames, rc_expected.max_num_dropped_frames); |
459 EXPECT_EQ(num_resize_actions, num_spatial_resizes); | 465 EXPECT_EQ(rc_expected.num_spatial_resizes, num_resize_actions); |
460 EXPECT_EQ(num_key_frames_, num_key_frames); | 466 EXPECT_EQ(rc_expected.num_key_frames, num_key_frames_); |
461 } | 467 } |
462 | 468 |
463 void VerifyQuality(const test::QualityMetricsResult& psnr_result, | 469 void VerifyQuality(const test::QualityMetricsResult& psnr_result, |
464 const test::QualityMetricsResult& ssim_result, | 470 const test::QualityMetricsResult& ssim_result, |
465 const QualityThresholds& quality_thresholds) { | 471 const QualityThresholds& quality_thresholds) { |
466 EXPECT_GT(psnr_result.average, quality_thresholds.min_avg_psnr); | 472 EXPECT_GT(psnr_result.average, quality_thresholds.min_avg_psnr); |
467 EXPECT_GT(psnr_result.min, quality_thresholds.min_min_psnr); | 473 EXPECT_GT(psnr_result.min, quality_thresholds.min_min_psnr); |
468 EXPECT_GT(ssim_result.average, quality_thresholds.min_avg_ssim); | 474 EXPECT_GT(ssim_result.average, quality_thresholds.min_avg_ssim); |
469 EXPECT_GT(ssim_result.min, quality_thresholds.min_min_ssim); | 475 EXPECT_GT(ssim_result.min, quality_thresholds.min_min_ssim); |
470 } | 476 } |
471 | 477 |
472 // Layer index corresponding to frame number, for up to 3 layers. | 478 // Layer index corresponding to frame number, for up to 3 layers. |
473 void LayerIndexForFrame(int frame_number) { | 479 int LayerIndexForFrame(int frame_number) { |
474 if (num_temporal_layers_ == 1) { | 480 int layer = -1; |
475 layer_ = 0; | 481 switch (num_temporal_layers_) { |
476 } else if (num_temporal_layers_ == 2) { | 482 case 1: |
477 // layer 0: 0 2 4 ... | 483 layer = 0; |
478 // layer 1: 1 3 | 484 break; |
479 if (frame_number % 2 == 0) { | 485 case 2: |
480 layer_ = 0; | 486 // layer 0: 0 2 4 ... |
481 } else { | 487 // layer 1: 1 3 |
482 layer_ = 1; | 488 layer = (frame_number % 2 == 0) ? 0 : 1; |
483 } | 489 break; |
484 } else if (num_temporal_layers_ == 3) { | 490 case 3: |
485 // layer 0: 0 4 8 ... | 491 // layer 0: 0 4 8 ... |
486 // layer 1: 2 6 | 492 // layer 1: 2 6 |
487 // layer 2: 1 3 5 7 | 493 // layer 2: 1 3 5 7 |
488 if (frame_number % 4 == 0) { | 494 if (frame_number % 4 == 0) { |
489 layer_ = 0; | 495 layer = 0; |
490 } else if ((frame_number + 2) % 4 == 0) { | 496 } else if ((frame_number + 2) % 4 == 0) { |
491 layer_ = 1; | 497 layer = 1; |
492 } else if ((frame_number + 1) % 2 == 0) { | 498 } else if ((frame_number + 1) % 2 == 0) { |
493 layer_ = 2; | 499 layer = 2; |
494 } | 500 } |
495 } else { | 501 break; |
496 RTC_NOTREACHED() << "Max 3 layers are supported."; | 502 default: |
| 503 RTC_NOTREACHED(); |
| 504 break; |
497 } | 505 } |
| 506 |
| 507 return layer; |
498 } | 508 } |
499 | 509 |
500 // Set the bitrate and frame rate per layer, for up to 3 layers. | 510 // Set the bitrate and frame rate per layer, for up to 3 layers. |
501 void SetLayerRates() { | 511 void SetLayerRates() { |
502 RTC_DCHECK_LE(num_temporal_layers_, 3); | 512 RTC_DCHECK_LE(num_temporal_layers_, kMaxNumTemporalLayers); |
503 for (int i = 0; i < num_temporal_layers_; i++) { | 513 for (int i = 0; i < num_temporal_layers_; i++) { |
504 float bit_rate_ratio = | 514 float bit_rate_ratio = |
505 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i]; | 515 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i]; |
506 if (i > 0) { | 516 if (i > 0) { |
507 float bit_rate_delta_ratio = | 517 float bit_rate_delta_ratio = |
508 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i] - | 518 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i] - |
509 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i - 1]; | 519 kVp8LayerRateAlloction[num_temporal_layers_ - 1][i - 1]; |
510 bit_rate_layer_[i] = bit_rate_ * bit_rate_delta_ratio; | 520 bit_rate_layer_[i] = bit_rate_ * bit_rate_delta_ratio; |
511 } else { | 521 } else { |
512 bit_rate_layer_[i] = bit_rate_ * bit_rate_ratio; | 522 bit_rate_layer_[i] = bit_rate_ * bit_rate_ratio; |
(...skipping 30 matching lines...) Expand all Loading... |
543 // Process each frame, up to |num_frames|. | 553 // Process each frame, up to |num_frames|. |
544 int num_frames = rate_profile.num_frames; | 554 int num_frames = rate_profile.num_frames; |
545 int update_index = 0; | 555 int update_index = 0; |
546 ResetRateControlMetrics( | 556 ResetRateControlMetrics( |
547 rate_profile.frame_index_rate_update[update_index + 1]); | 557 rate_profile.frame_index_rate_update[update_index + 1]); |
548 int frame_number = 0; | 558 int frame_number = 0; |
549 FrameType frame_type = kVideoFrameDelta; | 559 FrameType frame_type = kVideoFrameDelta; |
550 while (processor_->ProcessFrame(frame_number) && | 560 while (processor_->ProcessFrame(frame_number) && |
551 frame_number < num_frames) { | 561 frame_number < num_frames) { |
552 // Get the layer index for the frame |frame_number|. | 562 // Get the layer index for the frame |frame_number|. |
553 LayerIndexForFrame(frame_number); | 563 layer_ = LayerIndexForFrame(frame_number); |
554 // Get the frame_type. | 564 // Get the frame_type. |
555 frame_type = processor_->EncodedFrameType(); | 565 frame_type = processor_->EncodedFrameType(); |
556 // Counter for whole sequence run. | 566 // Counter for whole sequence run. |
557 ++frame_number; | 567 ++frame_number; |
558 // Counters for each rate update. | 568 // Counters for each rate update. |
559 ++num_frames_per_update_[layer_]; | 569 ++num_frames_per_update_[layer_]; |
560 ++num_frames_total_; | 570 ++num_frames_total_; |
561 UpdateRateControlMetrics(frame_number, frame_type); | 571 UpdateRateControlMetrics(frame_number, frame_type); |
562 // If we hit another/next update, verify stats for current state and | 572 // If we hit another/next update, verify stats for current state and |
563 // update layers and codec with new rates. | 573 // update layers and codec with new rates. |
564 if (frame_number == | 574 if (frame_number == |
565 rate_profile.frame_index_rate_update[update_index + 1]) { | 575 rate_profile.frame_index_rate_update[update_index + 1]) { |
566 VerifyRateControlMetrics( | 576 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); |
567 update_index, | |
568 rc_thresholds[update_index].max_key_frame_size_mismatch, | |
569 rc_thresholds[update_index].max_delta_frame_size_mismatch, | |
570 rc_thresholds[update_index].max_encoding_rate_mismatch, | |
571 rc_thresholds[update_index].max_time_hit_target, | |
572 rc_thresholds[update_index].max_num_dropped_frames, | |
573 rc_thresholds[update_index].num_spatial_resizes, | |
574 rc_thresholds[update_index].num_key_frames); | |
575 // Update layer rates and the codec with new rates. | 577 // Update layer rates and the codec with new rates. |
576 ++update_index; | 578 ++update_index; |
577 bit_rate_ = rate_profile.target_bit_rate[update_index]; | 579 bit_rate_ = rate_profile.target_bit_rate[update_index]; |
578 frame_rate_ = rate_profile.input_frame_rate[update_index]; | 580 frame_rate_ = rate_profile.input_frame_rate[update_index]; |
579 SetLayerRates(); | 581 SetLayerRates(); |
580 ResetRateControlMetrics( | 582 ResetRateControlMetrics( |
581 rate_profile.frame_index_rate_update[update_index + 1]); | 583 rate_profile.frame_index_rate_update[update_index + 1]); |
582 processor_->SetRates(bit_rate_, frame_rate_); | 584 processor_->SetRates(bit_rate_, frame_rate_); |
583 } | 585 } |
584 } | 586 } |
585 VerifyRateControlMetrics( | 587 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); |
586 update_index, rc_thresholds[update_index].max_key_frame_size_mismatch, | |
587 rc_thresholds[update_index].max_delta_frame_size_mismatch, | |
588 rc_thresholds[update_index].max_encoding_rate_mismatch, | |
589 rc_thresholds[update_index].max_time_hit_target, | |
590 rc_thresholds[update_index].max_num_dropped_frames, | |
591 rc_thresholds[update_index].num_spatial_resizes, | |
592 rc_thresholds[update_index].num_key_frames); | |
593 EXPECT_EQ(num_frames, frame_number); | 588 EXPECT_EQ(num_frames, frame_number); |
594 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); | 589 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); |
595 | 590 |
596 // Release encoder and decoder to make sure they have finished processing: | 591 // Release encoder and decoder to make sure they have finished processing: |
597 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | 592 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
598 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); | 593 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
599 | 594 |
600 // Close the analysis files before we use them for SSIM/PSNR calculations. | 595 // Close the analysis files before we use them for SSIM/PSNR calculations. |
601 analysis_frame_reader_->Close(); | 596 analysis_frame_reader_->Close(); |
602 analysis_frame_writer_->Close(); | 597 analysis_frame_writer_->Close(); |
(...skipping 12 matching lines...) Expand all Loading... |
615 // TODO(marpan): Should compute these quality metrics per SetRates update. | 610 // TODO(marpan): Should compute these quality metrics per SetRates update. |
616 test::QualityMetricsResult psnr_result, ssim_result; | 611 test::QualityMetricsResult psnr_result, ssim_result; |
617 EXPECT_EQ(0, test::I420MetricsFromFiles(config_.input_filename.c_str(), | 612 EXPECT_EQ(0, test::I420MetricsFromFiles(config_.input_filename.c_str(), |
618 config_.output_filename.c_str(), | 613 config_.output_filename.c_str(), |
619 config_.codec_settings->width, | 614 config_.codec_settings->width, |
620 config_.codec_settings->height, | 615 config_.codec_settings->height, |
621 &psnr_result, &ssim_result)); | 616 &psnr_result, &ssim_result)); |
622 printf("PSNR avg: %f, min: %f\nSSIM avg: %f, min: %f\n", | 617 printf("PSNR avg: %f, min: %f\nSSIM avg: %f, min: %f\n", |
623 psnr_result.average, psnr_result.min, ssim_result.average, | 618 psnr_result.average, psnr_result.min, ssim_result.average, |
624 ssim_result.min); | 619 ssim_result.min); |
| 620 VerifyQuality(psnr_result, ssim_result, quality_thresholds); |
625 stats_.PrintSummary(); | 621 stats_.PrintSummary(); |
626 VerifyQuality(psnr_result, ssim_result, quality_thresholds); | |
627 | 622 |
628 // Remove analysis file. | 623 // Remove analysis file. |
629 if (remove(config_.output_filename.c_str()) < 0) { | 624 if (remove(config_.output_filename.c_str()) < 0) { |
630 fprintf(stderr, "Failed to remove temporary file!\n"); | 625 fprintf(stderr, "Failed to remove temporary file!\n"); |
631 } | 626 } |
632 } | 627 } |
633 | 628 |
634 static void SetCodecParams(CodecParams* process_settings, | 629 static void SetCodecParams(CodecParams* process_settings, |
635 VideoCodecType codec_type, | 630 VideoCodecType codec_type, |
636 bool hw_codec, | 631 bool hw_codec, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 test::TestConfig config_; | 734 test::TestConfig config_; |
740 // Must be destroyed before |encoder_| and |decoder_|. | 735 // Must be destroyed before |encoder_| and |decoder_|. |
741 std::unique_ptr<test::VideoProcessor> processor_; | 736 std::unique_ptr<test::VideoProcessor> processor_; |
742 | 737 |
743 // Visualization objects. | 738 // Visualization objects. |
744 std::unique_ptr<test::FrameWriter> source_frame_writer_; | 739 std::unique_ptr<test::FrameWriter> source_frame_writer_; |
745 std::unique_ptr<IvfFileWriter> encoded_frame_writer_; | 740 std::unique_ptr<IvfFileWriter> encoded_frame_writer_; |
746 std::unique_ptr<test::FrameWriter> decoded_frame_writer_; | 741 std::unique_ptr<test::FrameWriter> decoded_frame_writer_; |
747 | 742 |
748 // Quantities defined/updated for every encoder rate update. | 743 // Quantities defined/updated for every encoder rate update. |
749 // Some quantities defined per temporal layer (at most 3 layers in this test). | 744 int num_frames_per_update_[kMaxNumTemporalLayers]; |
750 int num_frames_per_update_[3]; | 745 float sum_frame_size_mismatch_[kMaxNumTemporalLayers]; |
751 float sum_frame_size_mismatch_[3]; | 746 float sum_encoded_frame_size_[kMaxNumTemporalLayers]; |
752 float sum_encoded_frame_size_[3]; | 747 float encoding_bitrate_[kMaxNumTemporalLayers]; |
753 float encoding_bitrate_[3]; | 748 float per_frame_bandwidth_[kMaxNumTemporalLayers]; |
754 float per_frame_bandwidth_[3]; | 749 float bit_rate_layer_[kMaxNumTemporalLayers]; |
755 float bit_rate_layer_[3]; | 750 float frame_rate_layer_[kMaxNumTemporalLayers]; |
756 float frame_rate_layer_[3]; | |
757 int num_frames_total_; | 751 int num_frames_total_; |
758 float sum_encoded_frame_size_total_; | 752 float sum_encoded_frame_size_total_; |
759 float encoding_bitrate_total_; | 753 float encoding_bitrate_total_; |
760 float perc_encoding_rate_mismatch_; | 754 float perc_encoding_rate_mismatch_; |
761 int num_frames_to_hit_target_; | 755 int num_frames_to_hit_target_; |
762 bool encoding_rate_within_target_; | 756 bool encoding_rate_within_target_; |
763 int bit_rate_; | 757 int bit_rate_; |
764 int frame_rate_; | 758 int frame_rate_; |
765 int layer_; | 759 int layer_; |
766 float target_size_key_frame_initial_; | 760 float target_size_key_frame_initial_; |
767 float target_size_key_frame_; | 761 float target_size_key_frame_; |
768 float sum_key_frame_size_mismatch_; | 762 float sum_key_frame_size_mismatch_; |
769 int num_key_frames_; | 763 int num_key_frames_; |
770 float start_bitrate_; | 764 float start_bitrate_; |
771 int start_frame_rate_; | 765 int start_frame_rate_; |
772 | 766 |
773 // Codec and network settings. | 767 // Codec and network settings. |
774 float packet_loss_probability_; | 768 float packet_loss_probability_; |
775 int num_temporal_layers_; | 769 int num_temporal_layers_; |
776 }; | 770 }; |
777 | 771 |
778 } // namespace test | 772 } // namespace test |
779 } // namespace webrtc | 773 } // namespace webrtc |
780 | 774 |
781 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES
T_H_ | 775 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES
T_H_ |
OLD | NEW |