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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 // Class used for queuing request for starting a device. | 142 // Class used for queuing request for starting a device. |
| 143 class VideoCaptureManager::CaptureDeviceStartRequest { | 143 class VideoCaptureManager::CaptureDeviceStartRequest { |
| 144 public: | 144 public: |
| 145 CaptureDeviceStartRequest(int serial_id, | 145 CaptureDeviceStartRequest(int serial_id, |
| 146 media::VideoCaptureSessionId session_id, | 146 media::VideoCaptureSessionId session_id, |
| 147 const media::VideoCaptureParams& params); | 147 const media::VideoCaptureParams& params); |
| 148 int serial_id() const { return serial_id_; } | 148 int serial_id() const { return serial_id_; } |
| 149 media::VideoCaptureSessionId session_id() const { return session_id_; } | 149 media::VideoCaptureSessionId session_id() const { return session_id_; } |
| 150 media::VideoCaptureParams params() const { return params_; } | 150 media::VideoCaptureParams params() const { return params_; } |
| 151 | 151 |
| 152 // Set to true if the device should be stopped before it has successfully | |
| 153 // been started. | |
| 154 bool abort_start() const { return abort_start_; } | |
| 155 void set_abort_start() { abort_start_ = true; } | |
| 156 | |
| 157 private: | 152 private: |
| 158 const int serial_id_; | 153 const int serial_id_; |
| 159 const media::VideoCaptureSessionId session_id_; | 154 const media::VideoCaptureSessionId session_id_; |
| 160 const media::VideoCaptureParams params_; | 155 const media::VideoCaptureParams params_; |
| 161 // Set to true if the device should be stopped before it has successfully | |
| 162 // been started. | |
| 163 bool abort_start_; | |
| 164 }; | 156 }; |
| 165 | 157 |
| 166 VideoCaptureManager::DeviceInfo::DeviceInfo() = default; | 158 VideoCaptureManager::DeviceInfo::DeviceInfo() = default; |
| 167 | 159 |
| 168 VideoCaptureManager::DeviceInfo::DeviceInfo( | 160 VideoCaptureManager::DeviceInfo::DeviceInfo( |
| 169 media::VideoCaptureDeviceDescriptor descriptor) | 161 media::VideoCaptureDeviceDescriptor descriptor) |
| 170 : descriptor(descriptor) {} | 162 : descriptor(descriptor) {} |
| 171 | 163 |
| 172 VideoCaptureManager::DeviceInfo::DeviceInfo( | 164 VideoCaptureManager::DeviceInfo::DeviceInfo( |
| 173 const VideoCaptureManager::DeviceInfo& other) = default; | 165 const VideoCaptureManager::DeviceInfo& other) = default; |
| 174 | 166 |
| 175 VideoCaptureManager::DeviceInfo::~DeviceInfo() = default; | 167 VideoCaptureManager::DeviceInfo::~DeviceInfo() = default; |
| 176 | 168 |
| 177 VideoCaptureManager::DeviceInfo& VideoCaptureManager::DeviceInfo::operator=( | 169 VideoCaptureManager::DeviceInfo& VideoCaptureManager::DeviceInfo::operator=( |
| 178 const VideoCaptureManager::DeviceInfo& other) = default; | 170 const VideoCaptureManager::DeviceInfo& other) = default; |
| 179 | 171 |
| 180 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest( | 172 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest( |
| 181 int serial_id, | 173 int serial_id, |
| 182 media::VideoCaptureSessionId session_id, | 174 media::VideoCaptureSessionId session_id, |
| 183 const media::VideoCaptureParams& params) | 175 const media::VideoCaptureParams& params) |
| 184 : serial_id_(serial_id), | 176 : serial_id_(serial_id), session_id_(session_id), params_(params) {} |
| 185 session_id_(session_id), | |
| 186 params_(params), | |
| 187 abort_start_(false) {} | |
| 188 | 177 |
| 189 VideoCaptureManager::VideoCaptureManager( | 178 VideoCaptureManager::VideoCaptureManager( |
| 190 std::unique_ptr<media::VideoCaptureDeviceFactory> factory, | 179 std::unique_ptr<media::VideoCaptureDeviceFactory> factory, |
| 191 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner) | 180 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner) |
| 192 : device_task_runner_(std::move(device_task_runner)), | 181 : device_task_runner_(std::move(device_task_runner)), |
| 193 new_capture_session_id_(1), | 182 new_capture_session_id_(1), |
| 194 video_capture_device_factory_(std::move(factory)) {} | 183 video_capture_device_factory_(std::move(factory)) {} |
| 195 | 184 |
| 196 VideoCaptureManager::~VideoCaptureManager() { | 185 VideoCaptureManager::~VideoCaptureManager() { |
| 197 DCHECK(controllers_.empty()); | 186 DCHECK(controllers_.empty()); |
| 198 DCHECK(device_start_queue_.empty()); | 187 DCHECK(device_start_request_queue_.empty()); |
| 199 } | 188 } |
| 200 | 189 |
| 201 void VideoCaptureManager::AddVideoCaptureObserver( | 190 void VideoCaptureManager::AddVideoCaptureObserver( |
| 202 media::VideoCaptureObserver* observer) { | 191 media::VideoCaptureObserver* observer) { |
| 203 DCHECK(observer); | 192 DCHECK(observer); |
| 204 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 193 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 205 capture_observers_.AddObserver(observer); | 194 capture_observers_.AddObserver(observer); |
| 206 } | 195 } |
| 207 | 196 |
| 208 void VideoCaptureManager::RemoveAllVideoCaptureObservers() { | 197 void VideoCaptureManager::RemoveAllVideoCaptureObservers() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 void VideoCaptureManager::Close(int capture_session_id) { | 274 void VideoCaptureManager::Close(int capture_session_id) { |
| 286 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 275 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 287 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id; | 276 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id; |
| 288 | 277 |
| 289 SessionMap::iterator session_it = sessions_.find(capture_session_id); | 278 SessionMap::iterator session_it = sessions_.find(capture_session_id); |
| 290 if (session_it == sessions_.end()) { | 279 if (session_it == sessions_.end()) { |
| 291 NOTREACHED(); | 280 NOTREACHED(); |
| 292 return; | 281 return; |
| 293 } | 282 } |
| 294 | 283 |
| 295 VideoCaptureController* const existing_device = LookupControllerByTypeAndId( | 284 VideoCaptureController* const existing_device = |
| 296 session_it->second.type, session_it->second.id); | 285 LookupControllerByMediaTypeAndDeviceId(session_it->second.type, |
| 286 session_it->second.id); | |
| 297 if (existing_device) { | 287 if (existing_device) { |
| 298 // Remove any client that is still using the session. This is safe to call | 288 // Remove any client that is still using the session. This is safe to call |
| 299 // even if there are no clients using the session. | 289 // even if there are no clients using the session. |
| 300 existing_device->StopSession(capture_session_id); | 290 existing_device->StopSession(capture_session_id); |
| 301 | 291 |
| 302 // StopSession() may have removed the last client, so we might need to | 292 // StopSession() may have removed the last client, so we might need to |
| 303 // close the device. | 293 // close the device. |
| 304 DestroyControllerIfNoClients(existing_device); | 294 DestroyControllerIfNoClients(existing_device); |
| 305 } | 295 } |
| 306 | 296 |
| 307 // Notify listeners asynchronously, and forget the session. | 297 // Notify listeners asynchronously, and forget the session. |
| 308 base::ThreadTaskRunnerHandle::Get()->PostTask( | 298 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 309 FROM_HERE, base::Bind(&VideoCaptureManager::OnClosed, this, | 299 FROM_HERE, base::Bind(&VideoCaptureManager::OnClosed, this, |
| 310 session_it->second.type, capture_session_id)); | 300 session_it->second.type, capture_session_id)); |
| 311 sessions_.erase(session_it); | 301 sessions_.erase(session_it); |
| 312 } | 302 } |
| 313 | 303 |
| 314 void VideoCaptureManager::QueueStartDevice( | 304 void VideoCaptureManager::QueueStartDevice( |
| 315 media::VideoCaptureSessionId session_id, | 305 media::VideoCaptureSessionId session_id, |
| 316 VideoCaptureController* controller, | 306 VideoCaptureController* controller, |
| 317 const media::VideoCaptureParams& params) { | 307 const media::VideoCaptureParams& params) { |
| 318 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 308 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 319 device_start_queue_.push_back( | 309 device_start_request_queue_.push_back( |
| 320 CaptureDeviceStartRequest(controller->serial_id(), session_id, params)); | 310 CaptureDeviceStartRequest(controller->serial_id(), session_id, params)); |
| 321 if (device_start_queue_.size() == 1) | 311 if (device_start_request_queue_.size() == 1) |
| 322 HandleQueuedStartRequest(); | 312 ProcessDeviceStartRequestQueue(); |
| 323 } | 313 } |
| 324 | 314 |
| 325 void VideoCaptureManager::DoStopDevice(VideoCaptureController* controller) { | 315 void VideoCaptureManager::DoStopDevice(VideoCaptureController* controller) { |
| 326 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 316 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 327 // TODO(mcasas): use a helper function https://crbug.com/624854. | 317 // TODO(mcasas): use a helper function https://crbug.com/624854. |
| 328 DCHECK(std::find_if( | 318 DCHECK(std::find_if( |
| 329 controllers_.begin(), controllers_.end(), | 319 controllers_.begin(), controllers_.end(), |
| 330 [controller]( | 320 [controller]( |
| 331 const scoped_refptr<VideoCaptureController>& device_entry) { | 321 const scoped_refptr<VideoCaptureController>& device_entry) { |
| 332 return device_entry.get() == controller; | 322 return device_entry.get() == controller; |
| 333 }) != controllers_.end()); | 323 }) != controllers_.end()); |
| 334 | 324 |
| 335 // Find the matching start request. | 325 // If start request has not yet started processing, i.e. if it is not at the |
| 336 for (DeviceStartQueue::reverse_iterator request = | 326 // beginning of the queue, remove it from the queue. |
| 337 device_start_queue_.rbegin(); | 327 const int serial_id = controller->serial_id(); |
| 338 request != device_start_queue_.rend(); ++request) { | 328 auto request_iter = std::find_if( |
| 339 if (request->serial_id() == controller->serial_id()) { | 329 device_start_request_queue_.begin(), device_start_request_queue_.end(), |
|
miu
2017/03/17 21:48:02
nit (simplification): Make the 1st arg here begin(
chfremer
2017/03/21 22:37:23
Done.
Had to do it differently though, because |d
miu
2017/03/22 21:33:28
Acknowledged.
| |
| 340 request->set_abort_start(); | 330 [serial_id](const CaptureDeviceStartRequest& request) { |
| 341 DVLOG(3) << "DoStopDevice, aborting start request for device " | 331 return request.serial_id() == serial_id; |
| 342 << controller->device_id() | 332 }); |
| 343 << " serial_id = " << controller->serial_id(); | 333 if (request_iter != device_start_request_queue_.begin() && |
| 344 return; | 334 request_iter != device_start_request_queue_.end()) { |
| 345 } | 335 device_start_request_queue_.erase(request_iter); |
| 336 return; | |
| 346 } | 337 } |
| 347 | 338 |
| 348 const DeviceInfo* device_info = GetDeviceInfoById(controller->device_id()); | 339 const DeviceInfo* device_info = GetDeviceInfoById(controller->device_id()); |
| 349 if (device_info != nullptr) { | 340 if (device_info != nullptr) { |
| 350 for (auto& observer : capture_observers_) | 341 for (auto& observer : capture_observers_) |
| 351 observer.OnVideoCaptureStopped(device_info->descriptor.facing); | 342 observer.OnVideoCaptureStopped(device_info->descriptor.facing); |
| 352 } | 343 } |
| 353 | 344 |
| 354 DVLOG(3) << "DoStopDevice. Send stop request for device = " | 345 DVLOG(3) << "DoStopDevice. Send stop request for device = " |
| 355 << controller->device_id() | 346 << controller->device_id() |
| 356 << " serial_id = " << controller->serial_id() << "."; | 347 << " serial_id = " << controller->serial_id() << "."; |
| 357 controller->OnLog(base::StringPrintf("Stopping device: id: %s", | 348 controller->OnLog(base::StringPrintf("Stopping device: id: %s", |
| 358 controller->device_id().c_str())); | 349 controller->device_id().c_str())); |
| 359 | 350 |
| 360 if (controller->IsDeviceAlive()) { | 351 // Since we may be removing |controller| from |controllers_| while |
| 361 // Since we may be removing |controller| from |controllers_| while | 352 // ReleaseDeviceAsnyc() is executing, we pass it shared ownership to |
| 362 // ReleaseDeviceAsnyc() is executing, we pass it shared ownership to | 353 // |controller|. |
| 363 // |controller|. | 354 controller->ReleaseDeviceAsync(MakeScopedRefptrOwnership( |
| 364 controller->ReleaseDeviceAsync(MakeScopedRefptrOwnership( | 355 GetControllerSharedRefFromSerialId(controller->serial_id()))); |
| 365 GetControllerSharedRefFromSerialId(controller->serial_id()))); | |
| 366 } | |
| 367 } | 356 } |
| 368 | 357 |
| 369 void VideoCaptureManager::HandleQueuedStartRequest() { | 358 void VideoCaptureManager::ProcessDeviceStartRequestQueue() { |
| 370 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 359 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 371 // Remove all start requests that have been aborted. | 360 DeviceStartQueue::iterator request = device_start_request_queue_.begin(); |
| 372 while (device_start_queue_.begin() != device_start_queue_.end() && | 361 if (request == device_start_request_queue_.end()) |
| 373 device_start_queue_.begin()->abort_start()) { | |
| 374 device_start_queue_.pop_front(); | |
| 375 } | |
| 376 DeviceStartQueue::iterator request = device_start_queue_.begin(); | |
| 377 if (request == device_start_queue_.end()) | |
| 378 return; | 362 return; |
| 379 | 363 |
| 380 const int serial_id = request->serial_id(); | 364 const int serial_id = request->serial_id(); |
| 381 VideoCaptureController* const controller = | 365 VideoCaptureController* const controller = |
| 382 LookupControllerBySerialId(serial_id); | 366 LookupControllerBySerialId(serial_id); |
| 383 DCHECK(controller); | 367 DCHECK(controller); |
| 384 | 368 |
| 385 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = " | 369 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = " |
| 386 << controller->device_id() | 370 << controller->device_id() |
| 387 << " start id = " << controller->serial_id(); | 371 << " start id = " << controller->serial_id(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 404 } | 388 } |
| 405 | 389 |
| 406 void VideoCaptureManager::WillStartDevice(media::VideoFacingMode facing_mode) { | 390 void VideoCaptureManager::WillStartDevice(media::VideoFacingMode facing_mode) { |
| 407 for (auto& observer : capture_observers_) | 391 for (auto& observer : capture_observers_) |
| 408 observer.OnVideoCaptureStarted(facing_mode); | 392 observer.OnVideoCaptureStarted(facing_mode); |
| 409 } | 393 } |
| 410 | 394 |
| 411 void VideoCaptureManager::DidStartDevice(VideoCaptureController* controller) { | 395 void VideoCaptureManager::DidStartDevice(VideoCaptureController* controller) { |
| 412 DVLOG(3) << __func__; | 396 DVLOG(3) << __func__; |
| 413 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 397 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 398 DCHECK(!device_start_request_queue_.empty()); | |
| 399 DCHECK_EQ(controller->serial_id(), | |
|
miu
2017/03/17 21:48:02
OOC, why put a |serial_id| instead of the VCC poin
chfremer
2017/03/21 22:37:23
I have no idea whether or not the |serial_id| was
| |
| 400 device_start_request_queue_.begin()->serial_id()); | |
| 414 DCHECK(controller); | 401 DCHECK(controller); |
| 415 DCHECK_EQ(controller->serial_id(), device_start_queue_.begin()->serial_id()); | 402 if (controller->stream_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 416 if (device_start_queue_.front().abort_start()) { | 403 const media::VideoCaptureSessionId session_id = |
| 417 // A request to release the device may have arrived during the asynchronous | 404 device_start_request_queue_.front().session_id(); |
| 418 // device startup. | 405 DCHECK(session_id != kFakeSessionId); |
| 419 DVLOG(3) << "Device release request has been issued while device was " | 406 MaybePostDesktopCaptureWindowId(session_id); |
| 420 << "starting up asynchronously."; | 407 } |
| 421 controller->ReleaseDeviceAsync(MakeScopedRefptrOwnership( | |
| 422 GetControllerSharedRefFromSerialId(controller->serial_id()))); | |
| 423 } else { | |
| 424 if (controller->stream_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) { | |
| 425 const media::VideoCaptureSessionId session_id = | |
| 426 device_start_queue_.front().session_id(); | |
| 427 DCHECK(session_id != kFakeSessionId); | |
| 428 MaybePostDesktopCaptureWindowId(session_id); | |
| 429 } | |
| 430 | 408 |
| 431 auto it = photo_request_queue_.begin(); | 409 auto it = photo_request_queue_.begin(); |
| 432 while (it != photo_request_queue_.end()) { | 410 while (it != photo_request_queue_.end()) { |
| 433 auto request = it++; | 411 auto request = it++; |
| 434 VideoCaptureController* maybe_entry = | 412 VideoCaptureController* maybe_entry = |
| 435 LookupControllerBySessionId(request->first); | 413 LookupControllerBySessionId(request->first); |
| 436 if (maybe_entry && maybe_entry->IsDeviceAlive()) { | 414 if (maybe_entry && maybe_entry->IsDeviceAlive()) { |
| 437 request->second.Run(); | 415 request->second.Run(); |
| 438 photo_request_queue_.erase(request); | 416 photo_request_queue_.erase(request); |
| 439 } | |
| 440 } | 417 } |
| 441 } | 418 } |
| 442 | 419 |
| 443 device_start_queue_.pop_front(); | 420 device_start_request_queue_.pop_front(); |
| 444 HandleQueuedStartRequest(); | 421 ProcessDeviceStartRequestQueue(); |
| 445 } | 422 } |
| 446 | 423 |
| 447 void VideoCaptureManager::OnDeviceStartFailed( | 424 void VideoCaptureManager::OnDeviceStartFailed( |
| 448 VideoCaptureController* controller) { | 425 VideoCaptureController* controller) { |
| 449 const std::string log_message = base::StringPrintf( | 426 const std::string log_message = base::StringPrintf( |
| 450 "Starting device %s has failed. Maybe recently disconnected?", | 427 "Starting device %s has failed. Maybe recently disconnected?", |
| 451 controller->device_id().c_str()); | 428 controller->device_id().c_str()); |
| 452 DLOG(ERROR) << log_message; | 429 DLOG(ERROR) << log_message; |
| 453 controller->OnLog(log_message); | 430 controller->OnLog(log_message); |
| 454 controller->OnError(); | 431 controller->OnError(); |
| 455 | 432 |
| 456 device_start_queue_.pop_front(); | 433 device_start_request_queue_.pop_front(); |
| 457 HandleQueuedStartRequest(); | 434 ProcessDeviceStartRequestQueue(); |
| 458 } | 435 } |
| 459 | 436 |
| 460 void VideoCaptureManager::StartCaptureForClient( | 437 void VideoCaptureManager::OnDeviceStartAborted() { |
| 438 device_start_request_queue_.pop_front(); | |
| 439 ProcessDeviceStartRequestQueue(); | |
| 440 } | |
| 441 | |
| 442 void VideoCaptureManager::ConnectClient( | |
| 461 media::VideoCaptureSessionId session_id, | 443 media::VideoCaptureSessionId session_id, |
| 462 const media::VideoCaptureParams& params, | 444 const media::VideoCaptureParams& params, |
| 463 VideoCaptureControllerID client_id, | 445 VideoCaptureControllerID client_id, |
| 464 VideoCaptureControllerEventHandler* client_handler, | 446 VideoCaptureControllerEventHandler* client_handler, |
| 465 const DoneCB& done_cb) { | 447 const DoneCB& done_cb) { |
| 466 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 448 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 467 DVLOG(1) << __func__ << ", session_id = " << session_id << ", request: " | 449 DVLOG(1) << __func__ << ", session_id = " << session_id << ", request: " |
| 468 << media::VideoCaptureFormat::ToString(params.requested_format); | 450 << media::VideoCaptureFormat::ToString(params.requested_format); |
| 469 | 451 |
| 470 VideoCaptureController* controller = | 452 VideoCaptureController* controller = |
| 471 GetOrCreateController(session_id, params); | 453 GetOrCreateController(session_id, params); |
| 472 if (!controller) { | 454 if (!controller) { |
| 473 done_cb.Run(base::WeakPtr<VideoCaptureController>()); | 455 done_cb.Run(base::WeakPtr<VideoCaptureController>()); |
| 474 return; | 456 return; |
| 475 } | 457 } |
| 476 | 458 |
| 477 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE); | 459 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE); |
| 478 | 460 |
| 479 // First client starts the device. | 461 // First client starts the device. |
| 480 if (!controller->HasActiveClient() && !controller->HasPausedClient()) { | 462 if (!controller->HasActiveClient() && !controller->HasPausedClient()) { |
| 481 DVLOG(1) << "VideoCaptureManager starting device (id = " | 463 DVLOG(1) << "VideoCaptureManager starting device (id = " |
| 482 << controller->device_id() << ")"; | 464 << controller->device_id() << ")"; |
| 483 QueueStartDevice(session_id, controller, params); | 465 QueueStartDevice(session_id, controller, params); |
| 484 } | 466 } |
| 485 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 467 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
| 486 done_cb.Run(controller->GetWeakPtrForIOThread()); | 468 done_cb.Run(controller->GetWeakPtrForIOThread()); |
| 487 controller->AddClient(client_id, client_handler, session_id, params); | 469 controller->AddClient(client_id, client_handler, session_id, params); |
| 488 } | 470 } |
| 489 | 471 |
| 490 void VideoCaptureManager::StopCaptureForClient( | 472 void VideoCaptureManager::DisconnectClient( |
| 491 VideoCaptureController* controller, | 473 VideoCaptureController* controller, |
| 492 VideoCaptureControllerID client_id, | 474 VideoCaptureControllerID client_id, |
| 493 VideoCaptureControllerEventHandler* client_handler, | 475 VideoCaptureControllerEventHandler* client_handler, |
| 494 bool aborted_due_to_error) { | 476 bool aborted_due_to_error) { |
| 495 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 477 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 496 DCHECK(controller); | 478 DCHECK(controller); |
| 497 DCHECK(client_handler); | 479 DCHECK(client_handler); |
| 498 | 480 |
| 499 if (!IsControllerPointerValid(controller)) { | 481 if (!IsControllerPointerValid(controller)) { |
| 500 NOTREACHED(); | 482 NOTREACHED(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 } | 610 } |
| 629 | 611 |
| 630 bool VideoCaptureManager::GetDeviceFormatsInUse( | 612 bool VideoCaptureManager::GetDeviceFormatsInUse( |
| 631 MediaStreamType stream_type, | 613 MediaStreamType stream_type, |
| 632 const std::string& device_id, | 614 const std::string& device_id, |
| 633 media::VideoCaptureFormats* formats_in_use) { | 615 media::VideoCaptureFormats* formats_in_use) { |
| 634 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 616 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 635 DCHECK(formats_in_use->empty()); | 617 DCHECK(formats_in_use->empty()); |
| 636 // Return the currently in-use format(s) of the device, if it's started. | 618 // Return the currently in-use format(s) of the device, if it's started. |
| 637 VideoCaptureController* device_in_use = | 619 VideoCaptureController* device_in_use = |
| 638 LookupControllerByTypeAndId(stream_type, device_id); | 620 LookupControllerByMediaTypeAndDeviceId(stream_type, device_id); |
| 639 if (device_in_use) { | 621 if (device_in_use) { |
| 640 // Currently only one format-in-use is supported at the VCC level. | 622 // Currently only one format-in-use is supported at the VCC level. |
| 641 formats_in_use->push_back(device_in_use->GetVideoCaptureFormat()); | 623 formats_in_use->push_back(device_in_use->GetVideoCaptureFormat()); |
| 642 } | 624 } |
| 643 return true; | 625 return true; |
| 644 } | 626 } |
| 645 | 627 |
| 646 void VideoCaptureManager::SetDesktopCaptureWindowId( | 628 void VideoCaptureManager::SetDesktopCaptureWindowId( |
| 647 media::VideoCaptureSessionId session_id, | 629 media::VideoCaptureSessionId session_id, |
| 648 gfx::NativeViewId window_id) { | 630 gfx::NativeViewId window_id) { |
| 649 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 631 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 650 VLOG(2) << "SetDesktopCaptureWindowId called for session " << session_id; | 632 VLOG(2) << "SetDesktopCaptureWindowId called for session " << session_id; |
| 651 | 633 |
| 652 notification_window_ids_[session_id] = window_id; | 634 notification_window_ids_[session_id] = window_id; |
| 653 MaybePostDesktopCaptureWindowId(session_id); | 635 MaybePostDesktopCaptureWindowId(session_id); |
| 654 } | 636 } |
| 655 | 637 |
| 656 void VideoCaptureManager::MaybePostDesktopCaptureWindowId( | 638 void VideoCaptureManager::MaybePostDesktopCaptureWindowId( |
| 657 media::VideoCaptureSessionId session_id) { | 639 media::VideoCaptureSessionId session_id) { |
| 658 SessionMap::iterator session_it = sessions_.find(session_id); | 640 SessionMap::iterator session_it = sessions_.find(session_id); |
| 659 if (session_it == sessions_.end()) | 641 if (session_it == sessions_.end()) |
| 660 return; | 642 return; |
| 661 | 643 |
| 662 VideoCaptureController* const existing_device = LookupControllerByTypeAndId( | 644 VideoCaptureController* const existing_device = |
| 663 session_it->second.type, session_it->second.id); | 645 LookupControllerByMediaTypeAndDeviceId(session_it->second.type, |
| 646 session_it->second.id); | |
| 664 if (!existing_device) { | 647 if (!existing_device) { |
| 665 DVLOG(2) << "Failed to find an existing screen capture device."; | 648 DVLOG(2) << "Failed to find an existing screen capture device."; |
| 666 return; | 649 return; |
| 667 } | 650 } |
| 668 | 651 |
| 669 if (!existing_device->IsDeviceAlive()) { | 652 if (!existing_device->IsDeviceAlive()) { |
| 670 DVLOG(2) << "Screen capture device not yet started."; | 653 DVLOG(2) << "Screen capture device not yet started."; |
| 671 return; | 654 return; |
| 672 } | 655 } |
| 673 | 656 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 } | 832 } |
| 850 } | 833 } |
| 851 | 834 |
| 852 VideoCaptureController* VideoCaptureManager::LookupControllerBySessionId( | 835 VideoCaptureController* VideoCaptureManager::LookupControllerBySessionId( |
| 853 int session_id) { | 836 int session_id) { |
| 854 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 837 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 855 SessionMap::const_iterator session_it = sessions_.find(session_id); | 838 SessionMap::const_iterator session_it = sessions_.find(session_id); |
| 856 if (session_it == sessions_.end()) | 839 if (session_it == sessions_.end()) |
| 857 return nullptr; | 840 return nullptr; |
| 858 | 841 |
| 859 return LookupControllerByTypeAndId(session_it->second.type, | 842 return LookupControllerByMediaTypeAndDeviceId(session_it->second.type, |
| 860 session_it->second.id); | 843 session_it->second.id); |
| 861 } | 844 } |
| 862 | 845 |
| 863 VideoCaptureController* VideoCaptureManager::LookupControllerByTypeAndId( | 846 VideoCaptureController* |
| 847 VideoCaptureManager::LookupControllerByMediaTypeAndDeviceId( | |
| 864 MediaStreamType type, | 848 MediaStreamType type, |
| 865 const std::string& device_id) const { | 849 const std::string& device_id) const { |
| 866 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 850 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 867 | 851 |
| 868 for (const auto& entry : controllers_) { | 852 for (const auto& entry : controllers_) { |
| 869 if (type == entry->stream_type() && device_id == entry->device_id()) | 853 if (type == entry->stream_type() && device_id == entry->device_id()) |
| 870 return entry.get(); | 854 return entry.get(); |
| 871 } | 855 } |
| 872 return nullptr; | 856 return nullptr; |
| 873 } | 857 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 915 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 899 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 916 | 900 |
| 917 SessionMap::iterator session_it = sessions_.find(capture_session_id); | 901 SessionMap::iterator session_it = sessions_.find(capture_session_id); |
| 918 if (session_it == sessions_.end()) | 902 if (session_it == sessions_.end()) |
| 919 return nullptr; | 903 return nullptr; |
| 920 const MediaStreamDevice& device_info = session_it->second; | 904 const MediaStreamDevice& device_info = session_it->second; |
| 921 | 905 |
| 922 // Check if another session has already opened this device. If so, just | 906 // Check if another session has already opened this device. If so, just |
| 923 // use that opened device. | 907 // use that opened device. |
| 924 VideoCaptureController* const existing_device = | 908 VideoCaptureController* const existing_device = |
| 925 LookupControllerByTypeAndId(device_info.type, device_info.id); | 909 LookupControllerByMediaTypeAndDeviceId(device_info.type, device_info.id); |
| 926 if (existing_device) { | 910 if (existing_device) { |
| 927 DCHECK_EQ(device_info.type, existing_device->stream_type()); | 911 DCHECK_EQ(device_info.type, existing_device->stream_type()); |
| 928 return existing_device; | 912 return existing_device; |
| 929 } | 913 } |
| 930 | 914 |
| 931 VideoCaptureController* new_device_entry = new VideoCaptureController( | 915 VideoCaptureController* new_controller = new VideoCaptureController( |
| 932 device_info.id, device_info.type, params, | 916 device_info.id, device_info.type, params, |
| 933 base::MakeUnique<InProcessBuildableVideoCaptureDevice>( | 917 base::MakeUnique<InProcessBuildableVideoCaptureDevice>( |
| 934 device_task_runner_, video_capture_device_factory_.get())); | 918 device_task_runner_, video_capture_device_factory_.get())); |
| 935 controllers_.emplace_back(new_device_entry); | 919 controllers_.emplace_back(new_controller); |
| 936 return new_device_entry; | 920 return new_controller; |
| 937 } | 921 } |
| 938 | 922 |
| 939 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration( | 923 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration( |
| 940 const std::string& device_id) { | 924 const std::string& device_id) { |
| 941 VideoCaptureManager::DeviceInfo* info = GetDeviceInfoById(device_id); | 925 VideoCaptureManager::DeviceInfo* info = GetDeviceInfoById(device_id); |
| 942 if (!info) | 926 if (!info) |
| 943 return base::Optional<CameraCalibration>(); | 927 return base::Optional<CameraCalibration>(); |
| 944 return info->descriptor.camera_calibration; | 928 return info->descriptor.camera_calibration; |
| 945 } | 929 } |
| 946 | 930 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 978 | 962 |
| 979 for (auto& controller : controllers_) { | 963 for (auto& controller : controllers_) { |
| 980 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture. | 964 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture. |
| 981 // Do not try to restart already running devices. | 965 // Do not try to restart already running devices. |
| 982 if (controller->stream_type() != MEDIA_DEVICE_VIDEO_CAPTURE || | 966 if (controller->stream_type() != MEDIA_DEVICE_VIDEO_CAPTURE || |
| 983 controller->IsDeviceAlive()) | 967 controller->IsDeviceAlive()) |
| 984 continue; | 968 continue; |
| 985 | 969 |
| 986 // Check if the device is already in the start queue. | 970 // Check if the device is already in the start queue. |
| 987 bool device_in_queue = false; | 971 bool device_in_queue = false; |
| 988 for (auto& request : device_start_queue_) { | 972 for (auto& request : device_start_request_queue_) { |
| 989 if (request.serial_id() == controller->serial_id()) { | 973 if (request.serial_id() == controller->serial_id()) { |
| 990 device_in_queue = true; | 974 device_in_queue = true; |
| 991 break; | 975 break; |
| 992 } | 976 } |
| 993 } | 977 } |
| 994 | 978 |
| 995 if (!device_in_queue) { | 979 if (!device_in_queue) { |
| 996 // Session ID is only valid for Screen capture. So we can fake it to | 980 // Session ID is only valid for Screen capture. So we can fake it to |
| 997 // resume video capture devices here. | 981 // resume video capture devices here. |
| 998 QueueStartDevice(kFakeSessionId, controller.get(), | 982 QueueStartDevice(kFakeSessionId, controller.get(), |
| 999 controller->parameters()); | 983 controller->parameters()); |
| 1000 } | 984 } |
| 1001 } | 985 } |
| 1002 } | 986 } |
| 1003 #endif // defined(OS_ANDROID) | 987 #endif // defined(OS_ANDROID) |
| 1004 | 988 |
| 1005 } // namespace content | 989 } // namespace content |
| OLD | NEW |