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 #ifndef API_TEST_VIDEO_FUNCTION_VIDEO_ENCODER_FACTORY_H_ 12 #define API_TEST_VIDEO_FUNCTION_VIDEO_ENCODER_FACTORY_H_ 13 14 #include <functional> 15 #include <memory> 16 #include <utility> 17 #include <vector> 18 19 #include "api/video_codecs/sdp_video_format.h" 20 #include "api/video_codecs/video_encoder_factory.h" 21 #include "rtc_base/checks.h" 22 23 namespace webrtc { 24 namespace test { 25 26 // An encoder factory producing encoders by calling a supplied create 27 // function. 28 class FunctionVideoEncoderFactory final : public VideoEncoderFactory { 29 public: FunctionVideoEncoderFactory(std::function<std::unique_ptr<VideoEncoder> ()> create)30 explicit FunctionVideoEncoderFactory( 31 std::function<std::unique_ptr<VideoEncoder>()> create) 32 : create_([create = std::move(create)](const SdpVideoFormat&) { 33 return create(); 34 }) {} FunctionVideoEncoderFactory(std::function<std::unique_ptr<VideoEncoder> (const SdpVideoFormat &)> create)35 explicit FunctionVideoEncoderFactory( 36 std::function<std::unique_ptr<VideoEncoder>(const SdpVideoFormat&)> 37 create) 38 : create_(std::move(create)) {} 39 40 // Unused by tests. GetSupportedFormats()41 std::vector<SdpVideoFormat> GetSupportedFormats() const override { 42 RTC_NOTREACHED(); 43 return {}; 44 } 45 QueryVideoEncoder(const SdpVideoFormat &)46 CodecInfo QueryVideoEncoder( 47 const SdpVideoFormat& /* format */) const override { 48 CodecInfo codec_info; 49 codec_info.is_hardware_accelerated = false; 50 codec_info.has_internal_source = false; 51 return codec_info; 52 } 53 CreateVideoEncoder(const SdpVideoFormat & format)54 std::unique_ptr<VideoEncoder> CreateVideoEncoder( 55 const SdpVideoFormat& format) override { 56 return create_(format); 57 } 58 59 private: 60 const std::function<std::unique_ptr<VideoEncoder>(const SdpVideoFormat&)> 61 create_; 62 }; 63 64 } // namespace test 65 } // namespace webrtc 66 67 #endif // API_TEST_VIDEO_FUNCTION_VIDEO_ENCODER_FACTORY_H_ 68