mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Audio: DirectAudio for games, and the microphone, from Bannerlator's Linux session
Two opt-ins on a new Audio screen, both ported from Bannerlator's gamescope runtime where they are proven with voice in Steam's own tester. DirectAudio replaces the audio driver inside the games the client launches - Wine's mmdevapi driver, glibc build - with one that talks to a helper on the Android side over a unix socket. The client keeps PulseAudio either way: it is a native Linux program with no other way to make a sound. The helper runs here because nothing inside the session can open Android's audio: a game is a glibc process in a rootfs that binds no /system, and the uid the helper runs under is what the recording permission is checked against. The microphone is its own opt-in. The helper opens the input stream only when asked and writes it to a pipe; PulseAudio's module-pipe-source turns that into a source the client sees as DirectAudioMic. The daemon makes the pipe and the helper waits for it - the two used to race, and the module fails on EEXIST. The Proton wrappers gain Bannerlator's bl_directaudio, which adds the driver's directory to WINEDLLPATH and names the driver in the prefix, and refuses on any Proton that is not Wine 11 rather than pair a driver with an interface it was not built against, which would be silence rather than an error. bl_game_cpus comes along in the same splice and is inert until BL_GAME_CPUS is set. The driver is staged into the runtime at every launch like the session scripts; the helper ships as libdirectaudiorelay.so beside the PulseAudio daemon. Both are the binaries Bannerlator carries, built by The412Banner/directaudio's relay workflow (linux-wine11 build against ValveSoftware/wine proton_11.0).
This commit is contained in:
1 parent
3182ba780e
commit
f542e59a20
17 files changed
+534
-11
No files matched your search
@@ -70,6 +70,58 @@ TOOL_MANIFEST_VDF = """"manifest"
|
||||
}
|
||||
""" % LAUNCHER
|
||||
|
||||
# Resolves the depot at launch time, so the tool can be registered before the depot exists and
|
||||
# survives the client updating or replacing it. Proton takes its base directory from
|
||||
# dirname(sys.argv[0]) without resolving it, so it is run from the depot itself.
|
||||
# Cores for a game the client launches, kept separate from the client's own. One mask suits the
|
||||
# client's menus and another suits a game, and they are wanted at the same time - so the game's is
|
||||
# applied here, in the launch path every game goes through, rather than to the session as a whole.
|
||||
BL_GAME_CPUS_SETUP = """
|
||||
bl_game_cpus() {
|
||||
[ -n "${BL_GAME_CPUS:-}" ] || return 0
|
||||
command -v taskset >/dev/null 2>&1 || return 0
|
||||
# exec'd through taskset rather than set afterwards: a mask applied to a pid races the process
|
||||
# into spawning its own threads, and this way every thread inherits it from the first instruction.
|
||||
BL_TASKSET="taskset -c $BL_GAME_CPUS"
|
||||
echo "bannerlator-proton: game cores $BL_GAME_CPUS" >&2
|
||||
}
|
||||
"""
|
||||
|
||||
BL_DIRECTAUDIO_SETUP = """
|
||||
bl_directaudio() {
|
||||
base=$1
|
||||
[ -n "${BL_DIRECTAUDIO:-}" ] || return 0
|
||||
[ -d "$BL_DIRECTAUDIO/lib/wine" ] || return 0
|
||||
version=$("$base/files/bin-arm64/wine" --version 2>/dev/null)
|
||||
major=${version#wine-}
|
||||
major=${major%%.*}
|
||||
if [ "$major" != "11" ]; then
|
||||
echo "bannerlator-proton: DirectAudio left off - it is built for Wine 11 and this Proton is '${version:-unknown}'. Pairing them would be silent rather than broken, so it is not worth guessing." >&2
|
||||
return 0
|
||||
fi
|
||||
# Wine appends the per-architecture subdirectory to each entry, so the directory holding
|
||||
# aarch64-unix/ and aarch64-windows/ is what goes here.
|
||||
WINEDLLPATH="$BL_DIRECTAUDIO/lib/wine${WINEDLLPATH:+:$WINEDLLPATH}"
|
||||
export WINEDLLPATH
|
||||
# mmdevapi only tries the drivers named in the registry; its built-in list is pulse, alsa, oss and
|
||||
# coreaudio and knows nothing about this one. The key is appended to the prefix's user.reg rather
|
||||
# than written with `wine reg`, which would start a wineserver here just to set one value.
|
||||
reg="${STEAM_COMPAT_DATA_PATH:-}/pfx/user.reg"
|
||||
if [ -f "$reg" ]; then
|
||||
if ! grep -q '"Audio"="directaudio"' "$reg" 2>/dev/null; then
|
||||
printf '\n[Software\\\\Wine\\\\Drivers] %s\n"Audio"="directaudio"\n' "$(date +%s)" >> "$reg"
|
||||
echo "bannerlator-proton: DirectAudio selected in the prefix" >&2
|
||||
fi
|
||||
else
|
||||
# A prefix that does not exist yet is created by Proton moments from now, after this runs, so
|
||||
# the key lands on the NEXT launch of that game. Said out loud because silent audio on a first
|
||||
# launch would otherwise look like a fault.
|
||||
echo "bannerlator-proton: no prefix yet - DirectAudio takes effect the next time this game starts" >&2
|
||||
fi
|
||||
echo "bannerlator-proton: DirectAudio ready (Wine $major)" >&2
|
||||
}
|
||||
"""
|
||||
|
||||
# Resolves the depot at launch time, so the tool can be registered before the depot exists and
|
||||
# survives the client updating or replacing it. Proton takes its base directory from
|
||||
# dirname(sys.argv[0]) without resolving it, so it is run from the depot itself.
|
||||
@@ -98,12 +150,19 @@ fi
|
||||
for name in %s; do
|
||||
depot="$steam_root/steamapps/common/$name"
|
||||
if [ -d "$depot/files/bin-arm64" ] && [ -x "$depot/proton" ]; then
|
||||
exec "$depot/proton" "$verb" "$@"
|
||||
bl_directaudio "$depot"
|
||||
bl_game_cpus
|
||||
exec ${BL_TASKSET:-} "$depot/proton" "$verb" "$@"
|
||||
fi
|
||||
done
|
||||
echo "bannerlator-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
|
||||
exit 1
|
||||
""" % " ".join('"%s"' % n for n in SOURCES)
|
||||
# Spliced in after the formatting above, never through it: the function body contains ${major%%.*}
|
||||
# and a % format would eat that into a single %, leaving a shell expansion that silently does
|
||||
# something else.
|
||||
LAUNCHER_SH = LAUNCHER_SH.replace(
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP, 1)
|
||||
|
||||
# A third-party Proton dropped into compatibilitytools.d - GE-Proton, proton-cachyos, anything of
|
||||
# that shape - is adopted rather than used as shipped, for the same two reasons Valve's ARM64 depot
|
||||
@@ -135,9 +194,11 @@ if [ -f "$fake" ]; then
|
||||
*) LD_PRELOAD="$fake${LD_PRELOAD:+:$LD_PRELOAD}"; export LD_PRELOAD ;;
|
||||
esac
|
||||
fi
|
||||
bl_directaudio "$here"
|
||||
bl_game_cpus
|
||||
# Proton takes its base directory from dirname(sys.argv[0]) without resolving it, so it has to be
|
||||
# started from its own tree.
|
||||
exec "$here/%s" "$verb" "$@"
|
||||
exec ${BL_TASKSET:-} "$here/%s" "$verb" "$@"
|
||||
"""
|
||||
EXTRA_COMPAT_TOOL_VDF = """"compatibilitytools"
|
||||
{
|
||||
@@ -292,8 +353,13 @@ def adopt_extras(tools):
|
||||
name = first_key(compat_vdf, ["compatibilitytools", "compat_tools"]) or entry
|
||||
wrapper = os.path.join(tool_dir, EXTRA_WRAPPER)
|
||||
try:
|
||||
# Formatted first, spliced second: the function carries a printf %s and a
|
||||
# ${major%%.*} of its own, and putting it through the format would eat both.
|
||||
body = (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP, 1)
|
||||
with open(wrapper, "w", encoding="utf-8") as f:
|
||||
f.write(EXTRA_WRAPPER_SH % entry_point)
|
||||
f.write(body)
|
||||
os.chmod(wrapper, 0o755)
|
||||
with open(manifest, "w", encoding="utf-8") as f:
|
||||
f.write(EXTRA_MANIFEST_VDF)
|
||||
|
||||
Reference in new issue
Block a user