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 MEDIA_FOUNDATION_MEDIA_TYPES_H 17 #define MEDIA_FOUNDATION_MEDIA_TYPES_H 18 19 #include <cstdint> // NOLINT: used it 20 #include <string_view> 21 #include <vector> 22 23 namespace OHOS { 24 namespace Media { 25 namespace Plugins { 26 /** 27 * @enum Media Track Type 28 * 29 * @since 1.0 30 * @version 1.0 31 */ 32 enum class MediaType : int32_t { 33 UNKNOWN = -1, ///< Usually treated as DATA 34 AUDIO = 0, 35 VIDEO = 1, 36 SUBTITLE = 2, 37 ATTACHMENT, ///< Opaque data information usually sparse 38 DATA, ///< Opaque data information usually continuous 39 TIMEDMETA 40 }; 41 42 /** 43 * @enum Seekable Status. 44 * 45 * @since 1.0 46 * @version 1.0 47 */ 48 enum class Seekable : int32_t { 49 INVALID = -1, 50 UNSEEKABLE = 0, 51 SEEKABLE = 1 52 }; 53 54 /** 55 * @enum Codec Mode. 56 * 57 * @since 1.0 58 * @version 1.0 59 */ 60 enum struct CodecMode { 61 HARDWARE, ///< HARDWARE CODEC 62 SOFTWARE, ///< SOFTWARE CODEC 63 }; 64 65 /** 66 * @enum Mux file output format. 67 * 68 * @since 1.0 69 * @version 1.0 70 */ 71 enum class OutputFormat : uint32_t { 72 DEFAULT = 0, 73 MPEG_4 = 2, 74 M4A = 6, 75 AMR = 8, 76 MP3 = 9, 77 WAV = 10, 78 }; 79 80 struct Location { 81 float latitude = 0; 82 float longitude = 0; 83 }; 84 85 /** 86 * @enum Enumerates types of Seek Mode. 87 * 88 * @brief Seek modes, Options that SeekTo() behaviour. 89 * 90 * @since 1.0 91 * @version 1.0 92 */ 93 enum struct SeekMode : uint32_t { 94 SEEK_NEXT_SYNC = 0, ///> sync to keyframes after the time point. 95 SEEK_PREVIOUS_SYNC, ///> sync to keyframes before the time point. 96 SEEK_CLOSEST_SYNC, ///> sync to closest keyframes. 97 SEEK_CLOSEST, ///> seek to frames closest the time point. 98 SEEK_CLOSEST_INNER, ///> seek to frames closest the time point for inner accurate seek. 99 }; 100 101 /** 102 * @enum Buffer flags. 103 * 104 * @since 1.0 105 * @version 1.0 106 */ 107 enum class AVBufferFlag : uint32_t { 108 NONE = 0, 109 /* This signals the end of stream */ 110 EOS = 1 << 0, 111 /* This indicates that the buffer contains the data for a sync frame */ 112 SYNC_FRAME = 1 << 1, 113 /* This indicates that the buffer only contains part of a frame */ 114 PARTIAL_FRAME = 1 << 2, 115 /* This indicated that the buffer contains codec specific data */ 116 CODEC_DATA = 1 << 3, 117 /** 118 * Flag is used to discard packets which are required to maintain valid decoder state but are not required 119 * for output and should be dropped after decoding. 120 */ 121 DISCARD = 1 << 4, 122 /** 123 * Flag is used to indicate packets that contain frames that can be discarded by the decoder, 124 * I.e. Non-reference frames. 125 */ 126 DISPOSABLE = 1 << 5, 127 /** 128 * Indicates that the frame is an extended discardable frame. It is not on the main reference path and 129 * is referenced only by discardable frames on the branch reference path are discarded by decoder, the 130 * frame can be further discarded. 131 */ 132 DISPOSABLE_EXT = 1 << 6, 133 }; 134 135 /** 136 * @enum Demux file type. 137 * 138 * @since 1.0 139 * @version 1.0 140 */ 141 enum class FileType : int32_t { 142 UNKNOW = 0, 143 MP4 = 101, 144 MPEGTS = 102, 145 MKV = 103, 146 FLV = 104, 147 AVI = 105, 148 MPEGPS = 106, 149 MOV = 107, 150 AMR = 201, 151 AAC = 202, 152 MP3 = 203, 153 FLAC = 204, 154 OGG = 205, 155 M4A = 206, 156 WAV = 207, 157 APE = 208, 158 SRT = 301, 159 VTT = 302, 160 }; 161 162 /** 163 * @enum Media protocol type. 164 * 165 * @since 1.0 166 * @version 1.0 167 */ 168 enum struct ProtocolType : uint32_t { 169 UNKNOWN, ///< Unknown protocol 170 FILE, ///< File protocol, uri prefix: "file://" 171 FD, ///< File descriptor protocol, uri prefix: "fd://" 172 STREAM, ///< Stream protocol, uri prefix: "stream://" 173 HTTP, ///< Http protocol, uri prefix: "http://" 174 HTTPS, ///< Https protocol, uri prefix: "https://" 175 HLS, ///< Http live streaming protocol, uri prefix: "https://" or "https://" or "file://", suffix: ".m3u8" 176 DASH, ///< Dynamic adaptive streaming over Http protocol, uri prefix: "https://" or "https://", suffix: ".mpd" 177 RTSP, ///< Real time streaming protocol, uri prefix: "rtsp://" 178 RTP, ///< Real-time transport protocol, uri prefix: "rtp://" 179 RTMP, ///< RTMP protocol, uri prefix: "rtmp://" 180 FTP, ///< FTP protocol, uri prefix: "ftp://" 181 UDP, ///< User datagram protocol, uri prefix: "udp://" 182 }; 183 184 /** 185 * @enum Plugin Type. 186 * 187 * @since 1.0 188 * @version 1.0 189 */ 190 enum struct PluginType : int32_t { 191 INVALID_TYPE = -1, ///< Invalid plugin 192 SOURCE = 1, ///< reference SourcePlugin 193 DEMUXER, ///< reference DemuxerPlugin 194 AUDIO_DECODER, ///< reference CodecPlugin 195 AUDIO_ENCODER, ///< reference CodecPlugin 196 VIDEO_DECODER, ///< reference CodecPlugin 197 VIDEO_ENCODER, ///< reference CodecPlugin 198 AUDIO_SINK, ///< reference AudioSinkPlugin 199 VIDEO_SINK, ///< reference VideoSinkPlugin 200 MUXER, ///< reference MuxerPlugin 201 OUTPUT_SINK, ///< reference OutputSinkPlugin 202 GENERIC_PLUGIN, ///< generic plugin can be used to represent any user extended plugin 203 }; 204 205 /** 206 * @enum Plugin running state. 207 * 208 * @since 1.0 209 * @version 1.0 210 */ 211 enum struct State : int32_t { 212 CREATED = 0, ///< Indicates the status of the plugin when it is constructed. 213 ///< The plug-in will not be restored in the entire life cycle. 214 INITIALIZED = 1, ///< Plugin global resource initialization completion status. 215 PREPARED = 2, ///< Status of parameters required for plugin running. 216 RUNNING = 3, ///< The system enters the running state after call start(). 217 PAUSED = 4, ///< Plugin temporarily stops processing data. This state is optional. 218 DESTROYED = -1, ///< Plugin destruction state. In this state, all resources are released. 219 INVALID = -2, ///< An error occurs in any state and the plugin enters the invalid state. 220 }; 221 222 /** 223 * @enum codec name. 224 * 225 * @since 4.1 226 */ 227 class CodecName { 228 public: 229 static constexpr std::string_view AUDIO_DECODER_MP3_NAME = "OH.Media.Codec.Decoder.Audio.Mpeg"; 230 static constexpr std::string_view AUDIO_DECODER_AAC_NAME = "OH.Media.Codec.Decoder.Audio.AAC"; 231 static constexpr std::string_view AUDIO_DECODER_API9_AAC_NAME = "avdec_aac"; 232 static constexpr std::string_view AUDIO_DECODER_VORBIS_NAME = "OH.Media.Codec.Decoder.Audio.Vorbis"; 233 static constexpr std::string_view AUDIO_DECODER_FLAC_NAME = "OH.Media.Codec.Decoder.Audio.Flac"; 234 static constexpr std::string_view AUDIO_DECODER_AMRNB_NAME = "OH.Media.Codec.Decoder.Audio.Amrnb"; 235 static constexpr std::string_view AUDIO_DECODER_AMRWB_NAME = "OH.Media.Codec.Decoder.Audio.Amrwb"; 236 237 static constexpr std::string_view AUDIO_ENCODER_FLAC_NAME = "OH.Media.Codec.Encoder.Audio.Flac"; 238 static constexpr std::string_view AUDIO_ENCODER_AAC_NAME = "OH.Media.Codec.Encoder.Audio.AAC"; 239 static constexpr std::string_view AUDIO_ENCODER_API9_AAC_NAME = "avenc_aac"; 240 241 static constexpr std::string_view VIDEO_DECODER_AVC_NAME = "OH.Media.Codec.Decoder.Video.AVC"; 242 243 private: 244 CodecName() = delete; 245 ~CodecName() = delete; 246 }; 247 248 /** 249 * The tag content is stored in key-value format. 250 */ 251 using CodecConfig = std::vector<uint8_t>; 252 253 /** 254 * DRM structure definition 255 */ 256 #define META_DRM_KEY_ID_SIZE 16 257 #define META_DRM_IV_SIZE 16 258 #define META_DRM_MAX_SUB_SAMPLE_NUM 64 259 #define META_DRM_MAX_DRM_UUID_LEN 16 260 #define META_DRM_MAX_DRM_PSSH_LEN 2048 261 262 enum struct MetaDrmCencAlgorithm : uint32_t { 263 META_DRM_ALG_CENC_UNENCRYPTED = 0x0, 264 META_DRM_ALG_CENC_AES_CTR = 0x1, 265 META_DRM_ALG_CENC_AES_WV = 0x2, 266 META_DRM_ALG_CENC_AES_CBC = 0x3, 267 META_DRM_ALG_CENC_SM4_CBC = 0x4, 268 META_DRM_ALG_CENC_SM4_CTR, 269 }; 270 271 enum struct MetaDrmCencInfoMode : uint32_t { 272 /* key/iv/subsample set. */ 273 META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_SET = 0x0, 274 /* key/iv/subsample not set. */ 275 META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_NOT_SET = 0x1, 276 }; 277 278 struct _MetaDrmSubSample { 279 uint32_t clearHeaderLen; 280 uint32_t payLoadLen; 281 }; 282 typedef struct _MetaDrmSubSample MetaDrmSubSample; 283 284 struct _MetaDrmCencInfo { 285 MetaDrmCencAlgorithm algo; 286 uint8_t keyId[META_DRM_KEY_ID_SIZE]; 287 uint32_t keyIdLen; 288 uint8_t iv[META_DRM_IV_SIZE]; 289 uint32_t ivLen; 290 uint32_t encryptBlocks; 291 uint32_t skipBlocks; 292 uint32_t firstEncryptOffset; 293 MetaDrmSubSample subSamples[META_DRM_MAX_SUB_SAMPLE_NUM]; 294 uint32_t subSampleNum; 295 MetaDrmCencInfoMode mode; 296 }; 297 typedef struct _MetaDrmCencInfo MetaDrmCencInfo; 298 299 struct _MetaDrmInfo { 300 uint32_t uuidLen; 301 uint8_t uuid[META_DRM_MAX_DRM_UUID_LEN]; 302 uint32_t psshLen; 303 uint8_t pssh[META_DRM_MAX_DRM_PSSH_LEN]; 304 }; 305 typedef struct _MetaDrmInfo MetaDrmInfo; 306 } // namespace Plugins 307 } // namespace Media 308 } // namespace OHOS 309 #endif // MEDIA_FOUNDATION_MEDIA_TYPES_H 310