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::VideoCaptureCapability& capture_params, | 136 const media::VideoCaptureParams& 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(capture_params, device_client.Pass()); | 181 video_capture_device->AllocateAndStart(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, |
186 const media::VideoCaptureParams& params, | 187 const media::VideoCaptureParams& params, |
187 base::ProcessHandle client_render_process, | 188 base::ProcessHandle client_render_process, |
188 VideoCaptureControllerID client_id, | 189 VideoCaptureControllerID client_id, |
189 VideoCaptureControllerEventHandler* client_handler, | 190 VideoCaptureControllerEventHandler* client_handler, |
190 const DoneCB& done_cb) { | 191 const DoneCB& done_cb) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
192 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, (" | 193 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient, " |
193 << params.requested_format.width | 194 << params.requested_format.frame_size.ToString() << ", " |
194 << ", " << params.requested_format.height | 195 << params.requested_format.frame_rate << ", #" << session_id << ")"; |
195 << ", " << params.requested_format.frame_rate | |
196 << ", #" << params.session_id | |
197 << ")"; | |
198 | 196 |
199 DeviceEntry* entry = GetOrCreateDeviceEntry(params.session_id); | 197 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id); |
200 if (!entry) { | 198 if (!entry) { |
201 done_cb.Run(base::WeakPtr<VideoCaptureController>()); | 199 done_cb.Run(base::WeakPtr<VideoCaptureController>()); |
202 return; | 200 return; |
203 } | 201 } |
204 | 202 |
205 DCHECK(entry->video_capture_controller); | 203 DCHECK(entry->video_capture_controller); |
206 | 204 |
207 // First client starts the device. | 205 // First client starts the device. |
208 if (entry->video_capture_controller->GetClientCount() == 0) { | 206 if (entry->video_capture_controller->GetClientCount() == 0) { |
209 DVLOG(1) << "VideoCaptureManager starting device (type = " | 207 DVLOG(1) << "VideoCaptureManager starting device (type = " |
210 << entry->stream_type << ", id = " << entry->id << ")"; | 208 << entry->stream_type << ", id = " << entry->id << ")"; |
211 | 209 |
212 media::VideoCaptureCapability params_as_capability; | 210 device_loop_->PostTask( |
213 params_as_capability.width = params.requested_format.width; | 211 FROM_HERE, |
214 params_as_capability.height = params.requested_format.height; | 212 base::Bind( |
215 params_as_capability.frame_rate = params.requested_format.frame_rate; | 213 &VideoCaptureManager::DoStartDeviceOnDeviceThread, |
216 params_as_capability.frame_size_type = | 214 this, |
217 params.requested_format.frame_size_type; | 215 entry, |
218 | 216 params, |
219 device_loop_->PostTask(FROM_HERE, base::Bind( | 217 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
220 &VideoCaptureManager::DoStartDeviceOnDeviceThread, this, | |
221 entry, params_as_capability, | |
222 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | |
223 } | 218 } |
224 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 219 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
225 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); | 220 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); |
226 entry->video_capture_controller->AddClient(client_id, | 221 entry->video_capture_controller->AddClient( |
227 client_handler, | 222 client_id, client_handler, client_render_process, session_id, params); |
228 client_render_process, | |
229 params); | |
230 } | 223 } |
231 | 224 |
232 void VideoCaptureManager::StopCaptureForClient( | 225 void VideoCaptureManager::StopCaptureForClient( |
233 VideoCaptureController* controller, | 226 VideoCaptureController* controller, |
234 VideoCaptureControllerID client_id, | 227 VideoCaptureControllerID client_id, |
235 VideoCaptureControllerEventHandler* client_handler) { | 228 VideoCaptureControllerEventHandler* client_handler) { |
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
237 DCHECK(controller); | 230 DCHECK(controller); |
238 DCHECK(client_handler); | 231 DCHECK(client_handler); |
239 | 232 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 scoped_ptr<VideoCaptureController> video_capture_controller( | 407 scoped_ptr<VideoCaptureController> video_capture_controller( |
415 new VideoCaptureController()); | 408 new VideoCaptureController()); |
416 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 409 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
417 device_info.id, | 410 device_info.id, |
418 video_capture_controller.Pass()); | 411 video_capture_controller.Pass()); |
419 devices_.insert(new_device); | 412 devices_.insert(new_device); |
420 return new_device; | 413 return new_device; |
421 } | 414 } |
422 | 415 |
423 } // namespace content | 416 } // namespace content |
OLD | NEW |