blob: ebc2bb2a544d78a60f2f26de90d7b3de0a1201e2 [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"
20#include "webrtc/test/frame_generator_capturer.h"
21#include "webrtc/test/rtp_rtcp_observer.h"
22
23namespace webrtc {
Stefan Holmer9fea80f2016-01-07 17:43:18 +010024
25class VoEBase;
26class VoECodec;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010027
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000028namespace test {
29
30class BaseTest;
31
32class CallTest : public ::testing::Test {
33 public:
34 CallTest();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010035 virtual ~CallTest();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000036
37 static const size_t kNumSsrcs = 3;
38
Peter Boström5811a392015-12-10 13:02:50 +010039 static const int kDefaultTimeoutMs;
40 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010041 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000042 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010043 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000044 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 20:24:50 +080045 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000046 static const uint8_t kUlpfecPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010047 static const uint8_t kAudioSendPayloadType;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000048 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010049 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
50 static const uint32_t kAudioSendSsrc;
51 static const uint32_t kReceiverLocalVideoSsrc;
52 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000053 static const int kNackRtpHistoryMs;
54
55 protected:
Stefan Holmer9fea80f2016-01-07 17:43:18 +010056 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
57 // receive Call configs to simplify test code and avoid having old VoiceEngine
58 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080059 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000060
61 void CreateCalls(const Call::Config& sender_config,
62 const Call::Config& receiver_config);
63 void CreateSenderCall(const Call::Config& config);
64 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020065 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000066
Stefan Holmer9fea80f2016-01-07 17:43:18 +010067 void CreateSendConfig(size_t num_video_streams,
68 size_t num_audio_streams,
69 Transport* send_transport);
pbos2d566682015-09-28 09:59:31 -070070 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000071
danilchap9c6a0c72016-02-10 10:54:47 -080072 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock, float speed);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000073 void CreateFrameGeneratorCapturer();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010074 void CreateFakeAudioDevices();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000075
Stefan Holmer9fea80f2016-01-07 17:43:18 +010076 void CreateVideoStreams();
77 void CreateAudioStreams();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000078 void Start();
79 void Stop();
80 void DestroyStreams();
Perba7dc722016-04-19 15:01:23 +020081 void SetFakeVideoCaptureRotation(VideoRotation rotation);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000082
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000083 Clock* const clock_;
84
kwibergbfefb032016-05-01 14:53:46 -070085 std::unique_ptr<Call> sender_call_;
86 std::unique_ptr<PacketTransport> send_transport_;
stefanff483612015-12-21 03:14:00 -080087 VideoSendStream::Config video_send_config_;
88 VideoEncoderConfig video_encoder_config_;
89 VideoSendStream* video_send_stream_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010090 AudioSendStream::Config audio_send_config_;
91 AudioSendStream* audio_send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000092
kwibergbfefb032016-05-01 14:53:46 -070093 std::unique_ptr<Call> receiver_call_;
94 std::unique_ptr<PacketTransport> receive_transport_;
stefanff483612015-12-21 03:14:00 -080095 std::vector<VideoReceiveStream::Config> video_receive_configs_;
96 std::vector<VideoReceiveStream*> video_receive_streams_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010097 std::vector<AudioReceiveStream::Config> audio_receive_configs_;
98 std::vector<AudioReceiveStream*> audio_receive_streams_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000099
kwibergbfefb032016-05-01 14:53:46 -0700100 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000101 test::FakeEncoder fake_encoder_;
kwiberg4a206a92016-03-31 10:24:26 -0700102 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100103 size_t num_video_streams_;
104 size_t num_audio_streams_;
105
106 private:
107 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
108 // These methods are used to set up legacy voice engines and channels which is
109 // necessary while voice engine is being refactored to the new stream API.
110 struct VoiceEngineState {
111 VoiceEngineState()
112 : voice_engine(nullptr),
113 base(nullptr),
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100114 codec(nullptr),
mflodman3d7db262016-04-29 00:57:13 -0700115 channel_id(-1) {}
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100116
117 VoiceEngine* voice_engine;
118 VoEBase* base;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100119 VoECodec* codec;
120 int channel_id;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100121 };
122
123 void CreateVoiceEngines();
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100124 void DestroyVoiceEngines();
125
126 VoiceEngineState voe_send_;
127 VoiceEngineState voe_recv_;
128
129 // The audio devices must outlive the voice engines.
kwibergbfefb032016-05-01 14:53:46 -0700130 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_;
131 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000132};
133
134class BaseTest : public RtpRtcpObserver {
135 public:
136 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000137 virtual ~BaseTest();
138
139 virtual void PerformTest() = 0;
140 virtual bool ShouldCreateReceivers() const = 0;
141
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100142 virtual size_t GetNumVideoStreams() const;
143 virtual size_t GetNumAudioStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000144
145 virtual Call::Config GetSenderCallConfig();
146 virtual Call::Config GetReceiverCallConfig();
147 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800148
149 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
150 virtual test::PacketTransport* CreateReceiveTransport();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000151
stefanff483612015-12-21 03:14:00 -0800152 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000153 VideoSendStream::Config* send_config,
154 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000155 VideoEncoderConfig* encoder_config);
stefanff483612015-12-21 03:14:00 -0800156 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000157 VideoSendStream* send_stream,
158 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000159
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100160 virtual void ModifyAudioConfigs(
161 AudioSendStream::Config* send_config,
162 std::vector<AudioReceiveStream::Config>* receive_configs);
163 virtual void OnAudioStreamsCreated(
164 AudioSendStream* send_stream,
165 const std::vector<AudioReceiveStream*>& receive_streams);
166
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000167 virtual void OnFrameGeneratorCapturerCreated(
168 FrameGeneratorCapturer* frame_generator_capturer);
169};
170
171class SendTest : public BaseTest {
172 public:
173 explicit SendTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000174
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000175 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000176};
177
178class EndToEndTest : public BaseTest {
179 public:
180 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000181
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000182 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000183};
184
185} // namespace test
186} // namespace webrtc
187
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100188#endif // WEBRTC_TEST_CALL_TEST_H_