Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef API_VIDEO_HDR_METADATA_H_ |
| 12 | #define API_VIDEO_HDR_METADATA_H_ |
| 13 | |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 14 | namespace webrtc { |
| 15 | |
| 16 | // SMPTE ST 2086 mastering metadata, |
| 17 | // see https://ieeexplore.ieee.org/document/8353899. |
| 18 | struct HdrMasteringMetadata { |
| 19 | struct Chromaticity { |
Johannes Kron | fe79b34 | 2018-12-13 12:58:32 | [diff] [blame] | 20 | Chromaticity(); |
| 21 | |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 22 | bool operator==(const Chromaticity& rhs) const { |
| 23 | return x == rhs.x && y == rhs.y; |
| 24 | } |
| 25 | |
Johannes Kron | c13f4be | 2018-12-12 08:52:53 | [diff] [blame] | 26 | bool Validate() const { |
| 27 | return x >= 0.0 && x <= 1.0 && y >= 0.0 && y <= 1.0; |
| 28 | } |
| 29 | |
Johannes Kron | fe79b34 | 2018-12-13 12:58:32 | [diff] [blame] | 30 | // xy chromaticity coordinates must be calculated as specified in ISO |
| 31 | // 11664-3:2012 Section 7, and must be specified with four decimal places. |
| 32 | // The x coordinate should be in the range [0.0001, 0.7400] and the y |
| 33 | // coordinate should be in the range [0.0001, 0.8400]. Valid range [0.0000, |
| 34 | // 1.0000]. |
| 35 | float x = 0.0f; |
| 36 | float y = 0.0f; |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 37 | }; |
| 38 | |
Johannes Kron | fe79b34 | 2018-12-13 12:58:32 | [diff] [blame] | 39 | HdrMasteringMetadata(); |
| 40 | |
| 41 | bool operator==(const HdrMasteringMetadata& rhs) const { |
| 42 | return ((primary_r == rhs.primary_r) && (primary_g == rhs.primary_g) && |
| 43 | (primary_b == rhs.primary_b) && (white_point == rhs.white_point) && |
| 44 | (luminance_max == rhs.luminance_max) && |
| 45 | (luminance_min == rhs.luminance_min)); |
| 46 | } |
| 47 | |
| 48 | bool Validate() const { |
| 49 | return luminance_max >= 0.0 && luminance_max <= 20000.0 && |
| 50 | luminance_min >= 0.0 && luminance_min <= 5.0 && |
| 51 | primary_r.Validate() && primary_g.Validate() && |
| 52 | primary_b.Validate() && white_point.Validate(); |
| 53 | } |
| 54 | |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 55 | // The nominal primaries of the mastering display. |
| 56 | Chromaticity primary_r; |
| 57 | Chromaticity primary_g; |
| 58 | Chromaticity primary_b; |
| 59 | |
| 60 | // The nominal chromaticity of the white point of the mastering display. |
| 61 | Chromaticity white_point; |
| 62 | |
| 63 | // The nominal maximum display luminance of the mastering display. Specified |
Johannes Kron | c13f4be | 2018-12-12 08:52:53 | [diff] [blame] | 64 | // in the unit candela/m2. The value should be in the range [5, 10000] with |
| 65 | // zero decimal places. Valid range [0, 20000]. |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 66 | float luminance_max = 0.0f; |
| 67 | |
| 68 | // The nominal minimum display luminance of the mastering display. Specified |
Johannes Kron | c13f4be | 2018-12-12 08:52:53 | [diff] [blame] | 69 | // in the unit candela/m2. The value should be in the range [0.0001, 5.0000] |
| 70 | // with four decimal places. Valid range [0.0000, 5.0000]. |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 71 | float luminance_min = 0.0f; |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | // High dynamic range (HDR) metadata common for HDR10 and WebM/VP9-based HDR |
| 75 | // formats. This struct replicates the HDRMetadata struct defined in |
| 76 | // https://cs.chromium.org/chromium/src/media/base/hdr_metadata.h |
| 77 | struct HdrMetadata { |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 78 | HdrMetadata(); |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 79 | |
| 80 | bool operator==(const HdrMetadata& rhs) const { |
| 81 | return ( |
| 82 | (max_content_light_level == rhs.max_content_light_level) && |
| 83 | (max_frame_average_light_level == rhs.max_frame_average_light_level) && |
| 84 | (mastering_metadata == rhs.mastering_metadata)); |
| 85 | } |
Johannes Kron | c13f4be | 2018-12-12 08:52:53 | [diff] [blame] | 86 | |
| 87 | bool Validate() const { |
| 88 | return max_content_light_level >= 0 && max_content_light_level <= 20000 && |
| 89 | max_frame_average_light_level >= 0 && |
| 90 | max_frame_average_light_level <= 20000 && |
| 91 | mastering_metadata.Validate(); |
| 92 | } |
Johannes Kron | fe79b34 | 2018-12-13 12:58:32 | [diff] [blame] | 93 | |
| 94 | HdrMasteringMetadata mastering_metadata; |
| 95 | // Max content light level (CLL), i.e. maximum brightness level present in the |
| 96 | // stream, in nits. 1 nit = 1 candela/m2. Valid range [0, 20000]. |
| 97 | int max_content_light_level = 0; |
| 98 | // Max frame-average light level (FALL), i.e. maximum average brightness of |
| 99 | // the brightest frame in the stream, in nits. Valid range [0, 20000]. |
| 100 | int max_frame_average_light_level = 0; |
Johannes Kron | 23524ce | 2018-10-25 11:33:16 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | } // namespace webrtc |
| 104 | |
| 105 | #endif // API_VIDEO_HDR_METADATA_H_ |