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