OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/child/child_process.h" | 13 #include "content/child/child_process.h" |
14 #include "content/renderer/media/media_stream_video_source.h" | 14 #include "content/renderer/media/media_stream_video_source.h" |
15 #include "content/renderer/media/media_stream_video_track.h" | 15 #include "content/renderer/media/media_stream_video_track.h" |
16 #include "content/renderer/media/mock_media_constraint_factory.h" | 16 #include "content/renderer/media/mock_constraint_factory.h" |
17 #include "content/renderer/media/mock_media_stream_video_sink.h" | 17 #include "content/renderer/media/mock_media_stream_video_sink.h" |
18 #include "content/renderer/media/mock_media_stream_video_source.h" | 18 #include "content/renderer/media/mock_media_stream_video_source.h" |
| 19 #include "media/base/limits.h" |
19 #include "media/base/video_frame.h" | 20 #include "media/base/video_frame.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/web/WebHeap.h" | 22 #include "third_party/WebKit/public/web/WebHeap.h" |
22 | 23 |
23 using ::testing::_; | 24 using ::testing::_; |
24 using ::testing::DoAll; | 25 using ::testing::DoAll; |
25 using ::testing::SaveArg; | 26 using ::testing::SaveArg; |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); | 290 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); |
290 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); | 291 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); |
291 mock_source()->CompleteGetSupportedFormats(); | 292 mock_source()->CompleteGetSupportedFormats(); |
292 mock_source()->StartMockedSource(); | 293 mock_source()->StartMockedSource(); |
293 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); | 294 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); |
294 } | 295 } |
295 | 296 |
296 // Test that the capture output is CIF if we set max constraints to CIF. | 297 // Test that the capture output is CIF if we set max constraints to CIF. |
297 // and the capture device support CIF. | 298 // and the capture device support CIF. |
298 TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5Fps) { | 299 TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5Fps) { |
299 MockMediaConstraintFactory factory; | 300 MockConstraintFactory factory; |
300 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 352); | 301 factory.basic().width.setMax(352); |
301 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 288); | 302 factory.basic().height.setMax(288); |
302 factory.AddMandatory(MediaStreamVideoSource::kMaxFrameRate, 5); | 303 factory.basic().frameRate.setMax(5.0); |
303 | 304 |
304 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 352, 288, 5); | 305 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 352, 288, 5); |
305 } | 306 } |
306 | 307 |
307 // Test that the capture output is 720P if the camera support it and the | 308 // Test that the capture output is 720P if the camera support it and the |
308 // optional constraint is set to 720P. | 309 // optional constraint is set to 720P. |
309 TEST_F(MediaStreamVideoSourceTest, MandatoryMinVgaOptional720P) { | 310 TEST_F(MediaStreamVideoSourceTest, MandatoryMinVgaOptional720P) { |
310 MockMediaConstraintFactory factory; | 311 MockConstraintFactory factory; |
311 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640); | 312 factory.basic().width.setMin(640); |
312 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480); | 313 factory.basic().height.setMin(480); |
313 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 314 factory.add_advanced().width.setMin(1280); |
314 factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio, 1280.0 / 720); | 315 factory.add_advanced().aspectRatio.setMin(1280.0 / 720); |
315 | 316 |
316 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); | 317 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); |
317 } | 318 } |
318 | 319 |
319 // Test that the capture output have aspect ratio 4:3 if a mandatory constraint | 320 // Test that the capture output have aspect ratio 4:3 if a mandatory constraint |
320 // require it even if an optional constraint request a higher resolution | 321 // require it even if an optional constraint request a higher resolution |
321 // that don't have this aspect ratio. | 322 // that don't have this aspect ratio. |
322 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) { | 323 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) { |
323 MockMediaConstraintFactory factory; | 324 MockConstraintFactory factory; |
324 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640); | 325 factory.basic().width.setMin(640); |
325 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480); | 326 factory.basic().height.setMin(480); |
326 factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, 640.0 / 480); | 327 factory.basic().aspectRatio.setMax(640.0 / 480); |
327 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 328 factory.add_advanced().width.setMin(1280); |
328 | 329 |
329 TestSourceCropFrame(1280, 720, | 330 TestSourceCropFrame(1280, 720, |
330 factory.CreateWebMediaConstraints(), 960, 720); | 331 factory.CreateWebMediaConstraints(), 960, 720); |
331 } | 332 } |
332 | 333 |
333 // Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2. | 334 // Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2. |
334 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio2) { | 335 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio2) { |
335 MockMediaConstraintFactory factory; | 336 MockConstraintFactory factory; |
336 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); | 337 factory.basic().aspectRatio.setMin(2.0); |
337 | 338 |
338 TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth, | 339 TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth, |
339 MediaStreamVideoSource::kDefaultHeight, | 340 MediaStreamVideoSource::kDefaultHeight, |
340 factory.CreateWebMediaConstraints(), 640, 320); | 341 factory.CreateWebMediaConstraints(), 640, 320); |
341 } | 342 } |
342 | 343 |
343 TEST_F(MediaStreamVideoSourceTest, MinAspectRatioLargerThanMaxAspectRatio) { | 344 TEST_F(MediaStreamVideoSourceTest, MinAspectRatioLargerThanMaxAspectRatio) { |
344 MockMediaConstraintFactory factory; | 345 MockConstraintFactory factory; |
345 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); | 346 factory.basic().aspectRatio.setMin(2.0); |
346 factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, 1); | 347 factory.basic().aspectRatio.setMax(1.0); |
347 blink::WebMediaStreamTrack track = CreateTrack( | 348 blink::WebMediaStreamTrack track = CreateTrack( |
348 "123", factory.CreateWebMediaConstraints()); | 349 "123", factory.CreateWebMediaConstraints()); |
349 mock_source()->CompleteGetSupportedFormats(); | 350 mock_source()->CompleteGetSupportedFormats(); |
350 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 351 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
351 } | 352 } |
352 | 353 |
353 TEST_F(MediaStreamVideoSourceTest, MaxAspectRatioZero) { | 354 // This test doesn't seem to make sense. An optional constraint |
354 MockMediaConstraintFactory factory; | 355 // should be disregarded even if it's nonsensical. |
355 factory.AddOptional(MediaStreamVideoSource::kMaxAspectRatio, 0); | 356 TEST_F(MediaStreamVideoSourceTest, DISABLED_MaxAspectRatioZero) { |
| 357 MockConstraintFactory factory; |
| 358 factory.add_advanced().aspectRatio.setMax(0.0); |
356 blink::WebMediaStreamTrack track = CreateTrack( | 359 blink::WebMediaStreamTrack track = CreateTrack( |
357 "123", factory.CreateWebMediaConstraints()); | 360 "123", factory.CreateWebMediaConstraints()); |
358 mock_source()->CompleteGetSupportedFormats(); | 361 mock_source()->CompleteGetSupportedFormats(); |
359 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 362 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
360 } | 363 } |
361 | 364 |
362 TEST_F(MediaStreamVideoSourceTest, MinWidthLargerThanMaxWidth) { | 365 TEST_F(MediaStreamVideoSourceTest, MinWidthLargerThanMaxWidth) { |
363 MockMediaConstraintFactory factory; | 366 MockConstraintFactory factory; |
364 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640); | 367 factory.basic().width.setMin(640); |
365 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 320); | 368 factory.basic().width.setMax(320); |
366 blink::WebMediaStreamTrack track = CreateTrack( | 369 blink::WebMediaStreamTrack track = CreateTrack( |
367 "123", factory.CreateWebMediaConstraints()); | 370 "123", factory.CreateWebMediaConstraints()); |
368 mock_source()->CompleteGetSupportedFormats(); | 371 mock_source()->CompleteGetSupportedFormats(); |
369 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 372 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
370 } | 373 } |
371 | 374 |
372 TEST_F(MediaStreamVideoSourceTest, MinHeightLargerThanMaxHeight) { | 375 TEST_F(MediaStreamVideoSourceTest, MinHeightLargerThanMaxHeight) { |
373 MockMediaConstraintFactory factory; | 376 MockConstraintFactory factory; |
374 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480); | 377 factory.basic().height.setMin(480); |
375 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360); | 378 factory.basic().height.setMax(360); |
| 379 |
376 blink::WebMediaStreamTrack track = CreateTrack( | 380 blink::WebMediaStreamTrack track = CreateTrack( |
377 "123", factory.CreateWebMediaConstraints()); | 381 "123", factory.CreateWebMediaConstraints()); |
378 mock_source()->CompleteGetSupportedFormats(); | 382 mock_source()->CompleteGetSupportedFormats(); |
379 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 383 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
380 } | 384 } |
381 | 385 |
382 TEST_F(MediaStreamVideoSourceTest, MinFrameRateLargerThanMaxFrameRate) { | 386 TEST_F(MediaStreamVideoSourceTest, MinFrameRateLargerThanMaxFrameRate) { |
383 MockMediaConstraintFactory factory; | 387 MockConstraintFactory factory; |
384 factory.AddMandatory(MediaStreamVideoSource::kMinFrameRate, 25); | 388 factory.basic().frameRate.setMin(25); |
385 factory.AddMandatory(MediaStreamVideoSource::kMaxFrameRate, 15); | 389 factory.basic().frameRate.setMax(15); |
386 blink::WebMediaStreamTrack track = CreateTrack( | 390 blink::WebMediaStreamTrack track = CreateTrack( |
387 "123", factory.CreateWebMediaConstraints()); | 391 "123", factory.CreateWebMediaConstraints()); |
388 mock_source()->CompleteGetSupportedFormats(); | 392 mock_source()->CompleteGetSupportedFormats(); |
389 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 393 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
390 } | 394 } |
391 | 395 |
392 // Test that its safe to release the last reference of a blink track and the | 396 // Test that its safe to release the last reference of a blink track and the |
393 // source during the callback if adding a track succeeds. | 397 // source during the callback if adding a track succeeds. |
394 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) { | 398 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) { |
395 MockMediaConstraintFactory factory; | 399 MockConstraintFactory factory; |
396 { | 400 { |
397 blink::WebMediaStreamTrack track = | 401 blink::WebMediaStreamTrack track = |
398 CreateTrack("123", factory.CreateWebMediaConstraints()); | 402 CreateTrack("123", factory.CreateWebMediaConstraints()); |
399 ReleaseTrackAndSourceOnAddTrackCallback(track); | 403 ReleaseTrackAndSourceOnAddTrackCallback(track); |
400 } | 404 } |
401 mock_source()->CompleteGetSupportedFormats(); | 405 mock_source()->CompleteGetSupportedFormats(); |
402 mock_source()->StartMockedSource(); | 406 mock_source()->StartMockedSource(); |
403 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | 407 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); |
404 } | 408 } |
405 | 409 |
406 // Test that its safe to release the last reference of a blink track and the | 410 // Test that its safe to release the last reference of a blink track and the |
407 // source during the callback if adding a track fails. | 411 // source during the callback if adding a track fails. |
408 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnFailureCallBack) { | 412 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnFailureCallBack) { |
409 MockMediaConstraintFactory factory; | 413 MockConstraintFactory factory; |
410 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 99999); | 414 factory.basic().width.setMin(99999); |
411 { | 415 { |
412 blink::WebMediaStreamTrack track = | 416 blink::WebMediaStreamTrack track = |
413 CreateTrack("123", factory.CreateWebMediaConstraints()); | 417 CreateTrack("123", factory.CreateWebMediaConstraints()); |
414 ReleaseTrackAndSourceOnAddTrackCallback(track); | 418 ReleaseTrackAndSourceOnAddTrackCallback(track); |
415 } | 419 } |
416 mock_source()->CompleteGetSupportedFormats(); | 420 mock_source()->CompleteGetSupportedFormats(); |
417 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 421 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
418 } | 422 } |
419 | 423 |
420 // Test that the source ignores an optional aspect ratio that is higher than | 424 // Test that the source ignores an optional aspect ratio that is higher than |
421 // supported. | 425 // supported. |
422 TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHigh) { | 426 TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHigh) { |
423 MockMediaConstraintFactory factory; | 427 MockConstraintFactory factory; |
424 factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio, 2); | 428 factory.add_advanced().aspectRatio.setMin(2.0); |
425 blink::WebMediaStreamTrack track = CreateTrack( | 429 blink::WebMediaStreamTrack track = CreateTrack( |
426 "123", factory.CreateWebMediaConstraints()); | 430 "123", factory.CreateWebMediaConstraints()); |
427 mock_source()->CompleteGetSupportedFormats(); | 431 mock_source()->CompleteGetSupportedFormats(); |
428 | 432 |
429 const media::VideoCaptureFormat& format = mock_source()->start_format(); | 433 const media::VideoCaptureFormat& format = mock_source()->start_format(); |
430 const double aspect_ratio = static_cast<double>(format.frame_size.width()) / | 434 const double aspect_ratio = static_cast<double>(format.frame_size.width()) / |
431 format.frame_size.height(); | 435 format.frame_size.height(); |
432 EXPECT_LT(aspect_ratio, 2); | 436 EXPECT_LT(aspect_ratio, 2); |
433 } | 437 } |
434 | 438 |
(...skipping 10 matching lines...) Expand all Loading... |
445 | 449 |
446 blink::WebMediaConstraints constraints; | 450 blink::WebMediaConstraints constraints; |
447 constraints.initialize(); | 451 constraints.initialize(); |
448 CreateTrackAndStartSource(constraints, | 452 CreateTrackAndStartSource(constraints, |
449 MediaStreamVideoSource::kDefaultWidth, | 453 MediaStreamVideoSource::kDefaultWidth, |
450 MediaStreamVideoSource::kDefaultHeight, | 454 MediaStreamVideoSource::kDefaultHeight, |
451 30); | 455 30); |
452 } | 456 } |
453 | 457 |
454 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) { | 458 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) { |
455 MockMediaConstraintFactory factory; | 459 MockConstraintFactory factory; |
456 factory.AddMandatory("weird key", 640); | 460 // Use a constraint that is only known for audio. |
| 461 factory.basic().echoCancellation.setExact(true); |
457 blink::WebMediaStreamTrack track = CreateTrack( | 462 blink::WebMediaStreamTrack track = CreateTrack( |
458 "123", factory.CreateWebMediaConstraints()); | 463 "123", factory.CreateWebMediaConstraints()); |
459 mock_source()->CompleteGetSupportedFormats(); | 464 mock_source()->CompleteGetSupportedFormats(); |
460 EXPECT_EQ(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, error_type()); | 465 EXPECT_EQ(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, error_type()); |
461 EXPECT_EQ("weird key", error_name()); | 466 EXPECT_EQ("echoCancellation", error_name()); |
462 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 467 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
463 } | 468 } |
464 | 469 |
465 // Test that the source ignores an unknown optional constraint. | 470 // Test that the source ignores an unknown optional constraint. |
466 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) { | 471 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) { |
467 MockMediaConstraintFactory factory; | 472 MockConstraintFactory factory; |
468 factory.AddOptional("weird key", 640); | 473 factory.add_advanced().echoCancellation.setExact(true); |
469 | 474 |
470 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), | 475 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), |
471 MediaStreamVideoSource::kDefaultWidth, | 476 MediaStreamVideoSource::kDefaultWidth, |
472 MediaStreamVideoSource::kDefaultHeight, | 477 MediaStreamVideoSource::kDefaultHeight, |
473 30); | 478 30); |
474 } | 479 } |
475 | 480 |
476 // Tests that the source starts video with the max width and height set by | 481 // Tests that the source starts video with the max width and height set by |
477 // constraints for screencast. | 482 // constraints for screencast. |
478 TEST_F(MediaStreamVideoSourceTest, ScreencastResolutionWithConstraint) { | 483 TEST_F(MediaStreamVideoSourceTest, ScreencastResolutionWithConstraint) { |
479 media::VideoCaptureFormats formats; | 484 media::VideoCaptureFormats formats; |
480 formats.push_back(media::VideoCaptureFormat( | 485 formats.push_back(media::VideoCaptureFormat( |
481 gfx::Size(480, 270), 30, media::PIXEL_FORMAT_I420)); | 486 gfx::Size(480, 270), 30, media::PIXEL_FORMAT_I420)); |
482 mock_source()->SetSupportedFormats(formats); | 487 mock_source()->SetSupportedFormats(formats); |
483 MockMediaConstraintFactory factory; | 488 MockConstraintFactory factory; |
484 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 480); | 489 factory.basic().width.setMax(480); |
485 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 270); | 490 factory.basic().height.setMax(270); |
486 | 491 |
487 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( | 492 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( |
488 factory.CreateWebMediaConstraints(), 480, 270, 30); | 493 factory.CreateWebMediaConstraints(), 480, 270, 30); |
489 EXPECT_EQ(480, mock_source()->max_requested_height()); | 494 EXPECT_EQ(480, mock_source()->max_requested_height()); |
490 EXPECT_EQ(270, mock_source()->max_requested_width()); | 495 EXPECT_EQ(270, mock_source()->max_requested_width()); |
491 } | 496 } |
492 | 497 |
493 // Test that optional constraints are applied in order. | 498 // Test that optional constraints are applied in order. |
494 TEST_F(MediaStreamVideoSourceTest, OptionalConstraints) { | 499 TEST_F(MediaStreamVideoSourceTest, OptionalConstraints) { |
495 MockMediaConstraintFactory factory; | 500 MockConstraintFactory factory; |
496 // Min width of 2056 pixels can not be fulfilled. | 501 // Min width of 2056 pixels can not be fulfilled. |
497 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 2056); | 502 factory.add_advanced().width.setMin(2056); |
498 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 641); | 503 factory.add_advanced().width.setMin(641); |
499 // Since min width is set to 641 pixels, max width 640 can not be fulfilled. | 504 // Since min width is set to 641 pixels, max width 640 can not be fulfilled. |
500 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); | 505 factory.add_advanced().width.setMax(640); |
501 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); | 506 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); |
502 } | 507 } |
503 | 508 |
504 // Test that the source crops to the requested max width and | 509 // Test that the source crops to the requested max width and |
505 // height even though the camera delivers a larger frame. | 510 // height even though the camera delivers a larger frame. |
506 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameOptional640360) { | 511 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameOptional640360) { |
507 MockMediaConstraintFactory factory; | 512 MockConstraintFactory factory; |
508 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); | 513 factory.add_advanced().width.setMax(640); |
509 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 360); | 514 factory.add_advanced().height.setMax(360); |
510 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); | 515 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); |
511 } | 516 } |
512 | 517 |
513 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory640360) { | 518 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory640360) { |
514 MockMediaConstraintFactory factory; | 519 MockConstraintFactory factory; |
515 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 640); | 520 factory.basic().width.setMax(640); |
516 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360); | 521 factory.basic().height.setMax(360); |
517 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); | 522 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 640, 360); |
518 } | 523 } |
519 | 524 |
520 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory732489) { | 525 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory732489) { |
521 MockMediaConstraintFactory factory; | 526 MockConstraintFactory factory; |
522 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 732); | 527 factory.basic().width.setMax(732); |
523 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 489); | 528 factory.basic().height.setMax(489); |
524 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 732); | 529 factory.basic().width.setMin(732); |
525 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 489); | 530 factory.basic().height.setMin(489); |
526 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 732, 489); | 531 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 732, 489); |
527 } | 532 } |
528 | 533 |
529 // Test that the source crops to the requested max width and | 534 // Test that the source crops to the requested max width and |
530 // height even though the requested frame has odd size. | 535 // height even though the requested frame has odd size. |
531 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) { | 536 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) { |
532 MockMediaConstraintFactory factory; | 537 MockConstraintFactory factory; |
533 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637); | 538 factory.add_advanced().width.setMax(637); |
534 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359); | 539 factory.add_advanced().height.setMax(359); |
535 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); | 540 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); |
536 } | 541 } |
537 | 542 |
538 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame320320) { | 543 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame320320) { |
539 MockMediaConstraintFactory factory; | 544 MockConstraintFactory factory; |
540 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 320); | 545 factory.basic().width.setMax(320); |
541 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 320); | 546 factory.basic().height.setMax(320); |
542 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 320); | 547 factory.basic().height.setMin(320); |
543 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 320); | 548 factory.basic().width.setMax(320); |
544 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320); | 549 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320); |
545 } | 550 } |
546 | 551 |
547 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) { | 552 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) { |
548 MockMediaConstraintFactory factory; | 553 MockConstraintFactory factory; |
549 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920); | 554 factory.add_advanced().width.setMax(1920); |
550 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080); | 555 factory.add_advanced().height.setMax(1080); |
551 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 556 factory.add_advanced().width.setMin(1280); |
552 factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720); | 557 factory.add_advanced().height.setMin(720); |
553 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), | 558 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), |
554 1280, 720); | 559 1280, 720); |
555 } | 560 } |
556 | 561 |
557 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) { | 562 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) { |
558 MockMediaConstraintFactory factory1; | 563 MockConstraintFactory factory1; |
559 factory1.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); | 564 factory1.add_advanced().width.setMax(640); |
560 factory1.AddOptional(MediaStreamVideoSource::kMaxHeight, 480); | 565 factory1.add_advanced().height.setMax(480); |
561 | 566 |
562 MockMediaConstraintFactory factory2; | 567 MockConstraintFactory factory2; |
563 factory2.AddOptional(MediaStreamVideoSource::kMaxHeight, 360); | 568 factory2.add_advanced().height.setMax(360); |
564 | 569 |
565 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | 570 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
566 factory2.CreateWebMediaConstraints(), | 571 factory2.CreateWebMediaConstraints(), |
567 640, 480, | 572 640, 480, |
568 640, 480, | 573 640, 480, |
569 640, 360); | 574 640, 360); |
570 } | 575 } |
571 | 576 |
572 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) { | 577 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) { |
573 MockMediaConstraintFactory factory1; | 578 MockConstraintFactory factory1; |
574 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 579 factory1.add_advanced().width.setMin(1280); |
575 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720); | 580 factory1.add_advanced().height.setMin(720); |
576 | 581 |
577 | 582 MockConstraintFactory factory2; |
578 MockMediaConstraintFactory factory2; | 583 factory2.basic().width.setMax(640); |
579 factory2.AddMandatory(MediaStreamVideoSource::kMaxWidth, 640); | 584 factory2.basic().height.setMax(360); |
580 factory2.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360); | |
581 | 585 |
582 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | 586 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
583 factory2.CreateWebMediaConstraints(), | 587 factory2.CreateWebMediaConstraints(), |
584 1280, 720, | 588 1280, 720, |
585 1280, 720, | 589 1280, 720, |
586 640, 360); | 590 640, 360); |
587 } | 591 } |
588 | 592 |
589 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndW700H700) { | 593 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndW700H700) { |
590 MockMediaConstraintFactory factory1; | 594 MockConstraintFactory factory1; |
591 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 595 factory1.add_advanced().width.setMin(1280); |
592 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720); | 596 factory1.add_advanced().height.setMin(720); |
593 | 597 |
594 MockMediaConstraintFactory factory2; | 598 MockConstraintFactory factory2; |
595 factory2.AddMandatory(MediaStreamVideoSource::kMaxWidth, 700); | 599 factory2.basic().width.setMax(700); |
596 factory2.AddMandatory(MediaStreamVideoSource::kMaxHeight, 700); | 600 factory2.basic().height.setMax(700); |
597 | 601 |
598 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | 602 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
599 factory2.CreateWebMediaConstraints(), | 603 factory2.CreateWebMediaConstraints(), |
600 1280, 720, | 604 1280, 720, |
601 1280, 720, | 605 1280, 720, |
602 700, 700); | 606 700, 700); |
603 } | 607 } |
604 | 608 |
605 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndMaxAspectRatio4To3) { | 609 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndMaxAspectRatio4To3) { |
606 MockMediaConstraintFactory factory1; | 610 MockConstraintFactory factory1; |
607 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 611 factory1.add_advanced().width.setMin(1280); |
608 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720); | 612 factory1.add_advanced().height.setMin(720); |
609 | 613 |
610 MockMediaConstraintFactory factory2; | 614 MockConstraintFactory factory2; |
611 factory2.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, 640.0 / 480); | 615 factory2.basic().aspectRatio.setMax(640.0 / 480); |
612 | 616 |
613 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | 617 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
614 factory2.CreateWebMediaConstraints(), | 618 factory2.CreateWebMediaConstraints(), |
615 1280, 720, | 619 1280, 720, |
616 1280, 720, | 620 1280, 720, |
617 960, 720); | 621 960, 720); |
618 } | 622 } |
619 | 623 |
620 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVgaAndMinAspectRatio) { | 624 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVgaAndMinAspectRatio) { |
621 MockMediaConstraintFactory factory1; | 625 MockConstraintFactory factory1; |
622 factory1.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); | 626 factory1.add_advanced().width.setMax(640); |
623 factory1.AddOptional(MediaStreamVideoSource::kMaxHeight, 480); | 627 factory1.add_advanced().height.setMax(480); |
624 | 628 |
625 MockMediaConstraintFactory factory2; | 629 MockConstraintFactory factory2; |
626 factory2.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 640.0 / 360); | 630 factory2.basic().aspectRatio.setMin(640.0 / 360); |
627 | 631 |
628 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), | 632 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
629 factory2.CreateWebMediaConstraints(), | 633 factory2.CreateWebMediaConstraints(), |
630 640, 480, | 634 640, 480, |
631 640, 480, | 635 640, 480, |
632 640, 360); | 636 640, 360); |
633 } | 637 } |
634 | 638 |
635 TEST_F(MediaStreamVideoSourceTest, | 639 TEST_F(MediaStreamVideoSourceTest, |
636 TwoTracksWithSecondTrackFrameRateHigherThanFirst) { | 640 TwoTracksWithSecondTrackFrameRateHigherThanFirst) { |
637 MockMediaConstraintFactory factory1; | 641 MockConstraintFactory factory1; |
638 factory1.AddMandatory(MediaStreamVideoSource::kMinFrameRate, 15); | 642 factory1.basic().frameRate.setMin(15); |
639 factory1.AddMandatory(MediaStreamVideoSource::kMaxFrameRate, 15); | 643 factory1.basic().frameRate.setMax(15); |
640 | 644 |
641 blink::WebMediaStreamTrack track1 = | 645 blink::WebMediaStreamTrack track1 = |
642 CreateTrackAndStartSource(factory1.CreateWebMediaConstraints(), | 646 CreateTrackAndStartSource(factory1.CreateWebMediaConstraints(), |
643 MediaStreamVideoSource::kDefaultWidth, | 647 MediaStreamVideoSource::kDefaultWidth, |
644 MediaStreamVideoSource::kDefaultHeight, | 648 MediaStreamVideoSource::kDefaultHeight, |
645 15); | 649 15); |
646 | 650 |
647 MockMediaConstraintFactory factory2; | 651 MockConstraintFactory factory2; |
648 factory2.AddMandatory(MediaStreamVideoSource::kMinFrameRate, 30); | 652 factory2.basic().frameRate.setMin(30); |
649 blink::WebMediaStreamTrack track2 = CreateTrack( | 653 blink::WebMediaStreamTrack track2 = CreateTrack( |
650 "123", factory2.CreateWebMediaConstraints()); | 654 "123", factory2.CreateWebMediaConstraints()); |
651 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 655 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
652 } | 656 } |
653 | 657 |
654 // Test that a source can change the frame resolution on the fly and that | 658 // Test that a source can change the frame resolution on the fly and that |
655 // tracks sinks get the new frame size unless constraints force the frame to be | 659 // tracks sinks get the new frame size unless constraints force the frame to be |
656 // cropped. | 660 // cropped. |
657 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) { | 661 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) { |
658 MockMediaConstraintFactory factory; | 662 MockConstraintFactory factory; |
659 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 800); | 663 factory.add_advanced().width.setMax(800); |
660 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 700); | 664 factory.add_advanced().height.setMax(700); |
661 | 665 |
662 // Expect the source to start capture with the supported resolution. | 666 // Expect the source to start capture with the supported resolution. |
663 blink::WebMediaStreamTrack track = | 667 blink::WebMediaStreamTrack track = |
664 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), | 668 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), |
665 640, 480, 30); | 669 640, 480, 30); |
666 | 670 |
667 MockMediaStreamVideoSink sink; | 671 MockMediaStreamVideoSink sink; |
668 MediaStreamVideoSink::AddToVideoTrack( | 672 MediaStreamVideoSink::AddToVideoTrack( |
669 &sink, sink.GetDeliverFrameCB(), track); | 673 &sink, sink.GetDeliverFrameCB(), track); |
670 EXPECT_EQ(0, sink.number_of_frames()); | 674 EXPECT_EQ(0, sink.number_of_frames()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 // Expect the delivered frame to be passed unchanged since its smaller than | 743 // Expect the delivered frame to be passed unchanged since its smaller than |
740 // max requested. | 744 // max requested. |
741 EXPECT_EQ(320, sink.frame_size().width()); | 745 EXPECT_EQ(320, sink.frame_size().width()); |
742 EXPECT_EQ(240, sink.frame_size().height()); | 746 EXPECT_EQ(240, sink.frame_size().height()); |
743 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); | 747 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); |
744 } | 748 } |
745 | 749 |
746 // Test that a source producing no frames change the source readyState to muted. | 750 // Test that a source producing no frames change the source readyState to muted. |
747 // that in a reasonable time frame the muted state turns to false. | 751 // that in a reasonable time frame the muted state turns to false. |
748 TEST_F(MediaStreamVideoSourceTest, MutedSource) { | 752 TEST_F(MediaStreamVideoSourceTest, MutedSource) { |
749 // Setup the source for support a frame rate of 2000fps in order to test | 753 // Setup the source for support a frame rate of 999 fps in order to test |
750 // the muted event faster. This is since the frame monitoring uses | 754 // the muted event faster. This is since the frame monitoring uses |
751 // PostDelayedTask that is dependent on the source frame rate. | 755 // PostDelayedTask that is dependent on the source frame rate. |
| 756 // Note that media::limits::kMaxFramesPerSecond is 1000. |
752 media::VideoCaptureFormats formats; | 757 media::VideoCaptureFormats formats; |
753 formats.push_back(media::VideoCaptureFormat( | 758 formats.push_back(media::VideoCaptureFormat( |
754 gfx::Size(640, 480), 2000, media::PIXEL_FORMAT_I420)); | 759 gfx::Size(640, 480), media::limits::kMaxFramesPerSecond - 1, |
| 760 media::PIXEL_FORMAT_I420)); |
755 SetSourceSupportedFormats(formats); | 761 SetSourceSupportedFormats(formats); |
756 | 762 |
757 MockMediaConstraintFactory factory; | 763 MockConstraintFactory factory; |
758 blink::WebMediaStreamTrack track = | 764 blink::WebMediaStreamTrack track = |
759 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), | 765 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, |
760 640, 480, 2000); | 766 media::limits::kMaxFramesPerSecond - 1); |
761 MockMediaStreamVideoSink sink; | 767 MockMediaStreamVideoSink sink; |
762 MediaStreamVideoSink::AddToVideoTrack(&sink, sink.GetDeliverFrameCB(), track); | 768 MediaStreamVideoSink::AddToVideoTrack(&sink, sink.GetDeliverFrameCB(), track); |
763 EXPECT_EQ(track.source().readyState(), | 769 EXPECT_EQ(track.source().readyState(), |
764 blink::WebMediaStreamSource::ReadyStateLive); | 770 blink::WebMediaStreamSource::ReadyStateLive); |
765 | 771 |
766 base::RunLoop run_loop; | 772 base::RunLoop run_loop; |
767 base::Closure quit_closure = run_loop.QuitClosure(); | 773 base::Closure quit_closure = run_loop.QuitClosure(); |
768 bool muted_state = false; | 774 bool muted_state = false; |
769 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) | 775 EXPECT_CALL(*mock_source(), DoSetMutedState(_)) |
770 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure))); | 776 .WillOnce(DoAll(SaveArg<0>(&muted_state), RunClosure(quit_closure))); |
(...skipping 11 matching lines...) Expand all Loading... |
782 run_loop2.Run(); | 788 run_loop2.Run(); |
783 | 789 |
784 EXPECT_EQ(muted_state, false); | 790 EXPECT_EQ(muted_state, false); |
785 EXPECT_EQ(track.source().readyState(), | 791 EXPECT_EQ(track.source().readyState(), |
786 blink::WebMediaStreamSource::ReadyStateLive); | 792 blink::WebMediaStreamSource::ReadyStateLive); |
787 | 793 |
788 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); | 794 MediaStreamVideoSink::RemoveFromVideoTrack(&sink, track); |
789 } | 795 } |
790 | 796 |
791 } // namespace content | 797 } // namespace content |
OLD | NEW |