From 55ec47f555ea25256433fe4081ce63d0ed5312b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 20 Sep 2018 14:04:39 +0300 Subject: [PATCH] vorbisdec: Initialize decoder directly once we have the 3 headers ... instead of waiting for the first non-header buffer. Also drop non-identification headers arriving after initialization or before the identification header. We don't do anything with them and they would just accumulate. https://bugzilla.gnome.org/show_bug.cgi?id=796980 --- ext/vorbis/gstvorbisdec.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/ext/vorbis/gstvorbisdec.c b/ext/vorbis/gstvorbisdec.c index eaa38482fb..3862c620f8 100644 --- a/ext/vorbis/gstvorbisdec.c +++ b/ext/vorbis/gstvorbisdec.c @@ -680,7 +680,11 @@ vorbis_dec_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer) /* switch depending on packet type */ if ((gst_ogg_packet_data (packet))[0] & 1) { + gboolean have_all_headers; + GST_LOG_OBJECT (vd, "storing header for later analyzis"); + + /* An identification packet starts a new set of headers */ if (vd->pending_headers && (gst_ogg_packet_data (packet))[0] == 0x01) { GST_DEBUG_OBJECT (vd, "got new identification header packet, discarding old pending headers"); @@ -689,9 +693,29 @@ vorbis_dec_handle_frame (GstAudioDecoder * dec, GstBuffer * buffer) vd->pending_headers = NULL; } - vd->pending_headers = - g_list_append (vd->pending_headers, gst_buffer_ref (buffer)); - result = gst_audio_decoder_finish_frame (GST_AUDIO_DECODER (vd), NULL, 1); + /* if we have more than 3 headers with the new one and the new one is the + * type header, we can initialize the decoder now */ + have_all_headers = g_list_length (vd->pending_headers) >= 2 + && (gst_ogg_packet_data (packet))[0] == 0x05; + + if (!vd->pending_headers && (gst_ogg_packet_data (packet))[0] != 0x01) { + if (vd->initialized) { + GST_DEBUG_OBJECT (vd, + "Got another non-identification header after initialization, ignoring"); + } else { + GST_WARNING_OBJECT (vd, + "First header was not a identification header, dropping"); + } + result = gst_audio_decoder_finish_frame (GST_AUDIO_DECODER (vd), NULL, 1); + } else { + vd->pending_headers = + g_list_append (vd->pending_headers, gst_buffer_ref (buffer)); + result = gst_audio_decoder_finish_frame (GST_AUDIO_DECODER (vd), NULL, 1); + } + + if (result == GST_FLOW_OK && have_all_headers) { + result = check_pending_headers (vd); + } } else { GstClockTime timestamp, duration;