test_video_track_source.h (3341B)
1 /* 2 * Copyright (c) 2023 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 API_TEST_VIDEO_TEST_VIDEO_TRACK_SOURCE_H_ 12 #define API_TEST_VIDEO_TEST_VIDEO_TRACK_SOURCE_H_ 13 14 #include <optional> 15 #include <string> 16 17 #include "api/media_stream_interface.h" 18 #include "api/notifier.h" 19 #include "api/sequence_checker.h" 20 #include "api/video/recordable_encoded_frame.h" 21 #include "api/video/video_frame.h" 22 #include "api/video/video_sink_interface.h" 23 #include "api/video/video_source_interface.h" 24 #include "rtc_base/system/no_unique_address.h" 25 #include "rtc_base/thread_annotations.h" 26 27 namespace webrtc { 28 namespace test { 29 30 // Video source that can be used as input for tests. 31 class TestVideoTrackSource : public Notifier<VideoTrackSourceInterface> { 32 public: 33 explicit TestVideoTrackSource( 34 bool remote, 35 std::optional<std::string> stream_label = std::nullopt); 36 ~TestVideoTrackSource() override = default; 37 38 void SetState(SourceState new_state); 39 40 SourceState state() const override; 41 bool remote() const override { return remote_; } 42 43 bool is_screencast() const override { return false; } 44 std::optional<bool> needs_denoising() const override { return std::nullopt; } 45 46 bool GetStats(Stats* /* stats */) override { return false; } 47 48 void AddOrUpdateSink(VideoSinkInterface<VideoFrame>* sink, 49 const VideoSinkWants& wants) override; 50 void RemoveSink(VideoSinkInterface<VideoFrame>* sink) override; 51 52 bool SupportsEncodedOutput() const override { return false; } 53 void GenerateKeyFrame() override {} 54 void AddEncodedSink( 55 VideoSinkInterface<RecordableEncodedFrame>* /* sink */) override {} 56 void RemoveEncodedSink( 57 VideoSinkInterface<RecordableEncodedFrame>* /* sink */) override {} 58 59 // Starts producing video. 60 virtual void Start() = 0; 61 62 // Stops producing video. 63 virtual void Stop() = 0; 64 65 virtual void SetScreencast(bool is_screencast) = 0; 66 67 // TODO(titovartem): make next 4 methods pure virtual. 68 virtual void SetEnableAdaptation(bool /* enable_adaptation */) {} 69 70 virtual int GetFrameWidth() const { return 0; } 71 virtual int GetFrameHeight() const { return 0; } 72 73 virtual void OnOutputFormatRequest(int /* width */, 74 int /* height */, 75 const std::optional<int>& /* max_fps */) {} 76 77 // Returns stream label for this video source if present. Implementations 78 // may override this method to increase debugability and testability. 79 virtual std::optional<std::string> GetStreamLabel() { return stream_label_; } 80 81 protected: 82 virtual VideoSourceInterface<VideoFrame>* source() = 0; 83 84 private: 85 const std::optional<std::string> stream_label_; 86 RTC_NO_UNIQUE_ADDRESS SequenceChecker worker_thread_checker_; 87 RTC_NO_UNIQUE_ADDRESS SequenceChecker signaling_thread_checker_; 88 SourceState state_ RTC_GUARDED_BY(&signaling_thread_checker_); 89 const bool remote_; 90 }; 91 92 } // namespace test 93 } // namespace webrtc 94 95 #endif // API_TEST_VIDEO_TEST_VIDEO_TRACK_SOURCE_H_