Open Bug 2087144 Opened 1 month ago Updated 18 days ago

Web Audio crackles on Pixel 8a (Android 17) even with a single OscillatorNode; latencyHint has no effect (AAudio shared MMAP stream XRuns)

Categories

(Core :: Audio/Video: cubeb, defect, P2)

Firefox 158
All
Android
defect

Tracking

()

UNCONFIRMED

People

(Reporter: vincent.kerdraon, Unassigned, NeedInfo)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression)

Attachments

(2 files)

Attached file bug-logs.7z —

Steps to reproduce

Device: Google Pixel 8a (Tensor G3), Android 17 (build CP3A.261005.005, patch 2026-10-05), Firefox for Android 158.0.2, built-in speaker.

  1. Open the attached fx-lab.html (served from any static server) in Firefox for Android.
  2. Tap the sine link, then START. The page does only: new AudioContext() → OscillatorNode (220 Hz) → GainNode (0.05) → destination.
  3. Leave the page alone and listen for 60 s. Meanwhile run adb shell dumpsys media.aaudio twice, 60 s apart, and read the XRuns column of Firefox's row (Shared Endpoints → Registered Streams).
  4. Repeat with the other links: sine+PB (latencyHint: 'playback'), sine interactive, sine lh=0, sine 44.1k (sampleRate: 44100), sine MSD (graph → MediaStreamAudioDestinationNode → <audio>.srcObject).
  5. Control: ?parts=sine&route=wav plays the same 220 Hz sine as a looped WAV blob in a plain <audio src>, with no AudioContext.

Actual results

  • Audible clicks / crackles throughout, confirmed by ear over several runs. Chrome and Brave on the same phone play the same pages cleanly.
  • Firefox's output is a shared MMAP AAudio stream (it shares audioserver's exclusive endpoint, 48-frame HW burst): Burst 96, Capacity 1536, ~288 frames (6 ms) queued, 48 kHz float stereo. baseLatency = 0, outputLatency ≈ 0.0148 s.
  • XRuns per 60 s, ONE sine, no page activity: 92, 50, 41, 76, 199 across runs.
  • latencyHint: 'playback' → 76; 'interactive' → 41; 0 → 50; sampleRate: 44100 → 199 (worse). Burst / capacity / queued frames are identical under every latencyHint: the hint never reaches the output stream.
  • MediaStreamAudioDestinationNode → <audio>.srcObject: the SAME single stream, 54 XRuns / 60 s, still crackles.
  • Heavier graph (6 sawtooth pads + 2.6 s ConvolverNode + DynamicsCompressor + delay + biquads): 5072 XRuns / 60 s.
  • Control (clean): the plain <audio src=WAV> goes to audio_flinger's deep-buffer mixer thread (HAL 1920 frames, no FastMixer), ~230 ms track latency, 0 underruns / 60 s, no audible glitch.

Related: likely the same root cause as bug 2012750 (Android Web Audio noise, real-time budget ~23 ms on the AudioIPC callback thread). Same symptom as bug 1930825 (fixed 2024-11) and bug 1893939 (WORKSFORME 2025-12), back on 158.0.2. Tracked by meta bug 1951155.

Attachments: fx-lab.html (repro page), fx-aaudio-lh0.txt / fx-aaudio-msd.txt (dumpsys media.aaudio while the sine plays), fx-af-msd.txt / fx-af-wav0.txt (dumpsys media.audio_flinger: the MMAP track vs the clean <audio> WAV track), lab-results.txt (every run).

Expected results

Glitch-free Web Audio output for a trivial graph, as Chrome gives on the same device. Either the low-latency MMAP stream should be serviced in time, or latencyHint: 'playback' (or a fallback after repeated XRuns) should open a larger-buffer / POWER_SAVING stream, as Firefox already does for <audio src> playback.

See Also: → 2012750, 1893939, 1930825

The Bugbug bot thinks this bug should belong to the 'Firefox for Android::Media' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: General → Media

The severity field is not set for this bug.
:polly, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(polly)
Component: Media → Audio/Video: cubeb
Flags: needinfo?(polly)
Product: Firefox for Android → Core

Thanks for the detailed data. The attached dumpsys media.aaudio output agrees with the AAudio code in the current tree.

Analysis

