summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.com>2020-03-13 16:51:27 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.com>2020-03-31 09:34:05 -0400
commit6494d7b056ccf941c77bf0191a48a54630832d16 (patch)
tree3fcf48c783323f75e4978a7baab20e102fddefce
parent2a1836f1831c616a956a25c964502dc795aafda4 (diff)
v4l2format: Convert between V4L2 and GST video format
This will be needed in the output format negotiation.
-rw-r--r--sys/v4l2codecs/gstv4l2format.c40
-rw-r--r--sys/v4l2codecs/gstv4l2format.h6
2 files changed, 46 insertions, 0 deletions
diff --git a/sys/v4l2codecs/gstv4l2format.c b/sys/v4l2codecs/gstv4l2format.c
index 39b5e2be4..f07ac65ad 100644
--- a/sys/v4l2codecs/gstv4l2format.c
+++ b/sys/v4l2codecs/gstv4l2format.c
@@ -52,6 +52,22 @@ lookup_v4l2_fmt (guint v4l2_pix_fmt)
return ret;
}
+static struct FormatEntry *
+lookup_gst_fmt (GstVideoFormat gst_fmt)
+{
+ gint i;
+ struct FormatEntry *ret = NULL;
+
+ for (i = 0; format_map[i].v4l2_pix_fmt; i++) {
+ if (format_map[i].gst_fmt == gst_fmt) {
+ ret = format_map + i;
+ break;
+ }
+ }
+
+ return ret;
+}
+
static gint
extrapolate_stride (const GstVideoFormatInfo * finfo, gint plane, gint stride)
{
@@ -113,3 +129,27 @@ gst_v4l2_format_to_video_info (struct v4l2_format * fmt,
return TRUE;
}
+
+gboolean
+gst_v4l2_format_to_video_format (guint32 pix_fmt, GstVideoFormat * out_format)
+{
+ struct FormatEntry *entry = lookup_v4l2_fmt (pix_fmt);
+
+ if (!entry)
+ return FALSE;
+
+ *out_format = entry->gst_fmt;
+ return TRUE;
+}
+
+gboolean
+gst_v4l2_format_from_video_format (GstVideoFormat format, guint32 * out_pix_fmt)
+{
+ struct FormatEntry *entry = lookup_gst_fmt (format);
+
+ if (!entry)
+ return FALSE;
+
+ *out_pix_fmt = entry->v4l2_pix_fmt;
+ return TRUE;
+}
diff --git a/sys/v4l2codecs/gstv4l2format.h b/sys/v4l2codecs/gstv4l2format.h
index d76bd51fd..bcb091860 100644
--- a/sys/v4l2codecs/gstv4l2format.h
+++ b/sys/v4l2codecs/gstv4l2format.h
@@ -27,4 +27,10 @@
gboolean gst_v4l2_format_to_video_info (struct v4l2_format * fmt,
GstVideoInfo * out_info);
+gboolean gst_v4l2_format_to_video_format (guint32 pix_fmt,
+ GstVideoFormat * out_format);
+
+gboolean gst_v4l2_format_from_video_format (GstVideoFormat format,
+ guint32 * out_pix_fmt);
+
#endif /* __GST_V4L2_FORMAT_H__ */