Skip to content

publish: Audio.Encoder writes the discontinuity marker only when demand disappears; disabling it with a subscriber attached leaves the pre-pause group as the live edge #4781

Closed

Description

@aaisino

Summary

Audio.Encoder ends an epoch with a marker frame (an empty frame at the end of the submitted media, the Container.Legacy.Producer.cut semantics) in one place: the cleanup of the effect that tracks rendition.track, i.e. when the last subscriber leaves. When enabled turns false the pipeline effect just returns, and the input's own doc says the rendition "stays registered so a subscriber still gets an idle track". So an encoder disabled while someone is subscribed stops writing and marks nothing. A subscriber that keeps its subscription across the pause has no signal that the timeline broke (Chromium's AudioDecoder stamps output by counting samples, so frames after the pause land in the ring right behind the earlier ones), and a subscriber that joins during the pause is handed the last pre-pause group as live, the case cut is documented to prevent.

Versions

@moq/publish 0.5.1, @moq/hang 0.5.1 (npm), Chromium 151, relay 0.15.8, moq 0.13.0. The cited code is unchanged on release (moq-relay-v0.17.0, line numbers below) and on main (83ce47f). Not re-measured there.

Steps to reproduce

  1. Chromium listener on @moq/watch that keeps the audio subscription across the pause (it keeps the audio section in its own copy of the catalog, because the stock Audio.Decoder tears its graph down when the rendition leaves the catalog, see our other issue).
  2. Publisher sends a steady 440 Hz tone, then sets the audio encoder enabled: false for 10 s, then true; repeat 4 times. The listener's jitter buffer is about 420 ms.
  3. Measure the listener's ring cushion and dropouts when the tone resumes. Start moq export fmp4 right after the pause starts and look at the first audio in its file.

Expected

Disabling the encoder ends the epoch exactly as losing demand does: a marker at the end of the submitted media. @moq/watch already handles it (Audio.Decoder#onNext resets the ring, the shared clock and the decoder on a discontinuity), and a newcomer lands on the marker rather than on stale audio. For example, write the marker from the pipeline's teardown too (when enabled turns false or the pipeline is rebuilt while rendition.track is live), sharing #next and #floor with the demand path.

Actual

no marker (0.5.1) listener calls Audio.Decoder.reset() itself 1 s into the pause
ring cushion when speech resumes 0-10 ms 430-494 ms
dropouts in the first 5.5 s of speech 7-10 per resume, 51-525 ms in total (3 of 3 runs) 1-4, 3-171 ms

A moq export that subscribes right after the pause starts its file with 30 ms of pre-pause audio (3 of 3). We read how the viewer treats a marker from the code; we could not run it with a marker, since nothing writes one in this case.

Where in the code

  • js/publish/src/audio/encoder.ts: the pipeline effect returns when disabled (:301-309, return at :306); the marker is written only in the demand-loss cleanup (:311-327); the "stays registered" doc is at :78-79. In npm 0.5.1: :267, :272-288, :69-70.
  • js/hang/src/container/legacy.ts:128-158: Producer.cut and why the marker exists. js/watch/src/audio/decoder.ts:579-589: #onNext.

Workaround we use

None needed in our current model (the track is closed on mute, so subscribers leave, demand disappears and the marker is written). It matters for an app that keeps the subscription across a pause.

Related

#4041 (merged): "keep audio held across a demand gap from rewinding the live edge" (the demand-gap marker and floor). Searched discontinuity marker audio mute encoder disabled (2026-10-04): no duplicate.

Activity

  1. added
    questBeing tracked/planned in a quest. See `quest/`
    on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questBeing tracked/planned in a quest. See `quest/`

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions