changeset 6463:4f3cb203b378 libavformat

Add a special function to mkv demxuer to parse length values that includes special-case code to handle all possible encodings of "unknown length".
author reimar
date Mon, 06 Sep 2010 17:51:44 +0000
parents 22cb1e82d915
children b6e3e7876e4c
files matroskadec.c
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/matroskadec.c	Sun Sep 05 22:25:45 2010 +0000
+++ b/matroskadec.c	Mon Sep 06 17:51:44 2010 +0000
@@ -575,6 +575,20 @@
     return read;
 }
 
+/**
+ * Read a EBML length value.
+ * This needs special handling for the "unknown length" case which has multiple
+ * encodings.
+ */
+static int ebml_read_length(MatroskaDemuxContext *matroska, ByteIOContext *pb,
+                            uint64_t *number)
+{
+    int res = ebml_read_num(matroska, pb, 8, number);
+    if (res > 0 && *number + 1 == 1ULL << (7 * res))
+        *number = 0xffffffffffffffULL;
+    return res;
+}
+
 /*
  * Read the next element as an unsigned int.
  * 0 is success, < 0 is failure.
@@ -782,7 +796,7 @@
 
     if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) {
         matroska->current_id = 0;
-        if ((res = ebml_read_num(matroska, pb, 8, &length)) < 0)
+        if ((res = ebml_read_length(matroska, pb, &length)) < 0)
             return res;
     }