test: v4l2_device: Use DeviceEnumerator to find a UVCVideo
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> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
83148ce8be
commit
93ec63b867
2 changed files with 38 additions and 7 deletions
|
@ -10,6 +10,10 @@
|
||||||
|
|
||||||
#include "v4l2_device_test.h"
|
#include "v4l2_device_test.h"
|
||||||
|
|
||||||
|
#include "device_enumerator.h"
|
||||||
|
#include "media_device.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
bool exists(const std::string &path)
|
bool exists(const std::string &path)
|
||||||
|
@ -24,20 +28,40 @@ bool exists(const std::string &path)
|
||||||
|
|
||||||
int V4L2DeviceTest::init()
|
int V4L2DeviceTest::init()
|
||||||
{
|
{
|
||||||
const std::string device("/dev/video0");
|
enumerator_ = DeviceEnumerator::create();
|
||||||
|
if (!enumerator_) {
|
||||||
/* Validate the device node exists. */
|
cerr << "Failed to create device enumerator" << endl;
|
||||||
if (!exists(device)) {
|
return TestFail;
|
||||||
std::cout << "No video device available" << std::endl;
|
|
||||||
return TestSkip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_ = new V4L2Device(device);
|
if (enumerator_->enumerate()) {
|
||||||
|
cerr << "Failed to enumerate media devices" << endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceMatch dm("uvcvideo");
|
||||||
|
media_ = std::move(enumerator_->search(dm));
|
||||||
|
if (!media_)
|
||||||
|
return TestSkip;
|
||||||
|
|
||||||
|
media_->acquire();
|
||||||
|
|
||||||
|
for (MediaEntity *entity : media_->entities()) {
|
||||||
|
if (entity->flags() & MEDIA_ENT_FL_DEFAULT) {
|
||||||
|
dev_ = new V4L2Device(entity);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dev_)
|
||||||
|
return TestSkip;
|
||||||
|
|
||||||
return dev_->open();
|
return dev_->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
void V4L2DeviceTest::cleanup()
|
void V4L2DeviceTest::cleanup()
|
||||||
{
|
{
|
||||||
|
media_->release();
|
||||||
|
|
||||||
delete dev_;
|
delete dev_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,12 @@
|
||||||
#ifndef __LIBCAMERA_V4L2_DEVICE_TEST_H_
|
#ifndef __LIBCAMERA_V4L2_DEVICE_TEST_H_
|
||||||
#define __LIBCAMERA_V4L2_DEVICE_TEST_H_
|
#define __LIBCAMERA_V4L2_DEVICE_TEST_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
|
#include "device_enumerator.h"
|
||||||
|
#include "media_device.h"
|
||||||
#include "v4l2_device.h"
|
#include "v4l2_device.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
@ -21,6 +26,8 @@ protected:
|
||||||
int init();
|
int init();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
std::unique_ptr<DeviceEnumerator> enumerator_;
|
||||||
|
std::shared_ptr<MediaDevice> media_;
|
||||||
V4L2Device *dev_;
|
V4L2Device *dev_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue