xref: /aosp_15_r20/external/webrtc/media/engine/internal_encoder_factory.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_encoder_factory.h"
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "absl/strings/match.h"
18 #include "api/video_codecs/video_encoder_factory.h"
19 #include "api/video_codecs/video_encoder_factory_template.h"
20 #if defined(RTC_USE_LIBAOM_AV1_ENCODER)
21 #include "api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h"  // nogncheck
22 #endif
23 #include "api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h"
24 #include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
25 #if defined(WEBRTC_USE_H264)
26 #include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"  // nogncheck
27 #endif
28 
29 namespace webrtc {
30 namespace {
31 
32 using Factory =
33     VideoEncoderFactoryTemplate<webrtc::LibvpxVp8EncoderTemplateAdapter,
34 #if defined(WEBRTC_USE_H264)
35                                 webrtc::OpenH264EncoderTemplateAdapter,
36 #endif
37 #if defined(RTC_USE_LIBAOM_AV1_ENCODER)
38                                 webrtc::LibaomAv1EncoderTemplateAdapter,
39 #endif
40                                 webrtc::LibvpxVp9EncoderTemplateAdapter>;
41 }  // namespace
42 
GetSupportedFormats() const43 std::vector<SdpVideoFormat> InternalEncoderFactory::GetSupportedFormats()
44     const {
45   return Factory().GetSupportedFormats();
46 }
47 
CreateVideoEncoder(const SdpVideoFormat & format)48 std::unique_ptr<VideoEncoder> InternalEncoderFactory::CreateVideoEncoder(
49     const SdpVideoFormat& format) {
50   auto original_format =
51       FuzzyMatchSdpVideoFormat(Factory().GetSupportedFormats(), format);
52   return original_format ? Factory().CreateVideoEncoder(*original_format)
53                          : nullptr;
54 }
55 
QueryCodecSupport(const SdpVideoFormat & format,absl::optional<std::string> scalability_mode) const56 VideoEncoderFactory::CodecSupport InternalEncoderFactory::QueryCodecSupport(
57     const SdpVideoFormat& format,
58     absl::optional<std::string> scalability_mode) const {
59   auto original_format =
60       FuzzyMatchSdpVideoFormat(Factory().GetSupportedFormats(), format);
61   return original_format
62              ? Factory().QueryCodecSupport(*original_format, scalability_mode)
63              : VideoEncoderFactory::CodecSupport{.is_supported = false};
64 }
65 
66 }  // namespace webrtc
67