| 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 : device_task_runner_(std::move(device_task_runner)), | 333 : device_task_runner_(std::move(device_task_runner)), |
| 333 listener_(nullptr), | 334 listener_(nullptr), |
| 334 new_capture_session_id_(1), | 335 new_capture_session_id_(1), |
| 335 video_capture_device_factory_(std::move(factory)) {} | 336 video_capture_device_factory_(std::move(factory)) {} |
| 336 | 337 |
| 337 VideoCaptureManager::~VideoCaptureManager() { | 338 VideoCaptureManager::~VideoCaptureManager() { |
| 338 DCHECK(devices_.empty()); | 339 DCHECK(devices_.empty()); |
| 339 DCHECK(device_start_queue_.empty()); | 340 DCHECK(device_start_queue_.empty()); |
| 340 } | 341 } |
| 341 | 342 |
| 343 void VideoCaptureManager::AddVideoCaptureObserver( |
| 344 media::VideoCaptureObserver* observer) { |
| 345 DCHECK(observer); |
| 346 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 347 capture_observers_.AddObserver(observer); |
| 348 } |
| 349 |
| 350 void VideoCaptureManager::RemoveAllVideoCaptureObservers() { |
| 351 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 352 capture_observers_.Clear(); |
| 353 } |
| 354 |
| 342 void VideoCaptureManager::RegisterListener( | 355 void VideoCaptureManager::RegisterListener( |
| 343 MediaStreamProviderListener* listener) { | 356 MediaStreamProviderListener* listener) { |
| 344 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 357 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 345 DCHECK(!listener_); | 358 DCHECK(!listener_); |
| 346 DCHECK(device_task_runner_); | 359 DCHECK(device_task_runner_); |
| 347 listener_ = listener; | 360 listener_ = listener; |
| 348 #if defined(OS_ANDROID) | 361 #if defined(OS_ANDROID) |
| 349 application_state_has_running_activities_ = true; | 362 application_state_has_running_activities_ = true; |
| 350 app_status_listener_.reset(new base::android::ApplicationStatusListener( | 363 app_status_listener_.reset(new base::android::ApplicationStatusListener( |
| 351 base::Bind(&VideoCaptureManager::OnApplicationStateChange, | 364 base::Bind(&VideoCaptureManager::OnApplicationStateChange, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 device_start_queue_.rbegin(); | 474 device_start_queue_.rbegin(); |
| 462 request != device_start_queue_.rend(); ++request) { | 475 request != device_start_queue_.rend(); ++request) { |
| 463 if (request->serial_id() == entry->serial_id) { | 476 if (request->serial_id() == entry->serial_id) { |
| 464 request->set_abort_start(); | 477 request->set_abort_start(); |
| 465 DVLOG(3) << "DoStopDevice, aborting start request for device " | 478 DVLOG(3) << "DoStopDevice, aborting start request for device " |
| 466 << entry->id << " serial_id = " << entry->serial_id; | 479 << entry->id << " serial_id = " << entry->serial_id; |
| 467 return; | 480 return; |
| 468 } | 481 } |
| 469 } | 482 } |
| 470 | 483 |
| 484 const DeviceInfo* device_info = GetDeviceInfoById(entry->id); |
| 485 if (device_info != nullptr) { |
| 486 for (auto& observer : capture_observers_) |
| 487 observer.OnVideoCaptureStopped(device_info->descriptor.facing); |
| 488 } |
| 489 |
| 471 DVLOG(3) << "DoStopDevice. Send stop request for device = " << entry->id | 490 DVLOG(3) << "DoStopDevice. Send stop request for device = " << entry->id |
| 472 << " serial_id = " << entry->serial_id << "."; | 491 << " serial_id = " << entry->serial_id << "."; |
| 473 entry->video_capture_controller.OnLog( | 492 entry->video_capture_controller.OnLog( |
| 474 base::StringPrintf("Stopping device: id: %s", entry->id.c_str())); | 493 base::StringPrintf("Stopping device: id: %s", entry->id.c_str())); |
| 475 entry->video_capture_controller.SetConsumerFeedbackObserver(nullptr); | 494 entry->video_capture_controller.SetConsumerFeedbackObserver(nullptr); |
| 476 entry->video_capture_controller.SetFrameBufferPool(nullptr); | 495 entry->video_capture_controller.SetFrameBufferPool(nullptr); |
| 477 | 496 |
| 478 // |entry->video_capture_device| can be null if creating the device has | 497 // |entry->video_capture_device| can be null if creating the device has |
| 479 // failed. | 498 // failed. |
| 480 if (entry->video_capture_device) { | 499 if (entry->video_capture_device) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // since the renderer does not have all the information that might be | 536 // since the renderer does not have all the information that might be |
| 518 // held in the browser-side VideoCaptureDevice::Name structure. | 537 // held in the browser-side VideoCaptureDevice::Name structure. |
| 519 const DeviceInfo* found = GetDeviceInfoById(entry->id); | 538 const DeviceInfo* found = GetDeviceInfoById(entry->id); |
| 520 if (found) { | 539 if (found) { |
| 521 entry->video_capture_controller.OnLog( | 540 entry->video_capture_controller.OnLog( |
| 522 base::StringPrintf("Starting device: id: %s, name: %s, api: %s", | 541 base::StringPrintf("Starting device: id: %s, name: %s, api: %s", |
| 523 found->descriptor.device_id.c_str(), | 542 found->descriptor.device_id.c_str(), |
| 524 found->descriptor.GetNameAndModel().c_str(), | 543 found->descriptor.GetNameAndModel().c_str(), |
| 525 found->descriptor.GetCaptureApiTypeString())); | 544 found->descriptor.GetCaptureApiTypeString())); |
| 526 | 545 |
| 546 for (auto& observer : capture_observers_) |
| 547 observer.OnVideoCaptureStarted(found->descriptor.facing); |
| 548 |
| 527 start_capture_function = | 549 start_capture_function = |
| 528 base::Bind(&VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread, | 550 base::Bind(&VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread, |
| 529 this, found->descriptor, request->params(), | 551 this, found->descriptor, request->params(), |
| 530 base::Passed(std::move(device_client))); | 552 base::Passed(std::move(device_client))); |
| 531 } else { | 553 } else { |
| 532 // Errors from DoStartDeviceCaptureOnDeviceThread go via | 554 // Errors from DoStartDeviceCaptureOnDeviceThread go via |
| 533 // VideoCaptureDeviceClient::OnError, which needs some thread | 555 // VideoCaptureDeviceClient::OnError, which needs some thread |
| 534 // dancing to get errors processed on the IO thread. But since | 556 // dancing to get errors processed on the IO thread. But since |
| 535 // we're on that thread, we call VideoCaptureController | 557 // we're on that thread, we call VideoCaptureController |
| 536 // methods directly. | 558 // methods directly. |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 if (!device_in_queue) { | 1372 if (!device_in_queue) { |
| 1351 // Session ID is only valid for Screen capture. So we can fake it to | 1373 // Session ID is only valid for Screen capture. So we can fake it to |
| 1352 // resume video capture devices here. | 1374 // resume video capture devices here. |
| 1353 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1375 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
| 1354 } | 1376 } |
| 1355 } | 1377 } |
| 1356 } | 1378 } |
| 1357 #endif // defined(OS_ANDROID) | 1379 #endif // defined(OS_ANDROID) |
| 1358 | 1380 |
| 1359 } // namespace content | 1381 } // namespace content |
| OLD | NEW |