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