| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/renderer_host/media/media_devices_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_devices_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/common/media_stream_request.h" | 23 #include "content/public/common/media_stream_request.h" |
| 24 #include "media/base/video_facing.h" | 24 #include "media/base/video_facing.h" |
| 25 #include "mojo/public/cpp/bindings/strong_binding.h" | 25 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 26 #include "services/service_manager/public/cpp/interface_provider.h" | 26 #include "services/service_manager/public/cpp/interface_provider.h" |
| 27 #include "url/origin.h" | 27 #include "url/origin.h" |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Resolutions used if the source doesn't support capability enumeration. |
| 34 struct { |
| 35 int width; |
| 36 int height; |
| 37 } const kFallbackVideoResolutions[] = {{1920, 1080}, {1280, 720}, {960, 720}, |
| 38 {640, 480}, {640, 360}, {320, 240}, |
| 39 {320, 180}}; |
| 40 |
| 41 // Frame rates for sources with no support for capability enumeration. |
| 42 const int kFallbackVideoFrameRates[] = {30, 60}; |
| 43 |
| 33 MediaDeviceInfo TranslateDeviceInfo(bool has_permission, | 44 MediaDeviceInfo TranslateDeviceInfo(bool has_permission, |
| 34 const std::string& device_id_salt, | 45 const std::string& device_id_salt, |
| 35 const std::string& group_id_salt, | 46 const std::string& group_id_salt, |
| 36 const url::Origin& security_origin, | 47 const url::Origin& security_origin, |
| 37 const MediaDeviceInfo& device_info) { | 48 const MediaDeviceInfo& device_info) { |
| 38 return MediaDeviceInfo( | 49 return MediaDeviceInfo( |
| 39 GetHMACForMediaDeviceID(device_id_salt, security_origin, | 50 GetHMACForMediaDeviceID(device_id_salt, security_origin, |
| 40 device_info.device_id), | 51 device_info.device_id), |
| 41 has_permission ? device_info.label : std::string(), | 52 has_permission ? device_info.label : std::string(), |
| 42 device_info.group_id.empty() | 53 device_info.group_id.empty() |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 363 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 353 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> | 364 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> |
| 354 video_input_capabilities; | 365 video_input_capabilities; |
| 355 for (const auto& descriptor : device_descriptors) { | 366 for (const auto& descriptor : device_descriptors) { |
| 356 std::string hmac_device_id = GetHMACForMediaDeviceID( | 367 std::string hmac_device_id = GetHMACForMediaDeviceID( |
| 357 device_id_salt_, security_origin, descriptor.device_id); | 368 device_id_salt_, security_origin, descriptor.device_id); |
| 358 ::mojom::VideoInputDeviceCapabilitiesPtr capabilities = | 369 ::mojom::VideoInputDeviceCapabilitiesPtr capabilities = |
| 359 ::mojom::VideoInputDeviceCapabilities::New(); | 370 ::mojom::VideoInputDeviceCapabilities::New(); |
| 360 capabilities->device_id = std::move(hmac_device_id); | 371 capabilities->device_id = std::move(hmac_device_id); |
| 361 capabilities->formats = GetVideoInputFormats(descriptor.device_id); | 372 capabilities->formats = GetVideoInputFormats(descriptor.device_id); |
| 373 if (capabilities->formats.empty()) { |
| 374 // The device does not seem to support capability enumeration. Compose |
| 375 // a fallback list of capabilities. |
| 376 for (const auto& resolution : kFallbackVideoResolutions) { |
| 377 for (const auto frame_rate : kFallbackVideoFrameRates) { |
| 378 capabilities->formats.push_back(media::VideoCaptureFormat( |
| 379 gfx::Size(resolution.width, resolution.height), frame_rate, |
| 380 media::PIXEL_FORMAT_I420)); |
| 381 } |
| 382 } |
| 383 } |
| 362 capabilities->facing_mode = ToFacingMode(descriptor.facing); | 384 capabilities->facing_mode = ToFacingMode(descriptor.facing); |
| 363 #if defined(OS_ANDROID) | 385 #if defined(OS_ANDROID) |
| 364 // On Android, the facing mode is not available in the |facing| field, | 386 // On Android, the facing mode is not available in the |facing| field, |
| 365 // but is available as part of the label. | 387 // but is available as part of the label. |
| 366 // TODO(guidou): Remove this code once the |facing| field is supported | 388 // TODO(guidou): Remove this code once the |facing| field is supported |
| 367 // on Android. See http://crbug.com/672856. | 389 // on Android. See http://crbug.com/672856. |
| 368 if (descriptor.GetNameAndModel().find("front") != std::string::npos) | 390 if (descriptor.GetNameAndModel().find("front") != std::string::npos) |
| 369 capabilities->facing_mode = ::mojom::FacingMode::USER; | 391 capabilities->facing_mode = ::mojom::FacingMode::USER; |
| 370 else if (descriptor.GetNameAndModel().find("back") != std::string::npos) | 392 else if (descriptor.GetNameAndModel().find("back") != std::string::npos) |
| 371 capabilities->facing_mode = ::mojom::FacingMode::ENVIRONMENT; | 393 capabilities->facing_mode = ::mojom::FacingMode::ENVIRONMENT; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 389 MEDIA_DEVICE_VIDEO_CAPTURE, device_id, &formats); | 411 MEDIA_DEVICE_VIDEO_CAPTURE, device_id, &formats); |
| 390 if (!formats.empty()) | 412 if (!formats.empty()) |
| 391 return formats; | 413 return formats; |
| 392 | 414 |
| 393 media_stream_manager_->video_capture_manager()->GetDeviceSupportedFormats( | 415 media_stream_manager_->video_capture_manager()->GetDeviceSupportedFormats( |
| 394 device_id, &formats); | 416 device_id, &formats); |
| 395 return formats; | 417 return formats; |
| 396 } | 418 } |
| 397 | 419 |
| 398 } // namespace content | 420 } // namespace content |
| OLD | NEW |