diff -r 71e347f905f2 -r 4a7fac7dd34a gst_plugins_base/gst/subparse/tmplayerparse.c --- a/gst_plugins_base/gst/subparse/tmplayerparse.c Fri Mar 19 09:35:09 2010 +0200 +++ b/gst_plugins_base/gst/subparse/tmplayerparse.c Fri Apr 16 15:15:52 2010 +0300 @@ -1,5 +1,5 @@ /* GStreamer tmplayer format subtitle parser - * Copyright (C) 2006 Tim-Philipp Müller + * Copyright (C) 2006-2008 Tim-Philipp Müller * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -55,9 +55,30 @@ * 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; @@ -78,19 +99,34 @@ 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 = g_strndup (state->buf->str, state->buf->len); - g_strdelimit (ret, "|", '\n'); - g_string_truncate (state->buf, 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?!"); } @@ -101,6 +137,7 @@ state->start_time = ts; } + GST_LOG ("returning: '%s'", GST_STR_NULL (ret)); return ret; } #ifdef __SYMBIAN32__