typefind: improved and extended typefinder for module music formats

introduced new caps: audio/x-mod, modtype : { xm, okt, mod, ptm, ... }

https://bugzilla.gnome.org/show_bug.cgi?id=706061
This commit is contained in:
Carlos Rafael Giani 2013-08-13 23:18:34 +02:00 committed by Sebastian Dröge
parent c4d7ffddb5
commit 4c79f35c7a

View file

@ -3157,58 +3157,165 @@ static void
mod_type_find (GstTypeFind * tf, gpointer unused) mod_type_find (GstTypeFind * tf, gpointer unused)
{ {
const guint8 *data; const guint8 *data;
GstTypeFindProbability probability;
const char *mod_type = NULL;
/* MOD */ /* MOD */
if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) { if ((data = gst_type_find_peek (tf, 1080, 4)) != NULL) {
/* Protracker and variants */ /* Protracker and variants */
if ((memcmp (data, "M.K.", 4) == 0) || (memcmp (data, "M!K!", 4) == 0) || if ((memcmp (data, "M.K.", 4) == 0) ||
(memcmp (data, "M!K!", 4) == 0) ||
(memcmp (data, "M&K!", 4) == 0) || (memcmp (data, "N.T.", 4) == 0) ||
/* Star Tracker */ /* Star Tracker */
(memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) || (memcmp (data, "FLT", 3) == 0 && isdigit (data[3])) ||
(memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) || (memcmp (data, "EXO", 3) == 0 && isdigit (data[3])) ||
/* Oktalyzer (Amiga) */ /* Oktalyzer (Amiga) */
(memcmp (data, "OKTA", 4) == 0) || (memcmp (data, "OKTA", 4) == 0) || (memcmp (data, "OCTA", 4) == 0) ||
/* Oktalyser (Atari) */ /* Oktalyser (Atari) */
(memcmp (data, "CD81", 4) == 0) || (memcmp (data, "CD81", 4) == 0) ||
/* Taketracker */
(memcmp (data, "TDZ", 3) == 0 && isdigit (data[3])) ||
/* Fasttracker */ /* Fasttracker */
(memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) || (memcmp (data + 1, "CHN", 3) == 0 && isdigit (data[0])) ||
/* Fasttracker or Taketracker */ /* Fasttracker or Taketracker */
(memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0]) (memcmp (data + 2, "CH", 2) == 0 && isdigit (data[0])
&& isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0 && isdigit (data[1])) || (memcmp (data + 2, "CN", 2) == 0
&& isdigit (data[0]) && isdigit (data[1]))) { && isdigit (data[0]) && isdigit (data[1]))) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "mod";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
}
/* J2B (Jazz Jackrabbit 2) */
if ((data = gst_type_find_peek (tf, 0, 8)) != NULL) {
if ((memcmp (data, "MUSE\xDE\xAD", 4) == 0) &&
((memcmp (data + 6, "\xBE\xEF", 2) == 0) ||
(memcmp (data + 6, "\xBA\xBE", 2) == 0))) {
mod_type = "j2b";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
}
/* AMS (Velvet Studio) */
if ((data = gst_type_find_peek (tf, 0, 7)) != NULL) {
if (memcmp (data, "AMShdr\x1A", 7) == 0) {
mod_type = "velvet-ams";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
}
/* AMS (Extreme Tracker) */
if ((data = gst_type_find_peek (tf, 0, 9)) != NULL) {
if ((memcmp (data, "Extreme", 7) == 0) && (data[8] == 1)) {
mod_type = "extreme-ams";
probability = GST_TYPE_FIND_LIKELY;
goto suggest_audio_mod_caps;
}
}
/* ULT (Ultratracker) */
if ((data = gst_type_find_peek (tf, 0, 14)) != NULL) {
if (memcmp (data, "MAS_UTrack_V00", 14) == 0) {
mod_type = "ult";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
}
/* DIGI (DigiBooster) */
if ((data = gst_type_find_peek (tf, 0, 20)) != NULL) {
if (memcmp (data, "DIGI Booster module\0", 20) == 0) {
mod_type = "digi";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
}
/* PTM (PolyTracker) */
if ((data = gst_type_find_peek (tf, 0x2C, 4)) != NULL) {
if (memcmp (data, "PTMF", 4) == 0) {
mod_type = "ptm";
probability = GST_TYPE_FIND_LIKELY;
goto suggest_audio_mod_caps;
} }
} }
/* XM */ /* XM */
if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) { if ((data = gst_type_find_peek (tf, 0, 38)) != NULL) {
if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) { if (memcmp (data, "Extended Module: ", 17) == 0 && data[37] == 0x1A) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "xm";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
} }
/* OKT */ /* OKT */
if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) { if (data || (data = gst_type_find_peek (tf, 0, 8)) != NULL) {
if (memcmp (data, "OKTASONG", 8) == 0) { if (memcmp (data, "OKTASONG", 8) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "okt";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
} }
/* Various formats with a 4-byte magic ID at the beginning of the file */
if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) { if (data || (data = gst_type_find_peek (tf, 0, 4)) != NULL) {
/* PSM (Protracker Studio PSM) */
if (memcmp (data, "PSM", 3)) {
unsigned char fbyte = data[3];
if ((fbyte == ' ') || (fbyte == 254)) {
mod_type = "psm";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
}
/* 669 */ /* 669 */
if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) { if ((memcmp (data, "if", 2) == 0) || (memcmp (data, "JN", 2) == 0)) {
gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS); mod_type = "669";
return; probability = GST_TYPE_FIND_LIKELY;
goto suggest_audio_mod_caps;
} }
/* AMF */ /* AMF */
if ((memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) || if (memcmp (data, "AMF", 3) == 0 && data[3] > 10 && data[3] < 14) {
mod_type = "dsmi-amf";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* IT */ /* IT */
(memcmp (data, "IMPM", 4) == 0) || if (memcmp (data, "IMPM", 4) == 0) {
mod_type = "it";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* DBM (DigiBooster Pro) */
if (memcmp (data, "DBM0", 4) == 0) {
mod_type = "dbm";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* MDL (DigiTrakker) */
if (memcmp (data, "DMDL", 4) == 0) {
mod_type = "mdl";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* MT2 (MadTracker 2.0) */
if (memcmp (data, "MT20", 4) == 0) {
mod_type = "mt2";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* DMF (X-Tracker) */
if (memcmp (data, "DDMF", 4) == 0) {
mod_type = "dmf";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* MED */ /* MED */
(memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0) || if ((memcmp (data, "MMD0", 4) == 0) || (memcmp (data, "MMD1", 4) == 0)) {
mod_type = "med";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* MTM */ /* MTM */
(memcmp (data, "MTM", 3) == 0)) { if (memcmp (data, "MTM", 3) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "mtm";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
/* DSM */ /* DSM */
if (memcmp (data, "RIFF", 4) == 0) { if (memcmp (data, "RIFF", 4) == 0) {
@ -3216,23 +3323,33 @@ mod_type_find (GstTypeFind * tf, gpointer unused)
if (data2) { if (data2) {
if (memcmp (data2, "DSMF", 4) == 0) { if (memcmp (data2, "DSMF", 4) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "dsm";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
} }
} }
/* FAR (Farandole) */
if (memcmp (data, "FAR\xFE", 4) == 0) {
mod_type = "far";
probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
/* FAM */ /* FAM */
if (memcmp (data, "FAM\xFE", 4) == 0) { if (memcmp (data, "FAM\xFE", 4) == 0) {
const guint8 *data2 = gst_type_find_peek (tf, 44, 3); const guint8 *data2 = gst_type_find_peek (tf, 44, 3);
if (data2) { if (data2) {
if (memcmp (data2, "compare", 3) == 0) { if (memcmp (data2, "compare", 3) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "fam";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
/* otherwise do not suggest anything */
} else { } else {
gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS); mod_type = "fam";
return; probability = GST_TYPE_FIND_LIKELY;
goto suggest_audio_mod_caps;
} }
} }
/* GDM */ /* GDM */
@ -3241,27 +3358,40 @@ mod_type_find (GstTypeFind * tf, gpointer unused)
if (data2) { if (data2) {
if (memcmp (data2, "GMFS", 4) == 0) { if (memcmp (data2, "GMFS", 4) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "gdm";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
/* otherwise do not suggest anything */
} else { } else {
gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, MOD_CAPS); mod_type = "gdm";
return; probability = GST_TYPE_FIND_LIKELY;
goto suggest_audio_mod_caps;
} }
} }
} }
/* FAR (Farandole) (secondary detection) */
if ((data = gst_type_find_peek (tf, 44, 3)) != NULL) {
if (memcmp (data, "\x0D\x0A\x1A", 3) == 0) {
mod_type = "far";
probability = GST_TYPE_FIND_POSSIBLE;
goto suggest_audio_mod_caps;
}
}
/* IMF */ /* IMF */
if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) { if ((data = gst_type_find_peek (tf, 60, 4)) != NULL) {
if (memcmp (data, "IM10", 4) == 0) { if (memcmp (data, "IM10", 4) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "imf";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
} }
/* S3M */ /* S3M */
if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) { if ((data = gst_type_find_peek (tf, 44, 4)) != NULL) {
if (memcmp (data, "SCRM", 4) == 0) { if (memcmp (data, "SCRM", 4) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "s3m";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
} }
/* STM */ /* STM */
@ -3274,18 +3404,30 @@ mod_type_find (GstTypeFind * tf, gpointer unused)
return; return;
if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL) if ((stmtype = gst_type_find_peek (tf, 29, 1)) == NULL)
return; return;
if (*id == 0x1A && *stmtype == 2) if (*id == 0x1A && *stmtype == 2) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "stm";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
}
} }
} }
/* AMF */ /* AMF */
if ((data = gst_type_find_peek (tf, 0, 19)) != NULL) { if ((data = gst_type_find_peek (tf, 0, 19)) != NULL) {
if (memcmp (data, "ASYLUM Music Format", 19) == 0) { if (memcmp (data, "ASYLUM Music Format", 19) == 0) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MOD_CAPS); mod_type = "asylum-amf";
return; probability = GST_TYPE_FIND_MAXIMUM;
goto suggest_audio_mod_caps;
} }
} }
suggest_audio_mod_caps:
if (mod_type != NULL) {
GstCaps *caps = gst_caps_new_simple ("audio/x-mod",
"type", G_TYPE_STRING, mod_type, NULL);
gst_type_find_suggest (tf, probability, caps);
gst_caps_unref (caps);
}
} }
/*** application/x-shockwave-flash ***/ /*** application/x-shockwave-flash ***/
@ -5173,8 +5315,8 @@ plugin_init (GstPlugin * plugin)
TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY, TYPE_FIND_REGISTER (plugin, "audio/x-ttafile", GST_RANK_PRIMARY,
tta_type_find, "tta", TTA_CAPS, NULL, NULL); tta_type_find, "tta", TTA_CAPS, NULL, NULL);
TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find, TYPE_FIND_REGISTER (plugin, "audio/x-mod", GST_RANK_SECONDARY, mod_type_find,
"669,amf,dsm,gdm,far,imf,it,med,mod,mtm,okt,sam,s3m,stm,stx,ult,xm", "669,amf,ams,dbm,digi,dmf,dsm,gdm,far,imf,it,j2b,mdl,med,mod,mt2,mtm,"
MOD_CAPS, NULL, NULL); "okt,psm,ptm,sam,s3m,stm,stx,ult,xm", MOD_CAPS, NULL, NULL);
TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find, TYPE_FIND_REGISTER (plugin, "audio/mpeg", GST_RANK_PRIMARY, mp3_type_find,
"mp3,mp2,mp1,mpga", MP3_CAPS, NULL, NULL); "mp3,mp2,mp1,mpga", MP3_CAPS, NULL, NULL);
TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find, TYPE_FIND_REGISTER (plugin, "audio/x-ac3", GST_RANK_PRIMARY, ac3_type_find,