From f3114d4d7ed03107ac1c85c8b25bff0ee38e255e Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 24 Mar 2021 16:48:35 -0400 Subject: [PATCH] Introduce CODEC Alpha plugin This plugin contains a set of utility elements allowing to extract, decode and combine CODEC (typically VP8/VP9) alpha stream. Part-of: --- gst/codecalpha/gstcodecalphademux.c | 106 ++++++++++++++++++++++++++++ gst/codecalpha/gstcodecalphademux.h | 35 +++++++++ gst/codecalpha/gstplugin.c | 43 +++++++++++ gst/codecalpha/meson.build | 15 ++++ gst/meson.build | 2 +- meson_options.txt | 1 + 6 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 gst/codecalpha/gstcodecalphademux.c create mode 100644 gst/codecalpha/gstcodecalphademux.h create mode 100644 gst/codecalpha/gstplugin.c create mode 100644 gst/codecalpha/meson.build diff --git a/gst/codecalpha/gstcodecalphademux.c b/gst/codecalpha/gstcodecalphademux.c new file mode 100644 index 0000000000..2d013bce82 --- /dev/null +++ b/gst/codecalpha/gstcodecalphademux.c @@ -0,0 +1,106 @@ +/* GStreamer + * Copyright (C) <2021> Collabora Ltd. + * Author: 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. + */ + +/** + * SECTION:element-codecalphademux + * @title: CODEC Alpha Demuxer + * + * Extract the CODEC (typically VP8/VP9) alpha stream stored at meta and + * expose it as a stream. This element allow using single stream VP9 decoders + * in order to decode both streams. + * + * ## Example launch line + * |[ + * gst-launch-1.0 -v filesrc location=transparency.webm ! matroskademux ! + * codecalphademux name=d + * d.video ! queue ! vp9dec ! autovideosink + * d.alpha ! queue ! vp9dec ! autovideosink + * ]| This pipeline splits and decode the video and the alpha stream, showing + * the result on seperate window. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "gstcodecalphademux.h" + +GST_DEBUG_CATEGORY_STATIC (codecalphademux_debug); +#define GST_CAT_DEFAULT (codecalphademux_debug) + +struct _GstCodecAlphaDemux +{ + GstElement parent; +}; + +#define gst_codec_alpha_demux_parent_class parent_class +G_DEFINE_TYPE_WITH_CODE (GstCodecAlphaDemux, gst_codec_alpha_demux, + GST_TYPE_ELEMENT, + GST_DEBUG_CATEGORY_INIT (codecalphademux_debug, "codecalphademux", 0, + "codecalphademux")); + +GST_ELEMENT_REGISTER_DEFINE (codec_alpha_demux, "codecalphademux", + GST_RANK_NONE, GST_TYPE_CODEC_ALPHA_DEMUX); + +static GstStaticPadTemplate gst_codec_alpha_demux_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("ANY") + ); + +static GstStaticPadTemplate gst_codec_alpha_demux_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("ANY") + ); + +static GstStaticPadTemplate gst_codec_alpha_demux_alpha_template = +GST_STATIC_PAD_TEMPLATE ("alpha", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("ANY") + ); + +static void +gst_codec_alpha_demux_class_init (GstCodecAlphaDemuxClass * klass) +{ + GstElementClass *element_class = (GstElementClass *) klass; + + gst_element_class_set_static_metadata (element_class, + "CODEC Alpha Demuxer", "Codec/Demuxer", + "Extract and expose as a stream the CODEC alpha.", + "Nicolas Dufresne "); + + gst_element_class_add_static_pad_template (element_class, + &gst_codec_alpha_demux_sink_template); + gst_element_class_add_static_pad_template (element_class, + &gst_codec_alpha_demux_src_template); + gst_element_class_add_static_pad_template (element_class, + &gst_codec_alpha_demux_alpha_template); +} + +static void +gst_codec_alpha_demux_init (GstCodecAlphaDemux * demux) +{ +} diff --git a/gst/codecalpha/gstcodecalphademux.h b/gst/codecalpha/gstcodecalphademux.h new file mode 100644 index 0000000000..3bb2523000 --- /dev/null +++ b/gst/codecalpha/gstcodecalphademux.h @@ -0,0 +1,35 @@ +/* GStreamer + * Copyright (C) <2021> Collabora Ltd. + * Author: 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_CODEC_ALPHA_DEMUX_H__ +#define __GST_CODEC_ALPHA_DEMUX_H__ + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_CODEC_ALPHA_DEMUX (gst_codec_alpha_demux_get_type()) +G_DECLARE_FINAL_TYPE (GstCodecAlphaDemux, + gst_codec_alpha_demux, GST, CODEC_ALPHA_DEMUX, GstElement); + +GST_ELEMENT_REGISTER_DECLARE (codec_alpha_demux); + +G_END_DECLS +#endif diff --git a/gst/codecalpha/gstplugin.c b/gst/codecalpha/gstplugin.c new file mode 100644 index 0000000000..3a92c6a8c7 --- /dev/null +++ b/gst/codecalpha/gstplugin.c @@ -0,0 +1,43 @@ +/* GStreamer + * Copyright (C) <2021> Collabora Ltd. + * Author: 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. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "gstcodecalphademux.h" + +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean ret = FALSE; + + ret |= GST_ELEMENT_REGISTER (codec_alpha_demux, plugin); + + return ret; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + codecalpha, + "CODEC Alpha Utilities", + plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/gst/codecalpha/meson.build b/gst/codecalpha/meson.build new file mode 100644 index 0000000000..1c9d3b34ef --- /dev/null +++ b/gst/codecalpha/meson.build @@ -0,0 +1,15 @@ +codecalpha_sources = [ + 'gstplugin.c', + 'gstcodecalphademux.c', +] + +gstcodecalpha = library('gstcodecalpha', + codecalpha_sources, + c_args : gst_plugins_bad_args, + include_directories : [configinc], + dependencies : [gstvideo_dep], + install : true, + install_dir : plugins_install_dir, +) +pkgconfig.generate(gstcodecalpha, install_dir : plugins_pkgconfig_install_dir) +plugins += [gstcodecalpha] diff --git a/gst/meson.build b/gst/meson.build index 201e7890e1..9cf62db983 100644 --- a/gst/meson.build +++ b/gst/meson.build @@ -1,7 +1,7 @@ foreach plugin : ['accurip', 'adpcmdec', 'adpcmenc', 'aiff', 'asfmux', 'audiobuffersplit', 'audiofxbad', 'audiomixmatrix', 'audiolatency', 'audiovisualizers', 'autoconvert', 'bayer', - 'camerabin2', 'coloreffects', 'debugutils', 'dvbsubenc', + 'camerabin2', 'codecalpha', 'coloreffects', 'debugutils', 'dvbsubenc', 'dvbsuboverlay', 'dvdspu', 'faceoverlay', 'festival', 'fieldanalysis', 'freeverb', 'frei0r', 'gaudieffects', 'gdp', 'geometrictransform', 'id3tag', 'inter', 'interlace', diff --git a/meson_options.txt b/meson_options.txt index e2f13e77e4..81eabbc8a7 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -15,6 +15,7 @@ option('audiovisualizers', type : 'feature', value : 'auto') option('autoconvert', type : 'feature', value : 'auto') option('bayer', type : 'feature', value : 'auto') option('camerabin2', type : 'feature', value : 'auto') +option('codecalpha', type : 'feature', value : 'auto') option('coloreffects', type : 'feature', value : 'auto') option('debugutils', type : 'feature', value : 'auto') option('dvbsubenc', type : 'feature', value : 'auto')