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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, 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.
58 #include "aiffparse.h"
59 #include <gst/audio/audio.h>
60 #include <gst/gst-i18n-plugin.h>
62 GST_DEBUG_CATEGORY (aiffparse_debug);
63 #define GST_CAT_DEFAULT (aiffparse_debug)
65 static void gst_aiff_parse_dispose (GObject * object);
67 static gboolean gst_aiff_parse_sink_activate (GstPad * sinkpad);
68 static gboolean gst_aiff_parse_sink_activate_pull (GstPad * sinkpad,
70 static gboolean gst_aiff_parse_send_event (GstElement * element,
72 static GstStateChangeReturn gst_aiff_parse_change_state (GstElement * element,
73 GstStateChange transition);
75 static const GstQueryType *gst_aiff_parse_get_query_types (GstPad * pad);
76 static gboolean gst_aiff_parse_pad_query (GstPad * pad, GstQuery * query);
77 static gboolean gst_aiff_parse_pad_convert (GstPad * pad,
79 gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
81 static GstFlowReturn gst_aiff_parse_chain (GstPad * pad, GstBuffer * buf);
82 static void gst_aiff_parse_loop (GstPad * pad);
83 static gboolean gst_aiff_parse_srcpad_event (GstPad * pad, GstEvent * event);
85 static GstStaticPadTemplate sink_template_factory =
86 GST_STATIC_PAD_TEMPLATE ("sink",
89 GST_STATIC_CAPS ("audio/x-aiff")
92 static GstStaticPadTemplate src_template_factory =
93 GST_STATIC_PAD_TEMPLATE ("src",
96 GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS)
99 GST_BOILERPLATE (GstAiffParse, gst_aiff_parse, GstElement, GST_TYPE_ELEMENT);
102 gst_aiff_parse_base_init (gpointer g_class)
104 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
106 gst_element_class_add_pad_template (element_class,
107 gst_static_pad_template_get (&sink_template_factory));
108 gst_element_class_add_pad_template (element_class,
109 gst_static_pad_template_get (&src_template_factory));
111 gst_element_class_set_details_simple (element_class,
112 "AIFF audio demuxer", "Codec/Demuxer/Audio",
113 "Parse a .aiff file into raw audio",
114 "Pioneers of the Inevitable <songbird@songbirdnest.com>");
118 gst_aiff_parse_class_init (GstAiffParseClass * klass)
120 GstElementClass *gstelement_class;
121 GObjectClass *object_class;
123 gstelement_class = (GstElementClass *) klass;
124 object_class = (GObjectClass *) klass;
126 parent_class = g_type_class_peek_parent (klass);
128 object_class->dispose = gst_aiff_parse_dispose;
130 gstelement_class->change_state =
131 GST_DEBUG_FUNCPTR (gst_aiff_parse_change_state);
132 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_aiff_parse_send_event);
136 gst_aiff_parse_reset (GstAiffParse * aiff)
138 aiff->state = AIFF_PARSE_START;
140 /* These will all be set correctly in the fmt chunk */
147 aiff->end_offset = 0;
152 aiff->got_comm = FALSE;
155 gst_caps_unref (aiff->caps);
158 if (aiff->seek_event)
159 gst_event_unref (aiff->seek_event);
160 aiff->seek_event = NULL;
162 gst_adapter_clear (aiff->adapter);
163 aiff->adapter = NULL;
168 gst_aiff_parse_dispose (GObject * object)
170 GstAiffParse *aiff = GST_AIFF_PARSE (object);
172 GST_DEBUG_OBJECT (aiff, "AIFF: Dispose");
173 gst_aiff_parse_reset (aiff);
175 G_OBJECT_CLASS (parent_class)->dispose (object);
179 gst_aiff_parse_init (GstAiffParse * aiffparse, GstAiffParseClass * g_class)
181 gst_aiff_parse_reset (aiffparse);
185 gst_pad_new_from_static_template (&sink_template_factory, "sink");
186 gst_pad_set_activate_function (aiffparse->sinkpad,
187 GST_DEBUG_FUNCPTR (gst_aiff_parse_sink_activate));
188 gst_pad_set_activatepull_function (aiffparse->sinkpad,
189 GST_DEBUG_FUNCPTR (gst_aiff_parse_sink_activate_pull));
190 gst_pad_set_chain_function (aiffparse->sinkpad,
191 GST_DEBUG_FUNCPTR (gst_aiff_parse_chain));
192 gst_element_add_pad (GST_ELEMENT_CAST (aiffparse), aiffparse->sinkpad);
196 gst_pad_new_from_static_template (&src_template_factory, "src");
197 gst_pad_use_fixed_caps (aiffparse->srcpad);
198 gst_pad_set_query_type_function (aiffparse->srcpad,
199 GST_DEBUG_FUNCPTR (gst_aiff_parse_get_query_types));
200 gst_pad_set_query_function (aiffparse->srcpad,
201 GST_DEBUG_FUNCPTR (gst_aiff_parse_pad_query));
202 gst_pad_set_event_function (aiffparse->srcpad,
203 GST_DEBUG_FUNCPTR (gst_aiff_parse_srcpad_event));
204 gst_element_add_pad (GST_ELEMENT_CAST (aiffparse), aiffparse->srcpad);
208 gst_aiff_parse_parse_file_header (GstAiffParse * aiff, GstBuffer * buf)
211 guint32 header, type = 0;
213 if (GST_BUFFER_SIZE (buf) < 12) {
214 GST_WARNING_OBJECT (aiff, "Buffer too short");
218 data = GST_BUFFER_DATA (buf);
220 header = GST_READ_UINT32_LE (data);
221 type = GST_READ_UINT32_LE (data + 8);
223 if (header != GST_MAKE_FOURCC ('F', 'O', 'R', 'M'))
226 if (type == GST_MAKE_FOURCC ('A', 'I', 'F', 'F'))
227 aiff->is_aifc = FALSE;
228 else if (type == GST_MAKE_FOURCC ('A', 'I', 'F', 'C'))
229 aiff->is_aifc = TRUE;
233 gst_buffer_unref (buf);
239 GST_ELEMENT_ERROR (aiff, STREAM, WRONG_TYPE, (NULL),
240 ("File is not an AIFF file: %" GST_FOURCC_FORMAT,
241 GST_FOURCC_ARGS (type)));
242 gst_buffer_unref (buf);
248 gst_aiff_parse_stream_init (GstAiffParse * aiff)
251 GstBuffer *buf = NULL;
253 if ((res = gst_pad_pull_range (aiff->sinkpad,
254 aiff->offset, 12, &buf)) != GST_FLOW_OK)
256 else if (!gst_aiff_parse_parse_file_header (aiff, buf))
257 return GST_FLOW_ERROR;
264 /* This function is used to perform seeks on the element in
267 * It also works when event is NULL, in which case it will just
268 * start from the last configured segment. This technique is
269 * used when activating the element and to perform the seek in
273 gst_aiff_parse_perform_seek (GstAiffParse * aiff, GstEvent * event)
277 GstFormat format, bformat;
279 GstSeekType cur_type = GST_SEEK_TYPE_NONE, stop_type;
280 gint64 cur, stop, upstream_size;
283 GstSegment seeksegment = { 0, };
287 GST_DEBUG_OBJECT (aiff, "doing seek with event");
289 gst_event_parse_seek (event, &rate, &format, &flags,
290 &cur_type, &cur, &stop_type, &stop);
292 /* no negative rates yet */
296 if (format != aiff->segment.format) {
297 GST_INFO_OBJECT (aiff, "converting seek-event from %s to %s",
298 gst_format_get_name (format),
299 gst_format_get_name (aiff->segment.format));
301 if (cur_type != GST_SEEK_TYPE_NONE)
303 gst_pad_query_convert (aiff->srcpad, format, cur,
304 &aiff->segment.format, &cur);
305 if (res && stop_type != GST_SEEK_TYPE_NONE)
307 gst_pad_query_convert (aiff->srcpad, format, stop,
308 &aiff->segment.format, &stop);
312 format = aiff->segment.format;
315 GST_DEBUG_OBJECT (aiff, "doing seek without event");
318 cur_type = GST_SEEK_TYPE_SET;
319 stop_type = GST_SEEK_TYPE_SET;
323 flush = flags & GST_SEEK_FLAG_FLUSH;
325 /* now we need to make sure the streaming thread is stopped. We do this by
326 * either sending a FLUSH_START event downstream which will cause the
327 * streaming thread to stop with a WRONG_STATE.
328 * For a non-flushing seek we simply pause the task, which will happen as soon
329 * as it completes one iteration (and thus might block when the sink is
330 * blocking in preroll). */
332 GST_DEBUG_OBJECT (aiff, "sending flush start");
333 gst_pad_push_event (aiff->srcpad, gst_event_new_flush_start ());
335 gst_pad_pause_task (aiff->sinkpad);
338 /* we should now be able to grab the streaming thread because we stopped it
339 * with the above flush/pause code */
340 GST_PAD_STREAM_LOCK (aiff->sinkpad);
342 /* save current position */
343 last_stop = aiff->segment.last_stop;
345 GST_DEBUG_OBJECT (aiff, "stopped streaming at %" G_GINT64_FORMAT, last_stop);
347 /* copy segment, we need this because we still need the old
348 * segment when we close the current segment. */
349 memcpy (&seeksegment, &aiff->segment, sizeof (GstSegment));
351 /* configure the seek parameters in the seeksegment. We will then have the
352 * right values in the segment to perform the seek */
354 GST_DEBUG_OBJECT (aiff, "configuring seek");
355 gst_segment_set_seek (&seeksegment, rate, format, flags,
356 cur_type, cur, stop_type, stop, &update);
359 /* figure out the last position we need to play. If it's configured (stop !=
360 * -1), use that, else we play until the total duration of the file */
361 if ((stop = seeksegment.stop) == -1)
362 stop = seeksegment.duration;
364 GST_DEBUG_OBJECT (aiff, "cur_type =%d", cur_type);
365 if ((cur_type != GST_SEEK_TYPE_NONE)) {
366 /* bring offset to bytes, if the bps is 0, we have the segment in BYTES and
367 * we can just copy the last_stop. If not, we use the bps to convert TIME to
371 gst_util_uint64_scale_ceil (seeksegment.last_stop,
372 (guint64) aiff->bps, GST_SECOND);
374 aiff->offset = seeksegment.last_stop;
375 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
376 aiff->offset -= (aiff->offset % aiff->bytes_per_sample);
377 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
378 aiff->offset += aiff->datastart;
379 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
381 GST_LOG_OBJECT (aiff, "continue from offset=%" G_GUINT64_FORMAT,
385 if (stop_type != GST_SEEK_TYPE_NONE) {
388 gst_util_uint64_scale_ceil (stop, (guint64) aiff->bps, GST_SECOND);
390 aiff->end_offset = stop;
391 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
392 aiff->end_offset -= (aiff->end_offset % aiff->bytes_per_sample);
393 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
394 aiff->end_offset += aiff->datastart;
395 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
397 GST_LOG_OBJECT (aiff, "continue to end_offset=%" G_GUINT64_FORMAT,
401 /* make sure filesize is not exceeded due to rounding errors or so,
402 * same precaution as in _stream_headers */
403 bformat = GST_FORMAT_BYTES;
404 if (gst_pad_query_peer_duration (aiff->sinkpad, &bformat, &upstream_size))
405 aiff->end_offset = MIN (aiff->end_offset, upstream_size);
407 /* this is the range of bytes we will use for playback */
408 aiff->offset = MIN (aiff->offset, aiff->end_offset);
409 aiff->dataleft = aiff->end_offset - aiff->offset;
411 GST_DEBUG_OBJECT (aiff,
412 "seek: rate %lf, offset %" G_GUINT64_FORMAT ", end %" G_GUINT64_FORMAT
413 ", segment %" GST_TIME_FORMAT " -- %" GST_TIME_FORMAT, rate, aiff->offset,
414 aiff->end_offset, GST_TIME_ARGS (seeksegment.start),
415 GST_TIME_ARGS (stop));
417 /* prepare for streaming again */
419 /* if we sent a FLUSH_START, we now send a FLUSH_STOP */
420 GST_DEBUG_OBJECT (aiff, "sending flush stop");
421 gst_pad_push_event (aiff->srcpad, gst_event_new_flush_stop ());
422 } else if (aiff->segment_running) {
423 /* we are running the current segment and doing a non-flushing seek,
424 * close the segment first based on the previous last_stop. */
425 GST_DEBUG_OBJECT (aiff, "closing running segment %" G_GINT64_FORMAT
426 " to %" G_GINT64_FORMAT, aiff->segment.accum, aiff->segment.last_stop);
428 /* queue the segment for sending in the stream thread */
429 if (aiff->close_segment)
430 gst_event_unref (aiff->close_segment);
431 aiff->close_segment = gst_event_new_new_segment (TRUE,
432 aiff->segment.rate, aiff->segment.format,
433 aiff->segment.accum, aiff->segment.last_stop, aiff->segment.accum);
435 /* keep track of our last_stop */
436 seeksegment.accum = aiff->segment.last_stop;
439 /* now we did the seek and can activate the new segment values */
440 memcpy (&aiff->segment, &seeksegment, sizeof (GstSegment));
442 /* if we're doing a segment seek, post a SEGMENT_START message */
443 if (aiff->segment.flags & GST_SEEK_FLAG_SEGMENT) {
444 gst_element_post_message (GST_ELEMENT_CAST (aiff),
445 gst_message_new_segment_start (GST_OBJECT_CAST (aiff),
446 aiff->segment.format, aiff->segment.last_stop));
449 /* now create the newsegment */
450 GST_DEBUG_OBJECT (aiff, "Creating newsegment from %" G_GINT64_FORMAT
451 " to %" G_GINT64_FORMAT, aiff->segment.last_stop, stop);
453 /* store the newsegment event so it can be sent from the streaming thread. */
454 if (aiff->start_segment)
455 gst_event_unref (aiff->start_segment);
456 aiff->start_segment =
457 gst_event_new_new_segment (FALSE, aiff->segment.rate,
458 aiff->segment.format, aiff->segment.last_stop, stop,
459 aiff->segment.last_stop);
461 /* mark discont if we are going to stream from another position. */
462 if (last_stop != aiff->segment.last_stop) {
463 GST_DEBUG_OBJECT (aiff, "mark DISCONT, we did a seek to another position");
464 aiff->discont = TRUE;
467 /* and start the streaming task again */
468 aiff->segment_running = TRUE;
469 if (!aiff->streaming) {
470 gst_pad_start_task (aiff->sinkpad, (GstTaskFunction) gst_aiff_parse_loop,
474 GST_PAD_STREAM_UNLOCK (aiff->sinkpad);
481 GST_DEBUG_OBJECT (aiff, "negative playback rates are not supported yet.");
486 GST_DEBUG_OBJECT (aiff, "unsupported format given, seek aborted.");
492 * gst_aiff_parse_peek_chunk_info:
493 * @aiff AIFFparse object
494 * @tag holder for tag
495 * @size holder for tag size
497 * Peek next chunk info (tag and size)
499 * Returns: %TRUE when the chunk info (header) is available
502 gst_aiff_parse_peek_chunk_info (GstAiffParse * aiff, guint32 * tag,
505 const guint8 *data = NULL;
507 if (gst_adapter_available (aiff->adapter) < 8)
510 data = gst_adapter_peek (aiff->adapter, 8);
511 *tag = GST_READ_UINT32_LE (data);
512 *size = GST_READ_UINT32_BE (data + 4);
514 GST_DEBUG ("Next chunk size is %d bytes, type %" GST_FOURCC_FORMAT, *size,
515 GST_FOURCC_ARGS (*tag));
521 * gst_aiff_parse_peek_chunk:
522 * @aiff AIFFparse object
523 * @tag holder for tag
524 * @size holder for tag size
526 * Peek enough data for one full chunk
528 * Returns: %TRUE when the full chunk is available
531 gst_aiff_parse_peek_chunk (GstAiffParse * aiff, guint32 * tag, guint32 * size)
533 guint32 peek_size = 0;
536 if (!gst_aiff_parse_peek_chunk_info (aiff, tag, size))
539 GST_DEBUG ("Need to peek chunk of %d bytes", *size);
540 peek_size = (*size + 1) & ~1;
542 available = gst_adapter_available (aiff->adapter);
543 if (available >= (8 + peek_size)) {
546 GST_LOG ("but only %u bytes available now", available);
552 gst_aiff_parse_peek_data (GstAiffParse * aiff, guint32 size,
553 const guint8 ** data)
555 if (gst_adapter_available (aiff->adapter) < size)
558 *data = gst_adapter_peek (aiff->adapter, size);
563 * gst_aiff_parse_calculate_duration:
564 * @aiff: aiffparse object
566 * Calculate duration on demand and store in @aiff.
568 * Returns: %TRUE if duration is available.
571 gst_aiff_parse_calculate_duration (GstAiffParse * aiff)
573 if (aiff->duration > 0)
576 if (aiff->datasize > 0 && aiff->bps > 0) {
578 gst_util_uint64_scale_ceil (aiff->datasize, GST_SECOND,
579 (guint64) aiff->bps);
580 GST_INFO_OBJECT (aiff, "Got duration %" GST_TIME_FORMAT,
581 GST_TIME_ARGS (aiff->duration));
588 gst_aiff_parse_ignore_chunk (GstAiffParse * aiff, GstBuffer * buf, guint32 tag,
593 if (aiff->streaming) {
594 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
597 GST_DEBUG_OBJECT (aiff, "Ignoring tag %" GST_FOURCC_FORMAT,
598 GST_FOURCC_ARGS (tag));
599 flush = 8 + ((size + 1) & ~1);
600 aiff->offset += flush;
601 if (aiff->streaming) {
602 gst_adapter_flush (aiff->adapter, flush);
604 gst_buffer_unref (buf);
609 gst_aiff_parse_read_IEEE80 (guint8 * buf)
611 int s = buf[0] & 0xff;
612 int e = ((buf[0] & 0x7f) << 8) | (buf[1] & 0xff);
613 double f = ((unsigned long) (buf[2] & 0xff) << 24) |
614 ((buf[3] & 0xff) << 16) | ((buf[4] & 0xff) << 8) | (buf[5] & 0xff);
618 return HUGE_VAL; /* Really NaN, but this won't happen in reality */
628 f += ((buf[6] & 0xff) << 24) |
629 ((buf[7] & 0xff) << 16) | ((buf[8] & 0xff) << 8) | (buf[9] & 0xff);
631 return ldexp (f, e - 16446);
635 gst_aiff_parse_parse_comm (GstAiffParse * aiff, GstBuffer * buf)
645 if (GST_BUFFER_SIZE (buf) < size) {
646 GST_WARNING_OBJECT (aiff, "COMM chunk too short, cannot parse header");
650 data = GST_BUFFER_DATA (buf);
652 aiff->channels = GST_READ_UINT16_BE (data);
653 aiff->total_frames = GST_READ_UINT32_BE (data + 2);
654 aiff->depth = GST_READ_UINT16_BE (data + 6);
655 aiff->width = GST_ROUND_UP_8 (aiff->depth);
656 aiff->rate = (int) gst_aiff_parse_read_IEEE80 (data + 8);
658 aiff->floating_point = FALSE;
661 guint32 fourcc = GST_READ_UINT32_LE (data + 18);
663 /* We only support the 'trivial' uncompressed AIFC, but it can be
664 * either big or little endian */
666 case GST_MAKE_FOURCC ('N', 'O', 'N', 'E'):
667 aiff->endianness = G_BIG_ENDIAN;
669 case GST_MAKE_FOURCC ('s', 'o', 'w', 't'):
670 aiff->endianness = G_LITTLE_ENDIAN;
672 case GST_MAKE_FOURCC ('F', 'L', '3', '2'):
673 case GST_MAKE_FOURCC ('f', 'l', '3', '2'):
674 aiff->floating_point = TRUE;
675 aiff->width = aiff->depth = 32;
676 aiff->endianness = G_BIG_ENDIAN;
678 case GST_MAKE_FOURCC ('f', 'l', '6', '4'):
679 aiff->floating_point = TRUE;
680 aiff->width = aiff->depth = 64;
681 aiff->endianness = G_BIG_ENDIAN;
684 GST_WARNING_OBJECT (aiff, "Unsupported compression in AIFC "
685 "file: %" GST_FOURCC_FORMAT,
686 GST_FOURCC_ARGS (GST_READ_UINT32_LE (data + 18)));
691 aiff->endianness = G_BIG_ENDIAN;
697 gst_aiff_parse_read_chunk (GstAiffParse * aiff, guint64 * offset, guint32 * tag,
705 gst_pad_pull_range (aiff->sinkpad, *offset, 8, &buf)) != GST_FLOW_OK)
708 *tag = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
709 size = GST_READ_UINT32_BE (GST_BUFFER_DATA (buf) + 4);
712 gst_pad_pull_range (aiff->sinkpad, (*offset) + 8, size,
713 &buf)) != GST_FLOW_OK)
715 else if (GST_BUFFER_SIZE (buf) < size)
719 *offset += 8 + GST_ROUND_UP_2 (size);
726 /* short read, we return UNEXPECTED to mark the EOS case */
727 GST_DEBUG_OBJECT (aiff, "not enough data (available=%u, needed=%u)",
728 GST_BUFFER_SIZE (buf), size);
729 gst_buffer_unref (buf);
730 return GST_FLOW_UNEXPECTED;
736 gst_aiff_parse_create_caps (GstAiffParse * aiff)
740 if (aiff->floating_point) {
741 caps = gst_caps_new_simple ("audio/x-raw-float",
742 "width", G_TYPE_INT, aiff->width,
743 "channels", G_TYPE_INT, aiff->channels,
744 "endianness", G_TYPE_INT, aiff->endianness,
745 "rate", G_TYPE_INT, aiff->rate, NULL);
747 caps = gst_caps_new_simple ("audio/x-raw-int",
748 "width", G_TYPE_INT, aiff->width,
749 "depth", G_TYPE_INT, aiff->depth,
750 "channels", G_TYPE_INT, aiff->channels,
751 "endianness", G_TYPE_INT, aiff->endianness,
752 "rate", G_TYPE_INT, aiff->rate, "signed", G_TYPE_BOOLEAN, TRUE, NULL);
755 GST_DEBUG_OBJECT (aiff, "Created caps: %" GST_PTR_FORMAT, caps);
760 gst_aiff_parse_stream_headers (GstAiffParse * aiff)
765 gboolean gotdata = FALSE;
766 gboolean done = FALSE;
769 gint64 upstream_size = 0;
771 bformat = GST_FORMAT_BYTES;
772 gst_pad_query_peer_duration (aiff->sinkpad, &bformat, &upstream_size);
773 GST_DEBUG_OBJECT (aiff, "upstream size %" G_GUINT64_FORMAT, upstream_size);
775 /* loop headers until we get data */
777 if (aiff->streaming) {
778 if (!gst_aiff_parse_peek_chunk_info (aiff, &tag, &size))
782 gst_pad_pull_range (aiff->sinkpad, aiff->offset, 8,
783 &buf)) != GST_FLOW_OK)
784 goto header_read_error;
785 tag = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
786 size = GST_READ_UINT32_BE (GST_BUFFER_DATA (buf) + 4);
789 GST_INFO_OBJECT (aiff,
790 "Got TAG: %" GST_FOURCC_FORMAT ", offset %" G_GUINT64_FORMAT,
791 GST_FOURCC_ARGS (tag), aiff->offset);
793 /* We just keep reading chunks until we find the one we're interested in.
796 case GST_MAKE_FOURCC ('C', 'O', 'M', 'M'):{
797 if (aiff->streaming) {
798 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
801 gst_adapter_flush (aiff->adapter, 8);
804 buf = gst_adapter_take_buffer (aiff->adapter, size);
806 if ((res = gst_aiff_parse_read_chunk (aiff,
807 &aiff->offset, &tag, &buf)) != GST_FLOW_OK)
811 if (!gst_aiff_parse_parse_comm (aiff, buf)) {
812 gst_buffer_unref (buf);
813 goto parse_header_error;
816 gst_buffer_unref (buf);
818 /* do sanity checks of header fields */
819 if (aiff->channels == 0)
824 GST_DEBUG_OBJECT (aiff, "creating the caps");
826 aiff->caps = gst_aiff_parse_create_caps (aiff);
830 gst_pad_set_caps (aiff->srcpad, aiff->caps);
832 aiff->bytes_per_sample = aiff->channels * aiff->width / 8;
833 aiff->bps = aiff->bytes_per_sample * aiff->rate;
835 if (aiff->bytes_per_sample <= 0)
836 goto no_bytes_per_sample;
838 aiff->got_comm = TRUE;
841 case GST_MAKE_FOURCC ('S', 'S', 'N', 'D'):{
843 GstBuffer *ssndbuf = NULL;
844 const guint8 *ssnddata = NULL;
847 GST_DEBUG_OBJECT (aiff, "Got 'SSND' TAG, size : %d", size);
849 /* Now, read the 8-byte header in the SSND chunk */
850 if (aiff->streaming) {
851 if (!gst_aiff_parse_peek_data (aiff, 16, &ssnddata))
854 gst_buffer_unref (buf);
856 gst_pad_pull_range (aiff->sinkpad, aiff->offset, 16,
857 &ssndbuf)) != GST_FLOW_OK)
858 goto header_read_error;
859 ssnddata = GST_BUFFER_DATA (ssndbuf);
862 aiff->ssnd_offset = GST_READ_UINT32_BE (ssnddata + 8);
863 aiff->ssnd_blocksize = GST_READ_UINT32_BE (ssnddata + 12);
866 if (aiff->streaming) {
867 gst_adapter_flush (aiff->adapter, 16);
869 gst_buffer_unref (ssndbuf);
871 /* 8 byte chunk header, 8 byte SSND header */
874 datasize = size - 16;
876 aiff->datastart = aiff->offset + aiff->ssnd_offset;
877 /* file might be truncated */
878 fmt = GST_FORMAT_BYTES;
880 size = MIN (datasize, (upstream_size - aiff->datastart));
882 aiff->datasize = (guint64) datasize;
883 aiff->dataleft = (guint64) datasize;
884 aiff->end_offset = datasize + aiff->datastart;
885 if (!aiff->streaming) {
886 /* We will continue looking at chunks until the end - to read tags,
888 aiff->offset += datasize;
890 GST_DEBUG_OBJECT (aiff, "datasize = %d", datasize);
891 if (aiff->streaming) {
897 gst_aiff_parse_ignore_chunk (aiff, buf, tag, size);
900 if (upstream_size && (aiff->offset >= upstream_size)) {
901 /* Now we have gone through the whole file */
906 /* We read all the chunks (in pull mode) or reached the SSND chunk
907 * (in push mode). We must have both COMM and SSND now; error out
910 if (!aiff->got_comm) {
911 GST_WARNING_OBJECT (aiff, "Failed to find COMM chunk");
915 GST_WARNING_OBJECT (aiff, "Failed to find SSND chunk");
919 GST_DEBUG_OBJECT (aiff, "Finished parsing headers");
921 if (gst_aiff_parse_calculate_duration (aiff)) {
922 gst_segment_init (&aiff->segment, GST_FORMAT_TIME);
923 gst_segment_set_duration (&aiff->segment, GST_FORMAT_TIME, aiff->duration);
925 /* no bitrate, let downstream peer do the math, we'll feed it bytes. */
926 gst_segment_init (&aiff->segment, GST_FORMAT_BYTES);
927 gst_segment_set_duration (&aiff->segment, GST_FORMAT_BYTES, aiff->datasize);
930 /* now we have all the info to perform a pending seek if any, if no
931 * event, this will still do the right thing and it will also send
932 * the right newsegment event downstream. */
933 gst_aiff_parse_perform_seek (aiff, aiff->seek_event);
934 /* remove pending event */
935 event_p = &aiff->seek_event;
936 gst_event_replace (event_p, NULL);
938 /* we just started, we are discont */
939 aiff->discont = TRUE;
941 aiff->state = AIFF_PARSE_DATA;
948 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
949 ("Invalid AIFF header (no COMM found)"));
950 return GST_FLOW_ERROR;
954 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
955 ("Invalid AIFF: no SSND found"));
956 return GST_FLOW_ERROR;
960 GST_ELEMENT_ERROR (aiff, STREAM, DEMUX, (NULL),
961 ("Couldn't parse audio header"));
962 return GST_FLOW_ERROR;
966 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
967 ("Stream claims to contain no channels - invalid data"));
968 return GST_FLOW_ERROR;
972 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
973 ("Stream with sample_rate == 0 - invalid data"));
974 return GST_FLOW_ERROR;
978 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
979 ("Could not caluclate bytes per sample - invalid data"));
980 return GST_FLOW_ERROR;
984 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
985 ("No caps found for format 0x%x, %d channels, %d Hz",
986 aiff->format, aiff->channels, aiff->rate));
987 return GST_FLOW_ERROR;
991 GST_ELEMENT_ERROR (aiff, STREAM, DEMUX, (NULL),
992 ("Couldn't read in header"));
993 return GST_FLOW_ERROR;
998 * Read AIFF file tag when streaming
1000 static GstFlowReturn
1001 gst_aiff_parse_parse_stream_init (GstAiffParse * aiff)
1003 if (gst_adapter_available (aiff->adapter) >= 12) {
1006 /* _take flushes the data */
1007 tmp = gst_adapter_take_buffer (aiff->adapter, 12);
1009 GST_DEBUG ("Parsing aiff header");
1010 if (!gst_aiff_parse_parse_file_header (aiff, tmp))
1011 return GST_FLOW_ERROR;
1014 /* Go to next state */
1015 aiff->state = AIFF_PARSE_HEADER;
1020 /* handle an event sent directly to the element.
1022 * This event can be sent either in the READY state or the
1023 * >READY state. The only event of interest really is the seek
1026 * In the READY state we can only store the event and try to
1027 * respect it when going to PAUSED. We assume we are in the
1028 * READY state when our parsing state != AIFF_PARSE_DATA.
1030 * When we are steaming, we can simply perform the seek right
1034 gst_aiff_parse_send_event (GstElement * element, GstEvent * event)
1036 GstAiffParse *aiff = GST_AIFF_PARSE (element);
1037 gboolean res = FALSE;
1040 GST_DEBUG_OBJECT (aiff, "received event %s", GST_EVENT_TYPE_NAME (event));
1042 switch (GST_EVENT_TYPE (event)) {
1043 case GST_EVENT_SEEK:
1044 if (aiff->state == AIFF_PARSE_DATA) {
1045 /* we can handle the seek directly when streaming data */
1046 res = gst_aiff_parse_perform_seek (aiff, event);
1048 GST_DEBUG_OBJECT (aiff, "queuing seek for later");
1050 event_p = &aiff->seek_event;
1051 gst_event_replace (event_p, event);
1053 /* we always return true */
1060 gst_event_unref (event);
1064 #define MAX_BUFFER_SIZE 4096
1066 static GstFlowReturn
1067 gst_aiff_parse_stream_data (GstAiffParse * aiff)
1069 GstBuffer *buf = NULL;
1070 GstFlowReturn res = GST_FLOW_OK;
1071 guint64 desired, obtained;
1072 GstClockTime timestamp, next_timestamp, duration;
1073 guint64 pos, nextpos;
1076 GST_LOG_OBJECT (aiff,
1077 "offset: %" G_GINT64_FORMAT " , end: %" G_GINT64_FORMAT " , dataleft: %"
1078 G_GINT64_FORMAT, aiff->offset, aiff->end_offset, aiff->dataleft);
1080 /* Get the next n bytes and output them */
1081 if (aiff->dataleft == 0 || aiff->dataleft < aiff->bytes_per_sample)
1084 /* scale the amount of data by the segment rate so we get equal
1085 * amounts of data regardless of the playback rate */
1087 MIN (gst_guint64_to_gdouble (aiff->dataleft),
1088 MAX_BUFFER_SIZE * aiff->segment.abs_rate);
1090 if (desired >= aiff->bytes_per_sample && aiff->bytes_per_sample > 0)
1091 desired -= (desired % aiff->bytes_per_sample);
1093 GST_LOG_OBJECT (aiff, "Fetching %" G_GINT64_FORMAT " bytes of data "
1094 "from the sinkpad", desired);
1096 if (aiff->streaming) {
1097 guint avail = gst_adapter_available (aiff->adapter);
1099 if (avail < desired) {
1100 GST_LOG_OBJECT (aiff, "Got only %d bytes of data from the sinkpad",
1105 buf = gst_adapter_take_buffer (aiff->adapter, desired);
1107 if ((res = gst_pad_pull_range (aiff->sinkpad, aiff->offset,
1108 desired, &buf)) != GST_FLOW_OK)
1112 /* If we have a pending close/start segment, send it now. */
1113 if (G_UNLIKELY (aiff->close_segment != NULL)) {
1114 gst_pad_push_event (aiff->srcpad, aiff->close_segment);
1115 aiff->close_segment = NULL;
1117 if (G_UNLIKELY (aiff->start_segment != NULL)) {
1118 gst_pad_push_event (aiff->srcpad, aiff->start_segment);
1119 aiff->start_segment = NULL;
1122 obtained = GST_BUFFER_SIZE (buf);
1124 /* our positions in bytes */
1125 pos = aiff->offset - aiff->datastart;
1126 nextpos = pos + obtained;
1128 /* update offsets, does not overflow. */
1129 GST_BUFFER_OFFSET (buf) = pos / aiff->bytes_per_sample;
1130 GST_BUFFER_OFFSET_END (buf) = nextpos / aiff->bytes_per_sample;
1132 if (aiff->bps > 0) {
1133 /* and timestamps if we have a bitrate, be careful for overflows */
1135 gst_util_uint64_scale_ceil (pos, GST_SECOND, (guint64) aiff->bps);
1137 gst_util_uint64_scale_ceil (nextpos, GST_SECOND, (guint64) aiff->bps);
1138 duration = next_timestamp - timestamp;
1140 /* update current running segment position */
1141 gst_segment_set_last_stop (&aiff->segment, GST_FORMAT_TIME, next_timestamp);
1143 /* no bitrate, all we know is that the first sample has timestamp 0, all
1144 * other positions and durations have unknown timestamp. */
1148 timestamp = GST_CLOCK_TIME_NONE;
1149 duration = GST_CLOCK_TIME_NONE;
1150 /* update current running segment position with byte offset */
1151 gst_segment_set_last_stop (&aiff->segment, GST_FORMAT_BYTES, nextpos);
1153 if (aiff->discont) {
1154 GST_DEBUG_OBJECT (aiff, "marking DISCONT");
1155 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
1156 aiff->discont = FALSE;
1159 GST_BUFFER_TIMESTAMP (buf) = timestamp;
1160 GST_BUFFER_DURATION (buf) = duration;
1161 gst_buffer_set_caps (buf, aiff->caps);
1163 GST_LOG_OBJECT (aiff,
1164 "Got buffer. timestamp:%" GST_TIME_FORMAT " , duration:%" GST_TIME_FORMAT
1165 ", size:%u", GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration),
1166 GST_BUFFER_SIZE (buf));
1168 if ((res = gst_pad_push (aiff->srcpad, buf)) != GST_FLOW_OK)
1171 if (obtained < aiff->dataleft) {
1172 aiff->offset += obtained;
1173 aiff->dataleft -= obtained;
1175 aiff->offset += aiff->dataleft;
1179 /* Iterate until need more data, so adapter size won't grow */
1180 if (aiff->streaming) {
1181 GST_LOG_OBJECT (aiff,
1182 "offset: %" G_GINT64_FORMAT " , end: %" G_GINT64_FORMAT, aiff->offset,
1184 goto iterate_adapter;
1191 GST_DEBUG_OBJECT (aiff, "found EOS");
1192 return GST_FLOW_UNEXPECTED;
1196 /* check if we got EOS */
1197 if (res == GST_FLOW_UNEXPECTED)
1200 GST_WARNING_OBJECT (aiff,
1201 "Error getting %" G_GINT64_FORMAT " bytes from the "
1202 "sinkpad (dataleft = %" G_GINT64_FORMAT ")", desired, aiff->dataleft);
1207 GST_INFO_OBJECT (aiff,
1208 "Error pushing on srcpad %s:%s, reason %s, is linked? = %d",
1209 GST_DEBUG_PAD_NAME (aiff->srcpad), gst_flow_get_name (res),
1210 gst_pad_is_linked (aiff->srcpad));
1216 gst_aiff_parse_loop (GstPad * pad)
1219 GstAiffParse *aiff = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1221 GST_LOG_OBJECT (aiff, "process data");
1223 switch (aiff->state) {
1224 case AIFF_PARSE_START:
1225 GST_INFO_OBJECT (aiff, "AIFF_PARSE_START");
1226 if ((ret = gst_aiff_parse_stream_init (aiff)) != GST_FLOW_OK)
1229 aiff->state = AIFF_PARSE_HEADER;
1232 case AIFF_PARSE_HEADER:
1233 GST_INFO_OBJECT (aiff, "AIFF_PARSE_HEADER");
1234 if ((ret = gst_aiff_parse_stream_headers (aiff)) != GST_FLOW_OK)
1237 aiff->state = AIFF_PARSE_DATA;
1238 GST_INFO_OBJECT (aiff, "AIFF_PARSE_DATA");
1241 case AIFF_PARSE_DATA:
1242 if ((ret = gst_aiff_parse_stream_data (aiff)) != GST_FLOW_OK)
1246 g_assert_not_reached ();
1253 const gchar *reason = gst_flow_get_name (ret);
1255 GST_DEBUG_OBJECT (aiff, "pausing task, reason %s", reason);
1256 aiff->segment_running = FALSE;
1257 gst_pad_pause_task (pad);
1259 if (ret == GST_FLOW_UNEXPECTED) {
1260 /* perform EOS logic */
1261 if (aiff->segment.flags & GST_SEEK_FLAG_SEGMENT) {
1264 if ((stop = aiff->segment.stop) == -1)
1265 stop = aiff->segment.duration;
1267 gst_element_post_message (GST_ELEMENT_CAST (aiff),
1268 gst_message_new_segment_done (GST_OBJECT_CAST (aiff),
1269 aiff->segment.format, stop));
1271 gst_pad_push_event (aiff->srcpad, gst_event_new_eos ());
1273 } else if (ret < GST_FLOW_UNEXPECTED || ret == GST_FLOW_NOT_LINKED) {
1274 /* for fatal errors we post an error message, post the error
1275 * first so the app knows about the error first. */
1276 GST_ELEMENT_ERROR (aiff, STREAM, FAILED,
1277 (_("Internal data flow error.")),
1278 ("streaming task paused, reason %s (%d)", reason, ret));
1279 gst_pad_push_event (aiff->srcpad, gst_event_new_eos ());
1285 static GstFlowReturn
1286 gst_aiff_parse_chain (GstPad * pad, GstBuffer * buf)
1289 GstAiffParse *aiff = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1291 GST_LOG_OBJECT (aiff, "adapter_push %u bytes", GST_BUFFER_SIZE (buf));
1293 gst_adapter_push (aiff->adapter, buf);
1295 switch (aiff->state) {
1296 case AIFF_PARSE_START:
1297 GST_INFO_OBJECT (aiff, "AIFF_PARSE_START");
1298 if ((ret = gst_aiff_parse_parse_stream_init (aiff)) != GST_FLOW_OK)
1301 if (aiff->state != AIFF_PARSE_HEADER)
1304 /* otherwise fall-through */
1305 case AIFF_PARSE_HEADER:
1306 GST_INFO_OBJECT (aiff, "AIFF_PARSE_HEADER");
1307 if ((ret = gst_aiff_parse_stream_headers (aiff)) != GST_FLOW_OK)
1310 if (!aiff->got_comm || aiff->datastart == 0)
1313 aiff->state = AIFF_PARSE_DATA;
1314 GST_INFO_OBJECT (aiff, "AIFF_PARSE_DATA");
1317 case AIFF_PARSE_DATA:
1318 if ((ret = gst_aiff_parse_stream_data (aiff)) != GST_FLOW_OK)
1322 g_return_val_if_reached (GST_FLOW_ERROR);
1329 gst_aiff_parse_pad_convert (GstPad * pad,
1330 GstFormat src_format, gint64 src_value,
1331 GstFormat * dest_format, gint64 * dest_value)
1333 GstAiffParse *aiffparse;
1334 gboolean res = TRUE;
1336 aiffparse = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1338 if (*dest_format == src_format) {
1339 *dest_value = src_value;
1343 if (aiffparse->bytes_per_sample <= 0)
1346 GST_INFO_OBJECT (aiffparse, "converting value from %s to %s",
1347 gst_format_get_name (src_format), gst_format_get_name (*dest_format));
1349 switch (src_format) {
1350 case GST_FORMAT_BYTES:
1351 switch (*dest_format) {
1352 case GST_FORMAT_DEFAULT:
1353 *dest_value = src_value / aiffparse->bytes_per_sample;
1355 case GST_FORMAT_TIME:
1356 if (aiffparse->bps > 0) {
1357 *dest_value = gst_util_uint64_scale_ceil (src_value, GST_SECOND,
1358 (guint64) aiffparse->bps);
1361 /* Else fallthrough */
1368 case GST_FORMAT_DEFAULT:
1369 switch (*dest_format) {
1370 case GST_FORMAT_BYTES:
1371 *dest_value = src_value * aiffparse->bytes_per_sample;
1373 case GST_FORMAT_TIME:
1374 *dest_value = gst_util_uint64_scale (src_value, GST_SECOND,
1375 (guint64) aiffparse->rate);
1383 case GST_FORMAT_TIME:
1384 switch (*dest_format) {
1385 case GST_FORMAT_BYTES:
1386 if (aiffparse->bps > 0) {
1387 *dest_value = gst_util_uint64_scale (src_value,
1388 (guint64) aiffparse->bps, GST_SECOND);
1391 /* Else fallthrough */
1393 case GST_FORMAT_DEFAULT:
1394 *dest_value = gst_util_uint64_scale (src_value,
1395 (guint64) aiffparse->rate, GST_SECOND);
1413 static const GstQueryType *
1414 gst_aiff_parse_get_query_types (GstPad * pad)
1416 static const GstQueryType types[] = {
1426 /* handle queries for location and length in requested format */
1428 gst_aiff_parse_pad_query (GstPad * pad, GstQuery * query)
1430 gboolean res = TRUE;
1431 GstAiffParse *aiff = GST_AIFF_PARSE (gst_pad_get_parent (pad));
1433 /* only if we know */
1434 if (aiff->state != AIFF_PARSE_DATA) {
1435 gst_object_unref (aiff);
1439 switch (GST_QUERY_TYPE (query)) {
1440 case GST_QUERY_DURATION:
1442 gint64 duration = 0;
1445 gst_query_parse_duration (query, &format, NULL);
1448 case GST_FORMAT_TIME:{
1449 if ((res = gst_aiff_parse_calculate_duration (aiff))) {
1450 duration = aiff->duration;
1455 format = GST_FORMAT_BYTES;
1456 duration = aiff->datasize;
1459 gst_query_set_duration (query, format, duration);
1462 case GST_QUERY_CONVERT:
1464 gint64 srcvalue, dstvalue;
1465 GstFormat srcformat, dstformat;
1467 gst_query_parse_convert (query, &srcformat, &srcvalue,
1468 &dstformat, &dstvalue);
1469 res = gst_aiff_parse_pad_convert (pad, srcformat, srcvalue,
1470 &dstformat, &dstvalue);
1472 gst_query_set_convert (query, srcformat, srcvalue, dstformat, dstvalue);
1475 case GST_QUERY_SEEKING:{
1478 gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
1479 if (fmt == GST_FORMAT_TIME) {
1480 gboolean seekable = TRUE;
1482 if (!gst_aiff_parse_calculate_duration (aiff)) {
1485 gst_query_set_seeking (query, GST_FORMAT_TIME, seekable,
1492 res = gst_pad_query_default (pad, query);
1495 gst_object_unref (aiff);
1500 gst_aiff_parse_srcpad_event (GstPad * pad, GstEvent * event)
1502 GstAiffParse *aiffparse = GST_AIFF_PARSE (gst_pad_get_parent (pad));
1503 gboolean res = FALSE;
1505 GST_DEBUG_OBJECT (aiffparse, "%s event", GST_EVENT_TYPE_NAME (event));
1507 switch (GST_EVENT_TYPE (event)) {
1508 case GST_EVENT_SEEK:
1509 /* can only handle events when we are in the data state */
1510 if (aiffparse->state == AIFF_PARSE_DATA) {
1511 res = gst_aiff_parse_perform_seek (aiffparse, event);
1513 gst_event_unref (event);
1516 res = gst_pad_push_event (aiffparse->sinkpad, event);
1519 gst_object_unref (aiffparse);
1524 gst_aiff_parse_sink_activate (GstPad * sinkpad)
1526 GstAiffParse *aiff = GST_AIFF_PARSE (gst_pad_get_parent (sinkpad));
1530 g_object_unref (aiff->adapter);
1532 if (gst_pad_check_pull_range (sinkpad)) {
1533 GST_DEBUG ("going to pull mode");
1534 aiff->streaming = FALSE;
1535 aiff->adapter = NULL;
1536 res = gst_pad_activate_pull (sinkpad, TRUE);
1538 GST_DEBUG ("going to push (streaming) mode");
1539 aiff->streaming = TRUE;
1540 aiff->adapter = gst_adapter_new ();
1541 res = gst_pad_activate_push (sinkpad, TRUE);
1543 gst_object_unref (aiff);
1549 gst_aiff_parse_sink_activate_pull (GstPad * sinkpad, gboolean active)
1551 GstAiffParse *aiff = GST_AIFF_PARSE (GST_OBJECT_PARENT (sinkpad));
1554 aiff->segment_running = TRUE;
1555 return gst_pad_start_task (sinkpad, (GstTaskFunction) gst_aiff_parse_loop,
1558 aiff->segment_running = FALSE;
1559 return gst_pad_stop_task (sinkpad);
1563 static GstStateChangeReturn
1564 gst_aiff_parse_change_state (GstElement * element, GstStateChange transition)
1566 GstStateChangeReturn ret;
1567 GstAiffParse *aiff = GST_AIFF_PARSE (element);
1569 switch (transition) {
1570 case GST_STATE_CHANGE_NULL_TO_READY:
1572 case GST_STATE_CHANGE_READY_TO_PAUSED:
1573 gst_aiff_parse_reset (aiff);
1575 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1581 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1583 switch (transition) {
1584 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1586 case GST_STATE_CHANGE_PAUSED_TO_READY:
1587 gst_aiff_parse_reset (aiff);
1589 case GST_STATE_CHANGE_READY_TO_NULL: