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

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: Rebase Created 4 years, 3 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 #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
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_, mute_source));
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_, mute_source));
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 // Callback to the requester which audio/video devices have been selected. 348 // Callback to the requester which audio/video devices have been selected.
349 // It can be null if the requester has no interest to know the result. 349 // It can be null if the requester has no interest to know the result.
350 // Currently it is only used by |DEVICE_ACCESS| type. 350 // Currently it is only used by |DEVICE_ACCESS| type.
351 MediaStreamManager::MediaRequestResponseCallback callback; 351 MediaStreamManager::MediaRequestResponseCallback callback;
352 352
353 std::unique_ptr<MediaStreamUIProxy> ui_proxy; 353 std::unique_ptr<MediaStreamUIProxy> ui_proxy;
354 354
355 std::string tab_capture_device_id; 355 std::string tab_capture_device_id;
356 356
357 bool mute_source;
miu 2016/09/12 23:13:12 naming nit: We're not really muting the source, we
qiangchen 2016/09/13 21:46:57 Done.
358
357 private: 359 private:
358 std::vector<MediaRequestState> state_; 360 std::vector<MediaRequestState> state_;
359 std::unique_ptr<MediaStreamRequest> ui_request_; 361 std::unique_ptr<MediaStreamRequest> ui_request_;
360 MediaStreamType audio_type_; 362 MediaStreamType audio_type_;
361 MediaStreamType video_type_; 363 MediaStreamType video_type_;
362 int target_process_id_; 364 int target_process_id_;
363 int target_frame_id_; 365 int target_frame_id_;
364 }; 366 };
365 367
366 MediaStreamManager::EnumerationCache::EnumerationCache() 368 MediaStreamManager::EnumerationCache::EnumerationCache()
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 std::string capture_device_id; 1303 std::string capture_device_id;
1302 if (!request->controls.audio.device_ids.empty()) { 1304 if (!request->controls.audio.device_ids.empty()) {
1303 capture_device_id = request->controls.audio.device_ids[0]; 1305 capture_device_id = request->controls.audio.device_ids[0];
1304 } else if (!request->controls.video.device_ids.empty()) { 1306 } else if (!request->controls.video.device_ids.empty()) {
1305 capture_device_id = request->controls.video.device_ids[0]; 1307 capture_device_id = request->controls.video.device_ids[0];
1306 } else { 1308 } else {
1307 return false; 1309 return false;
1308 } 1310 }
1309 1311
1310 // Customize controls for a WebContents based capture. 1312 // Customize controls for a WebContents based capture.
1311 int target_render_process_id = 0; 1313 content::WebContentsMediaCaptureId web_id;
1312 int target_render_frame_id = 0; 1314 bool has_valid_device_id =
1313 1315 WebContentsMediaCaptureId::TryParse(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 || 1316 if (!has_valid_device_id ||
1317 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && 1317 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE &&
1318 request->audio_type() != MEDIA_NO_SERVICE) || 1318 request->audio_type() != MEDIA_NO_SERVICE) ||
1319 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE && 1319 (request->video_type() != MEDIA_TAB_VIDEO_CAPTURE &&
1320 request->video_type() != MEDIA_NO_SERVICE)) { 1320 request->video_type() != MEDIA_NO_SERVICE)) {
1321 return false; 1321 return false;
1322 } 1322 }
1323 request->tab_capture_device_id = capture_device_id; 1323 request->mute_source = request->controls.mute_source_audio;
1324 web_id.mute_source = request->mute_source;
1324 1325
1325 request->CreateTabCaptureUIRequest(target_render_process_id, 1326 request->tab_capture_device_id = web_id.ToString();
1326 target_render_frame_id); 1327
1328 request->CreateTabCaptureUIRequest(web_id.render_process_id,
1329 web_id.main_render_frame_id);
1327 1330
1328 DVLOG(3) << "SetupTabCaptureRequest " 1331 DVLOG(3) << "SetupTabCaptureRequest "
1329 << ", {capture_device_id = " << capture_device_id << "}" 1332 << ", {capture_device_id = " << capture_device_id << "}"
1330 << ", {target_render_process_id = " << target_render_process_id 1333 << ", {target_render_process_id = " << web_id.render_process_id
1331 << "}" 1334 << "}"
1332 << ", {target_render_frame_id = " << target_render_frame_id << "}"; 1335 << ", {target_render_frame_id = " << web_id.main_render_frame_id
1336 << "}";
1333 return true; 1337 return true;
1334 } 1338 }
1335 1339
1336 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { 1340 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) {
1337 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE || 1341 DCHECK(request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE ||
1338 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE); 1342 request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE);
1339 1343
1340 // For screen capture we only support two valid combinations: 1344 // For screen capture we only support two valid combinations:
1341 // (1) screen video capture only, or 1345 // (1) screen video capture only, or
1342 // (2) screen video capture with loopback audio capture. 1346 // (2) screen video capture with loopback audio capture.
1343 if (request->video_type() != MEDIA_DESKTOP_VIDEO_CAPTURE || 1347 if (request->video_type() != MEDIA_DESKTOP_VIDEO_CAPTURE ||
1344 (request->audio_type() != MEDIA_NO_SERVICE && 1348 (request->audio_type() != MEDIA_NO_SERVICE &&
1345 request->audio_type() != MEDIA_DESKTOP_AUDIO_CAPTURE)) { 1349 request->audio_type() != MEDIA_DESKTOP_AUDIO_CAPTURE)) {
1346 LOG(ERROR) << "Invalid screen capture request."; 1350 LOG(ERROR) << "Invalid screen capture request.";
1347 return false; 1351 return false;
1348 } 1352 }
1349 1353
1350 std::string video_device_id; 1354 std::string video_device_id;
1351 if (request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) { 1355 if (request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) {
1352 const std::string& video_stream_source = 1356 const std::string& video_stream_source =
1353 request->controls.video.stream_source; 1357 request->controls.video.stream_source;
1354 1358
1355 if (video_stream_source == kMediaStreamSourceDesktop && 1359 if (video_stream_source == kMediaStreamSourceDesktop &&
1356 !request->controls.video.device_ids.empty()) { 1360 !request->controls.video.device_ids.empty()) {
1357 video_device_id = request->controls.video.device_ids[0]; 1361 video_device_id = request->controls.video.device_ids[0];
1358 } 1362 }
1363 request->mute_source = request->controls.mute_source_audio;
1359 } 1364 }
1360 1365
1361 const std::string audio_device_id = 1366 const std::string audio_device_id =
1362 request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE ? video_device_id 1367 request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE ? video_device_id
1363 : ""; 1368 : "";
1364 1369
1365 request->CreateUIRequest(audio_device_id, video_device_id); 1370 request->CreateUIRequest(audio_device_id, video_device_id);
1366 return true; 1371 return true;
1367 } 1372 }
1368 1373
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
2183 if (device_info.session_id == session_id && 2188 if (device_info.session_id == session_id &&
2184 device_info.device.type == type) { 2189 device_info.device.type == type) {
2185 request->SetCapturingLinkSecured(is_secure); 2190 request->SetCapturingLinkSecured(is_secure);
2186 return; 2191 return;
2187 } 2192 }
2188 } 2193 }
2189 } 2194 }
2190 } 2195 }
2191 2196
2192 } // namespace content 2197 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698