xref: /aosp_15_r20/external/webrtc/api/video_codecs/builtin_video_encoder_factory.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 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 "api/video_codecs/builtin_video_encoder_factory.h"
12 
13 #include <memory>
14 #include <vector>
15 
16 #include "absl/strings/match.h"
17 #include "api/video_codecs/sdp_video_format.h"
18 #include "api/video_codecs/video_encoder.h"
19 #include "media/base/codec.h"
20 #include "media/base/media_constants.h"
21 #include "media/engine/encoder_simulcast_proxy.h"
22 #include "media/engine/internal_encoder_factory.h"
23 #include "rtc_base/checks.h"
24 
25 namespace webrtc {
26 
27 namespace {
28 
29 // This class wraps the internal factory and adds simulcast.
30 class BuiltinVideoEncoderFactory : public VideoEncoderFactory {
31  public:
BuiltinVideoEncoderFactory()32   BuiltinVideoEncoderFactory()
33       : internal_encoder_factory_(new InternalEncoderFactory()) {}
34 
CreateVideoEncoder(const SdpVideoFormat & format)35   std::unique_ptr<VideoEncoder> CreateVideoEncoder(
36       const SdpVideoFormat& format) override {
37     // Try creating internal encoder.
38     std::unique_ptr<VideoEncoder> internal_encoder;
39     if (format.IsCodecInList(
40             internal_encoder_factory_->GetSupportedFormats())) {
41       internal_encoder = std::make_unique<EncoderSimulcastProxy>(
42           internal_encoder_factory_.get(), format);
43     }
44 
45     return internal_encoder;
46   }
47 
GetSupportedFormats() const48   std::vector<SdpVideoFormat> GetSupportedFormats() const override {
49     return internal_encoder_factory_->GetSupportedFormats();
50   }
51 
52  private:
53   const std::unique_ptr<VideoEncoderFactory> internal_encoder_factory_;
54 };
55 
56 }  // namespace
57 
CreateBuiltinVideoEncoderFactory()58 std::unique_ptr<VideoEncoderFactory> CreateBuiltinVideoEncoderFactory() {
59   return std::make_unique<BuiltinVideoEncoderFactory>();
60 }
61 
62 }  // namespace webrtc
63