Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: webrtc/modules/congestion_controller/congestion_controller_unittest.cc

Issue 2553863003: Parse FlexFEC RTP headers in Call and add integration with BWE. (Closed)
Patch Set: Add basic CongestionController unit test, based on nisse's suggestion. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
29 namespace webrtc { 41 namespace webrtc {
30 namespace test { 42 namespace test {
31 43
32 class CongestionControllerTest : public ::testing::Test { 44 class CongestionControllerTest : public ::testing::Test {
33 protected: 45 protected:
34 CongestionControllerTest() : clock_(123456) {} 46 CongestionControllerTest() : clock_(123456) {}
35 ~CongestionControllerTest() override {} 47 ~CongestionControllerTest() override {}
36 48
37 void SetUp() override { 49 void SetUp() override {
38 pacer_ = new NiceMock<MockPacedSender>(); 50 pacer_ = new NiceMock<MockPacedSender>();
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 clock_.AdvanceTimeMilliseconds(25); 206 clock_.AdvanceTimeMilliseconds(25);
195 controller_->Process(); 207 controller_->Process();
196 208
197 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); 209 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0)));
198 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); 210 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_));
199 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); 211 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
200 clock_.AdvanceTimeMilliseconds(25); 212 clock_.AdvanceTimeMilliseconds(25);
201 controller_->Process(); 213 controller_->Process();
202 } 214 }
203 215
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
204 } // namespace test 244 } // namespace test
205 } // namespace webrtc 245 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698