1 /* 2 * Copyright 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_SCENARIO_VIDEO_STREAM_H_ 11 #define TEST_SCENARIO_VIDEO_STREAM_H_ 12 #include <memory> 13 #include <string> 14 #include <vector> 15 16 #include "rtc_base/constructor_magic.h" 17 #include "rtc_base/synchronization/mutex.h" 18 #include "test/fake_encoder.h" 19 #include "test/fake_videorenderer.h" 20 #include "test/frame_generator_capturer.h" 21 #include "test/logging/log_writer.h" 22 #include "test/scenario/call_client.h" 23 #include "test/scenario/column_printer.h" 24 #include "test/scenario/network_node.h" 25 #include "test/scenario/scenario_config.h" 26 #include "test/scenario/video_frame_matcher.h" 27 #include "test/test_video_capturer.h" 28 29 namespace webrtc { 30 namespace test { 31 // SendVideoStream provides an interface for changing parameters and retrieving 32 // states at run time. 33 class SendVideoStream { 34 public: 35 RTC_DISALLOW_COPY_AND_ASSIGN(SendVideoStream); 36 ~SendVideoStream(); 37 void SetCaptureFramerate(int framerate); 38 VideoSendStream::Stats GetStats() const; 39 ColumnPrinter StatsPrinter(); 40 void Start(); 41 void Stop(); 42 void UpdateConfig(std::function<void(VideoStreamConfig*)> modifier); 43 void UpdateActiveLayers(std::vector<bool> active_layers); 44 bool UsingSsrc(uint32_t ssrc) const; 45 bool UsingRtxSsrc(uint32_t ssrc) const; 46 47 private: 48 friend class Scenario; 49 friend class VideoStreamPair; 50 friend class ReceiveVideoStream; 51 // Handles RTCP feedback for this stream. 52 SendVideoStream(CallClient* sender, 53 VideoStreamConfig config, 54 Transport* send_transport, 55 VideoFrameMatcher* matcher); 56 57 Mutex mutex_; 58 std::vector<uint32_t> ssrcs_; 59 std::vector<uint32_t> rtx_ssrcs_; 60 VideoSendStream* send_stream_ = nullptr; 61 CallClient* const sender_; 62 VideoStreamConfig config_ RTC_GUARDED_BY(mutex_); 63 std::unique_ptr<VideoEncoderFactory> encoder_factory_; 64 std::vector<test::FakeEncoder*> fake_encoders_ RTC_GUARDED_BY(mutex_); 65 std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_; 66 std::unique_ptr<FrameGeneratorCapturer> video_capturer_; 67 std::unique_ptr<ForwardingCapturedFrameTap> frame_tap_; 68 int next_local_network_id_ = 0; 69 int next_remote_network_id_ = 0; 70 }; 71 72 // ReceiveVideoStream represents a video receiver. It can't be used directly. 73 class ReceiveVideoStream { 74 public: 75 RTC_DISALLOW_COPY_AND_ASSIGN(ReceiveVideoStream); 76 ~ReceiveVideoStream(); 77 void Start(); 78 void Stop(); 79 VideoReceiveStream::Stats GetStats() const; 80 81 private: 82 friend class Scenario; 83 friend class VideoStreamPair; 84 ReceiveVideoStream(CallClient* receiver, 85 VideoStreamConfig config, 86 SendVideoStream* send_stream, 87 size_t chosen_stream, 88 Transport* feedback_transport, 89 VideoFrameMatcher* matcher); 90 91 std::vector<VideoReceiveStream*> receive_streams_; 92 FlexfecReceiveStream* flecfec_stream_ = nullptr; 93 FakeVideoRenderer fake_renderer_; 94 std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>> 95 render_taps_; 96 CallClient* const receiver_; 97 const VideoStreamConfig config_; 98 std::unique_ptr<VideoDecoderFactory> decoder_factory_; 99 }; 100 101 // VideoStreamPair represents a video streaming session. It can be used to 102 // access underlying send and receive classes. It can also be used in calls to 103 // the Scenario class. 104 class VideoStreamPair { 105 public: 106 RTC_DISALLOW_COPY_AND_ASSIGN(VideoStreamPair); 107 ~VideoStreamPair(); send()108 SendVideoStream* send() { return &send_stream_; } receive()109 ReceiveVideoStream* receive() { return &receive_stream_; } matcher()110 VideoFrameMatcher* matcher() { return &matcher_; } 111 112 private: 113 friend class Scenario; 114 VideoStreamPair(CallClient* sender, 115 CallClient* receiver, 116 VideoStreamConfig config); 117 118 const VideoStreamConfig config_; 119 120 VideoFrameMatcher matcher_; 121 SendVideoStream send_stream_; 122 ReceiveVideoStream receive_stream_; 123 }; 124 } // namespace test 125 } // namespace webrtc 126 127 #endif // TEST_SCENARIO_VIDEO_STREAM_H_ 128