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/media_stream_impl.h" | 5 #include "content/renderer/media/media_stream_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 base::Bind(&MediaStreamImpl::OnLocalMediaStreamStop, AsWeakPtr()), | 345 base::Bind(&MediaStreamImpl::OnLocalMediaStreamStop, AsWeakPtr()), |
346 *web_stream)); | 346 *web_stream)); |
347 | 347 |
348 // Wait for the tracks to be started successfully or to fail. | 348 // Wait for the tracks to be started successfully or to fail. |
349 request_info->CallbackOnTracksStarted( | 349 request_info->CallbackOnTracksStarted( |
350 base::Bind(&MediaStreamImpl::OnCreateNativeTracksCompleted, AsWeakPtr())); | 350 base::Bind(&MediaStreamImpl::OnCreateNativeTracksCompleted, AsWeakPtr())); |
351 } | 351 } |
352 | 352 |
353 // Callback from MediaStreamDispatcher. | 353 // Callback from MediaStreamDispatcher. |
354 // The requested stream failed to be generated. | 354 // The requested stream failed to be generated. |
355 void MediaStreamImpl::OnStreamGenerationFailed(int request_id) { | 355 void MediaStreamImpl::OnStreamGenerationFailed( |
| 356 int request_id, |
| 357 content::MediaStreamRequestResult result) { |
356 DCHECK(CalledOnValidThread()); | 358 DCHECK(CalledOnValidThread()); |
357 DVLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed(" | 359 DVLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed(" |
358 << request_id << ")"; | 360 << request_id << ")"; |
359 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); | 361 UserMediaRequestInfo* request_info = FindUserMediaRequestInfo(request_id); |
360 if (!request_info) { | 362 if (!request_info) { |
361 // This can happen if the request is canceled or the frame reloads while | 363 // This can happen if the request is canceled or the frame reloads while |
362 // MediaStreamDispatcher is processing the request. | 364 // MediaStreamDispatcher is processing the request. |
363 DVLOG(1) << "Request ID not found"; | 365 DVLOG(1) << "Request ID not found"; |
364 return; | 366 return; |
365 } | 367 } |
366 CompleteGetUserMediaRequest(request_info->web_stream, | 368 CompleteGetUserMediaRequest(request_info->web_stream, |
367 &request_info->request, | 369 &request_info->request, |
368 false); | 370 result); |
369 DeleteUserMediaRequestInfo(request_info); | 371 DeleteUserMediaRequestInfo(request_info); |
370 } | 372 } |
371 | 373 |
372 // Callback from MediaStreamDispatcher. | 374 // Callback from MediaStreamDispatcher. |
373 // The browser process has stopped a device used by a MediaStream. | 375 // The browser process has stopped a device used by a MediaStream. |
374 void MediaStreamImpl::OnDeviceStopped( | 376 void MediaStreamImpl::OnDeviceStopped( |
375 const std::string& label, | 377 const std::string& label, |
376 const StreamDeviceInfo& device_info) { | 378 const StreamDeviceInfo& device_info) { |
377 DCHECK(CalledOnValidThread()); | 379 DCHECK(CalledOnValidThread()); |
378 DVLOG(1) << "MediaStreamImpl::OnDeviceStopped(" | 380 DVLOG(1) << "MediaStreamImpl::OnDeviceStopped(" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 constraints, | 523 constraints, |
522 request->frame, | 524 request->frame, |
523 &webkit_source); | 525 &webkit_source); |
524 (*webkit_tracks)[i].initialize(webkit_source); | 526 (*webkit_tracks)[i].initialize(webkit_source); |
525 request->StartTrack((*webkit_tracks)[i], constraints); | 527 request->StartTrack((*webkit_tracks)[i], constraints); |
526 } | 528 } |
527 } | 529 } |
528 | 530 |
529 void MediaStreamImpl::OnCreateNativeTracksCompleted( | 531 void MediaStreamImpl::OnCreateNativeTracksCompleted( |
530 UserMediaRequestInfo* request, | 532 UserMediaRequestInfo* request, |
531 bool request_succeeded) { | 533 content::MediaStreamRequestResult result) { |
532 DVLOG(1) << "MediaStreamImpl::OnCreateNativeTracksComplete(" | 534 DVLOG(1) << "MediaStreamImpl::OnCreateNativeTracksComplete(" |
533 << "{request_id = " << request->request_id << "} " | 535 << "{request_id = " << request->request_id << "} " |
534 << "{request_succeeded = " << request_succeeded << "})"; | 536 << "{result = " << result << "})"; |
535 CompleteGetUserMediaRequest(request->web_stream, &request->request, | 537 CompleteGetUserMediaRequest(request->web_stream, &request->request, |
536 request_succeeded); | 538 result); |
537 if (!request_succeeded) { | 539 if (result != MEDIA_DEVICE_OK) { |
538 // TODO(perkj): Once we don't support MediaStream::Stop the |request_info| | 540 // TODO(perkj): Once we don't support MediaStream::Stop the |request_info| |
539 // can be deleted even if the request succeeds. | 541 // can be deleted even if the request succeeds. |
540 DeleteUserMediaRequestInfo(request); | 542 DeleteUserMediaRequestInfo(request); |
541 StopUnreferencedSources(true); | 543 StopUnreferencedSources(true); |
542 } | 544 } |
543 } | 545 } |
544 | 546 |
545 void MediaStreamImpl::OnDevicesEnumerated( | 547 void MediaStreamImpl::OnDevicesEnumerated( |
546 int request_id, | 548 int request_id, |
547 const StreamDeviceInfoArray& device_array) { | 549 const StreamDeviceInfoArray& device_array) { |
(...skipping 13 matching lines...) Expand all Loading... |
561 | 563 |
562 void MediaStreamImpl::OnDeviceOpenFailed(int request_id) { | 564 void MediaStreamImpl::OnDeviceOpenFailed(int request_id) { |
563 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed(" | 565 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed(" |
564 << request_id << ")"; | 566 << request_id << ")"; |
565 NOTIMPLEMENTED(); | 567 NOTIMPLEMENTED(); |
566 } | 568 } |
567 | 569 |
568 void MediaStreamImpl::CompleteGetUserMediaRequest( | 570 void MediaStreamImpl::CompleteGetUserMediaRequest( |
569 const blink::WebMediaStream& stream, | 571 const blink::WebMediaStream& stream, |
570 blink::WebUserMediaRequest* request_info, | 572 blink::WebUserMediaRequest* request_info, |
571 bool request_succeeded) { | 573 content::MediaStreamRequestResult result) { |
572 if (request_succeeded) { | 574 |
573 request_info->requestSucceeded(stream); | 575 DVLOG(1) << "MediaStreamImpl::CompleteGetUserMediaRequest(" |
574 } else { | 576 << "result=" << result; |
575 request_info->requestFailed(); | 577 |
| 578 switch (result) { |
| 579 case MEDIA_DEVICE_OK: |
| 580 request_info->requestSucceeded(stream); |
| 581 break; |
| 582 case MEDIA_DEVICE_PERMISSION_DENIED: |
| 583 request_info->requestDenied(); |
| 584 break; |
| 585 case MEDIA_DEVICE_PERMISSION_DISMISSED: |
| 586 request_info->requestFailedUASpecific("PermissionDismissedError"); |
| 587 break; |
| 588 case MEDIA_DEVICE_INVALID_STATE: |
| 589 request_info->requestFailedUASpecific("InvalidStateError"); |
| 590 break; |
| 591 case MEDIA_DEVICE_NO_HARDWARE: |
| 592 request_info->requestFailedUASpecific("DevicesNotFoundError"); |
| 593 break; |
| 594 case MEDIA_DEVICE_INVALID_SECURITY_ORIGIN: |
| 595 request_info->requestFailedUASpecific("InvalidSecurityOriginError"); |
| 596 break; |
| 597 case MEDIA_DEVICE_TAB_CAPTURE_FAILURE: |
| 598 request_info->requestFailedUASpecific("TabCaptureError"); |
| 599 break; |
| 600 case MEDIA_DEVICE_SCREEN_CAPTURE_FAILURE: |
| 601 request_info->requestFailedUASpecific("ScreenCaptureError"); |
| 602 break; |
| 603 case MEDIA_DEVICE_CAPTURE_FAILURE: |
| 604 request_info->requestFailedUASpecific("DeviceCaptureError"); |
| 605 break; |
| 606 case MEDIA_DEVICE_TRACK_START_FAILURE: |
| 607 request_info->requestFailedUASpecific("TrackStartError"); |
| 608 break; |
| 609 default: |
| 610 request_info->requestFailed(); |
| 611 break; |
576 } | 612 } |
577 } | 613 } |
578 | 614 |
579 const blink::WebMediaStreamSource* MediaStreamImpl::FindLocalSource( | 615 const blink::WebMediaStreamSource* MediaStreamImpl::FindLocalSource( |
580 const StreamDeviceInfo& device) const { | 616 const StreamDeviceInfo& device) const { |
581 for (LocalStreamSources::const_iterator it = local_sources_.begin(); | 617 for (LocalStreamSources::const_iterator it = local_sources_.begin(); |
582 it != local_sources_.end(); ++it) { | 618 it != local_sources_.end(); ++it) { |
583 MediaStreamSource* source = | 619 MediaStreamSource* source = |
584 static_cast<MediaStreamSource*>(it->source.extraData()); | 620 static_cast<MediaStreamSource*>(it->source.extraData()); |
585 const StreamDeviceInfo& active_device = source->device_info(); | 621 const StreamDeviceInfo& active_device = source->device_info(); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 DCHECK(it != sources_waiting_for_callback_.end()); | 902 DCHECK(it != sources_waiting_for_callback_.end()); |
867 sources_waiting_for_callback_.erase(it); | 903 sources_waiting_for_callback_.erase(it); |
868 // All tracks must be started successfully. Otherwise the request is a | 904 // All tracks must be started successfully. Otherwise the request is a |
869 // failure. | 905 // failure. |
870 if (!success) | 906 if (!success) |
871 request_failed_ = true; | 907 request_failed_ = true; |
872 CheckAllTracksStarted(); | 908 CheckAllTracksStarted(); |
873 } | 909 } |
874 | 910 |
875 void MediaStreamImpl::UserMediaRequestInfo::CheckAllTracksStarted() { | 911 void MediaStreamImpl::UserMediaRequestInfo::CheckAllTracksStarted() { |
876 if (!ready_callback_.is_null() && sources_waiting_for_callback_.empty()) | 912 if (!ready_callback_.is_null() && sources_waiting_for_callback_.empty()) { |
877 ready_callback_.Run(this, !request_failed_); | 913 ready_callback_.Run( |
| 914 this, |
| 915 request_failed_ ? MEDIA_DEVICE_TRACK_START_FAILURE : MEDIA_DEVICE_OK); |
| 916 } |
878 } | 917 } |
879 | 918 |
880 bool MediaStreamImpl::UserMediaRequestInfo::IsSourceUsed( | 919 bool MediaStreamImpl::UserMediaRequestInfo::IsSourceUsed( |
881 const blink::WebMediaStreamSource& source) const { | 920 const blink::WebMediaStreamSource& source) const { |
882 for (std::vector<blink::WebMediaStreamSource>::const_iterator source_it = | 921 for (std::vector<blink::WebMediaStreamSource>::const_iterator source_it = |
883 sources_.begin(); | 922 sources_.begin(); |
884 source_it != sources_.end(); ++source_it) { | 923 source_it != sources_.end(); ++source_it) { |
885 if (source_it->id() == source.id()) | 924 if (source_it->id() == source.id()) |
886 return true; | 925 return true; |
887 } | 926 } |
888 return false; | 927 return false; |
889 } | 928 } |
890 | 929 |
891 void MediaStreamImpl::UserMediaRequestInfo::RemoveSource( | 930 void MediaStreamImpl::UserMediaRequestInfo::RemoveSource( |
892 const blink::WebMediaStreamSource& source) { | 931 const blink::WebMediaStreamSource& source) { |
893 for (std::vector<blink::WebMediaStreamSource>::iterator it = | 932 for (std::vector<blink::WebMediaStreamSource>::iterator it = |
894 sources_.begin(); | 933 sources_.begin(); |
895 it != sources_.end(); ++it) { | 934 it != sources_.end(); ++it) { |
896 if (source.id() == it->id()) { | 935 if (source.id() == it->id()) { |
897 sources_.erase(it); | 936 sources_.erase(it); |
898 return; | 937 return; |
899 } | 938 } |
900 } | 939 } |
901 } | 940 } |
902 | 941 |
903 } // namespace content | 942 } // namespace content |
OLD | NEW |