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

Side by Side Diff: media/cast/sender/congestion_control_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "media/cast/sender/congestion_control.h" 9 #include "media/cast/sender/congestion_control.h"
10 #include "media/cast/test/fake_single_thread_task_runner.h" 10 #include "media/cast/test/fake_single_thread_task_runner.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace media { 13 namespace media {
14 namespace cast { 14 namespace cast {
15 15
16 static const int kMaxBitrateConfigured = 5000000; 16 static const int kMaxBitrateConfigured = 5000000;
17 static const int kMinBitrateConfigured = 500000; 17 static const int kMinBitrateConfigured = 500000;
18 static const int64 kFrameDelayMs = 33; 18 static const int64_t kFrameDelayMs = 33;
19 static const double kMaxFrameRate = 1000.0 / kFrameDelayMs; 19 static const double kMaxFrameRate = 1000.0 / kFrameDelayMs;
20 static const int64 kStartMillisecond = INT64_C(12345678900000); 20 static const int64_t kStartMillisecond = INT64_C(12345678900000);
21 static const double kTargetEmptyBufferFraction = 0.9; 21 static const double kTargetEmptyBufferFraction = 0.9;
22 22
23 class CongestionControlTest : public ::testing::Test { 23 class CongestionControlTest : public ::testing::Test {
24 protected: 24 protected:
25 CongestionControlTest() 25 CongestionControlTest()
26 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) { 26 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) {
27 testing_clock_.Advance( 27 testing_clock_.Advance(
28 base::TimeDelta::FromMilliseconds(kStartMillisecond)); 28 base::TimeDelta::FromMilliseconds(kStartMillisecond));
29 congestion_control_.reset(NewAdaptiveCongestionControl( 29 congestion_control_.reset(NewAdaptiveCongestionControl(
30 &testing_clock_, kMaxBitrateConfigured, kMinBitrateConfigured, 30 &testing_clock_, kMaxBitrateConfigured, kMinBitrateConfigured,
31 kMaxFrameRate)); 31 kMaxFrameRate));
32 const int max_unacked_frames = 10; 32 const int max_unacked_frames = 10;
33 const base::TimeDelta target_playout_delay = 33 const base::TimeDelta target_playout_delay =
34 (max_unacked_frames - 1) * base::TimeDelta::FromSeconds(1) / 34 (max_unacked_frames - 1) * base::TimeDelta::FromSeconds(1) /
35 kMaxFrameRate; 35 kMaxFrameRate;
36 congestion_control_->UpdateTargetPlayoutDelay(target_playout_delay); 36 congestion_control_->UpdateTargetPlayoutDelay(target_playout_delay);
37 } 37 }
38 38
39 void AckFrame(uint32 frame_id) { 39 void AckFrame(uint32_t frame_id) {
40 congestion_control_->AckFrame(frame_id, testing_clock_.NowTicks()); 40 congestion_control_->AckFrame(frame_id, testing_clock_.NowTicks());
41 } 41 }
42 42
43 void Run(uint32 frames, 43 void Run(uint32_t frames,
44 size_t frame_size, 44 size_t frame_size,
45 base::TimeDelta rtt, 45 base::TimeDelta rtt,
46 base::TimeDelta frame_delay, 46 base::TimeDelta frame_delay,
47 base::TimeDelta ack_time) { 47 base::TimeDelta ack_time) {
48 for (frame_id_ = 0; frame_id_ < frames; frame_id_++) { 48 for (frame_id_ = 0; frame_id_ < frames; frame_id_++) {
49 congestion_control_->UpdateRtt(rtt); 49 congestion_control_->UpdateRtt(rtt);
50 congestion_control_->SendFrameToTransport( 50 congestion_control_->SendFrameToTransport(
51 frame_id_, frame_size, testing_clock_.NowTicks()); 51 frame_id_, frame_size, testing_clock_.NowTicks());
52 task_runner_->PostDelayedTask(FROM_HERE, 52 task_runner_->PostDelayedTask(FROM_HERE,
53 base::Bind(&CongestionControlTest::AckFrame, 53 base::Bind(&CongestionControlTest::AckFrame,
54 base::Unretained(this), 54 base::Unretained(this),
55 frame_id_), 55 frame_id_),
56 ack_time); 56 ack_time);
57 task_runner_->Sleep(frame_delay); 57 task_runner_->Sleep(frame_delay);
58 } 58 }
59 } 59 }
60 60
61 base::SimpleTestTickClock testing_clock_; 61 base::SimpleTestTickClock testing_clock_;
62 scoped_ptr<CongestionControl> congestion_control_; 62 scoped_ptr<CongestionControl> congestion_control_;
63 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 63 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
64 uint32 frame_id_; 64 uint32_t frame_id_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(CongestionControlTest); 66 DISALLOW_COPY_AND_ASSIGN(CongestionControlTest);
67 }; 67 };
68 68
69 // Tests that AdaptiveCongestionControl returns reasonable bitrates based on 69 // Tests that AdaptiveCongestionControl returns reasonable bitrates based on
70 // estimations of network bandwidth and how much is in-flight (i.e, using the 70 // estimations of network bandwidth and how much is in-flight (i.e, using the
71 // "target buffer fill" model). 71 // "target buffer fill" model).
72 TEST_F(CongestionControlTest, SimpleRun) { 72 TEST_F(CongestionControlTest, SimpleRun) {
73 uint32 frame_size = 10000 * 8; 73 uint32_t frame_size = 10000 * 8;
74 Run(500, 74 Run(500,
75 frame_size, 75 frame_size,
76 base::TimeDelta::FromMilliseconds(10), 76 base::TimeDelta::FromMilliseconds(10),
77 base::TimeDelta::FromMilliseconds(kFrameDelayMs), 77 base::TimeDelta::FromMilliseconds(kFrameDelayMs),
78 base::TimeDelta::FromMilliseconds(45)); 78 base::TimeDelta::FromMilliseconds(45));
79 // Empty the buffer. 79 // Empty the buffer.
80 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(100)); 80 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(100));
81 81
82 // Use a soft maximum bitrate limit so large it will not bound the results of 82 // Use a soft maximum bitrate limit so large it will not bound the results of
83 // the underlying computations. 83 // the underlying computations.
84 const int soft_max_bitrate = std::numeric_limits<int>::max(); 84 const int soft_max_bitrate = std::numeric_limits<int>::max();
85 85
86 uint32 safe_bitrate = frame_size * 1000 / kFrameDelayMs; 86 uint32_t safe_bitrate = frame_size * 1000 / kFrameDelayMs;
87 uint32 bitrate = congestion_control_->GetBitrate( 87 uint32_t bitrate = congestion_control_->GetBitrate(
88 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300), 88 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300),
89 base::TimeDelta::FromMilliseconds(300), 89 base::TimeDelta::FromMilliseconds(300), soft_max_bitrate);
90 soft_max_bitrate);
91 EXPECT_NEAR( 90 EXPECT_NEAR(
92 safe_bitrate / kTargetEmptyBufferFraction, bitrate, safe_bitrate * 0.05); 91 safe_bitrate / kTargetEmptyBufferFraction, bitrate, safe_bitrate * 0.05);
93 92
94 bitrate = congestion_control_->GetBitrate( 93 bitrate = congestion_control_->GetBitrate(
95 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(200), 94 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(200),
96 base::TimeDelta::FromMilliseconds(300), 95 base::TimeDelta::FromMilliseconds(300),
97 soft_max_bitrate); 96 soft_max_bitrate);
98 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 2 / 3, 97 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 2 / 3,
99 bitrate, 98 bitrate,
100 safe_bitrate * 0.05); 99 safe_bitrate * 0.05);
(...skipping 28 matching lines...) Expand all
129 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300), 128 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300),
130 base::TimeDelta::FromMilliseconds(300), 129 base::TimeDelta::FromMilliseconds(300),
131 soft_max_bitrate); 130 soft_max_bitrate);
132 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 1 / 3, 131 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 1 / 3,
133 bitrate, 132 bitrate,
134 safe_bitrate * 0.05); 133 safe_bitrate * 0.05);
135 } 134 }
136 135
137 } // namespace cast 136 } // namespace cast
138 } // namespace media 137 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698