libcamera: pipeline: uvcvideo: create a V4L2Device for the default video entity

Add a V4L2Device for the default video entity in the media graph. The
UVC pipeline needs to search for the entity marked with the
MEDIA_ENT_FL_DEFAULT flag as the entity names in the media graph varies
depending on which device is used.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Niklas Söderlund 2019-01-25 15:21:05 +01:00
parent 25a2f96a28
commit 67d313240c

View file

@ -10,6 +10,7 @@
#include "device_enumerator.h"
#include "media_device.h"
#include "pipeline_handler.h"
#include "v4l2_device.h"
namespace libcamera {
@ -23,15 +24,19 @@ public:
private:
std::shared_ptr<MediaDevice> media_;
V4L2Device *video_;
};
PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager)
: PipelineHandler(manager), media_(nullptr)
: PipelineHandler(manager), media_(nullptr), video_(nullptr)
{
}
PipelineHandlerUVC::~PipelineHandlerUVC()
{
if (video_)
delete video_;
if (media_)
media_->release();
}
@ -47,6 +52,18 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
media_->acquire();
for (MediaEntity *entity : media_->entities()) {
if (entity->flags() & MEDIA_ENT_FL_DEFAULT) {
video_ = new V4L2Device(*entity);
break;
}
}
if (!video_ || video_->open()) {
media_->release();
return false;
}
std::shared_ptr<Camera> camera = Camera::create(this, media_->model());
registerCamera(std::move(camera));
hotplugMediaDevice(media_.get());