From patchwork Fri May 22 14:54:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3846 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73F136108A for ; Fri, 22 May 2020 16:55:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="GDt27NM1"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0FE1D528 for ; Fri, 22 May 2020 16:55:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1590159321; bh=xu8GOP5HbBM65fpE8v4RrcN9ikFEEfRvQ98iksGeDXg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GDt27NM1K4Cw82s4uuInfQ6XWkw65qU86M5OUjo+Zd9cjqi3fXVnlosGxxCcFyIsP FfXDD1zWnA+20BJhkPs/J/6MxaBYRzKRgvoct+j0NLi48CC5nOmFfY/ZyNKxn0Mbaw jb0SMkVzydEhBlib8scQWHmxQXYFxfnA1pQuUzbg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 22 May 2020 17:54:54 +0300 Message-Id: <20200522145459.16836-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200522145459.16836-1-laurent.pinchart@ideasonboard.com> References: <20200522145459.16836-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH/RFC 06/11] gst: Replace explicit DRM FourCCs with libcamera formats X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 May 2020 14:55:24 -0000 Use the new pixel format constants to replace usage of macros from drm_fourcc.h. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/gstreamer/gstlibcamera-utils.cpp | 62 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index a3cb0746e012..61370d5fad56 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -8,56 +8,56 @@ #include "gstlibcamera-utils.h" -#include +#include using namespace libcamera; static struct { GstVideoFormat gst_format; - guint drm_fourcc; + PixelFormat format; } format_map[] = { - { GST_VIDEO_FORMAT_ENCODED, DRM_FORMAT_MJPEG }, - { GST_VIDEO_FORMAT_RGB, DRM_FORMAT_BGR888 }, - { GST_VIDEO_FORMAT_BGR, DRM_FORMAT_RGB888 }, - { GST_VIDEO_FORMAT_ARGB, DRM_FORMAT_BGRA8888 }, - { GST_VIDEO_FORMAT_NV12, DRM_FORMAT_NV12 }, - { GST_VIDEO_FORMAT_NV21, DRM_FORMAT_NV21 }, - { GST_VIDEO_FORMAT_NV16, DRM_FORMAT_NV16 }, - { GST_VIDEO_FORMAT_NV61, DRM_FORMAT_NV61 }, - { GST_VIDEO_FORMAT_NV24, DRM_FORMAT_NV24 }, - { GST_VIDEO_FORMAT_UYVY, DRM_FORMAT_UYVY }, - { GST_VIDEO_FORMAT_VYUY, DRM_FORMAT_VYUY }, - { GST_VIDEO_FORMAT_YUY2, DRM_FORMAT_YUYV }, - { GST_VIDEO_FORMAT_YVYU, DRM_FORMAT_YVYU }, + { GST_VIDEO_FORMAT_ENCODED, formats::MJPEG }, + { GST_VIDEO_FORMAT_RGB, formats::BGR888 }, + { GST_VIDEO_FORMAT_BGR, formats::RGB888 }, + { GST_VIDEO_FORMAT_ARGB, formats::BGRA8888 }, + { GST_VIDEO_FORMAT_NV12, formats::NV12 }, + { GST_VIDEO_FORMAT_NV21, formats::NV21 }, + { GST_VIDEO_FORMAT_NV16, formats::NV16 }, + { GST_VIDEO_FORMAT_NV61, formats::NV61 }, + { GST_VIDEO_FORMAT_NV24, formats::NV24 }, + { GST_VIDEO_FORMAT_UYVY, formats::UYVY }, + { GST_VIDEO_FORMAT_VYUY, formats::VYUY }, + { GST_VIDEO_FORMAT_YUY2, formats::YUYV }, + { GST_VIDEO_FORMAT_YVYU, formats::YVYU }, /* \todo NV42 is used in libcamera but is not mapped in GStreamer yet. */ }; static GstVideoFormat -drm_to_gst_format(guint drm_fourcc) +pixel_format_to_gst_format(const PixelFormat &format) { for (const auto &item : format_map) { - if (item.drm_fourcc == drm_fourcc) + if (item.format == format) return item.gst_format; } return GST_VIDEO_FORMAT_UNKNOWN; } -static guint -gst_format_to_drm(GstVideoFormat gst_format) +static PixelFormat +gst_format_to_pixel_format(GstVideoFormat gst_format) { if (gst_format == GST_VIDEO_FORMAT_ENCODED) - return DRM_FORMAT_INVALID; + return PixelFormat{}; for (const auto &item : format_map) if (item.gst_format == gst_format) - return item.drm_fourcc; - return DRM_FORMAT_INVALID; + return item.format; + return PixelFormat{}; } static GstStructure * -bare_structure_from_fourcc(guint fourcc) +bare_structure_from_format(const PixelFormat &format) { - GstVideoFormat gst_format = drm_to_gst_format(fourcc); + GstVideoFormat gst_format = pixel_format_to_gst_format(format); if (gst_format == GST_VIDEO_FORMAT_UNKNOWN) return nullptr; @@ -66,8 +66,8 @@ bare_structure_from_fourcc(guint fourcc) return gst_structure_new("video/x-raw", "format", G_TYPE_STRING, gst_video_format_to_string(gst_format), nullptr); - switch (fourcc) { - case DRM_FORMAT_MJPEG: + switch (format) { + case formats::MJPEG: return gst_structure_new_empty("image/jpeg"); default: return nullptr; @@ -80,7 +80,7 @@ gst_libcamera_stream_formats_to_caps(const StreamFormats &formats) GstCaps *caps = gst_caps_new_empty(); for (PixelFormat pixelformat : formats.pixelformats()) { - g_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(pixelformat); + g_autoptr(GstStructure) bare_s = bare_structure_from_format(pixelformat); if (!bare_s) { GST_WARNING("Unsupported DRM format %" GST_FOURCC_FORMAT, @@ -120,7 +120,7 @@ GstCaps * gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg) { GstCaps *caps = gst_caps_new_empty(); - GstStructure *s = bare_structure_from_fourcc(stream_cfg.pixelFormat); + GstStructure *s = bare_structure_from_format(stream_cfg.pixelFormat); gst_structure_set(s, "width", G_TYPE_INT, stream_cfg.size.width, @@ -135,7 +135,7 @@ void gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg, GstCaps *caps) { - GstVideoFormat gst_format = drm_to_gst_format(stream_cfg.pixelFormat); + GstVideoFormat gst_format = pixel_format_to_gst_format(stream_cfg.pixelFormat); /* First fixate the caps using default configuration value. */ g_assert(gst_caps_is_writable(caps)); @@ -154,9 +154,9 @@ gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg, if (gst_structure_has_name(s, "video/x-raw")) { const gchar *format = gst_structure_get_string(s, "format"); gst_format = gst_video_format_from_string(format); - stream_cfg.pixelFormat = PixelFormat(gst_format_to_drm(gst_format)); + stream_cfg.pixelFormat = gst_format_to_pixel_format(gst_format); } else if (gst_structure_has_name(s, "image/jpeg")) { - stream_cfg.pixelFormat = PixelFormat(DRM_FORMAT_MJPEG); + stream_cfg.pixelFormat = formats::MJPEG; } else { g_critical("Unsupported media type: %s", gst_structure_get_name(s)); }