Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(764)

Unified Diff: media/capture/video/video_capture_device_unittest.cc

Issue 2320873002: Revert of Video capture Android: enable unittests for Camera2 API (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/capture/video/android/video_capture_device_factory_android.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/capture/video/video_capture_device_unittest.cc
diff --git a/media/capture/video/video_capture_device_unittest.cc b/media/capture/video/video_capture_device_unittest.cc
index f752360a1c34c96c012bac03492825fef38318de..a684a3b7e5b3e8c5bcee5af06b32e0fe8823709f 100644
--- a/media/capture/video/video_capture_device_unittest.cc
+++ b/media/capture/video/video_capture_device_unittest.cc
@@ -39,7 +39,6 @@
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"
#include "media/capture/video/android/video_capture_device_android.h"
-#include "media/capture/video/android/video_capture_device_factory_android.h"
#endif
#if defined(OS_MACOSX)
@@ -53,8 +52,14 @@
#define MAYBE_CaptureMjpeg CaptureMjpeg
#define MAYBE_TakePhoto DISABLED_TakePhoto
#elif defined(OS_ANDROID)
-#define MAYBE_AllocateBadSize AllocateBadSize
-#define MAYBE_CaptureMjpeg CaptureMjpeg
+// TODO(wjia): enable those tests on Android.
+// On Android, native camera (JAVA) delivers frames on UI thread which is the
+// main thread for tests. This results in no frame received by
+// VideoCaptureAndroid.
+#define MAYBE_AllocateBadSize DISABLED_AllocateBadSize
+#define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning
+#define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning
+#define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg
#define MAYBE_TakePhoto DISABLED_TakePhoto
#elif defined(OS_LINUX)
// AllocateBadSize will hang when a real camera is attached and if more than one
@@ -99,7 +104,7 @@
base::TimeTicks reference_time,
base::TimeDelta timestamp) override {
ASSERT_GT(length, 0);
- ASSERT_TRUE(data);
+ ASSERT_TRUE(data != NULL);
main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format));
}
@@ -163,12 +168,12 @@
class DeviceEnumerationListener
: public base::RefCounted<DeviceEnumerationListener> {
public:
- MOCK_METHOD1(DoOnEnumerateDeviceDescriptors,
+ MOCK_METHOD1(OnEnumerateDeviceDescriptorsCallbackPtr,
void(VideoCaptureDeviceDescriptors* device_descriptors));
// GMock doesn't support move-only arguments, so we use this forward method.
- void OnEnumerateDeviceDescriptors(
+ void OnEnumerateDeviceDescriptorsCallback(
std::unique_ptr<VideoCaptureDeviceDescriptors> device_descriptors) {
- DoOnEnumerateDeviceDescriptors(device_descriptors.release());
+ OnEnumerateDeviceDescriptorsCallbackPtr(device_descriptors.release());
}
private:
@@ -196,10 +201,6 @@
#if defined(OS_ANDROID)
VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(
base::android::AttachCurrentThread());
-
- static_cast<VideoCaptureDeviceFactoryAndroid*>(
- video_capture_device_factory_.get())
- ->ConfigureForTesting();
#endif
#if defined(OS_MACOSX)
AVFoundationGlue::InitializeAVFoundation();
@@ -225,35 +226,17 @@
run_loop_->Run();
}
- bool EnumerateAndFindUsableDevices() {
- VideoCaptureDeviceDescriptors* descriptors = nullptr;
+ std::unique_ptr<VideoCaptureDeviceDescriptors> EnumerateDeviceDescriptors() {
+ VideoCaptureDeviceDescriptors* device_descriptors;
EXPECT_CALL(*device_enumeration_listener_.get(),
- DoOnEnumerateDeviceDescriptors(_))
- .WillOnce(SaveArg<0>(&descriptors));
-
- video_capture_device_factory_->EnumerateDeviceDescriptors(
- base::Bind(&DeviceEnumerationListener::OnEnumerateDeviceDescriptors,
- device_enumeration_listener_));
+ OnEnumerateDeviceDescriptorsCallbackPtr(_))
+ .WillOnce(SaveArg<0>(&device_descriptors));
+
+ video_capture_device_factory_->EnumerateDeviceDescriptors(base::Bind(
+ &DeviceEnumerationListener::OnEnumerateDeviceDescriptorsCallback,
+ device_enumeration_listener_));
base::RunLoop().RunUntilIdle();
-
- device_descriptors_.reset(descriptors);
- if (!device_descriptors_)
- return false;
-
-#if defined(OS_ANDROID)
- // Android deprecated/legacy devices capture on a single thread, which is
- // occupied by the tests, so nothing gets actually delivered.
- // TODO(mcasas): use those devices' test mode to deliver frames in a
- // background thread, https://crbug.com/626857
- for (const auto& descriptor : *descriptors) {
- if (VideoCaptureDeviceFactoryAndroid::IsLegacyOrDeprecatedDevice(
- descriptor.device_id)) {
- return false;
- }
- }
-#endif
-
- return !device_descriptors_->empty();
+ return std::unique_ptr<VideoCaptureDeviceDescriptors>(device_descriptors);
}
const VideoCaptureFormat& last_format() const { return last_format_; }
@@ -261,22 +244,25 @@
std::unique_ptr<VideoCaptureDeviceDescriptor>
GetFirstDeviceDescriptorSupportingPixelFormat(
const VideoPixelFormat& pixel_format) {
- if (!EnumerateAndFindUsableDevices())
- return nullptr;
-
- for (const auto& descriptor : *device_descriptors_) {
+ device_descriptors_ = EnumerateDeviceDescriptors();
+ if (device_descriptors_->empty()) {
+ DVLOG(1) << "No camera available.";
+ return std::unique_ptr<VideoCaptureDeviceDescriptor>();
+ }
+ for (const auto& descriptors_iterator : *device_descriptors_) {
VideoCaptureFormats supported_formats;
- video_capture_device_factory_->GetSupportedFormats(descriptor,
+ video_capture_device_factory_->GetSupportedFormats(descriptors_iterator,
&supported_formats);
for (const auto& formats_iterator : supported_formats) {
if (formats_iterator.pixel_format == pixel_format) {
return std::unique_ptr<VideoCaptureDeviceDescriptor>(
- new VideoCaptureDeviceDescriptor(descriptor));
+ new VideoCaptureDeviceDescriptor(descriptors_iterator));
}
}
}
DVLOG_IF(1, pixel_format != PIXEL_FORMAT_MAX)
- << VideoPixelFormatToString(pixel_format);
+ << "No camera can capture the"
+ << " format: " << VideoPixelFormatToString(pixel_format);
return std::unique_ptr<VideoCaptureDeviceDescriptor>();
}
@@ -315,7 +301,7 @@
#else
#define MAYBE_OpenInvalidDevice OpenInvalidDevice
#endif
-// Tries to allocate an invalid device and verifies it doesn't work.
+
TEST_F(VideoCaptureDeviceTest, MAYBE_OpenInvalidDevice) {
VideoCaptureDeviceDescriptor invalid_descriptor;
invalid_descriptor.device_id = "jibberish";
@@ -332,7 +318,7 @@
video_capture_device_factory_->CreateDevice(invalid_descriptor);
#if !defined(OS_MACOSX)
- EXPECT_FALSE(device);
+ EXPECT_TRUE(device == NULL);
#else
// The presence of the actual device is only checked on AllocateAndStart()
// and not on creation.
@@ -347,10 +333,12 @@
#endif
}
-// Allocates the first enumerated device, and expects a frame.
TEST_P(VideoCaptureDeviceTest, CaptureWithSize) {
- if (!EnumerateAndFindUsableDevices())
- return;
+ device_descriptors_ = EnumerateDeviceDescriptors();
+ if (device_descriptors_->empty()) {
+ VLOG(1) << "No camera available. Exiting test.";
+ return;
+ }
const gfx::Size& size = GetParam();
if (!IsCaptureSizeSupported(device_descriptors_->front(), size))
@@ -362,6 +350,7 @@
video_capture_device_factory_->CreateDevice(
device_descriptors_->front()));
ASSERT_TRUE(device);
+ DVLOG(1) << device_descriptors_->front().device_id;
EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
@@ -370,28 +359,29 @@
capture_params.requested_format.frame_rate = 30.0f;
capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
device->AllocateAndStart(capture_params, std::move(video_capture_client_));
-
+ // Get captured video frames.
WaitForCapturedFrame();
EXPECT_EQ(last_format().frame_size.width(), width);
EXPECT_EQ(last_format().frame_size.height(), height);
if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea());
- EXPECT_EQ(last_format().frame_rate, 30);
- device->StopAndDeAllocate();
-}
-
+ device->StopAndDeAllocate();
+}
+
+#if !defined(OS_ANDROID)
const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)};
INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests,
VideoCaptureDeviceTest,
testing::ValuesIn(kCaptureSizes));
-
-// Allocates a device with an uncommon resolution and verifies frames are
-// captured in a close, much more typical one.
+#endif
+
TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
- if (!EnumerateAndFindUsableDevices())
- return;
-
+ device_descriptors_ = EnumerateDeviceDescriptors();
+ if (device_descriptors_->empty()) {
+ VLOG(1) << "No camera available. Exiting test.";
+ return;
+ }
std::unique_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->CreateDevice(
device_descriptors_->front()));
@@ -413,10 +403,13 @@
EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea());
}
-// Cause hangs on Windows, Linux. Fails Android. https://crbug.com/417824
+// Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824
TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) {
- if (!EnumerateAndFindUsableDevices())
- return;
+ device_descriptors_ = EnumerateDeviceDescriptors();
+ if (device_descriptors_->empty()) {
+ VLOG(1) << "No camera available. Exiting test.";
+ return;
+ }
// First, do a number of very fast device start/stops.
for (int i = 0; i <= 5; i++) {
@@ -425,11 +418,11 @@
video_capture_device_factory_->CreateDevice(
device_descriptors_->front()));
gfx::Size resolution;
- if (i % 2)
+ if (i % 2) {
resolution = gfx::Size(640, 480);
- else
+ } else {
resolution = gfx::Size(1280, 1024);
-
+ }
VideoCaptureParams capture_params;
capture_params.requested_format.frame_size = resolution;
capture_params.requested_format.frame_rate = 30;
@@ -457,19 +450,45 @@
EXPECT_EQ(last_format().frame_size.height(), 240);
}
-// Starts the camera in 720p to try and capture MJPEG format.
+TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
+ device_descriptors_ = EnumerateDeviceDescriptors();
+ if (device_descriptors_->empty()) {
+ VLOG(1) << "No camera available. Exiting test.";
+ return;
+ }
+ std::unique_ptr<VideoCaptureDevice> device(
+ video_capture_device_factory_->CreateDevice(
+ device_descriptors_->front()));
+ ASSERT_TRUE(device);
+
+ EXPECT_CALL(*video_capture_client_, OnError(_, _)).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;
+ device->AllocateAndStart(capture_params, std::move(video_capture_client_));
+ // Get captured video frames.
+ 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) {
std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor =
GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MJPEG);
if (!device_descriptor) {
- DVLOG(1) << "No camera supports MJPEG format. Exiting test.";
+ VLOG(1) << "No camera supports MJPEG format. Exiting test.";
return;
}
#if defined(OS_WIN)
base::win::Version version = base::win::GetVersion();
+ VLOG(1) << "Windows version: " << (int)version;
if (version >= base::win::VERSION_WIN10) {
- VLOG(1) << "Skipped on Win10: http://crbug.com/570604, current: "
- << static_cast<int>(version);
+ VLOG(1) << "Skipped on Win10: http://crbug.com/570604.";
return;
}
#endif
@@ -484,7 +503,7 @@
capture_params.requested_format.frame_rate = 30;
capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
device->AllocateAndStart(capture_params, std::move(video_capture_client_));
-
+ // Get captured video frames.
WaitForCapturedFrame();
// Verify we get MJPEG from the device. Not all devices can capture 1280x720
// @ 30 fps, so we don't care about the exact resolution we get.
@@ -494,7 +513,7 @@
device->StopAndDeAllocate();
}
-TEST_F(VideoCaptureDeviceTest, NoCameraSupportsPixelFormatMax) {
+TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
// Use PIXEL_FORMAT_MAX to iterate all device names for testing
// GetDeviceSupportedFormats().
std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor =
@@ -504,11 +523,13 @@
ASSERT_FALSE(device_descriptor);
}
-// Starts the camera and take a photo.
+// Start the camera and take a photo.
TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) {
- if (!EnumerateAndFindUsableDevices())
- return;
-
+ device_descriptors_ = EnumerateDeviceDescriptors();
+ if (device_descriptors_->empty()) {
+ VLOG(1) << "No camera available. Exiting test.";
+ return;
+ }
std::unique_ptr<VideoCaptureDevice> device(
video_capture_device_factory_->CreateDevice(
device_descriptors_->front()));
« no previous file with comments | « media/capture/video/android/video_capture_device_factory_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698