builtin_video_encoder_factory.cc (2448B)
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 <optional> 15 #include <string> 16 #include <vector> 17 18 #include "api/environment/environment.h" 19 #include "api/video_codecs/sdp_video_format.h" 20 #include "api/video_codecs/video_encoder.h" 21 #include "api/video_codecs/video_encoder_factory.h" 22 #include "media/engine/internal_encoder_factory.h" 23 #include "media/engine/simulcast_encoder_adapter.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: 32 BuiltinVideoEncoderFactory() 33 : internal_encoder_factory_(new InternalEncoderFactory()) {} 34 35 std::unique_ptr<VideoEncoder> Create(const Environment& env, 36 const SdpVideoFormat& format) override { 37 // Try creating an InternalEncoderFactory-backed SimulcastEncoderAdapter. 38 // The adapter has a passthrough mode for the case that simulcast is not 39 // used, so all responsibility can be delegated to it. 40 if (format.IsCodecInList( 41 internal_encoder_factory_->GetSupportedFormats())) { 42 return std::make_unique<SimulcastEncoderAdapter>( 43 env, 44 /*primary_factory=*/internal_encoder_factory_.get(), 45 /*fallback_factory=*/nullptr, format); 46 } 47 48 return nullptr; 49 } 50 51 std::vector<SdpVideoFormat> GetSupportedFormats() const override { 52 return internal_encoder_factory_->GetSupportedFormats(); 53 } 54 55 CodecSupport QueryCodecSupport( 56 const SdpVideoFormat& format, 57 std::optional<std::string> scalability_mode) const override { 58 return internal_encoder_factory_->QueryCodecSupport(format, 59 scalability_mode); 60 } 61 62 private: 63 const std::unique_ptr<VideoEncoderFactory> internal_encoder_factory_; 64 }; 65 66 } // namespace 67 68 std::unique_ptr<VideoEncoderFactory> CreateBuiltinVideoEncoderFactory() { 69 return std::make_unique<BuiltinVideoEncoderFactory>(); 70 } 71 72 } // namespace webrtc