Add APIs for converting between native VideoFrameBuffers and their underlying CVPixelBuffer
on macOS
#355
+133
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depends on #354 (this branch contains that change as well).
Background
In the Zed editor, we're switching over from using the LiveKit Swift SDK to this crate. The main motivation is that we want our LiveKit-based screen-sharing and audio features to work on Linux (and someday Windows), not just macOS.
In order to implement screen sharing efficiently (as it was before, when using the Swift SDK), we want to pass video frames directly from the
ScreenCaptureKit
framework to this crate'sNativeVideoSource::capture_frame
method, without copying them into intermediate buffers. Similarly, when playing remote video tracks, we want to take decoded video frames directly from theNativeVideoStream
and use them as GPU textures without performing an extra copy.Change
To support both of these use cases, we have added two new macOS-specific APIs to the
video_frame::NativeBuffer
type:from_cv_pixel_buffer
, andget_cv_pixel_buffer
. I think it makes sense to have this functionality, since AFAICT, the purpose of theNative
variant ofVideoFrameBuffer
is to adapt a platform-specific video frame representation into the WebRTC's logic.Details
CoreMedia
framework, so we decided to leave the interface in terms of*mut c_void
.get_cv_pixel_buffer
can returnNULL
if the native buffer is not actually backed by aCVPixelBuffer
. Rather than implicitly perform some potentially expensive conversion implicitly, we decided to leave that to the caller. The only point of these method is to enable a fast path in which we minimize conversions.Let me know if there is a different solution to this problem that you'd prefer. Thanks!