Title: [284345] branches/safari-612-branch/Source/ThirdParty/libwebrtc
Revision
284345
Author
kocsen_ch...@apple.com
Date
2021-10-17 17:21:59 -0700 (Sun, 17 Oct 2021)

Log Message

Cherry-pick r284082. rdar://problem/84351872

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284082 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-612-branch/Source/ThirdParty/libwebrtc/ChangeLog (284344 => 284345)


--- branches/safari-612-branch/Source/ThirdParty/libwebrtc/ChangeLog	2021-10-17 23:15:46 UTC (rev 284344)
+++ branches/safari-612-branch/Source/ThirdParty/libwebrtc/ChangeLog	2021-10-18 00:21:59 UTC (rev 284345)
@@ -1,3 +1,52 @@
+2021-10-17  Kocsen Chung  <kocsen_ch...@apple.com>
+
+        Cherry-pick r284082. rdar://problem/84351872
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284082 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-10-13  Cameron McCormack  <hey...@apple.com>
+
+            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-09-23  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r282831. rdar://problem/83429823

Modified: branches/safari-612-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm (284344 => 284345)


--- branches/safari-612-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm	2021-10-17 23:15:46 UTC (rev 284344)
+++ branches/safari-612-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm	2021-10-18 00:21:59 UTC (rev 284345)
@@ -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: branches/safari-612-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm (284344 => 284345)


--- branches/safari-612-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm	2021-10-17 23:15:46 UTC (rev 284344)
+++ branches/safari-612-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH265.mm	2021-10-18 00:21:59 UTC (rev 284345)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to