| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 void OnFrameCaptured(VideoCapturer* capturer, | 66 void OnFrameCaptured(VideoCapturer* capturer, |
| 67 const CapturedFrame* captured_frame) { | 67 const CapturedFrame* captured_frame) { |
| 68 rtc::CritScope lock(&crit_); | 68 rtc::CritScope lock(&crit_); |
| 69 const int in_width = captured_frame->width; | 69 const int in_width = captured_frame->width; |
| 70 const int in_height = abs(captured_frame->height); | 70 const int in_height = abs(captured_frame->height); |
| 71 int cropped_width; | 71 int cropped_width; |
| 72 int cropped_height; | 72 int cropped_height; |
| 73 int out_width; | 73 int out_width; |
| 74 int out_height; | 74 int out_height; |
| 75 video_adapter_->AdaptFrameResolution(in_width, in_height, | 75 if (video_adapter_->AdaptFrameResolution(in_width, in_height, |
| 76 &cropped_width, &cropped_height, | 76 &cropped_width, &cropped_height, |
| 77 &out_width, &out_height); | 77 &out_width, &out_height)) { |
| 78 if (out_width != 0 && out_height != 0) { | |
| 79 cropped_width_ = cropped_width; | 78 cropped_width_ = cropped_width; |
| 80 cropped_height_ = cropped_height; | 79 cropped_height_ = cropped_height; |
| 81 out_width_ = out_width; | 80 out_width_ = out_width; |
| 82 out_height_ = out_height; | 81 out_height_ = out_height; |
| 83 last_adapt_was_no_op_ = | 82 last_adapt_was_no_op_ = |
| 84 (in_width == cropped_width && in_height == cropped_height && | 83 (in_width == cropped_width && in_height == cropped_height && |
| 85 in_width == out_width && in_height == out_height); | 84 in_width == out_width && in_height == out_height); |
| 86 } else { | 85 } else { |
| 87 ++dropped_frames_; | 86 ++dropped_frames_; |
| 88 } | 87 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 EXPECT_GT(listener_->GetStats().dropped_frames, 0); | 228 EXPECT_GT(listener_->GetStats().dropped_frames, 0); |
| 230 } | 229 } |
| 231 | 230 |
| 232 // Set a very high output pixel resolution. Expect no cropping or resolution | 231 // Set a very high output pixel resolution. Expect no cropping or resolution |
| 233 // change. | 232 // change. |
| 234 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { | 233 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { |
| 235 VideoFormat output_format = capture_format_; | 234 VideoFormat output_format = capture_format_; |
| 236 output_format.width *= 10; | 235 output_format.width *= 10; |
| 237 output_format.height *= 10; | 236 output_format.height *= 10; |
| 238 adapter_.OnOutputFormatRequest(output_format); | 237 adapter_.OnOutputFormatRequest(output_format); |
| 239 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 238 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 240 &cropped_width_, &cropped_height_, | 239 capture_format_.width, capture_format_.height, |
| 241 &out_width_, &out_height_); | 240 &cropped_width_, &cropped_height_, |
| 241 &out_width_, &out_height_)); |
| 242 EXPECT_EQ(capture_format_.width, cropped_width_); | 242 EXPECT_EQ(capture_format_.width, cropped_width_); |
| 243 EXPECT_EQ(capture_format_.height, cropped_height_); | 243 EXPECT_EQ(capture_format_.height, cropped_height_); |
| 244 EXPECT_EQ(capture_format_.width, out_width_); | 244 EXPECT_EQ(capture_format_.width, out_width_); |
| 245 EXPECT_EQ(capture_format_.height, out_height_); | 245 EXPECT_EQ(capture_format_.height, out_height_); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // Adapt the frame resolution to be the same as capture resolution. Expect no | 248 // Adapt the frame resolution to be the same as capture resolution. Expect no |
| 249 // cropping or resolution change. | 249 // cropping or resolution change. |
| 250 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) { | 250 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) { |
| 251 adapter_.OnOutputFormatRequest(capture_format_); | 251 adapter_.OnOutputFormatRequest(capture_format_); |
| 252 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 252 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 253 &cropped_width_, &cropped_height_, | 253 capture_format_.width, capture_format_.height, |
| 254 &out_width_, &out_height_); | 254 &cropped_width_, &cropped_height_, |
| 255 &out_width_, &out_height_)); |
| 255 EXPECT_EQ(capture_format_.width, cropped_width_); | 256 EXPECT_EQ(capture_format_.width, cropped_width_); |
| 256 EXPECT_EQ(capture_format_.height, cropped_height_); | 257 EXPECT_EQ(capture_format_.height, cropped_height_); |
| 257 EXPECT_EQ(capture_format_.width, out_width_); | 258 EXPECT_EQ(capture_format_.width, out_width_); |
| 258 EXPECT_EQ(capture_format_.height, out_height_); | 259 EXPECT_EQ(capture_format_.height, out_height_); |
| 259 } | 260 } |
| 260 | 261 |
| 261 // Adapt the frame resolution to be a quarter of the capture resolution. Expect | 262 // Adapt the frame resolution to be a quarter of the capture resolution. Expect |
| 262 // no cropping, but a resolution change. | 263 // no cropping, but a resolution change. |
| 263 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) { | 264 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) { |
| 264 VideoFormat request_format = capture_format_; | 265 VideoFormat request_format = capture_format_; |
| 265 request_format.width /= 2; | 266 request_format.width /= 2; |
| 266 request_format.height /= 2; | 267 request_format.height /= 2; |
| 267 adapter_.OnOutputFormatRequest(request_format); | 268 adapter_.OnOutputFormatRequest(request_format); |
| 268 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 269 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 269 &cropped_width_, &cropped_height_, | 270 capture_format_.width, capture_format_.height, |
| 270 &out_width_, &out_height_); | 271 &cropped_width_, &cropped_height_, |
| 272 &out_width_, &out_height_)); |
| 271 EXPECT_EQ(capture_format_.width, cropped_width_); | 273 EXPECT_EQ(capture_format_.width, cropped_width_); |
| 272 EXPECT_EQ(capture_format_.height, cropped_height_); | 274 EXPECT_EQ(capture_format_.height, cropped_height_); |
| 273 EXPECT_EQ(request_format.width, out_width_); | 275 EXPECT_EQ(request_format.width, out_width_); |
| 274 EXPECT_EQ(request_format.height, out_height_); | 276 EXPECT_EQ(request_format.height, out_height_); |
| 275 } | 277 } |
| 276 | 278 |
| 277 // Adapt the pixel resolution to 0. Expect frame drop. | 279 // Adapt the pixel resolution to 0. Expect frame drop. |
| 278 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) { | 280 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) { |
| 279 VideoFormat output_format = capture_format_; | 281 VideoFormat output_format = capture_format_; |
| 280 output_format.width = 0; | 282 output_format.width = 0; |
| 281 output_format.height = 0; | 283 output_format.height = 0; |
| 282 adapter_.OnOutputFormatRequest(output_format); | 284 adapter_.OnOutputFormatRequest(output_format); |
| 283 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, | 285 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 284 &cropped_width_, &cropped_height_, | 286 capture_format_.width, capture_format_.height, |
| 285 &out_width_, &out_height_); | 287 &cropped_width_, &cropped_height_, |
| 286 EXPECT_EQ(0, out_width_); | 288 &out_width_, &out_height_)); |
| 287 EXPECT_EQ(0, out_height_); | |
| 288 } | 289 } |
| 289 | 290 |
| 290 // Adapt the frame resolution to be a quarter of the capture resolution at the | 291 // Adapt the frame resolution to be a quarter of the capture resolution at the |
| 291 // beginning. Expect no cropping but a resolution change. | 292 // beginning. Expect no cropping but a resolution change. |
| 292 TEST_F(VideoAdapterTest, AdaptResolution) { | 293 TEST_F(VideoAdapterTest, AdaptResolution) { |
| 293 VideoFormat request_format = capture_format_; | 294 VideoFormat request_format = capture_format_; |
| 294 request_format.width /= 2; | 295 request_format.width /= 2; |
| 295 request_format.height /= 2; | 296 request_format.height /= 2; |
| 296 adapter_.OnOutputFormatRequest(request_format); | 297 adapter_.OnOutputFormatRequest(request_format); |
| 297 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 298 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 344 |
| 344 // Verify all frames are dropped. | 345 // Verify all frames are dropped. |
| 345 VideoCapturerListener::Stats stats = listener_->GetStats(); | 346 VideoCapturerListener::Stats stats = listener_->GetStats(); |
| 346 EXPECT_GE(stats.captured_frames, 10); | 347 EXPECT_GE(stats.captured_frames, 10); |
| 347 EXPECT_EQ(stats.captured_frames, stats.dropped_frames); | 348 EXPECT_EQ(stats.captured_frames, stats.dropped_frames); |
| 348 } | 349 } |
| 349 | 350 |
| 350 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) { | 351 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) { |
| 351 VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), 0); | 352 VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), 0); |
| 352 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 353 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); |
| 353 adapter_.AdaptFrameResolution(640, 400, | 354 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 354 &cropped_width_, &cropped_height_, | 355 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 355 &out_width_, &out_height_); | |
| 356 EXPECT_EQ(640, cropped_width_); | 356 EXPECT_EQ(640, cropped_width_); |
| 357 EXPECT_EQ(400, cropped_height_); | 357 EXPECT_EQ(400, cropped_height_); |
| 358 EXPECT_EQ(640, out_width_); | 358 EXPECT_EQ(640, out_width_); |
| 359 EXPECT_EQ(400, out_height_); | 359 EXPECT_EQ(400, out_height_); |
| 360 | 360 |
| 361 // Format request 640x400. | 361 // Format request 640x400. |
| 362 format.height = 400; | 362 format.height = 400; |
| 363 adapter_.OnOutputFormatRequest(format); | 363 adapter_.OnOutputFormatRequest(format); |
| 364 adapter_.AdaptFrameResolution(640, 400, | 364 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 365 &cropped_width_, &cropped_height_, | 365 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 366 &out_width_, &out_height_); | |
| 367 EXPECT_EQ(640, cropped_width_); | 366 EXPECT_EQ(640, cropped_width_); |
| 368 EXPECT_EQ(400, cropped_height_); | 367 EXPECT_EQ(400, cropped_height_); |
| 369 EXPECT_EQ(640, out_width_); | 368 EXPECT_EQ(640, out_width_); |
| 370 EXPECT_EQ(400, out_height_); | 369 EXPECT_EQ(400, out_height_); |
| 371 | 370 |
| 372 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but | 371 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but |
| 373 // no scaling. | 372 // no scaling. |
| 374 format.width = 1280; | 373 format.width = 1280; |
| 375 format.height = 720; | 374 format.height = 720; |
| 376 adapter_.OnOutputFormatRequest(format); | 375 adapter_.OnOutputFormatRequest(format); |
| 377 adapter_.AdaptFrameResolution(640, 400, | 376 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 378 &cropped_width_, &cropped_height_, | 377 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 379 &out_width_, &out_height_); | |
| 380 EXPECT_EQ(640, cropped_width_); | 378 EXPECT_EQ(640, cropped_width_); |
| 381 EXPECT_EQ(360, cropped_height_); | 379 EXPECT_EQ(360, cropped_height_); |
| 382 EXPECT_EQ(640, out_width_); | 380 EXPECT_EQ(640, out_width_); |
| 383 EXPECT_EQ(360, out_height_); | 381 EXPECT_EQ(360, out_height_); |
| 384 | 382 |
| 385 // Request 0x0. | 383 // Request 0x0. |
| 386 format.width = 0; | 384 format.width = 0; |
| 387 format.height = 0; | 385 format.height = 0; |
| 388 adapter_.OnOutputFormatRequest(format); | 386 adapter_.OnOutputFormatRequest(format); |
| 389 adapter_.AdaptFrameResolution(640, 400, | 387 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 390 &cropped_width_, &cropped_height_, | 388 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 391 &out_width_, &out_height_); | |
| 392 EXPECT_EQ(0, out_width_); | |
| 393 EXPECT_EQ(0, out_height_); | |
| 394 | 389 |
| 395 // Request 320x200. Expect scaling, but no cropping. | 390 // Request 320x200. Expect scaling, but no cropping. |
| 396 format.width = 320; | 391 format.width = 320; |
| 397 format.height = 200; | 392 format.height = 200; |
| 398 adapter_.OnOutputFormatRequest(format); | 393 adapter_.OnOutputFormatRequest(format); |
| 399 adapter_.AdaptFrameResolution(640, 400, | 394 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 400 &cropped_width_, &cropped_height_, | 395 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 401 &out_width_, &out_height_); | |
| 402 EXPECT_EQ(640, cropped_width_); | 396 EXPECT_EQ(640, cropped_width_); |
| 403 EXPECT_EQ(400, cropped_height_); | 397 EXPECT_EQ(400, cropped_height_); |
| 404 EXPECT_EQ(320, out_width_); | 398 EXPECT_EQ(320, out_width_); |
| 405 EXPECT_EQ(200, out_height_); | 399 EXPECT_EQ(200, out_height_); |
| 406 | 400 |
| 407 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3 | 401 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3 |
| 408 // is not optimized and not allowed, therefore 1/2 scaling will be used | 402 // is not optimized and not allowed, therefore 1/2 scaling will be used |
| 409 // instead. | 403 // instead. |
| 410 format.width = 424; | 404 format.width = 424; |
| 411 format.height = 265; | 405 format.height = 265; |
| 412 adapter_.OnOutputFormatRequest(format); | 406 adapter_.OnOutputFormatRequest(format); |
| 413 adapter_.AdaptFrameResolution(640, 400, | 407 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 414 &cropped_width_, &cropped_height_, | 408 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 415 &out_width_, &out_height_); | |
| 416 EXPECT_EQ(640, cropped_width_); | 409 EXPECT_EQ(640, cropped_width_); |
| 417 EXPECT_EQ(400, cropped_height_); | 410 EXPECT_EQ(400, cropped_height_); |
| 418 EXPECT_EQ(320, out_width_); | 411 EXPECT_EQ(320, out_width_); |
| 419 EXPECT_EQ(200, out_height_); | 412 EXPECT_EQ(200, out_height_); |
| 420 | 413 |
| 421 // Request resolution of 3 / 8. Expect adapt down. | 414 // Request resolution of 3 / 8. Expect adapt down. |
| 422 format.width = 640 * 3 / 8; | 415 format.width = 640 * 3 / 8; |
| 423 format.height = 400 * 3 / 8; | 416 format.height = 400 * 3 / 8; |
| 424 adapter_.OnOutputFormatRequest(format); | 417 adapter_.OnOutputFormatRequest(format); |
| 425 adapter_.AdaptFrameResolution(640, 400, | 418 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 426 &cropped_width_, &cropped_height_, | 419 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 427 &out_width_, &out_height_); | |
| 428 EXPECT_EQ(640, cropped_width_); | 420 EXPECT_EQ(640, cropped_width_); |
| 429 EXPECT_EQ(400, cropped_height_); | 421 EXPECT_EQ(400, cropped_height_); |
| 430 EXPECT_EQ(640 * 3 / 8, out_width_); | 422 EXPECT_EQ(640 * 3 / 8, out_width_); |
| 431 EXPECT_EQ(400 * 3 / 8, out_height_); | 423 EXPECT_EQ(400 * 3 / 8, out_height_); |
| 432 | 424 |
| 433 // Switch back up. Expect adapt. | 425 // Switch back up. Expect adapt. |
| 434 format.width = 320; | 426 format.width = 320; |
| 435 format.height = 200; | 427 format.height = 200; |
| 436 adapter_.OnOutputFormatRequest(format); | 428 adapter_.OnOutputFormatRequest(format); |
| 437 adapter_.AdaptFrameResolution(640, 400, | 429 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 438 &cropped_width_, &cropped_height_, | 430 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 439 &out_width_, &out_height_); | |
| 440 EXPECT_EQ(640, cropped_width_); | 431 EXPECT_EQ(640, cropped_width_); |
| 441 EXPECT_EQ(400, cropped_height_); | 432 EXPECT_EQ(400, cropped_height_); |
| 442 EXPECT_EQ(320, out_width_); | 433 EXPECT_EQ(320, out_width_); |
| 443 EXPECT_EQ(200, out_height_); | 434 EXPECT_EQ(200, out_height_); |
| 444 | 435 |
| 445 // Format request 480x300. | 436 // Format request 480x300. |
| 446 format.width = 480; | 437 format.width = 480; |
| 447 format.height = 300; | 438 format.height = 300; |
| 448 adapter_.OnOutputFormatRequest(format); | 439 adapter_.OnOutputFormatRequest(format); |
| 449 adapter_.AdaptFrameResolution(640, 400, | 440 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 450 &cropped_width_, &cropped_height_, | 441 640, 400, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 451 &out_width_, &out_height_); | |
| 452 EXPECT_EQ(640, cropped_width_); | 442 EXPECT_EQ(640, cropped_width_); |
| 453 EXPECT_EQ(400, cropped_height_); | 443 EXPECT_EQ(400, cropped_height_); |
| 454 EXPECT_EQ(480, out_width_); | 444 EXPECT_EQ(480, out_width_); |
| 455 EXPECT_EQ(300, out_height_); | 445 EXPECT_EQ(300, out_height_); |
| 456 } | 446 } |
| 457 | 447 |
| 458 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) { | 448 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) { |
| 459 // Start at HD. | 449 // Start at HD. |
| 460 VideoFormat format(1280, 720, VideoFormat::FpsToInterval(30), 0); | 450 VideoFormat format(1280, 720, VideoFormat::FpsToInterval(30), 0); |
| 461 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 451 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); |
| 462 adapter_.AdaptFrameResolution(1280, 720, | 452 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 463 &cropped_width_, &cropped_height_, | 453 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 464 &out_width_, &out_height_); | |
| 465 EXPECT_EQ(1280, cropped_width_); | 454 EXPECT_EQ(1280, cropped_width_); |
| 466 EXPECT_EQ(720, cropped_height_); | 455 EXPECT_EQ(720, cropped_height_); |
| 467 EXPECT_EQ(1280, out_width_); | 456 EXPECT_EQ(1280, out_width_); |
| 468 EXPECT_EQ(720, out_height_); | 457 EXPECT_EQ(720, out_height_); |
| 469 | 458 |
| 470 // Format request for VGA. | 459 // Format request for VGA. |
| 471 format.width = 640; | 460 format.width = 640; |
| 472 format.height = 360; | 461 format.height = 360; |
| 473 adapter_.OnOutputFormatRequest(format); | 462 adapter_.OnOutputFormatRequest(format); |
| 474 adapter_.AdaptFrameResolution(1280, 720, | 463 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 475 &cropped_width_, &cropped_height_, | 464 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 476 &out_width_, &out_height_); | |
| 477 EXPECT_EQ(1280, cropped_width_); | 465 EXPECT_EQ(1280, cropped_width_); |
| 478 EXPECT_EQ(720, cropped_height_); | 466 EXPECT_EQ(720, cropped_height_); |
| 479 EXPECT_EQ(640, out_width_); | 467 EXPECT_EQ(640, out_width_); |
| 480 EXPECT_EQ(360, out_height_); | 468 EXPECT_EQ(360, out_height_); |
| 481 | 469 |
| 482 // Now, the camera reopens at VGA. | 470 // Now, the camera reopens at VGA. |
| 483 // Both the frame and the output format should be 640x360. | 471 // Both the frame and the output format should be 640x360. |
| 484 adapter_.AdaptFrameResolution(640, 360, | 472 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 485 &cropped_width_, &cropped_height_, | 473 640, 360, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 486 &out_width_, &out_height_); | |
| 487 EXPECT_EQ(640, cropped_width_); | 474 EXPECT_EQ(640, cropped_width_); |
| 488 EXPECT_EQ(360, cropped_height_); | 475 EXPECT_EQ(360, cropped_height_); |
| 489 EXPECT_EQ(640, out_width_); | 476 EXPECT_EQ(640, out_width_); |
| 490 EXPECT_EQ(360, out_height_); | 477 EXPECT_EQ(360, out_height_); |
| 491 | 478 |
| 492 // And another view request comes in for 640x360, which should have no | 479 // And another view request comes in for 640x360, which should have no |
| 493 // real impact. | 480 // real impact. |
| 494 adapter_.OnOutputFormatRequest(format); | 481 adapter_.OnOutputFormatRequest(format); |
| 495 adapter_.AdaptFrameResolution(640, 360, | 482 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 496 &cropped_width_, &cropped_height_, | 483 640, 360, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 497 &out_width_, &out_height_); | |
| 498 EXPECT_EQ(640, cropped_width_); | 484 EXPECT_EQ(640, cropped_width_); |
| 499 EXPECT_EQ(360, cropped_height_); | 485 EXPECT_EQ(360, cropped_height_); |
| 500 EXPECT_EQ(640, out_width_); | 486 EXPECT_EQ(640, out_width_); |
| 501 EXPECT_EQ(360, out_height_); | 487 EXPECT_EQ(360, out_height_); |
| 502 } | 488 } |
| 503 | 489 |
| 504 TEST_F(VideoAdapterTest, TestVGAWidth) { | 490 TEST_F(VideoAdapterTest, TestVGAWidth) { |
| 505 // Reqeuested Output format is 640x360. | 491 // Reqeuested Output format is 640x360. |
| 506 VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); | 492 VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
| 507 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 493 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); |
| 508 adapter_.OnOutputFormatRequest(format); | 494 adapter_.OnOutputFormatRequest(format); |
| 509 | 495 |
| 510 adapter_.AdaptFrameResolution(640, 480, | 496 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 511 &cropped_width_, &cropped_height_, | 497 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 512 &out_width_, &out_height_); | |
| 513 // Expect cropping. | 498 // Expect cropping. |
| 514 EXPECT_EQ(640, cropped_width_); | 499 EXPECT_EQ(640, cropped_width_); |
| 515 EXPECT_EQ(360, cropped_height_); | 500 EXPECT_EQ(360, cropped_height_); |
| 516 EXPECT_EQ(640, out_width_); | 501 EXPECT_EQ(640, out_width_); |
| 517 EXPECT_EQ(360, out_height_); | 502 EXPECT_EQ(360, out_height_); |
| 518 | 503 |
| 519 // But if frames come in at 640x360, we shouldn't adapt them down. | 504 // But if frames come in at 640x360, we shouldn't adapt them down. |
| 520 adapter_.AdaptFrameResolution(640, 360, | 505 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 521 &cropped_width_, &cropped_height_, | 506 640, 360, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 522 &out_width_, &out_height_); | |
| 523 EXPECT_EQ(640, cropped_width_); | 507 EXPECT_EQ(640, cropped_width_); |
| 524 EXPECT_EQ(360, cropped_height_); | 508 EXPECT_EQ(360, cropped_height_); |
| 525 EXPECT_EQ(640, out_width_); | 509 EXPECT_EQ(640, out_width_); |
| 526 EXPECT_EQ(360, out_height_); | 510 EXPECT_EQ(360, out_height_); |
| 527 | 511 |
| 528 adapter_.AdaptFrameResolution(640, 480, | 512 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 529 &cropped_width_, &cropped_height_, | 513 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 530 &out_width_, &out_height_); | |
| 531 EXPECT_EQ(640, cropped_width_); | 514 EXPECT_EQ(640, cropped_width_); |
| 532 EXPECT_EQ(360, cropped_height_); | 515 EXPECT_EQ(360, cropped_height_); |
| 533 EXPECT_EQ(640, out_width_); | 516 EXPECT_EQ(640, out_width_); |
| 534 EXPECT_EQ(360, out_height_); | 517 EXPECT_EQ(360, out_height_); |
| 535 } | 518 } |
| 536 | 519 |
| 537 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { | 520 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { |
| 538 adapter_.AdaptFrameResolution(1280, 720, | 521 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 539 &cropped_width_, &cropped_height_, | 522 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 540 &out_width_, &out_height_); | |
| 541 EXPECT_EQ(1280, cropped_width_); | 523 EXPECT_EQ(1280, cropped_width_); |
| 542 EXPECT_EQ(720, cropped_height_); | 524 EXPECT_EQ(720, cropped_height_); |
| 543 EXPECT_EQ(1280, out_width_); | 525 EXPECT_EQ(1280, out_width_); |
| 544 EXPECT_EQ(720, out_height_); | 526 EXPECT_EQ(720, out_height_); |
| 545 | 527 |
| 546 // Adapt down one step. | 528 // Adapt down one step. |
| 547 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1), | 529 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1), |
| 548 rtc::Optional<int>()); | 530 rtc::Optional<int>()); |
| 549 adapter_.AdaptFrameResolution(1280, 720, | 531 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 550 &cropped_width_, &cropped_height_, | 532 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 551 &out_width_, &out_height_); | |
| 552 EXPECT_EQ(1280, cropped_width_); | 533 EXPECT_EQ(1280, cropped_width_); |
| 553 EXPECT_EQ(720, cropped_height_); | 534 EXPECT_EQ(720, cropped_height_); |
| 554 EXPECT_EQ(960, out_width_); | 535 EXPECT_EQ(960, out_width_); |
| 555 EXPECT_EQ(540, out_height_); | 536 EXPECT_EQ(540, out_height_); |
| 556 | 537 |
| 557 // Adapt down one step more. | 538 // Adapt down one step more. |
| 558 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1), | 539 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1), |
| 559 rtc::Optional<int>()); | 540 rtc::Optional<int>()); |
| 560 adapter_.AdaptFrameResolution(1280, 720, | 541 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 561 &cropped_width_, &cropped_height_, | 542 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 562 &out_width_, &out_height_); | |
| 563 EXPECT_EQ(1280, cropped_width_); | 543 EXPECT_EQ(1280, cropped_width_); |
| 564 EXPECT_EQ(720, cropped_height_); | 544 EXPECT_EQ(720, cropped_height_); |
| 565 EXPECT_EQ(640, out_width_); | 545 EXPECT_EQ(640, out_width_); |
| 566 EXPECT_EQ(360, out_height_); | 546 EXPECT_EQ(360, out_height_); |
| 567 | 547 |
| 568 // Adapt down one step more. | 548 // Adapt down one step more. |
| 569 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 549 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 570 rtc::Optional<int>()); | 550 rtc::Optional<int>()); |
| 571 adapter_.AdaptFrameResolution(1280, 720, | 551 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 572 &cropped_width_, &cropped_height_, | 552 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 573 &out_width_, &out_height_); | |
| 574 EXPECT_EQ(1280, cropped_width_); | 553 EXPECT_EQ(1280, cropped_width_); |
| 575 EXPECT_EQ(720, cropped_height_); | 554 EXPECT_EQ(720, cropped_height_); |
| 576 EXPECT_EQ(480, out_width_); | 555 EXPECT_EQ(480, out_width_); |
| 577 EXPECT_EQ(270, out_height_); | 556 EXPECT_EQ(270, out_height_); |
| 578 | 557 |
| 579 // Adapt up one step. | 558 // Adapt up one step. |
| 580 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 559 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 581 rtc::Optional<int>(480 * 270)); | 560 rtc::Optional<int>(480 * 270)); |
| 582 adapter_.AdaptFrameResolution(1280, 720, | 561 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 583 &cropped_width_, &cropped_height_, | 562 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 584 &out_width_, &out_height_); | |
| 585 EXPECT_EQ(1280, cropped_width_); | 563 EXPECT_EQ(1280, cropped_width_); |
| 586 EXPECT_EQ(720, cropped_height_); | 564 EXPECT_EQ(720, cropped_height_); |
| 587 EXPECT_EQ(640, out_width_); | 565 EXPECT_EQ(640, out_width_); |
| 588 EXPECT_EQ(360, out_height_); | 566 EXPECT_EQ(360, out_height_); |
| 589 | 567 |
| 590 // Adapt up one step more. | 568 // Adapt up one step more. |
| 591 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 569 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 592 rtc::Optional<int>(640 * 360)); | 570 rtc::Optional<int>(640 * 360)); |
| 593 adapter_.AdaptFrameResolution(1280, 720, | 571 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 594 &cropped_width_, &cropped_height_, | 572 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 595 &out_width_, &out_height_); | |
| 596 EXPECT_EQ(1280, cropped_width_); | 573 EXPECT_EQ(1280, cropped_width_); |
| 597 EXPECT_EQ(720, cropped_height_); | 574 EXPECT_EQ(720, cropped_height_); |
| 598 EXPECT_EQ(960, out_width_); | 575 EXPECT_EQ(960, out_width_); |
| 599 EXPECT_EQ(540, out_height_); | 576 EXPECT_EQ(540, out_height_); |
| 600 | 577 |
| 601 // Adapt up one step more. | 578 // Adapt up one step more. |
| 602 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 579 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 603 rtc::Optional<int>(960 * 720)); | 580 rtc::Optional<int>(960 * 720)); |
| 604 adapter_.AdaptFrameResolution(1280, 720, | 581 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 605 &cropped_width_, &cropped_height_, | 582 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 606 &out_width_, &out_height_); | |
| 607 EXPECT_EQ(1280, cropped_width_); | 583 EXPECT_EQ(1280, cropped_width_); |
| 608 EXPECT_EQ(720, cropped_height_); | 584 EXPECT_EQ(720, cropped_height_); |
| 609 EXPECT_EQ(1280, out_width_); | 585 EXPECT_EQ(1280, out_width_); |
| 610 EXPECT_EQ(720, out_height_); | 586 EXPECT_EQ(720, out_height_); |
| 611 } | 587 } |
| 612 | 588 |
| 613 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { | 589 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { |
| 614 adapter_.AdaptFrameResolution(1280, 720, | 590 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 615 &cropped_width_, &cropped_height_, | 591 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 616 &out_width_, &out_height_); | |
| 617 EXPECT_EQ(1280, cropped_width_); | 592 EXPECT_EQ(1280, cropped_width_); |
| 618 EXPECT_EQ(720, cropped_height_); | 593 EXPECT_EQ(720, cropped_height_); |
| 619 EXPECT_EQ(1280, out_width_); | 594 EXPECT_EQ(1280, out_width_); |
| 620 EXPECT_EQ(720, out_height_); | 595 EXPECT_EQ(720, out_height_); |
| 621 | 596 |
| 622 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>()); | 597 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>()); |
| 623 adapter_.AdaptFrameResolution(1280, 720, | 598 EXPECT_FALSE(adapter_.AdaptFrameResolution( |
| 624 &cropped_width_, &cropped_height_, | 599 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 625 &out_width_, &out_height_); | |
| 626 EXPECT_EQ(0, out_width_); | |
| 627 EXPECT_EQ(0, out_height_); | |
| 628 } | 600 } |
| 629 | 601 |
| 630 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { | 602 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { |
| 631 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 603 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 632 rtc::Optional<int>()); | 604 rtc::Optional<int>()); |
| 633 adapter_.AdaptFrameResolution(1280, 720, | 605 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 634 &cropped_width_, &cropped_height_, | 606 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 635 &out_width_, &out_height_); | |
| 636 EXPECT_EQ(1280, cropped_width_); | 607 EXPECT_EQ(1280, cropped_width_); |
| 637 EXPECT_EQ(720, cropped_height_); | 608 EXPECT_EQ(720, cropped_height_); |
| 638 EXPECT_EQ(480, out_width_); | 609 EXPECT_EQ(480, out_width_); |
| 639 EXPECT_EQ(270, out_height_); | 610 EXPECT_EQ(270, out_height_); |
| 640 | 611 |
| 641 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 612 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 642 rtc::Optional<int>(960 * 720)); | 613 rtc::Optional<int>(960 * 720)); |
| 643 adapter_.AdaptFrameResolution(1280, 720, | 614 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 644 &cropped_width_, &cropped_height_, | 615 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 645 &out_width_, &out_height_); | |
| 646 EXPECT_EQ(1280, cropped_width_); | 616 EXPECT_EQ(1280, cropped_width_); |
| 647 EXPECT_EQ(720, cropped_height_); | 617 EXPECT_EQ(720, cropped_height_); |
| 648 EXPECT_EQ(1280, out_width_); | 618 EXPECT_EQ(1280, out_width_); |
| 649 EXPECT_EQ(720, out_height_); | 619 EXPECT_EQ(720, out_height_); |
| 650 } | 620 } |
| 651 | 621 |
| 652 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { | 622 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { |
| 653 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 623 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 654 rtc::Optional<int>()); | 624 rtc::Optional<int>()); |
| 655 adapter_.AdaptFrameResolution(1280, 720, | 625 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 656 &cropped_width_, &cropped_height_, | 626 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 657 &out_width_, &out_height_); | |
| 658 EXPECT_EQ(1280, cropped_width_); | 627 EXPECT_EQ(1280, cropped_width_); |
| 659 EXPECT_EQ(720, cropped_height_); | 628 EXPECT_EQ(720, cropped_height_); |
| 660 EXPECT_EQ(480, out_width_); | 629 EXPECT_EQ(480, out_width_); |
| 661 EXPECT_EQ(270, out_height_); | 630 EXPECT_EQ(270, out_height_); |
| 662 | 631 |
| 663 VideoFormat new_format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); | 632 VideoFormat new_format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
| 664 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 633 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); |
| 665 adapter_.OnOutputFormatRequest(new_format); | 634 adapter_.OnOutputFormatRequest(new_format); |
| 666 adapter_.AdaptFrameResolution(1280, 720, | 635 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 667 &cropped_width_, &cropped_height_, | 636 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 668 &out_width_, &out_height_); | |
| 669 EXPECT_EQ(1280, cropped_width_); | 637 EXPECT_EQ(1280, cropped_width_); |
| 670 EXPECT_EQ(720, cropped_height_); | 638 EXPECT_EQ(720, cropped_height_); |
| 671 EXPECT_EQ(480, out_width_); | 639 EXPECT_EQ(480, out_width_); |
| 672 EXPECT_EQ(270, out_height_); | 640 EXPECT_EQ(270, out_height_); |
| 673 | 641 |
| 674 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 642 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 675 rtc::Optional<int>(960 * 720)); | 643 rtc::Optional<int>(960 * 720)); |
| 676 adapter_.AdaptFrameResolution(1280, 720, | 644 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 677 &cropped_width_, &cropped_height_, | 645 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 678 &out_width_, &out_height_); | |
| 679 EXPECT_EQ(1280, cropped_width_); | 646 EXPECT_EQ(1280, cropped_width_); |
| 680 EXPECT_EQ(720, cropped_height_); | 647 EXPECT_EQ(720, cropped_height_); |
| 681 EXPECT_EQ(640, out_width_); | 648 EXPECT_EQ(640, out_width_); |
| 682 EXPECT_EQ(360, out_height_); | 649 EXPECT_EQ(360, out_height_); |
| 683 } | 650 } |
| 684 | 651 |
| 685 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { | 652 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { |
| 686 adapter_.AdaptFrameResolution(1280, 720, | 653 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 687 &cropped_width_, &cropped_height_, | 654 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 688 &out_width_, &out_height_); | |
| 689 EXPECT_EQ(1280, cropped_width_); | 655 EXPECT_EQ(1280, cropped_width_); |
| 690 EXPECT_EQ(720, cropped_height_); | 656 EXPECT_EQ(720, cropped_height_); |
| 691 EXPECT_EQ(1280, out_width_); | 657 EXPECT_EQ(1280, out_width_); |
| 692 EXPECT_EQ(720, out_height_); | 658 EXPECT_EQ(720, out_height_); |
| 693 | 659 |
| 694 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 660 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 695 rtc::Optional<int>()); | 661 rtc::Optional<int>()); |
| 696 adapter_.AdaptFrameResolution(1280, 720, | 662 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 697 &cropped_width_, &cropped_height_, | 663 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 698 &out_width_, &out_height_); | |
| 699 EXPECT_EQ(1280, cropped_width_); | 664 EXPECT_EQ(1280, cropped_width_); |
| 700 EXPECT_EQ(720, cropped_height_); | 665 EXPECT_EQ(720, cropped_height_); |
| 701 EXPECT_EQ(480, out_width_); | 666 EXPECT_EQ(480, out_width_); |
| 702 EXPECT_EQ(270, out_height_); | 667 EXPECT_EQ(270, out_height_); |
| 703 | 668 |
| 704 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); | 669 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); |
| 705 adapter_.AdaptFrameResolution(1280, 720, | 670 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 706 &cropped_width_, &cropped_height_, | 671 1280, 720, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 707 &out_width_, &out_height_); | |
| 708 EXPECT_EQ(1280, cropped_width_); | 672 EXPECT_EQ(1280, cropped_width_); |
| 709 EXPECT_EQ(720, cropped_height_); | 673 EXPECT_EQ(720, cropped_height_); |
| 710 EXPECT_EQ(1280, out_width_); | 674 EXPECT_EQ(1280, out_width_); |
| 711 EXPECT_EQ(720, out_height_); | 675 EXPECT_EQ(720, out_height_); |
| 712 } | 676 } |
| 713 | 677 |
| 714 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { | 678 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { |
| 715 // Ask for 640x360 (16:9 aspect). | 679 // Ask for 640x360 (16:9 aspect). |
| 716 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 680 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); |
| 717 adapter_.OnOutputFormatRequest( | 681 adapter_.OnOutputFormatRequest( |
| 718 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420)); | 682 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420)); |
| 719 // Send 640x480 (4:3 aspect). | 683 // Send 640x480 (4:3 aspect). |
| 720 adapter_.AdaptFrameResolution(640, 480, | 684 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 721 &cropped_width_, &cropped_height_, | 685 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 722 &out_width_, &out_height_); | |
| 723 // Expect cropping to 16:9 format and no scaling. | 686 // Expect cropping to 16:9 format and no scaling. |
| 724 EXPECT_EQ(640, cropped_width_); | 687 EXPECT_EQ(640, cropped_width_); |
| 725 EXPECT_EQ(360, cropped_height_); | 688 EXPECT_EQ(360, cropped_height_); |
| 726 EXPECT_EQ(640, out_width_); | 689 EXPECT_EQ(640, out_width_); |
| 727 EXPECT_EQ(360, out_height_); | 690 EXPECT_EQ(360, out_height_); |
| 728 | 691 |
| 729 // Adapt down one step. | 692 // Adapt down one step. |
| 730 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), | 693 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), |
| 731 rtc::Optional<int>()); | 694 rtc::Optional<int>()); |
| 732 // Expect cropping to 16:9 format and 3/4 scaling. | 695 // Expect cropping to 16:9 format and 3/4 scaling. |
| 733 adapter_.AdaptFrameResolution(640, 480, | 696 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 734 &cropped_width_, &cropped_height_, | 697 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 735 &out_width_, &out_height_); | |
| 736 EXPECT_EQ(640, cropped_width_); | 698 EXPECT_EQ(640, cropped_width_); |
| 737 EXPECT_EQ(360, cropped_height_); | 699 EXPECT_EQ(360, cropped_height_); |
| 738 EXPECT_EQ(480, out_width_); | 700 EXPECT_EQ(480, out_width_); |
| 739 EXPECT_EQ(270, out_height_); | 701 EXPECT_EQ(270, out_height_); |
| 740 | 702 |
| 741 // Adapt down one step more. | 703 // Adapt down one step more. |
| 742 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1), | 704 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1), |
| 743 rtc::Optional<int>()); | 705 rtc::Optional<int>()); |
| 744 // Expect cropping to 16:9 format and 1/2 scaling. | 706 // Expect cropping to 16:9 format and 1/2 scaling. |
| 745 adapter_.AdaptFrameResolution(640, 480, | 707 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 746 &cropped_width_, &cropped_height_, | 708 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 747 &out_width_, &out_height_); | |
| 748 EXPECT_EQ(640, cropped_width_); | 709 EXPECT_EQ(640, cropped_width_); |
| 749 EXPECT_EQ(360, cropped_height_); | 710 EXPECT_EQ(360, cropped_height_); |
| 750 EXPECT_EQ(320, out_width_); | 711 EXPECT_EQ(320, out_width_); |
| 751 EXPECT_EQ(180, out_height_); | 712 EXPECT_EQ(180, out_height_); |
| 752 | 713 |
| 753 // Adapt up one step. | 714 // Adapt up one step. |
| 754 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 715 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 755 rtc::Optional<int>(320 * 180)); | 716 rtc::Optional<int>(320 * 180)); |
| 756 // Expect cropping to 16:9 format and 3/4 scaling. | 717 // Expect cropping to 16:9 format and 3/4 scaling. |
| 757 adapter_.AdaptFrameResolution(640, 480, | 718 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 758 &cropped_width_, &cropped_height_, | 719 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 759 &out_width_, &out_height_); | |
| 760 EXPECT_EQ(640, cropped_width_); | 720 EXPECT_EQ(640, cropped_width_); |
| 761 EXPECT_EQ(360, cropped_height_); | 721 EXPECT_EQ(360, cropped_height_); |
| 762 EXPECT_EQ(480, out_width_); | 722 EXPECT_EQ(480, out_width_); |
| 763 EXPECT_EQ(270, out_height_); | 723 EXPECT_EQ(270, out_height_); |
| 764 | 724 |
| 765 // Adapt up one step more. | 725 // Adapt up one step more. |
| 766 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 726 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 767 rtc::Optional<int>(480 * 270)); | 727 rtc::Optional<int>(480 * 270)); |
| 768 // Expect cropping to 16:9 format and no scaling. | 728 // Expect cropping to 16:9 format and no scaling. |
| 769 adapter_.AdaptFrameResolution(640, 480, | 729 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 770 &cropped_width_, &cropped_height_, | 730 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 771 &out_width_, &out_height_); | |
| 772 EXPECT_EQ(640, cropped_width_); | 731 EXPECT_EQ(640, cropped_width_); |
| 773 EXPECT_EQ(360, cropped_height_); | 732 EXPECT_EQ(360, cropped_height_); |
| 774 EXPECT_EQ(640, out_width_); | 733 EXPECT_EQ(640, out_width_); |
| 775 EXPECT_EQ(360, out_height_); | 734 EXPECT_EQ(360, out_height_); |
| 776 | 735 |
| 777 // Try to adapt up one step more. | 736 // Try to adapt up one step more. |
| 778 adapter_.OnResolutionRequest(rtc::Optional<int>(), | 737 adapter_.OnResolutionRequest(rtc::Optional<int>(), |
| 779 rtc::Optional<int>(640 * 360)); | 738 rtc::Optional<int>(640 * 360)); |
| 780 // Expect cropping to 16:9 format and no scaling. | 739 // Expect cropping to 16:9 format and no scaling. |
| 781 adapter_.AdaptFrameResolution(640, 480, | 740 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 782 &cropped_width_, &cropped_height_, | 741 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 783 &out_width_, &out_height_); | |
| 784 EXPECT_EQ(640, cropped_width_); | 742 EXPECT_EQ(640, cropped_width_); |
| 785 EXPECT_EQ(360, cropped_height_); | 743 EXPECT_EQ(360, cropped_height_); |
| 786 EXPECT_EQ(640, out_width_); | 744 EXPECT_EQ(640, out_width_); |
| 787 EXPECT_EQ(360, out_height_); | 745 EXPECT_EQ(360, out_height_); |
| 788 } | 746 } |
| 789 | 747 |
| 790 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { | 748 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { |
| 791 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. | 749 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. |
| 792 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); | 750 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); |
| 793 adapter_.OnOutputFormatRequest( | 751 adapter_.OnOutputFormatRequest( |
| 794 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420)); | 752 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420)); |
| 795 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), | 753 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), |
| 796 rtc::Optional<int>()); | 754 rtc::Optional<int>()); |
| 797 | 755 |
| 798 // Send 640x480 (4:3 aspect). | 756 // Send 640x480 (4:3 aspect). |
| 799 adapter_.AdaptFrameResolution(640, 480, | 757 EXPECT_TRUE(adapter_.AdaptFrameResolution( |
| 800 &cropped_width_, &cropped_height_, | 758 640, 480, &cropped_width_, &cropped_height_, &out_width_, &out_height_)); |
| 801 &out_width_, &out_height_); | |
| 802 | 759 |
| 803 // Instead of getting the exact aspect ratio with cropped resolution 640x360, | 760 // Instead of getting the exact aspect ratio with cropped resolution 640x360, |
| 804 // the resolution should be adjusted to get a perfect scale factor instead. | 761 // the resolution should be adjusted to get a perfect scale factor instead. |
| 805 EXPECT_EQ(640, cropped_width_); | 762 EXPECT_EQ(640, cropped_width_); |
| 806 EXPECT_EQ(368, cropped_height_); | 763 EXPECT_EQ(368, cropped_height_); |
| 807 EXPECT_EQ(120, out_width_); | 764 EXPECT_EQ(120, out_width_); |
| 808 EXPECT_EQ(69, out_height_); | 765 EXPECT_EQ(69, out_height_); |
| 809 } | 766 } |
| 810 | 767 |
| 811 } // namespace cricket | 768 } // namespace cricket |
| OLD | NEW |