mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-18 04:05:34 +00:00
typefinding: optimise AC-3 typefinder a bit
Make AC-3 typefinder use the DataScanCtx stuff so we don't have to do gst_type_find_peek() in the inner loop all the time. Also return when we've suggested AC3 caps, instead of continuing with the loop.
This commit is contained in:
parent
ca7ba91e5b
commit
eef885cf86
1 changed files with 22 additions and 18 deletions
|
@ -1090,7 +1090,7 @@ musepack_type_find (GstTypeFind * tf, gpointer unused)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** audio/x-ac3 ***/
|
/*** audio/x-ac3 ***/
|
||||||
/* This should be audio/ac3, but isn't for backwards compatibility */
|
/* FIXME 0.11: should be audio/ac3, but isn't for backwards compatibility */
|
||||||
static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
|
static GstStaticCaps ac3_caps = GST_STATIC_CAPS ("audio/x-ac3");
|
||||||
|
|
||||||
#define AC3_CAPS (gst_static_caps_get(&ac3_caps))
|
#define AC3_CAPS (gst_static_caps_get(&ac3_caps))
|
||||||
|
@ -1142,47 +1142,51 @@ static const struct ac3_frmsize ac3_frmsizecod_tbl[] = {
|
||||||
{640, {1280, 1394, 1920}}
|
{640, {1280, 1394, 1920}}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ac3_type_find (GstTypeFind * tf, gpointer unused)
|
ac3_type_find (GstTypeFind * tf, gpointer unused)
|
||||||
{
|
{
|
||||||
guint8 *data = gst_type_find_peek (tf, 0, 5);
|
DataScanCtx c = { 0, NULL, 0 };
|
||||||
gint offset = 0;
|
|
||||||
|
|
||||||
/* Search for an ac3 frame; not neccesarily right at the start, but give it
|
/* Search for an ac3 frame; not neccesarily right at the start, but give it
|
||||||
* a lower probability if not found right at the start. Check that the
|
* a lower probability if not found right at the start. Check that the
|
||||||
* frame is followed by a second frame at the expected offset.
|
* frame is followed by a second frame at the expected offset.
|
||||||
* We could also check the two ac3 CRCs, but we don't do that right now */
|
* We could also check the two ac3 CRCs, but we don't do that right now */
|
||||||
while (data && offset < 1024) {
|
while (c.offset < 1024) {
|
||||||
if (data[0] == 0x0b && data[1] == 0x77) {
|
if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 5)))
|
||||||
guint fscod = (data[4] >> 6) & 0x03;
|
break;
|
||||||
guint frmsizecod = data[4] & 0x3f;
|
|
||||||
|
if (c.data[0] == 0x0b && c.data[1] == 0x77) {
|
||||||
|
guint fscod = (c.data[4] >> 6) & 0x03;
|
||||||
|
guint frmsizecod = c.data[4] & 0x3f;
|
||||||
|
|
||||||
if (fscod < 3 && frmsizecod < 38) {
|
if (fscod < 3 && frmsizecod < 38) {
|
||||||
guint frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
|
DataScanCtx c_next = c;
|
||||||
|
guint frame_size;
|
||||||
|
|
||||||
data = gst_type_find_peek (tf, offset + frame_size * 2, 5);
|
frame_size = ac3_frmsizecod_tbl[frmsizecod].frm_size[fscod];
|
||||||
|
if (data_scan_ctx_ensure_data (tf, &c_next, (frame_size * 2) + 5)) {
|
||||||
|
data_scan_ctx_advance (tf, &c, frame_size * 2);
|
||||||
|
|
||||||
if (data) {
|
if (c_next.data[0] == 0x0b && c_next.data[1] == 0x77) {
|
||||||
if (data[0] == 0x0b && data[1] == 0x77) {
|
guint fscod2 = (c_next.data[4] >> 6) & 0x03;
|
||||||
guint fscod2 = (data[4] >> 6) & 0x03;
|
guint frmsizecod2 = c_next.data[4] & 0x3f;
|
||||||
guint frmsizecod2 = data[4] & 0x3f;
|
|
||||||
|
|
||||||
if (fscod == fscod2 && frmsizecod == frmsizecod2) {
|
if (fscod == fscod2 && frmsizecod == frmsizecod2) {
|
||||||
int prob;
|
GstTypeFindProbability prob;
|
||||||
|
|
||||||
if (offset == 0)
|
if (c.offset == 0)
|
||||||
prob = GST_TYPE_FIND_MAXIMUM;
|
prob = GST_TYPE_FIND_MAXIMUM;
|
||||||
else
|
else
|
||||||
prob = GST_TYPE_FIND_NEARLY_CERTAIN;
|
prob = GST_TYPE_FIND_NEARLY_CERTAIN;
|
||||||
|
|
||||||
gst_type_find_suggest (tf, prob, AC3_CAPS);
|
gst_type_find_suggest (tf, prob, AC3_CAPS);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
offset++;
|
data_scan_ctx_advance (tf, &c, 1);
|
||||||
data = gst_type_find_peek (tf, offset, 5);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue