| 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 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 VideoReceiveStream::Stats stats; | 91 VideoReceiveStream::Stats stats; |
| 92 { | 92 { |
| 93 rtc::CritScope lock(&crit_); | 93 rtc::CritScope lock(&crit_); |
| 94 if (receive_stream_) | 94 if (receive_stream_) |
| 95 stats = receive_stream_->GetStats(); | 95 stats = receive_stream_->GetStats(); |
| 96 } | 96 } |
| 97 if (stats.sync_offset_ms == std::numeric_limits<int>::max()) | 97 if (stats.sync_offset_ms == std::numeric_limits<int>::max()) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 int64_t now_ms = clock_->TimeInMilliseconds(); | 100 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 101 | |
| 102 sync_offset_ms_list_.push_back(stats.sync_offset_ms); | |
| 103 int64_t time_since_creation = now_ms - creation_time_ms_; | 101 int64_t time_since_creation = now_ms - creation_time_ms_; |
| 104 // During the first couple of seconds audio and video can falsely be | 102 // During the first couple of seconds audio and video can falsely be |
| 105 // estimated as being synchronized. We don't want to trigger on those. | 103 // estimated as being synchronized. We don't want to trigger on those. |
| 106 if (time_since_creation < kStartupTimeMs) | 104 if (time_since_creation < kStartupTimeMs) |
| 107 return; | 105 return; |
| 108 if (std::abs(stats.sync_offset_ms) < kInSyncThresholdMs) { | 106 if (std::abs(stats.sync_offset_ms) < kInSyncThresholdMs) { |
| 109 if (first_time_in_sync_ == -1) { | 107 if (first_time_in_sync_ == -1) { |
| 110 first_time_in_sync_ = now_ms; | 108 first_time_in_sync_ = now_ms; |
| 111 webrtc::test::PrintResult("sync_convergence_time", | 109 webrtc::test::PrintResult("sync_convergence_time", |
| 112 "", | 110 "", |
| 113 "synchronization", | 111 "synchronization", |
| 114 time_since_creation, | 112 time_since_creation, |
| 115 "ms", | 113 "ms", |
| 116 false); | 114 false); |
| 117 } | 115 } |
| 118 if (time_since_creation > kMinRunTimeMs) | 116 if (time_since_creation > kMinRunTimeMs) |
| 119 observation_complete_.Set(); | 117 observation_complete_.Set(); |
| 120 } | 118 } |
| 119 if (first_time_in_sync_ != -1) |
| 120 sync_offset_ms_list_.push_back(stats.sync_offset_ms); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void set_receive_stream(VideoReceiveStream* receive_stream) { | 123 void set_receive_stream(VideoReceiveStream* receive_stream) { |
| 124 rtc::CritScope lock(&crit_); | 124 rtc::CritScope lock(&crit_); |
| 125 receive_stream_ = receive_stream; | 125 receive_stream_ = receive_stream; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void PrintResults() { | 128 void PrintResults() { |
| 129 test::PrintResultList("stream_offset", "", "synchronization", | 129 test::PrintResultList("stream_offset", "", "synchronization", |
| 130 test::ValuesToString(sync_offset_ms_list_), "ms", | 130 test::ValuesToString(sync_offset_ms_list_), "ms", |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 static const int kMinTransmitBitrateBps = 150000; | 525 static const int kMinTransmitBitrateBps = 150000; |
| 526 static const int kMinAcceptableTransmitBitrate = 130; | 526 static const int kMinAcceptableTransmitBitrate = 130; |
| 527 static const int kMaxAcceptableTransmitBitrate = 170; | 527 static const int kMaxAcceptableTransmitBitrate = 170; |
| 528 static const int kNumBitrateObservationsInRange = 100; | 528 static const int kNumBitrateObservationsInRange = 100; |
| 529 static const int kAcceptableBitrateErrorMargin = 15; // +- 7 | 529 static const int kAcceptableBitrateErrorMargin = 15; // +- 7 |
| 530 class BitrateObserver : public test::EndToEndTest { | 530 class BitrateObserver : public test::EndToEndTest { |
| 531 public: | 531 public: |
| 532 explicit BitrateObserver(bool using_min_transmit_bitrate) | 532 explicit BitrateObserver(bool using_min_transmit_bitrate) |
| 533 : EndToEndTest(kLongTimeoutMs), | 533 : EndToEndTest(kLongTimeoutMs), |
| 534 send_stream_(nullptr), | 534 send_stream_(nullptr), |
| 535 converged_(false), |
| 535 pad_to_min_bitrate_(using_min_transmit_bitrate), | 536 pad_to_min_bitrate_(using_min_transmit_bitrate), |
| 537 min_acceptable_bitrate_(using_min_transmit_bitrate |
| 538 ? kMinAcceptableTransmitBitrate |
| 539 : (kMaxEncodeBitrateKbps - |
| 540 kAcceptableBitrateErrorMargin / 2)), |
| 541 max_acceptable_bitrate_(using_min_transmit_bitrate |
| 542 ? kMaxAcceptableTransmitBitrate |
| 543 : (kMaxEncodeBitrateKbps + |
| 544 kAcceptableBitrateErrorMargin / 2)), |
| 536 num_bitrate_observations_in_range_(0) {} | 545 num_bitrate_observations_in_range_(0) {} |
| 537 | 546 |
| 538 private: | 547 private: |
| 539 // TODO(holmer): Run this with a timer instead of once per packet. | 548 // TODO(holmer): Run this with a timer instead of once per packet. |
| 540 Action OnSendRtp(const uint8_t* packet, size_t length) override { | 549 Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 541 VideoSendStream::Stats stats = send_stream_->GetStats(); | 550 VideoSendStream::Stats stats = send_stream_->GetStats(); |
| 542 if (stats.substreams.size() > 0) { | 551 if (stats.substreams.size() > 0) { |
| 543 RTC_DCHECK_EQ(1u, stats.substreams.size()); | 552 RTC_DCHECK_EQ(1u, stats.substreams.size()); |
| 544 int bitrate_kbps = | 553 int bitrate_kbps = |
| 545 stats.substreams.begin()->second.total_bitrate_bps / 1000; | 554 stats.substreams.begin()->second.total_bitrate_bps / 1000; |
| 546 if (bitrate_kbps > 0) { | 555 if (bitrate_kbps > min_acceptable_bitrate_ && |
| 547 bitrate_kbps_list.push_back(bitrate_kbps); | 556 bitrate_kbps < max_acceptable_bitrate_) { |
| 548 if (pad_to_min_bitrate_) { | 557 converged_ = true; |
| 549 if (bitrate_kbps > kMinAcceptableTransmitBitrate && | 558 ++num_bitrate_observations_in_range_; |
| 550 bitrate_kbps < kMaxAcceptableTransmitBitrate) { | |
| 551 ++num_bitrate_observations_in_range_; | |
| 552 } | |
| 553 } else { | |
| 554 // Expect bitrate stats to roughly match the max encode bitrate. | |
| 555 if (bitrate_kbps > (kMaxEncodeBitrateKbps - | |
| 556 kAcceptableBitrateErrorMargin / 2) && | |
| 557 bitrate_kbps < (kMaxEncodeBitrateKbps + | |
| 558 kAcceptableBitrateErrorMargin / 2)) { | |
| 559 ++num_bitrate_observations_in_range_; | |
| 560 } | |
| 561 } | |
| 562 if (num_bitrate_observations_in_range_ == | 559 if (num_bitrate_observations_in_range_ == |
| 563 kNumBitrateObservationsInRange) | 560 kNumBitrateObservationsInRange) |
| 564 observation_complete_.Set(); | 561 observation_complete_.Set(); |
| 565 } | 562 } |
| 563 if (converged_) |
| 564 bitrate_kbps_list_.push_back(bitrate_kbps); |
| 566 } | 565 } |
| 567 return SEND_PACKET; | 566 return SEND_PACKET; |
| 568 } | 567 } |
| 569 | 568 |
| 570 void OnVideoStreamsCreated( | 569 void OnVideoStreamsCreated( |
| 571 VideoSendStream* send_stream, | 570 VideoSendStream* send_stream, |
| 572 const std::vector<VideoReceiveStream*>& receive_streams) override { | 571 const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 573 send_stream_ = send_stream; | 572 send_stream_ = send_stream; |
| 574 } | 573 } |
| 575 | 574 |
| 576 void ModifyVideoConfigs( | 575 void ModifyVideoConfigs( |
| 577 VideoSendStream::Config* send_config, | 576 VideoSendStream::Config* send_config, |
| 578 std::vector<VideoReceiveStream::Config>* receive_configs, | 577 std::vector<VideoReceiveStream::Config>* receive_configs, |
| 579 VideoEncoderConfig* encoder_config) override { | 578 VideoEncoderConfig* encoder_config) override { |
| 580 if (pad_to_min_bitrate_) { | 579 if (pad_to_min_bitrate_) { |
| 581 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 580 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
| 582 } else { | 581 } else { |
| 583 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); | 582 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); |
| 584 } | 583 } |
| 585 } | 584 } |
| 586 | 585 |
| 587 void PerformTest() override { | 586 void PerformTest() override { |
| 588 EXPECT_TRUE(Wait()) << "Timeout while waiting for send-bitrate stats."; | 587 EXPECT_TRUE(Wait()) << "Timeout while waiting for send-bitrate stats."; |
| 589 test::PrintResultList( | 588 test::PrintResultList( |
| 590 "bitrate_stats_", | 589 "bitrate_stats_", |
| 591 (pad_to_min_bitrate_ ? "min_transmit_bitrate" | 590 (pad_to_min_bitrate_ ? "min_transmit_bitrate" |
| 592 : "without_min_transmit_bitrate"), | 591 : "without_min_transmit_bitrate"), |
| 593 "bitrate_kbps", test::ValuesToString(bitrate_kbps_list), "kbps", | 592 "bitrate_kbps", test::ValuesToString(bitrate_kbps_list_), "kbps", |
| 594 false); | 593 false); |
| 595 } | 594 } |
| 596 | 595 |
| 597 VideoSendStream* send_stream_; | 596 VideoSendStream* send_stream_; |
| 597 bool converged_; |
| 598 const bool pad_to_min_bitrate_; | 598 const bool pad_to_min_bitrate_; |
| 599 const int min_acceptable_bitrate_; |
| 600 const int max_acceptable_bitrate_; |
| 599 int num_bitrate_observations_in_range_; | 601 int num_bitrate_observations_in_range_; |
| 600 std::vector<size_t> bitrate_kbps_list; | 602 std::vector<size_t> bitrate_kbps_list_; |
| 601 } test(pad_to_min_bitrate); | 603 } test(pad_to_min_bitrate); |
| 602 | 604 |
| 603 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps); | 605 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps); |
| 604 RunBaseTest(&test); | 606 RunBaseTest(&test); |
| 605 } | 607 } |
| 606 | 608 |
| 607 TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); } | 609 TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); } |
| 608 | 610 |
| 609 TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) { | 611 TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) { |
| 610 TestMinTransmitBitrate(false); | 612 TestMinTransmitBitrate(false); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 int encoder_inits_; | 696 int encoder_inits_; |
| 695 uint32_t last_set_bitrate_; | 697 uint32_t last_set_bitrate_; |
| 696 VideoSendStream* send_stream_; | 698 VideoSendStream* send_stream_; |
| 697 VideoEncoderConfig encoder_config_; | 699 VideoEncoderConfig encoder_config_; |
| 698 } test; | 700 } test; |
| 699 | 701 |
| 700 RunBaseTest(&test); | 702 RunBaseTest(&test); |
| 701 } | 703 } |
| 702 | 704 |
| 703 } // namespace webrtc | 705 } // namespace webrtc |
| OLD | NEW |