Skip to content

4.3.0 — first-frame audio by language preference (#72)

Choose a tag to compare

@superuser404notfound superuser404notfound released this 26 Jun 08:36

Added

First-frame audio selection by language preference (#72)

The engine already opens the source once and reuses that probe demuxer as the session demuxer (load probe -> session start). The remaining redundant open was the audio pre-probe: a host that wanted a saved audio-language preference honored on the first frame had to either open the source an extra time to inspect the tracks, or reload via selectAudioTrack after load. Each extra open re-runs avformat_open_input + find_stream_info + the size probe, multiplying pre-first-frame latency and request volume against a remote source (and adding to the rate-limit pressure that #69 / #70 address).

New LoadOptions.preferredAudioLanguages closes that gap by resolving the audio track from the engine's single internal probe:

try await engine.load(
    url: url,
    options: LoadOptions(preferredAudioLanguages: ["en", "de"])
)

Resolution order:

  1. an explicit audioSourceStreamIndex still wins,
  2. else the first track matching a preference, scanned in preference order (case-insensitive; ISO 639-1 / 639-2 B+T codes and English names, so en == eng == english, de == deu == ger),
  3. else the container default.

The resolved index drives the played audio on both the native and software paths, not just the reported activeAudioTrackIndex. The list is ordered, so an earlier preference on a later track still beats a later preference on an earlier track.

No behavior change until you opt in. An empty preferredAudioLanguages with no override is a no-op (the session keeps its own default pick). A probe-failed source still honors an explicit override verbatim. Live reload and mid-playback audio-switch paths keep their explicit index and are untouched.

Thanks to reckloon for the request and the staged-reuse framing.

Full changelog: https://github.com/superuser404notfound/AetherEngine/blob/main/CHANGELOG.md