@@ 194,12 194,6 @@ trackinfo(Biobuf *o, Ebml *e)
Bprint(o, "\n");
}
-static void
-flush(Ebml *e, int refblock)
-{
- USED(e); USED(refblock);
-}
-
int
matroskarun(Biobuf *f)
{
@@ 227,6 221,9 @@ matroskarun(Biobuf *f)
el.id = 0;
refblock = 0;
bgend = 0;
+ npackets = 0;
+ ts = 0;
+ key = 0;
for(isebml = 0; left != 0;){
if(el.id == EBlockDuration)
te.blockdur *= timestampscale;
@@ 237,6 234,16 @@ matroskarun(Biobuf *f)
}
off = Boffset(f);
+
+ if(off >= bgend && !skipdata){
+ if(npackets > 0){
+ if(te.fpacket(&out, &te, packets, npackets, ts, key || refblock) != 0)
+ goto err;
+ npackets = 0;
+ }
+ refblock = 0;
+ }
+
n = ebmlel(f, left, &el, &sz);
if(n < 0){
werrstr("invalid ebml: %r at %#llx (size %lld)", off, sz);
@@ 249,10 256,6 @@ matroskarun(Biobuf *f)
break;
}
left -= n;
- if(off >= bgend && !skipdata){
- flush(&te, refblock);
- refblock = 0;
- }
if(el.id == EEBML){ /* EBML comes first */
if(isebml != 0){
@@ 303,6 306,7 @@ matroskarun(Biobuf *f)
}else if(el.id == EBlockGroup && !skipdata){
refblock = 0;
bgend = off+sz;
+ npackets = 0;
continue;
}else if((el.id == ESimpleBlock || el.id == EBlock) && !skipdata){
if(te.tracknum == -1)
@@ 437,8 441,11 @@ matroskarun(Biobuf *f)
/* ns timestamp */
ts = (timestamp + timecode) * timestampscale - te.codec.delay;
- if(te.fpacket(&out, &te, packets, npackets, ts, key) != 0)
- goto err;
+ if(el.id != EBlock){
+ if(te.fpacket(&out, &te, packets, npackets, ts, key) != 0)
+ goto err;
+ npackets = 0;
+ }
continue;
}
}else