blob: 4667e088dbfd130b6e6023e0553084d7359bb5ab [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
16#include "webrtc/call.h"
Stefan Holmer9fea80f2016-01-07 17:43:18 +010017#include "webrtc/test/fake_audio_device.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000018#include "webrtc/test/fake_decoder.h"
19#include "webrtc/test/fake_encoder.h"
sakal55d932b2016-09-30 06:19:08 -070020#include "webrtc/test/fake_videorenderer.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000021#include "webrtc/test/frame_generator_capturer.h"
22#include "webrtc/test/rtp_rtcp_observer.h"
23
24namespace webrtc {
Stefan Holmer9fea80f2016-01-07 17:43:18 +010025
26class VoEBase;
27class VoECodec;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010028
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000029namespace test {
30
31class BaseTest;
32
33class CallTest : public ::testing::Test {
34 public:
35 CallTest();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010036 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000037
38 static const size_t kNumSsrcs = 3;
perkj3b703ed2016-09-29 23:25:40 -070039
Peter Boström5811a392015-12-10 13:02:50 +010040 static const int kDefaultTimeoutMs;
41 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010042 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000043 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010044 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000045 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 20:24:50 +080046 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000047 static const uint8_t kUlpfecPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010048 static const uint8_t kAudioSendPayloadType;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000049 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010050 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
51 static const uint32_t kAudioSendSsrc;
52 static const uint32_t kReceiverLocalVideoSsrc;
53 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000054 static const int kNackRtpHistoryMs;
55
56 protected:
Stefan Holmer9fea80f2016-01-07 17:43:18 +010057 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
58 // receive Call configs to simplify test code and avoid having old VoiceEngine
59 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080060 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000061
62 void CreateCalls(const Call::Config& sender_config,
63 const Call::Config& receiver_config);
64 void CreateSenderCall(const Call::Config& config);
65 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020066 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000067
Stefan Holmer9fea80f2016-01-07 17:43:18 +010068 void CreateSendConfig(size_t num_video_streams,
69 size_t num_audio_streams,
70 Transport* send_transport);
pbos2d566682015-09-28 09:59:31 -070071 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000072
perkj3b703ed2016-09-29 23:25:40 -070073 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock, float speed);
74 void CreateFrameGeneratorCapturer();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010075 void CreateFakeAudioDevices();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000076
Stefan Holmer9fea80f2016-01-07 17:43:18 +010077 void CreateVideoStreams();
78 void CreateAudioStreams();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000079 void Start();
80 void Stop();
81 void DestroyStreams();
Perba7dc722016-04-19 15:01:23 +020082 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000083
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000084 Clock* const clock_;
85
kwibergbfefb032016-05-01 14:53:46 -070086 std::unique_ptr<Call> sender_call_;
87 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -080088 VideoSendStream::Config video_send_config_;
89 VideoEncoderConfig video_encoder_config_;
90 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010091 AudioSendStream::Config audio_send_config_;
92 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000093
kwibergbfefb032016-05-01 14:53:46 -070094 std::unique_ptr<Call> receiver_call_;
95 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -080096 std::vector<VideoReceiveStream::Config> video_receive_configs_;
97 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010098 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
99 std::vector<AudioReceiveStream*> audio_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000100
kwibergbfefb032016-05-01 14:53:46 -0700101 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000102 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 10:24:26 -0700103 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100104 size_t num_video_streams_;
105 size_t num_audio_streams_;
ossu29b1a8d2016-06-13 07:34:51 -0700106 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
sakal55d932b2016-09-30 06:19:08 -0700107 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100108
109 private:
110 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
111 // These methods are used to set up legacy voice engines and channels which is
112 // necessary while voice engine is being refactored to the new stream API.
113 struct VoiceEngineState {
114 VoiceEngineState()
115 : voice_engine(nullptr),
116 base(nullptr),
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100117 codec(nullptr),
mflodman3d7db262016-04-29 00:57:13 -0700118 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100119
120 VoiceEngine* voice_engine;
121 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100122 VoECodec* codec;
123 int channel_id;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100124 };
125
126 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100127 void DestroyVoiceEngines();
128
129 VoiceEngineState voe_send_;
130 VoiceEngineState voe_recv_;
131
132 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 14:53:46 -0700133 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
134 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000135};
136
137class BaseTest : public RtpRtcpObserver {
138 public:
139 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000140 virtual ~BaseTest();
141
142 virtual void PerformTest() = 0;
143 virtual bool ShouldCreateReceivers() const = 0;
144
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100145 virtual size_t GetNumVideoStreams() const;
146 virtual size_t GetNumAudioStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000147
148 virtual Call::Config GetSenderCallConfig();
149 virtual Call::Config GetReceiverCallConfig();
150 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800151
152 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
153 virtual test::PacketTransport* CreateReceiveTransport();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000154
stefanff483612015-12-21 03:14:00 -0800155 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000156 VideoSendStream::Config* send_config,
157 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000158 VideoEncoderConfig* encoder_config);
stefanff483612015-12-21 03:14:00 -0800159 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000160 VideoSendStream* send_stream,
161 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000162
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100163 virtual void ModifyAudioConfigs(
164 AudioSendStream::Config* send_config,
165 std::vector<AudioReceiveStream::Config>* receive_configs);
166 virtual void OnAudioStreamsCreated(
167 AudioSendStream* send_stream,
168 const std::vector<AudioReceiveStream*>& receive_streams);
169
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000170 virtual void OnFrameGeneratorCapturerCreated(
171 FrameGeneratorCapturer* frame_generator_capturer);
172};
173
174class SendTest : public BaseTest {
175 public:
176 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000177
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000178 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000179};
180
181class EndToEndTest : public BaseTest {
182 public:
183 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000184
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000185 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000186};
187
188} // namespace test
189} // namespace webrtc
190
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100191#endif // WEBRTC_TEST_CALL_TEST_H_