@@ -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);
@@ -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
*/