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_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/location.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/single_thread_task_runner.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
| 18 #include "base/thread_task_runner_handle.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
18 #include "content/browser/media/capture/web_contents_video_capture_device.h" | 20 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
19 #include "content/browser/media/media_internals.h" | 21 #include "content/browser/media/media_internals.h" |
20 #include "content/browser/renderer_host/media/video_capture_controller.h" | 22 #include "content/browser/renderer_host/media/video_capture_controller.h" |
21 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 23 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/desktop_media_id.h" | 25 #include "content/public/browser/desktop_media_id.h" |
24 #include "content/public/common/media_stream_request.h" | 26 #include "content/public/common/media_stream_request.h" |
25 #include "media/base/bind_to_current_loop.h" | 27 #include "media/base/bind_to_current_loop.h" |
26 #include "media/video/capture/video_capture_device.h" | 28 #include "media/video/capture/video_capture_device.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 219 |
218 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); | 220 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); |
219 DVLOG(1) << "VideoCaptureManager::Open, id " << capture_session_id; | 221 DVLOG(1) << "VideoCaptureManager::Open, id " << capture_session_id; |
220 | 222 |
221 // We just save the stream info for processing later. | 223 // We just save the stream info for processing later. |
222 sessions_[capture_session_id] = device_info.device; | 224 sessions_[capture_session_id] = device_info.device; |
223 | 225 |
224 // Notify our listener asynchronously; this ensures that we return | 226 // Notify our listener asynchronously; this ensures that we return |
225 // |capture_session_id| to the caller of this function before using that same | 227 // |capture_session_id| to the caller of this function before using that same |
226 // id in a listener event. | 228 // id in a listener event. |
227 base::MessageLoop::current()->PostTask(FROM_HERE, | 229 base::ThreadTaskRunnerHandle::Get()->PostTask( |
228 base::Bind(&VideoCaptureManager::OnOpened, this, | 230 FROM_HERE, base::Bind(&VideoCaptureManager::OnOpened, this, |
229 device_info.device.type, capture_session_id)); | 231 device_info.device.type, capture_session_id)); |
230 return capture_session_id; | 232 return capture_session_id; |
231 } | 233 } |
232 | 234 |
233 void VideoCaptureManager::Close(int capture_session_id) { | 235 void VideoCaptureManager::Close(int capture_session_id) { |
234 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 236 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
235 DCHECK(listener_); | 237 DCHECK(listener_); |
236 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id; | 238 DVLOG(1) << "VideoCaptureManager::Close, id " << capture_session_id; |
237 | 239 |
238 SessionMap::iterator session_it = sessions_.find(capture_session_id); | 240 SessionMap::iterator session_it = sessions_.find(capture_session_id); |
239 if (session_it == sessions_.end()) { | 241 if (session_it == sessions_.end()) { |
240 NOTREACHED(); | 242 NOTREACHED(); |
241 return; | 243 return; |
242 } | 244 } |
243 | 245 |
244 DeviceEntry* const existing_device = GetDeviceEntryForMediaStreamDevice( | 246 DeviceEntry* const existing_device = GetDeviceEntryForMediaStreamDevice( |
245 session_it->second); | 247 session_it->second); |
246 if (existing_device) { | 248 if (existing_device) { |
247 // Remove any client that is still using the session. This is safe to call | 249 // Remove any client that is still using the session. This is safe to call |
248 // even if there are no clients using the session. | 250 // even if there are no clients using the session. |
249 existing_device->video_capture_controller() | 251 existing_device->video_capture_controller() |
250 ->StopSession(capture_session_id); | 252 ->StopSession(capture_session_id); |
251 | 253 |
252 // StopSession() may have removed the last client, so we might need to | 254 // StopSession() may have removed the last client, so we might need to |
253 // close the device. | 255 // close the device. |
254 DestroyDeviceEntryIfNoClients(existing_device); | 256 DestroyDeviceEntryIfNoClients(existing_device); |
255 } | 257 } |
256 | 258 |
257 // Notify listeners asynchronously, and forget the session. | 259 // Notify listeners asynchronously, and forget the session. |
258 base::MessageLoop::current()->PostTask(FROM_HERE, | 260 base::ThreadTaskRunnerHandle::Get()->PostTask( |
259 base::Bind(&VideoCaptureManager::OnClosed, this, session_it->second.type, | 261 FROM_HERE, base::Bind(&VideoCaptureManager::OnClosed, this, |
260 capture_session_id)); | 262 session_it->second.type, capture_session_id)); |
261 sessions_.erase(session_it); | 263 sessions_.erase(session_it); |
262 } | 264 } |
263 | 265 |
264 void VideoCaptureManager::QueueStartDevice( | 266 void VideoCaptureManager::QueueStartDevice( |
265 media::VideoCaptureSessionId session_id, | 267 media::VideoCaptureSessionId session_id, |
266 DeviceEntry* entry, | 268 DeviceEntry* entry, |
267 const media::VideoCaptureParams& params) { | 269 const media::VideoCaptureParams& params) { |
268 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 270 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
269 device_start_queue_.push_back( | 271 device_start_queue_.push_back( |
270 CaptureDeviceStartRequest(entry->serial_id, session_id, params)); | 272 CaptureDeviceStartRequest(entry->serial_id, session_id, params)); |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 DCHECK(IsOnDeviceThread()); | 859 DCHECK(IsOnDeviceThread()); |
858 #if defined(ENABLE_SCREEN_CAPTURE) | 860 #if defined(ENABLE_SCREEN_CAPTURE) |
859 DesktopCaptureDevice* desktop_device = | 861 DesktopCaptureDevice* desktop_device = |
860 static_cast<DesktopCaptureDevice*>(device); | 862 static_cast<DesktopCaptureDevice*>(device); |
861 desktop_device->SetNotificationWindowId(window_id); | 863 desktop_device->SetNotificationWindowId(window_id); |
862 VLOG(2) << "Screen capture notification window passed on device thread."; | 864 VLOG(2) << "Screen capture notification window passed on device thread."; |
863 #endif | 865 #endif |
864 } | 866 } |
865 | 867 |
866 } // namespace content | 868 } // namespace content |
OLD | NEW |