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" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 int NumberOfSuccessConstraintsCallbacks() const { | 87 int NumberOfSuccessConstraintsCallbacks() const { |
88 return number_of_successful_constraints_applied_; | 88 return number_of_successful_constraints_applied_; |
89 } | 89 } |
90 | 90 |
91 int NumberOfFailedConstraintsCallbacks() const { | 91 int NumberOfFailedConstraintsCallbacks() const { |
92 return number_of_failed_constraints_applied_; | 92 return number_of_failed_constraints_applied_; |
93 } | 93 } |
94 | 94 |
95 MockMediaStreamVideoSource* mock_source() { return mock_source_; } | 95 MockMediaStreamVideoSource* mock_source() { return mock_source_; } |
96 | 96 |
97 // Test that the source crops to the requested max width and | 97 // Test that the source crops/scales to the requested width and |
98 // height even though the camera delivers a larger frame. | 98 // height even though the camera delivers a larger frame. |
99 void TestSourceCropFrame(int capture_width, | 99 void TestSourceCropFrame(int capture_width, |
100 int capture_height, | 100 int capture_height, |
101 const blink::WebMediaConstraints& constraints, | 101 const blink::WebMediaConstraints& constraints, |
102 int expected_width, | 102 int expected_width, |
103 int expected_height) { | 103 int expected_height) { |
104 // Expect the source to start capture with the supported resolution. | 104 // Expect the source to start capture with the supported resolution. |
105 blink::WebMediaStreamTrack track = | 105 blink::WebMediaStreamTrack track = |
106 CreateTrackAndStartSource(constraints, capture_width, capture_height, | 106 CreateTrackAndStartSource(constraints, capture_width, capture_height, |
107 30); | 107 30); |
(...skipping 15 matching lines...) Expand all Loading... |
123 base::RunLoop run_loop; | 123 base::RunLoop run_loop; |
124 base::Closure quit_closure = run_loop.QuitClosure(); | 124 base::Closure quit_closure = run_loop.QuitClosure(); |
125 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( | 125 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( |
126 RunClosure(quit_closure)); | 126 RunClosure(quit_closure)); |
127 scoped_refptr<media::VideoFrame> frame = | 127 scoped_refptr<media::VideoFrame> frame = |
128 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); | 128 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); |
129 mock_source()->DeliverVideoFrame(frame); | 129 mock_source()->DeliverVideoFrame(frame); |
130 run_loop.Run(); | 130 run_loop.Run(); |
131 } | 131 } |
132 | 132 |
| 133 void DeliverVideoFrameAndWaitForTwoRenderers( |
| 134 int width, |
| 135 int height, |
| 136 MockMediaStreamVideoSink* sink1, |
| 137 MockMediaStreamVideoSink* sink2) { |
| 138 base::RunLoop run_loop; |
| 139 base::Closure quit_closure = run_loop.QuitClosure(); |
| 140 EXPECT_CALL(*sink1, OnVideoFrame()); |
| 141 EXPECT_CALL(*sink2, OnVideoFrame()).WillOnce( |
| 142 RunClosure(quit_closure)); |
| 143 scoped_refptr<media::VideoFrame> frame = |
| 144 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); |
| 145 mock_source()->DeliverVideoFrame(frame); |
| 146 run_loop.Run(); |
| 147 } |
| 148 |
| 149 void TestTwoTracksWithDifferentConstraints( |
| 150 const blink::WebMediaConstraints& constraints1, |
| 151 const blink::WebMediaConstraints& constraints2, |
| 152 int capture_width, |
| 153 int capture_height, |
| 154 int expected_width1, |
| 155 int expected_height1, |
| 156 int expected_width2, |
| 157 int expected_height2) { |
| 158 blink::WebMediaStreamTrack track1 = |
| 159 CreateTrackAndStartSource(constraints1, capture_width, capture_height, |
| 160 MediaStreamVideoSource::kDefaultFrameRate); |
| 161 |
| 162 blink::WebMediaStreamTrack track2 = |
| 163 CreateTrack("dummy", constraints2); |
| 164 |
| 165 MockMediaStreamVideoSink sink1; |
| 166 MediaStreamVideoSink::AddToVideoTrack(&sink1, track1); |
| 167 EXPECT_EQ(0, sink1.number_of_frames()); |
| 168 |
| 169 MockMediaStreamVideoSink sink2; |
| 170 MediaStreamVideoSink::AddToVideoTrack(&sink2, track2); |
| 171 EXPECT_EQ(0, sink2.number_of_frames()); |
| 172 |
| 173 DeliverVideoFrameAndWaitForTwoRenderers(capture_width, |
| 174 capture_height, |
| 175 &sink1, |
| 176 &sink2); |
| 177 |
| 178 EXPECT_EQ(1, sink1.number_of_frames()); |
| 179 EXPECT_EQ(expected_width1, sink1.frame_size().width()); |
| 180 EXPECT_EQ(expected_height1, sink1.frame_size().height()); |
| 181 |
| 182 EXPECT_EQ(1, sink2.number_of_frames()); |
| 183 EXPECT_EQ(expected_width2, sink2.frame_size().width()); |
| 184 EXPECT_EQ(expected_height2, sink2.frame_size().height()); |
| 185 |
| 186 MediaStreamVideoSink::RemoveFromVideoTrack(&sink1, track1); |
| 187 MediaStreamVideoSink::RemoveFromVideoTrack(&sink2, track2); |
| 188 } |
133 | 189 |
134 void ReleaseTrackAndSourceOnAddTrackCallback( | 190 void ReleaseTrackAndSourceOnAddTrackCallback( |
135 const blink::WebMediaStreamTrack& track_to_release) { | 191 const blink::WebMediaStreamTrack& track_to_release) { |
136 track_to_release_ = track_to_release; | 192 track_to_release_ = track_to_release; |
137 } | 193 } |
138 | 194 |
139 private: | 195 private: |
140 void OnConstraintsApplied(MediaStreamSource* source, bool success) { | 196 void OnConstraintsApplied(MediaStreamSource* source, bool success) { |
141 ASSERT_EQ(source, webkit_source_.extraData()); | 197 ASSERT_EQ(source, webkit_source_.extraData()); |
142 | 198 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // require it even if an optional constraint request a higher resolution | 295 // require it even if an optional constraint request a higher resolution |
240 // that don't have this aspect ratio. | 296 // that don't have this aspect ratio. |
241 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) { | 297 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) { |
242 MockMediaConstraintFactory factory; | 298 MockMediaConstraintFactory factory; |
243 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640); | 299 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640); |
244 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480); | 300 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480); |
245 factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, | 301 factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, |
246 640.0 / 480); | 302 640.0 / 480); |
247 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 303 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); |
248 | 304 |
249 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, 30); | 305 TestSourceCropFrame(1280, 720, |
| 306 factory.CreateWebMediaConstraints(), 960, 720); |
250 } | 307 } |
251 | 308 |
252 // Test that AddTrack fail if the mandatory aspect ratio | 309 // Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2. |
253 // is set higher than supported. | 310 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio2) { |
254 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) { | |
255 MockMediaConstraintFactory factory; | 311 MockMediaConstraintFactory factory; |
256 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); | 312 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); |
| 313 |
| 314 TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth, |
| 315 MediaStreamVideoSource::kDefaultHeight, |
| 316 factory.CreateWebMediaConstraints(), 640, 320); |
| 317 } |
| 318 |
| 319 TEST_F(MediaStreamVideoSourceTest, MinAspectRatioLargerThanMaxAspectRatio) { |
| 320 MockMediaConstraintFactory factory; |
| 321 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); |
| 322 factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, 1); |
257 blink::WebMediaStreamTrack track = CreateTrack( | 323 blink::WebMediaStreamTrack track = CreateTrack( |
258 "123", factory.CreateWebMediaConstraints()); | 324 "123", factory.CreateWebMediaConstraints()); |
259 mock_source()->CompleteGetSupportedFormats(); | 325 mock_source()->CompleteGetSupportedFormats(); |
| 326 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
| 327 } |
| 328 |
| 329 TEST_F(MediaStreamVideoSourceTest, MinWidthLargerThanMaxWidth) { |
| 330 MockMediaConstraintFactory factory; |
| 331 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640); |
| 332 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 320); |
| 333 blink::WebMediaStreamTrack track = CreateTrack( |
| 334 "123", factory.CreateWebMediaConstraints()); |
| 335 mock_source()->CompleteGetSupportedFormats(); |
| 336 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
| 337 } |
| 338 |
| 339 TEST_F(MediaStreamVideoSourceTest, MinHeightLargerThanMaxHeight) { |
| 340 MockMediaConstraintFactory factory; |
| 341 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480); |
| 342 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360); |
| 343 blink::WebMediaStreamTrack track = CreateTrack( |
| 344 "123", factory.CreateWebMediaConstraints()); |
| 345 mock_source()->CompleteGetSupportedFormats(); |
260 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 346 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
261 } | 347 } |
262 | 348 |
263 // Test that its safe to release the last reference of a blink track and the | 349 // Test that its safe to release the last reference of a blink track and the |
264 // source during the callback if adding a track succeeds. | 350 // source during the callback if adding a track succeeds. |
265 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) { | 351 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) { |
266 MockMediaConstraintFactory factory; | 352 MockMediaConstraintFactory factory; |
267 { | 353 { |
268 blink::WebMediaStreamTrack track = | 354 blink::WebMediaStreamTrack track = |
269 CreateTrack("123", factory.CreateWebMediaConstraints()); | 355 CreateTrack("123", factory.CreateWebMediaConstraints()); |
270 ReleaseTrackAndSourceOnAddTrackCallback(track); | 356 ReleaseTrackAndSourceOnAddTrackCallback(track); |
271 } | 357 } |
272 mock_source()->CompleteGetSupportedFormats(); | 358 mock_source()->CompleteGetSupportedFormats(); |
273 mock_source()->StartMockedSource(); | 359 mock_source()->StartMockedSource(); |
274 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | 360 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); |
275 } | 361 } |
276 | 362 |
277 // Test that its safe to release the last reference of a blink track and the | 363 // Test that its safe to release the last reference of a blink track and the |
278 // source during the callback if adding a track fails. | 364 // source during the callback if adding a track fails. |
279 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnFailureCallBack) { | 365 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnFailureCallBack) { |
280 MockMediaConstraintFactory factory; | 366 MockMediaConstraintFactory factory; |
281 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); | 367 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 99999); |
282 { | 368 { |
283 blink::WebMediaStreamTrack track = | 369 blink::WebMediaStreamTrack track = |
284 CreateTrack("123", factory.CreateWebMediaConstraints()); | 370 CreateTrack("123", factory.CreateWebMediaConstraints()); |
285 ReleaseTrackAndSourceOnAddTrackCallback(track); | 371 ReleaseTrackAndSourceOnAddTrackCallback(track); |
286 } | 372 } |
287 mock_source()->CompleteGetSupportedFormats(); | 373 mock_source()->CompleteGetSupportedFormats(); |
288 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 374 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
289 } | 375 } |
290 | 376 |
291 // Test that the source ignores an optional aspect ratio that is higher than | 377 // Test that the source ignores an optional aspect ratio that is higher than |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 484 |
399 // Test that the source crops to the requested max width and | 485 // Test that the source crops to the requested max width and |
400 // height even though the requested frame has odd size. | 486 // height even though the requested frame has odd size. |
401 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) { | 487 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) { |
402 MockMediaConstraintFactory factory; | 488 MockMediaConstraintFactory factory; |
403 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637); | 489 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637); |
404 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359); | 490 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359); |
405 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); | 491 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); |
406 } | 492 } |
407 | 493 |
| 494 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame320320) { |
| 495 MockMediaConstraintFactory factory; |
| 496 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 320); |
| 497 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 320); |
| 498 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 320); |
| 499 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 320); |
| 500 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320); |
| 501 } |
| 502 |
408 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) { | 503 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) { |
409 MockMediaConstraintFactory factory; | 504 MockMediaConstraintFactory factory; |
410 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920); | 505 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920); |
411 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080); | 506 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080); |
412 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | 507 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); |
413 factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720); | 508 factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720); |
414 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), | 509 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), |
415 1280, 720); | 510 1280, 720); |
416 } | 511 } |
417 | 512 |
| 513 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) { |
| 514 MockMediaConstraintFactory factory1; |
| 515 factory1.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); |
| 516 factory1.AddOptional(MediaStreamVideoSource::kMaxHeight, 480); |
| 517 |
| 518 MockMediaConstraintFactory factory2; |
| 519 factory2.AddOptional(MediaStreamVideoSource::kMaxHeight, 360); |
| 520 |
| 521 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
| 522 factory2.CreateWebMediaConstraints(), |
| 523 640, 480, |
| 524 640, 480, |
| 525 640, 360); |
| 526 } |
| 527 |
| 528 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) { |
| 529 MockMediaConstraintFactory factory1; |
| 530 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); |
| 531 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720); |
| 532 |
| 533 |
| 534 MockMediaConstraintFactory factory2; |
| 535 factory2.AddMandatory(MediaStreamVideoSource::kMaxWidth, 640); |
| 536 factory2.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360); |
| 537 |
| 538 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
| 539 factory2.CreateWebMediaConstraints(), |
| 540 1280, 720, |
| 541 1280, 720, |
| 542 640, 360); |
| 543 } |
| 544 |
| 545 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndW700H700) { |
| 546 MockMediaConstraintFactory factory1; |
| 547 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); |
| 548 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720); |
| 549 |
| 550 MockMediaConstraintFactory factory2; |
| 551 factory2.AddMandatory(MediaStreamVideoSource::kMaxWidth, 700); |
| 552 factory2.AddMandatory(MediaStreamVideoSource::kMaxHeight, 700); |
| 553 |
| 554 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
| 555 factory2.CreateWebMediaConstraints(), |
| 556 1280, 720, |
| 557 1280, 720, |
| 558 700, 700); |
| 559 } |
| 560 |
| 561 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndMaxAspectRatio4To3) { |
| 562 MockMediaConstraintFactory factory1; |
| 563 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); |
| 564 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720); |
| 565 |
| 566 MockMediaConstraintFactory factory2; |
| 567 factory2.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, 640.0 / 480); |
| 568 |
| 569 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
| 570 factory2.CreateWebMediaConstraints(), |
| 571 1280, 720, |
| 572 1280, 720, |
| 573 960, 720); |
| 574 } |
| 575 |
| 576 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVgaAndMinAspectRatio) { |
| 577 MockMediaConstraintFactory factory1; |
| 578 factory1.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); |
| 579 factory1.AddOptional(MediaStreamVideoSource::kMaxHeight, 480); |
| 580 |
| 581 MockMediaConstraintFactory factory2; |
| 582 factory2.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 640.0 / 360); |
| 583 |
| 584 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(), |
| 585 factory2.CreateWebMediaConstraints(), |
| 586 640, 480, |
| 587 640, 480, |
| 588 640, 360); |
| 589 } |
| 590 |
418 // Test that a source can change the frame resolution on the fly and that | 591 // Test that a source can change the frame resolution on the fly and that |
419 // tracks sinks get the new frame size unless constraints force the frame to be | 592 // tracks sinks get the new frame size unless constraints force the frame to be |
420 // cropped. | 593 // cropped. |
421 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) { | 594 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) { |
422 MockMediaConstraintFactory factory; | 595 MockMediaConstraintFactory factory; |
423 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 800); | 596 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 800); |
424 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 700); | 597 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 700); |
425 | 598 |
426 // Expect the source to start capture with the supported resolution. | 599 // Expect the source to start capture with the supported resolution. |
427 blink::WebMediaStreamTrack track = | 600 blink::WebMediaStreamTrack track = |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( | 644 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( |
472 MediaStreamVideoSource::kMaxAspectRatio)); | 645 MediaStreamVideoSource::kMaxAspectRatio)); |
473 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( | 646 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( |
474 MediaStreamVideoSource::kMinAspectRatio)); | 647 MediaStreamVideoSource::kMinAspectRatio)); |
475 | 648 |
476 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported( | 649 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported( |
477 "something unsupported")); | 650 "something unsupported")); |
478 } | 651 } |
479 | 652 |
480 } // namespace content | 653 } // namespace content |
OLD | NEW |