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/common_types.h" |
11 #include "webrtc/modules/video_coding/utility/quality_scaler.h" | 12 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
12 | 13 |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace webrtc { | 16 namespace webrtc { |
16 namespace { | 17 namespace { |
17 static const int kNumSeconds = 10; | 18 static const int kNumSeconds = 10; |
18 static const int kWidth = 1920; | 19 static const int kWidth = 1920; |
19 static const int kHeight = 1080; | 20 static const int kHeight = 1080; |
20 static const int kFramerate = 30; | 21 static const int kFramerate = 30; |
(...skipping 15 matching lines...) Expand all Loading... |
36 protected: | 37 protected: |
37 enum ScaleDirection { | 38 enum ScaleDirection { |
38 kKeepScaleAtHighQp, | 39 kKeepScaleAtHighQp, |
39 kScaleDown, | 40 kScaleDown, |
40 kScaleDownAboveHighQp, | 41 kScaleDownAboveHighQp, |
41 kScaleUp | 42 kScaleUp |
42 }; | 43 }; |
43 | 44 |
44 QualityScalerTest() { | 45 QualityScalerTest() { |
45 input_frame_ = I420Buffer::Create(kWidth, kHeight); | 46 input_frame_ = I420Buffer::Create(kWidth, kHeight); |
46 qs_.Init(kLowQpThreshold, kHighQp, 0, kWidth, kHeight, kFramerate); | 47 qs_.Init(kVideoCodecH264, 0, kWidth, kHeight, kFramerate, kLowQpThreshold, |
| 48 kHighQp); |
47 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 49 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
48 } | 50 } |
49 | 51 |
50 bool TriggerScale(ScaleDirection scale_direction) { | 52 bool TriggerScale(ScaleDirection scale_direction) { |
51 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 53 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
52 int initial_width = qs_.GetScaledResolution().width; | 54 int initial_width = qs_.GetScaledResolution().width; |
53 for (int i = 0; i < kFramerate * kNumSeconds; ++i) { | 55 for (int i = 0; i < kFramerate * kNumSeconds; ++i) { |
54 switch (scale_direction) { | 56 switch (scale_direction) { |
55 case kScaleUp: | 57 case kScaleUp: |
56 qs_.ReportQP(kLowQp); | 58 qs_.ReportQP(kLowQp); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 TEST_F(QualityScalerTest, DoesNotDownscaleBelow2xDefaultMinDimensionsHeight) { | 255 TEST_F(QualityScalerTest, DoesNotDownscaleBelow2xDefaultMinDimensionsHeight) { |
254 DoesNotDownscaleFrameDimensions( | 256 DoesNotDownscaleFrameDimensions( |
255 1000, 2 * kMinDownscaleDimension - 1); | 257 1000, 2 * kMinDownscaleDimension - 1); |
256 } | 258 } |
257 | 259 |
258 TEST_F(QualityScalerTest, DownscaleToVgaOnLowInitialBitrate) { | 260 TEST_F(QualityScalerTest, DownscaleToVgaOnLowInitialBitrate) { |
259 static const int kWidth720p = 1280; | 261 static const int kWidth720p = 1280; |
260 static const int kHeight720p = 720; | 262 static const int kHeight720p = 720; |
261 static const int kInitialBitrateKbps = 300; | 263 static const int kInitialBitrateKbps = 300; |
262 input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p); | 264 input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p); |
263 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps, | 265 qs_.Init(kVideoCodecH264, kInitialBitrateKbps, kWidth720p, kHeight720p, |
264 kWidth720p, kHeight720p, kFramerate); | 266 kFramerate, kLowQpThreshold, kDisabledBadQpThreshold); |
265 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 267 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
266 int init_width = qs_.GetScaledResolution().width; | 268 int init_width = qs_.GetScaledResolution().width; |
267 int init_height = qs_.GetScaledResolution().height; | 269 int init_height = qs_.GetScaledResolution().height; |
268 EXPECT_EQ(640, init_width); | 270 EXPECT_EQ(640, init_width); |
269 EXPECT_EQ(360, init_height); | 271 EXPECT_EQ(360, init_height); |
270 } | 272 } |
271 | 273 |
272 TEST_F(QualityScalerTest, DownscaleToQvgaOnLowerInitialBitrate) { | 274 TEST_F(QualityScalerTest, DownscaleToQvgaOnLowerInitialBitrate) { |
273 static const int kWidth720p = 1280; | 275 static const int kWidth720p = 1280; |
274 static const int kHeight720p = 720; | 276 static const int kHeight720p = 720; |
275 static const int kInitialBitrateKbps = 200; | 277 static const int kInitialBitrateKbps = 200; |
276 input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p); | 278 input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p); |
277 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps, | 279 qs_.Init(kVideoCodecH264, kInitialBitrateKbps, kWidth720p, kHeight720p, |
278 kWidth720p, kHeight720p, kFramerate); | 280 kFramerate, kLowQpThreshold, kDisabledBadQpThreshold); |
279 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 281 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
280 int init_width = qs_.GetScaledResolution().width; | 282 int init_width = qs_.GetScaledResolution().width; |
281 int init_height = qs_.GetScaledResolution().height; | 283 int init_height = qs_.GetScaledResolution().height; |
282 EXPECT_EQ(320, init_width); | 284 EXPECT_EQ(320, init_width); |
283 EXPECT_EQ(180, init_height); | 285 EXPECT_EQ(180, init_height); |
284 } | 286 } |
285 | 287 |
286 TEST_F(QualityScalerTest, DownscaleAfterMeasuredSecondsThenSlowerBackUp) { | 288 TEST_F(QualityScalerTest, DownscaleAfterMeasuredSecondsThenSlowerBackUp) { |
287 qs_.Init(kLowQpThreshold, kHighQp, 0, kWidth, kHeight, kFramerate); | 289 qs_.Init(kVideoCodecH264, 0, kWidth, kHeight, kFramerate, kLowQpThreshold, |
| 290 kHighQp); |
288 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 291 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
289 QualityScaler::Resolution initial_res = qs_.GetScaledResolution(); | 292 QualityScaler::Resolution initial_res = qs_.GetScaledResolution(); |
290 | 293 |
291 // Should not downscale if less than kMeasureSecondsDownscale seconds passed. | 294 // Should not downscale if less than kMeasureSecondsDownscale seconds passed. |
292 for (int i = 0; i < kFramerate * kMeasureSecondsDownscale - 1; ++i) { | 295 for (int i = 0; i < kFramerate * kMeasureSecondsDownscale - 1; ++i) { |
293 qs_.ReportQP(kHighQp + 1); | 296 qs_.ReportQP(kHighQp + 1); |
294 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 297 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
295 } | 298 } |
296 EXPECT_EQ(initial_res.width, qs_.GetScaledResolution().width); | 299 EXPECT_EQ(initial_res.width, qs_.GetScaledResolution().width); |
297 EXPECT_EQ(initial_res.height, qs_.GetScaledResolution().height); | 300 EXPECT_EQ(initial_res.height, qs_.GetScaledResolution().height); |
(...skipping 16 matching lines...) Expand all Loading... |
314 | 317 |
315 // Should upscale (back to initial) if kMeasureSecondsUpscale seconds passed | 318 // Should upscale (back to initial) if kMeasureSecondsUpscale seconds passed |
316 // (add last frame). | 319 // (add last frame). |
317 qs_.ReportQP(kLowQp); | 320 qs_.ReportQP(kLowQp); |
318 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 321 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
319 EXPECT_EQ(initial_res.width, qs_.GetScaledResolution().width); | 322 EXPECT_EQ(initial_res.width, qs_.GetScaledResolution().width); |
320 EXPECT_EQ(initial_res.height, qs_.GetScaledResolution().height); | 323 EXPECT_EQ(initial_res.height, qs_.GetScaledResolution().height); |
321 } | 324 } |
322 | 325 |
323 TEST_F(QualityScalerTest, UpscaleQuicklyInitiallyAfterMeasuredSeconds) { | 326 TEST_F(QualityScalerTest, UpscaleQuicklyInitiallyAfterMeasuredSeconds) { |
324 qs_.Init(kLowQpThreshold, kHighQp, kLowInitialBitrateKbps, kWidth, kHeight, | 327 qs_.Init(kVideoCodecH264, kLowInitialBitrateKbps, kWidth, kHeight, kFramerate, |
325 kFramerate); | 328 kLowQpThreshold, kHighQp); |
326 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 329 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
327 QualityScaler::Resolution initial_res = qs_.GetScaledResolution(); | 330 QualityScaler::Resolution initial_res = qs_.GetScaledResolution(); |
328 | 331 |
329 // Should not upscale if less than kMeasureSecondsFastUpscale seconds passed. | 332 // Should not upscale if less than kMeasureSecondsFastUpscale seconds passed. |
330 for (int i = 0; i < kFramerate * kMeasureSecondsFastUpscale - 1; ++i) { | 333 for (int i = 0; i < kFramerate * kMeasureSecondsFastUpscale - 1; ++i) { |
331 qs_.ReportQP(kLowQp); | 334 qs_.ReportQP(kLowQp); |
332 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 335 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
333 } | 336 } |
334 EXPECT_EQ(initial_res.width, qs_.GetScaledResolution().width); | 337 EXPECT_EQ(initial_res.width, qs_.GetScaledResolution().width); |
335 EXPECT_EQ(initial_res.height, qs_.GetScaledResolution().height); | 338 EXPECT_EQ(initial_res.height, qs_.GetScaledResolution().height); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 380 |
378 TEST_F(QualityScalerTest, DownscalesFrom1280x720To320x180) { | 381 TEST_F(QualityScalerTest, DownscalesFrom1280x720To320x180) { |
379 DownscaleEndsAt(1280, 720, 320, 180); | 382 DownscaleEndsAt(1280, 720, 320, 180); |
380 } | 383 } |
381 | 384 |
382 TEST_F(QualityScalerTest, DoesntDownscaleInitialQvga) { | 385 TEST_F(QualityScalerTest, DoesntDownscaleInitialQvga) { |
383 DownscaleEndsAt(320, 180, 320, 180); | 386 DownscaleEndsAt(320, 180, 320, 180); |
384 } | 387 } |
385 | 388 |
386 } // namespace webrtc | 389 } // namespace webrtc |
OLD | NEW |