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 Codec
18094332d3Sopenharmony_ci * @{
19094332d3Sopenharmony_ci *
20094332d3Sopenharmony_ci * @brief Defines codec-related APIs
21094332d3Sopenharmony_ci *
22094332d3Sopenharmony_ci * including custom data types and functions for initializing audio and video codecs,
23094332d3Sopenharmony_ci * setting parameters, and controlling and transferring data.
24094332d3Sopenharmony_ci *
25094332d3Sopenharmony_ci * @since 1.0
26094332d3Sopenharmony_ci * @version 1.0
27094332d3Sopenharmony_ci */
28094332d3Sopenharmony_ci
29094332d3Sopenharmony_ci/**
30094332d3Sopenharmony_ci * @file codec_interface.h
31094332d3Sopenharmony_ci *
32094332d3Sopenharmony_ci * @brief Declares codec-related APIs, including functions for initializing audio and video codecs,
33094332d3Sopenharmony_ci * setting parameters, and controlling and transferring data.
34094332d3Sopenharmony_ci *
35094332d3Sopenharmony_ci * @since 1.0
36094332d3Sopenharmony_ci * @version 1.0
37094332d3Sopenharmony_ci */
38094332d3Sopenharmony_ci
39094332d3Sopenharmony_ci#ifndef CODEC_INTERFACE_H
40094332d3Sopenharmony_ci#define CODEC_INTERFACE_H
41094332d3Sopenharmony_ci
42094332d3Sopenharmony_ci#include "codec_type.h"
43094332d3Sopenharmony_ci
44094332d3Sopenharmony_ci#ifdef __cplusplus
45094332d3Sopenharmony_ci#if __cplusplus
46094332d3Sopenharmony_ciextern "C" {
47094332d3Sopenharmony_ci#endif
48094332d3Sopenharmony_ci#endif /* __cplusplus */
49094332d3Sopenharmony_ci
50094332d3Sopenharmony_ci/**
51094332d3Sopenharmony_ci * @brief Initializes the internal audio and video submodules of the codec.
52094332d3Sopenharmony_ci *
53094332d3Sopenharmony_ci * This function needs to be called only once in a process.
54094332d3Sopenharmony_ci *
55094332d3Sopenharmony_ci * @return Returns <b>0</b> if the initialization is successful; returns a non-zero value otherwise.
56094332d3Sopenharmony_ci * @see CodecDeinit
57094332d3Sopenharmony_ci */
58094332d3Sopenharmony_ciint32_t CodecInit();
59094332d3Sopenharmony_ci
60094332d3Sopenharmony_ci/**
61094332d3Sopenharmony_ci * @brief Deinitializes the internal audio and video submodules of the codec.
62094332d3Sopenharmony_ci *
63094332d3Sopenharmony_ci * This function needs to be called only once in a process.
64094332d3Sopenharmony_ci *
65094332d3Sopenharmony_ci * @return Returns <b>0</b> if the deinitialization is successful; returns a non-zero value otherwise.
66094332d3Sopenharmony_ci * @see CodecInit
67094332d3Sopenharmony_ci */
68094332d3Sopenharmony_ciint32_t CodecDeinit();
69094332d3Sopenharmony_ci
70094332d3Sopenharmony_ci/**
71094332d3Sopenharmony_ci * @brief Obtains the capabilities of a specified media type based on an index.
72094332d3Sopenharmony_ci *
73094332d3Sopenharmony_ci * You can call this function repeatedly to obtain the codec capabilities until <b>CODEC_END</b> is returned.
74094332d3Sopenharmony_ci * The corresponding capabilities are described in the {@link Capability} structure,
75094332d3Sopenharmony_ci * including the maximum and minimum resolutions, maximum and minimum bit rates, and supported profiles and levels.
76094332d3Sopenharmony_ci * After obtaining the capabilities, determine whether they can meet your requirements, for example,
77094332d3Sopenharmony_ci * whether specific media files can be played and whether audio and video frames can be compressed.
78094332d3Sopenharmony_ci *
79094332d3Sopenharmony_ci * @param index Indicates the index of the capabilities.
80094332d3Sopenharmony_ci * @param cap Indicates the pointer to the capabilities.
81094332d3Sopenharmony_ci * @return Returns <b>0</b> if the capabilities corresponding to the index are available;
82094332d3Sopenharmony_ci * returns <b>-1</b> otherwise.
83094332d3Sopenharmony_ci */
84094332d3Sopenharmony_ciint32_t CodecEnumerateCapability(uint32_t index, CodecCapability *cap);
85094332d3Sopenharmony_ci
86094332d3Sopenharmony_ci/**
87094332d3Sopenharmony_ci * @brief Obtains the capabilities of a specified media type.
88094332d3Sopenharmony_ci *
89094332d3Sopenharmony_ci * You can call this function to obtain the codec capabilities.
90094332d3Sopenharmony_ci * The corresponding capabilities are described in the {@link Capability} structure,
91094332d3Sopenharmony_ci * including the maximum and minimum resolutions, maximum and minimum bit rates, and supported profiles and levels.
92094332d3Sopenharmony_ci * After obtaining the capabilities, determine whether they can meet your requirements, for example,
93094332d3Sopenharmony_ci * whether specific media files can be played and whether audio and video frames can be compressed.
94094332d3Sopenharmony_ci *
95094332d3Sopenharmony_ci * @param mime Indicates the media type. For details, see {@link AvCodecMime}.
96094332d3Sopenharmony_ci * @param type Indicates the audio and video codec types. For details, see {@link CodecType}.
97094332d3Sopenharmony_ci * @param flags Indicates the audio and video codec flags. <b>0</b> indicates hardware codec,
98094332d3Sopenharmony_ci * and <b>1</b> indicates software codec.
99094332d3Sopenharmony_ci * @param cap Indicates the pointer to the capabilities.
100094332d3Sopenharmony_ci * @return Returns <b>0</b> if the codec is supported and capabilities are available;
101094332d3Sopenharmony_ci * returns a non-zero value if the codec is not supported or the capabilities are unavailable.
102094332d3Sopenharmony_ci */
103094332d3Sopenharmony_ciint32_t CodecGetCapability(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapability *cap);
104094332d3Sopenharmony_ci
105094332d3Sopenharmony_ci/**
106094332d3Sopenharmony_ci * @brief Creates a specific codec component by name and returns the component context through a handle.
107094332d3Sopenharmony_ci *
108094332d3Sopenharmony_ci * You can adjust the parameters required for creating a component based on service requirements.
109094332d3Sopenharmony_ci *
110094332d3Sopenharmony_ci * @param name Indicates the pointer to the unique name of the component, for example,
111094332d3Sopenharmony_ci * <b>codec.avc.hardware.decoder</b>.
112094332d3Sopenharmony_ci * @param handle Indicates the pointer to the codec handle returned.
113094332d3Sopenharmony_ci * @return Returns <b>0</b> if the codec component is created and the handle is available;
114094332d3Sopenharmony_ci * returns a non-zero value otherwise.
115094332d3Sopenharmony_ci */
116094332d3Sopenharmony_ciint32_t CodecCreate(const char* name, CODEC_HANDLETYPE *handle);
117094332d3Sopenharmony_ci
118094332d3Sopenharmony_ci/**
119094332d3Sopenharmony_ci * @brief Creates a specific codec component by codec type and codec format,
120094332d3Sopenharmony_ci * returns the component context through a handle.
121094332d3Sopenharmony_ci *
122094332d3Sopenharmony_ci * You can adjust the parameters required for creating a component based on service requirements.
123094332d3Sopenharmony_ci *
124094332d3Sopenharmony_ci * @param type Indicates the codec type, for example, <b>VIDEO_DECODER</b>.
125094332d3Sopenharmony_ci * @param mime Indicates the codec format, for example, <b>MEDIA_MIMETYPE_VIDEO_AVC</b>.
126094332d3Sopenharmony_ci * @param handle Indicates the pointer to the codec handle returned.
127094332d3Sopenharmony_ci * @return Returns <b>0</b> if the codec component is created and the handle is available;
128094332d3Sopenharmony_ci * returns a non-zero value otherwise.
129094332d3Sopenharmony_ci */
130094332d3Sopenharmony_ciint32_t CodecCreateByType(CodecType type, AvCodecMime mime, CODEC_HANDLETYPE *handle);
131094332d3Sopenharmony_ci
132094332d3Sopenharmony_ci/**
133094332d3Sopenharmony_ci * @brief Destroys a codec component.
134094332d3Sopenharmony_ci *
135094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
136094332d3Sopenharmony_ci * @return Returns <b>0</b> if the codec component is destroyed; returns a non-zero value otherwise.
137094332d3Sopenharmony_ci * @see CodecCreate
138094332d3Sopenharmony_ci */
139094332d3Sopenharmony_ciint32_t CodecDestroy(CODEC_HANDLETYPE handle);
140094332d3Sopenharmony_ci
141094332d3Sopenharmony_ci/**
142094332d3Sopenharmony_ci * @brief Sets the input or output buffer mode.
143094332d3Sopenharmony_ci *
144094332d3Sopenharmony_ci * You can learn about the support of the codec input/output buffer for internal and external buffer modes
145094332d3Sopenharmony_ci * by calling {@link CodecGetCapability}. In this way, you can determine whether to use an internal or
146094332d3Sopenharmony_ci * external buffer mode. If the current codec can use only the specific buffer mode, you do not need to set it.
147094332d3Sopenharmony_ci *
148094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
149094332d3Sopenharmony_ci * @param direct Specifies whether the buffer type is an input type or an output type.
150094332d3Sopenharmony_ci * @param mode Specifies whether to use an internal or external buffer mode.
151094332d3Sopenharmony_ci * @param type Specifies the buffer memory type.
152094332d3Sopenharmony_ci * @return Returns <b>0</b> if the setting is successful; returns a non-zero value otherwise.
153094332d3Sopenharmony_ci */
154094332d3Sopenharmony_ciint32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode mode, BufferType type);
155094332d3Sopenharmony_ci
156094332d3Sopenharmony_ciint32_t CodecGetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode *mode, BufferType *type);
157094332d3Sopenharmony_ci
158094332d3Sopenharmony_ci/**
159094332d3Sopenharmony_ci * @brief Sets parameters required by a codec component.
160094332d3Sopenharmony_ci *
161094332d3Sopenharmony_ci * You should call this function to set parameters after {@link CodecCreate} is called
162094332d3Sopenharmony_ci * but before {@link CodecStart} is called.
163094332d3Sopenharmony_ci *
164094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
165094332d3Sopenharmony_ci * @param params Indicates the pointer to the parameters to set in the array.
166094332d3Sopenharmony_ci * @param paramCnt Indicates the number of elements in the parameter array.
167094332d3Sopenharmony_ci * @return Returns <b>0</b> if the setting is successful; returns a non-zero value otherwise.
168094332d3Sopenharmony_ci * @see CodecGetParameter
169094332d3Sopenharmony_ci */
170094332d3Sopenharmony_ciint32_t CodecSetParameter(CODEC_HANDLETYPE handle, const Param *params, int paramCnt);
171094332d3Sopenharmony_ci
172094332d3Sopenharmony_ci/**
173094332d3Sopenharmony_ci * @brief Obtains parameters from a codec component.
174094332d3Sopenharmony_ci *
175094332d3Sopenharmony_ci * This function must be called after {@link CodecCreate}.
176094332d3Sopenharmony_ci *
177094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
178094332d3Sopenharmony_ci * @param params Indicates the pointer to the parameters in the array used when the component is created.
179094332d3Sopenharmony_ci * @param paramCnt Indicates the number of elements in the parameter array.
180094332d3Sopenharmony_ci * @return Returns <b>0</b> if all parameters to obtain are supported; returns a non-zero value otherwise.
181094332d3Sopenharmony_ci * @see CodecSetParameter
182094332d3Sopenharmony_ci */
183094332d3Sopenharmony_ciint32_t CodecGetParameter(CODEC_HANDLETYPE handle, Param *params, int paramCnt);
184094332d3Sopenharmony_ci
185094332d3Sopenharmony_ci/**
186094332d3Sopenharmony_ci * @brief Starts a codec component.
187094332d3Sopenharmony_ci *
188094332d3Sopenharmony_ci * You can restart a component after it is stopped.
189094332d3Sopenharmony_ci *
190094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
191094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
192094332d3Sopenharmony_ci */
193094332d3Sopenharmony_ciint32_t CodecStart(CODEC_HANDLETYPE handle);
194094332d3Sopenharmony_ci
195094332d3Sopenharmony_ci/**
196094332d3Sopenharmony_ci * @brief Stops a codec component.
197094332d3Sopenharmony_ci *
198094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
199094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
200094332d3Sopenharmony_ci */
201094332d3Sopenharmony_ciint32_t CodecStop(CODEC_HANDLETYPE handle);
202094332d3Sopenharmony_ci
203094332d3Sopenharmony_ci/**
204094332d3Sopenharmony_ci * @brief Reset a codec component.
205094332d3Sopenharmony_ci *
206094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
207094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
208094332d3Sopenharmony_ci */
209094332d3Sopenharmony_ciint32_t CodecReset(CODEC_HANDLETYPE handle);
210094332d3Sopenharmony_ci
211094332d3Sopenharmony_ci/**
212094332d3Sopenharmony_ci * @brief Clears the cache when the codec component is the running state.
213094332d3Sopenharmony_ci *
214094332d3Sopenharmony_ci * Generally, this function is called when the seek operation is performed during playback.
215094332d3Sopenharmony_ci *
216094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
217094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
218094332d3Sopenharmony_ci */
219094332d3Sopenharmony_ciint32_t CodecFlush(CODEC_HANDLETYPE handle, DirectionType directType);
220094332d3Sopenharmony_ci
221094332d3Sopenharmony_ci/**
222094332d3Sopenharmony_ci * @brief Queues input data.
223094332d3Sopenharmony_ci *
224094332d3Sopenharmony_ci * This function works with {@link CodecDequeInput} to implement input data transmission.
225094332d3Sopenharmony_ci *
226094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
227094332d3Sopenharmony_ci * @param inputData Indicates the pointer to the input data.
228094332d3Sopenharmony_ci * @param timeoutMs Indicates the timeout duration.
229094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
230094332d3Sopenharmony_ci */
231094332d3Sopenharmony_ciint32_t CodecQueueInput(CODEC_HANDLETYPE handle, const CodecBuffer *inputData, uint32_t timeoutMs, int releaseFenceFd);
232094332d3Sopenharmony_ci
233094332d3Sopenharmony_ci/**
234094332d3Sopenharmony_ci * @brief Dequeues input data that has been used.
235094332d3Sopenharmony_ci *
236094332d3Sopenharmony_ci * This function works with {@link CodecQueueInput} to implement input data transmission.
237094332d3Sopenharmony_ci *
238094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
239094332d3Sopenharmony_ci * @param timeoutMs Indicates the timeout duration. Generally, the value is less than or equal to <b>3</b> seconds.
240094332d3Sopenharmony_ci * @param inputData Indicates the pointer to the input data that is used.
241094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
242094332d3Sopenharmony_ci */
243094332d3Sopenharmony_ciint32_t CodecDequeueInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int *acquireFd, CodecBuffer *inputData);
244094332d3Sopenharmony_ci
245094332d3Sopenharmony_ci/**
246094332d3Sopenharmony_ci * @brief Queues output data.
247094332d3Sopenharmony_ci *
248094332d3Sopenharmony_ci * This function works with {@link CodecDequeueOutput} to implement output data transmission.
249094332d3Sopenharmony_ci *
250094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
251094332d3Sopenharmony_ci * @param outInfo Indicates the pointer to the output data.
252094332d3Sopenharmony_ci * @param timeoutMs Indicates the timeout duration.
253094332d3Sopenharmony_ci * @param releaseFenceFd Indicates that the descriptor comes from a buffer consumer.
254094332d3Sopenharmony_ci * The output data can be used only after waiting for <b>releaseFenceFd</b> is successful.
255094332d3Sopenharmony_ci * The value <b>-1</b> indicates that <b>releaseFenceFd</b> is invalid.
256094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
257094332d3Sopenharmony_ci */
258094332d3Sopenharmony_ciint32_t CodecQueueOutput(CODEC_HANDLETYPE handle, CodecBuffer *outInfo, uint32_t timeoutMs, int releaseFenceFd);
259094332d3Sopenharmony_ci
260094332d3Sopenharmony_ci/**
261094332d3Sopenharmony_ci * @brief Dequeues output data.
262094332d3Sopenharmony_ci *
263094332d3Sopenharmony_ci * This function works with {@link CodecQueueOutput} to implement output data transmission.
264094332d3Sopenharmony_ci *
265094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
266094332d3Sopenharmony_ci * @param timeoutMs Indicates the timeout duration.
267094332d3Sopenharmony_ci * @param acquireFd Indicates that this parameter is derived from the codec mode.
268094332d3Sopenharmony_ci * The output data can be used only after waiting for <b>acquireFd</b> is successful.
269094332d3Sopenharmony_ci * The value <b>-1</b> indicates that <b>acquireFd</b> is invalid.
270094332d3Sopenharmony_ci * @param outInfo Indicates the pointer to the output data.
271094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
272094332d3Sopenharmony_ci */
273094332d3Sopenharmony_ciint32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int *acquireFd, CodecBuffer *outInfo);
274094332d3Sopenharmony_ci
275094332d3Sopenharmony_ci/**
276094332d3Sopenharmony_ci * @brief Sets the callback function.
277094332d3Sopenharmony_ci *
278094332d3Sopenharmony_ci * The codec uses the callback function to notify the upper layer of events and asynchronously
279094332d3Sopenharmony_ci * report available input/output information.
280094332d3Sopenharmony_ci *
281094332d3Sopenharmony_ci * @param handle Indicates the handle of the codec component.
282094332d3Sopenharmony_ci * @param cb Indicates the pointer to the callback function. For details, see {@link CodecCallback}.
283094332d3Sopenharmony_ci * @param instance Indicates the upper-layer instance to be notified.
284094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
285094332d3Sopenharmony_ci */
286094332d3Sopenharmony_ciint32_t CodecSetCallback(CODEC_HANDLETYPE handle, const CodecCallback *cb, UINTPTR instance);
287094332d3Sopenharmony_ci
288094332d3Sopenharmony_ci#ifdef __cplusplus
289094332d3Sopenharmony_ci#if __cplusplus
290094332d3Sopenharmony_ci}
291094332d3Sopenharmony_ci#endif
292094332d3Sopenharmony_ci#endif /* __cplusplus */
293094332d3Sopenharmony_ci
294094332d3Sopenharmony_ci#endif /* CODEC_INTERFACE_H */
295094332d3Sopenharmony_ci/** @} */