| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 GetConstraintValueAsBoolean( | 407 GetConstraintValueAsBoolean( |
| 408 current_request_info_->request().AudioConstraints(), | 408 current_request_info_->request().AudioConstraints(), |
| 409 &blink::WebMediaTrackConstraintSet::render_to_associated_sink, | 409 &blink::WebMediaTrackConstraintSet::render_to_associated_sink, |
| 410 &enable_automatic_output_device_selection); | 410 &enable_automatic_output_device_selection); |
| 411 current_request_info_->set_enable_automatic_output_device_selection( | 411 current_request_info_->set_enable_automatic_output_device_selection( |
| 412 enable_automatic_output_device_selection); | 412 enable_automatic_output_device_selection); |
| 413 | 413 |
| 414 if (request_audio_input_devices) { | 414 if (request_audio_input_devices) { |
| 415 GetMediaDevicesDispatcher()->EnumerateDevices( | 415 GetMediaDevicesDispatcher()->EnumerateDevices( |
| 416 true /* audio_input */, false /* video_input */, | 416 true /* audio_input */, false /* video_input */, |
| 417 false /* audio_output */, current_request_info_->security_origin(), | 417 false /* audio_output */, |
| 418 base::Bind(&UserMediaClientImpl::SelectAudioInputDevice, | 418 base::Bind(&UserMediaClientImpl::SelectAudioInputDevice, |
| 419 weak_factory_.GetWeakPtr(), | 419 weak_factory_.GetWeakPtr(), |
| 420 current_request_info_->request())); | 420 current_request_info_->request())); |
| 421 return; | 421 return; |
| 422 } | 422 } |
| 423 } | 423 } |
| 424 | 424 |
| 425 SetupVideoInput(current_request_info_->request()); | 425 SetupVideoInput(current_request_info_->request()); |
| 426 } | 426 } |
| 427 | 427 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 454 | 454 |
| 455 if (!user_media_request.Video()) { | 455 if (!user_media_request.Video()) { |
| 456 GenerateStreamForCurrentRequestInfo(); | 456 GenerateStreamForCurrentRequestInfo(); |
| 457 return; | 457 return; |
| 458 } | 458 } |
| 459 auto& video_controls = current_request_info_->stream_controls()->video; | 459 auto& video_controls = current_request_info_->stream_controls()->video; |
| 460 InitializeTrackControls(user_media_request.VideoConstraints(), | 460 InitializeTrackControls(user_media_request.VideoConstraints(), |
| 461 &video_controls); | 461 &video_controls); |
| 462 if (IsDeviceSource(video_controls.stream_source)) { | 462 if (IsDeviceSource(video_controls.stream_source)) { |
| 463 GetMediaDevicesDispatcher()->GetVideoInputCapabilities( | 463 GetMediaDevicesDispatcher()->GetVideoInputCapabilities( |
| 464 current_request_info_->security_origin(), | |
| 465 base::Bind(&UserMediaClientImpl::SelectVideoDeviceSettings, | 464 base::Bind(&UserMediaClientImpl::SelectVideoDeviceSettings, |
| 466 weak_factory_.GetWeakPtr(), user_media_request)); | 465 weak_factory_.GetWeakPtr(), user_media_request)); |
| 467 } else { | 466 } else { |
| 468 base::PostTaskAndReplyWithResult( | 467 base::PostTaskAndReplyWithResult( |
| 469 worker_task_runner_.get(), FROM_HERE, | 468 worker_task_runner_.get(), FROM_HERE, |
| 470 base::Bind(&SelectSettingsVideoContentCapture, | 469 base::Bind(&SelectSettingsVideoContentCapture, |
| 471 user_media_request.VideoConstraints(), | 470 user_media_request.VideoConstraints(), |
| 472 video_controls.stream_source), | 471 video_controls.stream_source), |
| 473 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoContentSettings, | 472 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoContentSettings, |
| 474 weak_factory_.GetWeakPtr(), user_media_request)); | 473 weak_factory_.GetWeakPtr(), user_media_request)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 // Instead, erase the request. Once the stream is generated we will stop the | 582 // Instead, erase the request. Once the stream is generated we will stop the |
| 584 // stream if the request does not exist. | 583 // stream if the request does not exist. |
| 585 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED); | 584 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED); |
| 586 } | 585 } |
| 587 } | 586 } |
| 588 | 587 |
| 589 void UserMediaClientImpl::RequestMediaDevices( | 588 void UserMediaClientImpl::RequestMediaDevices( |
| 590 const blink::WebMediaDevicesRequest& media_devices_request) { | 589 const blink::WebMediaDevicesRequest& media_devices_request) { |
| 591 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); | 590 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); |
| 592 DCHECK(CalledOnValidThread()); | 591 DCHECK(CalledOnValidThread()); |
| 593 | |
| 594 // |media_devices_request| can't be mocked, so in tests it will be empty (the | |
| 595 // underlying pointer is null). In order to use this function in a test we | |
| 596 // need to check if it isNull. | |
| 597 url::Origin security_origin; | |
| 598 if (!media_devices_request.IsNull()) | |
| 599 security_origin = media_devices_request.GetSecurityOrigin(); | |
| 600 | |
| 601 GetMediaDevicesDispatcher()->EnumerateDevices( | 592 GetMediaDevicesDispatcher()->EnumerateDevices( |
| 602 true /* audio input */, true /* video input */, true /* audio output */, | 593 true /* audio input */, true /* video input */, true /* audio output */, |
| 603 security_origin, | |
| 604 base::Bind(&UserMediaClientImpl::FinalizeEnumerateDevices, | 594 base::Bind(&UserMediaClientImpl::FinalizeEnumerateDevices, |
| 605 weak_factory_.GetWeakPtr(), media_devices_request)); | 595 weak_factory_.GetWeakPtr(), media_devices_request)); |
| 606 } | 596 } |
| 607 | 597 |
| 608 void UserMediaClientImpl::SetMediaDeviceChangeObserver( | 598 void UserMediaClientImpl::SetMediaDeviceChangeObserver( |
| 609 const blink::WebMediaDeviceChangeObserver& observer) { | 599 const blink::WebMediaDeviceChangeObserver& observer) { |
| 610 media_device_change_observer_ = observer; | 600 media_device_change_observer_ = observer; |
| 611 | 601 |
| 612 // Do nothing if setting a valid observer while already subscribed or setting | 602 // Do nothing if setting a valid observer while already subscribed or setting |
| 613 // no observer while unsubscribed. | 603 // no observer while unsubscribed. |
| 614 if (media_device_change_observer_.IsNull() == | 604 if (media_device_change_observer_.IsNull() == |
| 615 device_change_subscription_ids_.empty()) | 605 device_change_subscription_ids_.empty()) |
| 616 return; | 606 return; |
| 617 | 607 |
| 618 base::WeakPtr<MediaDevicesEventDispatcher> event_dispatcher = | 608 base::WeakPtr<MediaDevicesEventDispatcher> event_dispatcher = |
| 619 MediaDevicesEventDispatcher::GetForRenderFrame(render_frame()); | 609 MediaDevicesEventDispatcher::GetForRenderFrame(render_frame()); |
| 620 if (media_device_change_observer_.IsNull()) { | 610 if (media_device_change_observer_.IsNull()) { |
| 621 event_dispatcher->UnsubscribeDeviceChangeNotifications( | 611 event_dispatcher->UnsubscribeDeviceChangeNotifications( |
| 622 device_change_subscription_ids_); | 612 device_change_subscription_ids_); |
| 623 device_change_subscription_ids_.clear(); | 613 device_change_subscription_ids_.clear(); |
| 624 } else { | 614 } else { |
| 625 DCHECK(device_change_subscription_ids_.empty()); | 615 DCHECK(device_change_subscription_ids_.empty()); |
| 626 url::Origin security_origin = | |
| 627 media_device_change_observer_.GetSecurityOrigin(); | |
| 628 device_change_subscription_ids_ = | 616 device_change_subscription_ids_ = |
| 629 event_dispatcher->SubscribeDeviceChangeNotifications( | 617 event_dispatcher->SubscribeDeviceChangeNotifications(base::Bind( |
| 630 security_origin, base::Bind(&UserMediaClientImpl::DevicesChanged, | 618 &UserMediaClientImpl::DevicesChanged, weak_factory_.GetWeakPtr())); |
| 631 weak_factory_.GetWeakPtr())); | |
| 632 } | 619 } |
| 633 } | 620 } |
| 634 | 621 |
| 635 // Callback from MediaStreamDispatcher. | 622 // Callback from MediaStreamDispatcher. |
| 636 // The requested stream have been generated by the MediaStreamDispatcher. | 623 // The requested stream have been generated by the MediaStreamDispatcher. |
| 637 void UserMediaClientImpl::OnStreamGenerated( | 624 void UserMediaClientImpl::OnStreamGenerated( |
| 638 int request_id, | 625 int request_id, |
| 639 const std::string& label, | 626 const std::string& label, |
| 640 const StreamDeviceInfoArray& audio_array, | 627 const StreamDeviceInfoArray& audio_array, |
| 641 const StreamDeviceInfoArray& video_array) { | 628 const StreamDeviceInfoArray& video_array) { |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 const blink::WebString& result_name) { | 1378 const blink::WebString& result_name) { |
| 1392 // Check if we're waiting to be notified of this source. If not, then we'll | 1379 // Check if we're waiting to be notified of this source. If not, then we'll |
| 1393 // ignore the notification. | 1380 // ignore the notification. |
| 1394 auto found = std::find(sources_waiting_for_callback_.begin(), | 1381 auto found = std::find(sources_waiting_for_callback_.begin(), |
| 1395 sources_waiting_for_callback_.end(), source); | 1382 sources_waiting_for_callback_.end(), source); |
| 1396 if (found != sources_waiting_for_callback_.end()) | 1383 if (found != sources_waiting_for_callback_.end()) |
| 1397 OnTrackStarted(source, result, result_name); | 1384 OnTrackStarted(source, result, result_name); |
| 1398 } | 1385 } |
| 1399 | 1386 |
| 1400 } // namespace content | 1387 } // namespace content |
| OLD | NEW |