1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_HISTREAMER_ABILITY_PARSER_H 17 #define OHOS_HISTREAMER_ABILITY_PARSER_H 18 19 #include <cstdint> 20 #include <string> 21 #include <vector> 22 23 #include "cJSON.h" 24 25 #ifndef API_EXPORT 26 #define API_EXPORT __attribute__((visibility("default"))) 27 #endif 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 32 /** 33 * @enum Audio AAC Profile。 34 * 35 * AAC mode type. Note that the term profile is used with the MPEG-2 36 * standard and the term object type and profile is used with MPEG-4 37 * 38 * @since 1.0 39 * @version 1.0 40 */ 41 enum struct AudioAacProfile : uint8_t { 42 NONE = 0, ///< Null, not used 43 MAIN = 1, ///< AAC Main object 44 LC, ///< AAC Low Complexity object (AAC profile) 45 SSR, ///< AAC Scalable Sample Rate object 46 LTP, ///< AAC Long Term Prediction object 47 HE, ///< AAC High Efficiency (object type SBR, HE-AAC profile) 48 SCALABLE, ///< AAC Scalable object 49 ERLC = 17, ///< ER AAC Low Complexity object (Error Resilient AAC-LC) 50 ER_SCALABLE = 20, ///< ER AAC scalable object 51 LD = 23, ///< AAC Low Delay object (Error Resilient) 52 HE_PS = 29, ///< AAC High Efficiency with Parametric Stereo coding (HE-AAC v2, object type PS) 53 ELD = 39, ///< AAC Enhanced Low Delay. NOTE: Pending Khronos standardization 54 XHE = 42, ///< extended High Efficiency AAC. NOTE: Pending Khronos standardization 55 }; 56 57 /** 58 * @enum Audio AAC Stream Format 59 * 60 * @since 1.0 61 * @version 1.0 62 */ 63 enum struct AudioAacStreamFormat : uint8_t { 64 MP2ADTS = 0, ///< AAC Audio Data Transport Stream 2 format 65 MP4ADTS, ///< AAC Audio Data Transport Stream 4 format 66 MP4LOAS, ///< AAC Low Overhead Audio Stream format 67 MP4LATM, ///< AAC Low overhead Audio Transport Multiplex 68 ADIF, ///< AAC Audio Data Interchange Format 69 MP4FF, ///< AAC inside MPEG-4/ISO File Format 70 RAW, ///< AAC Raw Format 71 }; 72 73 /** 74 * @enum Audio Channel Masks 75 * 76 * A 64-bit integer with bits set for each channel. 77 * 78 * @since 1.0 79 * @version 1.0 80 */ 81 enum AudioChannelMasks : uint64_t { 82 FRONT_LEFT = 1ULL << 0U, 83 FRONT_RIGHT = 1ULL << 1U, 84 FRONT_CENTER = 1ULL << 2U, 85 LOW_FREQUENCY = 1ULL << 3U, 86 BACK_LEFT = 1ULL << 4U, 87 BACK_RIGHT = 1ULL << 5U, 88 FRONT_LEFT_OF_CENTER = 1ULL << 6U, 89 FRONT_RIGHT_OF_CENTER = 1ULL << 7U, 90 BACK_CENTER = 1ULL << 8U, 91 SIDE_LEFT = 1ULL << 9U, 92 SIDE_RIGHT = 1ULL << 10U, 93 TOP_CENTER = 1ULL << 11U, 94 TOP_FRONT_LEFT = 1ULL << 12U, 95 TOP_FRONT_CENTER = 1ULL << 13U, 96 TOP_FRONT_RIGHT = 1ULL << 14U, 97 TOP_BACK_LEFT = 1ULL << 15U, 98 TOP_BACK_CENTER = 1ULL << 16U, 99 TOP_BACK_RIGHT = 1ULL << 17U, 100 STEREO_LEFT = 1ULL << 29U, 101 STEREO_RIGHT = 1ULL << 30U, 102 WIDE_LEFT = 1ULL << 31U, 103 WIDE_RIGHT = 1ULL << 32U, 104 SURROUND_DIRECT_LEFT = 1ULL << 33U, 105 SURROUND_DIRECT_RIGHT = 1ULL << 34U, 106 LOW_FREQUENCY_2 = 1ULL << 35U, 107 TOP_SIDE_LEFT = 1ULL << 36U, 108 TOP_SIDE_RIGHT = 1ULL << 37U, 109 BOTTOM_FRONT_CENTER = 1ULL << 38U, 110 BOTTOM_FRONT_LEFT = 1ULL << 39U, 111 BOTTOM_FRONT_RIGHT = 1ULL << 40U, 112 }; 113 114 /** 115 * @enum Audio Channel Layout 116 * 117 * Indicates that the channel order in which the user requests decoder output 118 * is the native codec channel order. 119 * 120 * @since 1.0 121 * @version 1.0 122 */ 123 enum struct AudioChannelLayout : uint64_t { 124 UNKNOWN = 0, 125 MONO = (AudioChannelMasks::FRONT_CENTER), 126 STEREO = (AudioChannelMasks::FRONT_LEFT | AudioChannelMasks::FRONT_RIGHT), 127 CH_2POINT1 = (STEREO | AudioChannelMasks::LOW_FREQUENCY), 128 CH_2_1 = (STEREO | AudioChannelMasks::BACK_CENTER), 129 SURROUND = (STEREO | AudioChannelMasks::FRONT_CENTER), 130 CH_3POINT1 = (SURROUND | AudioChannelMasks::LOW_FREQUENCY), 131 CH_4POINT0 = (SURROUND | AudioChannelMasks::BACK_CENTER), 132 CH_4POINT1 = (CH_4POINT0 | AudioChannelMasks::LOW_FREQUENCY), 133 CH_2_2 = (STEREO | AudioChannelMasks::SIDE_LEFT | AudioChannelMasks::SIDE_RIGHT), 134 QUAD = (STEREO | AudioChannelMasks::BACK_LEFT | AudioChannelMasks::BACK_RIGHT), 135 CH_5POINT0 = (SURROUND | AudioChannelMasks::SIDE_LEFT | AudioChannelMasks::SIDE_RIGHT), 136 CH_5POINT1 = (CH_5POINT0 | AudioChannelMasks::LOW_FREQUENCY), 137 CH_5POINT0_BACK = (SURROUND | AudioChannelMasks::BACK_LEFT | AudioChannelMasks::BACK_RIGHT), 138 CH_5POINT1_BACK = (CH_5POINT0_BACK | AudioChannelMasks::LOW_FREQUENCY), 139 CH_6POINT0 = (CH_5POINT0 | AudioChannelMasks::BACK_CENTER), 140 CH_6POINT0_FRONT = (CH_2_2 | AudioChannelMasks::FRONT_LEFT_OF_CENTER | 141 AudioChannelMasks::FRONT_RIGHT_OF_CENTER), 142 HEXAGONAL = (CH_5POINT0_BACK | AudioChannelMasks::BACK_CENTER), 143 CH_6POINT1 = (CH_5POINT1 | AudioChannelMasks::BACK_CENTER), 144 CH_6POINT1_BACK = (CH_5POINT1_BACK | AudioChannelMasks::BACK_CENTER), 145 CH_6POINT1_FRONT = (CH_6POINT0_FRONT | AudioChannelMasks::LOW_FREQUENCY), 146 CH_7POINT0 = (CH_5POINT0 | AudioChannelMasks::BACK_LEFT | AudioChannelMasks::BACK_RIGHT), 147 CH_7POINT0_FRONT = (CH_5POINT0 | AudioChannelMasks::FRONT_LEFT_OF_CENTER | 148 AudioChannelMasks::FRONT_RIGHT_OF_CENTER), 149 CH_7POINT1 = (CH_5POINT1 | AudioChannelMasks::BACK_LEFT | AudioChannelMasks::BACK_RIGHT), 150 CH_7POINT1_WIDE = (CH_5POINT1 | AudioChannelMasks::FRONT_LEFT_OF_CENTER | 151 AudioChannelMasks::FRONT_RIGHT_OF_CENTER), 152 CH_7POINT1WIDE_BACK = (CH_5POINT1_BACK | AudioChannelMasks::FRONT_LEFT_OF_CENTER | 153 AudioChannelMasks::FRONT_RIGHT_OF_CENTER), 154 CH_3POINT1POINT2 = (CH_3POINT1 | AudioChannelMasks::TOP_FRONT_LEFT | AudioChannelMasks::TOP_FRONT_RIGHT), 155 CH_5POINT1POINT2 = (CH_5POINT1 | AudioChannelMasks::TOP_SIDE_LEFT | AudioChannelMasks::TOP_SIDE_RIGHT), 156 CH_5POINT1POINT4 = (CH_5POINT1 | AudioChannelMasks::TOP_FRONT_LEFT | AudioChannelMasks::TOP_FRONT_RIGHT | 157 AudioChannelMasks::TOP_BACK_LEFT | AudioChannelMasks::TOP_BACK_RIGHT), 158 CH_7POINT1POINT2 = (CH_7POINT1 | AudioChannelMasks::TOP_SIDE_LEFT | AudioChannelMasks::TOP_SIDE_RIGHT), 159 CH_7POINT1POINT4 = (CH_7POINT1 | AudioChannelMasks::TOP_FRONT_LEFT | AudioChannelMasks::TOP_FRONT_RIGHT | 160 AudioChannelMasks::TOP_BACK_LEFT | AudioChannelMasks::TOP_BACK_RIGHT), 161 CH_9POINT1POINT4 = (CH_7POINT1POINT4 | AudioChannelMasks::WIDE_LEFT | 162 AudioChannelMasks::WIDE_RIGHT), 163 CH_9POINT1POINT6 = (CH_9POINT1POINT4 | AudioChannelMasks::TOP_SIDE_LEFT | AudioChannelMasks::TOP_SIDE_RIGHT), 164 CH_10POINT2 = (AudioChannelMasks::FRONT_LEFT | AudioChannelMasks::FRONT_RIGHT | 165 AudioChannelMasks::FRONT_CENTER | AudioChannelMasks::TOP_FRONT_LEFT | 166 AudioChannelMasks::TOP_FRONT_RIGHT | AudioChannelMasks::BACK_LEFT | 167 AudioChannelMasks::BACK_RIGHT | AudioChannelMasks::BACK_CENTER | 168 AudioChannelMasks::SIDE_LEFT | AudioChannelMasks::SIDE_RIGHT | 169 AudioChannelMasks::WIDE_LEFT | AudioChannelMasks::WIDE_RIGHT), 170 CH_22POINT2 = (CH_7POINT1POINT4 | AudioChannelMasks::FRONT_LEFT_OF_CENTER | 171 AudioChannelMasks::FRONT_RIGHT_OF_CENTER | AudioChannelMasks::BACK_CENTER | 172 AudioChannelMasks::TOP_CENTER | AudioChannelMasks::TOP_FRONT_CENTER | 173 AudioChannelMasks::TOP_BACK_CENTER | AudioChannelMasks::TOP_SIDE_LEFT | 174 AudioChannelMasks::TOP_SIDE_RIGHT | AudioChannelMasks::BOTTOM_FRONT_LEFT | 175 AudioChannelMasks::BOTTOM_FRONT_RIGHT | AudioChannelMasks::BOTTOM_FRONT_CENTER | 176 AudioChannelMasks::LOW_FREQUENCY_2), 177 OCTAGONAL = (CH_5POINT0 | AudioChannelMasks::BACK_LEFT | AudioChannelMasks::BACK_CENTER | 178 AudioChannelMasks::BACK_RIGHT), 179 HEXADECAGONAL = (OCTAGONAL | AudioChannelMasks::WIDE_LEFT | AudioChannelMasks::WIDE_RIGHT | 180 AudioChannelMasks::TOP_BACK_LEFT | AudioChannelMasks::TOP_BACK_RIGHT | 181 AudioChannelMasks::TOP_BACK_CENTER | AudioChannelMasks::TOP_FRONT_CENTER | 182 AudioChannelMasks::TOP_FRONT_LEFT | AudioChannelMasks::TOP_FRONT_RIGHT), 183 STEREO_DOWNMIX = (AudioChannelMasks::STEREO_LEFT | AudioChannelMasks::STEREO_RIGHT), 184 }; 185 186 /** 187 * @enum Audio sample formats 188 * 189 * 'S' is signed, 'U' is unsigned, and 'F' is a floating-point number. 190 * 'P' is planes, default is interleaved. 191 * 192 * @since 1.0 193 * @version 1.0 194 */ 195 enum struct AudioSampleFormat : uint8_t { 196 NONE, 197 /* 8 bit */ 198 S8, U8, S8P, U8P, 199 /* 16 bit */ 200 S16, U16, S16P, U16P, 201 /* 24 bit */ 202 S24, U24, S24P, U24P, 203 /* 32 bit */ 204 S32, U32, S32P, U32P, 205 /* 64 bit */ 206 S64, U64, S64P, U64P, 207 /* float double */ 208 F32, F32P, F64, F64P, 209 }; 210 211 /** 212 * @enum Video Pixel Format. 213 * 214 * @since 1.0 215 * @version 1.0 216 */ 217 enum struct VideoPixelFormat : uint32_t { 218 UNKNOWN, 219 YUV410P, ///< planar YUV 4:1:0, 1 Cr & Cb sample per 4x4 Y samples 220 YUV411P, ///< planar YUV 4:1:1, 1 Cr & Cb sample per 4x1 Y samples 221 YUV420P, ///< planar YUV 4:2:0, 1 Cr & Cb sample per 2x2 Y samples 222 NV12, ///< semi-planar YUV 4:2:0, UVUV... 223 NV21, ///< semi-planar YUV 4:2:0, VUVU... 224 YUYV422, ///< packed YUV 4:2:2, Y0 Cb Y1 Cr 225 YUV422P, ///< planar YUV 4:2:2, 1 Cr & Cb sample per 2x1 Y samples 226 YUV444P, ///< planar YUV 4:4:4, 1 Cr & Cb sample per 1x1 Y samples 227 RGBA, ///< packed RGBA 8:8:8:8, 32bpp, RGBARGBA... 228 ARGB, ///< packed ARGB 8:8:8:8, 32bpp, ARGBARGB... 229 ABGR, ///< packed ABGR 8:8:8:8, 32bpp, ABGRABGR... 230 BGRA, ///< packed BGRA 8:8:8:8, 32bpp, BGRABGRA... 231 RGB24, ///< packed RGB 8:8:8, RGBRGB... 232 BGR24, ///< packed RGB 8:8:8, BGRBGR... 233 PAL8, ///< 8 bit with AV_PIX_FMT_RGB32 palette 234 GRAY8, ///< Y 235 MONOWHITE, ///< Y, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb 236 MONOBLACK, ///< Y, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb 237 YUVJ420P, ///< planar YUV 4:2:0, 12bpp, full scale (JPEG) 238 YUVJ422P, ///< planar YUV 4:2:2, 16bpp, full scale (JPEG) 239 YUVJ444P, ///< planar YUV 4:4:4, 24bpp, full scale (JPEG) 240 }; 241 242 /** 243 * @enum Video Bit Stream format. 244 * 245 * @since 1.0 246 * @version 1.0 247 */ 248 enum struct VideoBitStreamFormat : uint32_t { 249 UNKNOWN, 250 AVC1, // H264 bit stream format 251 HEVC, // H265 bit stream format 252 ANNEXB, // H264, H265 bit stream format 253 }; 254 255 static const std::string AUDIO_ENCODERS = "audioEncoders"; 256 static const std::string AUDIO_DECODERS = "audioDecoders"; 257 static const std::string VIDEO_ENCODERS = "videoEncoders"; 258 static const std::string VIDEO_DECODERS = "videoDecoders"; 259 260 /******************* AudioEncoder Begin *****************/ 261 struct AudioEncoderIn { 262 std::string mime; 263 std::vector<uint32_t> sample_rate; 264 }; 265 266 struct AudioEncoderOut { 267 std::string mime; 268 uint32_t ad_mpeg_ver; 269 AudioAacProfile aac_profile; 270 AudioAacStreamFormat aac_stm_fmt; 271 }; 272 273 struct AudioEncoder { 274 std::string name; 275 std::vector<AudioEncoderIn> ins; 276 std::vector<AudioEncoderOut> outs; 277 }; 278 279 void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn); 280 void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut); 281 void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder); 282 /******************* AudioEncoder End *******************/ 283 284 /******************* AudioDecoder Begin *****************/ 285 struct AudioDecoderIn { 286 std::string mime; 287 std::vector<AudioChannelLayout> channel_layout; 288 }; 289 290 struct AudioDecoderOut { 291 std::string mime; 292 std::vector<AudioSampleFormat> sample_fmt; 293 }; 294 295 struct AudioDecoder { 296 std::string name; 297 std::vector<AudioDecoderIn> ins; 298 std::vector<AudioDecoderOut> outs; 299 }; 300 301 void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn); 302 void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut); 303 void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder); 304 /******************* AudioDecoder End *******************/ 305 306 /******************* VideoEncoder Begin *****************/ 307 struct VideoEncoderIn { 308 std::string mime; 309 std::vector<VideoPixelFormat> pixel_fmt; 310 }; 311 312 struct VideoEncoderOut { 313 std::string mime; 314 }; 315 316 struct VideoEncoder { 317 std::string name; 318 std::vector<VideoEncoderIn> ins; 319 std::vector<VideoEncoderOut> outs; 320 }; 321 322 void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn); 323 void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut); 324 void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder); 325 /******************* VideoEncoder End *******************/ 326 327 /******************* VideoDecoder Begin *****************/ 328 struct VideoDecoderIn { 329 std::string mime; 330 std::vector<VideoBitStreamFormat> vd_bit_stream_fmt; 331 }; 332 333 struct VideoDecoderOut { 334 std::string mime; 335 std::vector<VideoPixelFormat> pixel_fmt; 336 }; 337 338 struct VideoDecoder { 339 std::string name; 340 std::vector<VideoDecoderIn> ins; 341 std::vector<VideoDecoderOut> outs; 342 }; 343 344 void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn); 345 void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut); 346 void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder); 347 /******************* VideoDecoder End *******************/ 348 template<typename T> 349 API_EXPORT void FromJson(const std::string &key, const cJSON *jsonObject, std::vector<T> &objs); 350 } 351 } 352 #endif