Skip to content

Commit 8d5e656

Browse files
committed
fix: rename noise_cancellation_leave_open -> auto_close_noise_cancellation
1 parent 75d8874 commit 8d5e656

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

livekit-rtc/livekit/rtc/audio_stream.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
num_channels: int = 1,
6666
frame_size_ms: int | None = None,
6767
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
68-
noise_cancellation_leave_open: bool = False,
68+
auto_close_noise_cancellation: bool = True,
6969
**kwargs: Any,
7070
) -> None:
7171
"""Initialize an `AudioStream` instance.
@@ -82,9 +82,9 @@ def __init__(
8282
noise_cancellation (Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]], optional):
8383
If noise cancellation is used, pass a `NoiseCancellationOptions` or `FrameProcessor[AudioFrame]` instance
8484
created by the noise cancellation module.
85-
noise_cancellation_leave_open (bool):
86-
When the audio stream closes, leaves the FrameProcessor in an unclosed state so it
87-
can be used with another AudioStream.
85+
auto_close_noise_cancellation (bool):
86+
When the audio stream closes, should the FrameProcessor's close method be run? If
87+
False, then the frame processor can be reused with another AudioStream.
8888
8989
Example:
9090
```python
@@ -117,13 +117,13 @@ def __init__(
117117
self._audio_filter_module: str | None = None
118118
self._audio_filter_options: dict[str, Any] | None = None
119119
self._processor: FrameProcessor[AudioFrame] | None = None
120-
self._processor_leave_open = False
120+
self._processor_auto_close = True
121121
if isinstance(noise_cancellation, NoiseCancellationOptions):
122122
self._audio_filter_module = noise_cancellation.module_id
123123
self._audio_filter_options = noise_cancellation.options
124124
elif isinstance(noise_cancellation, FrameProcessor):
125125
self._processor = noise_cancellation
126-
self._processor_leave_open = noise_cancellation_leave_open
126+
self._processor_auto_close = auto_close_noise_cancellation
127127

128128
self._task = self._loop.create_task(self._run())
129129
self._task.add_done_callback(task_done_logger)
@@ -153,7 +153,7 @@ def from_participant(
153153
num_channels: int = 1,
154154
frame_size_ms: int | None = None,
155155
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
156-
noise_cancellation_leave_open: bool = False,
156+
auto_close_noise_cancellation: bool = False,
157157
) -> AudioStream:
158158
"""Create an `AudioStream` from a participant's audio track.
159159
@@ -191,7 +191,7 @@ def from_participant(
191191
num_channels=num_channels,
192192
frame_size_ms=frame_size_ms,
193193
noise_cancellation=noise_cancellation,
194-
noise_cancellation_leave_open=noise_cancellation_leave_open,
194+
auto_close_noise_cancellation=auto_close_noise_cancellation,
195195
)
196196

197197
@classmethod
@@ -205,7 +205,7 @@ def from_track(
205205
num_channels: int = 1,
206206
frame_size_ms: int | None = None,
207207
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
208-
noise_cancellation_leave_open: bool = False,
208+
auto_close_noise_cancellation: bool = False,
209209
) -> AudioStream:
210210
"""Create an `AudioStream` from an existing audio track.
211211
@@ -218,7 +218,7 @@ def from_track(
218218
noise_cancellation (Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]], optional):
219219
If noise cancellation is used, pass a `NoiseCancellationOptions` or `FrameProcessor[AudioFrame]` instance
220220
created by the noise cancellation module.
221-
noise_cancellation_leave_open (bool):
221+
auto_close_noise_cancellation (bool):
222222
When the audio stream closes, leaves the FrameProcessor in an unclosed state so it
223223
can be used with another AudioStream.
224224
@@ -242,7 +242,7 @@ def from_track(
242242
num_channels=num_channels,
243243
frame_size_ms=frame_size_ms,
244244
noise_cancellation=noise_cancellation,
245-
noise_cancellation_leave_open=noise_cancellation_leave_open,
245+
auto_close_noise_cancellation=auto_close_noise_cancellation,
246246
)
247247

248248
def __del__(self) -> None:
@@ -323,7 +323,7 @@ async def aclose(self) -> None:
323323
self._track._unregister_audio_stream(self)
324324
self._ffi_handle.dispose()
325325
await self._task
326-
if self._processor is not None and not self._processor_leave_open:
326+
if self._processor is not None and self._processor_auto_close:
327327
self._processor._close()
328328

329329
def _is_event(self, e: proto_ffi.FfiEvent) -> bool:

livekit-rtc/tests/test_audio_stream_room_lifecycle.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- `_on_stream_info_updated` / `_on_credentials_updated` on every room transition
88
or token refresh,
99
- `_on_stream_info_cleared` / `_on_credentials_cleared` when the track leaves a room,
10-
and that `AudioStream.aclose()` honors `noise_cancellation_leave_open`.
10+
and that `AudioStream.aclose()` honors `auto_close_noise_cancellation`.
1111
"""
1212

1313
from __future__ import annotations
@@ -91,11 +91,11 @@ def _make_closeable_stream(
9191
*,
9292
track: Optional[rtc.Track] = None,
9393
processor: Optional[rtc.FrameProcessor[rtc.AudioFrame]] = None,
94-
leave_open: bool = False,
94+
auto_close: bool = True,
9595
) -> rtc.AudioStream:
9696
"""Extends _make_stream with the minimal state `aclose()` touches."""
9797
stream = _make_stream(track=track, processor=processor)
98-
stream._processor_leave_open = leave_open
98+
stream._processor_auto_close = auto_close
9999
stream._task = asyncio.ensure_future(asyncio.sleep(0))
100100
stream._ffi_handle = cast(Any, SimpleNamespace(dispose=lambda: None))
101101
return stream
@@ -446,24 +446,24 @@ def test_unregister_one_of_many_streams_only_fans_out_to_remaining() -> None:
446446

447447

448448
@pytest.mark.asyncio
449-
async def test_aclose_closes_processor_when_leave_open_false() -> None:
449+
async def test_aclose_closes_processor_when_auto_close_true() -> None:
450450
"""`aclose()` calls `_close()` on the attached FrameProcessor when
451-
`noise_cancellation_leave_open` is False (the default)."""
451+
`auto_close_noise_cancellation` is True (the default)."""
452452
processor = _RecordingProcessor()
453-
stream = _make_closeable_stream(processor=processor, leave_open=False)
453+
stream = _make_closeable_stream(processor=processor, auto_close=True)
454454

455455
await stream.aclose()
456456

457457
assert processor.close_calls == 1
458458

459459

460460
@pytest.mark.asyncio
461-
async def test_aclose_leaves_processor_open_when_leave_open_true() -> None:
462-
"""`aclose()` does NOT call `_close()` when `noise_cancellation_leave_open`
463-
is True — the agents SDK path for sharing one processor across many track
461+
async def test_aclose_leaves_processor_open_when_auto_close_false() -> None:
462+
"""`aclose()` does NOT call `_close()` when `auto_close_noise_cancellation`
463+
is False — the agents SDK path for sharing one processor across many track
464464
attach/detach cycles."""
465465
processor = _RecordingProcessor()
466-
stream = _make_closeable_stream(processor=processor, leave_open=True)
466+
stream = _make_closeable_stream(processor=processor, auto_close=False)
467467

468468
await stream.aclose()
469469

0 commit comments

Comments
 (0)