| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" | 11 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
| 12 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 12 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 13 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 13 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
| 14 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" | 14 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" |
| 15 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" | 15 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" |
| 16 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" | 16 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" |
| 17 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_observer.h" | 17 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_observer.h" |
| 18 #include "webrtc/system_wrappers/include/clock.h" | 18 #include "webrtc/system_wrappers/include/clock.h" |
| 19 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
| 20 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
| 21 | 21 |
| 22 using testing::_; | 22 using testing::_; |
| 23 using testing::AtLeast; | 23 using testing::AtLeast; |
| 24 using testing::NiceMock; | 24 using testing::NiceMock; |
| 25 using testing::Return; | 25 using testing::Return; |
| 26 using testing::SaveArg; | 26 using testing::SaveArg; |
| 27 using testing::StrictMock; | 27 using testing::StrictMock; |
| 28 | 28 |
| 29 namespace { | |
| 30 | |
| 31 // Helper to convert some time format to resolution used in absolute send time | |
| 32 // header extension, rounded upwards. |t| is the time to convert, in some | |
| 33 // resolution. |denom| is the value to divide |t| by to get whole seconds, | |
| 34 // e.g. |denom| = 1000 if |t| is in milliseconds. | |
| 35 uint32_t AbsSendTime(int64_t t, int64_t denom) { | |
| 36 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 namespace webrtc { | 29 namespace webrtc { |
| 42 namespace test { | 30 namespace test { |
| 43 | 31 |
| 44 class CongestionControllerTest : public ::testing::Test { | 32 class CongestionControllerTest : public ::testing::Test { |
| 45 protected: | 33 protected: |
| 46 CongestionControllerTest() : clock_(123456) {} | 34 CongestionControllerTest() : clock_(123456) {} |
| 47 ~CongestionControllerTest() override {} | 35 ~CongestionControllerTest() override {} |
| 48 | 36 |
| 49 void SetUp() override { | 37 void SetUp() override { |
| 50 pacer_ = new NiceMock<MockPacedSender>(); | 38 pacer_ = new NiceMock<MockPacedSender>(); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 clock_.AdvanceTimeMilliseconds(25); | 194 clock_.AdvanceTimeMilliseconds(25); |
| 207 controller_->Process(); | 195 controller_->Process(); |
| 208 | 196 |
| 209 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); | 197 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); |
| 210 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); | 198 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); |
| 211 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 199 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 212 clock_.AdvanceTimeMilliseconds(25); | 200 clock_.AdvanceTimeMilliseconds(25); |
| 213 controller_->Process(); | 201 controller_->Process(); |
| 214 } | 202 } |
| 215 | 203 |
| 216 TEST_F(CongestionControllerTest, OnReceivedPacketWithAbsSendTime) { | |
| 217 NiceMock<MockCongestionObserver> observer; | |
| 218 StrictMock<MockRemoteBitrateObserver> remote_bitrate_observer; | |
| 219 std::unique_ptr<PacedSender> pacer(new NiceMock<MockPacedSender>()); | |
| 220 controller_.reset( | |
| 221 new CongestionController(&clock_, &observer, &remote_bitrate_observer, | |
| 222 &event_log_, &packet_router_, std::move(pacer))); | |
| 223 | |
| 224 size_t payload_size = 1000; | |
| 225 RTPHeader header; | |
| 226 header.ssrc = 0x11eb21c; | |
| 227 header.extension.hasAbsoluteSendTime = true; | |
| 228 | |
| 229 std::vector<unsigned int> ssrcs; | |
| 230 EXPECT_CALL(remote_bitrate_observer, OnReceiveBitrateChanged(_, _)) | |
| 231 .WillRepeatedly(SaveArg<0>(&ssrcs)); | |
| 232 | |
| 233 for (int i = 0; i < 10; ++i) { | |
| 234 clock_.AdvanceTimeMilliseconds((1000 * payload_size) / kInitialBitrateBps); | |
| 235 int64_t now_ms = clock_.TimeInMilliseconds(); | |
| 236 header.extension.absoluteSendTime = AbsSendTime(now_ms, 1000); | |
| 237 controller_->OnReceivedPacket(now_ms, payload_size, header); | |
| 238 } | |
| 239 | |
| 240 ASSERT_EQ(1u, ssrcs.size()); | |
| 241 EXPECT_EQ(header.ssrc, ssrcs[0]); | |
| 242 } | |
| 243 | |
| 244 } // namespace test | 204 } // namespace test |
| 245 } // namespace webrtc | 205 } // namespace webrtc |
| OLD | NEW |