diff --git a/webrtc/modules/video_coding/codecs/test/plot_videoprocessor_integrationtest.cc b/webrtc/modules/video_coding/codecs/test/plot_videoprocessor_integrationtest.cc index b715d2e074..ef6dbde545 100644 --- a/webrtc/modules/video_coding/codecs/test/plot_videoprocessor_integrationtest.cc +++ b/webrtc/modules/video_coding/codecs/test/plot_videoprocessor_integrationtest.cc @@ -63,7 +63,8 @@ class PlotVideoProcessorIntegrationTest TempFilename(OutputPath(), "plot_videoprocessor_integrationtest"); config_.use_single_core = kUseSingleCore; config_.verbose = true; - config_.hw_codec = hw_codec_; + config_.hw_encoder = hw_codec_; + config_.hw_decoder = hw_codec_; SetCodecSettings(&config_, codec_type_, kNumTemporalLayers, kErrorConcealmentOn, kDenoisingOn, kFrameDropperOn, kSpatialResizeOn, kResilienceOn, width, height); diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc index ed19ae63f0..0641a87d68 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc @@ -94,7 +94,7 @@ void PrintCodecSettings(const VideoCodec& codec_settings) { void VerifyQpParser(const EncodedImage& encoded_frame, const TestConfig& config) { - if (config.hw_codec) + if (config.hw_encoder) return; int qp; diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.h b/webrtc/modules/video_coding/codecs/test/videoprocessor.h index 3ae3dc5c0e..072a3962ba 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.h +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.h @@ -93,8 +93,14 @@ struct TestConfig { // If printing of information to stdout shall be performed during processing. bool verbose = true; - // If HW or SW codec should be used. - bool hw_codec = false; + // Should hardware accelerated codecs be used? + bool hw_encoder = false; + bool hw_decoder = false; + + // Should the hardware codecs be wrapped in software fallbacks? + bool sw_fallback_encoder = false; + // TODO(brandtr): Add support for SW decoder fallbacks, when + // webrtc::VideoDecoder's can be wrapped in std::unique_ptr's. }; // Handles encoding/decoding of video using the VideoEncoder/VideoDecoder diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc index 68c2a683b8..cbc251896d 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc @@ -22,6 +22,7 @@ #include "webrtc/media/engine/internaldecoderfactory.h" #include "webrtc/media/engine/internalencoderfactory.h" +#include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" #include "webrtc/modules/video_coding/include/video_coding.h" @@ -89,8 +90,12 @@ void VideoProcessorIntegrationTest::SetCodecSettings(TestConfig* config, int width, int height) { webrtc::test::CodecSettings(codec_type, &config->codec_settings); + + // TODO(brandtr): Move the setting of |width| and |height| to the tests, and + // DCHECK that they are set before initializing the codec instead. config->codec_settings.width = width; config->codec_settings.height = height; + switch (config->codec_settings.codecType) { case kVideoCodecVP8: config->codec_settings.VP8()->resilience = @@ -186,7 +191,7 @@ void VideoProcessorIntegrationTest::ProcessFramesAndMaybeVerify( // MediaCodec API, we roughly pace the frames here. The downside // of this is that the encode run will be done in real-time. // TODO(brandtr): Investigate if this is needed on iOS. - if (config_.hw_codec) { + if (config_.hw_encoder || config_.hw_decoder) { SleepMs(rtc::kNumMillisecsPerSec / rate_profile.input_frame_rate[rate_update_index]); } @@ -207,7 +212,7 @@ void VideoProcessorIntegrationTest::ProcessFramesAndMaybeVerify( // Give the VideoProcessor pipeline some time to process the last frame, // and then release the codecs. - if (config_.hw_codec) { + if (config_.hw_encoder || config_.hw_decoder) { SleepMs(1 * rtc::kNumMillisecsPerSec); } ReleaseAndCloseObjects(&task_queue); @@ -269,41 +274,55 @@ void VideoProcessorIntegrationTest::ProcessFramesAndMaybeVerify( } void VideoProcessorIntegrationTest::CreateEncoderAndDecoder() { - if (config_.hw_codec) { + std::unique_ptr encoder_factory; + if (config_.hw_encoder) { +#if defined(WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED) +#if defined(WEBRTC_ANDROID) + encoder_factory.reset(new jni::MediaCodecVideoEncoderFactory()); +#elif defined(WEBRTC_IOS) + EXPECT_EQ(kVideoCodecH264, config_.codec_settings.codecType) + << "iOS HW codecs only support H264."; + encoder_factory = CreateObjCEncoderFactory(); +#else + RTC_NOTREACHED() << "Only support HW encoder on Android and iOS."; +#endif +#endif // WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED + } else { + encoder_factory.reset(new cricket::InternalEncoderFactory()); + } + + if (config_.hw_decoder) { #if defined(WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED) #if defined(WEBRTC_ANDROID) - encoder_factory_.reset(new jni::MediaCodecVideoEncoderFactory()); decoder_factory_.reset(new jni::MediaCodecVideoDecoderFactory()); #elif defined(WEBRTC_IOS) EXPECT_EQ(kVideoCodecH264, config_.codec_settings.codecType) << "iOS HW codecs only support H264."; - encoder_factory_ = CreateObjCEncoderFactory(); decoder_factory_ = CreateObjCDecoderFactory(); #else - RTC_NOTREACHED() << "Only support HW codecs on Android and iOS."; + RTC_NOTREACHED() << "Only support HW decoder on Android and iOS."; #endif #endif // WEBRTC_VIDEOPROCESSOR_INTEGRATIONTEST_HW_CODECS_ENABLED } else { - // SW codecs. - encoder_factory_.reset(new cricket::InternalEncoderFactory()); decoder_factory_.reset(new cricket::InternalDecoderFactory()); } + cricket::VideoCodec encoder_codec; switch (config_.codec_settings.codecType) { case kVideoCodecVP8: - encoder_ = encoder_factory_->CreateVideoEncoder( - cricket::VideoCodec(cricket::kVp8CodecName)); + encoder_codec = cricket::VideoCodec(cricket::kVp8CodecName); + encoder_.reset(encoder_factory->CreateVideoEncoder(encoder_codec)); decoder_ = decoder_factory_->CreateVideoDecoder(kVideoCodecVP8); break; case kVideoCodecVP9: - encoder_ = encoder_factory_->CreateVideoEncoder( - cricket::VideoCodec(cricket::kVp9CodecName)); + encoder_codec = cricket::VideoCodec(cricket::kVp9CodecName); + encoder_.reset(encoder_factory->CreateVideoEncoder(encoder_codec)); decoder_ = decoder_factory_->CreateVideoDecoder(kVideoCodecVP9); break; case kVideoCodecH264: // TODO(brandtr): Generalize so that we support multiple profiles here. - encoder_ = encoder_factory_->CreateVideoEncoder( - cricket::VideoCodec(cricket::kH264CodecName)); + encoder_codec = cricket::VideoCodec(cricket::kH264CodecName); + encoder_.reset(encoder_factory->CreateVideoEncoder(encoder_codec)); decoder_ = decoder_factory_->CreateVideoDecoder(kVideoCodecH264); break; default: @@ -311,12 +330,17 @@ void VideoProcessorIntegrationTest::CreateEncoderAndDecoder() { break; } + if (config_.sw_fallback_encoder) { + encoder_ = rtc::MakeUnique( + encoder_codec, std::move(encoder_)); + } + EXPECT_TRUE(encoder_) << "Encoder not successfully created."; EXPECT_TRUE(decoder_) << "Decoder not successfully created."; } void VideoProcessorIntegrationTest::DestroyEncoderAndDecoder() { - encoder_factory_->DestroyVideoEncoder(encoder_); + encoder_.reset(); decoder_factory_->DestroyVideoDecoder(decoder_); } @@ -340,7 +364,7 @@ void VideoProcessorIntegrationTest::SetUpAndInitObjects( if (visualization_params) { const std::string codec_name = CodecTypeToPayloadString(config_.codec_settings.codecType); - const std::string implementation_type = config_.hw_codec ? "hw" : "sw"; + const std::string implementation_type = config_.hw_encoder ? "hw" : "sw"; // clang-format off const std::string output_filename_base = OutputPath() + config_.filename + "-" + @@ -370,8 +394,12 @@ void VideoProcessorIntegrationTest::SetUpAndInitObjects( rtc::Event sync_event(false, false); task_queue->PostTask([this, &sync_event]() { + // TODO(brandtr): std::move |encoder_| and |decoder_| into the + // VideoProcessor when we are able to store |decoder_| in a + // std::unique_ptr. That is, when https://codereview.webrtc.org/3009973002 + // has been relanded. processor_ = rtc::MakeUnique( - encoder_, decoder_, analysis_frame_reader_.get(), + encoder_.get(), decoder_, analysis_frame_reader_.get(), analysis_frame_writer_.get(), packet_manipulator_.get(), config_, &stats_, encoded_frame_writer_.get(), decoded_frame_writer_.get()); processor_->Init(); diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h index 6c9f3df416..0efb9694b7 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h @@ -150,8 +150,7 @@ class VideoProcessorIntegrationTest : public testing::Test { const RateProfile& rate_profile); // Codecs. - std::unique_ptr encoder_factory_; - VideoEncoder* encoder_; + std::unique_ptr encoder_; std::unique_ptr decoder_factory_; VideoDecoder* decoder_; diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_libvpx.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_libvpx.cc index 9162b92f9a..163c6f1b5a 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_libvpx.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_libvpx.cc @@ -44,7 +44,8 @@ class VideoProcessorIntegrationTestLibvpx // Only allow encoder/decoder to use single core, for predictability. config_.use_single_core = true; config_.verbose = false; - config_.hw_codec = false; + config_.hw_encoder = false; + config_.hw_decoder = false; } }; diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_openh264.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_openh264.cc index e4c60e737c..a5f82619de 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_openh264.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest_openh264.cc @@ -43,7 +43,8 @@ class VideoProcessorIntegrationTestOpenH264 // Only allow encoder/decoder to use single core, for predictability. config_.use_single_core = true; config_.verbose = false; - config_.hw_codec = false; + config_.hw_encoder = false; + config_.hw_decoder = false; } };