[MPlayer-dev-eng] [PATCH] minor fixes and comments for vobsub.c/h

Rüdiger Sonderfeld ruediger at c-plusplus.de
Mon Sep 27 03:10:05 CEST 2010


Hello,
I'm currently working on a project to convert vobsub subtitles to .srt subtitles
(http://github.com/ruediger/VobSub2SRT). I'm using the vobsub and spudec code
from MPlayer for this and while working on the code I made some minor fixes and
added a few comments. I think the MPlayer project could benefit from those
changes despite being very very minor.

List of changes
1. explained a "magic number"
2. fixed potential problem in the use of realloc for OOM situations
3. added a comment explaining where the rest of the .idx settings is handled
4. changed vobsub_set_from_lang to be const correct

I'm writing this message with the gmane interface and can't attach the patch as
a separate file. So I had to include it in this message. Sorry about that.

Regards,
Rüdiger

Index: vobsub.c
===================================================================
--- vobsub.c    (revision 32379)
+++ vobsub.c    (working copy)
@@ -822,7 +822,7 @@
 static int vobsub_set_lang(const char *line)
 {
     if (vobsub_id == -1)
-        vobsub_id = atoi(line + 8);
+        vobsub_id = atoi(line + 8); // 8 == strlen("langidx:")
     return 0;
 }
 
@@ -832,8 +832,9 @@
 {
     ssize_t line_size;
     int res = -1;
-        size_t line_reserve = 0;
-        char *line = NULL;
+    size_t line_reserve = 0;
+    char *line = NULL;
+    unsigned char *tmp;
     do {
         line_size = vobsub_getline(&line, &line_reserve, fd);
         if (line_size < 0 || line_size > 1000000 ||
@@ -841,7 +842,12 @@
             break;
         }
 
-        *extradata = realloc(*extradata, *extradata_len+line_size+1);
+        tmp = realloc(*extradata, *extradata_len+line_size+1);
+        if(!tmp) {
+          mp_msg(MSGT_VOBSUB, MSGL_ERR, "ERROR out of memory");
+          break;
+        }
+        *extradata = tmp;
         memcpy(*extradata+*extradata_len, line, line_size);
         *extradata_len += line_size;
         (*extradata)[*extradata_len] = 0;
@@ -860,6 +866,10 @@
             res = vobsub_parse_timestamp(vob, line + 10);
         else {
             mp_msg(MSGT_VOBSUB, MSGL_V, "vobsub: ignoring %s", line);
+            /*
+              size, palette, forced subs: on, and custom colors: ON, tridx are
+              handled by spudec_parse_extradata in spudec.c
+             */
             continue;
         }
         if (res < 0)
@@ -1117,7 +1127,7 @@
     return j;
 }
 
-int vobsub_set_from_lang(void *vobhandle, unsigned char * lang)
+int vobsub_set_from_lang(void *vobhandle, const char *lang)
 {
     int i;
     vobsub_t *vob= vobhandle;
Index: vobsub.h
===================================================================
--- vobsub.h    (revision 32379)
+++ vobsub.h    (working copy)
@@ -41,7 +41,7 @@
 void *vobsub_out_open(const char *basename, const unsigned int *palette,
unsigned int orig_width, unsigned int orig_height, const char *id, unsigned int
index);
 void vobsub_out_output(void *me, const unsigned char *packet, int len, double pts);
 void vobsub_out_close(void *me);
-int vobsub_set_from_lang(void *vobhandle, unsigned char * lang);
+int vobsub_set_from_lang(void *vobhandle, const char *lang);
 void vobsub_seek(void * vobhandle, float pts);
 
 #endif /* MPLAYER_VOBSUB_H */




More information about the MPlayer-dev-eng mailing list