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/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/task_runner_util.h" | |
| 14 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "content/browser/renderer_host/media/video_capture_controller.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 17 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| 17 #include "content/browser/renderer_host/media/web_contents_video_capture_device. h" | 18 #include "content/browser/renderer_host/media/web_contents_video_capture_device. h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/common/desktop_media_id.h" | 21 #include "content/public/common/desktop_media_id.h" |
| 21 #include "content/public/common/media_stream_request.h" | 22 #include "content/public/common/media_stream_request.h" |
| 22 #include "media/base/scoped_histogram_timer.h" | 23 #include "media/base/scoped_histogram_timer.h" |
| 23 #include "media/video/capture/fake_video_capture_device.h" | 24 #include "media/video/capture/fake_video_capture_device.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 35 VideoCaptureManager::DeviceEntry::DeviceEntry( | 36 VideoCaptureManager::DeviceEntry::DeviceEntry( |
| 36 MediaStreamType stream_type, | 37 MediaStreamType stream_type, |
| 37 const std::string& id, | 38 const std::string& id, |
| 38 scoped_ptr<VideoCaptureController> controller) | 39 scoped_ptr<VideoCaptureController> controller) |
| 39 : stream_type(stream_type), | 40 : stream_type(stream_type), |
| 40 id(id), | 41 id(id), |
| 41 video_capture_controller(controller.Pass()) {} | 42 video_capture_controller(controller.Pass()) {} |
| 42 | 43 |
| 43 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} | 44 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} |
| 44 | 45 |
| 46 VideoCaptureManager::DeviceInfo::DeviceInfo() {} | |
| 47 | |
| 48 VideoCaptureManager::DeviceInfo::DeviceInfo( | |
| 49 const media::VideoCaptureDevice::Name& name, | |
| 50 const media::VideoCaptureFormats& supported_formats) | |
| 51 : name(name), | |
| 52 supported_formats(supported_formats) {} | |
| 53 | |
| 54 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} | |
| 55 | |
| 45 VideoCaptureManager::VideoCaptureManager() | 56 VideoCaptureManager::VideoCaptureManager() |
| 46 : listener_(NULL), | 57 : listener_(NULL), |
| 47 new_capture_session_id_(1), | 58 new_capture_session_id_(1), |
| 48 use_fake_device_(false) { | 59 use_fake_device_(false) { |
| 49 } | 60 } |
| 50 | 61 |
| 51 VideoCaptureManager::~VideoCaptureManager() { | 62 VideoCaptureManager::~VideoCaptureManager() { |
| 52 DCHECK(devices_.empty()); | 63 DCHECK(devices_.empty()); |
| 53 } | 64 } |
| 54 | 65 |
| 55 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, | 66 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, |
| 56 base::MessageLoopProxy* device_thread_loop) { | 67 base::MessageLoopProxy* device_thread_loop) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 58 DCHECK(!listener_); | 69 DCHECK(!listener_); |
| 59 DCHECK(!device_loop_.get()); | 70 DCHECK(!device_loop_.get()); |
| 60 listener_ = listener; | 71 listener_ = listener; |
| 61 device_loop_ = device_thread_loop; | 72 device_loop_ = device_thread_loop; |
| 62 } | 73 } |
| 63 | 74 |
| 64 void VideoCaptureManager::Unregister() { | 75 void VideoCaptureManager::Unregister() { |
| 65 DCHECK(listener_); | 76 DCHECK(listener_); |
| 66 listener_ = NULL; | 77 listener_ = NULL; |
| 67 } | 78 } |
| 68 | 79 |
| 69 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { | 80 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 71 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; | 82 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; |
| 72 DCHECK(listener_); | 83 DCHECK(listener_); |
| 84 | |
| 73 base::PostTaskAndReplyWithResult( | 85 base::PostTaskAndReplyWithResult( |
| 74 device_loop_, FROM_HERE, | 86 device_loop_, |
| 75 base::Bind(&VideoCaptureManager::GetAvailableDevicesOnDeviceThread, this, | 87 FROM_HERE, |
| 76 stream_type), | 88 base::Bind(&VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread, |
| 77 base::Bind(&VideoCaptureManager::OnDevicesEnumerated, this, stream_type)); | 89 this, |
| 90 stream_type, | |
| 91 devices_info_cache_), | |
| 92 base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, | |
| 93 this, | |
| 94 stream_type)); | |
| 78 } | 95 } |
| 79 | 96 |
| 80 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { | 97 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 82 DCHECK(listener_); | 99 DCHECK(listener_); |
| 83 | 100 |
| 84 // Generate a new id for the session being opened. | 101 // Generate a new id for the session being opened. |
| 85 const int capture_session_id = new_capture_session_id_++; | 102 const int capture_session_id = new_capture_session_id_++; |
| 86 | 103 |
| 87 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); | 104 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { | 157 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { |
| 141 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 158 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
| 142 DCHECK(IsOnDeviceThread()); | 159 DCHECK(IsOnDeviceThread()); |
| 143 | 160 |
| 144 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 161 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
| 145 switch (entry->stream_type) { | 162 switch (entry->stream_type) { |
| 146 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 163 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
| 147 // We look up the device id from the renderer in our local enumeration | 164 // We look up the device id from the renderer in our local enumeration |
| 148 // since the renderer does not have all the information that might be | 165 // since the renderer does not have all the information that might be |
| 149 // held in the browser-side VideoCaptureDevice::Name structure. | 166 // held in the browser-side VideoCaptureDevice::Name structure. |
| 150 media::VideoCaptureDevice::Name* found = | 167 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); |
| 151 video_capture_devices_.FindById(entry->id); | |
| 152 if (found) { | 168 if (found) { |
| 153 video_capture_device.reset(use_fake_device_ ? | 169 video_capture_device.reset(use_fake_device_ ? |
| 154 media::FakeVideoCaptureDevice::Create(*found) : | 170 media::FakeVideoCaptureDevice::Create(found->name) : |
| 155 media::VideoCaptureDevice::Create(*found)); | 171 media::VideoCaptureDevice::Create(found->name)); |
| 156 } | 172 } |
| 157 break; | 173 break; |
| 158 } | 174 } |
| 159 case MEDIA_TAB_VIDEO_CAPTURE: { | 175 case MEDIA_TAB_VIDEO_CAPTURE: { |
| 160 video_capture_device.reset( | 176 video_capture_device.reset( |
| 161 WebContentsVideoCaptureDevice::Create(entry->id)); | 177 WebContentsVideoCaptureDevice::Create(entry->id)); |
| 162 break; | 178 break; |
| 163 } | 179 } |
| 164 case MEDIA_DESKTOP_VIDEO_CAPTURE: { | 180 case MEDIA_DESKTOP_VIDEO_CAPTURE: { |
| 165 #if defined(ENABLE_SCREEN_CAPTURE) | 181 #if defined(ENABLE_SCREEN_CAPTURE) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 done_cb.Run(base::WeakPtr<VideoCaptureController>()); | 223 done_cb.Run(base::WeakPtr<VideoCaptureController>()); |
| 208 return; | 224 return; |
| 209 } | 225 } |
| 210 | 226 |
| 211 DCHECK(entry->video_capture_controller); | 227 DCHECK(entry->video_capture_controller); |
| 212 | 228 |
| 213 // First client starts the device. | 229 // First client starts the device. |
| 214 if (entry->video_capture_controller->GetClientCount() == 0) { | 230 if (entry->video_capture_controller->GetClientCount() == 0) { |
| 215 DVLOG(1) << "VideoCaptureManager starting device (type = " | 231 DVLOG(1) << "VideoCaptureManager starting device (type = " |
| 216 << entry->stream_type << ", id = " << entry->id << ")"; | 232 << entry->stream_type << ", id = " << entry->id << ")"; |
| 217 | |
| 218 device_loop_->PostTask( | 233 device_loop_->PostTask( |
| 219 FROM_HERE, | 234 FROM_HERE, |
| 220 base::Bind( | 235 base::Bind( |
| 221 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | 236 &VideoCaptureManager::DoStartDeviceOnDeviceThread, |
| 222 this, | 237 this, |
| 223 entry, | 238 entry, |
| 224 params, | 239 params, |
| 225 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | 240 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
| 226 } | 241 } |
| 227 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 242 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 246 | 261 |
| 247 // Detach client from controller. | 262 // Detach client from controller. |
| 248 int session_id = controller->RemoveClient(client_id, client_handler); | 263 int session_id = controller->RemoveClient(client_id, client_handler); |
| 249 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 264 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
| 250 << session_id; | 265 << session_id; |
| 251 | 266 |
| 252 // If controller has no more clients, delete controller and device. | 267 // If controller has no more clients, delete controller and device. |
| 253 DestroyDeviceEntryIfNoClients(entry); | 268 DestroyDeviceEntryIfNoClients(entry); |
| 254 } | 269 } |
| 255 | 270 |
| 271 void VideoCaptureManager::GetDeviceSupportedFormats( | |
| 272 int capture_session_id, | |
| 273 media::VideoCaptureFormats* supported_formats) { | |
| 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 275 supported_formats->clear(); | |
| 276 | |
| 277 std::map<int, MediaStreamDevice>::iterator it = | |
| 278 sessions_.find(capture_session_id); | |
| 279 DCHECK(it != sessions_.end()); | |
| 280 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; | |
| 281 | |
| 282 DeviceInfo* device_in_use = | |
| 283 FindDeviceInfoById(it->second.id, devices_info_cache_); | |
| 284 DCHECK(device_in_use); | |
|
scherkus (not reviewing)
2013/12/03 22:04:48
if you're DCHECK'ing this is non-null ... but then
mcasas
2013/12/04 15:23:32
Done.
| |
| 285 if (device_in_use) { | |
| 286 DeviceEntry* const existing_device = | |
| 287 GetDeviceEntryForMediaStreamDevice(it->second); | |
| 288 if (!existing_device) { | |
| 289 // If the device is not in use, return all its cached supported formats. | |
| 290 *supported_formats = device_in_use->supported_formats; | |
| 291 return; | |
| 292 } | |
| 293 // Otherwise, get the video capture parameters in use from the controller | |
| 294 // associated to the device. | |
| 295 supported_formats->push_back( | |
| 296 existing_device->video_capture_controller->GetVideoCaptureFormat()); | |
| 297 } | |
| 298 } | |
| 299 | |
| 256 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 300 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { |
| 257 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 301 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
| 258 DCHECK(IsOnDeviceThread()); | 302 DCHECK(IsOnDeviceThread()); |
| 259 if (entry->video_capture_device) { | 303 if (entry->video_capture_device) { |
| 260 entry->video_capture_device->StopAndDeAllocate(); | 304 entry->video_capture_device->StopAndDeAllocate(); |
| 261 } | 305 } |
| 262 entry->video_capture_device.reset(); | 306 entry->video_capture_device.reset(); |
| 263 } | 307 } |
| 264 | 308 |
| 265 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 309 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
| 266 int capture_session_id) { | 310 int capture_session_id) { |
| 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 268 if (!listener_) { | 312 if (!listener_) { |
| 269 // Listener has been removed. | 313 // Listener has been removed. |
| 270 return; | 314 return; |
| 271 } | 315 } |
| 272 listener_->Opened(stream_type, capture_session_id); | 316 listener_->Opened(stream_type, capture_session_id); |
| 273 } | 317 } |
| 274 | 318 |
| 275 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, | 319 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, |
| 276 int capture_session_id) { | 320 int capture_session_id) { |
| 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 278 if (!listener_) { | 322 if (!listener_) { |
| 279 // Listener has been removed. | 323 // Listener has been removed. |
| 280 return; | 324 return; |
| 281 } | 325 } |
| 282 listener_->Closed(stream_type, capture_session_id); | 326 listener_->Closed(stream_type, capture_session_id); |
| 283 } | 327 } |
| 284 | 328 |
| 285 void VideoCaptureManager::OnDevicesEnumerated( | 329 void VideoCaptureManager::OnDevicesInfoEnumerated( |
| 286 MediaStreamType stream_type, | 330 MediaStreamType stream_type, |
| 287 const media::VideoCaptureDevice::Names& device_names) { | 331 const DeviceInfos& new_devices_info_cache) { |
| 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 289 | 333 DVLOG(1) << "OnDevicesInfoEnumerated, #new devices: " |
| 290 if (!listener_) { | 334 << new_devices_info_cache.size(); |
| 291 // Listener has been removed. | 335 if (!listener_) { // Listener has been removed. |
| 292 return; | 336 return; |
| 293 } | 337 } |
| 338 devices_info_cache_ = new_devices_info_cache; | |
| 294 | 339 |
| 295 // Transform from VCD::Name to StreamDeviceInfo. | 340 // Walk the |devices_info_cache_| and transform from VCD::Name to |
| 341 // StreamDeviceInfo for return purposes. | |
| 296 StreamDeviceInfoArray devices; | 342 StreamDeviceInfoArray devices; |
| 297 for (media::VideoCaptureDevice::Names::const_iterator it = | 343 for (DeviceInfos::const_iterator it = devices_info_cache_.begin(); |
| 298 device_names.begin(); it != device_names.end(); ++it) { | 344 it != devices_info_cache_.end(); |
| 345 ++it) { | |
| 299 devices.push_back(StreamDeviceInfo( | 346 devices.push_back(StreamDeviceInfo( |
| 300 stream_type, it->GetNameAndModel(), it->id())); | 347 stream_type, it->name.GetNameAndModel(), it->name.id())); |
| 301 } | 348 } |
| 302 | |
| 303 listener_->DevicesEnumerated(stream_type, devices); | 349 listener_->DevicesEnumerated(stream_type, devices); |
| 304 } | 350 } |
| 305 | 351 |
| 306 bool VideoCaptureManager::IsOnDeviceThread() const { | 352 bool VideoCaptureManager::IsOnDeviceThread() const { |
| 307 return device_loop_->BelongsToCurrentThread(); | 353 return device_loop_->BelongsToCurrentThread(); |
| 308 } | 354 } |
| 309 | 355 |
| 310 media::VideoCaptureDevice::Names | 356 VideoCaptureManager::DeviceInfos |
| 311 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( | 357 VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread( |
| 312 MediaStreamType stream_type) { | 358 MediaStreamType stream_type, |
| 313 SCOPED_UMA_HISTOGRAM_TIMER( | 359 const DeviceInfos& old_device_info_cache) { |
| 314 "Media.VideoCaptureManager.GetAvailableDevicesTime"); | 360 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager." |
| 361 "GetAvailableDevicesInfoOnDeviceThreadTime"); | |
| 315 DCHECK(IsOnDeviceThread()); | 362 DCHECK(IsOnDeviceThread()); |
| 316 media::VideoCaptureDevice::Names result; | 363 media::VideoCaptureDevice::Names names_snapshot; |
| 317 | |
| 318 switch (stream_type) { | 364 switch (stream_type) { |
| 319 case MEDIA_DEVICE_VIDEO_CAPTURE: | 365 case MEDIA_DEVICE_VIDEO_CAPTURE: |
| 320 // Cache the latest enumeration of video capture devices. | 366 if (!use_fake_device_) |
| 321 // We'll refer to this list again in OnOpen to avoid having to | 367 media::VideoCaptureDevice::GetDeviceNames(&names_snapshot); |
| 322 // enumerate the devices again. | 368 else |
| 323 if (!use_fake_device_) { | 369 media::FakeVideoCaptureDevice::GetDeviceNames(&names_snapshot); |
| 324 media::VideoCaptureDevice::GetDeviceNames(&result); | |
| 325 } else { | |
| 326 media::FakeVideoCaptureDevice::GetDeviceNames(&result); | |
| 327 } | |
| 328 | |
| 329 // TODO(nick): The correctness of device start depends on this cache being | |
| 330 // maintained, but it seems a little odd to keep a cache here. Can we | |
| 331 // eliminate it? | |
| 332 video_capture_devices_ = result; | |
| 333 break; | 370 break; |
| 334 | |
| 335 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 371 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
| 336 // Do nothing. | 372 // Do nothing. |
| 337 break; | 373 break; |
| 338 | |
| 339 default: | 374 default: |
| 340 NOTREACHED(); | 375 NOTREACHED(); |
| 341 break; | 376 break; |
| 342 } | 377 } |
| 343 return result; | 378 |
| 379 // Construct |new_devices_info_cache| with the cached devices that are still | |
| 380 // present in the system, and remove their names from |names_snapshot|, so we | |
| 381 // keep there the truly new devices. | |
| 382 DeviceInfos new_devices_info_cache; | |
| 383 for (DeviceInfos::const_iterator it_device_info = | |
| 384 old_device_info_cache.begin(); | |
| 385 it_device_info != old_device_info_cache.end(); | |
| 386 ++it_device_info) { | |
| 387 media::VideoCaptureDevice::Names::iterator it; | |
| 388 for (it = names_snapshot.begin(); it != names_snapshot.end(); ++it) { | |
| 389 if (it_device_info->name.id() == it->id()) { | |
| 390 new_devices_info_cache.push_back(*it_device_info); | |
| 391 names_snapshot.erase(it); | |
| 392 break; | |
| 393 } | |
| 394 } | |
| 395 } | |
| 396 | |
| 397 // Get the supported capture formats for the new devices in |names_snapshot|. | |
| 398 for (media::VideoCaptureDevice::Names::const_iterator it = | |
| 399 names_snapshot.begin(); | |
| 400 it != names_snapshot.end(); | |
| 401 ++it) { | |
| 402 media::VideoCaptureFormats supported_formats; | |
| 403 DeviceInfo device_info(*it, media::VideoCaptureFormats()); | |
| 404 if (!use_fake_device_) { | |
| 405 media::VideoCaptureDevice::GetDeviceSupportedFormats( | |
| 406 *it, &(device_info.supported_formats)); | |
| 407 } else { | |
| 408 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( | |
| 409 *it, &(device_info.supported_formats)); | |
| 410 } | |
| 411 new_devices_info_cache.push_back(device_info); | |
| 412 } | |
| 413 return new_devices_info_cache; | |
| 344 } | 414 } |
| 345 | 415 |
| 346 VideoCaptureManager::DeviceEntry* | 416 VideoCaptureManager::DeviceEntry* |
| 347 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( | 417 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( |
| 348 const MediaStreamDevice& device_info) { | 418 const MediaStreamDevice& device_info) { |
| 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 350 | 420 |
| 351 for (DeviceEntries::iterator it = devices_.begin(); | 421 for (DeviceEntries::iterator it = devices_.begin(); |
| 352 it != devices_.end(); ++it) { | 422 it != devices_.end(); ++it) { |
| 353 DeviceEntry* device = *it; | 423 DeviceEntry* device = *it; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 380 << entry->stream_type << ", id = " << entry->id << ")"; | 450 << entry->stream_type << ", id = " << entry->id << ")"; |
| 381 | 451 |
| 382 // The DeviceEntry is removed from |devices_| immediately. The controller is | 452 // The DeviceEntry is removed from |devices_| immediately. The controller is |
| 383 // deleted immediately, and the device is freed asynchronously. After this | 453 // deleted immediately, and the device is freed asynchronously. After this |
| 384 // point, subsequent requests to open this same device ID will create a new | 454 // point, subsequent requests to open this same device ID will create a new |
| 385 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. | 455 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. |
| 386 devices_.erase(entry); | 456 devices_.erase(entry); |
| 387 entry->video_capture_controller.reset(); | 457 entry->video_capture_controller.reset(); |
| 388 device_loop_->PostTask( | 458 device_loop_->PostTask( |
| 389 FROM_HERE, | 459 FROM_HERE, |
| 390 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 460 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, |
| 461 this, | |
| 391 base::Owned(entry))); | 462 base::Owned(entry))); |
| 392 } | 463 } |
| 393 } | 464 } |
| 394 | 465 |
| 395 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 466 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
| 396 int capture_session_id) { | 467 int capture_session_id) { |
| 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 398 | 469 |
| 399 std::map<int, MediaStreamDevice>::iterator session_it = | 470 std::map<int, MediaStreamDevice>::iterator session_it = |
| 400 sessions_.find(capture_session_id); | 471 sessions_.find(capture_session_id); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 414 | 485 |
| 415 scoped_ptr<VideoCaptureController> video_capture_controller( | 486 scoped_ptr<VideoCaptureController> video_capture_controller( |
| 416 new VideoCaptureController()); | 487 new VideoCaptureController()); |
| 417 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 488 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
| 418 device_info.id, | 489 device_info.id, |
| 419 video_capture_controller.Pass()); | 490 video_capture_controller.Pass()); |
| 420 devices_.insert(new_device); | 491 devices_.insert(new_device); |
| 421 return new_device; | 492 return new_device; |
| 422 } | 493 } |
| 423 | 494 |
| 495 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById( | |
| 496 const std::string& id, | |
| 497 DeviceInfos& device_vector) { | |
| 498 for (DeviceInfos::iterator it = device_vector.begin(); | |
| 499 it != device_vector.end(); ++it) { | |
| 500 if (it->name.id() == id) | |
| 501 return &(*it); | |
| 502 } | |
| 503 return NULL; | |
| 504 } | |
| 505 | |
| 424 } // namespace content | 506 } // namespace content |
| OLD | NEW |