From 5b7b7085e4d5b34a66adae27d1429df964f57289 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Sun, 1 May 2022 16:58:34 +0200 Subject: [PATCH] plugin: Add RAW system memory importer Add "clapperrawimporter" module which allows importing RAW system memory mapped frames --- .../plugin/importers/gstclapperrawimporter.c | 111 ++++++++++++++++++ .../plugin/importers/gstclapperrawimporter.h | 36 ++++++ lib/gst/plugin/importers/meson.build | 11 ++ lib/gst/plugin/meson.build | 2 + meson_options.txt | 6 + 5 files changed, 166 insertions(+) create mode 100644 lib/gst/plugin/importers/gstclapperrawimporter.c create mode 100644 lib/gst/plugin/importers/gstclapperrawimporter.h create mode 100644 lib/gst/plugin/importers/meson.build diff --git a/lib/gst/plugin/importers/gstclapperrawimporter.c b/lib/gst/plugin/importers/gstclapperrawimporter.c new file mode 100644 index 00000000..67de1f58 --- /dev/null +++ b/lib/gst/plugin/importers/gstclapperrawimporter.c @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2022 Rafał Dzięgiel + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstclapperrawimporter.h" +#include "gst/plugin/gstgtkutils.h" +#include "gst/plugin/gstgdkformats.h" + +#define GST_CAT_DEFAULT gst_clapper_raw_importer_debug +GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); + +#define parent_class gst_clapper_raw_importer_parent_class +GST_CLAPPER_IMPORTER_DEFINE (GstClapperRawImporter, gst_clapper_raw_importer, GST_TYPE_CLAPPER_IMPORTER); + +static GstBufferPool * +gst_clapper_raw_importer_create_pool (GstClapperImporter *importer, GstStructure **config) +{ + GstClapperRawImporter *self = GST_CLAPPER_RAW_IMPORTER_CAST (importer); + GstBufferPool *pool; + + GST_DEBUG_OBJECT (self, "Creating new buffer pool"); + + pool = gst_video_buffer_pool_new (); + *config = gst_buffer_pool_get_config (pool); + + gst_buffer_pool_config_add_option (*config, GST_BUFFER_POOL_OPTION_VIDEO_META); + + return pool; +} + +static void +gst_clapper_raw_importer_add_allocation_metas (GstClapperImporter *importer, GstQuery *query) +{ + gst_query_add_allocation_meta (query, GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE, NULL); + gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL); +} + +static GdkTexture * +gst_clapper_raw_importer_generate_texture (GstClapperImporter *importer, + GstBuffer *buffer, GstVideoInfo *v_info) +{ + GdkTexture *texture; + GstVideoFrame frame; + + if (G_UNLIKELY (!gst_video_frame_map (&frame, v_info, buffer, GST_MAP_READ))) { + GST_ERROR_OBJECT (importer, "Could not map input buffer for reading"); + return NULL; + } + + texture = gst_video_frame_into_gdk_texture (&frame); + gst_video_frame_unmap (&frame); + + return texture; +} + +static void +gst_clapper_raw_importer_init (GstClapperRawImporter *self) +{ +} + +static void +gst_clapper_raw_importer_class_init (GstClapperRawImporterClass *klass) +{ + GstClapperImporterClass *importer_class = (GstClapperImporterClass *) klass; + + GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "clapperrawimporter", 0, + "Clapper RAW Importer"); + + importer_class->create_pool = gst_clapper_raw_importer_create_pool; + importer_class->add_allocation_metas = gst_clapper_raw_importer_add_allocation_metas; + importer_class->generate_texture = gst_clapper_raw_importer_generate_texture; +} + +GstClapperImporter * +make_importer (void) +{ + return g_object_new (GST_TYPE_CLAPPER_RAW_IMPORTER, NULL); +} + +GstCaps * +make_caps (GstRank *rank, GStrv *context_types) +{ + *rank = GST_RANK_MARGINAL; + + return gst_caps_from_string ( + GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY ", " + GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, + "{ " GST_GDK_MEMORY_FORMATS " }") + "; " + GST_VIDEO_CAPS_MAKE ( + "{ " GST_GDK_MEMORY_FORMATS " }")); +} diff --git a/lib/gst/plugin/importers/gstclapperrawimporter.h b/lib/gst/plugin/importers/gstclapperrawimporter.h new file mode 100644 index 00000000..811b52b7 --- /dev/null +++ b/lib/gst/plugin/importers/gstclapperrawimporter.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 Rafał Dzięgiel + * + * 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. + */ + +#pragma once + +#include "gst/plugin/gstclapperimporter.h" + +G_BEGIN_DECLS + +#define GST_TYPE_CLAPPER_RAW_IMPORTER (gst_clapper_raw_importer_get_type()) +G_DECLARE_FINAL_TYPE (GstClapperRawImporter, gst_clapper_raw_importer, GST, CLAPPER_RAW_IMPORTER, GstClapperImporter) + +#define GST_CLAPPER_RAW_IMPORTER_CAST(obj) ((GstClapperRawImporter *)(obj)) + +struct _GstClapperRawImporter +{ + GstClapperImporter parent; +}; + +G_END_DECLS diff --git a/lib/gst/plugin/importers/meson.build b/lib/gst/plugin/importers/meson.build new file mode 100644 index 00000000..2796afce --- /dev/null +++ b/lib/gst/plugin/importers/meson.build @@ -0,0 +1,11 @@ +if not get_option('rawimporter').disabled() + library( + 'gstclapperrawimporter', + 'gstclapperrawimporter.c', + dependencies: gst_clapper_sink_dep, + include_directories: configinc, + c_args: gst_clapper_plugin_args, + install: true, + install_dir: gst_clapper_importers_libdir, + ) +endif diff --git a/lib/gst/plugin/meson.build b/lib/gst/plugin/meson.build index 3694d46d..3a0e7ee5 100644 --- a/lib/gst/plugin/meson.build +++ b/lib/gst/plugin/meson.build @@ -68,3 +68,5 @@ gst_clapper_sink_dep = declare_dependency( include_directories: configinc, dependencies: gst_clapper_plugin_deps, ) + +subdir('importers') diff --git a/meson_options.txt b/meson_options.txt index 78817aff..87c8eec1 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -14,6 +14,12 @@ option('gst-plugin', description: 'Build GStreamer plugin (includes GTK video sink element)' ) +option('rawimporter', + type: 'feature', + value: 'auto', + description: 'Build RAW system memory importer for clappersink' +) + option('devel-checks', type: 'boolean', value: false,