From c708c00f95e8d95b34045ee71559599d43e9a844 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Mon, 22 Jan 2024 13:17:05 +0100 Subject: [PATCH] Add VideoDecoderFactory function to pass Environment for VideoDecoder construction Bug: webrtc:15791 Change-Id: I3fa962ae13d8b36092a5b910f1ce6e946689daea Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/335680 Reviewed-by: Philip Eliasson Reviewed-by: Mirko Bonadei Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#41600} --- api/BUILD.gn | 1 + api/test/mock_video_decoder_factory.h | 13 +++++-- api/video_codecs/BUILD.gn | 2 + api/video_codecs/video_decoder_factory.cc | 45 +++++++++++++++++++++++ api/video_codecs/video_decoder_factory.h | 31 +++++++--------- 5 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 api/video_codecs/video_decoder_factory.cc diff --git a/api/BUILD.gn b/api/BUILD.gn index 6af4fa5517..95850c6e17 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -1345,6 +1345,7 @@ if (rtc_include_tests) { deps = [ "../api/video_codecs:video_codecs_api", "../test:test_support", + "environment", ] } diff --git a/api/test/mock_video_decoder_factory.h b/api/test/mock_video_decoder_factory.h index 6150d9f8b5..48d96ea58b 100644 --- a/api/test/mock_video_decoder_factory.h +++ b/api/test/mock_video_decoder_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" @@ -21,17 +22,21 @@ namespace webrtc { -class MockVideoDecoderFactory : public webrtc::VideoDecoderFactory { +class MockVideoDecoderFactory : public VideoDecoderFactory { public: ~MockVideoDecoderFactory() override { Die(); } - MOCK_METHOD(std::vector, + MOCK_METHOD(std::vector, GetSupportedFormats, (), (const, override)); - MOCK_METHOD(std::unique_ptr, + MOCK_METHOD(std::unique_ptr, + Create, + (const Environment&, const SdpVideoFormat&), + (override)); + MOCK_METHOD(std::unique_ptr, CreateVideoDecoder, - (const webrtc::SdpVideoFormat&), + (const SdpVideoFormat&), (override)); MOCK_METHOD(void, Die, ()); }; diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn index 3865f4fee7..aaa2a5750a 100644 --- a/api/video_codecs/BUILD.gn +++ b/api/video_codecs/BUILD.gn @@ -58,6 +58,7 @@ rtc_library("video_codecs_api") { "video_codec.h", "video_decoder.cc", "video_decoder.h", + "video_decoder_factory.cc", "video_decoder_factory.h", "video_encoder.cc", "video_encoder.h", @@ -91,6 +92,7 @@ rtc_library("video_codecs_api") { "../../rtc_base:refcount", "../../rtc_base:stringutils", "../../rtc_base/system:rtc_export", + "../environment", "../units:data_rate", "../video:encoded_image", "../video:render_resolution", diff --git a/api/video_codecs/video_decoder_factory.cc b/api/video_codecs/video_decoder_factory.cc new file mode 100644 index 0000000000..60fe92bf38 --- /dev/null +++ b/api/video_codecs/video_decoder_factory.cc @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "api/video_codecs/video_decoder_factory.h" + +#include + +#include "api/video_codecs/sdp_video_format.h" +#include "api/video_codecs/video_decoder.h" +#include "rtc_base/checks.h" + +namespace webrtc { + +VideoDecoderFactory::CodecSupport VideoDecoderFactory::QueryCodecSupport( + const SdpVideoFormat& format, + bool reference_scaling) const { + // Default implementation, query for supported formats and check if the + // specified format is supported. Returns false if `reference_scaling` is + // true. + return {.is_supported = !reference_scaling && + format.IsCodecInList(GetSupportedFormats())}; +} + +std::unique_ptr VideoDecoderFactory::Create( + const Environment& env, + const SdpVideoFormat& format) { + return CreateVideoDecoder(format); +} + +std::unique_ptr VideoDecoderFactory::CreateVideoDecoder( + const SdpVideoFormat& format) { + // Newer code shouldn't call this function, + // Older code should implement it in derived classes. + RTC_CHECK_NOTREACHED(); + return nullptr; +} + +} // namespace webrtc diff --git a/api/video_codecs/video_decoder_factory.h b/api/video_codecs/video_decoder_factory.h index 7e1d2ee883..6048cb27fb 100644 --- a/api/video_codecs/video_decoder_factory.h +++ b/api/video_codecs/video_decoder_factory.h @@ -12,17 +12,15 @@ #define API_VIDEO_CODECS_VIDEO_DECODER_FACTORY_H_ #include -#include #include -#include "absl/types/optional.h" +#include "api/environment/environment.h" #include "api/video_codecs/sdp_video_format.h" +#include "api/video_codecs/video_decoder.h" #include "rtc_base/system/rtc_export.h" namespace webrtc { -class VideoDecoder; - // A factory that creates VideoDecoders. // NOTE: This class is still under development and may change without notice. class RTC_EXPORT VideoDecoderFactory { @@ -32,6 +30,8 @@ class RTC_EXPORT VideoDecoderFactory { bool is_power_efficient = false; }; + virtual ~VideoDecoderFactory() = default; + // Returns a list of supported video formats in order of preference, to use // for signaling etc. virtual std::vector GetSupportedFormats() const = 0; @@ -47,21 +47,18 @@ class RTC_EXPORT VideoDecoderFactory { // different scalabilty modes. NOTE: QueryCodecSupport is currently an // experimental feature that is subject to change without notice. virtual CodecSupport QueryCodecSupport(const SdpVideoFormat& format, - bool reference_scaling) const { - // Default implementation, query for supported formats and check if the - // specified format is supported. Returns false if `reference_scaling` is - // true. - CodecSupport codec_support; - codec_support.is_supported = - !reference_scaling && format.IsCodecInList(GetSupportedFormats()); - return codec_support; - } + bool reference_scaling) const; - // Creates a VideoDecoder for the specified format. + // Creates a VideoDecoder for the specified `format`. + // TODO: bugs.webrtc.org/15791 - Make pure virtual when implemented in all + // derived classes. + virtual std::unique_ptr Create(const Environment& env, + const SdpVideoFormat& format); + + // TODO: bugs.webrtc.org/15791 - Make private or delete when all callers are + // migrated to `Create`. virtual std::unique_ptr CreateVideoDecoder( - const SdpVideoFormat& format) = 0; - - virtual ~VideoDecoderFactory() {} + const SdpVideoFormat& format); }; } // namespace webrtc