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.
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);
74 static gboolean gst_aiff_parse_sink_activate_pull (GstPad * sinkpad,
76 static gboolean gst_aiff_parse_send_event (GstElement * element,
78 static GstStateChangeReturn gst_aiff_parse_change_state (GstElement * element,
79 GstStateChange transition);
81 static const GstQueryType *gst_aiff_parse_get_query_types (GstPad * pad);
82 static gboolean gst_aiff_parse_pad_query (GstPad * pad, GstQuery * query);
83 static gboolean gst_aiff_parse_pad_convert (GstPad * pad,
85 gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
87 static GstFlowReturn gst_aiff_parse_chain (GstPad * pad, GstBuffer * buf);
88 static void gst_aiff_parse_loop (GstPad * pad);
89 static gboolean gst_aiff_parse_srcpad_event (GstPad * pad, GstEvent * event);
91 static GstStaticPadTemplate sink_template_factory =
92 GST_STATIC_PAD_TEMPLATE ("sink",
95 GST_STATIC_CAPS ("audio/x-aiff")
98 static GstStaticPadTemplate src_template_factory =
99 GST_STATIC_PAD_TEMPLATE ("src",
102 GST_STATIC_CAPS (GST_AUDIO_INT_PAD_TEMPLATE_CAPS ";"
103 GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS)
106 GST_BOILERPLATE (GstAiffParse, gst_aiff_parse, GstElement, GST_TYPE_ELEMENT);
109 gst_aiff_parse_base_init (gpointer g_class)
111 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
113 gst_element_class_add_pad_template (element_class,
114 gst_static_pad_template_get (&sink_template_factory));
115 gst_element_class_add_pad_template (element_class,
116 gst_static_pad_template_get (&src_template_factory));
118 gst_element_class_set_static_metadata (element_class,
119 "AIFF audio demuxer", "Codec/Demuxer/Audio",
120 "Parse a .aiff file into raw audio",
121 "Pioneers of the Inevitable <songbird@songbirdnest.com>");
125 gst_aiff_parse_class_init (GstAiffParseClass * klass)
127 GstElementClass *gstelement_class;
128 GObjectClass *object_class;
130 gstelement_class = (GstElementClass *) klass;
131 object_class = (GObjectClass *) klass;
133 parent_class = g_type_class_peek_parent (klass);
135 object_class->dispose = gst_aiff_parse_dispose;
137 gstelement_class->change_state =
138 GST_DEBUG_FUNCPTR (gst_aiff_parse_change_state);
139 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_aiff_parse_send_event);
143 gst_aiff_parse_reset (GstAiffParse * aiff)
145 aiff->state = AIFF_PARSE_START;
147 /* These will all be set correctly in the fmt chunk */
154 aiff->end_offset = 0;
159 aiff->got_comm = FALSE;
162 gst_caps_unref (aiff->caps);
165 if (aiff->seek_event)
166 gst_event_unref (aiff->seek_event);
167 aiff->seek_event = NULL;
169 gst_adapter_clear (aiff->adapter);
170 aiff->adapter = NULL;
173 if (aiff->tags != NULL) {
174 gst_tag_list_unref (aiff->tags);
180 gst_aiff_parse_dispose (GObject * object)
182 GstAiffParse *aiff = GST_AIFF_PARSE (object);
184 GST_DEBUG_OBJECT (aiff, "AIFF: Dispose");
185 gst_aiff_parse_reset (aiff);
187 G_OBJECT_CLASS (parent_class)->dispose (object);
191 gst_aiff_parse_init (GstAiffParse * aiffparse, GstAiffParseClass * g_class)
193 gst_aiff_parse_reset (aiffparse);
197 gst_pad_new_from_static_template (&sink_template_factory, "sink");
198 gst_pad_set_activate_function (aiffparse->sinkpad,
199 GST_DEBUG_FUNCPTR (gst_aiff_parse_sink_activate));
200 gst_pad_set_activatepull_function (aiffparse->sinkpad,
201 GST_DEBUG_FUNCPTR (gst_aiff_parse_sink_activate_pull));
202 gst_pad_set_chain_function (aiffparse->sinkpad,
203 GST_DEBUG_FUNCPTR (gst_aiff_parse_chain));
204 gst_element_add_pad (GST_ELEMENT_CAST (aiffparse), aiffparse->sinkpad);
208 gst_pad_new_from_static_template (&src_template_factory, "src");
209 gst_pad_use_fixed_caps (aiffparse->srcpad);
210 gst_pad_set_query_type_function (aiffparse->srcpad,
211 GST_DEBUG_FUNCPTR (gst_aiff_parse_get_query_types));
212 gst_pad_set_query_function (aiffparse->srcpad,
213 GST_DEBUG_FUNCPTR (gst_aiff_parse_pad_query));
214 gst_pad_set_event_function (aiffparse->srcpad,
215 GST_DEBUG_FUNCPTR (gst_aiff_parse_srcpad_event));
216 gst_element_add_pad (GST_ELEMENT_CAST (aiffparse), aiffparse->srcpad);
220 gst_aiff_parse_parse_file_header (GstAiffParse * aiff, GstBuffer * buf)
223 guint32 header, type = 0;
225 if (GST_BUFFER_SIZE (buf) < 12) {
226 GST_WARNING_OBJECT (aiff, "Buffer too short");
230 data = GST_BUFFER_DATA (buf);
232 header = GST_READ_UINT32_LE (data);
233 type = GST_READ_UINT32_LE (data + 8);
235 if (header != GST_MAKE_FOURCC ('F', 'O', 'R', 'M'))
238 if (type == GST_MAKE_FOURCC ('A', 'I', 'F', 'F'))
239 aiff->is_aifc = FALSE;
240 else if (type == GST_MAKE_FOURCC ('A', 'I', 'F', 'C'))
241 aiff->is_aifc = TRUE;
245 gst_buffer_unref (buf);
251 GST_ELEMENT_ERROR (aiff, STREAM, WRONG_TYPE, (NULL),
252 ("File is not an AIFF file: %" GST_FOURCC_FORMAT,
253 GST_FOURCC_ARGS (type)));
254 gst_buffer_unref (buf);
260 gst_aiff_parse_stream_init (GstAiffParse * aiff)
263 GstBuffer *buf = NULL;
265 if ((res = gst_pad_pull_range (aiff->sinkpad,
266 aiff->offset, 12, &buf)) != GST_FLOW_OK)
268 else if (!gst_aiff_parse_parse_file_header (aiff, buf))
269 return GST_FLOW_ERROR;
276 /* This function is used to perform seeks on the element in
279 * It also works when event is NULL, in which case it will just
280 * start from the last configured segment. This technique is
281 * used when activating the element and to perform the seek in
285 gst_aiff_parse_perform_seek (GstAiffParse * aiff, GstEvent * event)
289 GstFormat format, bformat;
291 GstSeekType cur_type = GST_SEEK_TYPE_NONE, stop_type;
292 gint64 cur, stop, upstream_size;
295 GstSegment seeksegment = { 0, };
299 GST_DEBUG_OBJECT (aiff, "doing seek with event");
301 gst_event_parse_seek (event, &rate, &format, &flags,
302 &cur_type, &cur, &stop_type, &stop);
304 /* no negative rates yet */
308 if (format != aiff->segment.format) {
309 GST_INFO_OBJECT (aiff, "converting seek-event from %s to %s",
310 gst_format_get_name (format),
311 gst_format_get_name (aiff->segment.format));
313 if (cur_type != GST_SEEK_TYPE_NONE)
315 gst_pad_query_convert (aiff->srcpad, format, cur,
316 &aiff->segment.format, &cur);
317 if (res && stop_type != GST_SEEK_TYPE_NONE)
319 gst_pad_query_convert (aiff->srcpad, format, stop,
320 &aiff->segment.format, &stop);
324 format = aiff->segment.format;
327 GST_DEBUG_OBJECT (aiff, "doing seek without event");
330 cur_type = GST_SEEK_TYPE_SET;
331 stop_type = GST_SEEK_TYPE_SET;
335 flush = flags & GST_SEEK_FLAG_FLUSH;
337 /* now we need to make sure the streaming thread is stopped. We do this by
338 * either sending a FLUSH_START event downstream which will cause the
339 * streaming thread to stop with a WRONG_STATE.
340 * For a non-flushing seek we simply pause the task, which will happen as soon
341 * as it completes one iteration (and thus might block when the sink is
342 * blocking in preroll). */
344 GST_DEBUG_OBJECT (aiff, "sending flush start");
345 gst_pad_push_event (aiff->srcpad, gst_event_new_flush_start ());
347 gst_pad_pause_task (aiff->sinkpad);
350 /* we should now be able to grab the streaming thread because we stopped it
351 * with the above flush/pause code */
352 GST_PAD_STREAM_LOCK (aiff->sinkpad);
354 /* save current position */
355 last_stop = aiff->segment.last_stop;
357 GST_DEBUG_OBJECT (aiff, "stopped streaming at %" G_GINT64_FORMAT, last_stop);
359 /* copy segment, we need this because we still need the old
360 * segment when we close the current segment. */
361 memcpy (&seeksegment, &aiff->segment, sizeof (GstSegment));
363 /* configure the seek parameters in the seeksegment. We will then have the
364 * right values in the segment to perform the seek */
366 GST_DEBUG_OBJECT (aiff, "configuring seek");
367 gst_segment_set_seek (&seeksegment, rate, format, flags,
368 cur_type, cur, stop_type, stop, &update);
371 /* figure out the last position we need to play. If it's configured (stop !=
372 * -1), use that, else we play until the total duration of the file */
373 if ((stop = seeksegment.stop) == -1)
374 stop = seeksegment.duration;
376 GST_DEBUG_OBJECT (aiff, "cur_type =%d", cur_type);
377 if ((cur_type != GST_SEEK_TYPE_NONE)) {
378 /* bring offset to bytes, if the bps is 0, we have the segment in BYTES and
379 * we can just copy the last_stop. If not, we use the bps to convert TIME to
383 gst_util_uint64_scale_ceil (seeksegment.last_stop,
384 (guint64) aiff->bps, GST_SECOND);
386 aiff->offset = seeksegment.last_stop;
387 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
388 aiff->offset -= (aiff->offset % aiff->bytes_per_sample);
389 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
390 aiff->offset += aiff->datastart;
391 GST_LOG_OBJECT (aiff, "offset=%" G_GUINT64_FORMAT, aiff->offset);
393 GST_LOG_OBJECT (aiff, "continue from offset=%" G_GUINT64_FORMAT,
397 if (stop_type != GST_SEEK_TYPE_NONE) {
400 gst_util_uint64_scale_ceil (stop, (guint64) aiff->bps, GST_SECOND);
402 aiff->end_offset = stop;
403 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
404 aiff->end_offset -= (aiff->end_offset % aiff->bytes_per_sample);
405 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
406 aiff->end_offset += aiff->datastart;
407 GST_LOG_OBJECT (aiff, "end_offset=%" G_GUINT64_FORMAT, aiff->end_offset);
409 GST_LOG_OBJECT (aiff, "continue to end_offset=%" G_GUINT64_FORMAT,
413 /* make sure filesize is not exceeded due to rounding errors or so,
414 * same precaution as in _stream_headers */
415 bformat = GST_FORMAT_BYTES;
416 if (gst_pad_query_peer_duration (aiff->sinkpad, &bformat, &upstream_size))
417 aiff->end_offset = MIN (aiff->end_offset, upstream_size);
419 /* this is the range of bytes we will use for playback */
420 aiff->offset = MIN (aiff->offset, aiff->end_offset);
421 aiff->dataleft = aiff->end_offset - aiff->offset;
423 GST_DEBUG_OBJECT (aiff,
424 "seek: rate %lf, offset %" G_GUINT64_FORMAT ", end %" G_GUINT64_FORMAT
425 ", segment %" GST_TIME_FORMAT " -- %" GST_TIME_FORMAT, rate, aiff->offset,
426 aiff->end_offset, GST_TIME_ARGS (seeksegment.start),
427 GST_TIME_ARGS (stop));
429 /* prepare for streaming again */
431 /* if we sent a FLUSH_START, we now send a FLUSH_STOP */
432 GST_DEBUG_OBJECT (aiff, "sending flush stop");
433 gst_pad_push_event (aiff->srcpad, gst_event_new_flush_stop ());
434 } else if (aiff->segment_running) {
435 /* we are running the current segment and doing a non-flushing seek,
436 * close the segment first based on the previous last_stop. */
437 GST_DEBUG_OBJECT (aiff, "closing running segment %" G_GINT64_FORMAT
438 " to %" G_GINT64_FORMAT, aiff->segment.accum, aiff->segment.last_stop);
440 /* queue the segment for sending in the stream thread */
441 if (aiff->close_segment)
442 gst_event_unref (aiff->close_segment);
443 aiff->close_segment = gst_event_new_new_segment (TRUE,
444 aiff->segment.rate, aiff->segment.format,
445 aiff->segment.accum, aiff->segment.last_stop, aiff->segment.accum);
447 /* keep track of our last_stop */
448 seeksegment.accum = aiff->segment.last_stop;
451 /* now we did the seek and can activate the new segment values */
452 memcpy (&aiff->segment, &seeksegment, sizeof (GstSegment));
454 /* if we're doing a segment seek, post a SEGMENT_START message */
455 if (aiff->segment.flags & GST_SEEK_FLAG_SEGMENT) {
456 gst_element_post_message (GST_ELEMENT_CAST (aiff),
457 gst_message_new_segment_start (GST_OBJECT_CAST (aiff),
458 aiff->segment.format, aiff->segment.last_stop));
461 /* now create the newsegment */
462 GST_DEBUG_OBJECT (aiff, "Creating newsegment from %" G_GINT64_FORMAT
463 " to %" G_GINT64_FORMAT, aiff->segment.last_stop, stop);
465 /* store the newsegment event so it can be sent from the streaming thread. */
466 if (aiff->start_segment)
467 gst_event_unref (aiff->start_segment);
468 aiff->start_segment =
469 gst_event_new_new_segment (FALSE, aiff->segment.rate,
470 aiff->segment.format, aiff->segment.last_stop, stop,
471 aiff->segment.last_stop);
473 /* mark discont if we are going to stream from another position. */
474 if (last_stop != aiff->segment.last_stop) {
475 GST_DEBUG_OBJECT (aiff, "mark DISCONT, we did a seek to another position");
476 aiff->discont = TRUE;
479 /* and start the streaming task again */
480 aiff->segment_running = TRUE;
481 if (!aiff->streaming) {
482 gst_pad_start_task (aiff->sinkpad, (GstTaskFunction) gst_aiff_parse_loop,
483 aiff->sinkpad, NULL);
486 GST_PAD_STREAM_UNLOCK (aiff->sinkpad);
493 GST_DEBUG_OBJECT (aiff, "negative playback rates are not supported yet.");
498 GST_DEBUG_OBJECT (aiff, "unsupported format given, seek aborted.");
504 * gst_aiff_parse_peek_chunk_info:
505 * @aiff AIFFparse object
506 * @tag holder for tag
507 * @size holder for tag size
509 * Peek next chunk info (tag and size)
511 * Returns: %TRUE when the chunk info (header) is available
514 gst_aiff_parse_peek_chunk_info (GstAiffParse * aiff, guint32 * tag,
517 const guint8 *data = NULL;
519 if (gst_adapter_available (aiff->adapter) < 8)
522 data = gst_adapter_peek (aiff->adapter, 8);
523 *tag = GST_READ_UINT32_LE (data);
524 *size = GST_READ_UINT32_BE (data + 4);
526 GST_DEBUG ("Next chunk size is %d bytes, type %" GST_FOURCC_FORMAT, *size,
527 GST_FOURCC_ARGS (*tag));
533 * gst_aiff_parse_peek_chunk:
534 * @aiff AIFFparse object
535 * @tag holder for tag
536 * @size holder for tag size
538 * Peek enough data for one full chunk
540 * Returns: %TRUE when the full chunk is available
543 gst_aiff_parse_peek_chunk (GstAiffParse * aiff, guint32 * tag, guint32 * size)
545 guint32 peek_size = 0;
548 if (!gst_aiff_parse_peek_chunk_info (aiff, tag, size))
551 GST_DEBUG ("Need to peek chunk of %d bytes", *size);
552 peek_size = (*size + 1) & ~1;
554 available = gst_adapter_available (aiff->adapter);
555 if (available >= (8 + peek_size)) {
558 GST_LOG ("but only %u bytes available now", available);
564 gst_aiff_parse_peek_data (GstAiffParse * aiff, guint32 size,
565 const guint8 ** data)
567 if (gst_adapter_available (aiff->adapter) < size)
570 *data = gst_adapter_peek (aiff->adapter, size);
575 * gst_aiff_parse_calculate_duration:
576 * @aiff: aiffparse object
578 * Calculate duration on demand and store in @aiff.
580 * Returns: %TRUE if duration is available.
583 gst_aiff_parse_calculate_duration (GstAiffParse * aiff)
585 if (aiff->duration > 0)
588 if (aiff->datasize > 0 && aiff->bps > 0) {
590 gst_util_uint64_scale_ceil (aiff->datasize, GST_SECOND,
591 (guint64) aiff->bps);
592 GST_INFO_OBJECT (aiff, "Got duration %" GST_TIME_FORMAT,
593 GST_TIME_ARGS (aiff->duration));
600 gst_aiff_parse_ignore_chunk (GstAiffParse * aiff, GstBuffer * buf, guint32 tag,
605 if (aiff->streaming) {
606 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
609 GST_DEBUG_OBJECT (aiff, "Ignoring tag %" GST_FOURCC_FORMAT,
610 GST_FOURCC_ARGS (tag));
611 flush = 8 + ((size + 1) & ~1);
612 aiff->offset += flush;
613 if (aiff->streaming) {
614 gst_adapter_flush (aiff->adapter, flush);
616 gst_buffer_unref (buf);
621 gst_aiff_parse_read_IEEE80 (guint8 * buf)
623 int s = buf[0] & 0xff;
624 int e = ((buf[0] & 0x7f) << 8) | (buf[1] & 0xff);
625 double f = ((unsigned long) (buf[2] & 0xff) << 24) |
626 ((buf[3] & 0xff) << 16) | ((buf[4] & 0xff) << 8) | (buf[5] & 0xff);
630 return HUGE_VAL; /* Really NaN, but this won't happen in reality */
640 f += ((buf[6] & 0xff) << 24) |
641 ((buf[7] & 0xff) << 16) | ((buf[8] & 0xff) << 8) | (buf[9] & 0xff);
643 return ldexp (f, e - 16446);
647 gst_aiff_parse_parse_comm (GstAiffParse * aiff, GstBuffer * buf)
657 if (GST_BUFFER_SIZE (buf) < size) {
658 GST_WARNING_OBJECT (aiff, "COMM chunk too short, cannot parse header");
662 data = GST_BUFFER_DATA (buf);
664 aiff->channels = GST_READ_UINT16_BE (data);
665 aiff->total_frames = GST_READ_UINT32_BE (data + 2);
666 aiff->depth = GST_READ_UINT16_BE (data + 6);
667 aiff->width = GST_ROUND_UP_8 (aiff->depth);
668 aiff->rate = (int) gst_aiff_parse_read_IEEE80 (data + 8);
670 aiff->floating_point = FALSE;
673 guint32 fourcc = GST_READ_UINT32_LE (data + 18);
675 /* We only support the 'trivial' uncompressed AIFC, but it can be
676 * either big or little endian */
678 case GST_MAKE_FOURCC ('N', 'O', 'N', 'E'):
679 aiff->endianness = G_BIG_ENDIAN;
681 case GST_MAKE_FOURCC ('s', 'o', 'w', 't'):
682 aiff->endianness = G_LITTLE_ENDIAN;
684 case GST_MAKE_FOURCC ('F', 'L', '3', '2'):
685 case GST_MAKE_FOURCC ('f', 'l', '3', '2'):
686 aiff->floating_point = TRUE;
687 aiff->width = aiff->depth = 32;
688 aiff->endianness = G_BIG_ENDIAN;
690 case GST_MAKE_FOURCC ('f', 'l', '6', '4'):
691 aiff->floating_point = TRUE;
692 aiff->width = aiff->depth = 64;
693 aiff->endianness = G_BIG_ENDIAN;
696 GST_WARNING_OBJECT (aiff, "Unsupported compression in AIFC "
697 "file: %" GST_FOURCC_FORMAT,
698 GST_FOURCC_ARGS (GST_READ_UINT32_LE (data + 18)));
703 aiff->endianness = G_BIG_ENDIAN;
709 gst_aiff_parse_read_chunk (GstAiffParse * aiff, guint64 * offset, guint32 * tag,
717 gst_pad_pull_range (aiff->sinkpad, *offset, 8, &buf)) != GST_FLOW_OK)
720 *tag = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
721 size = GST_READ_UINT32_BE (GST_BUFFER_DATA (buf) + 4);
724 gst_pad_pull_range (aiff->sinkpad, (*offset) + 8, size,
725 &buf)) != GST_FLOW_OK)
727 else if (GST_BUFFER_SIZE (buf) < size)
731 *offset += 8 + GST_ROUND_UP_2 (size);
738 /* short read, we return UNEXPECTED to mark the EOS case */
739 GST_DEBUG_OBJECT (aiff, "not enough data (available=%u, needed=%u)",
740 GST_BUFFER_SIZE (buf), size);
741 gst_buffer_unref (buf);
742 return GST_FLOW_UNEXPECTED;
748 gst_aiff_parse_create_caps (GstAiffParse * aiff)
752 if (aiff->floating_point) {
753 caps = gst_caps_new_simple ("audio/x-raw-float",
754 "width", G_TYPE_INT, aiff->width,
755 "channels", G_TYPE_INT, aiff->channels,
756 "endianness", G_TYPE_INT, aiff->endianness,
757 "rate", G_TYPE_INT, aiff->rate, NULL);
759 caps = gst_caps_new_simple ("audio/x-raw-int",
760 "width", G_TYPE_INT, aiff->width,
761 "depth", G_TYPE_INT, aiff->depth,
762 "channels", G_TYPE_INT, aiff->channels,
763 "endianness", G_TYPE_INT, aiff->endianness,
764 "rate", G_TYPE_INT, aiff->rate, "signed", G_TYPE_BOOLEAN, TRUE, NULL);
767 GST_DEBUG_OBJECT (aiff, "Created caps: %" GST_PTR_FORMAT, caps);
772 gst_aiff_parse_stream_headers (GstAiffParse * aiff)
777 gboolean gotdata = FALSE;
778 gboolean done = FALSE;
781 gint64 upstream_size = 0;
783 bformat = GST_FORMAT_BYTES;
784 gst_pad_query_peer_duration (aiff->sinkpad, &bformat, &upstream_size);
785 GST_DEBUG_OBJECT (aiff, "upstream size %" G_GUINT64_FORMAT, upstream_size);
787 /* loop headers until we get data */
789 if (aiff->streaming) {
790 if (!gst_aiff_parse_peek_chunk_info (aiff, &tag, &size))
794 gst_pad_pull_range (aiff->sinkpad, aiff->offset, 8,
795 &buf)) != GST_FLOW_OK)
796 goto header_read_error;
797 tag = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
798 size = GST_READ_UINT32_BE (GST_BUFFER_DATA (buf) + 4);
801 GST_INFO_OBJECT (aiff,
802 "Got TAG: %" GST_FOURCC_FORMAT ", offset %" G_GUINT64_FORMAT,
803 GST_FOURCC_ARGS (tag), aiff->offset);
805 /* We just keep reading chunks until we find the one we're interested in.
808 case GST_MAKE_FOURCC ('C', 'O', 'M', 'M'):{
809 if (aiff->streaming) {
810 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
813 gst_adapter_flush (aiff->adapter, 8);
816 buf = gst_adapter_take_buffer (aiff->adapter, size);
818 if ((res = gst_aiff_parse_read_chunk (aiff,
819 &aiff->offset, &tag, &buf)) != GST_FLOW_OK)
823 if (!gst_aiff_parse_parse_comm (aiff, buf)) {
824 gst_buffer_unref (buf);
825 goto parse_header_error;
828 gst_buffer_unref (buf);
830 /* do sanity checks of header fields */
831 if (aiff->channels == 0)
836 GST_DEBUG_OBJECT (aiff, "creating the caps");
838 aiff->caps = gst_aiff_parse_create_caps (aiff);
842 gst_pad_set_caps (aiff->srcpad, aiff->caps);
844 aiff->bytes_per_sample = aiff->channels * aiff->width / 8;
845 aiff->bps = aiff->bytes_per_sample * aiff->rate;
847 if (aiff->bytes_per_sample <= 0)
848 goto no_bytes_per_sample;
850 aiff->got_comm = TRUE;
853 case GST_MAKE_FOURCC ('S', 'S', 'N', 'D'):{
854 GstBuffer *ssndbuf = NULL;
855 const guint8 *ssnddata = NULL;
858 GST_DEBUG_OBJECT (aiff, "Got 'SSND' TAG, size : %d", size);
860 /* Now, read the 8-byte header in the SSND chunk */
861 if (aiff->streaming) {
862 if (!gst_aiff_parse_peek_data (aiff, 16, &ssnddata))
865 gst_buffer_unref (buf);
867 gst_pad_pull_range (aiff->sinkpad, aiff->offset, 16,
868 &ssndbuf)) != GST_FLOW_OK)
869 goto header_read_error;
870 ssnddata = GST_BUFFER_DATA (ssndbuf);
873 aiff->ssnd_offset = GST_READ_UINT32_BE (ssnddata + 8);
874 aiff->ssnd_blocksize = GST_READ_UINT32_BE (ssnddata + 12);
877 if (aiff->streaming) {
878 gst_adapter_flush (aiff->adapter, 16);
880 gst_buffer_unref (ssndbuf);
882 /* 8 byte chunk header, 8 byte SSND header */
885 datasize = size - 16;
887 aiff->datastart = aiff->offset + aiff->ssnd_offset;
888 /* file might be truncated */
890 size = MIN (datasize, (upstream_size - aiff->datastart));
892 aiff->datasize = (guint64) datasize;
893 aiff->dataleft = (guint64) datasize;
894 aiff->end_offset = datasize + aiff->datastart;
895 if (!aiff->streaming) {
896 /* We will continue looking at chunks until the end - to read tags,
898 aiff->offset += datasize;
900 GST_DEBUG_OBJECT (aiff, "datasize = %d", datasize);
901 if (aiff->streaming) {
906 case GST_MAKE_FOURCC ('I', 'D', '3', ' '):{
909 if (aiff->streaming) {
910 if (!gst_aiff_parse_peek_chunk (aiff, &tag, &size))
913 gst_adapter_flush (aiff->adapter, 8);
916 buf = gst_adapter_take_buffer (aiff->adapter, size);
918 if ((res = gst_aiff_parse_read_chunk (aiff,
919 &aiff->offset, &tag, &buf)) != GST_FLOW_OK)
923 GST_LOG_OBJECT (aiff, "ID3 chunk of size %u", GST_BUFFER_SIZE (buf));
925 tags = gst_tag_list_from_id3v2_tag (buf);
926 gst_buffer_unref (buf);
928 GST_INFO_OBJECT (aiff, "ID3 tags: %" GST_PTR_FORMAT, tags);
930 if (aiff->tags == NULL) {
933 gst_tag_list_insert (aiff->tags, tags, GST_TAG_MERGE_APPEND);
934 gst_tag_list_unref (tags);
939 gst_aiff_parse_ignore_chunk (aiff, buf, tag, size);
942 if (upstream_size && (aiff->offset >= upstream_size)) {
943 /* Now we have gone through the whole file */
948 /* We read all the chunks (in pull mode) or reached the SSND chunk
949 * (in push mode). We must have both COMM and SSND now; error out
952 if (!aiff->got_comm) {
953 GST_WARNING_OBJECT (aiff, "Failed to find COMM chunk");
957 GST_WARNING_OBJECT (aiff, "Failed to find SSND chunk");
961 GST_DEBUG_OBJECT (aiff, "Finished parsing headers");
963 if (gst_aiff_parse_calculate_duration (aiff)) {
964 gst_segment_init (&aiff->segment, GST_FORMAT_TIME);
965 gst_segment_set_duration (&aiff->segment, GST_FORMAT_TIME, aiff->duration);
967 /* no bitrate, let downstream peer do the math, we'll feed it bytes. */
968 gst_segment_init (&aiff->segment, GST_FORMAT_BYTES);
969 gst_segment_set_duration (&aiff->segment, GST_FORMAT_BYTES, aiff->datasize);
972 /* now we have all the info to perform a pending seek if any, if no
973 * event, this will still do the right thing and it will also send
974 * the right newsegment event downstream. */
975 gst_aiff_parse_perform_seek (aiff, aiff->seek_event);
976 /* remove pending event */
977 event_p = &aiff->seek_event;
978 gst_event_replace (event_p, NULL);
980 /* we just started, we are discont */
981 aiff->discont = TRUE;
983 aiff->state = AIFF_PARSE_DATA;
990 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
991 ("Invalid AIFF header (no COMM found)"));
992 return GST_FLOW_ERROR;
996 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
997 ("Invalid AIFF: no SSND found"));
998 return GST_FLOW_ERROR;
1002 GST_ELEMENT_ERROR (aiff, STREAM, DEMUX, (NULL),
1003 ("Couldn't parse audio header"));
1004 return GST_FLOW_ERROR;
1008 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
1009 ("Stream claims to contain no channels - invalid data"));
1010 return GST_FLOW_ERROR;
1014 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
1015 ("Stream with sample_rate == 0 - invalid data"));
1016 return GST_FLOW_ERROR;
1018 no_bytes_per_sample:
1020 GST_ELEMENT_ERROR (aiff, STREAM, FAILED, (NULL),
1021 ("Could not caluclate bytes per sample - invalid data"));
1022 return GST_FLOW_ERROR;
1026 GST_ELEMENT_ERROR (aiff, STREAM, TYPE_NOT_FOUND, (NULL),
1027 ("No caps found for format 0x%x, %d channels, %d Hz",
1028 aiff->format, aiff->channels, aiff->rate));
1029 return GST_FLOW_ERROR;
1033 GST_ELEMENT_ERROR (aiff, STREAM, DEMUX, (NULL),
1034 ("Couldn't read in header"));
1035 return GST_FLOW_ERROR;
1040 * Read AIFF file tag when streaming
1042 static GstFlowReturn
1043 gst_aiff_parse_parse_stream_init (GstAiffParse * aiff)
1045 if (gst_adapter_available (aiff->adapter) >= 12) {
1048 /* _take flushes the data */
1049 tmp = gst_adapter_take_buffer (aiff->adapter, 12);
1051 GST_DEBUG ("Parsing aiff header");
1052 if (!gst_aiff_parse_parse_file_header (aiff, tmp))
1053 return GST_FLOW_ERROR;
1056 /* Go to next state */
1057 aiff->state = AIFF_PARSE_HEADER;
1062 /* handle an event sent directly to the element.
1064 * This event can be sent either in the READY state or the
1065 * >READY state. The only event of interest really is the seek
1068 * In the READY state we can only store the event and try to
1069 * respect it when going to PAUSED. We assume we are in the
1070 * READY state when our parsing state != AIFF_PARSE_DATA.
1072 * When we are steaming, we can simply perform the seek right
1076 gst_aiff_parse_send_event (GstElement * element, GstEvent * event)
1078 GstAiffParse *aiff = GST_AIFF_PARSE (element);
1079 gboolean res = FALSE;
1082 GST_DEBUG_OBJECT (aiff, "received event %s", GST_EVENT_TYPE_NAME (event));
1084 switch (GST_EVENT_TYPE (event)) {
1085 case GST_EVENT_SEEK:
1086 if (aiff->state == AIFF_PARSE_DATA) {
1087 /* we can handle the seek directly when streaming data */
1088 res = gst_aiff_parse_perform_seek (aiff, event);
1090 GST_DEBUG_OBJECT (aiff, "queuing seek for later");
1092 event_p = &aiff->seek_event;
1093 gst_event_replace (event_p, event);
1095 /* we always return true */
1102 gst_event_unref (event);
1106 #define MAX_BUFFER_SIZE 4096
1108 static GstFlowReturn
1109 gst_aiff_parse_stream_data (GstAiffParse * aiff)
1111 GstBuffer *buf = NULL;
1112 GstFlowReturn res = GST_FLOW_OK;
1113 guint64 desired, obtained;
1114 GstClockTime timestamp, next_timestamp, duration;
1115 guint64 pos, nextpos;
1118 GST_LOG_OBJECT (aiff,
1119 "offset: %" G_GINT64_FORMAT " , end: %" G_GINT64_FORMAT " , dataleft: %"
1120 G_GINT64_FORMAT, aiff->offset, aiff->end_offset, aiff->dataleft);
1122 /* Get the next n bytes and output them */
1123 if (aiff->dataleft == 0 || aiff->dataleft < aiff->bytes_per_sample)
1126 /* scale the amount of data by the segment rate so we get equal
1127 * amounts of data regardless of the playback rate */
1129 MIN (gst_guint64_to_gdouble (aiff->dataleft),
1130 MAX_BUFFER_SIZE * aiff->segment.abs_rate);
1132 if (desired >= aiff->bytes_per_sample && aiff->bytes_per_sample > 0)
1133 desired -= (desired % aiff->bytes_per_sample);
1135 GST_LOG_OBJECT (aiff, "Fetching %" G_GINT64_FORMAT " bytes of data "
1136 "from the sinkpad", desired);
1138 if (aiff->streaming) {
1139 guint avail = gst_adapter_available (aiff->adapter);
1141 if (avail < desired) {
1142 GST_LOG_OBJECT (aiff, "Got only %d bytes of data from the sinkpad",
1147 buf = gst_adapter_take_buffer (aiff->adapter, desired);
1149 if ((res = gst_pad_pull_range (aiff->sinkpad, aiff->offset,
1150 desired, &buf)) != GST_FLOW_OK)
1154 /* If we have a pending close/start segment, send it now. */
1155 if (G_UNLIKELY (aiff->close_segment != NULL)) {
1156 gst_pad_push_event (aiff->srcpad, aiff->close_segment);
1157 aiff->close_segment = NULL;
1159 if (G_UNLIKELY (aiff->start_segment != NULL)) {
1160 gst_pad_push_event (aiff->srcpad, aiff->start_segment);
1161 aiff->start_segment = NULL;
1163 if (G_UNLIKELY (aiff->tags != NULL)) {
1164 gst_element_found_tags_for_pad (GST_ELEMENT_CAST (aiff), aiff->srcpad,
1169 obtained = GST_BUFFER_SIZE (buf);
1171 /* our positions in bytes */
1172 pos = aiff->offset - aiff->datastart;
1173 nextpos = pos + obtained;
1175 /* update offsets, does not overflow. */
1176 GST_BUFFER_OFFSET (buf) = pos / aiff->bytes_per_sample;
1177 GST_BUFFER_OFFSET_END (buf) = nextpos / aiff->bytes_per_sample;
1179 if (aiff->bps > 0) {
1180 /* and timestamps if we have a bitrate, be careful for overflows */
1182 gst_util_uint64_scale_ceil (pos, GST_SECOND, (guint64) aiff->bps);
1184 gst_util_uint64_scale_ceil (nextpos, GST_SECOND, (guint64) aiff->bps);
1185 duration = next_timestamp - timestamp;
1187 /* update current running segment position */
1188 gst_segment_set_last_stop (&aiff->segment, GST_FORMAT_TIME, next_timestamp);
1190 /* no bitrate, all we know is that the first sample has timestamp 0, all
1191 * other positions and durations have unknown timestamp. */
1195 timestamp = GST_CLOCK_TIME_NONE;
1196 duration = GST_CLOCK_TIME_NONE;
1197 /* update current running segment position with byte offset */
1198 gst_segment_set_last_stop (&aiff->segment, GST_FORMAT_BYTES, nextpos);
1200 if (aiff->discont) {
1201 GST_DEBUG_OBJECT (aiff, "marking DISCONT");
1202 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
1203 aiff->discont = FALSE;
1206 GST_BUFFER_TIMESTAMP (buf) = timestamp;
1207 GST_BUFFER_DURATION (buf) = duration;
1208 gst_buffer_set_caps (buf, aiff->caps);
1210 GST_LOG_OBJECT (aiff,
1211 "Got buffer. timestamp:%" GST_TIME_FORMAT " , duration:%" GST_TIME_FORMAT
1212 ", size:%u", GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration),
1213 GST_BUFFER_SIZE (buf));
1215 if ((res = gst_pad_push (aiff->srcpad, buf)) != GST_FLOW_OK)
1218 if (obtained < aiff->dataleft) {
1219 aiff->offset += obtained;
1220 aiff->dataleft -= obtained;
1222 aiff->offset += aiff->dataleft;
1226 /* Iterate until need more data, so adapter size won't grow */
1227 if (aiff->streaming) {
1228 GST_LOG_OBJECT (aiff,
1229 "offset: %" G_GINT64_FORMAT " , end: %" G_GINT64_FORMAT, aiff->offset,
1231 goto iterate_adapter;
1238 GST_DEBUG_OBJECT (aiff, "found EOS");
1239 return GST_FLOW_UNEXPECTED;
1243 /* check if we got EOS */
1244 if (res == GST_FLOW_UNEXPECTED)
1247 GST_WARNING_OBJECT (aiff,
1248 "Error getting %" G_GINT64_FORMAT " bytes from the "
1249 "sinkpad (dataleft = %" G_GINT64_FORMAT ")", desired, aiff->dataleft);
1254 GST_INFO_OBJECT (aiff,
1255 "Error pushing on srcpad %s:%s, reason %s, is linked? = %d",
1256 GST_DEBUG_PAD_NAME (aiff->srcpad), gst_flow_get_name (res),
1257 gst_pad_is_linked (aiff->srcpad));
1263 gst_aiff_parse_loop (GstPad * pad)
1266 GstAiffParse *aiff = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1268 GST_LOG_OBJECT (aiff, "process data");
1270 switch (aiff->state) {
1271 case AIFF_PARSE_START:
1272 GST_INFO_OBJECT (aiff, "AIFF_PARSE_START");
1273 if ((ret = gst_aiff_parse_stream_init (aiff)) != GST_FLOW_OK)
1276 aiff->state = AIFF_PARSE_HEADER;
1279 case AIFF_PARSE_HEADER:
1280 GST_INFO_OBJECT (aiff, "AIFF_PARSE_HEADER");
1281 if ((ret = gst_aiff_parse_stream_headers (aiff)) != GST_FLOW_OK)
1284 aiff->state = AIFF_PARSE_DATA;
1285 GST_INFO_OBJECT (aiff, "AIFF_PARSE_DATA");
1288 case AIFF_PARSE_DATA:
1289 if ((ret = gst_aiff_parse_stream_data (aiff)) != GST_FLOW_OK)
1293 g_assert_not_reached ();
1300 const gchar *reason = gst_flow_get_name (ret);
1302 GST_DEBUG_OBJECT (aiff, "pausing task, reason %s", reason);
1303 aiff->segment_running = FALSE;
1304 gst_pad_pause_task (pad);
1306 if (ret == GST_FLOW_UNEXPECTED) {
1307 /* perform EOS logic */
1308 if (aiff->segment.flags & GST_SEEK_FLAG_SEGMENT) {
1311 if ((stop = aiff->segment.stop) == -1)
1312 stop = aiff->segment.duration;
1314 gst_element_post_message (GST_ELEMENT_CAST (aiff),
1315 gst_message_new_segment_done (GST_OBJECT_CAST (aiff),
1316 aiff->segment.format, stop));
1317 gst_pad_push_event (aiff->srcpad,
1318 gst_evnet_new_segment_done (aiff->segment.format, stop));
1320 gst_pad_push_event (aiff->srcpad, gst_event_new_eos ());
1322 } else if (ret < GST_FLOW_UNEXPECTED || ret == GST_FLOW_NOT_LINKED) {
1323 /* for fatal errors we post an error message, post the error
1324 * first so the app knows about the error first. */
1325 GST_ELEMENT_ERROR (aiff, STREAM, FAILED,
1326 (_("Internal data flow error.")),
1327 ("streaming task paused, reason %s (%d)", reason, ret));
1328 gst_pad_push_event (aiff->srcpad, gst_event_new_eos ());
1334 static GstFlowReturn
1335 gst_aiff_parse_chain (GstPad * pad, GstBuffer * buf)
1338 GstAiffParse *aiff = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1340 GST_LOG_OBJECT (aiff, "adapter_push %u bytes", GST_BUFFER_SIZE (buf));
1342 gst_adapter_push (aiff->adapter, buf);
1344 switch (aiff->state) {
1345 case AIFF_PARSE_START:
1346 GST_INFO_OBJECT (aiff, "AIFF_PARSE_START");
1347 if ((ret = gst_aiff_parse_parse_stream_init (aiff)) != GST_FLOW_OK)
1350 if (aiff->state != AIFF_PARSE_HEADER)
1353 /* otherwise fall-through */
1354 case AIFF_PARSE_HEADER:
1355 GST_INFO_OBJECT (aiff, "AIFF_PARSE_HEADER");
1356 if ((ret = gst_aiff_parse_stream_headers (aiff)) != GST_FLOW_OK)
1359 if (!aiff->got_comm || aiff->datastart == 0)
1362 aiff->state = AIFF_PARSE_DATA;
1363 GST_INFO_OBJECT (aiff, "AIFF_PARSE_DATA");
1366 case AIFF_PARSE_DATA:
1367 if ((ret = gst_aiff_parse_stream_data (aiff)) != GST_FLOW_OK)
1371 g_return_val_if_reached (GST_FLOW_ERROR);
1378 gst_aiff_parse_pad_convert (GstPad * pad,
1379 GstFormat src_format, gint64 src_value,
1380 GstFormat * dest_format, gint64 * dest_value)
1382 GstAiffParse *aiffparse;
1383 gboolean res = TRUE;
1385 aiffparse = GST_AIFF_PARSE (GST_PAD_PARENT (pad));
1387 if (*dest_format == src_format) {
1388 *dest_value = src_value;
1392 if (aiffparse->bytes_per_sample <= 0)
1395 GST_INFO_OBJECT (aiffparse, "converting value from %s to %s",
1396 gst_format_get_name (src_format), gst_format_get_name (*dest_format));
1398 switch (src_format) {
1399 case GST_FORMAT_BYTES:
1400 switch (*dest_format) {
1401 case GST_FORMAT_DEFAULT:
1402 *dest_value = src_value / aiffparse->bytes_per_sample;
1404 case GST_FORMAT_TIME:
1405 if (aiffparse->bps > 0) {
1406 *dest_value = gst_util_uint64_scale_ceil (src_value, GST_SECOND,
1407 (guint64) aiffparse->bps);
1410 /* Else fallthrough */
1417 case GST_FORMAT_DEFAULT:
1418 switch (*dest_format) {
1419 case GST_FORMAT_BYTES:
1420 *dest_value = src_value * aiffparse->bytes_per_sample;
1422 case GST_FORMAT_TIME:
1423 *dest_value = gst_util_uint64_scale (src_value, GST_SECOND,
1424 (guint64) aiffparse->rate);
1432 case GST_FORMAT_TIME:
1433 switch (*dest_format) {
1434 case GST_FORMAT_BYTES:
1435 if (aiffparse->bps > 0) {
1436 *dest_value = gst_util_uint64_scale (src_value,
1437 (guint64) aiffparse->bps, GST_SECOND);
1440 /* Else fallthrough */
1442 case GST_FORMAT_DEFAULT:
1443 *dest_value = gst_util_uint64_scale (src_value,
1444 (guint64) aiffparse->rate, GST_SECOND);
1462 static const GstQueryType *
1463 gst_aiff_parse_get_query_types (GstPad * pad)
1465 static const GstQueryType types[] = {
1475 /* handle queries for location and length in requested format */
1477 gst_aiff_parse_pad_query (GstPad * pad, GstQuery * query)
1479 gboolean res = TRUE;
1480 GstAiffParse *aiff = GST_AIFF_PARSE (gst_pad_get_parent (pad));
1482 /* only if we know */
1483 if (aiff->state != AIFF_PARSE_DATA) {
1484 gst_object_unref (aiff);
1488 switch (GST_QUERY_TYPE (query)) {
1489 case GST_QUERY_DURATION:
1491 gint64 duration = 0;
1494 gst_query_parse_duration (query, &format, NULL);
1497 case GST_FORMAT_TIME:{
1498 if ((res = gst_aiff_parse_calculate_duration (aiff))) {
1499 duration = aiff->duration;
1504 format = GST_FORMAT_BYTES;
1505 duration = aiff->datasize;
1508 gst_query_set_duration (query, format, duration);
1511 case GST_QUERY_CONVERT:
1513 gint64 srcvalue, dstvalue;
1514 GstFormat srcformat, dstformat;
1516 gst_query_parse_convert (query, &srcformat, &srcvalue,
1517 &dstformat, &dstvalue);
1518 res = gst_aiff_parse_pad_convert (pad, srcformat, srcvalue,
1519 &dstformat, &dstvalue);
1521 gst_query_set_convert (query, srcformat, srcvalue, dstformat, dstvalue);
1524 case GST_QUERY_SEEKING:{
1527 gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
1528 if (fmt == GST_FORMAT_TIME) {
1529 gboolean seekable = TRUE;
1531 if (!gst_aiff_parse_calculate_duration (aiff)) {
1534 gst_query_set_seeking (query, GST_FORMAT_TIME, seekable,
1541 res = gst_pad_query_default (pad, query);
1544 gst_object_unref (aiff);
1549 gst_aiff_parse_srcpad_event (GstPad * pad, GstEvent * event)
1551 GstAiffParse *aiffparse = GST_AIFF_PARSE (gst_pad_get_parent (pad));
1552 gboolean res = FALSE;
1554 GST_DEBUG_OBJECT (aiffparse, "%s event", GST_EVENT_TYPE_NAME (event));
1556 switch (GST_EVENT_TYPE (event)) {
1557 case GST_EVENT_SEEK:
1558 /* can only handle events when we are in the data state */
1559 if (aiffparse->state == AIFF_PARSE_DATA) {
1560 res = gst_aiff_parse_perform_seek (aiffparse, event);
1562 gst_event_unref (event);
1565 res = gst_pad_push_event (aiffparse->sinkpad, event);
1568 gst_object_unref (aiffparse);
1573 gst_aiff_parse_sink_activate (GstPad * sinkpad)
1575 GstAiffParse *aiff = GST_AIFF_PARSE (gst_pad_get_parent (sinkpad));
1579 g_object_unref (aiff->adapter);
1581 if (gst_pad_check_pull_range (sinkpad)) {
1582 GST_DEBUG ("going to pull mode");
1583 aiff->streaming = FALSE;
1584 aiff->adapter = NULL;
1585 res = gst_pad_activate_pull (sinkpad, TRUE);
1587 GST_DEBUG ("going to push (streaming) mode");
1588 aiff->streaming = TRUE;
1589 aiff->adapter = gst_adapter_new ();
1590 res = gst_pad_activate_push (sinkpad, TRUE);
1592 gst_object_unref (aiff);
1598 gst_aiff_parse_sink_activate_pull (GstPad * sinkpad, gboolean active)
1600 GstAiffParse *aiff = GST_AIFF_PARSE (GST_OBJECT_PARENT (sinkpad));
1603 aiff->segment_running = TRUE;
1604 return gst_pad_start_task (sinkpad, (GstTaskFunction) gst_aiff_parse_loop,
1607 aiff->segment_running = FALSE;
1608 return gst_pad_stop_task (sinkpad);
1612 static GstStateChangeReturn
1613 gst_aiff_parse_change_state (GstElement * element, GstStateChange transition)
1615 GstStateChangeReturn ret;
1616 GstAiffParse *aiff = GST_AIFF_PARSE (element);
1618 switch (transition) {
1619 case GST_STATE_CHANGE_NULL_TO_READY:
1621 case GST_STATE_CHANGE_READY_TO_PAUSED:
1622 gst_aiff_parse_reset (aiff);
1624 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1630 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1632 switch (transition) {
1633 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1635 case GST_STATE_CHANGE_PAUSED_TO_READY:
1636 gst_aiff_parse_reset (aiff);
1638 case GST_STATE_CHANGE_READY_TO_NULL: