blob: ff847826020bde4e71df3832e116a729cd673292 [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"
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;
29class VoECodec;
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;
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;
56 static const uint32_t kReceiverLocalVideoSsrc;
57 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000058 static const int kNackRtpHistoryMs;
59
60 protected:
Stefan Holmer9fea80f2016-01-07 17:43:18 +010061 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
62 // receive Call configs to simplify test code and avoid having old VoiceEngine
63 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080064 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000065
66 void CreateCalls(const Call::Config& sender_config,
67 const Call::Config& receiver_config);
68 void CreateSenderCall(const Call::Config& config);
69 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020070 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000071
Stefan Holmer9fea80f2016-01-07 17:43:18 +010072 void CreateSendConfig(size_t num_video_streams,
73 size_t num_audio_streams,
74 Transport* send_transport);
pbos2d566682015-09-28 09:59:31 -070075 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000076
perkjfa10b552016-10-02 23:45:26 -070077 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
78 float speed,
79 int framerate,
80 int width,
81 int height);
82 void CreateFrameGeneratorCapturer(int framerate, int width, int height);
Stefan Holmer9fea80f2016-01-07 17:43:18 +010083 void CreateFakeAudioDevices();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000084
Stefan Holmer9fea80f2016-01-07 17:43:18 +010085 void CreateVideoStreams();
86 void CreateAudioStreams();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000087 void Start();
88 void Stop();
89 void DestroyStreams();
Perba7dc722016-04-19 15:01:23 +020090 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000091
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000092 Clock* const clock_;
93
skvlad11a9cbf2016-10-07 11:53:05 -070094 webrtc::RtcEventLogNullImpl event_log_;
kwibergbfefb032016-05-01 14:53:46 -070095 std::unique_ptr<Call> sender_call_;
96 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -080097 VideoSendStream::Config video_send_config_;
98 VideoEncoderConfig video_encoder_config_;
99 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100100 AudioSendStream::Config audio_send_config_;
101 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000102
kwibergbfefb032016-05-01 14:53:46 -0700103 std::unique_ptr<Call> receiver_call_;
104 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -0800105 std::vector<VideoReceiveStream::Config> video_receive_configs_;
106 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100107 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
108 std::vector<AudioReceiveStream*> audio_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000109
kwibergbfefb032016-05-01 14:53:46 -0700110 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000111 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 10:24:26 -0700112 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100113 size_t num_video_streams_;
114 size_t num_audio_streams_;
ossu29b1a8d2016-06-13 07:34:51 -0700115 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
sakal55d932b2016-09-30 06:19:08 -0700116 test::FakeVideoRenderer fake_renderer_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100117
118 private:
119 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
120 // These methods are used to set up legacy voice engines and channels which is
121 // necessary while voice engine is being refactored to the new stream API.
122 struct VoiceEngineState {
123 VoiceEngineState()
124 : voice_engine(nullptr),
125 base(nullptr),
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100126 codec(nullptr),
mflodman3d7db262016-04-29 00:57:13 -0700127 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100128
129 VoiceEngine* voice_engine;
130 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100131 VoECodec* codec;
132 int channel_id;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100133 };
134
135 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100136 void DestroyVoiceEngines();
137
138 VoiceEngineState voe_send_;
139 VoiceEngineState voe_recv_;
140
141 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 14:53:46 -0700142 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
143 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000144};
145
146class BaseTest : public RtpRtcpObserver {
147 public:
148 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000149 virtual ~BaseTest();
150
151 virtual void PerformTest() = 0;
152 virtual bool ShouldCreateReceivers() const = 0;
153
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100154 virtual size_t GetNumVideoStreams() const;
155 virtual size_t GetNumAudioStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000156
157 virtual Call::Config GetSenderCallConfig();
158 virtual Call::Config GetReceiverCallConfig();
159 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800160
161 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
162 virtual test::PacketTransport* CreateReceiveTransport();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000163
stefanff483612015-12-21 03:14:00 -0800164 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000165 VideoSendStream::Config* send_config,
166 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000167 VideoEncoderConfig* encoder_config);
perkjfa10b552016-10-02 23:45:26 -0700168 virtual void ModifyVideoCaptureStartResolution(int* width,
169 int* heigt,
170 int* frame_rate);
stefanff483612015-12-21 03:14:00 -0800171 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000172 VideoSendStream* send_stream,
173 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000174
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100175 virtual void ModifyAudioConfigs(
176 AudioSendStream::Config* send_config,
177 std::vector<AudioReceiveStream::Config>* receive_configs);
178 virtual void OnAudioStreamsCreated(
179 AudioSendStream* send_stream,
180 const std::vector<AudioReceiveStream*>& receive_streams);
181
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000182 virtual void OnFrameGeneratorCapturerCreated(
183 FrameGeneratorCapturer* frame_generator_capturer);
skvlad11a9cbf2016-10-07 11:53:05 -0700184
185 webrtc::RtcEventLogNullImpl event_log_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000186};
187
188class SendTest : public BaseTest {
189 public:
190 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000191
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000192 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000193};
194
195class EndToEndTest : public BaseTest {
196 public:
197 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000198
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000199 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000200};
201
202} // namespace test
203} // namespace webrtc
204
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100205#endif // WEBRTC_TEST_CALL_TEST_H_