Commit ee35d239 authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Revert "Add media::GetFormatDescriptionColorSpace"

This reverts commit 6c5fa707.

Reason for revert: VTConfigUtil.FormatDescriptionBT709 and FormatDescriptionInvalid are failing on mac
https://ci.chromium.org/p/chromium/builders/ci/Mac10.10%20Tests/58972

Original change's description:
> Add media::GetFormatDescriptionColorSpace
>
> 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: I8a4d8468abc866a13cb6181cbd49d9ee04288124
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436513
> Commit-Queue: ccameron <ccameron@chromium.org>
> Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#811829}

TBR=dalecurtis@chromium.org,ccameron@chromium.org

Change-Id: Iaa57cf20273eb0bcdace23a1ee9e588da15ea733
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 959962
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438551Reviewed-by: default avatarKeishi Hattori <keishi@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811902}
parent ed1301fb
......@@ -26,9 +26,6 @@ CreateFormatExtensions(CMVideoCodecType codec_type,
MEDIA_GPU_EXPORT gfx::ColorSpace GetImageBufferColorSpace(
CVImageBufferRef image_buffer);
MEDIA_GPU_EXPORT gfx::ColorSpace GetFormatDescriptionColorSpace(
CMFormatDescriptionRef format_description);
} // namespace media
#endif // MEDIA_GPU_MAC_VT_CONFIG_UTIL_H_
......@@ -253,17 +253,17 @@ void SetMasteringMetadata(const gl::HDRMetadata& hdr_metadata,
// Use the list of pairs in |cfstr_id_pairs| to do the conversion (by doing a
// linear lookup).
template <typename IdType, typename StringIdPair>
bool GetImageBufferProperty(CFTypeRef value_untyped,
bool GetImageBufferProperty(CVImageBufferRef image_buffer,
CFStringRef key,
const std::vector<StringIdPair>& cfstr_id_pairs,
IdType* value_as_id) {
CFStringRef value_as_string = base::mac::CFCast<CFStringRef>(value_untyped);
CFStringRef value_as_string = reinterpret_cast<CFStringRef>(
CVBufferGetAttachment(image_buffer, key, nullptr));
if (!value_as_string)
return false;
for (const auto& p : cfstr_id_pairs) {
if (p.cfstr_cm)
DCHECK(!CFStringCompare(p.cfstr_cv, p.cfstr_cm, 0));
if (!CFStringCompare(value_as_string, p.cfstr_cv, 0)) {
if (!CFStringCompare(value_as_string, p.cfstr, 0)) {
*value_as_id = p.id;
return true;
}
......@@ -272,32 +272,24 @@ bool GetImageBufferProperty(CFTypeRef value_untyped,
return false;
}
gfx::ColorSpace::PrimaryID GetCoreVideoPrimary(CFTypeRef primaries_untyped) {
gfx::ColorSpace::PrimaryID GetImageBufferPrimary(
CVImageBufferRef image_buffer) {
struct CVImagePrimary {
const CFStringRef cfstr_cv;
const CFStringRef cfstr_cm;
const CFStringRef cfstr;
const gfx::ColorSpace::PrimaryID id;
};
static const base::NoDestructor<std::vector<CVImagePrimary>>
kSupportedPrimaries([] {
std::vector<CVImagePrimary> supported_primaries;
supported_primaries.push_back(
{kCVImageBufferColorPrimaries_ITU_R_709_2,
kCMFormatDescriptionColorPrimaries_ITU_R_709_2,
gfx::ColorSpace::PrimaryID::BT709});
supported_primaries.push_back(
{kCVImageBufferColorPrimaries_EBU_3213,
kCMFormatDescriptionColorPrimaries_EBU_3213,
gfx::ColorSpace::PrimaryID::BT470BG});
supported_primaries.push_back(
{kCVImageBufferColorPrimaries_SMPTE_C,
kCMFormatDescriptionColorPrimaries_SMPTE_C,
gfx::ColorSpace::PrimaryID::SMPTE240M});
supported_primaries.push_back({kCVImageBufferColorPrimaries_ITU_R_709_2,
gfx::ColorSpace::PrimaryID::BT709});
supported_primaries.push_back({kCVImageBufferColorPrimaries_EBU_3213,
gfx::ColorSpace::PrimaryID::BT470BG});
supported_primaries.push_back({kCVImageBufferColorPrimaries_SMPTE_C,
gfx::ColorSpace::PrimaryID::SMPTE240M});
if (@available(macos 10.11, *)) {
supported_primaries.push_back(
{kCVImageBufferColorPrimaries_ITU_R_2020,
kCMFormatDescriptionColorPrimaries_ITU_R_2020,
gfx::ColorSpace::PrimaryID::BT2020});
}
return supported_primaries;
......@@ -305,19 +297,18 @@ gfx::ColorSpace::PrimaryID GetCoreVideoPrimary(CFTypeRef primaries_untyped) {
// The named primaries. Default to BT709.
auto primary_id = gfx::ColorSpace::PrimaryID::BT709;
if (!GetImageBufferProperty(primaries_untyped, *kSupportedPrimaries,
&primary_id)) {
if (!GetImageBufferProperty(image_buffer, kCVImageBufferColorPrimariesKey,
*kSupportedPrimaries, &primary_id)) {
DLOG(ERROR) << "Failed to find CVImageBufferRef primaries.";
}
return primary_id;
}
gfx::ColorSpace::TransferID GetCoreVideoTransferFn(CFTypeRef transfer_untyped,
CFTypeRef gamma_untyped,
double* gamma) {
gfx::ColorSpace::TransferID GetImageBufferTransferFn(
CVImageBufferRef image_buffer,
double* gamma) {
struct CVImageTransferFn {
const CFStringRef cfstr_cv;
const CFStringRef cfstr_cm;
const CFStringRef cfstr;
const gfx::ColorSpace::TransferID id;
};
static const base::NoDestructor<std::vector<CVImageTransferFn>>
......@@ -325,61 +316,47 @@ gfx::ColorSpace::TransferID GetCoreVideoTransferFn(CFTypeRef transfer_untyped,
std::vector<CVImageTransferFn> supported_transfer_funcs;
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_ITU_R_709_2,
kCMFormatDescriptionTransferFunction_ITU_R_709_2,
gfx::ColorSpace::TransferID::BT709_APPLE});
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_SMPTE_240M_1995,
kCMFormatDescriptionTransferFunction_SMPTE_240M_1995,
gfx::ColorSpace::TransferID::SMPTE240M});
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_UseGamma,
kCMFormatDescriptionTransferFunction_UseGamma,
gfx::ColorSpace::TransferID::CUSTOM});
if (@available(macos 10.11, *)) {
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_ITU_R_2020,
kCMFormatDescriptionTransferFunction_ITU_R_2020,
gfx::ColorSpace::TransferID::BT2020_10});
}
if (@available(macos 10.12, *)) {
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_SMPTE_ST_428_1,
kCMFormatDescriptionTransferFunction_SMPTE_ST_428_1,
gfx::ColorSpace::TransferID::SMPTEST428_1});
}
if (@available(macos 10.13, *)) {
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ,
kCMFormatDescriptionTransferFunction_SMPTE_ST_2084_PQ,
gfx::ColorSpace::TransferID::SMPTEST2084});
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_ITU_R_2100_HLG,
kCMFormatDescriptionTransferFunction_ITU_R_2100_HLG,
gfx::ColorSpace::TransferID::ARIB_STD_B67});
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_sRGB, nullptr,
{kCVImageBufferTransferFunction_sRGB,
gfx::ColorSpace::TransferID::IEC61966_2_1});
}
if (@available(macos 10.14, *)) {
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_Linear,
kCMFormatDescriptionTransferFunction_Linear,
gfx::ColorSpace::TransferID::LINEAR});
}
if (@available(macos 10.15, *)) {
supported_transfer_funcs.push_back(
{kCVImageBufferTransferFunction_sRGB,
kCMFormatDescriptionTransferFunction_sRGB,
gfx::ColorSpace::TransferID::IEC61966_2_1});
}
return supported_transfer_funcs;
}());
// The named transfer function.
auto transfer_id = gfx::ColorSpace::TransferID::BT709;
if (!GetImageBufferProperty(transfer_untyped, *kSupportedTransferFuncs,
&transfer_id)) {
if (!GetImageBufferProperty(image_buffer, kCVImageBufferTransferFunctionKey,
*kSupportedTransferFuncs, &transfer_id)) {
DLOG(ERROR) << "Failed to find CVImageBufferRef transfer.";
}
......@@ -388,9 +365,11 @@ gfx::ColorSpace::TransferID GetCoreVideoTransferFn(CFTypeRef transfer_untyped,
// If we fail to retrieve the gamma parameter, fall back to BT709.
constexpr auto kDefaultTransferFn = gfx::ColorSpace::TransferID::BT709;
CFNumberRef gamma_number = base::mac::CFCast<CFNumberRef>(gamma_untyped);
CFNumberRef gamma_number =
reinterpret_cast<CFNumberRef>(CVBufferGetAttachment(
image_buffer, kCVImageBufferGammaLevelKey, nullptr));
if (!gamma_number) {
DLOG(ERROR) << "Failed to get gamma level.";
DLOG(ERROR) << "Failed to get CVImageBufferRef gamma level.";
return kDefaultTransferFn;
}
......@@ -410,39 +389,30 @@ gfx::ColorSpace::TransferID GetCoreVideoTransferFn(CFTypeRef transfer_untyped,
return transfer_id;
}
gfx::ColorSpace::MatrixID GetCoreVideoMatrix(CFTypeRef matrix_untyped) {
gfx::ColorSpace::MatrixID GetImageBufferMatrix(CVImageBufferRef image_buffer) {
struct CVImageMatrix {
const CFStringRef cfstr_cv;
const CFStringRef cfstr_cm;
const CFStringRef cfstr;
gfx::ColorSpace::MatrixID id;
};
static const base::NoDestructor<std::vector<CVImageMatrix>>
kSupportedMatrices([] {
std::vector<CVImageMatrix> supported_matrices;
supported_matrices.push_back(
{kCVImageBufferYCbCrMatrix_ITU_R_709_2,
kCMFormatDescriptionYCbCrMatrix_ITU_R_709_2,
gfx::ColorSpace::MatrixID::BT709});
supported_matrices.push_back(
{kCVImageBufferYCbCrMatrix_ITU_R_601_4,
kCMFormatDescriptionYCbCrMatrix_ITU_R_601_4,
gfx::ColorSpace::MatrixID::SMPTE170M});
supported_matrices.push_back(
{kCVImageBufferYCbCrMatrix_SMPTE_240M_1995,
kCMFormatDescriptionYCbCrMatrix_SMPTE_240M_1995,
gfx::ColorSpace::MatrixID::SMPTE240M});
supported_matrices.push_back({kCVImageBufferYCbCrMatrix_ITU_R_709_2,
gfx::ColorSpace::MatrixID::BT709});
supported_matrices.push_back({kCVImageBufferYCbCrMatrix_ITU_R_601_4,
gfx::ColorSpace::MatrixID::SMPTE170M});
supported_matrices.push_back({kCVImageBufferYCbCrMatrix_SMPTE_240M_1995,
gfx::ColorSpace::MatrixID::SMPTE240M});
if (@available(macos 10.11, *)) {
supported_matrices.push_back(
{kCVImageBufferYCbCrMatrix_ITU_R_2020,
kCMFormatDescriptionYCbCrMatrix_ITU_R_2020,
gfx::ColorSpace::MatrixID::BT2020_NCL});
supported_matrices.push_back({kCVImageBufferYCbCrMatrix_ITU_R_2020,
gfx::ColorSpace::MatrixID::BT2020_NCL});
}
return supported_matrices;
}());
auto matrix_id = gfx::ColorSpace::MatrixID::INVALID;
if (!GetImageBufferProperty(matrix_untyped, *kSupportedMatrices,
&matrix_id)) {
if (!GetImageBufferProperty(image_buffer, kCVImageBufferYCbCrMatrixKey,
*kSupportedMatrices, &matrix_id)) {
DLOG(ERROR) << "Failed to find CVImageBufferRef YUV matrix.";
}
return matrix_id;
......@@ -542,17 +512,11 @@ CFMutableDictionaryRef CreateFormatExtensions(
return base::mac::NSToCFCast(extensions);
}
namespace {
gfx::ColorSpace GetCoreVideoColorSpaceInternal(CFTypeRef primaries_untyped,
CFTypeRef transfer_untyped,
CFTypeRef gamma_untyped,
CFTypeRef matrix_untyped) {
gfx::ColorSpace GetImageBufferColorSpace(CVImageBufferRef image_buffer) {
double gamma;
auto primary_id = GetCoreVideoPrimary(primaries_untyped);
auto matrix_id = GetCoreVideoMatrix(matrix_untyped);
auto transfer_id =
GetCoreVideoTransferFn(transfer_untyped, gamma_untyped, &gamma);
auto primary_id = GetImageBufferPrimary(image_buffer);
auto matrix_id = GetImageBufferMatrix(image_buffer);
auto transfer_id = GetImageBufferTransferFn(image_buffer, &gamma);
// Use a matrix id that is coherent with a primary id. Useful when we fail to
// parse the matrix. Previously it was always defaulting to MatrixID::BT709
......@@ -584,30 +548,4 @@ gfx::ColorSpace GetCoreVideoColorSpaceInternal(CFTypeRef primaries_untyped,
return gfx::ColorSpace(primary_id, transfer_id, matrix_id, range_id);
}
} // anonymous namespace
gfx::ColorSpace GetImageBufferColorSpace(CVImageBufferRef image_buffer) {
return GetCoreVideoColorSpaceInternal(
CVBufferGetAttachment(image_buffer, kCVImageBufferColorPrimariesKey,
nullptr),
CVBufferGetAttachment(image_buffer, kCVImageBufferTransferFunctionKey,
nullptr),
CVBufferGetAttachment(image_buffer, kCVImageBufferGammaLevelKey, nullptr),
CVBufferGetAttachment(image_buffer, kCVImageBufferYCbCrMatrixKey,
nullptr));
}
gfx::ColorSpace GetFormatDescriptionColorSpace(
CMFormatDescriptionRef format_description) {
return GetCoreVideoColorSpaceInternal(
CMFormatDescriptionGetExtension(
format_description, kCMFormatDescriptionExtension_ColorPrimaries),
CMFormatDescriptionGetExtension(
format_description, kCMFormatDescriptionExtension_TransferFunction),
CMFormatDescriptionGetExtension(format_description,
kCMFormatDescriptionExtension_GammaLevel),
CMFormatDescriptionGetExtension(
format_description, kCMFormatDescriptionExtension_YCbCrMatrix));
}
} // namespace media
......@@ -74,34 +74,6 @@ base::ScopedCFTypeRef<CVImageBufferRef> CreateCVImageBuffer(
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) {
return gfx::ColorSpace(cs.GetPrimaryID(),
gfx::ColorSpace::TransferID::BT709_APPLE,
......@@ -392,22 +364,4 @@ TEST(VTConfigUtil, GetImageBufferColorSpace_BT2020_HLG) {
}
}
TEST(VTConfigUtil, FormatDescriptionInvalid) {
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) {
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
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