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_EXTEND_START = MS_ERR_OFFSET + 0xF000, // extend err start. 85 }; 86 87 // media api error code 88 enum MediaServiceExtErrCode : int32_t { 89 MSERR_EXT_OK = 0, 90 MSERR_EXT_NO_MEMORY = 1, // no memory. 91 MSERR_EXT_OPERATE_NOT_PERMIT = 2, // opertation not be permitted. 92 MSERR_EXT_INVALID_VAL = 3, // invalid argument. 93 MSERR_EXT_IO = 4, // IO error. 94 MSERR_EXT_TIMEOUT = 5, // network timeout. 95 MSERR_EXT_UNKNOWN = 6, // unknown error. 96 MSERR_EXT_SERVICE_DIED = 7, // media service died. 97 MSERR_EXT_INVALID_STATE = 8, // the state is not support this operation. 98 MSERR_EXT_UNSUPPORT = 9, // unsupport interface. 99 MSERR_EXT_EXTEND_START = 100, // extend err start. 100 }; 101 102 // media api9 error code 103 enum MediaServiceExtErrCodeAPI9 : int32_t { 104 MSERR_EXT_API9_OK = 0, // use for determine error 105 MSERR_EXT_API9_NO_PERMISSION = 201, // permission denied (AccessToken). 106 MSERR_EXT_API9_PERMISSION_DENIED = 202, // permission denied (system API). 107 MSERR_EXT_API9_INVALID_PARAMETER = 401, // invalid parameter. 108 MSERR_EXT_API9_UNSUPPORT_CAPABILITY = 801, // unsupport api. 109 MSERR_EXT_API9_NO_MEMORY = 5400101, // no memory. 110 MSERR_EXT_API9_OPERATE_NOT_PERMIT = 5400102, // opertation not be permitted. 111 MSERR_EXT_API9_IO = 5400103, // IO error. 112 MSERR_EXT_API9_TIMEOUT = 5400104, // opertate timeout. 113 MSERR_EXT_API9_SERVICE_DIED = 5400105, // media service died. 114 MSERR_EXT_API9_UNSUPPORT_FORMAT = 5400106, // unsupport format. 115 MSERR_EXT_API9_AUDIO_INTERRUPTED = 5400107, // audio interrupted. 116 }; 117 118 /** 119 * Media type 120 */ 121 enum MediaType : int32_t { 122 /** 123 * track is audio. 124 */ 125 MEDIA_TYPE_AUD = 0, 126 /** 127 * track is video. 128 */ 129 MEDIA_TYPE_VID = 1, 130 /** 131 * track is subtitle. 132 */ 133 MEDIA_TYPE_SUBTITLE = 2, 134 /** 135 * track is unknown 136 */ 137 MEDIA_TYPE_MAX_COUNT = 3, 138 }; 139 140 /** 141 * Enumerates the state change reason. 142 * 143 */ 144 enum StateChangeReason { 145 /** 146 * audio/video state change by user 147 */ 148 USER = 1, 149 /** 150 * audio/video state change by system 151 */ 152 BACKGROUND = 2, 153 }; 154 155 enum BufferingInfoType : int32_t { 156 /* begin to b buffering */ 157 BUFFERING_START = 1, 158 /* end to buffering */ 159 BUFFERING_END = 2, 160 /* buffering percent */ 161 BUFFERING_PERCENT = 3, 162 /* cached duration in milliseconds */ 163 CACHED_DURATION = 4, 164 }; 165 166 enum PlayerSeekMode : int32_t { 167 /* sync to keyframes after the time point. */ 168 SEEK_NEXT_SYNC = 0, 169 /* sync to keyframes before the time point. */ 170 SEEK_PREVIOUS_SYNC, 171 /* sync to closest keyframes. */ 172 SEEK_CLOSEST_SYNC, 173 /* seek to frames closest the time point. */ 174 SEEK_CLOSEST, 175 /* seek continously. */ 176 SEEK_CONTINOUS, 177 }; 178 179 enum PlayerSwitchMode : int32_t { 180 /* no seek. */ 181 SWITCH_SMOOTH = 0, 182 /* switch to keyframes before the time point. */ 183 SWITCH_SEGMENT, 184 /* switch to frames closest the time point. */ 185 SWITCH_CLOSEST, 186 }; 187 188 /** 189 * @brief Enumerates the container format types. 190 */ 191 class ContainerFormatType { 192 public: 193 static constexpr std::string_view CFT_MPEG_4A = "m4a"; 194 static constexpr std::string_view CFT_MPEG_4 = "mp4"; 195 }; 196 197 /** 198 * @brief the struct of geolocation 199 * 200 * @param latitude float: latitude in degrees. Its value must be in the range [-90, 90]. 201 * @param longitude float: longitude in degrees. Its value must be in the range [-180, 180]. 202 */ 203 struct Location { 204 int32_t latitude = 0; 205 int32_t longitude = 0; 206 }; 207 208 struct AVFileDescriptor { 209 int32_t fd = 0; 210 int64_t offset = 0; 211 int64_t length = -1; 212 }; 213 214 struct FrameLayerInfo { 215 bool isDiscardable = false; 216 uint32_t gopId = 0; 217 int32_t layer = -1; 218 }; 219 220 struct GopLayerInfo { 221 uint32_t gopSize = 0; 222 uint32_t layerCount = 0; 223 std::map<uint8_t, uint32_t> layerFrameNum; 224 }; 225 226 } // namespace Media 227 } // namespace OHOS 228 #endif // MEDIA_CORE_H 229