audio: add deafened property to suppress playback
When deafened, playback callback writes silence and queue_playback discards incoming PCM.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user