changeset 12547:a60ba1b93e25

Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
author mosu
date Tue, 08 Jun 2004 21:30:32 +0000
parents 7f8ae1376d6c
children 8584fdad0188
files libmpdemux/demux_mkv.c
diffstat 1 files changed, 92 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_mkv.c	Tue Jun 08 16:43:24 2004 +0000
+++ b/libmpdemux/demux_mkv.c	Tue Jun 08 21:30:32 2004 +0000
@@ -89,6 +89,9 @@
   /* generic content encoding support */
   mkv_content_encoding_t *encodings;
   int num_encodings;
+
+  /* For VobSubs */
+  mkv_sh_sub_t sh_sub;
 } mkv_track_t;
 
 typedef struct mkv_index
@@ -304,6 +307,89 @@
 
 
 static int
+demux_mkv_parse_idx (mkv_track_t *t)
+{
+  int things_found, last;
+  char *buf, *pos, *start;
+
+  if ((t->private_data == NULL) || (t->private_size == 0))
+    return 0;
+
+  things_found = 0;
+  buf = (char *)malloc(t->private_size + 1);
+  if (buf == NULL)
+    return 0;
+  memcpy(buf, t->private_data, t->private_size);
+  buf[t->private_size] = 0;
+
+  pos = buf;
+  start = buf;
+  last = 0;
+  do
+    {
+      if ((*pos == 0) || (*pos == '\r') || (*pos == '\n'))
+        {
+          if (*pos == 0)
+            last = 1;
+          *pos = 0;
+
+          if (!strncmp(start, "size: ", 6) &&
+              ((things_found & 1) == 0) &&
+              (sscanf(&start[6], "%dx%d", &t->sh_sub.width, &t->sh_sub.height)
+               == 2))
+            {
+              things_found |= 1;
+              mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub size: %ux%u\n",
+                     t->sh_sub.width, t->sh_sub.height);
+            }
+          else if (!strncmp(start, "palette: ", 9) &&
+                   ((things_found & 2) == 0) &&
+                   (sscanf(&start[9], "%06x,%06x,%06x,%06x,%06x,%06x,%06x,"
+                           "%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x",
+                           &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]) ==
+                    16))
+            {
+              things_found |= 2;
+              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]);
+            }
+          if (last)
+            break;
+          do
+            {
+              pos++;
+            }
+          while ((*pos == '\r') || (*pos == '\n'));
+          start = pos;
+        }
+      else
+        pos++;
+    }
+  while (!last && (*start != 0) && (things_found != 3));
+
+  free(buf);
+
+  return (things_found == 3);
+}
+
+
+static int
 demux_mkv_decode (mkv_track_t *track, uint8_t *src, uint8_t **dest,
                   uint32_t *size, uint32_t type)
 {
@@ -1808,6 +1894,12 @@
               free (track->private_data);
               track->private_data = buffer;
             }
+          if (demux_mkv_parse_idx (track))
+            {
+              demuxer->sub->sh = malloc(sizeof(mkv_sh_sub_t));
+              if (demuxer->sub->sh != NULL)
+                memcpy(demuxer->sub->sh, &track->sh_sub, sizeof(mkv_sh_sub_t));
+            }
         }
     }
   else