Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1245)

Side by Side Diff: webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h

Issue 2695653002: Add support for creating HW codecs in VideoProcessor tests. (Closed)
Patch Set: Don't forget the mac! Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #if defined(WEBRTC_ANDROID)
20 #include "webrtc/modules/video_coding/codecs/test/android_test_initializer.h"
21 #include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h"
22 #include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h"
23 #elif defined(WEBRTC_IOS)
24 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h"
25 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h"
26 #endif
27
19 #include "webrtc/base/checks.h" 28 #include "webrtc/base/checks.h"
29 #include "webrtc/media/engine/webrtcvideodecoderfactory.h"
30 #include "webrtc/media/engine/webrtcvideoencoderfactory.h"
20 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" 31 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
21 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" 32 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h"
22 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" 33 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h"
23 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 34 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
24 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" 35 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h"
25 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" 36 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
26 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" 37 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
27 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 38 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
28 #include "webrtc/modules/video_coding/include/video_coding.h" 39 #include "webrtc/modules/video_coding/include/video_coding.h"
29 #include "webrtc/test/gtest.h" 40 #include "webrtc/test/gtest.h"
(...skipping 14 matching lines...) Expand all
44 const int kBaseKeyFrameInterval = 3000; 55 const int kBaseKeyFrameInterval = 3000;
45 56
46 // Default sequence is foreman (CIF): may be better to use VGA for resize test. 57 // Default sequence is foreman (CIF): may be better to use VGA for resize test.
47 const int kCifWidth = 352; 58 const int kCifWidth = 352;
48 const int kCifHeight = 288; 59 const int kCifHeight = 288;
49 const char kFilenameForemanCif[] = "foreman_cif"; 60 const char kFilenameForemanCif[] = "foreman_cif";
50 61
51 // Codec and network settings. 62 // Codec and network settings.
52 struct CodecConfigPars { 63 struct CodecConfigPars {
53 VideoCodecType codec_type; 64 VideoCodecType codec_type;
65 bool hw_codec;
54 float packet_loss; 66 float packet_loss;
55 int num_temporal_layers; 67 int num_temporal_layers;
56 int key_frame_interval; 68 int key_frame_interval;
57 bool error_concealment_on; 69 bool error_concealment_on;
58 bool denoising_on; 70 bool denoising_on;
59 bool frame_dropper_on; 71 bool frame_dropper_on;
60 bool spatial_resize_on; 72 bool spatial_resize_on;
61 int width; 73 int width;
62 int height; 74 int height;
63 std::string filename; 75 std::string filename;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Integration test for video processor. Encodes+decodes a clip and 122 // Integration test for video processor. Encodes+decodes a clip and
111 // writes it to the output directory. After completion, quality metrics 123 // writes it to the output directory. After completion, quality metrics
112 // (PSNR and SSIM) and rate control metrics are computed to verify that the 124 // (PSNR and SSIM) and rate control metrics are computed to verify that the
113 // quality and encoder response is acceptable. The rate control tests allow us 125 // quality and encoder response is acceptable. The rate control tests allow us
114 // to verify the behavior for changing bitrate, changing frame rate, frame 126 // to verify the behavior for changing bitrate, changing frame rate, frame
115 // dropping/spatial resize, and temporal layers. The limits for the rate 127 // dropping/spatial resize, and temporal layers. The limits for the rate
116 // control metrics are set to be fairly conservative, so failure should only 128 // control metrics are set to be fairly conservative, so failure should only
117 // happen when some significant regression or breakdown occurs. 129 // happen when some significant regression or breakdown occurs.
118 class VideoProcessorIntegrationTest : public testing::Test { 130 class VideoProcessorIntegrationTest : public testing::Test {
119 protected: 131 protected:
120 VideoProcessorIntegrationTest() {} 132 VideoProcessorIntegrationTest() {
121 virtual ~VideoProcessorIntegrationTest() {} 133 #if defined(WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED) && \
134 defined(WEBRTC_ANDROID)
135 InitializeAndroidObjects();
136
137 external_encoder_factory_.reset(
138 new webrtc_jni::MediaCodecVideoEncoderFactory());
139 external_decoder_factory_.reset(
140 new webrtc_jni::MediaCodecVideoDecoderFactory());
141 #endif
142 }
143 virtual ~VideoProcessorIntegrationTest() = default;
122 144
123 void SetUpCodecConfig(const std::string& filename, 145 void SetUpCodecConfig(const std::string& filename,
124 int width, 146 int width,
125 int height, 147 int height,
126 bool verbose_logging) { 148 bool verbose_logging) {
127 if (codec_type_ == kVideoCodecH264) { 149 if (hw_codec_) {
128 encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264"))); 150 #if defined(WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED)
129 decoder_.reset(H264Decoder::Create()); 151 #if defined(WEBRTC_ANDROID)
130 VideoCodingModule::Codec(kVideoCodecH264, &codec_settings_); 152 // In general, external codecs should be destroyed by the factories that
131 } else if (codec_type_ == kVideoCodecVP8) { 153 // allocated them. For the particular case of the Android
132 encoder_.reset(VP8Encoder::Create()); 154 // MediaCodecVideo{En,De}coderFactory's, however, it turns out that it is
133 decoder_.reset(VP8Decoder::Create()); 155 // fine for the std::unique_ptr to destroy the owned codec directly.
134 VideoCodingModule::Codec(kVideoCodecVP8, &codec_settings_); 156 if (codec_type_ == kVideoCodecH264) {
135 } else if (codec_type_ == kVideoCodecVP9) { 157 encoder_.reset(external_encoder_factory_->CreateVideoEncoder(
136 encoder_.reset(VP9Encoder::Create()); 158 cricket::VideoCodec(cricket::kH264CodecName)));
137 decoder_.reset(VP9Decoder::Create()); 159 decoder_.reset(
138 VideoCodingModule::Codec(kVideoCodecVP9, &codec_settings_); 160 external_decoder_factory_->CreateVideoDecoder(kVideoCodecH264));
161 } else if (codec_type_ == kVideoCodecVP8) {
162 encoder_.reset(external_encoder_factory_->CreateVideoEncoder(
163 cricket::VideoCodec(cricket::kVp8CodecName)));
164 decoder_.reset(
165 external_decoder_factory_->CreateVideoDecoder(kVideoCodecVP8));
166 } else if (codec_type_ == kVideoCodecVP9) {
167 encoder_.reset(external_encoder_factory_->CreateVideoEncoder(
168 cricket::VideoCodec(cricket::kVp9CodecName)));
169 decoder_.reset(
170 external_decoder_factory_->CreateVideoDecoder(kVideoCodecVP9));
171 }
172 #elif defined(WEBRTC_IOS)
173 RTC_DCHECK_EQ(kVideoCodecH264, codec_type_)
174 << "iOS HW codecs only support H264.";
175 encoder_.reset(new H264VideoToolboxEncoder(
176 cricket::VideoCodec(cricket::kH264CodecName)));
177 decoder_.reset(new H264VideoToolboxDecoder());
178 #else
179 RTC_NOTREACHED() << "Only support HW codecs on Android and iOS.";
180 #endif
181 #endif // WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED
182 RTC_DCHECK(encoder_) << "HW encoder not successfully created.";
183 RTC_DCHECK(decoder_) << "HW decoder not successfully created.";
184 } else {
185 // SW codecs.
186 if (codec_type_ == kVideoCodecH264) {
187 encoder_.reset(
188 H264Encoder::Create(cricket::VideoCodec(cricket::kH264CodecName)));
189 decoder_.reset(H264Decoder::Create());
190 } else if (codec_type_ == kVideoCodecVP8) {
191 encoder_.reset(VP8Encoder::Create());
192 decoder_.reset(VP8Decoder::Create());
193 } else if (codec_type_ == kVideoCodecVP9) {
194 encoder_.reset(VP9Encoder::Create());
195 decoder_.reset(VP9Decoder::Create());
196 }
139 } 197 }
140 198
199 VideoCodingModule::Codec(codec_type_, &codec_settings_);
200
141 // Configure input filename. 201 // Configure input filename.
142 config_.input_filename = test::ResourcePath(filename, "yuv"); 202 config_.input_filename = test::ResourcePath(filename, "yuv");
143 if (verbose_logging) 203 if (verbose_logging)
144 printf("Filename: %s\n", filename.c_str()); 204 printf("Filename: %s\n", filename.c_str());
145 // Generate an output filename in a safe way. 205 // Generate an output filename in a safe way.
146 config_.output_filename = test::TempFilename( 206 config_.output_filename = test::TempFilename(
147 test::OutputPath(), "videoprocessor_integrationtest"); 207 test::OutputPath(), "videoprocessor_integrationtest");
148 config_.frame_length_in_bytes = CalcBufferSize(kI420, width, height); 208 config_.frame_length_in_bytes = CalcBufferSize(kI420, width, height);
149 config_.verbose = verbose_logging; 209 config_.verbose = verbose_logging;
150 // Only allow encoder/decoder to use single core, for predictability. 210 // Only allow encoder/decoder to use single core, for predictability.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 442 }
383 } 443 }
384 444
385 // Processes all frames in the clip and verifies the result. 445 // Processes all frames in the clip and verifies the result.
386 void ProcessFramesAndVerify(QualityMetrics quality_metrics, 446 void ProcessFramesAndVerify(QualityMetrics quality_metrics,
387 RateProfile rate_profile, 447 RateProfile rate_profile,
388 CodecConfigPars process, 448 CodecConfigPars process,
389 RateControlMetrics* rc_metrics) { 449 RateControlMetrics* rc_metrics) {
390 // Codec/config settings. 450 // Codec/config settings.
391 codec_type_ = process.codec_type; 451 codec_type_ = process.codec_type;
452 hw_codec_ = process.hw_codec;
392 start_bitrate_ = rate_profile.target_bit_rate[0]; 453 start_bitrate_ = rate_profile.target_bit_rate[0];
393 packet_loss_ = process.packet_loss; 454 packet_loss_ = process.packet_loss;
394 key_frame_interval_ = process.key_frame_interval; 455 key_frame_interval_ = process.key_frame_interval;
395 num_temporal_layers_ = process.num_temporal_layers; 456 num_temporal_layers_ = process.num_temporal_layers;
396 error_concealment_on_ = process.error_concealment_on; 457 error_concealment_on_ = process.error_concealment_on;
397 denoising_on_ = process.denoising_on; 458 denoising_on_ = process.denoising_on;
398 frame_dropper_on_ = process.frame_dropper_on; 459 frame_dropper_on_ = process.frame_dropper_on;
399 spatial_resize_on_ = process.spatial_resize_on; 460 spatial_resize_on_ = process.spatial_resize_on;
400 SetUpCodecConfig(process.filename, process.width, process.height, 461 SetUpCodecConfig(process.filename, process.width, process.height,
401 process.verbose_logging); 462 process.verbose_logging);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 int frame_rate, 555 int frame_rate,
495 int frame_index_rate_update) { 556 int frame_index_rate_update) {
496 rate_profile->target_bit_rate[update_index] = bit_rate; 557 rate_profile->target_bit_rate[update_index] = bit_rate;
497 rate_profile->input_frame_rate[update_index] = frame_rate; 558 rate_profile->input_frame_rate[update_index] = frame_rate;
498 rate_profile->frame_index_rate_update[update_index] = 559 rate_profile->frame_index_rate_update[update_index] =
499 frame_index_rate_update; 560 frame_index_rate_update;
500 } 561 }
501 562
502 static void SetCodecParameters(CodecConfigPars* process_settings, 563 static void SetCodecParameters(CodecConfigPars* process_settings,
503 VideoCodecType codec_type, 564 VideoCodecType codec_type,
565 bool hw_codec,
504 float packet_loss, 566 float packet_loss,
505 int key_frame_interval, 567 int key_frame_interval,
506 int num_temporal_layers, 568 int num_temporal_layers,
507 bool error_concealment_on, 569 bool error_concealment_on,
508 bool denoising_on, 570 bool denoising_on,
509 bool frame_dropper_on, 571 bool frame_dropper_on,
510 bool spatial_resize_on, 572 bool spatial_resize_on,
511 int width, 573 int width,
512 int height, 574 int height,
513 const std::string& filename, 575 const std::string& filename,
514 bool verbose_logging) { 576 bool verbose_logging) {
515 process_settings->codec_type = codec_type; 577 process_settings->codec_type = codec_type;
578 process_settings->hw_codec = hw_codec;
516 process_settings->packet_loss = packet_loss; 579 process_settings->packet_loss = packet_loss;
517 process_settings->key_frame_interval = key_frame_interval; 580 process_settings->key_frame_interval = key_frame_interval;
518 process_settings->num_temporal_layers = num_temporal_layers, 581 process_settings->num_temporal_layers = num_temporal_layers,
519 process_settings->error_concealment_on = error_concealment_on; 582 process_settings->error_concealment_on = error_concealment_on;
520 process_settings->denoising_on = denoising_on; 583 process_settings->denoising_on = denoising_on;
521 process_settings->frame_dropper_on = frame_dropper_on; 584 process_settings->frame_dropper_on = frame_dropper_on;
522 process_settings->spatial_resize_on = spatial_resize_on; 585 process_settings->spatial_resize_on = spatial_resize_on;
523 process_settings->width = width; 586 process_settings->width = width;
524 process_settings->height = height; 587 process_settings->height = height;
525 process_settings->filename = filename; 588 process_settings->filename = filename;
526 process_settings->verbose_logging = verbose_logging; 589 process_settings->verbose_logging = verbose_logging;
527 } 590 }
528 591
529 static void SetCodecParameters(CodecConfigPars* process_settings, 592 static void SetCodecParameters(CodecConfigPars* process_settings,
530 VideoCodecType codec_type, 593 VideoCodecType codec_type,
594 bool hw_codec,
531 float packet_loss, 595 float packet_loss,
532 int key_frame_interval, 596 int key_frame_interval,
533 int num_temporal_layers, 597 int num_temporal_layers,
534 bool error_concealment_on, 598 bool error_concealment_on,
535 bool denoising_on, 599 bool denoising_on,
536 bool frame_dropper_on, 600 bool frame_dropper_on,
537 bool spatial_resize_on) { 601 bool spatial_resize_on) {
538 SetCodecParameters(process_settings, codec_type, packet_loss, 602 SetCodecParameters(process_settings, codec_type, hw_codec, packet_loss,
539 key_frame_interval, num_temporal_layers, 603 key_frame_interval, num_temporal_layers,
540 error_concealment_on, denoising_on, frame_dropper_on, 604 error_concealment_on, denoising_on, frame_dropper_on,
541 spatial_resize_on, kCifWidth, kCifHeight, 605 spatial_resize_on, kCifWidth, kCifHeight,
542 kFilenameForemanCif, false /* verbose_logging */); 606 kFilenameForemanCif, false /* verbose_logging */);
543 } 607 }
544 608
545 static void SetQualityMetrics(QualityMetrics* quality_metrics, 609 static void SetQualityMetrics(QualityMetrics* quality_metrics,
546 double minimum_avg_psnr, 610 double minimum_avg_psnr,
547 double minimum_min_psnr, 611 double minimum_min_psnr,
548 double minimum_avg_ssim, 612 double minimum_avg_ssim,
(...skipping 19 matching lines...) Expand all
568 rc_metrics[update_index].max_delta_frame_size_mismatch = 632 rc_metrics[update_index].max_delta_frame_size_mismatch =
569 max_delta_frame_size_mismatch; 633 max_delta_frame_size_mismatch;
570 rc_metrics[update_index].max_encoding_rate_mismatch = 634 rc_metrics[update_index].max_encoding_rate_mismatch =
571 max_encoding_rate_mismatch; 635 max_encoding_rate_mismatch;
572 rc_metrics[update_index].max_time_hit_target = max_time_hit_target; 636 rc_metrics[update_index].max_time_hit_target = max_time_hit_target;
573 rc_metrics[update_index].num_spatial_resizes = num_spatial_resizes; 637 rc_metrics[update_index].num_spatial_resizes = num_spatial_resizes;
574 rc_metrics[update_index].num_key_frames = num_key_frames; 638 rc_metrics[update_index].num_key_frames = num_key_frames;
575 } 639 }
576 640
577 std::unique_ptr<VideoEncoder> encoder_; 641 std::unique_ptr<VideoEncoder> encoder_;
642 std::unique_ptr<cricket::WebRtcVideoEncoderFactory> external_encoder_factory_;
578 std::unique_ptr<VideoDecoder> decoder_; 643 std::unique_ptr<VideoDecoder> decoder_;
644 std::unique_ptr<cricket::WebRtcVideoDecoderFactory> external_decoder_factory_;
579 std::unique_ptr<test::FrameReader> frame_reader_; 645 std::unique_ptr<test::FrameReader> frame_reader_;
580 std::unique_ptr<test::FrameWriter> frame_writer_; 646 std::unique_ptr<test::FrameWriter> frame_writer_;
581 test::PacketReader packet_reader_; 647 test::PacketReader packet_reader_;
582 std::unique_ptr<test::PacketManipulator> packet_manipulator_; 648 std::unique_ptr<test::PacketManipulator> packet_manipulator_;
583 test::Stats stats_; 649 test::Stats stats_;
584 test::TestConfig config_; 650 test::TestConfig config_;
585 VideoCodec codec_settings_; 651 VideoCodec codec_settings_;
652 // Must be destroyed before |encoder_| and |decoder_|.
586 std::unique_ptr<test::VideoProcessor> processor_; 653 std::unique_ptr<test::VideoProcessor> processor_;
587 TemporalLayersFactory tl_factory_; 654 TemporalLayersFactory tl_factory_;
588 655
589 // Quantities defined/updated for every encoder rate update. 656 // Quantities defined/updated for every encoder rate update.
590 // Some quantities defined per temporal layer (at most 3 layers in this test). 657 // Some quantities defined per temporal layer (at most 3 layers in this test).
591 int num_frames_per_update_[3]; 658 int num_frames_per_update_[3];
592 float sum_frame_size_mismatch_[3]; 659 float sum_frame_size_mismatch_[3];
593 float sum_encoded_frame_size_[3]; 660 float sum_encoded_frame_size_[3];
594 float encoding_bitrate_[3]; 661 float encoding_bitrate_[3];
595 float per_frame_bandwidth_[3]; 662 float per_frame_bandwidth_[3];
596 float bit_rate_layer_[3]; 663 float bit_rate_layer_[3];
597 float frame_rate_layer_[3]; 664 float frame_rate_layer_[3];
598 int num_frames_total_; 665 int num_frames_total_;
599 float sum_encoded_frame_size_total_; 666 float sum_encoded_frame_size_total_;
600 float encoding_bitrate_total_; 667 float encoding_bitrate_total_;
601 float perc_encoding_rate_mismatch_; 668 float perc_encoding_rate_mismatch_;
602 int num_frames_to_hit_target_; 669 int num_frames_to_hit_target_;
603 bool encoding_rate_within_target_; 670 bool encoding_rate_within_target_;
604 int bit_rate_; 671 int bit_rate_;
605 int frame_rate_; 672 int frame_rate_;
606 int layer_; 673 int layer_;
607 float target_size_key_frame_initial_; 674 float target_size_key_frame_initial_;
608 float target_size_key_frame_; 675 float target_size_key_frame_;
609 float sum_key_frame_size_mismatch_; 676 float sum_key_frame_size_mismatch_;
610 int num_key_frames_; 677 int num_key_frames_;
611 float start_bitrate_; 678 float start_bitrate_;
612 679
613 // Codec and network settings. 680 // Codec and network settings.
614 VideoCodecType codec_type_; 681 VideoCodecType codec_type_;
682 bool hw_codec_;
615 float packet_loss_; 683 float packet_loss_;
616 int num_temporal_layers_; 684 int num_temporal_layers_;
617 int key_frame_interval_; 685 int key_frame_interval_;
618 bool error_concealment_on_; 686 bool error_concealment_on_;
619 bool denoising_on_; 687 bool denoising_on_;
620 bool frame_dropper_on_; 688 bool frame_dropper_on_;
621 bool spatial_resize_on_; 689 bool spatial_resize_on_;
622 }; 690 };
623 691
624 } // namespace test 692 } // namespace test
625 } // namespace webrtc 693 } // namespace webrtc
626 694
627 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES T_H_ 695 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES T_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698