libcamera: v4l2_videodevice: Match formats supported by the device

Now that V4L2PixelFormat::fromPixelFormat() returns a list of formats
to chose from, select the one supported by the video device by matching
against the list of supported pixel formats.

The first format found to match one of the device supported ones is
returned.

As the list of pixel formats supported by the video device does not
change at run-time, cache it at device open() time. Maximize the
lookup efficiency by storing the list of supported V4L2PixelFormat in an
std::unordered_set<>.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
Jacopo Mondi 2022-07-15 13:47:01 +02:00
parent 29c09e3ab6
commit d1abe2bdc8
2 changed files with 49 additions and 12 deletions

View file

@ -14,6 +14,7 @@
#include <ostream>
#include <stdint.h>
#include <string>
#include <unordered_set>
#include <vector>
#include <linux/videodev2.h>
@ -242,6 +243,8 @@ private:
Stopped,
};
int initFormats();
int getFormatMeta(V4L2DeviceFormat *format);
int trySetFormatMeta(V4L2DeviceFormat *format, bool set);
@ -268,6 +271,7 @@ private:
V4L2Capability caps_;
V4L2DeviceFormat format_;
const PixelFormatInfo *formatInfo_;
std::unordered_set<V4L2PixelFormat> pixelFormats_;
enum v4l2_buf_type bufferType_;
enum v4l2_memory memoryType_;