From 5a064ca4234ecbc9451b59d36b4e4f13de203d4f Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Fri, 28 Jun 2013 14:48:19 +0100 Subject: [PATCH] typefind: avoid too low mpeg/ts probability on small amount of data With the current test, we get into problems when we try to typefind a MPEG stream from a small amount of data, which can happen when we get data pushed from a HTTP source. We thus make a second test to give higher probability if all the potential headers were either pack or pes headers (ie, no potential header was unrecognized). This fixes an issue with a MPEG1/MP2 stream being properly discovered as video/mpeg from a file, but as audio/mpeg from souphttpsrc. https://bugzilla.gnome.org/show_bug.cgi?id=703256 --- gst/typefind/gsttypefindfunctions.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 8feb6d55e5..71b9234a47 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -2141,6 +2141,7 @@ mpeg_sys_type_find (GstTypeFind * tf, gpointer unused) guint pack_size; guint since_last_sync = 0; guint32 sync_word = 0xffffffff; + guint potential_headers = 0; G_STMT_START { gint len; @@ -2175,6 +2176,7 @@ mpeg_sys_type_find (GstTypeFind * tf, gpointer unused) } pack_size = 0; + potential_headers++; if (IS_MPEG_PACK_CODE (data[0])) { if ((data[1] & 0xC0) == 0x40) { /* MPEG-2 */ @@ -2234,6 +2236,17 @@ suggest: prob = GST_TYPE_FIND_POSSIBLE + (10 * (pack_headers + pes_headers)); prob = MIN (prob, GST_TYPE_FIND_MAXIMUM); + /* With the above test, we get into problems when we try to typefind + a MPEG stream from a small amount of data, which can happen when + we get data pushed from a HTTP source. We thus make a second test + to give higher probability if all the potential headers were either + pack or pes headers (ie, no potential header was unrecognized). */ + if (potential_headers == pack_headers + pes_headers) { + GST_LOG ("Only %u headers, but all were recognized", potential_headers); + prob += 10; + prob = MIN (prob, GST_TYPE_FIND_MAXIMUM); + } + /* lower probability if the first packet wasn't right at the start */ if (data0 != first_sync && prob >= 10) prob -= 10;