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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 class QualityScalerTest : public ::testing::Test { | 35 class QualityScalerTest : public ::testing::Test { |
36 protected: | 36 protected: |
37 enum ScaleDirection { | 37 enum ScaleDirection { |
38 kKeepScaleAtHighQp, | 38 kKeepScaleAtHighQp, |
39 kScaleDown, | 39 kScaleDown, |
40 kScaleDownAboveHighQp, | 40 kScaleDownAboveHighQp, |
41 kScaleUp | 41 kScaleUp |
42 }; | 42 }; |
43 | 43 |
44 QualityScalerTest() { | 44 QualityScalerTest() { |
45 input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>( | 45 input_frame_ = I420Buffer::Create(kWidth, kHeight); |
46 new rtc::RefCountedObject<I420Buffer>(kWidth, kHeight)); | |
47 qs_.Init(kLowQpThreshold, kHighQp, 0, 0, 0, kFramerate); | 46 qs_.Init(kLowQpThreshold, kHighQp, 0, 0, 0, kFramerate); |
48 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 47 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
49 } | 48 } |
50 | 49 |
51 bool TriggerScale(ScaleDirection scale_direction) { | 50 bool TriggerScale(ScaleDirection scale_direction) { |
52 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 51 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
53 int initial_width = qs_.GetScaledResolution().width; | 52 int initial_width = qs_.GetScaledResolution().width; |
54 for (int i = 0; i < kFramerate * kNumSeconds; ++i) { | 53 for (int i = 0; i < kFramerate * kNumSeconds; ++i) { |
55 switch (scale_direction) { | 54 switch (scale_direction) { |
56 case kScaleUp: | 55 case kScaleUp: |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 211 } |
213 | 212 |
214 TEST_F(QualityScalerTest, ContinuouslyDownscalesByHalfDimensionsAndBackUp) { | 213 TEST_F(QualityScalerTest, ContinuouslyDownscalesByHalfDimensionsAndBackUp) { |
215 ContinuouslyDownscalesByHalfDimensionsAndBackUp(); | 214 ContinuouslyDownscalesByHalfDimensionsAndBackUp(); |
216 } | 215 } |
217 | 216 |
218 TEST_F(QualityScalerTest, | 217 TEST_F(QualityScalerTest, |
219 ContinuouslyDownscalesOddResolutionsByHalfDimensionsAndBackUp) { | 218 ContinuouslyDownscalesOddResolutionsByHalfDimensionsAndBackUp) { |
220 const int kOddWidth = 517; | 219 const int kOddWidth = 517; |
221 const int kOddHeight = 1239; | 220 const int kOddHeight = 1239; |
222 input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>( | 221 input_frame_ = I420Buffer::Create(kOddWidth, kOddHeight); |
223 new rtc::RefCountedObject<I420Buffer>(kOddWidth, kOddHeight)); | |
224 ContinuouslyDownscalesByHalfDimensionsAndBackUp(); | 222 ContinuouslyDownscalesByHalfDimensionsAndBackUp(); |
225 } | 223 } |
226 | 224 |
227 void QualityScalerTest::DoesNotDownscaleFrameDimensions(int width, int height) { | 225 void QualityScalerTest::DoesNotDownscaleFrameDimensions(int width, int height) { |
228 input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>( | 226 input_frame_ = I420Buffer::Create(width, height); |
229 new rtc::RefCountedObject<I420Buffer>(width, height)); | |
230 | 227 |
231 for (int i = 0; i < kFramerate * kNumSeconds; ++i) { | 228 for (int i = 0; i < kFramerate * kNumSeconds; ++i) { |
232 qs_.ReportDroppedFrame(); | 229 qs_.ReportDroppedFrame(); |
233 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 230 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
234 ASSERT_EQ(input_frame_->width(), qs_.GetScaledResolution().width) | 231 ASSERT_EQ(input_frame_->width(), qs_.GetScaledResolution().width) |
235 << "Unexpected scale of minimal-size frame."; | 232 << "Unexpected scale of minimal-size frame."; |
236 } | 233 } |
237 } | 234 } |
238 | 235 |
239 TEST_F(QualityScalerTest, DoesNotDownscaleFrom1PxWidth) { | 236 TEST_F(QualityScalerTest, DoesNotDownscaleFrom1PxWidth) { |
(...skipping 15 matching lines...) Expand all Loading... |
255 | 252 |
256 TEST_F(QualityScalerTest, DoesNotDownscaleBelow2xDefaultMinDimensionsHeight) { | 253 TEST_F(QualityScalerTest, DoesNotDownscaleBelow2xDefaultMinDimensionsHeight) { |
257 DoesNotDownscaleFrameDimensions( | 254 DoesNotDownscaleFrameDimensions( |
258 1000, 2 * kMinDownscaleDimension - 1); | 255 1000, 2 * kMinDownscaleDimension - 1); |
259 } | 256 } |
260 | 257 |
261 TEST_F(QualityScalerTest, DownscaleToVgaOnLowInitialBitrate) { | 258 TEST_F(QualityScalerTest, DownscaleToVgaOnLowInitialBitrate) { |
262 static const int kWidth720p = 1280; | 259 static const int kWidth720p = 1280; |
263 static const int kHeight720p = 720; | 260 static const int kHeight720p = 720; |
264 static const int kInitialBitrateKbps = 300; | 261 static const int kInitialBitrateKbps = 300; |
265 input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>( | 262 input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p); |
266 new rtc::RefCountedObject<I420Buffer>(kWidth720p, kHeight720p)); | |
267 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps, | 263 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps, |
268 kWidth720p, kHeight720p, kFramerate); | 264 kWidth720p, kHeight720p, kFramerate); |
269 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 265 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
270 int init_width = qs_.GetScaledResolution().width; | 266 int init_width = qs_.GetScaledResolution().width; |
271 int init_height = qs_.GetScaledResolution().height; | 267 int init_height = qs_.GetScaledResolution().height; |
272 EXPECT_EQ(640, init_width); | 268 EXPECT_EQ(640, init_width); |
273 EXPECT_EQ(360, init_height); | 269 EXPECT_EQ(360, init_height); |
274 } | 270 } |
275 | 271 |
276 TEST_F(QualityScalerTest, DownscaleToQvgaOnLowerInitialBitrate) { | 272 TEST_F(QualityScalerTest, DownscaleToQvgaOnLowerInitialBitrate) { |
277 static const int kWidth720p = 1280; | 273 static const int kWidth720p = 1280; |
278 static const int kHeight720p = 720; | 274 static const int kHeight720p = 720; |
279 static const int kInitialBitrateKbps = 200; | 275 static const int kInitialBitrateKbps = 200; |
280 input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>( | 276 input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p); |
281 new rtc::RefCountedObject<I420Buffer>(kWidth720p, kHeight720p)); | |
282 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps, | 277 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps, |
283 kWidth720p, kHeight720p, kFramerate); | 278 kWidth720p, kHeight720p, kFramerate); |
284 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); | 279 qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height()); |
285 int init_width = qs_.GetScaledResolution().width; | 280 int init_width = qs_.GetScaledResolution().width; |
286 int init_height = qs_.GetScaledResolution().height; | 281 int init_height = qs_.GetScaledResolution().height; |
287 EXPECT_EQ(320, init_width); | 282 EXPECT_EQ(320, init_width); |
288 EXPECT_EQ(180, init_height); | 283 EXPECT_EQ(180, init_height); |
289 } | 284 } |
290 | 285 |
291 TEST_F(QualityScalerTest, DownscaleAfterMeasuredSecondsThenSlowerBackUp) { | 286 TEST_F(QualityScalerTest, DownscaleAfterMeasuredSecondsThenSlowerBackUp) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 EXPECT_LT(initial_res.width, qs_.GetScaledResolution().width); | 341 EXPECT_LT(initial_res.width, qs_.GetScaledResolution().width); |
347 EXPECT_LT(initial_res.height, qs_.GetScaledResolution().height); | 342 EXPECT_LT(initial_res.height, qs_.GetScaledResolution().height); |
348 } | 343 } |
349 | 344 |
350 void QualityScalerTest::DownscaleEndsAt(int input_width, | 345 void QualityScalerTest::DownscaleEndsAt(int input_width, |
351 int input_height, | 346 int input_height, |
352 int end_width, | 347 int end_width, |
353 int end_height) { | 348 int end_height) { |
354 // Create a frame with 2x expected end width/height to verify that we can | 349 // Create a frame with 2x expected end width/height to verify that we can |
355 // scale down to expected end width/height. | 350 // scale down to expected end width/height. |
356 input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>( | 351 input_frame_ = I420Buffer::Create(input_width, input_height); |
357 new rtc::RefCountedObject<I420Buffer>(input_width, input_height)); | |
358 | 352 |
359 int last_width = input_width; | 353 int last_width = input_width; |
360 int last_height = input_height; | 354 int last_height = input_height; |
361 // Drop all frames to force-trigger downscaling. | 355 // Drop all frames to force-trigger downscaling. |
362 while (true) { | 356 while (true) { |
363 TriggerScale(kScaleDown); | 357 TriggerScale(kScaleDown); |
364 QualityScaler::Resolution res = qs_.GetScaledResolution(); | 358 QualityScaler::Resolution res = qs_.GetScaledResolution(); |
365 if (last_width == res.width) { | 359 if (last_width == res.width) { |
366 EXPECT_EQ(last_height, res.height); | 360 EXPECT_EQ(last_height, res.height); |
367 EXPECT_EQ(end_width, res.width); | 361 EXPECT_EQ(end_width, res.width); |
(...skipping 15 matching lines...) Expand all Loading... |
383 | 377 |
384 TEST_F(QualityScalerTest, DownscalesFrom1280x720To320x180) { | 378 TEST_F(QualityScalerTest, DownscalesFrom1280x720To320x180) { |
385 DownscaleEndsAt(1280, 720, 320, 180); | 379 DownscaleEndsAt(1280, 720, 320, 180); |
386 } | 380 } |
387 | 381 |
388 TEST_F(QualityScalerTest, DoesntDownscaleInitialQvga) { | 382 TEST_F(QualityScalerTest, DoesntDownscaleInitialQvga) { |
389 DownscaleEndsAt(320, 180, 320, 180); | 383 DownscaleEndsAt(320, 180, 320, 180); |
390 } | 384 } |
391 | 385 |
392 } // namespace webrtc | 386 } // namespace webrtc |
OLD | NEW |