Skip to content

fix: correctly unsubscribe to the ffi queue #72

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

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 1 addition & 10 deletions examples/publish_wave.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import time
import logging
from signal import SIGINT, SIGTERM

Expand All @@ -12,30 +13,22 @@
SAMPLE_RATE = 48000
NUM_CHANNELS = 1


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

audio_frame = livekit.AudioFrame.create(
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

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

await source.capture_frame(audio_frame)

total_samples += samples_per_channel


async def main(room: livekit.Room) -> None:

@room.on("participant_disconnected")
Expand All @@ -45,11 +38,9 @@ def on_participant_disconnect(participant: livekit.Participant, *_):
logging.info("connecting to %s", URL)
try:
e2ee_options = livekit.E2EEOptions()
e2ee_options.key_provider_options.shared_key = b"password"

await room.connect(URL, TOKEN, options=livekit.RoomOptions(
auto_subscribe=True,
e2ee=e2ee_options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we leave these two lines there, but just to comment out e2ee here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have the e2ee.py example for that, I don't think this is necessary

))
logging.info("connected to room %s", room.name)
except livekit.ConnectError as e:
Expand Down
3 changes: 3 additions & 0 deletions livekit/audio_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self, track: Track,

self._task = self._loop.create_task(self._run())

def __del__(self) -> None:
ffi_client.queue.unsubscribe(self._ffi_queue)

async def _run(self):
while True:
event = await self._ffi_queue.wait_for(self._is_event)
Expand Down
3 changes: 3 additions & 0 deletions livekit/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def __init__(self, loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
self.participants: dict[str, RemoteParticipant] = {}
self.connection_state = ConnectionState.CONN_DISCONNECTED

def __del__(self) -> None:
ffi_client.queue.unsubscribe(self._ffi_queue)

@property
def sid(self) -> str:
return self._info.sid
Expand Down
3 changes: 3 additions & 0 deletions livekit/video_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self, track: Track,

self._task = self._loop.create_task(self._run())

def __del__(self) -> None:
ffi_client.queue.unsubscribe(self._ffi_queue)

async def _run(self):
while True:
event = await self._ffi_queue.wait_for(self._is_event)
Expand Down