summaryrefslogtreecommitdiff
path: root/gst/typefind
diff options
context:
space:
mode:
authorJan Schmidt <jan@centricular.com>2016-02-26 02:58:26 +1100
committerJan Schmidt <jan@centricular.com>2016-03-25 00:58:41 +1100
commitecb8d2e023762477f1284d8032309457b6b20be8 (patch)
tree608c9ea57ec2d5f5ff89b015dfeac694bb23e7db /gst/typefind
parent468111ee49418ab970f9cd3a8af5fe1d5657f564 (diff)
downloadgstreamer-plugins-base-ecb8d2e023762477f1284d8032309457b6b20be8.tar.gz
typefind: Add a typefinder for WebVTT files
Diffstat (limited to 'gst/typefind')
-rw-r--r--gst/typefind/gsttypefindfunctions.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c
index 63e1de983..353525ab2 100644
--- a/gst/typefind/gsttypefindfunctions.c
+++ b/gst/typefind/gsttypefindfunctions.c
@@ -4615,6 +4615,41 @@ kate_type_find (GstTypeFind * tf, gpointer private)
}
}
+/*** WEBVTTT subtitles ***/
+static GstStaticCaps webvtt_caps =
+GST_STATIC_CAPS ("application/x-subtitle-vtt, parsed=(boolean)false");
+#define WEBVTT_CAPS (gst_static_caps_get(&webvtt_caps))
+
+static void
+webvtt_type_find (GstTypeFind * tf, gpointer private)
+{
+ const guint8 *data;
+
+ data = gst_type_find_peek (tf, 0, 9);
+
+ if (data == NULL)
+ return;
+
+ /* there might be a UTF-8 BOM at the beginning */
+ if (memcmp (data, "WEBVTT", 6) != 0 && memcmp (data + 3, "WEBVTT", 6) != 0) {
+ return;
+ }
+
+ if (data[0] != 'W') {
+ if (data[0] != 0xef || data[1] != 0xbb || data[2] != 0xbf)
+ return; /* Not a UTF-8 BOM */
+ data += 3;
+ }
+
+ /* After the WEBVTT magic must be one of these chars:
+ * 0x20 (space), 0x9 (tab), 0xa (LF) or 0xd (CR) */
+ if (data[6] != 0x20 && data[6] != 0x9 && data[6] != 0xa && data[6] != 0xd) {
+ return;
+ }
+
+ gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, WEBVTT_CAPS);
+}
+
/*** application/x-ogm-video or audio***/
static GstStaticCaps ogmvideo_caps =
@@ -5737,6 +5772,8 @@ plugin_init (GstPlugin * plugin)
GST_RANK_SECONDARY, "Z", "\037\235", 2, GST_TYPE_FIND_LIKELY);
TYPE_FIND_REGISTER (plugin, "subtitle/x-kate", GST_RANK_MARGINAL,
kate_type_find, NULL, NULL, NULL, NULL);
+ TYPE_FIND_REGISTER (plugin, "application/x-subtitle-vtt", GST_RANK_MARGINAL,
+ webvtt_type_find, "vtt", WEBVTT_CAPS, NULL, NULL);
TYPE_FIND_REGISTER (plugin, "audio/x-flac", GST_RANK_PRIMARY, flac_type_find,
"flac", FLAC_CAPS, NULL, NULL);
TYPE_FIND_REGISTER (plugin, "audio/x-vorbis", GST_RANK_PRIMARY,