From 020a019fd627934d19a6340cdc56aa22b6b6d9e7 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 10 Feb 2020 18:02:37 -0500 Subject: [PATCH] v4l2codecs: Add initial formats helpers --- sys/v4l2codecs/gstv4l2format.c | 77 ++++++++++++++++++++++++++++++++++ sys/v4l2codecs/gstv4l2format.h | 30 +++++++++++++ sys/v4l2codecs/meson.build | 1 + 3 files changed, 108 insertions(+) create mode 100644 sys/v4l2codecs/gstv4l2format.c create mode 100644 sys/v4l2codecs/gstv4l2format.h diff --git a/sys/v4l2codecs/gstv4l2format.c b/sys/v4l2codecs/gstv4l2format.c new file mode 100644 index 0000000000..d7d7892003 --- /dev/null +++ b/sys/v4l2codecs/gstv4l2format.c @@ -0,0 +1,77 @@ +/* GStreamer + * Copyright (C) 2020 Nicolas Dufresne + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "gstv4l2format.h" + +#define GST_CAT_DEFAULT gstv4l2codecs_debug +GST_DEBUG_CATEGORY_EXTERN (gstv4l2codecs_debug); + +struct FormatEntry +{ + guint32 v4l2_pix_fmt; + gint num_planes; + GstVideoFormat gst_fmt; + guint bitdepth; + gint subsampling; +}; + +static struct FormatEntry format_map[] = { + {V4L2_PIX_FMT_NV12, 1, GST_VIDEO_FORMAT_NV12, 8, 420}, + {0,} +}; + +static struct FormatEntry * +lookup_v4l2_fmt (guint v4l2_pix_fmt) +{ + gint i; + struct FormatEntry *ret = NULL; + + for (i = 0; format_map[i].v4l2_pix_fmt; i++) { + if (format_map[i].v4l2_pix_fmt == v4l2_pix_fmt) { + ret = format_map + i; + break; + } + } + + return ret; +} + +gboolean +gst_v4l2_format_to_video_info (struct v4l2_format * fmt, + GstVideoInfo * out_info) +{ + struct FormatEntry *entry = lookup_v4l2_fmt (fmt->fmt.pix_mp.pixelformat); + + if (!entry) + return FALSE; + + if (entry->num_planes != 1) { + GST_FIXME ("Multi allocation formats are not supported yet"); + return FALSE; + } + + if (!gst_video_info_set_format (out_info, entry->gst_fmt, + fmt->fmt.pix_mp.width, fmt->fmt.pix_mp.height)) + return FALSE; + + /* FIXME play the extrapolation danse for single FDs formats, and copy over + * stride/offsets/size for the other formats */ + + return TRUE; +} diff --git a/sys/v4l2codecs/gstv4l2format.h b/sys/v4l2codecs/gstv4l2format.h new file mode 100644 index 0000000000..d76bd51fdd --- /dev/null +++ b/sys/v4l2codecs/gstv4l2format.h @@ -0,0 +1,30 @@ +/* GStreamer + * Copyright (C) 2020 Nicolas Dufresne + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_V4L2_FORMAT_H__ +#define __GST_V4L2_FORMAT_H__ + +#include +#include +#include "linux/videodev2.h" + +gboolean gst_v4l2_format_to_video_info (struct v4l2_format * fmt, + GstVideoInfo * out_info); + +#endif /* __GST_V4L2_FORMAT_H__ */ diff --git a/sys/v4l2codecs/meson.build b/sys/v4l2codecs/meson.build index efa0b15e39..048f63baad 100644 --- a/sys/v4l2codecs/meson.build +++ b/sys/v4l2codecs/meson.build @@ -3,6 +3,7 @@ v4l2codecs_sources = [ 'gstv4l2codecdevice.c', 'gstv4l2codech264dec.c', 'gstv4l2decoder.c', + 'gstv4l2format.c', ] libgudev_dep = dependency('gudev-1.0', required: get_option('v4l2codecs'))