[MPlayer-dev-eng] [PATCH] Two small subtitles improvments

Clément Bœsch ubitux at gmail.com
Thu Sep 30 00:16:55 CEST 2010


Hi again,

I'd like to propose two more patches for subreader.c:

- patch-malloc-memset-to-calloc.diff

As says the file name, just replace two couples of malloc+memset into
calloc calls.

- patch-rt-format.diff

Explicit recognition for the RealTime format. I made a Google research
("time begin ext:rt"), and fetched all the subtitles (not that much, 28).
I only ran into two "headers": "<window" and "<WINDOW" so I think it's
fine to rely on it. Even if there were no white spaces before, I used
strstr() function, just in case.

Also note the spaces before the opening brackets are here just to stay
consistent with the rest of the function.

Regards,

-- 
Clément B.
-------------- next part --------------
Index: subreader.c
===================================================================
--- subreader.c	(revision 32412)
+++ subreader.c	(working copy)
@@ -1926,8 +1920,7 @@
 
     tmpresult = malloc(len);
 
-    result = malloc(sizeof(subfn)*MAX_SUBTITLE_FILES);
-    memset(result, 0, sizeof(subfn)*MAX_SUBTITLE_FILES);
+    result = calloc(MAX_SUBTITLE_FILES, sizeof(*result));
 
     subcnt = 0;
 
@@ -2065,8 +2058,7 @@
 
     qsort(result, subcnt, sizeof(subfn), compare_sub_priority);
 
-    result2 = malloc(sizeof(char*)*(subcnt+1));
-    memset(result2, 0, sizeof(char*)*(subcnt+1));
+    result2 = calloc(subcnt + 1, sizeof(*result2));
 
     for (i = 0; i < subcnt; i++) {
 	result2[i] = result[i].fname;
-------------- next part --------------
Index: subreader.c
===================================================================
--- subreader.c	(revision 32412)
+++ subreader.c	(working copy)
@@ -1130,13 +1129,8 @@
 		{*uses_time=1;return SUB_VPLAYER;}
 	if (sscanf (line, "%d:%d:%d ",     &i, &i, &i )==3)
 		{*uses_time=1;return SUB_VPLAYER;}
-	//TODO: just checking if first line of sub starts with "<" is WAY
-	// too weak test for RT
-	// Please someone who knows the format of RT... FIX IT!!!
-	// It may conflict with other sub formats in the future (actually it doesn't)
-	if ( *line == '<' )
+	if (strstr (line, "<window") || strstr (line, "<WINDOW"))
 		{*uses_time=1;return SUB_RT;}
-
 	if (!memcmp(line, "Dialogue: Marked", 16))
 		{*uses_time=1; return SUB_SSA;}
 	if (!memcmp(line, "Dialogue: ", 10))


More information about the MPlayer-dev-eng mailing list