blob: cf15aacf114a6d7ac0fba35329d2585191f52938 [file] [log] [blame]
pbos@webrtc.org994d0b72014-06-27 08:47:521/*
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 04:47:3110#ifndef TEST_CALL_TEST_H_
11#define TEST_CALL_TEST_H_
pbos@webrtc.org994d0b72014-06-27 08:47:5212
kwiberg4a206a92016-03-31 17:24:2613#include <memory>
pbos@webrtc.org994d0b72014-06-27 08:47:5214#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#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:5227
28namespace webrtc {
Stefan Holmer9fea80f2016-01-07 16:43:1829
30class VoEBase;
Stefan Holmer9fea80f2016-01-07 16:43:1831
pbos@webrtc.org994d0b72014-06-27 08:47:5232namespace test {
33
34class BaseTest;
35
36class CallTest : public ::testing::Test {
37 public:
38 CallTest();
Stefan Holmer9fea80f2016-01-07 16:43:1839 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:5240
41 static const size_t kNumSsrcs = 3;
perkjfa10b552016-10-03 06:45:2642 static const int kDefaultWidth = 320;
43 static const int kDefaultHeight = 180;
44 static const int kDefaultFramerate = 30;
Peter Boström5811a392015-12-10 12:02:5045 static const int kDefaultTimeoutMs;
46 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 16:43:1847 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:5248 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 16:43:1849 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:1450 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 12:24:5051 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:1452 static const uint8_t kUlpfecPayloadType;
brandtr841de6a2016-11-15 15:10:5253 static const uint8_t kFlexfecPayloadType;
Stefan Holmer9fea80f2016-01-07 16:43:1854 static const uint8_t kAudioSendPayloadType;
ilnik863f03b2017-07-11 09:38:3655 static const uint8_t kPayloadTypeH264;
56 static const uint8_t kPayloadTypeVP8;
57 static const uint8_t kPayloadTypeVP9;
pbos@webrtc.org2bb1bda2014-07-07 13:06:4858 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 16:43:1859 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
60 static const uint32_t kAudioSendSsrc;
brandtr841de6a2016-11-15 15:10:5261 static const uint32_t kFlexfecSendSsrc;
Stefan Holmer9fea80f2016-01-07 16:43:1862 static const uint32_t kReceiverLocalVideoSsrc;
63 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:5264 static const int kNackRtpHistoryMs;
sprangd2702ef2017-07-10 15:41:1065 static const uint8_t kDefaultKeepalivePayloadType;
minyue20c84cc2017-04-10 23:57:5766 static const std::map<uint8_t, MediaType> payload_type_map_;
pbos@webrtc.org994d0b72014-06-27 08:47:5267
68 protected:
Stefan Holmer9fea80f2016-01-07 16:43:1869 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
70 // receive Call configs to simplify test code and avoid having old VoiceEngine
71 // APIs in the tests.
stefane74eef12016-01-08 14:47:1372 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:5273
74 void CreateCalls(const Call::Config& sender_config,
75 const Call::Config& receiver_config);
76 void CreateSenderCall(const Call::Config& config);
77 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2778 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:5279
Stefan Holmer9fea80f2016-01-07 16:43:1880 void CreateSendConfig(size_t num_video_streams,
81 size_t num_audio_streams,
brandtr841de6a2016-11-15 15:10:5282 size_t num_flexfec_streams,
Stefan Holmer9fea80f2016-01-07 16:43:1883 Transport* send_transport);
ilnika014cc52017-03-07 12:21:0484
pbos2d566682015-09-28 16:59:3185 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:5286
perkjfa10b552016-10-03 06:45:2687 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
88 float speed,
89 int framerate,
90 int width,
91 int height);
92 void CreateFrameGeneratorCapturer(int framerate, int width, int height);
oprypin92220ff2017-03-23 10:40:0393 void CreateFakeAudioDevices(
94 std::unique_ptr<FakeAudioDevice::Capturer> capturer,
95 std::unique_ptr<FakeAudioDevice::Renderer> renderer);
pbos@webrtc.org994d0b72014-06-27 08:47:5296
Stefan Holmer9fea80f2016-01-07 16:43:1897 void CreateVideoStreams();
98 void CreateAudioStreams();
brandtr841de6a2016-11-15 15:10:5299 void CreateFlexfecStreams();
eladalonc0d481a2017-08-02 14:39:07100
101 void AssociateFlexfecStreamsWithVideoStreams();
102 void DissociateFlexfecStreamsFromVideoStreams();
103
pbos@webrtc.org994d0b72014-06-27 08:47:52104 void Start();
105 void Stop();
106 void DestroyStreams();
Perba7dc722016-04-19 13:01:23107 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52108
pbos@webrtc.org2bb1bda2014-07-07 13:06:48109 Clock* const clock_;
110
philipel4fb651d2017-04-10 10:54:05111 std::unique_ptr<webrtc::RtcEventLog> event_log_;
kwibergbfefb032016-05-01 21:53:46112 std::unique_ptr<Call> sender_call_;
sprangdb2a9fc2017-08-09 13:42:32113 RtpTransportControllerSend* sender_call_transport_controller_;
kwibergbfefb032016-05-01 21:53:46114 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 11:14:00115 VideoSendStream::Config video_send_config_;
116 VideoEncoderConfig video_encoder_config_;
117 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 16:43:18118 AudioSendStream::Config audio_send_config_;
119 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52120
kwibergbfefb032016-05-01 21:53:46121 std::unique_ptr<Call> receiver_call_;
122 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 11:14:00123 std::vector<VideoReceiveStream::Config> video_receive_configs_;
124 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 16:43:18125 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
126 std::vector<AudioReceiveStream*> audio_receive_streams_;
brandtr841de6a2016-11-15 15:10:52127 std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_;
128 std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52129
kwibergbfefb032016-05-01 21:53:46130 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52131 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 17:24:26132 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 16:43:18133 size_t num_video_streams_;
134 size_t num_audio_streams_;
brandtr841de6a2016-11-15 15:10:52135 size_t num_flexfec_streams_;
brandtr2c301202017-09-22 11:30:08136 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
137 rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
sakal55d932b2016-09-30 13:19:08138 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 16:43:18139
eladalon413ee9a2017-08-22 11:02:52140 SingleThreadedTaskQueueForTesting task_queue_;
141
Stefan Holmer9fea80f2016-01-07 16:43:18142 private:
143 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
144 // These methods are used to set up legacy voice engines and channels which is
145 // necessary while voice engine is being refactored to the new stream API.
146 struct VoiceEngineState {
147 VoiceEngineState()
148 : voice_engine(nullptr),
149 base(nullptr),
mflodman3d7db262016-04-29 07:57:13150 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 16:43:18151
152 VoiceEngine* voice_engine;
153 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 16:43:18154 int channel_id;
Stefan Holmer9fea80f2016-01-07 16:43:18155 };
156
157 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 16:43:18158 void DestroyVoiceEngines();
159
160 VoiceEngineState voe_send_;
161 VoiceEngineState voe_recv_;
peaha9cc40b2017-06-29 15:32:09162 rtc::scoped_refptr<AudioProcessing> apm_send_;
163 rtc::scoped_refptr<AudioProcessing> apm_recv_;
Stefan Holmer9fea80f2016-01-07 16:43:18164
165 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 21:53:46166 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
167 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52168};
169
170class BaseTest : public RtpRtcpObserver {
171 public:
philipele828c962017-03-21 10:24:27172 BaseTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52173 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52174 virtual ~BaseTest();
175
176 virtual void PerformTest() = 0;
177 virtual bool ShouldCreateReceivers() const = 0;
178
Stefan Holmer9fea80f2016-01-07 16:43:18179 virtual size_t GetNumVideoStreams() const;
180 virtual size_t GetNumAudioStreams() const;
brandtr841de6a2016-11-15 15:10:52181 virtual size_t GetNumFlexfecStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52182
oprypin92220ff2017-03-23 10:40:03183 virtual std::unique_ptr<FakeAudioDevice::Capturer> CreateCapturer();
184 virtual std::unique_ptr<FakeAudioDevice::Renderer> CreateRenderer();
185 virtual void OnFakeAudioDevicesCreated(FakeAudioDevice* send_audio_device,
186 FakeAudioDevice* recv_audio_device);
187
pbos@webrtc.org994d0b72014-06-27 08:47:52188 virtual Call::Config GetSenderCallConfig();
189 virtual Call::Config GetReceiverCallConfig();
sprangdb2a9fc2017-08-09 13:42:32190 virtual void OnRtpTransportControllerSendCreated(
191 RtpTransportControllerSend* controller);
pbos@webrtc.org994d0b72014-06-27 08:47:52192 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 14:47:13193
eladalon413ee9a2017-08-22 11:02:52194 virtual test::PacketTransport* CreateSendTransport(
195 SingleThreadedTaskQueueForTesting* task_queue,
196 Call* sender_call);
197 virtual test::PacketTransport* CreateReceiveTransport(
198 SingleThreadedTaskQueueForTesting* task_queue);
pbos@webrtc.org994d0b72014-06-27 08:47:52199
stefanff483612015-12-21 11:14:00200 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09201 VideoSendStream::Config* send_config,
202 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25203 VideoEncoderConfig* encoder_config);
perkjfa10b552016-10-03 06:45:26204 virtual void ModifyVideoCaptureStartResolution(int* width,
205 int* heigt,
206 int* frame_rate);
stefanff483612015-12-21 11:14:00207 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09208 VideoSendStream* send_stream,
209 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52210
Stefan Holmer9fea80f2016-01-07 16:43:18211 virtual void ModifyAudioConfigs(
212 AudioSendStream::Config* send_config,
213 std::vector<AudioReceiveStream::Config>* receive_configs);
214 virtual void OnAudioStreamsCreated(
215 AudioSendStream* send_stream,
216 const std::vector<AudioReceiveStream*>& receive_streams);
217
brandtr841de6a2016-11-15 15:10:52218 virtual void ModifyFlexfecConfigs(
219 std::vector<FlexfecReceiveStream::Config>* receive_configs);
220 virtual void OnFlexfecStreamsCreated(
221 const std::vector<FlexfecReceiveStream*>& receive_streams);
222
pbos@webrtc.org994d0b72014-06-27 08:47:52223 virtual void OnFrameGeneratorCapturerCreated(
224 FrameGeneratorCapturer* frame_generator_capturer);
skvlad11a9cbf2016-10-07 18:53:05225
Fredrik Solenberg73276ad2017-09-14 12:46:47226 virtual void OnStreamsStopped();
oprypin92220ff2017-03-23 10:40:03227
philipel4fb651d2017-04-10 10:54:05228 std::unique_ptr<webrtc::RtcEventLog> event_log_;
pbos@webrtc.org994d0b72014-06-27 08:47:52229};
230
231class SendTest : public BaseTest {
232 public:
233 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52234
kjellander@webrtc.org14665ff2015-03-04 12:58:35235 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52236};
237
238class EndToEndTest : public BaseTest {
239 public:
philipele828c962017-03-21 10:24:27240 EndToEndTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52241 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52242
kjellander@webrtc.org14665ff2015-03-04 12:58:35243 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52244};
245
246} // namespace test
247} // namespace webrtc
248
Mirko Bonadei92ea95e2017-09-15 04:47:31249#endif // TEST_CALL_TEST_H_