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 16 matching lines...) Expand all Loading... | |
| 27 #include "content/browser/media/media_internals.h" | 27 #include "content/browser/media/media_internals.h" |
| 28 #include "content/browser/renderer_host/media/video_capture_controller.h" | 28 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 29 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 29 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| 30 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" | 30 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" |
| 31 #include "content/browser/renderer_host/media/video_frame_receiver_on_io_thread. h" | 31 #include "content/browser/renderer_host/media/video_frame_receiver_on_io_thread. h" |
| 32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/desktop_media_id.h" | 33 #include "content/public/browser/desktop_media_id.h" |
| 34 #include "content/public/common/media_stream_request.h" | 34 #include "content/public/common/media_stream_request.h" |
| 35 #include "media/base/bind_to_current_loop.h" | 35 #include "media/base/bind_to_current_loop.h" |
| 36 #include "media/base/media_switches.h" | 36 #include "media/base/media_switches.h" |
| 37 #include "media/base/video_facing.h" | |
| 37 #include "media/capture/video/video_capture_buffer_pool_impl.h" | 38 #include "media/capture/video/video_capture_buffer_pool_impl.h" |
| 38 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" | 39 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" |
| 39 #include "media/capture/video/video_capture_device.h" | 40 #include "media/capture/video/video_capture_device.h" |
| 40 #include "media/capture/video/video_capture_device_client.h" | 41 #include "media/capture/video/video_capture_device_client.h" |
| 41 #include "media/capture/video/video_capture_device_factory.h" | 42 #include "media/capture/video/video_capture_device_factory.h" |
| 42 | 43 |
| 43 #if defined(ENABLE_SCREEN_CAPTURE) | 44 #if defined(ENABLE_SCREEN_CAPTURE) |
| 44 | 45 |
| 45 #if BUILDFLAG(ENABLE_WEBRTC) && !defined(OS_ANDROID) | 46 #if BUILDFLAG(ENABLE_WEBRTC) && !defined(OS_ANDROID) |
| 46 #include "content/browser/media/capture/desktop_capture_device.h" | 47 #include "content/browser/media/capture/desktop_capture_device.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 : serial_id_(serial_id), | 328 : serial_id_(serial_id), |
| 328 session_id_(session_id), | 329 session_id_(session_id), |
| 329 params_(params), | 330 params_(params), |
| 330 abort_start_(false) { | 331 abort_start_(false) { |
| 331 } | 332 } |
| 332 | 333 |
| 333 VideoCaptureManager::VideoCaptureManager( | 334 VideoCaptureManager::VideoCaptureManager( |
| 334 std::unique_ptr<media::VideoCaptureDeviceFactory> factory) | 335 std::unique_ptr<media::VideoCaptureDeviceFactory> factory) |
| 335 : listener_(nullptr), | 336 : listener_(nullptr), |
| 336 new_capture_session_id_(1), | 337 new_capture_session_id_(1), |
| 337 video_capture_device_factory_(std::move(factory)) {} | 338 video_capture_device_factory_(std::move(factory)), |
| 339 capture_observer_(nullptr) {} | |
|
chfremer
2017/01/30 19:49:28
No need to initialize a std::unique_ptr<> member t
shenghao
2017/02/08 02:07:10
Done.
| |
| 338 | 340 |
| 339 VideoCaptureManager::~VideoCaptureManager() { | 341 VideoCaptureManager::~VideoCaptureManager() { |
| 340 DCHECK(devices_.empty()); | 342 DCHECK(devices_.empty()); |
| 341 DCHECK(device_start_queue_.empty()); | 343 DCHECK(device_start_queue_.empty()); |
| 342 } | 344 } |
| 343 | 345 |
| 346 void VideoCaptureManager::SetVideoCaptureObserver( | |
| 347 std::unique_ptr<media::VideoCaptureObserver> observer) { | |
| 348 capture_observer_ = std::move(observer); | |
| 349 } | |
| 350 | |
| 344 void VideoCaptureManager::Register( | 351 void VideoCaptureManager::Register( |
| 345 MediaStreamProviderListener* listener, | 352 MediaStreamProviderListener* listener, |
| 346 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { | 353 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { |
| 347 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 354 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 348 DCHECK(!listener_); | 355 DCHECK(!listener_); |
| 349 DCHECK(!device_task_runner_.get()); | 356 DCHECK(!device_task_runner_.get()); |
| 350 listener_ = listener; | 357 listener_ = listener; |
| 351 device_task_runner_ = device_task_runner; | 358 device_task_runner_ = device_task_runner; |
| 352 #if defined(OS_ANDROID) | 359 #if defined(OS_ANDROID) |
| 353 application_state_has_running_activities_ = true; | 360 application_state_has_running_activities_ = true; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 device_start_queue_.rbegin(); | 471 device_start_queue_.rbegin(); |
| 465 request != device_start_queue_.rend(); ++request) { | 472 request != device_start_queue_.rend(); ++request) { |
| 466 if (request->serial_id() == entry->serial_id) { | 473 if (request->serial_id() == entry->serial_id) { |
| 467 request->set_abort_start(); | 474 request->set_abort_start(); |
| 468 DVLOG(3) << "DoStopDevice, aborting start request for device " | 475 DVLOG(3) << "DoStopDevice, aborting start request for device " |
| 469 << entry->id << " serial_id = " << entry->serial_id; | 476 << entry->id << " serial_id = " << entry->serial_id; |
| 470 return; | 477 return; |
| 471 } | 478 } |
| 472 } | 479 } |
| 473 | 480 |
| 481 const DeviceInfo* device_info = GetDeviceInfoById(entry->id); | |
| 482 if (device_info != NULL && capture_observer_.get() != NULL) { | |
|
chfremer
2017/01/30 19:49:28
NULL -> nullptr
shenghao
2017/02/08 02:07:10
Done.
| |
| 483 capture_observer_->OnVideoCaptureStopped(device_info->descriptor.facing); | |
| 484 } | |
| 485 | |
| 474 DVLOG(3) << "DoStopDevice. Send stop request for device = " << entry->id | 486 DVLOG(3) << "DoStopDevice. Send stop request for device = " << entry->id |
| 475 << " serial_id = " << entry->serial_id << "."; | 487 << " serial_id = " << entry->serial_id << "."; |
| 476 entry->video_capture_controller.OnLog( | 488 entry->video_capture_controller.OnLog( |
| 477 base::StringPrintf("Stopping device: id: %s", entry->id.c_str())); | 489 base::StringPrintf("Stopping device: id: %s", entry->id.c_str())); |
| 478 entry->video_capture_controller.SetConsumerFeedbackObserver(nullptr); | 490 entry->video_capture_controller.SetConsumerFeedbackObserver(nullptr); |
| 479 entry->video_capture_controller.SetFrameBufferPool(nullptr); | 491 entry->video_capture_controller.SetFrameBufferPool(nullptr); |
| 480 | 492 |
| 481 // |entry->video_capture_device| can be null if creating the device has | 493 // |entry->video_capture_device| can be null if creating the device has |
| 482 // failed. | 494 // failed. |
| 483 if (entry->video_capture_device) { | 495 if (entry->video_capture_device) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 // since the renderer does not have all the information that might be | 532 // since the renderer does not have all the information that might be |
| 521 // held in the browser-side VideoCaptureDevice::Name structure. | 533 // held in the browser-side VideoCaptureDevice::Name structure. |
| 522 const DeviceInfo* found = GetDeviceInfoById(entry->id); | 534 const DeviceInfo* found = GetDeviceInfoById(entry->id); |
| 523 if (found) { | 535 if (found) { |
| 524 entry->video_capture_controller.OnLog( | 536 entry->video_capture_controller.OnLog( |
| 525 base::StringPrintf("Starting device: id: %s, name: %s, api: %s", | 537 base::StringPrintf("Starting device: id: %s, name: %s, api: %s", |
| 526 found->descriptor.device_id.c_str(), | 538 found->descriptor.device_id.c_str(), |
| 527 found->descriptor.GetNameAndModel().c_str(), | 539 found->descriptor.GetNameAndModel().c_str(), |
| 528 found->descriptor.GetCaptureApiTypeString())); | 540 found->descriptor.GetCaptureApiTypeString())); |
| 529 | 541 |
| 542 if (capture_observer_.get() != NULL) { | |
|
chfremer
2017/01/30 19:49:28
NULL -> nullptr
shenghao
2017/02/08 02:07:10
Done.
| |
| 543 capture_observer_->OnVideoCaptureStarted(found->descriptor.facing); | |
| 544 } | |
| 545 | |
| 530 start_capture_function = | 546 start_capture_function = |
| 531 base::Bind(&VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread, | 547 base::Bind(&VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread, |
| 532 this, found->descriptor, request->params(), | 548 this, found->descriptor, request->params(), |
| 533 base::Passed(std::move(device_client))); | 549 base::Passed(std::move(device_client))); |
| 534 } else { | 550 } else { |
| 535 // Errors from DoStartDeviceCaptureOnDeviceThread go via | 551 // Errors from DoStartDeviceCaptureOnDeviceThread go via |
| 536 // VideoCaptureDeviceClient::OnError, which needs some thread | 552 // VideoCaptureDeviceClient::OnError, which needs some thread |
| 537 // dancing to get errors processed on the IO thread. But since | 553 // dancing to get errors processed on the IO thread. But since |
| 538 // we're on that thread, we call VideoCaptureController | 554 // we're on that thread, we call VideoCaptureController |
| 539 // methods directly. | 555 // methods directly. |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1324 if (!device_in_queue) { | 1340 if (!device_in_queue) { |
| 1325 // Session ID is only valid for Screen capture. So we can fake it to | 1341 // Session ID is only valid for Screen capture. So we can fake it to |
| 1326 // resume video capture devices here. | 1342 // resume video capture devices here. |
| 1327 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1343 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
| 1328 } | 1344 } |
| 1329 } | 1345 } |
| 1330 } | 1346 } |
| 1331 #endif // defined(OS_ANDROID) | 1347 #endif // defined(OS_ANDROID) |
| 1332 | 1348 |
| 1333 } // namespace content | 1349 } // namespace content |
| OLD | NEW |