diff -r 567bb019e3e3 -r 7e817e7e631c gst_plugins_base/gst/subparse/samiparse.c --- a/gst_plugins_base/gst/subparse/samiparse.c Tue Aug 31 15:30:33 2010 +0300 +++ b/gst_plugins_base/gst/subparse/samiparse.c Wed Sep 01 12:16:41 2010 +0100 @@ -47,8 +47,8 @@ * 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 */ + gboolean in_title; /* flag to avoid appending the title content + * to buf */ guint64 time1; /* previous start attribute in sync tag */ guint64 time2; /* current start attribute in sync tag */ }; @@ -62,7 +62,6 @@ static void sami_context_push_state (GstSamiContext * sctx, char state) { - GST_LOG ("state %c", state); g_string_append_c (sctx->state, state); } @@ -73,7 +72,6 @@ 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: /* */ @@ -133,13 +131,10 @@ 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->time1 = sctx->time2; sctx->time2 = atoi ((const char *) value) * GST_MSECOND; + sctx->has_result = TRUE; g_string_append (sctx->resultbuf, sctx->buf->str); - sctx->has_result = (sctx->resultbuf->len != 0) ? TRUE : FALSE; g_string_truncate (sctx->buf, 0); } } @@ -215,11 +210,10 @@ { GstSamiContext *sctx = (GstSamiContext *) ctx; - GST_LOG ("name:%s", name); - - if (!xmlStrncmp ((const xmlChar *) "sync", name, 4)) { + if (!xmlStrncmp ((const xmlChar *) "title", name, 5)) { + sctx->in_title = TRUE; + } else 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)) { @@ -245,24 +239,8 @@ { 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); - } + if (!xmlStrncmp ((const xmlChar *) "title", name, 5)) { + sctx->in_title = FALSE; } else if (!xmlStrncmp ((const xmlChar *) "font", name, 4)) { sami_context_pop_state (sctx, SPAN_TAG); } else if (!xmlStrncmp ((const xmlChar *) "ruby", name, 4)) { @@ -277,29 +255,12 @@ { GstSamiContext *sctx = (GstSamiContext *) ctx; gchar *escaped; - gchar *tmp; - gint i; - /* Skip everything except content of the sync elements */ - if (!sctx->in_sync) + /* skip title */ + if (sctx->in_title) 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); @@ -412,7 +373,7 @@ g_string_truncate (context->resultbuf, 0); g_string_truncate (context->state, 0); context->has_result = FALSE; - context->in_sync = FALSE; + context->in_title = FALSE; context->time1 = 0; context->time2 = 0; }