[libcamera-devel,01/11] test: v4l2_device: Use DeviceEnumerator to find a UVCVideo

Message ID 20190203110102.5663-2-kieran.bingham@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: V4L2 Streams
Related show

Commit Message

Kieran Bingham Feb. 3, 2019, 11 a.m. UTC
Utilise the existing DeviceEnumerator system to identify a suitable
V4L2Device for testing.

Specifically target these tests at a uvcvideo driver based device as a known
supported target.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 test/v4l2_device/v4l2_device_test.cpp | 28 +++++++++++++++++++++------
 test/v4l2_device/v4l2_device_test.h   |  7 +++++++
 2 files changed, 29 insertions(+), 6 deletions(-)

Patch

diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp
index 362553712caa..e71a93cf2453 100644
--- a/test/v4l2_device/v4l2_device_test.cpp
+++ b/test/v4l2_device/v4l2_device_test.cpp
@@ -10,6 +10,10 @@ 
 
 #include "v4l2_device_test.h"
 
+#include "device_enumerator.h"
+#include "media_device.h"
+
+using namespace std;
 using namespace libcamera;
 
 bool exists(const std::string &path)
@@ -24,20 +28,32 @@  bool exists(const std::string &path)
 
 int V4L2DeviceTest::init()
 {
-	const std::string device("/dev/video0");
+	enumerator_ = DeviceEnumerator::create();
+	if (!enumerator_) {
+		cerr << "Failed to create device enumerator" << endl;
+		return TestFail;
+	}
 
-	/* Validate the device node exists. */
-	if (!exists(device)) {
-		std::cout << "No video device available" << std::endl;
-		return TestSkip;
+	if (enumerator_->enumerate()) {
+		cerr << "Failed to enumerate media devices" << endl;
+		return TestFail;
 	}
 
-	dev_ = new V4L2Device(device);
+	DeviceMatch dm("uvcvideo");
+	media_ = std::move(enumerator_->search(dm));
+	if (!media_)
+		return TestSkip;
+
+	media_->acquire();
+
+	dev_ = new V4L2Device(*media_->entities()[0]);
 
 	return dev_->open();
 }
 
 void V4L2DeviceTest::cleanup()
 {
+	media_->release();
+
 	delete dev_;
 };
diff --git a/test/v4l2_device/v4l2_device_test.h b/test/v4l2_device/v4l2_device_test.h
index 405cb7d6f404..d8652a5c9e15 100644
--- a/test/v4l2_device/v4l2_device_test.h
+++ b/test/v4l2_device/v4l2_device_test.h
@@ -7,7 +7,12 @@ 
 #ifndef __LIBCAMERA_V4L2_DEVICE_TEST_H_
 #define __LIBCAMERA_V4L2_DEVICE_TEST_H_
 
+#include <unistd.h>
+
 #include "test.h"
+
+#include "device_enumerator.h"
+#include "media_device.h"
 #include "v4l2_device.h"
 
 using namespace libcamera;
@@ -21,6 +26,8 @@  protected:
 	int init();
 	void cleanup();
 
+	std::unique_ptr<DeviceEnumerator> enumerator_;
+	std::shared_ptr<MediaDevice> media_;
 	V4L2Device *dev_;
 };