video_decoder_proxy_factory.h 2.5 KB

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