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

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

Issue 11298006: Browser-wide audio mirroring for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TabCapture API test Created 8 years, 1 month 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 | Annotate | Revision Log
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 <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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 if (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && 103 if (options.video_type != MEDIA_TAB_VIDEO_CAPTURE &&
104 options.audio_type != MEDIA_TAB_AUDIO_CAPTURE) 104 options.audio_type != MEDIA_TAB_AUDIO_CAPTURE)
105 return; 105 return;
106 106
107 MediaObserver* media_observer = 107 MediaObserver* media_observer =
108 GetContentClient()->browser()->GetMediaObserver(); 108 GetContentClient()->browser()->GetMediaObserver();
109 if (media_observer == NULL) 109 if (media_observer == NULL)
110 return; 110 return;
111 111
112 std::string device_id = requested_device_id;
113 if (WebContentsCaptureUtil::IsWebContentsDeviceId(requested_device_id))
114 device_id = WebContentsCaptureUtil::StripWebContentsDeviceScheme(
115 requested_device_id);
116
112 media_observer->OnMediaRequestStateChanged( 117 media_observer->OnMediaRequestStateChanged(
113 render_process_id, render_view_id, 118 render_process_id, render_view_id,
114 MediaStreamDevice( 119 MediaStreamDevice(
115 stream_type, requested_device_id, requested_device_id), new_state); 120 stream_type, device_id, device_id), new_state);
116 } 121 }
117 122
118 MediaRequestState getState(MediaStreamType stream_type) const { 123 MediaRequestState getState(MediaStreamType stream_type) const {
119 return state_[stream_type]; 124 return state_[stream_type];
120 } 125 }
121 126
122 MediaStreamRequester* requester; // Can be NULL. 127 MediaStreamRequester* requester; // Can be NULL.
123 StreamOptions options; 128 StreamOptions options;
124 RequestType type; 129 RequestType type;
125 int render_process_id; 130 int render_process_id;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const GURL& security_origin, std::string* label) { 244 const GURL& security_origin, std::string* label) {
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
241 246
242 // Create a new request based on options. 247 // Create a new request based on options.
243 AddRequest(DeviceRequest(requester, options, 248 AddRequest(DeviceRequest(requester, options,
244 DeviceRequest::GENERATE_STREAM, 249 DeviceRequest::GENERATE_STREAM,
245 render_process_id, render_view_id, 250 render_process_id, render_view_id,
246 security_origin), 251 security_origin),
247 label); 252 label);
248 DeviceRequest& request = requests_[*label]; 253 DeviceRequest& request = requests_[*label];
254
249 request.requested_device_id = device_id; 255 request.requested_device_id = device_id;
250 256
251 // Get user confirmation to use the capture device. 257 // Get user confirmation to use the capture device.
252 PostRequestToUI(*label); 258 PostRequestToUI(*label);
253 259
254 if (!security_origin.SchemeIs(kExtensionScheme) || 260 if (!security_origin.SchemeIs(kExtensionScheme) ||
255 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && 261 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE &&
256 options.audio_type != MEDIA_NO_SERVICE) || 262 options.audio_type != MEDIA_NO_SERVICE) ||
257 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && 263 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE &&
258 options.video_type != MEDIA_NO_SERVICE)) { 264 options.video_type != MEDIA_NO_SERVICE)) {
259 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; 265 LOG(ERROR) << "Invalid request or used tab capture outside extension API.";
260 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 266 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
261 base::Bind(&MediaStreamManager::CancelRequest, 267 base::Bind(&MediaStreamManager::CancelRequest,
262 base::Unretained(this), *label)); 268 base::Unretained(this), *label));
263 return; 269 return;
264 } 270 }
265 271
266 // TODO(miu): We should ask the device manager whether a device with id 272 // TODO(miu): We should ask the device manager whether a device with id
267 // |device_id| actually exists. Note that no such MediaStreamProvider API for 273 // |device_id| actually exists. Note that no such MediaStreamProvider API for
268 // this currently exists. Also, we don't have a user-friendly device name for 274 // this currently exists. Also, we don't have a user-friendly device name for
269 // the infobar UI. 275 // the infobar UI.
270 if (IsAudioMediaType(options.audio_type)) { 276 if (IsAudioMediaType(options.audio_type)) {
271 // TODO(justinlin): Updating the state to requested and pending are no-ops 277 // TODO(justinlin): Updating the state to requested and pending are no-ops
272 // in terms of the media manager, but these are the state changes we want to 278 // in terms of the media manager, but these are the state changes we want to
273 // support in terms of extensions (which is registered as an observer). 279 // support in terms of extensions (which is registered as an observer).
274 request.setState(options.audio_type, MEDIA_REQUEST_STATE_REQUESTED); 280 request.setState(options.audio_type, MEDIA_REQUEST_STATE_REQUESTED);
275 request.setState(options.audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); 281 request.setState(options.audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL);
276 ui_controller_->AddAvailableDevicesToRequest( 282 ui_controller_->AddAvailableDevicesToRequest(
277 *label, options.audio_type, StreamDeviceInfoArray( 283 *label, options.audio_type, StreamDeviceInfoArray(
278 1, StreamDeviceInfo(options.audio_type, device_id, device_id, 284 1, StreamDeviceInfo(options.audio_type,
285 device_id,
286 device_id,
279 false))); 287 false)));
280 } 288 }
281 if (IsVideoMediaType(options.video_type)) { 289 if (IsVideoMediaType(options.video_type)) {
282 request.setState(options.video_type, MEDIA_REQUEST_STATE_REQUESTED); 290 request.setState(options.video_type, MEDIA_REQUEST_STATE_REQUESTED);
283 request.setState(options.video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); 291 request.setState(options.video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL);
284 ui_controller_->AddAvailableDevicesToRequest( 292 ui_controller_->AddAvailableDevicesToRequest(
285 *label, options.video_type, StreamDeviceInfoArray( 293 *label, options.video_type, StreamDeviceInfoArray(
286 1, StreamDeviceInfo(options.video_type, device_id, device_id, 294 1, StreamDeviceInfo(options.video_type,
295 device_id,
296 device_id,
287 false))); 297 false)));
288 } 298 }
289 } 299 }
290 300
291 void MediaStreamManager::CancelRequest(const std::string& label) { 301 void MediaStreamManager::CancelRequest(const std::string& label) {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
293 303
294 DeviceRequests::iterator it = requests_.find(label); 304 DeviceRequests::iterator it = requests_.find(label);
295 if (it != requests_.end()) { 305 if (it != requests_.end()) {
296 // The request isn't complete, notify the UI immediately. 306 // The request isn't complete, notify the UI immediately.
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 } 1060 }
1051 1061
1052 // Always do enumeration even though some enumeration is in progress, 1062 // Always do enumeration even though some enumeration is in progress,
1053 // because those enumeration commands could be sent before these devices 1063 // because those enumeration commands could be sent before these devices
1054 // change. 1064 // change.
1055 ++active_enumeration_ref_count_[stream_type]; 1065 ++active_enumeration_ref_count_[stream_type];
1056 GetDeviceManager(stream_type)->EnumerateDevices(); 1066 GetDeviceManager(stream_type)->EnumerateDevices();
1057 } 1067 }
1058 1068
1059 } // namespace content 1069 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698