summaryrefslogtreecommitdiff
path: root/gst/subparse
diff options
context:
space:
mode:
Diffstat (limited to 'gst/subparse')
-rw-r--r--gst/subparse/Makefile.am33
-rw-r--r--gst/subparse/gstssaparse.c384
-rw-r--r--gst/subparse/gstssaparse.h57
-rw-r--r--gst/subparse/gstsubparse.c1888
-rw-r--r--gst/subparse/gstsubparse.h120
-rw-r--r--gst/subparse/mpl2parse.c104
-rw-r--r--gst/subparse/mpl2parse.h32
-rw-r--r--gst/subparse/qttextparse.c453
-rw-r--r--gst/subparse/qttextparse.h36
-rw-r--r--gst/subparse/samiparse.c474
-rw-r--r--gst/subparse/samiparse.h38
-rw-r--r--gst/subparse/tmplayerparse.c156
-rw-r--r--gst/subparse/tmplayerparse.h32
13 files changed, 0 insertions, 3807 deletions
diff --git a/gst/subparse/Makefile.am b/gst/subparse/Makefile.am
deleted file mode 100644
index 4a33bd41..00000000
--- a/gst/subparse/Makefile.am
+++ /dev/null
@@ -1,33 +0,0 @@
-plugin_LTLIBRARIES = libgstsubparse.la
-
-if USE_XML
-SAMIPARSE_SOURCES = samiparse.c samiparse.h
-else
-SAMIPARSE_SOURCES =
-endif
-
-libgstsubparse_la_SOURCES = \
- gstssaparse.c \
- gstssaparse.h \
- gstsubparse.c \
- gstsubparse.h \
- $(SAMIPARSE_SOURCES) \
- tmplayerparse.c \
- tmplayerparse.h \
- mpl2parse.c \
- mpl2parse.h \
- qttextparse.c \
- qttextparse.h
-
-libgstsubparse_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS)
-libgstsubparse_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
-libgstsubparse_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS)
-libgstsubparse_la_LIBTOOLFLAGS = --tag=disable-static
-
-noinst_HEADERS = \
- gstssaparse.h \
- gstsubparse.h \
- samiparse.h \
- tmplayerparse.h \
- mpl2parse.h \
- qttextparse.h
diff --git a/gst/subparse/gstssaparse.c b/gst/subparse/gstssaparse.c
deleted file mode 100644
index d4000770..00000000
--- a/gst/subparse/gstssaparse.c
+++ /dev/null
@@ -1,384 +0,0 @@
-/* GStreamer SSA subtitle parser
- * Copyright (c) 2006 Tim-Philipp Müller <tim centricular net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/* Super-primitive SSA parser - we just want the text and ignore
- * everything else like styles and timing codes etc. for now */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h> /* atoi() */
-#include <string.h>
-
-#include "gstssaparse.h"
-
-GST_DEBUG_CATEGORY_STATIC (ssa_parse_debug);
-#define GST_CAT_DEFAULT ssa_parse_debug
-
-static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("application/x-ssa; application/x-ass")
- );
-
-static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("text/x-pango-markup")
- );
-
-GST_BOILERPLATE (GstSsaParse, gst_ssa_parse, GstElement, GST_TYPE_ELEMENT);
-
-static GstStateChangeReturn gst_ssa_parse_change_state (GstElement *
- element, GstStateChange transition);
-static gboolean gst_ssa_parse_setcaps (GstPad * sinkpad, GstCaps * caps);
-static gboolean gst_ssa_parse_src_event (GstPad * pad, GstEvent * event);
-static gboolean gst_ssa_parse_sink_event (GstPad * pad, GstEvent * event);
-static GstFlowReturn gst_ssa_parse_chain (GstPad * sinkpad, GstBuffer * buf);
-
-static void
-gst_ssa_parse_base_init (gpointer klass)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
- static GstElementDetails ssa_parse_details = {
- "SSA Subtitle Parser",
- "Codec/Parser/Subtitle",
- "Parses SSA subtitle streams",
- "Tim-Philipp Müller <tim centricular net>"
- };
-
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&sink_templ));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&src_templ));
- gst_element_class_set_details (element_class, &ssa_parse_details);
-
- GST_DEBUG_CATEGORY_INIT (ssa_parse_debug, "ssaparse", 0,
- "SSA subtitle parser");
-}
-
-static void
-gst_ssa_parse_dispose (GObject * object)
-{
- GstSsaParse *parse = GST_SSA_PARSE (object);
-
- g_free (parse->ini);
- parse->ini = NULL;
-
- GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
-}
-
-static void
-gst_ssa_parse_init (GstSsaParse * parse, GstSsaParseClass * klass)
-{
- parse->sinkpad = gst_pad_new_from_static_template (&sink_templ, "sink");
- gst_pad_set_setcaps_function (parse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_ssa_parse_setcaps));
- gst_pad_set_chain_function (parse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_ssa_parse_chain));
- gst_pad_set_event_function (parse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_ssa_parse_sink_event));
- gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
-
- parse->srcpad = gst_pad_new_from_static_template (&src_templ, "src");
- gst_pad_set_event_function (parse->srcpad,
- GST_DEBUG_FUNCPTR (gst_ssa_parse_src_event));
- gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
- gst_pad_use_fixed_caps (parse->srcpad);
- gst_pad_set_caps (parse->srcpad,
- gst_static_pad_template_get_caps (&src_templ));
-
- parse->ini = NULL;
- parse->framed = FALSE;
- parse->send_tags = FALSE;
-}
-
-static void
-gst_ssa_parse_class_init (GstSsaParseClass * klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-
- object_class->dispose = gst_ssa_parse_dispose;
-
- element_class->change_state = GST_DEBUG_FUNCPTR (gst_ssa_parse_change_state);
-}
-
-static gboolean
-gst_ssa_parse_src_event (GstPad * pad, GstEvent * event)
-{
- return gst_pad_event_default (pad, event);
-}
-
-static gboolean
-gst_ssa_parse_sink_event (GstPad * pad, GstEvent * event)
-{
- return gst_pad_event_default (pad, event);
-}
-
-static gboolean
-gst_ssa_parse_setcaps (GstPad * sinkpad, GstCaps * caps)
-{
- GstSsaParse *parse = GST_SSA_PARSE (GST_PAD_PARENT (sinkpad));
- const GValue *val;
- GstStructure *s;
- const guchar bom_utf8[] = { 0xEF, 0xBB, 0xBF };
- GstBuffer *priv;
- gchar *data;
- guint size;
-
- s = gst_caps_get_structure (caps, 0);
- val = gst_structure_get_value (s, "codec_data");
- if (val == NULL) {
- parse->framed = FALSE;
- GST_ERROR ("Only SSA subtitles embedded in containers are supported");
- return FALSE;
- }
-
- parse->framed = TRUE;
- parse->send_tags = TRUE;
-
- priv = (GstBuffer *) gst_value_get_mini_object (val);
- g_return_val_if_fail (priv != NULL, FALSE);
-
- gst_buffer_ref (priv);
-
- data = (gchar *) GST_BUFFER_DATA (priv);
- size = GST_BUFFER_SIZE (priv);
- /* skip UTF-8 BOM */
- if (size >= 3 && memcmp (data, bom_utf8, 3) == 0) {
- data += 3;
- size -= 3;
- }
-
- if (!strstr (data, "[Script Info]")) {
- GST_WARNING_OBJECT (parse, "Invalid Init section - no Script Info header");
- gst_buffer_unref (priv);
- return FALSE;
- }
-
- if (!g_utf8_validate (data, size, NULL)) {
- GST_WARNING_OBJECT (parse, "Init section is not valid UTF-8");
- gst_buffer_unref (priv);
- return FALSE;
- }
-
- /* FIXME: parse initial section */
- parse->ini = g_strndup (data, size);
- GST_LOG_OBJECT (parse, "Init section:\n%s", parse->ini);
-
- gst_buffer_unref (priv);
-
- return TRUE;
-}
-
-static gboolean
-gst_ssa_parse_remove_override_codes (GstSsaParse * parse, gchar * txt)
-{
- gchar *t, *end;
- gboolean removed_any = FALSE;
-
- while ((t = strchr (txt, '{'))) {
- end = strchr (txt, '}');
- if (end == NULL) {
- GST_WARNING_OBJECT (parse, "Missing { for style override code");
- return removed_any;
- }
- /* move terminating NUL character forward as well */
- g_memmove (t, end + 1, strlen (end + 1) + 1);
- removed_any = TRUE;
- }
-
- /* these may occur outside of curly brackets. We don't handle the different
- * wrapping modes yet, so just remove these markers from the text for now */
- while ((t = strstr (txt, "\\n"))) {
- t[0] = ' ';
- t[1] = '\n';
- }
- while ((t = strstr (txt, "\\N"))) {
- t[0] = ' ';
- t[1] = '\n';
- }
- while ((t = strstr (txt, "\\h"))) {
- t[0] = ' ';
- t[1] = ' ';
- }
-
- return removed_any;
-}
-
-/**
- * gst_ssa_parse_push_line:
- * @parse: caller element
- * @txt: text to push
- * @start: timestamp for the buffer
- * @duration: duration for the buffer
- *
- * Parse the text in a buffer with the given properties and
- * push it to the srcpad of the @parse element
- *
- * Returns: result of the push of the created buffer
- */
-static GstFlowReturn
-gst_ssa_parse_push_line (GstSsaParse * parse, gchar * txt,
- GstClockTime start, GstClockTime duration)
-{
- GstFlowReturn ret;
- GstBuffer *buf;
- gchar *t, *escaped;
- gint num, i, len;
-
- num = atoi (txt);
- GST_LOG_OBJECT (parse, "Parsing line #%d at %" GST_TIME_FORMAT,
- num, GST_TIME_ARGS (start));
-
- /* skip all non-text fields before the actual text */
- t = txt;
- for (i = 0; i < 8; ++i) {
- t = strchr (t, ',');
- if (t == NULL)
- return GST_FLOW_ERROR;
- ++t;
- }
-
- GST_LOG_OBJECT (parse, "Text : %s", t);
-
- if (gst_ssa_parse_remove_override_codes (parse, t)) {
- GST_LOG_OBJECT (parse, "Clean: %s", t);
- }
-
- /* we claim to output pango markup, so we must escape the
- * text even if we don't actually use any pango markup yet */
- escaped = g_markup_printf_escaped ("%s", t);
-
- len = strlen (escaped);
-
- /* allocate enough for a terminating NUL, but don't include it in buf size */
- buf = gst_buffer_new_and_alloc (len + 1);
- memcpy (GST_BUFFER_DATA (buf), escaped, len + 1);
- GST_BUFFER_SIZE (buf) = len;
- g_free (escaped);
-
- GST_BUFFER_TIMESTAMP (buf) = start;
- GST_BUFFER_DURATION (buf) = duration;
-
- gst_buffer_set_caps (buf, GST_PAD_CAPS (parse->srcpad));
-
- GST_LOG_OBJECT (parse, "Pushing buffer with timestamp %" GST_TIME_FORMAT
- " and duration %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
- GST_TIME_ARGS (duration));
-
- ret = gst_pad_push (parse->srcpad, buf);
-
- if (ret != GST_FLOW_OK) {
- GST_DEBUG_OBJECT (parse, "Push of text '%s' returned flow %s", txt,
- gst_flow_get_name (ret));
- }
-
- return ret;
-}
-
-static GstFlowReturn
-gst_ssa_parse_chain (GstPad * sinkpad, GstBuffer * buf)
-{
- GstFlowReturn ret;
- GstSsaParse *parse = GST_SSA_PARSE (GST_PAD_PARENT (sinkpad));
- GstClockTime ts;
- gchar *txt;
-
- if (G_UNLIKELY (!parse->framed))
- goto not_framed;
-
- if (G_UNLIKELY (parse->send_tags)) {
- GstTagList *tags;
-
- tags = gst_tag_list_new ();
- gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_SUBTITLE_CODEC,
- "SubStation Alpha", NULL);
- gst_element_found_tags_for_pad (GST_ELEMENT (parse), parse->srcpad, tags);
- parse->send_tags = FALSE;
- }
-
- /* make double-sure it's 0-terminated and all */
- txt = g_strndup ((gchar *) GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
- if (txt == NULL)
- goto empty_text;
-
- ts = GST_BUFFER_TIMESTAMP (buf);
- ret = gst_ssa_parse_push_line (parse, txt, ts, GST_BUFFER_DURATION (buf));
-
- if (ret != GST_FLOW_OK && GST_CLOCK_TIME_IS_VALID (ts)) {
- /* just advance time without sending anything */
- gst_pad_push_event (parse->srcpad,
- gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, ts, -1, ts));
- ret = GST_FLOW_OK;
- }
-
- gst_buffer_unref (buf);
- g_free (txt);
-
- return ret;
-
-/* ERRORS */
-not_framed:
- {
- GST_ELEMENT_ERROR (parse, STREAM, FORMAT, (NULL),
- ("Only SSA subtitles embedded in containers are supported"));
- gst_buffer_unref (buf);
- return GST_FLOW_NOT_NEGOTIATED;
- }
-empty_text:
- {
- GST_ELEMENT_WARNING (parse, STREAM, FORMAT, (NULL),
- ("Received empty subtitle"));
- gst_buffer_unref (buf);
- return GST_FLOW_OK;
- }
-}
-
-static GstStateChangeReturn
-gst_ssa_parse_change_state (GstElement * element, GstStateChange transition)
-{
- GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
- GstSsaParse *parse = GST_SSA_PARSE (element);
-
- switch (transition) {
- case GST_STATE_CHANGE_READY_TO_PAUSED:
- break;
- default:
- break;
- }
-
- ret = parent_class->change_state (element, transition);
- if (ret == GST_STATE_CHANGE_FAILURE)
- return ret;
-
- switch (transition) {
- case GST_STATE_CHANGE_PAUSED_TO_READY:
- g_free (parse->ini);
- parse->ini = NULL;
- parse->framed = FALSE;
- break;
- default:
- break;
- }
-
- return ret;
-}
diff --git a/gst/subparse/gstssaparse.h b/gst/subparse/gstssaparse.h
deleted file mode 100644
index 518c3cd6..00000000
--- a/gst/subparse/gstssaparse.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* GStreamer SSA subtitle parser
- * Copyright (c) 2006 Tim-Philipp Müller <tim centricular net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GST_SSA_PARSE_H__
-#define __GST_SSA_PARSE_H__
-
-#include <gst/gst.h>
-
-G_BEGIN_DECLS
-
-#define GST_TYPE_SSA_PARSE (gst_ssa_parse_get_type ())
-#define GST_SSA_PARSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SSA_PARSE, GstSsaParse))
-#define GST_SSA_PARSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_SSA_PARSE, GstSsaParseClass))
-#define GST_IS_SSA_PARSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SSA_PARSE))
-#define GST_IS_SSA_PARSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_SSA_PARSE))
-
-typedef struct _GstSsaParse GstSsaParse;
-typedef struct _GstSsaParseClass GstSsaParseClass;
-
-struct _GstSsaParse {
- GstElement element;
-
- GstPad *sinkpad;
- GstPad *srcpad;
-
- gboolean framed;
- gboolean send_tags;
-
- gchar *ini;
-};
-
-struct _GstSsaParseClass {
- GstElementClass parent_class;
-};
-
-GType gst_ssa_parse_get_type (void);
-
-G_END_DECLS
-
-#endif /* __GST_SSA_PARSE_H__ */
-
diff --git a/gst/subparse/gstsubparse.c b/gst/subparse/gstsubparse.c
deleted file mode 100644
index b73b45c7..00000000
--- a/gst/subparse/gstsubparse.c
+++ /dev/null
@@ -1,1888 +0,0 @@
-/* GStreamer
- * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
- * Copyright (C) 2004 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
- * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <glib.h>
-
-#include "gstsubparse.h"
-#include "gstssaparse.h"
-#include "samiparse.h"
-#include "tmplayerparse.h"
-#include "mpl2parse.h"
-#include "qttextparse.h"
-
-GST_DEBUG_CATEGORY (sub_parse_debug);
-
-#define DEFAULT_ENCODING NULL
-
-enum
-{
- PROP_0,
- PROP_ENCODING,
- PROP_VIDEOFPS
-};
-
-static void
-gst_sub_parse_set_property (GObject * object, guint prop_id,
- const GValue * value, GParamSpec * pspec);
-static void
-gst_sub_parse_get_property (GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec);
-
-
-static const GstElementDetails sub_parse_details =
-GST_ELEMENT_DETAILS ("Subtitle parser",
- "Codec/Parser/Subtitle",
- "Parses subtitle (.sub) files into text streams",
- "Gustavo J. A. M. Carneiro <gjc@inescporto.pt>\n"
- "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
-
-#ifndef GST_DISABLE_XML
-static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("application/x-subtitle; application/x-subtitle-sami; "
- "application/x-subtitle-tmplayer; application/x-subtitle-mpl2; "
- "application/x-subtitle-dks; application/x-subtitle-qttext")
- );
-#else
-static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("application/x-subtitle; application/x-subtitle-dks; "
- "application/x-subtitle-tmplayer; application/x-subtitle-mpl2; "
- "application/x-subtitle-qttext")
- );
-#endif
-
-static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("text/plain; text/x-pango-markup")
- );
-
-static void gst_sub_parse_base_init (GstSubParseClass * klass);
-static void gst_sub_parse_class_init (GstSubParseClass * klass);
-static void gst_sub_parse_init (GstSubParse * subparse);
-
-static gboolean gst_sub_parse_src_event (GstPad * pad, GstEvent * event);
-static gboolean gst_sub_parse_src_query (GstPad * pad, GstQuery * query);
-static gboolean gst_sub_parse_sink_event (GstPad * pad, GstEvent * event);
-
-static GstStateChangeReturn gst_sub_parse_change_state (GstElement * element,
- GstStateChange transition);
-
-static GstFlowReturn gst_sub_parse_chain (GstPad * sinkpad, GstBuffer * buf);
-
-static GstElementClass *parent_class = NULL;
-
-GType
-gst_sub_parse_get_type (void)
-{
- static GType sub_parse_type = 0;
-
- if (!sub_parse_type) {
- static const GTypeInfo sub_parse_info = {
- sizeof (GstSubParseClass),
- (GBaseInitFunc) gst_sub_parse_base_init,
- NULL,
- (GClassInitFunc) gst_sub_parse_class_init,
- NULL,
- NULL,
- sizeof (GstSubParse),
- 0,
- (GInstanceInitFunc) gst_sub_parse_init,
- };
-
- sub_parse_type = g_type_register_static (GST_TYPE_ELEMENT,
- "GstSubParse", &sub_parse_info, 0);
- }
-
- return sub_parse_type;
-}
-
-static void
-gst_sub_parse_base_init (GstSubParseClass * klass)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&sink_templ));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&src_templ));
- gst_element_class_set_details (element_class, &sub_parse_details);
-}
-
-static void
-gst_sub_parse_dispose (GObject * object)
-{
- GstSubParse *subparse = GST_SUBPARSE (object);
-
- GST_DEBUG_OBJECT (subparse, "cleaning up subtitle parser");
-
- switch (subparse->parser_type) {
- case GST_SUB_PARSE_FORMAT_QTTEXT:
- qttext_context_deinit (&subparse->state);
- break;
-#ifndef GST_DISABLE_XML
- case GST_SUB_PARSE_FORMAT_SAMI:
- sami_context_deinit (&subparse->state);
- break;
-#endif
- default:
- break;
- }
-
- if (subparse->encoding) {
- g_free (subparse->encoding);
- subparse->encoding = NULL;
- }
-
- if (subparse->detected_encoding) {
- g_free (subparse->detected_encoding);
- subparse->detected_encoding = NULL;
- }
-
- if (subparse->adapter) {
- g_object_unref (subparse->adapter);
- subparse->adapter = NULL;
- }
-
- if (subparse->textbuf) {
- g_string_free (subparse->textbuf, TRUE);
- subparse->textbuf = NULL;
- }
-
- GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
-}
-
-static void
-gst_sub_parse_class_init (GstSubParseClass * klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->dispose = gst_sub_parse_dispose;
- object_class->set_property = gst_sub_parse_set_property;
- object_class->get_property = gst_sub_parse_get_property;
-
- element_class->change_state = gst_sub_parse_change_state;
-
- g_object_class_install_property (object_class, PROP_ENCODING,
- g_param_spec_string ("subtitle-encoding", "subtitle charset encoding",
- "Encoding to assume if input subtitles are not in UTF-8 or any other "
- "Unicode encoding. If not set, the GST_SUBTITLE_ENCODING environment "
- "variable will be checked for an encoding to use. If that is not set "
- "either, ISO-8859-15 will be assumed.", DEFAULT_ENCODING,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class, PROP_VIDEOFPS,
- gst_param_spec_fraction ("video-fps", "Video framerate",
- "Framerate of the video stream. This is needed by some subtitle "
- "formats to synchronize subtitles and video properly. If not set "
- "and the subtitle format requires it subtitles may be out of sync.",
- 0, 1, G_MAXINT, 1, 24000, 1001, G_PARAM_READWRITE));
-}
-
-static void
-gst_sub_parse_init (GstSubParse * subparse)
-{
- subparse->sinkpad = gst_pad_new_from_static_template (&sink_templ, "sink");
- gst_pad_set_chain_function (subparse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_sub_parse_chain));
- gst_pad_set_event_function (subparse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_sub_parse_sink_event));
- gst_element_add_pad (GST_ELEMENT (subparse), subparse->sinkpad);
-
- subparse->srcpad = gst_pad_new_from_static_template (&src_templ, "src");
- gst_pad_set_event_function (subparse->srcpad,
- GST_DEBUG_FUNCPTR (gst_sub_parse_src_event));
- gst_pad_set_query_function (subparse->srcpad,
- GST_DEBUG_FUNCPTR (gst_sub_parse_src_query));
- gst_element_add_pad (GST_ELEMENT (subparse), subparse->srcpad);
-
- subparse->textbuf = g_string_new (NULL);
- subparse->parser_type = GST_SUB_PARSE_FORMAT_UNKNOWN;
- subparse->flushing = FALSE;
- gst_segment_init (&subparse->segment, GST_FORMAT_TIME);
- subparse->need_segment = TRUE;
- subparse->encoding = g_strdup (DEFAULT_ENCODING);
- subparse->detected_encoding = NULL;
- subparse->adapter = gst_adapter_new ();
-
- subparse->fps_n = 24000;
- subparse->fps_d = 1001;
-}
-
-/*
- * Source pad functions.
- */
-
-static gboolean
-gst_sub_parse_src_query (GstPad * pad, GstQuery * query)
-{
- GstSubParse *self = GST_SUBPARSE (gst_pad_get_parent (pad));
- gboolean ret = FALSE;
-
- GST_DEBUG ("Handling %s query", GST_QUERY_TYPE_NAME (query));
-
- switch (GST_QUERY_TYPE (query)) {
- case GST_QUERY_POSITION:{
- GstFormat fmt;
-
- gst_query_parse_position (query, &fmt, NULL);
- if (fmt != GST_FORMAT_TIME) {
- ret = gst_pad_peer_query (self->sinkpad, query);
- } else {
- ret = TRUE;
- gst_query_set_position (query, GST_FORMAT_TIME,
- self->segment.last_stop);
- }
- }
- case GST_QUERY_SEEKING:
- {
- GstFormat fmt;
- gboolean seekable = FALSE;
-
- ret = TRUE;
-
- gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
- if (fmt == GST_FORMAT_TIME) {
- GstQuery *peerquery = gst_query_new_seeking (GST_FORMAT_BYTES);
-
- seekable = gst_pad_peer_query (self->sinkpad, peerquery);
- if (seekable)
- gst_query_parse_seeking (peerquery, NULL, &seekable, NULL, NULL);
- gst_query_unref (peerquery);
- }
-
- gst_query_set_seeking (query, fmt, seekable, seekable ? 0 : -1, -1);
-
- break;
- }
- default:
- ret = gst_pad_peer_query (self->sinkpad, query);
- break;
- }
-
- gst_object_unref (self);
-
- return ret;
-}
-
-static gboolean
-gst_sub_parse_src_event (GstPad * pad, GstEvent * event)
-{
- GstSubParse *self = GST_SUBPARSE (gst_pad_get_parent (pad));
- gboolean ret = FALSE;
-
- GST_DEBUG ("Handling %s event", GST_EVENT_TYPE_NAME (event));
-
- switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_SEEK:
- {
- GstFormat format;
- GstSeekType start_type, stop_type;
- gint64 start, stop;
- gdouble rate;
- gboolean update;
-
- gst_event_parse_seek (event, &rate, &format, &self->segment_flags,
- &start_type, &start, &stop_type, &stop);
-
- if (format != GST_FORMAT_TIME) {
- GST_WARNING_OBJECT (self, "we only support seeking in TIME format");
- gst_event_unref (event);
- goto beach;
- }
-
- /* Convert that seek to a seeking in bytes at position 0,
- FIXME: could use an index */
- ret = gst_pad_push_event (self->sinkpad,
- gst_event_new_seek (rate, GST_FORMAT_BYTES, self->segment_flags,
- GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, 0));
-
- if (ret) {
- /* Apply the seek to our segment */
- gst_segment_set_seek (&self->segment, rate, format, self->segment_flags,
- start_type, start, stop_type, stop, &update);
-
- GST_DEBUG_OBJECT (self, "segment after seek: %" GST_SEGMENT_FORMAT,
- &self->segment);
-
- self->next_offset = 0;
-
- self->need_segment = TRUE;
- } else {
- GST_WARNING_OBJECT (self, "seek to 0 bytes failed");
- }
-
- gst_event_unref (event);
- break;
- }
- default:
- ret = gst_pad_event_default (pad, event);
- break;
- }
-
-beach:
- gst_object_unref (self);
-
- return ret;
-}
-
-static void
-gst_sub_parse_set_property (GObject * object, guint prop_id,
- const GValue * value, GParamSpec * pspec)
-{
- GstSubParse *subparse = GST_SUBPARSE (object);
-
- GST_OBJECT_LOCK (subparse);
- switch (prop_id) {
- case PROP_ENCODING:
- g_free (subparse->encoding);
- subparse->encoding = g_value_dup_string (value);
- GST_LOG_OBJECT (object, "subtitle encoding set to %s",
- GST_STR_NULL (subparse->encoding));
- break;
- case PROP_VIDEOFPS:
- {
- subparse->fps_n = gst_value_get_fraction_numerator (value);
- subparse->fps_d = gst_value_get_fraction_denominator (value);
- GST_DEBUG_OBJECT (object, "video framerate set to %d/%d", subparse->fps_n,
- subparse->fps_d);
-
- if (!subparse->state.have_internal_fps) {
- subparse->state.fps_n = subparse->fps_n;
- subparse->state.fps_d = subparse->fps_d;
- }
- break;
- }
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
- GST_OBJECT_UNLOCK (subparse);
-}
-
-static void
-gst_sub_parse_get_property (GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec)
-{
- GstSubParse *subparse = GST_SUBPARSE (object);
-
- GST_OBJECT_LOCK (subparse);
- switch (prop_id) {
- case PROP_ENCODING:
- g_value_set_string (value, subparse->encoding);
- break;
- case PROP_VIDEOFPS:
- gst_value_set_fraction (value, subparse->fps_n, subparse->fps_d);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
- GST_OBJECT_UNLOCK (subparse);
-}
-
-static gchar *
-gst_sub_parse_get_format_description (GstSubParseFormat format)
-{
- switch (format) {
- case GST_SUB_PARSE_FORMAT_MDVDSUB:
- return "MicroDVD";
- case GST_SUB_PARSE_FORMAT_SUBRIP:
- return "SubRip";
- case GST_SUB_PARSE_FORMAT_MPSUB:
- return "MPSub";
- case GST_SUB_PARSE_FORMAT_SAMI:
- return "SAMI";
- case GST_SUB_PARSE_FORMAT_TMPLAYER:
- return "TMPlayer";
- case GST_SUB_PARSE_FORMAT_MPL2:
- return "MPL2";
- case GST_SUB_PARSE_FORMAT_SUBVIEWER:
- return "SubViewer";
- case GST_SUB_PARSE_FORMAT_DKS:
- return "DKS";
- case GST_SUB_PARSE_FORMAT_QTTEXT:
- return "QTtext";
- default:
- case GST_SUB_PARSE_FORMAT_UNKNOWN:
- break;
- }
- return NULL;
-}
-
-static gchar *
-gst_convert_to_utf8 (const gchar * str, gsize len, const gchar * encoding,
- gsize * consumed, GError ** err)
-{
- gchar *ret = NULL;
-
- *consumed = 0;
- ret =
- g_convert_with_fallback (str, len, "UTF-8", encoding, "*", consumed, NULL,
- err);
- if (ret == NULL)
- return ret;
-
- /* + 3 to skip UTF-8 BOM if it was added */
- len = strlen (ret);
- if (len >= 3 && (guint8) ret[0] == 0xEF && (guint8) ret[1] == 0xBB
- && (guint8) ret[2] == 0xBF)
- g_memmove (ret, ret + 3, len + 1 - 3);
-
- return ret;
-}
-
-static gchar *
-detect_encoding (const gchar * str, gsize len)
-{
- if (len >= 3 && (guint8) str[0] == 0xEF && (guint8) str[1] == 0xBB
- && (guint8) str[2] == 0xBF)
- return g_strdup ("UTF-8");
-
- if (len >= 2 && (guint8) str[0] == 0xFE && (guint8) str[1] == 0xFF)
- return g_strdup ("UTF-16BE");
-
- if (len >= 2 && (guint8) str[0] == 0xFF && (guint8) str[1] == 0xFE)
- return g_strdup ("UTF-16LE");
-
- if (len >= 4 && (guint8) str[0] == 0x00 && (guint8) str[1] == 0x00
- && (guint8) str[2] == 0xFE && (guint8) str[3] == 0xFF)
- return g_strdup ("UTF-32BE");
-
- if (len >= 4 && (guint8) str[0] == 0xFF && (guint8) str[1] == 0xFE
- && (guint8) str[2] == 0x00 && (guint8) str[3] == 0x00)
- return g_strdup ("UTF-32LE");
-
- return NULL;
-}
-
-static gchar *
-convert_encoding (GstSubParse * self, const gchar * str, gsize len,
- gsize * consumed)
-{
- const gchar *encoding;
- GError *err = NULL;
- gchar *ret = NULL;
-
- *consumed = 0;
-
- /* First try any detected encoding */
- if (self->detected_encoding) {
- ret =
- gst_convert_to_utf8 (str, len, self->detected_encoding, consumed, &err);
-
- if (!err)
- return ret;
-
- GST_WARNING_OBJECT (self, "could not convert string from '%s' to UTF-8: %s",
- self->detected_encoding, err->message);
- g_free (self->detected_encoding);
- self->detected_encoding = NULL;
- g_error_free (err);
- }
-
- /* Otherwise check if it's UTF8 */
- if (self->valid_utf8) {
- if (g_utf8_validate (str, len, NULL)) {
- GST_LOG_OBJECT (self, "valid UTF-8, no conversion needed");
- *consumed = len;
- return g_strndup (str, len);
- }
- GST_INFO_OBJECT (self, "invalid UTF-8!");
- self->valid_utf8 = FALSE;
- }
-
- /* Else try fallback */
- encoding = self->encoding;
- if (encoding == NULL || *encoding == '\0') {
- encoding = g_getenv ("GST_SUBTITLE_ENCODING");
- }
- if (encoding == NULL || *encoding == '\0') {
- /* if local encoding is UTF-8 and no encoding specified
- * via the environment variable, assume ISO-8859-15 */
- if (g_get_charset (&encoding)) {
- encoding = "ISO-8859-15";
- }
- }
-
- ret = gst_convert_to_utf8 (str, len, encoding, consumed, &err);
-
- if (err) {
- GST_WARNING_OBJECT (self, "could not convert string from '%s' to UTF-8: %s",
- encoding, err->message);
- g_error_free (err);
-
- /* invalid input encoding, fall back to ISO-8859-15 (always succeeds) */
- ret = gst_convert_to_utf8 (str, len, "ISO-8859-15", consumed, NULL);
- }
-
- GST_LOG_OBJECT (self,
- "successfully converted %" G_GSIZE_FORMAT " characters from %s to UTF-8"
- "%s", len, encoding, (err) ? " , using ISO-8859-15 as fallback" : "");
-
- return ret;
-}
-
-static gchar *
-get_next_line (GstSubParse * self)
-{
- char *line = NULL;
- const char *line_end;
- int line_len;
- gboolean have_r = FALSE;
-
- line_end = strchr (self->textbuf->str, '\n');
-
- if (!line_end) {
- /* end-of-line not found; return for more data */
- return NULL;
- }
-
- /* get rid of '\r' */
- if (line_end != self->textbuf->str && *(line_end - 1) == '\r') {
- line_end--;
- have_r = TRUE;
- }
-
- line_len = line_end - self->textbuf->str;
- line = g_strndup (self->textbuf->str, line_len);
- self->textbuf = g_string_erase (self->textbuf, 0,
- line_len + (have_r ? 2 : 1));
- return line;
-}
-
-static gchar *
-parse_mdvdsub (ParserState * state, const gchar * line)
-{
- const gchar *line_split;
- gchar *line_chunk;
- guint start_frame, end_frame;
- gint64 clip_start = 0, clip_stop = 0;
- gboolean in_seg = FALSE;
- GString *markup;
- gchar *ret;
-
- /* style variables */
- gboolean italic;
- gboolean bold;
- guint fontsize;
- gdouble fps = 0.0;
-
- if (sscanf (line, "{%u}{%u}", &start_frame, &end_frame) != 2) {
- g_warning ("Parse of the following line, assumed to be in microdvd .sub"
- " format, failed:\n%s", line);
- return NULL;
- }
-
- /* skip the {%u}{%u} part */
- line = strchr (line, '}') + 1;
- line = strchr (line, '}') + 1;
-
- /* see if there's a first line with a framerate */
- if (start_frame == 1 && end_frame == 1) {
- gchar *rest, *end = NULL;
-
- rest = g_strdup (line);
- g_strdelimit (rest, ",", '.');
- fps = g_ascii_strtod (rest, &end);
- if (end != rest) {
- gst_util_double_to_fraction (fps, &state->fps_n, &state->fps_d);
- GST_INFO ("framerate from file: %d/%d ('%s')", state->fps_n,
- state->fps_d, rest);
- }
- g_free (rest);
- return NULL;
- }
-
- state->start_time =
- gst_util_uint64_scale (start_frame, GST_SECOND * state->fps_d,
- state->fps_n);
- state->duration =
- gst_util_uint64_scale (end_frame - start_frame, GST_SECOND * state->fps_d,
- state->fps_n);
-
- /* Check our segment start/stop */
- in_seg = gst_segment_clip (state->segment, GST_FORMAT_TIME,
- state->start_time, state->start_time + state->duration, &clip_start,
- &clip_stop);
-
- /* No need to parse that text if it's out of segment */
- if (in_seg) {
- state->start_time = clip_start;
- state->duration = clip_stop - clip_start;
- } else {
- return NULL;
- }
-
- markup = g_string_new (NULL);
- while (1) {
- italic = FALSE;
- bold = FALSE;
- fontsize = 0;
- /* parse style markup */
- if (strncmp (line, "{y:i}", 5) == 0) {
- italic = TRUE;
- line = strchr (line, '}') + 1;
- }
- if (strncmp (line, "{y:b}", 5) == 0) {
- bold = TRUE;
- line = strchr (line, '}') + 1;
- }
- if (sscanf (line, "{s:%u}", &fontsize) == 1) {
- line = strchr (line, '}') + 1;
- }
- /* forward slashes at beginning/end signify italics too */
- if (g_str_has_prefix (line, "/")) {
- italic = TRUE;
- ++line;
- }
- if ((line_split = strchr (line, '|')))
- line_chunk = g_markup_escape_text (line, line_split - line);
- else
- line_chunk = g_markup_escape_text (line, strlen (line));
-
- /* Remove italics markers at end of line/stanza (CHECKME: are end slashes
- * always at the end of a line or can they span multiple lines?) */
- if (g_str_has_suffix (line_chunk, "/")) {
- line_chunk[strlen (line_chunk) - 1] = '\0';
- }
-
- markup = g_string_append (markup, "<span");
- if (italic)
- g_string_append (markup, " style=\"italic\"");
- if (bold)
- g_string_append (markup, " weight=\"bold\"");
- if (fontsize)
- g_string_append_printf (markup, " size=\"%u\"", fontsize * 1000);
- g_string_append_printf (markup, ">%s</span>", line_chunk);
- g_free (line_chunk);
- if (line_split) {
- g_string_append (markup, "\n");
- line = line_split + 1;
- } else {
- break;
- }
- }
- ret = markup->str;
- g_string_free (markup, FALSE);
- GST_DEBUG ("parse_mdvdsub returning (%f+%f): %s",
- state->start_time / (double) GST_SECOND,
- state->duration / (double) GST_SECOND, ret);
- return ret;
-}
-
-static void
-strip_trailing_newlines (gchar * txt)
-{
- if (txt) {
- guint len;
-
- len = strlen (txt);
- while (len > 1 && txt[len - 1] == '\n') {
- txt[len - 1] = '\0';
- --len;
- }
- }
-}
-
-/* we want to escape text in general, but retain basic markup like
- * <i></i>, <u></u>, and <b></b>. The easiest and safest way is to
- * just unescape a white list of allowed markups again after
- * escaping everything (the text between these simple markers isn't
- * necessarily escaped, so it seems best to do it like this) */
-static void
-subrip_unescape_formatting (gchar * txt)
-{
- gchar *pos;
-
- for (pos = txt; pos != NULL && *pos != '\0'; ++pos) {
- if (g_ascii_strncasecmp (pos, "&lt;u&gt;", 9) == 0 ||
- g_ascii_strncasecmp (pos, "&lt;i&gt;", 9) == 0 ||
- g_ascii_strncasecmp (pos, "&lt;b&gt;", 9) == 0) {
- pos[0] = '<';
- pos[1] = g_ascii_tolower (pos[4]);
- pos[2] = '>';
- /* move NUL terminator as well */
- g_memmove (pos + 3, pos + 9, strlen (pos + 9) + 1);
- pos += 2;
- }
- }
-
- for (pos = txt; pos != NULL && *pos != '\0'; ++pos) {
- if (g_ascii_strncasecmp (pos, "&lt;/u&gt;", 10) == 0 ||
- g_ascii_strncasecmp (pos, "&lt;/i&gt;", 10) == 0 ||
- g_ascii_strncasecmp (pos, "&lt;/b&gt;", 10) == 0) {
- pos[0] = '<';
- pos[1] = '/';
- pos[2] = g_ascii_tolower (pos[5]);
- pos[3] = '>';
- /* move NUL terminator as well */
- g_memmove (pos + 4, pos + 10, strlen (pos + 10) + 1);
- pos += 3;
- }
- }
-}
-
-
-static gboolean
-subrip_remove_unhandled_tag (gchar * start, gchar * stop)
-{
- gchar *tag, saved;
-
- tag = start + strlen ("&lt;");
- if (*tag == '/')
- ++tag;
-
- if (g_ascii_tolower (*tag) < 'a' || g_ascii_tolower (*tag) > 'z')
- return FALSE;
-
- saved = *stop;
- *stop = '\0';
- GST_LOG ("removing unhandled tag '%s'", start);
- *stop = saved;
- g_memmove (start, stop, strlen (stop) + 1);
- return TRUE;
-}
-
-/* remove tags we haven't explicitly allowed earlier on, like font tags
- * for example */
-static void
-subrip_remove_unhandled_tags (gchar * txt)
-{
- gchar *pos, *gt;
-
- for (pos = txt; pos != NULL && *pos != '\0'; ++pos) {
- if (strncmp (pos, "&lt;", 4) == 0 && (gt = strstr (pos + 4, "&gt;"))) {
- if (subrip_remove_unhandled_tag (pos, gt + strlen ("&gt;")))
- --pos;
- }
- }
-}
-
-/* we only allow <i>, <u> and <b>, so let's take a simple approach. This code
- * assumes the input has been escaped and subrip_unescape_formatting() has then
- * been run over the input! This function adds missing closing markup tags and
- * removes broken closing tags for tags that have never been opened. */
-static void
-subrip_fix_up_markup (gchar ** p_txt)
-{
- gchar *cur, *next_tag;
- gchar open_tags[32];
- guint num_open_tags = 0;
-
- g_assert (*p_txt != NULL);
-
- cur = *p_txt;
- while (*cur != '\0') {
- next_tag = strchr (cur, '<');
- if (next_tag == NULL)
- break;
- ++next_tag;
- switch (*next_tag) {
- case '/':{
- ++next_tag;
- if (num_open_tags == 0 || open_tags[num_open_tags - 1] != *next_tag) {
- GST_LOG ("broken input, closing tag '%c' is not open", *next_tag);
- g_memmove (next_tag - 2, next_tag + 2, strlen (next_tag + 2) + 1);
- next_tag -= 2;
- } else {
- /* it's all good, closing tag which is open */
- --num_open_tags;
- }
- break;
- }
- case 'i':
- case 'b':
- case 'u':
- if (num_open_tags == G_N_ELEMENTS (open_tags))
- return; /* something dodgy is going on, stop parsing */
- open_tags[num_open_tags] = *next_tag;
- ++num_open_tags;
- break;
- default:
- GST_ERROR ("unexpected tag '%c' (%s)", *next_tag, next_tag);
- g_assert_not_reached ();
- break;
- }
- cur = next_tag;
- }
-
- if (num_open_tags > 0) {
- GString *s;
-
- s = g_string_new (*p_txt);
- while (num_open_tags > 0) {
- GST_LOG ("adding missing closing tag '%c'", open_tags[num_open_tags - 1]);
- g_string_append_c (s, '<');
- g_string_append_c (s, '/');
- g_string_append_c (s, open_tags[num_open_tags - 1]);
- g_string_append_c (s, '>');
- --num_open_tags;
- }
- g_free (*p_txt);
- *p_txt = g_string_free (s, FALSE);
- }
-}
-
-static gboolean
-parse_subrip_time (const gchar * ts_string, GstClockTime * t)
-{
- gchar s[128] = { '\0', };
- gchar *end, *p;
- guint hour, min, sec, msec, len;
-
- while (*ts_string == ' ')
- ++ts_string;
-
- g_strlcpy (s, ts_string, sizeof (s));
- if ((end = strstr (s, "-->")))
- *end = '\0';
- g_strchomp (s);
-
- /* ms may be in these formats:
- * hh:mm:ss,500 = 500ms
- * hh:mm:ss, 5 = 5ms
- * hh:mm:ss, 5 = 50ms
- * hh:mm:ss, 50 = 50ms
- * hh:mm:ss,5 = 500ms
- * and the same with . instead of ,.
- * sscanf() doesn't differentiate between ' 5' and '5' so munge
- * the white spaces within the timestamp to '0' (I'm sure there's a
- * way to make sscanf() do this for us, but how?)
- */
- g_strdelimit (s, " ", '0');
- g_strdelimit (s, ".", ',');
-
- /* make sure we have exactly three digits after he comma */
- p = strchr (s, ',');
- g_assert (p != NULL);
- ++p;
- len = strlen (p);
- if (len > 3) {
- p[3] = '\0';
- } else
- while (len < 3) {
- g_strlcat (&p[len], "0", 2);
- ++len;
- }
-
- GST_LOG ("parsing timestamp '%s'", s);
- if (sscanf (s, "%u:%u:%u,%u", &hour, &min, &sec, &msec) != 4) {
- GST_WARNING ("failed to parse subrip timestamp string '%s'", s);
- return FALSE;
- }
-
- *t = ((hour * 3600) + (min * 60) + sec) * GST_SECOND + msec * GST_MSECOND;
- return TRUE;
-}
-
-static gchar *
-parse_subrip (ParserState * state, const gchar * line)
-{
- int subnum;
- gchar *ret;
-
- switch (state->state) {
- case 0:
- /* looking for a single integer */
- if (sscanf (line, "%u", &subnum) == 1)
- state->state = 1;
- return NULL;
- case 1:
- {
- GstClockTime ts_start, ts_end;
- gchar *end_time;
-
- /* looking for start_time --> end_time */
- if ((end_time = strstr (line, " --> ")) &&
- parse_subrip_time (line, &ts_start) &&
- parse_subrip_time (end_time + strlen (" --> "), &ts_end) &&
- state->start_time <= ts_end) {
- state->state = 2;
- state->start_time = ts_start;
- state->duration = ts_end - ts_start;
- } else {
- GST_DEBUG ("error parsing subrip time line '%s'", line);
- state->state = 0;
- }
- return NULL;
- }
- case 2:
- {
- /* No need to parse that text if it's out of segment */
- gint64 clip_start = 0, clip_stop = 0;
- gboolean in_seg = FALSE;
-
- /* Check our segment start/stop */
- in_seg = gst_segment_clip (state->segment, GST_FORMAT_TIME,
- state->start_time, state->start_time + state->duration,
- &clip_start, &clip_stop);
-
- if (in_seg) {
- state->start_time = clip_start;
- state->duration = clip_stop - clip_start;
- } else {
- state->state = 0;
- return NULL;
- }
- }
- /* looking for subtitle text; empty line ends this subtitle entry */
- if (state->buf->len)
- g_string_append_c (state->buf, '\n');
- g_string_append (state->buf, line);
- if (strlen (line) == 0) {
- ret = g_markup_escape_text (state->buf->str, state->buf->len);
- g_string_truncate (state->buf, 0);
- state->state = 0;
- subrip_unescape_formatting (ret);
- subrip_remove_unhandled_tags (ret);
- strip_trailing_newlines (ret);
- subrip_fix_up_markup (&ret);
- return ret;
- }
- return NULL;
- default:
- g_return_val_if_reached (NULL);
- }
-}
-
-static void
-unescape_newlines_br (gchar * read)
-{
- gchar *write = read;
-
- /* Replace all occurences of '[br]' with a newline as version 2
- * of the subviewer format uses this for newlines */
-
- if (read[0] == '\0' || read[1] == '\0' || read[2] == '\0' || read[3] == '\0')
- return;
-
- do {
- if (strncmp (read, "[br]", 4) == 0) {
- *write = '\n';
- read += 4;
- } else {
- *write = *read;
- read++;
- }
- write++;
- } while (*read);
-
- *write = '\0';
-}
-
-static gchar *
-parse_subviewer (ParserState * state, const gchar * line)
-{
- guint h1, m1, s1, ms1;
- guint h2, m2, s2, ms2;
- gchar *ret;
-
- /* TODO: Maybe also parse the fields in the header, especially DELAY.
- * For examples see the unit test or
- * http://www.doom9.org/index.html?/sub.htm */
-
- switch (state->state) {
- case 0:
- /* looking for start_time,end_time */
- if (sscanf (line, "%u:%u:%u.%u,%u:%u:%u.%u",
- &h1, &m1, &s1, &ms1, &h2, &m2, &s2, &ms2) == 8) {
- state->state = 1;
- state->start_time =
- (((guint64) h1) * 3600 + m1 * 60 + s1) * GST_SECOND +
- ms1 * GST_MSECOND;
- state->duration =
- (((guint64) h2) * 3600 + m2 * 60 + s2) * GST_SECOND +
- ms2 * GST_MSECOND - state->start_time;
- }
- return NULL;
- case 1:
- {
- /* No need to parse that text if it's out of segment */
- gint64 clip_start = 0, clip_stop = 0;
- gboolean in_seg = FALSE;
-
- /* Check our segment start/stop */
- in_seg = gst_segment_clip (state->segment, GST_FORMAT_TIME,
- state->start_time, state->start_time + state->duration,
- &clip_start, &clip_stop);
-
- if (in_seg) {
- state->start_time = clip_start;
- state->duration = clip_stop - clip_start;
- } else {
- state->state = 0;
- return NULL;
- }
- }
- /* looking for subtitle text; empty line ends this subtitle entry */
- if (state->buf->len)
- g_string_append_c (state->buf, '\n');
- g_string_append (state->buf, line);
- if (strlen (line) == 0) {
- ret = g_strdup (state->buf->str);
- unescape_newlines_br (ret);
- strip_trailing_newlines (ret);
- g_string_truncate (state->buf, 0);
- state->state = 0;
- return ret;
- }
- return NULL;
- default:
- g_assert_not_reached ();
- return NULL;
- }
-}
-
-static gchar *
-parse_mpsub (ParserState * state, const gchar * line)
-{
- gchar *ret;
- float t1, t2;
-
- switch (state->state) {
- case 0:
- /* looking for two floats (offset, duration) */
- if (sscanf (line, "%f %f", &t1, &t2) == 2) {
- state->state = 1;
- state->start_time += state->duration + GST_SECOND * t1;
- state->duration = GST_SECOND * t2;
- }
- return NULL;
- case 1:
- { /* No need to parse that text if it's out of segment */
- gint64 clip_start = 0, clip_stop = 0;
- gboolean in_seg = FALSE;
-
- /* Check our segment start/stop */
- in_seg = gst_segment_clip (state->segment, GST_FORMAT_TIME,
- state->start_time, state->start_time + state->duration,
- &clip_start, &clip_stop);
-
- if (in_seg) {
- state->start_time = clip_start;
- state->duration = clip_stop - clip_start;
- } else {
- state->state = 0;
- return NULL;
- }
- }
- /* looking for subtitle text; empty line ends this
- * subtitle entry */
- if (state->buf->len)
- g_string_append_c (state->buf, '\n');
- g_string_append (state->buf, line);
- if (strlen (line) == 0) {
- ret = g_strdup (state->buf->str);
- g_string_truncate (state->buf, 0);
- state->state = 0;
- return ret;
- }
- return NULL;
- default:
- g_assert_not_reached ();
- return NULL;
- }
-}
-
-static const gchar *
-dks_skip_timestamp (const gchar * line)
-{
- while (*line && *line != ']')
- line++;
- if (*line == ']')
- line++;
- return line;
-}
-
-static gchar *
-parse_dks (ParserState * state, const gchar * line)
-{
- guint h, m, s;
-
- switch (state->state) {
- case 0:
- /* Looking for the start time and text */
- if (sscanf (line, "[%u:%u:%u]", &h, &m, &s) == 3) {
- const gchar *text;
- state->start_time = (((guint64) h) * 3600 + m * 60 + s) * GST_SECOND;
- text = dks_skip_timestamp (line);
- if (*text) {
- state->state = 1;
- g_string_append (state->buf, text);
- }
- }
- return NULL;
- case 1:
- {
- gint64 clip_start = 0, clip_stop = 0;
- gboolean in_seg;
- gchar *ret;
-
- /* Looking for the end time */
- if (sscanf (line, "[%u:%u:%u]", &h, &m, &s) == 3) {
- state->state = 0;
- state->duration = (((guint64) h) * 3600 + m * 60 + s) * GST_SECOND -
- state->start_time;
- } else {
- GST_WARNING ("Failed to parse subtitle end time");
- return NULL;
- }
-
- /* Check if this subtitle is out of the current segment */
- in_seg = gst_segment_clip (state->segment, GST_FORMAT_TIME,
- state->start_time, state->start_time + state->duration,
- &clip_start, &clip_stop);
-
- if (!in_seg) {
- return NULL;
- }
-
- state->start_time = clip_start;
- state->duration = clip_stop - clip_start;
-
- ret = g_strdup (state->buf->str);
- g_string_truncate (state->buf, 0);
- unescape_newlines_br (ret);
- return ret;
- }
- default:
- g_assert_not_reached ();
- return NULL;
- }
-}
-
-static void
-parser_state_init (ParserState * state)
-{
- GST_DEBUG ("initialising parser");
-
- if (state->buf) {
- g_string_truncate (state->buf, 0);
- } else {
- state->buf = g_string_new (NULL);
- }
-
- state->start_time = 0;
- state->duration = 0;
- state->max_duration = 0; /* no limit */
- state->state = 0;
- state->segment = NULL;
-}
-
-static void
-parser_state_dispose (GstSubParse * self, ParserState * state)
-{
- if (state->buf) {
- g_string_free (state->buf, TRUE);
- state->buf = NULL;
- }
- if (state->user_data) {
- switch (self->parser_type) {
-#ifndef GST_DISABLE_XML
- case GST_SUB_PARSE_FORMAT_SAMI:
- sami_context_reset (state);
- break;
-#endif
- default:
- break;
- }
- }
-}
-
-/* regex type enum */
-typedef enum
-{
- GST_SUB_PARSE_REGEX_UNKNOWN = 0,
- GST_SUB_PARSE_REGEX_MDVDSUB = 1,
- GST_SUB_PARSE_REGEX_SUBRIP = 2,
- GST_SUB_PARSE_REGEX_DKS = 3,
-} GstSubParseRegex;
-
-static gpointer
-gst_sub_parse_data_format_autodetect_regex_once (GstSubParseRegex regtype)
-{
- gpointer result = NULL;
- GError *gerr = NULL;
- switch (regtype) {
- case GST_SUB_PARSE_REGEX_MDVDSUB:
- result =
- (gpointer) g_regex_new ("^\\{[0-9]+\\}\\{[0-9]+\\}", 0, 0, &gerr);
- if (result == NULL) {
- g_warning ("Compilation of mdvd regex failed: %s", gerr->message);
- g_error_free (gerr);
- }
- break;
- case GST_SUB_PARSE_REGEX_SUBRIP:
- result = (gpointer) g_regex_new ("^([ 0-9]){0,3}[0-9]\\s*(\x0d)?\x0a"
- "[ 0-9][0-9]:[ 0-9][0-9]:[ 0-9][0-9][,.][ 0-9]{0,2}[0-9]"
- " +--> +([ 0-9])?[0-9]:[ 0-9][0-9]:[ 0-9][0-9][,.][ 0-9]{0,2}[0-9]",
- 0, 0, &gerr);
- if (result == NULL) {
- g_warning ("Compilation of subrip regex failed: %s", gerr->message);
- g_error_free (gerr);
- }
- break;
- case GST_SUB_PARSE_REGEX_DKS:
- result = (gpointer) g_regex_new ("^\[[0-9]+:[0-9]+:[0-9]+].*",
- 0, 0, &gerr);
- if (result == NULL) {
- g_warning ("Compilation of dks regex failed: %s", gerr->message);
- g_error_free (gerr);
- }
- break;
- default:
- GST_WARNING ("Trying to allocate regex of unknown type %u", regtype);
- }
- return result;
-}
-
-/*
- * FIXME: maybe we should pass along a second argument, the preceding
- * text buffer, because that is how this originally worked, even though
- * I don't really see the use of that.
- */
-
-static GstSubParseFormat
-gst_sub_parse_data_format_autodetect (gchar * match_str)
-{
- guint n1, n2, n3;
-
- static GOnce mdvd_rx_once = G_ONCE_INIT;
- static GOnce subrip_rx_once = G_ONCE_INIT;
- static GOnce dks_rx_once = G_ONCE_INIT;
-
- GRegex *mdvd_grx;
- GRegex *subrip_grx;
- GRegex *dks_grx;
-
- g_once (&mdvd_rx_once,
- (GThreadFunc) gst_sub_parse_data_format_autodetect_regex_once,
- (gpointer) GST_SUB_PARSE_REGEX_MDVDSUB);
- g_once (&subrip_rx_once,
- (GThreadFunc) gst_sub_parse_data_format_autodetect_regex_once,
- (gpointer) GST_SUB_PARSE_REGEX_SUBRIP);
- g_once (&dks_rx_once,
- (GThreadFunc) gst_sub_parse_data_format_autodetect_regex_once,
- (gpointer) GST_SUB_PARSE_REGEX_DKS);
-
- mdvd_grx = (GRegex *) mdvd_rx_once.retval;
- subrip_grx = (GRegex *) subrip_rx_once.retval;
- dks_grx = (GRegex *) dks_rx_once.retval;
-
- if (g_regex_match (mdvd_grx, match_str, 0, NULL) == TRUE) {
- GST_LOG ("MicroDVD (frame based) format detected");
- return GST_SUB_PARSE_FORMAT_MDVDSUB;
- }
- if (g_regex_match (subrip_grx, match_str, 0, NULL) == TRUE) {
- GST_LOG ("SubRip (time based) format detected");
- return GST_SUB_PARSE_FORMAT_SUBRIP;
- }
- if (g_regex_match (dks_grx, match_str, 0, NULL) == TRUE) {
- GST_LOG ("DKS (time based) format detected");
- return GST_SUB_PARSE_FORMAT_DKS;
- }
-
- if (!strncmp (match_str, "FORMAT=TIME", 11)) {
- GST_LOG ("MPSub (time based) format detected");
- return GST_SUB_PARSE_FORMAT_MPSUB;
- }
-#ifndef GST_DISABLE_XML
- if (strstr (match_str, "<SAMI>") != NULL ||
- strstr (match_str, "<sami>") != NULL) {
- GST_LOG ("SAMI (time based) format detected");
- return GST_SUB_PARSE_FORMAT_SAMI;
- }
-#endif
- /* we're boldly assuming the first subtitle appears within the first hour */
- if (sscanf (match_str, "0:%02u:%02u:", &n1, &n2) == 2 ||
- sscanf (match_str, "0:%02u:%02u=", &n1, &n2) == 2 ||
- sscanf (match_str, "00:%02u:%02u:", &n1, &n2) == 2 ||
- sscanf (match_str, "00:%02u:%02u=", &n1, &n2) == 2 ||
- sscanf (match_str, "00:%02u:%02u,%u=", &n1, &n2, &n3) == 3) {
- GST_LOG ("TMPlayer (time based) format detected");
- return GST_SUB_PARSE_FORMAT_TMPLAYER;
- }
- if (sscanf (match_str, "[%u][%u]", &n1, &n2) == 2) {
- GST_LOG ("MPL2 (time based) format detected");
- return GST_SUB_PARSE_FORMAT_MPL2;
- }
- if (strstr (match_str, "[INFORMATION]") != NULL) {
- GST_LOG ("SubViewer (time based) format detected");
- return GST_SUB_PARSE_FORMAT_SUBVIEWER;
- }
- if (strstr (match_str, "{QTtext}") != NULL) {
- GST_LOG ("QTtext (time based) format detected");
- return GST_SUB_PARSE_FORMAT_QTTEXT;
- }
-
- GST_DEBUG ("no subtitle format detected");
- return GST_SUB_PARSE_FORMAT_UNKNOWN;
-}
-
-static GstCaps *
-gst_sub_parse_format_autodetect (GstSubParse * self)
-{
- gchar *data;
- GstSubParseFormat format;
-
- if (strlen (self->textbuf->str) < 30) {
- GST_DEBUG ("File too small to be a subtitles file");
- return NULL;
- }
-
- data = g_strndup (self->textbuf->str, 35);
- format = gst_sub_parse_data_format_autodetect (data);
- g_free (data);
-
- self->parser_type = format;
- self->subtitle_codec = gst_sub_parse_get_format_description (format);
- parser_state_init (&self->state);
-
- switch (format) {
- case GST_SUB_PARSE_FORMAT_MDVDSUB:
- self->parse_line = parse_mdvdsub;
- return gst_caps_new_simple ("text/x-pango-markup", NULL);
- case GST_SUB_PARSE_FORMAT_SUBRIP:
- self->parse_line = parse_subrip;
- return gst_caps_new_simple ("text/x-pango-markup", NULL);
- case GST_SUB_PARSE_FORMAT_MPSUB:
- self->parse_line = parse_mpsub;
- return gst_caps_new_simple ("text/plain", NULL);
-#ifndef GST_DISABLE_XML
- case GST_SUB_PARSE_FORMAT_SAMI:
- self->parse_line = parse_sami;
- sami_context_init (&self->state);
- return gst_caps_new_simple ("text/x-pango-markup", NULL);
-#endif
- case GST_SUB_PARSE_FORMAT_TMPLAYER:
- self->parse_line = parse_tmplayer;
- self->state.max_duration = 5 * GST_SECOND;
- return gst_caps_new_simple ("text/plain", NULL);
- case GST_SUB_PARSE_FORMAT_MPL2:
- self->parse_line = parse_mpl2;
- return gst_caps_new_simple ("text/x-pango-markup", NULL);
- case GST_SUB_PARSE_FORMAT_DKS:
- self->parse_line = parse_dks;
- return gst_caps_new_simple ("text/plain", NULL);
- case GST_SUB_PARSE_FORMAT_SUBVIEWER:
- self->parse_line = parse_subviewer;
- return gst_caps_new_simple ("text/plain", NULL);
- case GST_SUB_PARSE_FORMAT_QTTEXT:
- self->parse_line = parse_qttext;
- qttext_context_init (&self->state);
- return gst_caps_new_simple ("text/x-pango-markup", NULL);
- case GST_SUB_PARSE_FORMAT_UNKNOWN:
- default:
- GST_DEBUG ("no subtitle format detected");
- GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE,
- ("The input is not a valid/supported subtitle file"), (NULL));
- return NULL;
- }
-}
-
-static void
-feed_textbuf (GstSubParse * self, GstBuffer * buf)
-{
- gboolean discont;
- gsize consumed;
- gchar *input = NULL;
-
- discont = GST_BUFFER_IS_DISCONT (buf);
-
- if (GST_BUFFER_OFFSET_IS_VALID (buf) &&
- GST_BUFFER_OFFSET (buf) != self->offset) {
- self->offset = GST_BUFFER_OFFSET (buf);
- discont = TRUE;
- }
-
- if (discont) {
- GST_INFO ("discontinuity");
- /* flush the parser state */
- parser_state_init (&self->state);
- g_string_truncate (self->textbuf, 0);
- gst_adapter_clear (self->adapter);
-#ifndef GST_DISABLE_XML
- if (self->parser_type == GST_SUB_PARSE_FORMAT_SAMI)
- sami_context_reset (&self->state);
-#endif
- /* we could set a flag to make sure that the next buffer we push out also
- * has the DISCONT flag set, but there's no point really given that it's
- * subtitles which are discontinuous by nature. */
- }
-
- self->offset = GST_BUFFER_OFFSET (buf) + GST_BUFFER_SIZE (buf);
- self->next_offset = self->offset;
-
- gst_adapter_push (self->adapter, buf);
-
- input =
- convert_encoding (self, (const gchar *) gst_adapter_peek (self->adapter,
- gst_adapter_available (self->adapter)),
- (gsize) gst_adapter_available (self->adapter), &consumed);
-
- if (input && consumed > 0) {
- self->textbuf = g_string_append (self->textbuf, input);
- gst_adapter_flush (self->adapter, consumed);
- }
-
- g_free (input);
-}
-
-static GstFlowReturn
-handle_buffer (GstSubParse * self, GstBuffer * buf)
-{
- GstFlowReturn ret = GST_FLOW_OK;
- GstCaps *caps = NULL;
- gchar *line, *subtitle;
-
- if (self->first_buffer) {
- self->detected_encoding =
- detect_encoding ((gchar *) GST_BUFFER_DATA (buf),
- GST_BUFFER_SIZE (buf));
- self->first_buffer = FALSE;
- self->state.fps_n = self->fps_n;
- self->state.fps_d = self->fps_d;
- }
-
- feed_textbuf (self, buf);
-
- /* make sure we know the format */
- if (G_UNLIKELY (self->parser_type == GST_SUB_PARSE_FORMAT_UNKNOWN)) {
- if (!(caps = gst_sub_parse_format_autodetect (self))) {
- return GST_FLOW_UNEXPECTED;
- }
- if (!gst_pad_set_caps (self->srcpad, caps)) {
- gst_caps_unref (caps);
- return GST_FLOW_UNEXPECTED;
- }
- gst_caps_unref (caps);
-
- /* push tags */
- if (self->subtitle_codec != NULL) {
- GstTagList *tags;
-
- tags = gst_tag_list_new ();
- gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_SUBTITLE_CODEC,
- self->subtitle_codec, NULL);
- gst_element_found_tags_for_pad (GST_ELEMENT (self), self->srcpad, tags);
- }
- }
-
- while (!self->flushing && (line = get_next_line (self))) {
- guint offset = 0;
-
- /* Set segment on our parser state machine */
- self->state.segment = &self->segment;
- /* Now parse the line, out of segment lines will just return NULL */
- GST_LOG_OBJECT (self, "Parsing line '%s'", line + offset);
- subtitle = self->parse_line (&self->state, line + offset);
- g_free (line);
-
- if (subtitle) {
- guint subtitle_len = strlen (subtitle);
-
- /* +1 for terminating NUL character */
- ret = gst_pad_alloc_buffer_and_set_caps (self->srcpad,
- GST_BUFFER_OFFSET_NONE, subtitle_len + 1,
- GST_PAD_CAPS (self->srcpad), &buf);
-
- if (ret == GST_FLOW_OK) {
- /* copy terminating NUL character as well */
- memcpy (GST_BUFFER_DATA (buf), subtitle, subtitle_len + 1);
- GST_BUFFER_SIZE (buf) = subtitle_len;
- GST_BUFFER_TIMESTAMP (buf) = self->state.start_time;
- GST_BUFFER_DURATION (buf) = self->state.duration;
-
- /* in some cases (e.g. tmplayer) we can only determine the duration
- * of a text chunk from the timestamp of the next text chunk; in those
- * cases, we probably want to limit the duration to something
- * reasonable, so we don't end up showing some text for e.g. 40 seconds
- * just because nothing else is being said during that time */
- if (self->state.max_duration > 0 && GST_BUFFER_DURATION_IS_VALID (buf)) {
- if (GST_BUFFER_DURATION (buf) > self->state.max_duration)
- GST_BUFFER_DURATION (buf) = self->state.max_duration;
- }
-
- gst_segment_set_last_stop (&self->segment, GST_FORMAT_TIME,
- self->state.start_time);
-
- GST_DEBUG_OBJECT (self, "Sending text '%s', %" GST_TIME_FORMAT " + %"
- GST_TIME_FORMAT, subtitle, GST_TIME_ARGS (self->state.start_time),
- GST_TIME_ARGS (self->state.duration));
-
- ret = gst_pad_push (self->srcpad, buf);
- }
-
- /* move this forward (the tmplayer parser needs this) */
- if (self->state.duration != GST_CLOCK_TIME_NONE)
- self->state.start_time += self->state.duration;
-
- g_free (subtitle);
- subtitle = NULL;
-
- if (ret != GST_FLOW_OK) {
- GST_DEBUG_OBJECT (self, "flow: %s", gst_flow_get_name (ret));
- break;
- }
- }
- }
-
- return ret;
-}
-
-static GstFlowReturn
-gst_sub_parse_chain (GstPad * sinkpad, GstBuffer * buf)
-{
- GstFlowReturn ret;
- GstSubParse *self;
-
- self = GST_SUBPARSE (GST_PAD_PARENT (sinkpad));
-
- /* Push newsegment if needed */
- if (self->need_segment) {
- GST_LOG_OBJECT (self, "pushing newsegment event with %" GST_SEGMENT_FORMAT,
- &self->segment);
-
- gst_pad_push_event (self->srcpad, gst_event_new_new_segment (FALSE,
- self->segment.rate, self->segment.format,
- self->segment.last_stop, self->segment.stop, self->segment.time));
- self->need_segment = FALSE;
- }
-
- ret = handle_buffer (self, buf);
-
- return ret;
-}
-
-static gboolean
-gst_sub_parse_sink_event (GstPad * pad, GstEvent * event)
-{
- GstSubParse *self = GST_SUBPARSE (gst_pad_get_parent (pad));
- gboolean ret = FALSE;
-
- GST_DEBUG ("Handling %s event", GST_EVENT_TYPE_NAME (event));
-
- switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_EOS:{
- /* Make sure the last subrip chunk is pushed out even
- * if the file does not have an empty line at the end */
- if (self->parser_type == GST_SUB_PARSE_FORMAT_SUBRIP ||
- self->parser_type == GST_SUB_PARSE_FORMAT_TMPLAYER ||
- self->parser_type == GST_SUB_PARSE_FORMAT_MPL2 ||
- self->parser_type == GST_SUB_PARSE_FORMAT_QTTEXT) {
- GstBuffer *buf = gst_buffer_new_and_alloc (2 + 1);
-
- GST_DEBUG ("EOS. Pushing remaining text (if any)");
- GST_BUFFER_DATA (buf)[0] = '\n';
- GST_BUFFER_DATA (buf)[1] = '\n';
- GST_BUFFER_DATA (buf)[2] = '\0'; /* play it safe */
- GST_BUFFER_SIZE (buf) = 2;
- GST_BUFFER_OFFSET (buf) = self->offset;
- gst_sub_parse_chain (pad, buf);
- }
- ret = gst_pad_event_default (pad, event);
- break;
- }
- case GST_EVENT_NEWSEGMENT:
- {
- GstFormat format;
- gdouble rate;
- gint64 start, stop, time;
- gboolean update;
-
- gst_event_parse_new_segment (event, &update, &rate, &format, &start,
- &stop, &time);
-
- GST_DEBUG_OBJECT (self, "newsegment (%s)", gst_format_get_name (format));
-
- if (format == GST_FORMAT_TIME) {
- gst_segment_set_newsegment (&self->segment, update, rate, format,
- start, stop, time);
- } else {
- /* if not time format, we'll either start with a 0 timestamp anyway or
- * it's following a seek in which case we'll have saved the requested
- * seek segment and don't want to overwrite it (remember that on a seek
- * we always just seek back to the start in BYTES format and just throw
- * away all text that's before the requested position; if the subtitles
- * come from an upstream demuxer, it won't be able to handle our BYTES
- * seek request and instead send us a newsegment from the seek request
- * it received via its video pads instead, so all is fine then too) */
- }
-
- ret = TRUE;
- gst_event_unref (event);
- break;
- }
- case GST_EVENT_FLUSH_START:
- {
- self->flushing = TRUE;
-
- ret = gst_pad_event_default (pad, event);
- break;
- }
- case GST_EVENT_FLUSH_STOP:
- {
- self->flushing = FALSE;
-
- ret = gst_pad_event_default (pad, event);
- break;
- }
- default:
- ret = gst_pad_event_default (pad, event);
- break;
- }
-
- gst_object_unref (self);
-
- return ret;
-}
-
-
-static GstStateChangeReturn
-gst_sub_parse_change_state (GstElement * element, GstStateChange transition)
-{
- GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
- GstSubParse *self = GST_SUBPARSE (element);
-
- switch (transition) {
- case GST_STATE_CHANGE_READY_TO_PAUSED:
- /* format detection will init the parser state */
- self->offset = 0;
- self->next_offset = 0;
- self->parser_type = GST_SUB_PARSE_FORMAT_UNKNOWN;
- self->valid_utf8 = TRUE;
- self->first_buffer = TRUE;
- g_free (self->detected_encoding);
- self->detected_encoding = NULL;
- g_string_truncate (self->textbuf, 0);
- gst_adapter_clear (self->adapter);
- break;
- default:
- break;
- }
-
- ret = parent_class->change_state (element, transition);
- if (ret == GST_STATE_CHANGE_FAILURE)
- return ret;
-
- switch (transition) {
- case GST_STATE_CHANGE_PAUSED_TO_READY:
- parser_state_dispose (self, &self->state);
- self->parser_type = GST_SUB_PARSE_FORMAT_UNKNOWN;
- break;
- default:
- break;
- }
-
- return ret;
-}
-
-/*
- * Typefind support.
- */
-
-/* FIXME 0.11: these caps are ugly, use app/x-subtitle + type field or so;
- * also, give different subtitle formats really different types */
-static GstStaticCaps mpl2_caps =
-GST_STATIC_CAPS ("application/x-subtitle-mpl2");
-#define SUB_CAPS (gst_static_caps_get (&sub_caps))
-
-static GstStaticCaps tmp_caps =
-GST_STATIC_CAPS ("application/x-subtitle-tmplayer");
-#define TMP_CAPS (gst_static_caps_get (&tmp_caps))
-
-static GstStaticCaps sub_caps = GST_STATIC_CAPS ("application/x-subtitle");
-#define MPL2_CAPS (gst_static_caps_get (&mpl2_caps))
-
-#ifndef GST_DISABLE_XML
-static GstStaticCaps smi_caps = GST_STATIC_CAPS ("application/x-subtitle-sami");
-#define SAMI_CAPS (gst_static_caps_get (&smi_caps))
-#endif
-
-static GstStaticCaps dks_caps = GST_STATIC_CAPS ("application/x-subtitle-dks");
-#define DKS_CAPS (gst_static_caps_get (&dks_caps))
-
-static GstStaticCaps qttext_caps =
-GST_STATIC_CAPS ("application/x-subtitle-qttext");
-#define QTTEXT_CAPS (gst_static_caps_get (&qttext_caps))
-
-static void
-gst_subparse_type_find (GstTypeFind * tf, gpointer private)
-{
- GstSubParseFormat format;
- const guint8 *data;
- GstCaps *caps;
- gchar *str;
- gchar *encoding = NULL;
- const gchar *end;
-
- if (!(data = gst_type_find_peek (tf, 0, 129)))
- return;
-
- /* make sure string passed to _autodetect() is NUL-terminated */
- str = g_malloc0 (129);
- memcpy (str, data, 128);
-
- if ((encoding = detect_encoding (str, 128)) != NULL) {
- gchar *converted_str;
- GError *err = NULL;
- gsize tmp;
-
- converted_str = gst_convert_to_utf8 (str, 128, encoding, &tmp, &err);
- if (converted_str == NULL) {
- GST_DEBUG ("Encoding '%s' detected but conversion failed: %s", encoding,
- err->message);
- g_error_free (err);
- g_free (encoding);
- } else {
- g_free (str);
- str = converted_str;
- g_free (encoding);
- }
- }
-
- /* Check if at least the first 120 chars are valid UTF8,
- * otherwise convert as always */
- if (!g_utf8_validate (str, 128, &end) && (end - str) < 120) {
- gchar *converted_str;
- GError *err = NULL;
- gsize tmp;
- const gchar *enc;
-
- enc = g_getenv ("GST_SUBTITLE_ENCODING");
- if (enc == NULL || *enc == '\0') {
- /* if local encoding is UTF-8 and no encoding specified
- * via the environment variable, assume ISO-8859-15 */
- if (g_get_charset (&enc)) {
- enc = "ISO-8859-15";
- }
- }
- converted_str = gst_convert_to_utf8 (str, 128, enc, &tmp, &err);
- if (converted_str == NULL) {
- GST_DEBUG ("Charset conversion failed: %s", err->message);
- g_error_free (err);
- g_free (str);
- return;
- } else {
- g_free (str);
- str = converted_str;
- }
- }
-
- format = gst_sub_parse_data_format_autodetect (str);
- g_free (str);
-
- switch (format) {
- case GST_SUB_PARSE_FORMAT_MDVDSUB:
- GST_DEBUG ("MicroDVD format detected");
- caps = SUB_CAPS;
- break;
- case GST_SUB_PARSE_FORMAT_SUBRIP:
- GST_DEBUG ("SubRip format detected");
- caps = SUB_CAPS;
- break;
- case GST_SUB_PARSE_FORMAT_MPSUB:
- GST_DEBUG ("MPSub format detected");
- caps = SUB_CAPS;
- break;
-#ifndef GST_DISABLE_XML
- case GST_SUB_PARSE_FORMAT_SAMI:
- GST_DEBUG ("SAMI (time-based) format detected");
- caps = SAMI_CAPS;
- break;
-#endif
- case GST_SUB_PARSE_FORMAT_TMPLAYER:
- GST_DEBUG ("TMPlayer (time based) format detected");
- caps = TMP_CAPS;
- break;
- /* FIXME: our MPL2 typefinding is not really good enough to warrant
- * returning a high probability (however, since we registered our
- * typefinder here with a rank of MARGINAL we should pretty much only
- * be called if most other typefinders have already run */
- case GST_SUB_PARSE_FORMAT_MPL2:
- GST_DEBUG ("MPL2 (time based) format detected");
- caps = MPL2_CAPS;
- break;
- case GST_SUB_PARSE_FORMAT_SUBVIEWER:
- GST_DEBUG ("SubViewer format detected");
- caps = SUB_CAPS;
- break;
- case GST_SUB_PARSE_FORMAT_DKS:
- GST_DEBUG ("DKS format detected");
- caps = DKS_CAPS;
- break;
- case GST_SUB_PARSE_FORMAT_QTTEXT:
- GST_DEBUG ("QTtext format detected");
- caps = QTTEXT_CAPS;
- break;
- default:
- case GST_SUB_PARSE_FORMAT_UNKNOWN:
- GST_DEBUG ("no subtitle format detected");
- return;
- }
-
- /* if we're here, it's ok */
- gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, caps);
-}
-
-static gboolean
-plugin_init (GstPlugin * plugin)
-{
- static gchar *sub_exts[] = { "srt", "sub", "mpsub", "mdvd", "smi", "txt",
- "dks", NULL
- };
-
- GST_DEBUG_CATEGORY_INIT (sub_parse_debug, "subparse", 0, ".sub parser");
-
- if (!gst_type_find_register (plugin, "subparse_typefind", GST_RANK_MARGINAL,
- gst_subparse_type_find, sub_exts, SUB_CAPS, NULL, NULL))
- return FALSE;
-
- if (!gst_element_register (plugin, "subparse",
- GST_RANK_PRIMARY, GST_TYPE_SUBPARSE) ||
- !gst_element_register (plugin, "ssaparse",
- GST_RANK_PRIMARY, GST_TYPE_SSA_PARSE)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "subparse",
- "Subtitle parsing",
- plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
diff --git a/gst/subparse/gstsubparse.h b/gst/subparse/gstsubparse.h
deleted file mode 100644
index 5731d918..00000000
--- a/gst/subparse/gstsubparse.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/* GStreamer
- * Copyright (C) <2002> David A. Schleef <ds@schleef.org>
- * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GST_SUBPARSE_H__
-#define __GST_SUBPARSE_H__
-
-#include <gst/gst.h>
-#include <gst/base/gstadapter.h>
-
-GST_DEBUG_CATEGORY_EXTERN (sub_parse_debug);
-#define GST_CAT_DEFAULT sub_parse_debug
-
-G_BEGIN_DECLS
-
-#define GST_TYPE_SUBPARSE \
- (gst_sub_parse_get_type ())
-#define GST_SUBPARSE(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SUBPARSE, GstSubParse))
-#define GST_SUBPARSE_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_SUBPARSE, GstSubParseClass))
-#define GST_IS_SUBPARSE(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SUBPARSE))
-#define GST_IS_SUBPARSE_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_SUBPARSE))
-
-typedef struct _GstSubParse GstSubParse;
-typedef struct _GstSubParseClass GstSubParseClass;
-
-/* format enum */
-typedef enum
-{
- GST_SUB_PARSE_FORMAT_UNKNOWN = 0,
- GST_SUB_PARSE_FORMAT_MDVDSUB = 1,
- GST_SUB_PARSE_FORMAT_SUBRIP = 2,
- GST_SUB_PARSE_FORMAT_MPSUB = 3,
- GST_SUB_PARSE_FORMAT_SAMI = 4,
- GST_SUB_PARSE_FORMAT_TMPLAYER = 5,
- GST_SUB_PARSE_FORMAT_MPL2 = 6,
- GST_SUB_PARSE_FORMAT_SUBVIEWER = 7,
- GST_SUB_PARSE_FORMAT_DKS = 8,
- GST_SUB_PARSE_FORMAT_QTTEXT = 9
-} GstSubParseFormat;
-
-typedef struct {
- int state;
- GString *buf;
- guint64 start_time;
- guint64 duration;
- guint64 max_duration; /* to clamp duration, 0 = no limit (used by tmplayer parser) */
- GstSegment *segment;
- gpointer user_data;
- gboolean have_internal_fps; /* If TRUE don't overwrite fps by property */
- gint fps_n, fps_d; /* used by frame based parsers */
-} ParserState;
-
-typedef gchar* (*Parser) (ParserState *state, const gchar *line);
-
-struct _GstSubParse {
- GstElement element;
-
- GstPad *sinkpad,*srcpad;
-
- /* contains the input in the input encoding */
- GstAdapter *adapter;
- /* contains the UTF-8 decoded input */
- GString *textbuf;
-
- GstSubParseFormat parser_type;
- gboolean parser_detected;
- const gchar *subtitle_codec;
-
- Parser parse_line;
- ParserState state;
-
- /* seek */
- guint64 offset;
- guint64 next_offset;
-
- /* Segment */
- GstSegment segment;
- GstSeekFlags segment_flags;
- gboolean need_segment;
-
- gboolean flushing;
- gboolean valid_utf8;
- gchar *detected_encoding;
- gchar *encoding;
-
- gboolean first_buffer;
-
- /* used by frame based parsers */
- gint fps_n, fps_d;
-};
-
-struct _GstSubParseClass {
- GstElementClass parent_class;
-};
-
-GType gst_sub_parse_get_type (void);
-
-G_END_DECLS
-
-#endif /* __GST_SUBPARSE_H__ */
diff --git a/gst/subparse/mpl2parse.c b/gst/subparse/mpl2parse.c
deleted file mode 100644
index cd400bc0..00000000
--- a/gst/subparse/mpl2parse.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/* GStreamer mpl2 format subtitle parser
- * Copyright (C) 2006 Kamil Pawlowski <kamilpe gmail com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "mpl2parse.h"
-
-#include <stdio.h>
-#include <string.h>
-
-/* From http://lists.mplayerhq.hu/pipermail/mplayer-users/2003-February/030222.html
- *
- * [123][456] Sample subtitle
- * [1234][5678] Line 1|Line 2
- * [12345][67890] /Italic|Normal
- * [12345][67890] /Italic|/Italic
- * [12345][67890] Normal|/Italic
- *
- * (The space between the last ']' bracket and the text appears to be optional)
- */
-
-static gchar *
-mpl2_parse_line (ParserState * state, const gchar * line, guint line_num)
-{
- GString *markup;
- gint dc_start, dc_stop;
-
- /* parse subtitle file line */
- if (sscanf (line, "[%u][%u]", &dc_start, &dc_stop) != 2) {
- GST_WARNING ("failed to extract timestamps for line '%s'", line);
- return NULL;
- }
-
- GST_LOG ("line format %u %u", dc_start, dc_stop);
- state->start_time = GST_SECOND / 10 * dc_start;
- state->duration = (GST_SECOND / 10 * dc_stop) - state->start_time;
-
- /* skip brackets with timestamps */
- line = strchr (line, ']') + 1;
- line = strchr (line, ']') + 1;
-
- markup = g_string_new (NULL);
-
- while (1) {
- const gchar *format_string;
- const gchar *sep;
- gchar *line_chunk_escaped;
-
- /* skip leading white spaces */
- while (*line == ' ' || *line == '\t')
- ++line;
-
- /* a '/' at the beginning indicates italics */
- if (*line == '/') {
- format_string = "<i>%s</i>";
- ++line;
- } else {
- format_string = "%s";
- }
-
- if ((sep = strchr (line, '|')))
- line_chunk_escaped = g_markup_escape_text (line, sep - line);
- else
- line_chunk_escaped = g_markup_escape_text (line, -1);
-
- GST_LOG ("escaped line: %s", line_chunk_escaped);
- g_string_append_printf (markup, format_string, line_chunk_escaped);
-
- g_free (line_chunk_escaped);
-
- if (sep == NULL)
- break;
-
- /* move after the '|' and append another line */
- g_string_append (markup, "\n");
- line = sep + 1;
- }
-
- return g_strstrip (g_string_free (markup, FALSE));
-}
-
-gchar *
-parse_mpl2 (ParserState * state, const gchar * line)
-{
- gchar *ret;
-
- ret = mpl2_parse_line (state, line, state->state);
- ++state->state;
- return ret;
-}
diff --git a/gst/subparse/mpl2parse.h b/gst/subparse/mpl2parse.h
deleted file mode 100644
index aed62c0f..00000000
--- a/gst/subparse/mpl2parse.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* GStreamer mpl2 format subtitle parser
- * Copyright (C) 2006 Kamil Pawlowski <kamilpe gmail com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _MPL2_PARSE_H_
-#define _MPL2_PARSE_H_
-
-#include "gstsubparse.h"
-
-G_BEGIN_DECLS
-
-gchar * parse_mpl2 (ParserState * state, const gchar * line);
-
-G_END_DECLS
-
-#endif /* _MPL2_PARSE_H_ */
-
diff --git a/gst/subparse/qttextparse.c b/gst/subparse/qttextparse.c
deleted file mode 100644
index b48daf91..00000000
--- a/gst/subparse/qttextparse.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/* GStreamer QTtext subtitle parser
- * Copyright (c) 2009 Thiago Santos <thiago.sousa.santos collabora co uk>>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-/* References:
- * http://www.apple.com/quicktime/tutorials/texttracks.html
- * http://www.apple.com/quicktime/tutorials/textdescriptors.html
- */
-
-#include "qttextparse.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#define MIN_TO_NSEC (60 * GST_SECOND)
-#define HOUR_TO_NSEC (60 * MIN_TO_NSEC)
-
-#define GST_QTTEXT_CONTEXT(state) ((GstQTTextContext *) (state)->user_data)
-
-typedef struct _GstQTTextContext GstQTTextContext;
-
-struct _GstQTTextContext
-{
- /* timing variables */
- gint timescale;
- gboolean absolute;
- guint64 start_time;
-
- gboolean markup_open;
- gboolean need_markup;
-
- gchar *font;
- gint font_size;
- gchar *bg_color;
- gchar *fg_color;
-
- gboolean bold;
- gboolean italic;
-};
-
-void
-qttext_context_init (ParserState * state)
-{
- GstQTTextContext *context;
-
- state->user_data = g_new0 (GstQTTextContext, 1);
-
- context = GST_QTTEXT_CONTEXT (state);
-
- /* we use 1000 as a default */
- context->timescale = 1000;
- context->absolute = TRUE;
-
- context->markup_open = FALSE;
- context->need_markup = FALSE;
-
- context->font_size = 12;
-}
-
-void
-qttext_context_deinit (ParserState * state)
-{
- if (state->user_data != NULL) {
- GstQTTextContext *context = GST_QTTEXT_CONTEXT (state);
- g_free (context->font);
- g_free (context->bg_color);
- g_free (context->fg_color);
-
- g_free (state->user_data);
- state->user_data = NULL;
- }
-}
-
-/*
- * Reads the string right after the ':'
- */
-static gchar *
-read_str (const gchar * line, const gchar * end)
-{
- gint index = 0;
-
- while (line[index] != ':' && line[index] != '}') {
- index++;
- }
- if (line[index] != ':')
- return NULL;
- index++;
- while (line[index] == ' ')
- index++;
-
- return g_strndup (line + index, (end - (line + index)));
-}
-
-/* search for the ':' and parse the number right after it */
-static gint
-read_int (const gchar * line)
-{
- gint index = 0;
- while (line[index] != ':' && line[index] != '}') {
- index++;
- }
- if (line[index] != ':')
- return 0;
- index++;
- return atoi (line + index);
-}
-
-/* skip the ':' and then match the following string
- * with 'match', but only if it before 'upto' */
-static gboolean
-string_match (const gchar * line, const gchar * match, const gchar * upto)
-{
- gchar *result = strstr (line, match);
- return (result < upto);
-}
-
-/*
- * Reads the color values and stores them in r, g and b.
- */
-static gboolean
-read_color (const gchar * line, gint * r, gint * g, gint * b)
-{
- gint index = 0;
- while (line[index] != ':' && line[index] != '}') {
- index++;
- }
- if (line[index] != ':')
- return FALSE;
- index++;
-
- *r = atoi (line + index);
-
- while (line[index] != '}' && line[index] != ',') {
- index++;
- }
- if (line[index] != ',')
- return FALSE;
- index++;
-
- *g = atoi (line + index);
-
- while (line[index] != '}' && line[index] != ',') {
- index++;
- }
- if (line[index] != ',')
- return FALSE;
- index++;
-
- *b = atoi (line + index);
-
- return TRUE;
-}
-
-static gchar *
-make_color (gint r, gint g, gint b)
-{
- /* qttext goes up to 65535, while pango goes to 255 */
- r /= 256;
- g /= 256;
- b /= 256;
- return g_strdup_printf ("#%02X%02X%02X", r, g, b);
-}
-
-static gboolean
-qttext_parse_tag (ParserState * state, const gchar * line, gint * index)
-{
- gchar *next;
- gint next_index;
- gint aux;
- gchar *str;
- gint r, g, b;
- GstQTTextContext *context = GST_QTTEXT_CONTEXT (state);
-
- g_assert (line[*index] == '{');
-
- next = strchr (line + *index, '}');
- if (next == NULL) {
- goto error_out;
- } else {
- next_index = 1 + (next - line);
- }
- g_assert (line[next_index - 1] == '}');
-
- *index = *index + 1; /* skip the { */
-
- /* now identify our tag */
- /* FIXME: those should be case unsensitive */
- /* TODO: there are other tags that could be added here */
- if (strncmp (line + *index, "QTtext", 6) == 0) {
- /* NOP */
-
- } else if (strncmp (line + *index, "font", 4) == 0) {
- str = read_str (line + *index + 4, line + next_index - 1);
- if (str) {
- g_free (context->font);
- context->font = str;
- context->need_markup = TRUE;
- GST_DEBUG ("Setting qttext font to %s", str);
- } else {
- GST_WARNING ("Failed to parse qttext font at line: %s", line);
- }
-
- } else if (strncmp (line + *index, "size", 4) == 0) {
- aux = read_int (line + *index + 4);
- if (aux == 0) {
- GST_WARNING ("Invalid size at line %s, using 12", line);
- context->font_size = 12;
- } else {
- GST_DEBUG ("Setting qttext font-size to: %d", aux);
- context->font_size = aux;
- }
- context->need_markup = TRUE;
-
- } else if (strncmp (line + *index, "textColor", 9) == 0) {
- if (read_color (line + *index + 9, &r, &g, &b)) {
- context->fg_color = make_color (r, g, b);
- GST_DEBUG ("Setting qttext fg color to %s", context->fg_color);
- } else {
- GST_WARNING ("Failed to read textColor at line %s", line);
- }
- context->need_markup = TRUE;
-
- } else if (strncmp (line + *index, "backColor", 9) == 0) {
- if (read_color (line + *index + 9, &r, &g, &b)) {
- context->bg_color = make_color (r, g, b);
- GST_DEBUG ("Setting qttext bg color to %s", context->bg_color);
- } else {
- GST_WARNING ("Failed to read backColor at line %s, disabling", line);
- g_free (context->bg_color);
- context->bg_color = NULL;
- }
- context->need_markup = TRUE;
-
- } else if (strncmp (line + *index, "plain", 5) == 0) {
- context->bold = FALSE;
- context->italic = FALSE;
- context->need_markup = TRUE;
- GST_DEBUG ("Setting qttext style to plain");
-
- } else if (strncmp (line + *index, "bold", 4) == 0) {
- context->bold = TRUE;
- context->italic = FALSE;
- context->need_markup = TRUE;
- GST_DEBUG ("Setting qttext style to bold");
-
- } else if (strncmp (line + *index, "italic", 6) == 0) {
- context->bold = FALSE;
- context->italic = TRUE;
- context->need_markup = TRUE;
- GST_DEBUG ("Setting qttext style to italic");
-
- } else if (strncmp (line + *index, "timescale", 9) == 0) {
- aux = read_int (line + *index + 9);
- if (aux == 0) {
- GST_WARNING ("Couldn't interpret timescale at line %s, using 1000", line);
- context->timescale = 1000;
- } else {
- GST_DEBUG ("Setting qttext timescale to: %d", aux);
- context->timescale = aux;
- }
-
- } else if (strncmp (line + *index, "timestamps", 10) == 0) {
- if (string_match (line + *index + 10, "relative", line + next_index)) {
- GST_DEBUG ("Setting qttext timestamps to relative");
- context->absolute = FALSE;
- } else {
- /* call it absolute otherwise */
- GST_DEBUG ("Setting qttext timestamps to absolute");
- context->absolute = TRUE;
- }
-
- } else {
- GST_WARNING ("Unused qttext tag starting at: %s", line + *index);
- }
-
- *index = next_index;
- return TRUE;
-
-error_out:
- {
- GST_WARNING ("Failed to parse qttext tag at line %s", line);
- return FALSE;
- }
-}
-
-static guint64
-qttext_parse_timestamp (ParserState * state, const gchar * line, gint index)
-{
- int ret;
- gint hour, min, sec, dec;
- GstQTTextContext *context = GST_QTTEXT_CONTEXT (state);
-
- ret = sscanf (line + index, "[%d:%d:%d.%d]", &hour, &min, &sec, &dec);
- if (ret != 3 && ret != 4) {
- /* bad timestamp */
- GST_WARNING ("Bad qttext timestamp found: %s", line);
- return 0;
- }
-
- if (ret == 3) {
- /* be forgiving for missing decimal part */
- dec = 0;
- }
-
- /* parse the decimal part according to the timescale */
- g_assert (context->timescale != 0);
- dec = (GST_SECOND * dec) / context->timescale;
-
- /* return the result */
- return hour * HOUR_TO_NSEC + min * MIN_TO_NSEC + sec * GST_SECOND + dec;
-}
-
-static void
-qttext_open_markup (ParserState * state)
-{
- GstQTTextContext *context = GST_QTTEXT_CONTEXT (state);
-
- g_string_append (state->buf, "<span");
-
- /* add your markup tags here */
- if (context->font)
- g_string_append_printf (state->buf, " font='%s %d'", context->font,
- context->font_size);
- else
- g_string_append_printf (state->buf, " font='%d'", context->font_size);
-
- if (context->bg_color)
- g_string_append_printf (state->buf, " bgcolor='%s'", context->bg_color);
- if (context->fg_color)
- g_string_append_printf (state->buf, " color='%s'", context->fg_color);
-
- if (context->bold)
- g_string_append (state->buf, " weight='bold'");
- if (context->italic)
- g_string_append (state->buf, " style='italic'");
-
- g_string_append (state->buf, ">");
-}
-
-static void
-qttext_prepare_text (ParserState * state)
-{
- GstQTTextContext *context = GST_QTTEXT_CONTEXT (state);
- if (state->buf == NULL) {
- state->buf = g_string_sized_new (256); /* this should be enough */
- } else {
- g_string_append (state->buf, "\n");
- }
-
- /* if needed, add pango markup */
- if (context->need_markup) {
- if (context->markup_open) {
- g_string_append (state->buf, "</span>");
- }
- qttext_open_markup (state);
- context->markup_open = TRUE;
- }
-}
-
-static void
-qttext_parse_text (ParserState * state, const gchar * line, gint index)
-{
- qttext_prepare_text (state);
- g_string_append (state->buf, line + index);
-}
-
-static gchar *
-qttext_get_text (ParserState * state)
-{
- gchar *ret;
- GstQTTextContext *context = GST_QTTEXT_CONTEXT (state);
- if (state->buf == NULL)
- return NULL;
-
- if (context->markup_open) {
- g_string_append (state->buf, "</span>");
- }
- ret = g_string_free (state->buf, FALSE);
- state->buf = NULL;
- context->markup_open = FALSE;
- return ret;
-}
-
-gchar *
-parse_qttext (ParserState * state, const gchar * line)
-{
- gint i;
- guint64 ts;
- gchar *ret = NULL;
- GstQTTextContext *context = GST_QTTEXT_CONTEXT (state);
-
- i = 0;
- while (line[i] != '\0') {
- /* find first interesting character from 'i' onwards */
-
- if (line[i] == '{') {
- /* this is a tag, parse it */
- if (!qttext_parse_tag (state, line, &i)) {
- break;
- }
- } else if (line[i] == '[') {
- /* this is a time, convert it to a timestamp */
- ts = qttext_parse_timestamp (state, line, i);
-
- /* check if we have pending text to send, in case we prepare it */
- if (state->buf) {
- ret = qttext_get_text (state);
- if (context->absolute)
- state->duration = ts - context->start_time;
- else
- state->duration = ts;
- state->start_time = context->start_time;
- }
- state->buf = NULL;
-
- if (ts == 0) {
- /* this is an error */
- } else {
- if (context->absolute)
- context->start_time = ts;
- else
- context->start_time += ts;
- }
-
- /* we assume there is nothing else on this line */
- break;
-
- } else if (line[i] == ' ' || line[i] == '\t') {
- i++; /* NOP */
- } else {
- /* this is the actual text, output the rest of the line as it */
- qttext_parse_text (state, line, i);
- break;
- }
- }
- return ret;
-}
diff --git a/gst/subparse/qttextparse.h b/gst/subparse/qttextparse.h
deleted file mode 100644
index 6d4f393b..00000000
--- a/gst/subparse/qttextparse.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* GStreamer QTtext subtitle parser
- * Copyright (c) 2009 Thiago Santos <thiago.sousa.santos collabora co uk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _QTTEXT_PARSE_H_
-#define _QTTEXT_PARSE_H_
-
-#include "gstsubparse.h"
-
-G_BEGIN_DECLS
-
-gchar * parse_qttext (ParserState * state, const gchar * line);
-
-void qttext_context_init (ParserState * state);
-
-void qttext_context_deinit (ParserState * state);
-
-G_END_DECLS
-
-#endif /* _QTTEXT_PARSE_H_ */
-
diff --git a/gst/subparse/samiparse.c b/gst/subparse/samiparse.c
deleted file mode 100644
index 955ee4c4..00000000
--- a/gst/subparse/samiparse.c
+++ /dev/null
@@ -1,474 +0,0 @@
-/* GStreamer SAMI subtitle parser
- * Copyright (c) 2006 Young-Ho Cha <ganadist at chollian net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "samiparse.h"
-
-#include <libxml/HTMLparser.h>
-#include <string.h>
-
-#define ITALIC_TAG 'i'
-#define SPAN_TAG 's'
-#define RUBY_TAG 'r'
-#define RT_TAG 't'
-#define CLEAR_TAG '0'
-
-typedef struct _GstSamiContext GstSamiContext;
-
-struct _GstSamiContext
-{
- GString *buf; /* buffer to collect content */
- GString *rubybuf; /* buffer to collect ruby content */
- GString *resultbuf; /* when opening the next 'sync' tag, move
- * from 'buf' to avoid to append following
- * content */
- GString *state; /* in many sami files there are tags that
- * are not closed, so for each open tag the
- * parser will append a tag flag here so
- * that tags can be closed properly on
- * 'sync' tags. See _context_push_state()
- * and _context_pop_state(). */
- htmlParserCtxtPtr htmlctxt; /* html parser context */
- gboolean has_result; /* set when ready to push out result */
- gboolean in_sync; /* flag to avoid appending anything except the
- * content of the sync elements to buf */
- guint64 time1; /* previous start attribute in sync tag */
- guint64 time2; /* current start attribute in sync tag */
-};
-
-static gchar *
-has_tag (GString * str, const gchar tag)
-{
- return strrchr (str->str, tag);
-}
-
-static void
-sami_context_push_state (GstSamiContext * sctx, char state)
-{
- GST_LOG ("state %c", state);
- g_string_append_c (sctx->state, state);
-}
-
-static void
-sami_context_pop_state (GstSamiContext * sctx, char state)
-{
- GString *str = g_string_new ("");
- GString *context_state = sctx->state;
- int i;
-
- GST_LOG ("state %c", state);
- for (i = context_state->len - 1; i >= 0; i--) {
- switch (context_state->str[i]) {
- case ITALIC_TAG: /* <i> */
- {
- g_string_append (str, "</i>");
- break;
- }
- case SPAN_TAG: /* <span foreground= > */
- {
- g_string_append (str, "</span>");
- break;
- }
- case RUBY_TAG: /* <span size= > -- ruby */
- {
- break;
- }
- case RT_TAG: /* ruby */
- {
- /* FIXME: support for furigana/ruby once implemented in pango */
- g_string_append (sctx->rubybuf, "</span>");
- if (has_tag (context_state, ITALIC_TAG)) {
- g_string_append (sctx->rubybuf, "</i>");
- }
-
- break;
- }
- default:
- break;
- }
- if (context_state->str[i] == state) {
- g_string_append (sctx->buf, str->str);
- g_string_free (str, TRUE);
- g_string_truncate (context_state, i);
- return;
- }
- }
- if (state == CLEAR_TAG) {
- g_string_append (sctx->buf, str->str);
- g_string_truncate (context_state, 0);
- }
- g_string_free (str, TRUE);
-}
-
-static void
-handle_start_sync (GstSamiContext * sctx, const xmlChar ** atts)
-{
- int i;
-
- sami_context_pop_state (sctx, CLEAR_TAG);
- if (atts != NULL) {
- for (i = 0; (atts[i] != NULL); i += 2) {
- const xmlChar *key, *value;
-
- key = atts[i];
- value = atts[i + 1];
-
- if (!value)
- continue;
- if (!xmlStrncmp ((const xmlChar *) "start", key, 5)) {
- /* Only set a new start time if we don't have text pending */
- if (sctx->resultbuf->len == 0)
- sctx->time1 = sctx->time2;
-
- sctx->time2 = atoi ((const char *) value) * GST_MSECOND;
- g_string_append (sctx->resultbuf, sctx->buf->str);
- sctx->has_result = (sctx->resultbuf->len != 0) ? TRUE : FALSE;
- g_string_truncate (sctx->buf, 0);
- }
- }
- }
-}
-
-static void
-handle_start_font (GstSamiContext * sctx, const xmlChar ** atts)
-{
- int i;
-
- sami_context_pop_state (sctx, SPAN_TAG);
- if (atts != NULL) {
- g_string_append (sctx->buf, "<span");
- for (i = 0; (atts[i] != NULL); i += 2) {
- const xmlChar *key, *value;
-
- key = atts[i];
- value = atts[i + 1];
-
- if (!value)
- continue;
- if (!xmlStrncmp ((const xmlChar *) "color", key, 5)) {
- /*
- * There are invalid color value in many
- * sami files.
- * It will fix hex color value that start without '#'
- */
- gchar *sharp = "";
- int len = xmlStrlen (value);
-
- if (!(*value == '#' && len == 7)) {
- gchar *r;
-
- /* check if it looks like hex */
- if (strtol ((const char *) value, &r, 16) >= 0 &&
- ((xmlChar *) r == (value + 6) && len == 6)) {
- sharp = "#";
- }
- }
- /* some colours can be found in many sami files, but X RGB database
- * doesn't contain a colour by this name, so map explicitly */
- if (!xmlStrncasecmp (value, (const xmlChar *) "aqua", len)) {
- value = (const xmlChar *) "#00ffff";
- } else if (!xmlStrncasecmp (value, (const xmlChar *) "crimson", len)) {
- value = (const xmlChar *) "#dc143c";
- } else if (!xmlStrncasecmp (value, (const xmlChar *) "fuchsia", len)) {
- value = (const xmlChar *) "#ff00ff";
- } else if (!xmlStrncasecmp (value, (const xmlChar *) "indigo", len)) {
- value = (const xmlChar *) "#4b0082";
- } else if (!xmlStrncasecmp (value, (const xmlChar *) "lime", len)) {
- value = (const xmlChar *) "#00ff00";
- } else if (!xmlStrncasecmp (value, (const xmlChar *) "olive", len)) {
- value = (const xmlChar *) "#808000";
- } else if (!xmlStrncasecmp (value, (const xmlChar *) "silver", len)) {
- value = (const xmlChar *) "#c0c0c0";
- } else if (!xmlStrncasecmp (value, (const xmlChar *) "teal", len)) {
- value = (const xmlChar *) "#008080";
- }
- g_string_append_printf (sctx->buf, " foreground=\"%s%s\"", sharp,
- value);
- } else if (!xmlStrncasecmp ((const xmlChar *) "face", key, 4)) {
- g_string_append_printf (sctx->buf, " font_family=\"%s\"", value);
- }
- }
- g_string_append_c (sctx->buf, '>');
- sami_context_push_state (sctx, SPAN_TAG);
- }
-}
-
-static void
-start_sami_element (void *ctx, const xmlChar * name, const xmlChar ** atts)
-{
- GstSamiContext *sctx = (GstSamiContext *) ctx;
-
- GST_LOG ("name:%s", name);
-
- if (!xmlStrncmp ((const xmlChar *) "sync", name, 4)) {
- handle_start_sync (sctx, atts);
- sctx->in_sync = TRUE;
- } else if (!xmlStrncmp ((const xmlChar *) "font", name, 4)) {
- handle_start_font (sctx, atts);
- } else if (!xmlStrncmp ((const xmlChar *) "ruby", name, 4)) {
- sami_context_push_state (sctx, RUBY_TAG);
- } else if (!xmlStrncmp ((const xmlChar *) "br", name, 2)) {
- g_string_append_c (sctx->buf, '\n');
- /* FIXME: support for furigana/ruby once implemented in pango */
- } else if (!xmlStrncmp ((const xmlChar *) "rt", name, 2)) {
- if (has_tag (sctx->state, ITALIC_TAG)) {
- g_string_append (sctx->rubybuf, "<i>");
- }
- g_string_append (sctx->rubybuf, "<span size='xx-small' rise='-100'>");
- sami_context_push_state (sctx, RT_TAG);
- } else if (!xmlStrncmp ((const xmlChar *) "p", name, 1)) {
- } else if (!xmlStrncmp ((const xmlChar *) "i", name, 1)) {
- g_string_append (sctx->buf, "<i>");
- sami_context_push_state (sctx, ITALIC_TAG);
- }
-}
-
-static void
-end_sami_element (void *ctx, const xmlChar * name)
-{
- GstSamiContext *sctx = (GstSamiContext *) ctx;
-
- GST_LOG ("name:%s", name);
-
- if (!xmlStrncmp ((const xmlChar *) "sync", name, 4)) {
- sctx->in_sync = FALSE;
- } else if ((!xmlStrncmp ((const xmlChar *) "body", name, 4)) ||
- (!xmlStrncmp ((const xmlChar *) "sami", name, 4))) {
- /* We will usually have one buffer left when the body is closed
- * as we need the next sync to actually send it */
- if (sctx->buf->len != 0) {
- /* Only set a new start time if we don't have text pending */
- if (sctx->resultbuf->len == 0)
- sctx->time1 = sctx->time2;
-
- sctx->time2 = GST_CLOCK_TIME_NONE;
- g_string_append (sctx->resultbuf, sctx->buf->str);
- sctx->has_result = (sctx->resultbuf->len != 0) ? TRUE : FALSE;
- g_string_truncate (sctx->buf, 0);
- }
- } else if (!xmlStrncmp ((const xmlChar *) "font", name, 4)) {
- sami_context_pop_state (sctx, SPAN_TAG);
- } else if (!xmlStrncmp ((const xmlChar *) "ruby", name, 4)) {
- sami_context_pop_state (sctx, RUBY_TAG);
- } else if (!xmlStrncmp ((const xmlChar *) "i", name, 1)) {
- sami_context_pop_state (sctx, ITALIC_TAG);
- }
-}
-
-static void
-characters_sami (void *ctx, const xmlChar * ch, int len)
-{
- GstSamiContext *sctx = (GstSamiContext *) ctx;
- gchar *escaped;
- gchar *tmp;
- gint i;
-
- /* Skip everything except content of the sync elements */
- if (!sctx->in_sync)
- return;
-
- escaped = g_markup_escape_text ((const gchar *) ch, len);
- g_strstrip (escaped);
-
- /* Remove double spaces forom the string as those are
- * usually added by newlines and indention */
- tmp = escaped;
- for (i = 0; i <= strlen (escaped); i++) {
- escaped[i] = *tmp;
- if (*tmp != ' ') {
- tmp++;
- continue;
- }
- while (*tmp == ' ')
- tmp++;
- }
-
- if (has_tag (sctx->state, RT_TAG)) {
- g_string_append_c (sctx->rubybuf, ' ');
- g_string_append (sctx->rubybuf, escaped);
- g_string_append_c (sctx->rubybuf, ' ');
- } else {
- g_string_append (sctx->buf, escaped);
- }
- g_free (escaped);
-}
-
-static xmlSAXHandler samiSAXHandlerStruct = {
- NULL, /* internalSubset */
- NULL, /* isStandalone */
- NULL, /* hasInternalSubset */
- NULL, /* hasExternalSubset */
- NULL, /* resolveEntity */
- NULL, /* getEntity */
- NULL, /* entityDecl */
- NULL, /* notationDecl */
- NULL, /* attributeDecl */
- NULL, /* elementDecl */
- NULL, /* unparsedEntityDecl */
- NULL, /* setDocumentLocator */
- NULL, /* startDocument */
- NULL, /* endDocument */
- start_sami_element, /* startElement */
- end_sami_element, /* endElement */
- NULL, /* reference */
- characters_sami, /* characters */
- NULL, /* ignorableWhitespace */
- NULL, /* processingInstruction */
- NULL, /* comment */
- NULL, /* xmlParserWarning */
- NULL, /* xmlParserError */
- NULL, /* xmlParserError */
- NULL, /* getParameterEntity */
- NULL, /* cdataBlock */
- NULL, /* externalSubset */
- 1, /* initialized */
- NULL, /* private */
- NULL, /* startElementNsSAX2Func */
- NULL, /* endElementNsSAX2Func */
- NULL /* xmlStructuredErrorFunc */
-};
-
-static xmlSAXHandlerPtr samiSAXHandler = &samiSAXHandlerStruct;
-
-void
-sami_context_init (ParserState * state)
-{
- GstSamiContext *context;
-
- g_assert (state->user_data == NULL);
- state->user_data = (gpointer) g_new0 (GstSamiContext, 1);
- context = (GstSamiContext *) state->user_data;
-
- context->htmlctxt = htmlCreatePushParserCtxt (samiSAXHandler, context,
- "", 0, NULL, XML_CHAR_ENCODING_UTF8);
- context->buf = g_string_new ("");
- context->rubybuf = g_string_new ("");
- context->resultbuf = g_string_new ("");
- context->state = g_string_new ("");
-}
-
-void
-sami_context_deinit (ParserState * state)
-{
- GstSamiContext *context = (GstSamiContext *) state->user_data;
-
- if (context) {
- htmlParserCtxtPtr htmlctxt = context->htmlctxt;
-
- /* destroy sax context */
- htmlDocPtr doc;
-
- htmlParseChunk (htmlctxt, "", 0, 1);
- doc = htmlctxt->myDoc;
- htmlFreeParserCtxt (htmlctxt);
- context->htmlctxt = NULL;
- if (doc)
- xmlFreeDoc (doc);
- g_string_free (context->buf, TRUE);
- g_string_free (context->rubybuf, TRUE);
- g_string_free (context->resultbuf, TRUE);
- g_string_free (context->state, TRUE);
- g_free (context);
- state->user_data = NULL;
- }
-}
-
-void
-sami_context_reset (ParserState * state)
-{
- GstSamiContext *context = (GstSamiContext *) state->user_data;
-
- if (context) {
- g_string_truncate (context->buf, 0);
- g_string_truncate (context->rubybuf, 0);
- g_string_truncate (context->resultbuf, 0);
- g_string_truncate (context->state, 0);
- context->has_result = FALSE;
- context->in_sync = FALSE;
- context->time1 = 0;
- context->time2 = 0;
- }
-}
-
-static gchar *
-fix_invalid_entities (const gchar * line)
-{
- const gchar *cp, *pp; /* current pointer, previous pointer */
- gssize size;
- GString *ret = g_string_new (NULL);
-
- pp = line;
- cp = strchr (line, '&');
- while (cp) {
- size = cp - pp;
- ret = g_string_append_len (ret, pp, size);
- cp++;
- if (g_ascii_strncasecmp (cp, "nbsp;", 5)
- && (!g_ascii_strncasecmp (cp, "nbsp", 4))) {
- /* translate "&nbsp" to "&nbsp;" */
- ret = g_string_append_len (ret, "&nbsp;", 6);
- cp += 4;
- } else if (g_ascii_strncasecmp (cp, "quot;", 5)
- && g_ascii_strncasecmp (cp, "amp;", 4)
- && g_ascii_strncasecmp (cp, "apos;", 5)
- && g_ascii_strncasecmp (cp, "lt;", 3)
- && g_ascii_strncasecmp (cp, "gt;", 3)
- && g_ascii_strncasecmp (cp, "nbsp;", 5)
- && cp[0] != '#') {
- /* translate "&" to "&amp;" */
- ret = g_string_append_len (ret, "&amp;", 5);
- } else {
- /* do not translate */
- ret = g_string_append_c (ret, '&');
- }
-
- pp = cp;
- cp = strchr (pp, '&');
- }
- ret = g_string_append (ret, pp);
- return g_string_free (ret, FALSE);
-}
-
-gchar *
-parse_sami (ParserState * state, const gchar * line)
-{
- gchar *fixed_line;
- GstSamiContext *context = (GstSamiContext *) state->user_data;
-
- fixed_line = fix_invalid_entities (line);
- htmlParseChunk (context->htmlctxt, fixed_line, strlen (fixed_line), 0);
- g_free (fixed_line);
-
- if (context->has_result) {
- gchar *r;
-
- if (context->rubybuf->len) {
- context->rubybuf = g_string_append_c (context->rubybuf, '\n');
- g_string_prepend (context->resultbuf, context->rubybuf->str);
- context->rubybuf = g_string_truncate (context->rubybuf, 0);
- }
-
- r = g_string_free (context->resultbuf, FALSE);
- context->resultbuf = g_string_new ("");
- state->start_time = context->time1;
- state->duration = context->time2 - context->time1;
- context->has_result = FALSE;
- return r;
- }
- return NULL;
-}
diff --git a/gst/subparse/samiparse.h b/gst/subparse/samiparse.h
deleted file mode 100644
index a45de018..00000000
--- a/gst/subparse/samiparse.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* GStreamer SAMI subtitle parser
- * Copyright (c) 2006 Young-Ho Cha <ganadist chollian net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _SAMI_PARSE_H_
-#define _SAMI_PARSE_H_
-
-#include "gstsubparse.h"
-
-G_BEGIN_DECLS
-
-gchar * parse_sami (ParserState * state, const gchar * line);
-
-void sami_context_init (ParserState * state);
-
-void sami_context_deinit (ParserState * state);
-
-void sami_context_reset (ParserState * state);
-
-G_END_DECLS
-
-#endif /* _SAMI_PARSE_H_ */
-
diff --git a/gst/subparse/tmplayerparse.c b/gst/subparse/tmplayerparse.c
deleted file mode 100644
index 8f48c6e9..00000000
--- a/gst/subparse/tmplayerparse.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* GStreamer tmplayer format subtitle parser
- * Copyright (C) 2006-2008 Tim-Philipp Müller <tim centricular net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "tmplayerparse.h"
-
-#include <stdio.h>
-#include <string.h>
-
-/* From http://forum.doom9.org/archive/index.php/t-81059.html:
- *
- * TMPlayer format, which comes in five varieties:
- *
- * time-base 00:00:00:
- * 00:00:50:This is the Earth at a time|when the dinosaurs roamed...
- * 00:00:53:
- * 00:00:54:a lush and fertile planet.
- * 00:00:56:
- *
- * time-base 0:00:00:
- * 0:00:50:This is the Earth at a time|when the dinosaurs roamed...
- * 0:00:53:
- * 0:00:54:a lush and fertile planet.
- * 0:00:56:
- *
- * time-base 00:00:00=
- * 00:00:50=This is the Earth at a time|when the dinosaurs roamed...
- * 00:00:53=
- * 00:00:54=a lush and fertile planet.
- * 00:00:56=
- *
- * time-base 0:00:00=
- * 0:00:50=This is the Earth at a time|when the dinosaurs roamed...
- * 0:00:53=
- * 0:00:54=a lush and fertile planet.
- * 0:00:56=
- *
- * and multiline time-base 00:00:00,1=
- * 00:00:50,1=This is the Earth at a time
- * 00:00:50,2=when the dinosaurs roamed...
- * 00:00:53,1=
- * 00:00:54,1=a lush and fertile planet.
- * 00:00:56,1=
- *
- * --------------------------------------------------------------------------
- *
- * And another variety (which is 'time-base 0:00:00:' but without empty lines):
- *
- * 00:00:01:This is the Earth at a time|when the dinosaurs roamed...
- * 00:00:03:a lush and fertile planet.
- * 00:00:06:More text here
- * 00:00:12:Yet another line
- *
- */
-
-static gchar *
-tmplayer_process_buffer (ParserState * state)
-{
- gchar *ret;
-
- ret = g_strndup (state->buf->str, state->buf->len);
- g_strdelimit (ret, "|", '\n');
- g_string_truncate (state->buf, 0);
- return ret;
-}
-
-static gchar *
-tmplayer_parse_line (ParserState * state, const gchar * line, guint line_num)
-{
- GstClockTime ts = GST_CLOCK_TIME_NONE;
- const gchar *text_start = NULL;
- gboolean multiline = FALSE;
- gchar *ret = NULL;
- gchar divc = '\0';
- guint h, m, s, l = 1;
-
- if (sscanf (line, "%u:%02u:%02u,%u%c", &h, &m, &s, &l, &divc) == 5 &&
- (divc == '=')) {
- GST_LOG ("multiline format %u %u %u %u", h, m, s, l);
- ts = GST_SECOND * ((((h * 60) + m) * 60) + s);
- text_start = strchr (line, '=');
- multiline = TRUE;
- } else if (sscanf (line, "%u:%02u:%02u%c", &h, &m, &s, &divc) == 4 &&
- (divc == '=' || divc == ':')) {
- GST_LOG ("single line format %u %u %u %u %c", h, m, s, l, divc);
- ts = GST_SECOND * ((((h * 60) + m) * 60) + s);
- text_start = strchr (line + 6, divc);
- } else if (line[0] == '\0' && state->buf->len > 0 &&
- GST_CLOCK_TIME_IS_VALID (state->start_time)) {
- /* if we get an empty line (could be the end of the file, but doesn't have
- * to be), just push whatever is still in the buffer without a duration */
- GST_LOG ("empty line, and there's still text in the buffer");
- ret = tmplayer_process_buffer (state);
- state->duration = GST_CLOCK_TIME_NONE;
- return ret;
- } else {
- GST_WARNING ("failed to parse line: '%s'", line);
- return NULL;
- }
-
- /* if this is a line without text, or the first line in a multiline file,
- * process and return the data in the buffer, which is the previous line(s) */
- if (text_start == NULL || text_start[1] == '\0' ||
- (l == 1 && state->buf->len > 0)) {
-
- if (GST_CLOCK_TIME_IS_VALID (state->start_time) &&
- state->start_time < ts && line_num > 0) {
- ret = tmplayer_process_buffer (state);
- state->duration = ts - state->start_time;
- /* ..and append current line's text (if there is any) for the next round.
- * We don't have to store ts as pending_start_time, since we deduce the
- * durations from the start times anyway, so as long as the parser just
- * forwards state->start_time by duration after it pushes the line we
- * are about to return it will all be good. */
- g_string_append (state->buf, text_start + 1);
- } else if (line_num > 0) {
- GST_WARNING ("end of subtitle unit but no valid start time?!");
- }
- } else {
- if (l > 1)
- g_string_append_c (state->buf, '\n');
- g_string_append (state->buf, text_start + 1);
- state->start_time = ts;
- }
-
- GST_LOG ("returning: '%s'", GST_STR_NULL (ret));
- return ret;
-}
-
-gchar *
-parse_tmplayer (ParserState * state, const gchar * line)
-{
- gchar *ret;
-
- /* GST_LOG ("Parsing: %s", line); */
-
- ret = tmplayer_parse_line (state, line, state->state);
- ++state->state;
-
- return ret;
-}
diff --git a/gst/subparse/tmplayerparse.h b/gst/subparse/tmplayerparse.h
deleted file mode 100644
index a0001afc..00000000
--- a/gst/subparse/tmplayerparse.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* GStreamer tmplayer format subtitle parser
- * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _TMPLAYER_PARSE_H_
-#define _TMPLAYER_PARSE_H_
-
-#include "gstsubparse.h"
-
-G_BEGIN_DECLS
-
-gchar * parse_tmplayer (ParserState * state, const gchar * line);
-
-G_END_DECLS
-
-#endif /* _TMPLAYER_PARSE_H_ */
-