Skip to content

Commit a6114dc

Browse files
authored
feat: ffi improvements (#50)
1 parent 5204b14 commit a6114dc

28 files changed

+1492
-538
lines changed

client-sdk-rust

examples/basic_room.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ def on_track_unsubscribed(track: livekit.Track,
8080
participant: livekit.RemoteParticipant):
8181
logging.info("track unsubscribed: %s", publication.sid)
8282

83+
@room.listens_to("track_muted")
84+
def on_track_muted(publication: livekit.RemoteTrackPublication,
85+
participant: livekit.RemoteParticipant):
86+
logging.info("track muted: %s", publication.sid)
87+
88+
@room.listens_to("track_unmuted")
89+
def on_track_unmuted(publication: livekit.RemoteTrackPublication,
90+
participant: livekit.RemoteParticipant):
91+
logging.info("track unmuted: %s", publication.sid)
92+
8393
@room.listens_to("data_received")
8494
def on_data_received(data: bytes,
8595
kind: livekit.DataPacketKind,

examples/publish_wave.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,33 @@
99
URL = 'ws://localhost:7880'
1010
TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDY2MTMyODgsImlzcyI6IkFQSVRzRWZpZFpqclFvWSIsIm5hbWUiOiJuYXRpdmUiLCJuYmYiOjE2NzI2MTMyODgsInN1YiI6Im5hdGl2ZSIsInZpZGVvIjp7InJvb20iOiJ0ZXN0Iiwicm9vbUFkbWluIjp0cnVlLCJyb29tQ3JlYXRlIjp0cnVlLCJyb29tSm9pbiI6dHJ1ZSwicm9vbUxpc3QiOnRydWV9fQ.uSNIangMRu8jZD5mnRYoCHjcsQWCrJXgHCs0aNIgBFY'
1111

12+
SAMPLE_RATE = 48000
13+
NUM_CHANNELS = 1
14+
1215

1316
async def publish_frames(source: livekit.AudioSource):
14-
sample_rate = 48000
1517
frequency = 440
1618
amplitude = 32767 # for 16-bit audio
17-
num_channels = 1
1819
samples_per_channel = 480 # 10ms at 48kHz
19-
time = np.arange(samples_per_channel) / sample_rate
20+
time = np.arange(samples_per_channel) / SAMPLE_RATE
2021
total_samples = 0
2122

2223
audio_frame = livekit.AudioFrame.create(
23-
sample_rate, num_channels, samples_per_channel)
24+
SAMPLE_RATE, NUM_CHANNELS, samples_per_channel)
2425

2526
audio_data = np.ctypeslib.as_array(audio_frame.data)
2627

2728
while True:
28-
time = (total_samples + np.arange(samples_per_channel)) / sample_rate
29+
time = (total_samples + np.arange(samples_per_channel)) / SAMPLE_RATE
2930

3031
sine_wave = (amplitude * np.sin(2 * np.pi *
3132
frequency * time)).astype(np.int16)
3233
np.copyto(audio_data, sine_wave)
3334

34-
source.capture_frame(audio_frame)
35+
await source.capture_frame(audio_frame)
3536

3637
total_samples += samples_per_channel
3738

38-
try:
39-
await asyncio.sleep(1 / 100) # 10m
40-
except asyncio.CancelledError:
41-
break
42-
4339

4440
async def main() -> None:
4541
room = livekit.Room()
@@ -53,7 +49,7 @@ async def main() -> None:
5349
return
5450

5551
# publish a track
56-
source = livekit.AudioSource()
52+
source = livekit.AudioSource(SAMPLE_RATE, NUM_CHANNELS)
5753
source_task = asyncio.create_task(publish_frames(source))
5854

5955
track = livekit.LocalAudioTrack.create_audio_track("sinewave", source)

generate_proto.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ protoc \
2929
$FFI_PROTOCOL/participant.proto \
3030
$FFI_PROTOCOL/room.proto \
3131
$FFI_PROTOCOL/track.proto \
32-
$FFI_PROTOCOL/video_frame.proto
32+
$FFI_PROTOCOL/video_frame.proto \
33+
$FFI_PROTOCOL/e2ee.proto
3334

3435
touch -a "$OUT_PYTHON/__init__.py"
3536

3637
for f in "$OUT_PYTHON"/*.py "$OUT_PYTHON"/*.pyi; do
37-
perl -i -pe 's|^(import (audio_frame_pb2\|ffi_pb2\|handle_pb2\|participant_pb2\|room_pb2\|track_pb2\|video_frame_pb2))|from . $1|g' "$f"
38+
perl -i -pe 's|^(import (audio_frame_pb2\|ffi_pb2\|handle_pb2\|participant_pb2\|room_pb2\|track_pb2\|video_frame_pb2\|e2ee_pb2))|from . $1|g' "$f"
3839
done
3940

livekit/_ffi_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import ctypes
1717
import os
1818
import platform
19-
import threading
2019

2120
import pkg_resources
2221
from pyee.asyncio import EventEmitter

livekit/_proto/audio_frame_pb2.py

Lines changed: 50 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)