summaryrefslogtreecommitdiff
path: root/chromium/media/gpu/mac/vt_config_util.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/gpu/mac/vt_config_util.mm')
-rw-r--r--chromium/media/gpu/mac/vt_config_util.mm212
1 files changed, 3 insertions, 209 deletions
diff --git a/chromium/media/gpu/mac/vt_config_util.mm b/chromium/media/gpu/mac/vt_config_util.mm
index 37bf96fd9ec..4a0da1a0d6b 100644
--- a/chromium/media/gpu/mac/vt_config_util.mm
+++ b/chromium/media/gpu/mac/vt_config_util.mm
@@ -9,7 +9,6 @@
#include <simd/simd.h>
#include "base/mac/foundation_util.h"
-#include "base/no_destructor.h"
namespace {
@@ -173,7 +172,7 @@ CFStringRef GetMatrix(media::VideoColorSpace::MatrixID matrix_id) {
}
}
-void SetContentLightLevelInfo(const gl::HDRMetadata& hdr_metadata,
+void SetContentLightLevelInfo(const gfx::HDRMetadata& hdr_metadata,
NSMutableDictionary<NSString*, id>* extensions) {
if (@available(macos 10.13, *)) {
// This is a SMPTEST2086 Content Light Level Information box.
@@ -200,7 +199,7 @@ void SetContentLightLevelInfo(const gl::HDRMetadata& hdr_metadata,
}
}
-void SetMasteringMetadata(const gl::HDRMetadata& hdr_metadata,
+void SetMasteringMetadata(const gfx::HDRMetadata& hdr_metadata,
NSMutableDictionary<NSString*, id>* extensions) {
if (@available(macos 10.13, *)) {
// This is a SMPTEST2086 Mastering Display Color Volume box.
@@ -249,175 +248,6 @@ void SetMasteringMetadata(const gl::HDRMetadata& hdr_metadata,
}
}
-// Read the value for the key in |key| to CFString and convert it to IdType.
-// 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(CVImageBufferRef image_buffer,
- CFStringRef key,
- const std::vector<StringIdPair>& cfstr_id_pairs,
- IdType* value_as_id) {
- 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 (!CFStringCompare(value_as_string, p.cfstr, 0)) {
- *value_as_id = p.id;
- return true;
- }
- }
-
- return false;
-}
-
-gfx::ColorSpace::PrimaryID GetImageBufferPrimary(
- CVImageBufferRef image_buffer) {
- struct CVImagePrimary {
- 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,
- 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,
- gfx::ColorSpace::PrimaryID::BT2020});
- }
- return supported_primaries;
- }());
-
- // The named primaries. Default to BT709.
- auto primary_id = gfx::ColorSpace::PrimaryID::BT709;
- if (!GetImageBufferProperty(image_buffer, kCVImageBufferColorPrimariesKey,
- *kSupportedPrimaries, &primary_id)) {
- DLOG(ERROR) << "Failed to find CVImageBufferRef primaries.";
- }
- return primary_id;
-}
-
-gfx::ColorSpace::TransferID GetImageBufferTransferFn(
- CVImageBufferRef image_buffer,
- double* gamma) {
- struct CVImageTransferFn {
- const CFStringRef cfstr;
- const gfx::ColorSpace::TransferID id;
- };
- static const base::NoDestructor<std::vector<CVImageTransferFn>>
- kSupportedTransferFuncs([] {
- std::vector<CVImageTransferFn> supported_transfer_funcs;
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_ITU_R_709_2,
- gfx::ColorSpace::TransferID::BT709_APPLE});
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_SMPTE_240M_1995,
- gfx::ColorSpace::TransferID::SMPTE240M});
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_UseGamma,
- gfx::ColorSpace::TransferID::CUSTOM});
- if (@available(macos 10.11, *)) {
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_ITU_R_2020,
- gfx::ColorSpace::TransferID::BT2020_10});
- }
- if (@available(macos 10.12, *)) {
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_SMPTE_ST_428_1,
- gfx::ColorSpace::TransferID::SMPTEST428_1});
- }
- if (@available(macos 10.13, *)) {
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ,
- gfx::ColorSpace::TransferID::SMPTEST2084});
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_ITU_R_2100_HLG,
- gfx::ColorSpace::TransferID::ARIB_STD_B67});
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_sRGB,
- gfx::ColorSpace::TransferID::IEC61966_2_1});
- }
- if (@available(macos 10.14, *)) {
- supported_transfer_funcs.push_back(
- {kCVImageBufferTransferFunction_Linear,
- gfx::ColorSpace::TransferID::LINEAR});
- }
-
- return supported_transfer_funcs;
- }());
-
- // The named transfer function.
- auto transfer_id = gfx::ColorSpace::TransferID::BT709;
- if (!GetImageBufferProperty(image_buffer, kCVImageBufferTransferFunctionKey,
- *kSupportedTransferFuncs, &transfer_id)) {
- DLOG(ERROR) << "Failed to find CVImageBufferRef transfer.";
- }
-
- if (transfer_id != gfx::ColorSpace::TransferID::CUSTOM)
- return transfer_id;
-
- // If we fail to retrieve the gamma parameter, fall back to BT709.
- constexpr auto kDefaultTransferFn = gfx::ColorSpace::TransferID::BT709;
- CFNumberRef gamma_number =
- reinterpret_cast<CFNumberRef>(CVBufferGetAttachment(
- image_buffer, kCVImageBufferGammaLevelKey, nullptr));
- if (!gamma_number) {
- DLOG(ERROR) << "Failed to get CVImageBufferRef gamma level.";
- return kDefaultTransferFn;
- }
-
- // CGFloat is a double on 64-bit systems.
- CGFloat gamma_double = 0;
- if (!CFNumberGetValue(gamma_number, kCFNumberCGFloatType, &gamma_double)) {
- DLOG(ERROR) << "Failed to get CVImageBufferRef gamma level as float.";
- return kDefaultTransferFn;
- }
-
- if (gamma_double == 2.2)
- return gfx::ColorSpace::TransferID::GAMMA22;
- if (gamma_double == 2.8)
- return gfx::ColorSpace::TransferID::GAMMA28;
-
- *gamma = gamma_double;
- return transfer_id;
-}
-
-gfx::ColorSpace::MatrixID GetImageBufferMatrix(CVImageBufferRef image_buffer) {
- struct CVImageMatrix {
- 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,
- 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,
- gfx::ColorSpace::MatrixID::BT2020_NCL});
- }
- return supported_matrices;
- }());
-
- auto matrix_id = gfx::ColorSpace::MatrixID::INVALID;
- if (!GetImageBufferProperty(image_buffer, kCVImageBufferYCbCrMatrixKey,
- *kSupportedMatrices, &matrix_id)) {
- DLOG(ERROR) << "Failed to find CVImageBufferRef YUV matrix.";
- }
- return matrix_id;
-}
-
void SetVp9CodecConfigurationBox(
media::VideoCodecProfile codec_profile,
const media::VideoColorSpace& color_space,
@@ -469,7 +299,7 @@ CFMutableDictionaryRef CreateFormatExtensions(
CMVideoCodecType codec_type,
VideoCodecProfile profile,
const VideoColorSpace& color_space,
- base::Optional<gl::HDRMetadata> hdr_metadata) {
+ base::Optional<gfx::HDRMetadata> hdr_metadata) {
auto* extensions = [[NSMutableDictionary alloc] init];
SetDictionaryValue(extensions, kCMFormatDescriptionExtension_FormatName,
CMVideoCodecTypeToString(codec_type));
@@ -512,40 +342,4 @@ CFMutableDictionaryRef CreateFormatExtensions(
return base::mac::NSToCFCast(extensions);
}
-gfx::ColorSpace GetImageBufferColorSpace(CVImageBufferRef image_buffer) {
- double 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
- // See http://crbug.com/788236.
- if (matrix_id == gfx::ColorSpace::MatrixID::INVALID) {
- if (primary_id == gfx::ColorSpace::PrimaryID::BT470BG)
- matrix_id = gfx::ColorSpace::MatrixID::BT470BG;
- else
- matrix_id = gfx::ColorSpace::MatrixID::BT709;
- }
-
- // It is specified to the decoder to use luma=[16,235] chroma=[16,240] via
- // the kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange.
- //
- // TODO(crbug.com/1103432): We'll probably need support for more than limited
- // range content if we want this to be used for more than video sites.
- auto range_id = gfx::ColorSpace::RangeID::LIMITED;
-
- if (transfer_id == gfx::ColorSpace::TransferID::CUSTOM) {
- // Transfer functions can also be specified as a gamma value.
- skcms_TransferFunction custom_tr_fn = {2.2f, 1, 0, 1, 0, 0, 0};
- if (transfer_id == gfx::ColorSpace::TransferID::CUSTOM)
- custom_tr_fn.g = gamma;
-
- return gfx::ColorSpace(primary_id, gfx::ColorSpace::TransferID::CUSTOM,
- matrix_id, range_id, nullptr, &custom_tr_fn);
- }
-
- return gfx::ColorSpace(primary_id, transfer_id, matrix_id, range_id);
-}
-
} // namespace media