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
This commit is contained in:
Tim-Philipp Müller 2012-11-11 20:04:40 +00:00
parent 20c9d2d2cc
commit bccb3feebf

View file

@ -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 ***/