Commit 1e7d7525 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Use CMSampleBuffer or CVPixelBuffer color space

Pass the color space from CoreMedia or CoreVideo to the
FrameReceiver, and to the rest of the pipeline. Prefer to use
the ColorSpace specified by the CVPixelBuffer over the
CMSampleBuffer.

Of note is that on macOS, the default capture transfer function
is BT709_APPLE (gamma of 1.961) which is different from regular
BT709 (sRGB transfer function, in our interpretation).

This fixes a bug whereby the colors of a captured IOSurface are
different based on if it is being composited by CoreAnimation
(in which case it getting the BT709_APPLE via IOSurface metadata)
versus viz::GLRenderer (in which case it used to be defaulting
to BT709).

Bug: 959962
Change-Id: Idb2fdab39e4b4b292932c9bdb2f62dd3f662d4f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459690Reviewed-by: default avatarMarkus Handell <handellm@google.com>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815041}
parent 090102a7
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "media/base/mac/color_space_util_mac.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "media/base/timestamp_constants.h" #include "media/base/timestamp_constants.h"
#include "media/base/video_types.h" #include "media/base/video_types.h"
...@@ -648,11 +649,6 @@ AVCaptureDeviceFormat* FindBestCaptureFormat( ...@@ -648,11 +649,6 @@ AVCaptureDeviceFormat* FindBestCaptureFormat(
media::VideoPixelFormat videoPixelFormat = [VideoCaptureDeviceAVFoundation media::VideoPixelFormat videoPixelFormat = [VideoCaptureDeviceAVFoundation
FourCCToChromiumPixelFormat:sampleBufferPixelFormat]; FourCCToChromiumPixelFormat:sampleBufferPixelFormat];
// TODO(julien.isorce): move GetImageBufferColorSpace(CVImageBufferRef)
// from media::VTVideoDecodeAccelerator to media/base/mac and call it
// here to get the color space. See https://crbug.com/959962.
// colorSpace = media::GetImageBufferColorSpace(videoFrame);
gfx::ColorSpace colorSpace;
const media::VideoCaptureFormat captureFormat( const media::VideoCaptureFormat captureFormat(
gfx::Size(dimensions.width, dimensions.height), _frameRate, gfx::Size(dimensions.width, dimensions.height), _frameRate,
videoPixelFormat); videoPixelFormat);
...@@ -660,6 +656,8 @@ AVCaptureDeviceFormat* FindBestCaptureFormat( ...@@ -660,6 +656,8 @@ AVCaptureDeviceFormat* FindBestCaptureFormat(
if (CVPixelBufferRef pixelBuffer = if (CVPixelBufferRef pixelBuffer =
CMSampleBufferGetImageBuffer(sampleBuffer)) { CMSampleBufferGetImageBuffer(sampleBuffer)) {
const gfx::ColorSpace colorSpace =
media::GetImageBufferColorSpace(pixelBuffer);
OSType pixelBufferPixelFormat = OSType pixelBufferPixelFormat =
CVPixelBufferGetPixelFormatType(pixelBuffer); CVPixelBufferGetPixelFormatType(pixelBuffer);
DCHECK_EQ(pixelBufferPixelFormat, sampleBufferPixelFormat); DCHECK_EQ(pixelBufferPixelFormat, sampleBufferPixelFormat);
...@@ -688,7 +686,11 @@ AVCaptureDeviceFormat* FindBestCaptureFormat( ...@@ -688,7 +686,11 @@ AVCaptureDeviceFormat* FindBestCaptureFormat(
return; return;
} }
} }
// Last preference is to read the CMSampleBuffer. // Last preference is to read the CMSampleBuffer.
gfx::ColorSpace colorSpace;
if (@available(macOS 10.11, *))
colorSpace = media::GetFormatDescriptionColorSpace(formatDescription);
[self processSample:sampleBuffer [self processSample:sampleBuffer
captureFormat:captureFormat captureFormat:captureFormat
colorSpace:colorSpace colorSpace:colorSpace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment