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",
":rtc_media_base",
":rtc_simulcast_encoder_adapter",
"../api/environment",
"../api/video:encoded_image",
"../api/video:video_bitrate_allocation",
"../api/video:video_frame",

View File

@ -11,10 +11,12 @@
#include "media/engine/multiplex_codec_factory.h"
#include <map>
#include <memory>
#include <string>
#include <utility>
#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<SdpVideoFormat> MultiplexDecoderFactory::GetSupportedFormats()
return augmented_formats;
}
std::unique_ptr<VideoDecoder> MultiplexDecoderFactory::CreateVideoDecoder(
std::unique_ptr<VideoDecoder> 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<VideoDecoder>(new MultiplexDecoderAdapter(
factory_.get(), associated_format, supports_augmenting_data_));
return std::make_unique<MultiplexDecoderAdapter>(
env, factory_.get(), associated_format, supports_augmenting_data_);
}
} // namespace webrtc

View File

@ -14,6 +14,7 @@
#include <memory>
#include <vector>
#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,7 +67,7 @@ class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory {
bool supports_augmenting_data = false);
std::vector<SdpVideoFormat> GetSupportedFormats() const override;
std::unique_ptr<VideoDecoder> CreateVideoDecoder(
std::unique_ptr<VideoDecoder> Create(const Environment& env,
const SdpVideoFormat& format) override;
private:

View File

@ -10,8 +10,10 @@
#include "media/engine/multiplex_codec_factory.h"
#include <memory>
#include <utility>
#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<VideoDecoderFactory> internal_factory(
new InternalDecoderFactory());
TEST(MultiplexDecoderFactoryTest, CreateVideoDecoder) {
std::unique_ptr<VideoDecoderFactory> internal_factory =
std::make_unique<InternalDecoderFactory>();
MultiplexDecoderFactory factory(std::move(internal_factory));
std::unique_ptr<VideoDecoder> decoder =
factory.CreateVideoDecoder(SdpVideoFormat(
std::unique_ptr<VideoDecoder> decoder = factory.Create(
CreateEnvironment(),
SdpVideoFormat(
cricket::kMultiplexCodecName,
{{cricket::kCodecParamAssociatedCodecName, cricket::kVp9CodecName}}));
EXPECT_TRUE(decoder);

View File

@ -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",

View File

@ -15,6 +15,7 @@
#include <memory>
#include <vector>
#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<uint8_t[]> augmenting_data,
uint16_t augmenting_data_length);
const Environment env_;
VideoDecoderFactory* const factory_;
const SdpVideoFormat associated_format_;
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 "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<VideoDecoder> decoder =
factory_->CreateVideoDecoder(associated_format_);
factory_->Create(env_, associated_format_);
if (!decoder->Configure(associated_settings)) {
return false;
}

View File

@ -16,6 +16,8 @@
#include <vector>
#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<VideoDecoder> CreateDecoder() override {
return std::make_unique<MultiplexDecoderAdapter>(
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<webrtc::MockVideoDecoderFactory> decoder_factory_;
const std::unique_ptr<webrtc::MockVideoEncoderFactory> encoder_factory_;
const bool supports_augmenting_data_;

View File

@ -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<MultiplexDecoderAdapter>(
&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<MultiplexDecoderAdapter>(
&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);

View File

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