17777dab0Sopenharmony_ci/*
27777dab0Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License.
57777dab0Sopenharmony_ci * You may obtain a copy of the License at
67777dab0Sopenharmony_ci *
77777dab0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87777dab0Sopenharmony_ci *
97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and
137777dab0Sopenharmony_ci * limitations under the License.
147777dab0Sopenharmony_ci */
157777dab0Sopenharmony_ci
167777dab0Sopenharmony_ci/**
177777dab0Sopenharmony_ci * @file native_avformat.h
187777dab0Sopenharmony_ci *
197777dab0Sopenharmony_ci * @brief Provides audio and video format.
207777dab0Sopenharmony_ci *
217777dab0Sopenharmony_ci * @kit AVCodecKit
227777dab0Sopenharmony_ci * @library libnative_media_core.so
237777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
247777dab0Sopenharmony_ci * @since 9
257777dab0Sopenharmony_ci */
267777dab0Sopenharmony_ci
277777dab0Sopenharmony_ci#ifndef NATIVE_AVFORMAT_H
287777dab0Sopenharmony_ci#define NATIVE_AVFORMAT_H
297777dab0Sopenharmony_ci
307777dab0Sopenharmony_ci#include <stdint.h>
317777dab0Sopenharmony_ci#include <stdbool.h>
327777dab0Sopenharmony_ci#include <stdio.h>
337777dab0Sopenharmony_ci
347777dab0Sopenharmony_ci#ifdef __cplusplus
357777dab0Sopenharmony_ciextern "C" {
367777dab0Sopenharmony_ci#endif
377777dab0Sopenharmony_ci
387777dab0Sopenharmony_ci/**
397777dab0Sopenharmony_ci * @brief Forward declaration of OH_AVFormat.
407777dab0Sopenharmony_ci *
417777dab0Sopenharmony_ci * @since 9
427777dab0Sopenharmony_ci */
437777dab0Sopenharmony_citypedef struct OH_AVFormat OH_AVFormat;
447777dab0Sopenharmony_ci
457777dab0Sopenharmony_ci/**
467777dab0Sopenharmony_ci * @brief Enumerates AVPixel Format.
477777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
487777dab0Sopenharmony_ci * @since 9
497777dab0Sopenharmony_ci * @version 1.0
507777dab0Sopenharmony_ci */
517777dab0Sopenharmony_citypedef enum OH_AVPixelFormat {
527777dab0Sopenharmony_ci    /**
537777dab0Sopenharmony_ci     * yuv 420 planar.
547777dab0Sopenharmony_ci     */
557777dab0Sopenharmony_ci    AV_PIXEL_FORMAT_YUVI420 = 1,
567777dab0Sopenharmony_ci    /**
577777dab0Sopenharmony_ci     *  NV12. yuv 420 semiplanar.
587777dab0Sopenharmony_ci     */
597777dab0Sopenharmony_ci    AV_PIXEL_FORMAT_NV12 = 2,
607777dab0Sopenharmony_ci    /**
617777dab0Sopenharmony_ci     *  NV21. yvu 420 semiplanar.
627777dab0Sopenharmony_ci     */
637777dab0Sopenharmony_ci    AV_PIXEL_FORMAT_NV21 = 3,
647777dab0Sopenharmony_ci    /**
657777dab0Sopenharmony_ci     * format from surface.
667777dab0Sopenharmony_ci     */
677777dab0Sopenharmony_ci    AV_PIXEL_FORMAT_SURFACE_FORMAT = 4,
687777dab0Sopenharmony_ci    /**
697777dab0Sopenharmony_ci     * RGBA8888
707777dab0Sopenharmony_ci     */
717777dab0Sopenharmony_ci    AV_PIXEL_FORMAT_RGBA = 5,
727777dab0Sopenharmony_ci} OH_AVPixelFormat;
737777dab0Sopenharmony_ci
747777dab0Sopenharmony_ci/**
757777dab0Sopenharmony_ci * @briefCreate an OH_AVFormat handle pointer to read and write data
767777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
777777dab0Sopenharmony_ci * @return Returns a pointer to an OH_AVFormat instance
787777dab0Sopenharmony_ci * @since 9
797777dab0Sopenharmony_ci * @version 1.0
807777dab0Sopenharmony_ci */
817777dab0Sopenharmony_cistruct OH_AVFormat *OH_AVFormat_Create(void);
827777dab0Sopenharmony_ci
837777dab0Sopenharmony_ci/**
847777dab0Sopenharmony_ci * @briefCreate an audio OH_AVFormat handle pointer to read and write data
857777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
867777dab0Sopenharmony_ci * @param mimeType mime type
877777dab0Sopenharmony_ci * @param sampleRate sample rate
887777dab0Sopenharmony_ci * @param channelCount channel count
897777dab0Sopenharmony_ci * @return Returns a pointer to an OH_AVFormat instance if the execution is successful, otherwise nullptr
907777dab0Sopenharmony_ci * Possible failure causes: 1. mimeType is nullptr. 2. new format is nullptr.
917777dab0Sopenharmony_ci * @since 10
927777dab0Sopenharmony_ci * @version 1.0
937777dab0Sopenharmony_ci */
947777dab0Sopenharmony_cistruct OH_AVFormat *OH_AVFormat_CreateAudioFormat(const char *mimeType,
957777dab0Sopenharmony_ci                                                  int32_t sampleRate,
967777dab0Sopenharmony_ci                                                  int32_t channelCount);
977777dab0Sopenharmony_ci
987777dab0Sopenharmony_ci/**
997777dab0Sopenharmony_ci * @briefCreate an video OH_AVFormat handle pointer to read and write data
1007777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1017777dab0Sopenharmony_ci * @param mimeType mime type
1027777dab0Sopenharmony_ci * @param width width
1037777dab0Sopenharmony_ci * @param height height
1047777dab0Sopenharmony_ci * @return Returns a pointer to an OH_AVFormat instance if the execution is successful, otherwise nullptr
1057777dab0Sopenharmony_ci * Possible failure causes: 1. mimeType is nullptr. 2. new format is nullptr.
1067777dab0Sopenharmony_ci * @since 10
1077777dab0Sopenharmony_ci * @version 1.0
1087777dab0Sopenharmony_ci */
1097777dab0Sopenharmony_cistruct OH_AVFormat *OH_AVFormat_CreateVideoFormat(const char *mimeType,
1107777dab0Sopenharmony_ci                                                  int32_t width,
1117777dab0Sopenharmony_ci                                                  int32_t height);
1127777dab0Sopenharmony_ci
1137777dab0Sopenharmony_ci/**
1147777dab0Sopenharmony_ci * @brief Destroy the specified OH_AVFormat handle resource
1157777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1167777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
1177777dab0Sopenharmony_ci * @return void
1187777dab0Sopenharmony_ci * @since 9
1197777dab0Sopenharmony_ci * @version 1.0
1207777dab0Sopenharmony_ci */
1217777dab0Sopenharmony_civoid OH_AVFormat_Destroy(struct OH_AVFormat *format);
1227777dab0Sopenharmony_ci
1237777dab0Sopenharmony_ci/**
1247777dab0Sopenharmony_ci * @brief Copy OH_AVFormat handle resource
1257777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1267777dab0Sopenharmony_ci * @param to OH_AVFormat handle pointer to receive data
1277777dab0Sopenharmony_ci * @param from pointer to the OH_AVFormat handle of the copied data
1287777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
1297777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error.
1307777dab0Sopenharmony_ci * @since 9
1317777dab0Sopenharmony_ci * @version 1.0
1327777dab0Sopenharmony_ci */
1337777dab0Sopenharmony_cibool OH_AVFormat_Copy(struct OH_AVFormat *to, struct OH_AVFormat *from);
1347777dab0Sopenharmony_ci
1357777dab0Sopenharmony_ci/**
1367777dab0Sopenharmony_ci * @brief Write Int data to OH_AVFormat
1377777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1387777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
1397777dab0Sopenharmony_ci * @param key key to write data
1407777dab0Sopenharmony_ci * @param value written data
1417777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
1427777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
1437777dab0Sopenharmony_ci * @since 9
1447777dab0Sopenharmony_ci * @version 1.0
1457777dab0Sopenharmony_ci */
1467777dab0Sopenharmony_cibool OH_AVFormat_SetIntValue(struct OH_AVFormat *format, const char *key, int32_t value);
1477777dab0Sopenharmony_ci
1487777dab0Sopenharmony_ci/**
1497777dab0Sopenharmony_ci * @brief Write Long data to OH_AVFormat
1507777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1517777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
1527777dab0Sopenharmony_ci * @param key key to write data
1537777dab0Sopenharmony_ci * @param value written data
1547777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
1557777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
1567777dab0Sopenharmony_ci * @since 9
1577777dab0Sopenharmony_ci * @version 1.0
1587777dab0Sopenharmony_ci */
1597777dab0Sopenharmony_cibool OH_AVFormat_SetLongValue(struct OH_AVFormat *format, const char *key, int64_t value);
1607777dab0Sopenharmony_ci
1617777dab0Sopenharmony_ci/**
1627777dab0Sopenharmony_ci * @brief Write Float data to OH_AVFormat
1637777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1647777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
1657777dab0Sopenharmony_ci * @param key key to write data
1667777dab0Sopenharmony_ci * @param value written data
1677777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
1687777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
1697777dab0Sopenharmony_ci * @since 9
1707777dab0Sopenharmony_ci * @version 1.0
1717777dab0Sopenharmony_ci */
1727777dab0Sopenharmony_cibool OH_AVFormat_SetFloatValue(struct OH_AVFormat *format, const char *key, float value);
1737777dab0Sopenharmony_ci
1747777dab0Sopenharmony_ci/**
1757777dab0Sopenharmony_ci * @brief Write Double data to OH_AVFormat
1767777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1777777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
1787777dab0Sopenharmony_ci * @param key key to write data
1797777dab0Sopenharmony_ci * @param value written data
1807777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
1817777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
1827777dab0Sopenharmony_ci * @since 9
1837777dab0Sopenharmony_ci * @version 1.0
1847777dab0Sopenharmony_ci */
1857777dab0Sopenharmony_cibool OH_AVFormat_SetDoubleValue(struct OH_AVFormat *format, const char *key, double value);
1867777dab0Sopenharmony_ci
1877777dab0Sopenharmony_ci/**
1887777dab0Sopenharmony_ci * @brief Write String data to OH_AVFormat
1897777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
1907777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
1917777dab0Sopenharmony_ci * @param key key to write data
1927777dab0Sopenharmony_ci * @param value written data
1937777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
1947777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
1957777dab0Sopenharmony_ci * 4. value is nullptr.
1967777dab0Sopenharmony_ci * @since 9
1977777dab0Sopenharmony_ci * @version 1.0
1987777dab0Sopenharmony_ci */
1997777dab0Sopenharmony_cibool OH_AVFormat_SetStringValue(struct OH_AVFormat *format, const char *key, const char *value);
2007777dab0Sopenharmony_ci
2017777dab0Sopenharmony_ci/**
2027777dab0Sopenharmony_ci * @brief Write a block of data of a specified length to OH_AVFormat
2037777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
2047777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
2057777dab0Sopenharmony_ci * @param key key to write data
2067777dab0Sopenharmony_ci * @param addr written data addr
2077777dab0Sopenharmony_ci * @param size written data length
2087777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
2097777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
2107777dab0Sopenharmony_ci * 4. addr is nullptr. 5. size is zero.
2117777dab0Sopenharmony_ci * @since 9
2127777dab0Sopenharmony_ci * @version 1.0
2137777dab0Sopenharmony_ci */
2147777dab0Sopenharmony_cibool OH_AVFormat_SetBuffer(struct OH_AVFormat *format, const char *key, const uint8_t *addr, size_t size);
2157777dab0Sopenharmony_ci
2167777dab0Sopenharmony_ci/**
2177777dab0Sopenharmony_ci * @brief Read Int data from OH_AVFormat
2187777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
2197777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
2207777dab0Sopenharmony_ci * @param key read key value
2217777dab0Sopenharmony_ci * @param out read data
2227777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
2237777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
2247777dab0Sopenharmony_ci * 4. out is nullptr.
2257777dab0Sopenharmony_ci * @since 9
2267777dab0Sopenharmony_ci * @version 1.0
2277777dab0Sopenharmony_ci */
2287777dab0Sopenharmony_cibool OH_AVFormat_GetIntValue(struct OH_AVFormat *format, const char *key, int32_t *out);
2297777dab0Sopenharmony_ci
2307777dab0Sopenharmony_ci/**
2317777dab0Sopenharmony_ci * @brief Read Long data from OH_AVFormat
2327777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
2337777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
2347777dab0Sopenharmony_ci * @param key read key value
2357777dab0Sopenharmony_ci * @param out read data
2367777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
2377777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
2387777dab0Sopenharmony_ci * 4. out is nullptr.
2397777dab0Sopenharmony_ci * @since 9
2407777dab0Sopenharmony_ci * @version 1.0
2417777dab0Sopenharmony_ci */
2427777dab0Sopenharmony_cibool OH_AVFormat_GetLongValue(struct OH_AVFormat *format, const char *key, int64_t *out);
2437777dab0Sopenharmony_ci
2447777dab0Sopenharmony_ci/**
2457777dab0Sopenharmony_ci * @brief Read Float data from OH_AVFormat
2467777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
2477777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
2487777dab0Sopenharmony_ci * @param key read key value
2497777dab0Sopenharmony_ci * @param out read data
2507777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
2517777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
2527777dab0Sopenharmony_ci * 4. out is nullptr.
2537777dab0Sopenharmony_ci * @since 9
2547777dab0Sopenharmony_ci * @version 1.0
2557777dab0Sopenharmony_ci */
2567777dab0Sopenharmony_cibool OH_AVFormat_GetFloatValue(struct OH_AVFormat *format, const char *key, float *out);
2577777dab0Sopenharmony_ci
2587777dab0Sopenharmony_ci/**
2597777dab0Sopenharmony_ci * @brief Read Double data from OH_AVFormat
2607777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
2617777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
2627777dab0Sopenharmony_ci * @param key read key value
2637777dab0Sopenharmony_ci * @param out read data
2647777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
2657777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
2667777dab0Sopenharmony_ci * 4. out is nullptr.
2677777dab0Sopenharmony_ci * @since 9
2687777dab0Sopenharmony_ci * @version 1.0
2697777dab0Sopenharmony_ci */
2707777dab0Sopenharmony_cibool OH_AVFormat_GetDoubleValue(struct OH_AVFormat *format, const char *key, double *out);
2717777dab0Sopenharmony_ci
2727777dab0Sopenharmony_ci/**
2737777dab0Sopenharmony_ci * @brief Read String data from OH_AVFormat
2747777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
2757777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
2767777dab0Sopenharmony_ci * @param key read key value
2777777dab0Sopenharmony_ci * @param out The read string pointer, the data life cycle pointed to is updated with GetString,
2787777dab0Sopenharmony_ci * and Format is destroyed. If the caller needs to hold it for a long time, it must copy the memory
2797777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
2807777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
2817777dab0Sopenharmony_ci * 4. out is nullptr. 5. malloc out string nullptr.
2827777dab0Sopenharmony_ci * @since 9
2837777dab0Sopenharmony_ci * @version 1.0
2847777dab0Sopenharmony_ci */
2857777dab0Sopenharmony_cibool OH_AVFormat_GetStringValue(struct OH_AVFormat *format, const char *key, const char **out);
2867777dab0Sopenharmony_ci
2877777dab0Sopenharmony_ci/**
2887777dab0Sopenharmony_ci * @brief Read a block of data of specified length from OH_AVFormat
2897777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
2907777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
2917777dab0Sopenharmony_ci * @param key Key value for reading and writing data
2927777dab0Sopenharmony_ci * @param addr The life cycle is held by the format, with the destruction of the format,
2937777dab0Sopenharmony_ci * if the caller needs to hold it for a long time, it must copy the memory
2947777dab0Sopenharmony_ci * @param size Length of read and write data
2957777dab0Sopenharmony_ci * @return The return value is TRUE for success, FALSE for failure
2967777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. input format's magic error. 3. key is nullptr.
2977777dab0Sopenharmony_ci * 4. addr is nullptr. 5. size is nullptr.
2987777dab0Sopenharmony_ci * @since 9
2997777dab0Sopenharmony_ci * @version 1.0
3007777dab0Sopenharmony_ci */
3017777dab0Sopenharmony_cibool OH_AVFormat_GetBuffer(struct OH_AVFormat *format, const char *key, uint8_t **addr, size_t *size);
3027777dab0Sopenharmony_ci
3037777dab0Sopenharmony_ci/**
3047777dab0Sopenharmony_ci * @brief Output the information contained in OH_AVFormat as a string.
3057777dab0Sopenharmony_ci * @syscap SystemCapability.Multimedia.Media.Core
3067777dab0Sopenharmony_ci * @param format pointer to an OH_AVFormat instance
3077777dab0Sopenharmony_ci * @return Returns a string consisting of key and data for success, nullptr for failure
3087777dab0Sopenharmony_ci * Possible failure causes: 1. input format is nullptr. 2. malloc dump info nullptr.
3097777dab0Sopenharmony_ci * @since 9
3107777dab0Sopenharmony_ci * @version 1.0
3117777dab0Sopenharmony_ci */
3127777dab0Sopenharmony_ciconst char *OH_AVFormat_DumpInfo(struct OH_AVFormat *format);
3137777dab0Sopenharmony_ci
3147777dab0Sopenharmony_ci#ifdef __cplusplus
3157777dab0Sopenharmony_ci}
3167777dab0Sopenharmony_ci#endif
3177777dab0Sopenharmony_ci
3187777dab0Sopenharmony_ci#endif // NATIVE_AVFORMAT_H