Repository navigation
Pass 10-bit bi-planar buffers through BufferCapturer - #1232
Open
OleksandrHaidamaka wants to merge 1 commit into
Open
OleksandrHaidamaka wants to merge 1 commit into
OleksandrHaidamaka wants to merge 1 commit into
Conversation
OleksandrHaidamaka
requested review from
hiroshihorie,
pblazej and
xianshijing-lk
as code owners
November 23, 2026 12:09
Contributor
There was a problem hiding this comment.
Devin Review found 1 potential issue.
5 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
Comment on lines
+227
to
+228
| guard VideoCapturer.supportedPixelFormats.contains(where: { $0.uint32Value == pixelFormat }) | ||
| || VideoCapturer.tenBitPixelFormats.contains(pixelFormat) |
Contributor
There was a problem hiding this comment.
Author
There was a problem hiding this comment.
Right, the release path of RTCCVPixelBuffer.toI420() returns unwritten planes for a format it does not handle. Fixed in 041ce54: 10-bit frames are wrapped in TenBitPixelBuffer, whose toI420() and cropAndScaleTo(_:withTempBuffer:) read an 8-bit NV12 copy, and which stays itself through cropAndScaleWith. A built-in encoder now gets the picture; a custom one still gets the 10-bit buffer. Both paths are covered in BufferCapturerPixelFormatTests.
An HDR camera's HLG frames (kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange) were skipped as an unsupported pixel format, so a buffer track fed by one never resolved its dimensions and its publish waited out its timeout with no frame sent. WebRTC carries such a buffer untouched to an encoder set with LiveKitSDK.set(videoEncoderFactory:), which codes it (HEVC Main10). WebRTC's own encoders and its scaling read a frame through toI420() and cropAndScaleTo(_:withTempBuffer:), which RTCCVPixelBuffer implements only for its supported formats; for any other format they return planes they never wrote. 10-bit frames are wrapped in TenBitPixelBuffer, which answers both from an 8-bit NV12 copy (each sample's high byte) and stays itself when WebRTC crops or scales it.
OleksandrHaidamaka
force-pushed
the
tenbit-buffer-capture
branch
from
November 23, 2026 12:27
a74b308 to
041ce54
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
VideoCapturerskips any pixel buffer whose format isn't inLKRTCCVPixelBuffer.supportedPixelFormats(). That list has no 10-bit formats, so the frames an iPhone camera gives when it films HLG (kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange, orFullRange) are dropped before the capturer resolves its dimensions. A buffer track fed only such frames never gets dimensions, andpublishwaits out its timeout without sending a frame.WebRTC doesn't need the format to be on that list to carry the frame: an
RTCCVPixelBufferreaches the encoder untouched, and an encoder installed withLiveKitSDK.set(videoEncoderFactory:)can code it. We send HEVC Main10 HLG from a VideoToolbox encoder this way.WebRTC's own encoders and its scaling are another matter. They read a frame through
toI420()andcropAndScaleTo(_:withTempBuffer:), andRTCCVPixelBufferimplements both only for its supported formats: for anything else it hits aRTC_DCHECK_NOTREACHEDand, in release, returns planes it never wrote. So 10-bit frames are wrapped inTenBitPixelBuffer, a subclass that answers both from an 8-bit NV12 copy (each sample's high byte, video range 64...940 becoming 16...235) and returns itself fromcropAndScaleWith, so a built-in encoder on the same track (VP8, H.264, a software fallback) gets the picture rather than heap bytes. A custom encoder still gets the 10-bitpixelBufferas it is.Changes:
VideoCapturer.tenBitPixelFormats(the two 4:2:0 bi-planar 10-bit formats) pass the format check; any other unsupported format is still skipped.TenBitPixelBufferwraps them.Tests in
BufferCapturerPixelFormatTests:main);422YpCbCr8) is still skipped;toI420()of a 10-bit buffer gives 8-bit planes with the expected values, for both ranges;TenBitPixelBufferwith the expected values, andcropAndScaleTowrites an NV12 output buffer.