blob: b4f665821ee2ffa420a6465835a4dc310e8b3961 [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"
skvlad11a9cbf2016-10-07 11:53:05 -070017#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
perkjfa10b552016-10-02 23:45:26 -070018#include "webrtc/test/encoder_settings.h"
Stefan Holmer9fea80f2016-01-07 17:43:18 +010019#include "webrtc/test/fake_audio_device.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000020#include "webrtc/test/fake_decoder.h"
21#include "webrtc/test/fake_encoder.h"
sakal55d932b2016-09-30 06:19:08 -070022#include "webrtc/test/fake_videorenderer.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000023#include "webrtc/test/frame_generator_capturer.h"
24#include "webrtc/test/rtp_rtcp_observer.h"
25
26namespace webrtc {
Stefan Holmer9fea80f2016-01-07 17:43:18 +010027
28class VoEBase;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010029
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000030namespace test {
31
32class BaseTest;
33
34class CallTest : public ::testing::Test {
35 public:
36 CallTest();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010037 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000038
39 static const size_t kNumSsrcs = 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;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010045 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000046 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010047 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000048 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 20:24:50 +080049 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000050 static const uint8_t kUlpfecPayloadType;
brandtr841de6a2016-11-15 07:10:52 -080051 static const uint8_t kFlexfecPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010052 static const uint8_t kAudioSendPayloadType;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000053 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010054 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
55 static const uint32_t kAudioSendSsrc;
brandtr841de6a2016-11-15 07:10:52 -080056 static const uint32_t kFlexfecSendSsrc;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010057 static const uint32_t kReceiverLocalVideoSsrc;
58 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000059 static const int kNackRtpHistoryMs;
60
61 protected:
nissee5ad5ca2017-03-29 23:57:43 -070062 // Needed for tests sending both audio and video on the same
63 // FakeNetworkPipe. We then need to set correct MediaType based on
64 // packet payload type, before passing the packet on to Call.
65 class PayloadDemuxer : public PacketReceiver {
66 public:
67 PayloadDemuxer() = default;
68
69 void SetReceiver(PacketReceiver* receiver);
70 DeliveryStatus DeliverPacket(MediaType media_type,
71 const uint8_t* packet,
72 size_t length,
73 const PacketTime& packet_time) override;
74
75 private:
76 PacketReceiver* receiver_ = nullptr;
77 };
78
Stefan Holmer9fea80f2016-01-07 17:43:18 +010079 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
80 // receive Call configs to simplify test code and avoid having old VoiceEngine
81 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080082 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000083
84 void CreateCalls(const Call::Config& sender_config,
85 const Call::Config& receiver_config);
86 void CreateSenderCall(const Call::Config& config);
87 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020088 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000089
Stefan Holmer9fea80f2016-01-07 17:43:18 +010090 void CreateSendConfig(size_t num_video_streams,
91 size_t num_audio_streams,
brandtr841de6a2016-11-15 07:10:52 -080092 size_t num_flexfec_streams,
Stefan Holmer9fea80f2016-01-07 17:43:18 +010093 Transport* send_transport);
ilnika014cc52017-03-07 04:21:04 -080094
pbos2d566682015-09-28 09:59:31 -070095 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000096
perkjfa10b552016-10-02 23:45:26 -070097 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
98 float speed,
99 int framerate,
100 int width,
101 int height);
102 void CreateFrameGeneratorCapturer(int framerate, int width, int height);
oprypin92220ff2017-03-23 03:40:03 -0700103 void CreateFakeAudioDevices(
104 std::unique_ptr<FakeAudioDevice::Capturer> capturer,
105 std::unique_ptr<FakeAudioDevice::Renderer> renderer);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000106
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100107 void CreateVideoStreams();
108 void CreateAudioStreams();
brandtr841de6a2016-11-15 07:10:52 -0800109 void CreateFlexfecStreams();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000110 void Start();
111 void Stop();
112 void DestroyStreams();
Perba7dc722016-04-19 15:01:23 +0200113 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000114
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000115 Clock* const clock_;
116
skvlad11a9cbf2016-10-07 11:53:05 -0700117 webrtc::RtcEventLogNullImpl event_log_;
kwibergbfefb032016-05-01 14:53:46 -0700118 std::unique_ptr<Call> sender_call_;
119 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -0800120 VideoSendStream::Config video_send_config_;
121 VideoEncoderConfig video_encoder_config_;
122 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100123 AudioSendStream::Config audio_send_config_;
124 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000125
kwibergbfefb032016-05-01 14:53:46 -0700126 std::unique_ptr<Call> receiver_call_;
127 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -0800128 std::vector<VideoReceiveStream::Config> video_receive_configs_;
129 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100130 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
131 std::vector<AudioReceiveStream*> audio_receive_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800132 std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_;
133 std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000134
kwibergbfefb032016-05-01 14:53:46 -0700135 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000136 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 10:24:26 -0700137 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100138 size_t num_video_streams_;
139 size_t num_audio_streams_;
brandtr841de6a2016-11-15 07:10:52 -0800140 size_t num_flexfec_streams_;
ossu29b1a8d2016-06-13 07:34:51 -0700141 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
sakal55d932b2016-09-30 06:19:08 -0700142 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100143
nissee5ad5ca2017-03-29 23:57:43 -0700144 PayloadDemuxer receive_demuxer_;
145 PayloadDemuxer send_demuxer_;
146
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100147 private:
148 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
149 // These methods are used to set up legacy voice engines and channels which is
150 // necessary while voice engine is being refactored to the new stream API.
151 struct VoiceEngineState {
152 VoiceEngineState()
153 : voice_engine(nullptr),
154 base(nullptr),
mflodman3d7db262016-04-29 00:57:13 -0700155 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100156
157 VoiceEngine* voice_engine;
158 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100159 int channel_id;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100160 };
161
162 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100163 void DestroyVoiceEngines();
164
165 VoiceEngineState voe_send_;
166 VoiceEngineState voe_recv_;
167
168 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 14:53:46 -0700169 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
170 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000171};
172
173class BaseTest : public RtpRtcpObserver {
174 public:
philipele828c962017-03-21 03:24:27 -0700175 BaseTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000176 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000177 virtual ~BaseTest();
178
179 virtual void PerformTest() = 0;
180 virtual bool ShouldCreateReceivers() const = 0;
181
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100182 virtual size_t GetNumVideoStreams() const;
183 virtual size_t GetNumAudioStreams() const;
brandtr841de6a2016-11-15 07:10:52 -0800184 virtual size_t GetNumFlexfecStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000185
oprypin92220ff2017-03-23 03:40:03 -0700186 virtual std::unique_ptr<FakeAudioDevice::Capturer> CreateCapturer();
187 virtual std::unique_ptr<FakeAudioDevice::Renderer> CreateRenderer();
188 virtual void OnFakeAudioDevicesCreated(FakeAudioDevice* send_audio_device,
189 FakeAudioDevice* recv_audio_device);
190
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000191 virtual Call::Config GetSenderCallConfig();
192 virtual Call::Config GetReceiverCallConfig();
193 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800194
nissee5ad5ca2017-03-29 23:57:43 -0700195 // The default implementation creates MediaType::VIDEO transports.
stefane74eef12016-01-08 06:47:13 -0800196 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
197 virtual test::PacketTransport* CreateReceiveTransport();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000198
stefanff483612015-12-21 03:14:00 -0800199 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000200 VideoSendStream::Config* send_config,
201 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000202 VideoEncoderConfig* encoder_config);
perkjfa10b552016-10-02 23:45:26 -0700203 virtual void ModifyVideoCaptureStartResolution(int* width,
204 int* heigt,
205 int* frame_rate);
stefanff483612015-12-21 03:14:00 -0800206 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000207 VideoSendStream* send_stream,
208 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000209
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100210 virtual void ModifyAudioConfigs(
211 AudioSendStream::Config* send_config,
212 std::vector<AudioReceiveStream::Config>* receive_configs);
213 virtual void OnAudioStreamsCreated(
214 AudioSendStream* send_stream,
215 const std::vector<AudioReceiveStream*>& receive_streams);
216
brandtr841de6a2016-11-15 07:10:52 -0800217 virtual void ModifyFlexfecConfigs(
218 std::vector<FlexfecReceiveStream::Config>* receive_configs);
219 virtual void OnFlexfecStreamsCreated(
220 const std::vector<FlexfecReceiveStream*>& receive_streams);
221
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000222 virtual void OnFrameGeneratorCapturerCreated(
223 FrameGeneratorCapturer* frame_generator_capturer);
skvlad11a9cbf2016-10-07 11:53:05 -0700224
oprypin92220ff2017-03-23 03:40:03 -0700225 virtual void OnTestFinished();
226
skvlad11a9cbf2016-10-07 11:53:05 -0700227 webrtc::RtcEventLogNullImpl event_log_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000228};
229
230class SendTest : public BaseTest {
231 public:
232 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000233
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000234 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000235};
236
237class EndToEndTest : public BaseTest {
238 public:
philipele828c962017-03-21 03:24:27 -0700239 EndToEndTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000240 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000241
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000242 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000243};
244
245} // namespace test
246} // namespace webrtc
247
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100248#endif // WEBRTC_TEST_CALL_TEST_H_