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 { |
18 Entry(VideoCaptureController* controller) | 18 Entry(VideoCaptureController* controller) |
19 : controller(controller) {} | 19 : controller(controller) {} |
20 | 20 |
21 ~Entry() {} | 21 ~Entry() {} |
22 | 22 |
23 scoped_refptr<VideoCaptureController> controller; | 23 scoped_refptr<VideoCaptureController> controller; |
24 }; | 24 }; |
25 | 25 |
26 VideoCaptureHost::VideoCaptureHost() {} | 26 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) |
| 27 : media_stream_manager_(media_stream_manager) { |
| 28 } |
27 | 29 |
28 VideoCaptureHost::~VideoCaptureHost() {} | 30 VideoCaptureHost::~VideoCaptureHost() {} |
29 | 31 |
30 void VideoCaptureHost::OnChannelClosing() { | 32 void VideoCaptureHost::OnChannelClosing() { |
31 BrowserMessageFilter::OnChannelClosing(); | 33 BrowserMessageFilter::OnChannelClosing(); |
32 | 34 |
33 // Since the IPC channel is gone, close all requested VideCaptureDevices. | 35 // Since the IPC channel is gone, close all requested VideCaptureDevices. |
34 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); it++) { | 36 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); it++) { |
35 VideoCaptureController* controller = it->second->controller.get(); | 37 VideoCaptureController* controller = it->second->controller.get(); |
36 if (controller) { | 38 if (controller) { |
37 VideoCaptureControllerID controller_id(it->first); | 39 VideoCaptureControllerID controller_id(it->first); |
38 controller->StopCapture(controller_id, this); | 40 controller->StopCapture(controller_id, this); |
39 GetVideoCaptureManager()->RemoveController(controller, this); | 41 media_stream_manager_->video_capture_manager()->RemoveController( |
| 42 controller, this); |
40 } | 43 } |
41 } | 44 } |
42 STLDeleteValues(&entries_); | 45 STLDeleteValues(&entries_); |
43 } | 46 } |
44 | 47 |
45 void VideoCaptureHost::OnDestruct() const { | 48 void VideoCaptureHost::OnDestruct() const { |
46 BrowserThread::DeleteOnIOThread::Destruct(this); | 49 BrowserThread::DeleteOnIOThread::Destruct(this); |
47 } | 50 } |
48 | 51 |
49 /////////////////////////////////////////////////////////////////////////////// | 52 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 DVLOG(1) << "VideoCaptureHost::OnStartCapture, device_id " << device_id | 188 DVLOG(1) << "VideoCaptureHost::OnStartCapture, device_id " << device_id |
186 << ", (" << params.width | 189 << ", (" << params.width |
187 << ", " << params.height | 190 << ", " << params.height |
188 << ", " << params.frame_per_second | 191 << ", " << params.frame_per_second |
189 << ", " << params.session_id | 192 << ", " << params.session_id |
190 << ")"; | 193 << ")"; |
191 VideoCaptureControllerID controller_id(device_id); | 194 VideoCaptureControllerID controller_id(device_id); |
192 DCHECK(entries_.find(controller_id) == entries_.end()); | 195 DCHECK(entries_.find(controller_id) == entries_.end()); |
193 | 196 |
194 entries_[controller_id] = new Entry(NULL); | 197 entries_[controller_id] = new Entry(NULL); |
195 GetVideoCaptureManager()->AddController( | 198 media_stream_manager_->video_capture_manager()->AddController( |
196 params, this, base::Bind(&VideoCaptureHost::OnControllerAdded, this, | 199 params, this, base::Bind(&VideoCaptureHost::OnControllerAdded, this, |
197 device_id, params)); | 200 device_id, params)); |
198 } | 201 } |
199 | 202 |
200 void VideoCaptureHost::OnControllerAdded( | 203 void VideoCaptureHost::OnControllerAdded( |
201 int device_id, const media::VideoCaptureParams& params, | 204 int device_id, const media::VideoCaptureParams& params, |
202 VideoCaptureController* controller) { | 205 VideoCaptureController* controller) { |
203 BrowserThread::PostTask( | 206 BrowserThread::PostTask( |
204 BrowserThread::IO, FROM_HERE, | 207 BrowserThread::IO, FROM_HERE, |
205 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, | 208 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, |
206 this, device_id, params, make_scoped_refptr(controller))); | 209 this, device_id, params, make_scoped_refptr(controller))); |
207 } | 210 } |
208 | 211 |
209 void VideoCaptureHost::DoControllerAddedOnIOThread( | 212 void VideoCaptureHost::DoControllerAddedOnIOThread( |
210 int device_id, const media::VideoCaptureParams params, | 213 int device_id, const media::VideoCaptureParams params, |
211 VideoCaptureController* controller) { | 214 VideoCaptureController* controller) { |
212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
213 VideoCaptureControllerID controller_id(device_id); | 216 VideoCaptureControllerID controller_id(device_id); |
214 EntryMap::iterator it = entries_.find(controller_id); | 217 EntryMap::iterator it = entries_.find(controller_id); |
215 if (it == entries_.end()) { | 218 if (it == entries_.end()) { |
216 if (controller) | 219 if (controller) { |
217 GetVideoCaptureManager()->RemoveController(controller, this); | 220 media_stream_manager_->video_capture_manager()->RemoveController( |
| 221 controller, this); |
| 222 } |
218 return; | 223 return; |
219 } | 224 } |
220 | 225 |
221 if (controller == NULL) { | 226 if (controller == NULL) { |
222 Send(new VideoCaptureMsg_StateChanged(device_id, | 227 Send(new VideoCaptureMsg_StateChanged(device_id, |
223 VIDEO_CAPTURE_STATE_ERROR)); | 228 VIDEO_CAPTURE_STATE_ERROR)); |
224 delete it->second; | 229 delete it->second; |
225 entries_.erase(controller_id); | 230 entries_.erase(controller_id); |
226 return; | 231 return; |
227 } | 232 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 const VideoCaptureControllerID& controller_id) { | 269 const VideoCaptureControllerID& controller_id) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
266 | 271 |
267 EntryMap::iterator it = entries_.find(controller_id); | 272 EntryMap::iterator it = entries_.find(controller_id); |
268 if (it == entries_.end()) | 273 if (it == entries_.end()) |
269 return; | 274 return; |
270 | 275 |
271 VideoCaptureController* controller = it->second->controller.get(); | 276 VideoCaptureController* controller = it->second->controller.get(); |
272 if (controller) { | 277 if (controller) { |
273 controller->StopCapture(controller_id, this); | 278 controller->StopCapture(controller_id, this); |
274 GetVideoCaptureManager()->RemoveController(controller, this); | 279 media_stream_manager_->video_capture_manager()->RemoveController( |
| 280 controller, this); |
275 } | 281 } |
276 delete it->second; | 282 delete it->second; |
277 entries_.erase(controller_id); | 283 entries_.erase(controller_id); |
278 } | 284 } |
279 | 285 |
280 VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { | |
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
282 return BrowserMainLoop::GetMediaStreamManager()->video_capture_manager(); | |
283 } | |
284 | |
285 } // namespace content | 286 } // namespace content |
OLD | NEW |