diff --git a/media/BUILD.gn b/media/BUILD.gn index 93d104cdd0..2530e5ab4d 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -376,6 +376,7 @@ rtc_library("rtc_internal_video_codecs") { ":media_constants", ":rtc_media_base", ":rtc_simulcast_encoder_adapter", + "../api/environment", "../api/video:encoded_image", "../api/video:video_bitrate_allocation", "../api/video:video_frame", diff --git a/media/engine/multiplex_codec_factory.cc b/media/engine/multiplex_codec_factory.cc index 90df02a77e..cf17b46d7d 100644 --- a/media/engine/multiplex_codec_factory.cc +++ b/media/engine/multiplex_codec_factory.cc @@ -11,10 +11,12 @@ #include "media/engine/multiplex_codec_factory.h" #include +#include #include #include #include "absl/strings/match.h" +#include "api/environment/environment.h" #include "api/video_codecs/sdp_video_format.h" #include "media/base/codec.h" #include "media/base/media_constants.h" @@ -95,20 +97,21 @@ std::vector MultiplexDecoderFactory::GetSupportedFormats() return augmented_formats; } -std::unique_ptr MultiplexDecoderFactory::CreateVideoDecoder( +std::unique_ptr MultiplexDecoderFactory::Create( + const Environment& env, const SdpVideoFormat& format) { - if (!IsMultiplexCodec(cricket::CreateVideoCodec(format))) - return factory_->CreateVideoDecoder(format); - const auto& it = - format.parameters.find(cricket::kCodecParamAssociatedCodecName); + if (!IsMultiplexCodec(cricket::CreateVideoCodec(format))) { + return factory_->Create(env, format); + } + auto it = format.parameters.find(cricket::kCodecParamAssociatedCodecName); if (it == format.parameters.end()) { RTC_LOG(LS_ERROR) << "No assicated codec for multiplex."; return nullptr; } SdpVideoFormat associated_format = format; associated_format.name = it->second; - return std::unique_ptr(new MultiplexDecoderAdapter( - factory_.get(), associated_format, supports_augmenting_data_)); + return std::make_unique( + env, factory_.get(), associated_format, supports_augmenting_data_); } } // namespace webrtc diff --git a/media/engine/multiplex_codec_factory.h b/media/engine/multiplex_codec_factory.h index a4272a2eb2..164164f3ee 100644 --- a/media/engine/multiplex_codec_factory.h +++ b/media/engine/multiplex_codec_factory.h @@ -14,6 +14,7 @@ #include #include +#include "api/environment/environment.h" #include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/video_decoder.h" #include "api/video_codecs/video_decoder_factory.h" @@ -66,8 +67,8 @@ class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory { bool supports_augmenting_data = false); std::vector GetSupportedFormats() const override; - std::unique_ptr CreateVideoDecoder( - const SdpVideoFormat& format) override; + std::unique_ptr Create(const Environment& env, + const SdpVideoFormat& format) override; private: std::unique_ptr factory_; diff --git a/media/engine/multiplex_codec_factory_unittest.cc b/media/engine/multiplex_codec_factory_unittest.cc index 1cde2f37d8..7f0a418d4d 100644 --- a/media/engine/multiplex_codec_factory_unittest.cc +++ b/media/engine/multiplex_codec_factory_unittest.cc @@ -10,8 +10,10 @@ #include "media/engine/multiplex_codec_factory.h" +#include #include +#include "api/environment/environment_factory.h" #include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/video_decoder.h" #include "api/video_codecs/video_encoder.h" @@ -22,12 +24,13 @@ namespace webrtc { -TEST(MultiplexDecoderFactory, CreateVideoDecoder) { - std::unique_ptr internal_factory( - new InternalDecoderFactory()); +TEST(MultiplexDecoderFactoryTest, CreateVideoDecoder) { + std::unique_ptr internal_factory = + std::make_unique(); MultiplexDecoderFactory factory(std::move(internal_factory)); - std::unique_ptr decoder = - factory.CreateVideoDecoder(SdpVideoFormat( + std::unique_ptr decoder = factory.Create( + CreateEnvironment(), + SdpVideoFormat( cricket::kMultiplexCodecName, {{cricket::kCodecParamAssociatedCodecName, cricket::kVp9CodecName}})); EXPECT_TRUE(decoder); diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn index 1cdc83662c..8358995c45 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -529,6 +529,7 @@ rtc_library("webrtc_multiplex") { ":video_coding_utility", "../../api:fec_controller_api", "../../api:scoped_refptr", + "../../api/environment", "../../api/video:encoded_image", "../../api/video:video_frame", "../../api/video:video_rtp_headers", diff --git a/modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h b/modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h index d58981e4b2..ed02f2d72b 100644 --- a/modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h +++ b/modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h @@ -15,6 +15,7 @@ #include #include +#include "api/environment/environment.h" #include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/video_decoder.h" #include "api/video_codecs/video_decoder_factory.h" @@ -25,7 +26,8 @@ namespace webrtc { class MultiplexDecoderAdapter : public VideoDecoder { public: // `factory` is not owned and expected to outlive this class. - MultiplexDecoderAdapter(VideoDecoderFactory* factory, + MultiplexDecoderAdapter(const Environment& env, + VideoDecoderFactory* factory, const SdpVideoFormat& associated_format, bool supports_augmenting_data = false); virtual ~MultiplexDecoderAdapter(); @@ -62,6 +64,7 @@ class MultiplexDecoderAdapter : public VideoDecoder { std::unique_ptr augmenting_data, uint16_t augmenting_data_length); + const Environment env_; VideoDecoderFactory* const factory_; const SdpVideoFormat associated_format_; std::vector> decoders_; diff --git a/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc b/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc index 551a9490b0..7cebbe14d0 100644 --- a/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc +++ b/modules/video_coding/codecs/multiplex/multiplex_decoder_adapter.cc @@ -10,6 +10,7 @@ #include "modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h" +#include "api/environment/environment.h" #include "api/video/encoded_image.h" #include "api/video/i420_buffer.h" #include "api/video/video_frame_buffer.h" @@ -93,10 +94,12 @@ struct MultiplexDecoderAdapter::AugmentingData { }; MultiplexDecoderAdapter::MultiplexDecoderAdapter( + const Environment& env, VideoDecoderFactory* factory, const SdpVideoFormat& associated_format, bool supports_augmenting_data) - : factory_(factory), + : env_(env), + factory_(factory), associated_format_(associated_format), supports_augmenting_data_(supports_augmenting_data) {} @@ -111,7 +114,7 @@ bool MultiplexDecoderAdapter::Configure(const Settings& settings) { PayloadStringToCodecType(associated_format_.name)); for (size_t i = 0; i < kAlphaCodecStreams; ++i) { std::unique_ptr decoder = - factory_->CreateVideoDecoder(associated_format_); + factory_->Create(env_, associated_format_); if (!decoder->Configure(associated_settings)) { return false; } diff --git a/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc b/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc index a2f36a306d..9c6300e368 100644 --- a/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc +++ b/modules/video_coding/codecs/multiplex/test/multiplex_adapter_unittest.cc @@ -16,6 +16,8 @@ #include #include "absl/types/optional.h" +#include "api/environment/environment.h" +#include "api/environment/environment_factory.h" #include "api/scoped_refptr.h" #include "api/test/mock_video_decoder_factory.h" #include "api/test/mock_video_encoder_factory.h" @@ -63,7 +65,8 @@ class TestMultiplexAdapter : public VideoCodecUnitTest, protected: std::unique_ptr CreateDecoder() override { return std::make_unique( - decoder_factory_.get(), SdpVideoFormat(kMultiplexAssociatedCodecName), + env_, decoder_factory_.get(), + SdpVideoFormat(kMultiplexAssociatedCodecName), supports_augmenting_data_); } @@ -182,9 +185,9 @@ class TestMultiplexAdapter : public VideoCodecUnitTest, EXPECT_CALL(*decoder_factory_, Die); // The decoders/encoders will be owned by the caller of // CreateVideoDecoder()/CreateVideoEncoder(). - EXPECT_CALL(*decoder_factory_, CreateVideoDecoder) - .Times(2) - .WillRepeatedly([] { return VP9Decoder::Create(); }); + EXPECT_CALL(*decoder_factory_, Create).Times(2).WillRepeatedly([] { + return VP9Decoder::Create(); + }); EXPECT_CALL(*encoder_factory_, Die); EXPECT_CALL(*encoder_factory_, CreateVideoEncoder) @@ -194,6 +197,7 @@ class TestMultiplexAdapter : public VideoCodecUnitTest, VideoCodecUnitTest::SetUp(); } + const Environment env_ = CreateEnvironment(); const std::unique_ptr decoder_factory_; const std::unique_ptr encoder_factory_; const bool supports_augmenting_data_; diff --git a/video/end_to_end_tests/codec_tests.cc b/video/end_to_end_tests/codec_tests.cc index 60a0bc8a15..e9ec7d541f 100644 --- a/video/end_to_end_tests/codec_tests.cc +++ b/video/end_to_end_tests/codec_tests.cc @@ -196,9 +196,11 @@ TEST_F(CodecEndToEndTest, SendsAndReceivesMultiplex) { &internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); }); test::FunctionVideoDecoderFactory decoder_factory( - [&internal_decoder_factory]() { + [&internal_decoder_factory](const Environment& env, + const SdpVideoFormat& /*format*/) { return std::make_unique( - &internal_decoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); + env, &internal_decoder_factory, + SdpVideoFormat(cricket::kVp9CodecName)); }); CodecObserver test(5, kVideoRotation_0, absl::nullopt, "multiplex", @@ -215,9 +217,11 @@ TEST_F(CodecEndToEndTest, SendsAndReceivesMultiplexVideoRotation90) { &internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); }); test::FunctionVideoDecoderFactory decoder_factory( - [&internal_decoder_factory]() { + [&internal_decoder_factory](const Environment& env, + const SdpVideoFormat& /*format*/) { return std::make_unique( - &internal_decoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); + env, &internal_decoder_factory, + SdpVideoFormat(cricket::kVp9CodecName)); }); CodecObserver test(5, kVideoRotation_90, absl::nullopt, "multiplex", &encoder_factory, &decoder_factory); diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc index ebfc24130e..c8331bffec 100644 --- a/video/video_quality_test.cc +++ b/video/video_quality_test.cc @@ -299,7 +299,7 @@ std::unique_ptr VideoQualityTest::CreateVideoDecoder( std::unique_ptr decoder; if (format.name == "multiplex") { decoder = std::make_unique( - decoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName)); + env, decoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName)); } else if (format.name == "FakeCodec") { decoder = webrtc::FakeVideoDecoderFactory::CreateVideoDecoder(); } else {