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 AMR = 201, 148 AAC = 202, 149 MP3 = 203, 150 FLAC = 204, 151 OGG = 205, 152 M4A = 206, 153 WAV = 207, 154 APE = 208, 155 SRT = 301, 156 VTT = 302, 157 }; 158 159 /** 160 * @enum Media protocol type. 161 * 162 * @since 1.0 163 * @version 1.0 164 */ 165 enum struct ProtocolType : uint32_t { 166 UNKNOWN, ///< Unknown protocol 167 FILE, ///< File protocol, uri prefix: "file://" 168 FD, ///< File descriptor protocol, uri prefix: "fd://" 169 STREAM, ///< Stream protocol, uri prefix: "stream://" 170 HTTP, ///< Http protocol, uri prefix: "http://" 171 HTTPS, ///< Https protocol, uri prefix: "https://" 172 HLS, ///< Http live streaming protocol, uri prefix: "https://" or "https://" or "file://", suffix: ".m3u8" 173 DASH, ///< Dynamic adaptive streaming over Http protocol, uri prefix: "https://" or "https://", suffix: ".mpd" 174 RTSP, ///< Real time streaming protocol, uri prefix: "rtsp://" 175 RTP, ///< Real-time transport protocol, uri prefix: "rtp://" 176 RTMP, ///< RTMP protocol, uri prefix: "rtmp://" 177 FTP, ///< FTP protocol, uri prefix: "ftp://" 178 UDP, ///< User datagram protocol, uri prefix: "udp://" 179 }; 180 181 /** 182 * @enum Plugin Type. 183 * 184 * @since 1.0 185 * @version 1.0 186 */ 187 enum struct PluginType : int32_t { 188 INVALID_TYPE = -1, ///< Invalid plugin 189 SOURCE = 1, ///< reference SourcePlugin 190 DEMUXER, ///< reference DemuxerPlugin 191 AUDIO_DECODER, ///< reference CodecPlugin 192 AUDIO_ENCODER, ///< reference CodecPlugin 193 VIDEO_DECODER, ///< reference CodecPlugin 194 VIDEO_ENCODER, ///< reference CodecPlugin 195 AUDIO_SINK, ///< reference AudioSinkPlugin 196 VIDEO_SINK, ///< reference VideoSinkPlugin 197 MUXER, ///< reference MuxerPlugin 198 OUTPUT_SINK, ///< reference OutputSinkPlugin 199 GENERIC_PLUGIN, ///< generic plugin can be used to represent any user extended plugin 200 }; 201 202 /** 203 * @enum Plugin running state. 204 * 205 * @since 1.0 206 * @version 1.0 207 */ 208 enum struct State : int32_t { 209 CREATED = 0, ///< Indicates the status of the plugin when it is constructed. 210 ///< The plug-in will not be restored in the entire life cycle. 211 INITIALIZED = 1, ///< Plugin global resource initialization completion status. 212 PREPARED = 2, ///< Status of parameters required for plugin running. 213 RUNNING = 3, ///< The system enters the running state after call start(). 214 PAUSED = 4, ///< Plugin temporarily stops processing data. This state is optional. 215 DESTROYED = -1, ///< Plugin destruction state. In this state, all resources are released. 216 INVALID = -2, ///< An error occurs in any state and the plugin enters the invalid state. 217 }; 218 219 /** 220 * @enum codec name. 221 * 222 * @since 4.1 223 */ 224 class CodecName { 225 public: 226 static constexpr std::string_view AUDIO_DECODER_MP3_NAME = "OH.Media.Codec.Decoder.Audio.Mpeg"; 227 static constexpr std::string_view AUDIO_DECODER_AAC_NAME = "OH.Media.Codec.Decoder.Audio.AAC"; 228 static constexpr std::string_view AUDIO_DECODER_API9_AAC_NAME = "avdec_aac"; 229 static constexpr std::string_view AUDIO_DECODER_VORBIS_NAME = "OH.Media.Codec.Decoder.Audio.Vorbis"; 230 static constexpr std::string_view AUDIO_DECODER_FLAC_NAME = "OH.Media.Codec.Decoder.Audio.Flac"; 231 static constexpr std::string_view AUDIO_DECODER_AMRNB_NAME = "OH.Media.Codec.Decoder.Audio.Amrnb"; 232 static constexpr std::string_view AUDIO_DECODER_AMRWB_NAME = "OH.Media.Codec.Decoder.Audio.Amrwb"; 233 234 static constexpr std::string_view AUDIO_ENCODER_FLAC_NAME = "OH.Media.Codec.Encoder.Audio.Flac"; 235 static constexpr std::string_view AUDIO_ENCODER_AAC_NAME = "OH.Media.Codec.Encoder.Audio.AAC"; 236 static constexpr std::string_view AUDIO_ENCODER_API9_AAC_NAME = "avenc_aac"; 237 238 static constexpr std::string_view VIDEO_DECODER_AVC_NAME = "OH.Media.Codec.Decoder.Video.AVC"; 239 240 private: 241 CodecName() = delete; 242 ~CodecName() = delete; 243 }; 244 245 /** 246 * The tag content is stored in key-value format. 247 */ 248 using CodecConfig = std::vector<uint8_t>; 249 250 /** 251 * DRM structure definition 252 */ 253 #define META_DRM_KEY_ID_SIZE 16 254 #define META_DRM_IV_SIZE 16 255 #define META_DRM_MAX_SUB_SAMPLE_NUM 64 256 #define META_DRM_MAX_DRM_UUID_LEN 16 257 #define META_DRM_MAX_DRM_PSSH_LEN 2048 258 259 enum struct MetaDrmCencAlgorithm : uint32_t { 260 META_DRM_ALG_CENC_UNENCRYPTED = 0x0, 261 META_DRM_ALG_CENC_AES_CTR = 0x1, 262 META_DRM_ALG_CENC_AES_WV = 0x2, 263 META_DRM_ALG_CENC_AES_CBC = 0x3, 264 META_DRM_ALG_CENC_SM4_CBC = 0x4, 265 META_DRM_ALG_CENC_SM4_CTR, 266 }; 267 268 enum struct MetaDrmCencInfoMode : uint32_t { 269 /* key/iv/subsample set. */ 270 META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_SET = 0x0, 271 /* key/iv/subsample not set. */ 272 META_DRM_CENC_INFO_KEY_IV_SUBSAMPLES_NOT_SET = 0x1, 273 }; 274 275 struct _MetaDrmSubSample { 276 uint32_t clearHeaderLen; 277 uint32_t payLoadLen; 278 }; 279 typedef struct _MetaDrmSubSample MetaDrmSubSample; 280 281 struct _MetaDrmCencInfo { 282 MetaDrmCencAlgorithm algo; 283 uint8_t keyId[META_DRM_KEY_ID_SIZE]; 284 uint32_t keyIdLen; 285 uint8_t iv[META_DRM_IV_SIZE]; 286 uint32_t ivLen; 287 uint32_t encryptBlocks; 288 uint32_t skipBlocks; 289 uint32_t firstEncryptOffset; 290 MetaDrmSubSample subSamples[META_DRM_MAX_SUB_SAMPLE_NUM]; 291 uint32_t subSampleNum; 292 MetaDrmCencInfoMode mode; 293 }; 294 typedef struct _MetaDrmCencInfo MetaDrmCencInfo; 295 296 struct _MetaDrmInfo { 297 uint32_t uuidLen; 298 uint8_t uuid[META_DRM_MAX_DRM_UUID_LEN]; 299 uint32_t psshLen; 300 uint8_t pssh[META_DRM_MAX_DRM_PSSH_LEN]; 301 }; 302 typedef struct _MetaDrmInfo MetaDrmInfo; 303 } // namespace Plugins 304 } // namespace Media 305 } // namespace OHOS 306 #endif // MEDIA_FOUNDATION_MEDIA_TYPES_H 307