1 /*
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 */
10 #include "webrtc/test/call_test.h"
11
12 #include "webrtc/test/encoder_settings.h"
13
14 namespace webrtc {
15 namespace test {
16
CallTest()17 CallTest::CallTest()
18 : clock_(Clock::GetRealTimeClock()),
19 send_stream_(NULL),
20 fake_encoder_(clock_) {
21 }
~CallTest()22 CallTest::~CallTest() {
23 }
24
RunBaseTest(BaseTest * test)25 void CallTest::RunBaseTest(BaseTest* test) {
26 CreateSenderCall(test->GetSenderCallConfig());
27 if (test->ShouldCreateReceivers())
28 CreateReceiverCall(test->GetReceiverCallConfig());
29 test->OnCallsCreated(sender_call_.get(), receiver_call_.get());
30
31 if (test->ShouldCreateReceivers()) {
32 test->SetReceivers(receiver_call_->Receiver(), sender_call_->Receiver());
33 } else {
34 // Sender-only call delivers to itself.
35 test->SetReceivers(sender_call_->Receiver(), NULL);
36 }
37
38 CreateSendConfig(test->GetNumStreams());
39 if (test->ShouldCreateReceivers()) {
40 CreateMatchingReceiveConfigs();
41 }
42 test->ModifyConfigs(&send_config_, &receive_configs_, &encoder_config_);
43 CreateStreams();
44 test->OnStreamsCreated(send_stream_, receive_streams_);
45
46 CreateFrameGeneratorCapturer();
47 test->OnFrameGeneratorCapturerCreated(frame_generator_capturer_.get());
48
49 Start();
50 test->PerformTest();
51 test->StopSending();
52 Stop();
53
54 DestroyStreams();
55 }
56
Start()57 void CallTest::Start() {
58 send_stream_->Start();
59 for (size_t i = 0; i < receive_streams_.size(); ++i)
60 receive_streams_[i]->Start();
61 if (frame_generator_capturer_.get() != NULL)
62 frame_generator_capturer_->Start();
63 }
64
Stop()65 void CallTest::Stop() {
66 if (frame_generator_capturer_.get() != NULL)
67 frame_generator_capturer_->Stop();
68 for (size_t i = 0; i < receive_streams_.size(); ++i)
69 receive_streams_[i]->Stop();
70 send_stream_->Stop();
71 }
72
CreateCalls(const Call::Config & sender_config,const Call::Config & receiver_config)73 void CallTest::CreateCalls(const Call::Config& sender_config,
74 const Call::Config& receiver_config) {
75 CreateSenderCall(sender_config);
76 CreateReceiverCall(receiver_config);
77 }
78
CreateSenderCall(const Call::Config & config)79 void CallTest::CreateSenderCall(const Call::Config& config) {
80 sender_call_.reset(Call::Create(config));
81 }
82
CreateReceiverCall(const Call::Config & config)83 void CallTest::CreateReceiverCall(const Call::Config& config) {
84 receiver_call_.reset(Call::Create(config));
85 }
86
CreateSendConfig(size_t num_streams)87 void CallTest::CreateSendConfig(size_t num_streams) {
88 assert(num_streams <= kNumSsrcs);
89 send_config_ = VideoSendStream::Config();
90 send_config_.encoder_settings.encoder = &fake_encoder_;
91 send_config_.encoder_settings.payload_name = "FAKE";
92 send_config_.encoder_settings.payload_type = kFakeSendPayloadType;
93 encoder_config_.streams = test::CreateVideoStreams(num_streams);
94 for (size_t i = 0; i < num_streams; ++i)
95 send_config_.rtp.ssrcs.push_back(kSendSsrcs[i]);
96 }
97
CreateMatchingReceiveConfigs()98 void CallTest::CreateMatchingReceiveConfigs() {
99 assert(!send_config_.rtp.ssrcs.empty());
100 assert(receive_configs_.empty());
101 assert(fake_decoders_.empty());
102 VideoReceiveStream::Config config;
103 VideoCodec codec =
104 test::CreateDecoderVideoCodec(send_config_.encoder_settings);
105 config.codecs.push_back(codec);
106 config.rtp.local_ssrc = kReceiverLocalSsrc;
107 if (send_config_.encoder_settings.encoder == &fake_encoder_) {
108 config.external_decoders.resize(1);
109 config.external_decoders[0].payload_type =
110 send_config_.encoder_settings.payload_type;
111 }
112 for (size_t i = 0; i < send_config_.rtp.ssrcs.size(); ++i) {
113 if (send_config_.encoder_settings.encoder == &fake_encoder_) {
114 FakeDecoder* decoder = new FakeDecoder();
115 fake_decoders_.push_back(decoder);
116 config.external_decoders[0].decoder = decoder;
117 }
118 config.rtp.remote_ssrc = send_config_.rtp.ssrcs[i];
119 receive_configs_.push_back(config);
120 }
121 }
122
CreateFrameGeneratorCapturer()123 void CallTest::CreateFrameGeneratorCapturer() {
124 VideoStream stream = encoder_config_.streams.back();
125 frame_generator_capturer_.reset(
126 test::FrameGeneratorCapturer::Create(send_stream_->Input(),
127 stream.width,
128 stream.height,
129 stream.max_framerate,
130 clock_));
131 }
CreateStreams()132 void CallTest::CreateStreams() {
133 assert(send_stream_ == NULL);
134 assert(receive_streams_.empty());
135
136 send_stream_ =
137 sender_call_->CreateVideoSendStream(send_config_, encoder_config_);
138
139 for (size_t i = 0; i < receive_configs_.size(); ++i) {
140 receive_streams_.push_back(
141 receiver_call_->CreateVideoReceiveStream(receive_configs_[i]));
142 }
143 }
144
DestroyStreams()145 void CallTest::DestroyStreams() {
146 if (send_stream_ != NULL)
147 sender_call_->DestroyVideoSendStream(send_stream_);
148 send_stream_ = NULL;
149 for (size_t i = 0; i < receive_streams_.size(); ++i)
150 receiver_call_->DestroyVideoReceiveStream(receive_streams_[i]);
151 receive_streams_.clear();
152 fake_decoders_.clear();
153 }
154
155 const unsigned int CallTest::kDefaultTimeoutMs = 30 * 1000;
156 const unsigned int CallTest::kLongTimeoutMs = 120 * 1000;
157 const uint8_t CallTest::kSendPayloadType = 100;
158 const uint8_t CallTest::kFakeSendPayloadType = 125;
159 const uint8_t CallTest::kSendRtxPayloadType = 98;
160 const uint8_t CallTest::kRedPayloadType = 118;
161 const uint8_t CallTest::kUlpfecPayloadType = 119;
162 const uint32_t CallTest::kSendRtxSsrcs[kNumSsrcs] = {0xBADCAFD, 0xBADCAFE,
163 0xBADCAFF};
164 const uint32_t CallTest::kSendSsrcs[kNumSsrcs] = {0xC0FFED, 0xC0FFEE, 0xC0FFEF};
165 const uint32_t CallTest::kReceiverLocalSsrc = 0x123456;
166 const int CallTest::kNackRtpHistoryMs = 1000;
167
BaseTest(unsigned int timeout_ms)168 BaseTest::BaseTest(unsigned int timeout_ms) : RtpRtcpObserver(timeout_ms) {
169 }
170
BaseTest(unsigned int timeout_ms,const FakeNetworkPipe::Config & config)171 BaseTest::BaseTest(unsigned int timeout_ms,
172 const FakeNetworkPipe::Config& config)
173 : RtpRtcpObserver(timeout_ms, config) {
174 }
175
~BaseTest()176 BaseTest::~BaseTest() {
177 }
178
GetSenderCallConfig()179 Call::Config BaseTest::GetSenderCallConfig() {
180 return Call::Config(SendTransport());
181 }
182
GetReceiverCallConfig()183 Call::Config BaseTest::GetReceiverCallConfig() {
184 return Call::Config(ReceiveTransport());
185 }
186
OnCallsCreated(Call * sender_call,Call * receiver_call)187 void BaseTest::OnCallsCreated(Call* sender_call, Call* receiver_call) {
188 }
189
GetNumStreams() const190 size_t BaseTest::GetNumStreams() const {
191 return 1;
192 }
193
ModifyConfigs(VideoSendStream::Config * send_config,std::vector<VideoReceiveStream::Config> * receive_configs,VideoEncoderConfig * encoder_config)194 void BaseTest::ModifyConfigs(
195 VideoSendStream::Config* send_config,
196 std::vector<VideoReceiveStream::Config>* receive_configs,
197 VideoEncoderConfig* encoder_config) {
198 }
199
OnStreamsCreated(VideoSendStream * send_stream,const std::vector<VideoReceiveStream * > & receive_streams)200 void BaseTest::OnStreamsCreated(
201 VideoSendStream* send_stream,
202 const std::vector<VideoReceiveStream*>& receive_streams) {
203 }
204
OnFrameGeneratorCapturerCreated(FrameGeneratorCapturer * frame_generator_capturer)205 void BaseTest::OnFrameGeneratorCapturerCreated(
206 FrameGeneratorCapturer* frame_generator_capturer) {
207 }
208
SendTest(unsigned int timeout_ms)209 SendTest::SendTest(unsigned int timeout_ms) : BaseTest(timeout_ms) {
210 }
211
SendTest(unsigned int timeout_ms,const FakeNetworkPipe::Config & config)212 SendTest::SendTest(unsigned int timeout_ms,
213 const FakeNetworkPipe::Config& config)
214 : BaseTest(timeout_ms, config) {
215 }
216
ShouldCreateReceivers() const217 bool SendTest::ShouldCreateReceivers() const {
218 return false;
219 }
220
EndToEndTest(unsigned int timeout_ms)221 EndToEndTest::EndToEndTest(unsigned int timeout_ms) : BaseTest(timeout_ms) {
222 }
223
EndToEndTest(unsigned int timeout_ms,const FakeNetworkPipe::Config & config)224 EndToEndTest::EndToEndTest(unsigned int timeout_ms,
225 const FakeNetworkPipe::Config& config)
226 : BaseTest(timeout_ms, config) {
227 }
228
ShouldCreateReceivers() const229 bool EndToEndTest::ShouldCreateReceivers() const {
230 return true;
231 }
232
233 } // namespace test
234 } // namespace webrtc
235