*
* 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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/* TODO:
* <refsect2>
* <title>Example launch line</title>
* |[
- * 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
+ * gst-launch-1.0 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,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
+ * gst-launch-1.0 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.
GST_DEBUG_CATEGORY_INIT (gst_deinterleave_debug, "deinterleave", 0,
"deinterleave element");
- gst_element_class_set_details_simple (gstelement_class, "Audio deinterleaver",
- "Filter/Converter/Audio",
+ gst_element_class_set_static_metadata (gstelement_class,
+ "Audio deinterleaver", "Filter/Converter/Audio",
"Splits one interleaved multichannel audio stream into many mono audio streams",
- "Andy Wingo <wingo at pobox.com>, "
- "Iain <iain@prettypeople.org>, "
+ "Andy Wingo <wingo at pobox.com>, " "Iain <iain@prettypeople.org>, "
"Sebastian Dröge <slomo@circular-chaos.org>");
gst_element_class_add_pad_template (gstelement_class,
gst_element_add_pad (GST_ELEMENT (self), self->sink);
}
+typedef struct
+{
+ GstCaps *caps;
+ GstPad *pad;
+} CopyStickyEventsData;
+
+static gboolean
+copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
+{
+ CopyStickyEventsData *data = user_data;
+
+ if (GST_EVENT_TYPE (*event) >= GST_EVENT_CAPS && data->caps) {
+ gst_pad_set_caps (data->pad, data->caps);
+ data->caps = NULL;
+ }
+
+ if (GST_EVENT_TYPE (*event) != GST_EVENT_CAPS)
+ gst_pad_push_event (data->pad, gst_event_ref (*event));
+
+ return TRUE;
+}
+
static void
gst_deinterleave_add_new_pads (GstDeinterleave * self, GstCaps * caps)
{
GstPad *pad;
-
guint 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;
+ GstAudioChannelPosition position = GST_AUDIO_CHANNEL_POSITION_MONO;
+ CopyStickyEventsData data;
/* Set channel position if we know it */
if (self->keep_positions)
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);
+
+ data.pad = pad;
+ data.caps = srccaps;
+ gst_pad_sticky_events_foreach (self->sink, copy_sticky_events, &data);
+ if (data.caps)
+ gst_pad_set_caps (pad, data.caps);
gst_element_add_pad (GST_ELEMENT (self), pad);
self->srcpads = g_list_prepend (self->srcpads, gst_object_ref (pad));
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 (&info, 0) =
GST_AUDIO_INFO_POSITION (&self->audio_info, i);
srccaps = gst_audio_info_to_caps (&info);
cannot_change_caps:
{
- GST_ERROR_OBJECT (self, "can't set new caps: %" GST_PTR_FORMAT, caps);
+ GST_WARNING_OBJECT (self, "caps change from %" GST_PTR_FORMAT
+ " to %" GST_PTR_FORMAT " not supported: channel number or channel "
+ "positions change", self->sinkcaps, caps);
return FALSE;
}
unsupported_caps:
__remove_channels (GstCaps * caps)
{
GstStructure *s;
-
gint i, size;
size = gst_caps_get_size (caps);
__set_channels (GstCaps * caps, gint channels)
{
GstStructure *s;
-
gint i, size;
size = gst_caps_get_size (caps);
GstCaps * filter)
{
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
-
GstCaps *ret;
-
GList *l;
GST_OBJECT_LOCK (self);
ret = gst_caps_new_any ();
for (l = GST_ELEMENT (self)->pads; l != NULL; l = l->next) {
GstPad *ourpad = GST_PAD (l->data);
-
GstCaps *peercaps = NULL, *ourcaps;
ourcaps = gst_caps_copy (gst_pad_get_pad_template_caps (ourpad));
* otherwise assume that the peer accepts everything */
if (peercaps) {
GstCaps *intersection;
-
GstCaps *oldret = ret;
__remove_channels (peercaps);
gst_deinterleave_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
-
gboolean ret;
GST_DEBUG ("Got %s event on pad %s:%s", GST_EVENT_TYPE_NAME (event),
}
default:
- if (self->srcpads) {
- ret = gst_pad_event_default (pad, parent, event);
- } else {
+ if (!self->srcpads && !GST_EVENT_IS_STICKY (event)) {
+ /* Sticky events are copied when creating a new pad */
GST_OBJECT_LOCK (self);
self->pending_events = g_list_append (self->pending_events, event);
GST_OBJECT_UNLOCK (self);
ret = TRUE;
+ } else {
+ ret = gst_pad_event_default (pad, parent, event);
}
break;
}
gst_deinterleave_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
{
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
-
gboolean res;
res = gst_pad_query_default (pad, parent, query);
if (res && GST_QUERY_TYPE (query) == GST_QUERY_DURATION) {
GstFormat format;
-
gint64 dur;
gst_query_parse_duration (query, &format, &dur);
dur / GST_AUDIO_INFO_CHANNELS (&self->audio_info));
} else if (res && GST_QUERY_TYPE (query) == GST_QUERY_POSITION) {
GstFormat format;
-
gint64 pos;
gst_query_parse_position (query, &format, &pos);
gst_deinterleave_process (GstDeinterleave * self, GstBuffer * buf)
{
GstFlowReturn ret = GST_FLOW_OK;
-
guint channels = GST_AUDIO_INFO_CHANNELS (&self->audio_info);
-
guint pads_pushed = 0, buffers_allocated = 0;
-
guint nframes =
gst_buffer_get_size (buf) / channels /
(GST_AUDIO_INFO_WIDTH (&self->audio_info) / 8);
-
guint bufsize = nframes * (GST_AUDIO_INFO_WIDTH (&self->audio_info) / 8);
-
guint i;
-
GList *srcs;
-
GstBuffer **buffers_out = g_new0 (GstBuffer *, channels);
-
guint8 *in, *out;
-
GstMapInfo read_info;
- gst_buffer_map (buf, &read_info, GST_MAP_READ);
+ GList *pending_events, *l;
/* Send any pending events to all src pads */
GST_OBJECT_LOCK (self);
- if (self->pending_events) {
- GList *events;
+ pending_events = self->pending_events;
+ self->pending_events = NULL;
+ GST_OBJECT_UNLOCK (self);
+ if (pending_events) {
GstEvent *event;
GST_DEBUG_OBJECT (self, "Sending pending events to all src pads");
-
- for (events = self->pending_events; events != NULL; events = events->next) {
- event = GST_EVENT (events->data);
-
+ for (l = pending_events; l; l = l->next) {
+ event = l->data;
for (srcs = self->srcpads; srcs != NULL; srcs = srcs->next)
gst_pad_push_event (GST_PAD (srcs->data), gst_event_ref (event));
gst_event_unref (event);
}
-
- g_list_free (self->pending_events);
- self->pending_events = NULL;
+ g_list_free (pending_events);
}
- GST_OBJECT_UNLOCK (self);
+
+ gst_buffer_map (buf, &read_info, GST_MAP_READ);
/* Allocate buffers */
for (srcs = self->srcpads, i = 0; srcs; srcs = srcs->next, i++) {
- buffers_out[i] = gst_buffer_new_allocate (NULL, bufsize, 0);
+ buffers_out[i] = gst_buffer_new_allocate (NULL, bufsize, NULL);
/* Make sure we got a correct buffer. The only other case we allow
* here is an unliked pad */
GstPad *pad = (GstPad *) srcs->data;
GstMapInfo write_info;
-
in = (guint8 *) read_info.data;
in += i * (GST_AUDIO_INFO_WIDTH (&self->audio_info) / 8);
if (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]);
if (!pads_pushed)
ret = GST_FLOW_NOT_LINKED;
+ GST_DEBUG_OBJECT (self, "Pushed on %d pads", pads_pushed);
+
done:
gst_buffer_unmap (buf, &read_info);
gst_buffer_unref (buf);
gst_deinterleave_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{
GstDeinterleave *self = GST_DEINTERLEAVE (parent);
-
GstFlowReturn ret;
g_return_val_if_fail (self->func != NULL, GST_FLOW_NOT_NEGOTIATED);