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