| 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 | 10 |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webrtc/base/checks.h" | 12 #include "webrtc/base/checks.h" |
| 13 #include "webrtc/base/common.h" | 13 #include "webrtc/base/common.h" |
| 14 #include "webrtc/base/event.h" | |
| 15 #include "webrtc/modules/pacing/include/packet_router.h" | |
| 16 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s
end_time.h" | 14 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s
end_time.h" |
| 17 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" | 15 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl
e_stream.h" |
| 18 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | |
| 19 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" | 16 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
| 20 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 17 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
| 21 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" | 18 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" |
| 22 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" | 19 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" |
| 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 24 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 21 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 25 #include "webrtc/system_wrappers/interface/thread_wrapper.h" | |
| 26 #include "webrtc/test/testsupport/perf_test.h" | 22 #include "webrtc/test/testsupport/perf_test.h" |
| 27 #include "webrtc/video/rampup_tests.h" | 23 #include "webrtc/video/rampup_tests.h" |
| 28 | 24 |
| 29 namespace webrtc { | 25 namespace webrtc { |
| 30 namespace { | 26 namespace { |
| 31 | 27 |
| 32 static const int kMaxPacketSize = 1500; | 28 static const int kMaxPacketSize = 1500; |
| 33 const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; | 29 const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; |
| 34 | 30 |
| 35 std::vector<uint32_t> GenerateSsrcs(size_t num_streams, | 31 std::vector<uint32_t> GenerateSsrcs(size_t num_streams, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // RtpHeaderParser and a RemoteBitrateEstimator here, but due to the current | 63 // RtpHeaderParser and a RemoteBitrateEstimator here, but due to the current |
| 68 // state of the RTP module we need a full module and receive statistics to | 64 // state of the RTP module we need a full module and receive statistics to |
| 69 // be able to produce an RTCP with REMB. | 65 // be able to produce an RTCP with REMB. |
| 70 RtpRtcp::Configuration config; | 66 RtpRtcp::Configuration config; |
| 71 config.receive_statistics = receive_stats_.get(); | 67 config.receive_statistics = receive_stats_.get(); |
| 72 feedback_transport_.Enable(); | 68 feedback_transport_.Enable(); |
| 73 config.outgoing_transport = &feedback_transport_; | 69 config.outgoing_transport = &feedback_transport_; |
| 74 rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); | 70 rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); |
| 75 rtp_rtcp_->SetREMBStatus(true); | 71 rtp_rtcp_->SetREMBStatus(true); |
| 76 rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound); | 72 rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound); |
| 77 packet_router_.reset(new PacketRouter()); | |
| 78 packet_router_->AddRtpModule(rtp_rtcp_.get()); | |
| 79 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, | 73 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
| 80 kAbsSendTimeExtensionId); | 74 kAbsSendTimeExtensionId); |
| 81 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, | 75 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, |
| 82 kTransmissionTimeOffsetExtensionId); | 76 kTransmissionTimeOffsetExtensionId); |
| 83 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionTransportSequenceNumber, | |
| 84 kTransportSequenceNumberExtensionId); | |
| 85 payload_registry_->SetRtxPayloadType(RampUpTest::kSendRtxPayloadType, | 77 payload_registry_->SetRtxPayloadType(RampUpTest::kSendRtxPayloadType, |
| 86 RampUpTest::kFakeSendPayloadType); | 78 RampUpTest::kFakeSendPayloadType); |
| 87 } | 79 } |
| 88 | 80 |
| 89 StreamObserver::~StreamObserver() { | |
| 90 packet_router_->RemoveRtpModule(rtp_rtcp_.get()); | |
| 91 } | |
| 92 | |
| 93 void StreamObserver::set_expected_bitrate_bps( | 81 void StreamObserver::set_expected_bitrate_bps( |
| 94 unsigned int expected_bitrate_bps) { | 82 unsigned int expected_bitrate_bps) { |
| 95 rtc::CritScope lock(&crit_); | 83 rtc::CritScope lock(&crit_); |
| 96 expected_bitrate_bps_ = expected_bitrate_bps; | 84 expected_bitrate_bps_ = expected_bitrate_bps; |
| 97 } | 85 } |
| 98 | 86 |
| 99 void StreamObserver::set_start_bitrate_bps(unsigned int start_bitrate_bps) { | 87 void StreamObserver::set_start_bitrate_bps(unsigned int start_bitrate_bps) { |
| 100 rtc::CritScope lock(&crit_); | 88 rtc::CritScope lock(&crit_); |
| 101 start_bitrate_bps_ = start_bitrate_bps; | 89 start_bitrate_bps_ = start_bitrate_bps; |
| 102 } | 90 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 156 } |
| 169 | 157 |
| 170 EventTypeWrapper StreamObserver::Wait() { | 158 EventTypeWrapper StreamObserver::Wait() { |
| 171 return test_done_->Wait(test::CallTest::kLongTimeoutMs); | 159 return test_done_->Wait(test::CallTest::kLongTimeoutMs); |
| 172 } | 160 } |
| 173 | 161 |
| 174 void StreamObserver::SetRemoteBitrateEstimator(RemoteBitrateEstimator* rbe) { | 162 void StreamObserver::SetRemoteBitrateEstimator(RemoteBitrateEstimator* rbe) { |
| 175 remote_bitrate_estimator_.reset(rbe); | 163 remote_bitrate_estimator_.reset(rbe); |
| 176 } | 164 } |
| 177 | 165 |
| 178 PacketRouter* StreamObserver::GetPacketRouter() { | |
| 179 return packet_router_.get(); | |
| 180 } | |
| 181 | |
| 182 void StreamObserver::ReportResult(const std::string& measurement, | 166 void StreamObserver::ReportResult(const std::string& measurement, |
| 183 size_t value, | 167 size_t value, |
| 184 const std::string& units) { | 168 const std::string& units) { |
| 185 webrtc::test::PrintResult( | 169 webrtc::test::PrintResult( |
| 186 measurement, "", | 170 measurement, "", |
| 187 ::testing::UnitTest::GetInstance()->current_test_info()->name(), | 171 ::testing::UnitTest::GetInstance()->current_test_info()->name(), |
| 188 value, units, false); | 172 value, units, false); |
| 189 } | 173 } |
| 190 | 174 |
| 191 void StreamObserver::TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_) { | 175 void StreamObserver::TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } | 364 } |
| 381 break; | 365 break; |
| 382 } | 366 } |
| 383 } | 367 } |
| 384 } | 368 } |
| 385 | 369 |
| 386 EventTypeWrapper LowRateStreamObserver::Wait() { | 370 EventTypeWrapper LowRateStreamObserver::Wait() { |
| 387 return test_done_->Wait(test::CallTest::kLongTimeoutMs); | 371 return test_done_->Wait(test::CallTest::kLongTimeoutMs); |
| 388 } | 372 } |
| 389 | 373 |
| 390 class SendBitrateAdapter { | |
| 391 public: | |
| 392 static const int64_t kPollIntervalMs = 250; | |
| 393 | |
| 394 SendBitrateAdapter(const Call& call, | |
| 395 const std::vector<uint32_t>& ssrcs, | |
| 396 RemoteBitrateObserver* bitrate_observer) | |
| 397 : event_(false, false), | |
| 398 call_(call), | |
| 399 ssrcs_(ssrcs), | |
| 400 bitrate_observer_(bitrate_observer) { | |
| 401 RTC_DCHECK(bitrate_observer != nullptr); | |
| 402 poller_thread_ = ThreadWrapper::CreateThread(&SendBitrateAdapterThread, | |
| 403 this, "SendBitratePoller"); | |
| 404 RTC_DCHECK(poller_thread_->Start()); | |
| 405 } | |
| 406 | |
| 407 virtual ~SendBitrateAdapter() { | |
| 408 event_.Set(); | |
| 409 poller_thread_->Stop(); | |
| 410 } | |
| 411 | |
| 412 private: | |
| 413 static bool SendBitrateAdapterThread(void* obj) { | |
| 414 return static_cast<SendBitrateAdapter*>(obj)->PollStats(); | |
| 415 } | |
| 416 | |
| 417 bool PollStats() { | |
| 418 Call::Stats stats = call_.GetStats(); | |
| 419 | |
| 420 bitrate_observer_->OnReceiveBitrateChanged(ssrcs_, | |
| 421 stats.send_bandwidth_bps); | |
| 422 return !event_.Wait(kPollIntervalMs); | |
| 423 } | |
| 424 | |
| 425 rtc::Event event_; | |
| 426 rtc::scoped_ptr<ThreadWrapper> poller_thread_; | |
| 427 const Call& call_; | |
| 428 const std::vector<uint32_t> ssrcs_; | |
| 429 RemoteBitrateObserver* const bitrate_observer_; | |
| 430 }; | |
| 431 | |
| 432 void RampUpTest::RunRampUpTest(size_t num_streams, | 374 void RampUpTest::RunRampUpTest(size_t num_streams, |
| 433 unsigned int start_bitrate_bps, | 375 unsigned int start_bitrate_bps, |
| 434 const std::string& extension_type, | 376 const std::string& extension_type, |
| 435 bool rtx, | 377 bool rtx, |
| 436 bool red) { | 378 bool red) { |
| 437 std::vector<uint32_t> ssrcs(GenerateSsrcs(num_streams, 100)); | 379 std::vector<uint32_t> ssrcs(GenerateSsrcs(num_streams, 100)); |
| 438 std::vector<uint32_t> rtx_ssrcs(GenerateSsrcs(num_streams, 200)); | 380 std::vector<uint32_t> rtx_ssrcs(GenerateSsrcs(num_streams, 200)); |
| 439 StreamObserver::SsrcMap rtx_ssrc_map; | 381 StreamObserver::SsrcMap rtx_ssrc_map; |
| 440 if (rtx) { | 382 if (rtx) { |
| 441 for (size_t i = 0; i < ssrcs.size(); ++i) | 383 for (size_t i = 0; i < ssrcs.size(); ++i) |
| 442 rtx_ssrc_map[rtx_ssrcs[i]] = ssrcs[i]; | 384 rtx_ssrc_map[rtx_ssrcs[i]] = ssrcs[i]; |
| 443 } | 385 } |
| 444 | 386 |
| 445 test::DirectTransport receiver_transport; | 387 test::DirectTransport receiver_transport; |
| 446 StreamObserver stream_observer(rtx_ssrc_map, &receiver_transport, | 388 StreamObserver stream_observer(rtx_ssrc_map, &receiver_transport, |
| 447 Clock::GetRealTimeClock()); | 389 Clock::GetRealTimeClock()); |
| 448 | 390 |
| 449 CreateSendConfig(num_streams, &stream_observer); | 391 CreateSendConfig(num_streams, &stream_observer); |
| 450 send_config_.rtp.extensions.clear(); | 392 send_config_.rtp.extensions.clear(); |
| 451 | 393 |
| 452 rtc::scoped_ptr<SendBitrateAdapter> send_bitrate_adapter_; | |
| 453 | |
| 454 if (extension_type == RtpExtension::kAbsSendTime) { | 394 if (extension_type == RtpExtension::kAbsSendTime) { |
| 455 stream_observer.SetRemoteBitrateEstimator( | 395 stream_observer.SetRemoteBitrateEstimator( |
| 456 new RemoteBitrateEstimatorAbsSendTime( | 396 new RemoteBitrateEstimatorAbsSendTime( |
| 457 &stream_observer, Clock::GetRealTimeClock(), | 397 &stream_observer, Clock::GetRealTimeClock(), |
| 458 kRemoteBitrateEstimatorMinBitrateBps)); | 398 kRemoteBitrateEstimatorMinBitrateBps)); |
| 459 send_config_.rtp.extensions.push_back(RtpExtension( | 399 send_config_.rtp.extensions.push_back(RtpExtension( |
| 460 extension_type.c_str(), kAbsSendTimeExtensionId)); | 400 extension_type.c_str(), kAbsSendTimeExtensionId)); |
| 461 } else if (extension_type == RtpExtension::kTransportSequenceNumber) { | |
| 462 stream_observer.SetRemoteBitrateEstimator(new RemoteEstimatorProxy( | |
| 463 Clock::GetRealTimeClock(), stream_observer.GetPacketRouter())); | |
| 464 send_config_.rtp.extensions.push_back(RtpExtension( | |
| 465 extension_type.c_str(), kTransportSequenceNumberExtensionId)); | |
| 466 } else { | 401 } else { |
| 467 stream_observer.SetRemoteBitrateEstimator( | 402 stream_observer.SetRemoteBitrateEstimator( |
| 468 new RemoteBitrateEstimatorSingleStream( | 403 new RemoteBitrateEstimatorSingleStream( |
| 469 &stream_observer, Clock::GetRealTimeClock(), | 404 &stream_observer, Clock::GetRealTimeClock(), |
| 470 kRemoteBitrateEstimatorMinBitrateBps)); | 405 kRemoteBitrateEstimatorMinBitrateBps)); |
| 471 send_config_.rtp.extensions.push_back(RtpExtension( | 406 send_config_.rtp.extensions.push_back(RtpExtension( |
| 472 extension_type.c_str(), kTransmissionTimeOffsetExtensionId)); | 407 extension_type.c_str(), kTransmissionTimeOffsetExtensionId)); |
| 473 } | 408 } |
| 474 | 409 |
| 475 Call::Config call_config; | 410 Call::Config call_config; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 int expected_bitrate_bps = encoder_config_.streams.back().min_bitrate_bps; | 442 int expected_bitrate_bps = encoder_config_.streams.back().min_bitrate_bps; |
| 508 for (size_t i = 0; i < encoder_config_.streams.size() - 1; ++i) { | 443 for (size_t i = 0; i < encoder_config_.streams.size() - 1; ++i) { |
| 509 expected_bitrate_bps += encoder_config_.streams[i].target_bitrate_bps; | 444 expected_bitrate_bps += encoder_config_.streams[i].target_bitrate_bps; |
| 510 } | 445 } |
| 511 stream_observer.set_expected_bitrate_bps(expected_bitrate_bps); | 446 stream_observer.set_expected_bitrate_bps(expected_bitrate_bps); |
| 512 } | 447 } |
| 513 | 448 |
| 514 CreateStreams(); | 449 CreateStreams(); |
| 515 CreateFrameGeneratorCapturer(); | 450 CreateFrameGeneratorCapturer(); |
| 516 | 451 |
| 517 if (extension_type == RtpExtension::kTransportSequenceNumber) { | |
| 518 send_bitrate_adapter_.reset( | |
| 519 new SendBitrateAdapter(*sender_call_.get(), ssrcs, &stream_observer)); | |
| 520 } | |
| 521 Start(); | 452 Start(); |
| 522 | 453 |
| 523 EXPECT_EQ(kEventSignaled, stream_observer.Wait()); | 454 EXPECT_EQ(kEventSignaled, stream_observer.Wait()); |
| 524 | 455 |
| 525 // Destroy the SendBitrateAdapter (if any) to stop the poller thread in it, | |
| 526 // otherwise we might get a data race with the destruction of the call. | |
| 527 send_bitrate_adapter_.reset(); | |
| 528 | |
| 529 Stop(); | 456 Stop(); |
| 530 DestroyStreams(); | 457 DestroyStreams(); |
| 531 } | 458 } |
| 532 | 459 |
| 533 void RampUpTest::RunRampUpDownUpTest(size_t number_of_streams, | 460 void RampUpTest::RunRampUpDownUpTest(size_t number_of_streams, |
| 534 bool rtx, | 461 bool rtx, |
| 535 bool red) { | 462 bool red) { |
| 536 test::DirectTransport receiver_transport; | 463 test::DirectTransport receiver_transport; |
| 537 LowRateStreamObserver stream_observer( | 464 LowRateStreamObserver stream_observer( |
| 538 &receiver_transport, Clock::GetRealTimeClock(), number_of_streams, rtx); | 465 &receiver_transport, Clock::GetRealTimeClock(), number_of_streams, rtx); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 } | 556 } |
| 630 | 557 |
| 631 TEST_F(RampUpTest, AbsSendTimeSimulcastByRedWithRtx) { | 558 TEST_F(RampUpTest, AbsSendTimeSimulcastByRedWithRtx) { |
| 632 RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, true, true); | 559 RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, true, true); |
| 633 } | 560 } |
| 634 | 561 |
| 635 TEST_F(RampUpTest, AbsSendTimeSingleStreamWithHighStartBitrate) { | 562 TEST_F(RampUpTest, AbsSendTimeSingleStreamWithHighStartBitrate) { |
| 636 RunRampUpTest(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kAbsSendTime, | 563 RunRampUpTest(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kAbsSendTime, |
| 637 false, false); | 564 false, false); |
| 638 } | 565 } |
| 639 | |
| 640 TEST_F(RampUpTest, TransportSequenceNumberSingleStream) { | |
| 641 RunRampUpTest(1, 0, RtpExtension::kTransportSequenceNumber, false, false); | |
| 642 } | |
| 643 | |
| 644 TEST_F(RampUpTest, TransportSequenceNumberSimulcast) { | |
| 645 RunRampUpTest(3, 0, RtpExtension::kTransportSequenceNumber, false, false); | |
| 646 } | |
| 647 | |
| 648 TEST_F(RampUpTest, TransportSequenceNumberSimulcastWithRtx) { | |
| 649 RunRampUpTest(3, 0, RtpExtension::kTransportSequenceNumber, true, false); | |
| 650 } | |
| 651 | |
| 652 TEST_F(RampUpTest, TransportSequenceNumberSimulcastByRedWithRtx) { | |
| 653 RunRampUpTest(3, 0, RtpExtension::kTransportSequenceNumber, true, true); | |
| 654 } | |
| 655 | |
| 656 TEST_F(RampUpTest, TransportSequenceNumberSingleStreamWithHighStartBitrate) { | |
| 657 RunRampUpTest(1, 0.9 * kSingleStreamTargetBps, | |
| 658 RtpExtension::kTransportSequenceNumber, false, false); | |
| 659 } | |
| 660 } // namespace webrtc | 566 } // namespace webrtc |
| OLD | NEW |