Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ffi improvements #50

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client-sdk-rust
10 changes: 10 additions & 0 deletions examples/basic_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def on_track_unsubscribed(track: livekit.Track,
participant: livekit.RemoteParticipant):
logging.info("track unsubscribed: %s", publication.sid)

@room.listens_to("track_muted")
def on_track_muted(publication: livekit.RemoteTrackPublication,
participant: livekit.RemoteParticipant):
logging.info("track muted: %s", publication.sid)

@room.listens_to("track_unmuted")
def on_track_unmuted(publication: livekit.RemoteTrackPublication,
participant: livekit.RemoteParticipant):
logging.info("track unmuted: %s", publication.sid)

@room.listens_to("data_received")
def on_data_received(data: bytes,
kind: livekit.DataPacketKind,
Expand Down
20 changes: 8 additions & 12 deletions examples/publish_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,33 @@
URL = 'ws://localhost:7880'
TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDY2MTMyODgsImlzcyI6IkFQSVRzRWZpZFpqclFvWSIsIm5hbWUiOiJuYXRpdmUiLCJuYmYiOjE2NzI2MTMyODgsInN1YiI6Im5hdGl2ZSIsInZpZGVvIjp7InJvb20iOiJ0ZXN0Iiwicm9vbUFkbWluIjp0cnVlLCJyb29tQ3JlYXRlIjp0cnVlLCJyb29tSm9pbiI6dHJ1ZSwicm9vbUxpc3QiOnRydWV9fQ.uSNIangMRu8jZD5mnRYoCHjcsQWCrJXgHCs0aNIgBFY'

SAMPLE_RATE = 48000
NUM_CHANNELS = 1


async def publish_frames(source: livekit.AudioSource):
sample_rate = 48000
frequency = 440
amplitude = 32767 # for 16-bit audio
num_channels = 1
samples_per_channel = 480 # 10ms at 48kHz
time = np.arange(samples_per_channel) / sample_rate
time = np.arange(samples_per_channel) / SAMPLE_RATE
total_samples = 0

audio_frame = livekit.AudioFrame.create(
sample_rate, num_channels, samples_per_channel)
SAMPLE_RATE, NUM_CHANNELS, samples_per_channel)

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

while True:
time = (total_samples + np.arange(samples_per_channel)) / sample_rate
time = (total_samples + np.arange(samples_per_channel)) / SAMPLE_RATE

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

source.capture_frame(audio_frame)
await source.capture_frame(audio_frame)

total_samples += samples_per_channel

try:
await asyncio.sleep(1 / 100) # 10m
except asyncio.CancelledError:
break


async def main() -> None:
room = livekit.Room()
Expand All @@ -53,7 +49,7 @@ async def main() -> None:
return

# publish a track
source = livekit.AudioSource()
source = livekit.AudioSource(SAMPLE_RATE, NUM_CHANNELS)
source_task = asyncio.create_task(publish_frames(source))

track = livekit.LocalAudioTrack.create_audio_track("sinewave", source)
Expand Down
5 changes: 3 additions & 2 deletions generate_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ protoc \
$FFI_PROTOCOL/participant.proto \
$FFI_PROTOCOL/room.proto \
$FFI_PROTOCOL/track.proto \
$FFI_PROTOCOL/video_frame.proto
$FFI_PROTOCOL/video_frame.proto \
$FFI_PROTOCOL/e2ee.proto

touch -a "$OUT_PYTHON/__init__.py"

for f in "$OUT_PYTHON"/*.py "$OUT_PYTHON"/*.pyi; do
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"
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"
done

1 change: 0 additions & 1 deletion livekit/_ffi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import ctypes
import os
import platform
import threading

import pkg_resources
from pyee.asyncio import EventEmitter
Expand Down
90 changes: 50 additions & 40 deletions livekit/_proto/audio_frame_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading