audio: add deafened property to suppress playback

When deafened, playback callback writes silence and
queue_playback discards incoming PCM.
This commit is contained in:
Username
2026-02-24 12:58:39 +01:00
parent 31ac90d2c9
commit 3bbe8a96f3
2 changed files with 46 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ def test_default_construction():
assert ap._input_device is None
assert ap._output_device is None
assert ap.capturing is False
assert ap.deafened is False
def test_custom_construction():
@@ -89,6 +90,37 @@ def test_queue_playback_overflow_drops():
assert ap._playback_queue.qsize() == ap._playback_queue.maxsize
def test_deafened_toggle():
ap = AudioPipeline()
assert ap.deafened is False
ap.deafened = True
assert ap.deafened is True
ap.deafened = False
assert ap.deafened is False
def test_queue_playback_discards_when_deafened():
"""Incoming PCM is dropped when deafened."""
ap = AudioPipeline()
ap.deafened = True
ap.queue_playback(b"\x42" * 100)
assert ap._playback_queue.qsize() == 0
def test_playback_callback_silence_when_deafened():
"""Playback callback writes silence when deafened, even with queued data."""
ap = AudioPipeline()
frame_bytes = FRAME_SIZE * 2
# Queue data before deafening
pcm = b"\x42" * frame_bytes
ap.queue_playback(pcm)
ap.deafened = True
outdata = bytearray(b"\xff" * frame_bytes)
ap._playback_callback(outdata, FRAME_SIZE, None, None)
assert outdata == bytearray(frame_bytes) # all zeros
def test_stop_without_start():
"""Stop on unstarted pipeline should not raise."""
ap = AudioPipeline()