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 Core 18 * @{ 19 * 20 * @brief The Core module provides basic backbone capabilities for media frameworks, 21 * including functions such as memory, error codes, and media data structures. 22 * 23 * @syscap SystemCapability.Multimedia.Media.Core 24 * @since 9 25 */ 26 27 /** 28 * @file native_avbuffer.h 29 * 30 * @brief Declared the function interface of media data structure AVBuffer. 31 * 32 * @library libnative_media_core.so 33 * @syscap SystemCapability.Multimedia.Media.Core 34 * @since 11 35 */ 36 37 #ifndef NATIVE_AVBUFFER_H 38 #define NATIVE_AVBUFFER_H 39 40 #include <stdint.h> 41 #include <stdio.h> 42 #include "native_avbuffer_info.h" 43 #include "native_averrors.h" 44 #include "native_avformat.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 typedef struct OH_AVBuffer OH_AVBuffer; 50 typedef struct OH_NativeBuffer OH_NativeBuffer; 51 52 /** 53 * @brief Create an OH_AVBuffer instance, It should be noted that the OH_AVBuffer instance pointed 54 * to by the return value * needs to be released by {@link OH_AVBuffer_Destroy}. 55 * @syscap SystemCapability.Multimedia.Media.Core 56 * @param capacity the buffer's capacity, bytes 57 * @return Returns a pointer to an OH_AVBuffer instance if the execution is successful, otherwise returns NULL. 58 * Possible failure causes: 59 * 1. capacity <= 0; 60 * 2. internal error occurred, the system has no resources. 61 * @since 11 62 */ 63 OH_AVBuffer *OH_AVBuffer_Create(int32_t capacity); 64 65 /** 66 * @brief Clear the internal resources of the buffer and destroy the buffer instance. 67 * The same buffer can not be destroyed repeatedly. 68 * @syscap SystemCapability.Multimedia.Media.Core 69 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 70 * @return Function result code. 71 * {@link AV_ERR_OK} if the execution is successful. 72 * {@link AV_ERR_INVALID_VAL} if input buffer is NULL or structure verification failed of the buffer. 73 * {@link AV_ERR_OPERATE_NOT_PERMIT} if input buffer is not user created. 74 * @since 11 75 */ 76 OH_AVErrCode OH_AVBuffer_Destroy(OH_AVBuffer *buffer); 77 78 /** 79 * @brief Get the buffer's attribute, such as pts, size, offset, and flags. 80 * @syscap SystemCapability.Multimedia.Media.Core 81 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 82 * @param attr Encapsulate OH_AVCodecBufferAttr structure instance pointer, please refer to 83 * {@link OH_AVCodecBufferAttr} 84 * @return Function result code. 85 * {@link AV_ERR_OK} if the execution is successful. 86 * {@link AV_ERR_INVALID_VAL} 87 * 1. input buffer or attr is NULL; 88 * 2. structure verification failed of the buffer. 89 * @since 11 90 */ 91 OH_AVErrCode OH_AVBuffer_GetBufferAttr(OH_AVBuffer *buffer, OH_AVCodecBufferAttr *attr); 92 93 /** 94 * @brief Set the buffer's attribute, such as pts, size, offset, and flags. 95 * @syscap SystemCapability.Multimedia.Media.Core 96 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 97 * @param attr Encapsulate OH_AVCodecBufferAttr structure instance pointer, please refer to 98 * {@link OH_AVCodecBufferAttr} 99 * @return Function result code. 100 * {@link AV_ERR_OK} if the execution is successful. 101 * {@link AV_ERR_INVALID_VAL} 102 * 1. input buffer or attr is NULL; 103 * 2. structure verification failed of the buffer; 104 * 3. the size or offset of input buffer's memory is invalid. 105 * @since 11 106 */ 107 OH_AVErrCode OH_AVBuffer_SetBufferAttr(OH_AVBuffer *buffer, const OH_AVCodecBufferAttr *attr); 108 109 /** 110 * @brief Get parameters except basic attributes, the information is carried in OH_AVFormat. 111 * It should be noted that the OH_AVFormat instance pointed to 112 * by the return value * needs to be released by {@link OH_AVFormat_Destroy}. 113 * @syscap SystemCapability.Multimedia.Media.Core 114 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 115 * @return Returns Encapsulate OH_AVFormat structure instance pointer if the execution is successful, 116 * otherwise returns NULL. Possible failure causes: 117 * 1. input buffer is NULL; 118 * 2. structure verification failed of the buffer; 119 * 3. buffer's meta is NULL. 120 * @since 11 121 */ 122 OH_AVFormat *OH_AVBuffer_GetParameter(OH_AVBuffer *buffer); 123 124 /** 125 * @brief Set parameters except basic attributes, the information is carried in OH_AVFormat. 126 * @syscap SystemCapability.Multimedia.Media.Core 127 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 128 * @param format Encapsulate OH_AVFormat structure instance pointer 129 * @return Function result code. 130 * {@link AV_ERR_OK} if the execution is successful. 131 * {@link AV_ERR_INVALID_VAL} 132 * 1. input buffer or format is NULL; 133 * 2. structure verification failed of the buffer; 134 * 3. input meta is NULL. 135 * @since 11 136 */ 137 OH_AVErrCode OH_AVBuffer_SetParameter(OH_AVBuffer *buffer, const OH_AVFormat *format); 138 139 /** 140 * @brief Get the buffer's virtual address. 141 * @syscap SystemCapability.Multimedia.Media.Core 142 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 143 * @return the buffer's virtual address if the buffer is valid, otherwise NULL 144 * Possible failure causes: 145 * 1. input buffer is NULL; 146 * 2. structure verification failed of the OH_AVBuffer; 147 * 3. internal error has occurred. 148 * @since 11 149 */ 150 uint8_t *OH_AVBuffer_GetAddr(OH_AVBuffer *buffer); 151 152 /** 153 * @brief Get the buffer's capacity(byte). 154 * @syscap SystemCapability.Multimedia.Media.Core 155 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 156 * @return The buffer's capacity if the buffer is valid, otherwise -1 157 * Possible failure causes: 158 * 1. input buffer is NULL; 159 * 2. structure verification failed of the OH_AVBuffer; 160 * 3. internal error has occurred. 161 * @since 11 162 */ 163 int32_t OH_AVBuffer_GetCapacity(OH_AVBuffer *buffer); 164 165 /** 166 * @brief Get the OH_NativeBuffer instance pointer. It should be noted that the OH_AVBuffer 167 * instance pointed to by the return value * needs to be released by {@link OH_NativeBuffer_Unreference}. 168 * @syscap SystemCapability.Multimedia.Media.Core 169 * @param buffer Encapsulate OH_AVBuffer structure instance pointer 170 * @return Returns Encapsulate OH_NativeBuffer structure instance pointer is successful, otherwise returns NULL 171 * Possible failure causes: 172 * 1. input buffer is NULL; 173 * 2. structure verification failed of the OH_AVBuffer; 174 * 3. internal error has occurred. 175 * @since 11 176 */ 177 OH_NativeBuffer *OH_AVBuffer_GetNativeBuffer(OH_AVBuffer *buffer); 178 179 #ifdef __cplusplus 180 } 181 #endif 182 183 #endif // NATIVE_AVBUFFER_H 184 /** @} */