blob: eb33c0f1c40055cb9d859b82140dfb3ca38fb662 [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/call/transport_adapter.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;
28class VoENetwork;
29
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;
40
Peter Boström5811a392015-12-10 13:02:50 +010041 static const int kDefaultTimeoutMs;
42 static const int kLongTimeoutMs;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010043 static const uint8_t kVideoSendPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000044 static const uint8_t kSendRtxPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010045 static const uint8_t kFakeVideoSendPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000046 static const uint8_t kRedPayloadType;
Shao Changbine62202f2015-04-21 20:24:50 +080047 static const uint8_t kRtxRedPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +000048 static const uint8_t kUlpfecPayloadType;
Stefan Holmer9fea80f2016-01-07 17:43:18 +010049 static const uint8_t kAudioSendPayloadType;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000050 static const uint32_t kSendRtxSsrcs[kNumSsrcs];
Stefan Holmer9fea80f2016-01-07 17:43:18 +010051 static const uint32_t kVideoSendSsrcs[kNumSsrcs];
52 static const uint32_t kAudioSendSsrc;
53 static const uint32_t kReceiverLocalVideoSsrc;
54 static const uint32_t kReceiverLocalAudioSsrc;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000055 static const int kNackRtpHistoryMs;
56
57 protected:
Stefan Holmer9fea80f2016-01-07 17:43:18 +010058 // RunBaseTest overwrites the audio_state and the voice_engine of the send and
59 // receive Call configs to simplify test code and avoid having old VoiceEngine
60 // APIs in the tests.
stefane74eef12016-01-08 06:47:13 -080061 void RunBaseTest(BaseTest* test);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000062
63 void CreateCalls(const Call::Config& sender_config,
64 const Call::Config& receiver_config);
65 void CreateSenderCall(const Call::Config& config);
66 void CreateReceiverCall(const Call::Config& config);
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020067 void DestroyCalls();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000068
Stefan Holmer9fea80f2016-01-07 17:43:18 +010069 void CreateSendConfig(size_t num_video_streams,
70 size_t num_audio_streams,
71 Transport* send_transport);
pbos2d566682015-09-28 09:59:31 -070072 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000073
danilchap9c6a0c72016-02-10 10:54:47 -080074 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock, float speed);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000075 void CreateFrameGeneratorCapturer();
Stefan Holmer9fea80f2016-01-07 17:43:18 +010076 void CreateFakeAudioDevices();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000077
Stefan Holmer9fea80f2016-01-07 17:43:18 +010078 void CreateVideoStreams();
79 void CreateAudioStreams();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000080 void Start();
81 void Stop();
82 void DestroyStreams();
83
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000084 Clock* const clock_;
85
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000086 rtc::scoped_ptr<Call> sender_call_;
stefanf116bd02015-10-27 08:29:42 -070087 rtc::scoped_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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000094 rtc::scoped_ptr<Call> receiver_call_;
stefanf116bd02015-10-27 08:29:42 -070095 rtc::scoped_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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000101 rtc::scoped_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_;
106
107 private:
108 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
109 // These methods are used to set up legacy voice engines and channels which is
110 // necessary while voice engine is being refactored to the new stream API.
111 struct VoiceEngineState {
112 VoiceEngineState()
113 : voice_engine(nullptr),
114 base(nullptr),
115 network(nullptr),
116 codec(nullptr),
117 channel_id(-1),
118 transport_adapter(nullptr) {}
119
120 VoiceEngine* voice_engine;
121 VoEBase* base;
122 VoENetwork* network;
123 VoECodec* codec;
124 int channel_id;
125 rtc::scoped_ptr<internal::TransportAdapter> transport_adapter;
126 };
127
128 void CreateVoiceEngines();
129 void SetupVoiceEngineTransports(PacketTransport* send_transport,
130 PacketTransport* recv_transport);
131 void DestroyVoiceEngines();
132
133 VoiceEngineState voe_send_;
134 VoiceEngineState voe_recv_;
135
136 // The audio devices must outlive the voice engines.
137 rtc::scoped_ptr<test::FakeAudioDevice> fake_send_audio_device_;
138 rtc::scoped_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000139};
140
141class BaseTest : public RtpRtcpObserver {
142 public:
143 explicit BaseTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000144 virtual ~BaseTest();
145
146 virtual void PerformTest() = 0;
147 virtual bool ShouldCreateReceivers() const = 0;
148
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100149 virtual size_t GetNumVideoStreams() const;
150 virtual size_t GetNumAudioStreams() const;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000151
152 virtual Call::Config GetSenderCallConfig();
153 virtual Call::Config GetReceiverCallConfig();
154 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
stefane74eef12016-01-08 06:47:13 -0800155
156 virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
157 virtual test::PacketTransport* CreateReceiveTransport();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000158
stefanff483612015-12-21 03:14:00 -0800159 virtual void ModifyVideoConfigs(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000160 VideoSendStream::Config* send_config,
161 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000162 VideoEncoderConfig* encoder_config);
stefanff483612015-12-21 03:14:00 -0800163 virtual void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000164 VideoSendStream* send_stream,
165 const std::vector<VideoReceiveStream*>& receive_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000166
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100167 virtual void ModifyAudioConfigs(
168 AudioSendStream::Config* send_config,
169 std::vector<AudioReceiveStream::Config>* receive_configs);
170 virtual void OnAudioStreamsCreated(
171 AudioSendStream* send_stream,
172 const std::vector<AudioReceiveStream*>& receive_streams);
173
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000174 virtual void OnFrameGeneratorCapturerCreated(
175 FrameGeneratorCapturer* frame_generator_capturer);
176};
177
178class SendTest : public BaseTest {
179 public:
180 explicit SendTest(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
185class EndToEndTest : public BaseTest {
186 public:
187 explicit EndToEndTest(unsigned int timeout_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000188
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000189 bool ShouldCreateReceivers() const override;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000190};
191
192} // namespace test
193} // namespace webrtc
194
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100195#endif // WEBRTC_TEST_CALL_TEST_H_