fork/rust-sdks

git clone https://git.julia.blue/fork/rust-sdks

Théo Monnomfix av1 supported formats (#517)893fe0f

main
3.9 KiB120 linesraw
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__
42  factories_.push_back(livekit::CreateObjCVideoDecoderFactory());
43#endif
44
45#ifdef WEBRTC_ANDROID
46  factories_.push_back(CreateAndroidVideoDecoderFactory());
47#endif
48
49  // TODO(theomonnom): Add other HW decoders here
50}
51
52std::vector<webrtc::SdpVideoFormat> VideoDecoderFactory::GetSupportedFormats()
53    const {
54  std::vector<webrtc::SdpVideoFormat> formats;
55
56  for (const auto& factory : factories_) {
57    auto supported_formats = factory->GetSupportedFormats();
58    formats.insert(formats.end(), supported_formats.begin(),
59                   supported_formats.end());
60  }
61
62  formats.push_back(webrtc::SdpVideoFormat(cricket::kVp8CodecName));
63  for (const webrtc::SdpVideoFormat& format :
64       webrtc::SupportedVP9DecoderCodecs())
65    formats.push_back(format);
66  for (const webrtc::SdpVideoFormat& h264_format :
67       webrtc::SupportedH264DecoderCodecs())
68    formats.push_back(h264_format);
69
70  formats.push_back(webrtc::SdpVideoFormat(
71      webrtc::SdpVideoFormat::AV1Profile0(),
72      webrtc::LibaomAv1EncoderSupportedScalabilityModes()));
73  return formats;
74}
75
76VideoDecoderFactory::CodecSupport VideoDecoderFactory::QueryCodecSupport(
77    const webrtc::SdpVideoFormat& format,
78    bool reference_scaling) const {
79  if (reference_scaling) {
80    webrtc::VideoCodecType codec =
81        webrtc::PayloadStringToCodecType(format.name);
82    if (codec != webrtc::kVideoCodecVP9 && codec != webrtc::kVideoCodecAV1) {
83      return {/*is_supported=*/false, /*is_power_efficient=*/false};
84    }
85  }
86
87  CodecSupport codec_support;
88  codec_support.is_supported = format.IsCodecInList(GetSupportedFormats());
89  return codec_support;
90}
91
92std::unique_ptr<webrtc::VideoDecoder> VideoDecoderFactory::Create(
93    const webrtc::Environment& env, const webrtc::SdpVideoFormat& format) {
94  for (const auto& factory : factories_) {
95    for (const auto& supported_format : factory->GetSupportedFormats()) {
96      if (supported_format.IsSameCodec(format))
97        return factory->Create(env, format);
98    }
99  }
100
101  if (absl::EqualsIgnoreCase(format.name, cricket::kVp8CodecName))
102    return webrtc::CreateVp8Decoder(env);
103  if (absl::EqualsIgnoreCase(format.name, cricket::kVp9CodecName))
104    return webrtc::VP9Decoder::Create();
105  if (absl::EqualsIgnoreCase(format.name, cricket::kH264CodecName))
106    return webrtc::H264Decoder::Create();
107
108
109#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
110  if (absl::EqualsIgnoreCase(format.name, cricket::kAv1CodecName)) {
111    return webrtc::CreateDav1dDecoder();
112  }
113#endif
114
115
116  RTC_LOG(LS_ERROR) << "No VideoDecoder found for " << format.name;
117  return nullptr;
118}
119
120}  // namespace livekit