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