diff --git a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java index cb18481d2c..4f3bd64bd4 100644 --- a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java +++ b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java @@ -63,6 +63,19 @@ public class PulseAudioComponent extends SessionPart { this.relaySocketPath = path; } + /** CRC-32 of the bundled pulseaudio.tzst, or "?" if it cannot be read. About 600 KB; cheap. */ + private String bundleChecksum() { + java.util.zip.CRC32 crc = new java.util.zip.CRC32(); + byte[] buf = new byte[64 * 1024]; + try (java.io.InputStream in = app().getAssets().open("pulseaudio.tzst")) { + int n; + while ((n = in.read(buf)) > 0) crc.update(buf, 0, n); + } catch (java.io.IOException e) { + return "?"; + } + return Long.toHexString(crc.getValue()); + } + /** Send the daemon's output to this file as well as logcat. Set before {@link #start()}. */ public void setLogFile(File file) { this.logFile = file; @@ -86,17 +99,19 @@ public class PulseAudioComponent extends SessionPart { // once ever: an installed app kept the modules it unpacked on its first run, so a bundle // fixed in a later build never reached the device - which is how a 17.0 glibc build of // module-pipe-source sat beside the 13.0 daemon, failed to dlopen, and the microphone - // never appeared. Bump the stamp whenever pulseaudio.tzst changes. + // never appeared. The stamp carries a checksum of the bundle itself, so any change to it - + // a rebuilt sink module included - re-unpacks, whether or not BUNDLE_STAMP was bumped. File modulesDir = new File(workingDir, "modules"); File stamp = new File(modulesDir, ".bundle"); String have = FileUtils.readString(stamp); + String want = BUNDLE_STAMP + "-" + bundleChecksum(); if (!new File(modulesDir, "arm64/module-aaudio-sink.so").isFile() || !new File(workingDir, "pactl").isFile() - || have == null || !BUNDLE_STAMP.equals(have.trim())) { - Log.i(TAG, "unpacking pulseaudio.tzst (" + BUNDLE_STAMP + "; had " + have + ")"); + || have == null || !want.equals(have.trim())) { + Log.i(TAG, "unpacking pulseaudio.tzst (" + want + "; had " + have + ")"); FileUtils.delete(modulesDir); if (TarZst.extractAsset(app(), "pulseaudio.tzst", workingDir)) { - FileUtils.writeString(stamp, BUNDLE_STAMP); + FileUtils.writeString(stamp, want); } else { Log.e(TAG, "pulseaudio.tzst did not unpack"); } diff --git a/tools/aaudio-sink/module-directaudio-sink.c b/tools/aaudio-sink/module-directaudio-sink.c index 3e21128b18..b17520f0a3 100644 --- a/tools/aaudio-sink/module-directaudio-sink.c +++ b/tools/aaudio-sink/module-directaudio-sink.c @@ -102,6 +102,7 @@ struct userdata { pa_usec_t offline_at; pa_usec_t stats_at; uint32_t underruns_reported; + pa_usec_t settled_at; }; static void disconnect_relay(struct userdata *u) { @@ -189,9 +190,10 @@ static int connect_relay(struct userdata *u) { if (u->ring->rate != u->ss.rate) pa_log("directaudio-sink: the relay's ring runs at %u Hz, the sink at %u; expect resampling artefacts", u->ring->rate, u->ss.rate); u->stats_at = pa_rtclock_now(); + u->settled_at = u->stats_at + 10 * PA_USEC_PER_SEC; u->underruns_reported = u->ring->underruns; - pa_log("directaudio-sink: connected to the relay: %d Hz, burst %d, device buffer %d frames, ring %d frames, target %d", - ack.rate, ack.burst, ack.buf_frames, ack.out_cap_frames, (int) u->ring->target_frames); + pa_log("directaudio-sink: connected to the relay: %d Hz, burst %d, device buffer %d frames (asked %u ms), ring %d frames, target %d", + ack.rate, ack.burst, ack.buf_frames, u->buffer_ms, ack.out_cap_frames, (int) u->ring->target_frames); return 0; fail: @@ -262,6 +264,12 @@ static int service_ring(struct userdata *u) { if (want > 0) produce(u, want); } + /* Once, ten seconds in: what the relay's buffer has settled at, so a session log shows it. */ + if (u->settled_at && pa_rtclock_now() >= u->settled_at) { + pa_log("directaudio-sink: after 10 s: device buffer %d frames, ring target %d, relay underruns %u", + (int) r->hw_buf_frames, (int) r->target_frames, r->underruns); + u->settled_at = 0; + } if (r->underruns != u->underruns_reported && pa_rtclock_now() - u->stats_at >= STATS_EVERY_USEC) { pa_log("directaudio-sink: relay reports %u underrun(s), target %d frames, device buffer %d", r->underruns, (int) r->target_frames, (int) r->hw_buf_frames); u->underruns_reported = r->underruns;