From bccb3feebf303ea51cb6bfa4ee74bc1fb43a6eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 11 Nov 2012 20:04:40 +0000 Subject: [PATCH] typefinding: improve wavpack typefinder Check for second block sync and return different probabilities depending on what we found (trumping the AAC loas typefinder's LIKELY probability after finding a second frame sync in this particular case). https://bugzilla.gnome.org/show_bug.cgi?id=687674 --- gst/typefind/gsttypefindfunctions.c | 34 ++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 409cd2f420..8b84dca227 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -1678,9 +1678,11 @@ GST_STATIC_CAPS ("audio/x-wavpack-correction, framed = (boolean) false"); static void wavpack_type_find (GstTypeFind * tf, gpointer unused) { + GstTypeFindProbability base_prob = GST_TYPE_FIND_POSSIBLE; guint64 offset; guint32 blocksize; const guint8 *data; + guint count_wv, count_wvc; data = gst_type_find_peek (tf, 0, 32); if (!data) @@ -1695,6 +1697,8 @@ wavpack_type_find (GstTypeFind * tf, gpointer unused) * work in pull-mode */ blocksize = GST_READ_UINT32_LE (data + 4); GST_LOG ("wavpack header, blocksize=0x%04x", blocksize); + count_wv = 0; + count_wvc = 0; offset = 32; while (offset < 8 + blocksize) { guint32 sublen; @@ -1720,18 +1724,38 @@ wavpack_type_find (GstTypeFind * tf, gpointer unused) switch (data[0] & 0x0f) { case 0xa: /* ID_WV_BITSTREAM */ case 0xc: /* ID_WVX_BITSTREAM */ - gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, WAVPACK_CAPS); - return; + ++count_wv; + break; case 0xb: /* ID_WVC_BITSTREAM */ - gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, - WAVPACK_CORRECTION_CAPS); - return; + ++count_wvc; + break; default: break; } + if (count_wv >= 5 || count_wvc >= 5) + break; } offset += sublen; } + + /* check for second block header */ + data = gst_type_find_peek (tf, 8 + blocksize, 4); + if (data != NULL && memcmp (data, "wvpk", 4) == 0) { + GST_DEBUG ("found second block sync"); + base_prob = GST_TYPE_FIND_LIKELY; + } + + GST_DEBUG ("wvc=%d, wv=%d", count_wvc, count_wv); + + if (count_wvc > 0 && count_wvc > count_wv) { + gst_type_find_suggest (tf, + MIN (base_prob + 5 * count_wvc, GST_TYPE_FIND_NEARLY_CERTAIN), + WAVPACK_CORRECTION_CAPS); + } else if (count_wv > 0) { + gst_type_find_suggest (tf, + MIN (base_prob + 5 * count_wv, GST_TYPE_FIND_NEARLY_CERTAIN), + WAVPACK_CAPS); + } } /*** application/postscrip ***/