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 | |
254 // We will post the request to the target render view, not the source (i.e. | |
255 // source is an extension, and target is the tab we want to capture). | |
256 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
257 device_id, &target_render_process_id, &target_render_view_id); | |
258 | |
259 if (!has_valid_device_id || | |
260 !security_origin.SchemeIs(kExtensionScheme) || | |
261 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && | |
262 options.audio_type != MEDIA_NO_SERVICE) || | |
263 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && | |
264 options.video_type != MEDIA_NO_SERVICE)) { | |
265 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; | |
266 return std::string(); | |
wjia(left Chromium)
2012/12/08 20:09:40
drive by. I am wondering the consequence of return
justinlin
2012/12/08 23:30:27
Ah right. Actually, I just looked, and media_strea
no longer working on chromium
2012/12/10 10:03:18
I am trying to understand more. Justin, what kind
| |
267 } | |
268 | |
251 // Create a new request based on options. | 269 // Create a new request based on options. |
252 DeviceRequest* request = new DeviceRequest(requester, options, | 270 DeviceRequest* request = new DeviceRequest(requester, options, |
253 DeviceRequest::GENERATE_STREAM, | 271 DeviceRequest::GENERATE_STREAM, |
254 render_process_id, | 272 target_render_process_id, |
255 render_view_id, | 273 target_render_view_id, |
256 security_origin); | 274 security_origin); |
257 const std::string& label = AddRequest(request); | 275 const std::string& label = AddRequest(request); |
258 request->requested_device_id = device_id; | 276 request->requested_device_id = device_id; |
259 | 277 |
260 // Get user confirmation to use the capture device. | 278 // Get user confirmation to use the capture device. |
261 PostRequestToUI(label); | 279 PostRequestToUI(label); |
262 | 280 |
263 if (!security_origin.SchemeIs(kExtensionScheme) || | |
264 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && | |
265 options.audio_type != MEDIA_NO_SERVICE) || | |
266 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && | |
267 options.video_type != MEDIA_NO_SERVICE)) { | |
268 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; | |
269 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
270 base::Bind(&MediaStreamManager::CancelRequest, | |
271 base::Unretained(this), label)); | |
272 return label; | |
273 } | |
274 | |
275 // TODO(miu): We should ask the device manager whether a device with id | 281 // TODO(miu): We should ask the device manager whether a device with id |
276 // |device_id| actually exists. Note that no such MediaStreamProvider API for | 282 // |device_id| actually exists. Note that no such MediaStreamProvider API for |
277 // this currently exists. Also, we don't have a user-friendly device name for | 283 // this currently exists. Also, we don't have a user-friendly device name for |
278 // the infobar UI. | 284 // the infobar UI. |
279 if (IsAudioMediaType(options.audio_type)) { | 285 if (IsAudioMediaType(options.audio_type)) { |
280 // TODO(justinlin): Updating the state to requested and pending are no-ops | 286 // TODO(justinlin): Updating the state to requested and pending are no-ops |
281 // in terms of the media manager, but these are the state changes we want to | 287 // in terms of the media manager, but these are the state changes we want to |
282 // support in terms of extensions (which is registered as an observer). | 288 // support in terms of extensions (which is registered as an observer). |
283 request->setState(options.audio_type, MEDIA_REQUEST_STATE_REQUESTED); | 289 request->setState(options.audio_type, MEDIA_REQUEST_STATE_REQUESTED); |
284 request->setState(options.audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 290 request->setState(options.audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 return; | 858 return; |
853 } | 859 } |
854 | 860 |
855 // Process all newly-accepted devices for this request. | 861 // Process all newly-accepted devices for this request. |
856 DeviceRequest* request = request_it->second; | 862 DeviceRequest* request = request_it->second; |
857 bool found_audio = false, found_video = false; | 863 bool found_audio = false, found_video = false; |
858 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); | 864 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); |
859 device_it != devices.end(); ++device_it) { | 865 device_it != devices.end(); ++device_it) { |
860 StreamDeviceInfo device_info = *device_it; // Make a copy. | 866 StreamDeviceInfo device_info = *device_it; // Make a copy. |
861 | 867 |
868 // TODO(justinlin): Nicer way to do this? | |
869 // Re-append the device_id since we lost it when posting request to UI. | |
870 if (device_info.stream_type == content::MEDIA_TAB_VIDEO_CAPTURE || | |
871 device_info.stream_type == content::MEDIA_TAB_AUDIO_CAPTURE) | |
872 device_info.device_id = request->requested_device_id; | |
873 | |
862 // Set in_use to false to be able to track if this device has been | 874 // 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 | 875 // opened. in_use might be true if the device type can be used in more |
864 // than one session. | 876 // than one session. |
865 DCHECK_EQ(request->getState(device_it->stream_type), | 877 DCHECK_EQ(request->getState(device_it->stream_type), |
866 MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 878 MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
867 device_info.in_use = false; | 879 device_info.in_use = false; |
868 | 880 |
869 device_info.session_id = | 881 device_info.session_id = |
870 GetDeviceManager(device_info.stream_type)->Open(device_info); | 882 GetDeviceManager(device_info.stream_type)->Open(device_info); |
871 request->setState(device_it->stream_type, MEDIA_REQUEST_STATE_OPENING); | 883 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(); | 942 ui_controller_.reset(); |
931 } | 943 } |
932 | 944 |
933 void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) { | 945 void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) { |
934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 946 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
935 MediaStreamDevices opened_devices; | 947 MediaStreamDevices opened_devices; |
936 DevicesFromRequest(request, &opened_devices); | 948 DevicesFromRequest(request, &opened_devices); |
937 if (opened_devices.empty()) | 949 if (opened_devices.empty()) |
938 return; | 950 return; |
939 | 951 |
940 int target_render_process_id = request.render_process_id; | 952 NotifyUIDevicesOpened(request.render_process_id, |
941 int target_render_view_id = request.render_view_id; | 953 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); | 954 opened_devices); |
957 } | 955 } |
958 | 956 |
959 void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) { | 957 void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) { |
960 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 958 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
961 MediaStreamDevices closed_devices; | 959 MediaStreamDevices closed_devices; |
962 DevicesFromRequest(request, &closed_devices); | 960 DevicesFromRequest(request, &closed_devices); |
963 if (closed_devices.empty()) | 961 if (closed_devices.empty()) |
964 return; | 962 return; |
965 | 963 |
966 int target_render_process_id = request.render_process_id; | 964 NotifyUIDevicesClosed(request.render_process_id, |
967 int target_render_view_id = request.render_view_id; | 965 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); | 966 closed_devices); |
983 } | 967 } |
984 | 968 |
985 void MediaStreamManager::DevicesFromRequest( | 969 void MediaStreamManager::DevicesFromRequest( |
986 const DeviceRequest& request, MediaStreamDevices* devices) { | 970 const DeviceRequest& request, MediaStreamDevices* devices) { |
987 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); | 971 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); |
988 it != request.devices.end(); ++it) { | 972 it != request.devices.end(); ++it) { |
989 devices->push_back(MediaStreamDevice( | 973 devices->push_back(MediaStreamDevice( |
990 it->stream_type, it->device_id, it->name)); | 974 it->stream_type, it->device_id, it->name)); |
991 } | 975 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 } | 1065 } |
1082 | 1066 |
1083 // Always do enumeration even though some enumeration is in progress, | 1067 // Always do enumeration even though some enumeration is in progress, |
1084 // because those enumeration commands could be sent before these devices | 1068 // because those enumeration commands could be sent before these devices |
1085 // change. | 1069 // change. |
1086 ++active_enumeration_ref_count_[stream_type]; | 1070 ++active_enumeration_ref_count_[stream_type]; |
1087 GetDeviceManager(stream_type)->EnumerateDevices(); | 1071 GetDeviceManager(stream_type)->EnumerateDevices(); |
1088 } | 1072 } |
1089 | 1073 |
1090 } // namespace content | 1074 } // namespace content |
OLD | NEW |