summaryrefslogtreecommitdiff
path: root/libavformat/matroskaenc.c
diff options
context:
space:
mode:
authorDavid Conrad <lessen42@gmail.com>2007-09-05 00:24:42 +0000
committerDavid Conrad <lessen42@gmail.com>2007-09-05 00:24:42 +0000
commit1c73478c8ea2b2a525e71d2c333efcddd35e4fa6 (patch)
tree3f6b721db22853bd1526ef62cd504b016bd4af26 /libavformat/matroskaenc.c
parent9f38fd7efa9c4c59af2384af33c7e92b190ffb83 (diff)
Move calculating the bytes needed to represent a size in EBML to its own function
Originally committed as revision 10353 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r--libavformat/matroskaenc.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index a02c5a40d6..0cb11d8157 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -96,11 +96,21 @@ static void put_ebml_size_unknown(ByteIOContext *pb, int bytes)
put_byte(pb, value >> i*8);
}
+/**
+ * Calculate how many bytes are needed to represent a given size in EBML
+ */
+static int ebml_size_bytes(uint64_t size)
+{
+ int bytes = 1;
+ while ((size+1) >> bytes*7) bytes++;
+ return bytes;
+}
+
// XXX: test this thoroughly and get rid of minbytes hack (currently needed to
// use up all of the space reserved in start_ebml_master)
static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes)
{
- int i, bytes = minbytes;
+ int i, bytes = FFMAX(minbytes, ebml_size_bytes(size));
// sizes larger than this are currently undefined in EBML
// so write "unknown" size
@@ -109,8 +119,6 @@ static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes)
return;
}
- while ((size+1) >> bytes*7) bytes++;
-
put_byte(pb, (0x80 >> (bytes-1)) | (size >> (bytes-1)*8));
for (i = bytes - 2; i >= 0; i--)
put_byte(pb, size >> i*8);