Commit ec8f4ad9 authored by David Conrad's avatar David Conrad

Correct handling of smaller unknown sizes

Originally committed as revision 10349 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 541d443c
...@@ -83,6 +83,23 @@ static int ebml_id_size(unsigned int id) ...@@ -83,6 +83,23 @@ static int ebml_id_size(unsigned int id)
return (av_log2(id+1)-1)/7+1; return (av_log2(id+1)-1)/7+1;
} }
/**
* Write an EBML size meaning "unknown size"
*
* @param bytes The number of bytes the size should occupy. Maximum of 8.
*/
static void put_ebml_size_unknown(ByteIOContext *pb, int bytes)
{
uint64_t value = 0;
int i;
bytes = FFMIN(bytes, 8);
for (i = 0; i < bytes*7 + 1; i++)
value |= 1ULL << i;
for (i = bytes-1; i >= 0; i--)
put_byte(pb, value >> i*8);
}
// XXX: test this thoroughly and get rid of minbytes hack (currently needed to // XXX: test this thoroughly and get rid of minbytes hack (currently needed to
// use up all of the space reserved in start_ebml_master) // use up all of the space reserved in start_ebml_master)
static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes) static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes)
...@@ -91,9 +108,12 @@ static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes) ...@@ -91,9 +108,12 @@ static void put_ebml_size(ByteIOContext *pb, uint64_t size, int minbytes)
// 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
size = FFMIN(size, (1ULL<<56)-1); if (size >= (1ULL<<56)-1) {
put_ebml_size_unknown(pb, 1);
return;
}
while (size >> (bytes*7 + 7)) bytes++; while ((size+1) >> (bytes*7 + 7)) bytes++;
put_byte(pb, (0x80 >> bytes) | (size >> bytes*8)); put_byte(pb, (0x80 >> bytes) | (size >> bytes*8));
for (bytes -= 1; bytes >= 0; bytes--) for (bytes -= 1; bytes >= 0; bytes--)
...@@ -159,7 +179,7 @@ static offset_t start_ebml_master(ByteIOContext *pb, unsigned int elementid) ...@@ -159,7 +179,7 @@ static offset_t start_ebml_master(ByteIOContext *pb, unsigned int elementid)
put_ebml_id(pb, elementid); put_ebml_id(pb, elementid);
// XXX: this always reserves the maximum needed space to store any size value // XXX: this always reserves the maximum needed space to store any size value
// we should be smarter (additional parameter for expected size?) // we should be smarter (additional parameter for expected size?)
put_ebml_size(pb, (1ULL<<56)-1, 0); // largest unknown size put_ebml_size_unknown(pb, 8);
return url_ftell(pb); return url_ftell(pb);
} }
......
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