Skip to content

Commit c2c6d09

Browse files
committed
Merge branch 'main' into lukas/token-refresh
2 parents e6edd92 + 26b785a commit c2c6d09

File tree

7 files changed

+60
-9
lines changed

7 files changed

+60
-9
lines changed

livekit-api/livekit/api/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.7"
1+
__version__ = "1.1.0"

livekit-api/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"aiohttp>=3.9.0",
5454
"protobuf>=4",
5555
"types-protobuf>=4",
56-
"livekit-protocol>=1.0.4,<2.0.0",
56+
"livekit-protocol>=1.1.1,<2.0.0",
5757
],
5858
package_data={
5959
"livekit.api": ["py.typed", "*.pyi", "**/*.pyi"],

livekit-protocol/livekit/protocol/version.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

livekit-rtc/livekit/rtc/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
ByteStreamWriter,
109109
ByteStreamReader,
110110
)
111+
from .frame_processor import FrameProcessor
111112

112113
__all__ = [
113114
"ConnectionQuality",
@@ -184,6 +185,7 @@
184185
"ByteStreamReader",
185186
"ByteStreamWriter",
186187
"AudioProcessingModule",
188+
"FrameProcessor",
187189
"__version__",
188190
]
189191

livekit-rtc/livekit/rtc/audio_stream.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
from ._proto.track_pb2 import TrackSource
2626
from ._utils import RingQueue, task_done_logger
2727
from .audio_frame import AudioFrame
28+
from .log import logger
2829
from .participant import Participant
2930
from .track import Track
31+
from .frame_processor import FrameProcessor
3032

3133

3234
@dataclass
@@ -62,7 +64,7 @@ def __init__(
6264
sample_rate: int = 48000,
6365
num_channels: int = 1,
6466
frame_size_ms: int | None = None,
65-
noise_cancellation: Optional[NoiseCancellationOptions] = None,
67+
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
6668
**kwargs,
6769
) -> None:
6870
"""Initialize an `AudioStream` instance.
@@ -76,8 +78,8 @@ def __init__(
7678
sample_rate (int, optional): The sample rate for the audio stream in Hz.
7779
Defaults to 48000.
7880
num_channels (int, optional): The number of audio channels. Defaults to 1.
79-
noise_cancellation (Optional[NoiseCancellationOptions], optional):
80-
If noise cancellation is used, pass a `NoiseCancellationOptions` instance
81+
noise_cancellation (Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]], optional):
82+
If noise cancellation is used, pass a `NoiseCancellationOptions` or `FrameProcessor[AudioFrame]` instance
8183
created by the noise cancellation module.
8284
8385
Example:
@@ -105,9 +107,12 @@ def __init__(
105107

106108
self._audio_filter_module = None
107109
self._audio_filter_options = None
108-
if noise_cancellation is not None:
110+
if isinstance(noise_cancellation, NoiseCancellationOptions):
109111
self._audio_filter_module = noise_cancellation.module_id
110112
self._audio_filter_options = noise_cancellation.options
113+
elif isinstance(noise_cancellation, FrameProcessor):
114+
self._processor = noise_cancellation
115+
111116
self._task = self._loop.create_task(self._run())
112117
self._task.add_done_callback(task_done_logger)
113118

@@ -132,7 +137,7 @@ def from_participant(
132137
sample_rate: int = 48000,
133138
num_channels: int = 1,
134139
frame_size_ms: int | None = None,
135-
noise_cancellation: Optional[NoiseCancellationOptions] = None,
140+
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
136141
) -> AudioStream:
137142
"""Create an `AudioStream` from a participant's audio track.
138143
@@ -182,7 +187,7 @@ def from_track(
182187
sample_rate: int = 48000,
183188
num_channels: int = 1,
184189
frame_size_ms: int | None = None,
185-
noise_cancellation: Optional[NoiseCancellationOptions] = None,
190+
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
186191
) -> AudioStream:
187192
"""Create an `AudioStream` from an existing audio track.
188193
@@ -268,6 +273,14 @@ async def _run(self):
268273
if audio_event.HasField("frame_received"):
269274
owned_buffer_info = audio_event.frame_received.frame
270275
frame = AudioFrame._from_owned_info(owned_buffer_info)
276+
if self._processor is not None and self._processor.enabled:
277+
try:
278+
frame = self._processor._process(frame)
279+
except Exception:
280+
logger.warning(
281+
"Frame processing failed, passing through original frame",
282+
exc_info=True,
283+
)
271284
event = AudioFrameEvent(frame)
272285
self._queue.put(event)
273286
elif audio_event.HasField("eos"):
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from abc import ABC, abstractmethod
2+
from typing import Generic, TypeVar, Union
3+
from .audio_frame import AudioFrame
4+
from .video_frame import VideoFrame
5+
6+
7+
T = TypeVar("T", bound=Union[AudioFrame, VideoFrame])
8+
9+
10+
class FrameProcessor(Generic[T], ABC):
11+
@property
12+
@abstractmethod
13+
def enabled(self) -> bool: ...
14+
15+
@enabled.setter
16+
@abstractmethod
17+
def enabled(self, value: bool) -> None: ...
18+
19+
def _on_stream_info_updated(
20+
self,
21+
*,
22+
room_name: str,
23+
participant_identity: str,
24+
publication_sid: str,
25+
): ...
26+
27+
def _on_credentials_updated(self, *, token: str, url: str): ...
28+
29+
@abstractmethod
30+
def _process(self, frame: T) -> T: ...
31+
32+
@abstractmethod
33+
def _close(self): ...

livekit-rtc/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ manylinux-s390x-image = "manylinux_2_28"
2020
manylinux-pypy_x86_64-image = "manylinux_2_28"
2121
manylinux-pypy_i686-image = "manylinux_2_28"
2222
manylinux-pypy_aarch64-image = "manylinux_2_28"
23+
24+
[tool.cibuildwheel.linux]
25+
before-build = "pip install requests && python rust-sdks/download_ffi.py --output livekit/rtc/resources && yum install -y libX11-devel libXrandr-devel libXext-devel libXfixes-devel libXdamage-devel libXcomposite-devel libXi-devel mesa-libGL-devel || apt install -y xorg-dev"

0 commit comments

Comments
 (0)