blob: 567397f6c0c697994c60b5149b1d6dc37aa40d04 [file] [log] [blame]
Niels Möller4db138e2018-04-19 07:04:131/*
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 Brandt0cedc052018-05-31 10:53:0019#include "api/video_codecs/sdp_video_format.h"
Niels Möller4db138e2018-04-19 07:04:1320#include "api/video_codecs/video_encoder_factory.h"
Rasmus Brandt0cedc052018-05-31 10:53:0021#include "rtc_base/checks.h"
Niels Möller4db138e2018-04-19 07:04:1322
23namespace webrtc {
24namespace test {
25
26// An encoder factory producing encoders by calling a supplied create
27// function.
28class FunctionVideoEncoderFactory final : public VideoEncoderFactory {
29 public:
30 explicit FunctionVideoEncoderFactory(
31 std::function<std::unique_ptr<VideoEncoder>()> create)
Sebastian Janssone6d7c3e2018-07-11 13:00:4132 : 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öller4db138e2018-04-19 07:04:1337
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 Janssone6d7c3e2018-07-11 13:00:4146 CodecInfo codec_info;
47 codec_info.is_hardware_accelerated = false;
48 codec_info.has_internal_source = false;
49 return codec_info;
Niels Möller4db138e2018-04-19 07:04:1350 }
51
52 std::unique_ptr<VideoEncoder> CreateVideoEncoder(
Sebastian Janssone6d7c3e2018-07-11 13:00:4153 const SdpVideoFormat& format) override {
54 return create_(format);
Niels Möller4db138e2018-04-19 07:04:1355 }
56
57 private:
Sebastian Janssone6d7c3e2018-07-11 13:00:4158 const std::function<std::unique_ptr<VideoEncoder>(const SdpVideoFormat&)>
59 create_;
Niels Möller4db138e2018-04-19 07:04:1360};
61
62} // namespace test
63} // namespace webrtc
64
65#endif // TEST_FUNCTION_VIDEO_ENCODER_FACTORY_H_