| 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/logging.h" |
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 11 #include "content/browser/renderer_host/media/video_capture_controller.h" | 12 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 12 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 13 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/common/media_stream_request.h" |
| 14 #include "media/video/capture/fake_video_capture_device.h" | 16 #include "media/video/capture/fake_video_capture_device.h" |
| 15 #include "media/video/capture/video_capture_device.h" | 17 #include "media/video/capture/video_capture_device.h" |
| 16 | 18 |
| 17 using content::BrowserThread; | 19 using content::BrowserThread; |
| 18 | 20 |
| 19 namespace media_stream { | 21 namespace media_stream { |
| 20 | 22 |
| 21 // Starting id for the first capture session. | 23 // Starting id for the first capture session. |
| 22 // VideoCaptureManager::kStartOpenSessionId is used as default id without | 24 // VideoCaptureManager::kStartOpenSessionId is used as default id without |
| 23 // explicitly calling open device. | 25 // explicitly calling open device. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 base::Closure stopped_cb) { | 111 base::Closure stopped_cb) { |
| 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 111 device_loop_->PostTask( | 113 device_loop_->PostTask( |
| 112 FROM_HERE, | 114 FROM_HERE, |
| 113 base::Bind(&VideoCaptureManager::OnStop, this, capture_session_id, | 115 base::Bind(&VideoCaptureManager::OnStop, this, capture_session_id, |
| 114 stopped_cb)); | 116 stopped_cb)); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void VideoCaptureManager::Error( | 119 void VideoCaptureManager::Error( |
| 118 const media::VideoCaptureSessionId& capture_session_id) { | 120 const media::VideoCaptureSessionId& capture_session_id) { |
| 119 PostOnError(capture_session_id, kDeviceNotAvailable); | 121 device_loop_->PostTask( |
| 122 FROM_HERE, |
| 123 base::Bind(&VideoCaptureManager::PostOnError, this, capture_session_id, |
| 124 kDeviceNotAvailable)); |
| 120 } | 125 } |
| 121 | 126 |
| 122 void VideoCaptureManager::UseFakeDevice() { | 127 void VideoCaptureManager::UseFakeDevice() { |
| 123 use_fake_device_ = true; | 128 use_fake_device_ = true; |
| 124 } | 129 } |
| 125 | 130 |
| 126 void VideoCaptureManager::OnEnumerateDevices() { | 131 void VideoCaptureManager::OnEnumerateDevices() { |
| 127 DCHECK(IsOnDeviceThread()); | 132 DCHECK(IsOnDeviceThread()); |
| 128 | 133 |
| 129 media::VideoCaptureDevice::Names device_names; | 134 media::VideoCaptureDevice::Names device_names; |
| 130 GetAvailableDevices(&device_names); | 135 GetAvailableDevices(&device_names); |
| 131 | 136 |
| 132 StreamDeviceInfoArray devices; | 137 StreamDeviceInfoArray devices; |
| 133 for (media::VideoCaptureDevice::Names::iterator it = | 138 for (media::VideoCaptureDevice::Names::iterator it = |
| 134 device_names.begin(); it != device_names.end(); ++it) { | 139 device_names.begin(); it != device_names.end(); ++it) { |
| 135 bool opened = DeviceOpened(*it); | 140 bool opened = DeviceOpened(*it); |
| 141 // NOTE: Only support enumeration of the MEDIA_DEVICE_VIDEO_CAPTURE type. |
| 136 devices.push_back(StreamDeviceInfo( | 142 devices.push_back(StreamDeviceInfo( |
| 137 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, it->device_name, | 143 content::MEDIA_DEVICE_VIDEO_CAPTURE, it->device_name, |
| 138 it->unique_id, opened)); | 144 it->unique_id, opened)); |
| 139 } | 145 } |
| 140 | 146 |
| 141 PostOnDevicesEnumerated(devices); | 147 PostOnDevicesEnumerated(devices); |
| 142 } | 148 } |
| 143 | 149 |
| 144 void VideoCaptureManager::OnOpen(int capture_session_id, | 150 void VideoCaptureManager::OnOpen(int capture_session_id, |
| 145 const StreamDeviceInfo& device) { | 151 const StreamDeviceInfo& device) { |
| 146 DCHECK(IsOnDeviceThread()); | 152 DCHECK(IsOnDeviceThread()); |
| 147 DCHECK(devices_.find(capture_session_id) == devices_.end()); | 153 DCHECK(devices_.find(capture_session_id) == devices_.end()); |
| 148 DVLOG(1) << "VideoCaptureManager::OnOpen, id " << capture_session_id; | 154 DVLOG(1) << "VideoCaptureManager::OnOpen, id " << capture_session_id; |
| 149 | 155 |
| 150 // Check if another session has already opened this device. If so, just | 156 // Check if another session has already opened this device. If so, just |
| 151 // use that opened device. | 157 // use that opened device. |
| 152 media::VideoCaptureDevice* video_capture_device = GetOpenedDevice(device); | 158 media::VideoCaptureDevice* video_capture_device = GetOpenedDevice(device); |
| 153 if (video_capture_device) { | 159 if (video_capture_device) { |
| 154 devices_[capture_session_id] = video_capture_device; | 160 DeviceEntry& new_entry = devices_[capture_session_id]; |
| 155 PostOnOpened(capture_session_id); | 161 new_entry.stream_type = device.stream_type; |
| 162 new_entry.capture_device = video_capture_device; |
| 163 PostOnOpened(device.stream_type, capture_session_id); |
| 156 return; | 164 return; |
| 157 } | 165 } |
| 158 | 166 |
| 159 // Open the device. | 167 // Open the device. |
| 160 media::VideoCaptureDevice::Name vc_device_name; | 168 media::VideoCaptureDevice::Name vc_device_name; |
| 161 vc_device_name.device_name = device.name; | 169 vc_device_name.device_name = device.name; |
| 162 vc_device_name.unique_id = device.device_id; | 170 vc_device_name.unique_id = device.device_id; |
| 163 | 171 |
| 164 if (!use_fake_device_) { | 172 if (use_fake_device_) { |
| 165 video_capture_device = media::VideoCaptureDevice::Create(vc_device_name); | |
| 166 } else { | |
| 167 video_capture_device = | 173 video_capture_device = |
| 168 media::FakeVideoCaptureDevice::Create(vc_device_name); | 174 media::FakeVideoCaptureDevice::Create(vc_device_name); |
| 175 } else { |
| 176 switch (device.stream_type) { |
| 177 case content::MEDIA_DEVICE_VIDEO_CAPTURE: |
| 178 video_capture_device = |
| 179 media::VideoCaptureDevice::Create(vc_device_name); |
| 180 break; |
| 181 case content::MEDIA_TAB_VIDEO_CAPTURE: |
| 182 // TODO(miu): Replace this stub with the actual implementation in a |
| 183 // later change. |
| 184 video_capture_device = |
| 185 media::FakeVideoCaptureDevice::Create(vc_device_name); |
| 186 break; |
| 187 default: |
| 188 NOTIMPLEMENTED(); |
| 189 break; |
| 190 } |
| 169 } | 191 } |
| 170 if (!video_capture_device) { | 192 if (!video_capture_device) { |
| 171 PostOnError(capture_session_id, kDeviceNotAvailable); | 193 PostOnError(capture_session_id, kDeviceNotAvailable); |
| 172 return; | 194 return; |
| 173 } | 195 } |
| 174 | 196 |
| 175 devices_[capture_session_id] = video_capture_device; | 197 DeviceEntry& new_entry = devices_[capture_session_id]; |
| 176 PostOnOpened(capture_session_id); | 198 new_entry.stream_type = device.stream_type; |
| 199 new_entry.capture_device = video_capture_device; |
| 200 PostOnOpened(device.stream_type, capture_session_id); |
| 177 } | 201 } |
| 178 | 202 |
| 179 void VideoCaptureManager::OnClose(int capture_session_id) { | 203 void VideoCaptureManager::OnClose(int capture_session_id) { |
| 180 DCHECK(IsOnDeviceThread()); | 204 DCHECK(IsOnDeviceThread()); |
| 181 DVLOG(1) << "VideoCaptureManager::OnClose, id " << capture_session_id; | 205 DVLOG(1) << "VideoCaptureManager::OnClose, id " << capture_session_id; |
| 182 | 206 |
| 183 media::VideoCaptureDevice* video_capture_device = NULL; | |
| 184 VideoCaptureDevices::iterator device_it = devices_.find(capture_session_id); | 207 VideoCaptureDevices::iterator device_it = devices_.find(capture_session_id); |
| 185 if (device_it != devices_.end()) { | 208 if (device_it == devices_.end()) { |
| 186 video_capture_device = device_it->second; | 209 return; |
| 187 devices_.erase(device_it); | 210 } |
| 211 const DeviceEntry removed_entry = device_it->second; |
| 212 devices_.erase(device_it); |
| 188 | 213 |
| 189 Controllers::iterator cit = controllers_.find(video_capture_device); | 214 Controllers::iterator cit = controllers_.find(removed_entry.capture_device); |
| 215 if (cit != controllers_.end()) { |
| 216 BrowserThread::PostTask( |
| 217 BrowserThread::IO, FROM_HERE, |
| 218 base::Bind(&VideoCaptureController::StopSession, |
| 219 cit->second->controller, capture_session_id)); |
| 220 } |
| 221 |
| 222 if (!DeviceInUse(removed_entry.capture_device)) { |
| 223 // No other users of this device, deallocate (if not done already) and |
| 224 // delete the device. No need to take care of the controller, that is done |
| 225 // by |OnStop|. |
| 226 removed_entry.capture_device->DeAllocate(); |
| 227 Controllers::iterator cit = controllers_.find(removed_entry.capture_device); |
| 190 if (cit != controllers_.end()) { | 228 if (cit != controllers_.end()) { |
| 191 BrowserThread::PostTask( | 229 delete cit->second; |
| 192 BrowserThread::IO, FROM_HERE, | 230 controllers_.erase(cit); |
| 193 base::Bind(&VideoCaptureController::StopSession, | |
| 194 cit->second->controller, capture_session_id)); | |
| 195 } | 231 } |
| 232 delete removed_entry.capture_device; |
| 233 } |
| 196 | 234 |
| 197 if (!DeviceInUse(video_capture_device)) { | 235 PostOnClosed(removed_entry.stream_type, capture_session_id); |
| 198 // No other users of this device, deallocate (if not done already) and | |
| 199 // delete the device. No need to take care of the controller, that is done | |
| 200 // by |OnStop|. | |
| 201 video_capture_device->DeAllocate(); | |
| 202 Controllers::iterator cit = controllers_.find(video_capture_device); | |
| 203 if (cit != controllers_.end()) { | |
| 204 delete cit->second; | |
| 205 controllers_.erase(cit); | |
| 206 } | |
| 207 delete video_capture_device; | |
| 208 } | |
| 209 } | |
| 210 PostOnClosed(capture_session_id); | |
| 211 } | 236 } |
| 212 | 237 |
| 213 void VideoCaptureManager::OnStart( | 238 void VideoCaptureManager::OnStart( |
| 214 const media::VideoCaptureParams capture_params, | 239 const media::VideoCaptureParams capture_params, |
| 215 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { | 240 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { |
| 216 DCHECK(IsOnDeviceThread()); | 241 DCHECK(IsOnDeviceThread()); |
| 217 DCHECK(video_capture_receiver != NULL); | 242 DCHECK(video_capture_receiver != NULL); |
| 218 DVLOG(1) << "VideoCaptureManager::OnStart, (" << capture_params.width | 243 DVLOG(1) << "VideoCaptureManager::OnStart, (" << capture_params.width |
| 219 << ", " << capture_params.height | 244 << ", " << capture_params.height |
| 220 << ", " << capture_params.frame_per_second | 245 << ", " << capture_params.frame_per_second |
| (...skipping 21 matching lines...) Expand all Loading... |
| 242 } | 267 } |
| 243 | 268 |
| 244 void VideoCaptureManager::OnStop( | 269 void VideoCaptureManager::OnStop( |
| 245 const media::VideoCaptureSessionId capture_session_id, | 270 const media::VideoCaptureSessionId capture_session_id, |
| 246 base::Closure stopped_cb) { | 271 base::Closure stopped_cb) { |
| 247 DCHECK(IsOnDeviceThread()); | 272 DCHECK(IsOnDeviceThread()); |
| 248 DVLOG(1) << "VideoCaptureManager::OnStop, id " << capture_session_id; | 273 DVLOG(1) << "VideoCaptureManager::OnStop, id " << capture_session_id; |
| 249 | 274 |
| 250 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); | 275 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); |
| 251 if (it != devices_.end()) { | 276 if (it != devices_.end()) { |
| 252 media::VideoCaptureDevice* video_capture_device = it->second; | 277 media::VideoCaptureDevice* video_capture_device = it->second.capture_device; |
| 253 // Possible errors are signaled to video_capture_receiver by | 278 // Possible errors are signaled to video_capture_receiver by |
| 254 // video_capture_device. video_capture_receiver to perform actions. | 279 // video_capture_device. video_capture_receiver to perform actions. |
| 255 video_capture_device->Stop(); | 280 video_capture_device->Stop(); |
| 256 video_capture_device->DeAllocate(); | 281 video_capture_device->DeAllocate(); |
| 257 Controllers::iterator cit = controllers_.find(video_capture_device); | 282 Controllers::iterator cit = controllers_.find(video_capture_device); |
| 258 if (cit != controllers_.end()) { | 283 if (cit != controllers_.end()) { |
| 259 cit->second->ready_to_delete = true; | 284 cit->second->ready_to_delete = true; |
| 260 if (cit->second->handlers.empty()) { | 285 if (cit->second->handlers.empty()) { |
| 261 delete cit->second; | 286 delete cit->second; |
| 262 controllers_.erase(cit); | 287 controllers_.erase(cit); |
| 263 } | 288 } |
| 264 } | 289 } |
| 265 } | 290 } |
| 266 | 291 |
| 267 if (!stopped_cb.is_null()) | 292 if (!stopped_cb.is_null()) |
| 268 stopped_cb.Run(); | 293 stopped_cb.Run(); |
| 269 | 294 |
| 270 if (capture_session_id == kStartOpenSessionId) { | 295 if (capture_session_id == kStartOpenSessionId) { |
| 271 // This device was opened from Start(), not Open(). Close it! | 296 // This device was opened from Start(), not Open(). Close it! |
| 272 OnClose(capture_session_id); | 297 OnClose(capture_session_id); |
| 273 } | 298 } |
| 274 } | 299 } |
| 275 | 300 |
| 276 void VideoCaptureManager::OnOpened(int capture_session_id) { | 301 void VideoCaptureManager::OnOpened(content::MediaStreamDeviceType stream_type, |
| 302 int capture_session_id) { |
| 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 278 if (!listener_) { | 304 if (!listener_) { |
| 279 // Listener has been removed. | 305 // Listener has been removed. |
| 280 return; | 306 return; |
| 281 } | 307 } |
| 282 listener_->Opened(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 308 listener_->Opened(stream_type, capture_session_id); |
| 283 capture_session_id); | |
| 284 } | 309 } |
| 285 | 310 |
| 286 void VideoCaptureManager::OnClosed(int capture_session_id) { | 311 void VideoCaptureManager::OnClosed(content::MediaStreamDeviceType stream_type, |
| 312 int capture_session_id) { |
| 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 288 if (!listener_) { | 314 if (!listener_) { |
| 289 // Listener has been removed. | 315 // Listener has been removed. |
| 290 return; | 316 return; |
| 291 } | 317 } |
| 292 listener_->Closed(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 318 listener_->Closed(stream_type, capture_session_id); |
| 293 capture_session_id); | |
| 294 } | 319 } |
| 295 | 320 |
| 296 void VideoCaptureManager::OnDevicesEnumerated( | 321 void VideoCaptureManager::OnDevicesEnumerated( |
| 297 const StreamDeviceInfoArray& devices) { | 322 const StreamDeviceInfoArray& devices) { |
| 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 299 if (!listener_) { | 324 if (!listener_) { |
| 300 // Listener has been removed. | 325 // Listener has been removed. |
| 301 return; | 326 return; |
| 302 } | 327 } |
| 303 listener_->DevicesEnumerated(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 328 // NOTE: Only support enumeration of the MEDIA_DEVICE_VIDEO_CAPTURE type. |
| 304 devices); | 329 listener_->DevicesEnumerated(content::MEDIA_DEVICE_VIDEO_CAPTURE, devices); |
| 305 } | 330 } |
| 306 | 331 |
| 307 void VideoCaptureManager::OnError(int capture_session_id, | 332 void VideoCaptureManager::OnError(content::MediaStreamDeviceType stream_type, |
| 333 int capture_session_id, |
| 308 MediaStreamProviderError error) { | 334 MediaStreamProviderError error) { |
| 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 310 if (!listener_) { | 336 if (!listener_) { |
| 311 // Listener has been removed. | 337 // Listener has been removed. |
| 312 return; | 338 return; |
| 313 } | 339 } |
| 314 listener_->Error(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 340 listener_->Error(stream_type, capture_session_id, error); |
| 315 capture_session_id, error); | |
| 316 } | 341 } |
| 317 | 342 |
| 318 void VideoCaptureManager::PostOnOpened(int capture_session_id) { | 343 void VideoCaptureManager::PostOnOpened( |
| 344 content::MediaStreamDeviceType stream_type, int capture_session_id) { |
| 319 DCHECK(IsOnDeviceThread()); | 345 DCHECK(IsOnDeviceThread()); |
| 320 BrowserThread::PostTask(BrowserThread::IO, | 346 BrowserThread::PostTask(BrowserThread::IO, |
| 321 FROM_HERE, | 347 FROM_HERE, |
| 322 base::Bind(&VideoCaptureManager::OnOpened, this, | 348 base::Bind(&VideoCaptureManager::OnOpened, this, |
| 323 capture_session_id)); | 349 stream_type, capture_session_id)); |
| 324 } | 350 } |
| 325 | 351 |
| 326 void VideoCaptureManager::PostOnClosed(int capture_session_id) { | 352 void VideoCaptureManager::PostOnClosed( |
| 353 content::MediaStreamDeviceType stream_type, int capture_session_id) { |
| 327 DCHECK(IsOnDeviceThread()); | 354 DCHECK(IsOnDeviceThread()); |
| 328 BrowserThread::PostTask(BrowserThread::IO, | 355 BrowserThread::PostTask(BrowserThread::IO, |
| 329 FROM_HERE, | 356 FROM_HERE, |
| 330 base::Bind(&VideoCaptureManager::OnClosed, this, | 357 base::Bind(&VideoCaptureManager::OnClosed, this, |
| 331 capture_session_id)); | 358 stream_type, capture_session_id)); |
| 332 } | 359 } |
| 333 | 360 |
| 334 void VideoCaptureManager::PostOnDevicesEnumerated( | 361 void VideoCaptureManager::PostOnDevicesEnumerated( |
| 335 const StreamDeviceInfoArray& devices) { | 362 const StreamDeviceInfoArray& devices) { |
| 336 DCHECK(IsOnDeviceThread()); | 363 DCHECK(IsOnDeviceThread()); |
| 337 BrowserThread::PostTask(BrowserThread::IO, | 364 BrowserThread::PostTask(BrowserThread::IO, |
| 338 FROM_HERE, | 365 FROM_HERE, |
| 339 base::Bind(&VideoCaptureManager::OnDevicesEnumerated, | 366 base::Bind(&VideoCaptureManager::OnDevicesEnumerated, |
| 340 this, devices)); | 367 this, devices)); |
| 341 } | 368 } |
| 342 | 369 |
| 343 void VideoCaptureManager::PostOnError(int capture_session_id, | 370 void VideoCaptureManager::PostOnError(int capture_session_id, |
| 344 MediaStreamProviderError error) { | 371 MediaStreamProviderError error) { |
| 345 // Don't check thread here, can be called from both IO thread and device | 372 DCHECK(IsOnDeviceThread()); |
| 346 // thread. | 373 content::MediaStreamDeviceType stream_type = |
| 374 content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 375 VideoCaptureDevices::const_iterator it = devices_.find(capture_session_id); |
| 376 if (it != devices_.end()) |
| 377 stream_type = it->second.stream_type; |
| 347 BrowserThread::PostTask(BrowserThread::IO, | 378 BrowserThread::PostTask(BrowserThread::IO, |
| 348 FROM_HERE, | 379 FROM_HERE, |
| 349 base::Bind(&VideoCaptureManager::OnError, this, | 380 base::Bind(&VideoCaptureManager::OnError, this, |
| 350 capture_session_id, error)); | 381 stream_type, capture_session_id, error)); |
| 351 } | 382 } |
| 352 | 383 |
| 353 bool VideoCaptureManager::IsOnDeviceThread() const { | 384 bool VideoCaptureManager::IsOnDeviceThread() const { |
| 354 return device_loop_->BelongsToCurrentThread(); | 385 return device_loop_->BelongsToCurrentThread(); |
| 355 } | 386 } |
| 356 | 387 |
| 357 void VideoCaptureManager::GetAvailableDevices( | 388 void VideoCaptureManager::GetAvailableDevices( |
| 358 media::VideoCaptureDevice::Names* device_names) { | 389 media::VideoCaptureDevice::Names* device_names) { |
| 359 DCHECK(IsOnDeviceThread()); | 390 DCHECK(IsOnDeviceThread()); |
| 360 | 391 |
| 361 if (!use_fake_device_) { | 392 if (!use_fake_device_) { |
| 362 media::VideoCaptureDevice::GetDeviceNames(device_names); | 393 media::VideoCaptureDevice::GetDeviceNames(device_names); |
| 363 } else { | 394 } else { |
| 364 media::FakeVideoCaptureDevice::GetDeviceNames(device_names); | 395 media::FakeVideoCaptureDevice::GetDeviceNames(device_names); |
| 365 } | 396 } |
| 366 } | 397 } |
| 367 | 398 |
| 368 bool VideoCaptureManager::DeviceOpened( | 399 bool VideoCaptureManager::DeviceOpened( |
| 369 const media::VideoCaptureDevice::Name& device_name) { | 400 const media::VideoCaptureDevice::Name& device_name) { |
| 370 DCHECK(IsOnDeviceThread()); | 401 DCHECK(IsOnDeviceThread()); |
| 371 | 402 |
| 372 for (VideoCaptureDevices::iterator it = devices_.begin(); | 403 for (VideoCaptureDevices::iterator it = devices_.begin(); |
| 373 it != devices_.end(); ++it) { | 404 it != devices_.end(); ++it) { |
| 374 if (device_name.unique_id == it->second->device_name().unique_id) { | 405 if (device_name.unique_id == |
| 406 it->second.capture_device->device_name().unique_id) { |
| 375 // We've found the device! | 407 // We've found the device! |
| 376 return true; | 408 return true; |
| 377 } | 409 } |
| 378 } | 410 } |
| 379 return false; | 411 return false; |
| 380 } | 412 } |
| 381 | 413 |
| 382 media::VideoCaptureDevice* VideoCaptureManager::GetOpenedDevice( | 414 media::VideoCaptureDevice* VideoCaptureManager::GetOpenedDevice( |
| 383 const StreamDeviceInfo& device_info) { | 415 const StreamDeviceInfo& device_info) { |
| 384 DCHECK(IsOnDeviceThread()); | 416 DCHECK(IsOnDeviceThread()); |
| 385 | 417 |
| 386 for (VideoCaptureDevices::iterator it = devices_.begin(); | 418 for (VideoCaptureDevices::iterator it = devices_.begin(); |
| 387 it != devices_.end(); it++) { | 419 it != devices_.end(); it++) { |
| 388 if (device_info.device_id == it->second->device_name().unique_id) { | 420 if (device_info.device_id == |
| 389 return it->second; | 421 it->second.capture_device->device_name().unique_id) { |
| 422 return it->second.capture_device; |
| 390 } | 423 } |
| 391 } | 424 } |
| 392 return NULL; | 425 return NULL; |
| 393 } | 426 } |
| 394 | 427 |
| 395 bool VideoCaptureManager::DeviceInUse( | 428 bool VideoCaptureManager::DeviceInUse( |
| 396 const media::VideoCaptureDevice* video_capture_device) { | 429 const media::VideoCaptureDevice* video_capture_device) { |
| 397 DCHECK(IsOnDeviceThread()); | 430 DCHECK(IsOnDeviceThread()); |
| 398 | 431 |
| 399 for (VideoCaptureDevices::iterator it = devices_.begin(); | 432 for (VideoCaptureDevices::iterator it = devices_.begin(); |
| 400 it != devices_.end(); ++it) { | 433 it != devices_.end(); ++it) { |
| 401 if (video_capture_device == it->second) { | 434 if (video_capture_device == it->second.capture_device) { |
| 402 // We've found the device! | 435 // We've found the device! |
| 403 return true; | 436 return true; |
| 404 } | 437 } |
| 405 } | 438 } |
| 406 return false; | 439 return false; |
| 407 } | 440 } |
| 408 | 441 |
| 409 void VideoCaptureManager::AddController( | 442 void VideoCaptureManager::AddController( |
| 410 const media::VideoCaptureParams& capture_params, | 443 const media::VideoCaptureParams& capture_params, |
| 411 VideoCaptureControllerEventHandler* handler, | 444 VideoCaptureControllerEventHandler* handler, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 return; | 505 return; |
| 473 } | 506 } |
| 474 } | 507 } |
| 475 } | 508 } |
| 476 | 509 |
| 477 media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal( | 510 media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal( |
| 478 int capture_session_id) { | 511 int capture_session_id) { |
| 479 DCHECK(IsOnDeviceThread()); | 512 DCHECK(IsOnDeviceThread()); |
| 480 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); | 513 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); |
| 481 if (dit != devices_.end()) { | 514 if (dit != devices_.end()) { |
| 482 return dit->second; | 515 return dit->second.capture_device; |
| 483 } | 516 } |
| 484 | 517 |
| 485 // Solution for not using MediaStreamManager. | 518 // Solution for not using MediaStreamManager. |
| 486 // This session id won't be returned by Open(). | 519 // This session id won't be returned by Open(). |
| 487 if (capture_session_id == kStartOpenSessionId) { | 520 if (capture_session_id == kStartOpenSessionId) { |
| 488 media::VideoCaptureDevice::Names device_names; | 521 media::VideoCaptureDevice::Names device_names; |
| 489 GetAvailableDevices(&device_names); | 522 GetAvailableDevices(&device_names); |
| 490 if (device_names.empty()) { | 523 if (device_names.empty()) { |
| 491 // No devices available. | 524 // No devices available. |
| 492 return NULL; | 525 return NULL; |
| 493 } | 526 } |
| 494 StreamDeviceInfo device(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 527 // NOTE: Only support enumeration of the MEDIA_DEVICE_VIDEO_CAPTURE type. |
| 528 StreamDeviceInfo device(content::MEDIA_DEVICE_VIDEO_CAPTURE, |
| 495 device_names.front().device_name, | 529 device_names.front().device_name, |
| 496 device_names.front().unique_id, false); | 530 device_names.front().unique_id, false); |
| 497 | 531 |
| 498 // Call OnOpen to open using the first device in the list. | 532 // Call OnOpen to open using the first device in the list. |
| 499 OnOpen(capture_session_id, device); | 533 OnOpen(capture_session_id, device); |
| 500 | 534 |
| 501 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); | 535 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); |
| 502 if (dit != devices_.end()) { | 536 if (dit != devices_.end()) { |
| 503 return dit->second; | 537 return dit->second.capture_device; |
| 504 } | 538 } |
| 505 } | 539 } |
| 506 return NULL; | 540 return NULL; |
| 507 } | 541 } |
| 508 | 542 |
| 509 } // namespace media_stream | 543 } // namespace media_stream |
| OLD | NEW |