Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: content/renderer/media/media_stream_video_source_unittest.cc

Issue 246433006: Change MediaStreamVideoSource to output different resolutions to different tracks depending on the … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 int NumberOfSuccessConstraintsCallbacks() const { 88 int NumberOfSuccessConstraintsCallbacks() const {
89 return number_of_successful_constraints_applied_; 89 return number_of_successful_constraints_applied_;
90 } 90 }
91 91
92 int NumberOfFailedConstraintsCallbacks() const { 92 int NumberOfFailedConstraintsCallbacks() const {
93 return number_of_failed_constraints_applied_; 93 return number_of_failed_constraints_applied_;
94 } 94 }
95 95
96 MockMediaStreamVideoSource* mock_source() { return mock_source_; } 96 MockMediaStreamVideoSource* mock_source() { return mock_source_; }
97 97
98 // Test that the source crops to the requested max width and 98 // Test that the source crops/scales to the requested width and
99 // height even though the camera delivers a larger frame. 99 // height even though the camera delivers a larger frame.
100 void TestSourceCropFrame(int capture_width, 100 void TestSourceCropFrame(int capture_width,
101 int capture_height, 101 int capture_height,
102 const blink::WebMediaConstraints& constraints, 102 const blink::WebMediaConstraints& constraints,
103 int expected_width, 103 int expected_width,
104 int expected_height) { 104 int expected_height) {
105 // Expect the source to start capture with the supported resolution. 105 // Expect the source to start capture with the supported resolution.
106 blink::WebMediaStreamTrack track = 106 blink::WebMediaStreamTrack track =
107 CreateTrackAndStartSource(constraints, capture_width, capture_height, 107 CreateTrackAndStartSource(constraints, capture_width, capture_height,
108 30); 108 30);
(...skipping 15 matching lines...) Expand all
124 base::RunLoop run_loop; 124 base::RunLoop run_loop;
125 base::Closure quit_closure = run_loop.QuitClosure(); 125 base::Closure quit_closure = run_loop.QuitClosure();
126 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce( 126 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce(
127 RunClosure(quit_closure)); 127 RunClosure(quit_closure));
128 scoped_refptr<media::VideoFrame> frame = 128 scoped_refptr<media::VideoFrame> frame =
129 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); 129 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height));
130 mock_source()->DeliverVideoFrame(frame); 130 mock_source()->DeliverVideoFrame(frame);
131 run_loop.Run(); 131 run_loop.Run();
132 } 132 }
133 133
134 void DeliverVideoFrameAndWaitForTwoRenderers(
135 int width,
136 int height,
137 MockMediaStreamVideoSink* sink1,
138 MockMediaStreamVideoSink* sink2) {
139 base::RunLoop run_loop;
140 base::Closure quit_closure = run_loop.QuitClosure();
141 EXPECT_CALL(*sink1, OnVideoFrame());
142 EXPECT_CALL(*sink2, OnVideoFrame()).WillOnce(
143 RunClosure(quit_closure));
144 scoped_refptr<media::VideoFrame> frame =
145 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height));
146 mock_source()->DeliverVideoFrame(frame);
147 run_loop.Run();
148 }
149
150 void TestTwoTracksWithDifferentConstraints(
151 const blink::WebMediaConstraints& constraints1,
152 const blink::WebMediaConstraints& constraints2,
153 int capture_width,
154 int capture_height,
155 int expected_width1,
156 int expected_height1,
157 int expected_width2,
158 int expected_height2) {
159 blink::WebMediaStreamTrack track1 =
160 CreateTrackAndStartSource(constraints1, capture_width, capture_height,
161 MediaStreamVideoSource::kDefaultFrameRate);
162
163 blink::WebMediaStreamTrack track2 =
164 CreateTrack("dummy", constraints2);
165
166 MockMediaStreamVideoSink sink1;
167 MediaStreamVideoSink::AddToVideoTrack(&sink1, track1);
168 EXPECT_EQ(0, sink1.number_of_frames());
169
170 MockMediaStreamVideoSink sink2;
171 MediaStreamVideoSink::AddToVideoTrack(&sink2, track2);
172 EXPECT_EQ(0, sink2.number_of_frames());
173
174 DeliverVideoFrameAndWaitForTwoRenderers(capture_width,
175 capture_height,
176 &sink1,
177 &sink2);
178
179 EXPECT_EQ(1, sink1.number_of_frames());
180 EXPECT_EQ(expected_width1, sink1.frame_size().width());
181 EXPECT_EQ(expected_height1, sink1.frame_size().height());
182
183 EXPECT_EQ(1, sink2.number_of_frames());
184 EXPECT_EQ(expected_width2, sink2.frame_size().width());
185 EXPECT_EQ(expected_height2, sink2.frame_size().height());
186
187 MediaStreamVideoSink::RemoveFromVideoTrack(&sink1, track1);
188 MediaStreamVideoSink::RemoveFromVideoTrack(&sink2, track2);
189 }
134 190
135 void ReleaseTrackAndSourceOnAddTrackCallback( 191 void ReleaseTrackAndSourceOnAddTrackCallback(
136 const blink::WebMediaStreamTrack& track_to_release) { 192 const blink::WebMediaStreamTrack& track_to_release) {
137 track_to_release_ = track_to_release; 193 track_to_release_ = track_to_release;
138 } 194 }
139 195
140 private: 196 private:
141 void OnConstraintsApplied(MediaStreamSource* source, bool success) { 197 void OnConstraintsApplied(MediaStreamSource* source, bool success) {
142 ASSERT_EQ(source, webkit_source_.extraData()); 198 ASSERT_EQ(source, webkit_source_.extraData());
143 199
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // require it even if an optional constraint request a higher resolution 296 // require it even if an optional constraint request a higher resolution
241 // that don't have this aspect ratio. 297 // that don't have this aspect ratio.
242 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) { 298 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatio4To3) {
243 MockMediaConstraintFactory factory; 299 MockMediaConstraintFactory factory;
244 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640); 300 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 640);
245 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480); 301 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 480);
246 factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, 302 factory.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio,
247 640.0 / 480); 303 640.0 / 480);
248 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); 304 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
249 305
250 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, 30); 306 TestSourceCropFrame(1280, 720,
307 factory.CreateWebMediaConstraints(), 960, 720);
251 } 308 }
252 309
253 // Test that AddTrack fail if the mandatory aspect ratio 310 // Test that AddTrack succeeds if the mandatory min aspect ratio it set to 2.
254 // is set higher than supported.
255 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) { 311 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) {
256 MockMediaConstraintFactory factory; 312 MockMediaConstraintFactory factory;
257 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); 313 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2);
258 blink::WebMediaStreamTrack track = CreateTrack( 314
259 "123", factory.CreateWebMediaConstraints()); 315 TestSourceCropFrame(MediaStreamVideoSource::kDefaultWidth,
260 mock_source()->CompleteGetSupportedFormats(); 316 MediaStreamVideoSource::kDefaultHeight,
261 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 317 factory.CreateWebMediaConstraints(), 640, 320);
262 } 318 }
263 319
264 // Test that its safe to release the last reference of a blink track and the 320 // Test that its safe to release the last reference of a blink track and the
265 // source during the callback if adding a track succeeds. 321 // source during the callback if adding a track succeeds.
266 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) { 322 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnSuccessCallBack) {
267 MockMediaConstraintFactory factory; 323 MockMediaConstraintFactory factory;
268 { 324 {
269 blink::WebMediaStreamTrack track = 325 blink::WebMediaStreamTrack track =
270 CreateTrack("123", factory.CreateWebMediaConstraints()); 326 CreateTrack("123", factory.CreateWebMediaConstraints());
271 ReleaseTrackAndSourceOnAddTrackCallback(track); 327 ReleaseTrackAndSourceOnAddTrackCallback(track);
272 } 328 }
273 mock_source()->CompleteGetSupportedFormats(); 329 mock_source()->CompleteGetSupportedFormats();
274 mock_source()->StartMockedSource(); 330 mock_source()->StartMockedSource();
275 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 331 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
276 } 332 }
277 333
278 // Test that its safe to release the last reference of a blink track and the 334 // Test that its safe to release the last reference of a blink track and the
279 // source during the callback if adding a track fails. 335 // source during the callback if adding a track fails.
280 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnFailureCallBack) { 336 TEST_F(MediaStreamVideoSourceTest, ReleaseTrackAndSourceOnFailureCallBack) {
281 MockMediaConstraintFactory factory; 337 MockMediaConstraintFactory factory;
282 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); 338 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 99999);
283 { 339 {
284 blink::WebMediaStreamTrack track = 340 blink::WebMediaStreamTrack track =
285 CreateTrack("123", factory.CreateWebMediaConstraints()); 341 CreateTrack("123", factory.CreateWebMediaConstraints());
286 ReleaseTrackAndSourceOnAddTrackCallback(track); 342 ReleaseTrackAndSourceOnAddTrackCallback(track);
287 } 343 }
288 mock_source()->CompleteGetSupportedFormats(); 344 mock_source()->CompleteGetSupportedFormats();
289 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 345 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
290 } 346 }
291 347
292 // Test that the source ignores an optional aspect ratio that is higher than 348 // 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
399 455
400 // Test that the source crops to the requested max width and 456 // Test that the source crops to the requested max width and
401 // height even though the requested frame has odd size. 457 // height even though the requested frame has odd size.
402 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) { 458 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) {
403 MockMediaConstraintFactory factory; 459 MockMediaConstraintFactory factory;
404 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637); 460 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637);
405 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359); 461 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359);
406 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359); 462 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 637, 359);
407 } 463 }
408 464
465 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame320320) {
466 MockMediaConstraintFactory factory;
467 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 320);
468 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 320);
469 factory.AddMandatory(MediaStreamVideoSource::kMinHeight, 320);
470 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 320);
471 TestSourceCropFrame(640, 480, factory.CreateWebMediaConstraints(), 320, 320);
472 }
473
409 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) { 474 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) {
410 MockMediaConstraintFactory factory; 475 MockMediaConstraintFactory factory;
411 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920); 476 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920);
412 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080); 477 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080);
413 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); 478 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
414 factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720); 479 factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720);
415 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(), 480 TestSourceCropFrame(1280, 720, factory.CreateWebMediaConstraints(),
416 1280, 720); 481 1280, 720);
417 } 482 }
418 483
484 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) {
485 MockMediaConstraintFactory factory1;
486 factory1.AddOptional(MediaStreamVideoSource::kMaxWidth, 640);
487 factory1.AddOptional(MediaStreamVideoSource::kMaxHeight, 480);
488
489 MockMediaConstraintFactory factory2;
490 factory2.AddOptional(MediaStreamVideoSource::kMaxHeight, 360);
491
492 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
493 factory2.CreateWebMediaConstraints(),
494 640, 480,
495 640, 480,
496 640, 360);
497 }
498
499 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) {
500 MockMediaConstraintFactory factory1;
501 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
502 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720);
503
504
505 MockMediaConstraintFactory factory2;
506 factory2.AddMandatory(MediaStreamVideoSource::kMaxWidth, 640);
507 factory2.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360);
508
509 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
510 factory2.CreateWebMediaConstraints(),
511 1280, 720,
512 1280, 720,
513 640, 360);
514 }
515
516 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndW700H700) {
517 MockMediaConstraintFactory factory1;
518 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
519 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720);
520
521 MockMediaConstraintFactory factory2;
522 factory2.AddMandatory(MediaStreamVideoSource::kMaxWidth, 700);
523 factory2.AddMandatory(MediaStreamVideoSource::kMaxHeight, 700);
524
525 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
526 factory2.CreateWebMediaConstraints(),
527 1280, 720,
528 1280, 720,
529 700, 700);
530 }
531
532 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndMaxAspectRatio4To3) {
533 MockMediaConstraintFactory factory1;
534 factory1.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
535 factory1.AddOptional(MediaStreamVideoSource::kMinHeight, 720);
536
537 MockMediaConstraintFactory factory2;
538 factory2.AddMandatory(MediaStreamVideoSource::kMaxAspectRatio, 640.0 / 480);
539
540 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
541 factory2.CreateWebMediaConstraints(),
542 1280, 720,
543 1280, 720,
544 960, 720);
545 }
546
547 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVgaAndMinAspectRatio) {
548 MockMediaConstraintFactory factory1;
549 factory1.AddOptional(MediaStreamVideoSource::kMaxWidth, 640);
550 factory1.AddOptional(MediaStreamVideoSource::kMaxHeight, 480);
551
552 MockMediaConstraintFactory factory2;
553 factory2.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 640.0 / 360);
554
555 TestTwoTracksWithDifferentConstraints(factory1.CreateWebMediaConstraints(),
556 factory2.CreateWebMediaConstraints(),
557 640, 480,
558 640, 480,
559 640, 360);
560 }
561
419 // Test that a source can change the frame resolution on the fly and that 562 // Test that a source can change the frame resolution on the fly and that
420 // tracks sinks get the new frame size unless constraints force the frame to be 563 // tracks sinks get the new frame size unless constraints force the frame to be
421 // cropped. 564 // cropped.
422 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) { 565 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) {
423 MockMediaConstraintFactory factory; 566 MockMediaConstraintFactory factory;
424 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 800); 567 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 800);
425 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 700); 568 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 700);
426 569
427 // Expect the source to start capture with the supported resolution. 570 // Expect the source to start capture with the supported resolution.
428 blink::WebMediaStreamTrack track = 571 blink::WebMediaStreamTrack track =
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 615 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
473 MediaStreamVideoSource::kMaxAspectRatio)); 616 MediaStreamVideoSource::kMaxAspectRatio));
474 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 617 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
475 MediaStreamVideoSource::kMinAspectRatio)); 618 MediaStreamVideoSource::kMinAspectRatio));
476 619
477 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported( 620 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported(
478 "something unsupported")); 621 "something unsupported"));
479 } 622 }
480 623
481 } // namespace content 624 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698