Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [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_VIDEO_DECODER_PROXY_FACTORY_H_ |
| 12 | #define TEST_VIDEO_DECODER_PROXY_FACTORY_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 17 | #include "api/video_codecs/video_decoder.h" |
| 18 | #include "api/video_codecs/video_decoder_factory.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
Hua, Chunbo | b261118 | 2020-04-27 03:55:56 | [diff] [blame] | 23 | // A decoder factory with a single underlying VideoDecoder object, intended for |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 24 | // test purposes. Each call to CreateVideoDecoder returns a proxy for the same |
| 25 | // decoder, typically an instance of FakeDecoder or MockEncoder. |
| 26 | class VideoDecoderProxyFactory final : public VideoDecoderFactory { |
| 27 | public: |
| 28 | explicit VideoDecoderProxyFactory(VideoDecoder* decoder) |
| 29 | : decoder_(decoder) {} |
| 30 | |
| 31 | // Unused by tests. |
| 32 | std::vector<SdpVideoFormat> GetSupportedFormats() const override { |
| 33 | RTC_NOTREACHED(); |
| 34 | return {}; |
| 35 | } |
| 36 | |
| 37 | std::unique_ptr<VideoDecoder> CreateVideoDecoder( |
| 38 | const SdpVideoFormat& format) override { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 39 | return std::make_unique<DecoderProxy>(decoder_); |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | private: |
| 43 | // Wrapper class, since CreateVideoDecoder needs to surrender |
| 44 | // ownership to the object it returns. |
| 45 | class DecoderProxy final : public VideoDecoder { |
| 46 | public: |
| 47 | explicit DecoderProxy(VideoDecoder* decoder) : decoder_(decoder) {} |
| 48 | |
| 49 | private: |
| 50 | int32_t Decode(const EncodedImage& input_image, |
| 51 | bool missing_frames, |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 52 | int64_t render_time_ms) override { |
Niels Möller | 7aacdd9 | 2019-03-25 08:11:40 | [diff] [blame] | 53 | return decoder_->Decode(input_image, missing_frames, render_time_ms); |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 54 | } |
Danil Chapovalov | d08930d | 2021-08-12 11:26:55 | [diff] [blame] | 55 | bool Configure(const Settings& settings) override { |
| 56 | return decoder_->Configure(settings); |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 57 | } |
| 58 | int32_t RegisterDecodeCompleteCallback( |
| 59 | DecodedImageCallback* callback) override { |
| 60 | return decoder_->RegisterDecodeCompleteCallback(callback); |
| 61 | } |
| 62 | int32_t Release() override { return decoder_->Release(); } |
Erik Språng | c12f625 | 2021-01-13 20:49:59 | [diff] [blame] | 63 | DecoderInfo GetDecoderInfo() const override { |
| 64 | return decoder_->GetDecoderInfo(); |
| 65 | } |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 66 | const char* ImplementationName() const override { |
| 67 | return decoder_->ImplementationName(); |
| 68 | } |
| 69 | |
| 70 | VideoDecoder* const decoder_; |
| 71 | }; |
| 72 | |
| 73 | VideoDecoder* const decoder_; |
| 74 | }; |
| 75 | |
| 76 | } // namespace test |
| 77 | } // namespace webrtc |
| 78 | |
| 79 | #endif // TEST_VIDEO_DECODER_PROXY_FACTORY_H_ |