blob: 43c51eab7343b41becf13dd9ca52299215f52a30 [file] [log] [blame]
Sebastian Jansson98b07e912018-09-27 11:47:011/*
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 Handella5a4be12020-07-08 14:09:2116#include "rtc_base/synchronization/mutex.h"
Sebastian Jansson0c32e332018-11-12 15:47:4317#include "test/fake_encoder.h"
Sebastian Jansson5fbebd52019-02-20 10:16:1918#include "test/fake_videorenderer.h"
Sebastian Jansson98b07e912018-09-27 11:47:0119#include "test/frame_generator_capturer.h"
Sebastian Jansson52de8b02019-01-16 16:25:4420#include "test/logging/log_writer.h"
Sebastian Jansson98b07e912018-09-27 11:47:0121#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 Jansson7150d8c2019-04-09 12:18:0925#include "test/scenario/video_frame_matcher.h"
Sebastian Jansson98b07e912018-09-27 11:47:0126#include "test/test_video_capturer.h"
27
28namespace webrtc {
29namespace test {
30// SendVideoStream provides an interface for changing parameters and retrieving
31// states at run time.
Sebastian Jansson800e1212018-10-22 09:49:0332class SendVideoStream {
Sebastian Jansson98b07e912018-09-27 11:47:0133 public:
Sebastian Jansson98b07e912018-09-27 11:47:0134 ~SendVideoStream();
Artem Titov6cae2d52022-01-26 15:01:1035
36 SendVideoStream(const SendVideoStream&) = delete;
37 SendVideoStream& operator=(const SendVideoStream&) = delete;
38
Sebastian Jansson98b07e912018-09-27 11:47:0139 void SetCaptureFramerate(int framerate);
Sebastian Jansson98b07e912018-09-27 11:47:0140 VideoSendStream::Stats GetStats() const;
41 ColumnPrinter StatsPrinter();
42 void Start();
Christoffer Rodbro5f6abcf2019-02-08 10:00:1043 void Stop();
Sebastian Jansson0c32e332018-11-12 15:47:4344 void UpdateConfig(std::function<void(VideoStreamConfig*)> modifier);
Sebastian Janssone8226682019-04-30 12:29:0945 void UpdateActiveLayers(std::vector<bool> active_layers);
Sebastian Jansson3d4d94a2020-01-14 13:25:4146 bool UsingSsrc(uint32_t ssrc) const;
47 bool UsingRtxSsrc(uint32_t ssrc) const;
Sebastian Jansson98b07e912018-09-27 11:47:0148
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 Jansson9a4f38e2018-12-19 12:14:4156 Transport* send_transport,
Sebastian Janssoncf2df2f2019-04-02 09:51:2857 VideoFrameMatcher* matcher);
Sebastian Jansson98b07e912018-09-27 11:47:0158
Markus Handella5a4be12020-07-08 14:09:2159 Mutex mutex_;
Sebastian Jansson98b07e912018-09-27 11:47:0160 std::vector<uint32_t> ssrcs_;
61 std::vector<uint32_t> rtx_ssrcs_;
62 VideoSendStream* send_stream_ = nullptr;
63 CallClient* const sender_;
Markus Handella5a4be12020-07-08 14:09:2164 VideoStreamConfig config_ RTC_GUARDED_BY(mutex_);
Sebastian Jansson98b07e912018-09-27 11:47:0165 std::unique_ptr<VideoEncoderFactory> encoder_factory_;
Markus Handella5a4be12020-07-08 14:09:2166 std::vector<test::FakeEncoder*> fake_encoders_ RTC_GUARDED_BY(mutex_);
Jiawei Ouc2ebe212018-11-08 18:02:5667 std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_;
Sebastian Janssonf0c366b2019-02-14 12:18:4268 std::unique_ptr<FrameGeneratorCapturer> video_capturer_;
Sebastian Jansson9a4f38e2018-12-19 12:14:4169 std::unique_ptr<ForwardingCapturedFrameTap> frame_tap_;
Sebastian Jansson800e1212018-10-22 09:49:0370 int next_local_network_id_ = 0;
71 int next_remote_network_id_ = 0;
Sebastian Jansson98b07e912018-09-27 11:47:0172};
73
74// ReceiveVideoStream represents a video receiver. It can't be used directly.
Sebastian Jansson800e1212018-10-22 09:49:0375class ReceiveVideoStream {
Sebastian Jansson98b07e912018-09-27 11:47:0176 public:
Sebastian Jansson98b07e912018-09-27 11:47:0177 ~ReceiveVideoStream();
Artem Titov6cae2d52022-01-26 15:01:1078
79 ReceiveVideoStream(const ReceiveVideoStream&) = delete;
80 ReceiveVideoStream& operator=(const ReceiveVideoStream&) = delete;
81
Sebastian Jansson49a78432018-11-20 15:15:2982 void Start();
Sebastian Janssonbdfadd62019-02-08 12:34:5783 void Stop();
Tommif6f45432022-05-20 13:21:2084 VideoReceiveStreamInterface::Stats GetStats() const;
Sebastian Jansson98b07e912018-09-27 11:47:0185
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 Jansson9a4f38e2018-12-19 12:14:4193 Transport* feedback_transport,
Sebastian Janssoncf2df2f2019-04-02 09:51:2894 VideoFrameMatcher* matcher);
Sebastian Jansson800e1212018-10-22 09:49:0395
Tommif6f45432022-05-20 13:21:2096 std::vector<VideoReceiveStreamInterface*> receive_streams_;
Sebastian Jansson98b07e912018-09-27 11:47:0197 FlexfecReceiveStream* flecfec_stream_ = nullptr;
Sebastian Jansson5fbebd52019-02-20 10:16:1998 FakeVideoRenderer fake_renderer_;
Sebastian Janssoncf2df2f2019-04-02 09:51:2899 std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>>
100 render_taps_;
Sebastian Jansson98b07e912018-09-27 11:47:01101 CallClient* const receiver_;
102 const VideoStreamConfig config_;
Niels Möllercbcbc222018-09-28 07:07:24103 std::unique_ptr<VideoDecoderFactory> decoder_factory_;
Sebastian Jansson98b07e912018-09-27 11:47:01104};
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.
109class VideoStreamPair {
110 public:
Sebastian Jansson98b07e912018-09-27 11:47:01111 ~VideoStreamPair();
Artem Titov6cae2d52022-01-26 15:01:10112
113 VideoStreamPair(const VideoStreamPair&) = delete;
114 VideoStreamPair& operator=(const VideoStreamPair&) = delete;
115
Sebastian Jansson98b07e912018-09-27 11:47:01116 SendVideoStream* send() { return &send_stream_; }
117 ReceiveVideoStream* receive() { return &receive_stream_; }
Sebastian Janssoncf2df2f2019-04-02 09:51:28118 VideoFrameMatcher* matcher() { return &matcher_; }
Sebastian Jansson98b07e912018-09-27 11:47:01119
120 private:
121 friend class Scenario;
122 VideoStreamPair(CallClient* sender,
Sebastian Jansson98b07e912018-09-27 11:47:01123 CallClient* receiver,
Sebastian Janssoncf2df2f2019-04-02 09:51:28124 VideoStreamConfig config);
Sebastian Jansson98b07e912018-09-27 11:47:01125
126 const VideoStreamConfig config_;
Sebastian Jansson98b07e912018-09-27 11:47:01127
Sebastian Janssoncf2df2f2019-04-02 09:51:28128 VideoFrameMatcher matcher_;
Sebastian Jansson98b07e912018-09-27 11:47:01129 SendVideoStream send_stream_;
130 ReceiveVideoStream receive_stream_;
131};
Per Kb3046c22023-01-12 16:00:22132
133std::vector<RtpExtension> GetVideoRtpExtensions(const VideoStreamConfig config);
134
Sebastian Jansson98b07e912018-09-27 11:47:01135} // namespace test
136} // namespace webrtc
137
138#endif // TEST_SCENARIO_VIDEO_STREAM_H_