Skip to content

tecs-audio: a late buffer no longer ends the output stream - #12

Open
albanmgicquel wants to merge 1 commit into
tecs-dev:mainfrom
albanmgicquel:audio-xrun
Open

albanmgicquel wants to merge 1 commit into
tecs-dev:mainfrom
albanmgicquel:audio-xrun

Conversation

@albanmgicquel

Copy link
Copy Markdown
Collaborator

cpal's stream error callback reports more than failures. On macOS it reports an Xrun for every processor-overload notification (a callback that missed its deadline), DeviceChanged when the default output reroutes, and RealtimeDenied when the thread isn't promoted.

The output and capture streams treated every one of these as terminal. One late buffer, such as a slow first callback in a debug build, marked the stream failed for good: silence from then on, every voice stopped, until the mixer was made anew.

Now only the error kinds that leave the stream dead end it. device::ends_the_stream classifies them, and both output and capture use it:

  • Xrun: the stream keeps running; at most one short gap.
  • DeviceChanged: a stream on the default output is rerouted by CoreAudio's default-output unit (cpal's DefaultOutputMonitor), so the sound follows the new device.
  • RealtimeDenied: playback continues at normal priority.

The fatal kinds (DeviceNotAvailable, StreamInvalidated, HostUnavailable, ...) still end the stream as before. Reopening the output after one of those is left for a follow-up.

Tests: each error kind's classification.

Checks: fmt, clippy -D warnings, cargo test -p tecs-audio, nupp check --strict, nupp test (1017 passed). Independent of #8; based on main.

cpal reports more than failures through a stream's error callback: on
macOS an Xrun for every processor-overload notification (a callback that
missed its deadline), a DeviceChanged when the default output reroutes
and a RealtimeDenied when the thread is not promoted. The output and the
capture took any of them as terminal, so one late buffer (a slow first
callback of a debug build is enough) marked the stream failed for good:
the callback rendered silence from then on, tecs.audio stopped every
voice, and nothing played again until the mixer was made anew. Only the
kinds that leave the stream dead now end it.

Tests: the classification of each error kind.

This branch has not been deployed

No deployments
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