summaryrefslogtreecommitdiff
path: root/include/media/v4l2-common.h
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@linux.intel.com>2018-02-23 12:50:14 +0300
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2018-03-21 18:18:52 +0300
commit95ce9c28601afc5da0c11792601ad32dd14cdd44 (patch)
tree8e30f3685fe841a55833a753453c92f6b98ce3d9 /include/media/v4l2-common.h
parent2525fdcb6e8211ee9dbc270a7f882fbfb6433b55 (diff)
downloadlinux-95ce9c28601afc5da0c11792601ad32dd14cdd44.tar.xz
media: v4l: common: Add a function to obtain best size from a list
Add a function (as well as a helper macro) to obtain the best size in a list of device specific sizes. This helps writing drivers as well as aligns interface behaviour across drivers. The struct in which this information is contained in is typically specific to the driver, therefore the existing function v4l2_find_nearest_format() does not address the need. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'include/media/v4l2-common.h')
-rw-r--r--include/media/v4l2-common.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index f3aa1d728c0b..38947dc42ab6 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -333,6 +333,40 @@ v4l2_find_nearest_format(const struct v4l2_frmsize_discrete *sizes,
s32 width, s32 height);
/**
+ * v4l2_find_nearest_size - Find the nearest size among a discrete
+ * set of resolutions contained in an array of a driver specific struct.
+ *
+ * @array: a driver specific array of image sizes
+ * @array_size: the length of the driver specific array of image sizes
+ * @width_field: the name of the width field in the driver specific struct
+ * @height_field: the name of the height field in the driver specific struct
+ * @width: desired width.
+ * @height: desired height.
+ *
+ * Finds the closest resolution to minimize the width and height differences
+ * between what requested and the supported resolutions. The size of the width
+ * and height fields in the driver specific must equal to that of u32, i.e. four
+ * bytes.
+ *
+ * Returns the best match or NULL if the length of the array is zero.
+ */
+#define v4l2_find_nearest_size(array, array_size, width_field, height_field, \
+ width, height) \
+ ({ \
+ BUILD_BUG_ON(sizeof((array)->width_field) != sizeof(u32) || \
+ sizeof((array)->height_field) != sizeof(u32)); \
+ (typeof(&(*(array))))__v4l2_find_nearest_size( \
+ (array), array_size, sizeof(*(array)), \
+ offsetof(typeof(*(array)), width_field), \
+ offsetof(typeof(*(array)), height_field), \
+ width, height); \
+ })
+const void *
+__v4l2_find_nearest_size(const void *array, size_t array_size,
+ size_t entry_size, size_t width_offset,
+ size_t height_offset, s32 width, s32 height);
+
+/**
* v4l2_get_timestamp - helper routine to get a timestamp to be used when
* filling streaming metadata. Internally, it uses ktime_get_ts(),
* which is the recommended way to get it.