Message ID | 20190301115139.11060-5-jacopo@jmondi.org |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Jacopo, Thank you for the patch. On Fri, Mar 01, 2019 at 12:51:38PM +0100, Jacopo Mondi wrote: > Add support for devices that provide video meta-data to v4l2_device.cpp > and re-arrange bufferType handling in open() method. > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > src/libcamera/include/v4l2_device.h | 26 ++++++++++- > src/libcamera/v4l2_device.cpp | 70 +++++++++++++++++++++-------- > 2 files changed, 76 insertions(+), 20 deletions(-) > > diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h > index 622c9722c992..5c379fac66dc 100644 > --- a/src/libcamera/include/v4l2_device.h > +++ b/src/libcamera/include/v4l2_device.h > @@ -51,13 +51,37 @@ struct V4L2Capability final : v4l2_capability { > bool isCapture() const > { > return device_caps() & (V4L2_CAP_VIDEO_CAPTURE | > - V4L2_CAP_VIDEO_CAPTURE_MPLANE); > + V4L2_CAP_VIDEO_CAPTURE_MPLANE | > + V4L2_CAP_META_CAPTURE); > } > bool isOutput() const > { > return device_caps() & (V4L2_CAP_VIDEO_OUTPUT | > V4L2_CAP_VIDEO_OUTPUT_MPLANE); > } > + bool isVideo() const > + { > + return device_caps() & (V4L2_CAP_VIDEO_CAPTURE | > + V4L2_CAP_VIDEO_CAPTURE_MPLANE | > + V4L2_CAP_VIDEO_OUTPUT | > + V4L2_CAP_VIDEO_OUTPUT_MPLANE); > + } > + bool isMeta() const > + { > + return device_caps() & V4L2_CAP_META_CAPTURE; > + } > + bool isVideoCapture() const > + { > + return isVideo() && isCapture(); > + } > + bool isVideoOutput() const > + { > + return isVideo() && isOutput(); > + } > + bool isMetaCapture() const > + { > + return isMeta() && isCapture(); > + } > bool hasStreaming() const > { > return device_caps() & V4L2_CAP_STREAMING; > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp > index 4c670185bb7c..b19cf9f78029 100644 > --- a/src/libcamera/v4l2_device.cpp > +++ b/src/libcamera/v4l2_device.cpp > @@ -69,14 +69,47 @@ LOG_DEFINE_CATEGORY(V4L2) > > /** > * \fn bool V4L2Capability::isCapture() > - * \brief Identify if the device is capable of capturing video > - * \return True if the device can capture video frames > + * \brief Identify if the device captures data > + * \return True if the device can capture data > */ > > /** > * \fn bool V4L2Capability::isOutput() > - * \brief Identify if the device is capable of outputting video > - * \return True if the device can output video frames > + * \brief Identify if the device outputs data > + * \return True if the device can output data > + */ > + > +/** > + * \fn bool V4L2Capability::isVideo() > + * \brief Identify if the device captures or outputs images > + * \return True if the device can capture or output images > + */ > + > +/** > + * \fn bool V4L2Capability::isMeta() > + * \brief Identify if the device captures or outputs image meta-data > + * > + * \todo Add support for META_CAPTURE introduced in Linux v5.0 > + * > + * \return True if the device can capture or output image meta-data > + */ > + > +/** > + * \fn bool V4L2Capability::isVideoCapture() > + * \brief Identify if the device captures images > + * \return True if the device can capture images > + */ > + > +/** > + * \fn bool V4L2Capability::isVideoOutput() > + * \brief Identify if the device outputs images > + * \return True if the device can output images > + */ > + > +/** > + * \fn bool V4L2Capability::isMetaCapture() > + * \brief Identify if the device captures image meta-data > + * \return True if the device can capture image meta-data > */ > > /** > @@ -280,33 +313,32 @@ int V4L2Device::open() > << "Opened device " << caps_.bus_info() << ": " > << caps_.driver() << ": " << caps_.card(); > > - if (!caps_.isCapture() && !caps_.isOutput()) { > - LOG(V4L2, Debug) << "Device is not a supported type"; > - return -EINVAL; > - } > - > if (!caps_.hasStreaming()) { > LOG(V4L2, Error) << "Device does not support streaming I/O"; > return -EINVAL; > } > > - if (caps_.isCapture()) > + /* > + * Set buffer type and wait for read notifications on CAPTURE devices > + * (POLLIN), and write notifications for OUTPUT devices (POLLOUT). > + */ > + if (caps_.isVideoCapture()) { > + fdEvent_ = new EventNotifier(fd_, EventNotifier::Read); > bufferType_ = caps_.isMultiplanar() > ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE > : V4L2_BUF_TYPE_VIDEO_CAPTURE; > - else > + } else if (caps_.isVideoOutput()) { > + fdEvent_ = new EventNotifier(fd_, EventNotifier::Write); > bufferType_ = caps_.isMultiplanar() > ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE > : V4L2_BUF_TYPE_VIDEO_OUTPUT; > - > - /* > - * We wait for Read notifications on CAPTURE devices (POLLIN), and > - * Write notifications for OUTPUT devices (POLLOUT). > - */ > - if (caps_.isCapture()) > + } else if (caps_.isMetaCapture()) { > fdEvent_ = new EventNotifier(fd_, EventNotifier::Read); > - else > - fdEvent_ = new EventNotifier(fd_, EventNotifier::Write); > + bufferType_ = V4L2_BUF_TYPE_META_CAPTURE; > + } else { > + LOG(V4L2, Debug) << "Device is not a supported type"; > + return -EINVAL; > + } > > fdEvent_->activated.connect(this, &V4L2Device::bufferAvailable); > fdEvent_->setEnabled(false);
diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 622c9722c992..5c379fac66dc 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -51,13 +51,37 @@ struct V4L2Capability final : v4l2_capability { bool isCapture() const { return device_caps() & (V4L2_CAP_VIDEO_CAPTURE | - V4L2_CAP_VIDEO_CAPTURE_MPLANE); + V4L2_CAP_VIDEO_CAPTURE_MPLANE | + V4L2_CAP_META_CAPTURE); } bool isOutput() const { return device_caps() & (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE); } + bool isVideo() const + { + return device_caps() & (V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_VIDEO_CAPTURE_MPLANE | + V4L2_CAP_VIDEO_OUTPUT | + V4L2_CAP_VIDEO_OUTPUT_MPLANE); + } + bool isMeta() const + { + return device_caps() & V4L2_CAP_META_CAPTURE; + } + bool isVideoCapture() const + { + return isVideo() && isCapture(); + } + bool isVideoOutput() const + { + return isVideo() && isOutput(); + } + bool isMetaCapture() const + { + return isMeta() && isCapture(); + } bool hasStreaming() const { return device_caps() & V4L2_CAP_STREAMING; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 4c670185bb7c..b19cf9f78029 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -69,14 +69,47 @@ LOG_DEFINE_CATEGORY(V4L2) /** * \fn bool V4L2Capability::isCapture() - * \brief Identify if the device is capable of capturing video - * \return True if the device can capture video frames + * \brief Identify if the device captures data + * \return True if the device can capture data */ /** * \fn bool V4L2Capability::isOutput() - * \brief Identify if the device is capable of outputting video - * \return True if the device can output video frames + * \brief Identify if the device outputs data + * \return True if the device can output data + */ + +/** + * \fn bool V4L2Capability::isVideo() + * \brief Identify if the device captures or outputs images + * \return True if the device can capture or output images + */ + +/** + * \fn bool V4L2Capability::isMeta() + * \brief Identify if the device captures or outputs image meta-data + * + * \todo Add support for META_CAPTURE introduced in Linux v5.0 + * + * \return True if the device can capture or output image meta-data + */ + +/** + * \fn bool V4L2Capability::isVideoCapture() + * \brief Identify if the device captures images + * \return True if the device can capture images + */ + +/** + * \fn bool V4L2Capability::isVideoOutput() + * \brief Identify if the device outputs images + * \return True if the device can output images + */ + +/** + * \fn bool V4L2Capability::isMetaCapture() + * \brief Identify if the device captures image meta-data + * \return True if the device can capture image meta-data */ /** @@ -280,33 +313,32 @@ int V4L2Device::open() << "Opened device " << caps_.bus_info() << ": " << caps_.driver() << ": " << caps_.card(); - if (!caps_.isCapture() && !caps_.isOutput()) { - LOG(V4L2, Debug) << "Device is not a supported type"; - return -EINVAL; - } - if (!caps_.hasStreaming()) { LOG(V4L2, Error) << "Device does not support streaming I/O"; return -EINVAL; } - if (caps_.isCapture()) + /* + * Set buffer type and wait for read notifications on CAPTURE devices + * (POLLIN), and write notifications for OUTPUT devices (POLLOUT). + */ + if (caps_.isVideoCapture()) { + fdEvent_ = new EventNotifier(fd_, EventNotifier::Read); bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : V4L2_BUF_TYPE_VIDEO_CAPTURE; - else + } else if (caps_.isVideoOutput()) { + fdEvent_ = new EventNotifier(fd_, EventNotifier::Write); bufferType_ = caps_.isMultiplanar() ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : V4L2_BUF_TYPE_VIDEO_OUTPUT; - - /* - * We wait for Read notifications on CAPTURE devices (POLLIN), and - * Write notifications for OUTPUT devices (POLLOUT). - */ - if (caps_.isCapture()) + } else if (caps_.isMetaCapture()) { fdEvent_ = new EventNotifier(fd_, EventNotifier::Read); - else - fdEvent_ = new EventNotifier(fd_, EventNotifier::Write); + bufferType_ = V4L2_BUF_TYPE_META_CAPTURE; + } else { + LOG(V4L2, Debug) << "Device is not a supported type"; + return -EINVAL; + } fdEvent_->activated.connect(this, &V4L2Device::bufferAvailable); fdEvent_->setEnabled(false);