| 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/renderer_host/media/media_stream_manager.h" | 10 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void VideoCaptureHost::OnDestruct() const { | 63 void VideoCaptureHost::OnDestruct() const { |
| 64 BrowserThread::DeleteOnIOThread::Destruct(this); | 64 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 65 } | 65 } |
| 66 | 66 |
| 67 /////////////////////////////////////////////////////////////////////////////// | 67 /////////////////////////////////////////////////////////////////////////////// |
| 68 | 68 |
| 69 // Implements VideoCaptureControllerEventHandler. | 69 // Implements VideoCaptureControllerEventHandler. |
| 70 void VideoCaptureHost::OnError(const VideoCaptureControllerID& id) { | 70 void VideoCaptureHost::OnError(const VideoCaptureControllerID& id) { |
| 71 BrowserThread::PostTask( | 71 BrowserThread::PostTask( |
| 72 BrowserThread::IO, FROM_HERE, | 72 BrowserThread::IO, FROM_HERE, |
| 73 base::Bind(&VideoCaptureHost::DoHandleError, this, id.device_id)); | 73 base::Bind(&VideoCaptureHost::DoHandleErrorOnIOThread, |
| 74 this, id.device_id)); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void VideoCaptureHost::OnBufferCreated( | 77 void VideoCaptureHost::OnBufferCreated( |
| 77 const VideoCaptureControllerID& id, | 78 const VideoCaptureControllerID& id, |
| 78 base::SharedMemoryHandle handle, | 79 base::SharedMemoryHandle handle, |
| 79 int length, | 80 int length, |
| 80 int buffer_id) { | 81 int buffer_id) { |
| 81 BrowserThread::PostTask( | 82 BrowserThread::PostTask( |
| 82 BrowserThread::IO, FROM_HERE, | 83 BrowserThread::IO, FROM_HERE, |
| 83 base::Bind(&VideoCaptureHost::DoSendNewBuffer, | 84 base::Bind(&VideoCaptureHost::DoSendNewBufferOnIOThread, |
| 84 this, id.device_id, handle, length, buffer_id)); | 85 this, id.device_id, handle, length, buffer_id)); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void VideoCaptureHost::OnBufferReady( | 88 void VideoCaptureHost::OnBufferReady( |
| 88 const VideoCaptureControllerID& id, | 89 const VideoCaptureControllerID& id, |
| 89 int buffer_id, | 90 int buffer_id, |
| 90 base::Time timestamp) { | 91 base::Time timestamp) { |
| 91 BrowserThread::PostTask( | 92 BrowserThread::PostTask( |
| 92 BrowserThread::IO, FROM_HERE, | 93 BrowserThread::IO, FROM_HERE, |
| 93 base::Bind(&VideoCaptureHost::DoSendFilledBuffer, | 94 base::Bind(&VideoCaptureHost::DoSendFilledBufferOnIOThread, |
| 94 this, id.device_id, buffer_id, timestamp)); | 95 this, id.device_id, buffer_id, timestamp)); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void VideoCaptureHost::OnFrameInfo(const VideoCaptureControllerID& id, | 98 void VideoCaptureHost::OnFrameInfo(const VideoCaptureControllerID& id, |
| 98 int width, | 99 int width, |
| 99 int height, | 100 int height, |
| 100 int frame_per_second) { | 101 int frame_per_second) { |
| 101 BrowserThread::PostTask( | 102 BrowserThread::PostTask( |
| 102 BrowserThread::IO, FROM_HERE, | 103 BrowserThread::IO, FROM_HERE, |
| 103 base::Bind(&VideoCaptureHost::DoSendFrameInfo, | 104 base::Bind(&VideoCaptureHost::DoSendFrameInfoOnIOThread, |
| 104 this, id.device_id, width, height, frame_per_second)); | 105 this, id.device_id, width, height, frame_per_second)); |
| 105 } | 106 } |
| 106 | 107 |
| 108 void VideoCaptureHost::OnPaused(const VideoCaptureControllerID& id) { |
| 109 BrowserThread::PostTask( |
| 110 BrowserThread::IO, FROM_HERE, |
| 111 base::Bind(&VideoCaptureHost::DoPausedOnIOThread, this, id.device_id)); |
| 112 } |
| 113 |
| 107 void VideoCaptureHost::OnReadyToDelete(const VideoCaptureControllerID& id) { | 114 void VideoCaptureHost::OnReadyToDelete(const VideoCaptureControllerID& id) { |
| 108 BrowserThread::PostTask( | 115 BrowserThread::PostTask( |
| 109 BrowserThread::IO, FROM_HERE, | 116 BrowserThread::IO, FROM_HERE, |
| 110 base::Bind(&VideoCaptureHost::DoDeleteVideoCaptureController, this, id)); | 117 base::Bind(&VideoCaptureHost::DoDeleteVideoCaptureControllerOnIOThread, |
| 118 this, id)); |
| 111 } | 119 } |
| 112 | 120 |
| 113 void VideoCaptureHost::DoSendNewBuffer( | 121 void VideoCaptureHost::DoSendNewBufferOnIOThread( |
| 114 int device_id, base::SharedMemoryHandle handle, | 122 int device_id, base::SharedMemoryHandle handle, |
| 115 int length, int buffer_id) { | 123 int length, int buffer_id) { |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 117 | 125 |
| 118 Send(new VideoCaptureMsg_NewBuffer(device_id, handle, | 126 Send(new VideoCaptureMsg_NewBuffer(device_id, handle, |
| 119 length, buffer_id)); | 127 length, buffer_id)); |
| 120 } | 128 } |
| 121 | 129 |
| 122 void VideoCaptureHost::DoSendFilledBuffer( | 130 void VideoCaptureHost::DoSendFilledBufferOnIOThread( |
| 123 int device_id, int buffer_id, base::Time timestamp) { | 131 int device_id, int buffer_id, base::Time timestamp) { |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 125 | 133 |
| 126 Send(new VideoCaptureMsg_BufferReady(device_id, buffer_id, | 134 Send(new VideoCaptureMsg_BufferReady(device_id, buffer_id, |
| 127 timestamp)); | 135 timestamp)); |
| 128 } | 136 } |
| 129 | 137 |
| 130 void VideoCaptureHost::DoHandleError(int device_id) { | 138 void VideoCaptureHost::DoHandleErrorOnIOThread(int device_id) { |
| 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 132 | 140 |
| 133 VideoCaptureControllerID id(device_id); | 141 VideoCaptureControllerID id(device_id); |
| 134 EntryMap::iterator it = entries_.find(id); | 142 EntryMap::iterator it = entries_.find(id); |
| 135 if (it == entries_.end() || it->second->state == video_capture::kError) | 143 if (it == entries_.end() || it->second->state == video_capture::kError) |
| 136 return; | 144 return; |
| 137 | 145 |
| 138 it->second->state = video_capture::kError; | 146 it->second->state = video_capture::kError; |
| 139 Send(new VideoCaptureMsg_StateChanged(device_id, | 147 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 140 video_capture::kError)); | 148 video_capture::kError)); |
| 141 | 149 |
| 142 VideoCaptureController* controller = it->second->controller; | 150 VideoCaptureController* controller = it->second->controller; |
| 143 controller->StopCapture(id, this, false); | 151 controller->StopCapture(id, this, false); |
| 144 } | 152 } |
| 145 | 153 |
| 146 void VideoCaptureHost::DoSendFrameInfo(int device_id, | 154 void VideoCaptureHost::DoPausedOnIOThread(int device_id) { |
| 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 156 |
| 157 VideoCaptureControllerID id(device_id); |
| 158 EntryMap::iterator it = entries_.find(id); |
| 159 if (it == entries_.end() || it->second->state == video_capture::kPaused) |
| 160 return; |
| 161 |
| 162 it->second->state = video_capture::kPaused; |
| 163 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 164 video_capture::kPaused)); |
| 165 } |
| 166 |
| 167 void VideoCaptureHost::DoSendFrameInfoOnIOThread(int device_id, |
| 147 int width, | 168 int width, |
| 148 int height, | 169 int height, |
| 149 int frame_per_second) { | 170 int frame_per_second) { |
| 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 151 | 172 |
| 152 media::VideoCaptureParams params; | 173 media::VideoCaptureParams params; |
| 153 params.width = width; | 174 params.width = width; |
| 154 params.height = height; | 175 params.height = height; |
| 155 params.frame_per_second = frame_per_second; | 176 params.frame_per_second = frame_per_second; |
| 156 Send(new VideoCaptureMsg_DeviceInfo(device_id, params)); | 177 Send(new VideoCaptureMsg_DeviceInfo(device_id, params)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 video_capture::kError)); | 235 video_capture::kError)); |
| 215 return; | 236 return; |
| 216 } | 237 } |
| 217 | 238 |
| 218 Entry* entry = it->second; | 239 Entry* entry = it->second; |
| 219 entry->controller = controller; | 240 entry->controller = controller; |
| 220 if (entry->state == video_capture::kStarting) { | 241 if (entry->state == video_capture::kStarting) { |
| 221 entry->state = video_capture::kStarted; | 242 entry->state = video_capture::kStarted; |
| 222 controller->StartCapture(controller_id, this, peer_handle(), params); | 243 controller->StartCapture(controller_id, this, peer_handle(), params); |
| 223 } else if (entry->state == video_capture::kStopping) { | 244 } else if (entry->state == video_capture::kStopping) { |
| 224 DoDeleteVideoCaptureController(controller_id); | 245 DoDeleteVideoCaptureControllerOnIOThread(controller_id); |
| 225 } else { | 246 } else { |
| 226 NOTREACHED(); | 247 NOTREACHED(); |
| 227 } | 248 } |
| 228 } | 249 } |
| 229 | 250 |
| 230 void VideoCaptureHost::OnStopCapture(int device_id) { | 251 void VideoCaptureHost::OnStopCapture(int device_id) { |
| 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 232 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | 253 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; |
| 233 | 254 |
| 234 VideoCaptureControllerID controller_id(device_id); | 255 VideoCaptureControllerID controller_id(device_id); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 269 | 290 |
| 270 VideoCaptureControllerID controller_id(device_id); | 291 VideoCaptureControllerID controller_id(device_id); |
| 271 EntryMap::iterator it = entries_.find(controller_id); | 292 EntryMap::iterator it = entries_.find(controller_id); |
| 272 if (it != entries_.end()) { | 293 if (it != entries_.end()) { |
| 273 scoped_refptr<VideoCaptureController> controller = it->second->controller; | 294 scoped_refptr<VideoCaptureController> controller = it->second->controller; |
| 274 controller->ReturnBuffer(controller_id, this, buffer_id); | 295 controller->ReturnBuffer(controller_id, this, buffer_id); |
| 275 } | 296 } |
| 276 } | 297 } |
| 277 | 298 |
| 278 void VideoCaptureHost::DoDeleteVideoCaptureController( | 299 void VideoCaptureHost::DoDeleteVideoCaptureControllerOnIOThread( |
| 279 const VideoCaptureControllerID& id) { | 300 const VideoCaptureControllerID& id) { |
| 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 281 | 302 |
| 282 // Report that the device have successfully been stopped. | 303 // Report that the device have successfully been stopped. |
| 283 Send(new VideoCaptureMsg_StateChanged(id.device_id, | 304 Send(new VideoCaptureMsg_StateChanged(id.device_id, |
| 284 video_capture::kStopped)); | 305 video_capture::kStopped)); |
| 285 EntryMap::iterator it = entries_.find(id); | 306 EntryMap::iterator it = entries_.find(id); |
| 286 if (it != entries_.end()) { | 307 if (it != entries_.end()) { |
| 287 if (it->second->controller) { | 308 if (it->second->controller) { |
| 288 GetVideoCaptureManager()->RemoveController(it->second->controller, this); | 309 GetVideoCaptureManager()->RemoveController(it->second->controller, this); |
| 289 } | 310 } |
| 290 delete it->second; | 311 delete it->second; |
| 291 entries_.erase(id); | 312 entries_.erase(id); |
| 292 } | 313 } |
| 293 } | 314 } |
| 294 | 315 |
| 295 media_stream::VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { | 316 media_stream::VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { |
| 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 297 return media_stream::MediaStreamManager::GetForResourceContext( | 318 return media_stream::MediaStreamManager::GetForResourceContext( |
| 298 resource_context_, audio_manager_)->video_capture_manager(); | 319 resource_context_, audio_manager_)->video_capture_manager(); |
| 299 } | 320 } |
| OLD | NEW |