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

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

Issue 629493004: [Cast] Clean-up: Move max_unacked_frames into CongestionControl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 months 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
« no previous file with comments | « media/cast/sender/congestion_control.cc ('k') | media/cast/sender/frame_sender.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cast_defines.h" 9 #include "media/cast/cast_defines.h"
10 #include "media/cast/sender/congestion_control.h" 10 #include "media/cast/sender/congestion_control.h"
11 #include "media/cast/test/fake_single_thread_task_runner.h" 11 #include "media/cast/test/fake_single_thread_task_runner.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace media { 14 namespace media {
15 namespace cast { 15 namespace cast {
16 16
17 static const uint32 kMaxBitrateConfigured = 5000000; 17 static const uint32 kMaxBitrateConfigured = 5000000;
18 static const uint32 kMinBitrateConfigured = 500000; 18 static const uint32 kMinBitrateConfigured = 500000;
19 static const int64 kFrameDelayMs = 33;
20 static const double kMaxFrameRate = 1000.0 / kFrameDelayMs;
19 static const int64 kStartMillisecond = INT64_C(12345678900000); 21 static const int64 kStartMillisecond = INT64_C(12345678900000);
20 static const double kTargetEmptyBufferFraction = 0.9; 22 static const double kTargetEmptyBufferFraction = 0.9;
21 23
22 class CongestionControlTest : public ::testing::Test { 24 class CongestionControlTest : public ::testing::Test {
23 protected: 25 protected:
24 CongestionControlTest() 26 CongestionControlTest()
25 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) { 27 : task_runner_(new test::FakeSingleThreadTaskRunner(&testing_clock_)) {
26 testing_clock_.Advance( 28 testing_clock_.Advance(
27 base::TimeDelta::FromMilliseconds(kStartMillisecond)); 29 base::TimeDelta::FromMilliseconds(kStartMillisecond));
28 congestion_control_.reset(NewAdaptiveCongestionControl( 30 congestion_control_.reset(NewAdaptiveCongestionControl(
29 &testing_clock_, kMaxBitrateConfigured, kMinBitrateConfigured, 10)); 31 &testing_clock_, kMaxBitrateConfigured, kMinBitrateConfigured,
32 kMaxFrameRate));
33 const int max_unacked_frames = 10;
34 const base::TimeDelta target_playout_delay =
35 (max_unacked_frames - 1) * base::TimeDelta::FromSeconds(1) /
36 kMaxFrameRate;
37 congestion_control_->UpdateTargetPlayoutDelay(target_playout_delay);
30 } 38 }
31 39
32 void AckFrame(uint32 frame_id) { 40 void AckFrame(uint32 frame_id) {
33 congestion_control_->AckFrame(frame_id, testing_clock_.NowTicks()); 41 congestion_control_->AckFrame(frame_id, testing_clock_.NowTicks());
34 } 42 }
35 43
36 void Run(uint32 frames, 44 void Run(uint32 frames,
37 size_t frame_size, 45 size_t frame_size,
38 base::TimeDelta rtt, 46 base::TimeDelta rtt,
39 base::TimeDelta frame_delay, 47 base::TimeDelta frame_delay,
(...skipping 13 matching lines...) Expand all
53 61
54 base::SimpleTestTickClock testing_clock_; 62 base::SimpleTestTickClock testing_clock_;
55 scoped_ptr<CongestionControl> congestion_control_; 63 scoped_ptr<CongestionControl> congestion_control_;
56 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 64 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
57 uint32 frame_id_; 65 uint32 frame_id_;
58 66
59 DISALLOW_COPY_AND_ASSIGN(CongestionControlTest); 67 DISALLOW_COPY_AND_ASSIGN(CongestionControlTest);
60 }; 68 };
61 69
62 TEST_F(CongestionControlTest, SimpleRun) { 70 TEST_F(CongestionControlTest, SimpleRun) {
63 uint32 frame_delay = 33;
64 uint32 frame_size = 10000 * 8; 71 uint32 frame_size = 10000 * 8;
65 Run(500, 72 Run(500,
66 frame_size, 73 frame_size,
67 base::TimeDelta::FromMilliseconds(10), 74 base::TimeDelta::FromMilliseconds(10),
68 base::TimeDelta::FromMilliseconds(frame_delay), 75 base::TimeDelta::FromMilliseconds(kFrameDelayMs),
69 base::TimeDelta::FromMilliseconds(45)); 76 base::TimeDelta::FromMilliseconds(45));
70 // Empty the buffer. 77 // Empty the buffer.
71 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(100)); 78 task_runner_->Sleep(base::TimeDelta::FromMilliseconds(100));
72 79
73 uint32 safe_bitrate = frame_size * 1000 / frame_delay; 80 uint32 safe_bitrate = frame_size * 1000 / kFrameDelayMs;
74 uint32 bitrate = congestion_control_->GetBitrate( 81 uint32 bitrate = congestion_control_->GetBitrate(
75 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300), 82 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300),
76 base::TimeDelta::FromMilliseconds(300)); 83 base::TimeDelta::FromMilliseconds(300));
77 EXPECT_NEAR( 84 EXPECT_NEAR(
78 safe_bitrate / kTargetEmptyBufferFraction, bitrate, safe_bitrate * 0.05); 85 safe_bitrate / kTargetEmptyBufferFraction, bitrate, safe_bitrate * 0.05);
79 86
80 bitrate = congestion_control_->GetBitrate( 87 bitrate = congestion_control_->GetBitrate(
81 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(200), 88 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(200),
82 base::TimeDelta::FromMilliseconds(300)); 89 base::TimeDelta::FromMilliseconds(300));
83 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 2 / 3, 90 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 2 / 3,
(...skipping 28 matching lines...) Expand all
112 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300), 119 testing_clock_.NowTicks() + base::TimeDelta::FromMilliseconds(300),
113 base::TimeDelta::FromMilliseconds(300)); 120 base::TimeDelta::FromMilliseconds(300));
114 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 1 / 3, 121 EXPECT_NEAR(safe_bitrate / kTargetEmptyBufferFraction * 1 / 3,
115 bitrate, 122 bitrate,
116 safe_bitrate * 0.05); 123 safe_bitrate * 0.05);
117 } 124 }
118 125
119 126
120 } // namespace cast 127 } // namespace cast
121 } // namespace media 128 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/sender/congestion_control.cc ('k') | media/cast/sender/frame_sender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698