From b735321f58dd7b7943abe89fc62ee0a07eef44ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 10 Oct 2008 15:32:10 +0000 Subject: [PATCH] Make the detection of the used subtitle a bit less strict for srt subtitles. Fixes bug #555607. Original commit message from CVS: Based on a patch by: xavierb at gmail dot com * gst/subparse/gstsubparse.c: (gst_sub_parse_data_format_autodetect): * tests/check/elements/subparse.c: (GST_START_TEST): Make the detection of the used subtitle a bit less strict for srt subtitles. Fixes bug #555607. --- ChangeLog | 10 ++++++++++ gst/subparse/gstsubparse.c | 6 +++--- tests/check/elements/subparse.c | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8d1d0fec2..9439e35513 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-10-10 Sebastian Dröge + + Based on a patch by: xavierb at gmail dot com + + * gst/subparse/gstsubparse.c: + (gst_sub_parse_data_format_autodetect): + * tests/check/elements/subparse.c: (GST_START_TEST): + Make the detection of the used subtitle a bit less strict + for srt subtitles. Fixes bug #555607. + 2008-10-10 Sebastian Dröge * ext/vorbis/vorbisenc.c: diff --git a/gst/subparse/gstsubparse.c b/gst/subparse/gstsubparse.c index 6dc25bc396..dc2a345e0d 100644 --- a/gst/subparse/gstsubparse.c +++ b/gst/subparse/gstsubparse.c @@ -913,9 +913,9 @@ gst_sub_parse_data_format_autodetect (gchar * match_str) need_init_regexps = FALSE; if ((err = regcomp (&mdvd_rx, "^\\{[0-9]+\\}\\{[0-9]+\\}", REG_EXTENDED | REG_NEWLINE | REG_NOSUB) != 0) || - (err = regcomp (&subrip_rx, "^[0-9]([0-9]){0,3}(\x0d)?\x0a" - "[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9]{3}" - " --> [0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9]{3}", + (err = regcomp (&subrip_rx, "^([ 0-9]){0,3}[0-9](\x0d)?\x0a" + "[ 0-9][0-9]:[ 0-9][0-9]:[ 0-9][0-9],[ 0-9]{2}[0-9]" + " --> ([ 0-9])?[0-9]:[ 0-9][0-9]:[ 0-9][0-9],[ 0-9]{2}[0-9]", REG_EXTENDED | REG_NEWLINE | REG_NOSUB)) != 0) { regerror (err, &subrip_rx, errstr, 127); GST_WARNING ("Compilation of subrip regex failed: %s", errstr); diff --git a/tests/check/elements/subparse.c b/tests/check/elements/subparse.c index 8cb02f4022..05e3619a51 100644 --- a/tests/check/elements/subparse.c +++ b/tests/check/elements/subparse.c @@ -116,6 +116,22 @@ static SubParseInputChunk srt_input0[] = { 3 * GST_SECOND, 4 * GST_SECOND, "Three"} }; +/* has spaces instead of doubled zeroes (not exactly according to spec) */ +static SubParseInputChunk srt_input1[] = { + { + "1\n 0: 0:26, 26 --> 0: 0:28, 17\nI cant see.\n\n", + 26 * GST_SECOND + 26 * GST_MSECOND, + 28 * GST_SECOND + 17 * GST_MSECOND, "I cant see."}, + { + "2\n 0: 0:30, 30 --> 0: 0:33, 22\nI really cant see.\n\n", + 30 * GST_SECOND + 30 * GST_MSECOND, + 33 * GST_SECOND + 22 * GST_MSECOND, "I really cant see."}, + { + "3\n 0: 0:40, 40 --> 0: 0:44, 44\nI still cant see anything.\n\n", + 40 * GST_SECOND + 40 * GST_MSECOND, + 44 * GST_SECOND + 44 * GST_MSECOND, "I still cant see anything."} +}; + static void setup_subparse (void) { @@ -218,6 +234,9 @@ GST_START_TEST (test_srt) /* try with chunk number 0 (which is not exactly according to spec) */ test_srt_do_test (srt_input0, 0, G_N_ELEMENTS (srt_input0)); + + /* try with spaces instead of doubled zeroes (which is not exactly according to spec) */ + test_srt_do_test (srt_input1, 0, G_N_ELEMENTS (srt_input1)); } GST_END_TEST;