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