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

fix wait_for_playout finishing too early #270

Merged
merged 5 commits into from
Oct 1, 2024
Merged
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
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
Loading