Skip to content

Recover faster from stalled remote streams - #156

Open
chrizzchrizz wants to merge 2 commits into
dimitris-c:mainfrom
chrizzchrizz:fix/stall-recovery
Open

chrizzchrizz wants to merge 2 commits into
dimitris-c:mainfrom
chrizzchrizz:fix/stall-recovery

Conversation

@chrizzchrizz

Copy link
Copy Markdown
Contributor

Recover faster from stalled remote streams

Problem

On a weak mobile connection (short dead zones, e.g. while driving) a remote stream can hang for a long time or never recover:

  • The request timeout is 60 s, so a dead connection is only noticed long after the buffer has run dry.
  • A network path change (new cell, interface or address) only reconnects after a disconnect has been reported.
  • If the initial range request (bytes=0-1) fails without a response, the stream never opens.
  • Without range support a retry reopens the stream at byte 0, so the parser gets the start of the file again in the middle of playback.

Changes

Recover faster from stalled remote streams

  • Lower the request timeout from 60 s to 15 s, so a dead connection is detected while the buffer is still playing.
  • When the network path changes, reopen a stream that has not received data for 2 s instead of waiting for the timeout.
  • Retry when the initial range request fails without a response.

Resume streams without range support at the read position

  • When a stream without range support is reopened, drop the bytes the player has already read.
  • Keep the first 4 KB of the stream to check that the server sends the same content. If it differs (e.g. a live stream), the new stream plays from its start as before.
  • Streams with ICY metadata or a restructured MP4 keep the old behaviour.
  • A stalled stream is now also reopened on a network path change when the server does not support ranges.

Testing

  • New RemoteAudioSourceResumeTests cover resume with and without range support and with different content.
  • swift test: all tests pass.
  • Used on iOS for several weeks in a music player app streaming from Navidrome/Subsonic. Playback now resumes after short dead zones instead of hanging.

- Lower the request timeout from 60 s to 15 s so a dead connection is
  detected while the buffer still plays.
- Reopen a stream that has not received data for 2 s when the network
  path changes (new cell, interface or address), instead of waiting for
  the timeout.
- Retry when the initial range request fails without a response;
  previously the stream never opened.
Without range support a reopened stream starts at byte 0 again, so a retry
after a network failure fed the start of the file to the parser in the
middle of playback. Now the bytes the player has already read are dropped
from the reopened stream. The first 4 KB of the stream are kept to check
that the server delivers the same content; if it differs (e.g. a live
stream), the new stream plays from its start as before. Streams with ICY
metadata or a restructured MP4 keep the old behaviour.

A stalled stream is now also reopened on a network path change when the
server does not support ranges.
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