rawparse: Add unaligned raw audio parsing to audioparse and add new element

This helps in cases where raw audio data is being delivered, but the
buffers do not come in sample aligned sizes. The new unalignedaudioparse
bin can be autoplugged and configures an internal audioparse element to
align the data. audioparse itself gets support for audio/x-unaligned-raw
input caps; the output caps then contain the same information, except that
the name is changed to audio/x-raw (since audioparse aligns the data).
This ensures that souphttpsrc ! audioparse still works.

https://bugzilla.gnome.org/show_bug.cgi?id=689460
This commit is contained in:
Carlos Rafael Giani 2016-03-04 22:10:47 +01:00 committed by Sebastian Dröge
parent 4984828fcf
commit f6e6264711
5 changed files with 215 additions and 0 deletions

View file

@ -3,6 +3,7 @@ plugin_LTLIBRARIES = libgstrawparse.la
libgstrawparse_la_SOURCES = \
gstrawparse.c \
gstunalignedaudioparse.c \
gstaudioparse.c \
gstvideoparse.c \
plugin.c
@ -19,6 +20,8 @@ libgstrawparse_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstrawparse_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
noinst_HEADERS = \
unalignedaudio.h \
gstunalignedaudioparse.h \
gstaudioparse.h \
gstrawparse.h \
gstvideoparse.h

View file

@ -0,0 +1,125 @@
/* GStreamer
* Copyright (C) 2016 Carlos Rafael Giani <dv@pseudoterminal.org>
*
* gstunalignedaudioparse.c:
*
* 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 <string.h>
#include <stdio.h>
#include <gst/gst.h>
#include <gst/audio/audio.h>
#include "gstunalignedaudioparse.h"
#include "unalignedaudio.h"
GST_DEBUG_CATEGORY (unaligned_audio_parse_debug);
#define GST_CAT_DEFAULT unaligned_audio_parse_debug
struct _GstUnalignedAudioParse
{
GstBin parent;
GstElement *inner_parser;
};
struct _GstUnalignedAudioParseClass
{
GstBinClass parent_class;
};
static GstStaticPadTemplate static_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_UNALIGNED_RAW_AUDIO_CAPS)
);
static GstStaticPadTemplate static_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL)
", layout = (string) { interleaved, non-interleaved }")
);
G_DEFINE_TYPE (GstUnalignedAudioParse, gst_unaligned_audio_parse, GST_TYPE_BIN);
static void
gst_unaligned_audio_parse_class_init (GstUnalignedAudioParseClass * klass)
{
GstElementClass *element_class;
GST_DEBUG_CATEGORY_INIT (unaligned_audio_parse_debug, "unalignedaudioparse",
0, "Unaligned raw audio parser");
element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&static_sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&static_src_template));
gst_element_class_set_static_metadata (element_class,
"unalignedaudioparse",
"Codec/Parser/Bin/Audio",
"Parse unaligned raw audio data",
"Carlos Rafael Giani <dv@pseudoterminal.org>");
}
static void
gst_unaligned_audio_parse_init (GstUnalignedAudioParse * unaligned_audio_parse)
{
GstPad *inner_pad;
GstPad *ghostpad;
unaligned_audio_parse->inner_parser =
gst_element_factory_make ("audioparse", "inner_parser");
g_assert (unaligned_audio_parse->inner_parser != NULL);
g_object_set (G_OBJECT (unaligned_audio_parse->inner_parser),
"use-sink-caps", TRUE, NULL);
gst_bin_add (GST_BIN (unaligned_audio_parse),
unaligned_audio_parse->inner_parser);
inner_pad =
gst_element_get_static_pad (unaligned_audio_parse->inner_parser, "sink");
ghostpad =
gst_ghost_pad_new_from_template ("sink", inner_pad,
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
(unaligned_audio_parse), "sink"));
gst_element_add_pad (GST_ELEMENT (unaligned_audio_parse), ghostpad);
gst_object_unref (GST_OBJECT (inner_pad));
inner_pad = gst_element_get_static_pad (unaligned_audio_parse->inner_parser,
"src");
ghostpad =
gst_ghost_pad_new_from_template ("src", inner_pad,
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
(unaligned_audio_parse), "src"));
gst_element_add_pad (GST_ELEMENT (unaligned_audio_parse), ghostpad);
gst_object_unref (GST_OBJECT (inner_pad));
}

View file

@ -0,0 +1,49 @@
/* GStreamer
* Copyright (C) 2016 Carlos Rafael Giani <dv@pseudoterminal.org>
*
* gstunalignedaudioparse.h:
*
* 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_UNALIGNED_AUDIO_PARSE_H___
#define __GST_UNALIGNED_AUDIO_PARSE_H___
#include <gst/gst.h>
G_BEGIN_DECLS
#define GST_TYPE_UNALIGNED_AUDIO_PARSE \
(gst_unaligned_audio_parse_get_type())
#define GST_UNALIGNED_AUDIO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_UNALIGNED_AUDIO_PARSE, GstUnalignedAudioParse))
#define GST_UNALIGNED_AUDIO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_UNALIGNED_AUDIO_PARSE, GstUnalignedAudioParseClass))
#define GST_UNALIGNED_AUDIO_PARSE_CAST(obj) \
((GstUnalignedAudioParse *)(obj))
#define GST_IS_UNALIGNED_AUDIO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_UNALIGNED_AUDIO_PARSE))
#define GST_IS_UNALIGNED_AUDIO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_UNALIGNED_AUDIO_PARSE))
typedef struct _GstUnalignedAudioParse GstUnalignedAudioParse;
typedef struct _GstUnalignedAudioParseClass GstUnalignedAudioParseClass;
GType gst_unaligned_audio_parse_get_type (void);
G_END_DECLS
#endif /* __GST_UNALIGNED_AUDIO_PARSE_H___ */

View file

@ -3,6 +3,7 @@
#endif
#include <gst/gst.h>
#include "gstunalignedaudioparse.h"
#include "gstaudioparse.h"
#include "gstvideoparse.h"
@ -15,6 +16,8 @@ plugin_init (GstPlugin * plugin)
gst_video_parse_get_type ());
ret &= gst_element_register (plugin, "audioparse", GST_RANK_NONE,
gst_audio_parse_get_type ());
ret &= gst_element_register (plugin, "unalignedaudioparse", GST_RANK_MARGINAL,
gst_unaligned_audio_parse_get_type ());
return ret;
}

View file

@ -0,0 +1,35 @@
/* GStreamer
* Copyright (C) 2016 Carlos Rafael Giani <dv@pseudoterminal.org>
*
* unalignedaudio.h:
*
* 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_UNALIGNED_AUDIO_H__
#define __GST_UNALIGNED_AUDIO_H__
#include <gst/gst.h>
#include <gst/audio/audio.h>
#define GST_UNALIGNED_RAW_AUDIO_CAPS \
"audio/x-unaligned-raw" \
", format = (string) " GST_AUDIO_FORMATS_ALL \
", rate = (int) [ 1, MAX ]" \
", channels = (int) [ 1, MAX ]" \
", layout = (string) { interleaved, non-interleaved }"
#endif /* __GST_UNALIGNED_AUDIO_H__ */