| Message ID | 20261016202818.1405645-10-halfline@gmail.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
On Fri, Oct 16, 2026 at 04:28:16PM -0400, Ray Strode wrote: > From: Ray Strode <rstrode@redhat.com> > > This commit allows callers to query optional subdevice selections without > logging an error when the API or target is unsupported. > > Determining the sensor region captured by a pipeline requires checking > whether its intermediate subdevices crop or compose the image. The > selection ioctl or a particular target may be absent on a pass-through > device, and that expected result currently produces an error message. > > Signed-off-by: Ray Strode <rstrode@redhat.com> > --- > include/libcamera/internal/v4l2_subdevice.h | 7 ++++--- > src/libcamera/v4l2_subdevice.cpp | 12 ++++++++++-- > 2 files changed, 14 insertions(+), 5 deletions(-) > > diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h > index c37a82af..41dc80f2 100644 > --- a/include/libcamera/internal/v4l2_subdevice.h > +++ b/include/libcamera/internal/v4l2_subdevice.h > @@ -123,10 +123,11 @@ public: > const MediaEntity *entity() const { return entity_; } > > int getSelection(const Stream &stream, unsigned int target, > - Rectangle *rect); > - int getSelection(unsigned int pad, unsigned int target, Rectangle *rect) > + Rectangle *rect, bool optional = false); > + int getSelection(unsigned int pad, unsigned int target, Rectangle *rect, > + bool optional = false) > { > - return getSelection({ pad, 0 }, target, rect); > + return getSelection({ pad, 0 }, target, rect, optional); > } > int setSelection(const Stream &stream, unsigned int target, > Rectangle *rect); > diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp > index a69de154..2e23f9ad 100644 > --- a/src/libcamera/v4l2_subdevice.cpp > +++ b/src/libcamera/v4l2_subdevice.cpp > @@ -1171,13 +1171,17 @@ int V4L2Subdevice::open() > * \param[in] stream The stream the rectangle is retrieved from > * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags > * \param[out] rect The retrieved selection rectangle > + * \param[in] optional Whether unsupported targets are expected > + * > + * Optional queries return -ENOTTY or -EINVAL without logging an error when > + * the selection API or target is unsupported. Other errors are logged normally. > * > * \todo Define a V4L2SelectionTarget enum for the selection target > * > * \return 0 on success or a negative error code otherwise > */ > int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target, > - Rectangle *rect) > + Rectangle *rect, bool optional) > { > struct v4l2_subdev_selection sel = {}; > > @@ -1189,6 +1193,9 @@ int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target, > > int ret = ioctl(VIDIOC_SUBDEV_G_SELECTION, &sel); > if (ret < 0) { > + if (optional && (ret == -ENOTTY || ret == -EINVAL)) > + return ret; > + > LOG(V4L2, Error) > << "Unable to get rectangle " << target << " on pad " > << stream << ": " << strerror(-ret); > @@ -1205,11 +1212,12 @@ int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target, > > /** > * \fn V4L2Subdevice::getSelection(unsigned int pad, unsigned int target, > - * Rectangle *rect) > + * Rectangle *rect, bool optional) > * \brief Get selection rectangle \a rect for \a target > * \param[in] pad The 0-indexed pad number the rectangle is retrieved from > * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags > * \param[out] rect The retrieved selection rectangle > + * \param[in] optional Whether unsupported targets are expected That's not good API design. > * > * \return 0 on success or a negative error code otherwise > */
diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index c37a82af..41dc80f2 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -123,10 +123,11 @@ public: const MediaEntity *entity() const { return entity_; } int getSelection(const Stream &stream, unsigned int target, - Rectangle *rect); - int getSelection(unsigned int pad, unsigned int target, Rectangle *rect) + Rectangle *rect, bool optional = false); + int getSelection(unsigned int pad, unsigned int target, Rectangle *rect, + bool optional = false) { - return getSelection({ pad, 0 }, target, rect); + return getSelection({ pad, 0 }, target, rect, optional); } int setSelection(const Stream &stream, unsigned int target, Rectangle *rect); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index a69de154..2e23f9ad 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1171,13 +1171,17 @@ int V4L2Subdevice::open() * \param[in] stream The stream the rectangle is retrieved from * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags * \param[out] rect The retrieved selection rectangle + * \param[in] optional Whether unsupported targets are expected + * + * Optional queries return -ENOTTY or -EINVAL without logging an error when + * the selection API or target is unsupported. Other errors are logged normally. * * \todo Define a V4L2SelectionTarget enum for the selection target * * \return 0 on success or a negative error code otherwise */ int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target, - Rectangle *rect) + Rectangle *rect, bool optional) { struct v4l2_subdev_selection sel = {}; @@ -1189,6 +1193,9 @@ int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target, int ret = ioctl(VIDIOC_SUBDEV_G_SELECTION, &sel); if (ret < 0) { + if (optional && (ret == -ENOTTY || ret == -EINVAL)) + return ret; + LOG(V4L2, Error) << "Unable to get rectangle " << target << " on pad " << stream << ": " << strerror(-ret); @@ -1205,11 +1212,12 @@ int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target, /** * \fn V4L2Subdevice::getSelection(unsigned int pad, unsigned int target, - * Rectangle *rect) + * Rectangle *rect, bool optional) * \brief Get selection rectangle \a rect for \a target * \param[in] pad The 0-indexed pad number the rectangle is retrieved from * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags * \param[out] rect The retrieved selection rectangle + * \param[in] optional Whether unsupported targets are expected * * \return 0 on success or a negative error code otherwise */