From 23524ced41ef63c2c18134edafbf911f95d627c1 Mon Sep 17 00:00:00 2001 From: Johannes Kron Date: Thu, 25 Oct 2018 13:33:16 +0200 Subject: [PATCH] Add HDR metadata struct Bug: webrtc:8651 Change-Id: Ie7e263e945eedb47776e36e2e817991977e6ef6d Reviewed-on: https://webrtc-review.googlesource.com/c/107709 Commit-Queue: Johannes Kron Reviewed-by: Niels Moller Cr-Commit-Position: refs/heads/master@{#25359} --- api/video/BUILD.gn | 2 + api/video/hdr_metadata.cc | 26 +++++++++++ api/video/hdr_metadata.h | 90 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 api/video/hdr_metadata.cc create mode 100644 api/video/hdr_metadata.h diff --git a/api/video/BUILD.gn b/api/video/BUILD.gn index a429c6804c..e3c4136148 100644 --- a/api/video/BUILD.gn +++ b/api/video/BUILD.gn @@ -13,6 +13,8 @@ rtc_source_set("video_frame") { sources = [ "color_space.cc", "color_space.h", + "hdr_metadata.cc", + "hdr_metadata.h", "video_content_type.cc", "video_content_type.h", "video_frame.cc", diff --git a/api/video/hdr_metadata.cc b/api/video/hdr_metadata.cc new file mode 100644 index 0000000000..25cd75253c --- /dev/null +++ b/api/video/hdr_metadata.cc @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "api/video/hdr_metadata.h" + +namespace webrtc { + +HdrMasteringMetadata::Chromaticity::Chromaticity() = default; +HdrMasteringMetadata::Chromaticity::Chromaticity(const Chromaticity& rhs) = + default; + +HdrMasteringMetadata::HdrMasteringMetadata() = default; +HdrMasteringMetadata::HdrMasteringMetadata(const HdrMasteringMetadata& rhs) = + default; + +HdrMetadata::HdrMetadata() = default; +HdrMetadata::HdrMetadata(const HdrMetadata& rhs) = default; + +} // namespace webrtc diff --git a/api/video/hdr_metadata.h b/api/video/hdr_metadata.h new file mode 100644 index 0000000000..8a2e6e8ef4 --- /dev/null +++ b/api/video/hdr_metadata.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_VIDEO_HDR_METADATA_H_ +#define API_VIDEO_HDR_METADATA_H_ + +#include + +namespace webrtc { + +// SMPTE ST 2086 mastering metadata, +// see https://ieeexplore.ieee.org/document/8353899. +struct HdrMasteringMetadata { + struct Chromaticity { + // xy chromaticity coordinates must be calculated as specified in ISO + // 11664-3:2012 Section 7, and must be specified with four decimal places. + // The x coordinate must be in the range [0.0001, 0.7400] and the y + // coordinate must be in the range [0.0001, 0.8400]. + float x = 0.0f; + float y = 0.0f; + bool operator==(const Chromaticity& rhs) const { + return x == rhs.x && y == rhs.y; + } + + Chromaticity(); + Chromaticity(const Chromaticity& rhs); + }; + + // The nominal primaries of the mastering display. + Chromaticity primary_r; + Chromaticity primary_g; + Chromaticity primary_b; + + // The nominal chromaticity of the white point of the mastering display. + Chromaticity white_point; + + // The nominal maximum display luminance of the mastering display. Specified + // in the unit candela/m2. The value must be in the range [5, 10000] with zero + // decimal places. + float luminance_max = 0.0f; + + // The nominal minimum display luminance of the mastering display. Specified + // in the unit candela/m2. The value must be in the range [0.0001, 5.0000] + // with four decimal places. + float luminance_min = 0.0f; + + HdrMasteringMetadata(); + HdrMasteringMetadata(const HdrMasteringMetadata& rhs); + + bool operator==(const HdrMasteringMetadata& rhs) const { + return ((primary_r == rhs.primary_r) && (primary_g == rhs.primary_g) && + (primary_b == rhs.primary_b) && (white_point == rhs.white_point) && + (luminance_max == rhs.luminance_max) && + (luminance_min == rhs.luminance_min)); + } +}; + +// High dynamic range (HDR) metadata common for HDR10 and WebM/VP9-based HDR +// formats. This struct replicates the HDRMetadata struct defined in +// https://cs.chromium.org/chromium/src/media/base/hdr_metadata.h +struct HdrMetadata { + HdrMasteringMetadata mastering_metadata; + // Max content light level (CLL), i.e. maximum brightness level present in the + // stream, in nits. 1 nit = 1 candela/m2. + uint32_t max_content_light_level = 0; + // Max frame-average light level (FALL), i.e. maximum average brightness of + // the brightest frame in the stream, in nits. + uint32_t max_frame_average_light_level = 0; + + HdrMetadata(); + HdrMetadata(const HdrMetadata& rhs); + + bool operator==(const HdrMetadata& rhs) const { + return ( + (max_content_light_level == rhs.max_content_light_level) && + (max_frame_average_light_level == rhs.max_frame_average_light_level) && + (mastering_metadata == rhs.mastering_metadata)); + } +}; + +} // namespace webrtc + +#endif // API_VIDEO_HDR_METADATA_H_