Propagate webrtc::Environment through MultiplexDecoderAdapter

Bug: webrtc:15791
Change-Id: Ibe8fdc45722409b2cf6608ea6d8da2ea7e3472c2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/338621
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41747}
This commit is contained in:
Danil Chapovalov 2024-02-09 12:43:15 +01:00 committed by WebRTC LUCI CQ
parent ce1271af8f
commit 46364195d3
10 changed files with 49 additions and 26 deletions

View File

@ -376,6 +376,7 @@ rtc_library("rtc_internal_video_codecs") {
":media_constants", ":media_constants",
":rtc_media_base", ":rtc_media_base",
":rtc_simulcast_encoder_adapter", ":rtc_simulcast_encoder_adapter",
"../api/environment",
"../api/video:encoded_image", "../api/video:encoded_image",
"../api/video:video_bitrate_allocation", "../api/video:video_bitrate_allocation",
"../api/video:video_frame", "../api/video:video_frame",

View File

@ -11,10 +11,12 @@
#include "media/engine/multiplex_codec_factory.h" #include "media/engine/multiplex_codec_factory.h"
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "api/environment/environment.h"
#include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/sdp_video_format.h"
#include "media/base/codec.h" #include "media/base/codec.h"
#include "media/base/media_constants.h" #include "media/base/media_constants.h"
@ -95,20 +97,21 @@ std::vector<SdpVideoFormat> MultiplexDecoderFactory::GetSupportedFormats()
return augmented_formats; return augmented_formats;
} }
std::unique_ptr<VideoDecoder> MultiplexDecoderFactory::CreateVideoDecoder( std::unique_ptr<VideoDecoder> MultiplexDecoderFactory::Create(
const Environment& env,
const SdpVideoFormat& format) { const SdpVideoFormat& format) {
if (!IsMultiplexCodec(cricket::CreateVideoCodec(format))) if (!IsMultiplexCodec(cricket::CreateVideoCodec(format))) {
return factory_->CreateVideoDecoder(format); return factory_->Create(env, format);
const auto& it = }
format.parameters.find(cricket::kCodecParamAssociatedCodecName); auto it = format.parameters.find(cricket::kCodecParamAssociatedCodecName);
if (it == format.parameters.end()) { if (it == format.parameters.end()) {
RTC_LOG(LS_ERROR) << "No assicated codec for multiplex."; RTC_LOG(LS_ERROR) << "No assicated codec for multiplex.";
return nullptr; return nullptr;
} }
SdpVideoFormat associated_format = format; SdpVideoFormat associated_format = format;
associated_format.name = it->second; associated_format.name = it->second;
return std::unique_ptr<VideoDecoder>(new MultiplexDecoderAdapter( return std::make_unique<MultiplexDecoderAdapter>(
factory_.get(), associated_format, supports_augmenting_data_)); env, factory_.get(), associated_format, supports_augmenting_data_);
} }
} // namespace webrtc } // namespace webrtc

View File

@ -14,6 +14,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "api/environment/environment.h"
#include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_decoder.h" #include "api/video_codecs/video_decoder.h"
#include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_decoder_factory.h"
@ -66,7 +67,7 @@ class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory {
bool supports_augmenting_data = false); bool supports_augmenting_data = false);
std::vector<SdpVideoFormat> GetSupportedFormats() const override; std::vector<SdpVideoFormat> GetSupportedFormats() const override;
std::unique_ptr<VideoDecoder> CreateVideoDecoder( std::unique_ptr<VideoDecoder> Create(const Environment& env,
const SdpVideoFormat& format) override; const SdpVideoFormat& format) override;
private: private:

View File

