Skip to content

Commit

Permalink
fix wait_for_playout finishing too early (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Oct 1, 2024
1 parent 6f322fe commit 9e98632
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions livekit-rtc/livekit/rtc/audio_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def __init__(
self._info = resp.new_audio_source.source
self._ffi_handle = FfiHandle(self._info.handle.id)

self._last_capture = self._q_size = 0.0
self._last_capture = 0.0
self._q_size = 0.0
self._join_handle: asyncio.TimerHandle | None = None
self._join_fut: asyncio.Future[None] = self._loop.create_future()

Expand Down Expand Up @@ -128,11 +129,7 @@ async def capture_frame(self, frame: AudioFrame) -> None:
if self._join_fut.done():
self._join_fut = self._loop.create_future()

# remove 50ms to account for processing time
# (e.g. using wait_for_playout for very small chunks)
self._join_handle = self._loop.call_later(
self._q_size - 0.05, self._release_waiter
)
self._join_handle = self._loop.call_later(self._q_size, self._release_waiter)

req = proto_ffi.FfiRequest()
req.capture_audio_frame.source_handle = self._ffi_handle.handle
Expand Down

0 comments on commit 9e98632

Please sign in to comment.