| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // is asked for permission and device selection. | 251 // is asked for permission and device selection. |
| 252 void CreateUIRequest(const std::string& requested_audio_device_id, | 252 void CreateUIRequest(const std::string& requested_audio_device_id, |
| 253 const std::string& requested_video_device_id) { | 253 const std::string& requested_video_device_id) { |
| 254 DCHECK(!ui_request_); | 254 DCHECK(!ui_request_); |
| 255 target_process_id_ = requesting_process_id; | 255 target_process_id_ = requesting_process_id; |
| 256 target_frame_id_ = requesting_frame_id; | 256 target_frame_id_ = requesting_frame_id; |
| 257 ui_request_.reset(new MediaStreamRequest( | 257 ui_request_.reset(new MediaStreamRequest( |
| 258 requesting_process_id, requesting_frame_id, page_request_id, | 258 requesting_process_id, requesting_frame_id, page_request_id, |
| 259 ConvertToGURL(security_origin), user_gesture, request_type, | 259 ConvertToGURL(security_origin), user_gesture, request_type, |
| 260 requested_audio_device_id, requested_video_device_id, audio_type_, | 260 requested_audio_device_id, requested_video_device_id, audio_type_, |
| 261 video_type_)); | 261 video_type_, controls.disable_local_echo)); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Creates a tab capture specific MediaStreamRequest object that is used by | 264 // Creates a tab capture specific MediaStreamRequest object that is used by |
| 265 // this request when UI is asked for permission and device selection. | 265 // this request when UI is asked for permission and device selection. |
| 266 void CreateTabCaptureUIRequest(int target_render_process_id, | 266 void CreateTabCaptureUIRequest(int target_render_process_id, |
| 267 int target_render_frame_id) { | 267 int target_render_frame_id) { |
| 268 DCHECK(!ui_request_); | 268 DCHECK(!ui_request_); |
| 269 target_process_id_ = target_render_process_id; | 269 target_process_id_ = target_render_process_id; |
| 270 target_frame_id_ = target_render_frame_id; | 270 target_frame_id_ = target_render_frame_id; |
| 271 ui_request_.reset(new MediaStreamRequest( | 271 ui_request_.reset(new MediaStreamRequest( |
| 272 target_render_process_id, target_render_frame_id, page_request_id, | 272 target_render_process_id, target_render_frame_id, page_request_id, |
| 273 ConvertToGURL(security_origin), user_gesture, request_type, "", "", | 273 ConvertToGURL(security_origin), user_gesture, request_type, "", "", |
| 274 audio_type_, video_type_)); | 274 audio_type_, video_type_, controls.disable_local_echo)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 bool HasUIRequest() const { return ui_request_.get() != nullptr; } | 277 bool HasUIRequest() const { return ui_request_.get() != nullptr; } |
| 278 std::unique_ptr<MediaStreamRequest> DetachUIRequest() { | 278 std::unique_ptr<MediaStreamRequest> DetachUIRequest() { |
| 279 return std::move(ui_request_); | 279 return std::move(ui_request_); |
| 280 } | 280 } |
| 281 | 281 |
| 282 // Update the request state and notify observers. | 282 // Update the request state and notify observers. |
| 283 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { | 283 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { |
| 284 if (stream_type == NUM_MEDIA_TYPES) { | 284 if (stream_type == NUM_MEDIA_TYPES) { |
| (...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 std::string capture_device_id; | 1301 std::string capture_device_id; |
| 1302 if (!request->controls.audio.device_ids.empty()) { | 1302 if (!request->controls.audio.device_ids.empty()) { |
| 1303 capture_device_id = request->controls.audio.device_ids[0]; | 1303 capture_device_id = request->controls.audio.device_ids[0]; |
| 1304 } else if (!request->controls.video.device_ids.empty()) { | 1304 } else if (!request->controls.video.device_ids.empty()) { |
| 1305 capture_device_id = request->controls.video.device_ids[0]; | 1305 capture_device_id = request->controls.video.device_ids[0]; |
| 1306 } else { | 1306 } else { |
| 1307 return false; | 1307 return false; |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 // Customize controls for a WebContents based capture. | 1310 // Customize controls for a WebContents based capture. |
| 1311 int target_render_process_id = 0; | 1311 content::WebContentsMediaCaptureId web_id; |
| 1312 int target_render_frame_id = 0; | 1312 bool has_valid_device_id = |
| 1313 | 1313 WebContentsMediaCaptureId::Parse(capture_device_id, &web_id); |
| 1314 bool has_valid_device_id = WebContentsMediaCaptureId::ExtractTabCaptureTarget( | |
| 1315 capture_device_id, &target_render_process_id, &target_render_frame_id); | |
| 1316 if (!has_valid_device_id || | 1314 if (!has_valid_device_id || |
| 1317 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && | 1315 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && |
| 1318 request->audio_type() != MEDIA_NO_SERVICE) || | 1316 request->audio_type() != MEDIA_NO_SERVICE) || |
| 1319 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && | 1317 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && |
| 1320 request->video_type() != MEDIA_NO_SERVICE)) { | 1318 request->video_type() != MEDIA_NO_SERVICE)) { |
| 1321 return false; | 1319 return false; |
| 1322 } | 1320 } |
| 1323 request->tab_capture_device_id = capture_device_id; | 1321 web_id.disable_local_echo = request->controls.disable_local_echo; |
| 1324 | 1322 |
| 1325 request->CreateTabCaptureUIRequest(target_render_process_id, | 1323 request->tab_capture_device_id = web_id.ToString(); |
| 1326 target_render_frame_id); | 1324 |
| 1325 request->CreateTabCaptureUIRequest(web_id.render_process_id, |
| 1326 web_id.main_render_frame_id); |
| 1327 | 1327 |
| 1328 DVLOG(3) << "SetupTabCaptureRequest " | 1328 DVLOG(3) << "SetupTabCaptureRequest " |
| 1329 << ", {capture_device_id = " << capture_device_id << "}" | 1329 << ", {capture_device_id = " << capture_device_id << "}" |
| 1330 << ", {target_render_process_id = " << target_render_process_id | 1330 << ", {target_render_process_id = " << web_id.render_process_id |
| 1331 << "}" | 1331 << "}" |
| 1332 << ", {target_render_frame_id = " << target_render_frame_id << "}"; | 1332 << ", {target_render_frame_id = " << web_id.main_render_frame_id |
| 1333 << "}"; |
| 1333 return true; | 1334 return true; |
| 1334 } | 1335 } |
| 1335 | 1336 |
| 1336 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { | 1337 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { |
| 1337 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE || | 1338 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE || |
| 1338 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE); | 1339 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE); |
| 1339 | 1340 |
| 1340 // For screen capture we only support two valid combinations: | 1341 // For screen capture we only support two valid combinations: |
| 1341 // (1) screen video capture only, or | 1342 // (1) screen video capture only, or |
| 1342 // (2) screen video capture with loopback audio capture. | 1343 // (2) screen video capture with loopback audio capture. |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 if (device_info.session_id == session_id && | 2184 if (device_info.session_id == session_id && |
| 2184 device_info.device.type == type) { | 2185 device_info.device.type == type) { |
| 2185 request->SetCapturingLinkSecured(is_secure); | 2186 request->SetCapturingLinkSecured(is_secure); |
| 2186 return; | 2187 return; |
| 2187 } | 2188 } |
| 2188 } | 2189 } |
| 2189 } | 2190 } |
| 2190 } | 2191 } |
| 2191 | 2192 |
| 2192 } // namespace content | 2193 } // namespace content |
| OLD | NEW |