blob: 11ac0e670a360a49db47602354eefcff2ddffd70 [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"
19#include "test/encoder_settings.h"
20#include "test/fake_audio_device.h"
21#include "test/fake_decoder.h"
22#include "test/fake_encoder.h"
23#include "test/fake_videorenderer.h"
24#include "test/frame_generator_capturer.h"
25#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 {
Stefan Holmer9fea80f2016-01-07 17:43:18 +010029
30class VoEBase;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010031
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000032namespace test {
33
34class BaseTest;
35
36class CallTest : public ::testing::Test {
37 public:
38 CallTest();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010039 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000040
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +010041 static constexpr size_t kNumSsrcs = 6;
42 static const int kNumSimulcastStreams = 3;
perkjfa10b552016-10-02 23:45:26 -070043 static const int kDefaultWidth = 320;
44 static const int kDefaultHeight = 180;
45 static const int kDefaultFramerate = 30;
Peter Boström5811a392015-12-10 13:02:50 +010046 static const int kDefaultTimeoutMs;
47 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010048 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000049 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010050 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000051 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 20:24:50 +080052 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000053 static const uint8_t kUlpfecPayloadType;
brandtr841de6a2016-11-15 07:10:52 -080054 static const uint8_t kFlexfecPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010055 static const uint8_t kAudioSendPayloadType;
ilnik863f03b2017-07-11 02:38:36 -070056 static const uint8_t kPayloadTypeH264;
57 static const uint8_t kPayloadTypeVP8;
58 static const uint8_t kPayloadTypeVP9;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000059 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010060 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
61 static const uint32_t kAudioSendSsrc;
brandtr841de6a2016-11-15 07:10:52 -080062 static const uint32_t kFlexfecSendSsrc;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010063 static const uint32_t kReceiverLocalVideoSsrc;
64 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000065 static const int kNackRtpHistoryMs;
sprangd2702ef2017-07-10 08:41:10 -070066 static const uint8_t kDefaultKeepalivePayloadType;
minyue20c84cc2017-04-10 16:57:57 -070067 static const std::map<uint8_t, MediaType> payload_type_map_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000068
69 protected:
Stefan Holmer9fea80f2016-01-07 17:43:18 +010070 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
71 // receive Call configs to simplify test code and avoid having old VoiceEngine
72 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080073 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000074
75 void CreateCalls(const Call::Config& sender_config,
76 const Call::Config& receiver_config);
77 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(
106 std::unique_ptr<FakeAudioDevice::Capturer> capturer,
107 std::unique_ptr<FakeAudioDevice::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
philipel4fb651d2017-04-10 03:54:05 -0700123 std::unique_ptr<webrtc::RtcEventLog> event_log_;
kwibergbfefb032016-05-01 14:53:46 -0700124 std::unique_ptr<Call> sender_call_;
sprangdb2a9fc2017-08-09 06:42:32 -0700125 RtpTransportControllerSend* sender_call_transport_controller_;
kwibergbfefb032016-05-01 14:53:46 -0700126 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -0800127 VideoSendStream::Config video_send_config_;
128 VideoEncoderConfig video_encoder_config_;
129 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100130 AudioSendStream::Config audio_send_config_;
131 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000132
kwibergbfefb032016-05-01 14:53:46 -0700133 std::unique_ptr<Call> receiver_call_;
134 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -0800135 std::vector<VideoReceiveStream::Config> video_receive_configs_;
136 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100137 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
138 std::vector<AudioReceiveStream*> audio_receive_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800139 std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_;
140 std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000141
kwibergbfefb032016-05-01 14:53:46 -0700142 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000143 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 10:24:26 -0700144 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100145 size_t num_video_streams_;
146 size_t num_audio_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800147 size_t num_flexfec_streams_;
Rasmus Brandt31027342017-09-29 13:48:12 +0000148 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
149 rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
sakal55d932b2016-09-30 06:19:08 -0700150 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100151
eladalon413ee9a2017-08-22 04:02:52 -0700152 SingleThreadedTaskQueueForTesting task_queue_;
153
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100154 private:
155 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
156 // These methods are used to set up legacy voice engines and channels which is
157 // necessary while voice engine is being refactored to the new stream API.
158 struct VoiceEngineState {
159 VoiceEngineState()
160 : voice_engine(nullptr),
161 base(nullptr),
mflodman3d7db262016-04-29 00:57:13 -0700162 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100163
164 VoiceEngine* voice_engine;
165 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100166 int channel_id;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100167 };
168
169 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100170 void DestroyVoiceEngines();
171
172 VoiceEngineState voe_send_;
173 VoiceEngineState voe_recv_;
peaha9cc40b2017-06-29 08:32:09 -0700174 rtc::scoped_refptr<AudioProcessing> apm_send_;
175 rtc::scoped_refptr<AudioProcessing> apm_recv_;
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100176 rtc::scoped_refptr<test::FakeAudioDevice> fake_send_audio_device_;
177 rtc::scoped_refptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000178};
179
180class BaseTest : public RtpRtcpObserver {
181 public:
philipele828c962017-03-21 03:24:27 -0700182 BaseTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000183 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000184 virtual ~BaseTest();
185
186 virtual void PerformTest() = 0;
187 virtual bool ShouldCreateReceivers() const = 0;
188
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100189 virtual size_t GetNumVideoStreams() const;
190 virtual size_t GetNumAudioStreams() const;
brandtr841de6a2016-11-15 07:10:52 -0800191 virtual size_t GetNumFlexfecStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000192
oprypin92220ff2017-03-23 03:40:03 -0700193 virtual std::unique_ptr<FakeAudioDevice::Capturer> CreateCapturer();
194 virtual std::unique_ptr<FakeAudioDevice::Renderer> CreateRenderer();
195 virtual void OnFakeAudioDevicesCreated(FakeAudioDevice* send_audio_device,
196 FakeAudioDevice* recv_audio_device);
197
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000198 virtual Call::Config GetSenderCallConfig();
199 virtual Call::Config GetReceiverCallConfig();
sprangdb2a9fc2017-08-09 06:42:32 -0700200 virtual void OnRtpTransportControllerSendCreated(
201 RtpTransportControllerSend* controller);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000202 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800203
eladalon413ee9a2017-08-22 04:02:52 -0700204 virtual test::PacketTransport* CreateSendTransport(
205 SingleThreadedTaskQueueForTesting* task_queue,
206 Call* sender_call);
207 virtual test::PacketTransport* CreateReceiveTransport(
208 SingleThreadedTaskQueueForTesting* task_queue);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000209
stefanff483612015-12-21 03:14:00 -0800210 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000211 VideoSendStream::Config* send_config,
212 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000213 VideoEncoderConfig* encoder_config);
perkjfa10b552016-10-02 23:45:26 -0700214 virtual void ModifyVideoCaptureStartResolution(int* width,
215 int* heigt,
216 int* frame_rate);
stefanff483612015-12-21 03:14:00 -0800217 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000218 VideoSendStream* send_stream,
219 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000220
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100221 virtual void ModifyAudioConfigs(
222 AudioSendStream::Config* send_config,
223 std::vector<AudioReceiveStream::Config>* receive_configs);
224 virtual void OnAudioStreamsCreated(
225 AudioSendStream* send_stream,
226 const std::vector<AudioReceiveStream*>& receive_streams);
227
brandtr841de6a2016-11-15 07:10:52 -0800228 virtual void ModifyFlexfecConfigs(
229 std::vector<FlexfecReceiveStream::Config>* receive_configs);
230 virtual void OnFlexfecStreamsCreated(
231 const std::vector<FlexfecReceiveStream*>& receive_streams);
232
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000233 virtual void OnFrameGeneratorCapturerCreated(
234 FrameGeneratorCapturer* frame_generator_capturer);
skvlad11a9cbf2016-10-07 11:53:05 -0700235
Fredrik Solenberg73276ad2017-09-14 14:46:47 +0200236 virtual void OnStreamsStopped();
oprypin92220ff2017-03-23 03:40:03 -0700237
philipel4fb651d2017-04-10 03:54:05 -0700238 std::unique_ptr<webrtc::RtcEventLog> event_log_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000239};
240
241class SendTest : public BaseTest {
242 public:
243 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000244
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000245 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000246};
247
248class EndToEndTest : public BaseTest {
249 public:
philipele828c962017-03-21 03:24:27 -0700250 EndToEndTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000251 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000252
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000253 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000254};
255
256} // namespace test
257} // namespace webrtc
258
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200259#endif // TEST_CALL_TEST_H_