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