From c32a2aea3250224b15170c1fd3653ab43d127b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 1 Mar 2021 17:19:18 +0000 Subject: [PATCH] matroska: delay Block packets flushing until BlockGroup is parsed --- matroska.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/matroska.c b/matroska.c index 7480374..e513268 100644 --- a/matroska.c +++ b/matroska.c @@ -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 -- 2.45.2