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 |
mcasas
2014/04/25 17:18:35
ultra-nit: Remove empty line.
| |
181 DeleteVideoCaptureControllerOnIOThread(controller_id, true); | |
181 } | 182 } |
182 | 183 |
183 void VideoCaptureHost::DoEndedOnIOThread( | 184 void VideoCaptureHost::DoEndedOnIOThread( |
184 const VideoCaptureControllerID& controller_id) { | 185 const VideoCaptureControllerID& controller_id) { |
185 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 186 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
186 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; | 187 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; |
187 if (entries_.find(controller_id) == entries_.end()) | 188 if (entries_.find(controller_id) == entries_.end()) |
188 return; | 189 return; |
189 | 190 |
190 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 191 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
191 VIDEO_CAPTURE_STATE_ENDED)); | 192 VIDEO_CAPTURE_STATE_ENDED)); |
192 DeleteVideoCaptureControllerOnIOThread(controller_id); | 193 DeleteVideoCaptureControllerOnIOThread(controller_id, false); |
193 } | 194 } |
194 | 195 |
195 /////////////////////////////////////////////////////////////////////////////// | 196 /////////////////////////////////////////////////////////////////////////////// |
196 // IPC Messages handler. | 197 // IPC Messages handler. |
197 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, | 198 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, |
198 bool* message_was_ok) { | 199 bool* message_was_ok) { |
199 bool handled = true; | 200 bool handled = true; |
200 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) | 201 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) |
201 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) | 202 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) |
202 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) | 203 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 255 |
255 void VideoCaptureHost::DoControllerAddedOnIOThread( | 256 void VideoCaptureHost::DoControllerAddedOnIOThread( |
256 int device_id, | 257 int device_id, |
257 const base::WeakPtr<VideoCaptureController>& controller) { | 258 const base::WeakPtr<VideoCaptureController>& controller) { |
258 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 259 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
259 VideoCaptureControllerID controller_id(device_id); | 260 VideoCaptureControllerID controller_id(device_id); |
260 EntryMap::iterator it = entries_.find(controller_id); | 261 EntryMap::iterator it = entries_.find(controller_id); |
261 if (it == entries_.end()) { | 262 if (it == entries_.end()) { |
262 if (controller) { | 263 if (controller) { |
263 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 264 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
264 controller.get(), controller_id, this); | 265 controller.get(), controller_id, this, false); |
265 } | 266 } |
266 return; | 267 return; |
267 } | 268 } |
268 | 269 |
269 if (!controller) { | 270 if (!controller) { |
270 Send(new VideoCaptureMsg_StateChanged(device_id, | 271 Send(new VideoCaptureMsg_StateChanged(device_id, |
271 VIDEO_CAPTURE_STATE_ERROR)); | 272 VIDEO_CAPTURE_STATE_ERROR)); |
272 entries_.erase(controller_id); | 273 entries_.erase(controller_id); |
273 return; | 274 return; |
274 } | 275 } |
275 | 276 |
276 DCHECK(!it->second); | 277 DCHECK(!it->second); |
277 it->second = controller; | 278 it->second = controller; |
278 } | 279 } |
279 | 280 |
280 void VideoCaptureHost::OnStopCapture(int device_id) { | 281 void VideoCaptureHost::OnStopCapture(int device_id) { |
281 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 282 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
282 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | 283 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; |
283 | 284 |
284 VideoCaptureControllerID controller_id(device_id); | 285 VideoCaptureControllerID controller_id(device_id); |
285 | 286 |
286 Send(new VideoCaptureMsg_StateChanged(device_id, | 287 Send(new VideoCaptureMsg_StateChanged(device_id, |
287 VIDEO_CAPTURE_STATE_STOPPED)); | 288 VIDEO_CAPTURE_STATE_STOPPED)); |
288 DeleteVideoCaptureControllerOnIOThread(controller_id); | 289 DeleteVideoCaptureControllerOnIOThread(controller_id, false); |
289 } | 290 } |
290 | 291 |
291 void VideoCaptureHost::OnPauseCapture(int device_id) { | 292 void VideoCaptureHost::OnPauseCapture(int device_id) { |
292 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 293 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
293 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; | 294 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; |
294 // Not used. | 295 // Not used. |
295 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); | 296 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); |
296 } | 297 } |
297 | 298 |
298 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, | 299 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( | 338 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( |
338 capture_session_id, &formats_in_use)) { | 339 capture_session_id, &formats_in_use)) { |
339 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" | 340 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" |
340 << device_id << " capture_session_id=" << capture_session_id; | 341 << device_id << " capture_session_id=" << capture_session_id; |
341 } | 342 } |
342 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, | 343 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, |
343 formats_in_use)); | 344 formats_in_use)); |
344 } | 345 } |
345 | 346 |
346 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( | 347 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( |
347 const VideoCaptureControllerID& controller_id) { | 348 const VideoCaptureControllerID& controller_id, bool on_error) { |
348 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 349 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
349 | 350 |
350 EntryMap::iterator it = entries_.find(controller_id); | 351 EntryMap::iterator it = entries_.find(controller_id); |
351 if (it == entries_.end()) | 352 if (it == entries_.end()) |
352 return; | 353 return; |
353 | 354 |
354 if (it->second) { | 355 if (it->second) { |
355 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 356 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
356 it->second.get(), controller_id, this); | 357 it->second.get(), controller_id, this, on_error); |
357 } | 358 } |
358 entries_.erase(it); | 359 entries_.erase(it); |
359 } | 360 } |
360 | 361 |
361 } // namespace content | 362 } // namespace content |
OLD | NEW |