Chromium Code Reviews| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 111 |
| 112 VideoCaptureManager::VideoCaptureManager( | 112 VideoCaptureManager::VideoCaptureManager( |
| 113 scoped_ptr<media::VideoCaptureDeviceFactory> factory) | 113 scoped_ptr<media::VideoCaptureDeviceFactory> factory) |
| 114 : listener_(NULL), | 114 : listener_(NULL), |
| 115 new_capture_session_id_(1), | 115 new_capture_session_id_(1), |
| 116 video_capture_device_factory_(factory.Pass()) { | 116 video_capture_device_factory_(factory.Pass()) { |
| 117 } | 117 } |
| 118 | 118 |
| 119 VideoCaptureManager::~VideoCaptureManager() { | 119 VideoCaptureManager::~VideoCaptureManager() { |
| 120 DCHECK(devices_.empty()); | 120 DCHECK(devices_.empty()); |
| 121 DCHECK(device_start_queue_.empty()); | |
| 121 } | 122 } |
| 122 | 123 |
| 123 void VideoCaptureManager::Register( | 124 void VideoCaptureManager::Register( |
| 124 MediaStreamProviderListener* listener, | 125 MediaStreamProviderListener* listener, |
| 125 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { | 126 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { |
| 126 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 127 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 127 DCHECK(!listener_); | 128 DCHECK(!listener_); |
| 128 DCHECK(!device_task_runner_.get()); | 129 DCHECK(!device_task_runner_.get()); |
| 129 listener_ = listener; | 130 listener_ = listener; |
| 130 device_task_runner_ = device_task_runner; | 131 device_task_runner_ = device_task_runner; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 DestroyDeviceEntryIfNoClients(existing_device); | 210 DestroyDeviceEntryIfNoClients(existing_device); |
| 210 } | 211 } |
| 211 | 212 |
| 212 // Notify listeners asynchronously, and forget the session. | 213 // Notify listeners asynchronously, and forget the session. |
| 213 base::MessageLoop::current()->PostTask(FROM_HERE, | 214 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 214 base::Bind(&VideoCaptureManager::OnClosed, this, session_it->second.type, | 215 base::Bind(&VideoCaptureManager::OnClosed, this, session_it->second.type, |
| 215 capture_session_id)); | 216 capture_session_id)); |
| 216 sessions_.erase(session_it); | 217 sessions_.erase(session_it); |
| 217 } | 218 } |
| 218 | 219 |
| 219 void VideoCaptureManager::DoStartDeviceOnDeviceThread( | 220 VideoCaptureManager:: |
| 221 CaptureDeviceStartRequest::CaptureDeviceStartRequest( | |
| 222 DeviceEntry* entry, | |
| 223 media::VideoCaptureSessionId session_id, | |
| 224 const media::VideoCaptureParams& params) | |
| 225 : entry(entry), | |
| 226 session_id(session_id), | |
| 227 params(params) { | |
| 228 } | |
| 229 | |
| 230 void VideoCaptureManager::QueueStartDevice( | |
| 220 media::VideoCaptureSessionId session_id, | 231 media::VideoCaptureSessionId session_id, |
| 221 DeviceEntry* entry, | 232 DeviceEntry* entry, |
| 233 const media::VideoCaptureParams& params) { | |
| 234 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 235 device_start_queue_.push_back( | |
| 236 CaptureDeviceStartRequest(entry, session_id, params)); | |
| 237 if (device_start_queue_.size() == 1) { | |
| 238 HandleQueuedStartRequest(); | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 void VideoCaptureManager::DoStopDevice(DeviceEntry* entry) { | |
| 243 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 244 | |
| 245 // Check if the start request has not yet been sent to the device thread. | |
| 246 // If so, delete the request. | |
| 247 if (device_start_queue_.size() > 1) { | |
| 248 for (DeviceStartQueue::iterator request = ++device_start_queue_.begin(); | |
| 249 request != device_start_queue_.end(); ++request) { | |
| 250 if (request->entry == entry) { | |
| 251 device_start_queue_.erase(request); | |
| 252 DVLOG(3) << "DoStopDevice, erasing start request for device " | |
| 253 << entry->id << "."; | |
| 254 return; | |
| 255 } | |
| 256 } | |
| 257 } | |
| 258 | |
| 259 DVLOG(3) << "DoStopDevice. Send stop request for device " << entry->id << "."; | |
| 260 if (entry->video_capture_device.get()) { | |
| 261 // |entry->video_capture_device| can be null if creating the device fails. | |
| 262 device_task_runner_->PostTask( | |
| 263 FROM_HERE, | |
| 264 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | |
| 265 base::Passed(entry->video_capture_device.Pass()))); | |
| 266 } | |
| 267 } | |
| 268 | |
| 269 void VideoCaptureManager::HandleQueuedStartRequest() { | |
| 270 auto request = device_start_queue_.begin(); | |
| 271 if (request == device_start_queue_.end()) | |
| 272 return; | |
| 273 | |
| 274 DCHECK(std::find(devices_.begin(), devices_.end(), request->entry) | |
| 275 != devices_.end()); | |
| 276 DeviceEntry* entry = request->entry; | |
| 277 | |
| 278 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = " | |
| 279 << entry->id; | |
| 280 | |
| 281 base::PostTaskAndReplyWithResult( | |
| 282 device_task_runner_.get(), | |
| 283 FROM_HERE, | |
| 284 base::Bind( | |
| 285 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | |
| 286 this, | |
| 287 request->session_id, | |
| 288 entry->id, | |
| 289 entry->stream_type, | |
| 290 request->params, | |
| 291 base::Passed(entry->video_capture_controller->NewDeviceClient())), | |
| 292 base::Bind(&VideoCaptureManager::OnDeviceStarted, this, entry)); | |
| 293 } | |
| 294 | |
| 295 void VideoCaptureManager::OnDeviceStarted( | |
| 296 DeviceEntry* device_entry, | |
| 297 scoped_ptr<media::VideoCaptureDevice> device) { | |
| 298 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 299 DVLOG(3) << "OnDeviceStarted"; | |
| 300 device_start_queue_.pop_front(); | |
| 301 | |
| 302 DeviceEntries::iterator entry_it = | |
| 303 std::find(devices_.begin(), devices_.end(), device_entry); | |
| 304 if (entry_it == devices_.end()) { | |
| 305 // |device| can be null if creation failed in DoStartDeviceOnDeviceThread. | |
| 306 // The device is no longer wanted. Stop the device again. | |
| 307 if (device.get() && !device_task_runner_->PostTask( | |
| 308 FROM_HERE, | |
| 309 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | |
| 310 base::Passed(&device)))) { | |
| 311 // PostTask failed. The Chrome browser process probably closing down so | |
|
perkj_chrome
2014/12/16 20:15:05
is
| |
| 312 // just stop the device. | |
| 313 device->StopAndDeAllocate(); | |
| 314 } | |
| 315 } else { | |
| 316 (*entry_it)->video_capture_device.reset(device.release()); | |
| 317 } | |
| 318 | |
| 319 HandleQueuedStartRequest(); | |
| 320 } | |
| 321 | |
| 322 scoped_ptr<media::VideoCaptureDevice> | |
| 323 VideoCaptureManager::DoStartDeviceOnDeviceThread( | |
| 324 media::VideoCaptureSessionId session_id, | |
| 325 const std::string& id, | |
| 326 MediaStreamType stream_type, | |
| 222 const media::VideoCaptureParams& params, | 327 const media::VideoCaptureParams& params, |
| 223 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { | 328 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { |
| 224 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 329 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
| 225 DCHECK(IsOnDeviceThread()); | 330 DCHECK(IsOnDeviceThread()); |
| 226 | 331 |
| 227 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 332 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
| 228 switch (entry->stream_type) { | 333 switch (stream_type) { |
| 229 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 334 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
| 230 // We look up the device id from the renderer in our local enumeration | 335 // We look up the device id from the renderer in our local enumeration |
| 231 // since the renderer does not have all the information that might be | 336 // since the renderer does not have all the information that might be |
| 232 // held in the browser-side VideoCaptureDevice::Name structure. | 337 // held in the browser-side VideoCaptureDevice::Name structure. |
| 233 media::VideoCaptureDeviceInfo* found = | 338 media::VideoCaptureDeviceInfo* found = |
| 234 FindDeviceInfoById(entry->id, devices_info_cache_); | 339 FindDeviceInfoById(id, devices_info_cache_); |
| 235 if (found) { | 340 if (found) { |
| 236 video_capture_device = | 341 video_capture_device = |
| 237 video_capture_device_factory_->Create(found->name); | 342 video_capture_device_factory_->Create(found->name); |
| 238 } | 343 } |
| 239 break; | 344 break; |
| 240 } | 345 } |
| 241 case MEDIA_TAB_VIDEO_CAPTURE: { | 346 case MEDIA_TAB_VIDEO_CAPTURE: { |
| 242 video_capture_device.reset( | 347 video_capture_device.reset( |
| 243 WebContentsVideoCaptureDevice::Create(entry->id)); | 348 WebContentsVideoCaptureDevice::Create(id)); |
| 244 break; | 349 break; |
| 245 } | 350 } |
| 246 case MEDIA_DESKTOP_VIDEO_CAPTURE: { | 351 case MEDIA_DESKTOP_VIDEO_CAPTURE: { |
| 247 #if defined(ENABLE_SCREEN_CAPTURE) | 352 #if defined(ENABLE_SCREEN_CAPTURE) |
| 248 DesktopMediaID id = DesktopMediaID::Parse(entry->id); | 353 DesktopMediaID desktop_id = DesktopMediaID::Parse(id); |
| 249 #if defined(USE_AURA) | 354 #if defined(USE_AURA) |
| 250 if (id.type == DesktopMediaID::TYPE_AURA_WINDOW) { | 355 if (desktop_id.type == DesktopMediaID::TYPE_AURA_WINDOW) { |
| 251 video_capture_device.reset(DesktopCaptureDeviceAura::Create(id)); | 356 video_capture_device.reset( |
| 357 DesktopCaptureDeviceAura::Create(desktop_id)); | |
| 252 } else | 358 } else |
| 253 #endif | 359 #endif |
| 254 if (id.type != DesktopMediaID::TYPE_NONE && | 360 if (desktop_id.type != DesktopMediaID::TYPE_NONE && |
| 255 id.type != DesktopMediaID::TYPE_AURA_WINDOW) { | 361 desktop_id.type != DesktopMediaID::TYPE_AURA_WINDOW) { |
| 256 video_capture_device = DesktopCaptureDevice::Create(id); | 362 video_capture_device = DesktopCaptureDevice::Create(desktop_id); |
| 257 if (notification_window_ids_.find(session_id) != | 363 if (notification_window_ids_.find(session_id) != |
| 258 notification_window_ids_.end()) { | 364 notification_window_ids_.end()) { |
| 259 static_cast<DesktopCaptureDevice*>(video_capture_device.get()) | 365 static_cast<DesktopCaptureDevice*>(video_capture_device.get()) |
| 260 ->SetNotificationWindowId(notification_window_ids_[session_id]); | 366 ->SetNotificationWindowId(notification_window_ids_[session_id]); |
| 261 VLOG(2) << "Screen capture notification window passed for session " | 367 VLOG(2) << "Screen capture notification window passed for session " |
| 262 << session_id; | 368 << session_id; |
| 263 } | 369 } |
| 264 } | 370 } |
| 265 #endif // defined(ENABLE_SCREEN_CAPTURE) | 371 #endif // defined(ENABLE_SCREEN_CAPTURE) |
| 266 break; | 372 break; |
| 267 } | 373 } |
| 268 default: { | 374 default: { |
| 269 NOTIMPLEMENTED(); | 375 NOTIMPLEMENTED(); |
| 270 break; | 376 break; |
| 271 } | 377 } |
| 272 } | 378 } |
| 273 | 379 |
| 274 if (!video_capture_device) { | 380 if (!video_capture_device) { |
| 275 device_client->OnError("Could not create capture device"); | 381 device_client->OnError("Could not create capture device"); |
| 276 return; | 382 return nullptr; |
| 277 } | 383 } |
| 278 | 384 |
| 279 video_capture_device->AllocateAndStart(params, device_client.Pass()); | 385 video_capture_device->AllocateAndStart(params, device_client.Pass()); |
| 280 entry->video_capture_device = video_capture_device.Pass(); | 386 return video_capture_device.Pass(); |
| 281 } | 387 } |
| 282 | 388 |
| 283 void VideoCaptureManager::StartCaptureForClient( | 389 void VideoCaptureManager::StartCaptureForClient( |
| 284 media::VideoCaptureSessionId session_id, | 390 media::VideoCaptureSessionId session_id, |
| 285 const media::VideoCaptureParams& params, | 391 const media::VideoCaptureParams& params, |
| 286 base::ProcessHandle client_render_process, | 392 base::ProcessHandle client_render_process, |
| 287 VideoCaptureControllerID client_id, | 393 VideoCaptureControllerID client_id, |
| 288 VideoCaptureControllerEventHandler* client_handler, | 394 VideoCaptureControllerEventHandler* client_handler, |
| 289 const DoneCB& done_cb) { | 395 const DoneCB& done_cb) { |
| 290 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 396 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 291 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, " | 397 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, " |
| 292 << params.requested_format.frame_size.ToString() << ", " | 398 << params.requested_format.frame_size.ToString() << ", " |
| 293 << params.requested_format.frame_rate << ", #" << session_id << ")"; | 399 << params.requested_format.frame_rate << ", #" << session_id << ")"; |
| 294 | 400 |
| 295 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id); | 401 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id); |
| 296 if (!entry) { | 402 if (!entry) { |
| 297 done_cb.Run(base::WeakPtr<VideoCaptureController>()); | 403 done_cb.Run(base::WeakPtr<VideoCaptureController>()); |
| 298 return; | 404 return; |
| 299 } | 405 } |
| 300 | 406 |
| 301 DCHECK(entry->video_capture_controller); | 407 DCHECK(entry->video_capture_controller); |
| 302 | 408 |
| 303 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE); | 409 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE); |
| 304 | 410 |
| 305 // First client starts the device. | 411 // First client starts the device. |
| 306 if (entry->video_capture_controller->GetActiveClientCount() == 0) { | 412 if (entry->video_capture_controller->GetActiveClientCount() == 0) { |
| 307 DVLOG(1) << "VideoCaptureManager starting device (type = " | 413 DVLOG(1) << "VideoCaptureManager starting device (type = " |
| 308 << entry->stream_type << ", id = " << entry->id << ")"; | 414 << entry->stream_type << ", id = " << entry->id << ")"; |
| 309 | 415 QueueStartDevice(session_id, entry, params); |
| 310 device_task_runner_->PostTask( | |
| 311 FROM_HERE, | |
| 312 base::Bind( | |
| 313 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | |
| 314 this, | |
| 315 session_id, | |
| 316 entry, | |
| 317 params, | |
| 318 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | |
| 319 } | 416 } |
| 320 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 417 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
| 321 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); | 418 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); |
| 322 entry->video_capture_controller->AddClient( | 419 entry->video_capture_controller->AddClient( |
| 323 client_id, client_handler, client_render_process, session_id, params); | 420 client_id, client_handler, client_render_process, session_id, params); |
| 324 } | 421 } |
| 325 | 422 |
| 326 void VideoCaptureManager::StopCaptureForClient( | 423 void VideoCaptureManager::StopCaptureForClient( |
| 327 VideoCaptureController* controller, | 424 VideoCaptureController* controller, |
| 328 VideoCaptureControllerID client_id, | 425 VideoCaptureControllerID client_id, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 // We only pause the MEDIA_DEVICE_VIDEO_CAPTURE entry to release camera to | 482 // We only pause the MEDIA_DEVICE_VIDEO_CAPTURE entry to release camera to |
| 386 // system. | 483 // system. |
| 387 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) | 484 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) |
| 388 return; | 485 return; |
| 389 | 486 |
| 390 controller->PauseOrResumeClient(client_id, client_handler, true); | 487 controller->PauseOrResumeClient(client_id, client_handler, true); |
| 391 if (controller->GetActiveClientCount() != 0) | 488 if (controller->GetActiveClientCount() != 0) |
| 392 return; | 489 return; |
| 393 | 490 |
| 394 // There is no more client, release the camera. | 491 // There is no more client, release the camera. |
| 395 device_task_runner_->PostTask( | 492 DoStopDevice(entry); |
| 396 FROM_HERE, | |
| 397 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | |
| 398 base::Unretained(entry))); | |
| 399 } | 493 } |
| 400 | 494 |
| 401 void VideoCaptureManager::ResumeCaptureForClient( | 495 void VideoCaptureManager::ResumeCaptureForClient( |
| 402 media::VideoCaptureSessionId session_id, | 496 media::VideoCaptureSessionId session_id, |
| 403 const media::VideoCaptureParams& params, | 497 const media::VideoCaptureParams& params, |
| 404 VideoCaptureController* controller, | 498 VideoCaptureController* controller, |
| 405 VideoCaptureControllerID client_id, | 499 VideoCaptureControllerID client_id, |
| 406 VideoCaptureControllerEventHandler* client_handler) { | 500 VideoCaptureControllerEventHandler* client_handler) { |
| 407 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 501 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 408 DCHECK(controller); | 502 DCHECK(controller); |
| 409 DCHECK(client_handler); | 503 DCHECK(client_handler); |
| 410 | 504 |
| 411 DeviceEntry* entry = GetDeviceEntryForController(controller); | 505 DeviceEntry* entry = GetDeviceEntryForController(controller); |
| 412 if (!entry) { | 506 if (!entry) { |
| 413 NOTREACHED(); | 507 NOTREACHED(); |
| 414 return; | 508 return; |
| 415 } | 509 } |
| 416 | 510 |
| 417 // We only pause/resume the MEDIA_DEVICE_VIDEO_CAPTURE entry. | 511 // We only pause/resume the MEDIA_DEVICE_VIDEO_CAPTURE entry. |
| 418 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) | 512 if (entry->stream_type != MEDIA_DEVICE_VIDEO_CAPTURE) |
| 419 return; | 513 return; |
| 420 | 514 |
| 421 controller->PauseOrResumeClient(client_id, client_handler, false); | 515 controller->PauseOrResumeClient(client_id, client_handler, false); |
| 422 if (controller->GetActiveClientCount() != 1) | 516 if (controller->GetActiveClientCount() != 1) |
| 423 return; | 517 return; |
| 424 | 518 |
| 425 // This is first active client, allocate the camera. | 519 // This is first active client, allocate the camera. |
| 426 device_task_runner_->PostTask( | 520 QueueStartDevice(session_id, entry, params); |
| 427 FROM_HERE, | |
| 428 base::Bind( | |
| 429 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | |
| 430 this, | |
| 431 session_id, | |
| 432 entry, | |
| 433 params, | |
| 434 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | |
| 435 } | 521 } |
| 436 | 522 |
| 437 bool VideoCaptureManager::GetDeviceSupportedFormats( | 523 bool VideoCaptureManager::GetDeviceSupportedFormats( |
| 438 media::VideoCaptureSessionId capture_session_id, | 524 media::VideoCaptureSessionId capture_session_id, |
| 439 media::VideoCaptureFormats* supported_formats) { | 525 media::VideoCaptureFormats* supported_formats) { |
| 440 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 526 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 441 DCHECK(supported_formats->empty()); | 527 DCHECK(supported_formats->empty()); |
| 442 | 528 |
| 443 SessionMap::iterator it = sessions_.find(capture_session_id); | 529 SessionMap::iterator it = sessions_.find(capture_session_id); |
| 444 if (it == sessions_.end()) | 530 if (it == sessions_.end()) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 } | 596 } |
| 511 | 597 |
| 512 device_task_runner_->PostTask( | 598 device_task_runner_->PostTask( |
| 513 FROM_HERE, | 599 FROM_HERE, |
| 514 base::Bind(&VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread, | 600 base::Bind(&VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread, |
| 515 this, | 601 this, |
| 516 existing_device, | 602 existing_device, |
| 517 window_id)); | 603 window_id)); |
| 518 } | 604 } |
| 519 | 605 |
| 520 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 606 void VideoCaptureManager::DoStopDeviceOnDeviceThread( |
| 607 scoped_ptr<media::VideoCaptureDevice> device) { | |
| 521 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 608 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
| 522 DCHECK(IsOnDeviceThread()); | 609 DCHECK(IsOnDeviceThread()); |
| 523 if (entry->video_capture_device) { | 610 device->StopAndDeAllocate(); |
| 524 entry->video_capture_device->StopAndDeAllocate(); | 611 DVLOG(3) << "DoStopDeviceOnDeviceThread"; |
| 525 } | |
| 526 entry->video_capture_device.reset(); | |
| 527 } | 612 } |
| 528 | 613 |
| 529 void VideoCaptureManager::OnOpened( | 614 void VideoCaptureManager::OnOpened( |
| 530 MediaStreamType stream_type, | 615 MediaStreamType stream_type, |
| 531 media::VideoCaptureSessionId capture_session_id) { | 616 media::VideoCaptureSessionId capture_session_id) { |
| 532 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 617 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 533 if (!listener_) { | 618 if (!listener_) { |
| 534 // Listener has been removed. | 619 // Listener has been removed. |
| 535 return; | 620 return; |
| 536 } | 621 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 731 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 647 // Removal of the last client stops the device. | 732 // Removal of the last client stops the device. |
| 648 if (entry->video_capture_controller->GetClientCount() == 0) { | 733 if (entry->video_capture_controller->GetClientCount() == 0) { |
| 649 DVLOG(1) << "VideoCaptureManager stopping device (type = " | 734 DVLOG(1) << "VideoCaptureManager stopping device (type = " |
| 650 << entry->stream_type << ", id = " << entry->id << ")"; | 735 << entry->stream_type << ", id = " << entry->id << ")"; |
| 651 | 736 |
| 652 // The DeviceEntry is removed from |devices_| immediately. The controller is | 737 // The DeviceEntry is removed from |devices_| immediately. The controller is |
| 653 // deleted immediately, and the device is freed asynchronously. After this | 738 // deleted immediately, and the device is freed asynchronously. After this |
| 654 // point, subsequent requests to open this same device ID will create a new | 739 // point, subsequent requests to open this same device ID will create a new |
| 655 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. | 740 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. |
| 656 devices_.erase(entry); | 741 DoStopDevice(entry); |
| 657 entry->video_capture_controller.reset(); | 742 DeviceEntries::iterator device_it = std::find(devices_.begin(), |
| 658 device_task_runner_->PostTask( | 743 devices_.end(), |
| 659 FROM_HERE, | 744 entry); |
| 660 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 745 devices_.erase(device_it); |
| 661 base::Owned(entry))); | |
| 662 } | 746 } |
| 663 } | 747 } |
| 664 | 748 |
| 665 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 749 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
| 666 media::VideoCaptureSessionId capture_session_id) { | 750 media::VideoCaptureSessionId capture_session_id) { |
| 667 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 751 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 668 | 752 |
| 669 SessionMap::iterator session_it = sessions_.find(capture_session_id); | 753 SessionMap::iterator session_it = sessions_.find(capture_session_id); |
| 670 if (session_it == sessions_.end()) { | 754 if (session_it == sessions_.end()) { |
| 671 return NULL; | 755 return NULL; |
| 672 } | 756 } |
| 673 const MediaStreamDevice& device_info = session_it->second; | 757 const MediaStreamDevice& device_info = session_it->second; |
| 674 | 758 |
| 675 // Check if another session has already opened this device. If so, just | 759 // Check if another session has already opened this device. If so, just |
| 676 // use that opened device. | 760 // use that opened device. |
| 677 DeviceEntry* const existing_device = | 761 DeviceEntry* const existing_device = |
| 678 GetDeviceEntryForMediaStreamDevice(device_info); | 762 GetDeviceEntryForMediaStreamDevice(device_info); |
| 679 if (existing_device) { | 763 if (existing_device) { |
| 680 DCHECK_EQ(device_info.type, existing_device->stream_type); | 764 DCHECK_EQ(device_info.type, existing_device->stream_type); |
| 681 return existing_device; | 765 return existing_device; |
| 682 } | 766 } |
| 683 | 767 |
| 684 const int max_buffers = device_info.type == MEDIA_TAB_VIDEO_CAPTURE ? | 768 const int max_buffers = device_info.type == MEDIA_TAB_VIDEO_CAPTURE ? |
| 685 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers; | 769 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers; |
| 686 scoped_ptr<VideoCaptureController> video_capture_controller( | 770 scoped_ptr<VideoCaptureController> video_capture_controller( |
| 687 new VideoCaptureController(max_buffers)); | 771 new VideoCaptureController(max_buffers)); |
| 688 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 772 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
| 689 device_info.id, | 773 device_info.id, |
| 690 video_capture_controller.Pass()); | 774 video_capture_controller.Pass()); |
| 691 devices_.insert(new_device); | 775 devices_.push_back(new_device); |
| 692 return new_device; | 776 return new_device; |
| 693 } | 777 } |
| 694 | 778 |
| 695 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById( | 779 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById( |
| 696 const std::string& id, | 780 const std::string& id, |
| 697 media::VideoCaptureDeviceInfos& device_vector) { | 781 media::VideoCaptureDeviceInfos& device_vector) { |
| 698 for (auto& it : device_vector) { | 782 for (auto& it : device_vector) { |
| 699 if (it.name.id() == id) | 783 if (it.name.id() == id) |
| 700 return &(it); | 784 return &(it); |
| 701 } | 785 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 720 gfx::NativeViewId window_id) { | 804 gfx::NativeViewId window_id) { |
| 721 DCHECK(IsOnDeviceThread()); | 805 DCHECK(IsOnDeviceThread()); |
| 722 DCHECK(notification_window_ids_.find(session_id) == | 806 DCHECK(notification_window_ids_.find(session_id) == |
| 723 notification_window_ids_.end()); | 807 notification_window_ids_.end()); |
| 724 notification_window_ids_[session_id] = window_id; | 808 notification_window_ids_[session_id] = window_id; |
| 725 VLOG(2) << "Screen capture notification window saved for session " | 809 VLOG(2) << "Screen capture notification window saved for session " |
| 726 << session_id << " on device thread."; | 810 << session_id << " on device thread."; |
| 727 } | 811 } |
| 728 | 812 |
| 729 } // namespace content | 813 } // namespace content |
| OLD | NEW |