@ -10,8 +10,10 @@
#include "media/engine/multiplex_codec_factory.h" #include "media/engine/multiplex_codec_factory.h"
#include <memory>
#include <utility> #include <utility>
#include "api/environment/environment_factory.h"
#include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_decoder.h" #include "api/video_codecs/video_decoder.h"
#include "api/video_codecs/video_encoder.h" #include "api/video_codecs/video_encoder.h"
@ -22,12 +24,13 @@
namespace webrtc { namespace webrtc {
TEST(MultiplexDecoderFactory, CreateVideoDecoder) { TEST(MultiplexDecoderFactoryTest, CreateVideoDecoder) {
std::unique_ptr<VideoDecoderFactory> internal_factory( std::unique_ptr<VideoDecoderFactory> internal_factory =
new InternalDecoderFactory()); std::make_unique<InternalDecoderFactory>();
MultiplexDecoderFactory factory(std::move(internal_factory)); MultiplexDecoderFactory factory(std::move(internal_factory));
std::unique_ptr<VideoDecoder> decoder = std::unique_ptr<VideoDecoder> decoder = factory.Create(
factory.CreateVideoDecoder(SdpVideoFormat( CreateEnvironment(),
SdpVideoFormat(
cricket::kMultiplexCodecName, cricket::kMultiplexCodecName,
{{cricket::kCodecParamAssociatedCodecName, cricket::kVp9CodecName}})); {{cricket::kCodecParamAssociatedCodecName, cricket::kVp9CodecName}}));
EXPECT_TRUE(decoder); EXPECT_TRUE(decoder);

View File

@ -529,6 +529,7 @@ rtc_library("webrtc_multiplex") {
":video_coding_utility", ":video_coding_utility",
"../../api:fec_controller_api", "../../api:fec_controller_api",
"../../api:scoped_refptr", "../../api:scoped_refptr",
"../../api/environment",
"../../api/video:encoded_image", "../../api/video:encoded_image",
"../../api/video:video_frame", "../../api/video:video_frame",
"../../api/video:video_rtp_headers", "../../api/video:video_rtp_headers",

View File

@ -15,6 +15,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "api/environment/environment.h"
#include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_decoder.h" #include "api/video_codecs/video_decoder.h"
#include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_decoder_factory.h"
@ -25,7 +26,8 @@ namespace webrtc {
class MultiplexDecoderAdapter : public VideoDecoder { class MultiplexDecoderAdapter : public VideoDecoder {
public: public:
// `factory` is not owned and expected to outlive this class. // `factory` is not owned and expected to outlive this class.
MultiplexDecoderAdapter(VideoDecoderFactory* factory, MultiplexDecoderAdapter(const Environment& env,
VideoDecoderFactory* factory,
const SdpVideoFormat& associated_format, const SdpVideoFormat& associated_format,
bool supports_augmenting_data = false); bool supports_augmenting_data = false);
virtual ~MultiplexDecoderAdapter(); virtual ~MultiplexDecoderAdapter();
@ -62,6 +64,7 @@ class MultiplexDecoderAdapter : public VideoDecoder {
std::unique_ptr<uint8_t[]> augmenting_data, std::unique_ptr<uint8_t[]> augmenting_data,
uint16_t augmenting_data_length); uint16_t augmenting_data_length);
const Environment env_;
VideoDecoderFactory* const factory_; VideoDecoderFactory* const factory_;
const SdpVideoFormat associated_format_; const SdpVideoFormat associated_format_;
std::vector<std::unique_ptr<VideoDecoder>> decoders_; std::vector<std::unique_ptr<VideoDecoder>> decoders_;

View File

@ -10,6 +10,7 @@
#include "modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h" #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/encoded_image.h"
#include "api/video/i420_buffer.h" #include "api/video/i420_buffer.h"
#include "api/video/video_frame_buffer.h" #include "api/video/video_frame_buffer.h"
@ -93,10 +94,12 @@ struct MultiplexDecoderAdapter::AugmentingData {
}; };
MultiplexDecoderAdapter::MultiplexDecoderAdapter( MultiplexDecoderAdapter::MultiplexDecoderAdapter(
const Environment& env,
VideoDecoderFactory* factory, VideoDecoderFactory* factory,
const SdpVideoFormat& associated_format, const SdpVideoFormat& associated_format,
bool supports_augmenting_data) bool supports_augmenting_data)
: factory_(factory), : env_(env),
factory_(factory),
associated_format_(associated_format), associated_format_(associated_format),
supports_augmenting_data_(supports_augmenting_data) {} supports_augmenting_data_(supports_augmenting_data) {}
@ -111,7 +114,7 @@ bool MultiplexDecoderAdapter::Configure(const Settings& settings) {
PayloadStringToCodecType(associated_format_.name)); PayloadStringToCodecType(associated_format_.name));
for (size_t i = 0; i < kAlphaCodecStreams; ++i) { for (size_t i = 0; i < kAlphaCodecStreams; ++i) {
std::unique_ptr<VideoDecoder> decoder = std::unique_ptr<VideoDecoder> decoder =
factory_->CreateVideoDecoder(associated_format_); factory_->Create(env_, associated_format_);
if (!decoder->Configure(associated_settings)) { if (!decoder->Configure(associated_settings)) {
return false; return false;
} }

View File

@ -16,6 +16,8 @@
#include <vector> #include <vector>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "api/test/mock_video_decoder_factory.h" #include "api/test/mock_video_decoder_factory.h"
#include "api/test/mock_video_encoder_factory.h" #include "api/test/mock_video_encoder_factory.h"
@ -63,7 +65,8 @@ class TestMultiplexAdapter : public VideoCodecUnitTest,
protected: protected:
std::unique_ptr<VideoDecoder> CreateDecoder() override { std::unique_ptr<VideoDecoder> CreateDecoder() override {
return std::make_unique<MultiplexDecoderAdapter>( return std::make_unique<MultiplexDecoderAdapter>(
decoder_factory_.get(), SdpVideoFormat(kMultiplexAssociatedCodecName), env_, decoder_factory_.get(),
SdpVideoFormat(kMultiplexAssociatedCodecName),
supports_augmenting_data_); supports_augmenting_data_);
} }
@ -182,9 +185,9 @@ class TestMultiplexAdapter : public VideoCodecUnitTest,
EXPECT_CALL(*decoder_factory_, Die); EXPECT_CALL(*decoder_factory_, Die);
// The decoders/encoders will be owned by the caller of // The decoders/encoders will be owned by the caller of
// CreateVideoDecoder()/CreateVideoEncoder(). // CreateVideoDecoder()/CreateVideoEncoder().
EXPECT_CALL(*decoder_factory_, CreateVideoDecoder) EXPECT_CALL(*decoder_factory_, Create).Times(2).WillRepeatedly([] {
.Times(2) return VP9Decoder::Create();
.WillRepeatedly([] { return VP9Decoder::Create(); }); });
EXPECT_CALL(*encoder_factory_, Die); EXPECT_CALL(*encoder_factory_, Die);
EXPECT_CALL(*encoder_factory_, CreateVideoEncoder) EXPECT_CALL(*encoder_factory_, CreateVideoEncoder)
@ -194,6 +197,7 @@ class TestMultiplexAdapter : public VideoCodecUnitTest,
VideoCodecUnitTest::SetUp(); VideoCodecUnitTest::SetUp();
} }
const Environment env_ = CreateEnvironment();
const std::unique_ptr<webrtc::MockVideoDecoderFactory> decoder_factory_; const std::unique_ptr<webrtc::MockVideoDecoderFactory> decoder_factory_;
const std::unique_ptr<webrtc::MockVideoEncoderFactory> encoder_factory_; const std::unique_ptr<webrtc::MockVideoEncoderFactory> encoder_factory_;
const bool supports_augmenting_data_; const bool supports_augmenting_data_;

View File

@ -196,9 +196,11 @@ TEST_F(CodecEndToEndTest, SendsAndReceivesMultiplex) {
&internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); &internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName));
}); });
test::FunctionVideoDecoderFactory decoder_factory( test::FunctionVideoDecoderFactory decoder_factory(
[&internal_decoder_factory]() { [&internal_decoder_factory](const Environment& env,
const SdpVideoFormat& /*format*/) {
return std::make_unique<MultiplexDecoderAdapter>( return std::make_unique<MultiplexDecoderAdapter>(
&internal_decoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); env, &internal_decoder_factory,
SdpVideoFormat(cricket::kVp9CodecName));
}); });
CodecObserver test(5, kVideoRotation_0, absl::nullopt, "multiplex", CodecObserver test(5, kVideoRotation_0, absl::nullopt, "multiplex",
@ -215,9 +217,11 @@ TEST_F(CodecEndToEndTest, SendsAndReceivesMultiplexVideoRotation90) {
&internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); &internal_encoder_factory, SdpVideoFormat(cricket::kVp9CodecName));
}); });
test::FunctionVideoDecoderFactory decoder_factory( test::FunctionVideoDecoderFactory decoder_factory(
[&internal_decoder_factory]() { [&internal_decoder_factory](const Environment& env,
const SdpVideoFormat& /*format*/) {
return std::make_unique<MultiplexDecoderAdapter>( return std::make_unique<MultiplexDecoderAdapter>(
&internal_decoder_factory, SdpVideoFormat(cricket::kVp9CodecName)); env, &internal_decoder_factory,
SdpVideoFormat(cricket::kVp9CodecName));
}); });
CodecObserver test(5, kVideoRotation_90, absl::nullopt, "multiplex", CodecObserver test(5, kVideoRotation_90, absl::nullopt, "multiplex",
&encoder_factory, &decoder_factory); &encoder_factory, &decoder_factory);

View File

@ -299,7 +299,7 @@ std::unique_ptr<VideoDecoder> VideoQualityTest::CreateVideoDecoder(
std::unique_ptr<VideoDecoder> decoder; std::unique_ptr<VideoDecoder> decoder;
if (format.name == "multiplex") { if (format.name == "multiplex") {
decoder = std::make_unique<MultiplexDecoderAdapter>( decoder = std::make_unique<MultiplexDecoderAdapter>(
decoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName)); env, decoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName));
} else if (format.name == "FakeCodec") { } else if (format.name == "FakeCodec") {
decoder = webrtc::FakeVideoDecoderFactory::CreateVideoDecoder(); decoder = webrtc::FakeVideoDecoderFactory::CreateVideoDecoder();
} else { } else {