Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 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 TEST_FUNCTION_VIDEO_ENCODER_FACTORY_H_ |
| 12 | #define TEST_FUNCTION_VIDEO_ENCODER_FACTORY_H_ |
| 13 | |
| 14 | #include <functional> |
| 15 | #include <memory> |
| 16 | #include <utility> |
| 17 | #include <vector> |
| 18 | |
Rasmus Brandt | 0cedc05 | 2018-05-31 10:53:00 | [diff] [blame] | 19 | #include "api/video_codecs/sdp_video_format.h" |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 20 | #include "api/video_codecs/video_encoder_factory.h" |
Rasmus Brandt | 0cedc05 | 2018-05-31 10:53:00 | [diff] [blame] | 21 | #include "rtc_base/checks.h" |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 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: |
| 30 | explicit FunctionVideoEncoderFactory( |
| 31 | std::function<std::unique_ptr<VideoEncoder>()> create) |
Sebastian Jansson | e6d7c3e | 2018-07-11 13:00:41 | [diff] [blame] | 32 | : create_([create](const SdpVideoFormat&) { return create(); }) {} |
| 33 | explicit FunctionVideoEncoderFactory( |
| 34 | std::function<std::unique_ptr<VideoEncoder>(const SdpVideoFormat&)> |
| 35 | create) |
| 36 | : create_(std::move(create)) {} |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 37 | |
| 38 | // Unused by tests. |
| 39 | std::vector<SdpVideoFormat> GetSupportedFormats() const override { |
| 40 | RTC_NOTREACHED(); |
| 41 | return {}; |
| 42 | } |
| 43 | |
| 44 | CodecInfo QueryVideoEncoder( |
| 45 | const SdpVideoFormat& /* format */) const override { |
Sebastian Jansson | e6d7c3e | 2018-07-11 13:00:41 | [diff] [blame] | 46 | CodecInfo codec_info; |
| 47 | codec_info.is_hardware_accelerated = false; |
| 48 | codec_info.has_internal_source = false; |
| 49 | return codec_info; |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | std::unique_ptr<VideoEncoder> CreateVideoEncoder( |
Sebastian Jansson | e6d7c3e | 2018-07-11 13:00:41 | [diff] [blame] | 53 | const SdpVideoFormat& format) override { |
| 54 | return create_(format); |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | private: |
Sebastian Jansson | e6d7c3e | 2018-07-11 13:00:41 | [diff] [blame] | 58 | const std::function<std::unique_ptr<VideoEncoder>(const SdpVideoFormat&)> |
| 59 | create_; |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace test |
| 63 | } // namespace webrtc |
| 64 | |
| 65 | #endif // TEST_FUNCTION_VIDEO_ENCODER_FACTORY_H_ |