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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
14 #include "content/browser/renderer_host/media/video_capture_controller.h" | 14 #include "content/browser/renderer_host/media/video_capture_controller.h" |
15 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 15 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
16 #include "content/browser/renderer_host/media/web_contents_video_capture_device.
h" | 16 #include "content/browser/renderer_host/media/web_contents_video_capture_device.
h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/public/common/media_stream_request.h" | 19 #include "content/public/common/media_stream_request.h" |
| 20 #include "media/base/scoped_histogram_timer.h" |
20 #include "media/video/capture/fake_video_capture_device.h" | 21 #include "media/video/capture/fake_video_capture_device.h" |
21 #include "media/video/capture/video_capture_device.h" | 22 #include "media/video/capture/video_capture_device.h" |
22 | 23 |
23 #if defined(ENABLE_SCREEN_CAPTURE) | 24 #if defined(ENABLE_SCREEN_CAPTURE) |
24 #include "content/browser/renderer_host/media/screen_capture_device.h" | 25 #include "content/browser/renderer_host/media/screen_capture_device.h" |
25 #endif | 26 #endif |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 // Starting id for the first capture session. | 30 // Starting id for the first capture session. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 FROM_HERE, | 123 FROM_HERE, |
123 base::Bind(&VideoCaptureManager::OnStop, this, capture_session_id, | 124 base::Bind(&VideoCaptureManager::OnStop, this, capture_session_id, |
124 stopped_cb)); | 125 stopped_cb)); |
125 } | 126 } |
126 | 127 |
127 void VideoCaptureManager::UseFakeDevice() { | 128 void VideoCaptureManager::UseFakeDevice() { |
128 use_fake_device_ = true; | 129 use_fake_device_ = true; |
129 } | 130 } |
130 | 131 |
131 void VideoCaptureManager::OnEnumerateDevices(MediaStreamType stream_type) { | 132 void VideoCaptureManager::OnEnumerateDevices(MediaStreamType stream_type) { |
| 133 SCOPED_UMA_HISTOGRAM_TIMER( |
| 134 "Media.VideoCaptureManager.OnEnumerateDevicesTime"); |
132 DCHECK(IsOnDeviceThread()); | 135 DCHECK(IsOnDeviceThread()); |
133 | 136 |
134 media::VideoCaptureDevice::Names device_names; | 137 media::VideoCaptureDevice::Names device_names; |
135 GetAvailableDevices(stream_type, &device_names); | 138 GetAvailableDevices(stream_type, &device_names); |
136 | 139 |
137 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); | 140 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); |
138 for (media::VideoCaptureDevice::Names::iterator it = | 141 for (media::VideoCaptureDevice::Names::iterator it = |
139 device_names.begin(); it != device_names.end(); ++it) { | 142 device_names.begin(); it != device_names.end(); ++it) { |
140 bool opened = DeviceOpened(*it); | 143 bool opened = DeviceOpened(*it); |
141 devices->push_back(StreamDeviceInfo( | 144 devices->push_back(StreamDeviceInfo( |
142 stream_type, it->device_name, it->unique_id, opened)); | 145 stream_type, it->device_name, it->unique_id, opened)); |
143 } | 146 } |
144 | 147 |
145 PostOnDevicesEnumerated(stream_type, devices.Pass()); | 148 PostOnDevicesEnumerated(stream_type, devices.Pass()); |
146 } | 149 } |
147 | 150 |
148 void VideoCaptureManager::OnOpen(int capture_session_id, | 151 void VideoCaptureManager::OnOpen(int capture_session_id, |
149 const StreamDeviceInfo& device) { | 152 const StreamDeviceInfo& device) { |
| 153 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.OnOpenTime"); |
150 DCHECK(IsOnDeviceThread()); | 154 DCHECK(IsOnDeviceThread()); |
151 DCHECK(devices_.find(capture_session_id) == devices_.end()); | 155 DCHECK(devices_.find(capture_session_id) == devices_.end()); |
152 DVLOG(1) << "VideoCaptureManager::OnOpen, id " << capture_session_id; | 156 DVLOG(1) << "VideoCaptureManager::OnOpen, id " << capture_session_id; |
153 | 157 |
154 // Check if another session has already opened this device. If so, just | 158 // Check if another session has already opened this device. If so, just |
155 // use that opened device. | 159 // use that opened device. |
156 media::VideoCaptureDevice* video_capture_device = GetOpenedDevice(device); | 160 media::VideoCaptureDevice* video_capture_device = GetOpenedDevice(device); |
157 if (video_capture_device) { | 161 if (video_capture_device) { |
158 DeviceEntry& new_entry = devices_[capture_session_id]; | 162 DeviceEntry& new_entry = devices_[capture_session_id]; |
159 new_entry.stream_type = device.device.type; | 163 new_entry.stream_type = device.device.type; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return; | 207 return; |
204 } | 208 } |
205 | 209 |
206 DeviceEntry& new_entry = devices_[capture_session_id]; | 210 DeviceEntry& new_entry = devices_[capture_session_id]; |
207 new_entry.stream_type = device.device.type; | 211 new_entry.stream_type = device.device.type; |
208 new_entry.capture_device = video_capture_device; | 212 new_entry.capture_device = video_capture_device; |
209 PostOnOpened(device.device.type, capture_session_id); | 213 PostOnOpened(device.device.type, capture_session_id); |
210 } | 214 } |
211 | 215 |
212 void VideoCaptureManager::OnClose(int capture_session_id) { | 216 void VideoCaptureManager::OnClose(int capture_session_id) { |
| 217 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.OnCloseTime"); |
213 DCHECK(IsOnDeviceThread()); | 218 DCHECK(IsOnDeviceThread()); |
214 DVLOG(1) << "VideoCaptureManager::OnClose, id " << capture_session_id; | 219 DVLOG(1) << "VideoCaptureManager::OnClose, id " << capture_session_id; |
215 | 220 |
216 VideoCaptureDevices::iterator device_it = devices_.find(capture_session_id); | 221 VideoCaptureDevices::iterator device_it = devices_.find(capture_session_id); |
217 if (device_it == devices_.end()) { | 222 if (device_it == devices_.end()) { |
218 return; | 223 return; |
219 } | 224 } |
220 const DeviceEntry removed_entry = device_it->second; | 225 const DeviceEntry removed_entry = device_it->second; |
221 devices_.erase(device_it); | 226 devices_.erase(device_it); |
222 | 227 |
(...skipping 17 matching lines...) Expand all Loading... |
240 } | 245 } |
241 delete removed_entry.capture_device; | 246 delete removed_entry.capture_device; |
242 } | 247 } |
243 | 248 |
244 PostOnClosed(removed_entry.stream_type, capture_session_id); | 249 PostOnClosed(removed_entry.stream_type, capture_session_id); |
245 } | 250 } |
246 | 251 |
247 void VideoCaptureManager::OnStart( | 252 void VideoCaptureManager::OnStart( |
248 const media::VideoCaptureParams capture_params, | 253 const media::VideoCaptureParams capture_params, |
249 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { | 254 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { |
| 255 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.OnStartTime"); |
250 DCHECK(IsOnDeviceThread()); | 256 DCHECK(IsOnDeviceThread()); |
251 DCHECK(video_capture_receiver != NULL); | 257 DCHECK(video_capture_receiver != NULL); |
252 DVLOG(1) << "VideoCaptureManager::OnStart, (" << capture_params.width | 258 DVLOG(1) << "VideoCaptureManager::OnStart, (" << capture_params.width |
253 << ", " << capture_params.height | 259 << ", " << capture_params.height |
254 << ", " << capture_params.frame_per_second | 260 << ", " << capture_params.frame_per_second |
255 << ", " << capture_params.session_id | 261 << ", " << capture_params.session_id |
256 << ")"; | 262 << ")"; |
257 | 263 |
258 media::VideoCaptureDevice* video_capture_device = | 264 media::VideoCaptureDevice* video_capture_device = |
259 GetDeviceInternal(capture_params.session_id); | 265 GetDeviceInternal(capture_params.session_id); |
(...skipping 11 matching lines...) Expand all Loading... |
271 // video_capture_device. video_capture_receiver to perform actions. | 277 // video_capture_device. video_capture_receiver to perform actions. |
272 video_capture_device->Allocate(capture_params.width, capture_params.height, | 278 video_capture_device->Allocate(capture_params.width, capture_params.height, |
273 capture_params.frame_per_second, | 279 capture_params.frame_per_second, |
274 video_capture_receiver); | 280 video_capture_receiver); |
275 video_capture_device->Start(); | 281 video_capture_device->Start(); |
276 } | 282 } |
277 | 283 |
278 void VideoCaptureManager::OnStop( | 284 void VideoCaptureManager::OnStop( |
279 const media::VideoCaptureSessionId capture_session_id, | 285 const media::VideoCaptureSessionId capture_session_id, |
280 base::Closure stopped_cb) { | 286 base::Closure stopped_cb) { |
| 287 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.OnStopTime"); |
281 DCHECK(IsOnDeviceThread()); | 288 DCHECK(IsOnDeviceThread()); |
282 DVLOG(1) << "VideoCaptureManager::OnStop, id " << capture_session_id; | 289 DVLOG(1) << "VideoCaptureManager::OnStop, id " << capture_session_id; |
283 | 290 |
284 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); | 291 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); |
285 if (it != devices_.end()) { | 292 if (it != devices_.end()) { |
286 media::VideoCaptureDevice* video_capture_device = it->second.capture_device; | 293 media::VideoCaptureDevice* video_capture_device = it->second.capture_device; |
287 // Possible errors are signaled to video_capture_receiver by | 294 // Possible errors are signaled to video_capture_receiver by |
288 // video_capture_device. video_capture_receiver to perform actions. | 295 // video_capture_device. video_capture_receiver to perform actions. |
289 video_capture_device->Stop(); | 296 video_capture_device->Stop(); |
290 video_capture_device->DeAllocate(); | 297 video_capture_device->DeAllocate(); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 563 |
557 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); | 564 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); |
558 if (dit != devices_.end()) { | 565 if (dit != devices_.end()) { |
559 return dit->second.capture_device; | 566 return dit->second.capture_device; |
560 } | 567 } |
561 } | 568 } |
562 return NULL; | 569 return NULL; |
563 } | 570 } |
564 | 571 |
565 } // namespace content | 572 } // namespace content |
OLD | NEW |