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 <list> | 7 #include <list> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/run_loop.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 17 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
17 #include "content/browser/renderer_host/media/device_request_message_filter.h" | 18 #include "content/browser/renderer_host/media/device_request_message_filter.h" |
18 #include "content/browser/renderer_host/media/media_stream_requester.h" | 19 #include "content/browser/renderer_host/media/media_stream_requester.h" |
19 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 20 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
20 #include "content/browser/renderer_host/media/video_capture_manager.h" | 21 #include "content/browser/renderer_host/media/video_capture_manager.h" |
21 #include "content/browser/renderer_host/media/web_contents_capture_util.h" | 22 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
24 #include "content/public/browser/media_device_id.h" | 25 #include "content/public/browser/media_device_id.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return label; | 57 return label; |
57 } | 58 } |
58 | 59 |
59 // Helper to verify if a media stream type is part of options or not. | 60 // Helper to verify if a media stream type is part of options or not. |
60 static bool Requested(const MediaStreamRequest& request, | 61 static bool Requested(const MediaStreamRequest& request, |
61 MediaStreamType stream_type) { | 62 MediaStreamType stream_type) { |
62 return (request.audio_type == stream_type || | 63 return (request.audio_type == stream_type || |
63 request.video_type == stream_type); | 64 request.video_type == stream_type); |
64 } | 65 } |
65 | 66 |
66 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. | |
67 class MediaStreamManager::DeviceRequest { | 67 class MediaStreamManager::DeviceRequest { |
68 public: | 68 public: |
69 DeviceRequest(MediaStreamRequester* requester, | 69 DeviceRequest(MediaStreamRequester* requester, |
70 const MediaStreamRequest& request, | 70 const MediaStreamRequest& request, |
71 int requesting_process_id, | 71 int requesting_process_id, |
72 int requesting_view_id) | 72 int requesting_view_id) |
73 : requester(requester), | 73 : requester(requester), |
74 request(request), | 74 request(request), |
75 requesting_process_id(requesting_process_id), | 75 requesting_process_id(requesting_process_id), |
76 requesting_view_id(requesting_view_id), | 76 requesting_view_id(requesting_view_id), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 InitializeDeviceManagersOnIOThread(); | 174 InitializeDeviceManagersOnIOThread(); |
175 } else { | 175 } else { |
176 BrowserThread::PostTask( | 176 BrowserThread::PostTask( |
177 BrowserThread::IO, FROM_HERE, | 177 BrowserThread::IO, FROM_HERE, |
178 base::Bind(&MediaStreamManager::InitializeDeviceManagersOnIOThread, | 178 base::Bind(&MediaStreamManager::InitializeDeviceManagersOnIOThread, |
179 base::Unretained(this))); | 179 base::Unretained(this))); |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 MediaStreamManager::~MediaStreamManager() { | 183 MediaStreamManager::~MediaStreamManager() { |
| 184 DVLOG(1) << "~MediaStreamManager"; |
184 DCHECK(requests_.empty()); | 185 DCHECK(requests_.empty()); |
185 DCHECK(!device_thread_.get()); | 186 DCHECK(!device_thread_.get()); |
186 } | 187 } |
187 | 188 |
188 VideoCaptureManager* MediaStreamManager::video_capture_manager() { | 189 VideoCaptureManager* MediaStreamManager::video_capture_manager() { |
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
190 DCHECK(video_capture_manager_.get()); | 191 DCHECK(video_capture_manager_.get()); |
191 return video_capture_manager_.get(); | 192 return video_capture_manager_.get(); |
192 } | 193 } |
193 | 194 |
194 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { | 195 AudioInputDeviceManager* MediaStreamManager::audio_input_device_manager() { |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
196 DCHECK(audio_input_device_manager_.get()); | 197 DCHECK(audio_input_device_manager_.get()); |
197 return audio_input_device_manager_.get(); | 198 return audio_input_device_manager_.get(); |
198 } | 199 } |
199 | 200 |
200 std::string MediaStreamManager::MakeMediaAccessRequest( | 201 std::string MediaStreamManager::MakeMediaAccessRequest( |
201 int render_process_id, | 202 int render_process_id, |
202 int render_view_id, | 203 int render_view_id, |
203 int page_request_id, | 204 int page_request_id, |
204 const StreamOptions& options, | 205 const StreamOptions& options, |
205 const GURL& security_origin, | 206 const GURL& security_origin, |
206 const MediaRequestResponseCallback& callback) { | 207 const MediaRequestResponseCallback& callback) { |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
208 // Create a new request based on options. | 209 // Create a new request based on options. |
209 MediaStreamRequest stream_request( | 210 MediaStreamRequest stream_request( |
210 render_process_id, render_view_id, page_request_id, std::string(), | 211 render_process_id, render_view_id, page_request_id, |
211 security_origin, MEDIA_DEVICE_ACCESS, std::string(), std::string(), | 212 security_origin, MEDIA_DEVICE_ACCESS, std::string(), std::string(), |
212 options.audio_type, options.video_type); | 213 options.audio_type, options.video_type); |
213 DeviceRequest* request = new DeviceRequest(NULL, stream_request, | 214 DeviceRequest* request = new DeviceRequest(NULL, stream_request, |
214 render_process_id, render_view_id); | 215 render_process_id, render_view_id); |
215 const std::string& label = AddRequest(request); | 216 const std::string& label = AddRequest(request); |
216 | 217 |
217 request->callback = callback; | 218 request->callback = callback; |
218 | 219 // Post a task and handle the request asynchronously. The reason is that the |
219 HandleRequest(label); | 220 // requester won't have a label for the request until this function returns |
220 | 221 // and thus can not handle a response. Using base::Unretained is safe since |
| 222 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
| 223 // been stopped. |
| 224 BrowserThread::PostTask( |
| 225 BrowserThread::IO, FROM_HERE, |
| 226 base::Bind(&MediaStreamManager::SetupRequest, |
| 227 base::Unretained(this), label)); |
221 return label; | 228 return label; |
222 } | 229 } |
223 | 230 |
224 std::string MediaStreamManager::GenerateStream( | 231 std::string MediaStreamManager::GenerateStream(MediaStreamRequester* requester, |
225 MediaStreamRequester* requester, | 232 int render_process_id, |
226 int render_process_id, | 233 int render_view_id, |
227 int render_view_id, | 234 int page_request_id, |
228 int page_request_id, | 235 const StreamOptions& options, |
229 const StreamOptions& options, | 236 const GURL& security_origin) { |
230 const GURL& security_origin) { | |
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 238 DVLOG(1) << "GenerateStream()"; |
232 if (CommandLine::ForCurrentProcess()->HasSwitch( | 239 if (CommandLine::ForCurrentProcess()->HasSwitch( |
233 switches::kUseFakeDeviceForMediaStream)) { | 240 switches::kUseFakeDeviceForMediaStream)) { |
234 UseFakeDevice(); | 241 UseFakeDevice(); |
235 } | 242 } |
236 if (CommandLine::ForCurrentProcess()->HasSwitch( | 243 if (CommandLine::ForCurrentProcess()->HasSwitch( |
237 switches::kUseFakeUIForMediaStream)) { | 244 switches::kUseFakeUIForMediaStream)) { |
238 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 245 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
239 } | 246 } |
240 | 247 |
241 int target_render_process_id = render_process_id; | |
242 int target_render_view_id = render_view_id; | |
243 std::string tab_capture_device_id; | |
244 | |
245 // Customize options for a WebContents based capture. | |
246 if (options.audio_type == MEDIA_TAB_AUDIO_CAPTURE || | |
247 options.video_type == MEDIA_TAB_VIDEO_CAPTURE) { | |
248 // TODO(justinlin): Can't plumb audio mirroring using stream type right | |
249 // now, so plumbing by device_id. Will revisit once it's refactored. | |
250 // http://crbug.com/163100 | |
251 tab_capture_device_id = | |
252 WebContentsCaptureUtil::AppendWebContentsDeviceScheme( | |
253 !options.video_device_id.empty() ? | |
254 options.video_device_id : options.audio_device_id); | |
255 | |
256 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
257 tab_capture_device_id, &target_render_process_id, | |
258 &target_render_view_id); | |
259 if (!has_valid_device_id || | |
260 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && | |
261 options.audio_type != MEDIA_NO_SERVICE) || | |
262 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && | |
263 options.video_type != MEDIA_NO_SERVICE)) { | |
264 LOG(ERROR) << "Invalid request."; | |
265 return std::string(); | |
266 } | |
267 } | |
268 | |
269 std::string translated_audio_device_id; | |
270 std::string translated_video_device_id; | |
271 if (options.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE) { | |
272 bool found_match = TranslateGUIDToRawId( | |
273 MEDIA_DEVICE_AUDIO_CAPTURE, security_origin, options.audio_device_id, | |
274 &translated_audio_device_id); | |
275 DCHECK(found_match || translated_audio_device_id.empty()); | |
276 } | |
277 | |
278 if (options.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { | |
279 bool found_match = TranslateGUIDToRawId( | |
280 MEDIA_DEVICE_VIDEO_CAPTURE, security_origin, options.video_device_id, | |
281 &translated_video_device_id); | |
282 DCHECK(found_match || translated_video_device_id.empty()); | |
283 } | |
284 | |
285 if (options.video_type == MEDIA_DESKTOP_VIDEO_CAPTURE || | |
286 options.audio_type == MEDIA_LOOPBACK_AUDIO_CAPTURE) { | |
287 // For screen capture we only support two valid combinations: | |
288 // (1) screen video capture only, or | |
289 // (2) screen video capture with loopback audio capture. | |
290 if (options.video_type != MEDIA_DESKTOP_VIDEO_CAPTURE || | |
291 (options.audio_type != MEDIA_NO_SERVICE && | |
292 options.audio_type != MEDIA_LOOPBACK_AUDIO_CAPTURE)) { | |
293 // TODO(sergeyu): Surface error message to the calling JS code. | |
294 LOG(ERROR) << "Invalid screen capture request."; | |
295 return std::string(); | |
296 } | |
297 translated_video_device_id = options.video_device_id; | |
298 } | |
299 | |
300 // Create a new request based on options. | 248 // Create a new request based on options. |
301 MediaStreamRequest stream_request( | 249 MediaStreamRequest stream_request( |
302 target_render_process_id, target_render_view_id, page_request_id, | 250 render_process_id, render_view_id, page_request_id, |
303 tab_capture_device_id, security_origin, MEDIA_GENERATE_STREAM, | 251 security_origin, MEDIA_GENERATE_STREAM, |
304 translated_audio_device_id, translated_video_device_id, | 252 options.audio_device_id, options.video_device_id, |
305 options.audio_type, options.video_type); | 253 options.audio_type, options.video_type); |
306 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 254 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
307 render_process_id, | 255 render_process_id, |
308 render_view_id); | 256 render_view_id); |
309 const std::string& label = AddRequest(request); | 257 const std::string& label = AddRequest(request); |
310 HandleRequest(label); | 258 |
| 259 // Post a task and handle the request asynchronously. The reason is that the |
| 260 // requester won't have a label for the request until this function returns |
| 261 // and thus can not handle a response. Using base::Unretained is safe since |
| 262 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
| 263 // been stopped. |
| 264 BrowserThread::PostTask( |
| 265 BrowserThread::IO, FROM_HERE, |
| 266 base::Bind(&MediaStreamManager::SetupRequest, |
| 267 base::Unretained(this), label)); |
311 return label; | 268 return label; |
312 } | 269 } |
313 | 270 |
314 void MediaStreamManager::CancelRequest(const std::string& label) { | 271 void MediaStreamManager::CancelRequest(const std::string& label) { |
315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
316 DVLOG(1) << "CancelRequest({label = " << label << "})"; | 273 DVLOG(1) << "CancelRequest({label = " << label << "})"; |
317 DeviceRequests::iterator request_it = requests_.find(label); | 274 DeviceRequest* request = FindRequest(label); |
318 if (request_it == requests_.end()) { | 275 if (!request) { |
319 NOTREACHED(); | 276 // The request does not exist. |
| 277 LOG(ERROR) << "The request with label = " << label << " does not exist."; |
320 return; | 278 return; |
321 } | 279 } |
322 scoped_ptr<DeviceRequest> request(request_it->second); | |
323 RemoveRequest(request_it); | |
324 | |
325 if (request->request.request_type == MEDIA_ENUMERATE_DEVICES) { | 280 if (request->request.request_type == MEDIA_ENUMERATE_DEVICES) { |
| 281 DeleteRequest(label); |
326 return; | 282 return; |
327 } | 283 } |
328 | 284 |
329 // This is a request for opening one or more devices. | 285 // This is a request for opening one or more devices. |
330 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); | 286 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); |
331 device_it != request->devices.end(); ++device_it) { | 287 device_it != request->devices.end(); ++device_it) { |
| 288 MediaRequestState state = request->state(device_it->device.type); |
332 // If we have not yet requested the device to be opened - just ignore it. | 289 // If we have not yet requested the device to be opened - just ignore it. |
333 if (request->state(device_it->device.type) != MEDIA_REQUEST_STATE_OPENING | 290 if (state != MEDIA_REQUEST_STATE_OPENING && |
334 && | 291 state != MEDIA_REQUEST_STATE_DONE) { |
335 request->state(device_it->device.type) != MEDIA_REQUEST_STATE_DONE) { | |
336 continue; | 292 continue; |
337 } | 293 } |
338 // Stop the opening/opened devices of the requests. | 294 // Stop the opening/opened devices of the requests. |
339 CloseDevice(device_it->device.type, device_it->session_id); | 295 CloseDevice(device_it->device.type, device_it->session_id); |
340 } | 296 } |
341 | 297 |
342 // Cancel the request if still pending at UI side. | 298 // Cancel the request if still pending at UI side. |
343 request->SetState(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_CLOSING); | 299 request->SetState(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_CLOSING); |
| 300 DeleteRequest(label); |
344 } | 301 } |
345 | 302 |
346 void MediaStreamManager::CancelAllRequests(int render_process_id) { | 303 void MediaStreamManager::CancelAllRequests(int render_process_id) { |
347 DeviceRequests::iterator request_it = requests_.begin(); | 304 DeviceRequests::iterator request_it = requests_.begin(); |
348 while (request_it != requests_.end()) { | 305 while (request_it != requests_.end()) { |
349 if (request_it->second->requesting_process_id != render_process_id) { | 306 if (request_it->second->requesting_process_id != render_process_id) { |
350 ++request_it; | 307 ++request_it; |
351 continue; | 308 continue; |
352 } | 309 } |
353 | 310 |
354 std::string label = request_it->first; | 311 std::string label = request_it->first; |
355 ++request_it; | 312 ++request_it; |
356 CancelRequest(label); | 313 CancelRequest(label); |
357 } | 314 } |
358 } | 315 } |
359 | 316 |
360 void MediaStreamManager::StopStreamDevice(int render_process_id, | 317 void MediaStreamManager::StopStreamDevice(int render_process_id, |
361 int render_view_id, | 318 int render_view_id, |
362 const std::string& device_id) { | 319 const std::string& device_id) { |
363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
364 DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " | 321 DVLOG(1) << "StopStreamDevice({render_view_id = " << render_view_id << "} " |
365 << ", {device_id = " << device_id << "})"; | 322 << ", {device_id = " << device_id << "})"; |
366 | |
367 // Find the first request for this |render_process_id| and |render_view_id| | 323 // Find the first request for this |render_process_id| and |render_view_id| |
368 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and | 324 // of type MEDIA_GENERATE_STREAM that has requested to use |device_id| and |
369 // stop it. | 325 // stop it. |
370 for (DeviceRequests::iterator request_it = requests_.begin(); | 326 for (DeviceRequests::iterator request_it = requests_.begin(); |
371 request_it != requests_.end(); ++request_it) { | 327 request_it != requests_.end(); ++request_it) { |
372 DeviceRequest* request = request_it->second; | 328 DeviceRequest* request = request_it->second; |
373 const MediaStreamRequest& ms_request = request->request; | 329 const MediaStreamRequest& ms_request = request->request; |
374 if (request->requesting_process_id != render_process_id || | 330 if (request->requesting_process_id != render_process_id || |
375 request->requesting_view_id != render_view_id || | 331 request->requesting_view_id != render_view_id || |
376 ms_request.request_type != MEDIA_GENERATE_STREAM) { | 332 ms_request.request_type != MEDIA_GENERATE_STREAM) { |
(...skipping 25 matching lines...) Expand all Loading... |
402 device_it->session_id != session_id) { | 358 device_it->session_id != session_id) { |
403 ++device_it; | 359 ++device_it; |
404 continue; | 360 continue; |
405 } | 361 } |
406 if (request->state(type) == MEDIA_REQUEST_STATE_DONE) | 362 if (request->state(type) == MEDIA_REQUEST_STATE_DONE) |
407 CloseDevice(type, session_id); | 363 CloseDevice(type, session_id); |
408 device_it = devices->erase(device_it); | 364 device_it = devices->erase(device_it); |
409 } | 365 } |
410 // If this request doesn't have any active devices, remove the request. | 366 // If this request doesn't have any active devices, remove the request. |
411 if (devices->empty()) { | 367 if (devices->empty()) { |
412 DeviceRequests::iterator del_itor(request_it); | 368 std::string label = request_it->first; |
413 ++request_it; | 369 ++request_it; |
414 scoped_ptr<DeviceRequest> request(del_itor->second); | 370 DeleteRequest(label); |
415 RemoveRequest(del_itor); | |
416 } else { | 371 } else { |
417 ++request_it; | 372 ++request_it; |
418 } | 373 } |
419 } | 374 } |
420 } | 375 } |
421 | 376 |
422 void MediaStreamManager::CloseDevice(MediaStreamType type, int session_id) { | 377 void MediaStreamManager::CloseDevice(MediaStreamType type, int session_id) { |
423 DVLOG(1) << "CloseDevice(" | 378 DVLOG(1) << "CloseDevice(" |
424 << "{type = " << type << "} " | 379 << "{type = " << type << "} " |
425 << "{session_id = " << session_id << "})"; | 380 << "{session_id = " << session_id << "})"; |
(...skipping 29 matching lines...) Expand all Loading... |
455 // starts monitoring devices. | 410 // starts monitoring devices. |
456 if (!requester) { | 411 if (!requester) { |
457 if (!monitoring_started_) | 412 if (!monitoring_started_) |
458 StartMonitoring(); | 413 StartMonitoring(); |
459 | 414 |
460 return std::string(); | 415 return std::string(); |
461 } | 416 } |
462 | 417 |
463 // Create a new request. | 418 // Create a new request. |
464 StreamOptions options; | 419 StreamOptions options; |
465 EnumerationCache* cache = NULL; | |
466 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { | 420 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
467 options.audio_type = type; | 421 options.audio_type = type; |
468 cache = &audio_enumeration_cache_; | |
469 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { | 422 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
470 options.video_type = type; | 423 options.video_type = type; |
471 cache = &video_enumeration_cache_; | |
472 } else { | 424 } else { |
473 NOTREACHED(); | 425 NOTREACHED(); |
474 return std::string(); | 426 return std::string(); |
475 } | 427 } |
476 | 428 |
477 MediaStreamRequest stream_request( | 429 MediaStreamRequest stream_request( |
478 render_process_id, render_view_id, page_request_id, std::string(), | 430 render_process_id, render_view_id, page_request_id, |
479 security_origin, MEDIA_ENUMERATE_DEVICES, std::string(), std::string(), | 431 security_origin, MEDIA_ENUMERATE_DEVICES, std::string(), std::string(), |
480 options.audio_type, options.video_type); | 432 options.audio_type, options.video_type); |
481 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 433 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
482 render_process_id, | 434 render_process_id, |
483 render_view_id); | 435 render_view_id); |
484 const std::string& label = AddRequest(request); | 436 const std::string& label = AddRequest(request); |
| 437 // Post a task and handle the request asynchronously. The reason is that the |
| 438 // requester won't have a label for the request until this function returns |
| 439 // and thus can not handle a response. Using base::Unretained is safe since |
| 440 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
| 441 // been stopped. |
| 442 BrowserThread::PostTask( |
| 443 BrowserThread::IO, FROM_HERE, |
| 444 base::Bind(&MediaStreamManager::DoEnumerateDevices, |
| 445 base::Unretained(this), label)); |
| 446 |
| 447 return label; |
| 448 } |
| 449 |
| 450 void MediaStreamManager::DoEnumerateDevices(const std::string& label) { |
| 451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 452 DeviceRequest* request = FindRequest(label); |
| 453 if (!request) |
| 454 return; // This can happen if the request has been canceled. |
| 455 |
| 456 MediaStreamType type; |
| 457 EnumerationCache* cache; |
| 458 if (request->request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 459 DCHECK_EQ(MEDIA_NO_SERVICE, request->request.video_type); |
| 460 type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 461 cache = &audio_enumeration_cache_; |
| 462 } else { |
| 463 DCHECK_EQ(MEDIA_DEVICE_VIDEO_CAPTURE, request->request.video_type); |
| 464 type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 465 cache = &video_enumeration_cache_; |
| 466 } |
485 | 467 |
486 if (cache->valid) { | 468 if (cache->valid) { |
487 // Cached device list of this type exists. Just send it out. | 469 // Cached device list of this type exists. Just send it out. |
488 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); | 470 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); |
489 | 471 request->devices = cache->devices; |
490 // Need to post a task since the requester won't have label till | 472 FinalizeEnumerateDevices(label, request); |
491 // this function returns. | |
492 BrowserThread::PostTask( | |
493 BrowserThread::IO, FROM_HERE, | |
494 base::Bind(&MediaStreamManager::SendCachedDeviceList, | |
495 base::Unretained(this), cache, label)); | |
496 } else { | 473 } else { |
497 StartEnumeration(request); | 474 StartEnumeration(request); |
498 } | 475 } |
499 | |
500 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; | 476 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; |
501 return label; | |
502 } | 477 } |
503 | 478 |
504 std::string MediaStreamManager::OpenDevice( | 479 std::string MediaStreamManager::OpenDevice( |
505 MediaStreamRequester* requester, | 480 MediaStreamRequester* requester, |
506 int render_process_id, | 481 int render_process_id, |
507 int render_view_id, | 482 int render_view_id, |
508 int page_request_id, | 483 int page_request_id, |
509 const std::string& device_id, | 484 const std::string& device_id, |
510 MediaStreamType type, | 485 MediaStreamType type, |
511 const GURL& security_origin) { | 486 const GURL& security_origin) { |
512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
513 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 488 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
514 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 489 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
515 | 490 |
516 // Create a new request. | 491 // Create a new request. |
517 StreamOptions options; | 492 StreamOptions options; |
518 if (IsAudioMediaType(type)) { | 493 if (IsAudioMediaType(type)) { |
519 options.audio_type = type; | 494 options.audio_type = type; |
520 options.audio_device_id = device_id; | 495 options.audio_device_id = device_id; |
521 } else if (IsVideoMediaType(type)) { | 496 } else if (IsVideoMediaType(type)) { |
522 options.video_type = type; | 497 options.video_type = type; |
523 options.video_device_id = device_id; | 498 options.video_device_id = device_id; |
524 } else { | 499 } else { |
525 NOTREACHED(); | 500 NOTREACHED(); |
526 return std::string(); | 501 return std::string(); |
527 } | 502 } |
528 | 503 |
529 MediaStreamRequest stream_request( | 504 MediaStreamRequest stream_request( |
530 render_process_id, render_view_id, page_request_id, std::string(), | 505 render_process_id, render_view_id, page_request_id, |
531 security_origin, MEDIA_OPEN_DEVICE, options.audio_device_id, | 506 security_origin, MEDIA_OPEN_DEVICE, options.audio_device_id, |
532 options.video_device_id, options.audio_type, options.video_type); | 507 options.video_device_id, options.audio_type, options.video_type); |
533 DeviceRequest* request = new DeviceRequest(requester, stream_request, | 508 DeviceRequest* request = new DeviceRequest(requester, stream_request, |
534 render_process_id, | 509 render_process_id, |
535 render_view_id); | 510 render_view_id); |
536 const std::string& label = AddRequest(request); | 511 const std::string& label = AddRequest(request); |
537 StartEnumeration(request); | 512 // Post a task and handle the request asynchronously. The reason is that the |
| 513 // requester won't have a label for the request until this function returns |
| 514 // and thus can not handle a response. Using base::Unretained is safe since |
| 515 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
| 516 // been stopped. |
| 517 BrowserThread::PostTask( |
| 518 BrowserThread::IO, FROM_HERE, |
| 519 base::Bind(&MediaStreamManager::SetupRequest, |
| 520 base::Unretained(this), label)); |
538 | 521 |
539 DVLOG(1) << "OpenDevice ({label = " << label << "})"; | 522 DVLOG(1) << "OpenDevice ({label = " << label << "})"; |
540 return label; | 523 return label; |
541 } | 524 } |
542 | 525 |
543 void MediaStreamManager::SendCachedDeviceList( | |
544 EnumerationCache* cache, | |
545 const std::string& label) { | |
546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
547 if (cache->valid) { | |
548 DeviceRequests::iterator it = requests_.find(label); | |
549 if (it != requests_.end()) { | |
550 it->second->requester->DevicesEnumerated(label, cache->devices); | |
551 } | |
552 } | |
553 } | |
554 | |
555 void MediaStreamManager::StopRemovedDevices( | 526 void MediaStreamManager::StopRemovedDevices( |
556 const StreamDeviceInfoArray& old_devices, | 527 const StreamDeviceInfoArray& old_devices, |
557 const StreamDeviceInfoArray& new_devices) { | 528 const StreamDeviceInfoArray& new_devices) { |
558 DVLOG(1) << "StopRemovedDevices(" | 529 DVLOG(1) << "StopRemovedDevices(" |
559 << "{#old_devices = " << old_devices.size() << "} " | 530 << "{#old_devices = " << old_devices.size() << "} " |
560 << "{#new_devices = " << new_devices.size() << "})"; | 531 << "{#new_devices = " << new_devices.size() << "})"; |
561 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); | 532 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); |
562 old_dev_it != old_devices.end(); ++old_dev_it) { | 533 old_dev_it != old_devices.end(); ++old_dev_it) { |
563 bool device_found = false; | 534 bool device_found = false; |
564 for (StreamDeviceInfoArray::const_iterator new_dev_it = new_devices.begin(); | 535 for (StreamDeviceInfoArray::const_iterator new_dev_it = new_devices.begin(); |
(...skipping 13 matching lines...) Expand all Loading... |
578 } | 549 } |
579 | 550 |
580 void MediaStreamManager::StopRemovedDevice(const MediaStreamDevice& device) { | 551 void MediaStreamManager::StopRemovedDevice(const MediaStreamDevice& device) { |
581 std::vector<int> session_ids; | 552 std::vector<int> session_ids; |
582 for (DeviceRequests::const_iterator it = requests_.begin(); | 553 for (DeviceRequests::const_iterator it = requests_.begin(); |
583 it != requests_.end() ; ++it) { | 554 it != requests_.end() ; ++it) { |
584 const DeviceRequest* request = it->second; | 555 const DeviceRequest* request = it->second; |
585 for (StreamDeviceInfoArray::const_iterator device_it = | 556 for (StreamDeviceInfoArray::const_iterator device_it = |
586 request->devices.begin(); | 557 request->devices.begin(); |
587 device_it != request->devices.end(); ++device_it) { | 558 device_it != request->devices.end(); ++device_it) { |
588 if (device_it->device.IsEqual(device)) { | 559 std::string source_id = content::GetHMACForMediaDeviceID( |
| 560 request->request.security_origin, |
| 561 device.id); |
| 562 if (device_it->device.id == source_id && |
| 563 device_it->device.type == device.type) { |
589 session_ids.push_back(device_it->session_id); | 564 session_ids.push_back(device_it->session_id); |
590 if (it->second->requester) { | 565 if (it->second->requester) { |
591 it->second->requester->DeviceStopped( | 566 it->second->requester->DeviceStopped( |
592 it->second->requesting_view_id, | 567 it->second->requesting_view_id, |
593 it->first, | 568 it->first, |
594 *device_it); | 569 *device_it); |
595 } | 570 } |
596 } | 571 } |
597 } | 572 } |
598 } | 573 } |
(...skipping 24 matching lines...) Expand all Loading... |
623 void MediaStreamManager::StopMonitoring() { | 598 void MediaStreamManager::StopMonitoring() { |
624 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 599 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
625 if (monitoring_started_) { | 600 if (monitoring_started_) { |
626 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); | 601 base::SystemMonitor::Get()->RemoveDevicesChangedObserver(this); |
627 monitoring_started_ = false; | 602 monitoring_started_ = false; |
628 ClearEnumerationCache(&audio_enumeration_cache_); | 603 ClearEnumerationCache(&audio_enumeration_cache_); |
629 ClearEnumerationCache(&video_enumeration_cache_); | 604 ClearEnumerationCache(&video_enumeration_cache_); |
630 } | 605 } |
631 } | 606 } |
632 | 607 |
633 bool MediaStreamManager::TranslateGUIDToRawId(MediaStreamType stream_type, | 608 bool MediaStreamManager::TranslateRequestedSourceIdToDeviceId( |
634 const GURL& security_origin, | 609 MediaStreamRequest* request) { |
635 const std::string& device_guid, | 610 // If a specific device has been requested we need to find the real device id. |
636 std::string* raw_device_id) { | 611 if (request->audio_type == MEDIA_DEVICE_AUDIO_CAPTURE && |
| 612 !request->requested_audio_device_id.empty()) { |
| 613 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_AUDIO_CAPTURE, |
| 614 request->security_origin, |
| 615 request->requested_audio_device_id, |
| 616 &request->requested_audio_device_id)) { |
| 617 // TODO(perkj): gUM should support mandatory and optional constraints. |
| 618 // Ie - if the sourceId is optional but it does not match - gUM should |
| 619 // not fail. For now we treat sourceId as a mandatory constraint. |
| 620 LOG(ERROR) << "Requested device does not exist."; |
| 621 return false; |
| 622 } |
| 623 } |
| 624 |
| 625 if (request->video_type == MEDIA_DEVICE_VIDEO_CAPTURE && |
| 626 !request->requested_video_device_id.empty()) { |
| 627 if (!TranslateSourceIdToDeviceId(MEDIA_DEVICE_VIDEO_CAPTURE, |
| 628 request->security_origin, |
| 629 request->requested_video_device_id, |
| 630 &request->requested_video_device_id)) { |
| 631 // TODO(perkj): guM should support mandatory and optional constraints. |
| 632 // Ie - if the sourceId is optional but it does not match - guM should |
| 633 // not fail. For now we treat sourceId as a mandatory constraint. |
| 634 LOG(ERROR) << "Requested device does not exist."; |
| 635 return false; |
| 636 } |
| 637 } |
| 638 DVLOG(3) << "Requested audio device " << request->requested_audio_device_id |
| 639 << " video device " << request->requested_video_device_id; |
| 640 return true; |
| 641 } |
| 642 |
| 643 void MediaStreamManager::TranslateDeviceIdToSourceId( |
| 644 const MediaStreamRequest& request, |
| 645 MediaStreamDevice* device) { |
| 646 if (request.audio_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 647 request.video_type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
| 648 device->id = content::GetHMACForMediaDeviceID(request.security_origin, |
| 649 device->id); |
| 650 } |
| 651 } |
| 652 |
| 653 bool MediaStreamManager::TranslateSourceIdToDeviceId( |
| 654 MediaStreamType stream_type, |
| 655 const GURL& security_origin, |
| 656 const std::string& source_id, |
| 657 std::string* device_id) { |
637 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || | 658 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
638 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); | 659 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); |
639 if (device_guid.empty()) | 660 DCHECK(!source_id.empty()); |
640 return false; | |
641 | 661 |
642 EnumerationCache* cache = | 662 EnumerationCache* cache = |
643 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? | 663 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
644 &audio_enumeration_cache_ : &video_enumeration_cache_; | 664 &audio_enumeration_cache_ : &video_enumeration_cache_; |
645 | 665 |
646 // If device monitoring hasn't started, the |device_guid| is not valid. | 666 // If device monitoring hasn't started, the |device_guid| is not valid. |
647 if (!cache->valid) | 667 if (!cache->valid) |
648 return false; | 668 return false; |
649 | 669 |
650 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); | 670 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); |
651 it != cache->devices.end(); | 671 it != cache->devices.end(); |
652 ++it) { | 672 ++it) { |
653 if (content::DoesMediaDeviceIDMatchHMAC( | 673 if (content::DoesMediaDeviceIDMatchHMAC(security_origin, source_id, |
654 security_origin, device_guid, it->device.id)) { | 674 it->device.id)) { |
655 *raw_device_id = it->device.id; | 675 *device_id = it->device.id; |
656 return true; | 676 return true; |
657 } | 677 } |
658 } | 678 } |
659 return false; | 679 return false; |
660 } | 680 } |
661 | 681 |
662 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { | 682 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { |
663 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 683 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
664 cache->valid = false; | 684 cache->valid = false; |
665 } | 685 } |
(...skipping 27 matching lines...) Expand all Loading... |
693 std::string unique_label; | 713 std::string unique_label; |
694 do { | 714 do { |
695 unique_label = RandomLabel(); | 715 unique_label = RandomLabel(); |
696 } while (requests_.find(unique_label) != requests_.end()); | 716 } while (requests_.find(unique_label) != requests_.end()); |
697 | 717 |
698 requests_.insert(std::make_pair(unique_label, request)); | 718 requests_.insert(std::make_pair(unique_label, request)); |
699 | 719 |
700 return unique_label; | 720 return unique_label; |
701 } | 721 } |
702 | 722 |
703 void MediaStreamManager::RemoveRequest(DeviceRequests::iterator it) { | 723 MediaStreamManager::DeviceRequest* |
| 724 MediaStreamManager::FindRequest(const std::string& label) const { |
| 725 DeviceRequests::const_iterator request_it = requests_.find(label); |
| 726 return request_it == requests_.end() ? NULL : request_it->second; |
| 727 } |
| 728 |
| 729 void MediaStreamManager::DeleteRequest(const std::string& label) { |
| 730 DeviceRequests::iterator it = requests_.find(label); |
| 731 scoped_ptr<DeviceRequest> request(it->second); |
704 requests_.erase(it); | 732 requests_.erase(it); |
705 } | 733 } |
706 | 734 |
707 void MediaStreamManager::PostRequestToUI(const std::string& label) { | 735 void MediaStreamManager::PostRequestToUI(const std::string& label, |
| 736 DeviceRequest* request) { |
708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
709 DeviceRequest* request = requests_[label]; | 738 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; |
| 739 // If a specific device has been requested we need to find the real device id. |
| 740 if (!TranslateRequestedSourceIdToDeviceId(&request->request)) { |
| 741 FinalizeRequestFailed(label, request); |
| 742 return; |
| 743 } |
| 744 |
| 745 const MediaStreamType audio_type = request->request.audio_type; |
| 746 const MediaStreamType video_type = request->request.video_type; |
| 747 |
| 748 // Post the request to UI and set the state. |
| 749 if (IsAudioMediaType(audio_type)) |
| 750 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
| 751 if (IsVideoMediaType(video_type)) |
| 752 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
710 | 753 |
711 if (use_fake_ui_) { | 754 if (use_fake_ui_) { |
712 if (!fake_ui_) | 755 if (!fake_ui_) |
713 fake_ui_.reset(new FakeMediaStreamUIProxy()); | 756 fake_ui_.reset(new FakeMediaStreamUIProxy()); |
714 | 757 |
715 MediaStreamDevices devices; | 758 MediaStreamDevices devices; |
716 if (audio_enumeration_cache_.valid) { | 759 if (audio_enumeration_cache_.valid) { |
717 for (StreamDeviceInfoArray::const_iterator it = | 760 for (StreamDeviceInfoArray::const_iterator it = |
718 audio_enumeration_cache_.devices.begin(); | 761 audio_enumeration_cache_.devices.begin(); |
719 it != audio_enumeration_cache_.devices.end(); ++it) { | 762 it != audio_enumeration_cache_.devices.end(); ++it) { |
(...skipping 14 matching lines...) Expand all Loading... |
734 } else { | 777 } else { |
735 request->ui_proxy = MediaStreamUIProxy::Create(); | 778 request->ui_proxy = MediaStreamUIProxy::Create(); |
736 } | 779 } |
737 | 780 |
738 request->ui_proxy->RequestAccess( | 781 request->ui_proxy->RequestAccess( |
739 request->request, | 782 request->request, |
740 base::Bind(&MediaStreamManager::HandleAccessRequestResponse, | 783 base::Bind(&MediaStreamManager::HandleAccessRequestResponse, |
741 base::Unretained(this), label)); | 784 base::Unretained(this), label)); |
742 } | 785 } |
743 | 786 |
744 void MediaStreamManager::HandleRequest(const std::string& label) { | 787 void MediaStreamManager::SetupRequest(const std::string& label) { |
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 788 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
746 DeviceRequest* request = requests_[label]; | 789 DeviceRequest* request = FindRequest(label); |
| 790 if (!request) { |
| 791 DVLOG(1) << "SetupRequest label " << label << " doesn't exist!!"; |
| 792 return; // This can happen if the request has been canceled. |
| 793 } |
| 794 |
| 795 if (!request->request.security_origin.is_valid()) { |
| 796 LOG(ERROR) << "Invalid security origin. " |
| 797 << request->request.security_origin; |
| 798 FinalizeRequestFailed(label, request); |
| 799 return; |
| 800 } |
747 | 801 |
748 const MediaStreamType audio_type = request->request.audio_type; | 802 const MediaStreamType audio_type = request->request.audio_type; |
749 const MediaStreamType video_type = request->request.video_type; | 803 const MediaStreamType video_type = request->request.video_type; |
750 | 804 |
751 bool is_web_contents_capture = | 805 bool is_web_contents_capture = |
752 audio_type == MEDIA_TAB_AUDIO_CAPTURE || | 806 audio_type == MEDIA_TAB_AUDIO_CAPTURE || |
753 video_type == MEDIA_TAB_VIDEO_CAPTURE; | 807 video_type == MEDIA_TAB_VIDEO_CAPTURE; |
| 808 if (is_web_contents_capture && !SetupTabCaptureRequest(request)) { |
| 809 FinalizeRequestFailed(label, request); |
| 810 return; |
| 811 } |
754 | 812 |
755 bool is_screen_capture = | 813 bool is_screen_capture = |
756 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; | 814 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; |
| 815 if (is_screen_capture && !SetupScreenCaptureRequest(request)) { |
| 816 FinalizeRequestFailed(label, request); |
| 817 return; |
| 818 } |
757 | 819 |
758 if (!is_web_contents_capture && | 820 if (!is_web_contents_capture && |
759 !is_screen_capture && | 821 !is_screen_capture && |
760 ((IsAudioMediaType(audio_type) && !audio_enumeration_cache_.valid) || | 822 ((IsAudioMediaType(audio_type) && !audio_enumeration_cache_.valid) || |
761 (IsVideoMediaType(video_type) && !video_enumeration_cache_.valid))) { | 823 (IsVideoMediaType(video_type) && !video_enumeration_cache_.valid))) { |
762 // Enumerate the devices if there is no valid device lists to be used. | 824 // Enumerate the devices if there is no valid device lists to be used. |
763 StartEnumeration(request); | 825 StartEnumeration(request); |
764 return; | 826 return; |
765 } | 827 } |
| 828 PostRequestToUI(label, request); |
| 829 } |
766 | 830 |
767 // No need to do new device enumerations, post the request to UI | 831 bool MediaStreamManager::SetupTabCaptureRequest(DeviceRequest* request) { |
768 // immediately. | 832 DCHECK(request->request.audio_type == MEDIA_TAB_AUDIO_CAPTURE || |
769 if (IsAudioMediaType(audio_type)) | 833 request->request.video_type == MEDIA_TAB_VIDEO_CAPTURE); |
770 request->SetState(audio_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | |
771 if (IsVideoMediaType(video_type)) | |
772 request->SetState(video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | |
773 | 834 |
774 PostRequestToUI(label); | 835 MediaStreamRequest* ms_request = &request->request; |
| 836 // Customize options for a WebContents based capture. |
| 837 int target_render_process_id = 0; |
| 838 int target_render_view_id = 0; |
| 839 |
| 840 // TODO(justinlin): Can't plumb audio mirroring using stream type right |
| 841 // now, so plumbing by device_id. Will revisit once it's refactored. |
| 842 // http://crbug.com/163100 |
| 843 std::string tab_capture_device_id = |
| 844 WebContentsCaptureUtil::AppendWebContentsDeviceScheme( |
| 845 !ms_request->requested_video_device_id.empty() ? |
| 846 ms_request->requested_video_device_id : |
| 847 ms_request->requested_audio_device_id); |
| 848 |
| 849 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( |
| 850 tab_capture_device_id, &target_render_process_id, |
| 851 &target_render_view_id); |
| 852 if (!has_valid_device_id || |
| 853 (ms_request->audio_type != MEDIA_TAB_AUDIO_CAPTURE && |
| 854 ms_request->audio_type != MEDIA_NO_SERVICE) || |
| 855 (ms_request->video_type != MEDIA_TAB_VIDEO_CAPTURE && |
| 856 ms_request->video_type != MEDIA_NO_SERVICE)) { |
| 857 return false; |
| 858 } |
| 859 ms_request->tab_capture_device_id = tab_capture_device_id; |
| 860 ms_request->render_process_id = target_render_process_id; |
| 861 ms_request->render_view_id = target_render_view_id; |
| 862 DVLOG(3) << "SetupTabCaptureRequest " |
| 863 << ", {tab_capture_device_id = " << tab_capture_device_id << "}" |
| 864 << ", {target_render_process_id = " << target_render_process_id |
| 865 << "}" |
| 866 << ", {target_render_view_id = " << target_render_view_id << "}"; |
| 867 return true; |
| 868 } |
| 869 |
| 870 bool MediaStreamManager::SetupScreenCaptureRequest(DeviceRequest* request) { |
| 871 DCHECK(request->request.audio_type == MEDIA_LOOPBACK_AUDIO_CAPTURE || |
| 872 request->request.video_type == MEDIA_DESKTOP_VIDEO_CAPTURE); |
| 873 const MediaStreamRequest& ms_request = request->request; |
| 874 |
| 875 // For screen capture we only support two valid combinations: |
| 876 // (1) screen video capture only, or |
| 877 // (2) screen video capture with loopback audio capture. |
| 878 if (ms_request.video_type != MEDIA_DESKTOP_VIDEO_CAPTURE || |
| 879 (ms_request.audio_type != MEDIA_NO_SERVICE && |
| 880 ms_request.audio_type != MEDIA_LOOPBACK_AUDIO_CAPTURE)) { |
| 881 // TODO(sergeyu): Surface error message to the calling JS code. |
| 882 LOG(ERROR) << "Invalid screen capture request."; |
| 883 return false; |
| 884 } |
| 885 return true; |
| 886 } |
| 887 |
| 888 StreamDeviceInfoArray MediaStreamManager::GetDevicesOpenedByRequest( |
| 889 const std::string& label) const { |
| 890 DeviceRequest* request = FindRequest(label); |
| 891 if (!request) |
| 892 return StreamDeviceInfoArray(); |
| 893 return request->devices; |
775 } | 894 } |
776 | 895 |
777 bool MediaStreamManager::FindExistingRequestedDeviceInfo( | 896 bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
778 int render_process_id, | 897 int render_process_id, |
779 int render_view_id, | 898 int render_view_id, |
| 899 const GURL& security_origin, |
780 MediaStreamRequestType type, | 900 MediaStreamRequestType type, |
781 const std::string& device_id, | 901 const std::string& device_id, |
| 902 MediaStreamType device_type, |
782 StreamDeviceInfo* device_info, | 903 StreamDeviceInfo* device_info, |
783 MediaRequestState* request_state) const { | 904 MediaRequestState* request_state) const { |
784 DCHECK(device_info); | 905 DCHECK(device_info); |
785 DCHECK(request_state); | 906 DCHECK(request_state); |
| 907 |
| 908 std::string source_id = content::GetHMACForMediaDeviceID( |
| 909 security_origin, |
| 910 device_id); |
| 911 |
786 for (DeviceRequests::const_iterator it = requests_.begin(); | 912 for (DeviceRequests::const_iterator it = requests_.begin(); |
787 it != requests_.end() ; ++it) { | 913 it != requests_.end() ; ++it) { |
788 const DeviceRequest* request = it->second; | 914 const DeviceRequest* request = it->second; |
789 if (request->requesting_process_id ==render_process_id && | 915 if (request->requesting_process_id == render_process_id && |
790 request->requesting_view_id == render_view_id && | 916 request->requesting_view_id == render_view_id && |
791 request->request.request_type == type) { | 917 request->request.request_type == type) { |
792 for (StreamDeviceInfoArray::const_iterator device_it = | 918 for (StreamDeviceInfoArray::const_iterator device_it = |
793 request->devices.begin(); | 919 request->devices.begin(); |
794 device_it != request->devices.end(); ++device_it) { | 920 device_it != request->devices.end(); ++device_it) { |
795 if (device_it->device.id == device_id) { | 921 if (device_it->device.id == source_id && |
796 *device_info = *device_it; | 922 device_it->device.type == device_type) { |
797 *request_state = request->state(device_it->device.type); | 923 *device_info = *device_it; |
| 924 *request_state = request->state(device_it->device.type); |
798 return true; | 925 return true; |
799 } | 926 } |
800 } | 927 } |
801 } | 928 } |
802 } | 929 } |
803 return false; | 930 return false; |
804 } | 931 } |
805 | 932 |
| 933 void MediaStreamManager::FinalizeGenerateStream(const std::string& label, |
| 934 DeviceRequest* request) { |
| 935 DVLOG(1) << "FinalizeGenerateStream label " << label; |
| 936 const StreamDeviceInfoArray& requested_devices = request->devices; |
| 937 |
| 938 // Partition the array of devices into audio vs video. |
| 939 StreamDeviceInfoArray audio_devices, video_devices; |
| 940 for (StreamDeviceInfoArray::const_iterator device_it = |
| 941 requested_devices.begin(); |
| 942 device_it != requested_devices.end(); ++device_it) { |
| 943 if (IsAudioMediaType(device_it->device.type)) { |
| 944 audio_devices.push_back(*device_it); |
| 945 } else if (IsVideoMediaType(device_it->device.type)) { |
| 946 video_devices.push_back(*device_it); |
| 947 } else { |
| 948 NOTREACHED(); |
| 949 } |
| 950 } |
| 951 |
| 952 request->requester->StreamGenerated(label, audio_devices, video_devices); |
| 953 } |
| 954 |
| 955 void MediaStreamManager::FinalizeRequestFailed( |
| 956 const std::string& label, |
| 957 DeviceRequest* request) { |
| 958 if (request->requester) |
| 959 request->requester->StreamGenerationFailed(label); |
| 960 |
| 961 if (request->request.request_type == MEDIA_DEVICE_ACCESS && |
| 962 !request->callback.is_null()) { |
| 963 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); |
| 964 } |
| 965 |
| 966 DeleteRequest(label); |
| 967 } |
| 968 |
| 969 void MediaStreamManager::FinalizeOpenDevice(const std::string& label, |
| 970 DeviceRequest* request) { |
| 971 const StreamDeviceInfoArray& requested_devices = request->devices; |
| 972 request->requester->DeviceOpened(label, requested_devices.front()); |
| 973 } |
| 974 |
| 975 void MediaStreamManager::FinalizeEnumerateDevices(const std::string& label, |
| 976 DeviceRequest* request) { |
| 977 if (!request->request.security_origin.is_valid()) { |
| 978 request->requester->DevicesEnumerated(label, StreamDeviceInfoArray()); |
| 979 return; |
| 980 } |
| 981 for (StreamDeviceInfoArray::iterator it = request->devices.begin(); |
| 982 it != request->devices.end(); ++it) { |
| 983 TranslateDeviceIdToSourceId(request->request, &it->device); |
| 984 } |
| 985 request->requester->DevicesEnumerated(label, request->devices); |
| 986 } |
| 987 |
| 988 void MediaStreamManager::FinalizeMediaAccessRequest( |
| 989 const std::string& label, |
| 990 DeviceRequest* request, |
| 991 const MediaStreamDevices& devices) { |
| 992 if (!request->callback.is_null()) |
| 993 request->callback.Run(devices, request->ui_proxy.Pass()); |
| 994 |
| 995 // Delete the request since it is done. |
| 996 DeleteRequest(label); |
| 997 } |
| 998 |
806 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { | 999 void MediaStreamManager::InitializeDeviceManagersOnIOThread() { |
807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1000 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
808 if (device_thread_) | 1001 if (device_thread_) |
809 return; | 1002 return; |
810 | 1003 |
811 device_thread_.reset(new base::Thread("MediaStreamDeviceThread")); | 1004 device_thread_.reset(new base::Thread("MediaStreamDeviceThread")); |
812 #if defined(OS_WIN) | 1005 #if defined(OS_WIN) |
813 device_thread_->init_com_with_mta(true); | 1006 device_thread_->init_com_with_mta(true); |
814 #endif | 1007 #endif |
815 CHECK(device_thread_->Start()); | 1008 CHECK(device_thread_->Start()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 request->SetState(device_it->device.type, MEDIA_REQUEST_STATE_DONE); | 1044 request->SetState(device_it->device.type, MEDIA_REQUEST_STATE_DONE); |
852 | 1045 |
853 if (IsAudioMediaType(device_it->device.type)) { | 1046 if (IsAudioMediaType(device_it->device.type)) { |
854 // Store the native audio parameters in the device struct. | 1047 // Store the native audio parameters in the device struct. |
855 // TODO(xians): Handle the tab capture sample rate/channel layout | 1048 // TODO(xians): Handle the tab capture sample rate/channel layout |
856 // in AudioInputDeviceManager::Open(). | 1049 // in AudioInputDeviceManager::Open(). |
857 if (device_it->device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { | 1050 if (device_it->device.type != content::MEDIA_TAB_AUDIO_CAPTURE) { |
858 const StreamDeviceInfo* info = | 1051 const StreamDeviceInfo* info = |
859 audio_input_device_manager_->GetOpenedDeviceInfoById( | 1052 audio_input_device_manager_->GetOpenedDeviceInfoById( |
860 device_it->session_id); | 1053 device_it->session_id); |
861 DCHECK_EQ(info->device.id, device_it->device.id); | |
862 device_it->device.input = info->device.input; | 1054 device_it->device.input = info->device.input; |
863 device_it->device.matched_output = info->device.matched_output; | 1055 device_it->device.matched_output = info->device.matched_output; |
864 } | 1056 } |
865 } | 1057 } |
866 if (RequestDone(*request)) | 1058 if (RequestDone(*request)) |
867 HandleRequestDone(label, request); | 1059 HandleRequestDone(label, request); |
868 break; | 1060 break; |
869 } | 1061 } |
870 } | 1062 } |
871 } | 1063 } |
872 } | 1064 } |
873 | 1065 |
874 void MediaStreamManager::HandleRequestDone(const std::string& label, | 1066 void MediaStreamManager::HandleRequestDone(const std::string& label, |
875 DeviceRequest* request) { | 1067 DeviceRequest* request) { |
876 DCHECK(RequestDone(*request)); | 1068 DCHECK(RequestDone(*request)); |
877 DVLOG(1) << "HandleRequestDone(" | 1069 DVLOG(1) << "HandleRequestDone(" |
878 << ", {label = " << label << "})"; | 1070 << ", {label = " << label << "})"; |
879 | 1071 |
880 const StreamDeviceInfoArray& requested_devices = request->devices; | |
881 switch (request->request.request_type) { | 1072 switch (request->request.request_type) { |
882 case MEDIA_OPEN_DEVICE: | 1073 case MEDIA_OPEN_DEVICE: |
883 request->requester->DeviceOpened(label, requested_devices.front()); | 1074 FinalizeOpenDevice(label, request); |
884 break; | 1075 break; |
885 case MEDIA_GENERATE_STREAM: { | 1076 case MEDIA_GENERATE_STREAM: { |
886 // Partition the array of devices into audio vs video. | 1077 FinalizeGenerateStream(label, request); |
887 StreamDeviceInfoArray audio_devices, video_devices; | |
888 for (StreamDeviceInfoArray::const_iterator device_it = | |
889 requested_devices.begin(); | |
890 device_it != requested_devices.end(); ++device_it) { | |
891 if (IsAudioMediaType(device_it->device.type)) { | |
892 audio_devices.push_back(*device_it); | |
893 } else if (IsVideoMediaType(device_it->device.type)) { | |
894 video_devices.push_back(*device_it); | |
895 } else { | |
896 NOTREACHED(); | |
897 } | |
898 } | |
899 | |
900 request->requester->StreamGenerated(label, audio_devices, video_devices); | |
901 break; | 1078 break; |
902 } | 1079 } |
903 default: | 1080 default: |
904 NOTREACHED(); | 1081 NOTREACHED(); |
905 break; | 1082 break; |
906 } | 1083 } |
907 | 1084 |
908 if (request->ui_proxy.get()) { | 1085 if (request->ui_proxy.get()) { |
909 request->ui_proxy->OnStarted( | 1086 request->ui_proxy->OnStarted( |
910 base::Bind(&MediaStreamManager::StopMediaStreamFromBrowser, | 1087 base::Bind(&MediaStreamManager::StopMediaStreamFromBrowser, |
(...skipping 22 matching lines...) Expand all Loading... |
933 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), | 1110 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), |
934 StreamDeviceInfo::IsEqual)) { | 1111 StreamDeviceInfo::IsEqual)) { |
935 StopRemovedDevices(cache->devices, devices); | 1112 StopRemovedDevices(cache->devices, devices); |
936 cache->devices = devices; | 1113 cache->devices = devices; |
937 need_update_clients = true; | 1114 need_update_clients = true; |
938 | 1115 |
939 // The device might not be able to be enumerated when it is not warmed up, | 1116 // The device might not be able to be enumerated when it is not warmed up, |
940 // for example, when the machine just wakes up from sleep. We set the cache | 1117 // for example, when the machine just wakes up from sleep. We set the cache |
941 // to be invalid so that the next media request will trigger the | 1118 // to be invalid so that the next media request will trigger the |
942 // enumeration again. See issue/317673. | 1119 // enumeration again. See issue/317673. |
943 if (devices.size()) | 1120 cache->valid = !devices.empty(); |
944 cache->valid = true; | |
945 else | |
946 cache->valid = false; | |
947 } | 1121 } |
948 | 1122 |
949 if (need_update_clients && monitoring_started_) | 1123 if (need_update_clients && monitoring_started_) |
950 NotifyDevicesChanged(stream_type, devices); | 1124 NotifyDevicesChanged(stream_type, devices); |
951 | 1125 |
952 // Publish the result for all requests waiting for device list(s). | 1126 // Publish the result for all requests waiting for device list(s). |
953 // Find the requests waiting for this device list, store their labels and | 1127 // Find the requests waiting for this device list, store their labels and |
954 // release the iterator before calling device settings. We might get a call | 1128 // release the iterator before calling device settings. We might get a call |
955 // back from device_settings that will need to iterate through devices. | 1129 // back from device_settings that will need to iterate through devices. |
956 std::list<std::string> label_list; | 1130 std::list<std::string> label_list; |
957 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | 1131 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); |
958 ++it) { | 1132 ++it) { |
959 if (it->second->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && | 1133 if (it->second->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && |
960 Requested(it->second->request, stream_type)) { | 1134 Requested(it->second->request, stream_type)) { |
961 if (it->second->request.request_type != MEDIA_ENUMERATE_DEVICES) | 1135 if (it->second->request.request_type != MEDIA_ENUMERATE_DEVICES) |
962 it->second->SetState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 1136 it->second->SetState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
963 label_list.push_back(it->first); | 1137 label_list.push_back(it->first); |
964 } | 1138 } |
965 } | 1139 } |
966 for (std::list<std::string>::iterator it = label_list.begin(); | 1140 for (std::list<std::string>::iterator it = label_list.begin(); |
967 it != label_list.end(); ++it) { | 1141 it != label_list.end(); ++it) { |
968 DeviceRequest* request = requests_[*it]; | 1142 DeviceRequest* request = FindRequest(*it); |
969 switch (request->request.request_type) { | 1143 switch (request->request.request_type) { |
970 case MEDIA_ENUMERATE_DEVICES: | 1144 case MEDIA_ENUMERATE_DEVICES: |
971 if (need_update_clients && request->requester) | 1145 if (need_update_clients && request->requester) { |
972 request->requester->DevicesEnumerated(*it, devices); | 1146 request->devices = devices; |
| 1147 FinalizeEnumerateDevices(*it, request); |
| 1148 } |
973 break; | 1149 break; |
974 default: | 1150 default: |
975 if (request->state(request->request.audio_type) == | 1151 if (request->state(request->request.audio_type) == |
976 MEDIA_REQUEST_STATE_REQUESTED || | 1152 MEDIA_REQUEST_STATE_REQUESTED || |
977 request->state(request->request.video_type) == | 1153 request->state(request->request.video_type) == |
978 MEDIA_REQUEST_STATE_REQUESTED) { | 1154 MEDIA_REQUEST_STATE_REQUESTED) { |
979 // We are doing enumeration for other type of media, wait until it is | 1155 // We are doing enumeration for other type of media, wait until it is |
980 // all done before posting the request to UI because UI needs | 1156 // all done before posting the request to UI because UI needs |
981 // the device lists to handle the request. | 1157 // the device lists to handle the request. |
982 break; | 1158 break; |
983 } | 1159 } |
984 | 1160 |
985 // Post the request to UI for permission approval. | 1161 PostRequestToUI(*it, request); |
986 PostRequestToUI(*it); | |
987 break; | 1162 break; |
988 } | 1163 } |
989 } | 1164 } |
990 label_list.clear(); | 1165 label_list.clear(); |
991 --active_enumeration_ref_count_[stream_type]; | 1166 --active_enumeration_ref_count_[stream_type]; |
992 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); | 1167 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); |
993 } | 1168 } |
994 | 1169 |
995 void MediaStreamManager::HandleAccessRequestResponse( | 1170 void MediaStreamManager::HandleAccessRequestResponse( |
996 const std::string& label, | 1171 const std::string& label, |
997 const MediaStreamDevices& devices) { | 1172 const MediaStreamDevices& devices) { |
998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
999 DVLOG(1) << "HandleAccessRequestResponse(" | 1174 DVLOG(1) << "HandleAccessRequestResponse(" |
1000 << ", {label = " << label << "})"; | 1175 << ", {label = " << label << "})"; |
1001 | 1176 |
1002 DeviceRequests::iterator request_it = requests_.find(label); | 1177 DeviceRequest* request = FindRequest(label); |
1003 if (request_it == requests_.end()) { | 1178 if (!request) { |
| 1179 // The request has been canceled before the UI returned. |
| 1180 return; |
| 1181 } |
| 1182 |
| 1183 if (request->request.request_type == MEDIA_DEVICE_ACCESS) { |
| 1184 FinalizeMediaAccessRequest(label, request, devices); |
1004 return; | 1185 return; |
1005 } | 1186 } |
1006 | 1187 |
1007 // Handle the case when the request was denied. | 1188 // Handle the case when the request was denied. |
1008 if (devices.empty()) { | 1189 if (devices.empty()) { |
1009 // Notify the users about the request result. | 1190 FinalizeRequestFailed(label, request); |
1010 scoped_ptr<DeviceRequest> request(request_it->second); | |
1011 if (request->requester) | |
1012 request->requester->StreamGenerationFailed(label); | |
1013 | |
1014 if (request->request.request_type == MEDIA_DEVICE_ACCESS && | |
1015 !request->callback.is_null()) { | |
1016 request->callback.Run(MediaStreamDevices(), request->ui_proxy.Pass()); | |
1017 } | |
1018 | |
1019 RemoveRequest(request_it); | |
1020 return; | |
1021 } | |
1022 | |
1023 if (request_it->second->request.request_type == MEDIA_DEVICE_ACCESS) { | |
1024 scoped_ptr<DeviceRequest> request(request_it->second); | |
1025 if (!request->callback.is_null()) | |
1026 request->callback.Run(devices, request->ui_proxy.Pass()); | |
1027 | |
1028 // Delete the request since it is done. | |
1029 RemoveRequest(request_it); | |
1030 return; | 1191 return; |
1031 } | 1192 } |
1032 | 1193 |
1033 // Process all newly-accepted devices for this request. | 1194 // Process all newly-accepted devices for this request. |
1034 DeviceRequest* request = request_it->second; | |
1035 bool found_audio = false; | 1195 bool found_audio = false; |
1036 bool found_video = false; | 1196 bool found_video = false; |
1037 for (MediaStreamDevices::const_iterator device_it = devices.begin(); | 1197 for (MediaStreamDevices::const_iterator device_it = devices.begin(); |
1038 device_it != devices.end(); ++device_it) { | 1198 device_it != devices.end(); ++device_it) { |
1039 StreamDeviceInfo device_info; | 1199 StreamDeviceInfo device_info; |
1040 device_info.device = *device_it; | 1200 device_info.device = *device_it; |
1041 | 1201 |
1042 // TODO(justinlin): Nicer way to do this? | 1202 // TODO(justinlin): Nicer way to do this? |
1043 // Re-append the device's id since we lost it when posting request to UI. | 1203 // Re-append the device's id since we lost it when posting request to UI. |
1044 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE || | 1204 if (device_info.device.type == content::MEDIA_TAB_VIDEO_CAPTURE || |
(...skipping 20 matching lines...) Expand all Loading... |
1065 if (device_info.device.type == request->request.audio_type) { | 1225 if (device_info.device.type == request->request.audio_type) { |
1066 found_audio = true; | 1226 found_audio = true; |
1067 } else if (device_info.device.type == request->request.video_type) { | 1227 } else if (device_info.device.type == request->request.video_type) { |
1068 found_video = true; | 1228 found_video = true; |
1069 } | 1229 } |
1070 | 1230 |
1071 // If this is request for a new MediaStream, a device is only opened once | 1231 // If this is request for a new MediaStream, a device is only opened once |
1072 // per render view. This is so that the permission to use a device can be | 1232 // per render view. This is so that the permission to use a device can be |
1073 // revoked by a single call to StopStreamDevice regardless of how many | 1233 // revoked by a single call to StopStreamDevice regardless of how many |
1074 // MediaStreams it is being used in. | 1234 // MediaStreams it is being used in. |
1075 | |
1076 if (request->request.request_type == MEDIA_GENERATE_STREAM) { | 1235 if (request->request.request_type == MEDIA_GENERATE_STREAM) { |
1077 MediaRequestState state; | 1236 MediaRequestState state; |
1078 if (FindExistingRequestedDeviceInfo(request->requesting_process_id, | 1237 if (FindExistingRequestedDeviceInfo(request->requesting_process_id, |
1079 request->requesting_view_id, | 1238 request->requesting_view_id, |
| 1239 request->request.security_origin, |
1080 request->request.request_type, | 1240 request->request.request_type, |
1081 device_it->id, | 1241 device_info.device.id, |
| 1242 device_info.device.type, |
1082 &device_info, | 1243 &device_info, |
1083 &state)) { | 1244 &state)) { |
1084 request->devices.push_back(device_info); | 1245 request->devices.push_back(device_info); |
1085 request->SetState(device_info.device.type, state); | 1246 request->SetState(device_info.device.type, state); |
1086 DVLOG(1) << "HandleAccessRequestResponse - device already opened " | 1247 DVLOG(1) << "HandleAccessRequestResponse - device already opened " |
1087 << ", {label = " << label << "}" | 1248 << ", {label = " << label << "}" |
1088 << ", device_id = " << device_it->id << "}"; | 1249 << ", device_id = " << device_it->id << "}"; |
1089 continue; | 1250 continue; |
1090 } | 1251 } |
1091 } | 1252 } |
1092 device_info.session_id = | 1253 device_info.session_id = |
1093 GetDeviceManager(device_info.device.type)->Open(device_info); | 1254 GetDeviceManager(device_info.device.type)->Open(device_info); |
| 1255 TranslateDeviceIdToSourceId(request->request, &device_info.device); |
1094 request->devices.push_back(device_info); | 1256 request->devices.push_back(device_info); |
| 1257 |
1095 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); | 1258 request->SetState(device_info.device.type, MEDIA_REQUEST_STATE_OPENING); |
1096 DVLOG(1) << "HandleAccessRequestResponse - opening device " | 1259 DVLOG(1) << "HandleAccessRequestResponse - opening device " |
1097 << ", {label = " << label << "}" | 1260 << ", {label = " << label << "}" |
1098 << ", {device_id = " << device_it->id << "}" | 1261 << ", {device_id = " << device_info.device.id << "}" |
1099 << ", {session_id = " << device_info.session_id << "}"; | 1262 << ", {session_id = " << device_info.session_id << "}"; |
1100 } | 1263 } |
1101 | 1264 |
1102 // Check whether we've received all stream types requested. | 1265 // Check whether we've received all stream types requested. |
1103 if (!found_audio && IsAudioMediaType(request->request.audio_type)) { | 1266 if (!found_audio && IsAudioMediaType(request->request.audio_type)) { |
1104 request->SetState(request->request.audio_type, MEDIA_REQUEST_STATE_ERROR); | 1267 request->SetState(request->request.audio_type, MEDIA_REQUEST_STATE_ERROR); |
1105 DVLOG(1) << "Set no audio found label " << label; | 1268 DVLOG(1) << "Set no audio found label " << label; |
1106 } | 1269 } |
1107 | 1270 |
1108 if (!found_video && IsVideoMediaType(request->request.video_type)) | 1271 if (!found_video && IsVideoMediaType(request->request.video_type)) |
1109 request->SetState(request->request.video_type, MEDIA_REQUEST_STATE_ERROR); | 1272 request->SetState(request->request.video_type, MEDIA_REQUEST_STATE_ERROR); |
1110 | 1273 |
1111 if (RequestDone(*request)) | 1274 if (RequestDone(*request)) |
1112 HandleRequestDone(label, request); | 1275 HandleRequestDone(label, request); |
1113 } | 1276 } |
1114 | 1277 |
1115 void MediaStreamManager::StopMediaStreamFromBrowser(const std::string& label) { | 1278 void MediaStreamManager::StopMediaStreamFromBrowser(const std::string& label) { |
1116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1117 | 1280 |
1118 DeviceRequests::iterator it = requests_.find(label); | 1281 DeviceRequest* request = FindRequest(label); |
1119 if (it == requests_.end()) | 1282 if (!request) |
1120 return; | 1283 return; |
1121 | 1284 |
1122 DeviceRequest* request = it->second; | |
1123 // Notify renderers that the devices in the stream will be stopped. | 1285 // Notify renderers that the devices in the stream will be stopped. |
1124 if (request->requester) { | 1286 if (request->requester) { |
1125 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); | 1287 for (StreamDeviceInfoArray::iterator device_it = request->devices.begin(); |
1126 device_it != request->devices.end(); ++device_it) { | 1288 device_it != request->devices.end(); ++device_it) { |
1127 request->requester->DeviceStopped(request->requesting_view_id, | 1289 request->requester->DeviceStopped(request->requesting_view_id, |
1128 label, | 1290 label, |
1129 *device_it); | 1291 *device_it); |
1130 } | 1292 } |
1131 } | 1293 } |
1132 | 1294 |
1133 CancelRequest(label); | 1295 CancelRequest(label); |
1134 } | 1296 } |
1135 | 1297 |
1136 void MediaStreamManager::UseFakeDevice() { | 1298 void MediaStreamManager::UseFakeDevice() { |
1137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1138 video_capture_manager()->UseFakeDevice(); | 1300 video_capture_manager()->UseFakeDevice(); |
1139 audio_input_device_manager()->UseFakeDevice(); | 1301 audio_input_device_manager()->UseFakeDevice(); |
1140 } | 1302 } |
1141 | 1303 |
1142 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { | 1304 void MediaStreamManager::UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui) { |
1143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1144 use_fake_ui_ = true; | 1306 use_fake_ui_ = true; |
1145 fake_ui_ = fake_ui.Pass(); | 1307 fake_ui_ = fake_ui.Pass(); |
1146 } | 1308 } |
1147 | 1309 |
1148 void MediaStreamManager::WillDestroyCurrentMessageLoop() { | 1310 void MediaStreamManager::WillDestroyCurrentMessageLoop() { |
| 1311 DVLOG(3) << "MediaStreamManager::WillDestroyCurrentMessageLoop()"; |
1149 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 1312 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
1150 DCHECK(requests_.empty()); | 1313 DCHECK(requests_.empty()); |
1151 if (device_thread_) { | 1314 if (device_thread_) { |
1152 StopMonitoring(); | 1315 StopMonitoring(); |
1153 | 1316 |
1154 video_capture_manager_->Unregister(); | 1317 video_capture_manager_->Unregister(); |
1155 audio_input_device_manager_->Unregister(); | 1318 audio_input_device_manager_->Unregister(); |
1156 device_thread_.reset(); | 1319 device_thread_.reset(); |
1157 } | 1320 } |
1158 | 1321 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 } | 1403 } |
1241 | 1404 |
1242 // Always do enumeration even though some enumeration is in progress, | 1405 // Always do enumeration even though some enumeration is in progress, |
1243 // because those enumeration commands could be sent before these devices | 1406 // because those enumeration commands could be sent before these devices |
1244 // change. | 1407 // change. |
1245 ++active_enumeration_ref_count_[stream_type]; | 1408 ++active_enumeration_ref_count_[stream_type]; |
1246 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1409 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
1247 } | 1410 } |
1248 | 1411 |
1249 } // namespace content | 1412 } // namespace content |
OLD | NEW |