From 55403b23f358a666f864f90892cd67f4b176d0c7 Mon Sep 17 00:00:00 2001 From: Youenn Fablet Date: Thu, 27 Oct 2022 00:56:33 -0700 Subject: [PATCH] [WebCodecs] Expose encoder color space in decoder config https://bugs.webkit.org/show_bug.cgi?id=247054 rdar://problem/101582123 Reviewed by Eric Carlson. Set colorSpace to BT 601 for VP8 and VP9 as per spec. * LayoutTests/imported/w3c/web-platform-tests/webcodecs/video-encoder.https.any-expected.txt: * Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.cpp: (WebCore::WebCodecsVideoEncoder::createEncodedChunkMetadata): * Source/WebCore/platform/LibWebRTCVPXVideoEncoder.cpp: (WebCore::LibWebRTCVPXVideoEncoder::create): * Source/WebCore/platform/VideoEncoder.h: Canonical link: https://commits.webkit.org/256052@main --- .../webcodecs/video-encoder.https.any-expected.txt | 2 +- Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.cpp | 2 +- Source/WebCore/platform/LibWebRTCVPXVideoEncoder.cpp | 5 ++++- Source/WebCore/platform/VideoEncoder.h | 2 ++ .../WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/LayoutTests/imported/w3c/web-platform-tests/webcodecs/video-encoder.https.any-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/webcodecs/video-encoder.https.any-expected.txt index 3c5eb531e24a..60da4d5cd25f 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/webcodecs/video-encoder.https.any-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/webcodecs/video-encoder.https.any-expected.txt @@ -1,7 +1,7 @@ PASS Test VideoEncoder construction PASS Test VideoEncoder.configure() -FAIL Test successful configure(), encode(), and flush() promise_test: Unhandled rejection with value: object "TypeError: undefined is not an object (evaluating 'decoderConfig.colorSpace.primaries')" +PASS Test successful configure(), encode(), and flush() PASS encodeQueueSize test PASS Test successful reset() and re-confiugre() PASS Test successful encode() after re-configure(). diff --git a/Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.cpp b/Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.cpp index 6137d4f8ace3..73176c410605 100644 --- a/Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.cpp +++ b/Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.cpp @@ -177,7 +177,7 @@ WebCodecsEncodedVideoChunkMetadata WebCodecsVideoEncoder::createEncodedChunkMeta m_activeConfiguration.visibleHeight ? m_activeConfiguration.visibleHeight : m_baseConfiguration.height, m_activeConfiguration.displayWidth ? m_activeConfiguration.displayWidth : m_baseConfiguration.displayWidth, m_activeConfiguration.displayHeight ? m_activeConfiguration.displayHeight : m_baseConfiguration.displayHeight, - { }, + m_activeConfiguration.colorSpace, HardwareAcceleration::NoPreference, { } }; diff --git a/Source/WebCore/platform/LibWebRTCVPXVideoEncoder.cpp b/Source/WebCore/platform/LibWebRTCVPXVideoEncoder.cpp index 26c76b95b209..2a66ecd92017 100644 --- a/Source/WebCore/platform/LibWebRTCVPXVideoEncoder.cpp +++ b/Source/WebCore/platform/LibWebRTCVPXVideoEncoder.cpp @@ -92,7 +92,10 @@ void LibWebRTCVPXVideoEncoder::create(Type type, const VideoEncoder::Config& con return; } callback(UniqueRef { WTFMove(encoder) }); - descriptionCallback({ }); + + VideoEncoder::ActiveConfiguration configuration; + configuration.colorSpace = PlatformVideoColorSpace { PlatformVideoColorPrimaries::Bt709, PlatformVideoTransferCharacteristics::Iec6196621, PlatformVideoMatrixCoefficients::Smpte170m, false }; + descriptionCallback(WTFMove(configuration)); }); }); } diff --git a/Source/WebCore/platform/VideoEncoder.h b/Source/WebCore/platform/VideoEncoder.h index e2c2c41660d7..bbbfcbd47960 100644 --- a/Source/WebCore/platform/VideoEncoder.h +++ b/Source/WebCore/platform/VideoEncoder.h @@ -27,6 +27,7 @@ #if ENABLE(WEB_CODECS) +#include "PlatformVideoColorSpace.h" #include "VideoFrame.h" #include #include @@ -53,6 +54,7 @@ class VideoEncoder { std::optional displayWidth; std::optional displayHeight; std::optional> description; + std::optional colorSpace; }; struct EncodedFrame { Vector data; diff --git a/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp b/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp index 1af4cccc9364..e9ceca4fca16 100644 --- a/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp +++ b/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp @@ -297,7 +297,7 @@ void RemoteVideoEncoderCallbacks::notifyEncoderDescription(Vector&& des if (protectedThis->m_isClosed) return; - protectedThis->m_descriptionCallback(VideoEncoder::ActiveConfiguration { { }, { }, { }, { }, { }, WTFMove(description) }); + protectedThis->m_descriptionCallback(VideoEncoder::ActiveConfiguration { { }, { }, { }, { }, { }, WTFMove(description), { } }); }); }