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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 if (!entry) { | 301 if (!entry) { |
302 done_cb.Run(base::WeakPtr<VideoCaptureController>()); | 302 done_cb.Run(base::WeakPtr<VideoCaptureController>()); |
303 return; | 303 return; |
304 } | 304 } |
305 | 305 |
306 DCHECK(entry->video_capture_controller); | 306 DCHECK(entry->video_capture_controller); |
307 | 307 |
308 LogVideoCaptureEvent(VIDEO_CAPTURE_EVENT_START_CAPTURE); | 308 LogVideoCaptureEvent(VIDEO_CAPTURE_EVENT_START_CAPTURE); |
309 | 309 |
310 // First client starts the device. | 310 // First client starts the device. |
311 if (entry->video_capture_controller->GetClientCount() == 0) { | 311 if (entry->video_capture_controller->GetActiveClientCount() == 0) { |
312 DVLOG(1) << "VideoCaptureManager starting device (type = " | 312 DVLOG(1) << "VideoCaptureManager starting device (type = " |
313 << entry->stream_type << ", id = " << entry->id << ")"; | 313 << entry->stream_type << ", id = " << entry->id << ")"; |
314 | 314 |
315 device_task_runner_->PostTask( | 315 device_task_runner_->PostTask( |
316 FROM_HERE, | 316 FROM_HERE, |
317 base::Bind( | 317 base::Bind( |
318 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | 318 &VideoCaptureManager::DoStartDeviceOnDeviceThread, |
319 this, | 319 this, |
320 session_id, | 320 session_id, |
321 entry, | 321 entry, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // Detach client from controller. | 360 // Detach client from controller. |
361 media::VideoCaptureSessionId session_id = | 361 media::VideoCaptureSessionId session_id = |
362 controller->RemoveClient(client_id, client_handler); | 362 controller->RemoveClient(client_id, client_handler); |
363 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 363 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
364 << session_id; | 364 << session_id; |
365 | 365 |
366 // If controller has no more clients, delete controller and device. | 366 // If controller has no more clients, delete controller and device. |
367 DestroyDeviceEntryIfNoClients(entry); | 367 DestroyDeviceEntryIfNoClients(entry); |
368 } | 368 } |
369 | 369 |
| 370 void VideoCaptureManager::PauseCaptureForClient( |
| 371 VideoCaptureController* controller, |
| 372 VideoCaptureControllerID client_id, |
| 373 VideoCaptureControllerEventHandler* client_handler) { |
| 374 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 375 DCHECK(controller); |
| 376 DCHECK(client_handler); |
| 377 DeviceEntry* entry = GetDeviceEntryForController(controller); |
| 378 if (!entry) { |
| 379 NOTREACHED(); |
| 380 return; |
| 381 } |
| 382 |
| 383 // We only pause the MEDIA_DEVICE_VIDEO_CAPTURE entry to release camera to |
| 384 // system. |
| 385 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) |
| 386 return; |
| 387 |
| 388 controller->PauseOrResumeClient(client_id, client_handler, true); |
| 389 if (controller->GetActiveClientCount() != 0) |
| 390 return; |
| 391 |
| 392 // There is no more client, release the camera. |
| 393 device_task_runner_->PostTask( |
| 394 FROM_HERE, |
| 395 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, |
| 396 base::Unretained(entry))); |
| 397 } |
| 398 |
| 399 void VideoCaptureManager::ResumeCaptureForClient( |
| 400 media::VideoCaptureSessionId session_id, |
| 401 const media::VideoCaptureParams& params, |
| 402 VideoCaptureController* controller, |
| 403 VideoCaptureControllerID client_id, |
| 404 VideoCaptureControllerEventHandler* client_handler) { |
| 405 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 406 DCHECK(controller); |
| 407 DCHECK(client_handler); |
| 408 |
| 409 DeviceEntry* entry = GetDeviceEntryForController(controller); |
| 410 if (!entry) { |
| 411 NOTREACHED(); |
| 412 return; |
| 413 } |
| 414 |
| 415 // We only pause/resume the MEDIA_DEVICE_VIDEO_CAPTURE entry. |
| 416 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) |
| 417 return; |
| 418 |
| 419 controller->PauseOrResumeClient(client_id, client_handler, false); |
| 420 if (controller->GetActiveClientCount() != 1) |
| 421 return; |
| 422 |
| 423 // This is first active client, allocate the camera. |
| 424 device_task_runner_->PostTask( |
| 425 FROM_HERE, |
| 426 base::Bind( |
| 427 &VideoCaptureManager::DoStartDeviceOnDeviceThread, |
| 428 this, |
| 429 session_id, |
| 430 entry, |
| 431 params, |
| 432 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
| 433 } |
| 434 |
370 bool VideoCaptureManager::GetDeviceSupportedFormats( | 435 bool VideoCaptureManager::GetDeviceSupportedFormats( |
371 media::VideoCaptureSessionId capture_session_id, | 436 media::VideoCaptureSessionId capture_session_id, |
372 media::VideoCaptureFormats* supported_formats) { | 437 media::VideoCaptureFormats* supported_formats) { |
373 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 438 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
374 DCHECK(supported_formats->empty()); | 439 DCHECK(supported_formats->empty()); |
375 | 440 |
376 SessionMap::iterator it = sessions_.find(capture_session_id); | 441 SessionMap::iterator it = sessions_.find(capture_session_id); |
377 if (it == sessions_.end()) | 442 if (it == sessions_.end()) |
378 return false; | 443 return false; |
379 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; | 444 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 gfx::NativeViewId window_id) { | 722 gfx::NativeViewId window_id) { |
658 DCHECK(IsOnDeviceThread()); | 723 DCHECK(IsOnDeviceThread()); |
659 DCHECK(notification_window_ids_.find(session_id) == | 724 DCHECK(notification_window_ids_.find(session_id) == |
660 notification_window_ids_.end()); | 725 notification_window_ids_.end()); |
661 notification_window_ids_[session_id] = window_id; | 726 notification_window_ids_[session_id] = window_id; |
662 VLOG(2) << "Screen capture notification window saved for session " | 727 VLOG(2) << "Screen capture notification window saved for session " |
663 << session_id << " on device thread."; | 728 << session_id << " on device thread."; |
664 } | 729 } |
665 | 730 |
666 } // namespace content | 731 } // namespace content |
OLD | NEW |