Commit 741dff1f authored by zork@chromium.org's avatar zork@chromium.org

Add a ChromeOS implementation of VideoCaptureDevice that is aware of the...

Add a ChromeOS implementation of VideoCaptureDevice that is aware of the rotation of the internal display, and updates the rotation of captured frames to match.

BUG=360048

Review URL: https://codereview.chromium.org/270263008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271560 0039d316-1c4b-4281-b951-d872f2087c98
parent 7bc7e304
...@@ -200,7 +200,9 @@ void VideoCaptureManager::DoStartDeviceOnDeviceThread( ...@@ -200,7 +200,9 @@ void VideoCaptureManager::DoStartDeviceOnDeviceThread(
DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_);
if (found) { if (found) {
video_capture_device = video_capture_device =
video_capture_device_factory_->Create(found->name); video_capture_device_factory_->Create(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
found->name);
} }
break; break;
} }
......
...@@ -473,6 +473,8 @@ ...@@ -473,6 +473,8 @@
'video/capture/linux/video_capture_device_factory_linux.h', 'video/capture/linux/video_capture_device_factory_linux.h',
'video/capture/linux/video_capture_device_linux.cc', 'video/capture/linux/video_capture_device_linux.cc',
'video/capture/linux/video_capture_device_linux.h', 'video/capture/linux/video_capture_device_linux.h',
'video/capture/linux/video_capture_device_chromeos.cc',
'video/capture/linux/video_capture_device_chromeos.h',
'video/capture/mac/avfoundation_glue.h', 'video/capture/mac/avfoundation_glue.h',
'video/capture/mac/avfoundation_glue.mm', 'video/capture/mac/avfoundation_glue.mm',
'video/capture/mac/coremedia_glue.h', 'video/capture/mac/coremedia_glue.h',
......
...@@ -32,7 +32,9 @@ bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) { ...@@ -32,7 +32,9 @@ bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) {
// VideoCaptureDeviceFactory. // VideoCaptureDeviceFactory.
// static // static
VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { VideoCaptureDevice* VideoCaptureDevice::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const Name& device_name) {
NOTREACHED(); NOTREACHED();
return NULL; return NULL;
} }
......
...@@ -35,6 +35,7 @@ VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid( ...@@ -35,6 +35,7 @@ VideoCaptureDeviceFactoryAndroid::createVideoCaptureAndroid(
} }
scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryAndroid::Create( scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryAndroid::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) { const VideoCaptureDevice::Name& device_name) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
int id; int id;
......
...@@ -34,6 +34,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryAndroid : ...@@ -34,6 +34,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryAndroid :
virtual ~VideoCaptureDeviceFactoryAndroid() {} virtual ~VideoCaptureDeviceFactoryAndroid() {}
virtual scoped_ptr<VideoCaptureDevice> Create( virtual scoped_ptr<VideoCaptureDevice> Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) OVERRIDE; const VideoCaptureDevice::Name& device_name) OVERRIDE;
virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE; virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE;
virtual void GetDeviceSupportedFormats( virtual void GetDeviceSupportedFormats(
......
...@@ -14,6 +14,7 @@ FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() ...@@ -14,6 +14,7 @@ FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory()
} }
scoped_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::Create( scoped_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) { const VideoCaptureDevice::Name& device_name) {
for (int n = 0; n < number_of_devices_; ++n) { for (int n = 0; n < number_of_devices_; ++n) {
std::string possible_id = base::StringPrintf("/dev/video%d", n); std::string possible_id = base::StringPrintf("/dev/video%d", n);
......
...@@ -20,6 +20,7 @@ class MEDIA_EXPORT FakeVideoCaptureDeviceFactory : ...@@ -20,6 +20,7 @@ class MEDIA_EXPORT FakeVideoCaptureDeviceFactory :
virtual ~FakeVideoCaptureDeviceFactory() {} virtual ~FakeVideoCaptureDeviceFactory() {}
virtual scoped_ptr<VideoCaptureDevice> Create( virtual scoped_ptr<VideoCaptureDevice> Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) OVERRIDE; const VideoCaptureDevice::Name& device_name) OVERRIDE;
virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE; virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE;
virtual void GetDeviceSupportedFormats( virtual void GetDeviceSupportedFormats(
......
...@@ -95,7 +95,8 @@ TEST_F(FakeVideoCaptureDeviceTest, Capture) { ...@@ -95,7 +95,8 @@ TEST_F(FakeVideoCaptureDeviceTest, Capture) {
ASSERT_GT(static_cast<int>(names.size()), 0); ASSERT_GT(static_cast<int>(names.size()), 0);
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names.front())); video_capture_device_factory_->Create(
base::MessageLoopProxy::current(), names.front()));
ASSERT_TRUE(device); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()).Times(0); EXPECT_CALL(*client_, OnErr()).Times(0);
...@@ -153,7 +154,8 @@ TEST_F(FakeVideoCaptureDeviceTest, CaptureVariableResolution) { ...@@ -153,7 +154,8 @@ TEST_F(FakeVideoCaptureDeviceTest, CaptureVariableResolution) {
ASSERT_GT(static_cast<int>(names.size()), 0); ASSERT_GT(static_cast<int>(names.size()), 0);
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names.front())); video_capture_device_factory_->Create(
base::MessageLoopProxy::current(), names.front()));
ASSERT_TRUE(device); ASSERT_TRUE(device);
// Configure the FakeVideoCaptureDevice to use all its formats as roster. // Configure the FakeVideoCaptureDevice to use all its formats as roster.
......
...@@ -25,6 +25,7 @@ base::FilePath GetFilePathFromCommandLine() { ...@@ -25,6 +25,7 @@ base::FilePath GetFilePathFromCommandLine() {
} }
scoped_ptr<VideoCaptureDevice> FileVideoCaptureDeviceFactory::Create( scoped_ptr<VideoCaptureDevice> FileVideoCaptureDeviceFactory::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) { const VideoCaptureDevice::Name& device_name) {
#if defined(OS_WIN) #if defined(OS_WIN)
return scoped_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice( return scoped_ptr<VideoCaptureDevice>(new FileVideoCaptureDevice(
......
...@@ -19,6 +19,7 @@ class MEDIA_EXPORT FileVideoCaptureDeviceFactory : ...@@ -19,6 +19,7 @@ class MEDIA_EXPORT FileVideoCaptureDeviceFactory :
virtual ~FileVideoCaptureDeviceFactory() {} virtual ~FileVideoCaptureDeviceFactory() {}
virtual scoped_ptr<VideoCaptureDevice> Create( virtual scoped_ptr<VideoCaptureDevice> Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) OVERRIDE; const VideoCaptureDevice::Name& device_name) OVERRIDE;
virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE; virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE;
virtual void GetDeviceSupportedFormats( virtual void GetDeviceSupportedFormats(
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/video/capture/linux/video_capture_device_chromeos.h"
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop_proxy.h"
#include "ui/gfx/display.h"
#include "ui/gfx/display_observer.h"
#include "ui/gfx/screen.h"
namespace media {
// This is a delegate class used to transfer Display change events from the UI
// thread to the media thread.
class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
: public gfx::DisplayObserver,
public base::RefCountedThreadSafe<ScreenObserverDelegate> {
public:
ScreenObserverDelegate(
VideoCaptureDeviceChromeOS* capture_device,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
: capture_device_(capture_device),
ui_task_runner_(ui_task_runner),
capture_task_runner_(base::MessageLoopProxy::current()) {
ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ScreenObserverDelegate::AddObserverOnUIThread, this));
}
void RemoveObserver() {
DCHECK(capture_task_runner_->BelongsToCurrentThread());
capture_device_ = NULL;
ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ScreenObserverDelegate::RemoveObserverOnUIThread, this));
}
private:
friend class base::RefCountedThreadSafe<ScreenObserverDelegate>;
virtual ~ScreenObserverDelegate() {
DCHECK(!capture_device_);
}
// gfx::DisplayObserver:
virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE {
SendDisplayRotation(display);
}
virtual void OnDisplayAdded(const gfx::Display& /*new_display*/) OVERRIDE {}
virtual void OnDisplayRemoved(const gfx::Display& /*old_display*/) OVERRIDE {}
void AddObserverOnUIThread() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
gfx::Screen* screen =
gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
if (screen) {
screen->AddObserver(this);
SendDisplayRotation(screen->GetPrimaryDisplay());
}
}
void RemoveObserverOnUIThread() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
gfx::Screen* screen =
gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
if (screen)
screen->RemoveObserver(this);
}
void SendDisplayRotation(const gfx::Display& display) {
DCHECK(capture_task_runner_->BelongsToCurrentThread());
capture_task_runner_->PostTask(
FROM_HERE,
base::Bind(&ScreenObserverDelegate::SendDisplayRotationOnCaptureThread,
this, display));
}
void SendDisplayRotationOnCaptureThread(const gfx::Display& display) {
DCHECK(capture_task_runner_->BelongsToCurrentThread());
capture_device_->SetDisplayRotation(display);
}
VideoCaptureDeviceChromeOS* capture_device_;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
};
VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const Name& device_name)
: VideoCaptureDeviceLinux(device_name),
screen_observer_delegate_(new ScreenObserverDelegate(this,
ui_task_runner)) {
}
VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
screen_observer_delegate_->RemoveObserver();
}
void VideoCaptureDeviceChromeOS::SetDisplayRotation(
const gfx::Display& display) {
if (display.IsInternal())
SetRotation(display.rotation() * 90);
}
} // namespace media
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_
#define MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_
#include "media/video/capture/linux/video_capture_device_linux.h"
namespace gfx {
class Display;
} // namespace gfx
namespace media {
// This class is functionally the same as VideoCaptureDeviceLinux, with the
// exception that it is aware of the orientation of the internal Display. When
// the internal Display is rotated, the frames captured are rotated to match.
class VideoCaptureDeviceChromeOS : public VideoCaptureDeviceLinux {
public:
explicit VideoCaptureDeviceChromeOS(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const Name& device_name);
virtual ~VideoCaptureDeviceChromeOS();
void SetDisplayRotation(const gfx::Display& display);
private:
class ScreenObserverDelegate;
scoped_refptr<ScreenObserverDelegate> screen_observer_delegate_;
DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceChromeOS);
};
} // namespace media
#endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#if defined(OS_CHROMEOS)
#include "media/video/capture/linux/video_capture_device_chromeos.h"
#endif
#include "media/video/capture/linux/video_capture_device_linux.h" #include "media/video/capture/linux/video_capture_device_linux.h"
namespace media { namespace media {
...@@ -42,9 +45,15 @@ static bool HasUsableFormats(int fd) { ...@@ -42,9 +45,15 @@ static bool HasUsableFormats(int fd) {
} }
scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryLinux::Create( scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryLinux::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) { const VideoCaptureDevice::Name& device_name) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
#if defined(OS_CHROMEOS)
VideoCaptureDeviceChromeOS* self =
new VideoCaptureDeviceChromeOS(ui_task_runner, device_name);
#else
VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name); VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name);
#endif
if (!self) if (!self)
return scoped_ptr<VideoCaptureDevice>(); return scoped_ptr<VideoCaptureDevice>();
// Test opening the device driver. This is to make sure it is available. // Test opening the device driver. This is to make sure it is available.
......
...@@ -22,6 +22,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryLinux ...@@ -22,6 +22,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryLinux
virtual ~VideoCaptureDeviceFactoryLinux() {} virtual ~VideoCaptureDeviceFactoryLinux() {}
virtual scoped_ptr<VideoCaptureDevice> Create( virtual scoped_ptr<VideoCaptureDevice> Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) OVERRIDE; const VideoCaptureDevice::Name& device_name) OVERRIDE;
virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE; virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE;
virtual void GetDeviceSupportedFormats( virtual void GetDeviceSupportedFormats(
......
...@@ -113,7 +113,9 @@ void VideoCaptureDeviceLinux::GetListOfUsableFourCCs(bool favour_mjpeg, ...@@ -113,7 +113,9 @@ void VideoCaptureDeviceLinux::GetListOfUsableFourCCs(bool favour_mjpeg,
// VideoCaptureDeviceFactory. // VideoCaptureDeviceFactory.
// static // static
VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { VideoCaptureDevice* VideoCaptureDevice::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const Name& device_name) {
NOTREACHED(); NOTREACHED();
return NULL; return NULL;
} }
...@@ -157,7 +159,9 @@ VideoCaptureDeviceLinux::VideoCaptureDeviceLinux(const Name& device_name) ...@@ -157,7 +159,9 @@ VideoCaptureDeviceLinux::VideoCaptureDeviceLinux(const Name& device_name)
v4l2_thread_("V4L2Thread"), v4l2_thread_("V4L2Thread"),
buffer_pool_(NULL), buffer_pool_(NULL),
buffer_pool_size_(0), buffer_pool_size_(0),
timeout_count_(0) {} timeout_count_(0),
rotation_(0) {
}
VideoCaptureDeviceLinux::~VideoCaptureDeviceLinux() { VideoCaptureDeviceLinux::~VideoCaptureDeviceLinux() {
state_ = kIdle; state_ = kIdle;
...@@ -199,6 +203,25 @@ void VideoCaptureDeviceLinux::StopAndDeAllocate() { ...@@ -199,6 +203,25 @@ void VideoCaptureDeviceLinux::StopAndDeAllocate() {
DeAllocateVideoBuffers(); DeAllocateVideoBuffers();
} }
void VideoCaptureDeviceLinux::SetRotation(int rotation) {
if (v4l2_thread_.IsRunning()) {
v4l2_thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&VideoCaptureDeviceLinux::SetRotationOnV4L2Thread,
base::Unretained(this), rotation));
} else {
// If the |v4l2_thread_| is not running, there's no race condition and
// |rotation_| can be set directly.
rotation_ = rotation;
}
}
void VideoCaptureDeviceLinux::SetRotationOnV4L2Thread(int rotation) {
DCHECK_EQ(v4l2_thread_.message_loop(), base::MessageLoop::current());
DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0);
rotation_ = rotation;
}
void VideoCaptureDeviceLinux::OnAllocateAndStart(int width, void VideoCaptureDeviceLinux::OnAllocateAndStart(int width,
int height, int height,
int frame_rate, int frame_rate,
...@@ -407,7 +430,7 @@ void VideoCaptureDeviceLinux::OnCaptureTask() { ...@@ -407,7 +430,7 @@ void VideoCaptureDeviceLinux::OnCaptureTask() {
static_cast<uint8*>(buffer_pool_[buffer.index].start), static_cast<uint8*>(buffer_pool_[buffer.index].start),
buffer.bytesused, buffer.bytesused,
capture_format_, capture_format_,
0, rotation_,
base::TimeTicks::Now()); base::TimeTicks::Now());
// Enqueue the buffer again. // Enqueue the buffer again.
......
...@@ -35,6 +35,12 @@ class VideoCaptureDeviceLinux : public VideoCaptureDevice { ...@@ -35,6 +35,12 @@ class VideoCaptureDeviceLinux : public VideoCaptureDevice {
virtual void StopAndDeAllocate() OVERRIDE; virtual void StopAndDeAllocate() OVERRIDE;
protected:
void SetRotation(int rotation);
// Once |v4l2_thread_| is started, only called on that thread.
void SetRotationOnV4L2Thread(int rotation);
private: private:
enum InternalState { enum InternalState {
kIdle, // The device driver is opened but camera is not in use. kIdle, // The device driver is opened but camera is not in use.
...@@ -72,6 +78,11 @@ class VideoCaptureDeviceLinux : public VideoCaptureDevice { ...@@ -72,6 +78,11 @@ class VideoCaptureDeviceLinux : public VideoCaptureDevice {
int timeout_count_; int timeout_count_;
VideoCaptureFormat capture_format_; VideoCaptureFormat capture_format_;
// Clockwise rotation in degrees. This value should be 0, 90, 180, or 270.
// This is only used on |v4l2_thread_| when it is running, or the constructor
// thread otherwise.
int rotation_;
DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux); DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux);
}; };
......
...@@ -19,6 +19,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryMac : ...@@ -19,6 +19,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryMac :
virtual ~VideoCaptureDeviceFactoryMac() {} virtual ~VideoCaptureDeviceFactoryMac() {}
virtual scoped_ptr<VideoCaptureDevice> Create( virtual scoped_ptr<VideoCaptureDevice> Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) OVERRIDE; const VideoCaptureDevice::Name& device_name) OVERRIDE;
virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE; virtual void GetDeviceNames(VideoCaptureDevice::Names* device_names) OVERRIDE;
virtual void GetDeviceSupportedFormats( virtual void GetDeviceSupportedFormats(
......
...@@ -27,6 +27,7 @@ VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac() { ...@@ -27,6 +27,7 @@ VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac() {
} }
scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create( scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) { const VideoCaptureDevice::Name& device_name) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_NE(device_name.capture_api_type(), DCHECK_NE(device_name.capture_api_type(),
......
...@@ -67,7 +67,9 @@ void GetBestMatchSupportedResolution(int* width, int* height) { ...@@ -67,7 +67,9 @@ void GetBestMatchSupportedResolution(int* width, int* height) {
// VideoCaptureDeviceFactory. // VideoCaptureDeviceFactory.
// static // static
VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { VideoCaptureDevice* VideoCaptureDevice::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const Name& device_name) {
NOTREACHED(); NOTREACHED();
return NULL; return NULL;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
...@@ -190,7 +191,9 @@ class MEDIA_EXPORT VideoCaptureDevice { ...@@ -190,7 +191,9 @@ class MEDIA_EXPORT VideoCaptureDevice {
// Creates a VideoCaptureDevice object. // Creates a VideoCaptureDevice object.
// Return NULL if the hardware is not available. // Return NULL if the hardware is not available.
static VideoCaptureDevice* Create(const Name& device_name); static VideoCaptureDevice* Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const Name& device_name);
virtual ~VideoCaptureDevice(); virtual ~VideoCaptureDevice();
// Gets the names of all video capture devices connected to this computer. // Gets the names of all video capture devices connected to this computer.
......
...@@ -40,6 +40,9 @@ scoped_ptr<VideoCaptureDeviceFactory> ...@@ -40,6 +40,9 @@ scoped_ptr<VideoCaptureDeviceFactory>
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
return scoped_ptr<VideoCaptureDeviceFactory>(new return scoped_ptr<VideoCaptureDeviceFactory>(new
VideoCaptureDeviceFactoryLinux()); VideoCaptureDeviceFactoryLinux());
#elif defined(OS_LINUX)
return scoped_ptr<VideoCaptureDeviceFactory>(new
VideoCaptureDeviceFactoryLinux());
#elif defined(OS_ANDROID) #elif defined(OS_ANDROID)
return scoped_ptr<VideoCaptureDeviceFactory>(new return scoped_ptr<VideoCaptureDeviceFactory>(new
VideoCaptureDeviceFactoryAndroid()); VideoCaptureDeviceFactoryAndroid());
...@@ -57,10 +60,11 @@ VideoCaptureDeviceFactory::VideoCaptureDeviceFactory() { ...@@ -57,10 +60,11 @@ VideoCaptureDeviceFactory::VideoCaptureDeviceFactory() {
VideoCaptureDeviceFactory::~VideoCaptureDeviceFactory() {} VideoCaptureDeviceFactory::~VideoCaptureDeviceFactory() {}
scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactory::Create( scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactory::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name) { const VideoCaptureDevice::Name& device_name) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
return scoped_ptr<VideoCaptureDevice>( return scoped_ptr<VideoCaptureDevice>(
VideoCaptureDevice::Create(device_name)); VideoCaptureDevice::Create(ui_task_runner, device_name));
} }
void VideoCaptureDeviceFactory::GetDeviceNames( void VideoCaptureDeviceFactory::GetDeviceNames(
......
...@@ -23,6 +23,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactory { ...@@ -23,6 +23,7 @@ class MEDIA_EXPORT VideoCaptureDeviceFactory {
// Creates a VideoCaptureDevice object. Returns NULL if something goes wrong. // Creates a VideoCaptureDevice object. Returns NULL if something goes wrong.
virtual scoped_ptr<VideoCaptureDevice> Create( virtual scoped_ptr<VideoCaptureDevice> Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDevice::Name& device_name); const VideoCaptureDevice::Name& device_name);
// Gets the names of all video capture devices connected to this computer. // Gets the names of all video capture devices connected to this computer.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
...@@ -175,7 +176,9 @@ TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { ...@@ -175,7 +176,9 @@ TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) {
VideoCaptureDevice::Name device_name("jibberish", "jibberish"); VideoCaptureDevice::Name device_name("jibberish", "jibberish");
#endif #endif
scoped_ptr<VideoCaptureDevice> device = scoped_ptr<VideoCaptureDevice> device =
video_capture_device_factory_->Create(device_name); video_capture_device_factory_->Create(
base::MessageLoopProxy::current(),
device_name);
EXPECT_TRUE(device == NULL); EXPECT_TRUE(device == NULL);
} }
...@@ -187,7 +190,8 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) { ...@@ -187,7 +190,8 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names_.front())); video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
names_.front()));
ASSERT_TRUE(device); ASSERT_TRUE(device);
DVLOG(1) << names_.front().id(); DVLOG(1) << names_.front().id();
...@@ -215,7 +219,8 @@ TEST_F(VideoCaptureDeviceTest, Capture720p) { ...@@ -215,7 +219,8 @@ TEST_F(VideoCaptureDeviceTest, Capture720p) {
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names_.front())); video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
names_.front()));
ASSERT_TRUE(device); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
...@@ -239,7 +244,8 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { ...@@ -239,7 +244,8 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
return; return;
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names_.front())); video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
names_.front()));
ASSERT_TRUE(device); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
...@@ -268,7 +274,8 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { ...@@ -268,7 +274,8 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
for (int i = 0; i <= 5; i++) { for (int i = 0; i <= 5; i++) {
ResetWithNewClient(); ResetWithNewClient();
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names_.front())); video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
names_.front()));
gfx::Size resolution; gfx::Size resolution;
if (i % 2) { if (i % 2) {
resolution = gfx::Size(640, 480); resolution = gfx::Size(640, 480);
...@@ -293,7 +300,8 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { ...@@ -293,7 +300,8 @@ TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
ResetWithNewClient(); ResetWithNewClient();
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names_.front())); video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
names_.front()));
device->AllocateAndStart(capture_params, client_.PassAs<Client>()); device->AllocateAndStart(capture_params, client_.PassAs<Client>());
WaitForCapturedFrame(); WaitForCapturedFrame();
...@@ -310,7 +318,8 @@ TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { ...@@ -310,7 +318,8 @@ TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
return; return;
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(names_.front())); video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
names_.front()));
ASSERT_TRUE(device); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
...@@ -339,7 +348,8 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { ...@@ -339,7 +348,8 @@ TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
return; return;
} }
scoped_ptr<VideoCaptureDevice> device( scoped_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->Create(*name)); video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
*name));
ASSERT_TRUE(device); ASSERT_TRUE(device);
EXPECT_CALL(*client_, OnErr()) EXPECT_CALL(*client_, OnErr())
......
...@@ -245,7 +245,9 @@ void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device, ...@@ -245,7 +245,9 @@ void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device,
} }
// static // static
VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { VideoCaptureDevice* VideoCaptureDevice::Create(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const Name& device_name) {
VideoCaptureDevice* ret = NULL; VideoCaptureDevice* ret = NULL;
if (device_name.capture_api_type() == Name::MEDIA_FOUNDATION) { if (device_name.capture_api_type() == Name::MEDIA_FOUNDATION) {
DCHECK(VideoCaptureDeviceMFWin::PlatformSupported()); DCHECK(VideoCaptureDeviceMFWin::PlatformSupported());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment