deinterleave: port to 0.11

Port of the deinterleave element and its unittests. The interleave
element will be ported as part of another patch, hence disabling it
for now.

https://bugzilla.gnome.org/show_bug.cgi?id=668847
This commit is contained in:
Philippe Normand 2012-01-30 16:40:19 +01:00 committed by Sebastian Dröge
parent 697dcc60b4
commit 640be49e21
7 changed files with 292 additions and 268 deletions

View file

@ -312,7 +312,7 @@ dnl *** plug-ins to include ***
dnl Non ported plugins (non-dependant, then dependant)
dnl Make sure you have a space before and after all plugins
GST_PLUGINS_NONPORTED="deinterlace interleave flx goom2k1 \
imagefreeze interleave monoscope smpte \
imagefreeze monoscope smpte \
videobox \
cairo cairo_gobject dv1394 gdk_pixbuf \
oss oss4 shout2 \

View file

@ -1,13 +1,13 @@
plugin_LTLIBRARIES = libgstinterleave.la
libgstinterleave_la_SOURCES = plugin.c interleave.c deinterleave.c
libgstinterleave_la_SOURCES = plugin.c deinterleave.c
libgstinterleave_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS)
libgstinterleave_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR) $(GST_BASE_LIBS) $(GST_LIBS)
libgstinterleave_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstinterleave_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = plugin.h interleave.h deinterleave.h
noinst_HEADERS = plugin.h deinterleave.h
Android.mk: Makefile.am $(BUILT_SOURCES)
androgenizer \

View file

