livekit / python-sdks

LiveKit real-time and server SDKs for Python
https://docs.livekit.io
Apache License 2.0
123 stars 37 forks source link

Question about frame buffering #184

Closed karrih closed 11 hours ago

karrih commented 6 months ago

Hi,

I have a question about the frame buffering logic. It seems that the application can set maximum capacity for the queue when constructing rtc.VideoStream:

video_stream = rtc.VideoStream(track, capacity=1)

This is useful, since I consume frames at a slower rate than what the video track produces, and I only want to sample the latest video frame at each iteration. But it seems that the frame events themselves originate from the following _ffi_queue, which in turn is not capped: https://github.com/livekit/python-sdks/blob/c19f24a88a73d8e28e141b96fb2dca328d092a8d/livekit-rtc/livekit/rtc/video_stream.py#L71

Does this mean that even with capacity=1, my app may theoretically incur an arbitrarily large delay due to the internal buffer growing in size?