Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 180633008: Add different error codes for getUserMedia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/renderer_host/media/media_stream_manager.h" 5 #include "content/browser/renderer_host/media/media_stream_manager.h"
6 6
7 #include <list> 7 #include <list>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 &mandatory)) { 75 &mandatory)) {
76 DCHECK(mandatory); 76 DCHECK(mandatory);
77 // This is tab or screen capture. 77 // This is tab or screen capture.
78 if (audio_stream_source == kMediaStreamSourceTab) { 78 if (audio_stream_source == kMediaStreamSourceTab) {
79 *audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; 79 *audio_type = content::MEDIA_TAB_AUDIO_CAPTURE;
80 } else if (audio_stream_source == kMediaStreamSourceSystem) { 80 } else if (audio_stream_source == kMediaStreamSourceSystem) {
81 *audio_type = content::MEDIA_LOOPBACK_AUDIO_CAPTURE; 81 *audio_type = content::MEDIA_LOOPBACK_AUDIO_CAPTURE;
82 } 82 }
83 } else { 83 } else {
84 // This is normal audio device capture. 84 // This is normal audio device capture.
85 *audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; 85 *audio_type = MEDIA_DEVICE_AUDIO_CAPTURE;
86 } 86 }
87 } 87 }
88 if (options.video_requested) { 88 if (options.video_requested) {
89 std::string video_stream_source; 89 std::string video_stream_source;
90 bool mandatory = false; 90 bool mandatory = false;
91 if (options.GetFirstVideoConstraintByName(kMediaStreamSource, 91 if (options.GetFirstVideoConstraintByName(kMediaStreamSource,
92 &video_stream_source, 92 &video_stream_source,
93 &mandatory)) { 93 &mandatory)) {
94 DCHECK(mandatory); 94 DCHECK(mandatory);
95 // This is tab or screen capture. 95 // This is tab or screen capture.
96 if (video_stream_source == kMediaStreamSourceTab) { 96 if (video_stream_source == kMediaStreamSourceTab) {
97 *video_type = content::MEDIA_TAB_VIDEO_CAPTURE; 97 *video_type = content::MEDIA_TAB_VIDEO_CAPTURE;
98 } else if (video_stream_source == kMediaStreamSourceScreen) { 98 } else if (video_stream_source == kMediaStreamSourceScreen) {
99 *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; 99 *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE;
100 } else if (video_stream_source == kMediaStreamSourceDesktop) { 100 } else if (video_stream_source == kMediaStreamSourceDesktop) {
101 *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; 101 *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE;
102 } 102 }
103 } else { 103 } else {
104 // This is normal video device capture. 104 // This is normal video device capture.
105 *video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; 105 *video_type = MEDIA_DEVICE_VIDEO_CAPTURE;
106 } 106 }
107 } 107 }
108 } 108 }
109 109
110 // Private helper method for SendMessageToNativeLog() that obtains the global 110 // Private helper method for SendMessageToNativeLog() that obtains the global
111 // MediaStreamManager instance on the UI thread before sending |message| to the 111 // MediaStreamManager instance on the UI thread before sending |message| to the
112 // webrtcLoggingPrivate API. 112 // webrtcLoggingPrivate API.
113 void DoAddLogMessage(const std::string& message) { 113 void DoAddLogMessage(const std::string& message) {
114 // Must be on the UI thread to access BrowserMainLoop. 114 // Must be on the UI thread to access BrowserMainLoop.
115 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 115 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1023 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1024 DeviceRequest* request = FindRequest(label); 1024 DeviceRequest* request = FindRequest(label);
1025 if (!request) { 1025 if (!request) {
1026 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; 1026 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!";
1027 return; // This can happen if the request has been canceled. 1027 return; // This can happen if the request has been canceled.
1028 } 1028 }
1029 1029
1030 if (!request->security_origin.is_valid()) { 1030 if (!request->security_origin.is_valid()) {
1031 LOG(ERROR) << "Invalid security origin. " 1031 LOG(ERROR) << "Invalid security origin. "
1032 << request->security_origin; 1032 << request->security_origin;
1033 FinalizeRequestFailed(label, request); 1033 FinalizeRequestFailed(label,
1034 request,
1035 MEDIA_DEVICE_INVALID_SECURITY_ORIGIN);
1034 return; 1036 return;
1035 } 1037 }
1036 1038
1037 MediaStreamType audio_type = MEDIA_NO_SERVICE; 1039 MediaStreamType audio_type = MEDIA_NO_SERVICE;
1038 MediaStreamType video_type = MEDIA_NO_SERVICE; 1040 MediaStreamType video_type = MEDIA_NO_SERVICE;
1039 ParseStreamType(request->options, &audio_type, &video_type); 1041 ParseStreamType(request->options, &audio_type, &video_type);
1040 request->SetAudioType(audio_type); 1042 request->SetAudioType(audio_type);
1041 request->SetVideoType(video_type); 1043 request->SetVideoType(video_type);
1042 1044
1043 bool is_web_contents_capture = 1045 bool is_web_contents_capture =
1044 audio_type == MEDIA_TAB_AUDIO_CAPTURE || 1046 audio_type == MEDIA_TAB_AUDIO_CAPTURE ||
1045 video_type == MEDIA_TAB_VIDEO_CAPTURE; 1047 video_type == MEDIA_TAB_VIDEO_CAPTURE;
1046 if (is_web_contents_capture && !SetupTabCaptureRequest(request)) { 1048 if (is_web_contents_capture && !SetupTabCaptureRequest(request)) {
1047 FinalizeRequestFailed(label, request); 1049 FinalizeRequestFailed(label,
1050 request,
1051 MEDIA_DEVICE_TAB_CAPTURE_FAILURE);
1048 return; 1052 return;
1049 } 1053 }
1050 1054
1051 bool is_screen_capture = 1055 bool is_screen_capture =
1052 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; 1056 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE;
1053 if (is_screen_capture && !SetupScreenCaptureRequest(request)) { 1057 if (is_screen_capture && !SetupScreenCaptureRequest(request)) {
1054 FinalizeRequestFailed(label, request); 1058 FinalizeRequestFailed(label,
1059 request,
1060 MEDIA_DEVICE_SCREEN_CAPTURE_FAILURE);
1055 return; 1061 return;
1056 } 1062 }
1057 1063
1058 if (!is_web_contents_capture && !is_screen_capture) { 1064 if (!is_web_contents_capture && !is_screen_capture) {
1059 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || 1065 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) ||
1060 EnumerationRequired(&video_enumeration_cache_, video_type)) { 1066 EnumerationRequired(&video_enumeration_cache_, video_type)) {
1061 // Enumerate the devices if there is no valid device lists to be used. 1067 // Enumerate the devices if there is no valid device lists to be used.
1062 StartEnumeration(request); 1068 StartEnumeration(request);
1063 return; 1069 return;
1064 } else { 1070 } else {
1065 // Cache is valid, so log the cached devices for MediaStream requests. 1071 // Cache is valid, so log the cached devices for MediaStream requests.
1066 if (request->request_type == MEDIA_GENERATE_STREAM) { 1072 if (request->request_type == MEDIA_GENERATE_STREAM) {
1067 std::string log_message("Using cached devices for request.\n"); 1073 std::string log_message("Using cached devices for request.\n");
1068 if (audio_type != MEDIA_NO_SERVICE) { 1074 if (audio_type != MEDIA_NO_SERVICE) {
1069 log_message += 1075 log_message +=
1070 GetLogMessageString(audio_type, audio_enumeration_cache_.devices); 1076 GetLogMessageString(audio_type, audio_enumeration_cache_.devices);
1071 } 1077 }
1072 if (video_type != MEDIA_NO_SERVICE) { 1078 if (video_type != MEDIA_NO_SERVICE) {
1073 log_message += 1079 log_message +=
1074 GetLogMessageString(video_type, video_enumeration_cache_.devices); 1080 GetLogMessageString(video_type, video_enumeration_cache_.devices);
1075 } 1081 }
1076 SendMessageToNativeLog(log_message); 1082 SendMessageToNativeLog(log_message);
1077 } 1083 }
1078 } 1084 }
1079 1085
1080 if (!SetupDeviceCaptureRequest(request)) { 1086 if (!SetupDeviceCaptureRequest(request)) {
1081 FinalizeRequestFailed(label, request); 1087 FinalizeRequestFailed(label, request, MEDIA_DEVICE_CAPTURE_FAILURE);
1082 return; 1088 return;
1083 } 1089 }
1084 } 1090 }
1085 PostRequestToUI(label, request); 1091 PostRequestToUI(label, request);
1086 } 1092 }
1087 1093
1088 bool MediaStreamManager::SetupDeviceCaptureRequest(DeviceRequest* request) { 1094 bool MediaStreamManager::SetupDeviceCaptureRequest(DeviceRequest* request) {
1089 DCHECK((request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || 1095 DCHECK((request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE ||
1090 request->audio_type() == MEDIA_NO_SERVICE) && 1096 request->audio_type() == MEDIA_NO_SERVICE) &&
1091 (request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE || 1097 (request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE ||
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 } 1272 }
1267 1273
1268 request->requester->StreamGenerated( 1274 request->requester->StreamGenerated(
1269 request->requesting_view_id, 1275 request->requesting_view_id,
1270 request->page_request_id, 1276 request->page_request_id,
1271 label, audio_devices, video_devices); 1277 label, audio_devices, video_devices);
1272 } 1278 }
1273 1279
1274 void MediaStreamManager::FinalizeRequestFailed( 1280 void MediaStreamManager::FinalizeRequestFailed(
1275 const std::string& label, 1281 const std::string& label,
1276 DeviceRequest* request) { 1282 DeviceRequest* request,
1283 content::MediaStreamRequestResult result) {
1277 if (request->requester) 1284 if (request->requester)
1278 request->requester->StreamGenerationFailed( 1285 request->requester->StreamGenerationFailed(
1279 request->requesting_view_id, 1286 request->requesting_view_id,
1280 request->page_request_id); 1287 request->page_request_id,
1288 result);
1281 1289
1282 if (request->request_type == MEDIA_DEVICE_ACCESS && 1290 if (request->request_type == MEDIA_DEVICE_ACCESS &&
1283 !request->callback.is_null()) { 1291 !request->callback.is_null()) {
1284 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); 1292 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass());
1285 } 1293 }
1286 1294
1287 DeleteRequest(label); 1295 DeleteRequest(label);
1288 } 1296 }
1289 1297
1290 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, 1298 void MediaStreamManager::FinalizeOpenDevice(const std::string& label,
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 if (request->state(request->audio_type()) == 1525 if (request->state(request->audio_type()) ==
1518 MEDIA_REQUEST_STATE_REQUESTED || 1526 MEDIA_REQUEST_STATE_REQUESTED ||
1519 request->state(request->video_type()) == 1527 request->state(request->video_type()) ==
1520 MEDIA_REQUEST_STATE_REQUESTED) { 1528 MEDIA_REQUEST_STATE_REQUESTED) {
1521 // We are doing enumeration for other type of media, wait until it is 1529 // We are doing enumeration for other type of media, wait until it is
1522 // all done before posting the request to UI because UI needs 1530 // all done before posting the request to UI because UI needs
1523 // the device lists to handle the request. 1531 // the device lists to handle the request.
1524 break; 1532 break;
1525 } 1533 }
1526 if (!SetupDeviceCaptureRequest(request)) 1534 if (!SetupDeviceCaptureRequest(request))
1527 FinalizeRequestFailed(*it, request); 1535 FinalizeRequestFailed(*it,
1536 request,
1537 MEDIA_DEVICE_CAPTURE_FAILURE);
1528 else 1538 else
1529 PostRequestToUI(*it, request); 1539 PostRequestToUI(*it, request);
1530 break; 1540 break;
1531 } 1541 }
1532 } 1542 }
1533 label_list.clear(); 1543 label_list.clear();
1534 --active_enumeration_ref_count_[stream_type]; 1544 --active_enumeration_ref_count_[stream_type];
1535 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); 1545 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
1536 } 1546 }
1537 1547
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 static_cast<content::RenderProcessHostImpl*>( 1593 static_cast<content::RenderProcessHostImpl*>(
1584 content::RenderProcessHost::FromID(*it)); 1594 content::RenderProcessHost::FromID(*it));
1585 if (render_process_host_impl) 1595 if (render_process_host_impl)
1586 render_process_host_impl->WebRtcLogMessage(message); 1596 render_process_host_impl->WebRtcLogMessage(message);
1587 } 1597 }
1588 #endif 1598 #endif
1589 } 1599 }
1590 1600
1591 void MediaStreamManager::HandleAccessRequestResponse( 1601 void MediaStreamManager::HandleAccessRequestResponse(
1592 const std::string& label, 1602 const std::string& label,
1593 const MediaStreamDevices& devices) { 1603 const MediaStreamDevices& devices,
1604 content::MediaStreamRequestResult result) {
1594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1595 DVLOG(1) << "HandleAccessRequestResponse(" 1606 DVLOG(1) << "HandleAccessRequestResponse("
1596 << ", {label = " << label << "})"; 1607 << ", {label = " << label << "})";
1597 1608
1598 DeviceRequest* request = FindRequest(label); 1609 DeviceRequest* request = FindRequest(label);
1599 if (!request) { 1610 if (!request) {
1600 // The request has been canceled before the UI returned. 1611 // The request has been canceled before the UI returned.
1601 return; 1612 return;
1602 } 1613 }
1603 1614
1604 if (request->request_type == MEDIA_DEVICE_ACCESS) { 1615 if (request->request_type == MEDIA_DEVICE_ACCESS) {
1605 FinalizeMediaAccessRequest(label, request, devices); 1616 FinalizeMediaAccessRequest(label, request, devices);
1606 return; 1617 return;
1607 } 1618 }
1608 1619
1609 // Handle the case when the request was denied. 1620 // Handle the case when the request was denied.
1610 if (devices.empty()) { 1621 if (result != MEDIA_DEVICE_OK) {
1611 FinalizeRequestFailed(label, request); 1622 FinalizeRequestFailed(label, request, result);
1612 return; 1623 return;
1613 } 1624 }
1614 1625
1615 // Process all newly-accepted devices for this request. 1626 // Process all newly-accepted devices for this request.
1616 bool found_audio = false; 1627 bool found_audio = false;
1617 bool found_video = false; 1628 bool found_video = false;
1618 for (MediaStreamDevices::const_iterator device_it = devices.begin(); 1629 for (MediaStreamDevices::const_iterator device_it = devices.begin();
1619 device_it != devices.end(); ++device_it) { 1630 device_it != devices.end(); ++device_it) {
1620 StreamDeviceInfo device_info; 1631 StreamDeviceInfo device_info;
1621 device_info.device = *device_it; 1632 device_info.device = *device_it;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 } 1827 }
1817 1828
1818 // Always do enumeration even though some enumeration is in progress, 1829 // Always do enumeration even though some enumeration is in progress,
1819 // because those enumeration commands could be sent before these devices 1830 // because those enumeration commands could be sent before these devices
1820 // change. 1831 // change.
1821 ++active_enumeration_ref_count_[stream_type]; 1832 ++active_enumeration_ref_count_[stream_type];
1822 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); 1833 GetDeviceManager(stream_type)->EnumerateDevices(stream_type);
1823 } 1834 }
1824 1835
1825 } // namespace content 1836 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698