Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "content/browser/bad_message.h" | 14 #include "content/browser/bad_message.h" |
| 15 #include "content/browser/media/media_devices_util.h" | |
| 15 #include "content/browser/renderer_host/media/media_stream_manager.h" | 16 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 17 #include "content/browser/renderer_host/media/video_capture_manager.h" | |
| 16 #include "content/common/media/media_devices.h" | 18 #include "content/common/media/media_devices.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/media_device_id.h" | 20 #include "content/public/browser/media_device_id.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/resource_context.h" | 22 #include "content/public/browser/resource_context.h" |
| 21 #include "content/public/common/media_stream_request.h" | 23 #include "content/public/common/media_stream_request.h" |
| 24 #include "media/base/video_facing.h" | |
| 22 #include "mojo/public/cpp/bindings/strong_binding.h" | 25 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 23 #include "services/service_manager/public/cpp/interface_provider.h" | 26 #include "services/service_manager/public/cpp/interface_provider.h" |
| 24 #include "url/origin.h" | 27 #include "url/origin.h" |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 MediaDeviceInfo TranslateDeviceInfo(bool has_permission, | 33 MediaDeviceInfo TranslateDeviceInfo(bool has_permission, |
| 31 const std::string& device_id_salt, | 34 const std::string& device_id_salt, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 50 const MediaDeviceInfoArray& input) { | 53 const MediaDeviceInfoArray& input) { |
| 51 MediaDeviceInfoArray result; | 54 MediaDeviceInfoArray result; |
| 52 for (const auto& device_info : input) { | 55 for (const auto& device_info : input) { |
| 53 result.push_back(TranslateDeviceInfo(has_permission, device_id_salt, | 56 result.push_back(TranslateDeviceInfo(has_permission, device_id_salt, |
| 54 group_id_salt, security_origin, | 57 group_id_salt, security_origin, |
| 55 device_info)); | 58 device_info)); |
| 56 } | 59 } |
| 57 return result; | 60 return result; |
| 58 } | 61 } |
| 59 | 62 |
| 63 ::mojom::FacingMode ToFacingMode(media::VideoFacingMode facing_mode) { | |
| 64 switch (facing_mode) { | |
| 65 case media::MEDIA_VIDEO_FACING_NONE: | |
| 66 return ::mojom::FacingMode::NONE; | |
| 67 case media::MEDIA_VIDEO_FACING_USER: | |
| 68 return ::mojom::FacingMode::USER; | |
| 69 case media::MEDIA_VIDEO_FACING_ENVIRONMENT: | |
| 70 return ::mojom::FacingMode::ENVIRONMENT; | |
| 71 default: | |
| 72 NOTREACHED(); | |
| 73 return ::mojom::FacingMode::NONE; | |
| 74 } | |
| 75 } | |
| 76 | |
| 60 } // namespace | 77 } // namespace |
| 61 | 78 |
| 62 struct MediaDevicesDispatcherHost::SubscriptionInfo { | 79 struct MediaDevicesDispatcherHost::SubscriptionInfo { |
| 63 uint32_t subscription_id; | 80 uint32_t subscription_id; |
| 64 url::Origin security_origin; | 81 url::Origin security_origin; |
| 65 }; | 82 }; |
| 66 | 83 |
| 67 // static | 84 // static |
| 68 void MediaDevicesDispatcherHost::Create( | 85 void MediaDevicesDispatcherHost::Create( |
| 69 int render_process_id, | 86 int render_process_id, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; | 157 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = request_audio_output; |
| 141 | 158 |
| 142 permission_checker_->CheckPermissions( | 159 permission_checker_->CheckPermissions( |
| 143 devices_to_enumerate, render_process_id_, render_frame_id_, | 160 devices_to_enumerate, render_process_id_, render_frame_id_, |
| 144 security_origin, | 161 security_origin, |
| 145 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, | 162 base::Bind(&MediaDevicesDispatcherHost::DoEnumerateDevices, |
| 146 weak_factory_.GetWeakPtr(), devices_to_enumerate, | 163 weak_factory_.GetWeakPtr(), devices_to_enumerate, |
| 147 security_origin, client_callback)); | 164 security_origin, client_callback)); |
| 148 } | 165 } |
| 149 | 166 |
| 167 void MediaDevicesDispatcherHost::GetVideoInputCapabilities( | |
| 168 const url::Origin& security_origin, | |
| 169 const GetVideoInputCapabilitiesCallback& client_callback) { | |
| 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 171 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | |
| 172 security_origin)) { | |
| 173 bad_message::ReceivedBadMessage(render_process_id_, | |
| 174 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | |
| 175 return; | |
| 176 } | |
| 177 | |
| 178 GetDefaultMediaDeviceID( | |
| 179 MEDIA_DEVICE_TYPE_VIDEO_INPUT, render_process_id_, render_frame_id_, | |
| 180 base::Bind(&MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID, | |
| 181 weak_factory_.GetWeakPtr(), security_origin, client_callback)); | |
| 182 } | |
| 183 | |
| 150 void MediaDevicesDispatcherHost::SubscribeDeviceChangeNotifications( | 184 void MediaDevicesDispatcherHost::SubscribeDeviceChangeNotifications( |
| 151 MediaDeviceType type, | 185 MediaDeviceType type, |
| 152 uint32_t subscription_id, | 186 uint32_t subscription_id, |
| 153 const url::Origin& security_origin) { | 187 const url::Origin& security_origin) { |
| 154 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 188 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 155 DCHECK(IsValidMediaDeviceType(type)); | 189 DCHECK(IsValidMediaDeviceType(type)); |
| 156 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, | 190 if (!MediaStreamManager::IsOriginAllowed(render_process_id_, |
| 157 security_origin)) { | 191 security_origin)) { |
| 158 bad_message::ReceivedBadMessage(render_process_id_, | 192 bad_message::ReceivedBadMessage(render_process_id_, |
| 159 bad_message::MDDH_UNAUTHORIZED_ORIGIN); | 193 bad_message::MDDH_UNAUTHORIZED_ORIGIN); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 | 325 |
| 292 for (const auto& device_info : enumeration[i]) { | 326 for (const auto& device_info : enumeration[i]) { |
| 293 result[i].push_back(TranslateDeviceInfo(has_permissions[i], | 327 result[i].push_back(TranslateDeviceInfo(has_permissions[i], |
| 294 device_id_salt_, group_id_salt_, | 328 device_id_salt_, group_id_salt_, |
| 295 security_origin, device_info)); | 329 security_origin, device_info)); |
| 296 } | 330 } |
| 297 } | 331 } |
| 298 client_callback.Run(result); | 332 client_callback.Run(result); |
| 299 } | 333 } |
| 300 | 334 |
| 335 void MediaDevicesDispatcherHost::GotDefaultVideoInputDeviceID( | |
| 336 const url::Origin& security_origin, | |
| 337 const GetVideoInputCapabilitiesCallback& client_callback, | |
| 338 const std::string& default_device_id) { | |
| 339 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | |
| 340 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; | |
| 341 media_stream_manager_->video_capture_manager()->EnumerateDevices( | |
| 342 base::Bind(&MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities, | |
| 343 weak_factory_.GetWeakPtr(), security_origin, client_callback, | |
| 344 default_device_id)); | |
| 345 } | |
| 346 | |
| 347 void MediaDevicesDispatcherHost::FinalizeGetVideoInputCapabilities( | |
| 348 const url::Origin& security_origin, | |
| 349 const GetVideoInputCapabilitiesCallback& client_callback, | |
| 350 const std::string& default_device_id, | |
| 351 const media::VideoCaptureDeviceDescriptors& device_descriptors) { | |
| 352 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 353 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> | |
| 354 video_input_capabilities; | |
| 355 for (const auto& descriptor : device_descriptors) { | |
| 356 std::string hmac_device_id = GetHMACForMediaDeviceID( | |
| 357 device_id_salt_, security_origin, descriptor.device_id); | |
| 358 ::mojom::VideoInputDeviceCapabilitiesPtr capabilities = | |
| 359 ::mojom::VideoInputDeviceCapabilities::New(); | |
| 360 capabilities->device_id = std::move(hmac_device_id); | |
| 361 capabilities->formats = GetVideoInputFormats(descriptor.device_id); | |
| 362 capabilities->facing_mode = ToFacingMode(descriptor.facing); | |
| 363 #if defined(OS_ANDROID) | |
| 364 // On Android, the facing mode is not available in the |facing| field, | |
| 365 // but is available as part of the label. | |
| 366 // TODO(guidou): Remove this code once the |facing| field is supported | |
| 367 // on Android. See http://crbug.com/672856. | |
| 368 if (descriptor.GetNameAndModel().find("front") != std::string::npos) | |
| 369 capabilities->facing_mode = ::mojom::FacingMode::USER; | |
| 370 else if (descriptor.GetNameAndModel().find("back") != std::string::npos) | |
| 371 capabilities->facing_mode = ::mojom::FacingMode::ENVIRONMENT; | |
| 372 #endif | |
| 373 if (descriptor.device_id == default_device_id) { | |
|
tommi (sloooow) - chröme
2017/01/27 16:37:00
supernit: use of {} here and none above is inconsi
Guido Urdaneta
2017/01/27 17:02:14
My interpretation of the style guide is that brace
tommi (sloooow) - chröme
2017/01/27 17:14:51
you are absolutely correct, I withdraw my supernit
| |
| 374 video_input_capabilities.insert(video_input_capabilities.begin(), | |
| 375 std::move(capabilities)); | |
| 376 } else { | |
| 377 video_input_capabilities.push_back(std::move(capabilities)); | |
| 378 } | |
| 379 } | |
| 380 | |
| 381 client_callback.Run(std::move(video_input_capabilities)); | |
| 382 } | |
| 383 | |
| 384 media::VideoCaptureFormats MediaDevicesDispatcherHost::GetVideoInputFormats( | |
| 385 const std::string& device_id) { | |
| 386 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 387 media::VideoCaptureFormats formats; | |
| 388 media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( | |
| 389 MEDIA_DEVICE_VIDEO_CAPTURE, device_id, &formats); | |
| 390 if (!formats.empty()) | |
| 391 return formats; | |
| 392 | |
| 393 media_stream_manager_->video_capture_manager()->GetDeviceSupportedFormats( | |
| 394 device_id, &formats); | |
| 395 return formats; | |
| 396 } | |
| 397 | |
| 301 } // namespace content | 398 } // namespace content |
| OLD | NEW |