blob: 9e78e82d7ffc920c91ce29de67415fc34e641aec [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 */
10#include "webrtc/test/call_test.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000011#include "webrtc/test/encoder_settings.h"
12
13namespace webrtc {
14namespace test {
15
Guo-wei Shieh2c370782015-04-08 13:00:10 -070016namespace {
17const int kVideoRotationRtpExtensionId = 4;
18}
19
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000020CallTest::CallTest()
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000021 : clock_(Clock::GetRealTimeClock()),
22 send_stream_(NULL),
23 fake_encoder_(clock_) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000024}
pbos@webrtc.org32452b22014-10-22 12:15:24 +000025
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000026CallTest::~CallTest() {
27}
28
29void CallTest::RunBaseTest(BaseTest* test) {
30 CreateSenderCall(test->GetSenderCallConfig());
31 if (test->ShouldCreateReceivers())
32 CreateReceiverCall(test->GetReceiverCallConfig());
33 test->OnCallsCreated(sender_call_.get(), receiver_call_.get());
34
35 if (test->ShouldCreateReceivers()) {
36 test->SetReceivers(receiver_call_->Receiver(), sender_call_->Receiver());
37 } else {
38 // Sender-only call delivers to itself.
39 test->SetReceivers(sender_call_->Receiver(), NULL);
40 }
41
42 CreateSendConfig(test->GetNumStreams());
43 if (test->ShouldCreateReceivers()) {
44 CreateMatchingReceiveConfigs();
45 }
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +000046 test->ModifyConfigs(&send_config_, &receive_configs_, &encoder_config_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000047 CreateStreams();
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +000048 test->OnStreamsCreated(send_stream_, receive_streams_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000049
50 CreateFrameGeneratorCapturer();
51 test->OnFrameGeneratorCapturerCreated(frame_generator_capturer_.get());
52
53 Start();
54 test->PerformTest();
55 test->StopSending();
56 Stop();
57
58 DestroyStreams();
59}
60
61void CallTest::Start() {
62 send_stream_->Start();
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +000063 for (size_t i = 0; i < receive_streams_.size(); ++i)
64 receive_streams_[i]->Start();
65 if (frame_generator_capturer_.get() != NULL)
66 frame_generator_capturer_->Start();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000067}
68
69void CallTest::Stop() {
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +000070 if (frame_generator_capturer_.get() != NULL)
71 frame_generator_capturer_->Stop();
72 for (size_t i = 0; i < receive_streams_.size(); ++i)
73 receive_streams_[i]->Stop();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000074 send_stream_->Stop();
75}
76
77void CallTest::CreateCalls(const Call::Config& sender_config,
78 const Call::Config& receiver_config) {
79 CreateSenderCall(sender_config);
80 CreateReceiverCall(receiver_config);
81}
82
83void CallTest::CreateSenderCall(const Call::Config& config) {
84 sender_call_.reset(Call::Create(config));
85}
86
87void CallTest::CreateReceiverCall(const Call::Config& config) {
88 receiver_call_.reset(Call::Create(config));
89}
90
91void CallTest::CreateSendConfig(size_t num_streams) {
92 assert(num_streams <= kNumSsrcs);
pbos@webrtc.orgbd249bc2014-07-07 04:45:15 +000093 send_config_ = VideoSendStream::Config();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000094 send_config_.encoder_settings.encoder = &fake_encoder_;
95 send_config_.encoder_settings.payload_name = "FAKE";
96 send_config_.encoder_settings.payload_type = kFakeSendPayloadType;
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +000097 encoder_config_.streams = test::CreateVideoStreams(num_streams);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000098 for (size_t i = 0; i < num_streams; ++i)
99 send_config_.rtp.ssrcs.push_back(kSendSsrcs[i]);
Guo-wei Shieh2c370782015-04-08 13:00:10 -0700100 send_config_.rtp.extensions.push_back(
101 RtpExtension(RtpExtension::kVideoRotation, kVideoRotationRtpExtensionId));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000102}
103
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000104void CallTest::CreateMatchingReceiveConfigs() {
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000105 assert(!send_config_.rtp.ssrcs.empty());
106 assert(receive_configs_.empty());
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000107 assert(allocated_decoders_.empty());
pbos@webrtc.orgbd249bc2014-07-07 04:45:15 +0000108 VideoReceiveStream::Config config;
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000109 config.rtp.local_ssrc = kReceiverLocalSsrc;
110 for (size_t i = 0; i < send_config_.rtp.ssrcs.size(); ++i) {
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000111 VideoReceiveStream::Decoder decoder =
112 test::CreateMatchingDecoder(send_config_.encoder_settings);
113 allocated_decoders_.push_back(decoder.decoder);
114 config.decoders.clear();
115 config.decoders.push_back(decoder);
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000116 config.rtp.remote_ssrc = send_config_.rtp.ssrcs[i];
117 receive_configs_.push_back(config);
118 }
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000119}
120
121void CallTest::CreateFrameGeneratorCapturer() {
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000122 VideoStream stream = encoder_config_.streams.back();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000123 frame_generator_capturer_.reset(
124 test::FrameGeneratorCapturer::Create(send_stream_->Input(),
125 stream.width,
126 stream.height,
127 stream.max_framerate,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000128 clock_));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000129}
130void CallTest::CreateStreams() {
131 assert(send_stream_ == NULL);
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000132 assert(receive_streams_.empty());
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000133
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000134 send_stream_ =
135 sender_call_->CreateVideoSendStream(send_config_, encoder_config_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000136
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000137 for (size_t i = 0; i < receive_configs_.size(); ++i) {
138 receive_streams_.push_back(
139 receiver_call_->CreateVideoReceiveStream(receive_configs_[i]));
140 }
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000141}
142
143void CallTest::DestroyStreams() {
144 if (send_stream_ != NULL)
145 sender_call_->DestroyVideoSendStream(send_stream_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000146 send_stream_ = NULL;
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000147 for (size_t i = 0; i < receive_streams_.size(); ++i)
148 receiver_call_->DestroyVideoReceiveStream(receive_streams_[i]);
149 receive_streams_.clear();
pbos@webrtc.org776e6f22014-10-29 15:28:39 +0000150 allocated_decoders_.clear();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000151}
152
153const unsigned int CallTest::kDefaultTimeoutMs = 30 * 1000;
154const unsigned int CallTest::kLongTimeoutMs = 120 * 1000;
155const uint8_t CallTest::kSendPayloadType = 100;
156const uint8_t CallTest::kFakeSendPayloadType = 125;
157const uint8_t CallTest::kSendRtxPayloadType = 98;
stefan@webrtc.org01581da2014-09-04 06:48:14 +0000158const uint8_t CallTest::kRedPayloadType = 118;
159const uint8_t CallTest::kUlpfecPayloadType = 119;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000160const uint32_t CallTest::kSendRtxSsrcs[kNumSsrcs] = {0xBADCAFD, 0xBADCAFE,
161 0xBADCAFF};
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000162const uint32_t CallTest::kSendSsrcs[kNumSsrcs] = {0xC0FFED, 0xC0FFEE, 0xC0FFEF};
163const uint32_t CallTest::kReceiverLocalSsrc = 0x123456;
164const int CallTest::kNackRtpHistoryMs = 1000;
165
166BaseTest::BaseTest(unsigned int timeout_ms) : RtpRtcpObserver(timeout_ms) {
167}
168
169BaseTest::BaseTest(unsigned int timeout_ms,
170 const FakeNetworkPipe::Config& config)
171 : RtpRtcpObserver(timeout_ms, config) {
172}
173
174BaseTest::~BaseTest() {
175}
176
177Call::Config BaseTest::GetSenderCallConfig() {
178 return Call::Config(SendTransport());
179}
180
181Call::Config BaseTest::GetReceiverCallConfig() {
182 return Call::Config(ReceiveTransport());
183}
184
185void BaseTest::OnCallsCreated(Call* sender_call, Call* receiver_call) {
186}
187
188size_t BaseTest::GetNumStreams() const {
189 return 1;
190}
191
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000192void BaseTest::ModifyConfigs(
193 VideoSendStream::Config* send_config,
194 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000195 VideoEncoderConfig* encoder_config) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000196}
197
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000198void BaseTest::OnStreamsCreated(
199 VideoSendStream* send_stream,
200 const std::vector<VideoReceiveStream*>& receive_streams) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000201}
202
203void BaseTest::OnFrameGeneratorCapturerCreated(
204 FrameGeneratorCapturer* frame_generator_capturer) {
205}
206
207SendTest::SendTest(unsigned int timeout_ms) : BaseTest(timeout_ms) {
208}
209
210SendTest::SendTest(unsigned int timeout_ms,
211 const FakeNetworkPipe::Config& config)
212 : BaseTest(timeout_ms, config) {
213}
214
215bool SendTest::ShouldCreateReceivers() const {
216 return false;
217}
218
219EndToEndTest::EndToEndTest(unsigned int timeout_ms) : BaseTest(timeout_ms) {
220}
221
222EndToEndTest::EndToEndTest(unsigned int timeout_ms,
223 const FakeNetworkPipe::Config& config)
224 : BaseTest(timeout_ms, config) {
225}
226
227bool EndToEndTest::ShouldCreateReceivers() const {
228 return true;
229}
230
231} // namespace test
232} // namespace webrtc