Skip to content

fix(rtc-node): return no frames from AudioResampler.flush() when nothing is buffered - #779

Open
ANDROIDHASSAN wants to merge 2 commits into
livekit:mainfrom
ANDROIDHASSAN:fix/resampler-flush-empty
Open

ANDROIDHASSAN wants to merge 2 commits into
livekit:mainfrom
ANDROIDHASSAN:fix/resampler-flush-empty

Conversation

@ANDROIDHASSAN

@ANDROIDHASSAN ANDROIDHASSAN commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem: When nothing is buffered, AudioResampler.flush() returns one frame with samplesPerChannel: 0 instead of []. This happens on a fresh resampler and on a second flush. The FFI flush response sets outputPtr to a non-null buffer address even when size is 0, so the if (!res.outputPtr) check never matches. push() gets a 0 pointer for empty output, so it is not affected. Callers that forward flushed frames, for example to AudioSource.captureFrame or an STT stream, receive an empty frame.

The Python SDK has the same check and the same bug: livekit/python-sdks#938.

Fix: In flush(), also return [] when size is 0, next to the existing outputPtr check. One line.

Tests: I added src/audio_resampler.test.ts. It runs against the native bindings, like audio_source.test.ts.

  • on main it fails: expected [ AudioFrame{ …(5) } ] to deeply equal [], and the received frame has samplesPerChannel: 0.
  • with the fix it passes. A flush right after a push still returns the buffered tail.

vitest run src in packages/livekit-rtc: 67 passed, 1 skipped. Two e2e files fail to load locally both with and without this change, because they need a built livekit-server-sdk and a server. Prettier and ESLint are clean. A @livekit/rtc-node patch changeset is included.

…ing is buffered

The FFI flush response carries a non-zero outputPtr with size 0 when the resampler has nothing left, so the pointer check never matched and flush() returned one 0-sample frame. Check the size instead.
@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 25a85e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@livekit/rtc-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant