OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 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 |
| 11 #include "webrtc/modules/congestion_controller/acknowledged_bitrate_estimator.h" |
| 12 |
| 13 #include "webrtc/base/fakeclock.h" |
| 14 #include "webrtc/base/ptr_util.h" |
| 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 16 #include "webrtc/test/gmock.h" |
| 17 #include "webrtc/test/gtest.h" |
| 18 |
| 19 using testing::_; |
| 20 using testing::NiceMock; |
| 21 using testing::InSequence; |
| 22 |
| 23 namespace webrtc { |
| 24 |
| 25 namespace { |
| 26 class MockBitrateEstimator : public BitrateEstimator { |
| 27 public: |
| 28 ~MockBitrateEstimator() { Die(); } |
| 29 |
| 30 MOCK_METHOD0(Die, void()); |
| 31 MOCK_METHOD2(Update, void(int64_t now_ms, int bytes)); |
| 32 MOCK_CONST_METHOD0(bitrate_bps, rtc::Optional<uint32_t>()); |
| 33 }; |
| 34 |
| 35 struct AcknowledgedBitrateEstimatorTestStates { |
| 36 std::unique_ptr<AcknowledgedBitrateEstimator> acknowledged_bitrate_estimator; |
| 37 MockBitrateEstimator* bitrate_estimator; |
| 38 }; |
| 39 |
| 40 class MockBitrateEstimatorCreator : public BitrateEstimatorCreator { |
| 41 public: |
| 42 explicit MockBitrateEstimatorCreator( |
| 43 AcknowledgedBitrateEstimatorTestStates* states) |
| 44 : states_(states) { |
| 45 RTC_CHECK(states_); |
| 46 } |
| 47 std::unique_ptr<BitrateEstimator> Create() const override { |
| 48 auto bitrate_estimator = rtc::MakeUnique<NiceMock<MockBitrateEstimator>>(); |
| 49 states_->bitrate_estimator = bitrate_estimator.get(); |
| 50 return bitrate_estimator; |
| 51 } |
| 52 AcknowledgedBitrateEstimatorTestStates* states_; |
| 53 }; |
| 54 |
| 55 AcknowledgedBitrateEstimatorTestStates CreateTestStates() { |
| 56 AcknowledgedBitrateEstimatorTestStates states; |
| 57 states.acknowledged_bitrate_estimator = |
| 58 rtc::MakeUnique<AcknowledgedBitrateEstimator>( |
| 59 rtc::MakeUnique<MockBitrateEstimatorCreator>(&states)); |
| 60 EXPECT_CALL(*states.bitrate_estimator, Die()).Times(1); |
| 61 return states; |
| 62 } |
| 63 |
| 64 constexpr int64_t first_arrival_time_ms = 10; |
| 65 constexpr int64_t first_send_time_ms = 10; |
| 66 constexpr uint16_t sequence_number = 1; |
| 67 constexpr size_t payload_size = 10; |
| 68 |
| 69 std::vector<PacketFeedback> CreateFeedbackVector() { |
| 70 std::vector<PacketFeedback> packet_feedback_vector; |
| 71 const PacedPacketInfo pacing_info; |
| 72 packet_feedback_vector.push_back( |
| 73 PacketFeedback(first_arrival_time_ms, first_send_time_ms, sequence_number, |
| 74 payload_size, pacing_info)); |
| 75 packet_feedback_vector.push_back( |
| 76 PacketFeedback(first_arrival_time_ms + 10, first_send_time_ms + 10, |
| 77 sequence_number, payload_size + 10, pacing_info)); |
| 78 return packet_feedback_vector; |
| 79 } |
| 80 |
| 81 } // anonymous namespace |
| 82 |
| 83 TEST(TestAcknowledgedBitrateEstimator, DontAddPacketsWhichAreNotInSendHistory) { |
| 84 auto states = CreateTestStates(); |
| 85 std::vector<PacketFeedback> packet_feedback_vector; |
| 86 packet_feedback_vector.push_back( |
| 87 PacketFeedback(first_arrival_time_ms, sequence_number)); |
| 88 EXPECT_CALL(*states.bitrate_estimator, Update(_, _)).Times(0); |
| 89 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector( |
| 90 packet_feedback_vector, false); |
| 91 } |
| 92 |
| 93 TEST(TestAcknowledgedBitrateEstimator, UpdateBandwith) { |
| 94 auto states = CreateTestStates(); |
| 95 auto packet_feedback_vector = CreateFeedbackVector(); |
| 96 { |
| 97 InSequence dummy; |
| 98 EXPECT_CALL(*states.bitrate_estimator, |
| 99 Update(packet_feedback_vector[0].arrival_time_ms, |
| 100 packet_feedback_vector[0].payload_size)) |
| 101 .Times(1); |
| 102 EXPECT_CALL(*states.bitrate_estimator, |
| 103 Update(packet_feedback_vector[1].arrival_time_ms, |
| 104 packet_feedback_vector[1].payload_size)) |
| 105 .Times(1); |
| 106 } |
| 107 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector( |
| 108 packet_feedback_vector, false); |
| 109 } |
| 110 |
| 111 TEST(TestAcknowledgedBitrateEstimator, |
| 112 ResetAfterLeafAlrStateAndDontAddOldPackets) { |
| 113 auto states = CreateTestStates(); |
| 114 auto packet_feedback_vector = CreateFeedbackVector(); |
| 115 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector( |
| 116 packet_feedback_vector, true); |
| 117 |
| 118 rtc::ScopedFakeClock fake_clock; |
| 119 |
| 120 fake_clock.AdvanceTime( |
| 121 rtc::TimeDelta::FromMilliseconds(first_arrival_time_ms + 1)); |
| 122 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector( |
| 123 std::vector<PacketFeedback>(), false); |
| 124 EXPECT_CALL(*states.bitrate_estimator, Die()).Times(1); |
| 125 |
| 126 { |
| 127 InSequence dummy; |
| 128 EXPECT_CALL(*states.bitrate_estimator, |
| 129 Update(packet_feedback_vector[0].arrival_time_ms, |
| 130 packet_feedback_vector[0].payload_size)) |
| 131 .Times(0); |
| 132 EXPECT_CALL(*states.bitrate_estimator, |
| 133 Update(packet_feedback_vector[1].arrival_time_ms, |
| 134 packet_feedback_vector[1].payload_size)) |
| 135 .Times(1); |
| 136 } |
| 137 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector( |
| 138 packet_feedback_vector, false); |
| 139 } |
| 140 |
| 141 } // namespace webrtc |
OLD | NEW |