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 /** 17 * @addtogroup VideoEncoder 18 * @{ 19 * 20 * @brief The VideoEncoder module provides interfaces for video encoding. 21 * 22 * @syscap SystemCapability.Multimedia.VideoEncoder 23 * @since 9 24 */ 25 26 /** 27 * @file native_avcodec_videoencoder.h 28 * 29 * @brief Declare the interface used for video encoding. 30 * 31 * @kit AVCodecKit 32 * @library libnative_media_venc.so 33 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 34 * @since 9 35 */ 36 37 #ifndef NATIVE_AVCODEC_VIDEOENCODER_H 38 #define NATIVE_AVCODEC_VIDEOENCODER_H 39 40 #include <stdint.h> 41 #include <stdio.h> 42 #include "native_avcodec_base.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /** 49 * @brief When OH_AVCodec needs new input parameter during the running process, the function pointer will be called and 50 * carry an available OH_AVFormat to fill in the new input parameter. This parameter takes effect immediately with the 51 * frame. 52 * 53 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 54 * @param codec OH_AVCodec instance 55 * @param index The index corresponding to the new OH_AVFormat instance 56 * @param parameter Parameter containing the new OH_AVFormat instance 57 * @param userData specified data 58 * @since 12 59 */ 60 typedef void (*OH_VideoEncoder_OnNeedInputParameter)(OH_AVCodec *codec, uint32_t index, OH_AVFormat *parameter, 61 void *userData); 62 63 /** 64 * @brief Creates a video encoder instance from the mime type, which is recommended in most cases. 65 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 66 * @param mime mime type description string, refer to {@link AVCODEC_MIME_TYPE} 67 * @return Returns a Pointer to an OH_AVCodec instance. 68 * Return nullptr if memory ran out or the mime type is not supported. 69 * @since 9 70 */ 71 OH_AVCodec *OH_VideoEncoder_CreateByMime(const char *mime); 72 73 /** 74 * @brief Create a video encoder instance through the video encoder name. The premise of using this interface is to 75 * know the exact name of the encoder. 76 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 77 * @param name Video encoder name 78 * @return Returns a Pointer to an OH_AVCodec instance. 79 * Return nullptr if memory ran out or the encoder name is not supported. 80 * @since 9 81 */ 82 OH_AVCodec *OH_VideoEncoder_CreateByName(const char *name); 83 84 /** 85 * @brief Clear the internal resources of the encoder and destroy the encoder instance 86 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 87 * @param codec Pointer to an OH_AVCodec instance 88 * @return Returns AV_ERR_OK if the execution is successful, 89 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 90 * {@link AV_ERR_NO_MEMORY}, inner resource has already released. 91 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 92 * {@link AV_ERR_UNKNOWN}, unknown error. 93 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 94 * @since 9 95 */ 96 OH_AVErrCode OH_VideoEncoder_Destroy(OH_AVCodec *codec); 97 98 /** 99 * @brief Set the asynchronous callback function so that your application can respond to the events generated by the 100 * video encoder. This interface must be called before Prepare is called. 101 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 102 * @param codec Pointer to an OH_AVCodec instance 103 * @param callback A collection of all callback functions, see {@link OH_AVCodecAsyncCallback} 104 * @param userData User specific data 105 * @return Returns AV_ERR_OK if the execution is successful, 106 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 107 * {@link AV_ERR_NO_MEMORY}, inner resource has already released. 108 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 109 * {@link AV_ERR_UNKNOWN}, unknown error. 110 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 111 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare. 112 * @deprecated since 11 113 * @useinstead OH_VideoEncoder_RegisterCallback 114 * @since 9 115 */ 116 OH_AVErrCode OH_VideoEncoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData); 117 118 /** 119 * @brief Set the asynchronous callback function so that your application can respond to the events generated by the 120 * video encoder. This interface must be called before Prepare is called. 121 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 122 * @param codec Pointer to an OH_AVCodec instance 123 * @param callback A collection of all callback functions, see {@link OH_AVCodecCallback} 124 * @param userData User specific data 125 * @return Returns AV_ERR_OK if the execution is successful, 126 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 127 * {@link AV_ERR_NO_MEMORY}, inner resource has already released. 128 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 129 * {@link AV_ERR_UNKNOWN}, unknown error. 130 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 131 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare. 132 * @since 11 133 */ 134 OH_AVErrCode OH_VideoEncoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData); 135 136 /** 137 * @brief Set the asynchronous callback function so that your application can respond to the events generated by the 138 * video encoder. This interface is optional only for input surface. If this interface is used, it must be invoked 139 * before {@link OH_VideoEncoder_Configure}. 140 * 141 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 142 * @param codec Pointer to an OH_AVCodec instance 143 * @param onInputParameter A callback functions, see {@link OH_VideoEncoder_OnNeedInputParameter} 144 * @param userData User specific data 145 * @return Returns AV_ERR_OK if the execution is successful, 146 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 147 * {@link AV_ERR_NO_MEMORY}, inner resource has already released. 148 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 149 * {@link AV_ERR_UNKNOWN}, unknown error. 150 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 151 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare. 152 * @since 12 153 */ 154 OH_AVErrCode OH_VideoEncoder_RegisterParameterCallback(OH_AVCodec *codec, 155 OH_VideoEncoder_OnNeedInputParameter onInputParameter, 156 void *userData); 157 158 /** 159 * @brief To configure the video encoder, typically, you need to configure the description information of the 160 * encoded video track. This interface must be called before Prepare is called. 161 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 162 * @param codec Pointer to an OH_AVCodec instance 163 * @param format A pointer to an OH_AVFormat that gives the description of the video track to be encoded 164 * @return Returns AV_ERR_OK if the execution is successful, 165 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 166 * {@link AV_ERR_NO_MEMORY}, instance has already released. 167 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. Invalid param in format. 168 * {@link AV_ERR_UNKNOWN}, unknown error. 169 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 170 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare. 171 * @since 9 172 */ 173 OH_AVErrCode OH_VideoEncoder_Configure(OH_AVCodec *codec, OH_AVFormat *format); 174 175 /** 176 * @brief To prepare the internal resources of the encoder, the Configure interface must be called before 177 * calling this interface. 178 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 179 * @param codec Pointer to an OH_AVCodec instance 180 * @return Returns AV_ERR_OK if the execution is successful, 181 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 182 * {@link AV_ERR_NO_MEMORY}, instance has already released. 183 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 184 * {@link AV_ERR_UNKNOWN}, unknown error. 185 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 186 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 187 * @since 9 188 */ 189 OH_AVErrCode OH_VideoEncoder_Prepare(OH_AVCodec *codec); 190 191 /** 192 * @brief Start the encoder, this interface must be called after the Prepare is successful. After being 193 * successfully started, the encoder will start reporting NeedInputData events. 194 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 195 * @param codec Pointer to an OH_AVCodec instance 196 * @return Returns AV_ERR_OK if the execution is successful, 197 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 198 * {@link AV_ERR_NO_MEMORY}, instance has already released. 199 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 200 * {@link AV_ERR_UNKNOWN}, unknown error. 201 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 202 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 203 * @since 9 204 */ 205 OH_AVErrCode OH_VideoEncoder_Start(OH_AVCodec *codec); 206 207 /** 208 * @brief Stop the encoder. After stopping, you can re-enter the Started state through Start. 209 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 210 * @param codec Pointer to an OH_AVCodec instance 211 * @return Returns AV_ERR_OK if the execution is successful, 212 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 213 * {@link AV_ERR_NO_MEMORY}, instance has already released. 214 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 215 * {@link AV_ERR_UNKNOWN}, unknown error. 216 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 217 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 218 * @since 9 219 */ 220 OH_AVErrCode OH_VideoEncoder_Stop(OH_AVCodec *codec); 221 222 /** 223 * @brief Clear the input and output data buffered in the encoder. After this interface is called, all the Buffer 224 * indexes previously reported through the asynchronous callback will be invalidated, make sure not to access the 225 * Buffers corresponding to these indexes. 226 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 227 * @param codec Pointer to an OH_AVCodec instance 228 * @return Returns AV_ERR_OK if the execution is successful, 229 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 230 * {@link AV_ERR_NO_MEMORY}, instance has already released. 231 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 232 * {@link AV_ERR_UNKNOWN}, unknown error. 233 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 234 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 235 * @since 9 236 */ 237 OH_AVErrCode OH_VideoEncoder_Flush(OH_AVCodec *codec); 238 239 /** 240 * @brief Reset the encoder. To continue coding, you need to call the Configure interface again to 241 * configure the encoder instance. 242 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 243 * @param codec Pointer to an OH_AVCodec instance 244 * @return Returns AV_ERR_OK if the execution is successful, 245 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 246 * {@link AV_ERR_NO_MEMORY}, instance has already released. 247 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 248 * {@link AV_ERR_UNKNOWN}, unknown error. 249 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 250 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 251 * @since 9 252 */ 253 OH_AVErrCode OH_VideoEncoder_Reset(OH_AVCodec *codec); 254 255 /** 256 * @brief Get the description information of the output data of the encoder, refer to {@link OH_AVFormat} for details. 257 * It should be noted that the life cycle of the OH_AVFormat instance pointed to by the return value * needs to 258 * be manually released by the caller. 259 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 260 * @param codec Pointer to an OH_AVCodec instance 261 * @return Returns a pointer to an OH_AVFormat instance. 262 * Return nullptr if the codec is nullptr or invaild. 263 * @since 9 264 */ 265 OH_AVFormat *OH_VideoEncoder_GetOutputDescription(OH_AVCodec *codec); 266 267 /** 268 * @brief Set dynamic parameters to the encoder. Note: This interface can only be called after the encoder is started. 269 * At the same time, incorrect parameter settings may cause the encoding to fail. 270 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 271 * @param codec Pointer to an OH_AVCodec instance 272 * @param format OH_AVFormat handle pointer 273 * @return Returns AV_ERR_OK if the execution is successful, 274 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 275 * {@link AV_ERR_NO_MEMORY}, instance has already released. 276 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. Invalid param in format. 277 * {@link AV_ERR_UNKNOWN}, unknown error. 278 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 279 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 280 * @since 9 281 */ 282 OH_AVErrCode OH_VideoEncoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format); 283 284 /** 285 * @brief Get the input Surface from the video encoder, this interface must be called before Prepare is called. 286 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 287 * @param codec Pointer to an OH_AVCodec instance 288 * @param window A pointer to a OHNativeWindow instance, see {@link OHNativeWindow}, the application is responsible for 289 * managing the life cycle of the window, call OH_NativeWindow_DestroyNativeWindow() when done. 290 * @return Returns AV_ERR_OK if the execution is successful, 291 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 292 * {@link AV_ERR_NO_MEMORY}, inner resource has already released. 293 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 294 * {@link AV_ERR_UNKNOWN}, unknown error. 295 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 296 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 297 * @since 9 298 */ 299 OH_AVErrCode OH_VideoEncoder_GetSurface(OH_AVCodec *codec, OHNativeWindow **window); 300 301 /** 302 * @brief Return the processed output Buffer to the encoder. 303 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 304 * @param codec Pointer to an OH_AVCodec instance 305 * @param index The index value corresponding to the output Buffer 306 * @return Returns AV_ERR_OK if the execution is successful, 307 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 308 * {@link AV_ERR_NO_MEMORY}, instance has already released. 309 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 310 * Buffer index should be given by {@link OH_AVCodecOnNewOutputData}. 311 * {@link AV_ERR_UNKNOWN}, unknown error. 312 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 313 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 314 * @deprecated since 11 315 * @useinstead OH_VideoEncoder_FreeOutputBuffer 316 * @since 9 317 */ 318 OH_AVErrCode OH_VideoEncoder_FreeOutputData(OH_AVCodec *codec, uint32_t index); 319 320 /** 321 * @brief Notifies the video encoder that the input stream has ended. It is recommended to use this interface to notify 322 * the encoder of the end of the stream in surface mode 323 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 324 * @param codec Pointer to an OH_AVCodec instance 325 * @return Returns AV_ERR_OK if the execution is successful, 326 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 327 * {@link AV_ERR_NO_MEMORY}, instance has already released. 328 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 329 * {@link AV_ERR_UNKNOWN}, unknown error. 330 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 331 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 332 * @since 9 333 */ 334 OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec); 335 336 /** 337 * @brief Submit the input buffer filled with data to the video encoder. 338 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 339 * @param codec Pointer to an OH_AVCodec instance 340 * @param index Enter the index value corresponding to the Buffer 341 * @param attr Information describing the data contained in the Buffer 342 * @return Returns AV_ERR_OK if the execution is successful, 343 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 344 * {@link AV_ERR_NO_MEMORY}, instance has already released. 345 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 346 * Buffer index should be given by {@link OH_AVCodecOnNeedInputData}. 347 * {@link AV_ERR_UNKNOWN}, unknown error. 348 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 349 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 350 * @deprecated since 11 351 * @useinstead OH_VideoEncoder_PushInputBuffer 352 * @since 10 353 */ 354 OH_AVErrCode OH_VideoEncoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr); 355 356 /** 357 * @brief Submit the input buffer filled with data to the video encoder. 358 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 359 * @param codec Pointer to an OH_AVCodec instance 360 * @param index Enter the index value corresponding to the Buffer 361 * @return Returns AV_ERR_OK if the execution is successful, 362 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 363 * {@link AV_ERR_NO_MEMORY}, instance has already released. 364 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 365 * Buffer index should be given by {@link OH_AVCodecOnNeedInputBuffer}. 366 * {@link AV_ERR_UNKNOWN}, unknown error. 367 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 368 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 369 370 * @since 11 371 */ 372 OH_AVErrCode OH_VideoEncoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index); 373 374 /** 375 * @brief Submit the input parameter filled with data to the video encoder. 376 * 377 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 378 * @param codec Pointer to an OH_AVCodec instance 379 * @param index Enter the index value corresponding to the input parameter 380 * @return Returns AV_ERR_OK if the execution is successful, 381 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 382 * {@link AV_ERR_NO_MEMORY}, instance has already released. 383 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 384 * Index should be given by {@link OH_VideoEncoder_OnNeedInputParameter}. 385 * {@link AV_ERR_UNKNOWN}, unknown error. 386 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 387 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 388 * @since 12 389 */ 390 OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t index); 391 392 /** 393 * @brief Return the processed output Buffer to the encoder. 394 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 395 * @param codec Pointer to an OH_AVCodec instance 396 * @param index The index value corresponding to the output Buffer 397 * @return Returns AV_ERR_OK if the execution is successful, 398 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 399 * {@link AV_ERR_NO_MEMORY}, instance has already released. 400 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 401 * Buffer index should be given by {@link OH_AVCodecOnNewOutputBuffer}. 402 * {@link AV_ERR_UNKNOWN}, unknown error. 403 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 404 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 405 * @since 11 406 */ 407 OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index); 408 409 /** 410 * @brief Queries the index of the next available input buffer. 411 * 412 * This API must be followed by calling {@link OH_VideoEncoder_GetInputBuffer} to obtain the buffer handle, 413 * which should then be passed to the encoder via {@link OH_VideoEncoder_PushInputBuffer}.\n 414 * Note: This operation is only supported in synchronous mode.\n 415 * 416 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 417 * @param codec Pointer to an OH_AVCodec instance 418 * @param index The index of the input buffer 419 * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. 420 * @return Returns AV_ERR_OK if the execution is successful, 421 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 422 * {@link AV_ERR_NO_MEMORY}, internal errors in the input encode instance, such as an abnormal NULL. 423 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 424 * {@link AV_ERR_UNKNOWN}, unknown error. 425 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 426 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 427 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. 428 * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay.. 429 * @since 20 430 */ 431 OH_AVErrCode OH_VideoEncoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); 432 433 /** 434 * @brief Acquires the handle of an available input buffer. 435 * 436 * Note: It's only applicable in synchronous mode.\n 437 * 438 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 439 * @param codec Pointer to an OH_AVCodec instance 440 * @param index Buffer index obtained via {@link OH_VideoEncoder_QueryInputBuffer}. 441 * @return Returns a Pointer to an OH_AVBuffer instance. 442 * Return nullptr if no buffer available. 443 * @since 20 444 */ 445 OH_AVBuffer *OH_VideoEncoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index); 446 447 /** 448 * @brief Queries the index of the next available output buffer. 449 * 450 * The obtained buffer handle through {@link OH_VideoEncoder_GetOutputBuffer} must be 451 * return to the encoder via {@link OH_VideoEncoder_FreeOutputBuffer}.\n 452 * Note: This operation is only supported in synchronous mode.\n 453 * 454 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 455 * @param codec Pointer to an OH_AVCodec instance 456 * @param index The index value corresponding to the output buffer 457 * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. 458 * @return Returns AV_ERR_OK if the execution is successful, 459 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 460 * {@link AV_ERR_NO_MEMORY}, internal errors in the input encode instance, such as an abnormal NULL. 461 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 462 * {@link AV_ERR_UNKNOWN}, unknown error. 463 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 464 * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. 465 * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. 466 * {@link AV_ERR_STREAM_CHANGED}, stream format changed, call {@link OH_VideoEncoder_GetOutputDescription} to 467 * retrieve new steam information. 468 * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay. 469 * @since 20 470 */ 471 OH_AVErrCode OH_VideoEncoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); 472 473 /** 474 * @brief Acquires the handle of an available output buffer. 475 * 476 * Note: It's only applicable in synchronous mode.\n 477 * 478 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 479 * @param codec Pointer to an OH_AVCodec instance 480 * @param index Buffer index obtained via {@link OH_VideoEncoder_QueryOutputBuffer}. 481 * @return Returns a Pointer to an OH_AVBuffer instance. 482 * Return nullptr if no buffer available. 483 * @since 20 484 */ 485 OH_AVBuffer *OH_VideoEncoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index); 486 487 /** 488 * @brief Get the input data description of the encoder after call {@OH_VideoEncoder_Configure}, 489 * refer to {@link OH_AVFormat} for details. It should be noted that the life cycle of the OH_AVFormat 490 * instance pointed to by the return value needs to be manually released by the caller. 491 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 492 * @param codec Pointer to an OH_AVCodec instance 493 * @return Returns a pointer to an OH_AVFormat instance. 494 * Return nullptr if the encoder is nullptr or invaild. 495 * @since 10 496 */ 497 OH_AVFormat *OH_VideoEncoder_GetInputDescription(OH_AVCodec *codec); 498 499 /** 500 * @brief Check whether the current codec instance is valid. It can be used fault recovery or app 501 * switchback from the background 502 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 503 * @param codec Pointer to an OH_AVCodec instance 504 * @param isValid Output Parameter. A pointer to a boolean instance, it is true if the codec instance is valid, 505 * false if the codec instance is invalid 506 * @return Returns AV_ERR_OK if the execution is successful, 507 * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. 508 * {@link AV_ERR_NO_MEMORY}, instance has already released. 509 * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. 510 * {@link AV_ERR_UNKNOWN}, unknown error. 511 * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. 512 * @since 10 513 */ 514 OH_AVErrCode OH_VideoEncoder_IsValid(OH_AVCodec *codec, bool *isValid); 515 516 /** 517 * @brief The bitrate mode of video encoder. 518 * @syscap SystemCapability.Multimedia.Media.VideoEncoder 519 * @deprecated since 14 520 * @useinstead OH_BitrateMode 521 * @since 9 522 */ 523 typedef enum OH_VideoEncodeBitrateMode { 524 /** constant bit rate mode. 525 * @deprecated since 14 526 * @useinstead BITRATE_MODE_CBR 527 */ 528 CBR = 0, 529 /** variable bit rate mode. 530 * @deprecated since 14 531 * @useinstead BITRATE_MODE_VBR 532 */ 533 VBR = 1, 534 /** constant quality mode. 535 * @deprecated since 14 536 * @useinstead BITRATE_MODE_CQ 537 */ 538 CQ = 2, 539 } OH_VideoEncodeBitrateMode; 540 541 #ifdef __cplusplus 542 } 543 #endif 544 545 #endif // NATIVE_AVCODEC_VIDEOENCODER_H 546 /** @} */