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

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

Issue 7217018: Follow up patch on issue 7192007, containing mainly style fixes. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "content/browser/browser_thread.h" 8 #include "content/browser/browser_thread.h"
9 #include "media/video/capture/fake_video_capture_device.h" 9 #include "media/video/capture/fake_video_capture_device.h"
10 #include "media/video/capture/video_capture_device.h" 10 #include "media/video/capture/video_capture_device.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 vc_device_thread_.message_loop()->PostTask( 55 vc_device_thread_.message_loop()->PostTask(
56 FROM_HERE, 56 FROM_HERE,
57 NewRunnableMethod(this, 57 NewRunnableMethod(this,
58 &VideoCaptureManager::OnEnumerateDevices)); 58 &VideoCaptureManager::OnEnumerateDevices));
59 } 59 }
60 60
61 int VideoCaptureManager::Open(const StreamDeviceInfo& device) { 61 int VideoCaptureManager::Open(const StreamDeviceInfo& device) {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
63 DCHECK(listener_); 63 DCHECK(listener_);
64 64
65 // Generate a new id for this device 65 // Generate a new id for this device.
66 int video_capture_session_id = new_capture_session_id_++; 66 int video_capture_session_id = new_capture_session_id_++;
67 67
68 vc_device_thread_.message_loop()->PostTask( 68 vc_device_thread_.message_loop()->PostTask(
69 FROM_HERE, 69 FROM_HERE,
70 NewRunnableMethod(this, 70 NewRunnableMethod(this,
71 &VideoCaptureManager::OnOpen, 71 &VideoCaptureManager::OnOpen,
72 video_capture_session_id, 72 video_capture_session_id,
73 device)); 73 device));
74 74
75 return video_capture_session_id; 75 return video_capture_session_id;
(...skipping 17 matching lines...) Expand all
93 93
94 vc_device_thread_.message_loop()->PostTask( 94 vc_device_thread_.message_loop()->PostTask(
95 FROM_HERE, 95 FROM_HERE,
96 NewRunnableMethod(this, 96 NewRunnableMethod(this,
97 &VideoCaptureManager::OnStart, 97 &VideoCaptureManager::OnStart,
98 capture_params, 98 capture_params,
99 video_capture_receiver)); 99 video_capture_receiver));
100 } 100 }
101 101
102 void VideoCaptureManager::Stop( 102 void VideoCaptureManager::Stop(
103 const media::VideoCaptureSessionId capture_session_id, Task* stopped_task) { 103 const media::VideoCaptureSessionId& capture_session_id,
104 Task* stopped_task) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
105 106
106 vc_device_thread_.message_loop()->PostTask( 107 vc_device_thread_.message_loop()->PostTask(
107 FROM_HERE, 108 FROM_HERE,
108 NewRunnableMethod(this, 109 NewRunnableMethod(this,
109 &VideoCaptureManager::OnStop, 110 &VideoCaptureManager::OnStop,
110 capture_session_id, 111 capture_session_id,
111 stopped_task)); 112 stopped_task));
112 } 113 }
113 114
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DCHECK(IsOnCaptureDeviceThread()); 147 DCHECK(IsOnCaptureDeviceThread());
147 DCHECK(devices_.find(capture_session_id) == devices_.end()); 148 DCHECK(devices_.find(capture_session_id) == devices_.end());
148 149
149 // Check if another session has already opened this device, only one user per 150 // Check if another session has already opened this device, only one user per
150 // device is supported. 151 // device is supported.
151 if (DeviceOpened(device)) { 152 if (DeviceOpened(device)) {
152 PostOnError(capture_session_id, kDeviceAlreadyInUse); 153 PostOnError(capture_session_id, kDeviceAlreadyInUse);
153 return; 154 return;
154 } 155 }
155 156
156 // Open the device 157 // Open the device.
157 media::VideoCaptureDevice::Name vc_device_name; 158 media::VideoCaptureDevice::Name vc_device_name;
158 vc_device_name.device_name = device.name; 159 vc_device_name.device_name = device.name;
159 vc_device_name.unique_id = device.device_id; 160 vc_device_name.unique_id = device.device_id;
160 161
161 media::VideoCaptureDevice* video_capture_device = NULL; 162 media::VideoCaptureDevice* video_capture_device = NULL;
162 if (!use_fake_device_) { 163 if (!use_fake_device_) {
163 video_capture_device = media::VideoCaptureDevice::Create(vc_device_name); 164 video_capture_device = media::VideoCaptureDevice::Create(vc_device_name);
164 } else { 165 } else {
165 video_capture_device = 166 video_capture_device =
166 media::FakeVideoCaptureDevice::Create(vc_device_name); 167 media::FakeVideoCaptureDevice::Create(vc_device_name);
167 } 168 }
168 if (video_capture_device == NULL) { 169 if (!video_capture_device) {
169 PostOnError(capture_session_id, kDeviceNotAvailable); 170 PostOnError(capture_session_id, kDeviceNotAvailable);
170 return; 171 return;
171 } 172 }
172 173
173 devices_[capture_session_id] = video_capture_device; 174 devices_[capture_session_id] = video_capture_device;
174 PostOnOpened(capture_session_id); 175 PostOnOpened(capture_session_id);
175 } 176 }
176 177
177 void VideoCaptureManager::OnClose(int capture_session_id) { 178 void VideoCaptureManager::OnClose(int capture_session_id) {
178 DCHECK(IsOnCaptureDeviceThread()); 179 DCHECK(IsOnCaptureDeviceThread());
179 180
180 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); 181 VideoCaptureDevices::iterator it = devices_.find(capture_session_id);
181 if (it != devices_.end()) { 182 if (it != devices_.end()) {
182 // Deallocate (if not done already) and delete the device 183 // Deallocate (if not done already) and delete the device.
183 media::VideoCaptureDevice* video_capture_device = it->second; 184 media::VideoCaptureDevice* video_capture_device = it->second;
184 video_capture_device->DeAllocate(); 185 video_capture_device->DeAllocate();
185 delete video_capture_device; 186 delete video_capture_device;
186 devices_.erase(it); 187 devices_.erase(it);
187 } 188 }
188 189
189 PostOnClosed(capture_session_id); 190 PostOnClosed(capture_session_id);
190 } 191 }
191 192
192 void VideoCaptureManager::OnStart( 193 void VideoCaptureManager::OnStart(
193 const media::VideoCaptureParams capture_params, 194 const media::VideoCaptureParams capture_params,
194 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { 195 media::VideoCaptureDevice::EventHandler* video_capture_receiver) {
195 DCHECK(IsOnCaptureDeviceThread()); 196 DCHECK(IsOnCaptureDeviceThread());
196 DCHECK(video_capture_receiver != NULL); 197 DCHECK(video_capture_receiver != NULL);
197 198
198 // Solution for not using MediaStreamManager 199 // Solution for not using MediaStreamManager.
199 // This session id won't be returned by Open() 200 // This session id won't be returned by Open().
200 if (capture_params.session_id == kStartOpenSessionId) { 201 if (capture_params.session_id == kStartOpenSessionId) {
201 // Start() is called without using Open(), we need to open a device 202 // Start() is called without using Open(), we need to open a device.
202 media::VideoCaptureDevice::Names device_names; 203 media::VideoCaptureDevice::Names device_names;
203 GetAvailableDevices(&device_names); 204 GetAvailableDevices(&device_names);
204 if (device_names.empty()) { 205 if (device_names.empty()) {
205 // No devices available. 206 // No devices available.
206 video_capture_receiver->OnError(); 207 video_capture_receiver->OnError();
207 return; 208 return;
208 } 209 }
209 StreamDeviceInfo device(kVideoCapture, 210 StreamDeviceInfo device(kVideoCapture,
210 device_names.front().device_name, 211 device_names.front().device_name,
211 device_names.front().unique_id, false); 212 device_names.front().unique_id, false);
212 213
213 // Call OnOpen to open using the first device in the list 214 // Call OnOpen to open using the first device in the list.
214 OnOpen(capture_params.session_id, device); 215 OnOpen(capture_params.session_id, device);
215 } 216 }
216 217
217 VideoCaptureDevices::iterator it = devices_.find(capture_params.session_id); 218 VideoCaptureDevices::iterator it = devices_.find(capture_params.session_id);
218 if (it == devices_.end()) { 219 if (it == devices_.end()) {
219 // Invalid session id 220 // Invalid session id.
220 video_capture_receiver->OnError(); 221 video_capture_receiver->OnError();
221 return; 222 return;
222 } 223 }
223 media::VideoCaptureDevice* video_capture_device = it->second; 224 media::VideoCaptureDevice* video_capture_device = it->second;
224 225
225 // Possible errors are signaled to video_capture_receiver by 226 // Possible errors are signaled to video_capture_receiver by
226 // video_capture_device. video_capture_receiver to perform actions. 227 // video_capture_device. video_capture_receiver to perform actions.
227 video_capture_device->Allocate(capture_params.width, capture_params.height, 228 video_capture_device->Allocate(capture_params.width, capture_params.height,
228 capture_params.frame_per_second, 229 capture_params.frame_per_second,
229 video_capture_receiver); 230 video_capture_receiver);
(...skipping 20 matching lines...) Expand all
250 } 251 }
251 252
252 if (capture_session_id == kStartOpenSessionId) { 253 if (capture_session_id == kStartOpenSessionId) {
253 // This device was opened from Start(), not Open(). Close it! 254 // This device was opened from Start(), not Open(). Close it!
254 OnClose(capture_session_id); 255 OnClose(capture_session_id);
255 } 256 }
256 } 257 }
257 258
258 void VideoCaptureManager::OnOpened(int capture_session_id) { 259 void VideoCaptureManager::OnOpened(int capture_session_id) {
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
260 if (listener_ == NULL) { 261 if (!listener_) {
261 // Listener has been removed 262 // Listener has been removed.
262 return; 263 return;
263 } 264 }
264 listener_->Opened(kVideoCapture, capture_session_id); 265 listener_->Opened(kVideoCapture, capture_session_id);
265 } 266 }
266 267
267 void VideoCaptureManager::OnClosed(int capture_session_id) { 268 void VideoCaptureManager::OnClosed(int capture_session_id) {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
269 if (listener_ == NULL) { 270 if (!listener_) {
270 // Listener has been removed 271 // Listener has been removed.
271 return; 272 return;
272 } 273 }
273 listener_->Closed(kVideoCapture, capture_session_id); 274 listener_->Closed(kVideoCapture, capture_session_id);
274 } 275 }
275 276
276 void VideoCaptureManager::OnDevicesEnumerated( 277 void VideoCaptureManager::OnDevicesEnumerated(
277 const StreamDeviceInfoArray& devices) { 278 const StreamDeviceInfoArray& devices) {
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
279 if (!listener_) { 280 if (!listener_) {
280 // Listener has been removed 281 // Listener has been removed.
281 return; 282 return;
282 } 283 }
283 listener_->DevicesEnumerated(kVideoCapture, devices); 284 listener_->DevicesEnumerated(kVideoCapture, devices);
284 } 285 }
285 286
286 void VideoCaptureManager::OnError(int capture_session_id, 287 void VideoCaptureManager::OnError(int capture_session_id,
287 MediaStreamProviderError error) { 288 MediaStreamProviderError error) {
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
289 if (listener_ == NULL) { 290 if (!listener_) {
290 // Listener has been removed 291 // Listener has been removed.
291 return; 292 return;
292 } 293 }
293 listener_->Error(kVideoCapture, capture_session_id, error); 294 listener_->Error(kVideoCapture, capture_session_id, error);
294 } 295 }
295 296
296 void VideoCaptureManager::PostOnOpened(int capture_session_id) { 297 void VideoCaptureManager::PostOnOpened(int capture_session_id) {
297 DCHECK(IsOnCaptureDeviceThread()); 298 DCHECK(IsOnCaptureDeviceThread());
298 BrowserThread::PostTask(BrowserThread::IO, 299 BrowserThread::PostTask(BrowserThread::IO,
299 FROM_HERE, 300 FROM_HERE,
300 NewRunnableMethod(this, 301 NewRunnableMethod(this,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 for (VideoCaptureDevices::iterator it = devices_.begin(); 371 for (VideoCaptureDevices::iterator it = devices_.begin();
371 it != devices_.end(); 372 it != devices_.end();
372 it++) { 373 it++) {
373 if (device_info.device_id == it->second->device_name().unique_id) { 374 if (device_info.device_id == it->second->device_name().unique_id) {
374 return true; 375 return true;
375 } 376 }
376 } 377 }
377 return false; 378 return false;
378 } 379 }
379 380
380 } // namespace media 381 } // namespace media_stream
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.h ('k') | content/common/media/media_stream_options.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698