Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 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 | |
Markus Handell | a5a4be1 | 2020-07-08 14:09:21 | [diff] [blame] | 16 | #include "rtc_base/synchronization/mutex.h" |
Sebastian Jansson | 0c32e33 | 2018-11-12 15:47:43 | [diff] [blame] | 17 | #include "test/fake_encoder.h" |
Sebastian Jansson | 5fbebd5 | 2019-02-20 10:16:19 | [diff] [blame] | 18 | #include "test/fake_videorenderer.h" |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 19 | #include "test/frame_generator_capturer.h" |
Sebastian Jansson | 52de8b0 | 2019-01-16 16:25:44 | [diff] [blame] | 20 | #include "test/logging/log_writer.h" |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 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" |
Sebastian Jansson | 7150d8c | 2019-04-09 12:18:09 | [diff] [blame] | 25 | #include "test/scenario/video_frame_matcher.h" |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 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. |
Sebastian Jansson | 800e121 | 2018-10-22 09:49:03 | [diff] [blame] | 32 | class SendVideoStream { |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 33 | public: |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 34 | ~SendVideoStream(); |
Artem Titov | 6cae2d5 | 2022-01-26 15:01:10 | [diff] [blame] | 35 | |
| 36 | SendVideoStream(const SendVideoStream&) = delete; |
| 37 | SendVideoStream& operator=(const SendVideoStream&) = delete; |
| 38 | |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 39 | void SetCaptureFramerate(int framerate); |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 40 | VideoSendStream::Stats GetStats() const; |
| 41 | ColumnPrinter StatsPrinter(); |
| 42 | void Start(); |
Christoffer Rodbro | 5f6abcf | 2019-02-08 10:00:10 | [diff] [blame] | 43 | void Stop(); |
Sebastian Jansson | 0c32e33 | 2018-11-12 15:47:43 | [diff] [blame] | 44 | void UpdateConfig(std::function<void(VideoStreamConfig*)> modifier); |
Sebastian Jansson | e822668 | 2019-04-30 12:29:09 | [diff] [blame] | 45 | void UpdateActiveLayers(std::vector<bool> active_layers); |
Sebastian Jansson | 3d4d94a | 2020-01-14 13:25:41 | [diff] [blame] | 46 | bool UsingSsrc(uint32_t ssrc) const; |
| 47 | bool UsingRtxSsrc(uint32_t ssrc) const; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 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, |
Sebastian Jansson | 9a4f38e | 2018-12-19 12:14:41 | [diff] [blame] | 56 | Transport* send_transport, |
Sebastian Jansson | cf2df2f | 2019-04-02 09:51:28 | [diff] [blame] | 57 | VideoFrameMatcher* matcher); |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 58 | |
Markus Handell | a5a4be1 | 2020-07-08 14:09:21 | [diff] [blame] | 59 | Mutex mutex_; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 60 | std::vector<uint32_t> ssrcs_; |
| 61 | std::vector<uint32_t> rtx_ssrcs_; |
| 62 | VideoSendStream* send_stream_ = nullptr; |
| 63 | CallClient* const sender_; |
Markus Handell | a5a4be1 | 2020-07-08 14:09:21 | [diff] [blame] | 64 | VideoStreamConfig config_ RTC_GUARDED_BY(mutex_); |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 65 | std::unique_ptr<VideoEncoderFactory> encoder_factory_; |
Markus Handell | a5a4be1 | 2020-07-08 14:09:21 | [diff] [blame] | 66 | std::vector<test::FakeEncoder*> fake_encoders_ RTC_GUARDED_BY(mutex_); |
Jiawei Ou | c2ebe21 | 2018-11-08 18:02:56 | [diff] [blame] | 67 | std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_; |
Sebastian Jansson | f0c366b | 2019-02-14 12:18:42 | [diff] [blame] | 68 | std::unique_ptr<FrameGeneratorCapturer> video_capturer_; |
Sebastian Jansson | 9a4f38e | 2018-12-19 12:14:41 | [diff] [blame] | 69 | std::unique_ptr<ForwardingCapturedFrameTap> frame_tap_; |
Sebastian Jansson | 800e121 | 2018-10-22 09:49:03 | [diff] [blame] | 70 | int next_local_network_id_ = 0; |
| 71 | int next_remote_network_id_ = 0; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | // ReceiveVideoStream represents a video receiver. It can't be used directly. |
Sebastian Jansson | 800e121 | 2018-10-22 09:49:03 | [diff] [blame] | 75 | class ReceiveVideoStream { |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 76 | public: |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 77 | ~ReceiveVideoStream(); |
Artem Titov | 6cae2d5 | 2022-01-26 15:01:10 | [diff] [blame] | 78 | |
| 79 | ReceiveVideoStream(const ReceiveVideoStream&) = delete; |
| 80 | ReceiveVideoStream& operator=(const ReceiveVideoStream&) = delete; |
| 81 | |
Sebastian Jansson | 49a7843 | 2018-11-20 15:15:29 | [diff] [blame] | 82 | void Start(); |
Sebastian Jansson | bdfadd6 | 2019-02-08 12:34:57 | [diff] [blame] | 83 | void Stop(); |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 84 | VideoReceiveStreamInterface::Stats GetStats() const; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 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, |
Sebastian Jansson | 9a4f38e | 2018-12-19 12:14:41 | [diff] [blame] | 93 | Transport* feedback_transport, |
Sebastian Jansson | cf2df2f | 2019-04-02 09:51:28 | [diff] [blame] | 94 | VideoFrameMatcher* matcher); |
Sebastian Jansson | 800e121 | 2018-10-22 09:49:03 | [diff] [blame] | 95 | |
Tommi | f6f4543 | 2022-05-20 13:21:20 | [diff] [blame] | 96 | std::vector<VideoReceiveStreamInterface*> receive_streams_; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 97 | FlexfecReceiveStream* flecfec_stream_ = nullptr; |
Sebastian Jansson | 5fbebd5 | 2019-02-20 10:16:19 | [diff] [blame] | 98 | FakeVideoRenderer fake_renderer_; |
Sebastian Jansson | cf2df2f | 2019-04-02 09:51:28 | [diff] [blame] | 99 | std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>> |
| 100 | render_taps_; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 101 | CallClient* const receiver_; |
| 102 | const VideoStreamConfig config_; |
Niels Möller | cbcbc22 | 2018-09-28 07:07:24 | [diff] [blame] | 103 | std::unique_ptr<VideoDecoderFactory> decoder_factory_; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 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: |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 111 | ~VideoStreamPair(); |
Artem Titov | 6cae2d5 | 2022-01-26 15:01:10 | [diff] [blame] | 112 | |
| 113 | VideoStreamPair(const VideoStreamPair&) = delete; |
| 114 | VideoStreamPair& operator=(const VideoStreamPair&) = delete; |
| 115 | |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 116 | SendVideoStream* send() { return &send_stream_; } |
| 117 | ReceiveVideoStream* receive() { return &receive_stream_; } |
Sebastian Jansson | cf2df2f | 2019-04-02 09:51:28 | [diff] [blame] | 118 | VideoFrameMatcher* matcher() { return &matcher_; } |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 119 | |
| 120 | private: |
| 121 | friend class Scenario; |
| 122 | VideoStreamPair(CallClient* sender, |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 123 | CallClient* receiver, |
Sebastian Jansson | cf2df2f | 2019-04-02 09:51:28 | [diff] [blame] | 124 | VideoStreamConfig config); |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 125 | |
| 126 | const VideoStreamConfig config_; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 127 | |
Sebastian Jansson | cf2df2f | 2019-04-02 09:51:28 | [diff] [blame] | 128 | VideoFrameMatcher matcher_; |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 129 | SendVideoStream send_stream_; |
| 130 | ReceiveVideoStream receive_stream_; |
| 131 | }; |
Per K | b3046c2 | 2023-01-12 16:00:22 | [diff] [blame] | 132 | |
| 133 | std::vector<RtpExtension> GetVideoRtpExtensions(const VideoStreamConfig config); |
| 134 | |
Sebastian Jansson | 98b07e91 | 2018-09-27 11:47:01 | [diff] [blame] | 135 | } // namespace test |
| 136 | } // namespace webrtc |
| 137 | |
| 138 | #endif // TEST_SCENARIO_VIDEO_STREAM_H_ |