1 /* 2 * Copyright (c) 2025 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 17 /** 18 * @addtogroup AVTranscoder 19 * @{ 20 * 21 * @brief Provides APIs of request capability for Transcoder. 22 * 23 * @syscap SystemCapability.Multimedia.Media.AVTranscoder 24 * @since 20 25 * @} 26 */ 27 28 /** 29 * @file avtranscoder.h 30 * 31 * @brief Defines the avtranscoder APIs. Uses the Native APIs provided by Media AVTranscoder 32 * to transcode a source video file to a new video file. 33 * 34 * @kit MediaKit 35 * @library libavtranscoder.so 36 * @syscap SystemCapability.Multimedia.Media.AVTranscoder 37 * @since 20 38 */ 39 40 #ifndef MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_H 41 #define MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_H 42 43 #include <stdint.h> 44 #include <stdio.h> 45 #include "avtranscoder_base.h" 46 #include "native_avcodec_base.h" 47 #include "native_averrors.h" 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /** 54 * @brief Create a transcoder config 55 * @return Returns a pointer to an OH_AVTranscoder_Config instance for success, nullptr for failure 56 * @since 20 57 */ 58 OH_AVTranscoder_Config *OH_AVTranscoderConfig_Create(); 59 60 /** 61 * @brief release a transcoder config instance. 62 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance. 63 * @return @return Function result code. 64 * {@link AV_ERR_OK} if the execution is successful. 65 * {@link AV_ERR_INVALID_VAL} if input config is nullptr. 66 * @since 20 67 */ 68 OH_AVErrCode OH_AVTranscoderConfig_Release(OH_AVTranscoder_Config* config); 69 70 /** 71 * @brief Set Source file descriptor for transcoding. 72 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance. 73 * @param {int32_t} srcFd Source file descriptor. 74 * @param {int64_t} srcOffset The offset into the file where the data to be read, in bytes. 75 * @param {int64_t} length The length in bytes of the data to be read 76 * @return Function result code. 77 * {@link AV_ERR_OK} if the execution is successful. 78 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or file related parameter error. 79 * @since 20 80 */ 81 OH_AVErrCode OH_AVTranscoderConfig_SetSrcFD( 82 OH_AVTranscoder_Config *config, int32_t srcFd, int64_t srcOffset, int64_t length); 83 84 /** 85 * @brief Set destination file descriptor for transcoding. 86 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 87 * @param {int32_t} dstFd Destination file descriptor 88 * @return Function result code. 89 * {@link AV_ERR_OK} if the execution is successful. 90 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or dstFd is invalid. 91 * @since 20 92 */ 93 OH_AVErrCode OH_AVTranscoderConfig_SetDstFD(OH_AVTranscoder_Config *config, int32_t dstFd); 94 95 /** 96 * @brief Set destination video mime type. 97 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 98 * @param {const char*} mimeType Destination video mime type. See native_avcodec_base.h 99 * @return Function result code. 100 * {@link AV_ERR_OK} if the execution is successful. 101 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or mimeType is unrecognized. 102 * @since 20 103 */ 104 OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoType(OH_AVTranscoder_Config *config, const char *mimeType); 105 106 /** 107 * @brief Set destination audio mime type. 108 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 109 * @param {const char*} mimeType Destination audio mime type. See native_avcodec_base.h 110 * @return Function result code. 111 * {@link AV_ERR_OK} if the execution is successful. 112 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or mimeType is unrecognized. 113 * @since 20 114 */ 115 OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioType(OH_AVTranscoder_Config *config, const char *mimeType); 116 117 /** 118 * @brief Set destination file type. 119 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 120 * @param {OH_AVOutputFormat} mimeType Destination file type. See native_avcodec_base.h 121 * @return Function result code. 122 * {@link AV_ERR_OK} if the execution is successful. 123 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or mimeType is invalid. 124 * @since 20 125 */ 126 OH_AVErrCode OH_AVTranscoderConfig_SetDstFileType(OH_AVTranscoder_Config *config, OH_AVOutputFormat mimeType); 127 128 /** 129 * @brief Set destination audio bitrate. 130 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 131 * @param {int32_t} bitrate Destination audio bitrate. 132 * @return Function result code. 133 * {@link AV_ERR_OK} if the execution is successful. 134 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or bitrate value is invalid. 135 * @since 20 136 */ 137 OH_AVErrCode OH_AVTranscoderConfig_SetDstAudioBitrate(OH_AVTranscoder_Config *config, int32_t bitrate); 138 139 /** 140 * @brief Set destination video bitrate. 141 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 142 * @param {int32_t} bitrate Destination video bitrate. 143 * @return Function result code. 144 * {@link AV_ERR_OK} if the execution is successful. 145 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or bitrate value is invalid. 146 * @since 20 147 */ 148 OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoBitrate(OH_AVTranscoder_Config *config, int32_t bitrate); 149 150 /** 151 * @brief Set destination video resolution. 152 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 153 * @param {int32_t} width Destination for video width. 154 * @param {int32_t} height Destination for video height. 155 * @return Function result code. 156 * {@link AV_ERR_OK} if the execution is successful. 157 * {@link AV_ERR_INVALID_VAL} if input config is nullptr or width/height value is invalid. 158 * @since 20 159 */ 160 OH_AVErrCode OH_AVTranscoderConfig_SetDstVideoResolution(OH_AVTranscoder_Config *config, int32_t width, int32_t height); 161 162 /** 163 * @brief Create a transcoder 164 * @return {OH_AVTranscoder*} Returns a pointer to an OH_AVTranscoder instance for success, nullptr for failure 165 * @since 20 166 */ 167 OH_AVTranscoder *OH_AVTranscoder_Create(void); 168 169 /** 170 * @brief Prepare for transcoding with a config. 171 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 172 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance, 173 * see {@link OH_AVTranscoder_Config} 174 * @return Function result code. 175 * {@link AV_ERR_OK} if the execution is successful. 176 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder Prepare failed. 177 * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Prepare not allowed. 178 * {@link AV_ERR_IO} if Errors related to IO access 179 * {@link AV_ERR_SERVICE_DIED} if media service died. 180 * {@link AV_ERR_OPERATE_NOT_PERMIT} if unsupported format. 181 * @since 20 182 */ 183 OH_AVErrCode OH_AVTranscoder_Prepare(OH_AVTranscoder *transcoder, OH_AVTranscoder_Config *config); 184 185 /** 186 * @brief Start AVTranscoder. 187 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 188 * @return Function result code. 189 * {@link AV_ERR_OK} if the execution is successful. 190 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder start failed. 191 * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. 192 * {@link AV_ERR_IO} if errors related to IO access. 193 * {@link AV_ERR_SERVICE_DIED} if media service died. 194 * @since 20 195 */ 196 OH_AVErrCode OH_AVTranscoder_Start(OH_AVTranscoder *transcoder); 197 198 /** 199 * @brief Pause AVTranscoder. 200 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 201 * @return Function result code. 202 * {@link AV_ERR_OK} if the execution is successful. 203 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder pause failed. 204 * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. 205 * {@link AV_ERR_IO} if errors related to IO access. 206 * {@link AV_ERR_SERVICE_DIED} if media service died. 207 * @since 20 208 */ 209 OH_AVErrCode OH_AVTranscoder_Pause(OH_AVTranscoder *transcoder); 210 211 /** 212 * @brief Resume AVTranscoder. 213 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 214 * @return Function result code. 215 * {@link AV_ERR_OK} if the execution is successful. 216 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder resume failed. 217 * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. 218 * {@link AV_ERR_IO} if errors related to IO access. 219 * {@link AV_ERR_SERVICE_DIED} if media service died. 220 * @since 20 221 */ 222 OH_AVErrCode OH_AVTranscoder_Resume(OH_AVTranscoder *transcoder); 223 224 /** 225 * @brief Cancel AVTranscoder. 226 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 227 * @return Function result code. 228 * {@link AV_ERR_OK} if the execution is successful. 229 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder stop failed. 230 * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. 231 * {@link AV_ERR_IO} if errors related to IO access. 232 * {@link AV_ERR_SERVICE_DIED} if media service died. 233 * @since 20 234 */ 235 OH_AVErrCode OH_AVTranscoder_Cancel(OH_AVTranscoder *transcoder); 236 237 /** 238 * @brief Release AVTranscoder. 239 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 240 * @return Function result code. 241 * {@link AV_ERR_OK} if the execution is successful. 242 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or transcoder release failed. 243 * {@link AV_ERR_OPERATE_NOT_PERMIT} if the operation of Start not allowed. 244 * {@link AV_ERR_IO} if errors related to IO access. 245 * {@link AV_ERR_SERVICE_DIED} if media service died. 246 * @since 20 247 */ 248 OH_AVErrCode OH_AVTranscoder_Release(OH_AVTranscoder *transcoder); 249 250 /** 251 * @brief Set the state callback function so that your application can respond to the 252 * state change events generated by the avtranscoder. This interface must be called before Start is called. 253 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 254 * @param {OH_AVTranscoder_OnStateChange} callback State callback function, see {@link OH_AVTranscoder_OnStateChange} 255 * @param {void*} userData Pointer to user specific data 256 * @return Function result code. 257 * {@link AV_ERR_OK} if the execution is successful. 258 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or input callback is nullptr. 259 * @since 20 260 */ 261 OH_AVErrCode OH_AVTranscoder_SetStateCallback( 262 OH_AVTranscoder *transcoder, OH_AVTranscoder_OnStateChange callback, void *userData); 263 264 /** 265 * @brief Set the error callback function so that your application can respond to the 266 * error events generated by the avtranscoder. This interface must be called before Start is called. 267 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 268 * @param {OH_AVTranscoder_OnError} callback Error callback function, see {@link OH_AVTranscoder_OnError} 269 * @param {void*} userData Pointer to user specific data 270 * @return Function result code. 271 * {@link AV_ERR_OK} if the execution is successful. 272 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or input callback is nullptr. 273 * @since 20 274 */ 275 OH_AVErrCode OH_AVTranscoder_SetErrorCallback( 276 OH_AVTranscoder *transcoder, OH_AVTranscoder_OnError callback, void *userData); 277 278 /** 279 * @brief Set the progress updating callback function so that your application can respond to the 280 * progress updating events generated by the avtranscoder. This interface must be called before Start is called. 281 * @param {OH_AVTranscoder*} transcoder Pointer to an OH_AVTranscoder instance 282 * @param {OH_AVTranscoder_OnProgressUpdate} callback Uri callback function, 283 * see {@link OH_AVTranscoder_OnProgressUpdate} 284 * @param {void*} userData Pointer to user specific data 285 * @return Function result code. 286 * {@link AV_ERR_OK} if the execution is successful. 287 * {@link AV_ERR_INVALID_VAL} if input transcoder is nullptr or input callback is nullptr. 288 * @since 20 289 */ 290 OH_AVErrCode OH_AVTranscoder_SetProgressUpdateCallback( 291 OH_AVTranscoder *transcoder, OH_AVTranscoder_OnProgressUpdate callback, void *userData); 292 293 /** 294 * @brief Enable B frame in destination video. 295 * @param {OH_AVTranscoder_Config*} config Pointer to an OH_AVTranscoder_Config instance 296 * @param {bool} enabled Whecher enable B Frame. If this function is not called, B Frame is disabled. 297 * @return Function result code. 298 * {@link AV_ERR_OK} if the execution is successful. 299 * {@link AV_ERR_INVALID_VAL} if input config is nullptr. 300 * @since 20 301 */ 302 OH_AVErrCode OH_AVTranscoderConfig_EnableBFrame(OH_AVTranscoder_Config *config, bool enabled); 303 304 #ifdef __cplusplus 305 } 306 #endif 307 308 #endif // MULTIMEDIA_PLAYER_FRAMEWORK_AVTRANSCODER_H