Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 crop to the requested max width and | |
|
Jói
2014/02/27 14:52:25
source crop -> source crops
perkj_chrome
2014/03/01 12:32:59
Done.
| |
| 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 TestSourceCroppFrame(int capture_w, | |
|
Jói
2014/02/27 14:52:25
TestSourceCroppFrame -> TestSourceCropFrame
perkj_chrome
2014/03/01 12:32:59
Done.
| |
| 136 int capture_h, | |
| 137 const blink::WebMediaConstraints& constraints, | |
| 138 int extpected_h, | |
| 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 | |
| 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 Loading... | |
| 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 crop 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 TestSourceCroppFrame(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 TestSourceCroppFrame(640, 480, factory.CreateConstraints(), 640, 360); | |
| 395 } | |
| 396 | |
| 397 // Test that the source crop to the requested max width and | |
| 398 // height even though the requested frame has odd size. | |
| 399 TEST_F(MediaStreamVideoSourceTest, DeliverCroppedVideoFrame637359) { | |
| 400 ConstraintsFactory factory; | |
| 401 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 637); | |
| 402 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 359); | |
| 403 TestSourceCroppFrame(640, 480, factory.CreateConstraints(), 637, 359); | |
| 404 } | |
| 405 | |
| 406 TEST_F(MediaStreamVideoSourceTest, DeliverSmallerSizeWhenToLargeMax) { | |
|
Jói
2014/02/27 14:52:25
WhenToLargeMax -> WhenTooLargeMax
perkj_chrome
2014/03/01 12:32:59
Done.
| |
| 407 ConstraintsFactory factory; | |
| 408 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 1920); | |
| 409 factory.AddOptional(MediaStreamVideoSource::kMaxHeight, 1080); | |
| 410 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); | |
| 411 factory.AddOptional(MediaStreamVideoSource::kMinHeight, 720); | |
| 412 TestSourceCroppFrame(1280, 720, factory.CreateConstraints(), 1280, 720); | |
| 413 } | |
| 355 | 414 |
| 356 } // namespace content | 415 } // namespace content |
| OLD | NEW |