blob: 5186afa7533881e625692f20f52962c30403a358 [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 */
Stefan Holmer9fea80f2016-01-07 17:43:18 +010010#ifndef WEBRTC_TEST_CALL_TEST_H_
11#define WEBRTC_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
ossuf515ab82016-12-07 04:52:58 -080016#include "webrtc/call/call.h"
sprangdb2a9fc2017-08-09 06:42:32 -070017#include "webrtc/call/rtp_transport_controller_send.h"
skvlad11a9cbf2016-10-07 11:53:05 -070018#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
perkjfa10b552016-10-02 23:45:26 -070019#include "webrtc/test/encoder_settings.h"
Stefan Holmer9fea80f2016-01-07 17:43:18 +010020#include "webrtc/test/fake_audio_device.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000021#include "webrtc/test/fake_decoder.h"
22#include "webrtc/test/fake_encoder.h"
sakal55d932b2016-09-30 06:19:08 -070023#include "webrtc/test/fake_videorenderer.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000024#include "webrtc/test/frame_generator_capturer.h"
25#include "webrtc/test/rtp_rtcp_observer.h"
26
27namespace webrtc {
Stefan Holmer9fea80f2016-01-07 17:43:18 +010028
29class VoEBase;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010030
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000031namespace test {
32
33class BaseTest;
34
35class CallTest : public ::testing::Test {
36 public:
37 CallTest();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010038 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000039
40 static const size_t kNumSsrcs = 3;
perkjfa10b552016-10-02 23:45:26 -070041 static const int kDefaultWidth = 320;
42 static const int kDefaultHeight = 180;
43 static const int kDefaultFramerate = 30;
Peter Boström5811a392015-12-10 13:02:50 +010044 static const int kDefaultTimeoutMs;
45 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010046 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000047 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010048 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000049 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 20:24:50 +080050 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000051 static const uint8_t kUlpfecPayloadType;
brandtr841de6a2016-11-15 07:10:52 -080052 static const uint8_t kFlexfecPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010053 static const uint8_t kAudioSendPayloadType;
ilnik863f03b2017-07-11 02:38:36 -070054 static const uint8_t kPayloadTypeH264;
55 static const uint8_t kPayloadTypeVP8;
56 static const uint8_t kPayloadTypeVP9;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000057 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010058 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
59 static const uint32_t kAudioSendSsrc;
brandtr841de6a2016-11-15 07:10:52 -080060 static const uint32_t kFlexfecSendSsrc;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010061 static const uint32_t kReceiverLocalVideoSsrc;
62 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000063 static const int kNackRtpHistoryMs;
sprangd2702ef2017-07-10 08:41:10 -070064 static const uint8_t kDefaultKeepalivePayloadType;
minyue20c84cc2017-04-10 16:57:57 -070065 static const std::map<uint8_t, MediaType> payload_type_map_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000066
67 protected:
Stefan Holmer9fea80f2016-01-07 17:43:18 +010068 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
69 // receive Call configs to simplify test code and avoid having old VoiceEngine
70 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080071 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000072
73 void CreateCalls(const Call::Config& sender_config,
74 const Call::Config& receiver_config);
75 void CreateSenderCall(const Call::Config& config);
76 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020077 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000078
Stefan Holmer9fea80f2016-01-07 17:43:18 +010079 void CreateSendConfig(size_t num_video_streams,
80 size_t num_audio_streams,
brandtr841de6a2016-11-15 07:10:52 -080081 size_t num_flexfec_streams,
Stefan Holmer9fea80f2016-01-07 17:43:18 +010082 Transport* send_transport);
ilnika014cc52017-03-07 04:21:04 -080083
pbos2d566682015-09-28 09:59:31 -070084 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000085
perkjfa10b552016-10-02 23:45:26 -070086 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
87 float speed,
88 int framerate,
89 int width,
90 int height);
91 void CreateFrameGeneratorCapturer(int framerate, int width, int height);
oprypin92220ff2017-03-23 03:40:03 -070092 void CreateFakeAudioDevices(
93 std::unique_ptr<FakeAudioDevice::Capturer> capturer,
94 std::unique_ptr<FakeAudioDevice::Renderer> renderer);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000095
Stefan Holmer9fea80f2016-01-07 17:43:18 +010096 void CreateVideoStreams();
97 void CreateAudioStreams();
brandtr841de6a2016-11-15 07:10:52 -080098 void CreateFlexfecStreams();
eladalonc0d481a2017-08-02 07:39:07 -070099
100 void AssociateFlexfecStreamsWithVideoStreams();
101 void DissociateFlexfecStreamsFromVideoStreams();
102
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000103 void Start();
104 void Stop();
105 void DestroyStreams();
Perba7dc722016-04-19 15:01:23 +0200106 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000107
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000108 Clock* const clock_;
109
philipel4fb651d2017-04-10 03:54:05 -0700110 std::unique_ptr<webrtc::RtcEventLog> event_log_;
kwibergbfefb032016-05-01 14:53:46 -0700111 std::unique_ptr<Call> sender_call_;
sprangdb2a9fc2017-08-09 06:42:32 -0700112 RtpTransportControllerSend* sender_call_transport_controller_;
kwibergbfefb032016-05-01 14:53:46 -0700113 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -0800114 VideoSendStream::Config video_send_config_;
115 VideoEncoderConfig video_encoder_config_;
116 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100117 AudioSendStream::Config audio_send_config_;
118 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000119
kwibergbfefb032016-05-01 14:53:46 -0700120 std::unique_ptr<Call> receiver_call_;
121 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -0800122 std::vector<VideoReceiveStream::Config> video_receive_configs_;
123 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100124 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
125 std::vector<AudioReceiveStream*> audio_receive_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800126 std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_;
127 std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000128
kwibergbfefb032016-05-01 14:53:46 -0700129 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000130 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 10:24:26 -0700131 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100132 size_t num_video_streams_;
133 size_t num_audio_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800134 size_t num_flexfec_streams_;
ossu29b1a8d2016-06-13 07:34:51 -0700135 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
ossu20a4b3f2017-04-27 02:08:52 -0700136 rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
sakal55d932b2016-09-30 06:19:08 -0700137 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100138
139 private:
140 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
141 // These methods are used to set up legacy voice engines and channels which is
142 // necessary while voice engine is being refactored to the new stream API.
143 struct VoiceEngineState {
144 VoiceEngineState()
145 : voice_engine(nullptr),
146 base(nullptr),
mflodman3d7db262016-04-29 00:57:13 -0700147 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100148
149 VoiceEngine* voice_engine;
150 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100151 int channel_id;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100152 };
153
154 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100155 void DestroyVoiceEngines();
156
157 VoiceEngineState voe_send_;
158 VoiceEngineState voe_recv_;
peaha9cc40b2017-06-29 08:32:09 -0700159 rtc::scoped_refptr<AudioProcessing> apm_send_;
160 rtc::scoped_refptr<AudioProcessing> apm_recv_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100161
162 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 14:53:46 -0700163 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
164 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000165};
166
167class BaseTest : public RtpRtcpObserver {
168 public:
philipele828c962017-03-21 03:24:27 -0700169 BaseTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000170 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000171 virtual ~BaseTest();
172
173 virtual void PerformTest() = 0;
174 virtual bool ShouldCreateReceivers() const = 0;
175
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100176 virtual size_t GetNumVideoStreams() const;
177 virtual size_t GetNumAudioStreams() const;
brandtr841de6a2016-11-15 07:10:52 -0800178 virtual size_t GetNumFlexfecStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000179
oprypin92220ff2017-03-23 03:40:03 -0700180 virtual std::unique_ptr<FakeAudioDevice::Capturer> CreateCapturer();
181 virtual std::unique_ptr<FakeAudioDevice::Renderer> CreateRenderer();
182 virtual void OnFakeAudioDevicesCreated(FakeAudioDevice* send_audio_device,
183 FakeAudioDevice* recv_audio_device);
184
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000185 virtual Call::Config GetSenderCallConfig();
186 virtual Call::Config GetReceiverCallConfig();
sprangdb2a9fc2017-08-09 06:42:32 -0700187 virtual void OnRtpTransportControllerSendCreated(
188 RtpTransportControllerSend* controller);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000189 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800190
191 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
192 virtual test::PacketTransport* CreateReceiveTransport();
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
oprypin92220ff2017-03-23 03:40:03 -0700220 virtual void OnTestFinished();
221
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
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100243#endif // WEBRTC_TEST_CALL_TEST_H_