summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-03 01:32:32 +0000
committerjiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-03 01:32:32 +0000
commit766a13ffafa1dc641ef36de99de54ad458521cf2 (patch)
tree30883943709107bdc6197d947c5577e3b5c12054
parentfd2b2a506f91490c4739f62949f95185abf9dc43 (diff)
downloadchromium_src-766a13ffafa1dc641ef36de99de54ad458521cf2.zip
chromium_src-766a13ffafa1dc641ef36de99de54ad458521cf2.tar.gz
chromium_src-766a13ffafa1dc641ef36de99de54ad458521cf2.tar.bz2
Removes VideoCaptureDevice1 from all platforms.
BUG=297857, 297849, 297850 Review URL: https://codereview.chromium.org/25637002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226656 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/video/capture/android/video_capture_device_android.cc58
-rw-r--r--media/video/capture/android/video_capture_device_android.h15
-rw-r--r--media/video/capture/fake_video_capture_device.cc50
-rw-r--r--media/video/capture/fake_video_capture_device.h20
-rw-r--r--media/video/capture/mac/video_capture_device_mac.h15
-rw-r--r--media/video/capture/mac/video_capture_device_mac.mm36
-rw-r--r--media/video/capture/video_capture_device.cc19
-rw-r--r--media/video/capture/video_capture_device.h52
-rw-r--r--media/video/capture/win/video_capture_device_mf_win.cc53
-rw-r--r--media/video/capture/win/video_capture_device_mf_win.h14
-rw-r--r--media/video/capture/win/video_capture_device_win.cc38
-rw-r--r--media/video/capture/win/video_capture_device_win.h15
12 files changed, 86 insertions, 299 deletions
diff --git a/media/video/capture/android/video_capture_device_android.cc b/media/video/capture/android/video_capture_device_android.cc
index 43ff392..5a72b52 100644
--- a/media/video/capture/android/video_capture_device_android.cc
+++ b/media/video/capture/android/video_capture_device_android.cc
@@ -82,13 +82,12 @@ bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) {
VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid(const Name& device_name)
: state_(kIdle),
got_first_frame_(false),
- client_(NULL),
device_name_(device_name),
current_settings_() {
}
VideoCaptureDeviceAndroid::~VideoCaptureDeviceAndroid() {
- DeAllocate();
+ StopAndDeAllocate();
}
bool VideoCaptureDeviceAndroid::Init() {
@@ -105,19 +104,16 @@ bool VideoCaptureDeviceAndroid::Init() {
return true;
}
-const VideoCaptureDevice::Name& VideoCaptureDeviceAndroid::device_name() {
- return device_name_;
-}
-
-void VideoCaptureDeviceAndroid::Allocate(
+void VideoCaptureDeviceAndroid::AllocateAndStart(
const VideoCaptureCapability& capture_format,
- Client* client) {
+ scoped_ptr<Client> client) {
+ DVLOG(1) << "VideoCaptureDeviceAndroid::AllocateAndStart";
{
base::AutoLock lock(lock_);
if (state_ != kIdle)
return;
- client_ = client;
- state_ = kAllocated;
+ client_ = client.Pass();
+ got_first_frame_ = false;
}
JNIEnv* env = AttachCurrentThread();
@@ -158,20 +154,9 @@ void VideoCaptureDeviceAndroid::Allocate(
<< current_settings_.frame_rate;
// Report the frame size to the client.
client_->OnFrameInfo(current_settings_);
-}
-
-void VideoCaptureDeviceAndroid::Start() {
- DVLOG(1) << "VideoCaptureDeviceAndroid::Start";
- {
- base::AutoLock lock(lock_);
- got_first_frame_ = false;
- DCHECK_EQ(state_, kAllocated);
- }
- JNIEnv* env = AttachCurrentThread();
-
- jint ret = Java_VideoCapture_startCapture(env, j_capture_.obj());
- if (ret < 0) {
+ jint result = Java_VideoCapture_startCapture(env, j_capture_.obj());
+ if (result < 0) {
SetErrorState("failed to start capture");
return;
}
@@ -182,14 +167,12 @@ void VideoCaptureDeviceAndroid::Start() {
}
}
-void VideoCaptureDeviceAndroid::Stop() {
- DVLOG(1) << "VideoCaptureDeviceAndroid::Stop";
+void VideoCaptureDeviceAndroid::StopAndDeAllocate() {
+ DVLOG(1) << "VideoCaptureDeviceAndroid::StopAndDeAllocate";
{
base::AutoLock lock(lock_);
if (state_ != kCapturing && state_ != kError)
return;
- if (state_ == kCapturing)
- state_ = kAllocated;
}
JNIEnv* env = AttachCurrentThread();
@@ -199,28 +182,13 @@ void VideoCaptureDeviceAndroid::Stop() {
SetErrorState("failed to stop capture");
return;
}
-}
-void VideoCaptureDeviceAndroid::DeAllocate() {
- DVLOG(1) << "VideoCaptureDeviceAndroid::DeAllocate";
{
base::AutoLock lock(lock_);
- if (state_ == kIdle)
- return;
-
- if (state_ == kCapturing) {
- base::AutoUnlock unlock(lock_);
- Stop();
- }
-
- if (state_ == kAllocated)
- state_ = kIdle;
-
- client_ = NULL;
+ state_ = kIdle;
+ client_.reset();
}
- JNIEnv* env = AttachCurrentThread();
-
Java_VideoCapture_deallocate(env, j_capture_.obj());
}
@@ -235,7 +203,7 @@ void VideoCaptureDeviceAndroid::OnFrameAvailable(
DVLOG(3) << "VideoCaptureDeviceAndroid::OnFrameAvailable: length =" << length;
base::AutoLock lock(lock_);
- if (state_ != kCapturing || !client_)
+ if (state_ != kCapturing || !client_.get())
return;
jbyte* buffer = env->GetByteArrayElements(data, NULL);
diff --git a/media/video/capture/android/video_capture_device_android.h b/media/video/capture/android/video_capture_device_android.h
index 2573b45..c9ab5d7 100644
--- a/media/video/capture/android/video_capture_device_android.h
+++ b/media/video/capture/android/video_capture_device_android.h
@@ -21,7 +21,7 @@ namespace media {
// by VideoCaptureManager on its own thread, while OnFrameAvailable is called
// on JAVA thread (i.e., UI thread). Both will access |state_| and |client_|,
// but only VideoCaptureManager would change their value.
-class MEDIA_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice1 {
+class MEDIA_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice {
public:
virtual ~VideoCaptureDeviceAndroid();
@@ -29,12 +29,10 @@ class MEDIA_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice1 {
static bool RegisterVideoCaptureDevice(JNIEnv* env);
// VideoCaptureDevice implementation.
- virtual void Allocate(const VideoCaptureCapability& capture_format,
- Client* client) OVERRIDE;
- virtual void Start() OVERRIDE;
- virtual void Stop() OVERRIDE;
- virtual void DeAllocate() OVERRIDE;
- virtual const Name& device_name() OVERRIDE;
+ virtual void AllocateAndStart(
+ const VideoCaptureCapability& capture_format,
+ scoped_ptr<Client> client) OVERRIDE;
+ virtual void StopAndDeAllocate() OVERRIDE;
// Implement org.chromium.media.VideoCapture.nativeOnFrameAvailable.
void OnFrameAvailable(
@@ -49,7 +47,6 @@ class MEDIA_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice1 {
private:
enum InternalState {
kIdle, // The device is opened but not in use.
- kAllocated, // All resouces have been allocated and camera can be started.
kCapturing, // Video is being captured.
kError // Hit error. User needs to recover by destroying the object.
};
@@ -73,7 +70,7 @@ class MEDIA_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice1 {
bool got_first_frame_;
base::TimeTicks expected_next_frame_time_;
base::TimeDelta frame_interval_;
- VideoCaptureDevice::Client* client_;
+ scoped_ptr<VideoCaptureDevice::Client> client_;
Name device_name_;
VideoCaptureCapability current_settings_;
diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc
index 21bdc35..8e32651 100644
--- a/media/video/capture/fake_video_capture_device.cc
+++ b/media/video/capture/fake_video_capture_device.cc
@@ -42,7 +42,7 @@ VideoCaptureDevice* FakeVideoCaptureDevice::Create(const Name& device_name) {
for (int n = 0; n < kNumberOfFakeDevices; ++n) {
std::string possible_id = base::StringPrintf("/dev/video%d", n);
if (device_name.id().compare(possible_id) == 0) {
- return new FakeVideoCaptureDevice(device_name);
+ return new FakeVideoCaptureDevice();
}
}
return NULL;
@@ -52,10 +52,8 @@ void FakeVideoCaptureDevice::SetFailNextCreate() {
fail_next_create_ = true;
}
-FakeVideoCaptureDevice::FakeVideoCaptureDevice(const Name& device_name)
- : device_name_(device_name),
- client_(NULL),
- state_(kIdle),
+FakeVideoCaptureDevice::FakeVideoCaptureDevice()
+ : state_(kIdle),
capture_thread_("CaptureThread"),
frame_count_(0),
capabilities_roster_index_(0) {
@@ -67,9 +65,9 @@ FakeVideoCaptureDevice::~FakeVideoCaptureDevice() {
DCHECK(!capture_thread_.IsRunning());
}
-void FakeVideoCaptureDevice::Allocate(
+void FakeVideoCaptureDevice::AllocateAndStart(
const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) {
+ scoped_ptr<VideoCaptureDevice::Client> client) {
capture_format_.frame_size_type = capture_format.frame_size_type;
if (capture_format.frame_size_type == VariableResolutionVideoCaptureDevice)
PopulateCapabilitiesRoster();
@@ -78,7 +76,7 @@ void FakeVideoCaptureDevice::Allocate(
return; // Wrong state.
}
- client_ = client;
+ client_ = client.Pass();
capture_format_.color = PIXEL_FORMAT_I420;
capture_format_.expected_capture_delay = 0;
capture_format_.interlaced = false;
@@ -97,8 +95,14 @@ void FakeVideoCaptureDevice::Allocate(
gfx::Size(capture_format_.width, capture_format_.height));
fake_frame_.reset(new uint8[fake_frame_size]);
- state_ = kAllocated;
client_->OnFrameInfo(capture_format_);
+
+ state_ = kCapturing;
+ capture_thread_.Start();
+ capture_thread_.message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeVideoCaptureDevice::OnCaptureTask,
+ base::Unretained(this)));
}
void FakeVideoCaptureDevice::Reallocate() {
@@ -117,38 +121,14 @@ void FakeVideoCaptureDevice::Reallocate() {
client_->OnFrameInfoChanged(capture_format_);
}
-void FakeVideoCaptureDevice::Start() {
- if (state_ != kAllocated) {
- return; // Wrong state.
- }
- state_ = kCapturing;
- capture_thread_.Start();
- capture_thread_.message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&FakeVideoCaptureDevice::OnCaptureTask,
- base::Unretained(this)));
-}
-
-void FakeVideoCaptureDevice::Stop() {
+void FakeVideoCaptureDevice::StopAndDeAllocate() {
if (state_ != kCapturing) {
- return; // Wrong state.
- }
- capture_thread_.Stop();
- state_ = kAllocated;
-}
-
-void FakeVideoCaptureDevice::DeAllocate() {
- if (state_ != kAllocated && state_ != kCapturing) {
- return; // Wrong state.
+ return; // Wrong state.
}
capture_thread_.Stop();
state_ = kIdle;
}
-const VideoCaptureDevice::Name& FakeVideoCaptureDevice::device_name() {
- return device_name_;
-}
-
void FakeVideoCaptureDevice::OnCaptureTask() {
if (state_ != kCapturing) {
return;
diff --git a/media/video/capture/fake_video_capture_device.h b/media/video/capture/fake_video_capture_device.h
index 1d7f083..3bd0183 100644
--- a/media/video/capture/fake_video_capture_device.h
+++ b/media/video/capture/fake_video_capture_device.h
@@ -16,7 +16,7 @@
namespace media {
-class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice1 {
+class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice {
public:
static VideoCaptureDevice* Create(const Name& device_name);
virtual ~FakeVideoCaptureDevice();
@@ -27,22 +27,19 @@ class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice1 {
static void GetDeviceNames(Names* device_names);
// VideoCaptureDevice implementation.
- virtual void Allocate(const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) OVERRIDE;
- virtual void Start() OVERRIDE;
- virtual void Stop() OVERRIDE;
- virtual void DeAllocate() OVERRIDE;
- virtual const Name& device_name() OVERRIDE;
+ virtual void AllocateAndStart(
+ const VideoCaptureCapability& capture_format,
+ scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
+ virtual void StopAndDeAllocate() OVERRIDE;
private:
// Flag indicating the internal state.
enum InternalState {
kIdle,
- kAllocated,
kCapturing,
kError
};
- explicit FakeVideoCaptureDevice(const Name& device_name);
+ FakeVideoCaptureDevice();
// Called on the capture_thread_.
void OnCaptureTask();
@@ -52,8 +49,7 @@ class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice1 {
void Reallocate();
void PopulateCapabilitiesRoster();
- Name device_name_;
- VideoCaptureDevice::Client* client_;
+ scoped_ptr<VideoCaptureDevice::Client> client_;
InternalState state_;
base::Thread capture_thread_;
scoped_ptr<uint8[]> fake_frame_;
@@ -67,7 +63,7 @@ class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice1 {
static bool fail_next_create_;
- DISALLOW_IMPLICIT_CONSTRUCTORS(FakeVideoCaptureDevice);
+ DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
};
} // namespace media
diff --git a/media/video/capture/mac/video_capture_device_mac.h b/media/video/capture/mac/video_capture_device_mac.h
index 37607bd..f27b57a 100644
--- a/media/video/capture/mac/video_capture_device_mac.h
+++ b/media/video/capture/mac/video_capture_device_mac.h
@@ -22,18 +22,16 @@ namespace media {
// Called by VideoCaptureManager to open, close and start, stop video capture
// devices.
-class VideoCaptureDeviceMac : public VideoCaptureDevice1 {
+class VideoCaptureDeviceMac : public VideoCaptureDevice {
public:
explicit VideoCaptureDeviceMac(const Name& device_name);
virtual ~VideoCaptureDeviceMac();
// VideoCaptureDevice implementation.
- virtual void Allocate(const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) OVERRIDE;
- virtual void Start() OVERRIDE;
- virtual void Stop() OVERRIDE;
- virtual void DeAllocate() OVERRIDE;
- virtual const Name& device_name() OVERRIDE;
+ virtual void AllocateAndStart(
+ const VideoCaptureCapability& capture_format,
+ scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
+ virtual void StopAndDeAllocate() OVERRIDE;
bool Init();
@@ -54,13 +52,12 @@ class VideoCaptureDeviceMac : public VideoCaptureDevice1 {
enum InternalState {
kNotInitialized,
kIdle,
- kAllocated,
kCapturing,
kError
};
Name device_name_;
- VideoCaptureDevice::Client* client_;
+ scoped_ptr<VideoCaptureDevice::Client> client_;
VideoCaptureCapability current_settings_;
bool sent_frame_info_;
diff --git a/media/video/capture/mac/video_capture_device_mac.mm b/media/video/capture/mac/video_capture_device_mac.mm
index bbafa69..3e61437 100644
--- a/media/video/capture/mac/video_capture_device_mac.mm
+++ b/media/video/capture/mac/video_capture_device_mac.mm
@@ -99,7 +99,6 @@ VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name)
: device_name_(device_name),
- client_(NULL),
sent_frame_info_(false),
loop_proxy_(base::MessageLoopProxy::current()),
state_(kNotInitialized),
@@ -113,9 +112,9 @@ VideoCaptureDeviceMac::~VideoCaptureDeviceMac() {
[capture_device_ release];
}
-void VideoCaptureDeviceMac::Allocate(
+void VideoCaptureDeviceMac::AllocateAndStart(
const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) {
+ scoped_ptr<VideoCaptureDevice::Client> client) {
DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current());
if (state_ != kIdle) {
return;
@@ -130,7 +129,7 @@ void VideoCaptureDeviceMac::Allocate(
GetBestMatchSupportedResolution(&width,
&height);
- client_ = client;
+ client_ = client.Pass();
NSString* deviceId =
[NSString stringWithUTF8String:device_name_.id().c_str()];
@@ -174,44 +173,19 @@ void VideoCaptureDeviceMac::Allocate(
return;
}
- state_ = kAllocated;
-}
-
-void VideoCaptureDeviceMac::Start() {
- DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current());
- DCHECK_EQ(state_, kAllocated);
state_ = kCapturing;
-
- // This method no longer has any effect. Capturing is triggered by
- // the call to Allocate.
- // TODO(bemasc, ncarter): Remove this method.
}
-void VideoCaptureDeviceMac::Stop() {
+void VideoCaptureDeviceMac::StopAndDeAllocate() {
DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current());
DCHECK(state_ == kCapturing || state_ == kError) << state_;
[capture_device_ stopCapture];
- state_ = kAllocated;
-}
-
-void VideoCaptureDeviceMac::DeAllocate() {
- DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current());
- if (state_ != kAllocated && state_ != kCapturing) {
- return;
- }
- if (state_ == kCapturing) {
- [capture_device_ stopCapture];
- }
[capture_device_ setCaptureDevice:nil];
[capture_device_ setFrameReceiver:nil];
-
+ client_.reset();
state_ = kIdle;
}
-const VideoCaptureDevice::Name& VideoCaptureDeviceMac::device_name() {
- return device_name_;
-}
-
bool VideoCaptureDeviceMac::Init() {
DCHECK_EQ(loop_proxy_, base::MessageLoopProxy::current());
DCHECK_EQ(state_, kNotInitialized);
diff --git a/media/video/capture/video_capture_device.cc b/media/video/capture/video_capture_device.cc
index 6f06518..cd1f535 100644
--- a/media/video/capture/video_capture_device.cc
+++ b/media/video/capture/video_capture_device.cc
@@ -28,23 +28,4 @@ VideoCaptureDevice::Names::FindById(const std::string& id) {
VideoCaptureDevice::~VideoCaptureDevice() {}
-VideoCaptureDevice1::VideoCaptureDevice1() {}
-
-VideoCaptureDevice1::~VideoCaptureDevice1() {}
-
-void VideoCaptureDevice1::AllocateAndStart(
- const VideoCaptureCapability& capture_format,
- scoped_ptr<Client> client) {
- client_ = client.Pass();
- Allocate(capture_format, client_.get());
- Start();
-}
-
-void VideoCaptureDevice1::StopAndDeAllocate() {
- Stop();
- DeAllocate();
- client_.reset();
-};
-
-
} // namespace media
diff --git a/media/video/capture/video_capture_device.h b/media/video/capture/video_capture_device.h
index bc145ff..d00714d 100644
--- a/media/video/capture/video_capture_device.h
+++ b/media/video/capture/video_capture_device.h
@@ -212,58 +212,6 @@ class MEDIA_EXPORT VideoCaptureDevice {
virtual void StopAndDeAllocate() = 0;
};
-// VideoCaptureDevice1 is a bridge to an older API against which
-// VideoCaptureDevices were implemented. Differences between VideoCaptureDevice
-// (new style) and VideoCaptureDevice1 (old style) are as follows:
-//
-// [1] The Stop+DeAllocate calls are merged in the new style.
-// [2] The Allocate+Start calls are merged in the new style.
-// [3] New style devices own their Client* pointers, allowing the client to
-// linger after the device is stopped. Whereas old style devices
-// may not dereference their client after DeAllocate().
-// [4] device_name() is eliminated from the new-style interface.
-//
-// TODO(nick): Remove this bridge class. It exists to enable incremental
-// migration to an alternative VideoCaptureDevice API.
-class MEDIA_EXPORT VideoCaptureDevice1 : public VideoCaptureDevice {
- public:
- VideoCaptureDevice1();
- virtual ~VideoCaptureDevice1();
-
- // VideoCaptureDevice implementation.
- virtual void AllocateAndStart(
- const VideoCaptureCapability& capture_format,
- scoped_ptr<Client> client) OVERRIDE;
- virtual void StopAndDeAllocate() OVERRIDE;
-
- // Prepare the camera for use. After this function has been called no other
- // applications can use the camera. On completion Client::OnFrameInfo()
- // is called informing of the resulting resolution and frame rate.
- // DeAllocate() must be called before this function can be called again and
- // before the object is deleted.
- virtual void Allocate(const VideoCaptureCapability& capture_format,
- Client* client) = 0;
-
- // Start capturing video frames. Allocate must be called before this function.
- virtual void Start() = 0;
-
- // Stop capturing video frames.
- virtual void Stop() = 0;
-
- // Deallocates the camera. This means other applications can use it. After
- // this function has been called the capture device is reset to the state it
- // was when created. After DeAllocate() is called, the VideoCaptureDevice is
- // not permitted to make any additional calls to its Client.
- virtual void DeAllocate() = 0;
-
- // Get the name of the capture device.
- virtual const Name& device_name() = 0;
-
- private:
- // The device client which proxies device events to the controller.
- scoped_ptr<Client> client_;
-};
-
} // namespace media
#endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_
diff --git a/media/video/capture/win/video_capture_device_mf_win.cc b/media/video/capture/win/video_capture_device_mf_win.cc
index a8a0f9a..2e9277a 100644
--- a/media/video/capture/win/video_capture_device_mf_win.cc
+++ b/media/video/capture/win/video_capture_device_mf_win.cc
@@ -312,7 +312,7 @@ const std::string VideoCaptureDevice::Name::GetModel() const {
}
VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin(const Name& device_name)
- : name_(device_name), client_(NULL), capture_(0) {
+ : name_(device_name), capture_(0) {
DetachFromThread();
}
@@ -339,19 +339,14 @@ bool VideoCaptureDeviceMFWin::Init() {
reader_.Receive()));
}
-void VideoCaptureDeviceMFWin::Allocate(
+void VideoCaptureDeviceMFWin::AllocateAndStart(
const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) {
+ scoped_ptr<VideoCaptureDevice::Client> client) {
DCHECK(CalledOnValidThread());
base::AutoLock lock(lock_);
- if (client_) {
- DCHECK_EQ(client, client_);
- return;
- }
-
- client_ = client;
+ client_ = client.Pass();
DCHECK_EQ(capture_, false);
CapabilityList capabilities;
@@ -381,24 +376,16 @@ void VideoCaptureDeviceMFWin::Allocate(
}
client_->OnFrameInfo(found_capability);
-}
-
-void VideoCaptureDeviceMFWin::Start() {
- DCHECK(CalledOnValidThread());
- base::AutoLock lock(lock_);
- if (!capture_) {
- capture_ = true;
- HRESULT hr;
- if (FAILED(hr = reader_->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0,
- NULL, NULL, NULL, NULL))) {
- OnError(hr);
- capture_ = false;
- }
+ if (FAILED(hr = reader_->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0,
+ NULL, NULL, NULL, NULL))) {
+ OnError(hr);
+ return;
}
+ capture_ = true;
}
-void VideoCaptureDeviceMFWin::Stop() {
+void VideoCaptureDeviceMFWin::StopAndDeAllocate() {
DCHECK(CalledOnValidThread());
base::WaitableEvent flushed(false, false);
const int kFlushTimeOutInMs = 1000;
@@ -412,9 +399,9 @@ void VideoCaptureDeviceMFWin::Stop() {
wait = SUCCEEDED(hr);
if (!wait) {
callback_->SetSignalOnFlush(NULL);
- OnError(hr);
}
}
+ client_.reset();
}
// If the device has been unplugged, the Flush() won't trigger the event
@@ -426,20 +413,6 @@ void VideoCaptureDeviceMFWin::Stop() {
flushed.TimedWait(base::TimeDelta::FromMilliseconds(kFlushTimeOutInMs));
}
-void VideoCaptureDeviceMFWin::DeAllocate() {
- DCHECK(CalledOnValidThread());
-
- Stop();
-
- base::AutoLock lock(lock_);
- client_ = NULL;
-}
-
-const VideoCaptureDevice::Name& VideoCaptureDeviceMFWin::device_name() {
- DCHECK(CalledOnValidThread());
- return name_;
-}
-
void VideoCaptureDeviceMFWin::OnIncomingCapturedFrame(
const uint8* data,
int length,
@@ -448,7 +421,7 @@ void VideoCaptureDeviceMFWin::OnIncomingCapturedFrame(
bool flip_vert,
bool flip_horiz) {
base::AutoLock lock(lock_);
- if (data && client_)
+ if (data && client_.get())
client_->OnIncomingCapturedFrame(data, length, time_stamp,
rotation, flip_vert, flip_horiz);
@@ -468,7 +441,7 @@ void VideoCaptureDeviceMFWin::OnIncomingCapturedFrame(
void VideoCaptureDeviceMFWin::OnError(HRESULT hr) {
DLOG(ERROR) << "VideoCaptureDeviceMFWin: " << std::hex << hr;
- if (client_)
+ if (client_.get())
client_->OnError();
}
diff --git a/media/video/capture/win/video_capture_device_mf_win.h b/media/video/capture/win/video_capture_device_mf_win.h
index 9e27c0a..1ff6c75 100644
--- a/media/video/capture/win/video_capture_device_mf_win.h
+++ b/media/video/capture/win/video_capture_device_mf_win.h
@@ -28,7 +28,7 @@ class MFReaderCallback;
class MEDIA_EXPORT VideoCaptureDeviceMFWin
: public base::NonThreadSafe,
- public VideoCaptureDevice1 {
+ public VideoCaptureDevice {
public:
explicit VideoCaptureDeviceMFWin(const Name& device_name);
virtual ~VideoCaptureDeviceMFWin();
@@ -38,12 +38,10 @@ class MEDIA_EXPORT VideoCaptureDeviceMFWin
bool Init();
// VideoCaptureDevice implementation.
- virtual void Allocate(const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) OVERRIDE;
- virtual void Start() OVERRIDE;
- virtual void Stop() OVERRIDE;
- virtual void DeAllocate() OVERRIDE;
- virtual const Name& device_name() OVERRIDE;
+ virtual void AllocateAndStart(
+ const VideoCaptureCapability& capture_format,
+ scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
+ virtual void StopAndDeAllocate() OVERRIDE;
// Returns true iff the current platform supports the Media Foundation API
// and that the DLLs are available. On Vista this API is an optional download
@@ -71,7 +69,7 @@ class MEDIA_EXPORT VideoCaptureDeviceMFWin
scoped_refptr<MFReaderCallback> callback_;
base::Lock lock_; // Used to guard the below variables.
- VideoCaptureDevice::Client* client_;
+ scoped_ptr<VideoCaptureDevice::Client> client_;
base::win::ScopedComPtr<IMFSourceReader> reader_;
bool capture_;
diff --git a/media/video/capture/win/video_capture_device_win.cc b/media/video/capture/win/video_capture_device_win.cc
index 9c561f8..3c9bca4 100644
--- a/media/video/capture/win/video_capture_device_win.cc
+++ b/media/video/capture/win/video_capture_device_win.cc
@@ -257,8 +257,7 @@ void VideoCaptureDeviceWin::GetDeviceNames(Names* device_names) {
VideoCaptureDeviceWin::VideoCaptureDeviceWin(const Name& device_name)
: device_name_(device_name),
- state_(kIdle),
- client_(NULL) {
+ state_(kIdle) {
DetachFromThread();
}
@@ -333,14 +332,14 @@ bool VideoCaptureDeviceWin::Init() {
return CreateCapabilityMap();
}
-void VideoCaptureDeviceWin::Allocate(
+void VideoCaptureDeviceWin::AllocateAndStart(
const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) {
+ scoped_ptr<VideoCaptureDevice::Client> client) {
DCHECK(CalledOnValidThread());
if (state_ != kIdle)
return;
- client_ = client;
+ client_ = client.Pass();
// Get the camera capability that best match the requested resolution.
const VideoCaptureCapabilityWin& found_capability =
@@ -432,15 +431,8 @@ void VideoCaptureDeviceWin::Allocate(
= sink_filter_->ResultingCapability();
client_->OnFrameInfo(used_capability);
- state_ = kAllocated;
-}
-
-void VideoCaptureDeviceWin::Start() {
- DCHECK(CalledOnValidThread());
- if (state_ != kAllocated)
- return;
-
- HRESULT hr = media_control_->Run();
+ // Start capturing.
+ hr = media_control_->Run();
if (FAILED(hr)) {
SetErrorState("Failed to start the Capture device.");
return;
@@ -449,7 +441,7 @@ void VideoCaptureDeviceWin::Start() {
state_ = kCapturing;
}
-void VideoCaptureDeviceWin::Stop() {
+void VideoCaptureDeviceWin::StopAndDeAllocate() {
DCHECK(CalledOnValidThread());
if (state_ != kCapturing)
return;
@@ -460,15 +452,6 @@ void VideoCaptureDeviceWin::Stop() {
return;
}
- state_ = kAllocated;
-}
-
-void VideoCaptureDeviceWin::DeAllocate() {
- DCHECK(CalledOnValidThread());
- if (state_ == kIdle)
- return;
-
- HRESULT hr = media_control_->Stop();
graph_builder_->Disconnect(output_capture_pin_);
graph_builder_->Disconnect(input_sink_pin_);
@@ -482,15 +465,10 @@ void VideoCaptureDeviceWin::DeAllocate() {
SetErrorState("Failed to Stop the Capture device");
return;
}
-
+ client_.reset();
state_ = kIdle;
}
-const VideoCaptureDevice::Name& VideoCaptureDeviceWin::device_name() {
- DCHECK(CalledOnValidThread());
- return device_name_;
-}
-
// Implements SinkFilterObserver::SinkFilterObserver.
void VideoCaptureDeviceWin::FrameReceived(const uint8* buffer,
int length) {
diff --git a/media/video/capture/win/video_capture_device_win.h b/media/video/capture/win/video_capture_device_win.h
index fcf0d51..2654946 100644
--- a/media/video/capture/win/video_capture_device_win.h
+++ b/media/video/capture/win/video_capture_device_win.h
@@ -30,7 +30,7 @@ namespace media {
// All the methods in the class can only be run on a COM initialized thread.
class VideoCaptureDeviceWin
: public base::NonThreadSafe,
- public VideoCaptureDevice1,
+ public VideoCaptureDevice,
public SinkFilterObserver {
public:
explicit VideoCaptureDeviceWin(const Name& device_name);
@@ -40,19 +40,16 @@ class VideoCaptureDeviceWin
bool Init();
// VideoCaptureDevice implementation.
- virtual void Allocate(const VideoCaptureCapability& capture_format,
- VideoCaptureDevice::Client* client) OVERRIDE;
- virtual void Start() OVERRIDE;
- virtual void Stop() OVERRIDE;
- virtual void DeAllocate() OVERRIDE;
- virtual const Name& device_name() OVERRIDE;
+ virtual void AllocateAndStart(
+ const VideoCaptureCapability& capture_format,
+ scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
+ virtual void StopAndDeAllocate() OVERRIDE;
static void GetDeviceNames(Names* device_names);
private:
enum InternalState {
kIdle, // The device driver is opened but camera is not in use.
- kAllocated, // The camera has been allocated and can be started.
kCapturing, // Video is being captured.
kError // Error accessing HW functions.
// User needs to recover by destroying the object.
@@ -66,7 +63,7 @@ class VideoCaptureDeviceWin
Name device_name_;
InternalState state_;
- VideoCaptureDevice::Client* client_;
+ scoped_ptr<VideoCaptureDevice::Client> client_;
base::win::ScopedComPtr<IBaseFilter> capture_filter_;
base::win::ScopedComPtr<IGraphBuilder> graph_builder_;