ref: 08c77342b9170ca3f1376b493b9fbb086e2fec97
parent: 4f2bb7a70bc730f9cd5890a8bd93c8652f2a8c1a
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 5 09:32:14 EST 2021
matroska: support comp algo 3 with all types of lacing
--- a/matroska.c
+++ b/matroska.c
@@ -183,11 +183,11 @@
int
matroskarun(Biobuf *f)
{
- int isebml, npackets, i, skipdata, lacing;
vlong left, n, sz, nsz, bufsz, track, off, packetsz, x, endtracks;
+ int isebml, npackets, i, skipdata, lacing;
uvlong ts, timestamp, timestampscale;
- uchar *buf, *b;
double duration;
+ uchar *buf, *b;
Ebml e, te;
Elspec el;
@@ -222,8 +222,10 @@
}
if(el.type < 0)
continue;
- if(n == 0) /* eof */
+ if(n == 0){ /* eof */
+ left = 0;
break;
+ }
left -= n;
if(el.id == EEBML){ /* EBML comes first */
@@ -303,7 +305,7 @@
lacing = (buf[2] >> 1) & 3;
npackets = buf[3]+1;
- if(te.comp.algo == 3 && lacing == 0){ /* header stripping, need to put bytes back */
+ if(te.comp.algo == 3){ /* header stripping, need to put bytes back */
if(te.comp.sz == 0)
te.comp.algo = -1;
else{
@@ -314,7 +316,7 @@
}
}
}else if(te.comp.algo >= 0){
- werrstr("unsupported: comp algo %d, lacing %d, please report a bug", te.comp.algo, lacing);
+ werrstr("unsupported: comp algo %d, please report a bug", te.comp.algo);
goto err;
}
@@ -321,12 +323,6 @@
b = buf+3;
switch(lacing){ /* lacing */
case 0: /* none */
- if(te.comp.algo == 3){
- b = buf;
- memmove(b+te.comp.sz, b+3, sz);
- memmove(b, te.comp.data, te.comp.sz);
- sz += te.comp.sz;
- }
packets[0].data = b;
packets[0].sz = sz;
npackets = 1;
@@ -390,6 +386,18 @@
packets[i].data = buf+off;
packets[i].sz = sz;
break;
+ }
+
+ if(te.comp.algo == 3){ /* prepend stripped data to each packet */
+ b = buf+bufsz;
+ for(i = npackets-1; i >= 0; i--){
+ b -= packets[i].sz;
+ memmove(b, packets[i].data, packets[i].sz);
+ b -= te.comp.sz;
+ memmove(b, te.comp.data, te.comp.sz);
+ packets[i].data = b;
+ packets[i].sz += te.comp.sz;
+ }
}
if(te.fpacket(&out, &te, packets, npackets, ts) != 0)