nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_TEST_FAKE_VIDEO_TRACK_SOURCE_H_ |
| 12 | #define PC_TEST_FAKE_VIDEO_TRACK_SOURCE_H_ |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 13 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 14 | #include "api/media_stream_interface.h" |
Niels Möller | 3eaf9f1 | 2019-01-17 15:31:36 | [diff] [blame] | 15 | #include "media/base/video_broadcaster.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 16 | #include "pc/video_track_source.h" |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
Niels Möller | 3eaf9f1 | 2019-01-17 15:31:36 | [diff] [blame] | 20 | // A minimal implementation of VideoTrackSource. Includes a VideoBroadcaster for |
| 21 | // injection of frames. |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 22 | class FakeVideoTrackSource : public VideoTrackSource { |
| 23 | public: |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 24 | static rtc::scoped_refptr<FakeVideoTrackSource> Create(bool is_screencast) { |
| 25 | return new rtc::RefCountedObject<FakeVideoTrackSource>(is_screencast); |
| 26 | } |
| 27 | |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 28 | static rtc::scoped_refptr<FakeVideoTrackSource> Create() { |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 29 | return Create(false); |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 30 | } |
| 31 | |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 32 | bool is_screencast() const override { return is_screencast_; } |
Niels Möller | 3eaf9f1 | 2019-01-17 15:31:36 | [diff] [blame] | 33 | |
| 34 | void InjectFrame(const VideoFrame& frame) { |
| 35 | video_broadcaster_.OnFrame(frame); |
| 36 | } |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 37 | |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 38 | protected: |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 39 | explicit FakeVideoTrackSource(bool is_screencast) |
Niels Möller | 5d67f82 | 2018-05-23 14:28:17 | [diff] [blame] | 40 | : VideoTrackSource(false /* remote */), is_screencast_(is_screencast) {} |
| 41 | ~FakeVideoTrackSource() override = default; |
| 42 | |
Niels Möller | 3eaf9f1 | 2019-01-17 15:31:36 | [diff] [blame] | 43 | rtc::VideoSourceInterface<VideoFrame>* source() override { |
| 44 | return &video_broadcaster_; |
| 45 | } |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 46 | |
| 47 | private: |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 48 | const bool is_screencast_; |
Niels Möller | 3eaf9f1 | 2019-01-17 15:31:36 | [diff] [blame] | 49 | rtc::VideoBroadcaster video_broadcaster_; |
nisse | af510af | 2016-03-21 15:20:42 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | } // namespace webrtc |
| 53 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 54 | #endif // PC_TEST_FAKE_VIDEO_TRACK_SOURCE_H_ |