| 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" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 BrowserThread::PostTask( | 112 BrowserThread::PostTask( |
| 113 BrowserThread::IO, FROM_HERE, | 113 BrowserThread::IO, FROM_HERE, |
| 114 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); | 114 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void VideoCaptureHost::DoSendNewBufferOnIOThread( | 117 void VideoCaptureHost::DoSendNewBufferOnIOThread( |
| 118 const VideoCaptureControllerID& controller_id, | 118 const VideoCaptureControllerID& controller_id, |
| 119 base::SharedMemoryHandle handle, | 119 base::SharedMemoryHandle handle, |
| 120 int length, | 120 int length, |
| 121 int buffer_id) { | 121 int buffer_id) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 122 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 123 | 123 |
| 124 if (entries_.find(controller_id) == entries_.end()) | 124 if (entries_.find(controller_id) == entries_.end()) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 Send(new VideoCaptureMsg_NewBuffer(controller_id.device_id, handle, | 127 Send(new VideoCaptureMsg_NewBuffer(controller_id.device_id, handle, |
| 128 length, buffer_id)); | 128 length, buffer_id)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void VideoCaptureHost::DoSendFreeBufferOnIOThread( | 131 void VideoCaptureHost::DoSendFreeBufferOnIOThread( |
| 132 const VideoCaptureControllerID& controller_id, | 132 const VideoCaptureControllerID& controller_id, |
| 133 int buffer_id) { | 133 int buffer_id) { |
| 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 134 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 135 | 135 |
| 136 if (entries_.find(controller_id) == entries_.end()) | 136 if (entries_.find(controller_id) == entries_.end()) |
| 137 return; | 137 return; |
| 138 | 138 |
| 139 Send(new VideoCaptureMsg_FreeBuffer(controller_id.device_id, buffer_id)); | 139 Send(new VideoCaptureMsg_FreeBuffer(controller_id.device_id, buffer_id)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void VideoCaptureHost::DoSendFilledBufferOnIOThread( | 142 void VideoCaptureHost::DoSendFilledBufferOnIOThread( |
| 143 const VideoCaptureControllerID& controller_id, | 143 const VideoCaptureControllerID& controller_id, |
| 144 int buffer_id, | 144 int buffer_id, |
| 145 const media::VideoCaptureFormat& format, | 145 const media::VideoCaptureFormat& format, |
| 146 base::TimeTicks timestamp) { | 146 base::TimeTicks timestamp) { |
| 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 148 | 148 |
| 149 if (entries_.find(controller_id) == entries_.end()) | 149 if (entries_.find(controller_id) == entries_.end()) |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 Send(new VideoCaptureMsg_BufferReady( | 152 Send(new VideoCaptureMsg_BufferReady( |
| 153 controller_id.device_id, buffer_id, format, timestamp)); | 153 controller_id.device_id, buffer_id, format, timestamp)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void VideoCaptureHost::DoSendFilledMailboxBufferOnIOThread( | 156 void VideoCaptureHost::DoSendFilledMailboxBufferOnIOThread( |
| 157 const VideoCaptureControllerID& controller_id, | 157 const VideoCaptureControllerID& controller_id, |
| 158 int buffer_id, | 158 int buffer_id, |
| 159 const gpu::MailboxHolder& mailbox_holder, | 159 const gpu::MailboxHolder& mailbox_holder, |
| 160 const media::VideoCaptureFormat& format, | 160 const media::VideoCaptureFormat& format, |
| 161 base::TimeTicks timestamp) { | 161 base::TimeTicks timestamp) { |
| 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 162 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 163 | 163 |
| 164 if (entries_.find(controller_id) == entries_.end()) | 164 if (entries_.find(controller_id) == entries_.end()) |
| 165 return; | 165 return; |
| 166 | 166 |
| 167 Send(new VideoCaptureMsg_MailboxBufferReady( | 167 Send(new VideoCaptureMsg_MailboxBufferReady( |
| 168 controller_id.device_id, buffer_id, mailbox_holder, format, timestamp)); | 168 controller_id.device_id, buffer_id, mailbox_holder, format, timestamp)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void VideoCaptureHost::DoHandleErrorOnIOThread( | 171 void VideoCaptureHost::DoHandleErrorOnIOThread( |
| 172 const VideoCaptureControllerID& controller_id) { | 172 const VideoCaptureControllerID& controller_id) { |
| 173 DCHECK(BrowserThread::CurrentlyOn(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 DeleteVideoCaptureControllerOnIOThread(controller_id); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void VideoCaptureHost::DoEndedOnIOThread( | 183 void VideoCaptureHost::DoEndedOnIOThread( |
| 184 const VideoCaptureControllerID& controller_id) { | 184 const VideoCaptureControllerID& controller_id) { |
| 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 185 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 186 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; | 186 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; |
| 187 if (entries_.find(controller_id) == entries_.end()) | 187 if (entries_.find(controller_id) == entries_.end()) |
| 188 return; | 188 return; |
| 189 | 189 |
| 190 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 190 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
| 191 VIDEO_CAPTURE_STATE_ENDED)); | 191 VIDEO_CAPTURE_STATE_ENDED)); |
| 192 DeleteVideoCaptureControllerOnIOThread(controller_id); | 192 DeleteVideoCaptureControllerOnIOThread(controller_id); |
| 193 } | 193 } |
| 194 | 194 |
| 195 /////////////////////////////////////////////////////////////////////////////// | 195 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 12 matching lines...) Expand all Loading... |
| 208 OnGetDeviceFormatsInUse) | 208 OnGetDeviceFormatsInUse) |
| 209 IPC_MESSAGE_UNHANDLED(handled = false) | 209 IPC_MESSAGE_UNHANDLED(handled = false) |
| 210 IPC_END_MESSAGE_MAP_EX() | 210 IPC_END_MESSAGE_MAP_EX() |
| 211 | 211 |
| 212 return handled; | 212 return handled; |
| 213 } | 213 } |
| 214 | 214 |
| 215 void VideoCaptureHost::OnStartCapture(int device_id, | 215 void VideoCaptureHost::OnStartCapture(int device_id, |
| 216 media::VideoCaptureSessionId session_id, | 216 media::VideoCaptureSessionId session_id, |
| 217 const media::VideoCaptureParams& params) { | 217 const media::VideoCaptureParams& params) { |
| 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 218 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 219 DVLOG(1) << "VideoCaptureHost::OnStartCapture:" | 219 DVLOG(1) << "VideoCaptureHost::OnStartCapture:" |
| 220 << " session_id=" << session_id | 220 << " session_id=" << session_id |
| 221 << ", device_id=" << device_id | 221 << ", device_id=" << device_id |
| 222 << ", format=" << params.requested_format.frame_size.ToString() | 222 << ", format=" << params.requested_format.frame_size.ToString() |
| 223 << "@" << params.requested_format.frame_rate | 223 << "@" << params.requested_format.frame_rate |
| 224 << " (" << (params.allow_resolution_change ? "variable" : "constant") | 224 << " (" << (params.allow_resolution_change ? "variable" : "constant") |
| 225 << ")"; | 225 << ")"; |
| 226 VideoCaptureControllerID controller_id(device_id); | 226 VideoCaptureControllerID controller_id(device_id); |
| 227 if (entries_.find(controller_id) != entries_.end()) { | 227 if (entries_.find(controller_id) != entries_.end()) { |
| 228 Send(new VideoCaptureMsg_StateChanged(device_id, | 228 Send(new VideoCaptureMsg_StateChanged(device_id, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 248 FROM_HERE, | 248 FROM_HERE, |
| 249 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, | 249 base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThread, |
| 250 this, | 250 this, |
| 251 device_id, | 251 device_id, |
| 252 controller)); | 252 controller)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void VideoCaptureHost::DoControllerAddedOnIOThread( | 255 void VideoCaptureHost::DoControllerAddedOnIOThread( |
| 256 int device_id, | 256 int device_id, |
| 257 const base::WeakPtr<VideoCaptureController>& controller) { | 257 const base::WeakPtr<VideoCaptureController>& controller) { |
| 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 258 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 259 VideoCaptureControllerID controller_id(device_id); | 259 VideoCaptureControllerID controller_id(device_id); |
| 260 EntryMap::iterator it = entries_.find(controller_id); | 260 EntryMap::iterator it = entries_.find(controller_id); |
| 261 if (it == entries_.end()) { | 261 if (it == entries_.end()) { |
| 262 if (controller) { | 262 if (controller) { |
| 263 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 263 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 264 controller.get(), controller_id, this); | 264 controller.get(), controller_id, this); |
| 265 } | 265 } |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 | 268 |
| 269 if (!controller) { | 269 if (!controller) { |
| 270 Send(new VideoCaptureMsg_StateChanged(device_id, | 270 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 271 VIDEO_CAPTURE_STATE_ERROR)); | 271 VIDEO_CAPTURE_STATE_ERROR)); |
| 272 entries_.erase(controller_id); | 272 entries_.erase(controller_id); |
| 273 return; | 273 return; |
| 274 } | 274 } |
| 275 | 275 |
| 276 DCHECK(!it->second); | 276 DCHECK(!it->second); |
| 277 it->second = controller; | 277 it->second = controller; |
| 278 } | 278 } |
| 279 | 279 |
| 280 void VideoCaptureHost::OnStopCapture(int device_id) { | 280 void VideoCaptureHost::OnStopCapture(int device_id) { |
| 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 281 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 282 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | 282 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; |
| 283 | 283 |
| 284 VideoCaptureControllerID controller_id(device_id); | 284 VideoCaptureControllerID controller_id(device_id); |
| 285 | 285 |
| 286 Send(new VideoCaptureMsg_StateChanged(device_id, | 286 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 287 VIDEO_CAPTURE_STATE_STOPPED)); | 287 VIDEO_CAPTURE_STATE_STOPPED)); |
| 288 DeleteVideoCaptureControllerOnIOThread(controller_id); | 288 DeleteVideoCaptureControllerOnIOThread(controller_id); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void VideoCaptureHost::OnPauseCapture(int device_id) { | 291 void VideoCaptureHost::OnPauseCapture(int device_id) { |
| 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 292 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 293 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; | 293 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; |
| 294 // Not used. | 294 // Not used. |
| 295 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); | 295 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, | 298 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, |
| 299 int buffer_id, | 299 int buffer_id, |
| 300 uint32 sync_point) { | 300 uint32 sync_point) { |
| 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 301 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 302 | 302 |
| 303 VideoCaptureControllerID controller_id(device_id); | 303 VideoCaptureControllerID controller_id(device_id); |
| 304 EntryMap::iterator it = entries_.find(controller_id); | 304 EntryMap::iterator it = entries_.find(controller_id); |
| 305 if (it != entries_.end()) { | 305 if (it != entries_.end()) { |
| 306 const base::WeakPtr<VideoCaptureController>& controller = it->second; | 306 const base::WeakPtr<VideoCaptureController>& controller = it->second; |
| 307 if (controller) | 307 if (controller) |
| 308 controller->ReturnBuffer(controller_id, this, buffer_id, sync_point); | 308 controller->ReturnBuffer(controller_id, this, buffer_id, sync_point); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 void VideoCaptureHost::OnGetDeviceSupportedFormats( | 312 void VideoCaptureHost::OnGetDeviceSupportedFormats( |
| 313 int device_id, | 313 int device_id, |
| 314 media::VideoCaptureSessionId capture_session_id) { | 314 media::VideoCaptureSessionId capture_session_id) { |
| 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 315 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 316 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormats, capture_session_id " | 316 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormats, capture_session_id " |
| 317 << capture_session_id; | 317 << capture_session_id; |
| 318 media::VideoCaptureFormats device_supported_formats; | 318 media::VideoCaptureFormats device_supported_formats; |
| 319 if (!media_stream_manager_->video_capture_manager() | 319 if (!media_stream_manager_->video_capture_manager() |
| 320 ->GetDeviceSupportedFormats(capture_session_id, | 320 ->GetDeviceSupportedFormats(capture_session_id, |
| 321 &device_supported_formats)) { | 321 &device_supported_formats)) { |
| 322 DLOG(WARNING) | 322 DLOG(WARNING) |
| 323 << "Could not retrieve device supported formats for device_id=" | 323 << "Could not retrieve device supported formats for device_id=" |
| 324 << device_id << " capture_session_id=" << capture_session_id; | 324 << device_id << " capture_session_id=" << capture_session_id; |
| 325 } | 325 } |
| 326 Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated( | 326 Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated( |
| 327 device_id, device_supported_formats)); | 327 device_id, device_supported_formats)); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void VideoCaptureHost::OnGetDeviceFormatsInUse( | 330 void VideoCaptureHost::OnGetDeviceFormatsInUse( |
| 331 int device_id, | 331 int device_id, |
| 332 media::VideoCaptureSessionId capture_session_id) { | 332 media::VideoCaptureSessionId capture_session_id) { |
| 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 333 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 334 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormatsInUse, capture_session_id " | 334 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormatsInUse, capture_session_id " |
| 335 << capture_session_id; | 335 << capture_session_id; |
| 336 media::VideoCaptureFormats formats_in_use; | 336 media::VideoCaptureFormats formats_in_use; |
| 337 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( | 337 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( |
| 338 capture_session_id, &formats_in_use)) { | 338 capture_session_id, &formats_in_use)) { |
| 339 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" | 339 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" |
| 340 << device_id << " capture_session_id=" << capture_session_id; | 340 << device_id << " capture_session_id=" << capture_session_id; |
| 341 } | 341 } |
| 342 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, | 342 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, |
| 343 formats_in_use)); | 343 formats_in_use)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( | 346 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( |
| 347 const VideoCaptureControllerID& controller_id) { | 347 const VideoCaptureControllerID& controller_id) { |
| 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 348 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 349 | 349 |
| 350 EntryMap::iterator it = entries_.find(controller_id); | 350 EntryMap::iterator it = entries_.find(controller_id); |
| 351 if (it == entries_.end()) | 351 if (it == entries_.end()) |
| 352 return; | 352 return; |
| 353 | 353 |
| 354 if (it->second) { | 354 if (it->second) { |
| 355 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 355 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 356 it->second.get(), controller_id, this); | 356 it->second.get(), controller_id, this); |
| 357 } | 357 } |
| 358 entries_.erase(it); | 358 entries_.erase(it); |
| 359 } | 359 } |
| 360 | 360 |
| 361 } // namespace content | 361 } // namespace content |
| OLD | NEW |