@ -47,11 +47,11 @@
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch filesrc location=/path/to/file.mp3 ! decodebin ! audioconvert ! "audio/x-raw-int,channels=2 ! deinterleave name=d d.src0 ! queue ! audioconvert ! vorbisenc ! oggmux ! filesink location=channel1.ogg d.src1 ! queue ! audioconvert ! vorbisenc ! oggmux ! filesink location=channel2.ogg
* gst-launch filesrc location=/path/to/file.mp3 ! decodebin ! audioconvert ! "audio/x-raw,channels=2 ! deinterleave name=d d.src_0 ! queue ! audioconvert ! vorbisenc ! oggmux ! filesink location=channel1.ogg d.src_1 ! queue ! audioconvert ! vorbisenc ! oggmux ! filesink location=channel2.ogg
* ]| Decodes an MP3 file and encodes the left and right channel into separate
* Ogg Vorbis files.
* |[
* gst-launch filesrc location=file.mp3 ! decodebin ! audioconvert ! "audio/x-raw-int,channels=2" ! deinterleave name=d interleave name=i ! audioconvert ! wavenc ! filesink location=test.wav d.src0 ! queue ! audioconvert ! i.sink1 d.src1 ! queue ! audioconvert ! i.sink0
* gst-launch filesrc location=file.mp3 ! decodebin ! audioconvert ! "audio/x-raw,channels=2" ! deinterleave name=d interleave name=i ! audioconvert ! wavenc ! filesink location=test.wav d.src_0 ! queue ! audioconvert ! i.sink_1 d.src_1 ! queue ! audioconvert ! i.sink_0
* ]| Decodes and deinterleaves a Stereo MP3 file into separate channels and
* then interleaves the channels again to a WAV file with the channel with the
* channels exchanged.
@ -72,36 +72,18 @@ GST_DEBUG_CATEGORY_STATIC (gst_deinterleave_debug);
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src_%u",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
GST_STATIC_CAPS ("audio/x-raw-int, "
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " GST_AUDIO_FORMATS_ALL ", "
"rate = (int) [ 1, MAX ], "
"channels = (int) 1, "
"endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, "
"width = (int) { 8, 16, 24, 32 }, "
"depth = (int) [ 1, 32 ], "
"signed = (boolean) { true, false }; "
"audio/x-raw-float, "
"rate = (int) [ 1, MAX ], "
"channels = (int) 1, "
"endianness = (int) { LITTLE_ENDIAN , BIG_ENDIAN }, "
"width = (int) { 32, 64 }")
);
"channels = (int) 1, layout = (string) {non-interleaved, interleaved}"));
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-int, "
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " GST_AUDIO_FORMATS_ALL ", "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, "
"width = (int) { 8, 16, 24, 32 }, "
"depth = (int) [ 1, 32 ], "
"signed = (boolean) { true, false }; "
"audio/x-raw-float, "
"rate = (int) [ 1, MAX ], "
"channels = (int) [ 1, MAX ], "
"endianness = (int) { LITTLE_ENDIAN , BIG_ENDIAN }, "
"width = (int) { 32, 64 }")
);
"channels = (int) [ 1, MAX ], layout = (string) interleaved"));
#define MAKE_FUNC(type) \
static void deinterleave_##type (guint##type *out, guint##type *in, \
@ -132,8 +114,8 @@ deinterleave_24 (guint8 * out, guint8 * in, guint stride, guint nframes)
}
}
GST_BOILERPLATE (GstDeinterleave, gst_deinterleave, GstElement,
GST_TYPE_ELEMENT);
#define gst_deinterleave_parent_class parent_class
G_DEFINE_TYPE (GstDeinterleave, gst_deinterleave, GST_TYPE_ELEMENT);
enum
{
@ -141,17 +123,20 @@ enum
PROP_KEEP_POSITIONS
};
static GstFlowReturn gst_deinterleave_chain (GstPad * pad, GstBuffer * buffer);
static GstFlowReturn gst_deinterleave_chain (GstPad * pad, GstObject * parent,
GstBuffer * buffer);
static gboolean gst_deinterleave_sink_setcaps (GstPad * pad, GstCaps * caps);
static gboolean gst_deinterleave_sink_setcaps (GstDeinterleave * self,
GstCaps * caps);
static GstCaps *gst_deinterleave_sink_getcaps (GstPad * pad);
static GstStateChangeReturn
gst_deinterleave_change_state (GstElement * element, GstStateChange transition);
static gboolean gst_deinterleave_sink_activate_push (GstPad * pad,
gboolean active);
static gboolean gst_deinterleave_sink_event (GstPad * pad, GstEvent * event);
static gboolean gst_deinterleave_sink_event (GstPad * pad, GstObject * parent,
GstEvent * event);
static gboolean gst_deinterleave_src_query (GstPad * pad, GstQuery * query);
static gboolean gst_deinterleave_src_query (GstPad * pad, GstObject * parent,
GstQuery * query);
static void gst_deinterleave_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
@ -164,11 +149,6 @@ gst_deinterleave_finalize (GObject * obj)
{
GstDeinterleave *self = GST_DEINTERLEAVE (obj);
if (self->pos) {
g_free (self->pos);
self->pos = NULL;
}
if (self->pending_events) {
g_list_foreach (self->pending_events, (GFunc) gst_mini_object_unref, NULL);
g_list_free (self->pending_events);
@ -179,9 +159,13 @@ gst_deinterleave_finalize (GObject * obj)
}
static void
gst_deinterleave_base_init (gpointer g_class)
gst_deinterleave_class_init (GstDeinterleaveClass * klass)
{
GstElementClass *gstelement_class = (GstElementClass *) g_class;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
GST_DEBUG_CATEGORY_INIT (gst_deinterleave_debug, "deinterleave", 0,
"deinterleave element");
gst_element_class_set_details_simple (gstelement_class, "Audio deinterleaver",
"Filter/Converter/Audio",
@ -194,15 +178,8 @@ gst_deinterleave_base_init (gpointer g_class)
gst_static_pad_template_get (&sink_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_template));
}
static void
gst_deinterleave_class_init (GstDeinterleaveClass * klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
GST_DEBUG_CATEGORY_INIT (gst_deinterleave_debug, "deinterleave", 0,
"deinterleave element");
gstelement_class->change_state = gst_deinterleave_change_state;
gobject_class->finalize = gst_deinterleave_finalize;
gobject_class->set_property = gst_deinterleave_set_property;
@ -224,24 +201,16 @@ gst_deinterleave_class_init (GstDeinterleaveClass * klass)
}
static void
gst_deinterleave_init (GstDeinterleave * self, GstDeinterleaveClass * klass)
gst_deinterleave_init (GstDeinterleave * self)
{
self->channels = 0;
self->pos = NULL;
self->keep_positions = FALSE;
self->width = 0;
self->func = NULL;
gst_audio_info_init (&self->audio_info);
/* Add sink pad */
self->sink = gst_pad_new_from_static_template (&sink_template, "sink");
gst_pad_set_chain_function (self->sink,
GST_DEBUG_FUNCPTR (gst_deinterleave_chain));
gst_pad_set_setcaps_function (self->sink,
GST_DEBUG_FUNCPTR (gst_deinterleave_sink_setcaps));
gst_pad_set_getcaps_function (self->sink,
GST_DEBUG_FUNCPTR (gst_deinterleave_sink_getcaps));
gst_pad_set_activatepush_function (self->sink,
GST_DEBUG_FUNCPTR (gst_deinterleave_sink_activate_push));
gst_pad_set_event_function (self->sink,
GST_DEBUG_FUNCPTR (gst_deinterleave_sink_event));
gst_element_add_pad (GST_ELEMENT (self), self->sink);
@ -254,40 +223,36 @@ gst_deinterleave_add_new_pads (GstDeinterleave * self, GstCaps * caps)
guint i;
for (i = 0; i < self->channels; i++) {
for (i = 0; i < GST_AUDIO_INFO_CHANNELS (&self->audio_info); i++) {
gchar *name = g_strdup_printf ("src_%u", i);
GstCaps *srccaps;
GstAudioInfo info;
GstAudioFormat format = GST_AUDIO_INFO_FORMAT (&self->audio_info);
gint rate = GST_AUDIO_INFO_RATE (&self->audio_info);
GstAudioChannelPosition position = 0;
GstStructure *s;
/* Set channel position if we know it */
if (self->keep_positions)
position = GST_AUDIO_INFO_POSITION (&self->audio_info, i);
gst_audio_info_init (&info);
gst_audio_info_set_format (&info, format, rate, 1, &position);
srccaps = gst_audio_info_to_caps (&info);
pad = gst_pad_new_from_static_template (&src_template, name);
g_free (name);
/* Set channel position if we know it */
if (self->keep_positions) {
GstAudioChannelPosition pos[1] = { GST_AUDIO_CHANNEL_POSITION_NONE };
srccaps = gst_caps_copy (caps);
s = gst_caps_get_structure (srccaps, 0);
if (self->pos)
gst_audio_set_channel_positions (s, &self->pos[i]);
else
gst_audio_set_channel_positions (s, pos);
} else {
srccaps = caps;
}
gst_pad_set_caps (pad, srccaps);
gst_pad_use_fixed_caps (pad);
gst_pad_set_query_function (pad,
GST_DEBUG_FUNCPTR (gst_deinterleave_src_query));
gst_pad_set_active (pad, TRUE);
gst_pad_set_caps (pad, srccaps);
gst_element_add_pad (GST_ELEMENT (self), pad);
self->srcpads = g_list_prepend (self->srcpads, gst_object_ref (pad));
if (self->keep_positions)
gst_caps_unref (srccaps);
gst_caps_unref (srccaps);
}
gst_element_no_more_pads (GST_ELEMENT (self));
@ -298,34 +263,22 @@ static void
gst_deinterleave_set_pads_caps (GstDeinterleave * self, GstCaps * caps)
{
GList *l;
GstStructure *s;
gint i;
for (l = self->srcpads, i = 0; l; l = l->next, i++) {
GstPad *pad = GST_PAD (l->data);
GstCaps *srccaps;
GstAudioInfo info;
gst_audio_info_from_caps (&info, caps);
if (self->keep_positions)
GST_AUDIO_INFO_POSITION (&info, i) =
GST_AUDIO_INFO_POSITION (&self->audio_info, i);
/* Set channel position if we know it */
if (self->keep_positions) {
GstAudioChannelPosition pos[1] = { GST_AUDIO_CHANNEL_POSITION_NONE };
srccaps = gst_caps_copy (caps);
s = gst_caps_get_structure (srccaps, 0);
if (self->pos)
gst_audio_set_channel_positions (s, &self->pos[i]);
else
gst_audio_set_channel_positions (s, pos);
} else {
srccaps = caps;
}
srccaps = gst_audio_info_to_caps (&info);
gst_pad_set_caps (pad, srccaps);
if (self->keep_positions)
gst_caps_unref (srccaps);
gst_caps_unref (srccaps);
}
}
@ -345,20 +298,13 @@ gst_deinterleave_remove_pads (GstDeinterleave * self)
g_list_free (self->srcpads);
self->srcpads = NULL;
gst_pad_set_caps (self->sink, NULL);
gst_caps_replace (&self->sinkcaps, NULL);
}
static gboolean
gst_deinterleave_set_process_function (GstDeinterleave * self, GstCaps * caps)
gst_deinterleave_set_process_function (GstDeinterleave * self)
{
GstStructure *s;
s = gst_caps_get_structure (caps, 0);
if (!gst_structure_get_int (s, "width", &self->width))
return FALSE;
switch (self->width) {
switch (GST_AUDIO_INFO_WIDTH (&self->audio_info)) {
case 8:
self->func = (GstDeinterleaveFunc) deinterleave_8;
break;
@ -381,34 +327,40 @@ gst_deinterleave_set_process_function (GstDeinterleave * self, GstCaps * caps)
}
static gboolean
gst_deinterleave_sink_setcaps (GstPad * pad, GstCaps * caps)
gst_deinterleave_sink_setcaps (GstDeinterleave * self, GstCaps * caps)
{
GstDeinterleave *self;
GstCaps *srccaps;
GstStructure *s;
self = GST_DEINTERLEAVE (gst_pad_get_parent (pad));
GST_DEBUG_OBJECT (self, "got caps: %" GST_PTR_FORMAT, caps);
if (!gst_audio_info_from_caps (&self->audio_info, caps))
goto invalid_caps;
if (!gst_deinterleave_set_process_function (self))
goto unsupported_caps;
if (self->sinkcaps && !gst_caps_is_equal (caps, self->sinkcaps)) {
gint new_channels, i;
GstAudioChannelPosition *pos;
gint i;
gboolean same_layout = TRUE;
gboolean was_unpositioned;
gboolean is_unpositioned =
GST_AUDIO_INFO_IS_UNPOSITIONED (&self->audio_info);
gint new_channels = GST_AUDIO_INFO_CHANNELS (&self->audio_info);
gint old_channels;
GstAudioInfo old_info;
s = gst_caps_get_structure (caps, 0);
gst_audio_info_init (&old_info);
gst_audio_info_from_caps (&old_info, self->sinkcaps);
was_unpositioned = GST_AUDIO_INFO_IS_UNPOSITIONED (&old_info);
old_channels = GST_AUDIO_INFO_CHANNELS (&old_info);
/* We allow caps changes as long as the number of channels doesn't change
* and the channel positions stay the same. _getcaps() should've cared
* for this already but better be safe.
*/
if (!gst_structure_get_int (s, "channels", &new_channels) ||
new_channels != self->channels ||
!gst_deinterleave_set_process_function (self, caps))
if (new_channels != old_channels ||
!gst_deinterleave_set_process_function (self))
goto cannot_change_caps;
/* Now check the channel positions. If we had no channel positions
@ -416,32 +368,24 @@ gst_deinterleave_sink_setcaps (GstPad * pad, GstCaps * caps)
* If we had channel positions and get different ones things have
* changed too of course
*/
pos = gst_audio_get_channel_positions (s);
if ((pos && !self->pos) || (!pos && self->pos))
if ((!was_unpositioned && is_unpositioned) || (was_unpositioned
&& !is_unpositioned))
goto cannot_change_caps;
if (pos) {
for (i = 0; i < self->channels; i++) {
if (self->pos[i] != pos[i]) {
if (!is_unpositioned) {
if (GST_AUDIO_INFO_CHANNELS (&old_info) !=
GST_AUDIO_INFO_CHANNELS (&self->audio_info))
goto cannot_change_caps;
for (i = 0; i < GST_AUDIO_INFO_CHANNELS (&old_info); i++) {
if (self->audio_info.position[i] != old_info.position[i]) {
same_layout = FALSE;
break;
}
}
g_free (pos);
if (!same_layout)
goto cannot_change_caps;
}
} else {
s = gst_caps_get_structure (caps, 0);
if (!gst_structure_get_int (s, "channels", &self->channels))
goto no_channels;
if (!gst_deinterleave_set_process_function (self, caps))
goto unsupported_caps;
self->pos = gst_audio_get_channel_positions (s);
}
gst_caps_replace (&self->sinkcaps, caps);
@ -450,7 +394,7 @@ gst_deinterleave_sink_setcaps (GstPad * pad, GstCaps * caps)
srccaps = gst_caps_copy (caps);
s = gst_caps_get_structure (srccaps, 0);
gst_structure_set (s, "channels", G_TYPE_INT, 1, NULL);
gst_structure_remove_field (s, "channel-positions");
gst_structure_remove_field (s, "channel-mask");
/* If we already have pads, update the caps otherwise
* add new pads */
@ -461,26 +405,22 @@ gst_deinterleave_sink_setcaps (GstPad * pad, GstCaps * caps)
}
gst_caps_unref (srccaps);
gst_object_unref (self);
return TRUE;
cannot_change_caps:
{
GST_ERROR_OBJECT (self, "can't set new caps: %" GST_PTR_FORMAT, caps);
gst_object_unref (self);
return FALSE;
}
unsupported_caps:
{
GST_ERROR_OBJECT (self, "caps not supported: %" GST_PTR_FORMAT, caps);
gst_object_unref (self);
return FALSE;
}
no_channels:
invalid_caps:
{
GST_ERROR_OBJECT (self, "invalid caps");
gst_object_unref (self);
return FALSE;
}
}
@ -495,7 +435,7 @@ __remove_channels (GstCaps * caps)
size = gst_caps_get_size (caps);
for (i = 0; i < size; i++) {
s = gst_caps_get_structure (caps, i);
gst_structure_remove_field (s, "channel-positions");
gst_structure_remove_field (s, "channel-mask");
gst_structure_remove_field (s, "channels");
}
}
@ -518,9 +458,10 @@ __set_channels (GstCaps * caps, gint channels)
}
static GstCaps *
gst_deinterleave_sink_getcaps (GstPad * pad)
gst_deinterleave_sink_getcaps (GstPad * pad, GstObject * parent,
GstCaps * filter)
{
GstDeinterleave *self = GST_DEINTERLEAVE (gst_pad_get_parent (pad));
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
GstCaps *ret;
@ -544,7 +485,7 @@ gst_deinterleave_sink_getcaps (GstPad * pad)
if (pad == ourpad) {
if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK)
__set_channels (ourcaps, self->channels);
__set_channels (ourcaps, GST_AUDIO_INFO_CHANNELS (&self->audio_info));
else
__set_channels (ourcaps, 1);
} else {
@ -553,7 +494,8 @@ gst_deinterleave_sink_getcaps (GstPad * pad)
* as otherwise gst_pad_peer_get_caps() might call
* back into this function and deadlock
*/
peercaps = gst_pad_peer_get_caps (ourpad);
peercaps = gst_pad_peer_query_caps (ourpad, NULL);
peercaps = gst_caps_make_writable (peercaps);
}
/* If the peer exists and has caps add them to the intersection,
@ -581,17 +523,15 @@ gst_deinterleave_sink_getcaps (GstPad * pad)
}
GST_OBJECT_UNLOCK (self);
gst_object_unref (self);
GST_DEBUG_OBJECT (pad, "Intersected caps to %" GST_PTR_FORMAT, ret);
return ret;
}
static gboolean
gst_deinterleave_sink_event (GstPad * pad, GstEvent * event)
gst_deinterleave_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
GstDeinterleave *self = GST_DEINTERLEAVE (gst_pad_get_parent (pad));
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
gboolean ret;
@ -606,11 +546,21 @@ gst_deinterleave_sink_event (GstPad * pad, GstEvent * event)
case GST_EVENT_FLUSH_STOP:
case GST_EVENT_FLUSH_START:
case GST_EVENT_EOS:
ret = gst_pad_event_default (pad, event);
ret = gst_pad_event_default (pad, parent, event);
break;
case GST_EVENT_CAPS:
{
GstCaps *caps;
gst_event_parse_caps (event, &caps);
ret = gst_deinterleave_sink_setcaps (self, caps);
gst_event_unref (event);
break;
}
default:
if (self->srcpads) {
ret = gst_pad_event_default (pad, event);
ret = gst_pad_event_default (pad, parent, event);
} else {
GST_OBJECT_LOCK (self);
self->pending_events = g_list_append (self->pending_events, event);
@ -620,19 +570,17 @@ gst_deinterleave_sink_event (GstPad * pad, GstEvent * event)
break;
}
gst_object_unref (self);
return ret;
}
static gboolean
gst_deinterleave_src_query (GstPad * pad, GstQuery * query)
gst_deinterleave_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
{
GstDeinterleave *self = GST_DEINTERLEAVE (gst_pad_get_parent (pad));
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
gboolean res;
res = gst_pad_query_default (pad, query);
res = gst_pad_query_default (pad, parent, query);
if (res && GST_QUERY_TYPE (query) == GST_QUERY_DURATION) {
GstFormat format;
@ -645,7 +593,8 @@ gst_deinterleave_src_query (GstPad * pad, GstQuery * query)
* to get the correct value. All other formats should be fine
*/
if (format == GST_FORMAT_BYTES && dur != -1)
gst_query_set_duration (query, format, dur / self->channels);
gst_query_set_duration (query, format,
dur / GST_AUDIO_INFO_CHANNELS (&self->audio_info));
} else if (res && GST_QUERY_TYPE (query) == GST_QUERY_POSITION) {
GstFormat format;
@ -657,10 +606,17 @@ gst_deinterleave_src_query (GstPad * pad, GstQuery * query)
* to get the correct value. All other formats should be fine
*/
if (format == GST_FORMAT_BYTES && pos != -1)
gst_query_set_position (query, format, pos / self->channels);
gst_query_set_position (query, format,
pos / GST_AUDIO_INFO_CHANNELS (&self->audio_info));
} else if (res && GST_QUERY_TYPE (query) == GST_QUERY_CAPS) {
GstCaps *filter, *caps;
gst_query_parse_caps (query, &filter);
caps = gst_deinterleave_sink_getcaps (pad, parent, filter);
gst_query_set_caps_result (query, caps);
gst_caps_unref (caps);
}
gst_object_unref (self);
return res;
}
@ -701,13 +657,15 @@ gst_deinterleave_process (GstDeinterleave * self, GstBuffer * buf)
{
GstFlowReturn ret = GST_FLOW_OK;
guint channels = self->channels;
guint channels = GST_AUDIO_INFO_CHANNELS (&self->audio_info);
guint pads_pushed = 0, buffers_allocated = 0;
guint nframes = GST_BUFFER_SIZE (buf) / channels / (self->width / 8);
guint nframes =
gst_buffer_get_size (buf) / channels /
(GST_AUDIO_INFO_WIDTH (&self->audio_info) / 8);
guint bufsize = nframes * (self->width / 8);
guint bufsize = nframes * (GST_AUDIO_INFO_WIDTH (&self->audio_info) / 8);
guint i;
@ -717,6 +675,9 @@ gst_deinterleave_process (GstDeinterleave * self, GstBuffer * buf)
guint8 *in, *out;
GstMapInfo read_info;
gst_buffer_map (buf, &read_info, GST_MAP_READ);
/* Send any pending events to all src pads */
GST_OBJECT_LOCK (self);
if (self->pending_events) {
@ -741,27 +702,18 @@ gst_deinterleave_process (GstDeinterleave * self, GstBuffer * buf)
/* Allocate buffers */
for (srcs = self->srcpads, i = 0; srcs; srcs = srcs->next, i++) {
GstPad *pad = (GstPad *) srcs->data;
buffers_out[i] = NULL;
ret =
gst_pad_alloc_buffer (pad, GST_BUFFER_OFFSET_NONE, bufsize,
GST_PAD_CAPS (pad), &buffers_out[i]);
buffers_out[i] = gst_buffer_new_allocate (NULL, bufsize, 0);
/* Make sure we got a correct buffer. The only other case we allow
* here is an unliked pad */
if (ret != GST_FLOW_OK && ret != GST_FLOW_NOT_LINKED)
if (!buffers_out[i])
goto alloc_buffer_failed;
else if (buffers_out[i] && GST_BUFFER_SIZE (buffers_out[i]) != bufsize)
else if (buffers_out[i] && gst_buffer_get_size (buffers_out[i]) != bufsize)
goto alloc_buffer_bad_size;
else if (buffers_out[i] &&
!gst_caps_is_equal (GST_BUFFER_CAPS (buffers_out[i]),
GST_PAD_CAPS (pad)))
goto invalid_caps;
if (buffers_out[i]) {
gst_buffer_copy_metadata (buffers_out[i], buf,
GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_FLAGS);
gst_buffer_copy_into (buffers_out[i], buf, GST_BUFFER_COPY_METADATA, 0,
-1);
buffers_allocated++;
}
}
@ -777,14 +729,20 @@ gst_deinterleave_process (GstDeinterleave * self, GstBuffer * buf)
/* deinterleave */
for (srcs = self->srcpads, i = 0; srcs; srcs = srcs->next, i++) {
GstPad *pad = (GstPad *) srcs->data;
GstMapInfo write_info;
in = (guint8 *) GST_BUFFER_DATA (buf);
in += i * (self->width / 8);
in = (guint8 *) read_info.data;
in += i * (GST_AUDIO_INFO_WIDTH (&self->audio_info) / 8);
if (buffers_out[i]) {
out = (guint8 *) GST_BUFFER_DATA (buffers_out[i]);
gst_buffer_map (buffers_out[i], &write_info, GST_MAP_WRITE);
out = (guint8 *) write_info.data;
self->func (out, in, channels, nframes);
gst_buffer_unmap (buffers_out[i], &write_info);
ret = gst_pad_push (pad, buffers_out[i]);
buffers_out[i] = NULL;
if (ret == GST_FLOW_OK)
@ -801,6 +759,7 @@ gst_deinterleave_process (GstDeinterleave * self, GstBuffer * buf)
ret = GST_FLOW_NOT_LINKED;
done:
gst_buffer_unmap (buf, &read_info);
gst_buffer_unref (buf);
g_free (buffers_out);
return ret;
@ -817,12 +776,6 @@ alloc_buffer_bad_size:
ret = GST_FLOW_NOT_NEGOTIATED;
goto clean_buffers;
}
invalid_caps:
{
GST_WARNING ("called alloc_buffer(), but didn't get requested caps");
ret = GST_FLOW_NOT_NEGOTIATED;
goto clean_buffers;
}
push_failed:
{
GST_DEBUG ("push() failed, flow = %s", gst_flow_get_name (ret));
@ -830,6 +783,7 @@ push_failed:
}
clean_buffers:
{
gst_buffer_unmap (buf, &read_info);
for (i = 0; i < channels; i++) {
if (buffers_out[i])
gst_buffer_unref (buffers_out[i]);
@ -841,15 +795,17 @@ clean_buffers:
}
static GstFlowReturn
gst_deinterleave_chain (GstPad * pad, GstBuffer * buffer)
gst_deinterleave_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{
GstDeinterleave *self = GST_DEINTERLEAVE (GST_PAD_PARENT (pad));
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
GstFlowReturn ret;
g_return_val_if_fail (self->func != NULL, GST_FLOW_NOT_NEGOTIATED);
g_return_val_if_fail (self->width > 0, GST_FLOW_NOT_NEGOTIATED);
g_return_val_if_fail (self->channels > 0, GST_FLOW_NOT_NEGOTIATED);
g_return_val_if_fail (GST_AUDIO_INFO_WIDTH (&self->audio_info) > 0,
GST_FLOW_NOT_NEGOTIATED);
g_return_val_if_fail (GST_AUDIO_INFO_CHANNELS (&self->audio_info) > 0,
GST_FLOW_NOT_NEGOTIATED);
ret = gst_deinterleave_process (self, buffer);
@ -859,31 +815,54 @@ gst_deinterleave_chain (GstPad * pad, GstBuffer * buffer)
return ret;
}
static gboolean
gst_deinterleave_sink_activate_push (GstPad * pad, gboolean active)
static GstStateChangeReturn
gst_deinterleave_change_state (GstElement * element, GstStateChange transition)
{
GstDeinterleave *self = GST_DEINTERLEAVE (gst_pad_get_parent (pad));
GstStateChangeReturn ret;
GstDeinterleave *self = GST_DEINTERLEAVE (element);
/* Reset everything when the pad is deactivated */
if (!active) {
gst_deinterleave_remove_pads (self);
if (self->pos) {
g_free (self->pos);
self->pos = NULL;
}
self->channels = 0;
self->width = 0;
self->func = NULL;
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
gst_deinterleave_remove_pads (self);
if (self->pending_events) {
g_list_foreach (self->pending_events, (GFunc) gst_mini_object_unref,
NULL);
g_list_free (self->pending_events);
self->pending_events = NULL;
}
self->func = NULL;
if (self->pending_events) {
g_list_foreach (self->pending_events, (GFunc) gst_mini_object_unref,
NULL);
g_list_free (self->pending_events);
self->pending_events = NULL;
}
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
default:
break;
}
gst_object_unref (self);
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
return TRUE;
switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_deinterleave_remove_pads (self);
self->func = NULL;
if (self->pending_events) {
g_list_foreach (self->pending_events, (GFunc) gst_mini_object_unref,
NULL);
g_list_free (self->pending_events);
self->pending_events = NULL;
}
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
default:
break;
}
return ret;
}

View file

@ -29,7 +29,7 @@
G_BEGIN_DECLS
#include <gst/gst.h>
#include <gst/audio/multichannel.h>
#include <gst/audio/audio.h>
#define GST_TYPE_DEINTERLEAVE (gst_deinterleave_get_type())
#define GST_DEINTERLEAVE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DEINTERLEAVE,GstDeinterleave))
@ -51,13 +51,11 @@ struct _GstDeinterleave
/*< private > */
GList *srcpads;
GstCaps *sinkcaps;
gint channels;
GstAudioChannelPosition *pos;
GstAudioInfo audio_info;
gboolean keep_positions;
GstPad *sink;
gint width;
GstDeinterleaveFunc func;
GList *pending_events;

View file

@ -28,17 +28,16 @@
static gboolean
plugin_init (GstPlugin * plugin)
{
#if 0
if (!gst_element_register (plugin, "interleave",
GST_RANK_NONE, gst_interleave_get_type ()) ||
!gst_element_register (plugin, "deinterleave",
GST_RANK_NONE, gst_deinterleave_get_type ()))
return FALSE;
#endif
if (!gst_element_register (plugin, "deinterleave",
GST_RANK_NONE, gst_deinterleave_get_type ()))
return FALSE; return TRUE;}
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"interleave",
"Audio interleaver/deinterleaver",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"interleave",
"Audio interleaver/deinterleaver",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);

View file

@ -25,7 +25,9 @@
#include <gst/gst.h>
#if 0
#include "interleave.h"
#endif
#include "deinterleave.h"
#endif /* __GST_PLUGIN_INTERLEAVE_H__ */

View file

@ -22,6 +22,7 @@
#endif
#include <stdio.h>
#include <gst/audio/audio.h>
#include <gst/check/gstcheck.h>
#include <gst/audio/audio.h>
@ -48,31 +49,31 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " GST_AUDIO_NE (F32) ", "
"channels = (int) 1, " "rate = (int) {32000, 48000}"));
"channels = (int) 1, layout = (string) {interleaved, non-interleaved}, rate = (int) {32000, 48000}"));
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw, "
"format = (string) " GST_AUDIO_NE (F32) ", "
"channels = (int) { 2, 3 }, " "rate = (int) {32000, 48000}"));
"channels = (int) { 2, 3 }, layout = (string) interleaved, rate = (int) {32000, 48000}"));
#define CAPS_32khz \
"audio/x-raw, " \
"format = (string) "GST_AUDIO_NE (F32) ", " \
"channels = (int) 2, " \
"channels = (int) 2, layout = (string) interleaved, " \
"rate = (int) 32000"
#define CAPS_48khz \
"audio/x-raw, " \
"format = (string) "GST_AUDIO_NE (F32) ", " \
"channels = (int) 2, " \
"channels = (int) 2, layout = (string) interleaved, " \
"rate = (int) 48000"
#define CAPS_48khz_3CH \
"audio/x-raw, " \
"format = (string) "GST_AUDIO_NE (F32) ", " \
"channels = (int) 3, " \
"channels = (int) 3, layout = (string) interleaved, " \
"rate = (int) 48000"
static GstFlowReturn
@ -133,6 +134,7 @@ GST_START_TEST (test_2_channels)
GstCaps *caps;
gfloat *indata;
GstMapInfo map;
guint64 channel_mask = 0;
mysinkpads = g_new0 (GstPad *, 2);
nsinkpads = 0;
@ -142,8 +144,16 @@ GST_START_TEST (test_2_channels)
mysrcpad = gst_pad_new_from_static_template (&srctemplate, "src");
fail_unless (mysrcpad != NULL);
gst_pad_set_active (mysrcpad, TRUE);
caps = gst_caps_from_string (CAPS_48khz);
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
NULL);
fail_unless (gst_pad_set_caps (mysrcpad, caps));
gst_pad_use_fixed_caps (mysrcpad);
@ -162,6 +172,7 @@ GST_START_TEST (test_2_channels)
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
inbuf = gst_buffer_make_writable (inbuf);
gst_buffer_map (inbuf, &map, GST_MAP_WRITE);
indata = (gfloat *) map.data;
for (i = 0; i < 2 * 48000; i += 2) {
@ -196,6 +207,7 @@ GST_START_TEST (test_2_channels_1_linked)
GstCaps *caps;
gfloat *indata;
GstMapInfo map;
guint64 channel_mask = 0;
nsinkpads = 0;
mysinkpads = g_new0 (GstPad *, 2);
@ -205,8 +217,16 @@ GST_START_TEST (test_2_channels_1_linked)
mysrcpad = gst_pad_new_from_static_template (&srctemplate, "src");
fail_unless (mysrcpad != NULL);
gst_pad_set_active (mysrcpad, TRUE);
caps = gst_caps_from_string (CAPS_48khz);
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
NULL);
fail_unless (gst_pad_set_caps (mysrcpad, caps));
gst_pad_use_fixed_caps (mysrcpad);
@ -225,6 +245,7 @@ GST_START_TEST (test_2_channels_1_linked)
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
inbuf = gst_buffer_make_writable (inbuf);
gst_buffer_map (inbuf, &map, GST_MAP_WRITE);
indata = (gfloat *) map.data;
for (i = 0; i < 2 * 48000; i += 2) {
@ -259,6 +280,7 @@ GST_START_TEST (test_2_channels_caps_change)
GstBuffer *inbuf;
gfloat *indata;
GstMapInfo map;
guint64 channel_mask;
nsinkpads = 0;
mysinkpads = g_new0 (GstPad *, 2);
@ -269,7 +291,16 @@ GST_START_TEST (test_2_channels_caps_change)
mysrcpad = gst_pad_new_from_static_template (&srctemplate, "src");
fail_unless (mysrcpad != NULL);
gst_pad_set_active (mysrcpad, TRUE);
caps = gst_caps_from_string (CAPS_48khz);
channel_mask = 0;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
NULL);
fail_unless (gst_pad_set_caps (mysrcpad, caps));
gst_pad_use_fixed_caps (mysrcpad);
@ -288,6 +319,7 @@ GST_START_TEST (test_2_channels_caps_change)
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
inbuf = gst_buffer_make_writable (inbuf);
gst_buffer_map (inbuf, &map, GST_MAP_WRITE);
indata = (gfloat *) map.data;
for (i = 0; i < 2 * 48000; i += 2) {
@ -300,9 +332,17 @@ GST_START_TEST (test_2_channels_caps_change)
fail_unless (gst_pad_push (mysrcpad, inbuf) == GST_FLOW_OK);
caps2 = gst_caps_from_string (CAPS_32khz);
channel_mask = 0;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
gst_caps_set_simple (caps2, "channel-mask", GST_TYPE_BITMASK, channel_mask,
NULL);
gst_pad_set_caps (mysrcpad, caps2);
inbuf = gst_buffer_new_and_alloc (2 * 48000 * sizeof (gfloat));
inbuf = gst_buffer_make_writable (inbuf);
gst_buffer_map (inbuf, &map, GST_MAP_WRITE);
indata = (gfloat *) map.data;
for (i = 0; i < 2 * 48000; i += 2) {
@ -318,9 +358,19 @@ GST_START_TEST (test_2_channels_caps_change)
gst_caps_unref (caps2);
caps2 = gst_caps_from_string (CAPS_48khz_3CH);
channel_mask = 0;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
channel_mask |=
G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER;
gst_caps_set_simple (caps2, "channel-mask", GST_TYPE_BITMASK, channel_mask,
NULL);
gst_pad_set_caps (mysrcpad, caps2);
inbuf = gst_buffer_new_and_alloc (3 * 48000 * sizeof (gfloat));
inbuf = gst_buffer_make_writable (inbuf);
gst_buffer_map (inbuf, &map, GST_MAP_WRITE);
indata = (gfloat *) map.data;
for (i = 0; i < 3 * 48000; i += 3) {
@ -361,44 +411,37 @@ static void
set_channel_positions (GstCaps * caps, int channels,
GstAudioChannelPosition * channelpositions)
{
#if 0
GValue chanpos = { 0 };
GValue pos = { 0 };
GstStructure *structure = gst_caps_get_structure (caps, 0);
int c;
guint64 channel_mask = 0;
g_value_init (&chanpos, GST_TYPE_ARRAY);
g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
for (c = 0; c < channels; c++)
channel_mask |= G_GUINT64_CONSTANT (1) << channelpositions[c];
for (c = 0; c < channels; c++) {
g_value_set_enum (&pos, channelpositions[c]);
gst_value_array_append_value (&chanpos, &pos);
}
g_value_unset (&pos);
gst_structure_set_value (structure, "channel-positions", &chanpos);
g_value_unset (&chanpos);
#endif
gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
NULL);
}
static void
src_handoff_float32_8ch (GstElement * src, GstBuffer * buf, GstPad * pad,
gpointer user_data)
{
GstAudioChannelPosition layout[NUM_CHANNELS];
GstCaps *caps;
gfloat *data, *p;
guint size, i, c;
GstAudioChannelPosition layout[NUM_CHANNELS];
GstCaps *caps;
caps = gst_caps_new_simple ("audio/x-raw",
"format", G_TYPE_STRING, GST_AUDIO_NE (F32),
"channels", G_TYPE_INT, NUM_CHANNELS,
"layout", G_TYPE_STRING, "interleaved",
"rate", G_TYPE_INT, SAMPLE_RATE, NULL);
for (i = 0; i < NUM_CHANNELS; ++i)
layout[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
layout[i] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT + i;
set_channel_positions (caps, NUM_CHANNELS, layout);
gst_pad_set_caps (pad, caps);
gst_caps_unref (caps);
size = sizeof (gfloat) * SAMPLES_PER_BUFFER * NUM_CHANNELS;
data = p = (gfloat *) g_malloc (size);
@ -409,13 +452,12 @@ src_handoff_float32_8ch (GstElement * src, GstBuffer * buf, GstPad * pad,
++p;
}
}
buf = gst_buffer_new ();
gst_buffer_take_memory (buf, -1, gst_memory_new_wrapped (0, data, g_free,
size, 0, size));
GST_BUFFER_OFFSET (buf) = 0;
GST_BUFFER_TIMESTAMP (buf) = 0;
/* FIXME, caps */
}
static GstPadProbeReturn
@ -428,13 +470,13 @@ float_buffer_check_probe (GstPad * pad, GstPadProbeInfo * info,
guint num, i;
GstCaps *caps;
GstStructure *s;
#if 0
GstAudioChannelPosition *pos;
#endif
gint channels;
GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
GstAudioInfo audio_info;
gint pad_id = (gint) userdata;
fail_unless_equals_int (sscanf (GST_PAD_NAME (pad), "src%u", &padnum), 1);
fail_unless_equals_int (sscanf (GST_PAD_NAME (pad), "src_%u", &padnum), 1);
numpads = pads_created;
@ -444,12 +486,13 @@ float_buffer_check_probe (GstPad * pad, GstPadProbeInfo * info,
s = gst_caps_get_structure (caps, 0);
fail_unless (gst_structure_get_int (s, "channels", &channels));
fail_unless_equals_int (channels, 1);
fail_unless (gst_structure_has_field (s, "channel-positions"));
#if 0
pos = gst_audio_get_channel_positions (s);
fail_unless (pos != NULL && pos[0] == GST_AUDIO_CHANNEL_POSITION_NONE);
g_free (pos);
#endif
gst_audio_info_init (&audio_info);
fail_unless (gst_audio_info_from_caps (&audio_info, caps));
pos = audio_info.position;
fail_unless (pos != NULL
&& pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT + pad_id);
gst_caps_unref (caps);
gst_buffer_map (buffer, &map, GST_MAP_READ);
@ -488,14 +531,17 @@ pad_added_setup_data_check_float32_8ch_cb (GstElement * deinterleave,
fail_unless (sink != NULL);
gst_bin_add_many (GST_BIN (pipeline), queue, sink, NULL);
fail_unless (gst_element_link_many (queue, sink, NULL));
gst_element_link_pads_full (queue, "src", sink, "sink",
GST_PAD_LINK_CHECK_NOTHING);
sinkpad = gst_element_get_static_pad (queue, "sink");
fail_unless_equals_int (gst_pad_link (pad, sinkpad), GST_PAD_LINK_OK);
gst_object_unref (sinkpad);
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER, float_buffer_check_probe,
NULL, NULL);
(gpointer) pads_created, NULL);
gst_element_set_state (sink, GST_STATE_PLAYING);
gst_element_set_state (queue, GST_STATE_PLAYING);