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_avformat.h 29 * 30 * @brief Declared functions and enumerations related to OH_AVFormat. 31 * 32 * @kit AVCodecKit 33 * @library libnative_media_core.so 34 * @syscap SystemCapability.Multimedia.Media.Core 35 * @since 9 36 */ 37 38 #ifndef NATIVE_AVFORMAT_H 39 #define NATIVE_AVFORMAT_H 40 41 #include <stdint.h> 42 #include <stdbool.h> 43 #include <stdio.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 typedef struct OH_AVFormat OH_AVFormat; 50 51 /** 52 * @brief Enumerates AVPixel Format. 53 * @syscap SystemCapability.Multimedia.Media.Core 54 * @since 9 55 * @version 1.0 56 */ 57 typedef enum OH_AVPixelFormat { 58 /** 59 * yuv 420 planar. 60 */ 61 AV_PIXEL_FORMAT_YUVI420 = 1, 62 /** 63 * NV12. yuv 420 semiplanar. 64 */ 65 AV_PIXEL_FORMAT_NV12 = 2, 66 /** 67 * NV21. yvu 420 semiplanar. 68 */ 69 AV_PIXEL_FORMAT_NV21 = 3, 70 /** 71 * format from surface. 72 */ 73 AV_PIXEL_FORMAT_SURFACE_FORMAT = 4, 74 /** 75 * RGBA8888 76 */ 77 AV_PIXEL_FORMAT_RGBA = 5, 78 } OH_AVPixelFormat; 79 80 /** 81 * @briefCreate an OH_AVFormat handle pointer to read and write data 82 * @syscap SystemCapability.Multimedia.Media.Core 83 * @return Returns a pointer to an OH_AVFormat instance 84 * @since 9 85 * @version 1.0 86 */ 87 struct OH_AVFormat *OH_AVFormat_Create(void); 88 89 /** 90 * @briefCreate an audio OH_AVFormat handle pointer to read and write data 91 * @syscap SystemCapability.Multimedia.Media.Core 92 * @param mimeType mime type 93 * @param sampleRate sample rate 94 * @param channelCount channel count 95 * @return Returns a pointer to an OH_AVFormat instance 96 * @since 10 97 * @version 1.0 98 */ 99 struct OH_AVFormat *OH_AVFormat_CreateAudioFormat(const char *mimeType, 100 int32_t sampleRate, 101 int32_t channelCount); 102 103 /** 104 * @briefCreate an video OH_AVFormat handle pointer to read and write data 105 * @syscap SystemCapability.Multimedia.Media.Core 106 * @param mimeType mime type 107 * @param width width 108 * @param height height 109 * @return Returns a pointer to an OH_AVFormat instance 110 * @since 10 111 * @version 1.0 112 */ 113 struct OH_AVFormat *OH_AVFormat_CreateVideoFormat(const char *mimeType, 114 int32_t width, 115 int32_t height); 116 117 /** 118 * @brief Destroy the specified OH_AVFormat handle resource 119 * @syscap SystemCapability.Multimedia.Media.Core 120 * @param format pointer to an OH_AVFormat instance 121 * @return void 122 * @since 9 123 * @version 1.0 124 */ 125 void OH_AVFormat_Destroy(struct OH_AVFormat *format); 126 127 /** 128 * @brief Copy OH_AVFormat handle resource 129 * @syscap SystemCapability.Multimedia.Media.Core 130 * @param to OH_AVFormat handle pointer to receive data 131 * @param from pointer to the OH_AVFormat handle of the copied data 132 * @return The return value is TRUE for success, FALSE for failure 133 * @since 9 134 * @version 1.0 135 */ 136 bool OH_AVFormat_Copy(struct OH_AVFormat *to, struct OH_AVFormat *from); 137 138 /** 139 * @brief Write Int data to OH_AVFormat 140 * @syscap SystemCapability.Multimedia.Media.Core 141 * @param format pointer to an OH_AVFormat instance 142 * @param key key to write data 143 * @param value written data 144 * @return The return value is TRUE for success, FALSE for failure 145 * @since 9 146 * @version 1.0 147 */ 148 bool OH_AVFormat_SetIntValue(struct OH_AVFormat *format, const char *key, int32_t value); 149 150 /** 151 * @brief Write Long data to OH_AVFormat 152 * @syscap SystemCapability.Multimedia.Media.Core 153 * @param format pointer to an OH_AVFormat instance 154 * @param key key to write data 155 * @param value written data 156 * @return The return value is TRUE for success, FALSE for failure 157 * @since 9 158 * @version 1.0 159 */ 160 bool OH_AVFormat_SetLongValue(struct OH_AVFormat *format, const char *key, int64_t value); 161 162 /** 163 * @brief Write Float data to OH_AVFormat 164 * @syscap SystemCapability.Multimedia.Media.Core 165 * @param format pointer to an OH_AVFormat instance 166 * @param key key to write data 167 * @param value written data 168 * @return The return value is TRUE for success, FALSE for failure 169 * @since 9 170 * @version 1.0 171 */ 172 bool OH_AVFormat_SetFloatValue(struct OH_AVFormat *format, const char *key, float value); 173 174 /** 175 * @brief Write Double data to OH_AVFormat 176 * @syscap SystemCapability.Multimedia.Media.Core 177 * @param format pointer to an OH_AVFormat instance 178 * @param key key to write data 179 * @param value written data 180 * @return The return value is TRUE for success, FALSE for failure 181 * @since 9 182 * @version 1.0 183 */ 184 bool OH_AVFormat_SetDoubleValue(struct OH_AVFormat *format, const char *key, double value); 185 186 /** 187 * @brief Write String data to OH_AVFormat 188 * @syscap SystemCapability.Multimedia.Media.Core 189 * @param format pointer to an OH_AVFormat instance 190 * @param key key to write data 191 * @param value written data 192 * @return The return value is TRUE for success, FALSE for failure 193 * @since 9 194 * @version 1.0 195 */ 196 bool OH_AVFormat_SetStringValue(struct OH_AVFormat *format, const char *key, const char *value); 197 198 /** 199 * @brief Write a block of data of a specified length to OH_AVFormat 200 * @syscap SystemCapability.Multimedia.Media.Core 201 * @param format pointer to an OH_AVFormat instance 202 * @param key key to write data 203 * @param addr written data addr 204 * @param size written data length 205 * @return The return value is TRUE for success, FALSE for failure 206 * @since 9 207 * @version 1.0 208 */ 209 bool OH_AVFormat_SetBuffer(struct OH_AVFormat *format, const char *key, const uint8_t *addr, size_t size); 210 211 /** 212 * @brief Read Int data from OH_AVFormat 213 * @syscap SystemCapability.Multimedia.Media.Core 214 * @param format pointer to an OH_AVFormat instance 215 * @param key read key value 216 * @param out read data 217 * @return The return value is TRUE for success, FALSE for failure 218 * @since 9 219 * @version 1.0 220 */ 221 bool OH_AVFormat_GetIntValue(struct OH_AVFormat *format, const char *key, int32_t *out); 222 223 /** 224 * @brief Read Long data from OH_AVFormat 225 * @syscap SystemCapability.Multimedia.Media.Core 226 * @param format pointer to an OH_AVFormat instance 227 * @param key read key value 228 * @param out read data 229 * @return The return value is TRUE for success, FALSE for failure 230 * @since 9 231 * @version 1.0 232 */ 233 bool OH_AVFormat_GetLongValue(struct OH_AVFormat *format, const char *key, int64_t *out); 234 235 /** 236 * @brief Read Float data from OH_AVFormat 237 * @syscap SystemCapability.Multimedia.Media.Core 238 * @param format pointer to an OH_AVFormat instance 239 * @param key read key value 240 * @param out read data 241 * @return The return value is TRUE for success, FALSE for failure 242 * @since 9 243 * @version 1.0 244 */ 245 bool OH_AVFormat_GetFloatValue(struct OH_AVFormat *format, const char *key, float *out); 246 247 /** 248 * @brief Read Double data from OH_AVFormat 249 * @syscap SystemCapability.Multimedia.Media.Core 250 * @param format pointer to an OH_AVFormat instance 251 * @param key read key value 252 * @param out read data 253 * @return The return value is TRUE for success, FALSE for failure 254 * @since 9 255 * @version 1.0 256 */ 257 bool OH_AVFormat_GetDoubleValue(struct OH_AVFormat *format, const char *key, double *out); 258 259 /** 260 * @brief Read String data from OH_AVFormat 261 * @syscap SystemCapability.Multimedia.Media.Core 262 * @param format pointer to an OH_AVFormat instance 263 * @param key read key value 264 * @param out The read string pointer, the data life cycle pointed to is updated with GetString, 265 * and Format is destroyed. If the caller needs to hold it for a long time, it must copy the memory 266 * @return The return value is TRUE for success, FALSE for failure 267 * @since 9 268 * @version 1.0 269 */ 270 bool OH_AVFormat_GetStringValue(struct OH_AVFormat *format, const char *key, const char **out); 271 272 /** 273 * @brief Read a block of data of specified length from OH_AVFormat 274 * @syscap SystemCapability.Multimedia.Media.Core 275 * @param format pointer to an OH_AVFormat instance 276 * @param key Key value for reading and writing data 277 * @param addr The life cycle is held by the format, with the destruction of the format, 278 * if the caller needs to hold it for a long time, it must copy the memory 279 * @param size Length of read and write data 280 * @return The return value is TRUE for success, FALSE for failure 281 * @since 9 282 * @version 1.0 283 */ 284 bool OH_AVFormat_GetBuffer(struct OH_AVFormat *format, const char *key, uint8_t **addr, size_t *size); 285 286 /** 287 * @brief Output the information contained in OH_AVFormat as a string. 288 * @syscap SystemCapability.Multimedia.Media.Core 289 * @param format pointer to an OH_AVFormat instance 290 * @return Returns a string consisting of key and data 291 * @since 9 292 * @version 1.0 293 */ 294 const char *OH_AVFormat_DumpInfo(struct OH_AVFormat *format); 295 296 #ifdef __cplusplus 297 } 298 #endif 299 300 #endif // NATIVE_AVFORMAT_H 301 /** @} */