OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 void TestMinTransmitBitrate(bool pad_to_min_bitrate); | 51 void TestMinTransmitBitrate(bool pad_to_min_bitrate); |
52 | 52 |
53 void TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, | 53 void TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, |
54 int threshold_ms, | 54 int threshold_ms, |
55 int start_time_ms, | 55 int start_time_ms, |
56 int run_time_ms); | 56 int run_time_ms); |
57 }; | 57 }; |
58 | 58 |
59 class SyncRtcpObserver : public test::RtpRtcpObserver { | 59 class SyncRtcpObserver : public test::RtpRtcpObserver { |
60 public: | 60 public: |
61 explicit SyncRtcpObserver(const FakeNetworkPipe::Config& config) | 61 SyncRtcpObserver() : test::RtpRtcpObserver(CallPerfTest::kLongTimeoutMs) {} |
62 : test::RtpRtcpObserver(CallPerfTest::kLongTimeoutMs, config) {} | |
63 | 62 |
64 Action OnSendRtcp(const uint8_t* packet, size_t length) override { | 63 Action OnSendRtcp(const uint8_t* packet, size_t length) override { |
65 RTCPUtility::RTCPParserV2 parser(packet, length, true); | 64 RTCPUtility::RTCPParserV2 parser(packet, length, true); |
66 EXPECT_TRUE(parser.IsValid()); | 65 EXPECT_TRUE(parser.IsValid()); |
67 | 66 |
68 for (RTCPUtility::RTCPPacketTypes packet_type = parser.Begin(); | 67 for (RTCPUtility::RTCPPacketTypes packet_type = parser.Begin(); |
69 packet_type != RTCPUtility::RTCPPacketTypes::kInvalid; | 68 packet_type != RTCPUtility::RTCPPacketTypes::kInvalid; |
70 packet_type = parser.Iterate()) { | 69 packet_type = parser.Iterate()) { |
71 if (packet_type == RTCPUtility::RTCPPacketTypes::kSr) { | 70 if (packet_type == RTCPUtility::RTCPPacketTypes::kSr) { |
72 const RTCPUtility::RTCPPacket& packet = parser.Packet(); | 71 const RTCPUtility::RTCPPacket& packet = parser.Packet(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 class VideoRtcpAndSyncObserver : public SyncRtcpObserver, public VideoRenderer { | 119 class VideoRtcpAndSyncObserver : public SyncRtcpObserver, public VideoRenderer { |
121 static const int kInSyncThresholdMs = 50; | 120 static const int kInSyncThresholdMs = 50; |
122 static const int kStartupTimeMs = 2000; | 121 static const int kStartupTimeMs = 2000; |
123 static const int kMinRunTimeMs = 30000; | 122 static const int kMinRunTimeMs = 30000; |
124 | 123 |
125 public: | 124 public: |
126 VideoRtcpAndSyncObserver(Clock* clock, | 125 VideoRtcpAndSyncObserver(Clock* clock, |
127 int voe_channel, | 126 int voe_channel, |
128 VoEVideoSync* voe_sync, | 127 VoEVideoSync* voe_sync, |
129 SyncRtcpObserver* audio_observer) | 128 SyncRtcpObserver* audio_observer) |
130 : SyncRtcpObserver(FakeNetworkPipe::Config()), | 129 : clock_(clock), |
131 clock_(clock), | |
132 voe_channel_(voe_channel), | 130 voe_channel_(voe_channel), |
133 voe_sync_(voe_sync), | 131 voe_sync_(voe_sync), |
134 audio_observer_(audio_observer), | 132 audio_observer_(audio_observer), |
135 creation_time_ms_(clock_->TimeInMilliseconds()), | 133 creation_time_ms_(clock_->TimeInMilliseconds()), |
136 first_time_in_sync_(-1) {} | 134 first_time_in_sync_(-1) {} |
137 | 135 |
138 void RenderFrame(const VideoFrame& video_frame, | 136 void RenderFrame(const VideoFrame& video_frame, |
139 int time_to_render_ms) override { | 137 int time_to_render_ms) override { |
140 int64_t now_ms = clock_->TimeInMilliseconds(); | 138 int64_t now_ms = clock_->TimeInMilliseconds(); |
141 uint32_t playout_timestamp = 0; | 139 uint32_t playout_timestamp = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 173 } |
176 if (time_since_creation > kMinRunTimeMs) | 174 if (time_since_creation > kMinRunTimeMs) |
177 observation_complete_->Set(); | 175 observation_complete_->Set(); |
178 } | 176 } |
179 } | 177 } |
180 | 178 |
181 bool IsTextureSupported() const override { return false; } | 179 bool IsTextureSupported() const override { return false; } |
182 | 180 |
183 private: | 181 private: |
184 Clock* const clock_; | 182 Clock* const clock_; |
185 int voe_channel_; | 183 const int voe_channel_; |
186 VoEVideoSync* voe_sync_; | 184 VoEVideoSync* const voe_sync_; |
187 SyncRtcpObserver* audio_observer_; | 185 SyncRtcpObserver* const audio_observer_; |
188 int64_t creation_time_ms_; | 186 const int64_t creation_time_ms_; |
189 int64_t first_time_in_sync_; | 187 int64_t first_time_in_sync_; |
190 }; | 188 }; |
191 | 189 |
192 void CallPerfTest::TestAudioVideoSync(bool fec, bool create_audio_first) { | 190 void CallPerfTest::TestAudioVideoSync(bool fec, bool create_audio_first) { |
193 const char* kSyncGroup = "av_sync"; | 191 const char* kSyncGroup = "av_sync"; |
194 class AudioPacketReceiver : public PacketReceiver { | 192 class AudioPacketReceiver : public PacketReceiver { |
195 public: | 193 public: |
196 AudioPacketReceiver(int channel, VoENetwork* voe_network) | 194 AudioPacketReceiver(int channel, VoENetwork* voe_network) |
197 : channel_(channel), | 195 : channel_(channel), |
198 voe_network_(voe_network), | 196 voe_network_(voe_network), |
(...skipping 26 matching lines...) Expand all Loading... |
225 VoENetwork* voe_network = VoENetwork::GetInterface(voice_engine); | 223 VoENetwork* voe_network = VoENetwork::GetInterface(voice_engine); |
226 VoEVideoSync* voe_sync = VoEVideoSync::GetInterface(voice_engine); | 224 VoEVideoSync* voe_sync = VoEVideoSync::GetInterface(voice_engine); |
227 const std::string audio_filename = | 225 const std::string audio_filename = |
228 test::ResourcePath("voice_engine/audio_long16", "pcm"); | 226 test::ResourcePath("voice_engine/audio_long16", "pcm"); |
229 ASSERT_STRNE("", audio_filename.c_str()); | 227 ASSERT_STRNE("", audio_filename.c_str()); |
230 test::FakeAudioDevice fake_audio_device(Clock::GetRealTimeClock(), | 228 test::FakeAudioDevice fake_audio_device(Clock::GetRealTimeClock(), |
231 audio_filename); | 229 audio_filename); |
232 EXPECT_EQ(0, voe_base->Init(&fake_audio_device, nullptr)); | 230 EXPECT_EQ(0, voe_base->Init(&fake_audio_device, nullptr)); |
233 int channel = voe_base->CreateChannel(); | 231 int channel = voe_base->CreateChannel(); |
234 | 232 |
235 FakeNetworkPipe::Config net_config; | 233 SyncRtcpObserver audio_observer; |
236 net_config.queue_delay_ms = 500; | |
237 net_config.loss_percent = 5; | |
238 SyncRtcpObserver audio_observer(net_config); | |
239 VideoRtcpAndSyncObserver observer(Clock::GetRealTimeClock(), | |
240 channel, | |
241 voe_sync, | |
242 &audio_observer); | |
243 | 234 |
244 Call::Config receiver_config; | 235 Call::Config receiver_config; |
245 receiver_config.voice_engine = voice_engine; | 236 receiver_config.voice_engine = voice_engine; |
246 CreateCalls(Call::Config(), receiver_config); | 237 CreateCalls(Call::Config(), receiver_config); |
247 | 238 |
248 CodecInst isac = {103, "ISAC", 16000, 480, 1, 32000}; | 239 CodecInst isac = {103, "ISAC", 16000, 480, 1, 32000}; |
249 EXPECT_EQ(0, voe_codec->SetSendCodec(channel, isac)); | 240 EXPECT_EQ(0, voe_codec->SetSendCodec(channel, isac)); |
250 | 241 |
251 AudioPacketReceiver voe_packet_receiver(channel, voe_network); | 242 AudioPacketReceiver voe_packet_receiver(channel, voe_network); |
252 audio_observer.SetReceivers(&voe_packet_receiver, &voe_packet_receiver); | |
253 | 243 |
254 internal::TransportAdapter transport_adapter(audio_observer.SendTransport()); | 244 FakeNetworkPipe::Config net_config; |
| 245 net_config.queue_delay_ms = 500; |
| 246 net_config.loss_percent = 5; |
| 247 test::PacketTransport audio_send_transport( |
| 248 nullptr, &audio_observer, test::PacketTransport::kSender, net_config); |
| 249 audio_send_transport.SetReceiver(&voe_packet_receiver); |
| 250 test::PacketTransport audio_receive_transport( |
| 251 nullptr, &audio_observer, test::PacketTransport::kReceiver, net_config); |
| 252 audio_receive_transport.SetReceiver(&voe_packet_receiver); |
| 253 |
| 254 internal::TransportAdapter transport_adapter(&audio_send_transport); |
255 transport_adapter.Enable(); | 255 transport_adapter.Enable(); |
256 EXPECT_EQ(0, | 256 EXPECT_EQ(0, |
257 voe_network->RegisterExternalTransport(channel, transport_adapter)); | 257 voe_network->RegisterExternalTransport(channel, transport_adapter)); |
258 | 258 |
259 observer.SetReceivers(receiver_call_->Receiver(), sender_call_->Receiver()); | 259 VideoRtcpAndSyncObserver observer(Clock::GetRealTimeClock(), channel, |
| 260 voe_sync, &audio_observer); |
| 261 |
| 262 test::PacketTransport sync_send_transport(sender_call_.get(), &observer, |
| 263 test::PacketTransport::kSender, |
| 264 FakeNetworkPipe::Config()); |
| 265 sync_send_transport.SetReceiver(receiver_call_->Receiver()); |
| 266 test::PacketTransport sync_receive_transport(receiver_call_.get(), &observer, |
| 267 test::PacketTransport::kReceiver, |
| 268 FakeNetworkPipe::Config()); |
| 269 sync_receive_transport.SetReceiver(sender_call_->Receiver()); |
260 | 270 |
261 test::FakeDecoder fake_decoder; | 271 test::FakeDecoder fake_decoder; |
262 | 272 |
263 CreateSendConfig(1, observer.SendTransport()); | 273 CreateSendConfig(1, &sync_send_transport); |
264 CreateMatchingReceiveConfigs(observer.ReceiveTransport()); | 274 CreateMatchingReceiveConfigs(&sync_receive_transport); |
265 | 275 |
266 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; | 276 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
267 if (fec) { | 277 if (fec) { |
268 send_config_.rtp.fec.red_payload_type = kRedPayloadType; | 278 send_config_.rtp.fec.red_payload_type = kRedPayloadType; |
269 send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; | 279 send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; |
270 receive_configs_[0].rtp.fec.red_payload_type = kRedPayloadType; | 280 receive_configs_[0].rtp.fec.red_payload_type = kRedPayloadType; |
271 receive_configs_[0].rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; | 281 receive_configs_[0].rtp.fec.ulpfec_payload_type = kUlpfecPayloadType; |
272 } | 282 } |
273 receive_configs_[0].rtp.nack.rtp_history_ms = 1000; | 283 receive_configs_[0].rtp.nack.rtp_history_ms = 1000; |
274 receive_configs_[0].renderer = &observer; | 284 receive_configs_[0].renderer = &observer; |
(...skipping 26 matching lines...) Expand all Loading... |
301 | 311 |
302 EXPECT_EQ(kEventSignaled, observer.Wait()) | 312 EXPECT_EQ(kEventSignaled, observer.Wait()) |
303 << "Timed out while waiting for audio and video to be synchronized."; | 313 << "Timed out while waiting for audio and video to be synchronized."; |
304 | 314 |
305 EXPECT_EQ(0, voe_base->StopSend(channel)); | 315 EXPECT_EQ(0, voe_base->StopSend(channel)); |
306 EXPECT_EQ(0, voe_base->StopReceive(channel)); | 316 EXPECT_EQ(0, voe_base->StopReceive(channel)); |
307 EXPECT_EQ(0, voe_base->StopPlayout(channel)); | 317 EXPECT_EQ(0, voe_base->StopPlayout(channel)); |
308 fake_audio_device.Stop(); | 318 fake_audio_device.Stop(); |
309 | 319 |
310 Stop(); | 320 Stop(); |
311 observer.StopSending(); | 321 sync_send_transport.StopSending(); |
312 audio_observer.StopSending(); | 322 sync_receive_transport.StopSending(); |
| 323 audio_send_transport.StopSending(); |
| 324 audio_receive_transport.StopSending(); |
313 | 325 |
314 voe_base->DeleteChannel(channel); | 326 voe_base->DeleteChannel(channel); |
315 voe_base->Release(); | 327 voe_base->Release(); |
316 voe_codec->Release(); | 328 voe_codec->Release(); |
317 voe_network->Release(); | 329 voe_network->Release(); |
318 voe_sync->Release(); | 330 voe_sync->Release(); |
319 | 331 |
320 DestroyStreams(); | 332 DestroyStreams(); |
321 | 333 |
322 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); | 334 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); |
(...skipping 15 matching lines...) Expand all Loading... |
338 TestAudioVideoSync(true, false); | 350 TestAudioVideoSync(true, false); |
339 } | 351 } |
340 | 352 |
341 void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, | 353 void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, |
342 int threshold_ms, | 354 int threshold_ms, |
343 int start_time_ms, | 355 int start_time_ms, |
344 int run_time_ms) { | 356 int run_time_ms) { |
345 class CaptureNtpTimeObserver : public test::EndToEndTest, | 357 class CaptureNtpTimeObserver : public test::EndToEndTest, |
346 public VideoRenderer { | 358 public VideoRenderer { |
347 public: | 359 public: |
348 CaptureNtpTimeObserver(const FakeNetworkPipe::Config& config, | 360 CaptureNtpTimeObserver(int threshold_ms, int start_time_ms, int run_time_ms) |
349 int threshold_ms, | 361 : EndToEndTest(kLongTimeoutMs), |
350 int start_time_ms, | |
351 int run_time_ms) | |
352 : EndToEndTest(kLongTimeoutMs, config), | |
353 clock_(Clock::GetRealTimeClock()), | 362 clock_(Clock::GetRealTimeClock()), |
354 threshold_ms_(threshold_ms), | 363 threshold_ms_(threshold_ms), |
355 start_time_ms_(start_time_ms), | 364 start_time_ms_(start_time_ms), |
356 run_time_ms_(run_time_ms), | 365 run_time_ms_(run_time_ms), |
357 creation_time_ms_(clock_->TimeInMilliseconds()), | 366 creation_time_ms_(clock_->TimeInMilliseconds()), |
358 capturer_(nullptr), | 367 capturer_(nullptr), |
359 rtp_start_timestamp_set_(false), | 368 rtp_start_timestamp_set_(false), |
360 rtp_start_timestamp_(0) {} | 369 rtp_start_timestamp_(0) {} |
361 | 370 |
362 private: | 371 private: |
363 void RenderFrame(const VideoFrame& video_frame, | 372 void RenderFrame(const VideoFrame& video_frame, |
364 int time_to_render_ms) override { | 373 int time_to_render_ms) override { |
| 374 rtc::CritScope lock(&crit_); |
365 if (video_frame.ntp_time_ms() <= 0) { | 375 if (video_frame.ntp_time_ms() <= 0) { |
366 // Haven't got enough RTCP SR in order to calculate the capture ntp | 376 // Haven't got enough RTCP SR in order to calculate the capture ntp |
367 // time. | 377 // time. |
368 return; | 378 return; |
369 } | 379 } |
370 | 380 |
371 int64_t now_ms = clock_->TimeInMilliseconds(); | 381 int64_t now_ms = clock_->TimeInMilliseconds(); |
372 int64_t time_since_creation = now_ms - creation_time_ms_; | 382 int64_t time_since_creation = now_ms - creation_time_ms_; |
373 if (time_since_creation < start_time_ms_) { | 383 if (time_since_creation < start_time_ms_) { |
374 // Wait for |start_time_ms_| before start measuring. | 384 // Wait for |start_time_ms_| before start measuring. |
(...skipping 20 matching lines...) Expand all Loading... |
395 ss << time_offset_ms; | 405 ss << time_offset_ms; |
396 | 406 |
397 webrtc::test::PrintResult( | 407 webrtc::test::PrintResult( |
398 "capture_ntp_time", "", "real - estimated", ss.str(), "ms", true); | 408 "capture_ntp_time", "", "real - estimated", ss.str(), "ms", true); |
399 EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_); | 409 EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_); |
400 } | 410 } |
401 | 411 |
402 bool IsTextureSupported() const override { return false; } | 412 bool IsTextureSupported() const override { return false; } |
403 | 413 |
404 virtual Action OnSendRtp(const uint8_t* packet, size_t length) { | 414 virtual Action OnSendRtp(const uint8_t* packet, size_t length) { |
| 415 rtc::CritScope lock(&crit_); |
405 RTPHeader header; | 416 RTPHeader header; |
406 EXPECT_TRUE(parser_->Parse(packet, length, &header)); | 417 EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
407 | 418 |
408 if (!rtp_start_timestamp_set_) { | 419 if (!rtp_start_timestamp_set_) { |
409 // Calculate the rtp timestamp offset in order to calculate the real | 420 // Calculate the rtp timestamp offset in order to calculate the real |
410 // capture time. | 421 // capture time. |
411 uint32_t first_capture_timestamp = | 422 uint32_t first_capture_timestamp = |
412 90 * static_cast<uint32_t>(capturer_->first_frame_capture_time()); | 423 90 * static_cast<uint32_t>(capturer_->first_frame_capture_time()); |
413 rtp_start_timestamp_ = header.timestamp - first_capture_timestamp; | 424 rtp_start_timestamp_ = header.timestamp - first_capture_timestamp; |
414 rtp_start_timestamp_set_ = true; | 425 rtp_start_timestamp_set_ = true; |
(...skipping 18 matching lines...) Expand all Loading... |
433 // Enable the receiver side rtt calculation. | 444 // Enable the receiver side rtt calculation. |
434 (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true; | 445 (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true; |
435 } | 446 } |
436 | 447 |
437 void PerformTest() override { | 448 void PerformTest() override { |
438 EXPECT_EQ(kEventSignaled, Wait()) << "Timed out while waiting for " | 449 EXPECT_EQ(kEventSignaled, Wait()) << "Timed out while waiting for " |
439 "estimated capture NTP time to be " | 450 "estimated capture NTP time to be " |
440 "within bounds."; | 451 "within bounds."; |
441 } | 452 } |
442 | 453 |
443 Clock* clock_; | 454 rtc::CriticalSection crit_; |
| 455 Clock* const clock_; |
444 int threshold_ms_; | 456 int threshold_ms_; |
445 int start_time_ms_; | 457 int start_time_ms_; |
446 int run_time_ms_; | 458 int run_time_ms_; |
447 int64_t creation_time_ms_; | 459 int64_t creation_time_ms_; |
448 test::FrameGeneratorCapturer* capturer_; | 460 test::FrameGeneratorCapturer* capturer_; |
449 bool rtp_start_timestamp_set_; | 461 bool rtp_start_timestamp_set_; |
450 uint32_t rtp_start_timestamp_; | 462 uint32_t rtp_start_timestamp_; |
451 typedef std::map<uint32_t, uint32_t> FrameCaptureTimeList; | 463 typedef std::map<uint32_t, uint32_t> FrameCaptureTimeList; |
452 FrameCaptureTimeList capture_time_list_; | 464 FrameCaptureTimeList capture_time_list_ GUARDED_BY(&crit_); |
453 } test(net_config, threshold_ms, start_time_ms, run_time_ms); | 465 } test(threshold_ms, start_time_ms, run_time_ms); |
454 | 466 |
455 RunBaseTest(&test); | 467 RunBaseTest(&test, net_config); |
456 } | 468 } |
457 | 469 |
458 TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkDelay) { | 470 TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkDelay) { |
459 FakeNetworkPipe::Config net_config; | 471 FakeNetworkPipe::Config net_config; |
460 net_config.queue_delay_ms = 100; | 472 net_config.queue_delay_ms = 100; |
461 // TODO(wu): lower the threshold as the calculation/estimatation becomes more | 473 // TODO(wu): lower the threshold as the calculation/estimatation becomes more |
462 // accurate. | 474 // accurate. |
463 const int kThresholdMs = 100; | 475 const int kThresholdMs = 100; |
464 const int kStartTimeMs = 10000; | 476 const int kStartTimeMs = 10000; |
465 const int kRunTimeMs = 20000; | 477 const int kRunTimeMs = 20000; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 513 |
502 void PerformTest() override { | 514 void PerformTest() override { |
503 EXPECT_EQ(kEventSignaled, Wait()) | 515 EXPECT_EQ(kEventSignaled, Wait()) |
504 << "Timed out before receiving an overuse callback."; | 516 << "Timed out before receiving an overuse callback."; |
505 } | 517 } |
506 | 518 |
507 LoadObserver::Load tested_load_; | 519 LoadObserver::Load tested_load_; |
508 test::DelayedEncoder encoder_; | 520 test::DelayedEncoder encoder_; |
509 } test(tested_load, encode_delay_ms); | 521 } test(tested_load, encode_delay_ms); |
510 | 522 |
511 RunBaseTest(&test); | 523 RunBaseTest(&test, FakeNetworkPipe::Config()); |
512 } | 524 } |
513 | 525 |
514 TEST_F(CallPerfTest, ReceivesCpuUnderuse) { | 526 TEST_F(CallPerfTest, ReceivesCpuUnderuse) { |
515 const int kEncodeDelayMs = 2; | 527 const int kEncodeDelayMs = 2; |
516 TestCpuOveruse(LoadObserver::kUnderuse, kEncodeDelayMs); | 528 TestCpuOveruse(LoadObserver::kUnderuse, kEncodeDelayMs); |
517 } | 529 } |
518 | 530 |
519 TEST_F(CallPerfTest, ReceivesCpuOveruse) { | 531 TEST_F(CallPerfTest, ReceivesCpuOveruse) { |
520 const int kEncodeDelayMs = 35; | 532 const int kEncodeDelayMs = 35; |
521 TestCpuOveruse(LoadObserver::kOveruse, kEncodeDelayMs); | 533 TestCpuOveruse(LoadObserver::kOveruse, kEncodeDelayMs); |
522 } | 534 } |
523 | 535 |
524 void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { | 536 void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { |
525 static const int kMaxEncodeBitrateKbps = 30; | 537 static const int kMaxEncodeBitrateKbps = 30; |
526 static const int kMinTransmitBitrateBps = 150000; | 538 static const int kMinTransmitBitrateBps = 150000; |
527 static const int kMinAcceptableTransmitBitrate = 130; | 539 static const int kMinAcceptableTransmitBitrate = 130; |
528 static const int kMaxAcceptableTransmitBitrate = 170; | 540 static const int kMaxAcceptableTransmitBitrate = 170; |
529 static const int kNumBitrateObservationsInRange = 100; | 541 static const int kNumBitrateObservationsInRange = 100; |
530 static const int kAcceptableBitrateErrorMargin = 15; // +- 7 | 542 static const int kAcceptableBitrateErrorMargin = 15; // +- 7 |
531 class BitrateObserver : public test::EndToEndTest, public PacketReceiver { | 543 class BitrateObserver : public test::EndToEndTest { |
532 public: | 544 public: |
533 explicit BitrateObserver(bool using_min_transmit_bitrate) | 545 explicit BitrateObserver(bool using_min_transmit_bitrate) |
534 : EndToEndTest(kLongTimeoutMs), | 546 : EndToEndTest(kLongTimeoutMs), |
535 send_stream_(nullptr), | 547 send_stream_(nullptr), |
536 send_transport_receiver_(nullptr), | |
537 pad_to_min_bitrate_(using_min_transmit_bitrate), | 548 pad_to_min_bitrate_(using_min_transmit_bitrate), |
538 num_bitrate_observations_in_range_(0) {} | 549 num_bitrate_observations_in_range_(0) {} |
539 | 550 |
540 private: | 551 private: |
541 void SetReceivers(PacketReceiver* send_transport_receiver, | 552 // TODO(holmer): Run this with a timer instead of once per packet. |
542 PacketReceiver* receive_transport_receiver) override { | 553 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
543 send_transport_receiver_ = send_transport_receiver; | |
544 test::RtpRtcpObserver::SetReceivers(this, receive_transport_receiver); | |
545 } | |
546 | |
547 DeliveryStatus DeliverPacket(MediaType media_type, | |
548 const uint8_t* packet, | |
549 size_t length, | |
550 const PacketTime& packet_time) override { | |
551 VideoSendStream::Stats stats = send_stream_->GetStats(); | 554 VideoSendStream::Stats stats = send_stream_->GetStats(); |
552 if (stats.substreams.size() > 0) { | 555 if (stats.substreams.size() > 0) { |
553 RTC_DCHECK_EQ(1u, stats.substreams.size()); | 556 RTC_DCHECK_EQ(1u, stats.substreams.size()); |
554 int bitrate_kbps = | 557 int bitrate_kbps = |
555 stats.substreams.begin()->second.total_bitrate_bps / 1000; | 558 stats.substreams.begin()->second.total_bitrate_bps / 1000; |
556 if (bitrate_kbps > 0) { | 559 if (bitrate_kbps > 0) { |
557 test::PrintResult( | 560 test::PrintResult( |
558 "bitrate_stats_", | 561 "bitrate_stats_", |
559 (pad_to_min_bitrate_ ? "min_transmit_bitrate" | 562 (pad_to_min_bitrate_ ? "min_transmit_bitrate" |
560 : "without_min_transmit_bitrate"), | 563 : "without_min_transmit_bitrate"), |
(...skipping 13 matching lines...) Expand all Loading... |
574 bitrate_kbps < (kMaxEncodeBitrateKbps + | 577 bitrate_kbps < (kMaxEncodeBitrateKbps + |
575 kAcceptableBitrateErrorMargin / 2)) { | 578 kAcceptableBitrateErrorMargin / 2)) { |
576 ++num_bitrate_observations_in_range_; | 579 ++num_bitrate_observations_in_range_; |
577 } | 580 } |
578 } | 581 } |
579 if (num_bitrate_observations_in_range_ == | 582 if (num_bitrate_observations_in_range_ == |
580 kNumBitrateObservationsInRange) | 583 kNumBitrateObservationsInRange) |
581 observation_complete_->Set(); | 584 observation_complete_->Set(); |
582 } | 585 } |
583 } | 586 } |
584 return send_transport_receiver_->DeliverPacket(media_type, packet, length, | 587 return SEND_PACKET; |
585 packet_time); | |
586 } | 588 } |
587 | 589 |
588 void OnStreamsCreated( | 590 void OnStreamsCreated( |
589 VideoSendStream* send_stream, | 591 VideoSendStream* send_stream, |
590 const std::vector<VideoReceiveStream*>& receive_streams) override { | 592 const std::vector<VideoReceiveStream*>& receive_streams) override { |
591 send_stream_ = send_stream; | 593 send_stream_ = send_stream; |
592 } | 594 } |
593 | 595 |
594 void ModifyConfigs(VideoSendStream::Config* send_config, | 596 void ModifyConfigs(VideoSendStream::Config* send_config, |
595 std::vector<VideoReceiveStream::Config>* receive_configs, | 597 std::vector<VideoReceiveStream::Config>* receive_configs, |
596 VideoEncoderConfig* encoder_config) override { | 598 VideoEncoderConfig* encoder_config) override { |
597 if (pad_to_min_bitrate_) { | 599 if (pad_to_min_bitrate_) { |
598 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 600 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
599 } else { | 601 } else { |
600 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); | 602 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); |
601 } | 603 } |
602 } | 604 } |
603 | 605 |
604 void PerformTest() override { | 606 void PerformTest() override { |
605 EXPECT_EQ(kEventSignaled, Wait()) | 607 EXPECT_EQ(kEventSignaled, Wait()) |
606 << "Timeout while waiting for send-bitrate stats."; | 608 << "Timeout while waiting for send-bitrate stats."; |
607 } | 609 } |
608 | 610 |
609 VideoSendStream* send_stream_; | 611 VideoSendStream* send_stream_; |
610 PacketReceiver* send_transport_receiver_; | |
611 const bool pad_to_min_bitrate_; | 612 const bool pad_to_min_bitrate_; |
612 int num_bitrate_observations_in_range_; | 613 int num_bitrate_observations_in_range_; |
613 } test(pad_to_min_bitrate); | 614 } test(pad_to_min_bitrate); |
614 | 615 |
615 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps); | 616 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps); |
616 RunBaseTest(&test); | 617 RunBaseTest(&test, FakeNetworkPipe::Config()); |
617 } | 618 } |
618 | 619 |
619 TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); } | 620 TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); } |
620 | 621 |
621 TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) { | 622 TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) { |
622 TestMinTransmitBitrate(false); | 623 TestMinTransmitBitrate(false); |
623 } | 624 } |
624 | 625 |
625 TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) { | 626 TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) { |
626 static const uint32_t kInitialBitrateKbps = 400; | 627 static const uint32_t kInitialBitrateKbps = 400; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 } | 702 } |
702 | 703 |
703 private: | 704 private: |
704 rtc::scoped_ptr<webrtc::EventWrapper> time_to_reconfigure_; | 705 rtc::scoped_ptr<webrtc::EventWrapper> time_to_reconfigure_; |
705 int encoder_inits_; | 706 int encoder_inits_; |
706 uint32_t last_set_bitrate_; | 707 uint32_t last_set_bitrate_; |
707 VideoSendStream* send_stream_; | 708 VideoSendStream* send_stream_; |
708 VideoEncoderConfig encoder_config_; | 709 VideoEncoderConfig encoder_config_; |
709 } test; | 710 } test; |
710 | 711 |
711 RunBaseTest(&test); | 712 RunBaseTest(&test, FakeNetworkPipe::Config()); |
712 } | 713 } |
713 | 714 |
714 } // namespace webrtc | 715 } // namespace webrtc |
OLD | NEW |