diff mbox

[media-ctl,3/3] Sort enumerated media bus codes

Message ID 1358117253-13707-3-git-send-email-sakari.ailus@iki.fi (mailing list archive)
State New, archived
Headers show

Commit Message

Sakari Ailus Jan. 13, 2013, 10:47 p.m. UTC
Sort the enumeration result. This makes e.g. matching formats at both ends
of the link much easier.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 src/v4l2subdev.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox

Patch

diff --git a/src/v4l2subdev.c b/src/v4l2subdev.c
index 946c030..d553216 100644
--- a/src/v4l2subdev.c
+++ b/src/v4l2subdev.c
@@ -65,6 +65,19 @@  void v4l2_subdev_close(struct media_entity *entity)
 	}
 }
 
+static int mbus_code_sort(const void *p1, const void *p2)
+{
+	const unsigned int *c1 = p1, *c2 = p2;
+
+	if (*c1 < *c2)
+		return -1;
+
+	if (*c1 > *c2)
+		return 1;
+
+	return 0;
+}
+
 struct v4l2_subdev_mbus_codes *
 v4l2_subdev_enum_mbus_code(struct media_entity *entity, unsigned int pad)
 {
@@ -100,6 +113,7 @@  v4l2_subdev_enum_mbus_code(struct media_entity *entity, unsigned int pad)
 	}
 
 	codes->ncode = c.index;
+	qsort(codes->code, codes->ncode, sizeof(*codes->code), &mbus_code_sort);
 
 	v4l2_subdev_close(entity);
 	return codes;