fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
893fe0f
livekit/livekit-ffi@0.13.0
1/* 2* Copyright 2023 LiveKit 3* 4* Licensed under the Apache License, Version 2.0 (the “License”); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an “AS IS” BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15*/ 16 17#include "livekit/video_decoder_factory.h" 18 19#include <modules/video_coding/codecs/av1/av1_svc_config.h> 20#include "api/environment/environment.h" 21#include "api/video_codecs/av1_profile.h" 22#include "api/video_codecs/sdp_video_format.h" 23#include "livekit/objc_video_factory.h" 24#include "media/base/media_constants.h" 25#include "modules/video_coding/codecs/h264/include/h264.h" 26#include "modules/video_coding/codecs/vp8/include/vp8.h" 27#include "modules/video_coding/codecs/vp9/include/vp9.h" 28#include "rtc_base/logging.h" 29 30#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY ) 31#include "modules/video_coding/codecs/av1/dav1d_decoder.h" // nogncheck 32#endif 33 34#ifdef WEBRTC_ANDROID 35#include "livekit/android.h" 36#endif 37 38namespace livekit { 39 40VideoDecoderFactory ::VideoDecoderFactory () { 41#ifdef __APPLE__ 42factories_ .push_back (livekit::CreateObjCVideoDecoderFactory ()); 43#endif 44 45#ifdef WEBRTC_ANDROID 46factories_ .push_back (CreateAndroidVideoDecoderFactory ()); 47#endif 48 49// TODO(theomonnom): Add other HW decoders here 50} 51 52std::vector < webrtc::SdpVideoFormat > VideoDecoderFactory ::GetSupportedFormats () 53const { 54 std::vector < webrtc::SdpVideoFormat > formats ; 55 56for (const auto & factory :factories_ ) { 57auto supported_formats = factory -> GetSupportedFormats (); 58formats .insert (formats .end (),supported_formats .begin (), 59supported_formats .end ()); 60 } 61 62formats .push_back (webrtc::SdpVideoFormat (cricket::kVp8CodecName )); 63for (const webrtc::SdpVideoFormat & format : 64 webrtc::SupportedVP9DecoderCodecs ()) 65formats .push_back (format ); 66for (const webrtc::SdpVideoFormat & h264_format : 67 webrtc::SupportedH264DecoderCodecs ()) 68formats .push_back (h264_format ); 69 70formats .push_back (webrtc::SdpVideoFormat ( 71 webrtc::SdpVideoFormat ::AV1Profile0 (), 72 webrtc::LibaomAv1EncoderSupportedScalabilityModes ())); 73return formats ; 74} 75 76VideoDecoderFactory ::CodecSupport VideoDecoderFactory ::QueryCodecSupport ( 77const webrtc::SdpVideoFormat & format , 78bool reference_scaling )const { 79if (reference_scaling ) { 80 webrtc::VideoCodecType codec = 81 webrtc::PayloadStringToCodecType (format .name ); 82if (codec != webrtc::kVideoCodecVP9 && codec != webrtc::kVideoCodecAV1 ) { 83return {/*is_supported=*/ false,/*is_power_efficient=*/ false}; 84 } 85 } 86 87CodecSupport codec_support ; 88codec_support .is_supported = format .IsCodecInList (GetSupportedFormats ()); 89return codec_support ; 90} 91 92std::unique_ptr < webrtc::VideoDecoder > VideoDecoderFactory ::Create ( 93const webrtc::Environment & env ,const webrtc::SdpVideoFormat & format ) { 94for (const auto & factory :factories_ ) { 95for (const auto & supported_format :factory -> GetSupportedFormats ()) { 96if (supported_format .IsSameCodec (format )) 97return factory -> Create (env ,format ); 98 } 99 } 100 101if (absl::EqualsIgnoreCase (format .name , cricket::kVp8CodecName )) 102return webrtc::CreateVp8Decoder (env ); 103if (absl::EqualsIgnoreCase (format .name , cricket::kVp9CodecName )) 104return webrtc::VP9Decoder ::Create (); 105if (absl::EqualsIgnoreCase (format .name , cricket::kH264CodecName )) 106return webrtc::H264Decoder ::Create (); 107 108 109#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY ) 110if (absl::EqualsIgnoreCase (format .name , cricket::kAv1CodecName )) { 111return webrtc::CreateDav1dDecoder (); 112 } 113#endif 114 115 116RTC_LOG (LS_ERROR ) <<"No VideoDecoder found for " <<format .name ; 117return nullptr ; 118} 119 120}// namespace livekit