From 104bd7cf02bad9e83b440b48e57ea6483c5ca3ef Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Tue, 30 Dec 2014 08:07:18 -0300 Subject: [PATCH] hlsdemux: only typefind when we have a minimum amount of data For small amounts some data might be mistyped and it would cause the pipeline to fail. For example if you have AAC inside mpegts, for small amounts, the AAC samples would cause the typefinder to think it is AAC and not mpegts. https://bugzilla.gnome.org/show_bug.cgi?id=736061 --- ext/hls/gsthlsdemux.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/ext/hls/gsthlsdemux.c b/ext/hls/gsthlsdemux.c index c532cc39f9..bf9e29bbc0 100644 --- a/ext/hls/gsthlsdemux.c +++ b/ext/hls/gsthlsdemux.c @@ -664,12 +664,31 @@ gst_hls_demux_chunk_received (GstAdaptiveDemux * demux, buffer = *chunk; if (G_UNLIKELY (hlsdemux->do_typefind && buffer != NULL)) { - GstCaps *caps; + GstCaps *caps = NULL; + GstMapInfo info; + guint buffer_size; + GstTypeFindProbability prob = GST_TYPE_FIND_NONE; + + gst_buffer_map (buffer, &info, GST_MAP_READ); + buffer_size = info.size; + + /* Typefind could miss if buffer is too small. In this case we + * will retry later */ + if (buffer_size >= (2 * 1024)) { + caps = + gst_type_find_helper_for_data (GST_OBJECT_CAST (hlsdemux), info.data, + info.size, &prob); + } + gst_buffer_unmap (buffer, &info); - caps = gst_type_find_helper_for_buffer (NULL, buffer, NULL); if (G_UNLIKELY (!caps)) { - /* Typefind could fail if buffer is too small. Retry later */ - if (gst_buffer_get_size (buffer) < (2 * 1024 * 1024)) { + /* Only fail typefinding if we already a good amount of data + * and we still don't know the type */ + if (buffer_size > (2 * 1024 * 1024)) { + GST_ELEMENT_ERROR (hlsdemux, STREAM, TYPE_NOT_FOUND, + ("Could not determine type of stream"), (NULL)); + return GST_FLOW_NOT_NEGOTIATED; + } else { if (hlsdemux->pending_buffer) hlsdemux->pending_buffer = gst_buffer_append (buffer, hlsdemux->pending_buffer); @@ -678,11 +697,11 @@ gst_hls_demux_chunk_received (GstAdaptiveDemux * demux, *chunk = NULL; return GST_FLOW_OK; } - - GST_ELEMENT_ERROR (hlsdemux, STREAM, TYPE_NOT_FOUND, - ("Could not determine type of stream"), (NULL)); - return GST_FLOW_NOT_NEGOTIATED; } + + GST_DEBUG_OBJECT (hlsdemux, "Typefind result: %" GST_PTR_FORMAT " prob:%d", + caps, prob); + if (!hlsdemux->input_caps || !gst_caps_is_equal (caps, hlsdemux->input_caps)) { gst_caps_replace (&hlsdemux->input_caps, caps);