subparse->textbuf = g_string_new (NULL);
subparse->parser_type = GST_SUB_PARSE_FORMAT_UNKNOWN;
+#ifdef TIZEN_FEATURE_UPSTREAM
+ subparse->strip_pango_markup = FALSE;
+#endif
subparse->flushing = FALSE;
gst_segment_init (&subparse->segment, GST_FORMAT_TIME);
subparse->need_segment = TRUE;
g_free (input);
}
+#ifdef TIZEN_FEATURE_UPSTREAM
+static void
+xml_text (GMarkupParseContext * context,
+ const gchar * text, gsize text_len, gpointer user_data, GError ** error)
+{
+ gchar **accum = (gchar **) user_data;
+ gchar *concat;
+
+ if (*accum) {
+ concat = g_strconcat (*accum, text, NULL);
+ g_free (*accum);
+ *accum = concat;
+ } else {
+ *accum = g_strdup (text);
+ }
+}
+
+static gchar *
+strip_pango_markup (gchar * markup, GError ** error)
+{
+ GMarkupParser parser = { 0, };
+ GMarkupParseContext *context;
+ gchar *accum = NULL;
+
+ parser.text = xml_text;
+ context = g_markup_parse_context_new (&parser, 0, &accum, NULL);
+
+ g_markup_parse_context_parse (context, "<root>", 6, NULL);
+ g_markup_parse_context_parse (context, markup, strlen (markup), error);
+ g_markup_parse_context_parse (context, "</root>", 7, NULL);
+ if (*error)
+ goto error;
+
+ g_markup_parse_context_end_parse (context, error);
+ if (*error)
+ goto error;
+
+done:
+ g_markup_parse_context_free (context);
+ return accum;
+
+error:
+ g_free (accum);
+ accum = NULL;
+ goto done;
+}
+
+static gboolean
+gst_sub_parse_negotiate (GstSubParse * self, GstCaps * preferred)
+{
+ GstCaps *caps;
+ gboolean ret = FALSE;
+ const GstStructure *s1, *s2;
+
+ caps = gst_pad_get_allowed_caps (self->srcpad);
+
+ s1 = gst_caps_get_structure (preferred, 0);
+
+ if (!g_strcmp0 (gst_structure_get_string (s1, "format"), "utf8")) {
+ GstCaps *intersected = gst_caps_intersect (caps, preferred);
+ gst_caps_unref (caps);
+ caps = intersected;
+ }
+
+ caps = gst_caps_fixate (caps);
+
+ if (gst_caps_is_empty (caps)) {
+ goto done;
+ }
+
+ s2 = gst_caps_get_structure (caps, 0);
+
+ self->strip_pango_markup =
+ !g_strcmp0 (gst_structure_get_string (s2, "format"), "utf8")
+ && !g_strcmp0 (gst_structure_get_string (s1, "format"), "pango-markup");
+
+ if (self->strip_pango_markup) {
+ GST_INFO_OBJECT (self, "We will convert from pango-markup to utf8");
+ }
+
+ ret = gst_pad_set_caps (self->srcpad, caps);
+
+done:
+ gst_caps_unref (caps);
+ return ret;
+}
+#endif
+
static GstFlowReturn
handle_buffer (GstSubParse * self, GstBuffer * buf)
{
GstFlowReturn ret = GST_FLOW_OK;
+#ifndef TIZEN_FEATURE_UPSTREAM
GstCaps *caps = NULL;
+#endif
gchar *line, *subtitle;
gboolean need_tags = FALSE;
#ifdef TIZEN_FEATURE_SUBPARSE_MODIFICATION
/* make sure we know the format */
if (G_UNLIKELY (self->parser_type == GST_SUB_PARSE_FORMAT_UNKNOWN)) {
+#ifdef TIZEN_FEATURE_UPSTREAM
+ GstCaps *preferred;
+
+ if (!(preferred = gst_sub_parse_format_autodetect (self))) {
+ return GST_FLOW_NOT_NEGOTIATED;
+ }
+
+ if (!gst_sub_parse_negotiate (self, preferred)) {
+ gst_caps_unref (preferred);
+ return GST_FLOW_NOT_NEGOTIATED;
+ }
+
+ gst_caps_unref (preferred);
+#else
if (!(caps = gst_sub_parse_format_autodetect (self))) {
return GST_FLOW_EOS;
}
return GST_FLOW_EOS;
}
gst_caps_unref (caps);
+#endif
need_tags = TRUE;
}
}
#endif
if (subtitle) {
- guint subtitle_len = strlen (subtitle);
+#ifdef TIZEN_FEATURE_UPSTREAM
+ guint subtitle_len;
+
+ if (self->strip_pango_markup) {
+ GError *error = NULL;
+ gchar *stripped;
+
+ if ((stripped = strip_pango_markup (subtitle, &error))) {
+ g_free (subtitle);
+ subtitle = stripped;
+ } else {
+ GST_WARNING_OBJECT (self, "Failed to strip pango markup: %s",
+ error->message);
+ }
+ }
+ subtitle_len = strlen (subtitle);
+#else
+ guint subtitle_len = strlen (subtitle);
+#endif
/* +1 for terminating NUL character */
buf = gst_buffer_new_and_alloc (subtitle_len + 1);
/* format detection will init the parser state */
self->offset = 0;
self->parser_type = GST_SUB_PARSE_FORMAT_UNKNOWN;
+#ifdef TIZEN_FEATURE_UPSTREAM
+ self->strip_pango_markup = FALSE;
+#endif
self->valid_utf8 = TRUE;
self->first_buffer = TRUE;
g_free (self->detected_encoding);
#endif
#include <gst/check/gstcheck.h>
+#ifdef TIZEN_FEATURE_UPSTREAM
+#include <gst/check/gstharness.h>
+#endif
#include <string.h>
GST_END_TEST;
+#ifdef TIZEN_FEATURE_UPSTREAM
+GST_START_TEST (test_raw_conversion)
+{
+ GstHarness *h;
+ GstBuffer *buffer;
+ GstMapInfo map;
+
+ h = gst_harness_new ("subparse");
+
+ gst_harness_set_src_caps_str (h, "application/x-subtitle");
+ gst_harness_set_sink_caps_str (h, "text/x-raw, format=utf8");
+
+ buffer = buffer_from_static_string (srt_input[5].in);
+
+ buffer = gst_harness_push_and_pull (h, buffer);
+
+ gst_buffer_map (buffer, &map, GST_MAP_READ);
+ fail_unless_equals_int (map.size, 3);
+ fail_unless_equals_string ((gchar *) map.data, "Six");
+ gst_buffer_unmap (buffer, &map);
+
+ gst_clear_buffer (&buffer);
+
+ gst_harness_teardown (h);
+}
+
+GST_END_TEST;
+#endif
+
/* TODO:
* - add/modify tests so that lines aren't dogfed to the parsers in complete
* lines or sets of complete lines, but rather in random chunks
tcase_add_test (tc_chain, test_sami_bad_entities);
tcase_add_test (tc_chain, test_sami_comment);
tcase_add_test (tc_chain, test_lrc);
+#ifdef TIZEN_FEATURE_UPSTREAM
+ tcase_add_test (tc_chain, test_raw_conversion);
+#endif
return s;
}