update for _get_caps() -> _query_caps()
[platform/upstream/gstreamer.git] / ext / vorbis / gstvorbisparse.c
1 /* GStreamer
2  * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
3  * Copyright (C) 2006 Andy Wingo <wingo@pobox.com>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 /**
22  * SECTION:element-vorbisparse
23  * @see_also: vorbisdec, oggdemux, theoraparse
24  *
25  * The vorbisparse element will parse the header packets of the Vorbis
26  * stream and put them as the streamheader in the caps. This is used in the
27  * multifdsink case where you want to stream live vorbis streams to multiple
28  * clients, each client has to receive the streamheaders first before they can
29  * consume the vorbis packets.
30  *
31  * This element also makes sure that the buffers that it pushes out are properly
32  * timestamped and that their offset and offset_end are set. The buffers that
33  * vorbisparse outputs have all of the metadata that oggmux expects to receive,
34  * which allows you to (for example) remux an ogg/vorbis file.
35  *
36  * <refsect2>
37  * <title>Example pipelines</title>
38  * |[
39  * gst-launch -v filesrc location=sine.ogg ! oggdemux ! vorbisparse ! fakesink
40  * ]| This pipeline shows that the streamheader is set in the caps, and that each
41  * buffer has the timestamp, duration, offset, and offset_end set.
42  * |[
43  * gst-launch filesrc location=sine.ogg ! oggdemux ! vorbisparse \
44  *            ! oggmux ! filesink location=sine-remuxed.ogg
45  * ]| This pipeline shows remuxing. sine-remuxed.ogg might not be exactly the same
46  * as sine.ogg, but they should produce exactly the same decoded data.
47  * </refsect2>
48  *
49  * Last reviewed on 2006-04-01 (0.10.4.1)
50  */
51
52 #ifdef HAVE_CONFIG_H
53 #  include "config.h"
54 #endif
55
56 #include "gstvorbisparse.h"
57
58 GST_DEBUG_CATEGORY_EXTERN (vorbisparse_debug);
59 #define GST_CAT_DEFAULT vorbisparse_debug
60
61 static GstStaticPadTemplate vorbis_parse_sink_factory =
62 GST_STATIC_PAD_TEMPLATE ("sink",
63     GST_PAD_SINK,
64     GST_PAD_ALWAYS,
65     GST_STATIC_CAPS ("audio/x-vorbis")
66     );
67
68 static GstStaticPadTemplate vorbis_parse_src_factory =
69 GST_STATIC_PAD_TEMPLATE ("src",
70     GST_PAD_SRC,
71     GST_PAD_ALWAYS,
72     GST_STATIC_CAPS ("audio/x-vorbis")
73     );
74
75 #define gst_vorbis_parse_parent_class parent_class
76 G_DEFINE_TYPE (GstVorbisParse, gst_vorbis_parse, GST_TYPE_ELEMENT);
77
78 static GstFlowReturn vorbis_parse_chain (GstPad * pad, GstBuffer * buffer);
79 static GstStateChangeReturn vorbis_parse_change_state (GstElement * element,
80     GstStateChange transition);
81 static gboolean vorbis_parse_sink_event (GstPad * pad, GstEvent * event);
82 static gboolean vorbis_parse_src_query (GstPad * pad, GstQuery * query);
83 static gboolean vorbis_parse_convert (GstPad * pad,
84     GstFormat src_format, gint64 src_value,
85     GstFormat * dest_format, gint64 * dest_value);
86 static GstFlowReturn vorbis_parse_parse_packet (GstVorbisParse * parse,
87     GstBuffer * buf);
88
89 static void
90 gst_vorbis_parse_class_init (GstVorbisParseClass * klass)
91 {
92   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
93
94   gstelement_class->change_state = vorbis_parse_change_state;
95
96   gst_element_class_add_pad_template (gstelement_class,
97       gst_static_pad_template_get (&vorbis_parse_src_factory));
98   gst_element_class_add_pad_template (gstelement_class,
99       gst_static_pad_template_get (&vorbis_parse_sink_factory));
100   gst_element_class_set_details_simple (gstelement_class,
101       "VorbisParse", "Codec/Parser/Audio",
102       "parse raw vorbis streams",
103       "Thomas Vander Stichele <thomas at apestaart dot org>");
104
105   klass->parse_packet = GST_DEBUG_FUNCPTR (vorbis_parse_parse_packet);
106 }
107
108 static void
109 gst_vorbis_parse_init (GstVorbisParse * parse)
110 {
111   parse->sinkpad =
112       gst_pad_new_from_static_template (&vorbis_parse_sink_factory, "sink");
113   gst_pad_set_chain_function (parse->sinkpad,
114       GST_DEBUG_FUNCPTR (vorbis_parse_chain));
115   gst_pad_set_event_function (parse->sinkpad,
116       GST_DEBUG_FUNCPTR (vorbis_parse_sink_event));
117   gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
118
119   parse->srcpad =
120       gst_pad_new_from_static_template (&vorbis_parse_src_factory, "src");
121   gst_pad_set_query_function (parse->srcpad,
122       GST_DEBUG_FUNCPTR (vorbis_parse_src_query));
123   gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
124 }
125
126 static void
127 vorbis_parse_set_header_on_caps (GstVorbisParse * parse, GstCaps * caps)
128 {
129   GstBuffer *buf1, *buf2, *buf3;
130   GstStructure *structure;
131   GValue array = { 0 };
132   GValue value = { 0 };
133
134   g_assert (parse);
135   g_assert (parse->streamheader);
136   g_assert (parse->streamheader->next);
137   g_assert (parse->streamheader->next->next);
138   buf1 = parse->streamheader->data;
139   g_assert (buf1);
140   buf2 = parse->streamheader->next->data;
141   g_assert (buf2);
142   buf3 = parse->streamheader->next->next->data;
143   g_assert (buf3);
144
145   structure = gst_caps_get_structure (caps, 0);
146
147   /* mark buffers */
148   GST_BUFFER_FLAG_SET (buf1, GST_BUFFER_FLAG_IN_CAPS);
149   GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_FLAG_IN_CAPS);
150   GST_BUFFER_FLAG_SET (buf3, GST_BUFFER_FLAG_IN_CAPS);
151
152   /* put buffers in a fixed list */
153   g_value_init (&array, GST_TYPE_ARRAY);
154   g_value_init (&value, GST_TYPE_BUFFER);
155   gst_value_set_buffer (&value, buf1);
156   gst_value_array_append_value (&array, &value);
157   g_value_unset (&value);
158   g_value_init (&value, GST_TYPE_BUFFER);
159   gst_value_set_buffer (&value, buf2);
160   gst_value_array_append_value (&array, &value);
161   g_value_unset (&value);
162   g_value_init (&value, GST_TYPE_BUFFER);
163   gst_value_set_buffer (&value, buf3);
164   gst_value_array_append_value (&array, &value);
165   gst_structure_set_value (structure, "streamheader", &array);
166   g_value_unset (&value);
167   g_value_unset (&array);
168 }
169
170 static void
171 vorbis_parse_drain_event_queue (GstVorbisParse * parse)
172 {
173   while (parse->event_queue->length) {
174     GstEvent *event;
175
176     event = GST_EVENT_CAST (g_queue_pop_head (parse->event_queue));
177     gst_pad_event_default (parse->sinkpad, event);
178   }
179 }
180
181 static void
182 vorbis_parse_push_headers (GstVorbisParse * parse)
183 {
184   /* mark and put on caps */
185   GstCaps *caps;
186   GstBuffer *outbuf, *outbuf1, *outbuf2, *outbuf3;
187   ogg_packet packet;
188   gsize size;
189
190   /* get the headers into the caps, passing them to vorbis as we go */
191   caps = gst_caps_make_writable (gst_pad_query_caps (parse->srcpad, NULL));
192   vorbis_parse_set_header_on_caps (parse, caps);
193   GST_DEBUG_OBJECT (parse, "here are the caps: %" GST_PTR_FORMAT, caps);
194   gst_pad_set_caps (parse->srcpad, caps);
195   gst_caps_unref (caps);
196
197   outbuf = GST_BUFFER_CAST (parse->streamheader->data);
198   packet.packet = gst_buffer_map (outbuf, &size, NULL, GST_MAP_READ);
199   packet.bytes = size;
200   packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
201   packet.packetno = 1;
202   packet.e_o_s = 0;
203   packet.b_o_s = 1;
204   vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
205   gst_buffer_unmap (outbuf, packet.packet, size);
206   parse->sample_rate = parse->vi.rate;
207   outbuf1 = outbuf;
208
209   outbuf = GST_BUFFER_CAST (parse->streamheader->next->data);
210   packet.packet = gst_buffer_map (outbuf, &size, NULL, GST_MAP_READ);
211   packet.bytes = size;
212   packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
213   packet.packetno = 2;
214   packet.e_o_s = 0;
215   packet.b_o_s = 0;
216   vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
217   gst_buffer_unmap (outbuf, packet.packet, size);
218   outbuf2 = outbuf;
219
220   outbuf = GST_BUFFER_CAST (parse->streamheader->next->next->data);
221   packet.packet = gst_buffer_map (outbuf, &size, NULL, GST_MAP_READ);
222   packet.bytes = size;
223   packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
224   packet.packetno = 3;
225   packet.e_o_s = 0;
226   packet.b_o_s = 0;
227   vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
228   gst_buffer_unmap (outbuf, packet.packet, size);
229   outbuf3 = outbuf;
230
231   /* first process queued events */
232   vorbis_parse_drain_event_queue (parse);
233
234   /* push out buffers, ignoring return value... */
235   gst_pad_push (parse->srcpad, outbuf1);
236   gst_pad_push (parse->srcpad, outbuf2);
237   gst_pad_push (parse->srcpad, outbuf3);
238
239   g_list_free (parse->streamheader);
240   parse->streamheader = NULL;
241 }
242
243 static void
244 vorbis_parse_clear_queue (GstVorbisParse * parse)
245 {
246   while (parse->buffer_queue->length) {
247     GstBuffer *buf;
248
249     buf = GST_BUFFER_CAST (g_queue_pop_head (parse->buffer_queue));
250     gst_buffer_unref (buf);
251   }
252   while (parse->event_queue->length) {
253     GstEvent *event;
254
255     event = GST_EVENT_CAST (g_queue_pop_head (parse->event_queue));
256     gst_event_unref (event);
257   }
258 }
259
260 static GstFlowReturn
261 vorbis_parse_push_buffer (GstVorbisParse * parse, GstBuffer * buf,
262     gint64 granulepos)
263 {
264   guint64 samples;
265
266   /* our hack as noted below */
267   samples = GST_BUFFER_OFFSET (buf);
268
269   GST_BUFFER_OFFSET_END (buf) = granulepos;
270   GST_BUFFER_DURATION (buf) = samples * GST_SECOND / parse->sample_rate;
271   GST_BUFFER_OFFSET (buf) = granulepos * GST_SECOND / parse->sample_rate;
272   GST_BUFFER_TIMESTAMP (buf) =
273       GST_BUFFER_OFFSET (buf) - GST_BUFFER_DURATION (buf);
274
275   return gst_pad_push (parse->srcpad, buf);
276 }
277
278 static GstFlowReturn
279 vorbis_parse_drain_queue_prematurely (GstVorbisParse * parse)
280 {
281   GstFlowReturn ret = GST_FLOW_OK;
282   gint64 granulepos = MAX (parse->prev_granulepos, 0);
283
284   /* got an EOS event, make sure to push out any buffers that were in the queue
285    * -- won't normally be the case, but this catches the
286    * didn't-get-a-granulepos-on-the-last-packet case. Assuming a continuous
287    * stream. */
288
289   /* if we got EOS before any buffers came, go ahead and push the other events
290    * first */
291   vorbis_parse_drain_event_queue (parse);
292
293   while (!g_queue_is_empty (parse->buffer_queue)) {
294     GstBuffer *buf;
295
296     buf = GST_BUFFER_CAST (g_queue_pop_head (parse->buffer_queue));
297
298     granulepos += GST_BUFFER_OFFSET (buf);
299     ret = vorbis_parse_push_buffer (parse, buf, granulepos);
300
301     if (ret != GST_FLOW_OK)
302       goto done;
303   }
304
305   parse->prev_granulepos = granulepos;
306
307 done:
308   return ret;
309 }
310
311 static GstFlowReturn
312 vorbis_parse_drain_queue (GstVorbisParse * parse, gint64 granulepos)
313 {
314   GstFlowReturn ret = GST_FLOW_OK;
315   GList *walk;
316   gint64 cur = granulepos;
317   gint64 gp;
318
319   for (walk = parse->buffer_queue->head; walk; walk = walk->next)
320     cur -= GST_BUFFER_OFFSET (walk->data);
321
322   if (parse->prev_granulepos != -1)
323     cur = MAX (cur, parse->prev_granulepos);
324
325   while (!g_queue_is_empty (parse->buffer_queue)) {
326     GstBuffer *buf;
327
328     buf = GST_BUFFER_CAST (g_queue_pop_head (parse->buffer_queue));
329
330     cur += GST_BUFFER_OFFSET (buf);
331     gp = CLAMP (cur, 0, granulepos);
332
333     ret = vorbis_parse_push_buffer (parse, buf, gp);
334
335     if (ret != GST_FLOW_OK)
336       goto done;
337   }
338
339   parse->prev_granulepos = granulepos;
340
341 done:
342   return ret;
343 }
344
345 static GstFlowReturn
346 vorbis_parse_queue_buffer (GstVorbisParse * parse, GstBuffer * buf)
347 {
348   GstFlowReturn ret = GST_FLOW_OK;
349   long blocksize;
350   ogg_packet packet;
351   gsize size;
352
353   buf = gst_buffer_make_writable (buf);
354
355   packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
356   packet.bytes = size;
357   packet.granulepos = GST_BUFFER_OFFSET_END (buf);
358   packet.packetno = parse->packetno + parse->buffer_queue->length;
359   packet.e_o_s = 0;
360
361   blocksize = vorbis_packet_blocksize (&parse->vi, &packet);
362   gst_buffer_unmap (buf, packet.packet, size);
363
364   /* temporarily store the sample count in OFFSET -- we overwrite this later */
365
366   if (parse->prev_blocksize < 0)
367     GST_BUFFER_OFFSET (buf) = 0;
368   else
369     GST_BUFFER_OFFSET (buf) = (blocksize + parse->prev_blocksize) / 4;
370
371   parse->prev_blocksize = blocksize;
372
373   g_queue_push_tail (parse->buffer_queue, buf);
374
375   if (GST_BUFFER_OFFSET_END_IS_VALID (buf))
376     ret = vorbis_parse_drain_queue (parse, GST_BUFFER_OFFSET_END (buf));
377
378   return ret;
379 }
380
381 static GstFlowReturn
382 vorbis_parse_parse_packet (GstVorbisParse * parse, GstBuffer * buf)
383 {
384   GstFlowReturn ret;
385   guint8 *data;
386   gsize size;
387   gboolean have_header;
388
389   parse->packetno++;
390
391   have_header = FALSE;
392   data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
393   if (size >= 1) {
394     if (data[0] >= 0x01 && data[0] <= 0x05)
395       have_header = TRUE;
396   }
397   gst_buffer_unmap (buf, data, size);
398
399   if (have_header) {
400     if (!parse->streamheader_sent) {
401       /* we need to collect the headers still */
402       /* so put it on the streamheader list and return */
403       parse->streamheader = g_list_append (parse->streamheader, buf);
404     }
405     ret = GST_FLOW_OK;
406   } else {
407     /* data packet, push the headers we collected before */
408     if (!parse->streamheader_sent) {
409       vorbis_parse_push_headers (parse);
410       parse->streamheader_sent = TRUE;
411     }
412     ret = vorbis_parse_queue_buffer (parse, buf);
413   }
414
415   return ret;
416 }
417
418 static GstFlowReturn
419 vorbis_parse_chain (GstPad * pad, GstBuffer * buffer)
420 {
421   GstVorbisParseClass *klass;
422   GstVorbisParse *parse;
423
424   parse = GST_VORBIS_PARSE (GST_PAD_PARENT (pad));
425   klass = GST_VORBIS_PARSE_CLASS (G_OBJECT_GET_CLASS (parse));
426
427   g_assert (klass->parse_packet != NULL);
428
429   return klass->parse_packet (parse, buffer);
430 }
431
432 static gboolean
433 vorbis_parse_queue_event (GstVorbisParse * parse, GstEvent * event)
434 {
435   GstFlowReturn ret = TRUE;
436
437   g_queue_push_tail (parse->event_queue, event);
438
439   return ret;
440 }
441
442 static gboolean
443 vorbis_parse_sink_event (GstPad * pad, GstEvent * event)
444 {
445   gboolean ret;
446   GstVorbisParse *parse;
447
448   parse = GST_VORBIS_PARSE (gst_pad_get_parent (pad));
449
450   switch (GST_EVENT_TYPE (event)) {
451     case GST_EVENT_FLUSH_START:
452       vorbis_parse_clear_queue (parse);
453       parse->prev_granulepos = -1;
454       parse->prev_blocksize = -1;
455       ret = gst_pad_event_default (pad, event);
456       break;
457     case GST_EVENT_EOS:
458       vorbis_parse_drain_queue_prematurely (parse);
459       ret = gst_pad_event_default (pad, event);
460       break;
461     default:
462       if (!parse->streamheader_sent && GST_EVENT_IS_SERIALIZED (event))
463         ret = vorbis_parse_queue_event (parse, event);
464       else
465         ret = gst_pad_event_default (pad, event);
466       break;
467   }
468
469   gst_object_unref (parse);
470
471   return ret;
472 }
473
474 static gboolean
475 vorbis_parse_convert (GstPad * pad,
476     GstFormat src_format, gint64 src_value,
477     GstFormat * dest_format, gint64 * dest_value)
478 {
479   gboolean res = TRUE;
480   GstVorbisParse *parse;
481   guint64 scale = 1;
482
483   parse = GST_VORBIS_PARSE (GST_PAD_PARENT (pad));
484
485   /* fixme: assumes atomic access to lots of instance variables modified from
486    * the streaming thread, including 64-bit variables */
487
488   if (parse->packetno < 4)
489     return FALSE;
490
491   if (src_format == *dest_format) {
492     *dest_value = src_value;
493     return TRUE;
494   }
495
496   if (parse->sinkpad == pad &&
497       (src_format == GST_FORMAT_BYTES || *dest_format == GST_FORMAT_BYTES))
498     return FALSE;
499
500   switch (src_format) {
501     case GST_FORMAT_TIME:
502       switch (*dest_format) {
503         case GST_FORMAT_BYTES:
504           scale = sizeof (float) * parse->vi.channels;
505         case GST_FORMAT_DEFAULT:
506           *dest_value =
507               scale * gst_util_uint64_scale_int (src_value, parse->vi.rate,
508               GST_SECOND);
509           break;
510         default:
511           res = FALSE;
512       }
513       break;
514     case GST_FORMAT_DEFAULT:
515       switch (*dest_format) {
516         case GST_FORMAT_BYTES:
517           *dest_value = src_value * sizeof (float) * parse->vi.channels;
518           break;
519         case GST_FORMAT_TIME:
520           *dest_value =
521               gst_util_uint64_scale_int (src_value, GST_SECOND, parse->vi.rate);
522           break;
523         default:
524           res = FALSE;
525       }
526       break;
527     case GST_FORMAT_BYTES:
528       switch (*dest_format) {
529         case GST_FORMAT_DEFAULT:
530           *dest_value = src_value / (sizeof (float) * parse->vi.channels);
531           break;
532         case GST_FORMAT_TIME:
533           *dest_value = gst_util_uint64_scale_int (src_value, GST_SECOND,
534               parse->vi.rate * sizeof (float) * parse->vi.channels);
535           break;
536         default:
537           res = FALSE;
538       }
539       break;
540     default:
541       res = FALSE;
542   }
543
544   return res;
545 }
546
547 static gboolean
548 vorbis_parse_src_query (GstPad * pad, GstQuery * query)
549 {
550   gint64 granulepos;
551   GstVorbisParse *parse;
552   gboolean res = FALSE;
553
554   parse = GST_VORBIS_PARSE (GST_PAD_PARENT (pad));
555
556   switch (GST_QUERY_TYPE (query)) {
557     case GST_QUERY_POSITION:
558     {
559       GstFormat format;
560       gint64 value;
561
562       granulepos = parse->prev_granulepos;
563
564       gst_query_parse_position (query, &format, NULL);
565
566       /* and convert to the final format */
567       if (!(res =
568               vorbis_parse_convert (pad, GST_FORMAT_DEFAULT, granulepos,
569                   &format, &value)))
570         goto error;
571
572       /* fixme: support segments
573          value = (value - parse->segment_start) + parse->segment_time;
574        */
575
576       gst_query_set_position (query, format, value);
577
578       GST_LOG_OBJECT (parse, "query %p: peer returned granulepos: %"
579           G_GUINT64_FORMAT " - we return %" G_GUINT64_FORMAT " (format %u)",
580           query, granulepos, value, format);
581
582       break;
583     }
584     case GST_QUERY_DURATION:
585     {
586       /* fixme: not threadsafe */
587       /* query peer for total length */
588       if (!gst_pad_is_linked (parse->sinkpad)) {
589         GST_WARNING_OBJECT (parse, "sink pad %" GST_PTR_FORMAT " is not linked",
590             parse->sinkpad);
591         goto error;
592       }
593       if (!(res = gst_pad_query (GST_PAD_PEER (parse->sinkpad), query)))
594         goto error;
595       break;
596     }
597     case GST_QUERY_CONVERT:
598     {
599       GstFormat src_fmt, dest_fmt;
600       gint64 src_val, dest_val;
601
602       gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
603       if (!(res =
604               vorbis_parse_convert (pad, src_fmt, src_val, &dest_fmt,
605                   &dest_val)))
606         goto error;
607       gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
608       break;
609     }
610     default:
611       res = gst_pad_query_default (pad, query);
612       break;
613   }
614   return res;
615
616 error:
617   {
618     GST_WARNING_OBJECT (parse, "error handling query");
619     return res;
620   }
621 }
622
623 static GstStateChangeReturn
624 vorbis_parse_change_state (GstElement * element, GstStateChange transition)
625 {
626   GstVorbisParse *parse = GST_VORBIS_PARSE (element);
627   GstStateChangeReturn ret;
628
629   switch (transition) {
630     case GST_STATE_CHANGE_READY_TO_PAUSED:
631       vorbis_info_init (&parse->vi);
632       vorbis_comment_init (&parse->vc);
633       parse->prev_granulepos = -1;
634       parse->prev_blocksize = -1;
635       parse->packetno = 0;
636       parse->streamheader_sent = FALSE;
637       parse->buffer_queue = g_queue_new ();
638       parse->event_queue = g_queue_new ();
639       break;
640     default:
641       break;
642   }
643
644   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
645
646   switch (transition) {
647     case GST_STATE_CHANGE_PAUSED_TO_READY:
648       vorbis_info_clear (&parse->vi);
649       vorbis_comment_clear (&parse->vc);
650       vorbis_parse_clear_queue (parse);
651       g_queue_free (parse->buffer_queue);
652       parse->buffer_queue = NULL;
653       g_queue_free (parse->event_queue);
654       parse->event_queue = NULL;
655       break;
656     default:
657       break;
658   }
659
660   return ret;
661 }