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