2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
3 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-speexdec
23 * @see_also: speexenc, oggdemux
25 * This element decodes a Speex stream to raw integer audio.
26 * <ulink url="http://www.speex.org/">Speex</ulink> is a royalty-free
27 * audio codec maintained by the <ulink url="http://www.xiph.org/">Xiph.org
31 * <title>Example pipelines</title>
33 * gst-launch -v filesrc location=speex.ogg ! oggdemux ! speexdec ! audioconvert ! audioresample ! alsasink
34 * ]| Decode an Ogg/Speex file. To create an Ogg/Speex file refer to the
35 * documentation of speexenc.
38 * Last reviewed on 2006-04-05 (0.10.2)
45 #include "gstspeexdec.h"
48 #include <gst/tag/tag.h>
50 GST_DEBUG_CATEGORY_STATIC (speexdec_debug);
51 #define GST_CAT_DEFAULT speexdec_debug
53 #define DEFAULT_ENH TRUE
61 static GstStaticPadTemplate speex_dec_src_factory =
62 GST_STATIC_PAD_TEMPLATE ("src",
65 GST_STATIC_CAPS ("audio/x-raw-int, "
66 "rate = (int) [ 6000, 48000 ], "
67 "channels = (int) [ 1, 2 ], "
68 "endianness = (int) BYTE_ORDER, "
69 "signed = (boolean) true, " "width = (int) 16, " "depth = (int) 16")
72 static GstStaticPadTemplate speex_dec_sink_factory =
73 GST_STATIC_PAD_TEMPLATE ("sink",
76 GST_STATIC_CAPS ("audio/x-speex")
79 #define gst_speex_dec_parent_class parent_class
80 G_DEFINE_TYPE (GstSpeexDec, gst_speex_dec, GST_TYPE_ELEMENT);
82 static gboolean speex_dec_sink_event (GstPad * pad, GstEvent * event);
83 static GstFlowReturn speex_dec_chain (GstPad * pad, GstBuffer * buf);
84 static GstStateChangeReturn speex_dec_change_state (GstElement * element,
85 GstStateChange transition);
87 static gboolean speex_dec_src_event (GstPad * pad, GstEvent * event);
88 static gboolean speex_dec_src_query (GstPad * pad, GstQuery * query);
89 static gboolean speex_dec_sink_query (GstPad * pad, GstQuery * query);
90 static const GstQueryType *speex_get_src_query_types (GstPad * pad);
91 static const GstQueryType *speex_get_sink_query_types (GstPad * pad);
92 static gboolean speex_dec_convert (GstPad * pad,
93 GstFormat src_format, gint64 src_value,
94 GstFormat * dest_format, gint64 * dest_value);
96 static void gst_speex_dec_get_property (GObject * object, guint prop_id,
97 GValue * value, GParamSpec * pspec);
98 static void gst_speex_dec_set_property (GObject * object, guint prop_id,
99 const GValue * value, GParamSpec * pspec);
101 static GstFlowReturn speex_dec_chain_parse_data (GstSpeexDec * dec,
102 GstBuffer * buf, GstClockTime timestamp, GstClockTime duration);
104 static GstFlowReturn speex_dec_chain_parse_header (GstSpeexDec * dec,
106 static GstFlowReturn speex_dec_chain_parse_comments (GstSpeexDec * dec,
110 gst_speex_dec_class_init (GstSpeexDecClass * klass)
112 GObjectClass *gobject_class;
113 GstElementClass *gstelement_class;
115 gobject_class = (GObjectClass *) klass;
116 gstelement_class = (GstElementClass *) klass;
118 gobject_class->set_property = gst_speex_dec_set_property;
119 gobject_class->get_property = gst_speex_dec_get_property;
121 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ENH,
122 g_param_spec_boolean ("enh", "Enh", "Enable perceptual enhancement",
123 DEFAULT_ENH, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
125 gstelement_class->change_state = GST_DEBUG_FUNCPTR (speex_dec_change_state);
127 gst_element_class_add_pad_template (gstelement_class,
128 gst_static_pad_template_get (&speex_dec_src_factory));
129 gst_element_class_add_pad_template (gstelement_class,
130 gst_static_pad_template_get (&speex_dec_sink_factory));
131 gst_element_class_set_details_simple (gstelement_class, "Speex audio decoder",
132 "Codec/Decoder/Audio",
133 "decode speex streams to audio", "Wim Taymans <wim@fluendo.com>");
135 GST_DEBUG_CATEGORY_INIT (speexdec_debug, "speexdec", 0,
136 "speex decoding element");
140 gst_speex_dec_reset (GstSpeexDec * dec)
142 gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED);
145 dec->frame_duration = 0;
149 speex_bits_destroy (&dec->bits);
151 gst_buffer_replace (&dec->streamheader, NULL);
152 gst_buffer_replace (&dec->vorbiscomment, NULL);
155 speex_stereo_state_destroy (dec->stereo);
160 speex_decoder_destroy (dec->state);
166 gst_speex_dec_init (GstSpeexDec * dec)
169 gst_pad_new_from_static_template (&speex_dec_sink_factory, "sink");
170 gst_pad_set_chain_function (dec->sinkpad,
171 GST_DEBUG_FUNCPTR (speex_dec_chain));
172 gst_pad_set_event_function (dec->sinkpad,
173 GST_DEBUG_FUNCPTR (speex_dec_sink_event));
174 gst_pad_set_query_type_function (dec->sinkpad,
175 GST_DEBUG_FUNCPTR (speex_get_sink_query_types));
176 gst_pad_set_query_function (dec->sinkpad,
177 GST_DEBUG_FUNCPTR (speex_dec_sink_query));
178 gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
181 gst_pad_new_from_static_template (&speex_dec_src_factory, "src");
182 gst_pad_use_fixed_caps (dec->srcpad);
183 gst_pad_set_event_function (dec->srcpad,
184 GST_DEBUG_FUNCPTR (speex_dec_src_event));
185 gst_pad_set_query_type_function (dec->srcpad,
186 GST_DEBUG_FUNCPTR (speex_get_src_query_types));
187 gst_pad_set_query_function (dec->srcpad,
188 GST_DEBUG_FUNCPTR (speex_dec_src_query));
189 gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
191 dec->enh = DEFAULT_ENH;
193 gst_speex_dec_reset (dec);
197 speex_dec_sink_setcaps (GstPad * pad, GstCaps * caps)
199 GstSpeexDec *dec = GST_SPEEX_DEC (gst_pad_get_parent (pad));
202 const GValue *streamheader;
204 s = gst_caps_get_structure (caps, 0);
205 if ((streamheader = gst_structure_get_value (s, "streamheader")) &&
206 G_VALUE_HOLDS (streamheader, GST_TYPE_ARRAY) &&
207 gst_value_array_get_size (streamheader) >= 2) {
208 const GValue *header, *vorbiscomment;
210 GstFlowReturn res = GST_FLOW_OK;
212 header = gst_value_array_get_value (streamheader, 0);
213 if (header && G_VALUE_HOLDS (header, GST_TYPE_BUFFER)) {
214 buf = gst_value_get_buffer (header);
215 res = speex_dec_chain_parse_header (dec, buf);
216 if (res != GST_FLOW_OK)
218 gst_buffer_replace (&dec->streamheader, buf);
221 vorbiscomment = gst_value_array_get_value (streamheader, 1);
222 if (vorbiscomment && G_VALUE_HOLDS (vorbiscomment, GST_TYPE_BUFFER)) {
223 buf = gst_value_get_buffer (vorbiscomment);
224 res = speex_dec_chain_parse_comments (dec, buf);
225 if (res != GST_FLOW_OK)
227 gst_buffer_replace (&dec->vorbiscomment, buf);
232 gst_object_unref (dec);
237 speex_dec_convert (GstPad * pad,
238 GstFormat src_format, gint64 src_value,
239 GstFormat * dest_format, gint64 * dest_value)
245 dec = GST_SPEEX_DEC (gst_pad_get_parent (pad));
247 if (src_format == *dest_format) {
248 *dest_value = src_value;
253 if (dec->packetno < 1) {
258 if (pad == dec->sinkpad &&
259 (src_format == GST_FORMAT_BYTES || *dest_format == GST_FORMAT_BYTES)) {
264 switch (src_format) {
265 case GST_FORMAT_TIME:
266 switch (*dest_format) {
267 case GST_FORMAT_BYTES:
268 scale = 2 * dec->header->nb_channels;
269 case GST_FORMAT_DEFAULT:
271 gst_util_uint64_scale_int (scale * src_value, dec->header->rate,
279 case GST_FORMAT_DEFAULT:
280 switch (*dest_format) {
281 case GST_FORMAT_BYTES:
282 *dest_value = src_value * 2 * dec->header->nb_channels;
284 case GST_FORMAT_TIME:
286 gst_util_uint64_scale_int (src_value, GST_SECOND,
294 case GST_FORMAT_BYTES:
295 switch (*dest_format) {
296 case GST_FORMAT_DEFAULT:
297 *dest_value = src_value / (2 * dec->header->nb_channels);
299 case GST_FORMAT_TIME:
300 *dest_value = gst_util_uint64_scale_int (src_value, GST_SECOND,
301 dec->header->rate * 2 * dec->header->nb_channels);
314 gst_object_unref (dec);
318 static const GstQueryType *
319 speex_get_sink_query_types (GstPad * pad)
321 static const GstQueryType speex_dec_sink_query_types[] = {
326 return speex_dec_sink_query_types;
330 speex_dec_sink_query (GstPad * pad, GstQuery * query)
335 dec = GST_SPEEX_DEC (gst_pad_get_parent (pad));
337 switch (GST_QUERY_TYPE (query)) {
338 case GST_QUERY_CONVERT:
340 GstFormat src_fmt, dest_fmt;
341 gint64 src_val, dest_val;
343 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
344 res = speex_dec_convert (pad, src_fmt, src_val, &dest_fmt, &dest_val);
346 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
351 res = gst_pad_query_default (pad, query);
355 gst_object_unref (dec);
359 static const GstQueryType *
360 speex_get_src_query_types (GstPad * pad)
362 static const GstQueryType speex_dec_src_query_types[] = {
368 return speex_dec_src_query_types;
372 speex_dec_src_query (GstPad * pad, GstQuery * query)
375 gboolean res = FALSE;
377 dec = GST_SPEEX_DEC (gst_pad_get_parent (pad));
379 /* FIXME: why not just pass position/duration queries upstream to demuxer? */
380 switch (GST_QUERY_TYPE (query)) {
381 case GST_QUERY_POSITION:{
386 gst_query_parse_position (query, &format, NULL);
388 GST_PAD_STREAM_LOCK (dec->sinkpad);
389 segment = dec->segment;
390 GST_PAD_STREAM_UNLOCK (dec->sinkpad);
392 if (segment.format != GST_FORMAT_TIME) {
393 GST_DEBUG_OBJECT (dec, "segment not initialised yet");
397 if ((res = speex_dec_convert (dec->srcpad, GST_FORMAT_TIME,
398 segment.position, &format, &cur))) {
399 gst_query_set_position (query, format, cur);
403 case GST_QUERY_DURATION:{
407 /* get duration from demuxer */
408 if (!gst_pad_query_peer_duration (dec->sinkpad, GST_FORMAT_TIME, &dur))
411 gst_query_parse_duration (query, &format, NULL);
413 /* and convert it into the requested format */
414 if ((res = speex_dec_convert (dec->srcpad, GST_FORMAT_TIME,
415 dur, &format, &dur))) {
416 gst_query_set_duration (query, format, dur);
421 res = gst_pad_query_default (pad, query);
425 gst_object_unref (dec);
430 speex_dec_src_event (GstPad * pad, GstEvent * event)
432 gboolean res = FALSE;
433 GstSpeexDec *dec = GST_SPEEX_DEC (gst_pad_get_parent (pad));
435 GST_LOG_OBJECT (dec, "handling %s event", GST_EVENT_TYPE_NAME (event));
437 switch (GST_EVENT_TYPE (event)) {
438 case GST_EVENT_SEEK:{
439 GstFormat format, tformat;
443 GstSeekType cur_type, stop_type;
447 gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur,
450 /* we have to ask our peer to seek to time here as we know
451 * nothing about how to generate a granulepos from the src
452 * formats or anything.
454 * First bring the requested format to time
456 tformat = GST_FORMAT_TIME;
457 if (!(res = speex_dec_convert (pad, format, cur, &tformat, &tcur)))
459 if (!(res = speex_dec_convert (pad, format, stop, &tformat, &tstop)))
462 /* then seek with time on the peer */
463 real_seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
464 flags, cur_type, tcur, stop_type, tstop);
466 GST_LOG_OBJECT (dec, "seek to %" GST_TIME_FORMAT, GST_TIME_ARGS (tcur));
468 res = gst_pad_push_event (dec->sinkpad, real_seek);
469 gst_event_unref (event);
473 res = gst_pad_event_default (pad, event);
477 gst_object_unref (dec);
482 speex_dec_sink_event (GstPad * pad, GstEvent * event)
485 gboolean ret = FALSE;
487 dec = GST_SPEEX_DEC (gst_pad_get_parent (pad));
489 GST_LOG_OBJECT (dec, "handling %s event", GST_EVENT_TYPE_NAME (event));
491 switch (GST_EVENT_TYPE (event)) {
496 gst_event_parse_caps (event, &caps);
497 ret = speex_dec_sink_setcaps (pad, caps);
498 gst_event_unref (event);
501 case GST_EVENT_SEGMENT:{
504 gst_event_copy_segment (event, &segment);
506 if (segment.format != GST_FORMAT_TIME)
507 goto newseg_wrong_format;
509 if (segment.rate <= 0.0)
510 goto newseg_wrong_rate;
514 /* time progressed without data, see if we can fill the gap with
515 * some concealment data */
516 if (dec->segment.position < start) {
517 GstClockTime duration;
519 duration = start - dec->segment.position;
520 speex_dec_chain_parse_data (dec, NULL, dec->segment.position,
526 /* now configure the values */
527 dec->segment = segment;
529 GST_DEBUG_OBJECT (dec, "segment now: %" GST_SEGMENT_FORMAT, &segment);
530 ret = gst_pad_push_event (dec->srcpad, event);
534 ret = gst_pad_event_default (pad, event);
538 gst_object_unref (dec);
544 GST_DEBUG_OBJECT (dec, "received non TIME newsegment");
545 gst_object_unref (dec);
550 GST_DEBUG_OBJECT (dec, "negative rates not supported yet");
551 gst_object_unref (dec);
557 speex_dec_chain_parse_header (GstSpeexDec * dec, GstBuffer * buf)
564 data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
565 dec->header = speex_packet_to_header (data, size);
566 gst_buffer_unmap (buf, data, size);
571 if (dec->header->mode >= SPEEX_NB_MODES || dec->header->mode < 0)
574 dec->mode = speex_lib_get_mode (dec->header->mode);
576 /* initialize the decoder */
577 dec->state = speex_decoder_init (dec->mode);
581 speex_decoder_ctl (dec->state, SPEEX_SET_ENH, &dec->enh);
582 speex_decoder_ctl (dec->state, SPEEX_GET_FRAME_SIZE, &dec->frame_size);
584 if (dec->header->nb_channels != 1) {
585 dec->stereo = speex_stereo_state_init ();
586 dec->callback.callback_id = SPEEX_INBAND_STEREO;
587 dec->callback.func = speex_std_stereo_request_handler;
588 dec->callback.data = dec->stereo;
589 speex_decoder_ctl (dec->state, SPEEX_SET_HANDLER, &dec->callback);
592 speex_decoder_ctl (dec->state, SPEEX_SET_SAMPLING_RATE, &dec->header->rate);
594 dec->frame_duration = gst_util_uint64_scale_int (dec->frame_size,
595 GST_SECOND, dec->header->rate);
597 speex_bits_init (&dec->bits);
600 caps = gst_caps_new_simple ("audio/x-raw-int",
601 "rate", G_TYPE_INT, dec->header->rate,
602 "channels", G_TYPE_INT, dec->header->nb_channels,
603 "signed", G_TYPE_BOOLEAN, TRUE,
604 "endianness", G_TYPE_INT, G_BYTE_ORDER,
605 "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16, NULL);
607 if (!gst_pad_set_caps (dec->srcpad, caps))
610 gst_caps_unref (caps);
616 GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
617 (NULL), ("couldn't read header"));
618 return GST_FLOW_ERROR;
622 GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
624 ("Mode number %d does not (yet/any longer) exist in this version",
626 return GST_FLOW_ERROR;
630 GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
631 (NULL), ("couldn't initialize decoder"));
632 return GST_FLOW_ERROR;
636 GST_ELEMENT_ERROR (GST_ELEMENT (dec), STREAM, DECODE,
637 (NULL), ("couldn't negotiate format"));
638 gst_caps_unref (caps);
639 return GST_FLOW_NOT_NEGOTIATED;
644 speex_dec_chain_parse_comments (GstSpeexDec * dec, GstBuffer * buf)
647 gchar *ver, *encoder = NULL;
649 list = gst_tag_list_from_vorbiscomment_buffer (buf, NULL, 0, &encoder);
652 GST_WARNING_OBJECT (dec, "couldn't decode comments");
653 list = gst_tag_list_new ();
657 gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
658 GST_TAG_ENCODER, encoder, NULL);
661 gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
662 GST_TAG_AUDIO_CODEC, "Speex", NULL);
664 ver = g_strndup (dec->header->speex_version, SPEEX_HEADER_VERSION_LENGTH);
667 if (ver != NULL && *ver != '\0') {
668 gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
669 GST_TAG_ENCODER_VERSION, ver, NULL);
672 if (dec->header->bitrate > 0) {
673 gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
674 GST_TAG_BITRATE, (guint) dec->header->bitrate, NULL);
677 GST_INFO_OBJECT (dec, "tags: %" GST_PTR_FORMAT, list);
679 gst_element_found_tags_for_pad (GST_ELEMENT (dec), dec->srcpad, list);
688 speex_dec_chain_parse_data (GstSpeexDec * dec, GstBuffer * buf,
689 GstClockTime timestamp, GstClockTime duration)
691 GstFlowReturn res = GST_FLOW_OK;
697 if (!dec->frame_duration)
700 if (timestamp != -1) {
701 dec->segment.position = timestamp;
703 timestamp = dec->segment.position;
707 /* send data to the bitstream */
708 data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
709 speex_bits_read_from (&dec->bits, data, size);
710 gst_buffer_unmap (buf, data, size);
712 fpp = dec->header->frames_per_packet;
715 GST_DEBUG_OBJECT (dec, "received buffer of size %u, fpp %d, %d bits", size,
716 fpp, speex_bits_remaining (bits));
718 /* concealment data, pass NULL as the bits parameters */
719 GST_DEBUG_OBJECT (dec, "creating concealment data");
720 fpp = dec->header->frames_per_packet;
725 /* now decode each frame, catering for unknown number of them (e.g. rtp) */
726 for (i = 0; i < fpp; i++) {
731 GST_LOG_OBJECT (dec, "decoding frame %d/%d, %d bits remaining", i, fpp,
732 bits ? speex_bits_remaining (bits) : -1);
734 res = gst_pad_alloc_buffer_and_set_caps (dec->srcpad,
735 GST_BUFFER_OFFSET_NONE, dec->frame_size * dec->header->nb_channels * 2,
736 GST_PAD_CAPS (dec->srcpad), &outbuf);
738 if (res != GST_FLOW_OK) {
739 GST_DEBUG_OBJECT (dec, "buf alloc flow: %s", gst_flow_get_name (res));
743 /* FIXME, we can use a bufferpool because we have fixed size buffers. We
744 * could also use an allocator */
746 gst_buffer_new_allocate (NULL,
747 dec->frame_size * dec->header->nb_channels * 2, 0);
749 out_data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE);
750 ret = speex_decode_int (dec->state, bits, out_data);
751 gst_buffer_unmap (outbuf, out_data, size);
754 /* uh? end of stream */
755 if (fpp == 0 && speex_bits_remaining (bits) < 8) {
756 /* if we did not know how many frames to expect, then we get this
757 at the end if there are leftover bits to pad to the next byte */
759 GST_WARNING_OBJECT (dec, "Unexpected end of stream found");
761 gst_buffer_unref (outbuf);
764 } else if (ret == -2) {
765 GST_WARNING_OBJECT (dec, "Decoding error: corrupted stream?");
766 gst_buffer_unref (outbuf);
771 if (bits && speex_bits_remaining (bits) < 0) {
772 GST_WARNING_OBJECT (dec, "Decoding overflow: corrupted stream?");
773 gst_buffer_unref (outbuf);
777 if (dec->header->nb_channels == 2)
778 speex_decode_stereo_int (out_data, dec->frame_size, dec->stereo);
780 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
781 GST_BUFFER_DURATION (outbuf) = dec->frame_duration;
783 dec->segment.position += dec->frame_duration;
784 timestamp = dec->segment.position;
786 GST_LOG_OBJECT (dec, "pushing buffer with ts=%" GST_TIME_FORMAT ", dur=%"
787 GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
788 GST_TIME_ARGS (dec->frame_duration));
790 res = gst_pad_push (dec->srcpad, outbuf);
792 if (res != GST_FLOW_OK) {
793 GST_DEBUG_OBJECT (dec, "flow: %s", gst_flow_get_name (res));
803 GST_ELEMENT_ERROR (dec, CORE, NEGOTIATION, (NULL),
804 ("decoder not initialized"));
805 return GST_FLOW_NOT_NEGOTIATED;
810 memcmp_buffers (GstBuffer * buf1, GstBuffer * buf2)
816 size1 = gst_buffer_get_size (buf1);
817 size2 = gst_buffer_get_size (buf2);
822 data1 = gst_buffer_map (buf1, NULL, NULL, GST_MAP_READ);
823 res = gst_buffer_memcmp (buf2, 0, data1, size1) == 0;
824 gst_buffer_unmap (buf1, data1, size1);
830 speex_dec_chain (GstPad * pad, GstBuffer * buf)
835 dec = GST_SPEEX_DEC (gst_pad_get_parent (pad));
837 /* If we have the streamheader and vorbiscomment from the caps already
838 * ignore them here */
839 if (dec->streamheader && dec->vorbiscomment) {
840 if (memcmp_buffers (dec->streamheader, buf)) {
842 } else if (memcmp_buffers (dec->vorbiscomment, buf)) {
846 speex_dec_chain_parse_data (dec, buf, GST_BUFFER_TIMESTAMP (buf),
847 GST_BUFFER_DURATION (buf));
850 /* Otherwise fall back to packet counting and assume that the
851 * first two packets are the headers. */
852 switch (dec->packetno) {
854 res = speex_dec_chain_parse_header (dec, buf);
857 res = speex_dec_chain_parse_comments (dec, buf);
861 speex_dec_chain_parse_data (dec, buf, GST_BUFFER_TIMESTAMP (buf),
862 GST_BUFFER_DURATION (buf));
869 gst_buffer_unref (buf);
870 gst_object_unref (dec);
876 gst_speex_dec_get_property (GObject * object, guint prop_id,
877 GValue * value, GParamSpec * pspec)
879 GstSpeexDec *speexdec;
881 speexdec = GST_SPEEX_DEC (object);
885 g_value_set_boolean (value, speexdec->enh);
888 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
894 gst_speex_dec_set_property (GObject * object, guint prop_id,
895 const GValue * value, GParamSpec * pspec)
897 GstSpeexDec *speexdec;
899 speexdec = GST_SPEEX_DEC (object);
903 speexdec->enh = g_value_get_boolean (value);
906 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
912 static GstStateChangeReturn
913 speex_dec_change_state (GstElement * element, GstStateChange transition)
915 GstStateChangeReturn ret;
916 GstSpeexDec *dec = GST_SPEEX_DEC (element);
918 switch (transition) {
919 case GST_STATE_CHANGE_NULL_TO_READY:
920 case GST_STATE_CHANGE_READY_TO_PAUSED:
921 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
926 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
927 if (ret != GST_STATE_CHANGE_SUCCESS)
930 switch (transition) {
931 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
933 case GST_STATE_CHANGE_PAUSED_TO_READY:
934 gst_speex_dec_reset (dec);
936 case GST_STATE_CHANGE_READY_TO_NULL: