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_CORE_H 17 #define MEDIA_CORE_H 18 19 #include <map> 20 #include <string_view> 21 #include "errors.h" 22 23 namespace OHOS { 24 namespace Media { 25 using MSErrCode = ErrCode; 26 27 // bit 28~21 is subsys, bit 20~16 is Module. bit 15~0 is code 28 constexpr MSErrCode MS_MODULE = 0X01000; 29 constexpr MSErrCode MS_ERR_OFFSET = ErrCodeOffset(SUBSYS_MULTIMEDIA, MS_MODULE); 30 enum MediaServiceErrCode : ErrCode { 31 MSERR_OK = ERR_OK, 32 MSERR_NO_MEMORY = MS_ERR_OFFSET + ENOMEM, // no memory 33 MSERR_INVALID_OPERATION = MS_ERR_OFFSET + ENOSYS, // opertation not be permitted 34 MSERR_INVALID_VAL = MS_ERR_OFFSET + EINVAL, // invalid argument 35 MSERR_UNKNOWN = MS_ERR_OFFSET + 0x200, // unkown error. 36 MSERR_SERVICE_DIED, // media service died 37 MSERR_CREATE_REC_ENGINE_FAILED, // create recorder engine failed. 38 MSERR_CREATE_PLAYER_ENGINE_FAILED, // create player engine failed. 39 MSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, // create avmetadatahelper engine failed. 40 MSERR_CREATE_AVCODEC_ENGINE_FAILED, // create avcodec engine failed. 41 MSERR_INVALID_STATE, // the state is not support this operation. 42 MSERR_UNSUPPORT, // unsupport interface. 43 MSERR_UNSUPPORT_AUD_SRC_TYPE, // unsupport audio source type. 44 MSERR_UNSUPPORT_AUD_SAMPLE_RATE, // unsupport audio sample rate. 45 MSERR_UNSUPPORT_AUD_CHANNEL_NUM, // unsupport audio channel. 46 MSERR_UNSUPPORT_AUD_ENC_TYPE, // unsupport audio encoder type. 47 MSERR_UNSUPPORT_AUD_PARAMS, // unsupport audio params(other params). 48 MSERR_UNSUPPORT_VID_SRC_TYPE, // unsupport video source type. 49 MSERR_UNSUPPORT_VID_ENC_TYPE, // unsupport video encoder type. 50 MSERR_UNSUPPORT_VID_PARAMS, // unsupport video params(other params). 51 MSERR_UNSUPPORT_CONTAINER_TYPE, // unsupport container format type. 52 MSERR_UNSUPPORT_PROTOCOL_TYPE, // unsupport protocol type. 53 MSERR_UNSUPPORT_VID_DEC_TYPE, // unsupport video decoder type. 54 MSERR_UNSUPPORT_AUD_DEC_TYPE, // unsupport audio decoder type. 55 MSERR_UNSUPPORT_STREAM, // internal data stream error. 56 MSERR_UNSUPPORT_FILE, // this appears to be a text file. 57 MSERR_UNSUPPORT_SOURCE, // unsupport source type. 58 MSERR_AUD_RENDER_FAILED, // audio render failed. 59 MSERR_AUD_ENC_FAILED, // audio encode failed. 60 MSERR_VID_ENC_FAILED, // video encode failed. 61 MSERR_AUD_DEC_FAILED, // audio decode failed. 62 MSERR_VID_DEC_FAILED, // video decode failed. 63 MSERR_MUXER_FAILED, // stream avmuxer failed. 64 MSERR_DEMUXER_FAILED, // stream demuxer or parser failed. 65 MSERR_OPEN_FILE_FAILED, // open file failed. 66 MSERR_FILE_ACCESS_FAILED, // read or write file failed. 67 MSERR_START_FAILED, // audio/video start failed. 68 MSERR_PAUSE_FAILED, // audio/video pause failed. 69 MSERR_STOP_FAILED, // audio/video stop failed. 70 MSERR_SEEK_FAILED, // audio/video seek failed. 71 MSERR_NETWORK_TIMEOUT, // network timeout. 72 MSERR_NOT_FIND_CONTAINER, // not find a demuxer. 73 MSERR_DATA_SOURCE_IO_ERROR, // media data source IO failed. 74 MSERR_DATA_SOURCE_OBTAIN_MEM_ERROR, // media data source get mem failed. 75 MSERR_DATA_SOURCE_ERROR_UNKNOWN, // media data source error unknow. 76 MSERR_AUD_INTERRUPT, // audio interrupted. 77 MSERR_MANDATORY_PARAMETER_UNSPECIFIED, // mandatory parameters are left unspecified 78 MSERR_INCORRECT_PARAMETER_TYPE, // Incorrect parameter types 79 MSERR_PARAMETER_VERIFICATION_FAILED, // Parameter verification failed 80 MSERR_USER_NO_PERMISSION, // user permission denied (AccessToken). 81 MSERR_DRM_VERIFICATION_FAILED, // DRM verification failed 82 MSERR_UNSUPPORT_WATER_MARK, // unsupported watermark 83 MSERR_DEMUXER_BUFFER_NO_MEMORY, // demuxer cache data reached its limit 84 MSERR_IO_CANNOT_FIND_HOST = MS_ERR_OFFSET + 0x400, // IO can not find host 85 MSERR_IO_CONNECTION_TIMEOUT, // IO connection timeout 86 MSERR_IO_NETWORK_ABNORMAL, // IO network abnormal. 87 MSERR_IO_NETWORK_UNAVAILABLE, // IO network unavailable. 88 MSERR_IO_NO_PERMISSION, // IO no permission. 89 MSERR_IO_NETWORK_ACCESS_DENIED, // IO request denied. 90 MSERR_IO_RESOURE_NOT_FOUND, // IO resource not found. 91 MSERR_IO_SSL_CLIENT_CERT_NEEDED, // IO SSL client cert needed. 92 MSERR_IO_SSL_CONNECT_FAIL, // IO SSL connect fail. 93 MSERR_IO_SSL_SERVER_CERT_UNTRUSTED, // IO SSL server cert untrusted. 94 MSERR_IO_UNSUPPORTTED_REQUEST, // IO unsupported request. 95 MSERR_EXTEND_START = MS_ERR_OFFSET + 0xF000, // extend err start. 96 }; 97 98 // media api error code 99 enum MediaServiceExtErrCode : int32_t { 100 MSERR_EXT_OK = 0, 101 MSERR_EXT_NO_MEMORY = 1, // no memory. 102 MSERR_EXT_OPERATE_NOT_PERMIT = 2, // opertation not be permitted. 103 MSERR_EXT_INVALID_VAL = 3, // invalid argument. 104 MSERR_EXT_IO = 4, // IO error. 105 MSERR_EXT_TIMEOUT = 5, // network timeout. 106 MSERR_EXT_UNKNOWN = 6, // unknown error. 107 MSERR_EXT_SERVICE_DIED = 7, // media service died. 108 MSERR_EXT_INVALID_STATE = 8, // the state is not support this operation. 109 MSERR_EXT_UNSUPPORT = 9, // unsupport interface. 110 MSERR_EXT_EXTEND_START = 100, // extend err start. 111 }; 112 113 // media api9 error code 114 enum MediaServiceExtErrCodeAPI9 : int32_t { 115 MSERR_EXT_API9_OK = 0, // use for determine error 116 MSERR_EXT_API9_NO_PERMISSION = 201, // permission denied (AccessToken). 117 MSERR_EXT_API9_PERMISSION_DENIED = 202, // permission denied (system API). 118 MSERR_EXT_API9_INVALID_PARAMETER = 401, // invalid parameter. 119 MSERR_EXT_API9_UNSUPPORT_CAPABILITY = 801, // unsupport api. 120 MSERR_EXT_API9_NO_MEMORY = 5400101, // no memory. 121 MSERR_EXT_API9_OPERATE_NOT_PERMIT = 5400102, // opertation not be permitted. 122 MSERR_EXT_API9_IO = 5400103, // IO error. 123 MSERR_EXT_API9_TIMEOUT = 5400104, // opertate timeout. 124 MSERR_EXT_API9_SERVICE_DIED = 5400105, // media service died. 125 MSERR_EXT_API9_UNSUPPORT_FORMAT = 5400106, // unsupport format. 126 MSERR_EXT_API9_AUDIO_INTERRUPTED = 5400107, // audio interrupted. 127 MSERR_EXT_API14_IO_CANNOT_FIND_HOST = 5411001, // IO can not find host 128 MSERR_EXT_API14_IO_CONNECTION_TIMEOUT = 5411002, // IO connection timeout 129 MSERR_EXT_API14_IO_NETWORK_ABNORMAL = 5411003, // IO network abnormal. 130 MSERR_EXT_API14_IO_NETWORK_UNAVAILABLE = 5411004, // IO network unavailable. 131 MSERR_EXT_API14_IO_NO_PERMISSION = 5411005, // IO no permission. 132 MSERR_EXT_API14_IO_NETWORK_ACCESS_DENIED = 5411006, // IO request denied. 133 MSERR_EXT_API14_IO_RESOURE_NOT_FOUND = 5411007, // IO resource not found. 134 MSERR_EXT_API14_IO_SSL_CLIENT_CERT_NEEDED = 5411008, // IO SSL client cert needed. 135 MSERR_EXT_API14_IO_SSL_CONNECT_FAIL = 5411009, // IO SSL connect fail. 136 MSERR_EXT_API14_IO_SSL_SERVER_CERT_UNTRUSTED = 5411010, // IO SSL server cert untrusted. 137 MSERR_EXT_API14_IO_UNSUPPORTTED_REQUEST = 5411011, // IO unsupported request. 138 }; 139 140 /** 141 * Media type 142 */ 143 enum MediaType : int32_t { 144 /** 145 * track is audio. 146 */ 147 MEDIA_TYPE_AUD = 0, 148 /** 149 * track is video. 150 */ 151 MEDIA_TYPE_VID = 1, 152 /** 153 * track is subtitle. 154 */ 155 MEDIA_TYPE_SUBTITLE = 2, 156 /** 157 * track is unknown 158 */ 159 MEDIA_TYPE_MAX_COUNT = 3, 160 }; 161 162 /** 163 * Enumerates the state change reason. 164 * 165 */ 166 enum StateChangeReason { 167 /** 168 * audio/video state change by user 169 */ 170 USER = 1, 171 /** 172 * audio/video state change by system 173 */ 174 BACKGROUND = 2, 175 }; 176 177 enum BufferingInfoType : int32_t { 178 /* begin to b buffering */ 179 BUFFERING_START = 1, 180 /* end to buffering */ 181 BUFFERING_END = 2, 182 /* buffering percent */ 183 BUFFERING_PERCENT = 3, 184 /* cached duration in milliseconds */ 185 CACHED_DURATION = 4, 186 }; 187 188 enum PlayerSeekMode : int32_t { 189 /* sync to keyframes after the time point. */ 190 SEEK_NEXT_SYNC = 0, 191 /* sync to keyframes before the time point. */ 192 SEEK_PREVIOUS_SYNC, 193 /* sync to closest keyframes. */ 194 SEEK_CLOSEST_SYNC, 195 /* seek to frames closest the time point. */ 196 SEEK_CLOSEST, 197 /* seek continously. */ 198 SEEK_CONTINOUS, 199 }; 200 201 enum PlayerSwitchMode : int32_t { 202 /* no seek. */ 203 SWITCH_SMOOTH = 0, 204 /* switch to keyframes before the time point. */ 205 SWITCH_SEGMENT, 206 /* switch to frames closest the time point. */ 207 SWITCH_CLOSEST, 208 }; 209 210 /** 211 * @brief Enumerates the container format types. 212 */ 213 class ContainerFormatType { 214 public: 215 static constexpr std::string_view CFT_MPEG_4A = "m4a"; 216 static constexpr std::string_view CFT_MPEG_4 = "mp4"; 217 }; 218 219 /** 220 * @brief the struct of geolocation 221 * 222 * @param latitude float: latitude in degrees. Its value must be in the range [-90, 90]. 223 * @param longitude float: longitude in degrees. Its value must be in the range [-180, 180]. 224 */ 225 struct Location { 226 int32_t latitude = 0; 227 int32_t longitude = 0; 228 }; 229 230 struct AVFileDescriptor { 231 int32_t fd = 0; 232 int64_t offset = 0; 233 int64_t length = -1; 234 }; 235 236 struct FrameLayerInfo { 237 bool isDiscardable = false; 238 uint32_t gopId = 0; 239 int32_t layer = -1; 240 }; 241 242 struct GopLayerInfo { 243 uint32_t gopSize = 0; 244 uint32_t layerCount = 0; 245 std::map<uint8_t, uint32_t> layerFrameNum; 246 }; 247 248 } // namespace Media 249 } // namespace OHOS 250 #endif // MEDIA_CORE_H 251