Skip to content

WIP: resync parser, dont kill the stream#80

Open
alexanderadam wants to merge 5 commits into
philippe44:masterfrom
alexanderadam:fix/early_stop_webm_resync
Open

WIP: resync parser, dont kill the stream#80
alexanderadam wants to merge 5 commits into
philippe44:masterfrom
alexanderadam:fix/early_stop_webm_resync

Conversation

@alexanderadam
Copy link
Copy Markdown
Contributor

@alexanderadam alexanderadam commented May 19, 2026

EBML element bigger than MAX_EBML used to return WEBM_ERROR. callers ignore the return value so playback just stops a few seconds in. people see it as "song cuts off early".

new behaviour: scan the buffer for the next CLUSTER id and pick up there. if no cluster boundary is in the buffer yet, drop most of the buffer and wait for more bytes. we might lose a fragment but the song keeps going, which is what users want.

It's a little strange that this happens but it works for me 🤷‍♂️

I'm still not happy with the solution because something leads to broken chunks. It still has this 'stuttering' every in-between. But then then again: better that than killing the stream alltogether. I'm using it right now.
I'm undecided on this one, that's why I wrote WIP before it.

Probably it's still better to merge this, I guess? 🤷‍♂️

We'd need to find the culprit for the broken chunks though because despite being 'better' it's still not good yet.

EBML element bigger than MAX_EBML used to return WEBM_ERROR. callers
ignore the return value so playback just stops a few seconds in.
people see it as "song cuts off early".

new behaviour: scan the buffer for the next CLUSTER id and pick up
there. if no cluster boundary is in the buffer yet, drop most of
the buffer and wait for more bytes. we might lose a fragment but
the song keeps going, which is what users want.
@alexanderadam alexanderadam changed the title resync parser, dont kill the stream WIP: resync parser, dont kill the stream May 20, 2026
pass the youtube video id into WebM->new and store it in _webm.
later commits will use it to tag warn lines so the log is greppable
without hunting up to the matching new() line.
[videoId] prefix on every warn and error so grep yt:videoId server.log
shows everything that went wrong with one track. also split EBML too
large into in cues / in headers / resync so the failure stage is
visible.
when EBML reports a bogus huge size and there is no ID_CLUSTER in
the next few MB of data, the prebuffer dries out and the player
stops anyway. count dropped bytes, give up past 4 MB, propagate
WEBM_ERROR up so sysread_URL ends the stream cleanly and LMS skips
to the next track instead of just sitting there.
on a bad element_id length walk the parser was throwing away
EBML_NEED (12) bytes and leaving id/size stale. that confused the
next iteration into a cascade of EBML too large warns and around
57 KB of dropped opus, which sounded like a clear stutter.

drop 1 byte instead, clear id/size, let the caller loop. cluster
resync usually catches up within a packet, so the audio gap shrinks
from ~3s to under 100ms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant