| 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/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 81                                                &mandatory)) { | 81                                                &mandatory)) { | 
| 82        DCHECK(mandatory); | 82        DCHECK(mandatory); | 
| 83        // This is tab or screen capture. | 83        // This is tab or screen capture. | 
| 84        if (audio_stream_source == kMediaStreamSourceTab) { | 84        if (audio_stream_source == kMediaStreamSourceTab) { | 
| 85          *audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; | 85          *audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; | 
| 86        } else if (audio_stream_source == kMediaStreamSourceSystem) { | 86        } else if (audio_stream_source == kMediaStreamSourceSystem) { | 
| 87          *audio_type = content::MEDIA_LOOPBACK_AUDIO_CAPTURE; | 87          *audio_type = content::MEDIA_LOOPBACK_AUDIO_CAPTURE; | 
| 88        } | 88        } | 
| 89      } else { | 89      } else { | 
| 90        // This is normal audio device capture. | 90        // This is normal audio device capture. | 
| 91        *audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; | 91        *audio_type = MEDIA_DEVICE_AUDIO_CAPTURE; | 
| 92      } | 92      } | 
| 93   } | 93   } | 
| 94   if (options.video_requested) { | 94   if (options.video_requested) { | 
| 95      std::string video_stream_source; | 95      std::string video_stream_source; | 
| 96      bool mandatory = false; | 96      bool mandatory = false; | 
| 97      if (options.GetFirstVideoConstraintByName(kMediaStreamSource, | 97      if (options.GetFirstVideoConstraintByName(kMediaStreamSource, | 
| 98                                                &video_stream_source, | 98                                                &video_stream_source, | 
| 99                                                &mandatory)) { | 99                                                &mandatory)) { | 
| 100        DCHECK(mandatory); | 100        DCHECK(mandatory); | 
| 101        // This is tab or screen capture. | 101        // This is tab or screen capture. | 
| 102        if (video_stream_source == kMediaStreamSourceTab) { | 102        if (video_stream_source == kMediaStreamSourceTab) { | 
| 103          *video_type = content::MEDIA_TAB_VIDEO_CAPTURE; | 103          *video_type = content::MEDIA_TAB_VIDEO_CAPTURE; | 
| 104        } else if (video_stream_source == kMediaStreamSourceScreen) { | 104        } else if (video_stream_source == kMediaStreamSourceScreen) { | 
| 105          *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; | 105          *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; | 
| 106        } else if (video_stream_source == kMediaStreamSourceDesktop) { | 106        } else if (video_stream_source == kMediaStreamSourceDesktop) { | 
| 107          *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; | 107          *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; | 
| 108        } | 108        } | 
| 109      } else { | 109      } else { | 
| 110        // This is normal video device capture. | 110        // This is normal video device capture. | 
| 111        *video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; | 111        *video_type = MEDIA_DEVICE_VIDEO_CAPTURE; | 
| 112      } | 112      } | 
| 113   } | 113   } | 
| 114 } | 114 } | 
| 115 | 115 | 
| 116 // Private helper method for SendMessageToNativeLog() that obtains the global | 116 // Private helper method for SendMessageToNativeLog() that obtains the global | 
| 117 // MediaStreamManager instance on the UI thread before sending |message| to the | 117 // MediaStreamManager instance on the UI thread before sending |message| to the | 
| 118 // webrtcLoggingPrivate API. | 118 // webrtcLoggingPrivate API. | 
| 119 void DoAddLogMessage(const std::string& message) { | 119 void DoAddLogMessage(const std::string& message) { | 
| 120   // Must be on the UI thread to access BrowserMainLoop. | 120   // Must be on the UI thread to access BrowserMainLoop. | 
| 121   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 121   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1045   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1045   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 1046   DeviceRequest* request = FindRequest(label); | 1046   DeviceRequest* request = FindRequest(label); | 
| 1047   if (!request) { | 1047   if (!request) { | 
| 1048     DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; | 1048     DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; | 
| 1049     return;  // This can happen if the request has been canceled. | 1049     return;  // This can happen if the request has been canceled. | 
| 1050   } | 1050   } | 
| 1051 | 1051 | 
| 1052   if (!request->security_origin.is_valid()) { | 1052   if (!request->security_origin.is_valid()) { | 
| 1053     LOG(ERROR) << "Invalid security origin. " | 1053     LOG(ERROR) << "Invalid security origin. " | 
| 1054                << request->security_origin; | 1054                << request->security_origin; | 
| 1055     FinalizeRequestFailed(label, request); | 1055     FinalizeRequestFailed(label, | 
|  | 1056                           request, | 
|  | 1057                           MEDIA_DEVICE_INVALID_SECURITY_ORIGIN); | 
| 1056     return; | 1058     return; | 
| 1057   } | 1059   } | 
| 1058 | 1060 | 
| 1059   MediaStreamType audio_type = MEDIA_NO_SERVICE; | 1061   MediaStreamType audio_type = MEDIA_NO_SERVICE; | 
| 1060   MediaStreamType video_type = MEDIA_NO_SERVICE; | 1062   MediaStreamType video_type = MEDIA_NO_SERVICE; | 
| 1061   ParseStreamType(request->options, &audio_type, &video_type); | 1063   ParseStreamType(request->options, &audio_type, &video_type); | 
| 1062   request->SetAudioType(audio_type); | 1064   request->SetAudioType(audio_type); | 
| 1063   request->SetVideoType(video_type); | 1065   request->SetVideoType(video_type); | 
| 1064 | 1066 | 
| 1065   bool is_web_contents_capture = | 1067   bool is_web_contents_capture = | 
| 1066       audio_type == MEDIA_TAB_AUDIO_CAPTURE || | 1068       audio_type == MEDIA_TAB_AUDIO_CAPTURE || | 
| 1067       video_type == MEDIA_TAB_VIDEO_CAPTURE; | 1069       video_type == MEDIA_TAB_VIDEO_CAPTURE; | 
| 1068   if (is_web_contents_capture && !SetupTabCaptureRequest(request)) { | 1070   if (is_web_contents_capture && !SetupTabCaptureRequest(request)) { | 
| 1069     FinalizeRequestFailed(label, request); | 1071     FinalizeRequestFailed(label, | 
|  | 1072                           request, | 
|  | 1073                           MEDIA_DEVICE_TAB_CAPTURE_FAILURE); | 
| 1070     return; | 1074     return; | 
| 1071   } | 1075   } | 
| 1072 | 1076 | 
| 1073   bool is_screen_capture = | 1077   bool is_screen_capture = | 
| 1074       video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; | 1078       video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; | 
| 1075   if (is_screen_capture && !SetupScreenCaptureRequest(request)) { | 1079   if (is_screen_capture && !SetupScreenCaptureRequest(request)) { | 
| 1076     FinalizeRequestFailed(label, request); | 1080     FinalizeRequestFailed(label, | 
|  | 1081                           request, | 
|  | 1082                           MEDIA_DEVICE_SCREEN_CAPTURE_FAILURE); | 
| 1077     return; | 1083     return; | 
| 1078   } | 1084   } | 
| 1079 | 1085 | 
| 1080   if (!is_web_contents_capture && !is_screen_capture) { | 1086   if (!is_web_contents_capture && !is_screen_capture) { | 
| 1081     if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || | 1087     if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || | 
| 1082         EnumerationRequired(&video_enumeration_cache_, video_type)) { | 1088         EnumerationRequired(&video_enumeration_cache_, video_type)) { | 
| 1083       // Enumerate the devices if there is no valid device lists to be used. | 1089       // Enumerate the devices if there is no valid device lists to be used. | 
| 1084       StartEnumeration(request); | 1090       StartEnumeration(request); | 
| 1085       return; | 1091       return; | 
| 1086     } else { | 1092     } else { | 
| 1087         // Cache is valid, so log the cached devices for MediaStream requests. | 1093         // Cache is valid, so log the cached devices for MediaStream requests. | 
| 1088       if (request->request_type == MEDIA_GENERATE_STREAM) { | 1094       if (request->request_type == MEDIA_GENERATE_STREAM) { | 
| 1089         std::string log_message("Using cached devices for request.\n"); | 1095         std::string log_message("Using cached devices for request.\n"); | 
| 1090         if (audio_type != MEDIA_NO_SERVICE) { | 1096         if (audio_type != MEDIA_NO_SERVICE) { | 
| 1091           log_message += | 1097           log_message += | 
| 1092               GetLogMessageString(audio_type, audio_enumeration_cache_.devices); | 1098               GetLogMessageString(audio_type, audio_enumeration_cache_.devices); | 
| 1093         } | 1099         } | 
| 1094         if (video_type != MEDIA_NO_SERVICE) { | 1100         if (video_type != MEDIA_NO_SERVICE) { | 
| 1095           log_message += | 1101           log_message += | 
| 1096               GetLogMessageString(video_type, video_enumeration_cache_.devices); | 1102               GetLogMessageString(video_type, video_enumeration_cache_.devices); | 
| 1097         } | 1103         } | 
| 1098         SendMessageToNativeLog(log_message); | 1104         SendMessageToNativeLog(log_message); | 
| 1099       } | 1105       } | 
| 1100     } | 1106     } | 
| 1101 | 1107 | 
| 1102     if (!SetupDeviceCaptureRequest(request)) { | 1108     if (!SetupDeviceCaptureRequest(request)) { | 
| 1103       FinalizeRequestFailed(label, request); | 1109       FinalizeRequestFailed(label, request, MEDIA_DEVICE_CAPTURE_FAILURE); | 
| 1104       return; | 1110       return; | 
| 1105     } | 1111     } | 
| 1106   } | 1112   } | 
| 1107   PostRequestToUI(label, request); | 1113   PostRequestToUI(label, request); | 
| 1108 } | 1114 } | 
| 1109 | 1115 | 
| 1110 bool MediaStreamManager::SetupDeviceCaptureRequest(DeviceRequest* request) { | 1116 bool MediaStreamManager::SetupDeviceCaptureRequest(DeviceRequest* request) { | 
| 1111   DCHECK((request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || | 1117   DCHECK((request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || | 
| 1112           request->audio_type() == MEDIA_NO_SERVICE) && | 1118           request->audio_type() == MEDIA_NO_SERVICE) && | 
| 1113          (request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE || | 1119          (request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE || | 
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1288   } | 1294   } | 
| 1289 | 1295 | 
| 1290   request->requester->StreamGenerated( | 1296   request->requester->StreamGenerated( | 
| 1291       request->requesting_view_id, | 1297       request->requesting_view_id, | 
| 1292       request->page_request_id, | 1298       request->page_request_id, | 
| 1293       label, audio_devices, video_devices); | 1299       label, audio_devices, video_devices); | 
| 1294 } | 1300 } | 
| 1295 | 1301 | 
| 1296 void MediaStreamManager::FinalizeRequestFailed( | 1302 void MediaStreamManager::FinalizeRequestFailed( | 
| 1297     const std::string& label, | 1303     const std::string& label, | 
| 1298     DeviceRequest* request) { | 1304     DeviceRequest* request, | 
|  | 1305     content::MediaStreamRequestResult result) { | 
| 1299   if (request->requester) | 1306   if (request->requester) | 
| 1300     request->requester->StreamGenerationFailed( | 1307     request->requester->StreamGenerationFailed( | 
| 1301         request->requesting_view_id, | 1308         request->requesting_view_id, | 
| 1302         request->page_request_id); | 1309         request->page_request_id, | 
|  | 1310         result); | 
| 1303 | 1311 | 
| 1304   if (request->request_type == MEDIA_DEVICE_ACCESS && | 1312   if (request->request_type == MEDIA_DEVICE_ACCESS && | 
| 1305       !request->callback.is_null()) { | 1313       !request->callback.is_null()) { | 
| 1306     request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); | 1314     request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); | 
| 1307   } | 1315   } | 
| 1308 | 1316 | 
| 1309   DeleteRequest(label); | 1317   DeleteRequest(label); | 
| 1310 } | 1318 } | 
| 1311 | 1319 | 
| 1312 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, | 1320 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, | 
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1538       default: | 1546       default: | 
| 1539         if (request->state(request->audio_type()) == | 1547         if (request->state(request->audio_type()) == | 
| 1540                 MEDIA_REQUEST_STATE_REQUESTED || | 1548                 MEDIA_REQUEST_STATE_REQUESTED || | 
| 1541             request->state(request->video_type()) == | 1549             request->state(request->video_type()) == | 
| 1542                 MEDIA_REQUEST_STATE_REQUESTED) { | 1550                 MEDIA_REQUEST_STATE_REQUESTED) { | 
| 1543           // We are doing enumeration for other type of media, wait until it is | 1551           // We are doing enumeration for other type of media, wait until it is | 
| 1544           // all done before posting the request to UI because UI needs | 1552           // all done before posting the request to UI because UI needs | 
| 1545           // the device lists to handle the request. | 1553           // the device lists to handle the request. | 
| 1546           break; | 1554           break; | 
| 1547         } | 1555         } | 
| 1548         if (!SetupDeviceCaptureRequest(request)) | 1556         if (!SetupDeviceCaptureRequest(request)) { | 
| 1549           FinalizeRequestFailed(*it, request); | 1557           FinalizeRequestFailed(*it, | 
| 1550         else | 1558                                 request, | 
|  | 1559                                 MEDIA_DEVICE_CAPTURE_FAILURE); | 
|  | 1560         } else { | 
| 1551           PostRequestToUI(*it, request); | 1561           PostRequestToUI(*it, request); | 
|  | 1562         } | 
| 1552         break; | 1563         break; | 
| 1553     } | 1564     } | 
| 1554   } | 1565   } | 
| 1555   label_list.clear(); | 1566   label_list.clear(); | 
| 1556   --active_enumeration_ref_count_[stream_type]; | 1567   --active_enumeration_ref_count_[stream_type]; | 
| 1557   DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); | 1568   DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); | 
| 1558 } | 1569 } | 
| 1559 | 1570 | 
| 1560 // static | 1571 // static | 
| 1561 void MediaStreamManager::SendMessageToNativeLog(const std::string& message) { | 1572 void MediaStreamManager::SendMessageToNativeLog(const std::string& message) { | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1605         static_cast<content::RenderProcessHostImpl*>( | 1616         static_cast<content::RenderProcessHostImpl*>( | 
| 1606             content::RenderProcessHost::FromID(*it)); | 1617             content::RenderProcessHost::FromID(*it)); | 
| 1607     if (render_process_host_impl) | 1618     if (render_process_host_impl) | 
| 1608       render_process_host_impl->WebRtcLogMessage(message); | 1619       render_process_host_impl->WebRtcLogMessage(message); | 
| 1609   } | 1620   } | 
| 1610 #endif | 1621 #endif | 
| 1611 } | 1622 } | 
| 1612 | 1623 | 
| 1613 void MediaStreamManager::HandleAccessRequestResponse( | 1624 void MediaStreamManager::HandleAccessRequestResponse( | 
| 1614     const std::string& label, | 1625     const std::string& label, | 
| 1615     const MediaStreamDevices& devices) { | 1626     const MediaStreamDevices& devices, | 
|  | 1627     content::MediaStreamRequestResult result) { | 
| 1616   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1628   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 
| 1617   DVLOG(1) << "HandleAccessRequestResponse(" | 1629   DVLOG(1) << "HandleAccessRequestResponse(" | 
| 1618            << ", {label = " << label <<  "})"; | 1630            << ", {label = " << label <<  "})"; | 
| 1619 | 1631 | 
| 1620   DeviceRequest* request = FindRequest(label); | 1632   DeviceRequest* request = FindRequest(label); | 
| 1621   if (!request) { | 1633   if (!request) { | 
| 1622     // The request has been canceled before the UI returned. | 1634     // The request has been canceled before the UI returned. | 
| 1623     return; | 1635     return; | 
| 1624   } | 1636   } | 
| 1625 | 1637 | 
| 1626   if (request->request_type == MEDIA_DEVICE_ACCESS) { | 1638   if (request->request_type == MEDIA_DEVICE_ACCESS) { | 
| 1627     FinalizeMediaAccessRequest(label, request, devices); | 1639     FinalizeMediaAccessRequest(label, request, devices); | 
| 1628     return; | 1640     return; | 
| 1629   } | 1641   } | 
| 1630 | 1642 | 
| 1631   // Handle the case when the request was denied. | 1643   // Handle the case when the request was denied. | 
| 1632   if (devices.empty()) { | 1644   if (result != MEDIA_DEVICE_OK) { | 
| 1633     FinalizeRequestFailed(label, request); | 1645     FinalizeRequestFailed(label, request, result); | 
| 1634     return; | 1646     return; | 
| 1635   } | 1647   } | 
| 1636 | 1648 | 
| 1637   // Process all newly-accepted devices for this request. | 1649   // Process all newly-accepted devices for this request. | 
| 1638   bool found_audio = false; | 1650   bool found_audio = false; | 
| 1639   bool found_video = false; | 1651   bool found_video = false; | 
| 1640   for (MediaStreamDevices::const_iterator device_it = devices.begin(); | 1652   for (MediaStreamDevices::const_iterator device_it = devices.begin(); | 
| 1641        device_it != devices.end(); ++device_it) { | 1653        device_it != devices.end(); ++device_it) { | 
| 1642     StreamDeviceInfo device_info; | 1654     StreamDeviceInfo device_info; | 
| 1643     device_info.device = *device_it; | 1655     device_info.device = *device_it; | 
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1838   } | 1850   } | 
| 1839 | 1851 | 
| 1840   // Always do enumeration even though some enumeration is in progress, | 1852   // Always do enumeration even though some enumeration is in progress, | 
| 1841   // because those enumeration commands could be sent before these devices | 1853   // because those enumeration commands could be sent before these devices | 
| 1842   // change. | 1854   // change. | 
| 1843   ++active_enumeration_ref_count_[stream_type]; | 1855   ++active_enumeration_ref_count_[stream_type]; | 
| 1844   GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1856   GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 
| 1845 } | 1857 } | 
| 1846 | 1858 | 
| 1847 }  // namespace content | 1859 }  // namespace content | 
| OLD | NEW | 
|---|