87 lines
3.7 KiB
Python
87 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Opt-in PipeWire integration check using only an isolated synthetic tone.
|
|
|
|
Creates a temporary null output, plays a fixture into it, captures that fixture
|
|
stream, then removes the fixture to verify capture errors instead of falling back.
|
|
Does not change the default device, record private audio, or write system config.
|
|
Requires a running PipeWire/Pulse compatibility server, pactl and GStreamer tools.
|
|
"""
|
|
import json
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
|
|
|
|
def command(*args):
|
|
return subprocess.check_output(args, text=True).strip()
|
|
|
|
|
|
def nodes():
|
|
return [item for item in json.loads(command("pw-dump"))
|
|
if item.get("type") == "PipeWire:Interface:Node"]
|
|
|
|
|
|
def props(node):
|
|
return node.get("info", {}).get("props", {})
|
|
|
|
|
|
def stop(process):
|
|
if process and process.poll() is None:
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=3)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait()
|
|
|
|
|
|
module = None
|
|
playback = None
|
|
capture = None
|
|
with tempfile.TemporaryFile(mode="w+") as playback_log:
|
|
try:
|
|
module = command("pactl", "load-module", "module-null-sink",
|
|
"sink_name=vnox_capture_fixture",
|
|
"sink_properties=device.description=VNOX-Capture-Fixture")
|
|
time.sleep(0.2)
|
|
sink = next(node for node in nodes()
|
|
if props(node).get("node.name") == "vnox_capture_fixture")
|
|
sink_serial = str(props(sink)["object.serial"])
|
|
playback = subprocess.Popen([
|
|
"gst-launch-1.0", "-q", "audiotestsrc", "is-live=true", "freq=523",
|
|
"!", "audioconvert", "!", "audio/x-raw,rate=48000,channels=2,format=F32LE",
|
|
"!", "pipewiresink", "target-object=" + sink_serial,
|
|
"sync=false", "async=false", "client-name=CaptureFixture",
|
|
"stream-properties=props,node.name=CaptureFixture,media.name=CaptureFixture,node.dont-fallback=true",
|
|
], stdout=subprocess.DEVNULL, stderr=playback_log)
|
|
fixture = None
|
|
for _ in range(40):
|
|
time.sleep(0.1)
|
|
fixture = next((node for node in nodes()
|
|
if props(node).get("node.name") == "CaptureFixture"), None)
|
|
if fixture:
|
|
break
|
|
assert fixture is not None, "Synthetic application did not appear"
|
|
serial = str(props(fixture)["object.serial"])
|
|
capture = subprocess.Popen([
|
|
"gst-launch-1.0", "-m", "pipewiresrc", "target-object=" + serial,
|
|
"on-disconnect=error",
|
|
"stream-properties=props,stream.capture.sink=true,stream.monitor=true,node.dont-fallback=true,node.dont-reconnect=true,node.dont-move=true",
|
|
"!", "audioconvert", "!", "audio/x-raw,format=F32LE,rate=48000,channels=2",
|
|
"!", "level", "message=true", "interval=100000000",
|
|
"!", "fakesink", "sync=false",
|
|
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
time.sleep(1.2)
|
|
stop(playback)
|
|
stdout, stderr = capture.communicate(timeout=5)
|
|
levels = [float(value) for value in re.findall(r"rms=\(GValueArray\)<\s*([-0-9.]+)", stdout)]
|
|
assert levels and max(levels) > -20, "Selected synthetic application produced no captured audio"
|
|
assert capture.returncode != 0 and ("destroyed" in stderr or "removed" in stderr), \
|
|
"Capture must stop with an explicit disconnect error when the selected app exits"
|
|
print(f"PASS: selected fixture stream captured ({max(levels):.1f} dB RMS); app exit stopped capture without fallback.")
|
|
finally:
|
|
stop(capture)
|
|
stop(playback)
|
|
if module:
|
|
subprocess.run(["pactl", "unload-module", module], check=True)
|