| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "content/renderer/media/media_stream_constraints_util_video_source.h" | 5 #include "content/renderer/media/media_stream_constraints_util_video_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/optional.h" | 10 #include "base/optional.h" |
| 11 #include "content/renderer/media/media_stream_video_source.h" | 11 #include "content/renderer/media/media_stream_video_source.h" |
| 12 #include "content/renderer/media/mock_constraint_factory.h" | 12 #include "content/renderer/media/mock_constraint_factory.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const char kDeviceID1[] = "fake_device_1"; | 20 const char kDeviceID1[] = "fake_device_1"; |
| 21 const char kDeviceID2[] = "fake_device_2"; | 21 const char kDeviceID2[] = "fake_device_2"; |
| 22 const char kDeviceID3[] = "fake_device_3"; | 22 const char kDeviceID3[] = "fake_device_3"; |
| 23 const char kDeviceID4[] = "fake_device_4"; |
| 23 } | 24 } |
| 24 | 25 |
| 25 class MediaStreamConstraintsUtilVideoSourceTest : public testing::Test { | 26 class MediaStreamConstraintsUtilVideoSourceTest : public testing::Test { |
| 26 public: | 27 public: |
| 27 void SetUp() override { | 28 void SetUp() override { |
| 28 // Default device. It is default because it is the first in the enumeration. | 29 // Default device. It is default because it is the first in the enumeration. |
| 29 ::mojom::VideoInputDeviceCapabilitiesPtr device = | 30 ::mojom::VideoInputDeviceCapabilitiesPtr device = |
| 30 ::mojom::VideoInputDeviceCapabilities::New(); | 31 ::mojom::VideoInputDeviceCapabilities::New(); |
| 31 device->device_id = kDeviceID1; | 32 device->device_id = kDeviceID1; |
| 32 device->facing_mode = ::mojom::FacingMode::NONE; | 33 device->facing_mode = ::mojom::FacingMode::NONE; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 media::PIXEL_FORMAT_I420), | 79 media::PIXEL_FORMAT_I420), |
| 79 media::VideoCaptureFormat(gfx::Size(1280, 720), 60.0f, | 80 media::VideoCaptureFormat(gfx::Size(1280, 720), 60.0f, |
| 80 media::PIXEL_FORMAT_I420), | 81 media::PIXEL_FORMAT_I420), |
| 81 media::VideoCaptureFormat(gfx::Size(1920, 1080), 60.0f, | 82 media::VideoCaptureFormat(gfx::Size(1920, 1080), 60.0f, |
| 82 media::PIXEL_FORMAT_I420), | 83 media::PIXEL_FORMAT_I420), |
| 83 media::VideoCaptureFormat(gfx::Size(2304, 1536), 10.0f, | 84 media::VideoCaptureFormat(gfx::Size(2304, 1536), 10.0f, |
| 84 media::PIXEL_FORMAT_I420), | 85 media::PIXEL_FORMAT_I420), |
| 85 }; | 86 }; |
| 86 capabilities_.device_capabilities.push_back(std::move(device)); | 87 capabilities_.device_capabilities.push_back(std::move(device)); |
| 87 | 88 |
| 89 // A depth capture device. |
| 90 device = ::mojom::VideoInputDeviceCapabilities::New(); |
| 91 device->device_id = kDeviceID4; |
| 92 device->facing_mode = ::mojom::FacingMode::ENVIRONMENT; |
| 93 device->formats = {media::VideoCaptureFormat(gfx::Size(640, 480), 30.0f, |
| 94 media::PIXEL_FORMAT_Y16)}; |
| 95 capabilities_.device_capabilities.push_back(std::move(device)); |
| 96 |
| 88 capabilities_.power_line_capabilities = { | 97 capabilities_.power_line_capabilities = { |
| 89 media::PowerLineFrequency::FREQUENCY_DEFAULT, | 98 media::PowerLineFrequency::FREQUENCY_DEFAULT, |
| 90 media::PowerLineFrequency::FREQUENCY_50HZ, | 99 media::PowerLineFrequency::FREQUENCY_50HZ, |
| 91 media::PowerLineFrequency::FREQUENCY_60HZ, | 100 media::PowerLineFrequency::FREQUENCY_60HZ, |
| 92 }; | 101 }; |
| 93 | 102 |
| 94 default_device_ = capabilities_.device_capabilities[0].get(); | 103 default_device_ = capabilities_.device_capabilities[0].get(); |
| 95 low_res_device_ = capabilities_.device_capabilities[1].get(); | 104 low_res_device_ = capabilities_.device_capabilities[1].get(); |
| 96 high_res_device_ = capabilities_.device_capabilities[2].get(); | 105 high_res_device_ = capabilities_.device_capabilities[2].get(); |
| 97 default_closest_format_ = &default_device_->formats[1]; | 106 default_closest_format_ = &default_device_->formats[1]; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 constraint_factory_.Reset(); | 156 constraint_factory_.Reset(); |
| 148 // No device in |capabilities_| has facing mode equal to LEFT. | 157 // No device in |capabilities_| has facing mode equal to LEFT. |
| 149 constraint_factory_.basic().facingMode.setExact( | 158 constraint_factory_.basic().facingMode.setExact( |
| 150 blink::WebString::fromASCII("left")); | 159 blink::WebString::fromASCII("left")); |
| 151 auto result = SelectSettings(); | 160 auto result = SelectSettings(); |
| 152 EXPECT_FALSE(result.has_value()); | 161 EXPECT_FALSE(result.has_value()); |
| 153 EXPECT_EQ(constraint_factory_.basic().facingMode.name(), | 162 EXPECT_EQ(constraint_factory_.basic().facingMode.name(), |
| 154 result.failed_constraint_name); | 163 result.failed_constraint_name); |
| 155 } | 164 } |
| 156 | 165 |
| 166 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnVideoKind) { |
| 167 constraint_factory_.Reset(); |
| 168 // No device in |capabilities_| has video kind infrared. |
| 169 constraint_factory_.basic().videoKind.setExact( |
| 170 blink::WebString::fromASCII("infrared")); |
| 171 auto result = SelectSettings(); |
| 172 EXPECT_FALSE(result.has_value()); |
| 173 EXPECT_EQ(constraint_factory_.basic().videoKind.name(), |
| 174 result.failed_constraint_name); |
| 175 } |
| 176 |
| 157 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnHeight) { | 177 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, OverconstrainedOnHeight) { |
| 158 constraint_factory_.Reset(); | 178 constraint_factory_.Reset(); |
| 159 constraint_factory_.basic().height.setExact(123467890); | 179 constraint_factory_.basic().height.setExact(123467890); |
| 160 auto result = SelectSettings(); | 180 auto result = SelectSettings(); |
| 161 EXPECT_FALSE(result.has_value()); | 181 EXPECT_FALSE(result.has_value()); |
| 162 EXPECT_EQ(constraint_factory_.basic().height.name(), | 182 EXPECT_EQ(constraint_factory_.basic().height.name(), |
| 163 result.failed_constraint_name); | 183 result.failed_constraint_name); |
| 164 | 184 |
| 165 constraint_factory_.Reset(); | 185 constraint_factory_.Reset(); |
| 166 constraint_factory_.basic().height.setMin(123467890); | 186 constraint_factory_.basic().height.setMin(123467890); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 EXPECT_TRUE(result.has_value()); | 343 EXPECT_TRUE(result.has_value()); |
| 324 EXPECT_EQ(::mojom::FacingMode::USER, result.settings.facing_mode()); | 344 EXPECT_EQ(::mojom::FacingMode::USER, result.settings.facing_mode()); |
| 325 // Only the high-res device supports user facing mode. Should select default | 345 // Only the high-res device supports user facing mode. Should select default |
| 326 // settings for everything else. | 346 // settings for everything else. |
| 327 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); | 347 EXPECT_EQ(high_res_device_->device_id, result.settings.device_id()); |
| 328 EXPECT_EQ(*high_res_closest_format_, result.settings.format()); | 348 EXPECT_EQ(*high_res_closest_format_, result.settings.format()); |
| 329 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, | 349 EXPECT_EQ(media::PowerLineFrequency::FREQUENCY_DEFAULT, |
| 330 result.settings.power_line_frequency()); | 350 result.settings.power_line_frequency()); |
| 331 } | 351 } |
| 332 | 352 |
| 353 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryVideoKind) { |
| 354 constraint_factory_.Reset(); |
| 355 constraint_factory_.basic().videoKind.setExact( |
| 356 blink::WebString::fromASCII("depth")); |
| 357 auto result = SelectSettings(); |
| 358 EXPECT_TRUE(result.has_value()); |
| 359 EXPECT_EQ(kDeviceID4, result.settings.device_id()); |
| 360 EXPECT_EQ(media::PIXEL_FORMAT_Y16, result.settings.format().pixel_format); |
| 361 |
| 362 constraint_factory_.basic().videoKind.setExact( |
| 363 blink::WebString::fromASCII("color")); |
| 364 result = SelectSettings(); |
| 365 EXPECT_TRUE(result.has_value()); |
| 366 EXPECT_EQ(default_device_->device_id, result.settings.device_id()); |
| 367 } |
| 368 |
| 333 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryPowerLineFrequency) { | 369 TEST_F(MediaStreamConstraintsUtilVideoSourceTest, MandatoryPowerLineFrequency) { |
| 334 constraint_factory_.Reset(); | 370 constraint_factory_.Reset(); |
| 335 const media::PowerLineFrequency kPowerLineFrequencies[] = { | 371 const media::PowerLineFrequency kPowerLineFrequencies[] = { |
| 336 media::PowerLineFrequency::FREQUENCY_50HZ, | 372 media::PowerLineFrequency::FREQUENCY_50HZ, |
| 337 media::PowerLineFrequency::FREQUENCY_60HZ}; | 373 media::PowerLineFrequency::FREQUENCY_60HZ}; |
| 338 for (auto power_line_frequency : kPowerLineFrequencies) { | 374 for (auto power_line_frequency : kPowerLineFrequencies) { |
| 339 constraint_factory_.basic().googPowerLineFrequency.setExact( | 375 constraint_factory_.basic().googPowerLineFrequency.setExact( |
| 340 static_cast<long>(power_line_frequency)); | 376 static_cast<long>(power_line_frequency)); |
| 341 auto result = SelectSettings(); | 377 auto result = SelectSettings(); |
| 342 EXPECT_TRUE(result.has_value()); | 378 EXPECT_TRUE(result.has_value()); |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 constraint_factory_.Reset(); | 1304 constraint_factory_.Reset(); |
| 1269 constraint_factory_.basic().height.setExact(100); | 1305 constraint_factory_.basic().height.setExact(100); |
| 1270 VideoCaptureCapabilities capabilities; | 1306 VideoCaptureCapabilities capabilities; |
| 1271 auto result = SelectVideoCaptureSourceSettings( | 1307 auto result = SelectVideoCaptureSourceSettings( |
| 1272 capabilities, constraint_factory_.CreateWebMediaConstraints()); | 1308 capabilities, constraint_factory_.CreateWebMediaConstraints()); |
| 1273 EXPECT_FALSE(result.has_value()); | 1309 EXPECT_FALSE(result.has_value()); |
| 1274 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); | 1310 EXPECT_TRUE(std::string(result.failed_constraint_name).empty()); |
| 1275 } | 1311 } |
| 1276 | 1312 |
| 1277 } // namespace content | 1313 } // namespace content |
| OLD | NEW |