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 NATIVE_AVBUFFER_H 17 #define NATIVE_AVBUFFER_H 18 19 #include <stdint.h> 20 #include <stdio.h> 21 #include "native_averrors.h" 22 #include "native_avformat.h" 23 #include "native_avbuffer_info.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 typedef struct OH_AVBuffer OH_AVBuffer; 29 typedef struct OH_NativeBuffer OH_NativeBuffer; 30 31 /** 32 * @brief Create an OH_AVBuffer instance, It should be noted that the life cycle of the OH_AVBuffer instance pointed 33 * to by the return value * needs to be manually released by {@link OH_AVBuffer_Destroy}. 34 * @syscap SystemCapability.Multimedia.Media.Core 35 * @param capacity the buffer's capacity, bytes 36 * @return Returns a pointer to an OH_AVBuffer instance if the execution is successful, otherwise returns nullptr 37 * @since 11 38 */ 39 OH_AVBuffer *OH_AVBuffer_Create(int32_t capacity); 40 41 /** 42 * @brief Clear the internal resources of the buffer and destroy the buffer instance. 43 * @syscap SystemCapability.Multimedia.Media.Core 44 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 45 * @return Returns AV_ERR_OK if the execution is successful, otherwise returns a specific error code, refer to 46 * {@link OH_AVErrCode} 47 * @since 11 48 */ 49 OH_AVErrCode OH_AVBuffer_Destroy(OH_AVBuffer *buffer); 50 51 /** 52 * @brief Get the buffer's attribute. 53 * @syscap SystemCapability.Multimedia.Media.Core 54 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 55 * @param attr Encapsulate OH_AVCodecBufferAttr structure instance pointer, please refer to 56 * {@link OH_AVCodecBufferAttr} 57 * @return Returns AV_ERR_OK if the execution is successful, otherwise returns a specific error code, refer to 58 * {@link OH_AVErrCode} 59 * @since 11 60 */ 61 OH_AVErrCode OH_AVBuffer_GetBufferAttr(OH_AVBuffer *buffer, OH_AVCodecBufferAttr *attr); 62 63 /** 64 * @brief Set the buffer's attribute. 65 * @syscap SystemCapability.Multimedia.Media.Core 66 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 67 * @param attr Encapsulate OH_AVCodecBufferAttr structure instance pointer, please refer to 68 * {@link OH_AVCodecBufferAttr} 69 * @return Returns AV_ERR_OK if the execution is successful, otherwise returns a specific error code, refer to 70 * {@link OH_AVErrCode} 71 * @since 11 72 */ 73 OH_AVErrCode OH_AVBuffer_SetBufferAttr(OH_AVBuffer *buffer, const OH_AVCodecBufferAttr *attr); 74 75 /** 76 * @brief Get the buffer's parameter. It should be noted that the life cycle of the OH_AVFormat instance pointed to 77 * by the return value * needs to be manually released by {@link OH_AVFormat_Destroy}. 78 * @syscap SystemCapability.Multimedia.Media.Core 79 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 80 * @return Returns Encapsulate OH_AVFormat structure instance pointer if the execution is successful, 81 * otherwise returns nullptr 82 * @since 11 83 */ 84 OH_AVFormat *OH_AVBuffer_GetParameter(OH_AVBuffer *buffer); 85 86 /** 87 * @brief Set the buffer's parameter. 88 * @syscap SystemCapability.Multimedia.Media.Core 89 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 90 * @param format Encapsulate OH_AVFormat structure instance pointer 91 * @return Returns AV_ERR_OK if the execution is successful, otherwise returns a specific error code, refer to 92 * {@link OH_AVErrCode} 93 * @since 11 94 */ 95 OH_AVErrCode OH_AVBuffer_SetParameter(OH_AVBuffer *buffer, const OH_AVFormat *format); 96 97 /** 98 * @brief Get the buffer's virtual address. 99 * @syscap SystemCapability.Multimedia.Media.Core 100 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 101 * @return the buffer's virtual address if the buffer is valid, otherwise nullptr 102 * @since 11 103 */ 104 uint8_t *OH_AVBuffer_GetAddr(OH_AVBuffer *buffer); 105 106 /** 107 * @brief Get the buffer's capacity 108 * @syscap SystemCapability.Multimedia.Media.Core 109 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 110 * @return the buffer's capacity if the buffer is valid, otherwise -1 111 * @since 11 112 */ 113 int32_t OH_AVBuffer_GetCapacity(OH_AVBuffer *buffer); 114 115 /** 116 * @brief Get the OH_NativeBuffer instance pointer,It should be noted that the life cycle of the OH_AVBuffer 117 * instance pointed to by the return value * needs to be manually released by {@link OH_NativeBuffer_Unreference}. 118 * @syscap SystemCapability.Multimedia.Media.Core 119 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 120 * @return Returns Encapsulate OH_NativeBuffer structure instance pointer is successful, 121 * otherwise returns nullptr 122 * @since 11 123 */ 124 OH_NativeBuffer *OH_AVBuffer_GetNativeBuffer(OH_AVBuffer *buffer); 125 126 #ifdef __cplusplus 127 } 128 #endif 129 130 #endif // NATIVE_AVBUFFER_H 131