[MPlayer-dev-eng] [PATCH] mkv: use sh_sub_t argument instead of mkv_track_t where possible

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Jun 20 18:36:08 CEST 2007


Hello,
attached patch removes some useless clutter in the form of "t->" and
makes it also easier to fix how demuxer->sub->sh is set (it should be
set to one of the pointers in s_streams not malloc, esp. when it never
gets freed).
It also makes it easier to see what kind of "side effects" the functions
have.
Just adding a temporary sh variables in these functions would be
possible as well, if you think track_t might be needed for some future
code extension, but I doubt it...

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/demux_mkv.c
===================================================================
--- libmpdemux/demux_mkv.c	(revision 23586)
+++ libmpdemux/demux_mkv.c	(working copy)
@@ -290,19 +290,19 @@
 
 
 static int
-vobsub_parse_size (mkv_track_t *t, const char *start)
+vobsub_parse_size (sh_sub_t *sh, const char *start)
 {
-  if (sscanf(&start[6], "%dx%d", &t->sh_sub.width, &t->sh_sub.height) == 2)
+  if (sscanf(&start[6], "%dx%d", sh->width, sh->height) == 2)
     {
       mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub size: %ux%u\n",
-             t->sh_sub.width, t->sh_sub.height);
+             sh->width, sh->height);
       return 1;
     }
   return 0;
 }
 
 static int
-vobsub_parse_palette (mkv_track_t *t, const char *start)
+vobsub_parse_palette (sh_sub_t *sh, const char *start)
 {
   int i, r, g, b, y, u, v, tmp;
 
@@ -319,7 +319,7 @@
       y = av_clip_uint8( 0.1494  * r + 0.6061 * g + 0.2445 * b);
       u = av_clip_uint8( 0.6066  * r - 0.4322 * g - 0.1744 * b + 128);
       v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
-      t->sh_sub.palette[i] = y << 16 | u << 8 | v;
+      sh->palette[i] = y << 16 | u << 8 | v;
       start += 6;
       while ((*start == ',') || isspace(*start))
         start++;
@@ -328,23 +328,23 @@
     {
       mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub palette: %06x,%06x,"
              "%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,"
-             "%06x,%06x,%06x\n", t->sh_sub.palette[0],
-             t->sh_sub.palette[1], t->sh_sub.palette[2],
-             t->sh_sub.palette[3], t->sh_sub.palette[4],
-             t->sh_sub.palette[5], t->sh_sub.palette[6],
-             t->sh_sub.palette[7], t->sh_sub.palette[8],
-             t->sh_sub.palette[9], t->sh_sub.palette[10],
-             t->sh_sub.palette[11], t->sh_sub.palette[12],
-             t->sh_sub.palette[13], t->sh_sub.palette[14],
-             t->sh_sub.palette[15]);
-      t->sh_sub.has_palette = 1;
+             "%06x,%06x,%06x\n", sh->palette[0],
+             sh->palette[1], sh->palette[2],
+             sh->palette[3], sh->palette[4],
+             sh->palette[5], sh->palette[6],
+             sh->palette[7], sh->palette[8],
+             sh->palette[9], sh->palette[10],
+             sh->palette[11], sh->palette[12],
+             sh->palette[13], sh->palette[14],
+             sh->palette[15]);
+      sh->has_palette = 1;
       return 2;
     }
   return 0;
 }
 
 static int
-vobsub_parse_custom_colors (mkv_track_t *t, const char *start)
+vobsub_parse_custom_colors (sh_sub_t *sh, const char *start)
 {
   int use_custom_colors, i;
 
@@ -365,7 +365,7 @@
          start++;
        for (i = 0; i < 4; i++)
          {
-           if (sscanf(start, "%06x", &t->sh_sub.colors[i]) != 1)
+           if (sscanf(start, "%06x", &sh->colors[i]) != 1)
              break;
            start += 6;
            while ((*start == ',') || isspace(*start))
@@ -373,32 +373,32 @@
          }
        if (i == 4)
          {
-           t->sh_sub.custom_colors = 4;
+           sh->custom_colors = 4;
            mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub colors: %06x,"
-                  "%06x,%06x,%06x\n", t->sh_sub.colors[0],
-                  t->sh_sub.colors[1], t->sh_sub.colors[2],
-                  t->sh_sub.colors[3]);
+                  "%06x,%06x,%06x\n", sh->colors[0],
+                  sh->colors[1], sh->colors[2],
+                  sh->colors[3]);
          }
      }
    if (!use_custom_colors)
-     t->sh_sub.custom_colors = 0;
+     sh->custom_colors = 0;
    return 4;
 }
 
 static int
-vobsub_parse_forced_subs (mkv_track_t *t, const char *start)
+vobsub_parse_forced_subs (sh_sub_t *sh, const char *start)
 {
   start += 12;
   while (isspace(*start))
     start++;
   if (!strncasecmp(start, "on", 2) || (*start == '1'))
-    t->sh_sub.forced_subs_only = 1;
+    sh->forced_subs_only = 1;
   else if (!strncasecmp(start, "off", 3) || (*start == '0'))
-    t->sh_sub.forced_subs_only = 0;
+    sh->forced_subs_only = 0;
   else
     return 0;
   mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub forced subs: %d\n",
-         t->sh_sub.forced_subs_only);
+         sh->forced_subs_only);
   return 8;
 }
 
@@ -459,13 +459,13 @@
           *pos = 0;
 
           if (!strncasecmp(start, "size: ", 6))
-            things_found |= vobsub_parse_size(t, start);
+            things_found |= vobsub_parse_size(&t->sh_sub, start);
           else if (!strncasecmp(start, "palette:", 8))
-            things_found |= vobsub_parse_palette(t, start);
+            things_found |= vobsub_parse_palette(&t->sh_sub, start);
           else if (!strncasecmp(start, "custom colors:", 14))
-            things_found |= vobsub_parse_custom_colors(t, start);
+            things_found |= vobsub_parse_custom_colors(&t->sh_sub, start);
           else if (!strncasecmp(start, "forced subs:", 12))
-            things_found |= vobsub_parse_forced_subs(t, start);
+            things_found |= vobsub_parse_forced_subs(&t->sh_sub, start);
 
           if (last)
             break;


More information about the MPlayer-dev-eng mailing list