Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 2753073006: [Mojo Video Capture] Add support to BuildableVideoCaptureDevice for aborting the device start. (Closed)
Patch Set: Incorporate suggestions from Patch Set 1 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ~DeviceInfo(); 135 ~DeviceInfo();
136 DeviceInfo& operator=(const DeviceInfo& other); 136 DeviceInfo& operator=(const DeviceInfo& other);
137 137
138 media::VideoCaptureDeviceDescriptor descriptor; 138 media::VideoCaptureDeviceDescriptor descriptor;
139 media::VideoCaptureFormats supported_formats; 139 media::VideoCaptureFormats supported_formats;
140 }; 140 };
141 141
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(VideoCaptureController* controller,
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 VideoCaptureController* controller() const { return controller_; }
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 VideoCaptureController* const controller_;
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 VideoCaptureController* controller,
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 : controller_(controller), 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
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, 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 auto request_iter = device_start_request_queue_.begin();
338 request != device_start_queue_.rend(); ++request) { 328 if (request_iter != device_start_request_queue_.end()) {
339 if (request->serial_id() == controller->serial_id()) { 329 request_iter =
340 request->set_abort_start(); 330 std::find_if(++request_iter, device_start_request_queue_.end(),
341 DVLOG(3) << "DoStopDevice, aborting start request for device " 331 [controller](const CaptureDeviceStartRequest& request) {
342 << controller->device_id() 332 return request.controller() == controller;
343 << " serial_id = " << controller->serial_id(); 333 });
334 if (request_iter != device_start_request_queue_.end()) {
335 device_start_request_queue_.erase(request_iter);
344 return; 336 return;
345 } 337 }
346 } 338 }
347 339
348 const DeviceInfo* device_info = GetDeviceInfoById(controller->device_id()); 340 const DeviceInfo* device_info = GetDeviceInfoById(controller->device_id());
349 if (device_info != nullptr) { 341 if (device_info != nullptr) {
350 for (auto& observer : capture_observers_) 342 for (auto& observer : capture_observers_)
351 observer.OnVideoCaptureStopped(device_info->descriptor.facing); 343 observer.OnVideoCaptureStopped(device_info->descriptor.facing);
352 } 344 }
353 345
354 DVLOG(3) << "DoStopDevice. Send stop request for device = " 346 DVLOG(3) << "DoStopDevice. Send stop request for device = "
355 << controller->device_id() 347 << controller->device_id()
356 << " serial_id = " << controller->serial_id() << "."; 348 << " serial_id = " << controller->serial_id() << ".";
357 controller->OnLog(base::StringPrintf("Stopping device: id: %s", 349 controller->OnLog(base::StringPrintf("Stopping device: id: %s",
358 controller->device_id().c_str())); 350 controller->device_id().c_str()));
359 351
360 if (controller->IsDeviceAlive()) { 352 // Since we may be removing |controller| from |controllers_| while
361 // Since we may be removing |controller| from |controllers_| while 353 // ReleaseDeviceAsnyc() is executing, we pass it shared ownership to
362 // ReleaseDeviceAsnyc() is executing, we pass it shared ownership to 354 // |controller|.
363 // |controller|. 355 controller->ReleaseDeviceAsync(
364 controller->ReleaseDeviceAsync(base::Bind( 356 base::Bind([](scoped_refptr<VideoCaptureController>) {},
365 [](scoped_refptr<VideoCaptureController>) {}, 357 GetControllerSharedRef(controller)));
366 GetControllerSharedRefFromSerialId(controller->serial_id())));
367 }
368 } 358 }
369 359
370 void VideoCaptureManager::HandleQueuedStartRequest() { 360 void VideoCaptureManager::ProcessDeviceStartRequestQueue() {
371 DCHECK_CURRENTLY_ON(BrowserThread::IO); 361 DCHECK_CURRENTLY_ON(BrowserThread::IO);
372 // Remove all start requests that have been aborted. 362 DeviceStartQueue::iterator request = device_start_request_queue_.begin();
373 while (device_start_queue_.begin() != device_start_queue_.end() && 363 if (request == device_start_request_queue_.end())
374 device_start_queue_.begin()->abort_start()) {
375 device_start_queue_.pop_front();
376 }
377 DeviceStartQueue::iterator request = device_start_queue_.begin();
378 if (request == device_start_queue_.end())
379 return; 364 return;
380 365
381 const int serial_id = request->serial_id(); 366 VideoCaptureController* const controller = request->controller();
382 VideoCaptureController* const controller =
383 LookupControllerBySerialId(serial_id);
384 DCHECK(controller);
385 367
386 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = " 368 DVLOG(3) << "HandleQueuedStartRequest, Post start to device thread, device = "
387 << controller->device_id() 369 << controller->device_id()
388 << " start id = " << controller->serial_id(); 370 << " start id = " << controller->serial_id();
389 371
390 // The method CreateAndStartDeviceAsync() is going to run asynchronously. 372 // The method CreateAndStartDeviceAsync() is going to run asynchronously.
391 // Since we may be removing the controller while it is executing, we need to 373 // Since we may be removing the controller while it is executing, we need to
392 // pass it shared ownership to itself so that it stays alive while executing. 374 // pass it shared ownership to itself so that it stays alive while executing.
393 // And since the execution may make callbacks into |this|, we also need 375 // And since the execution may make callbacks into |this|, we also need
394 // to pass it shared ownership to |this|. 376 // to pass it shared ownership to |this|.
395 // TODO(chfremer): Check if request->params() can actually be different from 377 // TODO(chfremer): Check if request->params() can actually be different from
396 // controller->parameters, and simplify if this is not the case. 378 // controller->parameters, and simplify if this is not the case.
397 controller->CreateAndStartDeviceAsync( 379 controller->CreateAndStartDeviceAsync(
398 request->params(), static_cast<BuildableDeviceCallbacks*>(this), 380 request->params(), static_cast<BuildableDeviceCallbacks*>(this),
399 base::Bind([](scoped_refptr<VideoCaptureManager>, 381 base::Bind([](scoped_refptr<VideoCaptureManager>,
400 scoped_refptr<VideoCaptureController>) {}, 382 scoped_refptr<VideoCaptureController>) {},
401 scoped_refptr<VideoCaptureManager>(this), 383 scoped_refptr<VideoCaptureManager>(this),
402 GetControllerSharedRefFromSerialId(serial_id))); 384 GetControllerSharedRef(controller)));
403 } 385 }
404 386
405 void VideoCaptureManager::WillStartDevice(media::VideoFacingMode facing_mode) { 387 void VideoCaptureManager::WillStartDevice(media::VideoFacingMode facing_mode) {
406 for (auto& observer : capture_observers_) 388 for (auto& observer : capture_observers_)
407 observer.OnVideoCaptureStarted(facing_mode); 389 observer.OnVideoCaptureStarted(facing_mode);
408 } 390 }
409 391
410 void VideoCaptureManager::DidStartDevice(VideoCaptureController* controller) { 392 void VideoCaptureManager::DidStartDevice(VideoCaptureController* controller) {
411 DVLOG(3) << __func__; 393 DVLOG(3) << __func__;
412 DCHECK_CURRENTLY_ON(BrowserThread::IO); 394 DCHECK_CURRENTLY_ON(BrowserThread::IO);
395 DCHECK(!device_start_request_queue_.empty());
396 DCHECK_EQ(controller, device_start_request_queue_.begin()->controller());
413 DCHECK(controller); 397 DCHECK(controller);
414 DCHECK_EQ(controller->serial_id(), device_start_queue_.begin()->serial_id()); 398 if (controller->stream_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) {
415 if (device_start_queue_.front().abort_start()) { 399 const media::VideoCaptureSessionId session_id =
416 // A request to release the device may have arrived during the asynchronous 400 device_start_request_queue_.front().session_id();
417 // device startup. 401 DCHECK(session_id != kFakeSessionId);
418 DVLOG(3) << "Device release request has been issued while device was " 402 MaybePostDesktopCaptureWindowId(session_id);
419 << "starting up asynchronously."; 403 }
420 controller->ReleaseDeviceAsync(base::Bind(
421 [](scoped_refptr<VideoCaptureController>) {},
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 404
431 auto it = photo_request_queue_.begin(); 405 auto it = photo_request_queue_.begin();
432 while (it != photo_request_queue_.end()) { 406 while (it != photo_request_queue_.end()) {
433 auto request = it++; 407 auto request = it++;
434 VideoCaptureController* maybe_entry = 408 VideoCaptureController* maybe_entry =
435 LookupControllerBySessionId(request->first); 409 LookupControllerBySessionId(request->first);
436 if (maybe_entry && maybe_entry->IsDeviceAlive()) { 410 if (maybe_entry && maybe_entry->IsDeviceAlive()) {
437 request->second.Run(); 411 request->second.Run();
438 photo_request_queue_.erase(request); 412 photo_request_queue_.erase(request);
439 }
440 } 413 }
441 } 414 }
442 415
443 device_start_queue_.pop_front(); 416 device_start_request_queue_.pop_front();
444 HandleQueuedStartRequest(); 417 ProcessDeviceStartRequestQueue();
445 } 418 }
446 419
447 void VideoCaptureManager::OnDeviceStartFailed( 420 void VideoCaptureManager::OnDeviceStartFailed(
448 VideoCaptureController* controller) { 421 VideoCaptureController* controller) {
449 const std::string log_message = base::StringPrintf( 422 const std::string log_message = base::StringPrintf(
450 "Starting device %s has failed. Maybe recently disconnected?", 423 "Starting device %s has failed. Maybe recently disconnected?",
451 controller->device_id().c_str()); 424 controller->device_id().c_str());
452 DLOG(ERROR) << log_message; 425 DLOG(ERROR) << log_message;
453 controller->OnLog(log_message); 426 controller->OnLog(log_message);
454 controller->OnError(); 427 controller->OnError();
455 428
456 device_start_queue_.pop_front(); 429 device_start_request_queue_.pop_front();
457 HandleQueuedStartRequest(); 430 ProcessDeviceStartRequestQueue();
458 } 431 }
459 432
460 void VideoCaptureManager::StartCaptureForClient( 433 void VideoCaptureManager::OnDeviceStartAborted() {
434 device_start_request_queue_.pop_front();
435 ProcessDeviceStartRequestQueue();
436 }
437
438 void VideoCaptureManager::ConnectClient(
461 media::VideoCaptureSessionId session_id, 439 media::VideoCaptureSessionId session_id,
462 const media::VideoCaptureParams& params, 440 const media::VideoCaptureParams& params,
463 VideoCaptureControllerID client_id, 441 VideoCaptureControllerID client_id,
464 VideoCaptureControllerEventHandler* client_handler, 442 VideoCaptureControllerEventHandler* client_handler,
465 const DoneCB& done_cb) { 443 const DoneCB& done_cb) {
466 DCHECK_CURRENTLY_ON(BrowserThread::IO); 444 DCHECK_CURRENTLY_ON(BrowserThread::IO);
467 DVLOG(1) << __func__ << ", session_id = " << session_id << ", request: " 445 DVLOG(1) << __func__ << ", session_id = " << session_id << ", request: "
468 << media::VideoCaptureFormat::ToString(params.requested_format); 446 << media::VideoCaptureFormat::ToString(params.requested_format);
469 447
470 VideoCaptureController* controller = 448 VideoCaptureController* controller =
471 GetOrCreateController(session_id, params); 449 GetOrCreateController(session_id, params);
472 if (!controller) { 450 if (!controller) {
473 done_cb.Run(base::WeakPtr<VideoCaptureController>()); 451 done_cb.Run(base::WeakPtr<VideoCaptureController>());
474 return; 452 return;
475 } 453 }
476 454
477 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE); 455 LogVideoCaptureEvent(VIDEO_CAPTURE_START_CAPTURE);
478 456
479 // First client starts the device. 457 // First client starts the device.
480 if (!controller->HasActiveClient() && !controller->HasPausedClient()) { 458 if (!controller->HasActiveClient() && !controller->HasPausedClient()) {
481 DVLOG(1) << "VideoCaptureManager starting device (id = " 459 DVLOG(1) << "VideoCaptureManager starting device (id = "
482 << controller->device_id() << ")"; 460 << controller->device_id() << ")";
483 QueueStartDevice(session_id, controller, params); 461 QueueStartDevice(session_id, controller, params);
484 } 462 }
485 // Run the callback first, as AddClient() may trigger OnFrameInfo(). 463 // Run the callback first, as AddClient() may trigger OnFrameInfo().
486 done_cb.Run(controller->GetWeakPtrForIOThread()); 464 done_cb.Run(controller->GetWeakPtrForIOThread());
487 controller->AddClient(client_id, client_handler, session_id, params); 465 controller->AddClient(client_id, client_handler, session_id, params);
488 } 466 }
489 467
490 void VideoCaptureManager::StopCaptureForClient( 468 void VideoCaptureManager::DisconnectClient(
491 VideoCaptureController* controller, 469 VideoCaptureController* controller,
492 VideoCaptureControllerID client_id, 470 VideoCaptureControllerID client_id,
493 VideoCaptureControllerEventHandler* client_handler, 471 VideoCaptureControllerEventHandler* client_handler,
494 bool aborted_due_to_error) { 472 bool aborted_due_to_error) {
495 DCHECK_CURRENTLY_ON(BrowserThread::IO); 473 DCHECK_CURRENTLY_ON(BrowserThread::IO);
496 DCHECK(controller); 474 DCHECK(controller);
497 DCHECK(client_handler); 475 DCHECK(client_handler);
498 476
499 if (!IsControllerPointerValid(controller)) { 477 if (!IsControllerPointerValid(controller)) {
500 NOTREACHED(); 478 NOTREACHED();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 606 }
629 607
630 bool VideoCaptureManager::GetDeviceFormatsInUse( 608 bool VideoCaptureManager::GetDeviceFormatsInUse(
631 MediaStreamType stream_type, 609 MediaStreamType stream_type,
632 const std::string& device_id, 610 const std::string& device_id,
633 media::VideoCaptureFormats* formats_in_use) { 611 media::VideoCaptureFormats* formats_in_use) {
634 DCHECK_CURRENTLY_ON(BrowserThread::IO); 612 DCHECK_CURRENTLY_ON(BrowserThread::IO);
635 DCHECK(formats_in_use->empty()); 613 DCHECK(formats_in_use->empty());
636 // Return the currently in-use format(s) of the device, if it's started. 614 // Return the currently in-use format(s) of the device, if it's started.
637 VideoCaptureController* device_in_use = 615 VideoCaptureController* device_in_use =
638 LookupControllerByTypeAndId(stream_type, device_id); 616 LookupControllerByMediaTypeAndDeviceId(stream_type, device_id);
639 if (device_in_use) { 617 if (device_in_use) {
640 // Currently only one format-in-use is supported at the VCC level. 618 // Currently only one format-in-use is supported at the VCC level.
641 formats_in_use->push_back(device_in_use->GetVideoCaptureFormat()); 619 formats_in_use->push_back(device_in_use->GetVideoCaptureFormat());
642 } 620 }
643 return true; 621 return true;
644 } 622 }
645 623
646 void VideoCaptureManager::SetDesktopCaptureWindowId( 624 void VideoCaptureManager::SetDesktopCaptureWindowId(
647 media::VideoCaptureSessionId session_id, 625 media::VideoCaptureSessionId session_id,
648 gfx::NativeViewId window_id) { 626 gfx::NativeViewId window_id) {
649 DCHECK_CURRENTLY_ON(BrowserThread::IO); 627 DCHECK_CURRENTLY_ON(BrowserThread::IO);
650 VLOG(2) << "SetDesktopCaptureWindowId called for session " << session_id; 628 VLOG(2) << "SetDesktopCaptureWindowId called for session " << session_id;
651 629
652 notification_window_ids_[session_id] = window_id; 630 notification_window_ids_[session_id] = window_id;
653 MaybePostDesktopCaptureWindowId(session_id); 631 MaybePostDesktopCaptureWindowId(session_id);
654 } 632 }
655 633
656 void VideoCaptureManager::MaybePostDesktopCaptureWindowId( 634 void VideoCaptureManager::MaybePostDesktopCaptureWindowId(
657 media::VideoCaptureSessionId session_id) { 635 media::VideoCaptureSessionId session_id) {
658 SessionMap::iterator session_it = sessions_.find(session_id); 636 SessionMap::iterator session_it = sessions_.find(session_id);
659 if (session_it == sessions_.end()) 637 if (session_it == sessions_.end())
660 return; 638 return;
661 639
662 VideoCaptureController* const existing_device = LookupControllerByTypeAndId( 640 VideoCaptureController* const existing_device =
663 session_it->second.type, session_it->second.id); 641 LookupControllerByMediaTypeAndDeviceId(session_it->second.type,
642 session_it->second.id);
664 if (!existing_device) { 643 if (!existing_device) {
665 DVLOG(2) << "Failed to find an existing screen capture device."; 644 DVLOG(2) << "Failed to find an existing screen capture device.";
666 return; 645 return;
667 } 646 }
668 647
669 if (!existing_device->IsDeviceAlive()) { 648 if (!existing_device->IsDeviceAlive()) {
670 DVLOG(2) << "Screen capture device not yet started."; 649 DVLOG(2) << "Screen capture device not yet started.";
671 return; 650 return;
672 } 651 }
673 652
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 } 829 }
851 } 830 }
852 831
853 VideoCaptureController* VideoCaptureManager::LookupControllerBySessionId( 832 VideoCaptureController* VideoCaptureManager::LookupControllerBySessionId(
854 int session_id) { 833 int session_id) {
855 DCHECK_CURRENTLY_ON(BrowserThread::IO); 834 DCHECK_CURRENTLY_ON(BrowserThread::IO);
856 SessionMap::const_iterator session_it = sessions_.find(session_id); 835 SessionMap::const_iterator session_it = sessions_.find(session_id);
857 if (session_it == sessions_.end()) 836 if (session_it == sessions_.end())
858 return nullptr; 837 return nullptr;
859 838
860 return LookupControllerByTypeAndId(session_it->second.type, 839 return LookupControllerByMediaTypeAndDeviceId(session_it->second.type,
861 session_it->second.id); 840 session_it->second.id);
862 } 841 }
863 842
864 VideoCaptureController* VideoCaptureManager::LookupControllerByTypeAndId( 843 VideoCaptureController*
844 VideoCaptureManager::LookupControllerByMediaTypeAndDeviceId(
865 MediaStreamType type, 845 MediaStreamType type,
866 const std::string& device_id) const { 846 const std::string& device_id) const {
867 DCHECK_CURRENTLY_ON(BrowserThread::IO); 847 DCHECK_CURRENTLY_ON(BrowserThread::IO);
868 848
869 for (const auto& entry : controllers_) { 849 for (const auto& entry : controllers_) {
870 if (type == entry->stream_type() && device_id == entry->device_id()) 850 if (type == entry->stream_type() && device_id == entry->device_id())
871 return entry.get(); 851 return entry.get();
872 } 852 }
873 return nullptr; 853 return nullptr;
874 } 854 }
875 855
876 bool VideoCaptureManager::IsControllerPointerValid( 856 bool VideoCaptureManager::IsControllerPointerValid(
877 const VideoCaptureController* controller) const { 857 const VideoCaptureController* controller) const {
878 DCHECK_CURRENTLY_ON(BrowserThread::IO); 858 DCHECK_CURRENTLY_ON(BrowserThread::IO);
879 return base::ContainsValue(controllers_, controller); 859 return base::ContainsValue(controllers_, controller);
880 } 860 }
881 861
882 VideoCaptureController* VideoCaptureManager::LookupControllerBySerialId( 862 scoped_refptr<VideoCaptureController>
883 int serial_id) const { 863 VideoCaptureManager::GetControllerSharedRef(
864 VideoCaptureController* controller) const {
884 DCHECK_CURRENTLY_ON(BrowserThread::IO); 865 DCHECK_CURRENTLY_ON(BrowserThread::IO);
885 866
886 for (const auto& entry : controllers_) { 867 for (const auto& entry : controllers_) {
887 if (entry->serial_id() == serial_id) 868 if (entry.get() == controller)
888 return entry.get();
889 }
890 return nullptr;
891 }
892
893 scoped_refptr<VideoCaptureController>
894 VideoCaptureManager::GetControllerSharedRefFromSerialId(int serial_id) const {
895 DCHECK_CURRENTLY_ON(BrowserThread::IO);
896
897 for (const auto& entry : controllers_) {
898 if (entry->serial_id() == serial_id)
899 return entry; 869 return entry;
900 } 870 }
901 return nullptr; 871 return nullptr;
902 } 872 }
903 873
904 VideoCaptureManager::DeviceInfo* VideoCaptureManager::GetDeviceInfoById( 874 VideoCaptureManager::DeviceInfo* VideoCaptureManager::GetDeviceInfoById(
905 const std::string& id) { 875 const std::string& id) {
906 for (auto& it : devices_info_cache_) { 876 for (auto& it : devices_info_cache_) {
907 if (it.descriptor.device_id == id) 877 if (it.descriptor.device_id == id)
908 return &it; 878 return &it;
909 } 879 }
910 return nullptr; 880 return nullptr;
911 } 881 }
912 882
913 VideoCaptureController* VideoCaptureManager::GetOrCreateController( 883 VideoCaptureController* VideoCaptureManager::GetOrCreateController(
914 media::VideoCaptureSessionId capture_session_id, 884 media::VideoCaptureSessionId capture_session_id,
915 const media::VideoCaptureParams& params) { 885 const media::VideoCaptureParams& params) {
916 DCHECK_CURRENTLY_ON(BrowserThread::IO); 886 DCHECK_CURRENTLY_ON(BrowserThread::IO);
917 887
918 SessionMap::iterator session_it = sessions_.find(capture_session_id); 888 SessionMap::iterator session_it = sessions_.find(capture_session_id);
919 if (session_it == sessions_.end()) 889 if (session_it == sessions_.end())
920 return nullptr; 890 return nullptr;
921 const MediaStreamDevice& device_info = session_it->second; 891 const MediaStreamDevice& device_info = session_it->second;
922 892
923 // Check if another session has already opened this device. If so, just 893 // Check if another session has already opened this device. If so, just
924 // use that opened device. 894 // use that opened device.
925 VideoCaptureController* const existing_device = 895 VideoCaptureController* const existing_device =
926 LookupControllerByTypeAndId(device_info.type, device_info.id); 896 LookupControllerByMediaTypeAndDeviceId(device_info.type, device_info.id);
927 if (existing_device) { 897 if (existing_device) {
928 DCHECK_EQ(device_info.type, existing_device->stream_type()); 898 DCHECK_EQ(device_info.type, existing_device->stream_type());
929 return existing_device; 899 return existing_device;
930 } 900 }
931 901
932 VideoCaptureController* new_device_entry = new VideoCaptureController( 902 VideoCaptureController* new_controller = new VideoCaptureController(
933 device_info.id, device_info.type, params, 903 device_info.id, device_info.type, params,
934 base::MakeUnique<InProcessBuildableVideoCaptureDevice>( 904 base::MakeUnique<InProcessBuildableVideoCaptureDevice>(
935 device_task_runner_, video_capture_device_factory_.get())); 905 device_task_runner_, video_capture_device_factory_.get()));
936 controllers_.emplace_back(new_device_entry); 906 controllers_.emplace_back(new_controller);
937 return new_device_entry; 907 return new_controller;
938 } 908 }
939 909
940 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration( 910 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration(
941 const std::string& device_id) { 911 const std::string& device_id) {
942 VideoCaptureManager::DeviceInfo* info = GetDeviceInfoById(device_id); 912 VideoCaptureManager::DeviceInfo* info = GetDeviceInfoById(device_id);
943 if (!info) 913 if (!info)
944 return base::Optional<CameraCalibration>(); 914 return base::Optional<CameraCalibration>();
945 return info->descriptor.camera_calibration; 915 return info->descriptor.camera_calibration;
946 } 916 }
947 917
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 949
980 for (auto& controller : controllers_) { 950 for (auto& controller : controllers_) {
981 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture. 951 // Do not resume Content Video Capture devices, e.g. Tab or Screen capture.
982 // Do not try to restart already running devices. 952 // Do not try to restart already running devices.
983 if (controller->stream_type() != MEDIA_DEVICE_VIDEO_CAPTURE || 953 if (controller->stream_type() != MEDIA_DEVICE_VIDEO_CAPTURE ||
984 controller->IsDeviceAlive()) 954 controller->IsDeviceAlive())
985 continue; 955 continue;
986 956
987 // Check if the device is already in the start queue. 957 // Check if the device is already in the start queue.
988 bool device_in_queue = false; 958 bool device_in_queue = false;
989 for (auto& request : device_start_queue_) { 959 for (auto& request : device_start_request_queue_) {
990 if (request.serial_id() == controller->serial_id()) { 960 if (request.serial_id() == controller->serial_id()) {
991 device_in_queue = true; 961 device_in_queue = true;
992 break; 962 break;
993 } 963 }
994 } 964 }
995 965
996 if (!device_in_queue) { 966 if (!device_in_queue) {
997 // Session ID is only valid for Screen capture. So we can fake it to 967 // Session ID is only valid for Screen capture. So we can fake it to
998 // resume video capture devices here. 968 // resume video capture devices here.
999 QueueStartDevice(kFakeSessionId, controller.get(), 969 QueueStartDevice(kFakeSessionId, controller.get(),
1000 controller->parameters()); 970 controller->parameters());
1001 } 971 }
1002 } 972 }
1003 } 973 }
1004 #endif // defined(OS_ANDROID) 974 #endif // defined(OS_ANDROID)
1005 975
1006 } // namespace content 976 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698