Title: [284082] trunk/Source/ThirdParty/libwebrtc
Revision
284082
Author
[email protected]
Date
2021-10-13 00:51:12 -0700 (Wed, 13 Oct 2021)

Log Message

Override guessed color space for incoming H.264/265 streams
https://bugs.webkit.org/show_bug.cgi?id=231353
<rdar://problem/83969311>

Reviewed by Youenn Fablet.

When the VTDecompressionSession decodes incoming H.264/H.265 samples,
it puts guessed color space attachments on the CVPixelBuffer, and the
guesses are based on video resolution. WebRTC streams however default
to being sRGB. So this patch overrides a guess with what we know the
stream will be. (Once we support different color spaces in WebRTC
video streams we'll need to adjust this.)

* Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm:
(overrideColorSpaceAttachmentsIfNeeded):
(decompressionOutputCallback):
* Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm:
(overrideColorSpaceAttachmentsIfNeeded):
(h265DecompressionOutputCallback):

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/libwebrtc/ChangeLog (284081 => 284082)


--- trunk/Source/ThirdParty/libwebrtc/ChangeLog	2021-10-13 07:29:46 UTC (rev 284081)
+++ trunk/Source/ThirdParty/libwebrtc/ChangeLog	2021-10-13 07:51:12 UTC (rev 284082)
@@ -1,3 +1,25 @@
+2021-10-13  Cameron McCormack  <[email protected]>
+
+        Override guessed color space for incoming H.264/265 streams
+        https://bugs.webkit.org/show_bug.cgi?id=231353
+        <rdar://problem/83969311>
+
+        Reviewed by Youenn Fablet.
+
+        When the VTDecompressionSession decodes incoming H.264/H.265 samples,
+        it puts guessed color space attachments on the CVPixelBuffer, and the
+        guesses are based on video resolution. WebRTC streams however default
+        to being sRGB. So this patch overrides a guess with what we know the
+        stream will be. (Once we support different color spaces in WebRTC
+        video streams we'll need to adjust this.)
+
+        * Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm:
+        (overrideColorSpaceAttachmentsIfNeeded):
+        (decompressionOutputCallback):
+        * Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm:
+        (overrideColorSpaceAttachmentsIfNeeded):
+        (h265DecompressionOutputCallback):
+
 2021-10-12  Alexey Proskuryakov  <[email protected]>
 
         Invoke ThirdParty build scripts with python3 explicitly

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm (284081 => 284082)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm	2021-10-13 07:29:46 UTC (rev 284081)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm	2021-10-13 07:51:12 UTC (rev 284082)
@@ -41,6 +41,18 @@
 - (void)setError:(OSStatus)error;
 @end
 
+static void overrideColorSpaceAttachmentsIfNeeded(CVImageBufferRef imageBuffer) {
+  auto guess = CVBufferGetAttachment(imageBuffer, (CFStringRef)@"ColorInfoGuessedBy", nullptr);
+  if (!guess || !CFEqual(guess, (CFStringRef)@"VideoToolbox"))
+    return;
+
+  CVBufferRemoveAttachment(imageBuffer, kCVImageBufferCGColorSpaceKey);
+  CVBufferSetAttachment(imageBuffer, kCVImageBufferColorPrimariesKey, kCVImageBufferColorPrimaries_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate);
+  CVBufferSetAttachment(imageBuffer, kCVImageBufferTransferFunctionKey, kCVImageBufferTransferFunction_sRGB, kCVAttachmentMode_ShouldPropagate);
+  CVBufferSetAttachment(imageBuffer, kCVImageBufferYCbCrMatrixKey, kCVImageBufferYCbCrMatrix_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate);
+  CVBufferSetAttachment(imageBuffer, (CFStringRef)@"ColorInfoGuessedBy", (CFStringRef)@"RTCVideoDecoderH264", kCVAttachmentMode_ShouldPropagate);
+}
+
 // This is the callback function that VideoToolbox calls when decode is
 // complete.
 void decompressionOutputCallback(void *decoderRef,
@@ -57,6 +69,8 @@
     return;
   }
 
+  overrideColorSpaceAttachmentsIfNeeded(imageBuffer);
+
   std::unique_ptr<RTCFrameDecodeParams> decodeParams(reinterpret_cast<RTCFrameDecodeParams *>(params));
   // TODO(tkchin): Handle CVO properly.
   RTCCVPixelBuffer *frameBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:imageBuffer];

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm (284081 => 284082)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm	2021-10-13 07:29:46 UTC (rev 284081)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm	2021-10-13 07:51:12 UTC (rev 284082)
@@ -38,6 +38,18 @@
 - (void)setError:(OSStatus)error;
 @end
 
+static void overrideColorSpaceAttachmentsIfNeeded(CVImageBufferRef imageBuffer) {
+  auto guess = CVBufferGetAttachment(imageBuffer, (CFStringRef)@"ColorInfoGuessedBy", nullptr);
+  if (!guess || !CFEqual(guess, (CFStringRef)@"VideoToolbox"))
+    return;
+
+  CVBufferRemoveAttachment(imageBuffer, kCVImageBufferCGColorSpaceKey);
+  CVBufferSetAttachment(imageBuffer, kCVImageBufferColorPrimariesKey, kCVImageBufferColorPrimaries_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate);
+  CVBufferSetAttachment(imageBuffer, kCVImageBufferTransferFunctionKey, kCVImageBufferTransferFunction_sRGB, kCVAttachmentMode_ShouldPropagate);
+  CVBufferSetAttachment(imageBuffer, kCVImageBufferYCbCrMatrixKey, kCVImageBufferYCbCrMatrix_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate);
+  CVBufferSetAttachment(imageBuffer, (CFStringRef)@"ColorInfoGuessedBy", (CFStringRef)@"RTCVideoDecoderH265", kCVAttachmentMode_ShouldPropagate);
+}
+
 // This is the callback function that VideoToolbox calls when decode is
 // complete.
 void h265DecompressionOutputCallback(void* decoderRef,
@@ -54,6 +66,8 @@
     return;
   }
 
+  overrideColorSpaceAttachmentsIfNeeded(imageBuffer);
+
   std::unique_ptr<RTCH265FrameDecodeParams> decodeParams(reinterpret_cast<RTCH265FrameDecodeParams*>(params));
   // TODO(tkchin): Handle CVO properly.
   RTCCVPixelBuffer* frameBuffer =
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to