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