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

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

Issue 2800493002: [Mojo Video Capture] Create abstraction VideoCaptureProvider (Closed)
Patch Set: Incorporated suggestions from PatchSet 2 Created 3 years, 8 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/task_runner_util.h" 21 #include "base/task_runner_util.h"
22 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" 25 #include "content/browser/media/capture/desktop_capture_device_uma_types.h"
26 #include "content/browser/media/capture/web_contents_video_capture_device.h" 26 #include "content/browser/media/capture/web_contents_video_capture_device.h"
27 #include "content/browser/media/media_internals.h" 27 #include "content/browser/media/media_internals.h"
28 #include "content/browser/renderer_host/media/in_process_buildable_video_capture _device.h"
29 #include "content/browser/renderer_host/media/video_capture_controller.h" 28 #include "content/browser/renderer_host/media/video_capture_controller.h"
30 #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"
31 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/desktop_media_id.h" 31 #include "content/public/browser/desktop_media_id.h"
33 #include "content/public/common/media_stream_request.h" 32 #include "content/public/common/media_stream_request.h"
34 #include "media/base/bind_to_current_loop.h" 33 #include "media/base/bind_to_current_loop.h"
35 #include "media/base/media_switches.h" 34 #include "media/base/media_switches.h"
36 #include "media/base/video_facing.h" 35 #include "media/base/video_facing.h"
37 #include "media/capture/video/video_capture_buffer_pool_impl.h" 36 #include "media/capture/video/video_capture_buffer_pool_impl.h"
38 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" 37 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 const media::VideoCaptureParams params_; 96 const media::VideoCaptureParams params_;
98 }; 97 };
99 98
100 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest( 99 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest(
101 VideoCaptureController* controller, 100 VideoCaptureController* controller,
102 media::VideoCaptureSessionId session_id, 101 media::VideoCaptureSessionId session_id,
103 const media::VideoCaptureParams& params) 102 const media::VideoCaptureParams& params)
104 : controller_(controller), session_id_(session_id), params_(params) {} 103 : controller_(controller), session_id_(session_id), params_(params) {}
105 104
106 VideoCaptureManager::VideoCaptureManager( 105 VideoCaptureManager::VideoCaptureManager(
107 std::unique_ptr<media::VideoCaptureSystem> video_capture_system, 106 std::unique_ptr<VideoCaptureProvider> video_capture_provider)
108 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner) 107 : new_capture_session_id_(1),
109 : device_task_runner_(std::move(device_task_runner)), 108 video_capture_provider_(std::move(video_capture_provider)) {}
110 new_capture_session_id_(1),
111 video_capture_system_(std::move(video_capture_system)) {}
112 109
113 VideoCaptureManager::~VideoCaptureManager() { 110 VideoCaptureManager::~VideoCaptureManager() {
114 DCHECK(controllers_.empty()); 111 DCHECK(controllers_.empty());
115 DCHECK(device_start_request_queue_.empty()); 112 DCHECK(device_start_request_queue_.empty());
116 } 113 }
117 114
118 void VideoCaptureManager::AddVideoCaptureObserver( 115 void VideoCaptureManager::AddVideoCaptureObserver(
119 media::VideoCaptureObserver* observer) { 116 media::VideoCaptureObserver* observer) {
120 DCHECK(observer); 117 DCHECK(observer);
121 DCHECK_CURRENTLY_ON(BrowserThread::IO); 118 DCHECK_CURRENTLY_ON(BrowserThread::IO);
122 capture_observers_.AddObserver(observer); 119 capture_observers_.AddObserver(observer);
123 } 120 }
124 121
125 void VideoCaptureManager::RemoveAllVideoCaptureObservers() { 122 void VideoCaptureManager::RemoveAllVideoCaptureObservers() {
126 DCHECK_CURRENTLY_ON(BrowserThread::IO); 123 DCHECK_CURRENTLY_ON(BrowserThread::IO);
127 capture_observers_.Clear(); 124 capture_observers_.Clear();
128 } 125 }
129 126
130 void VideoCaptureManager::RegisterListener( 127 void VideoCaptureManager::RegisterListener(
131 MediaStreamProviderListener* listener) { 128 MediaStreamProviderListener* listener) {
132 DCHECK_CURRENTLY_ON(BrowserThread::IO); 129 DCHECK_CURRENTLY_ON(BrowserThread::IO);
133 DCHECK(listener); 130 DCHECK(listener);
134 DCHECK(device_task_runner_);
135 listeners_.AddObserver(listener); 131 listeners_.AddObserver(listener);
136 #if defined(OS_ANDROID) 132 #if defined(OS_ANDROID)
137 application_state_has_running_activities_ = true; 133 application_state_has_running_activities_ = true;
138 app_status_listener_.reset(new base::android::ApplicationStatusListener( 134 app_status_listener_.reset(new base::android::ApplicationStatusListener(
139 base::Bind(&VideoCaptureManager::OnApplicationStateChange, 135 base::Bind(&VideoCaptureManager::OnApplicationStateChange,
140 base::Unretained(this)))); 136 base::Unretained(this))));
141 #endif 137 #endif
142 } 138 }
143 139
144 void VideoCaptureManager::UnregisterListener( 140 void VideoCaptureManager::UnregisterListener(
145 MediaStreamProviderListener* listener) { 141 MediaStreamProviderListener* listener) {
146 DCHECK_CURRENTLY_ON(BrowserThread::IO); 142 DCHECK_CURRENTLY_ON(BrowserThread::IO);
147 listeners_.RemoveObserver(listener); 143 listeners_.RemoveObserver(listener);
148 } 144 }
149 145
150 void VideoCaptureManager::EnumerateDevices( 146 void VideoCaptureManager::EnumerateDevices(
151 const EnumerationCallback& client_callback) { 147 const EnumerationCallback& client_callback) {
152 DCHECK_CURRENTLY_ON(BrowserThread::IO); 148 DCHECK_CURRENTLY_ON(BrowserThread::IO);
153 DVLOG(1) << "VideoCaptureManager::EnumerateDevices"; 149 DVLOG(1) << "VideoCaptureManager::EnumerateDevices";
154 150
155 // OK to use base::Unretained(video_capture_system_) since we own the 151 // Pass a timer for UMA histogram collection.
156 // |video_capture_system_| and |this| is bound in 152 video_capture_provider_->GetDeviceInfosAsync(media::BindToCurrentLoop(
157 // |devices_enumerated_callback|. 153 base::Bind(&VideoCaptureManager::OnDeviceInfosReceived, this,
158 device_task_runner_->PostTask( 154 base::Owned(new base::ElapsedTimer()), client_callback)));
159 FROM_HERE,
160 base::Bind(&media::VideoCaptureSystem::GetDeviceInfosAsync,
161 base::Unretained(video_capture_system_.get()),
162 // Pass a timer for UMA histogram collection.
163 media::BindToCurrentLoop(base::Bind(
164 &VideoCaptureManager::OnDeviceInfosReceived, this,
165 base::Owned(new base::ElapsedTimer()), client_callback))));
166 } 155 }
167 156
168 int VideoCaptureManager::Open(const MediaStreamDevice& device) { 157 int VideoCaptureManager::Open(const MediaStreamDevice& device) {
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); 158 DCHECK_CURRENTLY_ON(BrowserThread::IO);
170 159
171 // Generate a new id for the session being opened. 160 // Generate a new id for the session being opened.
172 const media::VideoCaptureSessionId capture_session_id = 161 const media::VideoCaptureSessionId capture_session_id =
173 new_capture_session_id_++; 162 new_capture_session_id_++;
174 163
175 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); 164 DCHECK(sessions_.find(capture_session_id) == sessions_.end());
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 780
792 // Check if another session has already opened this device. If so, just 781 // Check if another session has already opened this device. If so, just
793 // use that opened device. 782 // use that opened device.
794 VideoCaptureController* const existing_device = 783 VideoCaptureController* const existing_device =
795 LookupControllerByMediaTypeAndDeviceId(device_info.type, device_info.id); 784 LookupControllerByMediaTypeAndDeviceId(device_info.type, device_info.id);
796 if (existing_device) { 785 if (existing_device) {
797 DCHECK_EQ(device_info.type, existing_device->stream_type()); 786 DCHECK_EQ(device_info.type, existing_device->stream_type());
798 return existing_device; 787 return existing_device;
799 } 788 }
800 789
801 VideoCaptureController* new_controller = new VideoCaptureController( 790 VideoCaptureController* new_controller =
802 device_info.id, device_info.type, params, 791 new VideoCaptureController(device_info.id, device_info.type, params,
803 base::MakeUnique<InProcessBuildableVideoCaptureDevice>( 792 video_capture_provider_->CreateBuildableDevice(
804 device_task_runner_, video_capture_system_.get())); 793 device_info.id, device_info.type));
805 controllers_.emplace_back(new_controller); 794 controllers_.emplace_back(new_controller);
806 return new_controller; 795 return new_controller;
807 } 796 }
808 797
809 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration( 798 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration(
810 const std::string& device_id) { 799 const std::string& device_id) {
811 media::VideoCaptureDeviceInfo* info = GetDeviceInfoById(device_id); 800 media::VideoCaptureDeviceInfo* info = GetDeviceInfoById(device_id);
812 if (!info) 801 if (!info)
813 return base::Optional<CameraCalibration>(); 802 return base::Optional<CameraCalibration>();
814 return info->descriptor.camera_calibration; 803 return info->descriptor.camera_calibration;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 // Session ID is only valid for Screen capture. So we can fake it to 855 // Session ID is only valid for Screen capture. So we can fake it to
867 // resume video capture devices here. 856 // resume video capture devices here.
868 QueueStartDevice(kFakeSessionId, controller.get(), 857 QueueStartDevice(kFakeSessionId, controller.get(),
869 controller->parameters()); 858 controller->parameters());
870 } 859 }
871 } 860 }
872 } 861 }
873 #endif // defined(OS_ANDROID) 862 #endif // defined(OS_ANDROID)
874 863
875 } // namespace content 864 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698