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" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 capture_session_id)); | 126 capture_session_id)); |
127 sessions_.erase(session_it); | 127 sessions_.erase(session_it); |
128 } | 128 } |
129 | 129 |
130 void VideoCaptureManager::UseFakeDevice() { | 130 void VideoCaptureManager::UseFakeDevice() { |
131 use_fake_device_ = true; | 131 use_fake_device_ = true; |
132 } | 132 } |
133 | 133 |
134 void VideoCaptureManager::DoStartDeviceOnDeviceThread( | 134 void VideoCaptureManager::DoStartDeviceOnDeviceThread( |
135 DeviceEntry* entry, | 135 DeviceEntry* entry, |
136 const media::VideoCaptureParams& params, | 136 const media::VideoCaptureCapability& capture_params, |
137 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { | 137 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { |
138 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 138 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
139 DCHECK(IsOnDeviceThread()); | 139 DCHECK(IsOnDeviceThread()); |
140 | 140 |
141 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 141 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
142 switch (entry->stream_type) { | 142 switch (entry->stream_type) { |
143 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 143 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
144 // We look up the device id from the renderer in our local enumeration | 144 // We look up the device id from the renderer in our local enumeration |
145 // since the renderer does not have all the information that might be | 145 // since the renderer does not have all the information that might be |
146 // held in the browser-side VideoCaptureDevice::Name structure. | 146 // held in the browser-side VideoCaptureDevice::Name structure. |
(...skipping 24 matching lines...) Expand all Loading... |
171 NOTIMPLEMENTED(); | 171 NOTIMPLEMENTED(); |
172 break; | 172 break; |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 if (!video_capture_device) { | 176 if (!video_capture_device) { |
177 device_client->OnError(); | 177 device_client->OnError(); |
178 return; | 178 return; |
179 } | 179 } |
180 | 180 |
181 video_capture_device->AllocateAndStart(params, device_client.Pass()); | 181 video_capture_device->AllocateAndStart(capture_params, device_client.Pass()); |
182 entry->video_capture_device = video_capture_device.Pass(); | 182 entry->video_capture_device = video_capture_device.Pass(); |
183 } | 183 } |
184 | 184 |
185 void VideoCaptureManager::StartCaptureForClient( | 185 void VideoCaptureManager::StartCaptureForClient( |
186 media::VideoCaptureSessionId session_id, | |
187 const media::VideoCaptureParams& params, | 186 const media::VideoCaptureParams& params, |
188 base::ProcessHandle client_render_process, | 187 base::ProcessHandle client_render_process, |
189 VideoCaptureControllerID client_id, | 188 VideoCaptureControllerID client_id, |
190 VideoCaptureControllerEventHandler* client_handler, | 189 VideoCaptureControllerEventHandler* client_handler, |
191 const DoneCB& done_cb) { | 190 const DoneCB& done_cb) { |
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
193 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, " | 192 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, (" |
194 << params.requested_format.frame_size.ToString() << ", " | 193 << params.requested_format.width |
195 << params.requested_format.frame_rate << ", #" << session_id << ")"; | 194 << ", " << params.requested_format.height |
| 195 << ", " << params.requested_format.frame_rate |
| 196 << ", #" << params.session_id |
| 197 << ")"; |
196 | 198 |
197 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id); | 199 DeviceEntry* entry = GetOrCreateDeviceEntry(params.session_id); |
198 if (!entry) { | 200 if (!entry) { |
199 done_cb.Run(base::WeakPtr<VideoCaptureController>()); | 201 done_cb.Run(base::WeakPtr<VideoCaptureController>()); |
200 return; | 202 return; |
201 } | 203 } |
202 | 204 |
203 DCHECK(entry->video_capture_controller); | 205 DCHECK(entry->video_capture_controller); |
204 | 206 |
205 // First client starts the device. | 207 // First client starts the device. |
206 if (entry->video_capture_controller->GetClientCount() == 0) { | 208 if (entry->video_capture_controller->GetClientCount() == 0) { |
207 DVLOG(1) << "VideoCaptureManager starting device (type = " | 209 DVLOG(1) << "VideoCaptureManager starting device (type = " |
208 << entry->stream_type << ", id = " << entry->id << ")"; | 210 << entry->stream_type << ", id = " << entry->id << ")"; |
209 | 211 |
210 device_loop_->PostTask( | 212 media::VideoCaptureCapability params_as_capability; |
211 FROM_HERE, | 213 params_as_capability.width = params.requested_format.width; |
212 base::Bind( | 214 params_as_capability.height = params.requested_format.height; |
213 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | 215 params_as_capability.frame_rate = params.requested_format.frame_rate; |
214 this, | 216 params_as_capability.frame_size_type = |
215 entry, | 217 params.requested_format.frame_size_type; |
216 params, | 218 |
217 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | 219 device_loop_->PostTask(FROM_HERE, base::Bind( |
| 220 &VideoCaptureManager::DoStartDeviceOnDeviceThread, this, |
| 221 entry, params_as_capability, |
| 222 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
218 } | 223 } |
219 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 224 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
220 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); | 225 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); |
221 entry->video_capture_controller->AddClient( | 226 entry->video_capture_controller->AddClient(client_id, |
222 client_id, client_handler, client_render_process, session_id, params); | 227 client_handler, |
| 228 client_render_process, |
| 229 params); |
223 } | 230 } |
224 | 231 |
225 void VideoCaptureManager::StopCaptureForClient( | 232 void VideoCaptureManager::StopCaptureForClient( |
226 VideoCaptureController* controller, | 233 VideoCaptureController* controller, |
227 VideoCaptureControllerID client_id, | 234 VideoCaptureControllerID client_id, |
228 VideoCaptureControllerEventHandler* client_handler) { | 235 VideoCaptureControllerEventHandler* client_handler) { |
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
230 DCHECK(controller); | 237 DCHECK(controller); |
231 DCHECK(client_handler); | 238 DCHECK(client_handler); |
232 | 239 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 scoped_ptr<VideoCaptureController> video_capture_controller( | 414 scoped_ptr<VideoCaptureController> video_capture_controller( |
408 new VideoCaptureController()); | 415 new VideoCaptureController()); |
409 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 416 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
410 device_info.id, | 417 device_info.id, |
411 video_capture_controller.Pass()); | 418 video_capture_controller.Pass()); |
412 devices_.insert(new_device); | 419 devices_.insert(new_device); |
413 return new_device; | 420 return new_device; |
414 } | 421 } |
415 | 422 |
416 } // namespace content | 423 } // namespace content |
OLD | NEW |