1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci/**
17094332d3Sopenharmony_ci * @addtogroup format
18094332d3Sopenharmony_ci * @{
19094332d3Sopenharmony_ci *
20094332d3Sopenharmony_ci * @brief Defines format-related APIs.
21094332d3Sopenharmony_ci *
22094332d3Sopenharmony_ci * For example, you use this module to define custom data types and to initialize, create,
23094332d3Sopenharmony_ci * destroy the muxer and demuxer, and set their parameters. Also, you can read demuxer data frames,
24094332d3Sopenharmony_ci * select demuxer tracks, add muxer tracks, and write data frames into a container.
25094332d3Sopenharmony_ci *
26094332d3Sopenharmony_ci * @since 1.0
27094332d3Sopenharmony_ci * @version 1.0
28094332d3Sopenharmony_ci */
29094332d3Sopenharmony_ci
30094332d3Sopenharmony_ci/**
31094332d3Sopenharmony_ci * @file format_interface.h
32094332d3Sopenharmony_ci *
33094332d3Sopenharmony_ci * @brief Declares format-related APIs.
34094332d3Sopenharmony_ci *
35094332d3Sopenharmony_ci * For example, you use the functions provided in this file to define custom data types and to initialize,
36094332d3Sopenharmony_ci * create, destroy the muxer and demuxer, and set their parameters. Also, you can read demuxer data frames,
37094332d3Sopenharmony_ci * select demuxer tracks, add muxer tracks, and write data frames into a container.
38094332d3Sopenharmony_ci *
39094332d3Sopenharmony_ci * @since 1.0
40094332d3Sopenharmony_ci * @version 1.0
41094332d3Sopenharmony_ci */
42094332d3Sopenharmony_ci
43094332d3Sopenharmony_ci#ifndef FORMAT_INTERFACE_H
44094332d3Sopenharmony_ci#define FORMAT_INTERFACE_H
45094332d3Sopenharmony_ci
46094332d3Sopenharmony_ci#include "format_type.h"
47094332d3Sopenharmony_ci
48094332d3Sopenharmony_ci#ifdef __cplusplus
49094332d3Sopenharmony_ci#if __cplusplus
50094332d3Sopenharmony_ciextern "C" {
51094332d3Sopenharmony_ci#endif
52094332d3Sopenharmony_ci#endif /* __cplusplus */
53094332d3Sopenharmony_ci
54094332d3Sopenharmony_ci/**
55094332d3Sopenharmony_ci * @brief Initializes the format.
56094332d3Sopenharmony_ci *
57094332d3Sopenharmony_ci * You can call this function to initialize the demuxer and muxer.
58094332d3Sopenharmony_ci * This function should always be called before other format-specific functions,
59094332d3Sopenharmony_ci * and it can be called only once within a process.
60094332d3Sopenharmony_ci *
61094332d3Sopenharmony_ci * @since 1.0
62094332d3Sopenharmony_ci * @version 1.0
63094332d3Sopenharmony_ci */
64094332d3Sopenharmony_civoid FormatInit(void);
65094332d3Sopenharmony_ci
66094332d3Sopenharmony_ci/**
67094332d3Sopenharmony_ci * @brief Deinitializes the format.
68094332d3Sopenharmony_ci *
69094332d3Sopenharmony_ci * You can call this function to deinitialize the demuxer and muxer.
70094332d3Sopenharmony_ci * This function works in pair with {@link FormatInit}.
71094332d3Sopenharmony_ci *
72094332d3Sopenharmony_ci * @since 1.0
73094332d3Sopenharmony_ci * @version 1.0
74094332d3Sopenharmony_ci */
75094332d3Sopenharmony_civoid FormatDeInit(void);
76094332d3Sopenharmony_ci
77094332d3Sopenharmony_ci/**
78094332d3Sopenharmony_ci * @brief Creates a demuxer component and returns its context handle.
79094332d3Sopenharmony_ci *
80094332d3Sopenharmony_ci * This function returns the demuxer context handle without probing the container format or
81094332d3Sopenharmony_ci * obtaining stream information.
82094332d3Sopenharmony_ci *
83094332d3Sopenharmony_ci * @param source Indicates the pointer to the format source of the demuxer. For details, see {@link FormatSource}.
84094332d3Sopenharmony_ci * @param handle Indicates the double pointer to the demuxer context handle.
85094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
86094332d3Sopenharmony_ci */
87094332d3Sopenharmony_ciint32_t FormatDemuxerCreate(const FormatSource *source, FormatHandle * const handle);
88094332d3Sopenharmony_ci
89094332d3Sopenharmony_ci/**
90094332d3Sopenharmony_ci * @brief Sets demuxer attributes.
91094332d3Sopenharmony_ci *
92094332d3Sopenharmony_ci * You can call this function to set the HTTP header, HTTP referer, and other extension items for the demuxer
93094332d3Sopenharmony_ci * after {@link FormatDemuxerCreate} is called.
94094332d3Sopenharmony_ci *
95094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
96094332d3Sopenharmony_ci * @param trackId Identifies the track. If the value is an invalid value (<b>-1</b>),
97094332d3Sopenharmony_ci * this parameter identifies the file or program.
98094332d3Sopenharmony_ci * @param metaData Indicates the pointer to an array of key-value pairs representing parameter names and values.
99094332d3Sopenharmony_ci * For details, see {@link ParameterItem}.
100094332d3Sopenharmony_ci * @param metaDataCnt Indicates the number of key-value pairs in the array.
101094332d3Sopenharmony_ci * This parameter works in pair with <b>metaData</b>.
102094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
103094332d3Sopenharmony_ci * @since 1.0
104094332d3Sopenharmony_ci * @version 1.0
105094332d3Sopenharmony_ci */
106094332d3Sopenharmony_ciint32_t FormatDemuxerSetParameter(const FormatHandle handle, int32_t trackId,
107094332d3Sopenharmony_ci    const ParameterItem *metaData, int32_t metaDataCnt);
108094332d3Sopenharmony_ci
109094332d3Sopenharmony_ci/**
110094332d3Sopenharmony_ci * @brief Obtains demuxer attributes.
111094332d3Sopenharmony_ci *
112094332d3Sopenharmony_ci * You can call this function to obtain the HTTP header, HTTP referer, and other extension items for the demuxer
113094332d3Sopenharmony_ci * after {@link FormatDemuxerCreate} is called. The demuxer will store the value in the <b>metaData</b>
114094332d3Sopenharmony_ci * based on the key.If the demuxer has allocated memory for the <b>metaData</b> to store the value,
115094332d3Sopenharmony_ci * the caller should manually free the memory.
116094332d3Sopenharmony_ci *
117094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
118094332d3Sopenharmony_ci * @param trackId Identifies the track. If the value is an invalid value (<b>-1</b>),
119094332d3Sopenharmony_ci * this parameter identifies the file or program.
120094332d3Sopenharmony_ci * @param metaData Indicates the pointer to the buffer for storing the parameters values
121094332d3Sopenharmony_ci * that the demuxer has searched for based on the input key. For details, see {@link ParameterItem}.
122094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
123094332d3Sopenharmony_ci * @since 1.0
124094332d3Sopenharmony_ci * @version 1.0
125094332d3Sopenharmony_ci */
126094332d3Sopenharmony_ciint32_t FormatDemuxerGetParameter(const FormatHandle handle, int32_t trackId, ParameterItem *metaData);
127094332d3Sopenharmony_ci
128094332d3Sopenharmony_ci/**
129094332d3Sopenharmony_ci * @brief Sets a callback for the demuxer.
130094332d3Sopenharmony_ci *
131094332d3Sopenharmony_ci * The callback will be invoked to notify the upper layer of internal events of the demuxer.
132094332d3Sopenharmony_ci *
133094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
134094332d3Sopenharmony_ci * @param callBack Indicates the pointer to the callback, as defined in {@link FormatCallback}.
135094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
136094332d3Sopenharmony_ci * @since 1.0
137094332d3Sopenharmony_ci * @version 1.0
138094332d3Sopenharmony_ci */
139094332d3Sopenharmony_ciint32_t FormatDemuxerSetCallBack(const FormatHandle handle, const FormatCallback *callBack);
140094332d3Sopenharmony_ci
141094332d3Sopenharmony_ci/**
142094332d3Sopenharmony_ci * @brief Sets buffer information for the demuxer.
143094332d3Sopenharmony_ci *
144094332d3Sopenharmony_ci * If there is a buffer mechanism in the demuxer, you can call this function to set the maximum buffer size and time.
145094332d3Sopenharmony_ci * Alternatively, you can disable the buffer mechanism by setting the buffer size and time to <b>0</b> in
146094332d3Sopenharmony_ci * the <b>setting</b> parameter. If there is no buffer mechanism or the default setting is retained,
147094332d3Sopenharmony_ci * you can skip this function.
148094332d3Sopenharmony_ci *
149094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
150094332d3Sopenharmony_ci * @param setting Indicates the pointer to the maximum demuxer buffer size and time,
151094332d3Sopenharmony_ci * as defined in {@link FormatBufferSetting}.
152094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
153094332d3Sopenharmony_ci */
154094332d3Sopenharmony_ciint32_t FormatDemuxerSetBufferConfig(const FormatHandle handle, const FormatBufferSetting *setting);
155094332d3Sopenharmony_ci
156094332d3Sopenharmony_ci/**
157094332d3Sopenharmony_ci * @brief Obtains the buffer information of the demuxer.
158094332d3Sopenharmony_ci *
159094332d3Sopenharmony_ci * If there is a buffer mechanism in the demuxer, you can call this function to obtain the maximum buffer size and time.
160094332d3Sopenharmony_ci *
161094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
162094332d3Sopenharmony_ci * @param setting Indicates the pointer to the maximum demuxer buffer size and time,
163094332d3Sopenharmony_ci * as defined in {@link FormatBufferSetting}.
164094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
165094332d3Sopenharmony_ci * @since 1.0
166094332d3Sopenharmony_ci * @version 1.0
167094332d3Sopenharmony_ci */
168094332d3Sopenharmony_ciint32_t FormatDemuxerGetBufferConfig(const FormatHandle handle, FormatBufferSetting *setting);
169094332d3Sopenharmony_ci
170094332d3Sopenharmony_ci/**
171094332d3Sopenharmony_ci * @brief Makes preparations for the demuxer.
172094332d3Sopenharmony_ci *
173094332d3Sopenharmony_ci * This function triggers the demuxer to probe the media file container format and parse stream information.
174094332d3Sopenharmony_ci * You can obtain media file attributes only after this function is called.
175094332d3Sopenharmony_ci *
176094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
177094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
178094332d3Sopenharmony_ci * @since 1.0
179094332d3Sopenharmony_ci * @version 1.0
180094332d3Sopenharmony_ci */
181094332d3Sopenharmony_ciint32_t FormatDemuxerPrepare(const FormatHandle handle);
182094332d3Sopenharmony_ci
183094332d3Sopenharmony_ci/**
184094332d3Sopenharmony_ci * @brief Obtains the attributes of a media file.
185094332d3Sopenharmony_ci *
186094332d3Sopenharmony_ci * The attributes contain file, program, and stream attributes.
187094332d3Sopenharmony_ci * This function should be called after {@link FormatDemuxerPrepare} is called.
188094332d3Sopenharmony_ci *
189094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
190094332d3Sopenharmony_ci * @param info Indicates the pointer to the source attributes, as defined in {@link FileInfo}.
191094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
192094332d3Sopenharmony_ci * @since 1.0
193094332d3Sopenharmony_ci * @version 1.0
194094332d3Sopenharmony_ci */
195094332d3Sopenharmony_ciint32_t FormatDemuxerGetFileInfo(const FormatHandle handle, FileInfo *info);
196094332d3Sopenharmony_ci
197094332d3Sopenharmony_ci/**
198094332d3Sopenharmony_ci * @brief Selects a specified media track.
199094332d3Sopenharmony_ci *
200094332d3Sopenharmony_ci * The media tracks to select must belong to the same program.
201094332d3Sopenharmony_ci * If you do not call this function, the default media tracks of the default program are selected.
202094332d3Sopenharmony_ci * If <b>programId</b> is valid but <b>trackId</b> is invalid, the default media track of the specified program is used.
203094332d3Sopenharmony_ci *
204094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
205094332d3Sopenharmony_ci * @param programId Identifies the program.
206094332d3Sopenharmony_ci * @param trackId Identifies the media track. If a valid value is passed, the media track must belong to
207094332d3Sopenharmony_ci * the specified program. If an invalid value is passed, the default media track of the specified program is used.
208094332d3Sopenharmony_ci * If multiple audio tracks are specified, the player determines which audio track to use.
209094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
210094332d3Sopenharmony_ci * @since 1.0
211094332d3Sopenharmony_ci * @version 1.0
212094332d3Sopenharmony_ci */
213094332d3Sopenharmony_ciint32_t FormatDemuxerSelectTrack(const FormatHandle handle, int32_t programId, int32_t trackId);
214094332d3Sopenharmony_ci
215094332d3Sopenharmony_ci/**
216094332d3Sopenharmony_ci * @brief Unselects a specified media track from which the demuxer reads data frames.
217094332d3Sopenharmony_ci *
218094332d3Sopenharmony_ci * The demuxer can read all media tracks of the default program. You can call this function to
219094332d3Sopenharmony_ci * unselect all or certain tracks of a specified program that the demuxer is expected not to read.
220094332d3Sopenharmony_ci * If <b>trackId</b> is invalid, the demuxer will read none of the tracks of the specified program.
221094332d3Sopenharmony_ci *
222094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
223094332d3Sopenharmony_ci * @param programId Identifies the program.
224094332d3Sopenharmony_ci * @param trackId Identifies the media track that the demuxer will unselect.
225094332d3Sopenharmony_ci * This parameter works in pair with <b>programId</b>. If a valid value is passed, the media track must belong to
226094332d3Sopenharmony_ci * the program specified by <b>programId</b>. If an invalid value is passed, and all media tracks of the specified
227094332d3Sopenharmony_ci * program are unselected.
228094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
229094332d3Sopenharmony_ci * @since 1.0
230094332d3Sopenharmony_ci * @version 1.0
231094332d3Sopenharmony_ci */
232094332d3Sopenharmony_ciint32_t FormatDemuxerUnselectTrack(const FormatHandle handle, int32_t programId, int32_t trackId);
233094332d3Sopenharmony_ci
234094332d3Sopenharmony_ci/**
235094332d3Sopenharmony_ci * @brief Starts the demuxer.
236094332d3Sopenharmony_ci *
237094332d3Sopenharmony_ci * After being started, the caller can read data frames from the demuxer.
238094332d3Sopenharmony_ci * This function should be called after {@link FormatDemuxerPrepare} is called.
239094332d3Sopenharmony_ci *
240094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
241094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
242094332d3Sopenharmony_ci * @since 1.0
243094332d3Sopenharmony_ci * @version 1.0
244094332d3Sopenharmony_ci */
245094332d3Sopenharmony_ciint32_t FormatDemuxerStart(const FormatHandle handle);
246094332d3Sopenharmony_ci
247094332d3Sopenharmony_ci/**
248094332d3Sopenharmony_ci * @brief Obtains the ID of the media track selected by the demuxer for output.
249094332d3Sopenharmony_ci *
250094332d3Sopenharmony_ci * The demuxer automatically selects the default program and its media tracks.
251094332d3Sopenharmony_ci * However, if the program and media tracks have changed after {@link FormatDemuxerSelectTrack} and
252094332d3Sopenharmony_ci * {@link FormatDemuxerUnselectTrack} are called, you can obtain the currently selected program and media tracks
253094332d3Sopenharmony_ci * by calling this function (<b>FormatDemuxerGetSelectedTrack</b>.
254094332d3Sopenharmony_ci *
255094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
256094332d3Sopenharmony_ci * @param programId Identifies the pointer to the program.
257094332d3Sopenharmony_ci * @param trackId Identifies the array of selected media tracks. This parameter works in pair with <b>nums</b>.
258094332d3Sopenharmony_ci * @param nums Indicates the pointer to the total number of selected media tracks.
259094332d3Sopenharmony_ci * This parameter works in pair with <b>trackId</b>.
260094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
261094332d3Sopenharmony_ci * @since 1.0
262094332d3Sopenharmony_ci * @version 1.0
263094332d3Sopenharmony_ci */
264094332d3Sopenharmony_ciint32_t FormatDemuxerGetSelectedTrack(const FormatHandle handle, int32_t *programId, int32_t trackId[], int32_t *nums);
265094332d3Sopenharmony_ci
266094332d3Sopenharmony_ci/**
267094332d3Sopenharmony_ci * @brief Reads data frames.
268094332d3Sopenharmony_ci *
269094332d3Sopenharmony_ci * After the data frames are read,
270094332d3Sopenharmony_ci * you need to call {@link FormatDemuxerFreeFame} to free them.
271094332d3Sopenharmony_ci *
272094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
273094332d3Sopenharmony_ci * @param frame Indicates the pointer to the data structure {@link FormatFrame}.
274094332d3Sopenharmony_ci * @param timeOutMs Indicates the time required for waiting data frame read.
275094332d3Sopenharmony_ci * The value <b>0</b> indicates that data frames are immediately read without any wait.
276094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
277094332d3Sopenharmony_ci * @since 1.0
278094332d3Sopenharmony_ci * @version 1.0
279094332d3Sopenharmony_ci */
280094332d3Sopenharmony_ciint32_t FormatDemuxerReadFrame(const FormatHandle handle, FormatFrame *frame, int32_t timeOutMs);
281094332d3Sopenharmony_ci
282094332d3Sopenharmony_ci/**
283094332d3Sopenharmony_ci * @brief Frees data frames.
284094332d3Sopenharmony_ci *
285094332d3Sopenharmony_ci * You can call this function to free the data frames obtained by calling {@link FormatDemuxerReadFrame}.
286094332d3Sopenharmony_ci *
287094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
288094332d3Sopenharmony_ci * @param frame Indicates the pointer to the data structure {@link FormatFrame}.
289094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
290094332d3Sopenharmony_ci * @since 1.0
291094332d3Sopenharmony_ci * @version 1.0
292094332d3Sopenharmony_ci */
293094332d3Sopenharmony_ciint32_t FormatDemuxerFreeFrame(const FormatHandle handle, FormatFrame *frame);
294094332d3Sopenharmony_ci
295094332d3Sopenharmony_ci/**
296094332d3Sopenharmony_ci * @brief Seeks for a specified position for the demuxer.
297094332d3Sopenharmony_ci *
298094332d3Sopenharmony_ci * After being started, the demuxer seeks for a specified position to read data frames.
299094332d3Sopenharmony_ci * You can specify the position close to the time specified by <b>streamIndex</b>.
300094332d3Sopenharmony_ci *
301094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
302094332d3Sopenharmony_ci * @param streamIndex Identifies the stream in the media file.
303094332d3Sopenharmony_ci * @param timeStampUs Indicates the target position, in microseconds.
304094332d3Sopenharmony_ci * @param mode Indicates the seek mode, as defined in {@link FormatSeekMode}.
305094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
306094332d3Sopenharmony_ci * @since 1.0
307094332d3Sopenharmony_ci * @version 1.0
308094332d3Sopenharmony_ci */
309094332d3Sopenharmony_ciint32_t FormatDemuxerSeek(const FormatHandle handle, int32_t streamIndex, int64_t timeStampUs, FormatSeekMode mode);
310094332d3Sopenharmony_ci
311094332d3Sopenharmony_ci/**
312094332d3Sopenharmony_ci * @brief Stops the demuxer from working.
313094332d3Sopenharmony_ci *
314094332d3Sopenharmony_ci * After this function is called, the demuxer cannot resume decapsulation.
315094332d3Sopenharmony_ci *
316094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
317094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
318094332d3Sopenharmony_ci * @since 1.0
319094332d3Sopenharmony_ci * @version 1.0
320094332d3Sopenharmony_ci */
321094332d3Sopenharmony_ciint32_t FormatDemuxerStop(const FormatHandle handle);
322094332d3Sopenharmony_ci
323094332d3Sopenharmony_ci/**
324094332d3Sopenharmony_ci * @brief Destroys demuxer resources.
325094332d3Sopenharmony_ci *
326094332d3Sopenharmony_ci * This function works in pair with {@link FormatDemuxerCreate}.
327094332d3Sopenharmony_ci * If you do not call this function, resource leakage may occur.
328094332d3Sopenharmony_ci *
329094332d3Sopenharmony_ci * @param handle Indicates the pointer to the demuxer context handle.
330094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
331094332d3Sopenharmony_ci * @since 1.0
332094332d3Sopenharmony_ci * @version 1.0
333094332d3Sopenharmony_ci */
334094332d3Sopenharmony_ciint32_t FormatDemuxerDestroy(const FormatHandle handle);
335094332d3Sopenharmony_ci
336094332d3Sopenharmony_ci/**
337094332d3Sopenharmony_ci * @brief Creates a muxer and returns its context handle.
338094332d3Sopenharmony_ci *
339094332d3Sopenharmony_ci * @param handle Indicates the double pointer to the muxer context handle.
340094332d3Sopenharmony_ci * @param outputConfig Indicates the pointer to the muxer output configuration,
341094332d3Sopenharmony_ci * as defined in {@link FormatOutputConfig}.
342094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
343094332d3Sopenharmony_ci * @since 1.0
344094332d3Sopenharmony_ci * @version 1.0
345094332d3Sopenharmony_ci */
346094332d3Sopenharmony_ciint32_t FormatMuxerCreate(FormatHandle * const handle, const FormatOutputConfig *outputConfig);
347094332d3Sopenharmony_ci
348094332d3Sopenharmony_ci/**
349094332d3Sopenharmony_ci * @brief Destroys a muxer and releases its resources created by calling {@link FormatMuxerCreate}.
350094332d3Sopenharmony_ci *
351094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
352094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
353094332d3Sopenharmony_ci * @since 1.0
354094332d3Sopenharmony_ci * @version 1.0
355094332d3Sopenharmony_ci */
356094332d3Sopenharmony_ciint32_t FormatMuxerDestroy(const FormatHandle handle);
357094332d3Sopenharmony_ci
358094332d3Sopenharmony_ci/**
359094332d3Sopenharmony_ci * @brief Adds a media track source for the muxer. For details about track sources, see {@link TrackSource}.
360094332d3Sopenharmony_ci *
361094332d3Sopenharmony_ci * This function must be called after {@link FormatMuxerCreate} is successfully called and
362094332d3Sopenharmony_ci * before {@link FormatMuxerStart} is called.
363094332d3Sopenharmony_ci *
364094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
365094332d3Sopenharmony_ci * @param trackSource Indicates the pointer to the track source.
366094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
367094332d3Sopenharmony_ci * @since 1.0
368094332d3Sopenharmony_ci * @version 1.0
369094332d3Sopenharmony_ci */
370094332d3Sopenharmony_ciint32_t FormatMuxerAddTrack(const FormatHandle handle, const TrackSource *trackSource);
371094332d3Sopenharmony_ci
372094332d3Sopenharmony_ci/**
373094332d3Sopenharmony_ci * @brief Sets a callback for the muxer. For details about the callback, see {@link FormatCallback}.
374094332d3Sopenharmony_ci *
375094332d3Sopenharmony_ci * This function should be called after {@link FormatMuxerCreate} is successfully called.
376094332d3Sopenharmony_ci *
377094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
378094332d3Sopenharmony_ci * @param FormatCallback Indicates the pointer to the muxer callback to set.
379094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
380094332d3Sopenharmony_ci * @since 1.0
381094332d3Sopenharmony_ci * @version 1.0
382094332d3Sopenharmony_ci */
383094332d3Sopenharmony_ciint32_t FormatMuxerSetCallBack(const FormatHandle handle, const FormatCallback *callBack);
384094332d3Sopenharmony_ci
385094332d3Sopenharmony_ci/**
386094332d3Sopenharmony_ci * @brief Sets the orientation of the video track for the muxer.
387094332d3Sopenharmony_ci *
388094332d3Sopenharmony_ci * This function should be called after {@link FormatMuxerAddTrack} is successfully called.
389094332d3Sopenharmony_ci * The following degrees are supported: 0, 90, 180, and 270.
390094332d3Sopenharmony_ci *
391094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
392094332d3Sopenharmony_ci * @param degrees Indicates the clockwise angle of the video track.
393094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
394094332d3Sopenharmony_ci * @since 1.0
395094332d3Sopenharmony_ci * @version 1.0
396094332d3Sopenharmony_ci */
397094332d3Sopenharmony_ciint32_t FormatMuxerSetOrientation(const FormatHandle handle, int degrees);
398094332d3Sopenharmony_ci
399094332d3Sopenharmony_ci/**
400094332d3Sopenharmony_ci * @brief Sets the geographical information for the output file of the muxer.
401094332d3Sopenharmony_ci *
402094332d3Sopenharmony_ci * This function should be called after {@link FormatMuxerCreate} is successfully called.
403094332d3Sopenharmony_ci *
404094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
405094332d3Sopenharmony_ci * @param latitude Indicates the latitude, within the range [-90,90].
406094332d3Sopenharmony_ci * @param longitude Indicates the longitude, within the range [-180,180].
407094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
408094332d3Sopenharmony_ci * @since 1.0
409094332d3Sopenharmony_ci * @version 1.0
410094332d3Sopenharmony_ci */
411094332d3Sopenharmony_ciint32_t FormatMuxerSetLocation(const FormatHandle handle, int latitude, int longitude);
412094332d3Sopenharmony_ci
413094332d3Sopenharmony_ci/**
414094332d3Sopenharmony_ci * @brief Sets the maximum size (in bytes) for the output file of the muxer.
415094332d3Sopenharmony_ci *
416094332d3Sopenharmony_ci * This function should be called after {@link FormatMuxerCreate} is successfully called.
417094332d3Sopenharmony_ci *
418094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
419094332d3Sopenharmony_ci * @param bytes Indicates the maximum size of a file, in bytes. If the value is <b>0</b> or negative,
420094332d3Sopenharmony_ci * the operation fails and the maximum size does not take effect. In this case, the maximum size of a single file
421094332d3Sopenharmony_ci * supported by the current file system is used as the value of this parameter.
422094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
423094332d3Sopenharmony_ci * @since 1.0
424094332d3Sopenharmony_ci * @version 1.0
425094332d3Sopenharmony_ci */
426094332d3Sopenharmony_ciint32_t FormatMuxerSetMaxFileSize(const FormatHandle handle, int64_t bytes);
427094332d3Sopenharmony_ci
428094332d3Sopenharmony_ci/**
429094332d3Sopenharmony_ci * @brief Sets the maximum duration (in seconds) for the output file.
430094332d3Sopenharmony_ci *
431094332d3Sopenharmony_ci * You need to call this function before calling {@link FormatMuxerStart}. If the maximum duration you set is valid
432094332d3Sopenharmony_ci * and capturing is approaching 90% of that duration or the remaining duration is 1s, the message
433094332d3Sopenharmony_ci * {@link MUXER_INFO_MAX_DURATION_APPROACHING} is reported via {@link OnInfo} of {@link FormatCallback}. If the output
434094332d3Sopenharmony_ci * file has been set by calling {@link FormatMuxerCreate}, you need to call {@link FormatMuxerSetNextOutputFile}
435094332d3Sopenharmony_ci * to set the next output file. Otherwise, the current output file will be overwritten when the capturing reaches
436094332d3Sopenharmony_ci * the maximum duration you set.
437094332d3Sopenharmony_ci *
438094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
439094332d3Sopenharmony_ci * @param duration Indicates the maximum duration to set, in seconds. If the value is <b>0</b> or negative,
440094332d3Sopenharmony_ci * the operation fails. In this case, the default duration (60 seconds) will be used.
441094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
442094332d3Sopenharmony_ci * @since 1.0
443094332d3Sopenharmony_ci * @version 1.0
444094332d3Sopenharmony_ci */
445094332d3Sopenharmony_ciint32_t FormatMuxerSetMaxFileDuration(const FormatHandle handle, int64_t durationUs);
446094332d3Sopenharmony_ci
447094332d3Sopenharmony_ci/**
448094332d3Sopenharmony_ci * @brief Manually splits a file.
449094332d3Sopenharmony_ci *
450094332d3Sopenharmony_ci * This function can be called after {@link FormatMuxerStart} is called. Once this function is called,
451094332d3Sopenharmony_ci * the file is split based on the manual split type. After manual split is complete, file split will proceed to
452094332d3Sopenharmony_ci * use the initially set split type. You can call this function again only after
453094332d3Sopenharmony_ci * the {@link MUXER_INFO_FILE_SPLIT_FINISHED} event is reported.
454094332d3Sopenharmony_ci *
455094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
456094332d3Sopenharmony_ci * @param type Indicates the file split type, as defined in {@link FileSplitType}.
457094332d3Sopenharmony_ci * @param timestamp Indicates the file split timestamp. This parameter is not supported currently.
458094332d3Sopenharmony_ci * The value <b>¨C1</b> indicates that the file is split at the time this function is called.
459094332d3Sopenharmony_ci * @param duration Indicates the period from the file split time to the time the next output file starts.
460094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
461094332d3Sopenharmony_ci * @since 1.0
462094332d3Sopenharmony_ci * @version 1.0
463094332d3Sopenharmony_ci */
464094332d3Sopenharmony_ciint32_t FormatMuxerSetFileSplitDuration(const FormatHandle handle, ManualSplitType type,
465094332d3Sopenharmony_ci                                        int64_t timestampUs, uint32_t durationUs);
466094332d3Sopenharmony_ci
467094332d3Sopenharmony_ci/**
468094332d3Sopenharmony_ci * @brief Starts the muxer.
469094332d3Sopenharmony_ci *
470094332d3Sopenharmony_ci * You can call this function to encapsulate media data after the muxer is created, media tracks are added,
471094332d3Sopenharmony_ci * and related parameters are set.
472094332d3Sopenharmony_ci *
473094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
474094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
475094332d3Sopenharmony_ci * @since 1.0
476094332d3Sopenharmony_ci * @version 1.0
477094332d3Sopenharmony_ci */
478094332d3Sopenharmony_ciint32_t FormatMuxerStart(FormatHandle handle);
479094332d3Sopenharmony_ci
480094332d3Sopenharmony_ci/**
481094332d3Sopenharmony_ci * @brief Writes data frames into the muxer.
482094332d3Sopenharmony_ci *
483094332d3Sopenharmony_ci * This function should be called after {@link FormatMuxerCreate} is successfully called.
484094332d3Sopenharmony_ci *
485094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
486094332d3Sopenharmony_ci * @param frameData Indicates the pointer to the data structure {@link FormatFrame}.
487094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
488094332d3Sopenharmony_ci * @since 1.0
489094332d3Sopenharmony_ci * @version 1.0
490094332d3Sopenharmony_ci */
491094332d3Sopenharmony_ciint32_t FormatMuxerWriteFrame(const FormatHandle handle, const FormatFrame *frameData);
492094332d3Sopenharmony_ci
493094332d3Sopenharmony_ci/**
494094332d3Sopenharmony_ci * @brief Sets the descriptor for the next output file.
495094332d3Sopenharmony_ci *
496094332d3Sopenharmony_ci * If {@link FormatMuxerCreate} is successfully called and the file descriptor involved is valid, you can call
497094332d3Sopenharmony_ci * this function (<b>FormatMuxerSetNextOutputFile</b>) upon receiving the message
498094332d3Sopenharmony_ci * {@link MUXER_INFO_MAX_FILESIZE_APPROACHING} or {@link MUXER_INFO_MAX_DURATION_APPROACHING}.
499094332d3Sopenharmony_ci *
500094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
501094332d3Sopenharmony_ci * @param fd Indicates the file descriptor to set.
502094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
503094332d3Sopenharmony_ci * @since 1.0
504094332d3Sopenharmony_ci * @version 1.0
505094332d3Sopenharmony_ci */
506094332d3Sopenharmony_ciint32_t FormatMuxerSetNextOutputFile(const FormatHandle handle, int32_t fd);
507094332d3Sopenharmony_ci
508094332d3Sopenharmony_ci/**
509094332d3Sopenharmony_ci * @brief Stops the muxer that was started by calling {@link FormatMuxerStart}.
510094332d3Sopenharmony_ci *
511094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
512094332d3Sopenharmony_ci * @param block Indicates how to stop the muxer. The value <b>true</b> indicates that the muxer is stopped
513094332d3Sopenharmony_ci * after all buffered data is processed, and <b>false</b> indicates that the buffered data is discarded and
514094332d3Sopenharmony_ci * the muxer is immediately stopped.
515094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
516094332d3Sopenharmony_ci * @since 1.0
517094332d3Sopenharmony_ci * @version 1.0
518094332d3Sopenharmony_ci */
519094332d3Sopenharmony_ciint32_t FormatMuxerStop(const FormatHandle handle, bool block);
520094332d3Sopenharmony_ci
521094332d3Sopenharmony_ci/**
522094332d3Sopenharmony_ci * @brief Sets muxer attributes.
523094332d3Sopenharmony_ci *
524094332d3Sopenharmony_ci * This is an extended function that can be used to add MP4-dedicated boxes and tags (such as <b>exif</b>).
525094332d3Sopenharmony_ci *
526094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
527094332d3Sopenharmony_ci * @param trackId Identifies the media track. If the value is {@link FORMAT_INVALID_TRACK_ID},
528094332d3Sopenharmony_ci * this function sets the muxer attributes.
529094332d3Sopenharmony_ci * @param item Indicates the pointer to the items carrying muxer attributes. You can specify multiple items at a time
530094332d3Sopenharmony_ci * in this parameter, which works in pair with <b>itemNum</b>.
531094332d3Sopenharmony_ci * @param itemNum Indicates the number of attributes set at a time.
532094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
533094332d3Sopenharmony_ci * @since 1.0
534094332d3Sopenharmony_ci * @version 1.0
535094332d3Sopenharmony_ci */
536094332d3Sopenharmony_ciint32_t FormatMuxerSetParameter(const FormatHandle handle, int32_t trackId, const ParameterItem *item,
537094332d3Sopenharmony_ci    int32_t itemNum);
538094332d3Sopenharmony_ci
539094332d3Sopenharmony_ci/**
540094332d3Sopenharmony_ci * @brief Obtains muxer attributes.
541094332d3Sopenharmony_ci *
542094332d3Sopenharmony_ci * This is an extended function that can be used to obtain muxer or track attributes.
543094332d3Sopenharmony_ci * The demuxer then obtains the muxer attributes based on the key contained in <b>item</b>.
544094332d3Sopenharmony_ci *
545094332d3Sopenharmony_ci * @param handle Indicates the pointer to the muxer context handle.
546094332d3Sopenharmony_ci * @param trackId Identifies the media track. If the value is {@link FORMAT_INVALID_TRACK_ID},
547094332d3Sopenharmony_ci * this function obtains the muxer attributes.
548094332d3Sopenharmony_ci * @param item Indicates the pointer to the items carrying muxer attributes. You can specify multiple items at a time
549094332d3Sopenharmony_ci * in this parameter, which works in pair with <b>itemNum</b>.
550094332d3Sopenharmony_ci * @param itemNum Indicates the number of attributes set at a time.
551094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value if any requested attribute
552094332d3Sopenharmony_ci * fails to be obtained or is not found.
553094332d3Sopenharmony_ci * @since 1.0
554094332d3Sopenharmony_ci * @version 1.0
555094332d3Sopenharmony_ci */
556094332d3Sopenharmony_ciint32_t FormatMuxerGetParameter(const FormatHandle handle, int32_t trackId, ParameterItem *item, int32_t itemNum);
557094332d3Sopenharmony_ci
558094332d3Sopenharmony_ci#ifdef __cplusplus
559094332d3Sopenharmony_ci#if __cplusplus
560094332d3Sopenharmony_ci}
561094332d3Sopenharmony_ci#endif
562094332d3Sopenharmony_ci#endif /* __cplusplus */
563094332d3Sopenharmony_ci
564094332d3Sopenharmony_ci#endif  // FORMAT_INTERFACE_H
565094332d3Sopenharmony_ci/** @} */