| 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 : RenderFrameObserver(render_frame), | 329 : RenderFrameObserver(render_frame), |
| 330 dependency_factory_(dependency_factory), | 330 dependency_factory_(dependency_factory), |
| 331 media_stream_dispatcher_(std::move(media_stream_dispatcher)), | 331 media_stream_dispatcher_(std::move(media_stream_dispatcher)), |
| 332 worker_task_runner_(worker_task_runner), | 332 worker_task_runner_(worker_task_runner), |
| 333 weak_factory_(this) { | 333 weak_factory_(this) { |
| 334 DCHECK(dependency_factory_); | 334 DCHECK(dependency_factory_); |
| 335 DCHECK(media_stream_dispatcher_.get()); | 335 DCHECK(media_stream_dispatcher_.get()); |
| 336 } | 336 } |
| 337 | 337 |
| 338 UserMediaClientImpl::~UserMediaClientImpl() { | 338 UserMediaClientImpl::~UserMediaClientImpl() { |
| 339 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 339 // Force-close all outstanding user media requests and local sources here, | 340 // Force-close all outstanding user media requests and local sources here, |
| 340 // before the outstanding WeakPtrs are invalidated, to ensure a clean | 341 // before the outstanding WeakPtrs are invalidated, to ensure a clean |
| 341 // shutdown. | 342 // shutdown. |
| 342 WillCommitProvisionalLoad(); | 343 WillCommitProvisionalLoad(); |
| 343 } | 344 } |
| 344 | 345 |
| 345 void UserMediaClientImpl::RequestUserMedia( | 346 void UserMediaClientImpl::RequestUserMedia( |
| 346 const blink::WebUserMediaRequest& user_media_request) { | 347 const blink::WebUserMediaRequest& user_media_request) { |
| 347 // Save histogram data so we can see how much GetUserMedia is used. | 348 // Save histogram data so we can see how much GetUserMedia is used. |
| 348 // The histogram counts the number of calls to the JS API | 349 // The histogram counts the number of calls to the JS API |
| 349 // webGetUserMedia. | 350 // webGetUserMedia. |
| 350 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); | 351 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
| 351 DCHECK(CalledOnValidThread()); | 352 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 352 DCHECK(!user_media_request.IsNull()); | 353 DCHECK(!user_media_request.IsNull()); |
| 353 DCHECK(user_media_request.Audio() || user_media_request.Video()); | 354 DCHECK(user_media_request.Audio() || user_media_request.Video()); |
| 354 // ownerDocument may be null if we are in a test. | 355 // ownerDocument may be null if we are in a test. |
| 355 // In that case, it's OK to not check frame(). | 356 // In that case, it's OK to not check frame(). |
| 356 DCHECK(user_media_request.OwnerDocument().IsNull() || | 357 DCHECK(user_media_request.OwnerDocument().IsNull() || |
| 357 render_frame()->GetWebFrame() == | 358 render_frame()->GetWebFrame() == |
| 358 static_cast<blink::WebFrame*>( | 359 static_cast<blink::WebFrame*>( |
| 359 user_media_request.OwnerDocument().GetFrame())); | 360 user_media_request.OwnerDocument().GetFrame())); |
| 360 | 361 |
| 361 if (RenderThreadImpl::current()) { | 362 if (RenderThreadImpl::current()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 375 static_cast<url::Origin>(user_media_request.GetSecurityOrigin())); | 376 static_cast<url::Origin>(user_media_request.GetSecurityOrigin())); |
| 376 pending_request_infos_.push_back(std::move(request_info)); | 377 pending_request_infos_.push_back(std::move(request_info)); |
| 377 if (!current_request_info_) { | 378 if (!current_request_info_) { |
| 378 base::ThreadTaskRunnerHandle::Get()->PostTask( | 379 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 379 FROM_HERE, base::Bind(&UserMediaClientImpl::MaybeProcessNextRequestInfo, | 380 FROM_HERE, base::Bind(&UserMediaClientImpl::MaybeProcessNextRequestInfo, |
| 380 weak_factory_.GetWeakPtr())); | 381 weak_factory_.GetWeakPtr())); |
| 381 } | 382 } |
| 382 } | 383 } |
| 383 | 384 |
| 384 void UserMediaClientImpl::MaybeProcessNextRequestInfo() { | 385 void UserMediaClientImpl::MaybeProcessNextRequestInfo() { |
| 385 DCHECK(CalledOnValidThread()); | 386 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 386 if (current_request_info_ || pending_request_infos_.empty()) | 387 if (current_request_info_ || pending_request_infos_.empty()) |
| 387 return; | 388 return; |
| 388 | 389 |
| 389 current_request_info_ = std::move(pending_request_infos_.front()); | 390 current_request_info_ = std::move(pending_request_infos_.front()); |
| 390 pending_request_infos_.pop_front(); | 391 pending_request_infos_.pop_front(); |
| 391 | 392 |
| 392 // TODO(guidou): Request audio and video capabilities in parallel. | 393 // TODO(guidou): Request audio and video capabilities in parallel. |
| 393 if (current_request_info_->request().Audio()) { | 394 if (current_request_info_->request().Audio()) { |
| 394 bool request_audio_input_devices = false; | 395 bool request_audio_input_devices = false; |
| 395 // TODO(guidou): Implement spec-compliant device selection for audio. See | 396 // TODO(guidou): Implement spec-compliant device selection for audio. See |
| (...skipping 25 matching lines...) Expand all Loading... |
| 421 return; | 422 return; |
| 422 } | 423 } |
| 423 } | 424 } |
| 424 | 425 |
| 425 SetupVideoInput(current_request_info_->request()); | 426 SetupVideoInput(current_request_info_->request()); |
| 426 } | 427 } |
| 427 | 428 |
| 428 void UserMediaClientImpl::SelectAudioInputDevice( | 429 void UserMediaClientImpl::SelectAudioInputDevice( |
| 429 const blink::WebUserMediaRequest& user_media_request, | 430 const blink::WebUserMediaRequest& user_media_request, |
| 430 const EnumerationResult& device_enumeration) { | 431 const EnumerationResult& device_enumeration) { |
| 431 DCHECK(CalledOnValidThread()); | 432 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 432 if (!IsCurrentRequestInfo(user_media_request)) | 433 if (!IsCurrentRequestInfo(user_media_request)) |
| 433 return; | 434 return; |
| 434 | 435 |
| 435 auto& audio_controls = current_request_info_->stream_controls()->audio; | 436 auto& audio_controls = current_request_info_->stream_controls()->audio; |
| 436 DCHECK(audio_controls.requested); | 437 DCHECK(audio_controls.requested); |
| 437 DCHECK(IsDeviceSource(audio_controls.stream_source)); | 438 DCHECK(IsDeviceSource(audio_controls.stream_source)); |
| 438 | 439 |
| 439 if (!PickDeviceId(user_media_request.AudioConstraints(), | 440 if (!PickDeviceId(user_media_request.AudioConstraints(), |
| 440 device_enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT], | 441 device_enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT], |
| 441 &audio_controls.device_id)) { | 442 &audio_controls.device_id)) { |
| 442 GetUserMediaRequestFailed(user_media_request, MEDIA_DEVICE_NO_HARDWARE, ""); | 443 GetUserMediaRequestFailed(user_media_request, MEDIA_DEVICE_NO_HARDWARE, ""); |
| 443 return; | 444 return; |
| 444 } | 445 } |
| 445 | 446 |
| 446 SetupVideoInput(user_media_request); | 447 SetupVideoInput(user_media_request); |
| 447 } | 448 } |
| 448 | 449 |
| 449 void UserMediaClientImpl::SetupVideoInput( | 450 void UserMediaClientImpl::SetupVideoInput( |
| 450 const blink::WebUserMediaRequest& user_media_request) { | 451 const blink::WebUserMediaRequest& user_media_request) { |
| 451 DCHECK(CalledOnValidThread()); | 452 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 452 if (!IsCurrentRequestInfo(user_media_request)) | 453 if (!IsCurrentRequestInfo(user_media_request)) |
| 453 return; | 454 return; |
| 454 | 455 |
| 455 if (!user_media_request.Video()) { | 456 if (!user_media_request.Video()) { |
| 456 GenerateStreamForCurrentRequestInfo(); | 457 GenerateStreamForCurrentRequestInfo(); |
| 457 return; | 458 return; |
| 458 } | 459 } |
| 459 auto& video_controls = current_request_info_->stream_controls()->video; | 460 auto& video_controls = current_request_info_->stream_controls()->video; |
| 460 InitializeTrackControls(user_media_request.VideoConstraints(), | 461 InitializeTrackControls(user_media_request.VideoConstraints(), |
| 461 &video_controls); | 462 &video_controls); |
| 462 if (IsDeviceSource(video_controls.stream_source)) { | 463 if (IsDeviceSource(video_controls.stream_source)) { |
| 463 GetMediaDevicesDispatcher()->GetVideoInputCapabilities( | 464 GetMediaDevicesDispatcher()->GetVideoInputCapabilities( |
| 464 base::Bind(&UserMediaClientImpl::SelectVideoDeviceSettings, | 465 base::Bind(&UserMediaClientImpl::SelectVideoDeviceSettings, |
| 465 weak_factory_.GetWeakPtr(), user_media_request)); | 466 weak_factory_.GetWeakPtr(), user_media_request)); |
| 466 } else { | 467 } else { |
| 467 base::PostTaskAndReplyWithResult( | 468 base::PostTaskAndReplyWithResult( |
| 468 worker_task_runner_.get(), FROM_HERE, | 469 worker_task_runner_.get(), FROM_HERE, |
| 469 base::Bind(&SelectSettingsVideoContentCapture, | 470 base::Bind(&SelectSettingsVideoContentCapture, |
| 470 user_media_request.VideoConstraints(), | 471 user_media_request.VideoConstraints(), |
| 471 video_controls.stream_source), | 472 video_controls.stream_source), |
| 472 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoContentSettings, | 473 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoContentSettings, |
| 473 weak_factory_.GetWeakPtr(), user_media_request)); | 474 weak_factory_.GetWeakPtr(), user_media_request)); |
| 474 } | 475 } |
| 475 } | 476 } |
| 476 | 477 |
| 477 void UserMediaClientImpl::SelectVideoDeviceSettings( | 478 void UserMediaClientImpl::SelectVideoDeviceSettings( |
| 478 const blink::WebUserMediaRequest& user_media_request, | 479 const blink::WebUserMediaRequest& user_media_request, |
| 479 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> | 480 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> |
| 480 video_input_capabilities) { | 481 video_input_capabilities) { |
| 481 DCHECK(CalledOnValidThread()); | 482 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 482 if (!IsCurrentRequestInfo(user_media_request)) | 483 if (!IsCurrentRequestInfo(user_media_request)) |
| 483 return; | 484 return; |
| 484 | 485 |
| 485 DCHECK(current_request_info_->stream_controls()->video.requested); | 486 DCHECK(current_request_info_->stream_controls()->video.requested); |
| 486 DCHECK(IsDeviceSource( | 487 DCHECK(IsDeviceSource( |
| 487 current_request_info_->stream_controls()->video.stream_source)); | 488 current_request_info_->stream_controls()->video.stream_source)); |
| 488 | 489 |
| 489 VideoDeviceCaptureCapabilities capabilities; | 490 VideoDeviceCaptureCapabilities capabilities; |
| 490 capabilities.device_capabilities = std::move(video_input_capabilities); | 491 capabilities.device_capabilities = std::move(video_input_capabilities); |
| 491 capabilities.power_line_capabilities = { | 492 capabilities.power_line_capabilities = { |
| 492 media::PowerLineFrequency::FREQUENCY_DEFAULT, | 493 media::PowerLineFrequency::FREQUENCY_DEFAULT, |
| 493 media::PowerLineFrequency::FREQUENCY_50HZ, | 494 media::PowerLineFrequency::FREQUENCY_50HZ, |
| 494 media::PowerLineFrequency::FREQUENCY_60HZ}; | 495 media::PowerLineFrequency::FREQUENCY_60HZ}; |
| 495 capabilities.noise_reduction_capabilities = {base::Optional<bool>(), | 496 capabilities.noise_reduction_capabilities = {base::Optional<bool>(), |
| 496 base::Optional<bool>(true), | 497 base::Optional<bool>(true), |
| 497 base::Optional<bool>(false)}; | 498 base::Optional<bool>(false)}; |
| 498 base::PostTaskAndReplyWithResult( | 499 base::PostTaskAndReplyWithResult( |
| 499 worker_task_runner_.get(), FROM_HERE, | 500 worker_task_runner_.get(), FROM_HERE, |
| 500 base::Bind(&SelectSettingsVideoDeviceCapture, std::move(capabilities), | 501 base::Bind(&SelectSettingsVideoDeviceCapture, std::move(capabilities), |
| 501 user_media_request.VideoConstraints()), | 502 user_media_request.VideoConstraints()), |
| 502 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoDeviceSettings, | 503 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoDeviceSettings, |
| 503 weak_factory_.GetWeakPtr(), user_media_request)); | 504 weak_factory_.GetWeakPtr(), user_media_request)); |
| 504 } | 505 } |
| 505 | 506 |
| 506 void UserMediaClientImpl::FinalizeSelectVideoDeviceSettings( | 507 void UserMediaClientImpl::FinalizeSelectVideoDeviceSettings( |
| 507 const blink::WebUserMediaRequest& user_media_request, | 508 const blink::WebUserMediaRequest& user_media_request, |
| 508 const VideoCaptureSettings& settings) { | 509 const VideoCaptureSettings& settings) { |
| 509 DCHECK(CalledOnValidThread()); | 510 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 510 if (!IsCurrentRequestInfo(user_media_request)) | 511 if (!IsCurrentRequestInfo(user_media_request)) |
| 511 return; | 512 return; |
| 512 | 513 |
| 513 if (!settings.HasValue()) { | 514 if (!settings.HasValue()) { |
| 514 blink::WebString failed_constraint_name = | 515 blink::WebString failed_constraint_name = |
| 515 blink::WebString::FromASCII(settings.failed_constraint_name()); | 516 blink::WebString::FromASCII(settings.failed_constraint_name()); |
| 516 MediaStreamRequestResult result = | 517 MediaStreamRequestResult result = |
| 517 failed_constraint_name.IsEmpty() | 518 failed_constraint_name.IsEmpty() |
| 518 ? MEDIA_DEVICE_NO_HARDWARE | 519 ? MEDIA_DEVICE_NO_HARDWARE |
| 519 : MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; | 520 : MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; |
| 520 GetUserMediaRequestFailed(user_media_request, result, | 521 GetUserMediaRequestFailed(user_media_request, result, |
| 521 failed_constraint_name); | 522 failed_constraint_name); |
| 522 return; | 523 return; |
| 523 } | 524 } |
| 524 current_request_info_->stream_controls()->video.device_id = | 525 current_request_info_->stream_controls()->video.device_id = |
| 525 settings.device_id(); | 526 settings.device_id(); |
| 526 current_request_info_->SetVideoCaptureSettings( | 527 current_request_info_->SetVideoCaptureSettings( |
| 527 settings, false /* is_content_capture */); | 528 settings, false /* is_content_capture */); |
| 528 GenerateStreamForCurrentRequestInfo(); | 529 GenerateStreamForCurrentRequestInfo(); |
| 529 } | 530 } |
| 530 | 531 |
| 531 void UserMediaClientImpl::FinalizeSelectVideoContentSettings( | 532 void UserMediaClientImpl::FinalizeSelectVideoContentSettings( |
| 532 const blink::WebUserMediaRequest& user_media_request, | 533 const blink::WebUserMediaRequest& user_media_request, |
| 533 const VideoCaptureSettings& settings) { | 534 const VideoCaptureSettings& settings) { |
| 534 DCHECK(CalledOnValidThread()); | 535 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 535 if (!IsCurrentRequestInfo(user_media_request)) | 536 if (!IsCurrentRequestInfo(user_media_request)) |
| 536 return; | 537 return; |
| 537 | 538 |
| 538 if (!settings.HasValue()) { | 539 if (!settings.HasValue()) { |
| 539 blink::WebString failed_constraint_name = | 540 blink::WebString failed_constraint_name = |
| 540 blink::WebString::FromASCII(settings.failed_constraint_name()); | 541 blink::WebString::FromASCII(settings.failed_constraint_name()); |
| 541 DCHECK(!failed_constraint_name.IsEmpty()); | 542 DCHECK(!failed_constraint_name.IsEmpty()); |
| 542 blink::WebString device_id_constraint_name = blink::WebString::FromASCII( | 543 blink::WebString device_id_constraint_name = blink::WebString::FromASCII( |
| 543 user_media_request.VideoConstraints().Basic().device_id.GetName()); | 544 user_media_request.VideoConstraints().Basic().device_id.GetName()); |
| 544 GetUserMediaRequestFailed(user_media_request, | 545 GetUserMediaRequestFailed(user_media_request, |
| 545 MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, | 546 MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, |
| 546 failed_constraint_name); | 547 failed_constraint_name); |
| 547 return; | 548 return; |
| 548 } | 549 } |
| 549 current_request_info_->stream_controls()->video.device_id = | 550 current_request_info_->stream_controls()->video.device_id = |
| 550 settings.device_id(); | 551 settings.device_id(); |
| 551 current_request_info_->SetVideoCaptureSettings(settings, | 552 current_request_info_->SetVideoCaptureSettings(settings, |
| 552 true /* is_content_capture */); | 553 true /* is_content_capture */); |
| 553 GenerateStreamForCurrentRequestInfo(); | 554 GenerateStreamForCurrentRequestInfo(); |
| 554 } | 555 } |
| 555 | 556 |
| 556 void UserMediaClientImpl::GenerateStreamForCurrentRequestInfo() { | 557 void UserMediaClientImpl::GenerateStreamForCurrentRequestInfo() { |
| 557 DCHECK(CalledOnValidThread()); | 558 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 558 DCHECK(current_request_info_); | 559 DCHECK(current_request_info_); |
| 559 | 560 |
| 560 WebRtcLogMessage(base::StringPrintf( | 561 WebRtcLogMessage(base::StringPrintf( |
| 561 "MSI::requestUserMedia. request_id=%d" | 562 "MSI::requestUserMedia. request_id=%d" |
| 562 ", audio source id=%s" | 563 ", audio source id=%s" |
| 563 ", video source id=%s", | 564 ", video source id=%s", |
| 564 current_request_info_->request_id(), | 565 current_request_info_->request_id(), |
| 565 current_request_info_->stream_controls()->audio.device_id.c_str(), | 566 current_request_info_->stream_controls()->audio.device_id.c_str(), |
| 566 current_request_info_->stream_controls()->video.device_id.c_str())); | 567 current_request_info_->stream_controls()->video.device_id.c_str())); |
| 567 | 568 |
| 568 current_request_info_->set_state( | 569 current_request_info_->set_state( |
| 569 UserMediaRequestInfo::State::SENT_FOR_GENERATION); | 570 UserMediaRequestInfo::State::SENT_FOR_GENERATION); |
| 570 media_stream_dispatcher_->GenerateStream( | 571 media_stream_dispatcher_->GenerateStream( |
| 571 current_request_info_->request_id(), weak_factory_.GetWeakPtr(), | 572 current_request_info_->request_id(), weak_factory_.GetWeakPtr(), |
| 572 *current_request_info_->stream_controls(), | 573 *current_request_info_->stream_controls(), |
| 573 current_request_info_->security_origin(), | 574 current_request_info_->security_origin(), |
| 574 current_request_info_->is_processing_user_gesture()); | 575 current_request_info_->is_processing_user_gesture()); |
| 575 } | 576 } |
| 576 | 577 |
| 577 void UserMediaClientImpl::CancelUserMediaRequest( | 578 void UserMediaClientImpl::CancelUserMediaRequest( |
| 578 const blink::WebUserMediaRequest& user_media_request) { | 579 const blink::WebUserMediaRequest& user_media_request) { |
| 579 DCHECK(CalledOnValidThread()); | 580 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 580 if (DeleteRequestInfo(user_media_request)) { | 581 if (DeleteRequestInfo(user_media_request)) { |
| 581 // We can't abort the stream generation process. | 582 // We can't abort the stream generation process. |
| 582 // Instead, erase the request. Once the stream is generated we will stop the | 583 // Instead, erase the request. Once the stream is generated we will stop the |
| 583 // stream if the request does not exist. | 584 // stream if the request does not exist. |
| 584 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED); | 585 LogUserMediaRequestWithNoResult(MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED); |
| 585 } | 586 } |
| 586 } | 587 } |
| 587 | 588 |
| 588 void UserMediaClientImpl::RequestMediaDevices( | 589 void UserMediaClientImpl::RequestMediaDevices( |
| 589 const blink::WebMediaDevicesRequest& media_devices_request) { | 590 const blink::WebMediaDevicesRequest& media_devices_request) { |
| 590 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); | 591 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); |
| 591 DCHECK(CalledOnValidThread()); | 592 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 592 GetMediaDevicesDispatcher()->EnumerateDevices( | 593 GetMediaDevicesDispatcher()->EnumerateDevices( |
| 593 true /* audio input */, true /* video input */, true /* audio output */, | 594 true /* audio input */, true /* video input */, true /* audio output */, |
| 594 base::Bind(&UserMediaClientImpl::FinalizeEnumerateDevices, | 595 base::Bind(&UserMediaClientImpl::FinalizeEnumerateDevices, |
| 595 weak_factory_.GetWeakPtr(), media_devices_request)); | 596 weak_factory_.GetWeakPtr(), media_devices_request)); |
| 596 } | 597 } |
| 597 | 598 |
| 598 void UserMediaClientImpl::SetMediaDeviceChangeObserver( | 599 void UserMediaClientImpl::SetMediaDeviceChangeObserver( |
| 599 const blink::WebMediaDeviceChangeObserver& observer) { | 600 const blink::WebMediaDeviceChangeObserver& observer) { |
| 600 media_device_change_observer_ = observer; | 601 media_device_change_observer_ = observer; |
| 601 | 602 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 619 } | 620 } |
| 620 } | 621 } |
| 621 | 622 |
| 622 // Callback from MediaStreamDispatcher. | 623 // Callback from MediaStreamDispatcher. |
| 623 // The requested stream have been generated by the MediaStreamDispatcher. | 624 // The requested stream have been generated by the MediaStreamDispatcher. |
| 624 void UserMediaClientImpl::OnStreamGenerated( | 625 void UserMediaClientImpl::OnStreamGenerated( |
| 625 int request_id, | 626 int request_id, |
| 626 const std::string& label, | 627 const std::string& label, |
| 627 const StreamDeviceInfoArray& audio_array, | 628 const StreamDeviceInfoArray& audio_array, |
| 628 const StreamDeviceInfoArray& video_array) { | 629 const StreamDeviceInfoArray& video_array) { |
| 629 DCHECK(CalledOnValidThread()); | 630 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 630 if (!IsCurrentRequestInfo(request_id)) { | 631 if (!IsCurrentRequestInfo(request_id)) { |
| 631 // This can happen if the request is cancelled or the frame reloads while | 632 // This can happen if the request is cancelled or the frame reloads while |
| 632 // MediaStreamDispatcher is processing the request. | 633 // MediaStreamDispatcher is processing the request. |
| 633 DVLOG(1) << "Request ID not found"; | 634 DVLOG(1) << "Request ID not found"; |
| 634 OnStreamGeneratedForCancelledRequest(audio_array, video_array); | 635 OnStreamGeneratedForCancelledRequest(audio_array, video_array); |
| 635 return; | 636 return; |
| 636 } | 637 } |
| 637 current_request_info_->set_state(UserMediaRequestInfo::State::GENERATED); | 638 current_request_info_->set_state(UserMediaRequestInfo::State::GENERATED); |
| 638 | 639 |
| 639 for (const auto* array : {&audio_array, &video_array}) { | 640 for (const auto* array : {&audio_array, &video_array}) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 const blink::WebString& result_name) { | 693 const blink::WebString& result_name) { |
| 693 task_runner->PostTask(FROM_HERE, | 694 task_runner->PostTask(FROM_HERE, |
| 694 base::Bind(&UserMediaClientImpl::OnAudioSourceStarted, | 695 base::Bind(&UserMediaClientImpl::OnAudioSourceStarted, |
| 695 weak_ptr, source, result, result_name)); | 696 weak_ptr, source, result, result_name)); |
| 696 } | 697 } |
| 697 | 698 |
| 698 void UserMediaClientImpl::OnAudioSourceStarted( | 699 void UserMediaClientImpl::OnAudioSourceStarted( |
| 699 MediaStreamSource* source, | 700 MediaStreamSource* source, |
| 700 MediaStreamRequestResult result, | 701 MediaStreamRequestResult result, |
| 701 const blink::WebString& result_name) { | 702 const blink::WebString& result_name) { |
| 702 DCHECK(CalledOnValidThread()); | 703 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 703 | 704 |
| 704 for (auto it = pending_local_sources_.begin(); | 705 for (auto it = pending_local_sources_.begin(); |
| 705 it != pending_local_sources_.end(); ++it) { | 706 it != pending_local_sources_.end(); ++it) { |
| 706 MediaStreamSource* const source_extra_data = | 707 MediaStreamSource* const source_extra_data = |
| 707 static_cast<MediaStreamSource*>((*it).GetExtraData()); | 708 static_cast<MediaStreamSource*>((*it).GetExtraData()); |
| 708 if (source_extra_data != source) | 709 if (source_extra_data != source) |
| 709 continue; | 710 continue; |
| 710 if (result == MEDIA_DEVICE_OK) | 711 if (result == MEDIA_DEVICE_OK) |
| 711 local_sources_.push_back((*it)); | 712 local_sources_.push_back((*it)); |
| 712 pending_local_sources_.erase(it); | 713 pending_local_sources_.erase(it); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 } | 749 } |
| 749 | 750 |
| 750 EnumerateDevicesSucceded(&request, devices); | 751 EnumerateDevicesSucceded(&request, devices); |
| 751 } | 752 } |
| 752 | 753 |
| 753 // Callback from MediaStreamDispatcher. | 754 // Callback from MediaStreamDispatcher. |
| 754 // The requested stream failed to be generated. | 755 // The requested stream failed to be generated. |
| 755 void UserMediaClientImpl::OnStreamGenerationFailed( | 756 void UserMediaClientImpl::OnStreamGenerationFailed( |
| 756 int request_id, | 757 int request_id, |
| 757 MediaStreamRequestResult result) { | 758 MediaStreamRequestResult result) { |
| 758 DCHECK(CalledOnValidThread()); | 759 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 759 if (!IsCurrentRequestInfo(request_id)) { | 760 if (!IsCurrentRequestInfo(request_id)) { |
| 760 // This can happen if the request is cancelled or the frame reloads while | 761 // This can happen if the request is cancelled or the frame reloads while |
| 761 // MediaStreamDispatcher is processing the request. | 762 // MediaStreamDispatcher is processing the request. |
| 762 return; | 763 return; |
| 763 } | 764 } |
| 764 | 765 |
| 765 GetUserMediaRequestFailed(current_request_info_->request(), result, ""); | 766 GetUserMediaRequestFailed(current_request_info_->request(), result, ""); |
| 766 DeleteRequestInfo(current_request_info_->request()); | 767 DeleteRequestInfo(current_request_info_->request()); |
| 767 } | 768 } |
| 768 | 769 |
| 769 // Callback from MediaStreamDispatcher. | 770 // Callback from MediaStreamDispatcher. |
| 770 // The browser process has stopped a device used by a MediaStream. | 771 // The browser process has stopped a device used by a MediaStream. |
| 771 void UserMediaClientImpl::OnDeviceStopped( | 772 void UserMediaClientImpl::OnDeviceStopped( |
| 772 const std::string& label, | 773 const std::string& label, |
| 773 const StreamDeviceInfo& device_info) { | 774 const StreamDeviceInfo& device_info) { |
| 774 DCHECK(CalledOnValidThread()); | 775 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 775 DVLOG(1) << "UserMediaClientImpl::OnDeviceStopped(" | 776 DVLOG(1) << "UserMediaClientImpl::OnDeviceStopped(" |
| 776 << "{device_id = " << device_info.device.id << "})"; | 777 << "{device_id = " << device_info.device.id << "})"; |
| 777 | 778 |
| 778 const blink::WebMediaStreamSource* source_ptr = FindLocalSource(device_info); | 779 const blink::WebMediaStreamSource* source_ptr = FindLocalSource(device_info); |
| 779 if (!source_ptr) { | 780 if (!source_ptr) { |
| 780 // This happens if the same device is used in several guM requests or | 781 // This happens if the same device is used in several guM requests or |
| 781 // if a user happen stop a track from JS at the same time | 782 // if a user happen stop a track from JS at the same time |
| 782 // as the underlying media device is unplugged from the system. | 783 // as the underlying media device is unplugged from the system. |
| 783 return; | 784 return; |
| 784 } | 785 } |
| 785 // By creating |source| it is guaranteed that the blink::WebMediaStreamSource | 786 // By creating |source| it is guaranteed that the blink::WebMediaStreamSource |
| 786 // object is valid during the cleanup. | 787 // object is valid during the cleanup. |
| 787 blink::WebMediaStreamSource source(*source_ptr); | 788 blink::WebMediaStreamSource source(*source_ptr); |
| 788 StopLocalSource(source, false); | 789 StopLocalSource(source, false); |
| 789 RemoveLocalSource(source); | 790 RemoveLocalSource(source); |
| 790 } | 791 } |
| 791 | 792 |
| 792 blink::WebMediaStreamSource UserMediaClientImpl::InitializeVideoSourceObject( | 793 blink::WebMediaStreamSource UserMediaClientImpl::InitializeVideoSourceObject( |
| 793 const StreamDeviceInfo& device) { | 794 const StreamDeviceInfo& device) { |
| 794 DCHECK(CalledOnValidThread()); | 795 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 795 DCHECK(current_request_info_); | 796 DCHECK(current_request_info_); |
| 796 | 797 |
| 797 blink::WebMediaStreamSource source = FindOrInitializeSourceObject(device); | 798 blink::WebMediaStreamSource source = FindOrInitializeSourceObject(device); |
| 798 if (!source.GetExtraData()) { | 799 if (!source.GetExtraData()) { |
| 799 source.SetExtraData(CreateVideoSource( | 800 source.SetExtraData(CreateVideoSource( |
| 800 device, base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, | 801 device, base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, |
| 801 weak_factory_.GetWeakPtr()))); | 802 weak_factory_.GetWeakPtr()))); |
| 802 local_sources_.push_back(source); | 803 local_sources_.push_back(source); |
| 803 } | 804 } |
| 804 return source; | 805 return source; |
| 805 } | 806 } |
| 806 | 807 |
| 807 blink::WebMediaStreamSource UserMediaClientImpl::InitializeAudioSourceObject( | 808 blink::WebMediaStreamSource UserMediaClientImpl::InitializeAudioSourceObject( |
| 808 const StreamDeviceInfo& device, | 809 const StreamDeviceInfo& device, |
| 809 const blink::WebMediaConstraints& constraints, | 810 const blink::WebMediaConstraints& constraints, |
| 810 bool* is_pending) { | 811 bool* is_pending) { |
| 811 DCHECK(CalledOnValidThread()); | 812 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 812 | 813 |
| 813 *is_pending = true; | 814 *is_pending = true; |
| 814 | 815 |
| 815 // See if the source is already being initialized. | 816 // See if the source is already being initialized. |
| 816 auto* pending = FindPendingLocalSource(device); | 817 auto* pending = FindPendingLocalSource(device); |
| 817 if (pending) | 818 if (pending) |
| 818 return *pending; | 819 return *pending; |
| 819 | 820 |
| 820 blink::WebMediaStreamSource source = FindOrInitializeSourceObject(device); | 821 blink::WebMediaStreamSource source = FindOrInitializeSourceObject(device); |
| 821 if (source.GetExtraData()) { | 822 if (source.GetExtraData()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 838 audio_source->SetStopCallback(base::Bind( | 839 audio_source->SetStopCallback(base::Bind( |
| 839 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); | 840 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); |
| 840 source.SetExtraData(audio_source); // Takes ownership. | 841 source.SetExtraData(audio_source); // Takes ownership. |
| 841 return source; | 842 return source; |
| 842 } | 843 } |
| 843 | 844 |
| 844 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( | 845 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( |
| 845 const StreamDeviceInfo& device, | 846 const StreamDeviceInfo& device, |
| 846 const blink::WebMediaConstraints& constraints, | 847 const blink::WebMediaConstraints& constraints, |
| 847 const MediaStreamSource::ConstraintsCallback& source_ready) { | 848 const MediaStreamSource::ConstraintsCallback& source_ready) { |
| 848 DCHECK(CalledOnValidThread()); | 849 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 849 // If the audio device is a loopback device (for screen capture), or if the | 850 // If the audio device is a loopback device (for screen capture), or if the |
| 850 // constraints/effects parameters indicate no audio processing is needed, | 851 // constraints/effects parameters indicate no audio processing is needed, |
| 851 // create an efficient, direct-path MediaStreamAudioSource instance. | 852 // create an efficient, direct-path MediaStreamAudioSource instance. |
| 852 if (IsScreenCaptureMediaType(device.device.type) || | 853 if (IsScreenCaptureMediaType(device.device.type) || |
| 853 !MediaStreamAudioProcessor::WouldModifyAudio( | 854 !MediaStreamAudioProcessor::WouldModifyAudio( |
| 854 constraints, device.device.input.effects)) { | 855 constraints, device.device.input.effects)) { |
| 855 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), | 856 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), |
| 856 device, source_ready); | 857 device, source_ready); |
| 857 } | 858 } |
| 858 | 859 |
| 859 // The audio device is not associated with screen capture and also requires | 860 // The audio device is not associated with screen capture and also requires |
| 860 // processing. | 861 // processing. |
| 861 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( | 862 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( |
| 862 RenderFrameObserver::routing_id(), device, constraints, source_ready, | 863 RenderFrameObserver::routing_id(), device, constraints, source_ready, |
| 863 dependency_factory_); | 864 dependency_factory_); |
| 864 return source; | 865 return source; |
| 865 } | 866 } |
| 866 | 867 |
| 867 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( | 868 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( |
| 868 const StreamDeviceInfo& device, | 869 const StreamDeviceInfo& device, |
| 869 const MediaStreamSource::SourceStoppedCallback& stop_callback) { | 870 const MediaStreamSource::SourceStoppedCallback& stop_callback) { |
| 870 DCHECK(CalledOnValidThread()); | 871 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 871 DCHECK(current_request_info_); | 872 DCHECK(current_request_info_); |
| 872 if (IsOldVideoConstraints()) { | 873 if (IsOldVideoConstraints()) { |
| 873 return new MediaStreamVideoCapturerSource(stop_callback, device, | 874 return new MediaStreamVideoCapturerSource(stop_callback, device, |
| 874 render_frame()); | 875 render_frame()); |
| 875 } | 876 } |
| 876 | 877 |
| 877 DCHECK(current_request_info_->video_capture_settings().HasValue()); | 878 DCHECK(current_request_info_->video_capture_settings().HasValue()); |
| 878 return new MediaStreamVideoCapturerSource( | 879 return new MediaStreamVideoCapturerSource( |
| 879 stop_callback, device, | 880 stop_callback, device, |
| 880 current_request_info_->video_capture_settings().capture_params(), | 881 current_request_info_->video_capture_settings().capture_params(), |
| 881 render_frame()); | 882 render_frame()); |
| 882 } | 883 } |
| 883 | 884 |
| 884 void UserMediaClientImpl::CreateVideoTracks( | 885 void UserMediaClientImpl::CreateVideoTracks( |
| 885 const StreamDeviceInfoArray& devices, | 886 const StreamDeviceInfoArray& devices, |
| 886 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks) { | 887 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks) { |
| 887 DCHECK(CalledOnValidThread()); | 888 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 888 DCHECK(current_request_info_); | 889 DCHECK(current_request_info_); |
| 889 DCHECK_EQ(devices.size(), webkit_tracks->size()); | 890 DCHECK_EQ(devices.size(), webkit_tracks->size()); |
| 890 | 891 |
| 891 for (size_t i = 0; i < devices.size(); ++i) { | 892 for (size_t i = 0; i < devices.size(); ++i) { |
| 892 blink::WebMediaStreamSource source = | 893 blink::WebMediaStreamSource source = |
| 893 InitializeVideoSourceObject(devices[i]); | 894 InitializeVideoSourceObject(devices[i]); |
| 894 (*webkit_tracks)[i] = | 895 (*webkit_tracks)[i] = |
| 895 current_request_info_->CreateAndStartVideoTrack(source); | 896 current_request_info_->CreateAndStartVideoTrack(source); |
| 896 } | 897 } |
| 897 } | 898 } |
| 898 | 899 |
| 899 void UserMediaClientImpl::CreateAudioTracks( | 900 void UserMediaClientImpl::CreateAudioTracks( |
| 900 const StreamDeviceInfoArray& devices, | 901 const StreamDeviceInfoArray& devices, |
| 901 const blink::WebMediaConstraints& constraints, | 902 const blink::WebMediaConstraints& constraints, |
| 902 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks) { | 903 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks) { |
| 903 DCHECK(CalledOnValidThread()); | 904 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 904 DCHECK(current_request_info_); | 905 DCHECK(current_request_info_); |
| 905 DCHECK_EQ(devices.size(), webkit_tracks->size()); | 906 DCHECK_EQ(devices.size(), webkit_tracks->size()); |
| 906 | 907 |
| 907 StreamDeviceInfoArray overridden_audio_array = devices; | 908 StreamDeviceInfoArray overridden_audio_array = devices; |
| 908 if (!current_request_info_->enable_automatic_output_device_selection()) { | 909 if (!current_request_info_->enable_automatic_output_device_selection()) { |
| 909 // If the GetUserMedia request did not explicitly set the constraint | 910 // If the GetUserMedia request did not explicitly set the constraint |
| 910 // kMediaStreamRenderToAssociatedSink, the output device parameters must | 911 // kMediaStreamRenderToAssociatedSink, the output device parameters must |
| 911 // be removed. | 912 // be removed. |
| 912 for (auto& device_info : overridden_audio_array) { | 913 for (auto& device_info : overridden_audio_array) { |
| 913 device_info.device.matched_output_device_id = ""; | 914 device_info.device.matched_output_device_id = ""; |
| 914 device_info.device.matched_output = | 915 device_info.device.matched_output = |
| 915 MediaStreamDevice::AudioDeviceParameters(); | 916 MediaStreamDevice::AudioDeviceParameters(); |
| 916 } | 917 } |
| 917 } | 918 } |
| 918 | 919 |
| 919 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { | 920 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { |
| 920 bool is_pending = false; | 921 bool is_pending = false; |
| 921 blink::WebMediaStreamSource source = InitializeAudioSourceObject( | 922 blink::WebMediaStreamSource source = InitializeAudioSourceObject( |
| 922 overridden_audio_array[i], constraints, &is_pending); | 923 overridden_audio_array[i], constraints, &is_pending); |
| 923 (*webkit_tracks)[i].Initialize(source); | 924 (*webkit_tracks)[i].Initialize(source); |
| 924 current_request_info_->StartAudioTrack((*webkit_tracks)[i], is_pending); | 925 current_request_info_->StartAudioTrack((*webkit_tracks)[i], is_pending); |
| 925 } | 926 } |
| 926 } | 927 } |
| 927 | 928 |
| 928 void UserMediaClientImpl::OnCreateNativeTracksCompleted( | 929 void UserMediaClientImpl::OnCreateNativeTracksCompleted( |
| 929 const std::string& label, | 930 const std::string& label, |
| 930 UserMediaRequestInfo* request_info, | 931 UserMediaRequestInfo* request_info, |
| 931 MediaStreamRequestResult result, | 932 MediaStreamRequestResult result, |
| 932 const blink::WebString& result_name) { | 933 const blink::WebString& result_name) { |
| 933 DCHECK(CalledOnValidThread()); | 934 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 934 if (result == content::MEDIA_DEVICE_OK) { | 935 if (result == content::MEDIA_DEVICE_OK) { |
| 935 GetUserMediaRequestSucceeded(*request_info->web_stream(), | 936 GetUserMediaRequestSucceeded(*request_info->web_stream(), |
| 936 request_info->request()); | 937 request_info->request()); |
| 937 media_stream_dispatcher_->OnStreamStarted(label); | 938 media_stream_dispatcher_->OnStreamStarted(label); |
| 938 } else { | 939 } else { |
| 939 GetUserMediaRequestFailed(request_info->request(), result, result_name); | 940 GetUserMediaRequestFailed(request_info->request(), result, result_name); |
| 940 | 941 |
| 941 blink::WebVector<blink::WebMediaStreamTrack> tracks; | 942 blink::WebVector<blink::WebMediaStreamTrack> tracks; |
| 942 request_info->web_stream()->AudioTracks(tracks); | 943 request_info->web_stream()->AudioTracks(tracks); |
| 943 for (auto& web_track : tracks) { | 944 for (auto& web_track : tracks) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 false /* remote */); | 1109 false /* remote */); |
| 1109 | 1110 |
| 1110 DVLOG(1) << "Initialize source object :" | 1111 DVLOG(1) << "Initialize source object :" |
| 1111 << "id = " << source.Id().Utf8() | 1112 << "id = " << source.Id().Utf8() |
| 1112 << ", name = " << source.GetName().Utf8(); | 1113 << ", name = " << source.GetName().Utf8(); |
| 1113 return source; | 1114 return source; |
| 1114 } | 1115 } |
| 1115 | 1116 |
| 1116 bool UserMediaClientImpl::RemoveLocalSource( | 1117 bool UserMediaClientImpl::RemoveLocalSource( |
| 1117 const blink::WebMediaStreamSource& source) { | 1118 const blink::WebMediaStreamSource& source) { |
| 1118 DCHECK(CalledOnValidThread()); | 1119 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1119 | 1120 |
| 1120 for (LocalStreamSources::iterator device_it = local_sources_.begin(); | 1121 for (LocalStreamSources::iterator device_it = local_sources_.begin(); |
| 1121 device_it != local_sources_.end(); ++device_it) { | 1122 device_it != local_sources_.end(); ++device_it) { |
| 1122 if (IsSameSource(*device_it, source)) { | 1123 if (IsSameSource(*device_it, source)) { |
| 1123 local_sources_.erase(device_it); | 1124 local_sources_.erase(device_it); |
| 1124 return true; | 1125 return true; |
| 1125 } | 1126 } |
| 1126 } | 1127 } |
| 1127 | 1128 |
| 1128 // Check if the source was pending. | 1129 // Check if the source was pending. |
| 1129 for (LocalStreamSources::iterator device_it = pending_local_sources_.begin(); | 1130 for (LocalStreamSources::iterator device_it = pending_local_sources_.begin(); |
| 1130 device_it != pending_local_sources_.end(); ++device_it) { | 1131 device_it != pending_local_sources_.end(); ++device_it) { |
| 1131 if (IsSameSource(*device_it, source)) { | 1132 if (IsSameSource(*device_it, source)) { |
| 1132 MediaStreamSource* const source_extra_data = | 1133 MediaStreamSource* const source_extra_data = |
| 1133 static_cast<MediaStreamSource*>(source.GetExtraData()); | 1134 static_cast<MediaStreamSource*>(source.GetExtraData()); |
| 1134 NotifyCurrentRequestInfoOfAudioSourceStarted( | 1135 NotifyCurrentRequestInfoOfAudioSourceStarted( |
| 1135 source_extra_data, MEDIA_DEVICE_TRACK_START_FAILURE, | 1136 source_extra_data, MEDIA_DEVICE_TRACK_START_FAILURE, |
| 1136 "Failed to access audio capture device"); | 1137 "Failed to access audio capture device"); |
| 1137 pending_local_sources_.erase(device_it); | 1138 pending_local_sources_.erase(device_it); |
| 1138 return true; | 1139 return true; |
| 1139 } | 1140 } |
| 1140 } | 1141 } |
| 1141 | 1142 |
| 1142 return false; | 1143 return false; |
| 1143 } | 1144 } |
| 1144 | 1145 |
| 1145 bool UserMediaClientImpl::IsCurrentRequestInfo(int request_id) const { | 1146 bool UserMediaClientImpl::IsCurrentRequestInfo(int request_id) const { |
| 1146 DCHECK(CalledOnValidThread()); | 1147 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1147 return current_request_info_ && | 1148 return current_request_info_ && |
| 1148 current_request_info_->request_id() == request_id; | 1149 current_request_info_->request_id() == request_id; |
| 1149 } | 1150 } |
| 1150 | 1151 |
| 1151 bool UserMediaClientImpl::IsCurrentRequestInfo( | 1152 bool UserMediaClientImpl::IsCurrentRequestInfo( |
| 1152 const blink::WebUserMediaRequest& request) const { | 1153 const blink::WebUserMediaRequest& request) const { |
| 1153 DCHECK(CalledOnValidThread()); | 1154 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1154 return current_request_info_ && current_request_info_->request() == request; | 1155 return current_request_info_ && current_request_info_->request() == request; |
| 1155 } | 1156 } |
| 1156 | 1157 |
| 1157 bool UserMediaClientImpl::DeleteRequestInfo( | 1158 bool UserMediaClientImpl::DeleteRequestInfo( |
| 1158 const blink::WebUserMediaRequest& user_media_request) { | 1159 const blink::WebUserMediaRequest& user_media_request) { |
| 1159 DCHECK(CalledOnValidThread()); | 1160 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1160 if (current_request_info_ && | 1161 if (current_request_info_ && |
| 1161 current_request_info_->request() == user_media_request) { | 1162 current_request_info_->request() == user_media_request) { |
| 1162 current_request_info_.reset(); | 1163 current_request_info_.reset(); |
| 1163 if (!pending_request_infos_.empty()) { | 1164 if (!pending_request_infos_.empty()) { |
| 1164 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1165 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1165 FROM_HERE, | 1166 FROM_HERE, |
| 1166 base::Bind(&UserMediaClientImpl::MaybeProcessNextRequestInfo, | 1167 base::Bind(&UserMediaClientImpl::MaybeProcessNextRequestInfo, |
| 1167 weak_factory_.GetWeakPtr())); | 1168 weak_factory_.GetWeakPtr())); |
| 1168 } | 1169 } |
| 1169 return true; | 1170 return true; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 } | 1218 } |
| 1218 } | 1219 } |
| 1219 | 1220 |
| 1220 void UserMediaClientImpl::SetMediaDevicesDispatcherForTesting( | 1221 void UserMediaClientImpl::SetMediaDevicesDispatcherForTesting( |
| 1221 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher) { | 1222 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher) { |
| 1222 media_devices_dispatcher_ = std::move(media_devices_dispatcher); | 1223 media_devices_dispatcher_ = std::move(media_devices_dispatcher); |
| 1223 } | 1224 } |
| 1224 | 1225 |
| 1225 void UserMediaClientImpl::OnLocalSourceStopped( | 1226 void UserMediaClientImpl::OnLocalSourceStopped( |
| 1226 const blink::WebMediaStreamSource& source) { | 1227 const blink::WebMediaStreamSource& source) { |
| 1227 DCHECK(CalledOnValidThread()); | 1228 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1228 DVLOG(1) << "UserMediaClientImpl::OnLocalSourceStopped"; | 1229 DVLOG(1) << "UserMediaClientImpl::OnLocalSourceStopped"; |
| 1229 | 1230 |
| 1230 const bool some_source_removed = RemoveLocalSource(source); | 1231 const bool some_source_removed = RemoveLocalSource(source); |
| 1231 CHECK(some_source_removed); | 1232 CHECK(some_source_removed); |
| 1232 | 1233 |
| 1233 MediaStreamSource* source_impl = | 1234 MediaStreamSource* source_impl = |
| 1234 static_cast<MediaStreamSource*>(source.GetExtraData()); | 1235 static_cast<MediaStreamSource*>(source.GetExtraData()); |
| 1235 media_stream_dispatcher_->StopStreamDevice(source_impl->device_info()); | 1236 media_stream_dispatcher_->StopStreamDevice(source_impl->device_info()); |
| 1236 } | 1237 } |
| 1237 | 1238 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 const blink::WebString& result_name) { | 1379 const blink::WebString& result_name) { |
| 1379 // Check if we're waiting to be notified of this source. If not, then we'll | 1380 // Check if we're waiting to be notified of this source. If not, then we'll |
| 1380 // ignore the notification. | 1381 // ignore the notification. |
| 1381 auto found = std::find(sources_waiting_for_callback_.begin(), | 1382 auto found = std::find(sources_waiting_for_callback_.begin(), |
| 1382 sources_waiting_for_callback_.end(), source); | 1383 sources_waiting_for_callback_.end(), source); |
| 1383 if (found != sources_waiting_for_callback_.end()) | 1384 if (found != sources_waiting_for_callback_.end()) |
| 1384 OnTrackStarted(source, result, result_name); | 1385 OnTrackStarted(source, result, result_name); |
| 1385 } | 1386 } |
| 1386 | 1387 |
| 1387 } // namespace content | 1388 } // namespace content |
| OLD | NEW |