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