blob: e7b75d6671c7f95b694c92755931d06fcc550420 [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 */
Stefan Holmer9fea80f2016-01-07 16:43:1810#ifndef WEBRTC_TEST_CALL_TEST_H_
11#define WEBRTC_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
ossuf515ab82016-12-07 12:52:5816#include "webrtc/call/call.h"
skvlad11a9cbf2016-10-07 18:53:0517#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
perkjfa10b552016-10-03 06:45:2618#include "webrtc/test/encoder_settings.h"
Stefan Holmer9fea80f2016-01-07 16:43:1819#include "webrtc/test/fake_audio_device.h"
pbos@webrtc.org994d0b72014-06-27 08:47:5220#include "webrtc/test/fake_decoder.h"
21#include "webrtc/test/fake_encoder.h"
sakal55d932b2016-09-30 13:19:0822#include "webrtc/test/fake_videorenderer.h"
pbos@webrtc.org994d0b72014-06-27 08:47:5223#include "webrtc/test/frame_generator_capturer.h"
24#include "webrtc/test/rtp_rtcp_observer.h"
25
26namespace webrtc {
Stefan Holmer9fea80f2016-01-07 16:43:1827
28class VoEBase;
Stefan Holmer9fea80f2016-01-07 16:43:1829
pbos@webrtc.org994d0b72014-06-27 08:47:5230namespace test {
31
32class BaseTest;
33
34class CallTest : public ::testing::Test {
35 public:
36 CallTest();
Stefan Holmer9fea80f2016-01-07 16:43:1837 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:5238
39 static const size_t kNumSsrcs = 3;
perkjfa10b552016-10-03 06:45:2640 static const int kDefaultWidth = 320;
41 static const int kDefaultHeight = 180;
42 static const int kDefaultFramerate = 30;
Peter Boström5811a392015-12-10 12:02:5043 static const int kDefaultTimeoutMs;
44 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 16:43:1845 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:5246 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 16:43:1847 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:1448 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 12:24:5049 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:1450 static const uint8_t kUlpfecPayloadType;
brandtr841de6a2016-11-15 15:10:5251 static const uint8_t kFlexfecPayloadType;
Stefan Holmer9fea80f2016-01-07 16:43:1852 static const uint8_t kAudioSendPayloadType;
pbos@webrtc.org2bb1bda2014-07-07 13:06:4853 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 16:43:1854 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
55 static const uint32_t kAudioSendSsrc;
brandtr841de6a2016-11-15 15:10:5256 static const uint32_t kFlexfecSendSsrc;
Stefan Holmer9fea80f2016-01-07 16:43:1857 static const uint32_t kReceiverLocalVideoSsrc;
58 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:5259 static const int kNackRtpHistoryMs;
minyue20c84cc2017-04-10 23:57:5760 static const std::map<uint8_t, MediaType> payload_type_map_;
pbos@webrtc.org994d0b72014-06-27 08:47:5261
62 protected:
Stefan Holmer9fea80f2016-01-07 16:43:1863 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
64 // receive Call configs to simplify test code and avoid having old VoiceEngine
65 // APIs in the tests.
stefane74eef12016-01-08 14:47:1366 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:5267
68 void CreateCalls(const Call::Config& sender_config,
69 const Call::Config& receiver_config);
70 void CreateSenderCall(const Call::Config& config);
71 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 08:49:2772 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:5273
Stefan Holmer9fea80f2016-01-07 16:43:1874 void CreateSendConfig(size_t num_video_streams,
75 size_t num_audio_streams,
brandtr841de6a2016-11-15 15:10:5276 size_t num_flexfec_streams,
Stefan Holmer9fea80f2016-01-07 16:43:1877 Transport* send_transport);
ilnika014cc52017-03-07 12:21:0478
pbos2d566682015-09-28 16:59:3179 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:5280
perkjfa10b552016-10-03 06:45:2681 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
82 float speed,
83 int framerate,
84 int width,
85 int height);
86 void CreateFrameGeneratorCapturer(int framerate, int width, int height);
oprypin92220ff2017-03-23 10:40:0387 void CreateFakeAudioDevices(
88 std::unique_ptr<FakeAudioDevice::Capturer> capturer,
89 std::unique_ptr<FakeAudioDevice::Renderer> renderer);
pbos@webrtc.org994d0b72014-06-27 08:47:5290
Stefan Holmer9fea80f2016-01-07 16:43:1891 void CreateVideoStreams();
92 void CreateAudioStreams();
brandtr841de6a2016-11-15 15:10:5293 void CreateFlexfecStreams();
pbos@webrtc.org994d0b72014-06-27 08:47:5294 void Start();
95 void Stop();
96 void DestroyStreams();
Perba7dc722016-04-19 13:01:2397 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:5298
pbos@webrtc.org2bb1bda2014-07-07 13:06:4899 Clock* const clock_;
100
philipel4fb651d2017-04-10 10:54:05101 std::unique_ptr<webrtc::RtcEventLog> event_log_;
kwibergbfefb032016-05-01 21:53:46102 std::unique_ptr<Call> sender_call_;
103 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 11:14:00104 VideoSendStream::Config video_send_config_;
105 VideoEncoderConfig video_encoder_config_;
106 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 16:43:18107 AudioSendStream::Config audio_send_config_;
108 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52109
kwibergbfefb032016-05-01 21:53:46110 std::unique_ptr<Call> receiver_call_;
111 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 11:14:00112 std::vector<VideoReceiveStream::Config> video_receive_configs_;
113 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 16:43:18114 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
115 std::vector<AudioReceiveStream*> audio_receive_streams_;
brandtr841de6a2016-11-15 15:10:52116 std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_;
117 std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52118
kwibergbfefb032016-05-01 21:53:46119 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52120 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 17:24:26121 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 16:43:18122 size_t num_video_streams_;
123 size_t num_audio_streams_;
brandtr841de6a2016-11-15 15:10:52124 size_t num_flexfec_streams_;
ossu29b1a8d2016-06-13 14:34:51125 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
ossu20a4b3f2017-04-27 09:08:52126 rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
sakal55d932b2016-09-30 13:19:08127 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 16:43:18128
129 private:
130 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
131 // These methods are used to set up legacy voice engines and channels which is
132 // necessary while voice engine is being refactored to the new stream API.
133 struct VoiceEngineState {
134 VoiceEngineState()
135 : voice_engine(nullptr),
136 base(nullptr),
mflodman3d7db262016-04-29 07:57:13137 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 16:43:18138
139 VoiceEngine* voice_engine;
140 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 16:43:18141 int channel_id;
Stefan Holmer9fea80f2016-01-07 16:43:18142 };
143
144 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 16:43:18145 void DestroyVoiceEngines();
146
147 VoiceEngineState voe_send_;
148 VoiceEngineState voe_recv_;
peaha9cc40b2017-06-29 15:32:09149 rtc::scoped_refptr<AudioProcessing> apm_send_;
150 rtc::scoped_refptr<AudioProcessing> apm_recv_;
Stefan Holmer9fea80f2016-01-07 16:43:18151
152 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 21:53:46153 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
154 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52155};
156
157class BaseTest : public RtpRtcpObserver {
158 public:
philipele828c962017-03-21 10:24:27159 BaseTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52160 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52161 virtual ~BaseTest();
162
163 virtual void PerformTest() = 0;
164 virtual bool ShouldCreateReceivers() const = 0;
165
Stefan Holmer9fea80f2016-01-07 16:43:18166 virtual size_t GetNumVideoStreams() const;
167 virtual size_t GetNumAudioStreams() const;
brandtr841de6a2016-11-15 15:10:52168 virtual size_t GetNumFlexfecStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52169
oprypin92220ff2017-03-23 10:40:03170 virtual std::unique_ptr<FakeAudioDevice::Capturer> CreateCapturer();
171 virtual std::unique_ptr<FakeAudioDevice::Renderer> CreateRenderer();
172 virtual void OnFakeAudioDevicesCreated(FakeAudioDevice* send_audio_device,
173 FakeAudioDevice* recv_audio_device);
174
pbos@webrtc.org994d0b72014-06-27 08:47:52175 virtual Call::Config GetSenderCallConfig();
176 virtual Call::Config GetReceiverCallConfig();
177 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 14:47:13178
179 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
180 virtual test::PacketTransport* CreateReceiveTransport();
pbos@webrtc.org994d0b72014-06-27 08:47:52181
stefanff483612015-12-21 11:14:00182 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09183 VideoSendStream::Config* send_config,
184 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25185 VideoEncoderConfig* encoder_config);
perkjfa10b552016-10-03 06:45:26186 virtual void ModifyVideoCaptureStartResolution(int* width,
187 int* heigt,
188 int* frame_rate);
stefanff483612015-12-21 11:14:00189 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09190 VideoSendStream* send_stream,
191 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52192
Stefan Holmer9fea80f2016-01-07 16:43:18193 virtual void ModifyAudioConfigs(
194 AudioSendStream::Config* send_config,
195 std::vector<AudioReceiveStream::Config>* receive_configs);
196 virtual void OnAudioStreamsCreated(
197 AudioSendStream* send_stream,
198 const std::vector<AudioReceiveStream*>& receive_streams);
199
brandtr841de6a2016-11-15 15:10:52200 virtual void ModifyFlexfecConfigs(
201 std::vector<FlexfecReceiveStream::Config>* receive_configs);
202 virtual void OnFlexfecStreamsCreated(
203 const std::vector<FlexfecReceiveStream*>& receive_streams);
204
pbos@webrtc.org994d0b72014-06-27 08:47:52205 virtual void OnFrameGeneratorCapturerCreated(
206 FrameGeneratorCapturer* frame_generator_capturer);
skvlad11a9cbf2016-10-07 18:53:05207
oprypin92220ff2017-03-23 10:40:03208 virtual void OnTestFinished();
209
philipel4fb651d2017-04-10 10:54:05210 std::unique_ptr<webrtc::RtcEventLog> event_log_;
pbos@webrtc.org994d0b72014-06-27 08:47:52211};
212
213class SendTest : public BaseTest {
214 public:
215 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52216
kjellander@webrtc.org14665ff2015-03-04 12:58:35217 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52218};
219
220class EndToEndTest : public BaseTest {
221 public:
philipele828c962017-03-21 10:24:27222 EndToEndTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52223 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52224
kjellander@webrtc.org14665ff2015-03-04 12:58:35225 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52226};
227
228} // namespace test
229} // namespace webrtc
230
Stefan Holmer9fea80f2016-01-07 16:43:18231#endif // WEBRTC_TEST_CALL_TEST_H_