ext/theora/theoradec.c: Don't crash on missing header packets.

Original commit message from CVS:
* ext/theora/theoradec.c: (gst_theora_dec_class_init),
(theora_get_formats), (theora_dec_src_convert),
(theora_dec_sink_convert), (theora_dec_src_query),
(theora_dec_src_event), (theora_dec_event), (theora_dec_chain),
(theora_dec_change_state):
Don't crash on missing header packets.
This commit is contained in:
Wim Taymans 2004-08-09 13:16:04 +00:00
parent 8491fd9fa5
commit 8d74cc9136
2 changed files with 30 additions and 2 deletions

View file

@ -1,3 +1,12 @@
2004-08-09 Wim Taymans <wim@fluendo.com>
* ext/theora/theoradec.c: (gst_theora_dec_class_init),
(theora_get_formats), (theora_dec_src_convert),
(theora_dec_sink_convert), (theora_dec_src_query),
(theora_dec_src_event), (theora_dec_event), (theora_dec_chain),
(theora_dec_change_state):
Don't crash on missing header packets.
2004-08-09 Thomas Vander Stichele <thomas at apestaart dot org>
* po/LINGUAS:

View file

@ -57,6 +57,7 @@ struct _GstTheoraDec
guint packetno;
guint64 granulepos;
gboolean initialized;
gboolean need_keyframe;
gint width, height;
gint offset_x, offset_y;
@ -530,10 +531,13 @@ theora_dec_chain (GstPad * pad, GstData * data)
packet.packet = GST_BUFFER_DATA (buf);
packet.bytes = GST_BUFFER_SIZE (buf);
packet.granulepos = dec->granulepos;
packet.packetno = dec->packetno++;
packet.packetno = dec->packetno;
packet.b_o_s = (packet.packetno == 0) ? 1 : 0;
packet.e_o_s = 0;
GST_DEBUG_OBJECT (dec, "header=%d packetno=%d", packet.packet[0],
packet.packetno);
/* switch depending on packet type */
if (packet.packet[0] & 0x80) {
/* header packet */
@ -543,7 +547,9 @@ theora_dec_chain (GstPad * pad, GstData * data)
gst_data_unref (data);
return;
}
if (packet.packetno == 1) {
if (packet.packetno == 0) {
dec->packetno++;
} else if (packet.packetno == 1) {
gchar *encoder = NULL;
GstTagList *list =
gst_tag_list_from_vorbiscomment_buffer (buf, "\201theora", 7,
@ -561,6 +567,8 @@ theora_dec_chain (GstPad * pad, GstData * data)
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
GST_TAG_ENCODER_VERSION, dec->info.version_major, NULL);
gst_element_found_tags_for_pad (GST_ELEMENT (dec), dec->srcpad, 0, list);
dec->packetno++;
} else if (packet.packetno == 2) {
GstCaps *caps;
gint par_num, par_den;
@ -621,6 +629,9 @@ theora_dec_chain (GstPad * pad, GstData * data)
dec->height, NULL);
gst_pad_set_explicit_caps (dec->srcpad, caps);
gst_caps_free (caps);
dec->initialized = TRUE;
dec->packetno++;
}
} else {
/* normal data packet */
@ -633,6 +644,13 @@ theora_dec_chain (GstPad * pad, GstData * data)
gint width, height;
gint cwidth, cheight;
dec->packetno++;
if (!dec->initialized) {
gst_data_unref (data);
return;
}
/* the second most significant bit of the first data byte is cleared
* for keyframes */
keyframe = (packet.packet[0] & 0x40) == 0;
@ -739,6 +757,7 @@ theora_dec_change_state (GstElement * element)
theora_info_init (&dec->info);
theora_comment_init (&dec->comment);
dec->need_keyframe = TRUE;
dec->initialized = FALSE;
break;
case GST_STATE_PAUSED_TO_PLAYING:
break;