1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
2 /* GStreamer AIFF parser
3 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * <2006> Nokia Corporation, Stefan Kost <stefan.kost@nokia.com>.
5 * <2008> Pioneers of the Inevitable <songbird@songbirdnest.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 * SECTION:element-aiffparse
29 * Parse a .aiff file into raw or compressed audio.
32 * AIFFparse supports both push and pull mode operations, making it possible to
33 * stream from a network source.
35 * <title>Example launch line</title>
38 * gst-launch filesrc location=sine.aiff ! aiffparse ! audioconvert ! alsasink
40 * Read a aiff file and output to the soundcard using the ALSA element. The
41 * aiff file is assumed to contain raw uncompressed samples.
45 * gst-launch gnomevfssrc location=http://www.example.org/sine.aiff ! queue ! aiffparse ! audioconvert ! alsasink
47 * Stream data from a network url.
56 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
57 * with newer GLib versions (>= 2.31.0) */
58 #define GLIB_DISABLE_DEPRECATION_WARNINGS
63 #include "aiffparse.h"
64 #include <gst/audio/audio.h>
65 #include <gst/tag/tag.h>
66 #include <gst/gst-i18n-plugin.h>
68 GST_DEBUG_CATEGORY (aiffparse_debug);
69 #define GST_CAT_DEFAULT (aiffparse_debug)
71 static void gst_aiff_parse_dispose (GObject * object);
73 static gboolean gst_aiff_parse_sink_activate (GstPad * sinkpad,
75 static gboolean gst_aiff_parse_sink_activate_mode (GstPad * sinkpad,
76 GstObject * parent, GstPadMode mode, gboolean active);
77 static gboolean gst_aiff_parse_send_event (GstElement * element,
79 static GstStateChangeReturn gst_aiff_parse_change_state (GstElement * element,
80 GstStateChange transition);
82 static gboolean gst_aiff_parse_pad_query (GstPad * pad, GstObject * parent,
84 static gboolean gst_aiff_parse_pad_convert (GstPad * pad,
86 gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
88 static GstFlowReturn gst_aiff_parse_chain (GstPad * pad, GstObject * parent,
90 static void gst_aiff_parse_loop (GstPad * pad);
91 static gboolean gst_aiff_parse_srcpad_event (GstPad * pad, GstObject * parent,
94 static GstStaticPadTemplate sink_template_factory =
95 GST_STATIC_PAD_TEMPLATE ("sink",
98 GST_STATIC_CAPS ("audio/x-aiff")
101 static GstStaticPadTemplate src_template_factory =
102 GST_STATIC_PAD_TEMPLATE ("src",
105 GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE ("{ S8, S16BE, S16LE, S24BE, S24LE, "
106 "S32LE, S32BE, F32BE, F64BE }"))
109 #define gst_aiff_parse_parent_class parent_class
110 G_DEFINE_TYPE (GstAiffParse, gst_aiff_parse, GST_TYPE_ELEMENT);
113 gst_aiff_parse_class_init (GstAiffParseClass * klass)
115 GstElementClass *gstelement_class;
116 GObjectClass *object_class;
118 gstelement_class = (GstElementClass *) klass;
119 object_class = (GObjectClass *) klass;
121 object_class->dispose = gst_aiff_parse_dispose;
123 gst_element_class_add_pad_template (gstelement_class,
124 gst_static_pad_template_get (&sink_template_factory));
125 gst_element_class_add_pad_template (gstelement_class,
126 gst_static_pad_template_get (&src_template_factory));
128 gst_element_class_set_static_metadata (gstelement_class,
129 "AIFF audio demuxer", "Codec/Demuxer/Audio",
130 "Parse a .aiff file into raw audio",
131 "Pioneers of the Inevitable <songbird@songbirdnest.com>");
133 gstelement_class->change_state =
134 GST_DEBUG_FUNCPTR (gst_aiff_parse_change_state);
135 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_aiff_parse_send_event);
139 gst_aiff_parse_reset (GstAiffParse * aiff)
141 aiff->state = AIFF_PARSE_START;
143 /* These will all be set correctly in the fmt chunk */
150 aiff->end_offset = 0;
155 aiff->got_comm = FALSE;
157 if (aiff->seek_event)
158 gst_event_unref (aiff->seek_event);
159 aiff->seek_event = NULL;
161 gst_adapter_clear (aiff->adapter);
162 aiff->adapter = NULL;
165 if (aiff->tags != NULL) {
166 gst_tag_list_unref (aiff->tags);
172 gst_aiff_parse_dispose (GObject * object)
174 GstAiffParse *aiff = GST_AIFF_PARSE (object);
176 GST_DEBUG_OBJECT (aiff, "AIFF: Dispose");
177 gst_aiff_parse_reset (aiff);
179 G_OBJECT_CLASS (parent_class)->dispose (object);
183 gst_aiff_parse_init (GstAiffParse * aiffparse)
185 gst_aiff_parse_reset (aiffparse);
189 gst_pad_new_from_static_template (&sink_template_factory, "sink");
190 gst_pad_set_activate_function (aiffparse->sinkpad,
191 GST_DEBUG_FUNCPTR (gst_aiff_parse_sink_activate));
192 gst_pad_set_activatemode_function (aiffparse->sinkpad,
193 GST_DEBUG_FUNCPTR (gst_aiff_parse_sink_activate_mode));
194 gst_pad_set_chain_function (aiffparse->sinkpad,
195 GST_DEBUG_FUNCPTR (gst_aiff_parse_chain));
196 gst_element_add_pad (GST_ELEMENT_CAST (aiffparse), aiffparse->sinkpad);
200 gst_pad_new_from_static_template (&src_template_factory, "src");
201 gst_pad_use_fixed_caps (aiffparse->srcpad);
202 gst_pad_set_query_function (aiffparse->srcpad,
203 GST_DEBUG_FUNCPTR (gst_aiff_parse_pad_query));
204 gst_pad_set_event_function (aiffparse->srcpad,
205 GST_DEBUG_FUNCPTR (gst_aiff_parse_srcpad_event));
206 gst_element_add_pad (GST_ELEMENT_CAST (aiffparse), aiffparse->srcpad);
210 gst_aiff_parse_parse_file_header (GstAiffParse * aiff, GstBuffer * buf)
212 guint32 header, type = 0;
215 if (!gst_buffer_map (buf, &info, GST_MAP_READ)) {
216 GST_WARNING_OBJECT (aiff, "Could not map buffer");
220 if (info.size < 12) {
221 GST_WARNING_OBJECT (aiff, "Buffer too short");
222 gst_buffer_unmap (buf, &info);
226 header = GST_READ_UINT32_LE (info.data);
227 type = GST_READ_UINT32_LE (info.data + 8);
228 gst_buffer_unmap (buf, &info);
230 if (header != GST_MAKE_FOURCC ('F', 'O', 'R', 'M'))
233 if (type == GST_MAKE_FOURCC ('A', 'I', 'F', 'F'))
234 aiff->is_aifc = FALSE;
235 else if (type == GST_MAKE_FOURCC ('A', 'I', 'F', 'C'))
236 aiff->is_aifc = TRUE;
240 gst_buffer_unref (buf);
246 GST_ELEMENT_ERROR (aiff, STREAM, WRONG_TYPE, (NULL),
247 ("File is not an AIFF file: %" GST_FOURCC_FORMAT,
248 GST_FOURCC_ARGS (type)));
249 gst_buffer_unref (buf);
255 gst_aiff_parse_stream_init (GstAiffParse * aiff)
258 GstBuffer *buf = NULL;
260 if ((res = gst_pad_pull_range (aiff->sinkpad,
261 aiff->offset, 12, &buf)) != GST_FLOW_OK)
263 else if (!gst_aiff_parse_parse_file_header (aiff, buf))
264 return GST_FLOW_ERROR;
271 /* This function is used to perform seeks on the element in
274 * It also works when event is NULL, in which case it will just
275 * start from the last configured segment. This technique is
276 * used when activating the element and to perform the seek in
280 gst_aiff_parse_perform_seek (GstAiffParse * aiff, GstEvent * event)
286 GstSeekType cur_type = GST_SEEK_TYPE_NONE, stop_type;
287 gint64 cur, stop, upstream_size;
290 GstSegment seeksegment = { 0, };
294 GST_DEBUG_OBJECT (aiff, "doing seek with event");
296 gst_event_parse_seek (event, &rate, &format, &flags,
297 &cur_type, &cur, &stop_type, &stop);
299 /* no negative rates yet */
303 if (format != aiff->segment.format) {
304 GST_INFO_OBJECT (aiff, "converting seek-event from %s to %s",
305 gst_format_get_name (format),
306 gst_format_get_name (aiff->segment.format));
308 if (cur_type != GST_SEEK_TYPE_NONE)
310 gst_pad_query_convert (aiff->srcpad, format, cur,
311 aiff->segment.format, &cur);
312 if (res && stop_type != GST_SEEK_TYPE_NONE)
314 gst_pad_query_convert (aiff->srcpad, format, stop,
315 aiff->segment.format, &stop);
319 format = aiff->segment.format;
322 GST_DEBUG_OBJECT (aiff, "doing seek without event");
325 cur_type = GST_SEEK_TYPE_SET;
326 stop_type = GST_SEEK_TYPE_SET;
330 flush = flags & GST_SEEK_FLAG_FLUSH;
332 /* now we need to make sure the streaming thread is stopped. We do this by
333 * either sending a FLUSH_START event downstream which will cause the
334 * streaming thread to stop with a FLUSHING.
335 * For a non-flushing seek we simply pause the task, which will happen as soon
336 * as it completes one iteration (and thus might block when the sink is
337 * blocking in preroll). */
339 GST_DEBUG_OBJECT (aiff, "sending flush start");
340 gst_pad_push_event (aiff->srcpad, gst_event_new_flush_start ());
342 gst_pad_pause_task (aiff->sinkpad);
345 /* we should now be able to grab the streaming thread because we stopped it
346 * with the above flush/pause code */
347 GST_PAD_STREAM_LOCK (aiff->sinkpad);
349 /* save current position */
350 position = aiff->segment.position;
352 GST_DEBUG_OBJECT (aiff, "stopped streaming at %" G_GINT64_FORMAT, position);
354 /* copy segment, we need this because we still need the old
355 * segment when we close the current segment. */
356 memcpy (&seeksegment, &aiff->segment, sizeof (GstSegment));
358 /* configure the seek parameters in the seeksegment. We will then have the
359 * right values in the segment to perform the seek */
361 GST_DEBUG_OBJECT (aiff, "configuring seek");
362 gst_segment_do_seek (&seeksegment, rate, format, flags,
363 cur_type, cur, stop_type, stop, &update);
366 /* figure out the last position we need to play. If it's configured (stop !=
367 * -1), use that, else we play until the total duration of the file */
368 if ((stop = seeksegment.stop) == -1)
369 stop = seeksegment.duration;
371 GST_DEBUG_OBJECT (aiff, "cur_type =%d", cur_type);
372 if ((cur_type != GST_SEEK_TYPE_NONE)) {
373 /* bring offset to bytes, if the bps is 0, we have the segment in BYTES and
374 * we can just copy the position. If not, we use the bps to convert TIME to
378 gst_util_uint64_scale_ceil (seeksegment.position,
379 (guint64) aiff->bps, GST_SECOND);
381 aiff->offset = seeksegment.position;
382 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
383 aiff->offset -= (aiff->offset % aiff->bytes_per_sample);
384 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
385 aiff->offset += aiff->datastart;
386 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
388 GST_LOG_OBJECT (aiff, "continue from offset=%" G_GUINT64_FORMAT,
392 if (stop_type != GST_SEEK_TYPE_NONE) {
395 gst_util_uint64_scale_ceil (stop, (guint64) aiff->bps, GST_SECOND);
397 aiff->end_offset = stop;
398 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
399 aiff->end_offset -= (aiff->end_offset % aiff->bytes_per_sample);
400 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
401 aiff->end_offset += aiff->datastart;
402 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
404 GST_LOG_OBJECT (aiff, "continue to end_offset=%" G_GUINT64_FORMAT,
408 /* make sure filesize is not exceeded due to rounding errors or so,
409 * same precaution as in _stream_headers */
410 if (gst_pad_peer_query_duration (aiff->sinkpad, GST_FORMAT_BYTES,
412 aiff->end_offset = MIN (aiff->end_offset, upstream_size);
414 /* this is the range of bytes we will use for playback */
415 aiff->offset = MIN (aiff->offset, aiff->end_offset);
416 aiff->dataleft = aiff->end_offset - aiff->offset;
418 GST_DEBUG_OBJECT (aiff,
419 "seek: rate %lf, offset %" G_GUINT64_FORMAT ", end %" G_GUINT64_FORMAT
420 ", segment %" GST_TIME_FORMAT " -- %" GST_TIME_FORMAT, rate, aiff->offset,
421 aiff->end_offset, GST_TIME_ARGS (seeksegment.start),
422 GST_TIME_ARGS (stop));
424 /* prepare for streaming again */
426 /* if we sent a FLUSH_START, we now send a FLUSH_STOP */
427 GST_DEBUG_OBJECT (aiff, "sending flush stop");
428 gst_pad_push_event (aiff->srcpad, gst_event_new_flush_stop (TRUE));
431 /* now we did the seek and can activate the new segment values */
432 memcpy (&aiff->segment, &seeksegment, sizeof (GstSegment));
434 /* if we're doing a segment seek, post a SEGMENT_START message */
435 if (aiff->segment.flags & GST_SEEK_FLAG_SEGMENT) {
436 gst_element_post_message (GST_ELEMENT_CAST (aiff),
437 gst_message_new_segment_start (GST_OBJECT_CAST (aiff),
438 aiff->segment.format, aiff->segment.position));
441 /* now create the newsegment */
442 GST_DEBUG_OBJECT (aiff, "Creating newsegment from %" G_GINT64_FORMAT
443 " to %" G_GINT64_FORMAT, aiff->segment.position, stop);
445 /* store the newsegment event so it can be sent from the streaming thread. */
446 if (aiff->start_segment)
447 gst_event_unref (aiff->start_segment);
448 aiff->start_segment = gst_event_new_segment (&aiff->segment);
450 /* mark discont if we are going to stream from another position. */
451 if (position != aiff->segment.position) {
452 GST_DEBUG_OBJECT (aiff, "mark DISCONT, we did a seek to another position");
453 aiff->discont = TRUE;
456 /* and start the streaming task again */
457 aiff->segment_running = TRUE;
458 if (!aiff->streaming) {
459 gst_pad_start_task (aiff->sinkpad, (GstTaskFunction) gst_aiff_parse_loop,
460 aiff->sinkpad, NULL);
463 GST_PAD_STREAM_UNLOCK (aiff->sinkpad);
470 GST_DEBUG_OBJECT (aiff, "negative playback rates are not supported yet.");
475 GST_DEBUG_OBJECT (aiff, "unsupported format given, seek aborted.");
481 * gst_aiff_parse_peek_chunk_info:
482 * @aiff AIFFparse object
483 * @tag holder for tag
484 * @size holder for tag size
486 * Peek next chunk info (tag and size)
488 * Returns: %TRUE when the chunk info (header) is available
491 gst_aiff_parse_peek_chunk_info (GstAiffParse * aiff, guint32 * tag,
494 const guint8 *data = NULL;
496 if (gst_adapter_available (aiff->adapter) < 8)
499 data = gst_adapter_map (aiff->adapter, 8);
500 *tag = GST_READ_UINT32_LE (data);
501 *size = GST_READ_UINT32_BE (data + 4);
502 gst_adapter_unmap (aiff->adapter);
504 GST_DEBUG ("Next chunk size is %d bytes, type %" GST_FOURCC_FORMAT, *size,
505 GST_FOURCC_ARGS (*tag));
511 * gst_aiff_parse_peek_chunk:
512 * @aiff AIFFparse object
513 * @tag holder for tag
514 * @size holder for tag size
516 * Peek enough data for one full chunk
518 * Returns: %TRUE when the full chunk is available
521 gst_aiff_parse_peek_chunk (GstAiffParse * aiff, guint32 * tag, guint32 * size)
523 guint32 peek_size = 0;
526 if (!gst_aiff_parse_peek_chunk_info (aiff, tag, size))
529 GST_DEBUG ("Need to peek chunk of %d bytes", *size);
530 peek_size = (*size + 1) & ~1;
532 available = gst_adapter_available (aiff->adapter);
533 if (available >= (8 + peek_size)) {
536 GST_LOG ("but only %u bytes available now", available);
542 gst_aiff_parse_peek_data (GstAiffParse * aiff, guint32 size,
543 const guint8 ** data)
545 if (gst_adapter_available (aiff->adapter) < size)
548 *data = gst_adapter_map (aiff->adapter, size);
553 * gst_aiff_parse_calculate_duration:
554 * @aiff: aiffparse object
556 * Calculate duration on demand and store in @aiff.
558 * Returns: %TRUE if duration is available.
561 gst_aiff_parse_calculate_duration (GstAiffParse * aiff)
563 if (aiff->duration > 0)
566 if (aiff->datasize > 0 && aiff->bps > 0) {
568 gst_util_uint64_scale_ceil (aiff->datasize, GST_SECOND,
569 (guint64) aiff->bps);
570 GST_INFO_OBJECT (aiff, "Got duration %" GST_TIME_FORMAT,
571 GST_TIME_ARGS (aiff->duration));
578 gst_aiff_parse_ignore_chunk (GstAiffParse * aiff, GstBuffer * buf, guint32 tag,
583 if (aiff->streaming) {
584 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
587 GST_DEBUG_OBJECT (aiff, "Ignoring tag %" GST_FOURCC_FORMAT,
588 GST_FOURCC_ARGS (tag));
589 flush = 8 + ((size + 1) & ~1);
590 aiff->offset += flush;
591 if (aiff->streaming) {
592 gst_adapter_flush (aiff->adapter, flush);
594 gst_buffer_unref (buf);
599 gst_aiff_parse_read_IEEE80 (guint8 * buf)
601 int s = buf[0] & 0xff;
602 int e = ((buf[0] & 0x7f) << 8) | (buf[1] & 0xff);
603 double f = ((unsigned long) (buf[2] & 0xff) << 24) |
604 ((buf[3] & 0xff) << 16) | ((buf[4] & 0xff) << 8) | (buf[5] & 0xff);
608 return HUGE_VAL; /* Really NaN, but this won't happen in reality */
618 f += ((buf[6] & 0xff) << 24) |
619 ((buf[7] & 0xff) << 16) | ((buf[8] & 0xff) << 8) | (buf[9] & 0xff);
621 return ldexp (f, e - 16446);
625 gst_aiff_parse_parse_comm (GstAiffParse * aiff, GstBuffer * buf)
631 if (!gst_buffer_map (buf, &info, GST_MAP_READ)) {
632 GST_WARNING_OBJECT (aiff, "Can't map buffer");
633 gst_buffer_unref (buf);
642 if (info.size < size)
645 aiff->channels = GST_READ_UINT16_BE (info.data);
646 aiff->total_frames = GST_READ_UINT32_BE (info.data + 2);
647 aiff->depth = GST_READ_UINT16_BE (info.data + 6);
648 aiff->width = GST_ROUND_UP_8 (aiff->depth);
649 aiff->rate = (int) gst_aiff_parse_read_IEEE80 (info.data + 8);
651 aiff->floating_point = FALSE;
654 fourcc = GST_READ_UINT32_LE (info.data + 18);
656 /* We only support the 'trivial' uncompressed AIFC, but it can be
657 * either big or little endian */
659 case GST_MAKE_FOURCC ('N', 'O', 'N', 'E'):
660 aiff->endianness = G_BIG_ENDIAN;
662 case GST_MAKE_FOURCC ('s', 'o', 'w', 't'):
663 aiff->endianness = G_LITTLE_ENDIAN;
665 case GST_MAKE_FOURCC ('F', 'L', '3', '2'):
666 case GST_MAKE_FOURCC ('f', 'l', '3', '2'):
667 aiff->floating_point = TRUE;
668 aiff->width = aiff->depth = 32;
669 aiff->endianness = G_BIG_ENDIAN;
671 case GST_MAKE_FOURCC ('f', 'l', '6', '4'):
672 aiff->floating_point = TRUE;
673 aiff->width = aiff->depth = 64;
674 aiff->endianness = G_BIG_ENDIAN;
677 goto unknown_compression;
680 aiff->endianness = G_BIG_ENDIAN;
682 gst_buffer_unmap (buf, &info);
683 gst_buffer_unref (buf);
690 GST_WARNING_OBJECT (aiff, "COMM chunk too short, cannot parse header");
691 gst_buffer_unmap (buf, &info);
692 gst_buffer_unref (buf);
697 GST_WARNING_OBJECT (aiff, "Unsupported compression in AIFC "
698 "file: %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
699 gst_buffer_unmap (buf, &info);
700 gst_buffer_unref (buf);
706 gst_aiff_parse_read_chunk (GstAiffParse * aiff, guint64 * offset, guint32 * tag,
715 gst_pad_pull_range (aiff->sinkpad, *offset, 8, &buf)) != GST_FLOW_OK)
718 gst_buffer_map (buf, &info, GST_MAP_READ);
719 *tag = GST_READ_UINT32_LE (info.data);
720 size = GST_READ_UINT32_BE (info.data + 4);
721 gst_buffer_unmap (buf, &info);
722 gst_buffer_unref (buf);
725 gst_pad_pull_range (aiff->sinkpad, (*offset) + 8, size,
726 &buf)) != GST_FLOW_OK)
728 else if (gst_buffer_get_size (buf) < size)
732 *offset += 8 + GST_ROUND_UP_2 (size);
739 /* short read, we return EOS to mark the EOS case */
740 GST_DEBUG_OBJECT (aiff,
741 "not enough data (available=%" G_GSIZE_FORMAT ", needed=%u)",
742 gst_buffer_get_size (buf), size);
743 gst_buffer_unref (buf);
750 gst_aiff_parse_create_caps (GstAiffParse * aiff)
752 GstCaps *caps = NULL;
753 const gchar *format = NULL;
755 if (aiff->floating_point) {
756 if (aiff->endianness == G_BIG_ENDIAN) {
757 if (aiff->width == 32)
759 else if (aiff->width == 32)
763 if (aiff->endianness == G_BIG_ENDIAN) {
764 if (aiff->width == 8)
766 else if (aiff->width == 16)
768 else if (aiff->width == 24)
770 else if (aiff->width == 32)
773 if (aiff->width == 8)
775 else if (aiff->width == 16)
777 else if (aiff->width == 24)
779 else if (aiff->width == 32)
784 caps = gst_caps_new_simple ("audio/x-raw",
785 "format", G_TYPE_STRING, format,
786 "channels", G_TYPE_INT, aiff->channels,
787 "rate", G_TYPE_INT, aiff->rate, NULL);
790 GST_DEBUG_OBJECT (aiff, "Created caps: %" GST_PTR_FORMAT, caps);
796 gst_aiff_parse_stream_headers (GstAiffParse * aiff)
801 gboolean gotdata = FALSE;
802 gboolean done = FALSE;
804 gint64 upstream_size = 0;
806 gst_pad_peer_query_duration (aiff->sinkpad, GST_FORMAT_BYTES, &upstream_size);
807 GST_DEBUG_OBJECT (aiff, "upstream size %" G_GUINT64_FORMAT, upstream_size);
809 /* loop headers until we get data */
811 if (aiff->streaming) {
812 if (!gst_aiff_parse_peek_chunk_info (aiff, &tag, &size))
818 gst_pad_pull_range (aiff->sinkpad, aiff->offset, 8,
819 &buf)) != GST_FLOW_OK)
820 goto header_read_error;
822 gst_buffer_map (buf, &info, GST_MAP_READ);
823 tag = GST_READ_UINT32_LE (info.data);
824 size = GST_READ_UINT32_BE (info.data + 4);
825 gst_buffer_unmap (buf, &info);
828 GST_INFO_OBJECT (aiff,
829 "Got TAG: %" GST_FOURCC_FORMAT ", offset %" G_GUINT64_FORMAT,
830 GST_FOURCC_ARGS (tag), aiff->offset);
832 /* We just keep reading chunks until we find the one we're interested in.
835 case GST_MAKE_FOURCC ('C', 'O', 'M', 'M'):{
838 if (aiff->streaming) {
839 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
842 gst_adapter_flush (aiff->adapter, 8);
845 buf = gst_adapter_take_buffer (aiff->adapter, size);
847 if ((res = gst_aiff_parse_read_chunk (aiff,
848 &aiff->offset, &tag, &buf)) != GST_FLOW_OK)
852 if (!gst_aiff_parse_parse_comm (aiff, buf))
853 goto parse_header_error;
855 /* do sanity checks of header fields */
856 if (aiff->channels == 0)
861 GST_DEBUG_OBJECT (aiff, "creating the caps");
863 caps = gst_aiff_parse_create_caps (aiff);
867 gst_pad_push_event (aiff->srcpad, gst_event_new_caps (caps));
868 gst_caps_unref (caps);
870 aiff->bytes_per_sample = aiff->channels * aiff->width / 8;
871 aiff->bps = aiff->bytes_per_sample * aiff->rate;
873 if (aiff->bytes_per_sample <= 0)
874 goto no_bytes_per_sample;
876 aiff->got_comm = TRUE;
879 case GST_MAKE_FOURCC ('S', 'S', 'N', 'D'):{
882 GST_DEBUG_OBJECT (aiff, "Got 'SSND' TAG, size : %d", size);
884 /* Now, read the 8-byte header in the SSND chunk */
885 if (aiff->streaming) {
886 const guint8 *ssnddata = NULL;
888 if (!gst_aiff_parse_peek_data (aiff, 16, &ssnddata))
891 aiff->ssnd_offset = GST_READ_UINT32_BE (ssnddata + 8);
892 aiff->ssnd_blocksize = GST_READ_UINT32_BE (ssnddata + 12);
893 gst_adapter_unmap (aiff->adapter);
894 gst_adapter_flush (aiff->adapter, 16);
896 GstBuffer *ssndbuf = NULL;
899 gst_buffer_unref (buf);
901 gst_pad_pull_range (aiff->sinkpad, aiff->offset, 16,
902 &ssndbuf)) != GST_FLOW_OK)
903 goto header_read_error;
905 gst_buffer_map (ssndbuf, &info, GST_MAP_READ);
906 aiff->ssnd_offset = GST_READ_UINT32_BE (info.data + 8);
907 aiff->ssnd_blocksize = GST_READ_UINT32_BE (info.data + 12);
908 gst_buffer_unmap (ssndbuf, &info);
909 gst_buffer_unref (ssndbuf);
914 /* 8 byte chunk header, 8 byte SSND header */
916 datasize = size - 16;
918 aiff->datastart = aiff->offset + aiff->ssnd_offset;
919 /* file might be truncated */
921 size = MIN (datasize, (upstream_size - aiff->datastart));
923 aiff->datasize = (guint64) datasize;
924 aiff->dataleft = (guint64) datasize;
925 aiff->end_offset = datasize + aiff->datastart;
926 if (!aiff->streaming) {
927 /* We will continue looking at chunks until the end - to read tags,
929 aiff->offset += datasize;
931 GST_DEBUG_OBJECT (aiff, "datasize = %d", datasize);
932 if (aiff->streaming) {
937 case GST_MAKE_FOURCC ('I', 'D', '3', ' '):{
940 if (aiff->streaming) {
941 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
944 gst_adapter_flush (aiff->adapter, 8);
947 buf = gst_adapter_take_buffer (aiff->adapter, size);
949 if ((res = gst_aiff_parse_read_chunk (aiff,
950 &aiff->offset, &tag, &buf)) != GST_FLOW_OK)
954 GST_LOG_OBJECT (aiff, "ID3 chunk of size %" G_GSIZE_FORMAT,
955 gst_buffer_get_size (buf));
957 tags = gst_tag_list_from_id3v2_tag (buf);
958 gst_buffer_unref (buf);
960 GST_INFO_OBJECT (aiff, "ID3 tags: %" GST_PTR_FORMAT, tags);
962 if (aiff->tags == NULL) {
965 gst_tag_list_insert (aiff->tags, tags, GST_TAG_MERGE_APPEND);
966 gst_tag_list_unref (tags);
971 gst_aiff_parse_ignore_chunk (aiff, buf, tag, size);
974 if (upstream_size && (aiff->offset >= upstream_size)) {
975 /* Now we have gone through the whole file */
980 /* We read all the chunks (in pull mode) or reached the SSND chunk
981 * (in push mode). We must have both COMM and SSND now; error out
984 if (!aiff->got_comm) {
985 GST_WARNING_OBJECT (aiff, "Failed to find COMM chunk");
989 GST_WARNING_OBJECT (aiff, "Failed to find SSND chunk");
993 GST_DEBUG_OBJECT (aiff, "Finished parsing headers");
995 if (gst_aiff_parse_calculate_duration (aiff)) {
996 gst_segment_init (&aiff->segment, GST_FORMAT_TIME);
997 aiff->segment.duration = aiff->duration;
999 /* no bitrate, let downstream peer do the math, we'll feed it bytes. */
1000 gst_segment_init (&aiff->segment, GST_FORMAT_BYTES);
1001 aiff->segment.duration = aiff->datasize;
1004 /* now we have all the info to perform a pending seek if any, if no
1005 * event, this will still do the right thing and it will also send
1006 * the right newsegment event downstream. */
1007 gst_aiff_parse_perform_seek (aiff, aiff->seek_event);
1008 /* remove pending event */
1009 event_p = &aiff->seek_event;
1010 gst_event_replace (event_p, NULL);
1012 /* we just started, we are discont */
1013 aiff->discont = TRUE;
1015 aiff->state = AIFF_PARSE_DATA;
1022 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
1023 ("Invalid AIFF header (no COMM found)"));
1024 return GST_FLOW_ERROR;
1028 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
1029 ("Invalid AIFF: no SSND found"));
1030 return GST_FLOW_ERROR;
1034 GST_ELEMENT_ERROR (aiff, STREAM, DEMUX, (NULL),
1035 ("Couldn't parse audio header"));
1036 return GST_FLOW_ERROR;
1040 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
1041 ("Stream claims to contain no channels - invalid data"));
1042 return GST_FLOW_ERROR;
1046 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
1047 ("Stream with sample_rate == 0 - invalid data"));
1048 return GST_FLOW_ERROR;
1050 no_bytes_per_sample:
1052 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
1053 ("Could not caluclate bytes per sample - invalid data"));
1054 return GST_FLOW_ERROR;
1058 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
1059 ("No caps found for format 0x%x, %d channels, %d Hz",
1060 aiff->format, aiff->channels, aiff->rate));
1061 return GST_FLOW_ERROR;
1065 GST_ELEMENT_ERROR (aiff, STREAM, DEMUX, (NULL),
1066 ("Couldn't read in header"));
1067 return GST_FLOW_ERROR;
1072 * Read AIFF file tag when streaming
1074 static GstFlowReturn
1075 gst_aiff_parse_parse_stream_init (GstAiffParse * aiff)
1077 if (gst_adapter_available (aiff->adapter) >= 12) {
1080 /* _take flushes the data */
1081 tmp = gst_adapter_take_buffer (aiff->adapter, 12);
1083 GST_DEBUG ("Parsing aiff header");
1084 if (!gst_aiff_parse_parse_file_header (aiff, tmp))
1085 return GST_FLOW_ERROR;
1088 /* Go to next state */
1089 aiff->state = AIFF_PARSE_HEADER;
1094 /* handle an event sent directly to the element.
1096 * This event can be sent either in the READY state or the
1097 * >READY state. The only event of interest really is the seek
1100 * In the READY state we can only store the event and try to
1101 * respect it when going to PAUSED. We assume we are in the
1102 * READY state when our parsing state != AIFF_PARSE_DATA.
1104 * When we are steaming, we can simply perform the seek right
1108 gst_aiff_parse_send_event (GstElement * element, GstEvent * event)
1110 GstAiffParse *aiff = GST_AIFF_PARSE (element);
1111 gboolean res = FALSE;
1114 GST_DEBUG_OBJECT (aiff, "received event %s", GST_EVENT_TYPE_NAME (event));
1116 switch (GST_EVENT_TYPE (event)) {
1117 case GST_EVENT_SEEK:
1118 if (aiff->state == AIFF_PARSE_DATA) {
1119 /* we can handle the seek directly when streaming data */
1120 res = gst_aiff_parse_perform_seek (aiff, event);
1122 GST_DEBUG_OBJECT (aiff, "queuing seek for later");
1124 event_p = &aiff->seek_event;
1125 gst_event_replace (event_p, event);
1127 /* we always return true */
1134 gst_event_unref (event);
1138 #define MAX_BUFFER_SIZE 4096
1140 static GstFlowReturn
1141 gst_aiff_parse_stream_data (GstAiffParse * aiff)
1143 GstBuffer *buf = NULL;
1144 GstFlowReturn res = GST_FLOW_OK;
1145 guint64 desired, obtained;
1146 GstClockTime timestamp, next_timestamp, duration;
1147 guint64 pos, nextpos;
1150 GST_LOG_OBJECT (aiff,
1151 "offset: %" G_GINT64_FORMAT " , end: %" G_GINT64_FORMAT " , dataleft: %"
1152 G_GINT64_FORMAT, aiff->offset, aiff->end_offset, aiff->dataleft);
1154 /* Get the next n bytes and output them */
1155 if (aiff->dataleft == 0 || aiff->dataleft < aiff->bytes_per_sample)
1158 /* scale the amount of data by the segment rate so we get equal
1159 * amounts of data regardless of the playback rate */
1161 MIN (gst_guint64_to_gdouble (aiff->dataleft),
1162 MAX_BUFFER_SIZE * ABS (aiff->segment.rate));
1164 if (desired >= aiff->bytes_per_sample && aiff->bytes_per_sample > 0)
1165 desired -= (desired % aiff->bytes_per_sample);
1167 GST_LOG_OBJECT (aiff, "Fetching %" G_GINT64_FORMAT " bytes of data "
1168 "from the sinkpad", desired);
1170 if (aiff->streaming) {
1171 guint avail = gst_adapter_available (aiff->adapter);
1173 if (avail < desired) {
1174 GST_LOG_OBJECT (aiff, "Got only %d bytes of data from the sinkpad",
1179 buf = gst_adapter_take_buffer (aiff->adapter, desired);
1181 if ((res = gst_pad_pull_range (aiff->sinkpad, aiff->offset,
1182 desired, &buf)) != GST_FLOW_OK)
1186 /* If we have a pending close/start segment, send it now. */
1187 if (G_UNLIKELY (aiff->close_segment != NULL)) {
1188 gst_pad_push_event (aiff->srcpad, aiff->close_segment);
1189 aiff->close_segment = NULL;
1191 if (G_UNLIKELY (aiff->start_segment != NULL)) {
1192 gst_pad_push_event (aiff->srcpad, aiff->start_segment);
1193 aiff->start_segment = NULL;
1195 if (G_UNLIKELY (aiff->tags != NULL)) {
1196 gst_pad_push_event (aiff->srcpad, gst_event_new_tag (aiff->tags));
1200 obtained = gst_buffer_get_size (buf);
1202 /* our positions in bytes */
1203 pos = aiff->offset - aiff->datastart;
1204 nextpos = pos + obtained;
1206 /* update offsets, does not overflow. */
1207 GST_BUFFER_OFFSET (buf) = pos / aiff->bytes_per_sample;
1208 GST_BUFFER_OFFSET_END (buf) = nextpos / aiff->bytes_per_sample;
1210 if (aiff->bps > 0) {
1211 /* and timestamps if we have a bitrate, be careful for overflows */
1213 gst_util_uint64_scale_ceil (pos, GST_SECOND, (guint64) aiff->bps);
1215 gst_util_uint64_scale_ceil (nextpos, GST_SECOND, (guint64) aiff->bps);
1216 duration = next_timestamp - timestamp;
1218 /* update current running segment position */
1219 aiff->segment.position = next_timestamp;
1221 /* no bitrate, all we know is that the first sample has timestamp 0, all
1222 * other positions and durations have unknown timestamp. */
1226 timestamp = GST_CLOCK_TIME_NONE;
1227 duration = GST_CLOCK_TIME_NONE;
1228 /* update current running segment position with byte offset */
1229 aiff->segment.position = nextpos;
1231 if (aiff->discont) {
1232 GST_DEBUG_OBJECT (aiff, "marking DISCONT");
1233 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
1234 aiff->discont = FALSE;
1237 GST_BUFFER_TIMESTAMP (buf) = timestamp;
1238 GST_BUFFER_DURATION (buf) = duration;
1240 GST_LOG_OBJECT (aiff,
1241 "Got buffer. timestamp:%" GST_TIME_FORMAT " , duration:%" GST_TIME_FORMAT
1242 ", size:%" G_GUINT64_FORMAT, GST_TIME_ARGS (timestamp),
1243 GST_TIME_ARGS (duration), obtained);
1245 if ((res = gst_pad_push (aiff->srcpad, buf)) != GST_FLOW_OK)
1248 if (obtained < aiff->dataleft) {
1249 aiff->offset += obtained;
1250 aiff->dataleft -= obtained;
1252 aiff->offset += aiff->dataleft;
1256 /* Iterate until need more data, so adapter size won't grow */
1257 if (aiff->streaming) {
1258 GST_LOG_OBJECT (aiff,
1259 "offset: %" G_GINT64_FORMAT " , end: %" G_GINT64_FORMAT, aiff->offset,
1261 goto iterate_adapter;
1268 GST_DEBUG_OBJECT (aiff, "found EOS");
1269 return GST_FLOW_EOS;
1273 /* check if we got EOS */
1274 if (res == GST_FLOW_EOS)
1277 GST_WARNING_OBJECT (aiff,
1278 "Error getting %" G_GINT64_FORMAT " bytes from the "
1279 "sinkpad (dataleft = %" G_GINT64_FORMAT ")", desired, aiff->dataleft);
1284 GST_INFO_OBJECT (aiff,
1285 "Error pushing on srcpad %s:%s, reason %s, is linked? = %d",
1286 GST_DEBUG_PAD_NAME (aiff->srcpad), gst_flow_get_name (res),
1287 gst_pad_is_linked (aiff->srcpad));
1293 gst_aiff_parse_loop (GstPad * pad)
1296 GstAiffParse *aiff = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1298 GST_LOG_OBJECT (aiff, "process data");
1300 switch (aiff->state) {
1301 case AIFF_PARSE_START:
1302 GST_INFO_OBJECT (aiff, "AIFF_PARSE_START");
1303 if ((ret = gst_aiff_parse_stream_init (aiff)) != GST_FLOW_OK)
1306 aiff->state = AIFF_PARSE_HEADER;
1309 case AIFF_PARSE_HEADER:
1310 GST_INFO_OBJECT (aiff, "AIFF_PARSE_HEADER");
1311 if ((ret = gst_aiff_parse_stream_headers (aiff)) != GST_FLOW_OK)
1314 aiff->state = AIFF_PARSE_DATA;
1315 GST_INFO_OBJECT (aiff, "AIFF_PARSE_DATA");
1318 case AIFF_PARSE_DATA:
1319 if ((ret = gst_aiff_parse_stream_data (aiff)) != GST_FLOW_OK)
1323 g_assert_not_reached ();
1330 const gchar *reason = gst_flow_get_name (ret);
1332 GST_DEBUG_OBJECT (aiff, "pausing task, reason %s", reason);
1333 aiff->segment_running = FALSE;
1334 gst_pad_pause_task (pad);
1336 if (ret == GST_FLOW_EOS) {
1337 /* perform EOS logic */
1338 if (aiff->segment.flags & GST_SEEK_FLAG_SEGMENT) {
1341 if ((stop = aiff->segment.stop) == -1)
1342 stop = aiff->segment.duration;
1344 gst_element_post_message (GST_ELEMENT_CAST (aiff),
1345 gst_message_new_segment_done (GST_OBJECT_CAST (aiff),
1346 aiff->segment.format, stop));
1347 gst_pad_push_event (aiff->srcpad,
1348 gst_event_new_segment_done (aiff->segment.format, stop));
1350 gst_pad_push_event (aiff->srcpad, gst_event_new_eos ());
1352 } else if (ret < GST_FLOW_EOS || ret == GST_FLOW_NOT_LINKED) {
1353 /* for fatal errors we post an error message, post the error
1354 * first so the app knows about the error first. */
1355 GST_ELEMENT_ERROR (aiff, STREAM, FAILED,
1356 (_("Internal data flow error.")),
1357 ("streaming task paused, reason %s (%d)", reason, ret));
1358 gst_pad_push_event (aiff->srcpad, gst_event_new_eos ());
1364 static GstFlowReturn
1365 gst_aiff_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
1368 GstAiffParse *aiff = GST_AIFF_PARSE (parent);
1370 GST_LOG_OBJECT (aiff, "adapter_push %" G_GSIZE_FORMAT " bytes",
1371 gst_buffer_get_size (buf));
1373 gst_adapter_push (aiff->adapter, buf);
1375 switch (aiff->state) {
1376 case AIFF_PARSE_START:
1377 GST_INFO_OBJECT (aiff, "AIFF_PARSE_START");
1378 if ((ret = gst_aiff_parse_parse_stream_init (aiff)) != GST_FLOW_OK)
1381 if (aiff->state != AIFF_PARSE_HEADER)
1384 /* otherwise fall-through */
1385 case AIFF_PARSE_HEADER:
1386 GST_INFO_OBJECT (aiff, "AIFF_PARSE_HEADER");
1387 if ((ret = gst_aiff_parse_stream_headers (aiff)) != GST_FLOW_OK)
1390 if (!aiff->got_comm || aiff->datastart == 0)
1393 aiff->state = AIFF_PARSE_DATA;
1394 GST_INFO_OBJECT (aiff, "AIFF_PARSE_DATA");
1397 case AIFF_PARSE_DATA:
1398 if ((ret = gst_aiff_parse_stream_data (aiff)) != GST_FLOW_OK)
1402 g_return_val_if_reached (GST_FLOW_ERROR);
1409 gst_aiff_parse_pad_convert (GstPad * pad,
1410 GstFormat src_format, gint64 src_value,
1411 GstFormat * dest_format, gint64 * dest_value)
1413 GstAiffParse *aiffparse;
1414 gboolean res = TRUE;
1416 aiffparse = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1418 if (*dest_format == src_format) {
1419 *dest_value = src_value;
1423 if (aiffparse->bytes_per_sample <= 0)
1426 GST_INFO_OBJECT (aiffparse, "converting value from %s to %s",
1427 gst_format_get_name (src_format), gst_format_get_name (*dest_format));
1429 switch (src_format) {
1430 case GST_FORMAT_BYTES:
1431 switch (*dest_format) {
1432 case GST_FORMAT_DEFAULT:
1433 *dest_value = src_value / aiffparse->bytes_per_sample;
1435 case GST_FORMAT_TIME:
1436 if (aiffparse->bps > 0) {
1437 *dest_value = gst_util_uint64_scale_ceil (src_value, GST_SECOND,
1438 (guint64) aiffparse->bps);
1441 /* Else fallthrough */
1448 case GST_FORMAT_DEFAULT:
1449 switch (*dest_format) {
1450 case GST_FORMAT_BYTES:
1451 *dest_value = src_value * aiffparse->bytes_per_sample;
1453 case GST_FORMAT_TIME:
1454 *dest_value = gst_util_uint64_scale (src_value, GST_SECOND,
1455 (guint64) aiffparse->rate);
1463 case GST_FORMAT_TIME:
1464 switch (*dest_format) {
1465 case GST_FORMAT_BYTES:
1466 if (aiffparse->bps > 0) {
1467 *dest_value = gst_util_uint64_scale (src_value,
1468 (guint64) aiffparse->bps, GST_SECOND);
1471 /* Else fallthrough */
1473 case GST_FORMAT_DEFAULT:
1474 *dest_value = gst_util_uint64_scale (src_value,
1475 (guint64) aiffparse->rate, GST_SECOND);
1493 /* handle queries for location and length in requested format */
1495 gst_aiff_parse_pad_query (GstPad * pad, GstObject * parent, GstQuery * query)
1497 gboolean res = TRUE;
1498 GstAiffParse *aiff = GST_AIFF_PARSE (parent);
1500 /* only if we know */
1501 if (aiff->state != AIFF_PARSE_DATA) {
1505 switch (GST_QUERY_TYPE (query)) {
1506 case GST_QUERY_DURATION:
1508 gint64 duration = 0;
1511 gst_query_parse_duration (query, &format, NULL);
1514 case GST_FORMAT_TIME:{
1515 if ((res = gst_aiff_parse_calculate_duration (aiff))) {
1516 duration = aiff->duration;
1521 format = GST_FORMAT_BYTES;
1522 duration = aiff->datasize;
1525 gst_query_set_duration (query, format, duration);
1528 case GST_QUERY_CONVERT:
1530 gint64 srcvalue, dstvalue;
1531 GstFormat srcformat, dstformat;
1533 gst_query_parse_convert (query, &srcformat, &srcvalue,
1534 &dstformat, &dstvalue);
1535 res = gst_aiff_parse_pad_convert (pad, srcformat, srcvalue,
1536 &dstformat, &dstvalue);
1538 gst_query_set_convert (query, srcformat, srcvalue, dstformat, dstvalue);
1541 case GST_QUERY_SEEKING:{
1544 gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
1545 if (fmt == GST_FORMAT_TIME) {
1546 gboolean seekable = TRUE;
1548 if (!gst_aiff_parse_calculate_duration (aiff)) {
1551 gst_query_set_seeking (query, GST_FORMAT_TIME, seekable,
1558 res = gst_pad_query_default (pad, parent, query);
1565 gst_aiff_parse_srcpad_event (GstPad * pad, GstObject * parent, GstEvent * event)
1567 GstAiffParse *aiffparse = GST_AIFF_PARSE (parent);
1568 gboolean res = FALSE;
1570 GST_DEBUG_OBJECT (aiffparse, "%s event", GST_EVENT_TYPE_NAME (event));
1572 switch (GST_EVENT_TYPE (event)) {
1573 case GST_EVENT_SEEK:
1574 /* can only handle events when we are in the data state */
1575 if (aiffparse->state == AIFF_PARSE_DATA) {
1576 res = gst_aiff_parse_perform_seek (aiffparse, event);
1578 gst_event_unref (event);
1581 res = gst_pad_push_event (aiffparse->sinkpad, event);
1588 gst_aiff_parse_sink_activate (GstPad * sinkpad, GstObject * parent)
1593 query = gst_query_new_scheduling ();
1595 if (!gst_pad_peer_query (sinkpad, query)) {
1596 gst_query_unref (query);
1600 pull_mode = gst_query_has_scheduling_mode_with_flags (query,
1601 GST_PAD_MODE_PULL, GST_SCHEDULING_FLAG_SEEKABLE);
1602 gst_query_unref (query);
1607 GST_DEBUG_OBJECT (sinkpad, "going to pull mode");
1608 return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PULL, TRUE);
1612 GST_DEBUG_OBJECT (sinkpad, "going to push (streaming) mode");
1613 return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PUSH, TRUE);
1619 gst_aiff_parse_sink_activate_mode (GstPad * sinkpad, GstObject * parent,
1620 GstPadMode mode, gboolean active)
1623 GstAiffParse *aiff = GST_AIFF_PARSE (parent);
1626 g_object_unref (aiff->adapter);
1629 case GST_PAD_MODE_PUSH:
1630 aiff->streaming = TRUE;
1631 aiff->adapter = gst_adapter_new ();
1634 case GST_PAD_MODE_PULL:
1636 aiff->streaming = FALSE;
1637 aiff->adapter = NULL;
1638 aiff->segment_running = TRUE;
1640 gst_pad_start_task (sinkpad, (GstTaskFunction) gst_aiff_parse_loop,
1643 aiff->segment_running = FALSE;
1644 res = gst_pad_stop_task (sinkpad);
1654 static GstStateChangeReturn
1655 gst_aiff_parse_change_state (GstElement * element, GstStateChange transition)
1657 GstStateChangeReturn ret;
1658 GstAiffParse *aiff = GST_AIFF_PARSE (element);
1660 switch (transition) {
1661 case GST_STATE_CHANGE_NULL_TO_READY:
1663 case GST_STATE_CHANGE_READY_TO_PAUSED:
1664 gst_aiff_parse_reset (aiff);
1666 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1672 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1674 switch (transition) {
1675 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1677 case GST_STATE_CHANGE_PAUSED_TO_READY:
1678 gst_aiff_parse_reset (aiff);
1680 case GST_STATE_CHANGE_READY_TO_NULL: