blob: e14e7e6214eeef4baf6e7207a377e49abb4f8cf1 [file] [log] [blame]
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001/*
2 * Copyright (c) 2014 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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef TEST_CALL_TEST_H_
11#define TEST_CALL_TEST_H_
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000012
kwiberg4a206a92016-03-31 10:24:26 -070013#include <memory>
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000014#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "call/call.h"
17#include "call/rtp_transport_controller_send.h"
18#include "logging/rtc_event_log/rtc_event_log.h"
Artem Titov3faa8322018-03-07 14:44:00 +010019#include "modules/audio_device/include/test_audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "test/encoder_settings.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "test/fake_decoder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "test/fake_videorenderer.h"
23#include "test/frame_generator_capturer.h"
Niels Möller4db138e2018-04-19 09:04:13 +020024#include "test/function_video_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "test/rtp_rtcp_observer.h"
26#include "test/single_threaded_task_queue.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000027
28namespace webrtc {
29namespace test {
30
31class BaseTest;
32
33class CallTest : public ::testing::Test {
34 public:
35 CallTest();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010036 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000037
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +010038 static constexpr size_t kNumSsrcs = 6;
39 static const int kNumSimulcastStreams = 3;
perkjfa10b552016-10-02 23:45:26 -070040 static const int kDefaultWidth = 320;
41 static const int kDefaultHeight = 180;
42 static const int kDefaultFramerate = 30;
Peter Boström5811a392015-12-10 13:02:50 +010043 static const int kDefaultTimeoutMs;
44 static const int kLongTimeoutMs;
Ilya Nikolaevskiy465a5d92018-03-16 11:12:06 +010045 enum classPayloadTypes : uint8_t {
46 kSendRtxPayloadType = 98,
47 kRtxRedPayloadType = 99,
48 kVideoSendPayloadType = 100,
49 kAudioSendPayloadType = 103,
50 kRedPayloadType = 118,
51 kUlpfecPayloadType = 119,
52 kFlexfecPayloadType = 120,
53 kPayloadTypeH264 = 122,
54 kPayloadTypeVP8 = 123,
55 kPayloadTypeVP9 = 124,
56 kFakeVideoSendPayloadType = 125,
57 };
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000058 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010059 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
60 static const uint32_t kAudioSendSsrc;
brandtr841de6a2016-11-15 07:10:52 -080061 static const uint32_t kFlexfecSendSsrc;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010062 static const uint32_t kReceiverLocalVideoSsrc;
63 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000064 static const int kNackRtpHistoryMs;
sprangd2702ef2017-07-10 08:41:10 -070065 static const uint8_t kDefaultKeepalivePayloadType;
minyue20c84cc2017-04-10 16:57:57 -070066 static const std::map<uint8_t, MediaType> payload_type_map_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000067
68 protected:
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010069 // RunBaseTest overwrites the audio_state of the send and receive Call configs
70 // to simplify test code.
stefane74eef12016-01-08 06:47:13 -080071 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000072
Sebastian Jansson8e6602f2018-07-13 10:43:20 +020073 void CreateCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000074 void CreateCalls(const Call::Config& sender_config,
75 const Call::Config& receiver_config);
Sebastian Jansson8e6602f2018-07-13 10:43:20 +020076 void CreateSenderCall();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000077 void CreateSenderCall(const Call::Config& config);
78 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020079 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000080
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +010081 void CreateVideoSendConfig(VideoSendStream::Config* video_config,
82 size_t num_video_streams,
83 size_t num_used_ssrcs,
84 Transport* send_transport);
85 void CreateAudioAndFecSendConfigs(size_t num_audio_streams,
86 size_t num_flexfec_streams,
87 Transport* send_transport);
Stefan Holmer9fea80f2016-01-07 17:43:18 +010088 void CreateSendConfig(size_t num_video_streams,
89 size_t num_audio_streams,
brandtr841de6a2016-11-15 07:10:52 -080090 size_t num_flexfec_streams,
Stefan Holmer9fea80f2016-01-07 17:43:18 +010091 Transport* send_transport);
ilnika014cc52017-03-07 04:21:04 -080092
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +010093 std::vector<VideoReceiveStream::Config> CreateMatchingVideoReceiveConfigs(
94 const VideoSendStream::Config& video_send_config,
95 Transport* rtcp_send_transport);
96 void CreateMatchingAudioAndFecConfigs(Transport* rtcp_send_transport);
pbos2d566682015-09-28 09:59:31 -070097 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000098
perkjfa10b552016-10-02 23:45:26 -070099 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
100 float speed,
101 int framerate,
102 int width,
103 int height);
104 void CreateFrameGeneratorCapturer(int framerate, int width, int height);
oprypin92220ff2017-03-23 03:40:03 -0700105 void CreateFakeAudioDevices(
Artem Titov3faa8322018-03-07 14:44:00 +0100106 std::unique_ptr<TestAudioDeviceModule::Capturer> capturer,
107 std::unique_ptr<TestAudioDeviceModule::Renderer> renderer);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000108
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100109 void CreateVideoStreams();
110 void CreateAudioStreams();
brandtr841de6a2016-11-15 07:10:52 -0800111 void CreateFlexfecStreams();
eladalonc0d481a2017-08-02 07:39:07 -0700112
113 void AssociateFlexfecStreamsWithVideoStreams();
114 void DissociateFlexfecStreamsFromVideoStreams();
115
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000116 void Start();
117 void Stop();
118 void DestroyStreams();
Perba7dc722016-04-19 15:01:23 +0200119 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000120
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000121 Clock* const clock_;
122
Sebastian Jansson8e6602f2018-07-13 10:43:20 +0200123 std::unique_ptr<webrtc::RtcEventLog> send_event_log_;
124 std::unique_ptr<webrtc::RtcEventLog> recv_event_log_;
kwibergbfefb032016-05-01 14:53:46 -0700125 std::unique_ptr<Call> sender_call_;
sprangdb2a9fc2017-08-09 06:42:32 -0700126 RtpTransportControllerSend* sender_call_transport_controller_;
kwibergbfefb032016-05-01 14:53:46 -0700127 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -0800128 VideoSendStream::Config video_send_config_;
129 VideoEncoderConfig video_encoder_config_;
130 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100131 AudioSendStream::Config audio_send_config_;
132 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000133
kwibergbfefb032016-05-01 14:53:46 -0700134 std::unique_ptr<Call> receiver_call_;
135 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -0800136 std::vector<VideoReceiveStream::Config> video_receive_configs_;
137 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100138 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
139 std::vector<AudioReceiveStream*> audio_receive_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800140 std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_;
141 std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000142
kwibergbfefb032016-05-01 14:53:46 -0700143 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
Niels Möller4db138e2018-04-19 09:04:13 +0200144 test::FunctionVideoEncoderFactory fake_encoder_factory_;
145 int fake_encoder_max_bitrate_ = -1;
kwiberg4a206a92016-03-31 10:24:26 -0700146 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100147 size_t num_video_streams_;
148 size_t num_audio_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800149 size_t num_flexfec_streams_;
Niels Möller2784a032018-03-28 14:16:04 +0200150 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_;
151 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory_;
sakal55d932b2016-09-30 06:19:08 -0700152 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100153
eladalon413ee9a2017-08-22 04:02:52 -0700154 SingleThreadedTaskQueueForTesting task_queue_;
155
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100156 private:
peaha9cc40b2017-06-29 08:32:09 -0700157 rtc::scoped_refptr<AudioProcessing> apm_send_;
158 rtc::scoped_refptr<AudioProcessing> apm_recv_;
Artem Titov3faa8322018-03-07 14:44:00 +0100159 rtc::scoped_refptr<TestAudioDeviceModule> fake_send_audio_device_;
160 rtc::scoped_refptr<TestAudioDeviceModule> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000161};
162
163class BaseTest : public RtpRtcpObserver {
164 public:
philipele828c962017-03-21 03:24:27 -0700165 BaseTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000166 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000167 virtual ~BaseTest();
168
169 virtual void PerformTest() = 0;
170 virtual bool ShouldCreateReceivers() const = 0;
171
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100172 virtual size_t GetNumVideoStreams() const;
173 virtual size_t GetNumAudioStreams() const;
brandtr841de6a2016-11-15 07:10:52 -0800174 virtual size_t GetNumFlexfecStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000175
Artem Titov3faa8322018-03-07 14:44:00 +0100176 virtual std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer();
177 virtual std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer();
178 virtual void OnFakeAudioDevicesCreated(
179 TestAudioDeviceModule* send_audio_device,
180 TestAudioDeviceModule* recv_audio_device);
oprypin92220ff2017-03-23 03:40:03 -0700181
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000182 virtual Call::Config GetSenderCallConfig();
183 virtual Call::Config GetReceiverCallConfig();
sprangdb2a9fc2017-08-09 06:42:32 -0700184 virtual void OnRtpTransportControllerSendCreated(
185 RtpTransportControllerSend* controller);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000186 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800187
eladalon413ee9a2017-08-22 04:02:52 -0700188 virtual test::PacketTransport* CreateSendTransport(
189 SingleThreadedTaskQueueForTesting* task_queue,
190 Call* sender_call);
191 virtual test::PacketTransport* CreateReceiveTransport(
192 SingleThreadedTaskQueueForTesting* task_queue);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000193
stefanff483612015-12-21 03:14:00 -0800194 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000195 VideoSendStream::Config* send_config,
196 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000197 VideoEncoderConfig* encoder_config);
perkjfa10b552016-10-02 23:45:26 -0700198 virtual void ModifyVideoCaptureStartResolution(int* width,
199 int* heigt,
200 int* frame_rate);
stefanff483612015-12-21 03:14:00 -0800201 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000202 VideoSendStream* send_stream,
203 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000204
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100205 virtual void ModifyAudioConfigs(
206 AudioSendStream::Config* send_config,
207 std::vector<AudioReceiveStream::Config>* receive_configs);
208 virtual void OnAudioStreamsCreated(
209 AudioSendStream* send_stream,
210 const std::vector<AudioReceiveStream*>& receive_streams);
211
brandtr841de6a2016-11-15 07:10:52 -0800212 virtual void ModifyFlexfecConfigs(
213 std::vector<FlexfecReceiveStream::Config>* receive_configs);
214 virtual void OnFlexfecStreamsCreated(
215 const std::vector<FlexfecReceiveStream*>& receive_streams);
216
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000217 virtual void OnFrameGeneratorCapturerCreated(
218 FrameGeneratorCapturer* frame_generator_capturer);
skvlad11a9cbf2016-10-07 11:53:05 -0700219
Fredrik Solenberg73276ad2017-09-14 14:46:47 +0200220 virtual void OnStreamsStopped();
oprypin92220ff2017-03-23 03:40:03 -0700221
philipel4fb651d2017-04-10 03:54:05 -0700222 std::unique_ptr<webrtc::RtcEventLog> event_log_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000223};
224
225class SendTest : public BaseTest {
226 public:
227 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000228
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000229 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000230};
231
232class EndToEndTest : public BaseTest {
233 public:
philipele828c962017-03-21 03:24:27 -0700234 EndToEndTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000235 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000236
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000237 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000238};
239
240} // namespace test
241} // namespace webrtc
242
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200243#endif // TEST_CALL_TEST_H_