Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 2291893002: Let Contraints Controll Mute/Unmute Audio Local Playback For Desktop Sharing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // is asked for permission and device selection. 302 // is asked for permission and device selection.
303 void CreateUIRequest(const std::string& requested_audio_device_id, 303 void CreateUIRequest(const std::string& requested_audio_device_id,
304 const std::string& requested_video_device_id) { 304 const std::string& requested_video_device_id) {
305 DCHECK(!ui_request_); 305 DCHECK(!ui_request_);
306 target_process_id_ = requesting_process_id; 306 target_process_id_ = requesting_process_id;
307 target_frame_id_ = requesting_frame_id; 307 target_frame_id_ = requesting_frame_id;
308 ui_request_.reset(new MediaStreamRequest( 308 ui_request_.reset(new MediaStreamRequest(
309 requesting_process_id, requesting_frame_id, page_request_id, 309 requesting_process_id, requesting_frame_id, page_request_id,
310 ConvertToGURL(security_origin), user_gesture, request_type, 310 ConvertToGURL(security_origin), user_gesture, request_type,
311 requested_audio_device_id, requested_video_device_id, audio_type_, 311 requested_audio_device_id, requested_video_device_id, audio_type_,
312 video_type_)); 312 video_type_, controls.disable_local_echo));
313 } 313 }
314 314
315 // Creates a tab capture specific MediaStreamRequest object that is used by 315 // Creates a tab capture specific MediaStreamRequest object that is used by
316 // this request when UI is asked for permission and device selection. 316 // this request when UI is asked for permission and device selection.
317 void CreateTabCaptureUIRequest(int target_render_process_id, 317 void CreateTabCaptureUIRequest(int target_render_process_id,
318 int target_render_frame_id) { 318 int target_render_frame_id) {
319 DCHECK(!ui_request_); 319 DCHECK(!ui_request_);
320 target_process_id_ = target_render_process_id; 320 target_process_id_ = target_render_process_id;
321 target_frame_id_ = target_render_frame_id; 321 target_frame_id_ = target_render_frame_id;
322 ui_request_.reset(new MediaStreamRequest( 322 ui_request_.reset(new MediaStreamRequest(
323 target_render_process_id, target_render_frame_id, page_request_id, 323 target_render_process_id, target_render_frame_id, page_request_id,
324 ConvertToGURL(security_origin), user_gesture, request_type, "", "", 324 ConvertToGURL(security_origin), user_gesture, request_type, "", "",
325 audio_type_, video_type_)); 325 audio_type_, video_type_, controls.disable_local_echo));
326 } 326 }
327 327
328 bool HasUIRequest() const { return ui_request_.get() != nullptr; } 328 bool HasUIRequest() const { return ui_request_.get() != nullptr; }
329 std::unique_ptr<MediaStreamRequest> DetachUIRequest() { 329 std::unique_ptr<MediaStreamRequest> DetachUIRequest() {
330 return std::move(ui_request_); 330 return std::move(ui_request_);
331 } 331 }
332 332
333 // Update the request state and notify observers. 333 // Update the request state and notify observers.
334 void SetState(MediaStreamType stream_type, MediaRequestState new_state) { 334 void SetState(MediaStreamType stream_type, MediaRequestState new_state) {
335 if (stream_type == NUM_MEDIA_TYPES) { 335 if (stream_type == NUM_MEDIA_TYPES) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 bool user_gesture) { 539 bool user_gesture) {
540 DCHECK_CURRENTLY_ON(BrowserThread::IO); 540 DCHECK_CURRENTLY_ON(BrowserThread::IO);
541 DVLOG(1) << "GenerateStream()"; 541 DVLOG(1) << "GenerateStream()";
542 542
543 DeviceRequest* request = new DeviceRequest( 543 DeviceRequest* request = new DeviceRequest(
544 requester, render_process_id, render_frame_id, page_request_id, 544 requester, render_process_id, render_frame_id, page_request_id,
545 security_origin, user_gesture, MEDIA_GENERATE_STREAM, controls, salt); 545 security_origin, user_gesture, MEDIA_GENERATE_STREAM, controls, salt);
546 546
547 const std::string& label = AddRequest(request); 547 const std::string& label = AddRequest(request);
548 548
549 if (!generate_stream_test_callback_.is_null()) {
550 // The test callback is responsible to verify whether the |controls| is
551 // as expected. Then we need to finish getUserMedia and let Javascript
552 // access the result.
553 if (generate_stream_test_callback_.Run(controls)) {
554 FinalizeGenerateStream(label, request);
555 } else {
556 FinalizeRequestFailed(label, request, MEDIA_DEVICE_INVALID_STATE);
557 }
558 return;
559 }
560
549 // Post a task and handle the request asynchronously. The reason is that the 561 // Post a task and handle the request asynchronously. The reason is that the
550 // requester won't have a label for the request until this function returns 562 // requester won't have a label for the request until this function returns
551 // and thus can not handle a response. Using base::Unretained is safe since 563 // and thus can not handle a response. Using base::Unretained is safe since
552 // MediaStreamManager is deleted on the UI thread, after the IO thread has 564 // MediaStreamManager is deleted on the UI thread, after the IO thread has
553 // been stopped. 565 // been stopped.
554 BrowserThread::PostTask( 566 BrowserThread::PostTask(
555 BrowserThread::IO, FROM_HERE, 567 BrowserThread::IO, FROM_HERE,
556 base::Bind(&MediaStreamManager::SetupRequest, 568 base::Bind(&MediaStreamManager::SetupRequest,
557 base::Unretained(this), label)); 569 base::Unretained(this), label));
558 } 570 }
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 std::string capture_device_id; 1191 std::string capture_device_id;
1180 if (!request->controls.audio.device_ids.empty()) { 1192 if (!request->controls.audio.device_ids.empty()) {
1181 capture_device_id = request->controls.audio.device_ids[0]; 1193 capture_device_id = request->controls.audio.device_ids[0];
1182 } else if (!request->controls.video.device_ids.empty()) { 1194 } else if (!request->controls.video.device_ids.empty()) {
1183 capture_device_id = request->controls.video.device_ids[0]; 1195 capture_device_id = request->controls.video.device_ids[0];
1184 } else { 1196 } else {
1185 return false; 1197 return false;
1186 } 1198 }
1187 1199
1188 // Customize controls for a WebContents based capture. 1200 // Customize controls for a WebContents based capture.
1189 int target_render_process_id = 0; 1201 content::WebContentsMediaCaptureId web_id;
1190 int target_render_frame_id = 0; 1202 bool has_valid_device_id =
1191 1203 WebContentsMediaCaptureId::Parse(capture_device_id, &web_id);
1192 bool has_valid_device_id = WebContentsMediaCaptureId::ExtractTabCaptureTarget(
1193 capture_device_id, &target_render_process_id, &target_render_frame_id);
1194 if (!has_valid_device_id || 1204 if (!has_valid_device_id ||
1195 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && 1205 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE &&
1196 request->audio_type() != MEDIA_NO_SERVICE) || 1206 request->audio_type() != MEDIA_NO_SERVICE) ||
1197 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && 1207 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE &&
1198 request->video_type() != MEDIA_NO_SERVICE)) { 1208 request->video_type() != MEDIA_NO_SERVICE)) {
1199 return false; 1209 return false;
1200 } 1210 }
1201 request->tab_capture_device_id = capture_device_id; 1211 web_id.disable_local_echo = request->controls.disable_local_echo;
1202 1212
1203 request->CreateTabCaptureUIRequest(target_render_process_id, 1213 request->tab_capture_device_id = web_id.ToString();
1204 target_render_frame_id); 1214
1215 request->CreateTabCaptureUIRequest(web_id.render_process_id,
1216 web_id.main_render_frame_id);
1205 1217
1206 DVLOG(3) << "SetupTabCaptureRequest " 1218 DVLOG(3) << "SetupTabCaptureRequest "
1207 << ", {capture_device_id = " << capture_device_id << "}" 1219 << ", {capture_device_id = " << capture_device_id << "}"
1208 << ", {target_render_process_id = " << target_render_process_id 1220 << ", {target_render_process_id = " << web_id.render_process_id
1209 << "}" 1221 << "}"
1210 << ", {target_render_frame_id = " << target_render_frame_id << "}"; 1222 << ", {target_render_frame_id = " << web_id.main_render_frame_id
1223 << "}";
1211 return true; 1224 return true;
1212 } 1225 }
1213 1226
1214 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { 1227 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) {
1215 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE || 1228 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE ||
1216 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE); 1229 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE);
1217 1230
1218 // For screen capture we only support two valid combinations: 1231 // For screen capture we only support two valid combinations:
1219 // (1) screen video capture only, or 1232 // (1) screen video capture only, or
1220 // (2) screen video capture with loopback audio capture. 1233 // (2) screen video capture with loopback audio capture.
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 if (request->request_type == MEDIA_ENUMERATE_DEVICES && 2048 if (request->request_type == MEDIA_ENUMERATE_DEVICES &&
2036 request->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && 2049 request->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED &&
2037 (request->audio_type() == stream_type || 2050 (request->audio_type() == stream_type ||
2038 request->video_type() == stream_type)) { 2051 request->video_type() == stream_type)) {
2039 ProcessEnumerationRequest(labeled_request.first, request, stream_type, 2052 ProcessEnumerationRequest(labeled_request.first, request, stream_type,
2040 device_infos); 2053 device_infos);
2041 } 2054 }
2042 } 2055 }
2043 } 2056 }
2044 2057
2058 void MediaStreamManager::SetGenerateStreamCallbackForTesting(
2059 GenerateStreamTestCallback test_callback) {
2060 generate_stream_test_callback_ = test_callback;
2061 }
2062
2045 } // namespace content 2063 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698