summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authormcasas@chromium.org <mcasas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 12:01:42 +0000
committermcasas@chromium.org <mcasas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 12:01:42 +0000
commit0ce455660d7ab0ecb09d973c8331ce8d155a923d (patch)
tree9a2fb8b257700ff4ac01292a711135f2ac7d22a6 /media
parentc52aebd06dc0832f7f3b918d267359215b743653 (diff)
downloadchromium_src-0ce455660d7ab0ecb09d973c8331ce8d155a923d.zip
chromium_src-0ce455660d7ab0ecb09d973c8331ce8d155a923d.tar.gz
chromium_src-0ce455660d7ab0ecb09d973c8331ce8d155a923d.tar.bz2
FakeVCD refactoring, moving some variable use into inner
thread. Move manipulation of |capture_format_|, |fake_frame_| to be used only in the |capture_thread_| -- this is a cleanup so that the behaviour is similar to other VCD implementations where the "capture thread" does the heavy lifting and the other thread (whatever its name) is mostly passing by messages and starting/stopping the "capture thread" (see f.i. Linux impl [1]). Following this cleanup, |client_| manipulation is shifted to the "capture_thread" as well. |state_| disappears, substituted by checking of |capture_thread_| running state. [1] https://code.google.com/p/chromium/codesearch#chromium/src/media/video/capture/linux/video_capture_device_linux.cc&sq=package:chromium&type=cs&l=296 BUG=323893 Review URL: https://codereview.chromium.org/91523002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238677 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/video/capture/fake_video_capture_device.cc87
-rw-r--r--media/video/capture/fake_video_capture_device.h28
2 files changed, 63 insertions, 52 deletions
diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc
index 81bc9b8..c6f5f61 100644
--- a/media/video/capture/fake_video_capture_device.cc
+++ b/media/video/capture/fake_video_capture_device.cc
@@ -75,74 +75,71 @@ void FakeVideoCaptureDevice::SetNumberOfFakeDevices(size_t number_of_devices) {
}
FakeVideoCaptureDevice::FakeVideoCaptureDevice()
- : state_(kIdle),
- capture_thread_("CaptureThread"),
+ : capture_thread_("CaptureThread"),
frame_count_(0),
format_roster_index_(0) {}
FakeVideoCaptureDevice::~FakeVideoCaptureDevice() {
- // Check if the thread is running.
- // This means that the device have not been DeAllocated properly.
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!capture_thread_.IsRunning());
}
void FakeVideoCaptureDevice::AllocateAndStart(
const VideoCaptureParams& params,
scoped_ptr<VideoCaptureDevice::Client> client) {
- if (params.allow_resolution_change)
- PopulateFormatRoster();
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(!capture_thread_.IsRunning());
- if (state_ != kIdle) {
- return; // Wrong state.
- }
+ capture_thread_.Start();
+ capture_thread_.message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeVideoCaptureDevice::OnAllocateAndStart,
+ base::Unretained(this),
+ params,
+ base::Passed(&client)));
+}
+void FakeVideoCaptureDevice::StopAndDeAllocate() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(capture_thread_.IsRunning());
+ capture_thread_.message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeVideoCaptureDevice::OnStopAndDeAllocate,
+ base::Unretained(this)));
+ capture_thread_.Stop();
+}
+
+void FakeVideoCaptureDevice::OnAllocateAndStart(
+ const VideoCaptureParams& params,
+ scoped_ptr<VideoCaptureDevice::Client> client) {
+ DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current());
client_ = client.Pass();
capture_format_.pixel_format = PIXEL_FORMAT_I420;
- if (params.requested_format.frame_size.width() > 320) { // VGA
+ capture_format_.frame_rate = 30;
+ if (params.requested_format.frame_size.width() > 320)
capture_format_.frame_size.SetSize(640, 480);
- capture_format_.frame_rate = 30;
- } else { // QVGA
+ else
capture_format_.frame_size.SetSize(320, 240);
- capture_format_.frame_rate = 30;
- }
-
+ if (params.allow_resolution_change)
+ PopulateFormatRoster();
const size_t fake_frame_size =
VideoFrame::AllocationSize(VideoFrame::I420, capture_format_.frame_size);
fake_frame_.reset(new uint8[fake_frame_size]);
- state_ = kCapturing;
- capture_thread_.Start();
capture_thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&FakeVideoCaptureDevice::OnCaptureTask,
base::Unretained(this)));
}
-void FakeVideoCaptureDevice::Reallocate() {
- DCHECK_EQ(state_, kCapturing);
- capture_format_ =
- format_roster_.at(++format_roster_index_ % format_roster_.size());
- DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_I420);
- DVLOG(3) << "Reallocating FakeVideoCaptureDevice, new capture resolution "
- << capture_format_.frame_size.ToString();
-
- const size_t fake_frame_size =
- VideoFrame::AllocationSize(VideoFrame::I420, capture_format_.frame_size);
- fake_frame_.reset(new uint8[fake_frame_size]);
-}
-
-void FakeVideoCaptureDevice::StopAndDeAllocate() {
- if (state_ != kCapturing) {
- return; // Wrong state.
- }
- capture_thread_.Stop();
- state_ = kIdle;
+void FakeVideoCaptureDevice::OnStopAndDeAllocate() {
+ DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current());
+ client_.reset();
}
void FakeVideoCaptureDevice::OnCaptureTask() {
- if (state_ != kCapturing) {
+ if (!client_)
return;
- }
const size_t frame_size =
VideoFrame::AllocationSize(VideoFrame::I420, capture_format_.frame_size);
@@ -222,7 +219,21 @@ void FakeVideoCaptureDevice::OnCaptureTask() {
base::TimeDelta::FromMilliseconds(kFakeCaptureTimeoutMs));
}
+void FakeVideoCaptureDevice::Reallocate() {
+ DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current());
+ capture_format_ =
+ format_roster_.at(++format_roster_index_ % format_roster_.size());
+ DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_I420);
+ DVLOG(3) << "Reallocating FakeVideoCaptureDevice, new capture resolution "
+ << capture_format_.frame_size.ToString();
+
+ const size_t fake_frame_size =
+ VideoFrame::AllocationSize(VideoFrame::I420, capture_format_.frame_size);
+ fake_frame_.reset(new uint8[fake_frame_size]);
+}
+
void FakeVideoCaptureDevice::PopulateFormatRoster() {
+ DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current());
format_roster_.push_back(
media::VideoCaptureFormat(gfx::Size(320, 240), 30, PIXEL_FORMAT_I420));
format_roster_.push_back(
diff --git a/media/video/capture/fake_video_capture_device.h b/media/video/capture/fake_video_capture_device.h
index de1fe32..2a884a3 100644
--- a/media/video/capture/fake_video_capture_device.h
+++ b/media/video/capture/fake_video_capture_device.h
@@ -13,6 +13,7 @@
#include "base/atomicops.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread.h"
+#include "base/threading/thread_checker.h"
#include "media/video/capture/video_capture_device.h"
namespace media {
@@ -37,31 +38,30 @@ class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice {
virtual void StopAndDeAllocate() OVERRIDE;
private:
- // Flag indicating the internal state.
- enum InternalState {
- kIdle,
- kCapturing,
- kError
- };
FakeVideoCaptureDevice();
- // Called on the capture_thread_.
+ // Called on the |capture_thread_| only.
+ void OnAllocateAndStart(const VideoCaptureParams& params,
+ scoped_ptr<Client> client);
+ void OnStopAndDeAllocate();
void OnCaptureTask();
-
- // EXPERIMENTAL, similar to allocate, but changes resolution and calls
- // client->OnFrameInfoChanged(VideoCaptureCapability&)
void Reallocate();
void PopulateFormatRoster();
- scoped_ptr<VideoCaptureDevice::Client> client_;
- InternalState state_;
+ // |thread_checker_| is used to check that destructor, AllocateAndStart() and
+ // StopAndDeAllocate() are called in the correct thread that owns the object.
+ base::ThreadChecker thread_checker_;
+
base::Thread capture_thread_;
+ // The following members are only used on the |capture_thread_|.
+ scoped_ptr<VideoCaptureDevice::Client> client_;
scoped_ptr<uint8[]> fake_frame_;
int frame_count_;
VideoCaptureFormat capture_format_;
- // When the device is configured as mutating video captures, this vector
- // holds the available ones which are used in sequence, restarting at the end.
+ // When the device is allowed to change resolution, this vector holds the
+ // available ones which are used in sequence, restarting at the end. These
+ // two members belong to and are only used in |capture_thread_|.
std::vector<VideoCaptureFormat> format_roster_;
int format_roster_index_;