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/video_capture_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 base::Bind(&VideoCaptureManager::OnOpened, this, | 153 base::Bind(&VideoCaptureManager::OnOpened, this, |
154 device_info.device.type, capture_session_id)); | 154 device_info.device.type, capture_session_id)); |
155 return capture_session_id; | 155 return capture_session_id; |
156 } | 156 } |
157 | 157 |
158 void VideoCaptureManager::Close(int capture_session_id) { | 158 void VideoCaptureManager::Close(int capture_session_id) { |
159 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 159 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
160 DCHECK(listener_); | 160 DCHECK(listener_); |
161 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id; | 161 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id; |
162 | 162 |
163 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator | 163 SessionMap::iterator session_it = sessions_.find(capture_session_id); |
164 session_it = sessions_.find(capture_session_id); | |
165 if (session_it == sessions_.end()) { | 164 if (session_it == sessions_.end()) { |
166 NOTREACHED(); | 165 NOTREACHED(); |
167 return; | 166 return; |
168 } | 167 } |
169 | 168 |
170 DeviceEntry* const existing_device = GetDeviceEntryForMediaStreamDevice( | 169 DeviceEntry* const existing_device = GetDeviceEntryForMediaStreamDevice( |
171 session_it->second); | 170 session_it->second); |
172 if (existing_device) { | 171 if (existing_device) { |
173 // Remove any client that is still using the session. This is safe to call | 172 // Remove any client that is still using the session. This is safe to call |
174 // even if there are no clients using the session. | 173 // even if there are no clients using the session. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 304 } |
306 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 305 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
307 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); | 306 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); |
308 entry->video_capture_controller->AddClient( | 307 entry->video_capture_controller->AddClient( |
309 client_id, client_handler, client_render_process, session_id, params); | 308 client_id, client_handler, client_render_process, session_id, params); |
310 } | 309 } |
311 | 310 |
312 void VideoCaptureManager::StopCaptureForClient( | 311 void VideoCaptureManager::StopCaptureForClient( |
313 VideoCaptureController* controller, | 312 VideoCaptureController* controller, |
314 VideoCaptureControllerID client_id, | 313 VideoCaptureControllerID client_id, |
315 VideoCaptureControllerEventHandler* client_handler) { | 314 VideoCaptureControllerEventHandler* client_handler, |
| 315 bool aborted_due_to_error) { |
316 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 316 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
317 DCHECK(controller); | 317 DCHECK(controller); |
318 DCHECK(client_handler); | 318 DCHECK(client_handler); |
319 | 319 |
320 DeviceEntry* entry = GetDeviceEntryForController(controller); | 320 DeviceEntry* entry = GetDeviceEntryForController(controller); |
321 if (!entry) { | 321 if (!entry) { |
322 NOTREACHED(); | 322 NOTREACHED(); |
323 return; | 323 return; |
324 } | 324 } |
| 325 if (aborted_due_to_error) { |
| 326 SessionMap::iterator it; |
| 327 for (it = sessions_.begin(); it != sessions_.end(); ++it) { |
| 328 if (it->second.type == entry->stream_type && |
| 329 it->second.id == entry->id) { |
| 330 listener_->Aborted(it->second.type, it->first); |
| 331 break; |
| 332 } |
| 333 } |
| 334 } |
325 | 335 |
326 // Detach client from controller. | 336 // Detach client from controller. |
327 media::VideoCaptureSessionId session_id = | 337 media::VideoCaptureSessionId session_id = |
328 controller->RemoveClient(client_id, client_handler); | 338 controller->RemoveClient(client_id, client_handler); |
329 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 339 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
330 << session_id; | 340 << session_id; |
331 | 341 |
332 // If controller has no more clients, delete controller and device. | 342 // If controller has no more clients, delete controller and device. |
333 DestroyDeviceEntryIfNoClients(entry); | 343 DestroyDeviceEntryIfNoClients(entry); |
334 } | 344 } |
335 | 345 |
336 bool VideoCaptureManager::GetDeviceSupportedFormats( | 346 bool VideoCaptureManager::GetDeviceSupportedFormats( |
337 media::VideoCaptureSessionId capture_session_id, | 347 media::VideoCaptureSessionId capture_session_id, |
338 media::VideoCaptureFormats* supported_formats) { | 348 media::VideoCaptureFormats* supported_formats) { |
339 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 349 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
340 DCHECK(supported_formats->empty()); | 350 DCHECK(supported_formats->empty()); |
341 | 351 |
342 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator it = | 352 SessionMap::iterator it = sessions_.find(capture_session_id); |
343 sessions_.find(capture_session_id); | |
344 if (it == sessions_.end()) | 353 if (it == sessions_.end()) |
345 return false; | 354 return false; |
346 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; | 355 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; |
347 | 356 |
348 // Return all available formats of the device, regardless its started state. | 357 // Return all available formats of the device, regardless its started state. |
349 DeviceInfo* existing_device = | 358 DeviceInfo* existing_device = |
350 FindDeviceInfoById(it->second.id, devices_info_cache_); | 359 FindDeviceInfoById(it->second.id, devices_info_cache_); |
351 if (existing_device) | 360 if (existing_device) |
352 *supported_formats = existing_device->supported_formats; | 361 *supported_formats = existing_device->supported_formats; |
353 return true; | 362 return true; |
354 } | 363 } |
355 | 364 |
356 bool VideoCaptureManager::GetDeviceFormatsInUse( | 365 bool VideoCaptureManager::GetDeviceFormatsInUse( |
357 media::VideoCaptureSessionId capture_session_id, | 366 media::VideoCaptureSessionId capture_session_id, |
358 media::VideoCaptureFormats* formats_in_use) { | 367 media::VideoCaptureFormats* formats_in_use) { |
359 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 368 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
360 DCHECK(formats_in_use->empty()); | 369 DCHECK(formats_in_use->empty()); |
361 | 370 |
362 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator it = | 371 SessionMap::iterator it = sessions_.find(capture_session_id); |
363 sessions_.find(capture_session_id); | |
364 if (it == sessions_.end()) | 372 if (it == sessions_.end()) |
365 return false; | 373 return false; |
366 DVLOG(1) << "GetDeviceFormatsInUse for device: " << it->second.name; | 374 DVLOG(1) << "GetDeviceFormatsInUse for device: " << it->second.name; |
367 | 375 |
368 // Return the currently in-use format(s) of the device, if it's started. | 376 // Return the currently in-use format(s) of the device, if it's started. |
369 DeviceEntry* device_in_use = | 377 DeviceEntry* device_in_use = |
370 GetDeviceEntryForMediaStreamDevice(it->second); | 378 GetDeviceEntryForMediaStreamDevice(it->second); |
371 if (device_in_use) { | 379 if (device_in_use) { |
372 // Currently only one format-in-use is supported at the VCC level. | 380 // Currently only one format-in-use is supported at the VCC level. |
373 formats_in_use->push_back( | 381 formats_in_use->push_back( |
374 device_in_use->video_capture_controller->GetVideoCaptureFormat()); | 382 device_in_use->video_capture_controller->GetVideoCaptureFormat()); |
375 } | 383 } |
376 return true; | 384 return true; |
377 } | 385 } |
378 | 386 |
379 void VideoCaptureManager::SetDesktopCaptureWindowId( | 387 void VideoCaptureManager::SetDesktopCaptureWindowId( |
380 media::VideoCaptureSessionId session_id, | 388 media::VideoCaptureSessionId session_id, |
381 gfx::NativeViewId window_id) { | 389 gfx::NativeViewId window_id) { |
382 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 390 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
383 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator | 391 SessionMap::iterator session_it = sessions_.find(session_id); |
384 session_it = sessions_.find(session_id); | |
385 if (session_it == sessions_.end()) { | 392 if (session_it == sessions_.end()) { |
386 device_task_runner_->PostTask( | 393 device_task_runner_->PostTask( |
387 FROM_HERE, | 394 FROM_HERE, |
388 base::Bind( | 395 base::Bind( |
389 &VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread, | 396 &VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread, |
390 this, | 397 this, |
391 session_id, | 398 session_id, |
392 window_id)); | 399 window_id)); |
393 return; | 400 return; |
394 } | 401 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 if (device_info.type == device->stream_type && | 567 if (device_info.type == device->stream_type && |
561 device_info.id == device->id) { | 568 device_info.id == device->id) { |
562 return device; | 569 return device; |
563 } | 570 } |
564 } | 571 } |
565 return NULL; | 572 return NULL; |
566 } | 573 } |
567 | 574 |
568 VideoCaptureManager::DeviceEntry* | 575 VideoCaptureManager::DeviceEntry* |
569 VideoCaptureManager::GetDeviceEntryForController( | 576 VideoCaptureManager::GetDeviceEntryForController( |
570 const VideoCaptureController* controller) { | 577 const VideoCaptureController* controller) const { |
571 // Look up |controller| in |devices_|. | 578 // Look up |controller| in |devices_|. |
572 for (DeviceEntries::iterator it = devices_.begin(); | 579 for (DeviceEntries::const_iterator it = devices_.begin(); |
573 it != devices_.end(); ++it) { | 580 it != devices_.end(); ++it) { |
574 if ((*it)->video_capture_controller.get() == controller) { | 581 if ((*it)->video_capture_controller.get() == controller) { |
575 return *it; | 582 return *it; |
576 } | 583 } |
577 } | 584 } |
578 return NULL; | 585 return NULL; |
579 } | 586 } |
580 | 587 |
581 void VideoCaptureManager::DestroyDeviceEntryIfNoClients(DeviceEntry* entry) { | 588 void VideoCaptureManager::DestroyDeviceEntryIfNoClients(DeviceEntry* entry) { |
582 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 589 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
(...skipping 12 matching lines...) Expand all Loading... |
595 FROM_HERE, | 602 FROM_HERE, |
596 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 603 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, |
597 base::Owned(entry))); | 604 base::Owned(entry))); |
598 } | 605 } |
599 } | 606 } |
600 | 607 |
601 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 608 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
602 media::VideoCaptureSessionId capture_session_id) { | 609 media::VideoCaptureSessionId capture_session_id) { |
603 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 610 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
604 | 611 |
605 std::map<media::VideoCaptureSessionId, MediaStreamDevice>::iterator | 612 SessionMap::iterator session_it = sessions_.find(capture_session_id); |
606 session_it = sessions_.find(capture_session_id); | |
607 if (session_it == sessions_.end()) { | 613 if (session_it == sessions_.end()) { |
608 return NULL; | 614 return NULL; |
609 } | 615 } |
610 const MediaStreamDevice& device_info = session_it->second; | 616 const MediaStreamDevice& device_info = session_it->second; |
611 | 617 |
612 // Check if another session has already opened this device. If so, just | 618 // Check if another session has already opened this device. If so, just |
613 // use that opened device. | 619 // use that opened device. |
614 DeviceEntry* const existing_device = | 620 DeviceEntry* const existing_device = |
615 GetDeviceEntryForMediaStreamDevice(device_info); | 621 GetDeviceEntryForMediaStreamDevice(device_info); |
616 if (existing_device) { | 622 if (existing_device) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( | 659 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( |
654 media::VideoCaptureSessionId session_id, | 660 media::VideoCaptureSessionId session_id, |
655 gfx::NativeViewId window_id) { | 661 gfx::NativeViewId window_id) { |
656 DCHECK(IsOnDeviceThread()); | 662 DCHECK(IsOnDeviceThread()); |
657 DCHECK(notification_window_ids_.find(session_id) == | 663 DCHECK(notification_window_ids_.find(session_id) == |
658 notification_window_ids_.end()); | 664 notification_window_ids_.end()); |
659 notification_window_ids_[session_id] = window_id; | 665 notification_window_ids_[session_id] = window_id; |
660 } | 666 } |
661 | 667 |
662 } // namespace content | 668 } // namespace content |
OLD | NEW |