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_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/browser_main_loop.h" | 10 #include "content/browser/browser_main_loop.h" |
11 #include "content/browser/renderer_host/media/media_stream_manager.h" | 11 #include "content/browser/renderer_host/media/media_stream_manager.h" |
12 #include "content/browser/renderer_host/media/video_capture_manager.h" | 12 #include "content/browser/renderer_host/media/video_capture_manager.h" |
13 #include "content/common/media/video_capture_messages.h" | 13 #include "content/common/media/video_capture_messages.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 struct VideoCaptureHost::Entry { | 17 struct VideoCaptureHost::Entry { |
Ami GONE FROM CHROMIUM
2013/09/13 21:17:59
What's the point of this struct now?
(feels like
ncarter (slow)
2013/09/14 00:07:24
What was the point of it before?
The point of thi
| |
18 Entry(VideoCaptureController* controller) | 18 base::WeakPtr<VideoCaptureController> controller; |
19 : controller(controller) {} | |
20 | |
21 ~Entry() {} | |
22 | |
23 scoped_refptr<VideoCaptureController> controller; | |
24 }; | 19 }; |
25 | 20 |
26 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) | 21 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) |
27 : media_stream_manager_(media_stream_manager) { | 22 : media_stream_manager_(media_stream_manager) { |
28 } | 23 } |
29 | 24 |
30 VideoCaptureHost::~VideoCaptureHost() {} | 25 VideoCaptureHost::~VideoCaptureHost() {} |
31 | 26 |
32 void VideoCaptureHost::OnChannelClosing() { | 27 void VideoCaptureHost::OnChannelClosing() { |
33 BrowserMessageFilter::OnChannelClosing(); | 28 BrowserMessageFilter::OnChannelClosing(); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 DVLOG(1) << "VideoCaptureHost::OnStartCapture, device_id " << device_id | 210 DVLOG(1) << "VideoCaptureHost::OnStartCapture, device_id " << device_id |
216 << ", (" << params.width << ", " << params.height << ", " | 211 << ", (" << params.width << ", " << params.height << ", " |
217 << params.frame_rate << ", " << params.session_id | 212 << params.frame_rate << ", " << params.session_id |
218 << ", variable resolution device:" | 213 << ", variable resolution device:" |
219 << ((params.frame_size_type == | 214 << ((params.frame_size_type == |
220 media::VariableResolutionVideoCaptureDevice) ? "yes" : "no") | 215 media::VariableResolutionVideoCaptureDevice) ? "yes" : "no") |
221 << ")"; | 216 << ")"; |
222 VideoCaptureControllerID controller_id(device_id); | 217 VideoCaptureControllerID controller_id(device_id); |
223 DCHECK(entries_.find(controller_id) == entries_.end()); | 218 DCHECK(entries_.find(controller_id) == entries_.end()); |
224 | 219 |
225 entries_[controller_id] = new Entry(NULL); | 220 entries_[controller_id] = new Entry(); |
226 media_stream_manager_->video_capture_manager()->StartCaptureForClient( | 221 media_stream_manager_->video_capture_manager()->StartCaptureForClient( |
227 params, PeerHandle(), controller_id, this, base::Bind( | 222 params, PeerHandle(), controller_id, this, base::Bind( |
228 &VideoCaptureHost::OnControllerAdded, this, device_id, params)); | 223 &VideoCaptureHost::OnControllerAdded, this, device_id, params)); |
229 } | 224 } |
230 | 225 |
231 void VideoCaptureHost::OnControllerAdded( | 226 void VideoCaptureHost::OnControllerAdded( |
232 int device_id, const media::VideoCaptureParams& params, | 227 int device_id, const media::VideoCaptureParams& params, |
233 VideoCaptureController* controller) { | 228 base::WeakPtr<VideoCaptureController> controller) { |
234 BrowserThread::PostTask( | 229 BrowserThread::PostTask( |
235 BrowserThread::IO, FROM_HERE, | 230 BrowserThread::IO, FROM_HERE, |
236 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, | 231 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, |
237 this, device_id, params, make_scoped_refptr(controller))); | 232 this, device_id, params, controller)); |
238 } | 233 } |
239 | 234 |
240 void VideoCaptureHost::DoControllerAddedOnIOThread( | 235 void VideoCaptureHost::DoControllerAddedOnIOThread( |
241 int device_id, const media::VideoCaptureParams params, | 236 int device_id, const media::VideoCaptureParams params, |
242 VideoCaptureController* controller) { | 237 base::WeakPtr<VideoCaptureController> controller) { |
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
244 VideoCaptureControllerID controller_id(device_id); | 239 VideoCaptureControllerID controller_id(device_id); |
245 EntryMap::iterator it = entries_.find(controller_id); | 240 EntryMap::iterator it = entries_.find(controller_id); |
246 if (it == entries_.end()) { | 241 if (it == entries_.end()) { |
247 if (controller) { | 242 if (controller) { |
248 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 243 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
249 controller, controller_id, this); | 244 controller.get(), controller_id, this); |
250 } | 245 } |
251 return; | 246 return; |
252 } | 247 } |
253 | 248 |
254 if (controller == NULL) { | 249 if (!controller) { |
255 Send(new VideoCaptureMsg_StateChanged(device_id, | 250 Send(new VideoCaptureMsg_StateChanged(device_id, |
256 VIDEO_CAPTURE_STATE_ERROR)); | 251 VIDEO_CAPTURE_STATE_ERROR)); |
257 delete it->second; | 252 delete it->second; |
258 entries_.erase(controller_id); | 253 entries_.erase(controller_id); |
259 return; | 254 return; |
260 } | 255 } |
261 | 256 |
262 it->second->controller = controller; | 257 it->second->controller = controller; |
263 } | 258 } |
264 | 259 |
(...skipping 14 matching lines...) Expand all Loading... | |
279 // Not used. | 274 // Not used. |
280 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); | 275 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); |
281 } | 276 } |
282 | 277 |
283 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { | 278 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { |
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
285 | 280 |
286 VideoCaptureControllerID controller_id(device_id); | 281 VideoCaptureControllerID controller_id(device_id); |
287 EntryMap::iterator it = entries_.find(controller_id); | 282 EntryMap::iterator it = entries_.find(controller_id); |
288 if (it != entries_.end()) { | 283 if (it != entries_.end()) { |
289 scoped_refptr<VideoCaptureController> controller = it->second->controller; | 284 base::WeakPtr<VideoCaptureController> controller = it->second->controller; |
290 if (controller.get()) | 285 if (controller) |
291 controller->ReturnBuffer(controller_id, this, buffer_id); | 286 controller->ReturnBuffer(controller_id, this, buffer_id); |
292 } | 287 } |
293 } | 288 } |
294 | 289 |
295 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( | 290 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( |
296 const VideoCaptureControllerID& controller_id) { | 291 const VideoCaptureControllerID& controller_id) { |
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
298 | 293 |
299 EntryMap::iterator it = entries_.find(controller_id); | 294 EntryMap::iterator it = entries_.find(controller_id); |
300 if (it == entries_.end()) | 295 if (it == entries_.end()) |
301 return; | 296 return; |
302 | 297 |
303 VideoCaptureController* controller = it->second->controller.get(); | 298 if (it->second->controller) { |
304 if (controller) { | |
305 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 299 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
306 controller, controller_id, this); | 300 it->second->controller.get(), controller_id, this); |
307 } | 301 } |
308 delete it->second; | 302 delete it->second; |
309 entries_.erase(controller_id); | 303 entries_.erase(controller_id); |
310 } | 304 } |
311 | 305 |
312 } // namespace content | 306 } // namespace content |
OLD | NEW |