gst/typefind/gsttypefindfunctions.c: Improve matroska typefinding for odd-typed headers...

Original commit message from CVS:
2004-01-14  Ronald Bultje  <rbultje@ronald.bitfreak.net>

* gst/typefind/gsttypefindfunctions.c: (matroska_type_find),
(plugin_init):
Improve matroska typefinding for odd-typed headers...
This commit is contained in:
Ronald S. Bultje 2004-01-14 11:10:05 +00:00
parent d323f309eb
commit b00b7ac8f0
2 changed files with 56 additions and 2 deletions

View file

@ -1,3 +1,9 @@
2004-01-14 Ronald Bultje <rbultje@ronald.bitfreak.net>
* gst/typefind/gsttypefindfunctions.c: (matroska_type_find),
(plugin_init):
Improve matroska typefinding for odd-typed headers...
2004-01-14 Ronald Bultje <rbultje@ronald.bitfreak.net>
* gst/matroska/matroska-demux.c: (gst_matroska_demux_add_stream):

View file

@ -863,6 +863,54 @@ tiff_type_find (GstTypeFind *tf, gpointer ununsed)
}
}
/*** video/x-matroska ********************/
static GstStaticCaps matroska_caps = GST_STATIC_CAPS ("video/x-matroska" );
#define MATROSKA_CAPS gst_caps_copy(gst_static_caps_get(&matroska_caps))
static void
matroska_type_find (GstTypeFind *tf, gpointer ununsed)
{
/* 4 bytes for EBML ID, 1 byte for header length identifier */
guint8 *data = gst_type_find_peek (tf, 0, 4 + 1);
gint len_mask = 0x80, size = 1, n = 1, total;
guint8 probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' };
if (!data)
return;
/* ebml header? */
if (data[0] != 0x1A || data[1] != 0x45 ||
data[2] != 0xDF || data[3] != 0xA3)
return;
/* length of header */
total = data[4];
while (size <= 8 && !(total & len_mask)) {
size++;
len_mask >>= 1;
}
if (size > 8)
return;
total &= (len_mask - 1);
while (n < size)
total = (total << 8) | data[4 + n++];
/* get new data for full header, 4 bytes for EBML ID,
* EBML length tag and the actual header */
data = gst_type_find_peek (tf, 0, 4 + size + total);
if (!data)
return;
/* the header must contain the document type 'matroska'. For now,
* we don't parse the whole header but simply check for the
* availability of that array of characters inside the header.
* Not fully fool-proof, but good enough. */
for (n = 4 + size; n < 4 + size + total - sizeof (probe_data); n++)
if (!memcmp (&data[n], probe_data, sizeof (probe_data))) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MATROSKA_CAPS);
break;
}
}
/*** video/x-dv ***************************************************************/
static GstStaticCaps dv_caps = GST_STATIC_CAPS ("video/x-dv, "
@ -1093,8 +1141,8 @@ plugin_init (GstPlugin *plugin)
bmp_type_find, bmp_exts, BMP_CAPS, NULL);
TYPE_FIND_REGISTER (plugin, "image/tiff", GST_RANK_PRIMARY,
tiff_type_find, tiff_exts, TIFF_CAPS, NULL);
TYPE_FIND_REGISTER_START_WITH (plugin, "video/x-matroska", GST_RANK_SECONDARY,
matroska_exts, "\032\105\337\243\223\102\202\210matroska", 16, GST_TYPE_FIND_MAXIMUM);
TYPE_FIND_REGISTER (plugin, "video/x-matroska", GST_RANK_PRIMARY,
matroska_type_find, matroska_exts, MATROSKA_CAPS, NULL);
TYPE_FIND_REGISTER (plugin, "video/x-dv", GST_RANK_SECONDARY,
dv_type_find, dv_exts, DV_CAPS, NULL);
TYPE_FIND_REGISTER_START_WITH (plugin, "audio/x-sid", GST_RANK_MARGINAL,