Repository navigation
fix(rtc): copy read-only frame buffers that get_address cannot take - #885
Conversation
|
👋 This PR has no changeset. If it should be released, add a markdown file under ---
"livekit-rtc": patch
---
Short description of the change, used in the release notes.
If this change doesn't need a release (docs, CI, tests), you can ignore this comment. |
…-buffers # Conflicts: # tests/rtc/test_video_frame.py
|
Merged the latest |
cloudwebrtc
left a comment
There was a problem hiding this comment.
Reviewed the buffer normalization change and regression tests. Verified the original TypeError for both AudioFrame and VideoFrame, then validated the fix with 35 tests and 14 additional buffer/frame combinations. The change preserves existing writable-buffer behavior.
Summary
VideoFrameandAudioFrameaccept a memoryview, and_ensure_compatible_bufferkeeps a full-length memoryview as is. When that memoryview is read-only and its exporter is notbytesorbytearray,get_addressfalls back todata.objand raises aTypeError. The constructor accepts the frame, butcapture_framefails later with:A common way to hit this is a frame built from
np.frombuffer(...), which returns a read-only array:Changes
_ensure_compatible_buffercopies a read-only memoryview intobyteswhen its exporter is notbytesorbytearray. This matches what the function already does for sliced read-only memoryviews. Writable memoryviews and read-only views ofbytesorbytearrayare still passed through without a copy.Testing
tests/rtc/test_video_frame.py::test_frame_from_a_read_only_numpy_buffer_can_be_capturedandtests/rtc/test_audio_frame.py::test_frame_from_a_read_only_numpy_buffer_can_be_capturedbuild a frame from a read-only NumPy buffer and check that_proto_info()points at the frame's bytes. Both fail onmainwith theTypeErrorabove and pass with this change.ruff checkandruff format --checkpass.mypyreports no new errors.Fixes #884