From c29e1f54158539a8fd733c21cb9cf7885cbda24c Mon Sep 17 00:00:00 2001 From: Johannes Kron Date: Mon, 26 Apr 2021 22:18:57 +0200 Subject: [PATCH] Add QueryCodecSupport() to VideoEncoderFactory and VideoDecoderFactory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QueryCodecSupport() is needed in the coming work with extending the MediaCapabilities API to WebRTC. In the API, a user can query whether a specified media configuration is supported, power efficient, and smooth. QueryCodecSupport() will be used to determine if the configuration is supported and power efficient. Bug: chromium:1187565 Change-Id: Ib1d93433a180b433f0bf60d6e871d03cebc4c0a6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215922 Commit-Queue: Johannes Kron Reviewed-by: Erik Språng Cr-Commit-Position: refs/heads/master@{#33843} --- api/video_codecs/video_decoder_factory.h | 28 +++++++++++++++++++++++- api/video_codecs/video_encoder_factory.h | 26 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/api/video_codecs/video_decoder_factory.h b/api/video_codecs/video_decoder_factory.h index e4d83c2465..40a2c82faf 100644 --- a/api/video_codecs/video_decoder_factory.h +++ b/api/video_codecs/video_decoder_factory.h @@ -15,21 +15,47 @@ #include #include +#include "absl/types/optional.h" +#include "api/video_codecs/sdp_video_format.h" #include "rtc_base/system/rtc_export.h" namespace webrtc { class VideoDecoder; -struct SdpVideoFormat; // A factory that creates VideoDecoders. // NOTE: This class is still under development and may change without notice. class RTC_EXPORT VideoDecoderFactory { public: + struct CodecSupport { + bool is_supported = false; + bool is_power_efficient = false; + }; + // Returns a list of supported video formats in order of preference, to use // for signaling etc. virtual std::vector GetSupportedFormats() const = 0; + // Query whether the specifed format is supported or not and if it will be + // power efficient, which is currently interpreted as if there is support for + // hardware acceleration. + // See https://w3c.github.io/webrtc-svc/#scalabilitymodes* for a specification + // of valid values for |scalability_mode|. + // NOTE: QueryCodecSupport is currently an experimental feature that is + // subject to change without notice. + virtual CodecSupport QueryCodecSupport( + const SdpVideoFormat& format, + absl::optional scalability_mode) const { + // Default implementation, query for supported formats and check if the + // specified format is supported. Returns false if scalability_mode is + // specified. + CodecSupport codec_support; + if (!scalability_mode) { + codec_support.is_supported = format.IsCodecInList(GetSupportedFormats()); + } + return codec_support; + } + // Creates a VideoDecoder for the specified format. virtual std::unique_ptr CreateVideoDecoder( const SdpVideoFormat& format) = 0; diff --git a/api/video_codecs/video_encoder_factory.h b/api/video_codecs/video_encoder_factory.h index 22430eb19d..c2d66cfa86 100644 --- a/api/video_codecs/video_encoder_factory.h +++ b/api/video_codecs/video_encoder_factory.h @@ -12,6 +12,7 @@ #define API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_ #include +#include #include #include "absl/types/optional.h" @@ -36,6 +37,11 @@ class VideoEncoderFactory { bool has_internal_source = false; }; + struct CodecSupport { + bool is_supported = false; + bool is_power_efficient = false; + }; + // An injectable class that is continuously updated with encoding conditions // and selects the best encoder given those conditions. class EncoderSelectorInterface { @@ -78,6 +84,26 @@ class VideoEncoderFactory { return CodecInfo(); } + // Query whether the specifed format is supported or not and if it will be + // power efficient, which is currently interpreted as if there is support for + // hardware acceleration. + // See https://w3c.github.io/webrtc-svc/#scalabilitymodes* for a specification + // of valid values for |scalability_mode|. + // NOTE: QueryCodecSupport is currently an experimental feature that is + // subject to change without notice. + virtual CodecSupport QueryCodecSupport( + const SdpVideoFormat& format, + absl::optional scalability_mode) const { + // Default implementation, query for supported formats and check if the + // specified format is supported. Returns false if scalability_mode is + // specified. + CodecSupport codec_support; + if (!scalability_mode) { + codec_support.is_supported = format.IsCodecInList(GetSupportedFormats()); + } + return codec_support; + } + // Creates a VideoEncoder for the specified format. virtual std::unique_ptr CreateVideoEncoder( const SdpVideoFormat& format) = 0;