2 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
3 * Copyright (C) 2006 Andy Wingo <wingo@pobox.com>
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-theoraparse
23 * @see_also: theoradec, oggdemux, vorbisparse
25 * The theoraparse element will parse the header packets of the Theora
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 theora streams to multiple
28 * clients, each client has to receive the streamheaders first before they can
29 * consume the theora packets.
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 * theoraparse outputs have all of the metadata that oggmux expects to receive,
34 * which allows you to (for example) remux an ogg/theora file.
36 * In addition, this element allows you to fix badly synchronized streams. You
37 * pass in an array of (granule time, buffer time) synchronization points via
38 * the synchronization-points GValueArray property, and this element will adjust
39 * the granulepos values that it outputs. The adjustment will be made by
40 * offsetting all buffers that it outputs by a specified amount, and updating
41 * that offset from the value array whenever a keyframe is processed.
44 * <title>Example pipelines</title>
46 * gst-launch -v filesrc location=video.ogg ! oggdemux ! theoraparse ! fakesink
47 * ]| This pipeline shows that the streamheader is set in the caps, and that each
48 * buffer has the timestamp, duration, offset, and offset_end set.
50 * gst-launch filesrc location=video.ogg ! oggdemux ! theoraparse \
51 * ! oggmux ! filesink location=video-remuxed.ogg
52 * ]| This pipeline shows remuxing. video-remuxed.ogg might not be exactly the same
53 * as video.ogg, but they should produce exactly the same decoded data.
56 * Last reviewed on 2008-05-28 (0.10.20)
63 #include "gsttheoraparse.h"
65 #define GST_CAT_DEFAULT theoraparse_debug
66 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
68 static GstStaticPadTemplate theora_parse_sink_factory =
69 GST_STATIC_PAD_TEMPLATE ("sink",
72 GST_STATIC_CAPS ("video/x-theora")
75 static GstStaticPadTemplate theora_parse_src_factory =
76 GST_STATIC_PAD_TEMPLATE ("src",
79 GST_STATIC_CAPS ("video/x-theora")
85 PROP_SYNCHRONIZATION_POINTS
88 #define gst_theora_parse_parent_class parent_class
89 G_DEFINE_TYPE (GstTheoraParse, gst_theora_parse, GST_TYPE_ELEMENT);
91 static void theora_parse_dispose (GObject * object);
92 static void theora_parse_get_property (GObject * object, guint prop_id,
93 GValue * value, GParamSpec * pspec);
94 static void theora_parse_set_property (GObject * object, guint prop_id,
95 const GValue * value, GParamSpec * pspec);
97 static GstFlowReturn theora_parse_chain (GstPad * pad, GstBuffer * buffer);
98 static GstStateChangeReturn theora_parse_change_state (GstElement * element,
99 GstStateChange transition);
100 static gboolean theora_parse_sink_event (GstPad * pad, GstEvent * event);
101 static gboolean theora_parse_src_query (GstPad * pad, GstQuery * query);
104 gst_theora_parse_class_init (GstTheoraParseClass * klass)
106 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
107 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
109 gobject_class->dispose = theora_parse_dispose;
110 gobject_class->get_property = theora_parse_get_property;
111 gobject_class->set_property = theora_parse_set_property;
114 * GstTheoraParse:sychronization-points
116 * An array of (granuletime, buffertime) pairs
120 g_object_class_install_property (gobject_class, PROP_SYNCHRONIZATION_POINTS,
121 g_param_spec_value_array ("synchronization-points",
122 "Synchronization points",
123 "An array of (granuletime, buffertime) pairs",
124 g_param_spec_uint64 ("time", "Time",
125 "Time (either granuletime or buffertime)", 0, G_MAXUINT64, 0,
126 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS),
127 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
130 gst_element_class_add_pad_template (gstelement_class,
131 gst_static_pad_template_get (&theora_parse_src_factory));
132 gst_element_class_add_pad_template (gstelement_class,
133 gst_static_pad_template_get (&theora_parse_sink_factory));
134 gst_element_class_set_details_simple (gstelement_class,
135 "Theora video parser", "Codec/Parser/Video",
136 "parse raw theora streams", "Andy Wingo <wingo@pobox.com>");
138 gstelement_class->change_state = theora_parse_change_state;
140 GST_DEBUG_CATEGORY_INIT (theoraparse_debug, "theoraparse", 0,
145 gst_theora_parse_init (GstTheoraParse * parse)
148 gst_pad_new_from_static_template (&theora_parse_sink_factory, "sink");
149 gst_pad_set_chain_function (parse->sinkpad, theora_parse_chain);
150 gst_pad_set_event_function (parse->sinkpad, theora_parse_sink_event);
151 gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
154 gst_pad_new_from_static_template (&theora_parse_src_factory, "src");
155 gst_pad_set_query_function (parse->srcpad, theora_parse_src_query);
156 gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
160 theora_parse_dispose (GObject * object)
162 GstTheoraParse *parse = GST_THEORA_PARSE (object);
164 g_free (parse->times);
167 G_OBJECT_CLASS (parent_class)->dispose (object);
171 theora_parse_set_property (GObject * object, guint prop_id,
172 const GValue * value, GParamSpec * pspec)
174 GstTheoraParse *parse = GST_THEORA_PARSE (object);
177 case PROP_SYNCHRONIZATION_POINTS:
182 array = g_value_get_boxed (value);
185 if (array->n_values % 2)
188 g_free (parse->times);
189 parse->times = g_new (GstClockTime, array->n_values);
190 parse->npairs = array->n_values / 2;
191 for (i = 0; i < array->n_values; i++)
192 parse->times[i] = g_value_get_uint64 (&array->values[i]);
194 g_free (parse->times);
200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
208 g_critical ("expected an even number of time values for "
209 "synchronization-points");
215 theora_parse_get_property (GObject * object, guint prop_id,
216 GValue * value, GParamSpec * pspec)
218 GstTheoraParse *parse = GST_THEORA_PARSE (object);
221 case PROP_SYNCHRONIZATION_POINTS:
223 GValueArray *array = NULL;
226 array = g_value_array_new (parse->npairs * 2);
228 for (i = 0; i < parse->npairs; i++) {
231 g_value_init (&v, G_TYPE_UINT64);
232 g_value_set_uint64 (&v, parse->times[i * 2]);
233 g_value_array_append (array, &v);
234 g_value_set_uint64 (&v, parse->times[i * 2 + 1]);
235 g_value_array_append (array, &v);
239 g_value_set_boxed (value, array);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 theora_parse_set_header_on_caps (GstTheoraParse * parse, GstCaps * caps)
252 GstStructure *structure;
254 GValue array = { 0 };
255 GValue value = { 0 };
257 bufs = parse->streamheader;
258 structure = gst_caps_get_structure (caps, 0);
259 g_value_init (&array, GST_TYPE_ARRAY);
261 for (i = 0; i < 3; i++) {
265 bufs[i] = gst_buffer_make_writable (bufs[i]);
266 GST_BUFFER_FLAG_SET (bufs[i], GST_BUFFER_FLAG_IN_CAPS);
268 g_value_init (&value, GST_TYPE_BUFFER);
269 gst_value_set_buffer (&value, bufs[i]);
270 gst_value_array_append_value (&array, &value);
271 g_value_unset (&value);
274 gst_structure_set_value (structure, "streamheader", &array);
275 g_value_unset (&array);
278 /* two tasks to do here: set the streamheader on the caps, and use libtheora to
281 theora_parse_set_streamheader (GstTheoraParse * parse)
285 guint32 bitstream_version;
286 th_setup_info *setup = NULL;
288 g_assert (!parse->streamheader_received);
290 caps = gst_caps_make_writable (gst_pad_query_caps (parse->srcpad, NULL));
291 theora_parse_set_header_on_caps (parse, caps);
292 GST_DEBUG_OBJECT (parse, "here are the caps: %" GST_PTR_FORMAT, caps);
293 gst_pad_set_caps (parse->srcpad, caps);
294 gst_caps_unref (caps);
296 for (i = 0; i < 3; i++) {
302 buf = parse->streamheader[i];
306 packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
308 packet.granulepos = GST_BUFFER_OFFSET_END (buf);
309 packet.packetno = i + 1;
311 packet.b_o_s = (i == 0);
312 ret = th_decode_headerin (&parse->info, &parse->comment, &setup, &packet);
313 gst_buffer_unmap (buf, packet.packet, size);
315 GST_WARNING_OBJECT (parse, "Failed to decode Theora header %d: %d\n",
320 th_setup_free (setup);
323 parse->fps_n = parse->info.fps_numerator;
324 parse->fps_d = parse->info.fps_denominator;
325 parse->shift = parse->info.keyframe_granule_shift;
327 /* With libtheora-1.0beta1 the granulepos scheme was changed:
328 * where earlier the granulepos refered to the index/beginning
329 * of a frame, it now refers to the end, which matches the use
330 * in vorbis/speex. We check the bitstream version from the header so
331 * we know which way to interpret the incoming granuepos
333 bitstream_version = (parse->info.version_major << 16) |
334 (parse->info.version_minor << 8) | parse->info.version_subminor;
335 parse->is_old_bitstream = (bitstream_version <= 0x00030200);
337 parse->streamheader_received = TRUE;
341 theora_parse_drain_event_queue (GstTheoraParse * parse)
343 while (parse->event_queue->length) {
346 event = GST_EVENT_CAST (g_queue_pop_head (parse->event_queue));
347 gst_pad_event_default (parse->sinkpad, event);
352 theora_parse_push_headers (GstTheoraParse * parse)
356 theora_parse_drain_event_queue (parse);
358 if (!parse->streamheader_received)
359 theora_parse_set_streamheader (parse);
361 /* ignore return values, we pass along the result of pushing data packets only
363 for (i = 0; i < 3; i++) {
366 if ((buf = parse->streamheader[i])) {
367 gst_pad_push (parse->srcpad, buf);
368 parse->streamheader[i] = NULL;
374 theora_parse_clear_queue (GstTheoraParse * parse)
376 while (parse->buffer_queue->length) {
379 buf = GST_BUFFER_CAST (g_queue_pop_head (parse->buffer_queue));
380 gst_buffer_unref (buf);
382 while (parse->event_queue->length) {
385 event = GST_EVENT_CAST (g_queue_pop_head (parse->event_queue));
386 gst_event_unref (event);
391 make_granulepos (GstTheoraParse * parse, gint64 keyframe, gint64 frame)
397 /* If using newer theora, offset the granulepos by +1, see comment in
398 * theora_parse_set_streamheader.
400 * We don't increment keyframe directly, as internally we always index frames
401 * starting from 0 and we do some sanity checking below. */
402 if (!parse->is_old_bitstream)
403 iframe = keyframe + 1;
407 g_return_val_if_fail (frame >= keyframe, -1);
408 g_return_val_if_fail (frame - keyframe < 1 << parse->shift, -1);
410 return (iframe << parse->shift) + (frame - keyframe);
414 parse_granulepos (GstTheoraParse * parse, gint64 granulepos,
415 gint64 * keyframe, gint64 * frame)
419 kf = granulepos >> parse->shift;
420 /* If using newer theora, offset the granulepos by -1, see comment
421 * in theora_parse_set_streamheader */
422 if (!parse->is_old_bitstream)
427 *frame = kf + (granulepos & ((1 << parse->shift) - 1));
431 is_keyframe (GstBuffer * buf)
436 size = gst_buffer_get_size (buf);
440 gst_buffer_extract (buf, 0, data, 1);
442 return ((data[0] & 0x40) == 0);
446 theora_parse_munge_granulepos (GstTheoraParse * parse, GstBuffer * buf,
447 gint64 keyframe, gint64 frame)
450 GstClockTimeDiff time_diff;
452 if (keyframe == frame) {
455 /* update granule_offset */
456 for (i = 0; i < parse->npairs; i++) {
457 if (parse->times[i * 2] >= GST_BUFFER_OFFSET (buf))
461 /* time_diff gets reset below */
462 time_diff = parse->times[i * 2 - 1] - parse->times[i * 2 - 2];
463 parse->granule_offset = gst_util_uint64_scale (time_diff,
464 parse->fps_n, parse->fps_d * GST_SECOND);
465 parse->granule_offset <<= parse->shift;
469 frames_diff = parse->granule_offset >> parse->shift;
470 time_diff = gst_util_uint64_scale_int (GST_SECOND * frames_diff,
471 parse->fps_d, parse->fps_n);
473 GST_DEBUG_OBJECT (parse, "offsetting theora stream by %" G_GINT64_FORMAT
474 " frames (%" GST_TIME_FORMAT ")", frames_diff, GST_TIME_ARGS (time_diff));
476 GST_BUFFER_OFFSET_END (buf) += parse->granule_offset;
477 GST_BUFFER_OFFSET (buf) += time_diff;
478 GST_BUFFER_TIMESTAMP (buf) += time_diff;
482 theora_parse_push_buffer (GstTheoraParse * parse, GstBuffer * buf,
483 gint64 keyframe, gint64 frame)
486 GstClockTime this_time, next_time;
488 this_time = gst_util_uint64_scale_int (GST_SECOND * frame,
489 parse->fps_d, parse->fps_n);
491 next_time = gst_util_uint64_scale_int (GST_SECOND * (frame + 1),
492 parse->fps_d, parse->fps_n);
494 GST_BUFFER_OFFSET_END (buf) = make_granulepos (parse, keyframe, frame);
495 GST_BUFFER_OFFSET (buf) = this_time;
496 GST_BUFFER_TIMESTAMP (buf) = this_time;
497 GST_BUFFER_DURATION (buf) = next_time - this_time;
500 theora_parse_munge_granulepos (parse, buf, keyframe, frame);
502 GST_DEBUG_OBJECT (parse, "pushing buffer with granulepos %" G_GINT64_FORMAT
503 "|%" G_GINT64_FORMAT, keyframe, frame - keyframe);
505 return gst_pad_push (parse->srcpad, buf);
509 theora_parse_drain_queue_prematurely (GstTheoraParse * parse)
511 GstFlowReturn ret = GST_FLOW_OK;
513 /* got an EOS event, make sure to push out any buffers that were in the queue
514 * -- won't normally be the case, but this catches the
515 * didn't-get-a-granulepos-on-the-last-packet case. Assuming a continuous
518 GST_DEBUG_OBJECT (parse, "got EOS, draining queue");
520 /* if we get an eos before pushing the streamheaders, drain our events before
522 theora_parse_drain_event_queue (parse);
524 while (!g_queue_is_empty (parse->buffer_queue)) {
527 buf = GST_BUFFER_CAST (g_queue_pop_head (parse->buffer_queue));
531 if (is_keyframe (buf))
532 /* we have a keyframe */
533 parse->prev_keyframe = parse->prev_frame;
535 GST_BUFFER_FLAGS (buf) |= GST_BUFFER_FLAG_DELTA_UNIT;
537 if (parse->prev_keyframe < 0) {
538 if (GST_BUFFER_OFFSET_END_IS_VALID (buf)) {
539 parse_granulepos (parse, GST_BUFFER_OFFSET_END (buf),
540 &parse->prev_keyframe, NULL);
542 /* No previous keyframe known; can't extract one from this frame. That
543 * means we can't do any valid output for this frame, just continue to
546 gst_buffer_unref (buf);
551 ret = theora_parse_push_buffer (parse, buf, parse->prev_keyframe,
554 if (ret != GST_FLOW_OK)
563 theora_parse_drain_queue (GstTheoraParse * parse, gint64 granulepos)
565 GstFlowReturn ret = GST_FLOW_OK;
566 gint64 keyframe, prev_frame, frame;
568 parse_granulepos (parse, granulepos, &keyframe, &frame);
570 GST_DEBUG ("draining queue of length %d",
571 g_queue_get_length (parse->buffer_queue));
573 GST_LOG_OBJECT (parse, "gp %" G_GINT64_FORMAT ", kf %" G_GINT64_FORMAT
574 ", frame %" G_GINT64_FORMAT, granulepos, keyframe, frame);
576 prev_frame = frame - g_queue_get_length (parse->buffer_queue);
578 GST_LOG_OBJECT (parse,
579 "new prev %" G_GINT64_FORMAT ", prev %" G_GINT64_FORMAT, prev_frame,
582 if (prev_frame < parse->prev_frame) {
583 GST_WARNING ("jumped %" G_GINT64_FORMAT
584 " frames backwards! not sure what to do here",
585 parse->prev_frame - prev_frame);
586 parse->prev_frame = prev_frame;
587 } else if (prev_frame > parse->prev_frame) {
588 GST_INFO ("discontinuity detected (%" G_GINT64_FORMAT
589 " frames)", prev_frame - parse->prev_frame);
590 if (keyframe <= prev_frame && keyframe > parse->prev_keyframe)
591 parse->prev_keyframe = keyframe;
592 parse->prev_frame = prev_frame;
595 while (!g_queue_is_empty (parse->buffer_queue)) {
599 g_assert (parse->prev_frame >= 0);
601 buf = GST_BUFFER_CAST (g_queue_pop_head (parse->buffer_queue));
603 if (is_keyframe (buf))
604 /* we have a keyframe */
605 parse->prev_keyframe = parse->prev_frame;
607 GST_BUFFER_FLAGS (buf) |= GST_BUFFER_FLAG_DELTA_UNIT;
609 ret = theora_parse_push_buffer (parse, buf, parse->prev_keyframe,
612 if (ret != GST_FLOW_OK)
621 theora_parse_queue_buffer (GstTheoraParse * parse, GstBuffer * buf)
623 GstFlowReturn ret = GST_FLOW_OK;
625 buf = gst_buffer_make_writable (buf);
627 g_queue_push_tail (parse->buffer_queue, buf);
629 if (GST_BUFFER_OFFSET_END_IS_VALID (buf)) {
630 if (parse->prev_keyframe < 0) {
631 parse_granulepos (parse, GST_BUFFER_OFFSET_END (buf),
632 &parse->prev_keyframe, NULL);
634 ret = theora_parse_drain_queue (parse, GST_BUFFER_OFFSET_END (buf));
641 theora_parse_chain (GstPad * pad, GstBuffer * buffer)
644 GstTheoraParse *parse;
645 guint8 *data, header;
647 gboolean have_header;
649 parse = GST_THEORA_PARSE (gst_pad_get_parent (pad));
653 data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
655 gst_buffer_unmap (buffer, data, size);
663 if (parse->send_streamheader) {
664 /* we need to collect the headers still */
665 /* so put it on the streamheader list and return */
666 if (header >= 0x80 && header <= 0x82)
667 parse->streamheader[header - 0x80] = buffer;
671 /* data packet, push the headers we collected before */
672 if (parse->send_streamheader) {
673 theora_parse_push_headers (parse);
674 parse->send_streamheader = FALSE;
677 ret = theora_parse_queue_buffer (parse, buffer);
680 gst_object_unref (parse);
686 theora_parse_queue_event (GstTheoraParse * parse, GstEvent * event)
688 g_queue_push_tail (parse->event_queue, event);
693 theora_parse_sink_event (GstPad * pad, GstEvent * event)
696 GstTheoraParse *parse;
698 parse = GST_THEORA_PARSE (gst_pad_get_parent (pad));
700 switch (GST_EVENT_TYPE (event)) {
701 case GST_EVENT_FLUSH_STOP:
702 theora_parse_clear_queue (parse);
703 parse->prev_keyframe = -1;
704 parse->prev_frame = -1;
705 ret = gst_pad_event_default (pad, event);
708 theora_parse_drain_queue_prematurely (parse);
709 ret = gst_pad_event_default (pad, event);
712 if (parse->send_streamheader && GST_EVENT_IS_SERIALIZED (event))
713 ret = theora_parse_queue_event (parse, event);
715 ret = gst_pad_event_default (pad, event);
719 gst_object_unref (parse);
725 theora_parse_src_convert (GstPad * pad,
726 GstFormat src_format, gint64 src_value,
727 GstFormat * dest_format, gint64 * dest_value)
730 GstTheoraParse *parse;
733 if (src_format == *dest_format) {
734 *dest_value = src_value;
738 parse = GST_THEORA_PARSE (gst_pad_get_parent (pad));
740 /* we need the info part before we can done something */
741 if (!parse->streamheader_received)
744 switch (src_format) {
745 case GST_FORMAT_BYTES:
746 switch (*dest_format) {
747 case GST_FORMAT_DEFAULT:
748 *dest_value = gst_util_uint64_scale_int (src_value, 2,
749 parse->info.pic_height * parse->info.pic_width * 3);
751 case GST_FORMAT_TIME:
752 /* seems like a rather silly conversion, implement me if you like */
757 case GST_FORMAT_TIME:
758 switch (*dest_format) {
759 case GST_FORMAT_BYTES:
760 scale = 3 * (parse->info.pic_width * parse->info.pic_height) / 2;
761 case GST_FORMAT_DEFAULT:
762 *dest_value = scale * gst_util_uint64_scale (src_value,
763 parse->info.fps_numerator,
764 parse->info.fps_denominator * GST_SECOND);
767 GST_DEBUG_OBJECT (parse, "cannot convert to format %s",
768 gst_format_get_name (*dest_format));
772 case GST_FORMAT_DEFAULT:
773 switch (*dest_format) {
774 case GST_FORMAT_TIME:
775 *dest_value = gst_util_uint64_scale (src_value,
776 GST_SECOND * parse->info.fps_denominator,
777 parse->info.fps_numerator);
779 case GST_FORMAT_BYTES:
780 *dest_value = gst_util_uint64_scale_int (src_value,
781 3 * parse->info.pic_width * parse->info.pic_height, 2);
791 gst_object_unref (parse);
797 GST_DEBUG_OBJECT (parse, "no header yet, cannot convert");
804 theora_parse_src_query (GstPad * pad, GstQuery * query)
806 GstTheoraParse *parse;
808 gboolean res = FALSE;
810 parse = GST_THEORA_PARSE (gst_pad_get_parent (pad));
812 switch (GST_QUERY_TYPE (query)) {
813 case GST_QUERY_POSITION:
816 GstFormat my_format, format;
819 frame = parse->prev_frame;
821 GST_LOG_OBJECT (parse,
822 "query %p: we have current frame: %" G_GINT64_FORMAT, query, frame);
825 gst_query_parse_position (query, &format, NULL);
827 /* and convert to the final format in two steps with time as the
828 * intermediate step */
829 my_format = GST_FORMAT_TIME;
831 theora_parse_src_convert (parse->sinkpad, GST_FORMAT_DEFAULT,
832 frame, &my_format, &time)))
835 /* fixme: handle segments
836 time = (time - parse->segment.start) + parse->segment.time;
839 GST_LOG_OBJECT (parse,
840 "query %p: our time: %" GST_TIME_FORMAT " (conv to %s)",
841 query, GST_TIME_ARGS (time), gst_format_get_name (format));
844 theora_parse_src_convert (pad, my_format, time, &format, &value)))
847 gst_query_set_position (query, format, value);
849 GST_LOG_OBJECT (parse,
850 "query %p: we return %" G_GINT64_FORMAT " (format %u)", query, value,
855 case GST_QUERY_DURATION:
856 /* forward to peer for total */
857 if (!(res = gst_pad_query (GST_PAD_PEER (parse->sinkpad), query)))
860 case GST_QUERY_CONVERT:
862 GstFormat src_fmt, dest_fmt;
863 gint64 src_val, dest_val;
865 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
867 theora_parse_src_convert (pad, src_fmt, src_val, &dest_fmt,
871 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
875 res = gst_pad_query_default (pad, query);
879 gst_object_unref (parse);
886 GST_DEBUG_OBJECT (parse, "query failed");
891 static GstStateChangeReturn
892 theora_parse_change_state (GstElement * element, GstStateChange transition)
894 GstTheoraParse *parse = GST_THEORA_PARSE (element);
895 GstStateChangeReturn ret;
898 switch (transition) {
899 case GST_STATE_CHANGE_READY_TO_PAUSED:
900 th_info_init (&parse->info);
901 th_comment_init (&parse->comment);
902 parse->send_streamheader = TRUE;
903 parse->buffer_queue = g_queue_new ();
904 parse->event_queue = g_queue_new ();
905 parse->prev_keyframe = -1;
906 parse->prev_frame = -1;
907 parse->granule_offset = 0;
913 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
915 switch (transition) {
916 case GST_STATE_CHANGE_PAUSED_TO_READY:
917 th_info_clear (&parse->info);
918 th_comment_clear (&parse->comment);
919 theora_parse_clear_queue (parse);
920 g_queue_free (parse->buffer_queue);
921 g_queue_free (parse->event_queue);
922 parse->buffer_queue = NULL;
923 for (i = 0; i < 3; i++) {
924 if (parse->streamheader[i]) {
925 gst_buffer_unref (parse->streamheader[i]);
926 parse->streamheader[i] = NULL;
929 parse->streamheader_received = FALSE;