Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/user_media_client_impl.h" | 5 #include "content/renderer/media/user_media_client_impl.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/hash.h" | 12 #include "base/hash.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "build/build_config.h" | |
| 21 #include "content/public/renderer/render_frame.h" | 22 #include "content/public/renderer/render_frame.h" |
| 22 #include "content/renderer/media/local_media_stream_audio_source.h" | 23 #include "content/renderer/media/local_media_stream_audio_source.h" |
| 23 #include "content/renderer/media/media_stream.h" | 24 #include "content/renderer/media/media_stream.h" |
| 24 #include "content/renderer/media/media_stream_constraints_util.h" | 25 #include "content/renderer/media/media_stream_constraints_util.h" |
| 25 #include "content/renderer/media/media_stream_dispatcher.h" | 26 #include "content/renderer/media/media_stream_dispatcher.h" |
| 26 #include "content/renderer/media/media_stream_video_capturer_source.h" | 27 #include "content/renderer/media/media_stream_video_capturer_source.h" |
| 27 #include "content/renderer/media/media_stream_video_track.h" | 28 #include "content/renderer/media/media_stream_video_track.h" |
| 28 #include "content/renderer/media/peer_connection_tracker.h" | 29 #include "content/renderer/media/peer_connection_tracker.h" |
| 29 #include "content/renderer/media/webrtc/processed_local_audio_source.h" | 30 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
| 30 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 31 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 static_cast<MediaStreamSource*>(source.getExtraData()); | 117 static_cast<MediaStreamSource*>(source.getExtraData()); |
| 117 const StreamDeviceInfo& device = source_extra_data->device_info(); | 118 const StreamDeviceInfo& device = source_extra_data->device_info(); |
| 118 | 119 |
| 119 MediaStreamSource* const other_source_extra_data = | 120 MediaStreamSource* const other_source_extra_data = |
| 120 static_cast<MediaStreamSource*>(other_source.getExtraData()); | 121 static_cast<MediaStreamSource*>(other_source.getExtraData()); |
| 121 const StreamDeviceInfo& other_device = other_source_extra_data->device_info(); | 122 const StreamDeviceInfo& other_device = other_source_extra_data->device_info(); |
| 122 | 123 |
| 123 return IsSameDevice(device, other_device); | 124 return IsSameDevice(device, other_device); |
| 124 } | 125 } |
| 125 | 126 |
| 126 static int g_next_request_id = 0; | 127 blink::WebMediaDeviceInfo::MediaDeviceKind ToMediaDeviceKind( |
| 128 MediaDeviceType type) { | |
| 129 switch (type) { | |
| 130 case MEDIA_DEVICE_TYPE_AUDIO_INPUT: | |
| 131 return blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput; | |
| 132 case MEDIA_DEVICE_TYPE_VIDEO_INPUT: | |
| 133 return blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput; | |
| 134 case MEDIA_DEVICE_TYPE_AUDIO_OUTPUT: | |
| 135 return blink::WebMediaDeviceInfo::MediaDeviceKindAudioOutput; | |
| 136 default: | |
| 137 NOTREACHED(); | |
| 138 return blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput; | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 blink::WebSourceInfo::VideoFacingMode ToVideoFacingMode( | |
| 143 const std::string& device_label) { | |
| 144 #if defined(OS_ANDROID) | |
| 145 if (device_label.find("front") != std::string::npos) { | |
|
tommi (sloooow) - chröme
2016/10/07 19:59:40
is this behavior copied from somewhere? Would it
Guido Urdaneta
2016/10/08 10:09:56
This is copied from here: https://cs.chromium.org/
| |
| 146 return blink::WebSourceInfo::VideoFacingModeUser; | |
| 147 } else if (device_label.find("back") != std::string::npos) { | |
| 148 return blink::WebSourceInfo::VideoFacingModeEnvironment; | |
| 149 } | |
| 150 #endif | |
| 151 return blink::WebSourceInfo::VideoFacingModeNone; | |
| 152 } | |
| 153 | |
| 154 static int g_next_request_id = 0; | |
| 127 | 155 |
| 128 } // namespace | 156 } // namespace |
| 129 | 157 |
| 130 struct UserMediaClientImpl::MediaDevicesRequestInfo { | |
| 131 MediaDevicesRequestInfo(const blink::WebMediaDevicesRequest& request, | |
| 132 int audio_input_request_id, | |
| 133 int video_input_request_id, | |
| 134 int audio_output_request_id) | |
| 135 : media_devices_request(request), | |
| 136 audio_input_request_id(audio_input_request_id), | |
| 137 video_input_request_id(video_input_request_id), | |
| 138 audio_output_request_id(audio_output_request_id), | |
| 139 has_audio_input_returned(false), | |
| 140 has_video_input_returned(false), | |
| 141 has_audio_output_returned(false) {} | |
| 142 | |
| 143 MediaDevicesRequestInfo( | |
| 144 const blink::WebMediaStreamTrackSourcesRequest& request, | |
| 145 int audio_input_request_id, | |
| 146 int video_input_request_id) | |
| 147 : sources_request(request), | |
| 148 audio_input_request_id(audio_input_request_id), | |
| 149 video_input_request_id(video_input_request_id), | |
| 150 audio_output_request_id(-1), | |
| 151 has_audio_input_returned(false), | |
| 152 has_video_input_returned(false), | |
| 153 has_audio_output_returned(false) {} | |
| 154 | |
| 155 bool IsSourcesRequest() { | |
| 156 // We can't check isNull() on |media_devices_request| and |sources_request|, | |
| 157 // because in unit tests they will always be null. | |
| 158 return audio_output_request_id == -1; | |
| 159 } | |
| 160 | |
| 161 blink::WebMediaDevicesRequest media_devices_request; | |
| 162 blink::WebMediaStreamTrackSourcesRequest sources_request; | |
| 163 int audio_input_request_id; | |
| 164 int video_input_request_id; | |
| 165 int audio_output_request_id; | |
| 166 bool has_audio_input_returned; | |
| 167 bool has_video_input_returned; | |
| 168 bool has_audio_output_returned; | |
| 169 StreamDeviceInfoArray audio_input_devices; | |
| 170 StreamDeviceInfoArray video_input_devices; | |
| 171 StreamDeviceInfoArray audio_output_devices; | |
| 172 }; | |
| 173 | |
| 174 UserMediaClientImpl::UserMediaClientImpl( | 158 UserMediaClientImpl::UserMediaClientImpl( |
| 175 RenderFrame* render_frame, | 159 RenderFrame* render_frame, |
| 176 PeerConnectionDependencyFactory* dependency_factory, | 160 PeerConnectionDependencyFactory* dependency_factory, |
| 177 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher) | 161 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher) |
| 178 : RenderFrameObserver(render_frame), | 162 : RenderFrameObserver(render_frame), |
| 179 dependency_factory_(dependency_factory), | 163 dependency_factory_(dependency_factory), |
| 180 media_stream_dispatcher_(std::move(media_stream_dispatcher)), | 164 media_stream_dispatcher_(std::move(media_stream_dispatcher)), |
| 181 weak_factory_(this) { | 165 weak_factory_(this) { |
| 182 DCHECK(dependency_factory_); | 166 DCHECK(dependency_factory_); |
| 183 DCHECK(media_stream_dispatcher_.get()); | 167 DCHECK(media_stream_dispatcher_.get()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED); | 267 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED); |
| 284 DeleteUserMediaRequestInfo(request); | 268 DeleteUserMediaRequestInfo(request); |
| 285 } | 269 } |
| 286 } | 270 } |
| 287 | 271 |
| 288 void UserMediaClientImpl::requestMediaDevices( | 272 void UserMediaClientImpl::requestMediaDevices( |
| 289 const blink::WebMediaDevicesRequest& media_devices_request) { | 273 const blink::WebMediaDevicesRequest& media_devices_request) { |
| 290 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); | 274 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); |
| 291 DCHECK(CalledOnValidThread()); | 275 DCHECK(CalledOnValidThread()); |
| 292 | 276 |
| 293 int audio_input_request_id = g_next_request_id++; | |
| 294 int video_input_request_id = g_next_request_id++; | |
| 295 int audio_output_request_id = g_next_request_id++; | |
| 296 | |
| 297 // |media_devices_request| can't be mocked, so in tests it will be empty (the | 277 // |media_devices_request| can't be mocked, so in tests it will be empty (the |
| 298 // underlying pointer is null). In order to use this function in a test we | 278 // underlying pointer is null). In order to use this function in a test we |
| 299 // need to check if it isNull. | 279 // need to check if it isNull. |
| 300 url::Origin security_origin; | 280 url::Origin security_origin; |
| 301 if (!media_devices_request.isNull()) | 281 if (!media_devices_request.isNull()) |
| 302 security_origin = media_devices_request.getSecurityOrigin(); | 282 security_origin = media_devices_request.getSecurityOrigin(); |
| 303 | 283 |
| 304 DVLOG(1) << "UserMediaClientImpl::requestMediaDevices(" | 284 GetMediaDevicesDispatcher()->EnumerateDevices( |
| 305 << audio_input_request_id << ", " << video_input_request_id << ", " | 285 true /* audio input */, true /* video input */, true /* audio output */, |
| 306 << audio_output_request_id << ", " << security_origin << ")"; | 286 security_origin, |
| 307 | 287 base::Bind(&UserMediaClientImpl::FinalizeEnumerateDevices, |
| 308 media_devices_requests_.push_back(new MediaDevicesRequestInfo( | 288 weak_factory_.GetWeakPtr(), media_devices_request)); |
| 309 media_devices_request, | |
| 310 audio_input_request_id, | |
| 311 video_input_request_id, | |
| 312 audio_output_request_id)); | |
| 313 | |
| 314 media_stream_dispatcher_->EnumerateDevices( | |
| 315 audio_input_request_id, | |
| 316 weak_factory_.GetWeakPtr(), | |
| 317 MEDIA_DEVICE_AUDIO_CAPTURE, | |
| 318 security_origin); | |
| 319 | |
| 320 media_stream_dispatcher_->EnumerateDevices( | |
| 321 video_input_request_id, | |
| 322 weak_factory_.GetWeakPtr(), | |
| 323 MEDIA_DEVICE_VIDEO_CAPTURE, | |
| 324 security_origin); | |
| 325 | |
| 326 media_stream_dispatcher_->EnumerateDevices( | |
| 327 audio_output_request_id, | |
| 328 weak_factory_.GetWeakPtr(), | |
| 329 MEDIA_DEVICE_AUDIO_OUTPUT, | |
| 330 security_origin); | |
| 331 } | 289 } |
| 332 | 290 |
| 333 void UserMediaClientImpl::requestSources( | 291 void UserMediaClientImpl::requestSources( |
| 334 const blink::WebMediaStreamTrackSourcesRequest& sources_request) { | 292 const blink::WebMediaStreamTrackSourcesRequest& sources_request) { |
| 335 // We don't call UpdateWebRTCMethodCount() here to track the API count in UMA | 293 // We don't call UpdateWebRTCMethodCount() here to track the API count in UMA |
| 336 // stats. This is instead counted in MediaStreamTrack::getSources in blink. | 294 // stats. This is instead counted in MediaStreamTrack::getSources in blink. |
| 337 DCHECK(CalledOnValidThread()); | 295 DCHECK(CalledOnValidThread()); |
| 338 | 296 |
| 339 int audio_input_request_id = g_next_request_id++; | |
| 340 int video_input_request_id = g_next_request_id++; | |
| 341 | |
| 342 // |sources_request| can't be mocked, so in tests it will be empty (the | 297 // |sources_request| can't be mocked, so in tests it will be empty (the |
| 343 // underlying pointer is null). In order to use this function in a test we | 298 // underlying pointer is null). In order to use this function in a test we |
| 344 // need to check if it isNull. | 299 // need to check if it isNull. |
| 345 url::Origin security_origin; | 300 url::Origin security_origin; |
| 346 if (!sources_request.isNull()) | 301 if (!sources_request.isNull()) |
| 347 security_origin = sources_request.origin(); | 302 security_origin = sources_request.origin(); |
| 348 | 303 |
| 349 DVLOG(1) << "UserMediaClientImpl::requestSources(" << audio_input_request_id | 304 GetMediaDevicesDispatcher()->EnumerateDevices( |
| 350 << ", " << video_input_request_id << ", " << security_origin << ")"; | 305 true /* audio input */, true /* video input */, false /* audio output */, |
| 351 | 306 security_origin, base::Bind(&UserMediaClientImpl::FinalizeGetSources, |
| 352 media_devices_requests_.push_back(new MediaDevicesRequestInfo( | 307 weak_factory_.GetWeakPtr(), sources_request)); |
| 353 sources_request, | |
| 354 audio_input_request_id, | |
| 355 video_input_request_id)); | |
| 356 | |
| 357 media_stream_dispatcher_->EnumerateDevices( | |
| 358 audio_input_request_id, | |
| 359 weak_factory_.GetWeakPtr(), | |
| 360 MEDIA_DEVICE_AUDIO_CAPTURE, | |
| 361 security_origin); | |
| 362 | |
| 363 media_stream_dispatcher_->EnumerateDevices( | |
| 364 video_input_request_id, | |
| 365 weak_factory_.GetWeakPtr(), | |
| 366 MEDIA_DEVICE_VIDEO_CAPTURE, | |
| 367 security_origin); | |
| 368 } | 308 } |
| 369 | 309 |
| 370 void UserMediaClientImpl::setMediaDeviceChangeObserver( | 310 void UserMediaClientImpl::setMediaDeviceChangeObserver( |
| 371 const blink::WebMediaDeviceChangeObserver& observer) { | 311 const blink::WebMediaDeviceChangeObserver& observer) { |
| 372 media_device_change_observer_ = observer; | 312 media_device_change_observer_ = observer; |
| 373 | 313 |
| 374 if (media_device_change_observer_.isNull()) { | 314 if (media_device_change_observer_.isNull()) { |
| 375 media_stream_dispatcher_->CancelDeviceChangeNotifications( | 315 media_stream_dispatcher_->CancelDeviceChangeNotifications( |
| 376 weak_factory_.GetWeakPtr()); | 316 weak_factory_.GetWeakPtr()); |
| 377 } else { | 317 } else { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 } | 389 } |
| 450 | 390 |
| 451 for (StreamDeviceInfoArray::const_iterator device_it = video_array.begin(); | 391 for (StreamDeviceInfoArray::const_iterator device_it = video_array.begin(); |
| 452 device_it != video_array.end(); ++device_it) { | 392 device_it != video_array.end(); ++device_it) { |
| 453 if (!FindLocalSource(*device_it)) | 393 if (!FindLocalSource(*device_it)) |
| 454 media_stream_dispatcher_->StopStreamDevice(*device_it); | 394 media_stream_dispatcher_->StopStreamDevice(*device_it); |
| 455 } | 395 } |
| 456 } | 396 } |
| 457 | 397 |
| 458 void UserMediaClientImpl::FinalizeEnumerateDevices( | 398 void UserMediaClientImpl::FinalizeEnumerateDevices( |
| 459 MediaDevicesRequestInfo* request) { | 399 blink::WebMediaDevicesRequest request, |
| 460 blink::WebVector<blink::WebMediaDeviceInfo> | 400 const EnumerationResult& result) { |
| 461 devices(request->audio_input_devices.size() + | 401 DCHECK_EQ(static_cast<size_t>(NUM_MEDIA_DEVICE_TYPES), result.size()); |
| 462 request->video_input_devices.size() + | |
| 463 request->audio_output_devices.size()); | |
| 464 for (size_t i = 0; i < request->audio_input_devices.size(); ++i) { | |
| 465 const MediaStreamDevice& device = request->audio_input_devices[i].device; | |
| 466 DCHECK_EQ(device.type, MEDIA_DEVICE_AUDIO_CAPTURE); | |
| 467 | 402 |
| 468 devices[i].initialize(blink::WebString::fromUTF8(device.id), | 403 blink::WebVector<blink::WebMediaDeviceInfo> devices( |
| 469 blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput, | 404 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT].size() + |
| 470 blink::WebString::fromUTF8(device.name), | 405 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT].size() + |
| 471 blink::WebString::fromUTF8(device.group_id)); | 406 result[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].size()); |
| 472 } | 407 size_t index = 0; |
| 473 size_t offset = request->audio_input_devices.size(); | 408 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) { |
| 474 for (size_t i = 0; i < request->video_input_devices.size(); ++i) { | 409 blink::WebMediaDeviceInfo::MediaDeviceKind device_kind = |
| 475 const MediaStreamDevice& device = request->video_input_devices[i].device; | 410 ToMediaDeviceKind(static_cast<MediaDeviceType>(i)); |
| 476 DCHECK_EQ(device.type, MEDIA_DEVICE_VIDEO_CAPTURE); | 411 for (const auto& device_info : result[i]) { |
| 477 devices[offset + i].initialize( | 412 devices[index++].initialize( |
| 478 blink::WebString::fromUTF8(device.id), | 413 blink::WebString::fromUTF8(device_info.device_id), device_kind, |
| 479 blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput, | 414 blink::WebString::fromUTF8(device_info.label), |
| 480 blink::WebString::fromUTF8(device.name), | 415 blink::WebString::fromUTF8(device_info.group_id)); |
| 481 blink::WebString()); | 416 } |
| 482 } | |
| 483 offset += request->video_input_devices.size(); | |
| 484 for (size_t i = 0; i < request->audio_output_devices.size(); ++i) { | |
| 485 const MediaStreamDevice& device = request->audio_output_devices[i].device; | |
| 486 DCHECK_EQ(device.type, MEDIA_DEVICE_AUDIO_OUTPUT); | |
| 487 devices[offset + i].initialize( | |
| 488 blink::WebString::fromUTF8(device.id), | |
| 489 blink::WebMediaDeviceInfo::MediaDeviceKindAudioOutput, | |
| 490 blink::WebString::fromUTF8(device.name), | |
| 491 blink::WebString::fromUTF8(device.group_id)); | |
| 492 } | 417 } |
| 493 | 418 |
| 494 EnumerateDevicesSucceded(&request->media_devices_request, devices); | 419 EnumerateDevicesSucceded(&request, devices); |
| 495 } | 420 } |
| 496 | 421 |
| 497 void UserMediaClientImpl::FinalizeEnumerateSources( | 422 void UserMediaClientImpl::FinalizeGetSources( |
| 498 MediaDevicesRequestInfo* request) { | 423 blink::WebMediaStreamTrackSourcesRequest request, |
| 499 blink::WebVector<blink::WebSourceInfo> | 424 const EnumerationResult& result) { |
| 500 sources(request->audio_input_devices.size() + | 425 DCHECK_EQ(static_cast<size_t>(NUM_MEDIA_DEVICE_TYPES), result.size()); |
| 501 request->video_input_devices.size()); | 426 |
| 502 for (size_t i = 0; i < request->audio_input_devices.size(); ++i) { | 427 blink::WebVector<blink::WebSourceInfo> sources( |
| 503 const MediaStreamDevice& device = request->audio_input_devices[i].device; | 428 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT].size() + |
| 504 DCHECK_EQ(device.type, MEDIA_DEVICE_AUDIO_CAPTURE); | 429 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT].size()); |
| 505 std::string group_id = base::UintToString(base::Hash( | 430 size_t index = 0; |
| 506 !device.matched_output_device_id.empty() ? | 431 for (const auto& device_info : result[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { |
| 507 device.matched_output_device_id : | 432 sources[index++].initialize( |
| 508 device.id)); | 433 blink::WebString::fromUTF8(device_info.device_id), |
| 509 sources[i].initialize(blink::WebString::fromUTF8(device.id), | 434 blink::WebSourceInfo::SourceKindAudio, |
| 510 blink::WebSourceInfo::SourceKindAudio, | 435 blink::WebString::fromUTF8(device_info.label), |
| 511 blink::WebString::fromUTF8(device.name), | 436 blink::WebSourceInfo::VideoFacingModeNone); |
| 512 blink::WebSourceInfo::VideoFacingModeNone); | |
| 513 } | |
| 514 size_t offset = request->audio_input_devices.size(); | |
| 515 for (size_t i = 0; i < request->video_input_devices.size(); ++i) { | |
| 516 const MediaStreamDevice& device = request->video_input_devices[i].device; | |
| 517 DCHECK_EQ(device.type, MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 518 blink::WebSourceInfo::VideoFacingMode video_facing; | |
| 519 switch (device.video_facing) { | |
| 520 case MEDIA_VIDEO_FACING_USER: | |
| 521 video_facing = blink::WebSourceInfo::VideoFacingModeUser; | |
| 522 break; | |
| 523 case MEDIA_VIDEO_FACING_ENVIRONMENT: | |
| 524 video_facing = blink::WebSourceInfo::VideoFacingModeEnvironment; | |
| 525 break; | |
| 526 default: | |
| 527 video_facing = blink::WebSourceInfo::VideoFacingModeNone; | |
| 528 } | |
| 529 sources[offset + i].initialize(blink::WebString::fromUTF8(device.id), | |
| 530 blink::WebSourceInfo::SourceKindVideo, | |
| 531 blink::WebString::fromUTF8(device.name), | |
| 532 video_facing); | |
| 533 } | 437 } |
| 534 | 438 |
| 535 EnumerateSourcesSucceded(&request->sources_request, sources); | 439 for (const auto& device_info : result[MEDIA_DEVICE_TYPE_VIDEO_INPUT]) { |
| 440 sources[index++].initialize( | |
| 441 blink::WebString::fromUTF8(device_info.device_id), | |
| 442 blink::WebSourceInfo::SourceKindVideo, | |
| 443 blink::WebString::fromUTF8(device_info.label), | |
| 444 ToVideoFacingMode(device_info.label)); | |
| 445 } | |
| 446 | |
| 447 EnumerateSourcesSucceded(&request, sources); | |
| 536 } | 448 } |
| 537 | 449 |
| 538 // Callback from MediaStreamDispatcher. | 450 // Callback from MediaStreamDispatcher. |
| 539 // The requested stream failed to be generated. | 451 // The requested stream failed to be generated. |
| 540 void UserMediaClientImpl::OnStreamGenerationFailed( | 452 void UserMediaClientImpl::OnStreamGenerationFailed( |
| 541 int request_id, | 453 int request_id, |
| 542 MediaStreamRequestResult result) { | 454 MediaStreamRequestResult result) { |
| 543 DCHECK(CalledOnValidThread()); | 455 DCHECK(CalledOnValidThread()); |
| 544 DVLOG(1) << "UserMediaClientImpl::OnStreamGenerationFailed(" | 456 DVLOG(1) << "UserMediaClientImpl::OnStreamGenerationFailed(" |
| 545 << request_id << ")"; | 457 << request_id << ")"; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 track->Stop(); | 647 track->Stop(); |
| 736 } | 648 } |
| 737 } | 649 } |
| 738 | 650 |
| 739 DeleteUserMediaRequestInfo(request); | 651 DeleteUserMediaRequestInfo(request); |
| 740 } | 652 } |
| 741 | 653 |
| 742 void UserMediaClientImpl::OnDevicesEnumerated( | 654 void UserMediaClientImpl::OnDevicesEnumerated( |
| 743 int request_id, | 655 int request_id, |
| 744 const StreamDeviceInfoArray& device_array) { | 656 const StreamDeviceInfoArray& device_array) { |
| 745 DVLOG(1) << "UserMediaClientImpl::OnDevicesEnumerated(" << request_id << ")"; | 657 NOTREACHED(); |
| 746 | |
| 747 MediaDevicesRequestInfo* request = FindMediaDevicesRequestInfo(request_id); | |
| 748 if (!request) | |
| 749 return; | |
| 750 | |
| 751 if (request_id == request->audio_input_request_id) { | |
| 752 request->has_audio_input_returned = true; | |
| 753 request->audio_input_devices = device_array; | |
| 754 } else if (request_id == request->video_input_request_id) { | |
| 755 request->has_video_input_returned = true; | |
| 756 request->video_input_devices = device_array; | |
| 757 } else { | |
| 758 DCHECK_EQ(request->audio_output_request_id, request_id); | |
| 759 request->has_audio_output_returned = true; | |
| 760 request->audio_output_devices = device_array; | |
| 761 } | |
| 762 | |
| 763 if (!request->has_audio_input_returned || | |
| 764 !request->has_video_input_returned || | |
| 765 (!request->IsSourcesRequest() && !request->has_audio_output_returned)) { | |
| 766 // Wait for the rest of the devices to complete. | |
| 767 return; | |
| 768 } | |
| 769 | |
| 770 if (request->IsSourcesRequest()) | |
| 771 FinalizeEnumerateSources(request); | |
| 772 else | |
| 773 FinalizeEnumerateDevices(request); | |
| 774 | |
| 775 CancelAndDeleteMediaDevicesRequest(request); | |
| 776 } | 658 } |
| 777 | 659 |
| 778 void UserMediaClientImpl::OnDeviceOpened( | 660 void UserMediaClientImpl::OnDeviceOpened( |
| 779 int request_id, | 661 int request_id, |
| 780 const std::string& label, | 662 const std::string& label, |
| 781 const StreamDeviceInfo& video_device) { | 663 const StreamDeviceInfo& video_device) { |
| 782 DVLOG(1) << "UserMediaClientImpl::OnDeviceOpened(" | 664 DVLOG(1) << "UserMediaClientImpl::OnDeviceOpened(" |
| 783 << request_id << ", " << label << ")"; | 665 << request_id << ", " << label << ")"; |
| 784 NOTIMPLEMENTED(); | 666 NOTIMPLEMENTED(); |
| 785 } | 667 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 976 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_NOT_GENERATED); | 858 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_NOT_GENERATED); |
| 977 } else { | 859 } else { |
| 978 DCHECK((*request_it)->HasPendingSources()); | 860 DCHECK((*request_it)->HasPendingSources()); |
| 979 LogUserMediaRequestWithNoResult( | 861 LogUserMediaRequestWithNoResult( |
| 980 MEDIA_STREAM_REQUEST_PENDING_MEDIA_TRACKS); | 862 MEDIA_STREAM_REQUEST_PENDING_MEDIA_TRACKS); |
| 981 } | 863 } |
| 982 request_it = user_media_requests_.erase(request_it); | 864 request_it = user_media_requests_.erase(request_it); |
| 983 } | 865 } |
| 984 } | 866 } |
| 985 | 867 |
| 986 UserMediaClientImpl::MediaDevicesRequestInfo* | |
| 987 UserMediaClientImpl::FindMediaDevicesRequestInfo( | |
| 988 int request_id) { | |
| 989 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); | |
| 990 for (; it != media_devices_requests_.end(); ++it) { | |
| 991 if ((*it)->audio_input_request_id == request_id || | |
| 992 (*it)->video_input_request_id == request_id || | |
| 993 (*it)->audio_output_request_id == request_id) { | |
| 994 return (*it); | |
| 995 } | |
| 996 } | |
| 997 return NULL; | |
| 998 } | |
| 999 | |
| 1000 UserMediaClientImpl::MediaDevicesRequestInfo* | |
| 1001 UserMediaClientImpl::FindMediaDevicesRequestInfo( | |
| 1002 const blink::WebMediaDevicesRequest& request) { | |
| 1003 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); | |
| 1004 for (; it != media_devices_requests_.end(); ++it) { | |
| 1005 if ((*it)->media_devices_request == request) | |
| 1006 return (*it); | |
| 1007 } | |
| 1008 return NULL; | |
| 1009 } | |
| 1010 | |
| 1011 void UserMediaClientImpl::CancelAndDeleteMediaDevicesRequest( | |
| 1012 MediaDevicesRequestInfo* request) { | |
| 1013 MediaDevicesRequests::iterator it = media_devices_requests_.begin(); | |
| 1014 for (; it != media_devices_requests_.end(); ++it) { | |
| 1015 if ((*it) == request) { | |
| 1016 // Cancel device enumeration. | |
| 1017 media_stream_dispatcher_->StopEnumerateDevices( | |
| 1018 request->audio_input_request_id, weak_factory_.GetWeakPtr()); | |
| 1019 media_stream_dispatcher_->StopEnumerateDevices( | |
| 1020 request->video_input_request_id, weak_factory_.GetWeakPtr()); | |
| 1021 media_stream_dispatcher_->StopEnumerateDevices( | |
| 1022 request->audio_output_request_id, weak_factory_.GetWeakPtr()); | |
| 1023 | |
| 1024 media_devices_requests_.erase(it); | |
| 1025 return; | |
| 1026 } | |
| 1027 } | |
| 1028 NOTREACHED(); | |
| 1029 } | |
| 1030 | |
| 1031 void UserMediaClientImpl::WillCommitProvisionalLoad() { | 868 void UserMediaClientImpl::WillCommitProvisionalLoad() { |
| 1032 // Cancel all outstanding UserMediaRequests. | 869 // Cancel all outstanding UserMediaRequests. |
| 1033 DeleteAllUserMediaRequests(); | 870 DeleteAllUserMediaRequests(); |
| 1034 | 871 |
| 1035 // Loop through all current local sources and stop the sources. | 872 // Loop through all current local sources and stop the sources. |
| 1036 LocalStreamSources::iterator sources_it = local_sources_.begin(); | 873 LocalStreamSources::iterator sources_it = local_sources_.begin(); |
| 1037 while (sources_it != local_sources_.end()) { | 874 while (sources_it != local_sources_.end()) { |
| 1038 StopLocalSource(*sources_it, true); | 875 StopLocalSource(*sources_it, true); |
| 1039 sources_it = local_sources_.erase(sources_it); | 876 sources_it = local_sources_.erase(sources_it); |
| 1040 } | 877 } |
| 1041 } | 878 } |
| 1042 | 879 |
| 880 void UserMediaClientImpl::SetMediaDevicesDispatcherForTesting( | |
| 881 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher) { | |
| 882 media_devices_dispatcher_ = std::move(media_devices_dispatcher); | |
| 883 } | |
| 884 | |
| 1043 void UserMediaClientImpl::OnLocalSourceStopped( | 885 void UserMediaClientImpl::OnLocalSourceStopped( |
| 1044 const blink::WebMediaStreamSource& source) { | 886 const blink::WebMediaStreamSource& source) { |
| 1045 DCHECK(CalledOnValidThread()); | 887 DCHECK(CalledOnValidThread()); |
| 1046 DVLOG(1) << "UserMediaClientImpl::OnLocalSourceStopped"; | 888 DVLOG(1) << "UserMediaClientImpl::OnLocalSourceStopped"; |
| 1047 | 889 |
| 1048 const bool some_source_removed = RemoveLocalSource(source); | 890 const bool some_source_removed = RemoveLocalSource(source); |
| 1049 CHECK(some_source_removed); | 891 CHECK(some_source_removed); |
| 1050 | 892 |
| 1051 MediaStreamSource* source_impl = | 893 MediaStreamSource* source_impl = |
| 1052 static_cast<MediaStreamSource*>(source.getExtraData()); | 894 static_cast<MediaStreamSource*>(source.getExtraData()); |
| 1053 media_stream_dispatcher_->StopStreamDevice(source_impl->device_info()); | 895 media_stream_dispatcher_->StopStreamDevice(source_impl->device_info()); |
| 1054 } | 896 } |
| 1055 | 897 |
| 1056 void UserMediaClientImpl::StopLocalSource( | 898 void UserMediaClientImpl::StopLocalSource( |
| 1057 const blink::WebMediaStreamSource& source, | 899 const blink::WebMediaStreamSource& source, |
| 1058 bool notify_dispatcher) { | 900 bool notify_dispatcher) { |
| 1059 MediaStreamSource* source_impl = | 901 MediaStreamSource* source_impl = |
| 1060 static_cast<MediaStreamSource*>(source.getExtraData()); | 902 static_cast<MediaStreamSource*>(source.getExtraData()); |
| 1061 DVLOG(1) << "UserMediaClientImpl::StopLocalSource(" | 903 DVLOG(1) << "UserMediaClientImpl::StopLocalSource(" |
| 1062 << "{device_id = " << source_impl->device_info().device.id << "})"; | 904 << "{device_id = " << source_impl->device_info().device.id << "})"; |
| 1063 | 905 |
| 1064 if (notify_dispatcher) | 906 if (notify_dispatcher) |
| 1065 media_stream_dispatcher_->StopStreamDevice(source_impl->device_info()); | 907 media_stream_dispatcher_->StopStreamDevice(source_impl->device_info()); |
| 1066 | 908 |
| 1067 source_impl->ResetSourceStoppedCallback(); | 909 source_impl->ResetSourceStoppedCallback(); |
| 1068 source_impl->StopSource(); | 910 source_impl->StopSource(); |
| 1069 } | 911 } |
| 1070 | 912 |
| 913 const ::mojom::MediaDevicesDispatcherHostPtr& | |
| 914 UserMediaClientImpl::GetMediaDevicesDispatcher() { | |
| 915 if (!media_devices_dispatcher_) { | |
| 916 render_frame()->GetRemoteInterfaces()->GetInterface( | |
| 917 mojo::GetProxy(&media_devices_dispatcher_)); | |
| 918 } | |
| 919 | |
| 920 return media_devices_dispatcher_; | |
| 921 } | |
| 922 | |
| 1071 UserMediaClientImpl::UserMediaRequestInfo::UserMediaRequestInfo( | 923 UserMediaClientImpl::UserMediaRequestInfo::UserMediaRequestInfo( |
| 1072 int request_id, | 924 int request_id, |
| 1073 const blink::WebUserMediaRequest& request, | 925 const blink::WebUserMediaRequest& request, |
| 1074 bool enable_automatic_output_device_selection) | 926 bool enable_automatic_output_device_selection) |
| 1075 : request_id(request_id), | 927 : request_id(request_id), |
| 1076 generated(false), | 928 generated(false), |
| 1077 enable_automatic_output_device_selection( | 929 enable_automatic_output_device_selection( |
| 1078 enable_automatic_output_device_selection), | 930 enable_automatic_output_device_selection), |
| 1079 request(request), | 931 request(request), |
| 1080 request_result_(MEDIA_DEVICE_OK), | 932 request_result_(MEDIA_DEVICE_OK), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1176 | 1028 |
| 1177 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { | 1029 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { |
| 1178 return !sources_waiting_for_callback_.empty(); | 1030 return !sources_waiting_for_callback_.empty(); |
| 1179 } | 1031 } |
| 1180 | 1032 |
| 1181 void UserMediaClientImpl::OnDestruct() { | 1033 void UserMediaClientImpl::OnDestruct() { |
| 1182 delete this; | 1034 delete this; |
| 1183 } | 1035 } |
| 1184 | 1036 |
| 1185 } // namespace content | 1037 } // namespace content |
| OLD | NEW |