Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: ad68f450f0c14847600643fd3932a3820862afc2
https://github.com/WebKit/WebKit/commit/ad68f450f0c14847600643fd3932a3820862afc2
Author: Youenn Fablet <[email protected]>
Date: 2026-09-24 (Thu, 24 Sep 2026)
Changed paths:
M Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.cpp
M Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.h
M Source/WebCore/platform/graphics/cocoa/CMUtilities.h
M Source/WebCore/platform/graphics/cocoa/CMUtilities.mm
M Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoder.h
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoder.mm
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTB.h
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTB.mm
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH264.h
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH264.mm
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH265.h
M Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH265.mm
M Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm
M Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp
Log Message:
-----------
Preserve color space info when encoding/decoding H265 via VideoToolbox
rdar://187787801
https://bugs.webkit.org/show_bug.cgi?id=324554
Reviewed by Jean-Yves Avenard.
VideoToolbox H265 encoding/decoding was always tagging output with a hardcoded
Bt709/limited-range color space.
Instead we are now propagating what the source frame or bitstream actually
carried.
On decode, HEVCUtilitiesCocoa derives the VideoInfo's color space from the
CMFormatDescription instead of a fixed default.
On encode, GPUVideoEncoderVTB now tracks the color space of the CVPixelBuffer
being encoded, but only for HEVC.
We apply this color space to the VTCompressionSession's
ColorPrimaries/TransferFunction/YCbCrMatrix properties.
We recreate a VTCompressionSession everytime the color space of CVPixelBuffers
change.
For H264, we do not yet set the VTCompressionSession's
ColorPrimaries/TransferFunction/YCbCrMatrix properties.
We are not yet ready to encode with the color space of the CVPixelBuffer being
encoded, we keep the current behaviour until we implement better color support
in the H264 decoder.
To make sure WebCodecs gets the right color space info in the decoder config,
we are copying the color space of the encoded frame to the compression callback.
We can then pass it to convertAndNotify/notifyDescription.
In the GPU process, LibWebRTCCodecsProxy forwards the encoder's reported color
space instead of a hardcoded one.
It attaches the color space carried on the SharedVideoFrame to the pixel buffer
before encoding.
LibWebRTCCodecs populates that SharedVideoFrame's color space field from the
source webrtc::VideoFrame/WebCore::VideoFrame instead of leaving it
default-constructed.
We make a small refactoring for how to call the notify description callback.
Classes like GPUVideoEncoderVTBH264 and GPUVideoEncoderVTBH265 now call
GPUVideoEncoderVTB::notifyDescriptionIfNeeded.
It checks whether we need to call the callback directly.
This allows to share more code between the two encoders.
Like done for software encoders, we convert RGB video frames to YUV video range
with BT color space before encoding.
Covered by WPT HEVC tests, in particular
LayoutTests/imported/w3c/web-platform-tests/webcodecs/full-cycle-test.https.any.html.
* Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.cpp:
* Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.h:
* Source/WebCore/platform/graphics/cocoa/CMUtilities.h:
* Source/WebCore/platform/graphics/cocoa/CMUtilities.mm:
(WebCore::convertToCMColorPrimaries):
(WebCore::convertToCMTransferFunction):
(WebCore::convertToCMYCbCRMatrix):
* Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm:
(WebCore::createVideoInfoFromHEVCAnnexBStream):
(WebCore::createVideoInfoFromHVCC):
(WebCore::defaultHEVCPlatformVideoColorSpace): Deleted.
(WebCore::createVideoInfoFromHEVCFormatDescription):
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoder.h:
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoder.mm:
(WebCore::GPUVideoEncoder::create):
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTB.h:
(WebCore::GPUVideoEncoderVTB::colorSpace const):
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTB.mm:
(WebCore::GPUVideoEncoderVTB::notifyDescription):
(WebCore::GPUVideoEncoderVTB::resetCompressionSession):
(WebCore::GPUVideoEncoderVTB::configureCompressionSession):
(WebCore::GPUVideoEncoderVTB::encodeFrame):
(WebCore::GPUVideoEncoderVTB::notifyDescriptionIfNeeded):
(WebCore::defaultH264EncodingColorSpace):
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH265.mm:
(WebCore::GPUVideoEncoderVTBH265::convertAndNotify):
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
(WebKit::LibWebRTCCodecsProxy::createEncoder):
(WebKit::LibWebRTCCodecsProxy::encodeFrame):
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::frameColorSpace):
(WebKit::LibWebRTCCodecs::encodeFrameInternalWithLock):
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH265.h:
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH264.h:
* Source/WebCore/platform/video-codecs/cocoa/GPUVideoEncoderVTBH264.mm:
(WebCore::GPUVideoEncoderVTBH264::convertAndNotify):
Canonical link: https://commits.webkit.org/321788@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications