Mercurial > libavformat.hg
changeset 2484:60428e4e5242 libavformat
Move calculating the bytes needed to represent a size in EBML to its own function
author | conrad |
---|---|
date | Wed, 05 Sep 2007 00:24:42 +0000 |
parents | d5428813739d |
children | d0a635b1ae35 |
files | matroskaenc.c |
diffstat | 1 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/matroskaenc.c Wed Sep 05 00:24:39 2007 +0000 +++ b/matroskaenc.c Wed Sep 05 00:24:42 2007 +0000 @@ -96,11 +96,21 @@ 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 @@ 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);