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

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

Issue 183113004: Make sure MediaStreamVideoSource support cropping. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Crop with origin 0,0 and temporary disable failing test. Created 6 years, 9 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/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/renderer/media/media_stream_video_source.h" 10 #include "content/renderer/media/media_stream_video_source.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 MediaStreamVideoSourceTest() 57 MediaStreamVideoSourceTest()
58 : number_of_successful_constraints_applied_(0), 58 : number_of_successful_constraints_applied_(0),
59 number_of_failed_constraints_applied_(0), 59 number_of_failed_constraints_applied_(0),
60 mock_source_(new MockMediaStreamVideoSource(&factory_, true)) { 60 mock_source_(new MockMediaStreamVideoSource(&factory_, true)) {
61 media::VideoCaptureFormats formats; 61 media::VideoCaptureFormats formats;
62 formats.push_back(media::VideoCaptureFormat( 62 formats.push_back(media::VideoCaptureFormat(
63 gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420)); 63 gfx::Size(1280, 720), 30, media::PIXEL_FORMAT_I420));
64 formats.push_back(media::VideoCaptureFormat( 64 formats.push_back(media::VideoCaptureFormat(
65 gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420)); 65 gfx::Size(640, 480), 30, media::PIXEL_FORMAT_I420));
66 formats.push_back(media::VideoCaptureFormat( 66 formats.push_back(media::VideoCaptureFormat(
67 gfx::Size(640, 400), 30, media::PIXEL_FORMAT_I420));
68 formats.push_back(media::VideoCaptureFormat(
69 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420)); 67 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420));
70 formats.push_back(media::VideoCaptureFormat( 68 formats.push_back(media::VideoCaptureFormat(
71 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420)); 69 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420));
72 mock_source_->SetSupportedFormats(formats); 70 mock_source_->SetSupportedFormats(formats);
73 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), 71 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"),
74 blink::WebMediaStreamSource::TypeVideo, 72 blink::WebMediaStreamSource::TypeVideo,
75 base::UTF8ToUTF16("dummy_source_name")); 73 base::UTF8ToUTF16("dummy_source_name"));
76 webkit_source_.setExtraData(mock_source_); 74 webkit_source_.setExtraData(mock_source_);
77 } 75 }
78 76
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 int NumberOfSuccessConstraintsCallbacks() const { 121 int NumberOfSuccessConstraintsCallbacks() const {
124 return number_of_successful_constraints_applied_; 122 return number_of_successful_constraints_applied_;
125 } 123 }
126 124
127 int NumberOfFailedConstraintsCallbacks() const { 125 int NumberOfFailedConstraintsCallbacks() const {
128 return number_of_failed_constraints_applied_; 126 return number_of_failed_constraints_applied_;
129 } 127 }
130 128
131 MockMediaStreamVideoSource* mock_source() { return mock_source_; } 129 MockMediaStreamVideoSource* mock_source() { return mock_source_; }
132 130
131 // Test that the source crops to the requested max width and
132 // height even though the camera delivers a larger frame.
133 // TODO(perkj): Frame resolution should be verified in MediaStreamVideoTrack
134 // and not in the adapter.
135 void TestSourceCropFrame(int capture_w,
136 int capture_h,
137 const blink::WebMediaConstraints& constraints,
138 int extpected_h,
tommi (sloooow) - chröme 2014/03/06 10:14:09 expected_h (or even expected_height)
perkj_chrome 2014/03/06 12:45:42 Done.
tommi (sloooow) - chröme 2014/03/06 13:28:50 missed extpected -> expected
perkj_chrome 2014/03/06 14:22:53 Done.
139 int expected_w) {
140 // Expect the source to start capture with the supported resolution.
141 CreateTrackAndStartSource(constraints, capture_w, capture_h , 30);
142
143 ASSERT_TRUE(mock_source()->GetAdapter());
144 MockVideoSource* adapter = static_cast<MockVideoSource*>(
145 mock_source()->GetAdapter());
146 EXPECT_EQ(0, adapter->GetFrameNum());
147
148 scoped_refptr<media::VideoFrame> frame =
149 media::VideoFrame::CreateBlackFrame(gfx::Size(capture_w, capture_h));
150 mock_source()->DeliverVideoFrame(frame);
151 EXPECT_EQ(1, adapter->GetFrameNum());
152
153 // Expect the delivered frame to be cropped.
154 EXPECT_EQ(extpected_h, adapter->GetLastFrameWidth());
155 EXPECT_EQ(expected_w, adapter->GetLastFrameHeight());
156 }
157
158
tommi (sloooow) - chröme 2014/03/06 10:14:09 one empty line
perkj_chrome 2014/03/06 12:45:42 Done.
133 private: 159 private:
134 void OnConstraintsApplied(MediaStreamSource* source, bool success) { 160 void OnConstraintsApplied(MediaStreamSource* source, bool success) {
135 ASSERT_EQ(source, webkit_source_.extraData()); 161 ASSERT_EQ(source, webkit_source_.extraData());
136 162
137 if (success) 163 if (success)
138 ++number_of_successful_constraints_applied_; 164 ++number_of_successful_constraints_applied_;
139 else 165 else
140 ++number_of_failed_constraints_applied_; 166 ++number_of_failed_constraints_applied_;
141 } 167 }
142 168
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 gfx::Size(MediaStreamVideoSource::kDefaultWidth, 371 gfx::Size(MediaStreamVideoSource::kDefaultWidth,
346 MediaStreamVideoSource::kDefaultHeight)); 372 MediaStreamVideoSource::kDefaultHeight));
347 mock_source()->DeliverVideoFrame(frame); 373 mock_source()->DeliverVideoFrame(frame);
348 EXPECT_EQ(1, adapter->GetFrameNum()); 374 EXPECT_EQ(1, adapter->GetFrameNum());
349 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth, 375 EXPECT_EQ(MediaStreamVideoSource::kDefaultWidth,
350 adapter->GetLastFrameWidth()); 376 adapter->GetLastFrameWidth());
351 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight, 377 EXPECT_EQ(MediaStreamVideoSource::kDefaultHeight,
352 adapter->GetLastFrameHeight()); 378 adapter->GetLastFrameHeight());
353 } 379 }
354 380
381 // Test that the source crops to the requested max width and
382 // height even though the camera delivers a larger frame.
383 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameOptional640360) {
384 ConstraintsFactory factory;
385 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640);
386 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 360);
387 TestSourceCropFrame(640, 480, factory.CreateConstraints(), 640, 360);
388 }
389
390 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory640360) {
391 ConstraintsFactory factory;
392 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 640);
393 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 360);
394 TestSourceCropFrame(640, 480, factory.CreateConstraints(), 640, 360);
395 }
396
397 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrameMandatory732489) {
398 ConstraintsFactory factory;
399 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 732);
400 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 489);
401 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 732);
402 factory.AddMandatory(MediaStreamVideoSource::kMinWidth, 489);
403 TestSourceCropFrame(1280, 720, factory.CreateConstraints(), 732, 489);
404 }
405
406 // Test that the source crops to the requested max width and
407 // height even though the requested frame has odd size.
408 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) {
409 ConstraintsFactory factory;
410 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637);
411 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359);
412 TestSourceCropFrame(640, 480, factory.CreateConstraints(), 637, 359);
413 }
414
415 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenTooLargeMax) {
416 ConstraintsFactory factory;
417 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920);
418 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080);
419 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
420 factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720);
421 TestSourceCropFrame(1280, 720, factory.CreateConstraints(), 1280, 720);
422 }
355 423
356 } // namespace content 424 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698