fake_video_track_source.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2016 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 PC_TEST_FAKE_VIDEO_TRACK_SOURCE_H_
  11. #define PC_TEST_FAKE_VIDEO_TRACK_SOURCE_H_
  12. #include "api/media_stream_interface.h"
  13. #include "media/base/video_broadcaster.h"
  14. #include "pc/video_track_source.h"
  15. namespace webrtc {
  16. // A minimal implementation of VideoTrackSource. Includes a VideoBroadcaster for
  17. // injection of frames.
  18. class FakeVideoTrackSource : public VideoTrackSource {
  19. public:
  20. static rtc::scoped_refptr<FakeVideoTrackSource> Create(bool is_screencast) {
  21. return new rtc::RefCountedObject<FakeVideoTrackSource>(is_screencast);
  22. }
  23. static rtc::scoped_refptr<FakeVideoTrackSource> Create() {
  24. return Create(false);
  25. }
  26. bool is_screencast() const override { return is_screencast_; }
  27. void InjectFrame(const VideoFrame& frame) {
  28. video_broadcaster_.OnFrame(frame);
  29. }
  30. protected:
  31. explicit FakeVideoTrackSource(bool is_screencast)
  32. : VideoTrackSource(false /* remote */), is_screencast_(is_screencast) {}
  33. ~FakeVideoTrackSource() override = default;
  34. rtc::VideoSourceInterface<VideoFrame>* source() override {
  35. return &video_broadcaster_;
  36. }
  37. private:
  38. const bool is_screencast_;
  39. rtc::VideoBroadcaster video_broadcaster_;
  40. };
  41. } // namespace webrtc
  42. #endif // PC_TEST_FAKE_VIDEO_TRACK_SOURCE_H_