0

use lock to make sure device will not deliver any frame after it's stopped.

BUG=139004
Review URL: https://chromiumcodereview.appspot.com/10905134

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155250 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
wjia@chromium.org
2012-09-06 21:29:33 +00:00
parent 65eb35ec05
commit a9b83a2f03
2 changed files with 12 additions and 2 deletions

@ -10,6 +10,7 @@
#include <string>
#include "base/compiler_specific.h"
#include "base/synchronization/lock.h"
#include "media/video/capture/video_capture_device.h"
#include "media/video/capture/video_capture_types.h"
@ -55,6 +56,7 @@ class VideoCaptureDeviceMac : public VideoCaptureDevice {
VideoCaptureDevice::Name device_name_;
VideoCaptureDevice::EventHandler* observer_;
InternalState state_;
base::Lock lock_;
VideoCaptureDeviceQTKit* capture_device_;

@ -49,6 +49,7 @@ VideoCaptureDeviceMac::~VideoCaptureDeviceMac() {
void VideoCaptureDeviceMac::Allocate(int width, int height, int frame_rate,
EventHandler* observer) {
base::AutoLock auto_lock(lock_);
if (state_ != kIdle) {
return;
}
@ -85,16 +86,19 @@ void VideoCaptureDeviceMac::Start() {
SetErrorState("Could not start capture device.");
return;
}
base::AutoLock auto_lock(lock_);
state_ = kCapturing;
}
void VideoCaptureDeviceMac::Stop() {
DCHECK_EQ(state_, kCapturing);
[capture_device_ stopCapture];
base::AutoLock auto_lock(lock_);
state_ = kAllocated;
}
void VideoCaptureDeviceMac::DeAllocate() {
base::AutoLock auto_lock(lock_);
if (state_ != kAllocated && state_ != kCapturing) {
return;
}
@ -134,12 +138,16 @@ void VideoCaptureDeviceMac::ReceiveFrame(
const uint8* video_frame,
int video_frame_length,
const VideoCaptureCapability& frame_info) {
observer_->OnIncomingCapturedFrame(video_frame, video_frame_length,
base::Time::Now());
base::AutoLock auto_lock(lock_);
if (state_ == kCapturing) {
observer_->OnIncomingCapturedFrame(video_frame, video_frame_length,
base::Time::Now());
}
}
void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) {
DLOG(ERROR) << reason;
base::AutoLock auto_lock(lock_);
state_ = kError;
observer_->OnError();
}