Skip to content

Conversation

Hernqvist
Copy link

@Hernqvist Hernqvist commented Sep 16, 2025

Integrates the Playout Statistics API for WebAudio spec into the WebAudio spec.

The following changes are made between the version incubated in WICG and this PR:

  • "fallback"/"fallbackFrames" terminology is replaced with "underrun".
  • Duration types are changed from DOMHighResTimestamp to double.
  • Time units are changed from milliseconds to seconds.

Related issue: #2642


Preview | Diff

Copy link
Member

@hoch hoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good with some nits.

Also could you wrap the text at the column 80?

@Hernqvist
Copy link
Author

Implemented your comments and wrapped the lines at 80 (except where it would have cut through a link, which seems to be the standard for the rest of the document), thanks!

Copy link
Member

@hoch hoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@hoch hoch requested a review from padenot September 18, 2025 15:58
@hoch
Copy link
Member

hoch commented Sep 18, 2025

@padenot Could you take a look?

1. Set {{[[underrun duration]]}} to the total duration of all
[=underrun frames=] (in seconds) that
{{[[audio context]]}} has played since its construction.
1. Set {{[[underrun events]]}} to the number of times that {{[[audio context]]}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if this design holds up to distinguish these three cases

  1. occasional spike
  2. consistent overload -> consistent underruns (every quantum processed)
  3. periodic overload. as an example, a misaligned block based computation that ends up processing every N frames

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!

  1. An occasional spike will manifest as a single increase in underrunDuration, and an increase in underrunEvents by 1.
  2. Consistent underruns will manifest as many small increases in underrunDuration, and many increases in underrunEvents.
  3. Similar to 1, but periodic. Since the API updates at most once per second (for privacy reasons), this might not be possible to immediately detect if N is small enough that we get several underruns per second. If N is large, it should be possible to see that the underruns occur at regular intervals. Also (if my math is correct) underrunEvents / currentTime should converge steadily towards sampleRate / N, so you could also look for that.

Co-authored-by: Christoph Guttandin <chrisguttandin@media-codings.com>
Copy link
Member

@padenot padenot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

index.bs Outdated
Comment on lines 11570 to 11575
Audio underruns (also commonly called glitches) are gaps in the audio
playout which occur when the audio pipeline cannot deliver audio on time.
Underruns (often manifesting as audible "clicks" in the playout) are bad
for the user experience, so if any of these occur it
can be useful for the application to be able to detect them and possibly
take some action to improve the playout.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Audio underruns (also commonly called glitches) are gaps in the audio
playout which occur when the audio pipeline cannot deliver audio on time.
Underruns (often manifesting as audible "clicks" in the playout) are bad
for the user experience, so if any of these occur it
can be useful for the application to be able to detect them and possibly
take some action to improve the playout.
Audio underruns (also commonly called glitches) are gaps in the audio
playback that occur when an audio pipeline cannot deliver audio on time.
Underruns (often manifesting as audible "clicks" in the playout) are bad
for the user experience, so if any of these occur it
can be useful for the application to be able to detect them and possibly
take some action to improve the playout.

we probably need to rephrase this. When the audio isn't delievered on time, it causes an audio underrun, that causes a discontinuity, that causes and audible click, that can be called a glitch. This is because of the synchronous nature of the AudioContext, unlike for example a PeerConnection, that will do something when audio input is missing to cover it up.

index.bs Outdated
Comment on lines 11579 to 11580
{{AudioContext's}} playout path via
{{AudioDestinationNode}} and the associated output device. This allows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{AudioContext's}} playout path via
{{AudioDestinationNode}} and the associated output device. This allows
{{AudioContext's}} playout path via the
{{AudioDestinationNode}} and its associated audio output device. This allows

index.bs Outdated
Comment on lines 11581 to 11583
applications to measure underruns occurring due to underperforming
AudioWorklets as well as underruns and latency originating in the playout
path between the {{AudioDestinationNode}} and the output device.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important, but unrelated to AudioWorklet. We want to point out two possible causes:

  • The audio graph itself is too expensive for the current setup -- latency is too low, computer is generally too slow, etc.
  • The audio graph itself would render fine, but an external factor causes issues: other audio program on the device, global system overload, overload because of thermal throttling, etc.

it is important to make it extra clear what is being discussed here (especially in relation to the other section).

index.bs Outdated
{{[[latency reset time]]}}.
</div>

<h4>Privacy considerations of glitch stats</h4>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the API name here, and not introduce another term.

covert channel between two cooperating sites.
One site could transmit information by intentionally causing audio glitches
(by causing very high CPU usage, for example) while the other site
could detect these glitches.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but only if:

  • There is a linearization point somewhere on the system (typically the audio mixer, be it in the OS or in the browser)
  • The callbacks are effectively synchronous all the way from this linearization point, without a buffer in between that could flatten load spikes (that could be because of a different AudioContextLatencyCategory).

index.bs Outdated
<h5 id="AudioPlayoutStats-mitigations">Mitigations</h5>
To inhibit the usage of such a covert channel, the API implements these
mitigations.
- The values returned by the API should not be updated more than once per
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not MUST?

index.bs Outdated
mitigations.
- The values returned by the API should not be updated more than once per
second.
- The API should be restricted to sites that fulfill at least one of the following
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why not MUST? Is this normative at all?

index.bs Outdated
if (playoutDelay > 0.2) {
// Do something to reduce latency, like suggesting alternative
// playout methods
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current prose makes this example unnecessary, it's already quite clear.

Hernqvist and others added 3 commits September 30, 2025 16:40
Co-authored-by: Paul Adenot <paul@paul.cx>
Co-authored-by: Paul Adenot <paul@paul.cx>
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.

5 participants