fake_webrtc_video_engine.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2010 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 MEDIA_ENGINE_FAKE_WEBRTC_VIDEO_ENGINE_H_
  11. #define MEDIA_ENGINE_FAKE_WEBRTC_VIDEO_ENGINE_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <memory>
  15. #include <string>
  16. #include <vector>
  17. #include "api/fec_controller_override.h"
  18. #include "api/video/encoded_image.h"
  19. #include "api/video/video_bitrate_allocation.h"
  20. #include "api/video/video_frame.h"
  21. #include "api/video_codecs/sdp_video_format.h"
  22. #include "api/video_codecs/video_codec.h"
  23. #include "api/video_codecs/video_decoder.h"
  24. #include "api/video_codecs/video_decoder_factory.h"
  25. #include "api/video_codecs/video_encoder.h"
  26. #include "api/video_codecs/video_encoder_factory.h"
  27. #include "modules/video_coding/include/video_codec_interface.h"
  28. #include "rtc_base/event.h"
  29. #include "rtc_base/synchronization/mutex.h"
  30. #include "rtc_base/thread_annotations.h"
  31. namespace cricket {
  32. class FakeWebRtcVideoDecoderFactory;
  33. class FakeWebRtcVideoEncoderFactory;
  34. // Fake class for mocking out webrtc::VideoDecoder
  35. class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder {
  36. public:
  37. explicit FakeWebRtcVideoDecoder(FakeWebRtcVideoDecoderFactory* factory);
  38. ~FakeWebRtcVideoDecoder();
  39. int32_t InitDecode(const webrtc::VideoCodec*, int32_t) override;
  40. int32_t Decode(const webrtc::EncodedImage&, bool, int64_t) override;
  41. int32_t RegisterDecodeCompleteCallback(
  42. webrtc::DecodedImageCallback*) override;
  43. int32_t Release() override;
  44. int GetNumFramesReceived() const;
  45. private:
  46. int num_frames_received_;
  47. FakeWebRtcVideoDecoderFactory* factory_;
  48. };
  49. // Fake class for mocking out webrtc::VideoDecoderFactory.
  50. class FakeWebRtcVideoDecoderFactory : public webrtc::VideoDecoderFactory {
  51. public:
  52. FakeWebRtcVideoDecoderFactory();
  53. std::vector<webrtc::SdpVideoFormat> GetSupportedFormats() const override;
  54. std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder(
  55. const webrtc::SdpVideoFormat& format) override;
  56. void DecoderDestroyed(FakeWebRtcVideoDecoder* decoder);
  57. void AddSupportedVideoCodecType(const std::string& name);
  58. int GetNumCreatedDecoders();
  59. const std::vector<FakeWebRtcVideoDecoder*>& decoders();
  60. private:
  61. std::vector<webrtc::SdpVideoFormat> supported_codec_formats_;
  62. std::vector<FakeWebRtcVideoDecoder*> decoders_;
  63. int num_created_decoders_;
  64. };
  65. // Fake class for mocking out webrtc::VideoEnoder
  66. class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder {
  67. public:
  68. explicit FakeWebRtcVideoEncoder(FakeWebRtcVideoEncoderFactory* factory);
  69. ~FakeWebRtcVideoEncoder();
  70. void SetFecControllerOverride(
  71. webrtc::FecControllerOverride* fec_controller_override) override;
  72. int32_t InitEncode(const webrtc::VideoCodec* codecSettings,
  73. const VideoEncoder::Settings& settings) override;
  74. int32_t Encode(
  75. const webrtc::VideoFrame& inputImage,
  76. const std::vector<webrtc::VideoFrameType>* frame_types) override;
  77. int32_t RegisterEncodeCompleteCallback(
  78. webrtc::EncodedImageCallback* callback) override;
  79. int32_t Release() override;
  80. void SetRates(const RateControlParameters& parameters) override;
  81. webrtc::VideoEncoder::EncoderInfo GetEncoderInfo() const override;
  82. bool WaitForInitEncode();
  83. webrtc::VideoCodec GetCodecSettings();
  84. int GetNumEncodedFrames();
  85. private:
  86. webrtc::Mutex mutex_;
  87. rtc::Event init_encode_event_;
  88. int num_frames_encoded_ RTC_GUARDED_BY(mutex_);
  89. webrtc::VideoCodec codec_settings_ RTC_GUARDED_BY(mutex_);
  90. FakeWebRtcVideoEncoderFactory* factory_;
  91. };
  92. // Fake class for mocking out webrtc::VideoEncoderFactory.
  93. class FakeWebRtcVideoEncoderFactory : public webrtc::VideoEncoderFactory {
  94. public:
  95. FakeWebRtcVideoEncoderFactory();
  96. std::vector<webrtc::SdpVideoFormat> GetSupportedFormats() const override;
  97. std::unique_ptr<webrtc::VideoEncoder> CreateVideoEncoder(
  98. const webrtc::SdpVideoFormat& format) override;
  99. CodecInfo QueryVideoEncoder(
  100. const webrtc::SdpVideoFormat& format) const override;
  101. bool WaitForCreatedVideoEncoders(int num_encoders);
  102. void EncoderDestroyed(FakeWebRtcVideoEncoder* encoder);
  103. void set_encoders_have_internal_sources(bool internal_source);
  104. void AddSupportedVideoCodec(const webrtc::SdpVideoFormat& format);
  105. void AddSupportedVideoCodecType(const std::string& name);
  106. int GetNumCreatedEncoders();
  107. const std::vector<FakeWebRtcVideoEncoder*> encoders();
  108. private:
  109. webrtc::Mutex mutex_;
  110. rtc::Event created_video_encoder_event_;
  111. std::vector<webrtc::SdpVideoFormat> formats_;
  112. std::vector<FakeWebRtcVideoEncoder*> encoders_ RTC_GUARDED_BY(mutex_);
  113. int num_created_encoders_ RTC_GUARDED_BY(mutex_);
  114. bool encoders_have_internal_sources_;
  115. bool vp8_factory_mode_;
  116. };
  117. } // namespace cricket
  118. #endif // MEDIA_ENGINE_FAKE_WEBRTC_VIDEO_ENGINE_H_