{"id":2736,"url":"https://patchwork.libcamera.org/api/1.1/patches/2736/?format=json","web_url":"https://patchwork.libcamera.org/patch/2736/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200129033210.278800-3-nicolas@ndufresne.ca>","date":"2020-01-29T03:31:49","name":"[libcamera-devel,v1,02/23] gst: Add utility to convert StreamFormats to GstCaps","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"64bef40d021c86b90da8ab5b7b0d87db2b166246","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/1.1/people/30/?format=json","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2736/mbox/","series":[{"id":648,"url":"https://patchwork.libcamera.org/api/1.1/series/648/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=648","date":"2020-01-29T03:31:47","name":"GStreamer Element for libcamera","version":1,"mbox":"https://patchwork.libcamera.org/series/648/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2736/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2736/checks/","tags":{},"headers":{"Return-Path":"<nicolas@ndufresne.ca>","Received":["from bhuna.collabora.co.uk (bhuna.collabora.co.uk\n\t[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 81EC960447\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Jan 2020 04:35:16 +0100 (CET)","from nicolas-tpx395.localdomain (unknown\n\t[IPv6:2002:c0de:c115:0:66fc:8b:2a38:8313])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nicolas)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id A8E6528EA9F;\n\tWed, 29 Jan 2020 03:35:12 +0000 (GMT)"],"From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"libcamera-devel@lists.libcamera.org","Cc":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","Date":"Tue, 28 Jan 2020 22:31:49 -0500","Message-Id":"<20200129033210.278800-3-nicolas@ndufresne.ca>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200129033210.278800-1-nicolas@ndufresne.ca>","References":"<20200129033210.278800-1-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 02/23] gst: Add utility to convert\n\tStreamFormats to GstCaps","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 29 Jan 2020 03:35:16 -0000"},"content":"From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nThis transform the basic information found in StreamFormats to GstCaps.\nThis can be handy to reply to early caps query or inside a device\nprovider. Note that we ignored generated range as they are harmful to\ncaps negotiation. We also don't simplify the caps for readability\nreasons, so some of the discrete value may be included in a range.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\n src/gstreamer/gstlibcamera-utils.cpp | 102 +++++++++++++++++++++++++++\n src/gstreamer/gstlibcamera-utils.h   |  18 +++++\n src/gstreamer/meson.build            |   1 +\n 3 files changed, 121 insertions(+)\n create mode 100644 src/gstreamer/gstlibcamera-utils.cpp\n create mode 100644 src/gstreamer/gstlibcamera-utils.h","diff":"diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp\nnew file mode 100644\nindex 0000000..2540be0\n--- /dev/null\n+++ b/src/gstreamer/gstlibcamera-utils.cpp\n@@ -0,0 +1,102 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Collabora Ltd.\n+ *     Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n+ *\n+ * gstlibcamera-utils.c - GStreamer Libcamera Utility Function\n+ */\n+\n+#include \"gstlibcamera-utils.h\"\n+#include <linux/drm_fourcc.h>\n+\n+using namespace libcamera;\n+\n+static struct {\n+\tGstVideoFormat gst_format;\n+\tguint drm_fourcc;\n+} format_map[] = {\n+\t{ GST_VIDEO_FORMAT_ENCODED, DRM_FORMAT_MJPEG },\n+\t{ GST_VIDEO_FORMAT_RGB, DRM_FORMAT_BGR888 },\n+\t{ GST_VIDEO_FORMAT_BGR, DRM_FORMAT_RGB888 },\n+\t{ GST_VIDEO_FORMAT_ARGB, DRM_FORMAT_BGRA8888 },\n+\t{ GST_VIDEO_FORMAT_NV12, DRM_FORMAT_NV12 },\n+\t{ GST_VIDEO_FORMAT_NV21, DRM_FORMAT_NV21 },\n+\t{ GST_VIDEO_FORMAT_NV16, DRM_FORMAT_NV16 },\n+\t{ GST_VIDEO_FORMAT_NV61, DRM_FORMAT_NV61 },\n+\t{ GST_VIDEO_FORMAT_NV24, DRM_FORMAT_NV24 },\n+\t/* { GST_VIDEO_FORMAT_NV42,    DRM_FORMAT_NV42 }, */\n+\t{ GST_VIDEO_FORMAT_UYVY, DRM_FORMAT_UYVY },\n+\t{ GST_VIDEO_FORMAT_VYUY, DRM_FORMAT_VYUY },\n+\t{ GST_VIDEO_FORMAT_YUY2, DRM_FORMAT_YUYV },\n+\t{ GST_VIDEO_FORMAT_YVYU, DRM_FORMAT_YVYU },\n+};\n+#define FORMAT_MAP_SIZE G_N_ELEMENTS(format_map)\n+\n+static inline GstVideoFormat\n+drm_to_gst_format(guint drm_fourcc)\n+{\n+\tfor (guint i = 0; i < FORMAT_MAP_SIZE; i++)\n+\t\tif (format_map[i].drm_fourcc == drm_fourcc)\n+\t\t\treturn format_map[i].gst_format;\n+\treturn GST_VIDEO_FORMAT_UNKNOWN;\n+}\n+\n+static GstStructure *\n+bare_structure_from_fourcc(guint fourcc)\n+{\n+\tGstVideoFormat gst_format = drm_to_gst_format(fourcc);\n+\n+\tif (gst_format == GST_VIDEO_FORMAT_UNKNOWN)\n+\t\treturn NULL;\n+\n+\tif (gst_format != GST_VIDEO_FORMAT_ENCODED)\n+\t\treturn gst_structure_new(\"video/x-raw\", \"format\", G_TYPE_STRING,\n+\t\t\t\t\t gst_video_format_to_string(gst_format), NULL);\n+\n+\tswitch (fourcc) {\n+\tcase DRM_FORMAT_MJPEG:\n+\t\treturn gst_structure_new_empty(\"image/jpeg\");\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+GstCaps *\n+gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)\n+{\n+\tGstCaps *caps = gst_caps_new_empty();\n+\n+\tfor (unsigned int fourcc : formats.pixelformats()) {\n+\t\tg_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(fourcc);\n+\n+\t\tif (!bare_s) {\n+\t\t\tGST_WARNING(\"Unsupported DRM format %\" GST_FOURCC_FORMAT,\n+\t\t\t\t    GST_FOURCC_ARGS(fourcc));\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tfor (const Size &size : formats.sizes(fourcc)) {\n+\t\t\tGstStructure *s = gst_structure_copy(bare_s);\n+\t\t\tgst_structure_set(s,\n+\t\t\t\t\t  \"width\", G_TYPE_INT, size.width,\n+\t\t\t\t\t  \"height\", G_TYPE_INT, size.height,\n+\t\t\t\t\t  NULL);\n+\t\t\tgst_caps_append_structure(caps, s);\n+\t\t}\n+\n+\t\tconst SizeRange &range = formats.range(fourcc);\n+\t\tif (range.hStep && range.vStep) {\n+\t\t\tGstStructure *s = gst_structure_copy(bare_s);\n+\n+\t\t\tgst_structure_set(s,\n+\t\t\t\t\"width\", GST_TYPE_INT_RANGE, range.min.width, range.max.width, range.hStep,\n+\t\t\t\t\"height\", GST_TYPE_INT_RANGE, range.min.height, range.max.height, range.vStep,\n+\t\t\t\tNULL);\n+\t\t\tgst_caps_append_structure(caps, s);\n+\t\t}\n+\t}\n+\n+\treturn caps;\n+}\ndiff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h\nnew file mode 100644\nindex 0000000..4545512\n--- /dev/null\n+++ b/src/gstreamer/gstlibcamera-utils.h\n@@ -0,0 +1,18 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Collabora Ltd.\n+ *     Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n+ *\n+ * gstlibcamera-utils.h - GStreamer Libcamera Utility Functions\n+ */\n+\n+#include <gst/gst.h>\n+#include <gst/video/video.h>\n+\n+#include <libcamera/stream.h>\n+\n+#ifndef __GST_LIBCAMERA_UTILS_H_\n+\n+GstCaps *gst_libcamera_stream_formats_to_caps(const libcamera::StreamFormats &formats);\n+\n+#endif /* __GST_LIBCAMERA_UTILS_H_ */\ndiff --git a/src/gstreamer/meson.build b/src/gstreamer/meson.build\nindex 32d4233..39a34e7 100644\n--- a/src/gstreamer/meson.build\n+++ b/src/gstreamer/meson.build\n@@ -1,5 +1,6 @@\n libcamera_gst_sources = [\n     'gstlibcamera.c',\n+    'gstlibcamera-utils.cpp',\n     'gstlibcamerasrc.cpp',\n ]\n \n","prefixes":["libcamera-devel","v1","02/23"]}