blob: f8d52aca9ed1b861d28a2b40d64c892bfcc6474d [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"
perkj26105b42016-09-29 22:39:10 -070017#include "webrtc/test/encoder_settings.h"
Stefan Holmer9fea80f2016-01-07 17:43:18 +010018#include "webrtc/test/fake_audio_device.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000019#include "webrtc/test/fake_decoder.h"
20#include "webrtc/test/fake_encoder.h"
21#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;
perkj26105b42016-09-29 22:39:10 -070039 static const int kDefaultWidth = 320;
40 static const int kDefaultHeight = 180;
41 static const int kDefaultFramerate = 30;
Peter Boström5811a392015-12-10 13:02:50 +010042 static const int kDefaultTimeoutMs;
43 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010044 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000045 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010046 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000047 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 20:24:50 +080048 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000049 static const uint8_t kUlpfecPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010050 static const uint8_t kAudioSendPayloadType;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000051 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010052 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
53 static const uint32_t kAudioSendSsrc;
54 static const uint32_t kReceiverLocalVideoSsrc;
55 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000056 static const int kNackRtpHistoryMs;
57
58 protected:
Stefan Holmer9fea80f2016-01-07 17:43:18 +010059 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
60 // receive Call configs to simplify test code and avoid having old VoiceEngine
61 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080062 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000063
64 void CreateCalls(const Call::Config& sender_config,
65 const Call::Config& receiver_config);
66 void CreateSenderCall(const Call::Config& config);
67 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020068 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000069
Stefan Holmer9fea80f2016-01-07 17:43:18 +010070 void CreateSendConfig(size_t num_video_streams,
71 size_t num_audio_streams,
72 Transport* send_transport);
pbos2d566682015-09-28 09:59:31 -070073 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000074
perkj26105b42016-09-29 22:39:10 -070075 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
76 float speed,
77 int framerate,
78 int width,
79 int height);
80 void CreateFrameGeneratorCapturer(int framerate, int width, int height);
Stefan Holmer9fea80f2016-01-07 17:43:18 +010081 void CreateFakeAudioDevices();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000082
Stefan Holmer9fea80f2016-01-07 17:43:18 +010083 void CreateVideoStreams();
84 void CreateAudioStreams();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000085 void Start();
86 void Stop();
87 void DestroyStreams();
Perba7dc722016-04-19 15:01:23 +020088 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000089
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000090 Clock* const clock_;
91
kwibergbfefb032016-05-01 14:53:46 -070092 std::unique_ptr<Call> sender_call_;
93 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -080094 VideoSendStream::Config video_send_config_;
95 VideoEncoderConfig video_encoder_config_;
96 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010097 AudioSendStream::Config audio_send_config_;
98 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000099
kwibergbfefb032016-05-01 14:53:46 -0700100 std::unique_ptr<Call> receiver_call_;
101 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -0800102 std::vector<VideoReceiveStream::Config> video_receive_configs_;
103 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100104 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
105 std::vector<AudioReceiveStream*> audio_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000106
kwibergbfefb032016-05-01 14:53:46 -0700107 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000108 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 10:24:26 -0700109 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100110 size_t num_video_streams_;
111 size_t num_audio_streams_;
ossu29b1a8d2016-06-13 07:34:51 -0700112 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100113
114 private:
115 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
116 // These methods are used to set up legacy voice engines and channels which is
117 // necessary while voice engine is being refactored to the new stream API.
118 struct VoiceEngineState {
119 VoiceEngineState()
120 : voice_engine(nullptr),
121 base(nullptr),
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100122 codec(nullptr),
mflodman3d7db262016-04-29 00:57:13 -0700123 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100124
125 VoiceEngine* voice_engine;
126 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100127 VoECodec* codec;
128 int channel_id;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100129 };
130
131 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100132 void DestroyVoiceEngines();
133
134 VoiceEngineState voe_send_;
135 VoiceEngineState voe_recv_;
136
137 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 14:53:46 -0700138 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
139 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000140};
141
142class BaseTest : public RtpRtcpObserver {
143 public:
144 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000145 virtual ~BaseTest();
146
147 virtual void PerformTest() = 0;
148 virtual bool ShouldCreateReceivers() const = 0;
149
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100150 virtual size_t GetNumVideoStreams() const;
151 virtual size_t GetNumAudioStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000152
153 virtual Call::Config GetSenderCallConfig();
154 virtual Call::Config GetReceiverCallConfig();
155 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800156
157 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
158 virtual test::PacketTransport* CreateReceiveTransport();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000159
stefanff483612015-12-21 03:14:00 -0800160 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000161 VideoSendStream::Config* send_config,
162 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000163 VideoEncoderConfig* encoder_config);
perkj26105b42016-09-29 22:39:10 -0700164 virtual void ModifyVideoCaptureStartResolution(int* width,
165 int* heigt,
166 int* frame_rate);
stefanff483612015-12-21 03:14:00 -0800167 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000168 VideoSendStream* send_stream,
169 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000170
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100171 virtual void ModifyAudioConfigs(
172 AudioSendStream::Config* send_config,
173 std::vector<AudioReceiveStream::Config>* receive_configs);
174 virtual void OnAudioStreamsCreated(
175 AudioSendStream* send_stream,
176 const std::vector<AudioReceiveStream*>& receive_streams);
177
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000178 virtual void OnFrameGeneratorCapturerCreated(
179 FrameGeneratorCapturer* frame_generator_capturer);
180};
181
182class SendTest : public BaseTest {
183 public:
184 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000185
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000186 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000187};
188
189class EndToEndTest : public BaseTest {
190 public:
191 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000192
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000193 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000194};
195
196} // namespace test
197} // namespace webrtc
198
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100199#endif // WEBRTC_TEST_CALL_TEST_H_