1 /* 2 * Copyright (c) 2024, Alliance for Open Media. All rights reserved. 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 // Experimental multilayer metadata defined in CWG-E050. 13 14 #ifndef AOM_EXAMPLES_MULTILAYER_METADATA_H_ 15 #define AOM_EXAMPLES_MULTILAYER_METADATA_H_ 16 17 #include <cstdint> 18 #include <utility> 19 #include <vector> 20 21 namespace libaom_examples { 22 23 // std::pair<T, bool> is used to indicate presence of a field, 24 // like an std::optional (which cannot be used because it's C++17). 25 // If the boolean is true, then the value is present. 26 27 struct ColorProperties { 28 bool color_range; // true for full range values 29 uint8_t color_primaries; 30 uint8_t transfer_characteristics; 31 uint8_t matrix_coefficients; 32 }; 33 34 enum AlphaUse { 35 ALPHA_STRAIGHT = 0, 36 ALPHA_PREMULTIPLIED = 1, 37 ALPHA_SEGMENTATION = 2, 38 ALPHA_UNSPECIFIED = 3, 39 }; 40 41 struct AlphaInformation { 42 AlphaUse alpha_use_idc; // [0, 7] 43 uint8_t alpha_bit_depth; // [8, 15] 44 uint8_t alpha_clip_idc; // [0, 3] 45 bool alpha_incr_flag; 46 uint16_t alpha_transparent_value; // [0, 1<<(alpha_bit_depth+1)) 47 uint16_t alpha_opaque_value; // [0, 1<<(alpha_bit_depth+1)) 48 // Relevant for ALPHA_STRAIGHT only. 49 std::pair<ColorProperties, bool> alpha_color_description; 50 // Relevant for ALPHA_SEGMENTATION only. 51 // Must be either empty or have the same size as the number of values between 52 // alpha_transparent_value and alpha_opaque_value, inclusively. 53 std::vector<uint16_t> label_type_id; 54 }; 55 56 struct DepthRepresentationElement { 57 bool sign_flag; 58 uint8_t exponent; // [0, 126] (biased exponent) 59 uint8_t mantissa_len; // [1, 32] 60 uint32_t mantissa; 61 }; 62 63 struct DepthInformation { 64 std::pair<DepthRepresentationElement, bool> z_near; 65 std::pair<DepthRepresentationElement, bool> z_far; 66 std::pair<DepthRepresentationElement, bool> d_min; 67 std::pair<DepthRepresentationElement, bool> d_max; 68 uint8_t depth_representation_type; // [0, 15] 69 uint8_t disparity_ref_view_id; // [0, 3] 70 uint8_t depth_nonlinear_precision; // [8, 23] 71 // [0, 1<<depth_nonlinear_precision] 72 std::vector<uint32_t> depth_nonlinear_representation_model; 73 }; 74 75 enum MultilayerUseCase { 76 MULTILAYER_USE_CASE_UNSPECIFIED = 0, 77 MULTILAYER_USE_CASE_GLOBAL_ALPHA = 1, 78 MULTILAYER_USE_CASE_GLOBAL_DEPTH = 2, 79 MULTILAYER_USE_CASE_ALPHA = 3, 80 MULTILAYER_USE_CASE_DEPTH = 4, 81 MULTILAYER_USE_CASE_STEREO = 5, 82 MULTILAYER_USE_CASE_STEREO_GLOBAL_ALPHA = 6, 83 MULTILAYER_USE_CASE_STEREO_GLOBAL_DEPTH = 7, 84 MULTILAYER_USE_CASE_STEREO_ALPHA = 8, 85 MULTILAYER_USE_CASE_STEREO_DEPTH = 9, 86 MULTILAYER_USE_CASE_444_GLOBAL_ALPHA = 10, 87 MULTILAYER_USE_CASE_444_GLOBAL_DEPTH = 11, 88 MULTILAYER_USE_CASE_444 = 12, 89 MULTILAYER_USE_CASE_420_444 = 13, 90 }; 91 92 enum LayerType { 93 MULTILAYER_LAYER_TYPE_UNSPECIFIED = 0, 94 MULTILAYER_LAYER_TYPE_TEXTURE = 1, 95 MULTILAYER_LAYER_TYPE_TEXTURE_1 = 2, 96 MULTILAYER_LAYER_TYPE_TEXTURE_2 = 3, 97 MULTILAYER_LAYER_TYPE_TEXTURE_3 = 4, 98 MULTILAYER_LAYER_TYPE_ALPHA = 5, 99 MULTILAYER_LAYER_TYPE_DEPTH = 6, 100 }; 101 102 enum MultilayerMetadataScope { 103 SCOPE_UNSPECIFIED = 0, 104 SCOPE_LOCAL = 1, 105 SCOPE_GLOBAL = 2, 106 SCOPE_MIXED = 3, 107 }; 108 109 enum MultilayerViewType { 110 VIEW_UNSPECIFIED = 0, 111 VIEW_CENTER = 1, 112 VIEW_LEFT = 2, 113 VIEW_RIGHT = 3, 114 }; 115 116 struct LayerMetadata { 117 LayerType layer_type; // [0, 31] 118 bool luma_plane_only_flag; 119 MultilayerViewType layer_view_type; // [0, 7] 120 uint8_t group_id; // [0, 3] 121 uint8_t layer_dependency_idc; // [0, 7] 122 MultilayerMetadataScope layer_metadata_scope; // [0, 3] 123 124 std::pair<ColorProperties, bool> layer_color_description; 125 126 // Relevant for MULTILAYER_LAYER_TYPE_ALPHA with scope >= SCOPE_GLOBAL. 127 AlphaInformation global_alpha_info; 128 // Relevant for MULTILAYER_LAYER_TYPE_DEPTH with scope >= SCOPE_GLOBAL. 129 DepthInformation global_depth_info; 130 }; 131 132 struct MultilayerMetadata { 133 MultilayerUseCase use_case; // [0, 63] 134 std::vector<LayerMetadata> layers; 135 }; 136 137 // Parses a multilayer metadata file. 138 // The metadata is expected to be in a subset of the YAML format supporting 139 // simple lists and maps with integer values, and comments. 140 // Checks that the metadata is valid and terminates the process in case of 141 // error. 142 bool parse_multilayer_file(const char *metadata_path, 143 MultilayerMetadata *multilayer); 144 145 // Prints the multilayer metadata to stdout for debugging. 146 void print_multilayer_metadata(const MultilayerMetadata &multilayer); 147 148 // Converts a double value to a DepthRepresentationElement struct. 149 bool double_to_depth_representation_element( 150 double v, DepthRepresentationElement *element); 151 // Converts a DepthRepresentationElement struct to a double value. 152 double depth_representation_element_to_double( 153 const DepthRepresentationElement &e); 154 155 } // namespace libaom_examples 156 157 #endif // AOM_EXAMPLES_MULTILAYER_METADATA_H_ 158