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 | |
| 17 | #include "absl/memory/memory.h" |
| 18 | #include "api/video_codecs/video_decoder.h" |
| 19 | #include "api/video_codecs/video_decoder_factory.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | namespace test { |
| 23 | |
| 24 | // An decoder factory with a single underlying VideoDecoder object, intended for |
| 25 | // test purposes. Each call to CreateVideoDecoder returns a proxy for the same |
| 26 | // decoder, typically an instance of FakeDecoder or MockEncoder. |
| 27 | class VideoDecoderProxyFactory final : public VideoDecoderFactory { |
| 28 | public: |
| 29 | explicit VideoDecoderProxyFactory(VideoDecoder* decoder) |
| 30 | : decoder_(decoder) {} |
| 31 | |
| 32 | // Unused by tests. |
| 33 | std::vector<SdpVideoFormat> GetSupportedFormats() const override { |
| 34 | RTC_NOTREACHED(); |
| 35 | return {}; |
| 36 | } |
| 37 | |
| 38 | std::unique_ptr<VideoDecoder> CreateVideoDecoder( |
| 39 | const SdpVideoFormat& format) override { |
| 40 | return absl::make_unique<DecoderProxy>(decoder_); |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | // Wrapper class, since CreateVideoDecoder needs to surrender |
| 45 | // ownership to the object it returns. |
| 46 | class DecoderProxy final : public VideoDecoder { |
| 47 | public: |
| 48 | explicit DecoderProxy(VideoDecoder* decoder) : decoder_(decoder) {} |
| 49 | |
| 50 | private: |
| 51 | int32_t Decode(const EncodedImage& input_image, |
| 52 | bool missing_frames, |
| 53 | const CodecSpecificInfo* codec_specific_info, |
| 54 | int64_t render_time_ms) override { |
| 55 | return decoder_->Decode(input_image, missing_frames, codec_specific_info, |
| 56 | render_time_ms); |
| 57 | } |
| 58 | int32_t InitDecode(const VideoCodec* config, |
| 59 | int32_t number_of_cores) override { |
| 60 | return decoder_->InitDecode(config, number_of_cores); |
| 61 | } |
| 62 | int32_t RegisterDecodeCompleteCallback( |
| 63 | DecodedImageCallback* callback) override { |
| 64 | return decoder_->RegisterDecodeCompleteCallback(callback); |
| 65 | } |
| 66 | int32_t Release() override { return decoder_->Release(); } |
| 67 | bool PrefersLateDecoding() const { return decoder_->PrefersLateDecoding(); } |
| 68 | const char* ImplementationName() const override { |
| 69 | return decoder_->ImplementationName(); |
| 70 | } |
| 71 | |
| 72 | VideoDecoder* const decoder_; |
| 73 | }; |
| 74 | |
| 75 | VideoDecoder* const decoder_; |
| 76 | }; |
| 77 | |
| 78 | } // namespace test |
| 79 | } // namespace webrtc |
| 80 | |
| 81 | #endif // TEST_VIDEO_DECODER_PROXY_FACTORY_H_ |