The Web Audio graph asks for a latency below POWERSAVE_LATENCY_FRAMES_THRESHOLD (4000 frames), so cubeb opens the output stream in AAUDIO_PERFORMANCE_MODE_LOW_LATENCY (cubeb_aaudio.cpp). In that mode, cubeb sets the output buffer to 3 bursts when the burst is smaller than 128 frames (cubeb_aaudio.cpp). With a burst of 96 frames, the buffer is 288 frames, or 6 ms. This is the "Avail 288" in the attached dump.

The buffer size does not depend on the requested latency. cubeb also does not read the XRun count and does not make the buffer larger after XRuns. The probable reason for the XRuns is that 6 ms is too short for each callback, which goes through AudioIPC. No log or profile proves this yet.

Firefox ignores latencyHint: AudioContextOptions declares only sampleRate (AudioContext.webidl). This explains why the burst and the buffer stay the same for every hint. Bug 2020377 covers the latencyHint implementation. The MediaStreamAudioDestinationNode route plays through the same graph stream, so it crackles too.

The plain <audio src> control asks for about 100 ms (AudioStream.cpp). That is above the threshold, so the stream gets the power saving mode and the AudioFlinger deep buffer mixer. This explains why the control is clean.

The probable cause is the libcubeb update of bug 2026000, which landed on 2026-03-25 for Firefox 151. It added the fixed 3 burst sizing in the output setup of cubeb_aaudio.cpp. Before it, the buffer also grew with the requested latency, and the Android graph asked for at least 1024 frames (bug 1930825). This comes from code reading only, so a regression range can confirm it.

Fix direction: in upstream libcubeb first, then vendored, make the low latency output buffer depend on the requested latency again. Another option is to add one burst to the buffer after new XRuns. Implementing latencyHint (bug 2020377) can also let 'playback' open a power saving stream. This bug already blocks the crackling meta bug 1951155.

Matthew, could you please look at the output buffer sizing of the AAudio backend for this bug?

Next steps

@vincent.kerdraon, could you please record a capture while the single sine page crackles? It shows how Firefox 158.0.2 opens the stream and where the callback is late.

Please capture a profile:

  1. Open about:logging.
  2. Under Log module selection, choose "Media playback" in the Logging preset: drop-down.
  3. Under Logging output, select "Logging to the Firefox Profiler".
  4. Click Start Logging.
  5. Reload the page. Then do the steps that show the problem.
  6. Click Stop Logging. The profile opens in the Firefox Profiler.
  7. Click Upload Local Profile. This is the share button.
  8. Copy the share URL. Add it to this bug.

The instruction video shows these steps.

On Android, about:logging offers to upload the profile itself. After the upload, it shows a "Share URL" to add to this bug.

@vincent.kerdraon, could you please also find the regression range? It shows if bug 2026000 is the change that brought the crackling back.

Please find the regression range with mozregression:

  1. Install it from https://mozilla.github.io/mozregression/.
  2. Run it with the first known bad and the last known good versions.
  3. Follow the steps that show the problem on each build it opens.
  4. Paste the final "pushlog" link into this bug.

If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.

Severity: -- → S3
Flags: needinfo?(vincent.kerdraon)
Flags: needinfo?(kinetik)
Keywords: regression
Priority: -- → P2
See Also: → 2026000, 2020377
Flags: needinfo?(vincent.kerdraon)
Regressed by: 2026000

Regression range, from mozregression 7.6.0 (--app gve --arch aarch64, GeckoView example, same Pixel 8a, Android 17):

https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=be119a4144b917b9b3d6fb104d33d138025b4160&tochange=974d05baa6903a423536f76c22ec3808da0b7846

The range is one push with one changeset: 974d05baa690, Bug 2026000 - Update libcubeb to 774182f2c1b6d5e0d8ce975f2ed9f58fab7f1da2. This confirms comment 3. In that changeset, cubeb_aaudio.cpp drops output_buffer_size_frames = std::max(output_buffer_size_frames, stm->latency_frames / 2), so the low latency output buffer no longer follows the requested latency.

Method: each build opens the single sine page (OscillatorNode 220 Hz -> GainNode 0.05 -> destination). Autoplay is allowed by prefs in the GeckoView config YAML, so the page starts without a gesture. The verdict is automatic: the XRuns of the app's stream in adb shell dumpsys media.aaudio, sampled 10 s after load and again 60 s later. More than 10 XRuns per 60 s is bad. No listening was involved.

