avformat/matroskaenc: Fix BlockGroup size calculation
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Fri, 19 Apr 2019 23:40:57 +0000 (01:40 +0200)
committerJames Almer <jamrial@gmail.com>
Wed, 8 May 2019 16:02:28 +0000 (13:02 -0300)
The earlier code included the size of the BlockGroup's length field and
the EBML ID in the calculation of the size for the payload and ignored
the size of the  duration's length field. This meant that Blockgroups
corresponding to packets with size 2^(7n) - 17 - n - i, i = 0,..., n - 1,
n = 1,..., 8 (i.e. 110, 16364, 16365, 2097130..2097132, ...) were written
with length fields that are unnecessarily long.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
libavformat/matroskaenc.c

index c006cbf..1849ae3 100644 (file)
@@ -2059,9 +2059,7 @@ static int mkv_blockgroup_size(int pkt_size)
     int size = pkt_size + 4;
     size += ebml_num_size(size);
     size += 2;              // EBML ID for block and block duration
-    size += 8;              // max size of block duration
-    size += ebml_num_size(size);
-    size += 1;              // blockgroup EBML ID
+    size += 9;              // max size of block duration incl. length field
     return size;
 }