Commit 46f6bdf9 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Add media::GetFormatDescriptionColorSpace

Restrict this to macOS 10.11 and above. In theory the function should
not compile when targeting macOS 10.10. In practice it does, because
the CoreMedia constants are preprocessor defined to their CoreVideo
equivalents (which are defined).

This function is nearly identical to media::GetImageBufferColorSpace,
but instead operates on a CMFormatDescriptionRef.

Add DCHECKs that the behavior of the two functions be the same, that is,
the kCVImageBuffer-prefixed and  kCMFormatDescription-prefixed
constants be equal.

Use base::mac::CFCast instead of reinterpret_casts.

The next patch in this sequence will move these two functions over
to media/base/mac, because it will be accessed in capture.

Bug: 959962
Change-Id: Iea9d8d357dec72ddc928b7e1fd3a631c131ade74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2449934Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813924}
parent 850b4866
...@@ -26,6 +26,9 @@ CreateFormatExtensions(CMVideoCodecType codec_type, ...@@ -26,6 +26,9 @@ CreateFormatExtensions(CMVideoCodecType codec_type,
MEDIA_GPU_EXPORT gfx::ColorSpace GetImageBufferColorSpace( MEDIA_GPU_EXPORT gfx::ColorSpace GetImageBufferColorSpace(
CVImageBufferRef image_buffer); CVImageBufferRef image_buffer);
MEDIA_GPU_EXPORT gfx::ColorSpace GetFormatDescriptionColorSpace(
CMFormatDescriptionRef format_description) API_AVAILABLE(macos(10.11));
} // namespace media } // namespace media
#endif // MEDIA_GPU_MAC_VT_CONFIG_UTIL_H_ #endif // MEDIA_GPU_MAC_VT_CONFIG_UTIL_H_
This diff is collapsed.
...@@ -74,6 +74,34 @@ base::ScopedCFTypeRef<CVImageBufferRef> CreateCVImageBuffer( ...@@ -74,6 +74,34 @@ base::ScopedCFTypeRef<CVImageBufferRef> CreateCVImageBuffer(
return image_buffer; return image_buffer;
} }
base::ScopedCFTypeRef<CMFormatDescriptionRef> CreateFormatDescription(
CFStringRef primaries,
CFStringRef transfer,
CFStringRef matrix) {
base::ScopedCFTypeRef<CFMutableDictionaryRef> extensions(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
if (primaries) {
CFDictionarySetValue(
extensions, kCMFormatDescriptionExtension_ColorPrimaries, primaries);
}
if (transfer) {
CFDictionarySetValue(
extensions, kCMFormatDescriptionExtension_TransferFunction, transfer);
}
if (matrix) {
CFDictionarySetValue(extensions, kCMFormatDescriptionExtension_YCbCrMatrix,
matrix);
}
base::ScopedCFTypeRef<CMFormatDescriptionRef> result;
CMFormatDescriptionCreate(nullptr, kCMMediaType_Video,
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
extensions.get(), result.InitializeInto());
return result;
}
gfx::ColorSpace ToBT709_APPLE(gfx::ColorSpace cs) { gfx::ColorSpace ToBT709_APPLE(gfx::ColorSpace cs) {
return gfx::ColorSpace(cs.GetPrimaryID(), return gfx::ColorSpace(cs.GetPrimaryID(),
gfx::ColorSpace::TransferID::BT709_APPLE, gfx::ColorSpace::TransferID::BT709_APPLE,
...@@ -364,4 +392,26 @@ TEST(VTConfigUtil, GetImageBufferColorSpace_BT2020_HLG) { ...@@ -364,4 +392,26 @@ TEST(VTConfigUtil, GetImageBufferColorSpace_BT2020_HLG) {
} }
} }
TEST(VTConfigUtil, FormatDescriptionInvalid) {
if (__builtin_available(macos 10.11, *)) {
auto format_descriptor =
CreateFormatDescription(CFSTR("Cows"), CFSTR("Go"), CFSTR("Moo"));
ASSERT_TRUE(format_descriptor);
auto cs = GetFormatDescriptionColorSpace(format_descriptor);
EXPECT_EQ(gfx::ColorSpace::CreateREC709(), cs);
}
}
TEST(VTConfigUtil, FormatDescriptionBT709) {
if (__builtin_available(macos 10.11, *)) {
auto format_descriptor = CreateFormatDescription(
kCMFormatDescriptionColorPrimaries_ITU_R_709_2,
kCMFormatDescriptionTransferFunction_ITU_R_709_2,
kCMFormatDescriptionYCbCrMatrix_ITU_R_709_2);
ASSERT_TRUE(format_descriptor);
auto cs = GetFormatDescriptionColorSpace(format_descriptor);
EXPECT_EQ(ToBT709_APPLE(gfx::ColorSpace::CreateREC709()), cs);
}
}
} // namespace media } // namespace media
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