Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_device_impl.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_impl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
| 29 | 29 |
| 30 namespace content { | 30 namespace content { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 void DeleteCaptureMachineOnUIThread( | 34 void DeleteCaptureMachineOnUIThread( |
| 35 scoped_ptr<VideoCaptureMachine> capture_machine) { | 35 scoped_ptr<VideoCaptureMachine> capture_machine) { |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 37 if (capture_machine) { | 37 if (capture_machine) { |
| 38 capture_machine->Stop(); | |
| 39 capture_machine.reset(); | 38 capture_machine.reset(); |
| 40 } | 39 } |
| 41 } | 40 } |
| 42 | 41 |
| 43 } // namespace | 42 } // namespace |
| 44 | 43 |
| 45 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( | 44 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( |
| 46 scoped_ptr<media::VideoCaptureDevice::Client> client, | 45 scoped_ptr<media::VideoCaptureDevice::Client> client, |
| 47 scoped_ptr<VideoCaptureOracle> oracle, | 46 scoped_ptr<VideoCaptureOracle> oracle, |
| 48 const media::VideoCaptureParams& params) | 47 const media::VideoCaptureParams& params) |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 | 239 |
| 241 oracle_proxy_->Stop(); | 240 oracle_proxy_->Stop(); |
| 242 oracle_proxy_ = NULL; | 241 oracle_proxy_ = NULL; |
| 243 | 242 |
| 244 TransitionStateTo(kIdle); | 243 TransitionStateTo(kIdle); |
| 245 | 244 |
| 246 // Stops the capture machine asynchronously. | 245 // Stops the capture machine asynchronously. |
| 247 BrowserThread::PostTask( | 246 BrowserThread::PostTask( |
| 248 BrowserThread::UI, FROM_HERE, base::Bind( | 247 BrowserThread::UI, FROM_HERE, base::Bind( |
| 249 &VideoCaptureMachine::Stop, | 248 &VideoCaptureMachine::Stop, |
| 250 base::Unretained(capture_machine_.get()))); | 249 base::Unretained(capture_machine_.get()), |
| 250 base::Bind(&base::DoNothing))); | |
| 251 } | 251 } |
| 252 | 252 |
| 253 void VideoCaptureDeviceImpl::CaptureStarted(bool success) { | 253 void VideoCaptureDeviceImpl::CaptureStarted(bool success) { |
| 254 DCHECK(thread_checker_.CalledOnValidThread()); | 254 DCHECK(thread_checker_.CalledOnValidThread()); |
| 255 if (!success) { | 255 if (!success) { |
| 256 DVLOG(1) << "Failed to start capture machine."; | 256 DVLOG(1) << "Failed to start capture machine."; |
| 257 Error(); | 257 Error(); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 VideoCaptureDeviceImpl::VideoCaptureDeviceImpl( | 261 VideoCaptureDeviceImpl::VideoCaptureDeviceImpl( |
| 262 scoped_ptr<VideoCaptureMachine> capture_machine) | 262 scoped_ptr<VideoCaptureMachine> capture_machine) |
| 263 : state_(kIdle), | 263 : state_(kIdle), |
| 264 capture_machine_(capture_machine.Pass()) {} | 264 capture_machine_(capture_machine.Pass()) {} |
| 265 | 265 |
| 266 VideoCaptureDeviceImpl::~VideoCaptureDeviceImpl() { | 266 VideoCaptureDeviceImpl::~VideoCaptureDeviceImpl() { |
| 267 // If capture_machine is not NULL, then we need to return to the UI thread to | 267 // If capture_machine is not NULL, then we need to return to the UI thread to |
| 268 // safely stop the capture machine. | 268 // safely stop the capture machine. |
| 269 if (capture_machine_) { | 269 if (capture_machine_) { |
| 270 BrowserThread::PostTask( | 270 BrowserThread::PostTask( |
| 271 BrowserThread::UI, FROM_HERE, base::Bind( | 271 BrowserThread::UI, FROM_HERE, |
| 272 &DeleteCaptureMachineOnUIThread, base::Passed(&capture_machine_))); | 272 base::Bind(&VideoCaptureMachine::Stop, |
| 273 base::Unretained(capture_machine_.get()), | |
| 274 base::Bind(&DeleteCaptureMachineOnUIThread, | |
| 275 base::Passed(&capture_machine_)))); | |
|
imcheng
2014/01/09 01:15:17
Not sure if this is problematic here - will VideoC
Alpha Left Google
2014/01/09 01:37:07
when you call base::Bind(&DeleteCaptureMachineOnUI
imcheng
2014/01/09 23:31:09
Thanks for the explanation. I changed the code to
| |
| 273 } | 276 } |
| 274 DVLOG(1) << "VideoCaptureDeviceImpl@" << this << " destroying."; | 277 DVLOG(1) << "VideoCaptureDeviceImpl@" << this << " destroying."; |
| 275 } | 278 } |
| 276 | 279 |
| 277 void VideoCaptureDeviceImpl::TransitionStateTo(State next_state) { | 280 void VideoCaptureDeviceImpl::TransitionStateTo(State next_state) { |
| 278 DCHECK(thread_checker_.CalledOnValidThread()); | 281 DCHECK(thread_checker_.CalledOnValidThread()); |
| 279 | 282 |
| 280 #ifndef NDEBUG | 283 #ifndef NDEBUG |
| 281 static const char* kStateNames[] = { | 284 static const char* kStateNames[] = { |
| 282 "Idle", "Allocated", "Capturing", "Error" | 285 "Idle", "Allocated", "Capturing", "Error" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 295 return; | 298 return; |
| 296 | 299 |
| 297 if (oracle_proxy_) | 300 if (oracle_proxy_) |
| 298 oracle_proxy_->ReportError(); | 301 oracle_proxy_->ReportError(); |
| 299 | 302 |
| 300 StopAndDeAllocate(); | 303 StopAndDeAllocate(); |
| 301 TransitionStateTo(kError); | 304 TransitionStateTo(kError); |
| 302 } | 305 } |
| 303 | 306 |
| 304 } // namespace content | 307 } // namespace content |
| OLD | NEW |