[v2,1/7] libcamera: V4L2Subdevice: Add whence argument to [get|set]Selection()
diff mbox series

Message ID 20260721145958.68489-2-johannes.goede@oss.qualcomm.com
State New
Headers show
Series
  • camss: Add CAMSS pipeline handler
Related show

Commit Message

Hans de Goede July 21, 2026, 2:59 p.m. UTC
Add a whence argument to V4L2Subdevice::[get|set]Selection() allowing
callers to specify that the operation should be applied to the try state,
rather then always applying it to the active state.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
---
 include/libcamera/internal/v4l2_subdevice.h | 14 ++++++++------
 src/libcamera/v4l2_subdevice.cpp            | 20 ++++++++++++++------
 2 files changed, 22 insertions(+), 12 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h
index c37a82afa..36848915f 100644
--- a/include/libcamera/internal/v4l2_subdevice.h
+++ b/include/libcamera/internal/v4l2_subdevice.h
@@ -123,16 +123,18 @@  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, Whence whence = ActiveFormat);
+	int getSelection(unsigned int pad, unsigned int target, Rectangle *rect,
+			 Whence whence = ActiveFormat)
 	{
-		return getSelection({ pad, 0 }, target, rect);
+		return getSelection({ pad, 0 }, target, rect, whence);
 	}
 	int setSelection(const Stream &stream, unsigned int target,
-			 Rectangle *rect);
-	int setSelection(unsigned int pad, unsigned int target, Rectangle *rect)
+			 Rectangle *rect, Whence whence = ActiveFormat);
+	int setSelection(unsigned int pad, unsigned int target, Rectangle *rect,
+			 Whence whence = ActiveFormat)
 	{
-		return setSelection({ pad, 0 }, target, rect);
+		return setSelection({ pad, 0 }, target, rect, whence);
 	}
 
 	Formats formats(const Stream &stream);
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index a69de154e..8f9d4dbd9 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -1171,17 +1171,19 @@  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] whence The format to get, \ref V4L2Subdevice::ActiveFormat
+ * "ActiveFormat" or \ref V4L2Subdevice::TryFormat "TryFormat"
  *
  * \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, Whence whence)
 {
 	struct v4l2_subdev_selection sel = {};
 
-	sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+	sel.which = whence;
 	sel.pad = stream.pad;
 	sel.stream = stream.stream;
 	sel.target = target;
@@ -1205,11 +1207,13 @@  int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target,
 
 /**
  * \fn V4L2Subdevice::getSelection(unsigned int pad, unsigned int target,
- * Rectangle *rect)
+ * Rectangle *rect, Whence whence = ActiveFormat)
  * \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] whence The format to get, \ref V4L2Subdevice::ActiveFormat
+ * "ActiveFormat" or \ref V4L2Subdevice::TryFormat "TryFormat"
  *
  * \return 0 on success or a negative error code otherwise
  */
@@ -1219,17 +1223,19 @@  int V4L2Subdevice::getSelection(const Stream &stream, unsigned int target,
  * \param[in] stream The stream the rectangle is to be applied to
  * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags
  * \param[inout] rect The selection rectangle to be applied
+ * \param[in] whence The format to get, \ref V4L2Subdevice::ActiveFormat
+ * "ActiveFormat" or \ref V4L2Subdevice::TryFormat "TryFormat"
  *
  * \todo Define a V4L2SelectionTarget enum for the selection target
  *
  * \return 0 on success or a negative error code otherwise
  */
 int V4L2Subdevice::setSelection(const Stream &stream, unsigned int target,
-				Rectangle *rect)
+				Rectangle *rect, Whence whence)
 {
 	struct v4l2_subdev_selection sel = {};
 
-	sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+	sel.which = whence;
 	sel.pad = stream.pad;
 	sel.stream = stream.stream;
 	sel.target = target;
@@ -1258,11 +1264,13 @@  int V4L2Subdevice::setSelection(const Stream &stream, unsigned int target,
 
 /**
  * \fn V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
- * Rectangle *rect)
+ * Rectangle *rect, Whence whence = ActiveFormat)
  * \brief Set selection rectangle \a rect for \a target
  * \param[in] pad The 0-indexed pad number the rectangle is to be applied to
  * \param[in] target The selection target defined by the V4L2_SEL_TGT_* flags
  * \param[inout] rect The selection rectangle to be applied
+ * \param[in] whence The format to get, \ref V4L2Subdevice::ActiveFormat
+ * "ActiveFormat" or \ref V4L2Subdevice::TryFormat "TryFormat"
  *
  * \todo Define a V4L2SelectionTarget enum for the selection target
  *