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