1 /* 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "media/engine/internal_decoder_factory.h" 12 13 #include "absl/strings/match.h" 14 #include "api/video_codecs/av1_profile.h" 15 #include "api/video_codecs/sdp_video_format.h" 16 #include "api/video_codecs/video_codec.h" 17 #include "media/base/codec.h" 18 #include "media/base/media_constants.h" 19 #include "modules/video_coding/codecs/h264/include/h264.h" 20 #include "modules/video_coding/codecs/vp8/include/vp8.h" 21 #include "modules/video_coding/codecs/vp9/include/vp9.h" 22 #include "rtc_base/checks.h" 23 #include "rtc_base/logging.h" 24 #include "system_wrappers/include/field_trial.h" 25 26 #if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY) 27 #include "modules/video_coding/codecs/av1/dav1d_decoder.h" // nogncheck 28 #endif 29 30 namespace webrtc { 31 namespace { 32 constexpr char kDav1dFieldTrial[] = "WebRTC-Dav1dDecoder"; 33 #if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY) 34 constexpr bool kDav1dIsIncluded = true; 35 #else 36 constexpr bool kDav1dIsIncluded = false; CreateDav1dDecoder()37std::unique_ptr<VideoDecoder> CreateDav1dDecoder() { 38 return nullptr; 39 } 40 #endif 41 42 } // namespace 43 GetSupportedFormats() const44std::vector<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats() 45 const { 46 std::vector<SdpVideoFormat> formats; 47 formats.push_back(SdpVideoFormat(cricket::kVp8CodecName)); 48 for (const SdpVideoFormat& format : SupportedVP9DecoderCodecs()) 49 formats.push_back(format); 50 for (const SdpVideoFormat& h264_format : SupportedH264DecoderCodecs()) 51 formats.push_back(h264_format); 52 53 if (kDav1dIsIncluded && !field_trial::IsDisabled(kDav1dFieldTrial)) { 54 formats.push_back(SdpVideoFormat(cricket::kAv1CodecName)); 55 formats.push_back(SdpVideoFormat( 56 cricket::kAv1CodecName, 57 {{kAV1FmtpProfile, AV1ProfileToString(AV1Profile::kProfile1).data()}})); 58 } 59 60 return formats; 61 } 62 QueryCodecSupport(const SdpVideoFormat & format,bool reference_scaling) const63VideoDecoderFactory::CodecSupport InternalDecoderFactory::QueryCodecSupport( 64 const SdpVideoFormat& format, 65 bool reference_scaling) const { 66 // Query for supported formats and check if the specified format is supported. 67 // Return unsupported if an invalid combination of format and 68 // reference_scaling is specified. 69 if (reference_scaling) { 70 VideoCodecType codec = PayloadStringToCodecType(format.name); 71 if (codec != kVideoCodecVP9 && codec != kVideoCodecAV1) { 72 return {/*is_supported=*/false, /*is_power_efficient=*/false}; 73 } 74 } 75 76 CodecSupport codec_support; 77 codec_support.is_supported = format.IsCodecInList(GetSupportedFormats()); 78 return codec_support; 79 } 80 CreateVideoDecoder(const SdpVideoFormat & format)81std::unique_ptr<VideoDecoder> InternalDecoderFactory::CreateVideoDecoder( 82 const SdpVideoFormat& format) { 83 if (!format.IsCodecInList(GetSupportedFormats())) { 84 RTC_LOG(LS_WARNING) << "Trying to create decoder for unsupported format. " 85 << format.ToString(); 86 return nullptr; 87 } 88 89 if (absl::EqualsIgnoreCase(format.name, cricket::kVp8CodecName)) 90 return VP8Decoder::Create(); 91 if (absl::EqualsIgnoreCase(format.name, cricket::kVp9CodecName)) 92 return VP9Decoder::Create(); 93 if (absl::EqualsIgnoreCase(format.name, cricket::kH264CodecName)) 94 return H264Decoder::Create(); 95 96 if (absl::EqualsIgnoreCase(format.name, cricket::kAv1CodecName) && 97 kDav1dIsIncluded && !field_trial::IsDisabled(kDav1dFieldTrial)) { 98 return CreateDav1dDecoder(); 99 } 100 101 RTC_DCHECK_NOTREACHED(); 102 return nullptr; 103 } 104 105 } // namespace webrtc 106