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