| Differences between
and this patch
- a/Source/ThirdParty/libwebrtc/ChangeLog +14 lines
Lines 1-3 a/Source/ThirdParty/libwebrtc/ChangeLog_sec1
1
2021-10-06  Cameron McCormack  <heycam@apple.com>
2
3
        Incoming WebRTC H.264 video is not correctly color managed
4
        https://bugs.webkit.org/show_bug.cgi?id=231353
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Override inferred default Rec.601 color space with sRGB for incoming
9
        WebRTC video.
10
11
        * Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm:
12
        (overrideColorSpaceAttachmentsIfNeeded):
13
        (decompressionOutputCallback):
14
1
2021-10-06  Youenn Fablet  <youenn@apple.com>
15
2021-10-06  Youenn Fablet  <youenn@apple.com>
2
16
3
        ObjectiveC WebRTC frame buffers are autoreleased late, especially on Debug builds
17
        ObjectiveC WebRTC frame buffers are autoreleased late, especially on Debug builds
- a/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm +22 lines
Lines 41-46 @interface RTCVideoDecoderH264 () a/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm_sec1
41
- (void)setError:(OSStatus)error;
41
- (void)setError:(OSStatus)error;
42
@end
42
@end
43
43
44
// VideoToolbox will assume video data with no color space information is Rec.601
45
// and put the guessed color space attachments on the CVImageBuffer. To avoid
46
// confusing users of the color space attachments, detect when that guess has been
47
// made and override it to the WebRTC default, sRGB.
48
static void overrideColorSpaceAttachmentsIfNeeded(CVImageBufferRef imageBuffer) {
49
  auto guess = CVBufferGetAttachment(imageBuffer, (CFStringRef)@"ColorInfoGuessedBy", nullptr);
50
  if (!guess || !CFEqual(guess, (CFStringRef)@"VideoToolbox"))
51
    return;
52
53
  auto colorPrimaries = CVBufferGetAttachment(imageBuffer, kCVImageBufferColorPrimariesKey, nullptr);
54
  if (!colorPrimaries || !CFEqual(colorPrimaries, kCVImageBufferColorPrimaries_SMPTE_C))
55
    return;
56
57
  CVBufferRemoveAttachment(imageBuffer, kCVImageBufferCGColorSpaceKey);
58
  CVBufferSetAttachment(imageBuffer, kCVImageBufferColorPrimariesKey, kCVImageBufferColorPrimaries_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate);
59
  CVBufferSetAttachment(imageBuffer, kCVImageBufferTransferFunctionKey, kCVImageBufferTransferFunction_sRGB, kCVAttachmentMode_ShouldPropagate);
60
  CVBufferSetAttachment(imageBuffer, kCVImageBufferYCbCrMatrixKey, kCVImageBufferYCbCrMatrix_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate);
61
  CVBufferSetAttachment(imageBuffer, (CFStringRef)@"ColorInfoGuessedBy", (CFStringRef)@"RTCVideoDecoderH264", kCVAttachmentMode_ShouldPropagate);
62
}
63
44
// This is the callback function that VideoToolbox calls when decode is
64
// This is the callback function that VideoToolbox calls when decode is
45
// complete.
65
// complete.
46
void decompressionOutputCallback(void *decoderRef,
66
void decompressionOutputCallback(void *decoderRef,
Lines 57-62 void decompressionOutputCallback(void *decoderRef, a/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm_sec2
57
    return;
77
    return;
58
  }
78
  }
59
79
80
  overrideColorSpaceAttachmentsIfNeeded(imageBuffer);
81
60
  std::unique_ptr<RTCFrameDecodeParams> decodeParams(reinterpret_cast<RTCFrameDecodeParams *>(params));
82
  std::unique_ptr<RTCFrameDecodeParams> decodeParams(reinterpret_cast<RTCFrameDecodeParams *>(params));
61
  // TODO(tkchin): Handle CVO properly.
83
  // TODO(tkchin): Handle CVO properly.
62
  RTCCVPixelBuffer *frameBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:imageBuffer];
84
  RTCCVPixelBuffer *frameBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:imageBuffer];

Return to Bug 231353