| 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 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // is asked for permission and device selection. | 298 // is asked for permission and device selection. |
| 299 void CreateUIRequest(const std::string& requested_audio_device_id, | 299 void CreateUIRequest(const std::string& requested_audio_device_id, |
| 300 const std::string& requested_video_device_id) { | 300 const std::string& requested_video_device_id) { |
| 301 DCHECK(!ui_request_); | 301 DCHECK(!ui_request_); |
| 302 target_process_id_ = requesting_process_id; | 302 target_process_id_ = requesting_process_id; |
| 303 target_frame_id_ = requesting_frame_id; | 303 target_frame_id_ = requesting_frame_id; |
| 304 ui_request_.reset(new MediaStreamRequest( | 304 ui_request_.reset(new MediaStreamRequest( |
| 305 requesting_process_id, requesting_frame_id, page_request_id, | 305 requesting_process_id, requesting_frame_id, page_request_id, |
| 306 security_origin.GetURL(), user_gesture, request_type, | 306 security_origin.GetURL(), user_gesture, request_type, |
| 307 requested_audio_device_id, requested_video_device_id, audio_type_, | 307 requested_audio_device_id, requested_video_device_id, audio_type_, |
| 308 video_type_)); | 308 video_type_, controls.disable_local_echo)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 // Creates a tab capture specific MediaStreamRequest object that is used by | 311 // Creates a tab capture specific MediaStreamRequest object that is used by |
| 312 // this request when UI is asked for permission and device selection. | 312 // this request when UI is asked for permission and device selection. |
| 313 void CreateTabCaptureUIRequest(int target_render_process_id, | 313 void CreateTabCaptureUIRequest(int target_render_process_id, |
| 314 int target_render_frame_id) { | 314 int target_render_frame_id) { |
| 315 DCHECK(!ui_request_); | 315 DCHECK(!ui_request_); |
| 316 target_process_id_ = target_render_process_id; | 316 target_process_id_ = target_render_process_id; |
| 317 target_frame_id_ = target_render_frame_id; | 317 target_frame_id_ = target_render_frame_id; |
| 318 ui_request_.reset(new MediaStreamRequest( | 318 ui_request_.reset(new MediaStreamRequest( |
| 319 target_render_process_id, target_render_frame_id, page_request_id, | 319 target_render_process_id, target_render_frame_id, page_request_id, |
| 320 security_origin.GetURL(), user_gesture, request_type, "", "", | 320 security_origin.GetURL(), user_gesture, request_type, "", "", |
| 321 audio_type_, video_type_)); | 321 audio_type_, video_type_, controls.disable_local_echo)); |
| 322 } | 322 } |
| 323 | 323 |
| 324 bool HasUIRequest() const { return ui_request_.get() != nullptr; } | 324 bool HasUIRequest() const { return ui_request_.get() != nullptr; } |
| 325 std::unique_ptr<MediaStreamRequest> DetachUIRequest() { | 325 std::unique_ptr<MediaStreamRequest> DetachUIRequest() { |
| 326 return std::move(ui_request_); | 326 return std::move(ui_request_); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Update the request state and notify observers. | 329 // Update the request state and notify observers. |
| 330 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { | 330 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { |
| 331 if (stream_type == NUM_MEDIA_TYPES) { | 331 if (stream_type == NUM_MEDIA_TYPES) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 bool user_gesture) { | 528 bool user_gesture) { |
| 529 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 529 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 530 DVLOG(1) << "GenerateStream()"; | 530 DVLOG(1) << "GenerateStream()"; |
| 531 | 531 |
| 532 DeviceRequest* request = new DeviceRequest( | 532 DeviceRequest* request = new DeviceRequest( |
| 533 requester, render_process_id, render_frame_id, page_request_id, | 533 requester, render_process_id, render_frame_id, page_request_id, |
| 534 security_origin, user_gesture, MEDIA_GENERATE_STREAM, controls, salt); | 534 security_origin, user_gesture, MEDIA_GENERATE_STREAM, controls, salt); |
| 535 | 535 |
| 536 const std::string& label = AddRequest(request); | 536 const std::string& label = AddRequest(request); |
| 537 | 537 |
| 538 if (!generate_stream_test_callback_.is_null()) { |
| 539 // The test callback is responsible to verify whether the |controls| is |
| 540 // as expected. Then we need to finish getUserMedia and let Javascript |
| 541 // access the result. |
| 542 if (generate_stream_test_callback_.Run(controls)) { |
| 543 FinalizeGenerateStream(label, request); |
| 544 } else { |
| 545 FinalizeRequestFailed(label, request, MEDIA_DEVICE_INVALID_STATE); |
| 546 } |
| 547 return; |
| 548 } |
| 549 |
| 538 // Post a task and handle the request asynchronously. The reason is that the | 550 // Post a task and handle the request asynchronously. The reason is that the |
| 539 // requester won't have a label for the request until this function returns | 551 // requester won't have a label for the request until this function returns |
| 540 // and thus can not handle a response. Using base::Unretained is safe since | 552 // and thus can not handle a response. Using base::Unretained is safe since |
| 541 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 553 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
| 542 // been stopped. | 554 // been stopped. |
| 543 BrowserThread::PostTask( | 555 BrowserThread::PostTask( |
| 544 BrowserThread::IO, FROM_HERE, | 556 BrowserThread::IO, FROM_HERE, |
| 545 base::Bind(&MediaStreamManager::SetupRequest, | 557 base::Bind(&MediaStreamManager::SetupRequest, |
| 546 base::Unretained(this), label)); | 558 base::Unretained(this), label)); |
| 547 } | 559 } |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 std::string capture_device_id; | 1184 std::string capture_device_id; |
| 1173 if (!request->controls.audio.device_ids.empty()) { | 1185 if (!request->controls.audio.device_ids.empty()) { |
| 1174 capture_device_id = request->controls.audio.device_ids[0]; | 1186 capture_device_id = request->controls.audio.device_ids[0]; |
| 1175 } else if (!request->controls.video.device_ids.empty()) { | 1187 } else if (!request->controls.video.device_ids.empty()) { |
| 1176 capture_device_id = request->controls.video.device_ids[0]; | 1188 capture_device_id = request->controls.video.device_ids[0]; |
| 1177 } else { | 1189 } else { |
| 1178 return false; | 1190 return false; |
| 1179 } | 1191 } |
| 1180 | 1192 |
| 1181 // Customize controls for a WebContents based capture. | 1193 // Customize controls for a WebContents based capture. |
| 1182 int target_render_process_id = 0; | 1194 content::WebContentsMediaCaptureId web_id; |
| 1183 int target_render_frame_id = 0; | 1195 bool has_valid_device_id = |
| 1184 | 1196 WebContentsMediaCaptureId::Parse(capture_device_id, &web_id); |
| 1185 bool has_valid_device_id = WebContentsMediaCaptureId::ExtractTabCaptureTarget( | |
| 1186 capture_device_id, &target_render_process_id, &target_render_frame_id); | |
| 1187 if (!has_valid_device_id || | 1197 if (!has_valid_device_id || |
| 1188 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && | 1198 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && |
| 1189 request->audio_type() != MEDIA_NO_SERVICE) || | 1199 request->audio_type() != MEDIA_NO_SERVICE) || |
| 1190 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && | 1200 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && |
| 1191 request->video_type() != MEDIA_NO_SERVICE)) { | 1201 request->video_type() != MEDIA_NO_SERVICE)) { |
| 1192 return false; | 1202 return false; |
| 1193 } | 1203 } |
| 1194 request->tab_capture_device_id = capture_device_id; | 1204 web_id.disable_local_echo = request->controls.disable_local_echo; |
| 1195 | 1205 |
| 1196 request->CreateTabCaptureUIRequest(target_render_process_id, | 1206 request->tab_capture_device_id = web_id.ToString(); |
| 1197 target_render_frame_id); | 1207 |
| 1208 request->CreateTabCaptureUIRequest(web_id.render_process_id, |
| 1209 web_id.main_render_frame_id); |
| 1198 | 1210 |
| 1199 DVLOG(3) << "SetupTabCaptureRequest " | 1211 DVLOG(3) << "SetupTabCaptureRequest " |
| 1200 << ", {capture_device_id = " << capture_device_id << "}" | 1212 << ", {capture_device_id = " << capture_device_id << "}" |
| 1201 << ", {target_render_process_id = " << target_render_process_id | 1213 << ", {target_render_process_id = " << web_id.render_process_id |
| 1202 << "}" | 1214 << "}" |
| 1203 << ", {target_render_frame_id = " << target_render_frame_id << "}"; | 1215 << ", {target_render_frame_id = " << web_id.main_render_frame_id |
| 1216 << "}"; |
| 1204 return true; | 1217 return true; |
| 1205 } | 1218 } |
| 1206 | 1219 |
| 1207 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { | 1220 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { |
| 1208 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE || | 1221 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE || |
| 1209 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE); | 1222 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE); |
| 1210 | 1223 |
| 1211 // For screen capture we only support two valid combinations: | 1224 // For screen capture we only support two valid combinations: |
| 1212 // (1) screen video capture only, or | 1225 // (1) screen video capture only, or |
| 1213 // (2) screen video capture with loopback audio capture. | 1226 // (2) screen video capture with loopback audio capture. |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2024 if (request->request_type == MEDIA_ENUMERATE_DEVICES && | 2037 if (request->request_type == MEDIA_ENUMERATE_DEVICES && |
| 2025 request->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && | 2038 request->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && |
| 2026 (request->audio_type() == stream_type || | 2039 (request->audio_type() == stream_type || |
| 2027 request->video_type() == stream_type)) { | 2040 request->video_type() == stream_type)) { |
| 2028 ProcessEnumerationRequest(labeled_request.first, request, stream_type, | 2041 ProcessEnumerationRequest(labeled_request.first, request, stream_type, |
| 2029 device_infos); | 2042 device_infos); |
| 2030 } | 2043 } |
| 2031 } | 2044 } |
| 2032 } | 2045 } |
| 2033 | 2046 |
| 2047 void MediaStreamManager::SetGenerateStreamCallbackForTesting( |
| 2048 GenerateStreamTestCallback test_callback) { |
| 2049 generate_stream_test_callback_ = test_callback; |
| 2050 } |
| 2051 |
| 2034 } // namespace content | 2052 } // namespace content |
| OLD | NEW |