OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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/video_coding/utility/frame_dropper.h" | |
12 | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "webrtc/base/logging.h" | |
15 | |
16 namespace webrtc { | |
17 | |
18 namespace { | |
19 | |
20 const float kTargetBitRateKbps = 300; | |
21 const float kIncomingFrameRate = 30; | |
22 const size_t kFrameSizeBytes = 1250; | |
23 | |
24 const size_t kLargeFrameSizeBytes = 25000; | |
25 | |
26 const bool kIncludeKeyFrame = true; | |
27 const bool kDoNotIncludeKeyFrame = false; | |
28 | |
29 } // namespace | |
30 | |
31 class FrameDropperTest : public ::testing::Test { | |
32 protected: | |
33 virtual void SetUp() { | |
sprang
2016/03/04 08:57:04
void SetUp() override {
Irfan
2016/03/04 15:05:26
Done.
| |
34 frame_dropper_.SetRates(kTargetBitRateKbps, kIncomingFrameRate); | |
35 } | |
36 | |
37 // virtual void TearDown() {} | |
sprang
2016/03/04 08:57:04
Remove
Irfan
2016/03/04 15:05:26
Done.
| |
38 | |
39 void OverflowLeakyBucket() { | |
40 // Overflow bucket in frame dropper. | |
41 for (int i = 0; i < kIncomingFrameRate; ++i) { | |
42 frame_dropper_.Fill(kFrameSizeBytes, true); | |
43 } | |
44 frame_dropper_.Leak(kIncomingFrameRate); | |
45 } | |
46 | |
47 void ValidateNoDropsAtTargetBitrate(int large_frame_size_bytes, | |
48 int large_frame_rate, | |
49 bool is_large_frame_delta) { | |
50 // Smaller frame size is computed to meet |kTargetBitRateKbps|. | |
51 int small_frame_size_bytes = | |
52 (kFrameSizeBytes - | |
53 (large_frame_size_bytes * large_frame_rate) / kIncomingFrameRate); | |
sprang
2016/03/04 08:57:04
Remove outer parentheses or change to:
int small_f
Irfan
2016/03/04 15:05:26
Done.
| |
54 | |
55 for (int i = 1; i <= 5 * large_frame_rate; ++i) { | |
56 // Large frame. First frame is always a key frame. | |
57 frame_dropper_.Fill(large_frame_size_bytes, | |
58 (i == 1) ? false : is_large_frame_delta); | |
59 frame_dropper_.Leak(kIncomingFrameRate); | |
60 EXPECT_FALSE(frame_dropper_.DropFrame()); | |
61 | |
62 // Smaller frames. | |
63 for (int j = 1; j < kIncomingFrameRate / large_frame_rate; ++j) { | |
64 frame_dropper_.Fill(small_frame_size_bytes, true); | |
65 frame_dropper_.Leak(kIncomingFrameRate); | |
66 EXPECT_FALSE(frame_dropper_.DropFrame()); | |
67 } | |
68 } | |
69 } | |
70 | |
71 void ValidateThroughputMatchesTargetBitrate(int bitrate_kbps, | |
72 bool include_keyframe) { | |
73 int delta_frame_size; | |
74 int total_bytes = 0; | |
75 | |
76 if (include_keyframe) { | |
77 delta_frame_size = ((1000.0 / 8 * bitrate_kbps) - kLargeFrameSizeBytes) / | |
78 (kIncomingFrameRate - 1); | |
79 } else { | |
80 delta_frame_size = bitrate_kbps * 1000.0 / (8 * kIncomingFrameRate); | |
81 } | |
82 const int num_iterations = 1000; | |
sprang
2016/03/04 08:57:04
kNumIterations
Irfan
2016/03/04 15:05:26
Done.
| |
83 for (int i = 1; i <= num_iterations; ++i) { | |
84 int j = 0; | |
85 if (include_keyframe) { | |
86 if (!frame_dropper_.DropFrame()) { | |
87 frame_dropper_.Fill(kLargeFrameSizeBytes, false); | |
88 total_bytes += kLargeFrameSizeBytes; | |
89 } | |
90 frame_dropper_.Leak(kIncomingFrameRate); | |
91 j++; | |
92 } | |
93 for (; j < kIncomingFrameRate; ++j) { | |
94 if (!frame_dropper_.DropFrame()) { | |
95 frame_dropper_.Fill(delta_frame_size, true); | |
96 total_bytes += delta_frame_size; | |
97 } | |
98 frame_dropper_.Leak(kIncomingFrameRate); | |
99 } | |
100 } | |
101 float throughput_kbps = total_bytes * 8.0 / (1000 * num_iterations); | |
102 float deviation_from_target = | |
103 (throughput_kbps - kTargetBitRateKbps) * 100.0 / kTargetBitRateKbps; | |
104 if (deviation_from_target < 0) { | |
105 deviation_from_target = -deviation_from_target; | |
106 } | |
107 | |
108 // Variation is < 0.1% | |
109 EXPECT_LE(deviation_from_target, 0.1); | |
110 } | |
111 | |
112 FrameDropper frame_dropper_; | |
113 }; | |
114 | |
115 TEST_F(FrameDropperTest, NoDropsWhenDisabled) { | |
116 frame_dropper_.Enable(false); | |
117 OverflowLeakyBucket(); | |
118 EXPECT_FALSE(frame_dropper_.DropFrame()); | |
119 } | |
120 | |
121 TEST_F(FrameDropperTest, DropsByDefaultWhenBucketOverflows) { | |
122 OverflowLeakyBucket(); | |
123 EXPECT_TRUE(frame_dropper_.DropFrame()); | |
124 } | |
125 | |
126 TEST_F(FrameDropperTest, NoDropsWhenFillRateMatchesLeakRate) { | |
127 for (int i = 0; i < 5 * kIncomingFrameRate; ++i) { | |
128 frame_dropper_.Fill(kFrameSizeBytes, true); | |
129 frame_dropper_.Leak(kIncomingFrameRate); | |
130 EXPECT_FALSE(frame_dropper_.DropFrame()); | |
131 } | |
132 } | |
133 | |
134 TEST_F(FrameDropperTest, LargeKeyFrames) { | |
135 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes, 1, false); | |
136 frame_dropper_.Reset(); | |
137 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes / 2, 2, false); | |
138 frame_dropper_.Reset(); | |
139 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes / 4, 4, false); | |
140 frame_dropper_.Reset(); | |
141 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes / 8, 8, false); | |
142 } | |
143 | |
144 TEST_F(FrameDropperTest, LargeDeltaFrames) { | |
145 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes, 1, true); | |
146 frame_dropper_.Reset(); | |
147 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes / 2, 2, true); | |
148 frame_dropper_.Reset(); | |
149 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes / 4, 4, true); | |
150 frame_dropper_.Reset(); | |
151 ValidateNoDropsAtTargetBitrate(kLargeFrameSizeBytes / 8, 8, true); | |
152 } | |
153 | |
154 TEST_F(FrameDropperTest, TrafficVolumeAboveAvailableBandwidth) { | |
155 ValidateThroughputMatchesTargetBitrate(700, kIncludeKeyFrame); | |
156 ValidateThroughputMatchesTargetBitrate(700, kDoNotIncludeKeyFrame); | |
157 ValidateThroughputMatchesTargetBitrate(600, kIncludeKeyFrame); | |
158 ValidateThroughputMatchesTargetBitrate(600, kDoNotIncludeKeyFrame); | |
159 ValidateThroughputMatchesTargetBitrate(500, kIncludeKeyFrame); | |
160 ValidateThroughputMatchesTargetBitrate(500, kDoNotIncludeKeyFrame); | |
161 } | |
162 | |
163 } // namespace webrtc | |
OLD | NEW |