Commit d49adf20 authored by conrad's avatar conrad

Modify put_ebml_size() so that the bytes parameter is exact rather than minimum


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@10356 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 2d492399
...@@ -106,11 +106,15 @@ static int ebml_size_bytes(uint64_t size) ...@@ -106,11 +106,15 @@ static int ebml_size_bytes(uint64_t size)
return 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) * Write a size in EBML variable length format.
static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes) *
* @param bytes The number of bytes that need to be used to write the size.
* If zero, any number of bytes can be used.
*/
static void put_ebml_size(ByteIOContext *pb, uint64_t size, int bytes)
{ {
int i, bytes = FFMAX(minbytes, ebml_size_bytes(size)); int i, needed_bytes = ebml_size_bytes(size);
// sizes larger than this are currently undefined in EBML // sizes larger than this are currently undefined in EBML
// so write "unknown" size // so write "unknown" size
...@@ -119,6 +123,18 @@ static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes) ...@@ -119,6 +123,18 @@ static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes)
return; return;
} }
if (bytes == 0)
// don't care how many bytes are used, so use the min
bytes = needed_bytes;
else if (needed_bytes > bytes) {
// the bytes needed to write the given size would exceed the bytes
// that we need to use, so write unknown size. This shouldn't happen.
av_log(NULL, AV_LOG_WARNING, "Size of %llu needs %d bytes but only %d bytes reserved\n",
size, needed_bytes, bytes);
put_ebml_size_unknown(pb, bytes);
return;
}
size |= 1ULL << bytes*7; size |= 1ULL << bytes*7;
for (i = bytes - 1; i >= 0; i--) for (i = bytes - 1; i >= 0; i--)
put_byte(pb, size >> i*8); put_byte(pb, size >> i*8);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment