summaryrefslogtreecommitdiff
path: root/libavformat/matroskadec.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-09-06 17:51:44 +0000
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-09-06 17:51:44 +0000
commit1b4d327b1c7ab01495ea896cf9034d5eed8c4893 (patch)
tree02b631a92f288ef5378cc357c950c2a7e47b5b2d /libavformat/matroskadec.c
parent2b0bcfc9172aa1d9e57a66c556dc00e9d68d63d9 (diff)
Add a special function to mkv demxuer to parse length values that includes
special-case code to handle all possible encodings of "unknown length". Originally committed as revision 25049 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/matroskadec.c')
-rw-r--r--libavformat/matroskadec.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 888f099ff2..0d0285e6c0 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -575,6 +575,20 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, ByteIOContext *pb,
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 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
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;
}