Chromium Code Reviews| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 | 241 |
| 242 return label; | 242 return label; |
| 243 } | 243 } |
| 244 | 244 |
| 245 std::string MediaStreamManager::GenerateStreamForDevice( | 245 std::string MediaStreamManager::GenerateStreamForDevice( |
| 246 MediaStreamRequester* requester, int render_process_id, int render_view_id, | 246 MediaStreamRequester* requester, int render_process_id, int render_view_id, |
| 247 const StreamOptions& options, const std::string& device_id, | 247 const StreamOptions& options, const std::string& device_id, |
| 248 const GURL& security_origin) { | 248 const GURL& security_origin) { |
| 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 250 | 250 |
| 251 int target_render_process_id = -1; | |
| 252 int target_render_view_id = -1; | |
| 253 // We will post the request to the target render view, not the source (i.e. | |
| 254 // source is an extension, and target is the tab we want to capture). | |
| 255 CHECK(WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
|
no longer working on chromium
2012/12/07 14:13:10
what will trigger this GenerateStreamForDevice?
If
justinlin
2012/12/07 15:50:09
Done. Good point. Fixed and tested this possible i
| |
| 256 device_id, &target_render_process_id, &target_render_view_id)); | |
| 257 DCHECK_NE(target_render_process_id, -1); | |
| 258 DCHECK_NE(target_render_view_id, -1); | |
| 259 | |
| 251 // Create a new request based on options. | 260 // Create a new request based on options. |
| 252 DeviceRequest* request = new DeviceRequest(requester, options, | 261 DeviceRequest* request = new DeviceRequest(requester, options, |
| 253 DeviceRequest::GENERATE_STREAM, | 262 DeviceRequest::GENERATE_STREAM, |
| 254 render_process_id, | 263 target_render_process_id, |
| 255 render_view_id, | 264 target_render_view_id, |
| 256 security_origin); | 265 security_origin); |
| 257 const std::string& label = AddRequest(request); | 266 const std::string& label = AddRequest(request); |
| 258 request->requested_device_id = device_id; | 267 request->requested_device_id = device_id; |
| 259 | 268 |
| 260 // Get user confirmation to use the capture device. | 269 // Get user confirmation to use the capture device. |
| 261 PostRequestToUI(label); | 270 PostRequestToUI(label); |
| 262 | 271 |
| 263 if (!security_origin.SchemeIs(kExtensionScheme) || | 272 if (!security_origin.SchemeIs(kExtensionScheme) || |
| 264 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && | 273 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && |
| 265 options.audio_type != MEDIA_NO_SERVICE) || | 274 options.audio_type != MEDIA_NO_SERVICE) || |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 return; | 861 return; |
| 853 } | 862 } |
| 854 | 863 |
| 855 // Process all newly-accepted devices for this request. | 864 // Process all newly-accepted devices for this request. |
| 856 DeviceRequest* request = request_it->second; | 865 DeviceRequest* request = request_it->second; |
| 857 bool found_audio = false, found_video = false; | 866 bool found_audio = false, found_video = false; |
| 858 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); | 867 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); |
| 859 device_it != devices.end(); ++device_it) { | 868 device_it != devices.end(); ++device_it) { |
| 860 StreamDeviceInfo device_info = *device_it; // Make a copy. | 869 StreamDeviceInfo device_info = *device_it; // Make a copy. |
| 861 | 870 |
| 871 // TODO(justinlin): Nicer way to do this? | |
| 872 // Re-append the device_id since we lost it when posting request to UI. | |
| 873 if (device_info.stream_type == content::MEDIA_TAB_VIDEO_CAPTURE || | |
| 874 device_info.stream_type == content::MEDIA_TAB_AUDIO_CAPTURE) | |
| 875 device_info.device_id = request->requested_device_id; | |
|
no longer working on chromium
2012/12/07 14:13:10
curiously, what is this device_id? is the process_
justinlin
2012/12/07 15:50:09
It's 'process_id + view_id'. We need to pass it to
| |
| 876 | |
| 862 // Set in_use to false to be able to track if this device has been | 877 // Set in_use to false to be able to track if this device has been |
| 863 // opened. in_use might be true if the device type can be used in more | 878 // opened. in_use might be true if the device type can be used in more |
| 864 // than one session. | 879 // than one session. |
| 865 DCHECK_EQ(request->getState(device_it->stream_type), | 880 DCHECK_EQ(request->getState(device_it->stream_type), |
| 866 MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 881 MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
| 867 device_info.in_use = false; | 882 device_info.in_use = false; |
| 868 | 883 |
| 869 device_info.session_id = | 884 device_info.session_id = |
| 870 GetDeviceManager(device_info.stream_type)->Open(device_info); | 885 GetDeviceManager(device_info.stream_type)->Open(device_info); |
| 871 request->setState(device_it->stream_type, MEDIA_REQUEST_STATE_OPENING); | 886 request->setState(device_it->stream_type, MEDIA_REQUEST_STATE_OPENING); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 930 ui_controller_.reset(); | 945 ui_controller_.reset(); |
| 931 } | 946 } |
| 932 | 947 |
| 933 void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) { | 948 void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) { |
| 934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 949 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 935 MediaStreamDevices opened_devices; | 950 MediaStreamDevices opened_devices; |
| 936 DevicesFromRequest(request, &opened_devices); | 951 DevicesFromRequest(request, &opened_devices); |
| 937 if (opened_devices.empty()) | 952 if (opened_devices.empty()) |
| 938 return; | 953 return; |
| 939 | 954 |
| 940 int target_render_process_id = request.render_process_id; | 955 NotifyUIDevicesOpened(request.render_process_id, |
| 941 int target_render_view_id = request.render_view_id; | 956 request.render_view_id, |
| 942 | |
| 943 // For tab capture requests, we should notify the UI to update the renderer | |
| 944 // that is the target of the capture instead of the requester. | |
| 945 if (request.options.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || | |
| 946 request.options.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { | |
| 947 if (!WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
| 948 request.requested_device_id, | |
| 949 &target_render_process_id, | |
| 950 &target_render_view_id)) | |
| 951 return; | |
| 952 } | |
| 953 | |
| 954 NotifyUIDevicesOpened(target_render_process_id, | |
| 955 target_render_view_id, | |
| 956 opened_devices); | 957 opened_devices); |
| 957 } | 958 } |
| 958 | 959 |
| 959 void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) { | 960 void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) { |
| 960 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 961 MediaStreamDevices closed_devices; | 962 MediaStreamDevices closed_devices; |
| 962 DevicesFromRequest(request, &closed_devices); | 963 DevicesFromRequest(request, &closed_devices); |
| 963 if (closed_devices.empty()) | 964 if (closed_devices.empty()) |
| 964 return; | 965 return; |
| 965 | 966 |
| 966 int target_render_process_id = request.render_process_id; | 967 NotifyUIDevicesClosed(request.render_process_id, |
| 967 int target_render_view_id = request.render_view_id; | 968 request.render_view_id, |
| 968 | |
| 969 // For tab capture requests, we should notify the UI to update the renderer | |
| 970 // that is the target of the capture instead of the requester. | |
| 971 if (request.options.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || | |
| 972 request.options.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { | |
| 973 if (!WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
| 974 request.requested_device_id, | |
| 975 &target_render_process_id, | |
| 976 &target_render_view_id)) | |
| 977 return; | |
| 978 } | |
| 979 | |
| 980 NotifyUIDevicesClosed(target_render_process_id, | |
| 981 target_render_view_id, | |
| 982 closed_devices); | 969 closed_devices); |
| 983 } | 970 } |
| 984 | 971 |
| 985 void MediaStreamManager::DevicesFromRequest( | 972 void MediaStreamManager::DevicesFromRequest( |
| 986 const DeviceRequest& request, MediaStreamDevices* devices) { | 973 const DeviceRequest& request, MediaStreamDevices* devices) { |
| 987 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); | 974 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); |
| 988 it != request.devices.end(); ++it) { | 975 it != request.devices.end(); ++it) { |
| 989 devices->push_back(MediaStreamDevice( | 976 devices->push_back(MediaStreamDevice( |
| 990 it->stream_type, it->device_id, it->name)); | 977 it->stream_type, it->device_id, it->name)); |
| 991 } | 978 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 } | 1068 } |
| 1082 | 1069 |
| 1083 // Always do enumeration even though some enumeration is in progress, | 1070 // Always do enumeration even though some enumeration is in progress, |
| 1084 // because those enumeration commands could be sent before these devices | 1071 // because those enumeration commands could be sent before these devices |
| 1085 // change. | 1072 // change. |
| 1086 ++active_enumeration_ref_count_[stream_type]; | 1073 ++active_enumeration_ref_count_[stream_type]; |
| 1087 GetDeviceManager(stream_type)->EnumerateDevices(); | 1074 GetDeviceManager(stream_type)->EnumerateDevices(); |
| 1088 } | 1075 } |
| 1089 | 1076 |
| 1090 } // namespace content | 1077 } // namespace content |
| OLD | NEW |