OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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/modules/video_coding/utility/quality_scaler.h" | 11 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/base/event.h" | 15 #include "webrtc/base/event.h" |
16 #include "webrtc/base/task_queue.h" | 16 #include "webrtc/base/task_queue.h" |
17 #include "webrtc/test/gmock.h" | 17 #include "webrtc/test/gmock.h" |
18 #include "webrtc/test/gtest.h" | 18 #include "webrtc/test/gtest.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 namespace { | 21 namespace { |
22 static const int kFramerate = 30; | 22 static const int kFramerate = 30; |
23 static const int kLowQp = 15; | 23 static const int kLowQp = 15; |
24 static const int kLowQpThreshold = 18; | 24 static const int kLowQpThreshold = 18; |
25 static const int kHighQp = 40; | 25 static const int kHighQp = 40; |
26 static const size_t kDefaultTimeoutMs = 150; | 26 static const size_t kDefaultTimeoutMs = 150; |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 class MockScaleObserver : public ScalingObserverInterface { | 29 class MockAdaptationObserver : public AdaptationObserverInterface { |
30 public: | 30 public: |
31 MockScaleObserver() : event(false, false) {} | 31 MockAdaptationObserver() : event(false, false) {} |
32 virtual ~MockScaleObserver() {} | 32 virtual ~MockAdaptationObserver() {} |
33 | 33 |
34 void ScaleUp(ScaleReason r) override { | 34 void AdaptUp(AdaptReason r) override { |
35 scaled_up++; | 35 adapt_up_events_++; |
36 event.Set(); | 36 event.Set(); |
37 } | 37 } |
38 void ScaleDown(ScaleReason r) override { | 38 void AdaptDown(AdaptReason r) override { |
39 scaled_down++; | 39 adapt_down_events_++; |
40 event.Set(); | 40 event.Set(); |
41 } | 41 } |
42 | 42 |
43 rtc::Event event; | 43 rtc::Event event; |
44 int scaled_up = 0; | 44 int adapt_up_events_ = 0; |
45 int scaled_down = 0; | 45 int adapt_down_events_ = 0; |
46 }; | 46 }; |
47 | 47 |
48 // Pass a lower sampling period to speed up the tests. | 48 // Pass a lower sampling period to speed up the tests. |
49 class QualityScalerUnderTest : public QualityScaler { | 49 class QualityScalerUnderTest : public QualityScaler { |
50 public: | 50 public: |
51 explicit QualityScalerUnderTest(ScalingObserverInterface* observer, | 51 explicit QualityScalerUnderTest(AdaptationObserverInterface* observer, |
52 VideoEncoder::QpThresholds thresholds) | 52 VideoEncoder::QpThresholds thresholds) |
53 : QualityScaler(observer, thresholds, 5) {} | 53 : QualityScaler(observer, thresholds, 5) {} |
54 }; | 54 }; |
55 | 55 |
56 class QualityScalerTest : public ::testing::Test { | 56 class QualityScalerTest : public ::testing::Test { |
57 protected: | 57 protected: |
58 enum ScaleDirection { | 58 enum ScaleDirection { |
59 kKeepScaleAtHighQp, | 59 kKeepScaleAtHighQp, |
60 kScaleDown, | 60 kScaleDown, |
61 kScaleDownAboveHighQp, | 61 kScaleDownAboveHighQp, |
62 kScaleUp | 62 kScaleUp |
63 }; | 63 }; |
64 | 64 |
65 QualityScalerTest() | 65 QualityScalerTest() |
66 : q_(new rtc::TaskQueue("QualityScalerTestQueue")), | 66 : q_(new rtc::TaskQueue("QualityScalerTestQueue")), |
67 observer_(new MockScaleObserver()) { | 67 observer_(new MockAdaptationObserver()) { |
68 rtc::Event event(false, false); | 68 rtc::Event event(false, false); |
69 q_->PostTask([this, &event] { | 69 q_->PostTask([this, &event] { |
70 qs_ = std::unique_ptr<QualityScaler>(new QualityScalerUnderTest( | 70 qs_ = std::unique_ptr<QualityScaler>(new QualityScalerUnderTest( |
71 observer_.get(), | 71 observer_.get(), |
72 VideoEncoder::QpThresholds(kLowQpThreshold, kHighQp))); | 72 VideoEncoder::QpThresholds(kLowQpThreshold, kHighQp))); |
73 event.Set(); | 73 event.Set(); |
74 }); | 74 }); |
75 EXPECT_TRUE(event.Wait(kDefaultTimeoutMs)); | 75 EXPECT_TRUE(event.Wait(kDefaultTimeoutMs)); |
76 } | 76 } |
77 | 77 |
(...skipping 20 matching lines...) Expand all Loading... |
98 break; | 98 break; |
99 case kScaleDownAboveHighQp: | 99 case kScaleDownAboveHighQp: |
100 qs_->ReportQP(kHighQp + 1); | 100 qs_->ReportQP(kHighQp + 1); |
101 break; | 101 break; |
102 } | 102 } |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 std::unique_ptr<rtc::TaskQueue> q_; | 106 std::unique_ptr<rtc::TaskQueue> q_; |
107 std::unique_ptr<QualityScaler> qs_; | 107 std::unique_ptr<QualityScaler> qs_; |
108 std::unique_ptr<MockScaleObserver> observer_; | 108 std::unique_ptr<MockAdaptationObserver> observer_; |
109 }; | 109 }; |
110 | 110 |
111 #define DISABLED_TEST(basename, test) TEST_F(basename, DISABLED_##test) | 111 #define DISABLED_TEST(basename, test) TEST_F(basename, DISABLED_##test) |
112 DISABLED_TEST(QualityScalerTest, DownscalesAfterContinuousFramedrop) { | 112 DISABLED_TEST(QualityScalerTest, DownscalesAfterContinuousFramedrop) { |
113 q_->PostTask([this] { TriggerScale(kScaleDown); }); | 113 q_->PostTask([this] { TriggerScale(kScaleDown); }); |
114 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); | 114 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); |
115 EXPECT_EQ(1, observer_->scaled_down); | 115 EXPECT_EQ(1, observer_->adapt_down_events_); |
116 } | 116 } |
117 | 117 |
118 DISABLED_TEST(QualityScalerTest, KeepsScaleAtHighQp) { | 118 DISABLED_TEST(QualityScalerTest, KeepsScaleAtHighQp) { |
119 q_->PostTask([this] { TriggerScale(kKeepScaleAtHighQp); }); | 119 q_->PostTask([this] { TriggerScale(kKeepScaleAtHighQp); }); |
120 EXPECT_FALSE(observer_->event.Wait(kDefaultTimeoutMs)); | 120 EXPECT_FALSE(observer_->event.Wait(kDefaultTimeoutMs)); |
121 EXPECT_EQ(0, observer_->scaled_down); | 121 EXPECT_EQ(0, observer_->adapt_down_events_); |
122 EXPECT_EQ(0, observer_->scaled_up); | 122 EXPECT_EQ(0, observer_->adapt_up_events_); |
123 } | 123 } |
124 | 124 |
125 DISABLED_TEST(QualityScalerTest, DownscalesAboveHighQp) { | 125 DISABLED_TEST(QualityScalerTest, DownscalesAboveHighQp) { |
126 q_->PostTask([this] { TriggerScale(kScaleDownAboveHighQp); }); | 126 q_->PostTask([this] { TriggerScale(kScaleDownAboveHighQp); }); |
127 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); | 127 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); |
128 EXPECT_EQ(1, observer_->scaled_down); | 128 EXPECT_EQ(1, observer_->adapt_down_events_); |
129 EXPECT_EQ(0, observer_->scaled_up); | 129 EXPECT_EQ(0, observer_->adapt_up_events_); |
130 } | 130 } |
131 | 131 |
132 DISABLED_TEST(QualityScalerTest, DownscalesAfterTwoThirdsFramedrop) { | 132 DISABLED_TEST(QualityScalerTest, DownscalesAfterTwoThirdsFramedrop) { |
133 q_->PostTask([this] { | 133 q_->PostTask([this] { |
134 qs_->ReportDroppedFrame(); | 134 qs_->ReportDroppedFrame(); |
135 qs_->ReportDroppedFrame(); | 135 qs_->ReportDroppedFrame(); |
136 qs_->ReportQP(kHighQp); | 136 qs_->ReportQP(kHighQp); |
137 }); | 137 }); |
138 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); | 138 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); |
139 EXPECT_EQ(1, observer_->scaled_down); | 139 EXPECT_EQ(1, observer_->adapt_down_events_); |
140 EXPECT_EQ(0, observer_->scaled_up); | 140 EXPECT_EQ(0, observer_->adapt_up_events_); |
141 } | 141 } |
142 | 142 |
143 DISABLED_TEST(QualityScalerTest, DoesNotDownscaleOnNormalQp) { | 143 DISABLED_TEST(QualityScalerTest, DoesNotDownscaleOnNormalQp) { |
144 q_->PostTask([this] { TriggerScale(kScaleDownAboveHighQp); }); | 144 q_->PostTask([this] { TriggerScale(kScaleDownAboveHighQp); }); |
145 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); | 145 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); |
146 EXPECT_EQ(1, observer_->scaled_down); | 146 EXPECT_EQ(1, observer_->adapt_down_events_); |
147 EXPECT_EQ(0, observer_->scaled_up); | 147 EXPECT_EQ(0, observer_->adapt_up_events_); |
148 } | 148 } |
149 | 149 |
150 DISABLED_TEST(QualityScalerTest, DoesNotDownscaleAfterHalfFramedrop) { | 150 DISABLED_TEST(QualityScalerTest, DoesNotDownscaleAfterHalfFramedrop) { |
151 q_->PostTask([this] { | 151 q_->PostTask([this] { |
152 qs_->ReportDroppedFrame(); | 152 qs_->ReportDroppedFrame(); |
153 qs_->ReportQP(kHighQp); | 153 qs_->ReportQP(kHighQp); |
154 }); | 154 }); |
155 EXPECT_FALSE(observer_->event.Wait(kDefaultTimeoutMs)); | 155 EXPECT_FALSE(observer_->event.Wait(kDefaultTimeoutMs)); |
156 EXPECT_EQ(0, observer_->scaled_down); | 156 EXPECT_EQ(0, observer_->adapt_down_events_); |
157 EXPECT_EQ(0, observer_->scaled_up); | 157 EXPECT_EQ(0, observer_->adapt_up_events_); |
158 } | 158 } |
159 | 159 |
160 DISABLED_TEST(QualityScalerTest, UpscalesAfterLowQp) { | 160 DISABLED_TEST(QualityScalerTest, UpscalesAfterLowQp) { |
161 q_->PostTask([this] { TriggerScale(kScaleUp); }); | 161 q_->PostTask([this] { TriggerScale(kScaleUp); }); |
162 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); | 162 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); |
163 EXPECT_EQ(0, observer_->scaled_down); | 163 EXPECT_EQ(0, observer_->adapt_down_events_); |
164 EXPECT_EQ(1, observer_->scaled_up); | 164 EXPECT_EQ(1, observer_->adapt_up_events_); |
165 } | 165 } |
166 | 166 |
167 DISABLED_TEST(QualityScalerTest, ScalesDownAndBackUp) { | 167 DISABLED_TEST(QualityScalerTest, ScalesDownAndBackUp) { |
168 q_->PostTask([this] { TriggerScale(kScaleDown); }); | 168 q_->PostTask([this] { TriggerScale(kScaleDown); }); |
169 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); | 169 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); |
170 EXPECT_EQ(1, observer_->scaled_down); | 170 EXPECT_EQ(1, observer_->adapt_down_events_); |
171 EXPECT_EQ(0, observer_->scaled_up); | 171 EXPECT_EQ(0, observer_->adapt_up_events_); |
172 q_->PostTask([this] { TriggerScale(kScaleUp); }); | 172 q_->PostTask([this] { TriggerScale(kScaleUp); }); |
173 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); | 173 EXPECT_TRUE(observer_->event.Wait(kDefaultTimeoutMs)); |
174 EXPECT_EQ(1, observer_->scaled_down); | 174 EXPECT_EQ(1, observer_->adapt_down_events_); |
175 EXPECT_EQ(1, observer_->scaled_up); | 175 EXPECT_EQ(1, observer_->adapt_up_events_); |
176 } | 176 } |
177 #undef DISABLED_TEST | 177 #undef DISABLED_TEST |
178 } // namespace webrtc | 178 } // namespace webrtc |
OLD | NEW |