| 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_(NULL) {} |
| 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 media::VideoCaptureObserver* observer) { |
| 348 capture_observer_ = 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_ != NULL) { |
| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 654 |
| 643 std::unique_ptr<VideoCaptureDevice> video_capture_device; | 655 std::unique_ptr<VideoCaptureDevice> video_capture_device; |
| 644 video_capture_device = | 656 video_capture_device = |
| 645 video_capture_device_factory_->CreateDevice(descriptor); | 657 video_capture_device_factory_->CreateDevice(descriptor); |
| 646 | 658 |
| 647 if (!video_capture_device) { | 659 if (!video_capture_device) { |
| 648 device_client->OnError(FROM_HERE, "Could not create capture device"); | 660 device_client->OnError(FROM_HERE, "Could not create capture device"); |
| 649 return nullptr; | 661 return nullptr; |
| 650 } | 662 } |
| 651 | 663 |
| 664 if (capture_observer_ != NULL) { |
| 665 capture_observer_->OnVideoCaptureStarted(descriptor.facing); |
| 666 } |
| 667 |
| 652 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 668 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
| 653 return video_capture_device; | 669 return video_capture_device; |
| 654 } | 670 } |
| 655 | 671 |
| 656 std::unique_ptr<media::VideoCaptureDevice> | 672 std::unique_ptr<media::VideoCaptureDevice> |
| 657 VideoCaptureManager::DoStartTabCaptureOnDeviceThread( | 673 VideoCaptureManager::DoStartTabCaptureOnDeviceThread( |
| 658 const std::string& id, | 674 const std::string& id, |
| 659 const media::VideoCaptureParams& params, | 675 const media::VideoCaptureParams& params, |
| 660 std::unique_ptr<VideoCaptureDevice::Client> device_client) { | 676 std::unique_ptr<VideoCaptureDevice::Client> device_client) { |
| 661 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 677 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
| (...skipping 662 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 |