| Index: media/video/capture/video_capture_device_unittest.cc
|
| ===================================================================
|
| --- media/video/capture/video_capture_device_unittest.cc (revision 269380)
|
| +++ media/video/capture/video_capture_device_unittest.cc (working copy)
|
| @@ -3,12 +3,15 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/run_loop.h"
|
| +#include "base/synchronization/waitable_event.h"
|
| #include "base/test/test_timeouts.h"
|
| #include "base/threading/thread.h"
|
| +#include "media/video/capture/fake_video_capture_device.h"
|
| +#include "media/video/capture/fake_video_capture_device_factory.h"
|
| #include "media/video/capture/video_capture_device.h"
|
| -#include "media/video/capture/video_capture_device_factory.h"
|
| #include "media/video/capture/video_capture_types.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -50,6 +53,11 @@
|
| #define MAYBE_CaptureMjpeg CaptureMjpeg
|
| #endif
|
|
|
| +using ::testing::_;
|
| +using ::testing::AnyNumber;
|
| +using ::testing::Return;
|
| +using ::testing::AtLeast;
|
| +
|
| namespace media {
|
|
|
| class MockClient : public media::VideoCaptureDevice::Client {
|
| @@ -96,8 +104,7 @@
|
| client_(
|
| new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured,
|
| base::Unretained(this)))),
|
| - video_capture_device_factory_(
|
| - VideoCaptureDeviceFactory::CreateFactory()) {}
|
| + video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {}
|
|
|
| virtual void SetUp() {
|
| #if defined(OS_ANDROID)
|
| @@ -125,7 +132,7 @@
|
|
|
| scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat(
|
| const VideoPixelFormat& pixel_format) {
|
| - video_capture_device_factory_->GetDeviceNames(&names_);
|
| + VideoCaptureDevice::GetDeviceNames(&names_);
|
| if (!names_.size()) {
|
| DVLOG(1) << "No camera available.";
|
| return scoped_ptr<VideoCaptureDevice::Name>();
|
| @@ -134,9 +141,8 @@
|
| for (names_iterator = names_.begin(); names_iterator != names_.end();
|
| ++names_iterator) {
|
| VideoCaptureFormats supported_formats;
|
| - video_capture_device_factory_->GetDeviceSupportedFormats(
|
| - *names_iterator,
|
| - &supported_formats);
|
| + VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator,
|
| + &supported_formats);
|
| VideoCaptureFormats::iterator formats_iterator;
|
| for (formats_iterator = supported_formats.begin();
|
| formats_iterator != supported_formats.end(); ++formats_iterator) {
|
| @@ -168,26 +174,22 @@
|
| ? VideoCaptureDevice::Name::MEDIA_FOUNDATION
|
| : VideoCaptureDevice::Name::DIRECT_SHOW;
|
| VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type);
|
| -#elif defined(OS_MACOSX)
|
| - VideoCaptureDevice::Name device_name("jibberish", "jibberish",
|
| - VideoCaptureDevice::Name::AVFOUNDATION);
|
| #else
|
| VideoCaptureDevice::Name device_name("jibberish", "jibberish");
|
| #endif
|
| - scoped_ptr<VideoCaptureDevice> device =
|
| - video_capture_device_factory_->Create(device_name);
|
| + VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name);
|
| EXPECT_TRUE(device == NULL);
|
| }
|
|
|
| TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
|
| - video_capture_device_factory_->GetDeviceNames(&names_);
|
| + VideoCaptureDevice::GetDeviceNames(&names_);
|
| if (!names_.size()) {
|
| DVLOG(1) << "No camera available. Exiting test.";
|
| return;
|
| }
|
|
|
| scoped_ptr<VideoCaptureDevice> device(
|
| - video_capture_device_factory_->Create(names_.front()));
|
| + VideoCaptureDevice::Create(names_.front()));
|
| ASSERT_TRUE(device);
|
| DVLOG(1) << names_.front().id();
|
|
|
| @@ -208,14 +210,14 @@
|
| }
|
|
|
| TEST_F(VideoCaptureDeviceTest, Capture720p) {
|
| - video_capture_device_factory_->GetDeviceNames(&names_);
|
| + VideoCaptureDevice::GetDeviceNames(&names_);
|
| if (!names_.size()) {
|
| DVLOG(1) << "No camera available. Exiting test.";
|
| return;
|
| }
|
|
|
| scoped_ptr<VideoCaptureDevice> device(
|
| - video_capture_device_factory_->Create(names_.front()));
|
| + VideoCaptureDevice::Create(names_.front()));
|
| ASSERT_TRUE(device);
|
|
|
| EXPECT_CALL(*client_, OnErr())
|
| @@ -233,13 +235,13 @@
|
| }
|
|
|
| TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
|
| - video_capture_device_factory_->GetDeviceNames(&names_);
|
| + VideoCaptureDevice::GetDeviceNames(&names_);
|
| if (!names_.size()) {
|
| DVLOG(1) << "No camera available. Exiting test.";
|
| return;
|
| }
|
| scoped_ptr<VideoCaptureDevice> device(
|
| - video_capture_device_factory_->Create(names_.front()));
|
| + VideoCaptureDevice::Create(names_.front()));
|
| ASSERT_TRUE(device);
|
|
|
| EXPECT_CALL(*client_, OnErr())
|
| @@ -258,7 +260,7 @@
|
| }
|
|
|
| TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
|
| - video_capture_device_factory_->GetDeviceNames(&names_);
|
| + VideoCaptureDevice::GetDeviceNames(&names_);
|
| if (!names_.size()) {
|
| DVLOG(1) << "No camera available. Exiting test.";
|
| return;
|
| @@ -268,7 +270,7 @@
|
| for (int i = 0; i <= 5; i++) {
|
| ResetWithNewClient();
|
| scoped_ptr<VideoCaptureDevice> device(
|
| - video_capture_device_factory_->Create(names_.front()));
|
| + VideoCaptureDevice::Create(names_.front()));
|
| gfx::Size resolution;
|
| if (i % 2) {
|
| resolution = gfx::Size(640, 480);
|
| @@ -293,7 +295,7 @@
|
|
|
| ResetWithNewClient();
|
| scoped_ptr<VideoCaptureDevice> device(
|
| - video_capture_device_factory_->Create(names_.front()));
|
| + VideoCaptureDevice::Create(names_.front()));
|
|
|
| device->AllocateAndStart(capture_params, client_.PassAs<Client>());
|
| WaitForCapturedFrame();
|
| @@ -304,13 +306,13 @@
|
| }
|
|
|
| TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
|
| - video_capture_device_factory_->GetDeviceNames(&names_);
|
| + VideoCaptureDevice::GetDeviceNames(&names_);
|
| if (!names_.size()) {
|
| DVLOG(1) << "No camera available. Exiting test.";
|
| return;
|
| }
|
| scoped_ptr<VideoCaptureDevice> device(
|
| - video_capture_device_factory_->Create(names_.front()));
|
| + VideoCaptureDevice::Create(names_.front()));
|
| ASSERT_TRUE(device);
|
|
|
| EXPECT_CALL(*client_, OnErr())
|
| @@ -330,6 +332,33 @@
|
| device->StopAndDeAllocate();
|
| }
|
|
|
| +TEST_F(VideoCaptureDeviceTest, FakeCapture) {
|
| + VideoCaptureDevice::Names names;
|
| +
|
| + video_capture_device_factory_->GetDeviceNames(&names);
|
| +
|
| + ASSERT_GT(static_cast<int>(names.size()), 0);
|
| +
|
| + scoped_ptr<VideoCaptureDevice> device(
|
| + video_capture_device_factory_->Create(names.front()));
|
| + ASSERT_TRUE(device);
|
| +
|
| + EXPECT_CALL(*client_, OnErr())
|
| + .Times(0);
|
| +
|
| + VideoCaptureParams capture_params;
|
| + capture_params.requested_format.frame_size.SetSize(640, 480);
|
| + capture_params.requested_format.frame_rate = 30;
|
| + capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
|
| + capture_params.allow_resolution_change = false;
|
| + device->AllocateAndStart(capture_params, client_.PassAs<Client>());
|
| + WaitForCapturedFrame();
|
| + EXPECT_EQ(last_format().frame_size.width(), 640);
|
| + EXPECT_EQ(last_format().frame_size.height(), 480);
|
| + EXPECT_EQ(last_format().frame_rate, 30);
|
| + device->StopAndDeAllocate();
|
| +}
|
| +
|
| // Start the camera in 720p to capture MJPEG instead of a raw format.
|
| TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
|
| scoped_ptr<VideoCaptureDevice::Name> name =
|
| @@ -338,8 +367,7 @@
|
| DVLOG(1) << "No camera supports MJPEG format. Exiting test.";
|
| return;
|
| }
|
| - scoped_ptr<VideoCaptureDevice> device(
|
| - video_capture_device_factory_->Create(*name));
|
| + scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name));
|
| ASSERT_TRUE(device);
|
|
|
| EXPECT_CALL(*client_, OnErr())
|
| @@ -369,4 +397,68 @@
|
| ASSERT_FALSE(name);
|
| }
|
|
|
| +TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) {
|
| + VideoCaptureDevice::Names names;
|
| +
|
| + video_capture_device_factory_->GetDeviceNames(&names);
|
| + VideoCaptureParams capture_params;
|
| + capture_params.requested_format.frame_size.SetSize(640, 480);
|
| + capture_params.requested_format.frame_rate = 30;
|
| + capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
|
| + capture_params.allow_resolution_change = true;
|
| +
|
| + ASSERT_GT(static_cast<int>(names.size()), 0);
|
| +
|
| + scoped_ptr<VideoCaptureDevice> device(
|
| + video_capture_device_factory_->Create(names.front()));
|
| + ASSERT_TRUE(device);
|
| +
|
| + // Configure the FakeVideoCaptureDevice to use all its formats as roster.
|
| + VideoCaptureFormats formats;
|
| + video_capture_device_factory_->GetDeviceSupportedFormats(names.front(),
|
| + &formats);
|
| + static_cast<FakeVideoCaptureDevice*>(device.get())->
|
| + PopulateVariableFormatsRoster(formats);
|
| +
|
| + EXPECT_CALL(*client_, OnErr())
|
| + .Times(0);
|
| + int action_count = 200;
|
| +
|
| + device->AllocateAndStart(capture_params, client_.PassAs<Client>());
|
| +
|
| + // We set TimeWait to 200 action timeouts and this should be enough for at
|
| + // least action_count/kFakeCaptureCapabilityChangePeriod calls.
|
| + for (int i = 0; i < action_count; ++i) {
|
| + WaitForCapturedFrame();
|
| + }
|
| + device->StopAndDeAllocate();
|
| +}
|
| +
|
| +TEST_F(VideoCaptureDeviceTest, FakeGetDeviceSupportedFormats) {
|
| + VideoCaptureDevice::Names names;
|
| + video_capture_device_factory_->GetDeviceNames(&names);
|
| +
|
| + VideoCaptureFormats supported_formats;
|
| + VideoCaptureDevice::Names::iterator names_iterator;
|
| +
|
| + for (names_iterator = names.begin(); names_iterator != names.end();
|
| + ++names_iterator) {
|
| + video_capture_device_factory_->GetDeviceSupportedFormats(
|
| + *names_iterator, &supported_formats);
|
| + EXPECT_EQ(supported_formats.size(), 3u);
|
| + EXPECT_EQ(supported_formats[0].frame_size.width(), 320);
|
| + EXPECT_EQ(supported_formats[0].frame_size.height(), 240);
|
| + EXPECT_EQ(supported_formats[0].pixel_format, media::PIXEL_FORMAT_I420);
|
| + EXPECT_GE(supported_formats[0].frame_rate, 20);
|
| + EXPECT_EQ(supported_formats[1].frame_size.width(), 640);
|
| + EXPECT_EQ(supported_formats[1].frame_size.height(), 480);
|
| + EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420);
|
| + EXPECT_GE(supported_formats[1].frame_rate, 20);
|
| + EXPECT_EQ(supported_formats[2].frame_size.width(), 1280);
|
| + EXPECT_EQ(supported_formats[2].frame_size.height(), 720);
|
| + EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420);
|
| + EXPECT_GE(supported_formats[2].frame_rate, 20);
|
| + }
|
| +}
|
| +
|
| }; // namespace media
|
|
|