| 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 using content::BrowserMainLoop; | 15 namespace content { |
| 16 using content::BrowserMessageFilter; | |
| 17 using content::BrowserThread; | |
| 18 | 16 |
| 19 struct VideoCaptureHost::Entry { | 17 struct VideoCaptureHost::Entry { |
| 20 Entry(VideoCaptureController* controller) | 18 Entry(VideoCaptureController* controller) |
| 21 : controller(controller) {} | 19 : controller(controller) {} |
| 22 | 20 |
| 23 ~Entry() {} | 21 ~Entry() {} |
| 24 | 22 |
| 25 scoped_refptr<VideoCaptureController> controller; | 23 scoped_refptr<VideoCaptureController> controller; |
| 26 }; | 24 }; |
| 27 | 25 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 121 } |
| 124 | 122 |
| 125 void VideoCaptureHost::DoHandleErrorOnIOThread( | 123 void VideoCaptureHost::DoHandleErrorOnIOThread( |
| 126 const VideoCaptureControllerID& controller_id) { | 124 const VideoCaptureControllerID& controller_id) { |
| 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 128 | 126 |
| 129 if (entries_.find(controller_id) == entries_.end()) | 127 if (entries_.find(controller_id) == entries_.end()) |
| 130 return; | 128 return; |
| 131 | 129 |
| 132 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 130 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
| 133 video_capture::kError)); | 131 VIDEO_CAPTURE_STATE_ERROR)); |
| 134 DeleteVideoCaptureControllerOnIOThread(controller_id); | 132 DeleteVideoCaptureControllerOnIOThread(controller_id); |
| 135 } | 133 } |
| 136 | 134 |
| 137 void VideoCaptureHost::DoPausedOnIOThread( | 135 void VideoCaptureHost::DoPausedOnIOThread( |
| 138 const VideoCaptureControllerID& controller_id) { | 136 const VideoCaptureControllerID& controller_id) { |
| 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 140 | 138 |
| 141 if (entries_.find(controller_id) == entries_.end()) | 139 if (entries_.find(controller_id) == entries_.end()) |
| 142 return; | 140 return; |
| 143 | 141 |
| 144 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 142 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
| 145 video_capture::kPaused)); | 143 VIDEO_CAPTURE_STATE_PAUSED)); |
| 146 DeleteVideoCaptureControllerOnIOThread(controller_id); | 144 DeleteVideoCaptureControllerOnIOThread(controller_id); |
| 147 } | 145 } |
| 148 | 146 |
| 149 void VideoCaptureHost::DoSendFrameInfoOnIOThread( | 147 void VideoCaptureHost::DoSendFrameInfoOnIOThread( |
| 150 const VideoCaptureControllerID& controller_id, | 148 const VideoCaptureControllerID& controller_id, |
| 151 int width, int height, int frame_per_second) { | 149 int width, int height, int frame_per_second) { |
| 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 153 | 151 |
| 154 if (entries_.find(controller_id) == entries_.end()) | 152 if (entries_.find(controller_id) == entries_.end()) |
| 155 return; | 153 return; |
| 156 | 154 |
| 157 media::VideoCaptureParams params; | 155 media::VideoCaptureParams params; |
| 158 params.width = width; | 156 params.width = width; |
| 159 params.height = height; | 157 params.height = height; |
| 160 params.frame_per_second = frame_per_second; | 158 params.frame_per_second = frame_per_second; |
| 161 Send(new VideoCaptureMsg_DeviceInfo(controller_id.device_id, params)); | 159 Send(new VideoCaptureMsg_DeviceInfo(controller_id.device_id, params)); |
| 162 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 160 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
| 163 video_capture::kStarted)); | 161 VIDEO_CAPTURE_STATE_STARTED)); |
| 164 } | 162 } |
| 165 | 163 |
| 166 /////////////////////////////////////////////////////////////////////////////// | 164 /////////////////////////////////////////////////////////////////////////////// |
| 167 // IPC Messages handler. | 165 // IPC Messages handler. |
| 168 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, | 166 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, |
| 169 bool* message_was_ok) { | 167 bool* message_was_ok) { |
| 170 bool handled = true; | 168 bool handled = true; |
| 171 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) | 169 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) |
| 172 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) | 170 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) |
| 173 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) | 171 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 VideoCaptureControllerID controller_id(device_id); | 211 VideoCaptureControllerID controller_id(device_id); |
| 214 EntryMap::iterator it = entries_.find(controller_id); | 212 EntryMap::iterator it = entries_.find(controller_id); |
| 215 if (it == entries_.end()) { | 213 if (it == entries_.end()) { |
| 216 if (controller) | 214 if (controller) |
| 217 GetVideoCaptureManager()->RemoveController(controller, this); | 215 GetVideoCaptureManager()->RemoveController(controller, this); |
| 218 return; | 216 return; |
| 219 } | 217 } |
| 220 | 218 |
| 221 if (controller == NULL) { | 219 if (controller == NULL) { |
| 222 Send(new VideoCaptureMsg_StateChanged(device_id, | 220 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 223 video_capture::kError)); | 221 VIDEO_CAPTURE_STATE_ERROR)); |
| 224 delete it->second; | 222 delete it->second; |
| 225 entries_.erase(controller_id); | 223 entries_.erase(controller_id); |
| 226 return; | 224 return; |
| 227 } | 225 } |
| 228 | 226 |
| 229 it->second->controller = controller; | 227 it->second->controller = controller; |
| 230 controller->StartCapture(controller_id, this, peer_handle(), params); | 228 controller->StartCapture(controller_id, this, peer_handle(), params); |
| 231 } | 229 } |
| 232 | 230 |
| 233 void VideoCaptureHost::OnStopCapture(int device_id) { | 231 void VideoCaptureHost::OnStopCapture(int device_id) { |
| 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 235 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | 233 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; |
| 236 | 234 |
| 237 VideoCaptureControllerID controller_id(device_id); | 235 VideoCaptureControllerID controller_id(device_id); |
| 238 | 236 |
| 239 Send(new VideoCaptureMsg_StateChanged(device_id, | 237 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 240 video_capture::kStopped)); | 238 VIDEO_CAPTURE_STATE_STOPPED)); |
| 241 DeleteVideoCaptureControllerOnIOThread(controller_id); | 239 DeleteVideoCaptureControllerOnIOThread(controller_id); |
| 242 } | 240 } |
| 243 | 241 |
| 244 void VideoCaptureHost::OnPauseCapture(int device_id) { | 242 void VideoCaptureHost::OnPauseCapture(int device_id) { |
| 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 246 // Not used. | 244 // Not used. |
| 247 Send(new VideoCaptureMsg_StateChanged(device_id, | 245 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); |
| 248 video_capture::kError)); | |
| 249 } | 246 } |
| 250 | 247 |
| 251 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { | 248 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { |
| 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 253 | 250 |
| 254 VideoCaptureControllerID controller_id(device_id); | 251 VideoCaptureControllerID controller_id(device_id); |
| 255 EntryMap::iterator it = entries_.find(controller_id); | 252 EntryMap::iterator it = entries_.find(controller_id); |
| 256 if (it != entries_.end()) { | 253 if (it != entries_.end()) { |
| 257 scoped_refptr<VideoCaptureController> controller = it->second->controller; | 254 scoped_refptr<VideoCaptureController> controller = it->second->controller; |
| 258 if (controller) | 255 if (controller) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 270 | 267 |
| 271 VideoCaptureController* controller = it->second->controller; | 268 VideoCaptureController* controller = it->second->controller; |
| 272 if (controller) { | 269 if (controller) { |
| 273 controller->StopCapture(controller_id, this); | 270 controller->StopCapture(controller_id, this); |
| 274 GetVideoCaptureManager()->RemoveController(controller, this); | 271 GetVideoCaptureManager()->RemoveController(controller, this); |
| 275 } | 272 } |
| 276 delete it->second; | 273 delete it->second; |
| 277 entries_.erase(controller_id); | 274 entries_.erase(controller_id); |
| 278 } | 275 } |
| 279 | 276 |
| 280 media_stream::VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { | 277 VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { |
| 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 282 return BrowserMainLoop::GetMediaStreamManager()->video_capture_manager(); | 279 return BrowserMainLoop::GetMediaStreamManager()->video_capture_manager(); |
| 283 } | 280 } |
| 281 |
| 282 } // namespace content |
| OLD | NEW |