19 runs on 17 builds. The two classes separate on every run:

runs buffer capacity Avail XRuns / 60 s
good 5 2112 frames 576 to 1568 frames 0 to 4
bad 14 1536 frames 192 to 384 frames 17 to 157

The capacity changes from 2112 to 1536 frames at the same push as the XRuns, so the two signals agree on every build.

  • Last good, be119a4144b9: capacity 2112, Avail 1408 -> 1472, 0 XRuns in 60 s.
  • First bad, 974d05baa690: capacity 1536, Avail 288 -> 384, 17 XRuns in 60 s.

The per-build log is attached (results.txt).

Profile (about:logging, "Media playback" preset, output to the Firefox Profiler), recorded while the single sine page crackled:
https://profiler.firefox.com/public/28ne45s4c165sevm50eys19g9b189pdg8ttnd18

Note: Firefox updated itself since the report, so this profile is from Firefox 159.0 (build 20261102144711, mozilla-release 7b34a03a910d), not 158.0.2. The crackle is the same: the stream had 86 XRuns in 30 s while the profile was recording. The cubeb log in the profile shows the sizing from comment 3:

AAudio setting low latency mode for stream
AAudio output stream default buffer size: 768
AAudio output stream buffer size requested: 288, actual: 288
AAudio output stream sharing mode: 1
AAudio output stream performance mode: 12
AAudio output stream buffer capacity: 1536
AAudio output stream buffer size: 288
AAudio output stream burst size: 96
AAudio output stream sample-rate: 48000

AAudio's default buffer for this stream is 768 frames, and cubeb reduces it to 288 frames (3 bursts).

Thanks for the bisection, the per-build log and the profile. They answer both requests of comment 3.

Analysis

The mozregression range in comment 5 is one push: changeset 974d05baa690, the libcubeb update of bug 2026000 (Firefox 151). This confirms the regressor in the Regressed by field. The update changes three output settings in aaudio_stream_init_impl (cubeb_aaudio.cpp). It removes the capacity request of two times the requested latency, and the setFramesPerDataCallback call. It also replaces max(3 bursts, latency_frames / 2) with a fixed 3 bursts when the burst is below 128 frames. The bisection does not show which of the three changes matters most.

All 19 runs in attachment 9678174 [details] agree with this. Firefox 151 to 159 ask for 1024 frames on Android. With that request, the old code gave a capacity of 2112 frames and a buffer of at least 576 frames. The new code keeps the AAudio default capacity of 1536 frames. It cuts the AAudio default buffer of 768 frames to 288 frames, or 6 ms.

The about:logging profile in comment 5 has the AudioIPC callback threads and the GraphRunner thread. The graph work is small: MTG::Process takes 55 µs on average, against a burst of 2 ms. The time between two callbacks reaches 9.2 ms, and 124 gaps are longer than 4 ms. This is close to the reported XRun rate. Most of the delay is the wait for GraphRunner to wake up, and the return to the callback thread.

11 of the 12 gaps over 6 ms come within 80 ms of the paint that the page does once per second. Thus the cause is the thread scheduling delay against a 6 ms buffer, not heavy audio work. The profile has no XRun markers, and its libxul stacks have no symbols.

Fix direction

Bug 2009308 (Firefox 160) changes the fix on trunk, because it removed the Android minimum of 1024 frames. Now GetCubebMTGLatencyInFrames returns the cubeb minimum latency (CubebUtils.cpp). The graph then clamps it to 128 frames (GraphDriver.cpp). With 128 frames, latency_frames / 2 is 64 frames, so the old floor alone gives 288 frames again. The bad build of 2026-11-05 in attachment 9678174 [details] (157 XRuns in 60 s) agrees with this.

The fix belongs in upstream libcubeb first, then in the vendored copy. Options are a floor tied to the request together with an Android minimum request in GetCubebMTGLatencyInFrames. Another option is a floor at the AAudio default buffer size. A third option is one more burst after each new XRun from AAudioStream_getXRunCount. The new sizing in bug 2026000 looks intentional, so the choice needs the cubeb owner. Matthew already has the needinfo from comment 3 for this.

No test in the tree can show the XRuns, because they depend on real device scheduling. The dumpsys XRun method of comment 5 on a patched build can confirm a fix. This bug still blocks the crackling meta bug 1951155.


If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.

See Also: → 2009308
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: