Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 932d9b36d64da93a2a6a6c1af0ee2ffc7ac0c151
      
https://github.com/WebKit/WebKit/commit/932d9b36d64da93a2a6a6c1af0ee2ffc7ac0c151
  Author: Youenn Fablet <[email protected]>
  Date:   2026-06-15 (Mon, 15 Jun 2026)

  Changed paths:
    A LayoutTests/http/wpt/webrtc/peer-connection-color-space-expected.txt
    A LayoutTests/http/wpt/webrtc/peer-connection-color-space-worker.js
    A LayoutTests/http/wpt/webrtc/peer-connection-color-space.html
    M LayoutTests/platform/glib/TestExpectations
    M Source/ThirdParty/libwebrtc/Configurations/libwebrtc.exp
    M 
Source/ThirdParty/libwebrtc/Source/webrtc/webkit_sdk/WebKit/WebKitDecoder.h
    M 
Source/ThirdParty/libwebrtc/Source/webrtc/webkit_sdk/WebKit/WebKitDecoder.mm
    M Source/WebCore/Headers.cmake
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/platform/SourcesLibWebRTC.txt
    M Source/WebCore/platform/libwebrtc/LibWebRTCVPXVideoEncoder.cpp
    M Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.cpp
    A 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCColorSpaceUtilities.h
    A 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.cpp
    M 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.h
    M Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoder.h
    M Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoder.mm
    M Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoderVTB.h
    M Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoderVTB.mm
    M Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h
    M Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.messages.in
    M Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm
    M Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp
    M Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h

  Log Message:
  -----------
  WebRTC HDR decoding should be enabled via the RTP color space information
rdar://178529773
https://bugs.webkit.org/show_bug.cgi?id=316393

Reviewed by Jean-Yves Avenard.

WebRTC video has two channels for color-space metadata: in-band (the codec
bitstream's own color tags, e.g. VP9's color_space field) and out-of-band
(libwebrtc's WebRTC ColorSpace metadata, populated from the RTP color-space
header extension RFC 7798 §3.4 and surfaced as
EncodedImage::ColorSpace()).

Until now the GPU-process VTB decoder only honored the in-band channel.
For HDR over WebRTC — where senders signal BT.2020/PQ via the RTP
extension while the bitstream may not carry equivalent in-band tags
(or carries an SDR fallback) — frames came out tagged as their bitstream
color space rather than the sender's intended HDR space.

This patch routes the libwebrtc-surfaced per-frame ColorSpace through to
the GPU-side decoder (building on the VideoInfo/colorSpaceOverride
refactoring in the preceding commit) so the receiver tags decoded
VideoFrames with the right color space, and so VTB produces a
CMVideoFormatDescription whose extensions reflect that color space (which
AVSampleBufferDisplayLayer then uses for HDR display routing).

Plumbing, in order:
  - WebKitDecoder.h: VideoDecoderDecodeCallback gains a const
    webrtc::ColorSpace* parameter (forward-declared in the webrtc namespace).
  - WebKitDecoder.mm RemoteVideoDecoder::Decode reads
    input_image.ColorSpace() (a const std::optional<ColorSpace>&) and
    passes the optional's address (or nullptr) through the callback.
  - LibWebRTCVideoFrameUtilities.h: the existing
    colorSpaceFromLibWebRTCVideoFrame is refactored to delegate to a new
    colorSpaceFromLibWebRTCColorSpace(const webrtc::ColorSpace&), so the
    libwebrtc → PlatformVideoColorSpace translation is reusable from the
    decode-callback path. A pointer overload is also provided for
    convenience.
  - LibWebRTCCodecs.cpp's decodeVideoFrame static converts the
    webrtc::ColorSpace* to std::optional<PlatformVideoColorSpace> at the
    boundary; WebKit code never sees webrtc:: types beyond this point.
  - LibWebRTCCodecs::decodeWebRTCFrame compares the surfaced color space
    against decoder.colorSpaceOverride. On change (including clearing to
    nullopt when the RTP extension is absent), it updates the WebProcess-side
    store and sends a new SetDecoderColorSpaceOverride IPC so the GPU-side
    decoder applies the override on subsequent frames.
    Storing on the WebProcess side also means the override survives a GPU
    process bounce — createRemoteDecoder already re-sends CreateDecoder
    with decoder.colorSpaceOverride.
  - LibWebRTCCodecsProxy gets the new SetDecoderColorSpaceOverride
    message + handler, which forwards into 
WebRTCVideoDecoder::setColorSpaceOverride.
  - WebRTCVideoDecoder gains setColorSpaceOverride() (WEBCORE_EXPORT) and
    the colorSpaceOverrideChanged() virtual hook. WebRTCVideoDecoderVTB
    implements the hook to call updateFormat() with the stored VideoInfo,
    triggering an immediate format description rebuild.

Test: http/wpt/webrtc/peer-connection-color-space.html

The test creates two VideoTrackGenerator-backed tracks in a worker —
one tagged BT.601, one BT.709 — runs them through a loopback PC over
VP9, and reads the receiver-side color space via MediaStreamTrackProcessor
(also worker-only). Then it swaps which generator carries which color
space and verifies the change propagates end-to-end.

The test runs twice: once without modification, exercising the
in-bitstream path; and once with a sender-side RTCRtpScriptTransform
that overwrites the VP9 keyframe's color_space field with CS_UNKNOWN
before transmission. The second run is what specifically exercises the
new RTP-metadata path through the plumbing above — bitstream tags are
gone, so the receiver's only source of color-space info is libwebrtc's
EncodedImage::ColorSpace().
The test also runs with AV1 for completeness and to handle change of
color space outside of a key frame.

We also update LibWebRTC color space utilities so that we can use them in 
WebKit.
We split LibWebRTCVideoFrameUtilities.h in LibWebRTCVideoFrameUtilities.cpp and
LibWebRTCColorSpaceUtilities.h to limit header dependencies.

Test: http/wpt/webrtc/peer-connection-color-space.html
* LayoutTests/http/wpt/webrtc/peer-connection-color-space-expected.txt: Added.
* LayoutTests/http/wpt/webrtc/peer-connection-color-space-worker.js: Added.
* LayoutTests/http/wpt/webrtc/peer-connection-color-space.html: Added.
* LayoutTests/platform/glib/TestExpectations:
* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.exp:
* Source/ThirdParty/libwebrtc/Source/webrtc/webkit_sdk/WebKit/WebKitDecoder.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/webkit_sdk/WebKit/WebKitDecoder.mm:
* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/SourcesLibWebRTC.txt:
* Source/WebCore/platform/libwebrtc/LibWebRTCVPXVideoEncoder.cpp:
* Source/WebCore/platform/mediastream/LibWebRTCColorSpaceUtilities.h: Copied 
from 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.h.
* Source/WebCore/platform/mediastream/LibWebRTCVideoFrameUtilities.cpp: Copied 
from 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.h.
(WebCore::colorSpaceFromLibWebRTCColorSpace):
(WebCore::colorSpaceFromLibWebRTCVideoFrame):
(WebCore::videoRotationFromLibWebRTCVideoFrame):
* Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.cpp:
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCColorSpaceUtilities.h: 
Copied from 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.h.
(WebCore::toWebRTCColorSpace):
(WebCore::colorSpaceFromLibWebRTCColorSpace):
(WebCore::colorSpaceFromLibWebRTCVideoFrame):
(WebCore::videoRotationFromLibWebRTCVideoFrame):
* 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.cpp: 
Copied from 
Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.h.
(WebCore::colorSpaceFromLibWebRTCColorSpace):
(WebCore::colorSpaceFromLibWebRTCVideoFrame):
(WebCore::videoRotationFromLibWebRTCVideoFrame):
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCVideoFrameUtilities.h:
(WebCore::colorSpaceFromLibWebRTCColorSpace):
(WebCore::toWebRTCColorSpace): Deleted.
(WebCore::colorSpaceFromLibWebRTCVideoFrame): Deleted.
(WebCore::videoRotationFromLibWebRTCVideoFrame): Deleted.
* Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoder.h:
(WebCore::WebRTCVideoDecoder::colorSpaceOverrideChanged):
* Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoder.mm:
(WebCore::WebRTCVideoDecoder::setColorSpaceOverride):
* Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoderVTB.h:
* Source/WebCore/platform/video-codecs/cocoa/WebRTCVideoDecoderVTB.mm:
(WebCore::WebRTCVideoDecoderVTB::colorSpaceOverrideChanged):
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.messages.in:
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
(WebKit::LibWebRTCCodecsProxy::setDecoderColorSpaceOverride):
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::decodeVideoFrame):
(WebKit::LibWebRTCCodecs::decodeWebRTCFrame):
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h:

Canonical link: https://commits.webkit.org/315272@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to