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 "content/browser/browser_main_loop.h" | 9 #include "content/browser/browser_main_loop.h" |
10 #include "content/browser/renderer_host/media/media_stream_manager.h" | 10 #include "content/browser/renderer_host/media/media_stream_manager.h" |
11 #include "content/browser/renderer_host/media/video_capture_manager.h" | 11 #include "content/browser/renderer_host/media/video_capture_manager.h" |
12 #include "content/common/media/video_capture_messages.h" | 12 #include "content/common/media/video_capture_messages.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) | 16 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) |
17 : BrowserMessageFilter(VideoCaptureMsgStart), | 17 : BrowserMessageFilter(VideoCaptureMsgStart), |
18 media_stream_manager_(media_stream_manager) { | 18 media_stream_manager_(media_stream_manager) { |
19 } | 19 } |
20 | 20 |
21 VideoCaptureHost::~VideoCaptureHost() {} | 21 VideoCaptureHost::~VideoCaptureHost() {} |
22 | 22 |
23 void VideoCaptureHost::OnChannelClosing() { | 23 void VideoCaptureHost::OnChannelClosing() { |
24 // Since the IPC channel is gone, close all requested VideoCaptureDevices. | 24 // Since the IPC channel is gone, close all requested VideoCaptureDevices. |
25 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) { | 25 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) { |
26 const base::WeakPtr<VideoCaptureController>& controller = it->second; | 26 const base::WeakPtr<VideoCaptureController>& controller = it->second; |
27 if (controller) { | 27 if (controller) { |
28 VideoCaptureControllerID controller_id(it->first); | 28 VideoCaptureControllerID controller_id(it->first); |
29 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 29 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
30 controller.get(), controller_id, this); | 30 controller.get(), controller_id, this, false); |
31 ++it; | 31 ++it; |
32 } else { | 32 } else { |
33 // Remove the entry for this controller_id so that when the controller | 33 // Remove the entry for this controller_id so that when the controller |
34 // is added, the controller will be notified to stop for this client | 34 // is added, the controller will be notified to stop for this client |
35 // in DoControllerAddedOnIOThread. | 35 // in DoControllerAddedOnIOThread. |
36 entries_.erase(it++); | 36 entries_.erase(it++); |
37 } | 37 } |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 void VideoCaptureHost::DoHandleErrorOnIOThread( | 171 void VideoCaptureHost::DoHandleErrorOnIOThread( |
172 const VideoCaptureControllerID& controller_id) { | 172 const VideoCaptureControllerID& controller_id) { |
173 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 173 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
174 | 174 |
175 if (entries_.find(controller_id) == entries_.end()) | 175 if (entries_.find(controller_id) == entries_.end()) |
176 return; | 176 return; |
177 | 177 |
178 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 178 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
179 VIDEO_CAPTURE_STATE_ERROR)); | 179 VIDEO_CAPTURE_STATE_ERROR)); |
180 DeleteVideoCaptureControllerOnIOThread(controller_id); | 180 DeleteVideoCaptureControllerOnIOThread(controller_id, true); |
181 } | 181 } |
182 | 182 |
183 void VideoCaptureHost::DoEndedOnIOThread( | 183 void VideoCaptureHost::DoEndedOnIOThread( |
184 const VideoCaptureControllerID& controller_id) { | 184 const VideoCaptureControllerID& controller_id) { |
185 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 185 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
186 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; | 186 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; |
187 if (entries_.find(controller_id) == entries_.end()) | 187 if (entries_.find(controller_id) == entries_.end()) |
188 return; | 188 return; |
189 | 189 |
190 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 190 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
191 VIDEO_CAPTURE_STATE_ENDED)); | 191 VIDEO_CAPTURE_STATE_ENDED)); |
192 DeleteVideoCaptureControllerOnIOThread(controller_id); | 192 DeleteVideoCaptureControllerOnIOThread(controller_id, false); |
193 } | 193 } |
194 | 194 |
195 /////////////////////////////////////////////////////////////////////////////// | 195 /////////////////////////////////////////////////////////////////////////////// |
196 // IPC Messages handler. | 196 // IPC Messages handler. |
197 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, | 197 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, |
198 bool* message_was_ok) { | 198 bool* message_was_ok) { |
199 bool handled = true; | 199 bool handled = true; |
200 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) | 200 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) |
201 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) | 201 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) |
202 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) | 202 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 254 |
255 void VideoCaptureHost::DoControllerAddedOnIOThread( | 255 void VideoCaptureHost::DoControllerAddedOnIOThread( |
256 int device_id, | 256 int device_id, |
257 const base::WeakPtr<VideoCaptureController>& controller) { | 257 const base::WeakPtr<VideoCaptureController>& controller) { |
258 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 258 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
259 VideoCaptureControllerID controller_id(device_id); | 259 VideoCaptureControllerID controller_id(device_id); |
260 EntryMap::iterator it = entries_.find(controller_id); | 260 EntryMap::iterator it = entries_.find(controller_id); |
261 if (it == entries_.end()) { | 261 if (it == entries_.end()) { |
262 if (controller) { | 262 if (controller) { |
263 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 263 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
264 controller.get(), controller_id, this); | 264 controller.get(), controller_id, this, false); |
265 } | 265 } |
266 return; | 266 return; |
267 } | 267 } |
268 | 268 |
269 if (!controller) { | 269 if (!controller) { |
270 Send(new VideoCaptureMsg_StateChanged(device_id, | 270 Send(new VideoCaptureMsg_StateChanged(device_id, |
271 VIDEO_CAPTURE_STATE_ERROR)); | 271 VIDEO_CAPTURE_STATE_ERROR)); |
272 entries_.erase(controller_id); | 272 entries_.erase(controller_id); |
273 return; | 273 return; |
274 } | 274 } |
275 | 275 |
276 DCHECK(!it->second); | 276 DCHECK(!it->second); |
277 it->second = controller; | 277 it->second = controller; |
278 } | 278 } |
279 | 279 |
280 void VideoCaptureHost::OnStopCapture(int device_id) { | 280 void VideoCaptureHost::OnStopCapture(int device_id) { |
281 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 281 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
282 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | 282 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; |
283 | 283 |
284 VideoCaptureControllerID controller_id(device_id); | 284 VideoCaptureControllerID controller_id(device_id); |
285 | 285 |
286 Send(new VideoCaptureMsg_StateChanged(device_id, | 286 Send(new VideoCaptureMsg_StateChanged(device_id, |
287 VIDEO_CAPTURE_STATE_STOPPED)); | 287 VIDEO_CAPTURE_STATE_STOPPED)); |
288 DeleteVideoCaptureControllerOnIOThread(controller_id); | 288 DeleteVideoCaptureControllerOnIOThread(controller_id, false); |
289 } | 289 } |
290 | 290 |
291 void VideoCaptureHost::OnPauseCapture(int device_id) { | 291 void VideoCaptureHost::OnPauseCapture(int device_id) { |
292 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 292 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
293 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; | 293 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; |
294 // Not used. | 294 // Not used. |
295 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); | 295 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); |
296 } | 296 } |
297 | 297 |
298 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, | 298 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( | 337 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( |
338 capture_session_id, &formats_in_use)) { | 338 capture_session_id, &formats_in_use)) { |
339 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" | 339 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" |
340 << device_id << " capture_session_id=" << capture_session_id; | 340 << device_id << " capture_session_id=" << capture_session_id; |
341 } | 341 } |
342 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, | 342 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, |
343 formats_in_use)); | 343 formats_in_use)); |
344 } | 344 } |
345 | 345 |
346 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( | 346 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( |
347 const VideoCaptureControllerID& controller_id) { | 347 const VideoCaptureControllerID& controller_id, bool on_error) { |
348 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 348 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
349 | 349 |
350 EntryMap::iterator it = entries_.find(controller_id); | 350 EntryMap::iterator it = entries_.find(controller_id); |
351 if (it == entries_.end()) | 351 if (it == entries_.end()) |
352 return; | 352 return; |
353 | 353 |
354 if (it->second) { | 354 if (it->second) { |
355 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 355 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
356 it->second.get(), controller_id, this); | 356 it->second.get(), controller_id, this, on_error); |
357 } | 357 } |
358 entries_.erase(it); | 358 entries_.erase(it); |
359 } | 359 } |
360 | 360 |
361 } // namespace content | 361 } // namespace content |
OLD | NEW |