From c47074371af2e483673822611e1db084aa43558e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 19 Jan 2007 11:31:50 +0000 Subject: [PATCH] gst/typefind/gsttypefindfunctions.c: Small mpeg2 system stream typefinding improvement: make typefinder probe a bit i... Original commit message from CVS: * gst/typefind/gsttypefindfunctions.c: (mpeg2_sys_type_find): Small mpeg2 system stream typefinding improvement: make typefinder probe a bit into the stream instead of just looking for a marker at the beginning. Fixes #397810. --- ChangeLog | 7 +++++ gst/typefind/gsttypefindfunctions.c | 40 +++++++++++++++++++---------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74ceb3a7e2..cc8ee2c957 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-01-19 Tim-Philipp Müller + + * gst/typefind/gsttypefindfunctions.c: (mpeg2_sys_type_find): + Small mpeg2 system stream typefinding improvement: make typefinder + probe a bit into the stream instead of just looking for a marker + at the beginning. Fixes #397810. + 2007-01-18 Tim-Philipp Müller * gst/audioconvert/gstchannelmix.c: diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 92b69b8ada..66b14501e8 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -1029,27 +1029,41 @@ static GstStaticCaps mpeg_sys_caps = GST_STATIC_CAPS ("video/mpeg, " (((guint8 *)(data))[3] == 0xC0) || \ (((guint8 *)(data))[3] == 0xBD))) +#define MPEG2_MAX_PROBE_LENGTH 4096 /* 4kB (random value) */ + static void mpeg2_sys_type_find (GstTypeFind * tf, gpointer unused) { - guint8 *data = gst_type_find_peek (tf, 0, 5); - gint mpegversion; + guint8 *data; + gint mpegversion, len; - if (data && IS_MPEG_PACK_HEADER (data)) { - if ((data[4] & 0xC0) == 0x40) { - /* type 2 */ + len = MPEG2_MAX_PROBE_LENGTH * 2; + do { + len = len / 2; + data = gst_type_find_peek (tf, 0, 5 + len); + } while (data == NULL && len >= 32); + + if (!data) + return; + + while (len > 0) { + if (IS_MPEG_PACK_HEADER (data)) { + if ((data[4] & 0xC0) == 0x40) { + /* type 2 */ + mpegversion = 2; + goto suggest; + } else if ((data[4] & 0xF0) == 0x20) { + mpegversion = 1; + goto suggest; + } + } else if (IS_MPEG_PES_HEADER (data)) { + /* PES stream */ mpegversion = 2; goto suggest; - } else if ((data[4] & 0xF0) == 0x20) { - mpegversion = 1; - goto suggest; } - } else if (data && IS_MPEG_PES_HEADER (data)) { - /* PES stream */ - mpegversion = 2; - goto suggest; + ++data; + --len; } - return; suggest: {