matroska: add temporary webm typefinder

Add webm typefinder just for the release, so webm works for
people whose distros don't patch gst-plugins-base as well.
We'll remove this again after the release.
This commit is contained in:
Tim-Philipp Müller 2010-05-25 15:40:01 +01:00
parent 9bdfc7254a
commit d148ec0ad2

View file

@ -28,9 +28,62 @@
#include "matroska-ids.h" #include "matroska-ids.h"
#include "webm-mux.h" #include "webm-mux.h"
#include <string.h>
/*** video/webm typefinder (temporary) ***/
static GstStaticCaps webm_caps = GST_STATIC_CAPS ("video/webm");
#define WEBM_CAPS (gst_static_caps_get(&webm_caps))
static void
webm_type_find (GstTypeFind * tf, gpointer ununsed)
{
static const guint8 webm_doctype[] = { 'w', 'e', 'b', 'm' };
guint8 *data;
gint len_mask = 0x80, size = 1, n = 1, total;
/* 4 bytes for EBML ID, 1 byte for header length identifier */
data = gst_type_find_peek (tf, 0, 4 + 1);
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 'webm'. 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 (webm_doctype); n++) {
if (!memcmp (&data[n], webm_doctype, sizeof (webm_doctype))) {
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBM_CAPS);
return;
}
}
}
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {
static const gchar *webm_exts[] = { "webm", "weba", "webv", NULL };
gboolean ret; gboolean ret;
gst_matroska_register_tags (); gst_matroska_register_tags ();
@ -40,6 +93,8 @@ plugin_init (GstPlugin * plugin)
GST_TYPE_MATROSKA_MUX); GST_TYPE_MATROSKA_MUX);
ret &= gst_element_register (plugin, "webmmux", GST_RANK_PRIMARY, ret &= gst_element_register (plugin, "webmmux", GST_RANK_PRIMARY,
GST_TYPE_WEBM_MUX); GST_TYPE_WEBM_MUX);
ret &= gst_type_find_register (plugin, "good-webm", GST_RANK_MARGINAL,
webm_type_find, (gchar **) webm_exts, WEBM_CAPS, NULL, NULL);
return ret; return ret;
} }