Add media codec sync APIs for internal
[platform/core/api/mediacodec.git] / include / media_codec_sync_internal.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __TIZEN_MEDIA_CODEC_SYNC_INTERNAL_H__
18 #define __TIZEN_MEDIA_CODEC_SYNC_INTERNAL_H__
19
20 #include <media_codec.h>
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 /**
27 * @file media_codec_sync_internal.h
28 * @brief This file contains the internal capi media codec sync API.
29 */
30
31 /**
32 * @addtogroup CAPI_MEDIA_CODEC_SYNC_MODULE
33 * @{
34 */
35
36 /**
37  * @brief Media Codec Sync type handle.
38  * @since_tizen 5.5
39  */
40 typedef struct mediacodecsync_s *mediacodecsync_h;
41
42
43 typedef enum {
44         MEDIACODECSYNC_STATE_CREATED = 0,   /**< Media codec sync is created */
45         MEDIACODECSYNC_STATE_READY,         /**< Media codec sync is ready to run */
46         MEDIACODECSYNC_STATE_RUNNING,       /**< Media codec sync is running */
47         MEDIACODECSYNC_STATE_PAUSED         /**< Media codec sync is paused */
48 } mediacodecsync_state_e;
49
50 typedef enum {
51         MEDIACODECSYNC_PACKET_TYPE_AUDIO = 0,
52         MEDIACODECSYNC_PACKET_TYPE_VIDEO
53 } mediacodecsync_packet_type_e;
54
55 typedef void (*mediacodecsync_buffer_used_cb)(media_packet_h packet, mediacodecsync_packet_type_e type, void *user_data);
56
57 /**
58  * @brief Creates a mediacodecsync handle for synchronous AV rendering.
59  * @since_tizen 5.5
60  * @remarks you must release @a mediacodecsync using mediacodecsync_destroy().\n
61  *          Although you can create multiple mediacodecsync handles at the same time,
62  *          the mediacodec cannot guarantee proper operation because of limited resources, like
63  *          audio or display device.
64  *
65  * @param[in] callback   The callback function to register
66  * @param[in] user_data  The user data to be passed to the callback function
67  * @param[out] mediacodecsync  A new handle to mediacodecsync
68  * @return @c 0 on success, otherwise a negative error value
69  * @retval #MEDIACODEC_ERROR_NONE Successful
70  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
71  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
72  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
73  * @post   If it succeeds, the state will be #MEDIACODECSYNC_STATE_CREATED.
74  */
75 int mediacodecsync_create(mediacodecsync_buffer_used_cb callback, void *userdata, mediacodecsync_h *mediacodecsync);
76
77 /**
78  * @brief Destroys the mediacodecsync handle and releases all its resources.
79  * @since_tizen 5.5
80  * @param[in] mediacodecsync The handle to mediacodecsync to be destroyed.
81  * @return @c 0 on success, otherwise a negative error value
82  * @retval #MEDIACODEC_ERROR_NONE Successful
83  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
84  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
85  * @pre The state should be #MEDIACODECSYNC_STATE_CREATED.
86  */
87 int mediacodecsync_destroy(mediacodecsync_h mediacodecsync);
88
89 /**
90  * @brief Sets the media format to be rendered.
91  * @since_tizen 5.5
92  * @param[in] mediacodecsync The mediacodecsync handle
93  * @param[in] audio_format   The #media_format_h of audio data
94  * @param[in] video_format   The #media_format_h of video data
95  * @return @c 0 on success, otherwise a negative error value
96  * @retval #MEDIACODEC_ERROR_NONE Successful
97  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
98  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device
99  * @pre The state should be #MEDIACODECSYNC_STATE_CREATED.
100  * @pre The media format has been created and the required values have been set.
101  * @see media_format_set_video_mime()
102  * @see media_format_set_audio_mime()
103  * @see media_format_set_video_width()
104  * @see media_format_set_video_height()
105  * @see media_format_set_video_avg_bps()
106  * @see media_format_set_video_frame_rate()
107  * @see media_format_set_audio_channel()
108  * @see media_format_set_audio_samplerate()
109  * @see media_format_set_audio_bit()
110  * @see media_format_set_audio_avg_bps()
111  */
112 int mediacodecsync_set_format(mediacodecsync_h mediacodecsync, media_format_h audio_format, media_format_h video_format);
113
114 /**
115  * @brief Prepares @a mediacodecsync for synchronous rendering.
116  * @since_tizen 5.5
117  * @param[in] mediacodecsync The handle to mediacodecsync
118  * @return @c 0 on success, otherwise a negative error value
119  * @retval #MEDIACODEC_ERROR_NONE Successful
120  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
121  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
122  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
123  * @retval #MEDIACODEC_ERROR_RESOURCE_OVERLOADED Exceed the instance limits
124  * @retval #MEDIACODEC_ERROR_INTERNAL Internal error
125  * @pre The mediacodecsync should call mediacodecsync_set_format() before calling mediacodec_prepare().
126  * @pre The state should be #MEDIACODECSYNC_STATE_CREATED.
127  * @post   If it succeeds, the state will be #MEDIACODECSYNC_STATE_READY.
128  */
129 int mediacodecsync_prepare(mediacodecsync_h mediacodecsync);
130
131 /**
132  * @brief Unprepares @a mediacodecsync.
133  * @since_tizen 5.5
134  * @param[in] mediacodecsync The handle to mediacodecsync
135  * @return @c 0 on success, otherwise a negative error value
136  * @retval #MEDIACODEC_ERROR_NONE Successful
137  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
138  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
139  * @pre The state should be #MEDIACODECSYNC_STATE_READY.
140  * @post   If it succeeds, the state will be #MEDIACODECSYNC_STATE_CREATED.
141  */
142 int mediacodecsync_unprepare(mediacodecsync_h mediacodecsync);
143
144 /**
145  * @brief Runs @a mediacodecsync.
146  * @since_tizen 5.5
147  * @param[in] mediacodecsync The handle to mediacodecsync
148  * @return @c 0 on success, otherwise a negative error value
149  * @retval #MEDIACODEC_ERROR_NONE Successful
150  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
151  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
152  * @pre The state should be #MEDIACODECSYNC_STATE_READY or #MEDIACODECSYNC_STATE_PAUSED.
153  * @post   If it succeeds, the state will be #MEDIACODECSYNC_STATE_RUNNING.
154  */
155 int mediacodecsync_run(mediacodecsync_h mediacodecsync);
156
157 /**
158  * @brief Stops @a mediacodecsync.
159  * @since_tizen 5.5
160  * @param[in] mediacodecsync The handle to mediacodecsync
161  * @return @c 0 on success, otherwise a negative error value
162  * @retval #MEDIACODEC_ERROR_NONE Successful
163  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
164  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
165  * @pre The state should be #MEDIACODECSYNC_STATE_RUN or #MEDIACODECSYNC_STATE_PAUSED.
166  * @post   If it succeeds, the state will be #MEDIACODECSYNC_STATE_READY.
167  */
168 int mediacodecsync_stop(mediacodecsync_h mediacodecsync);
169
170 /**
171  * @brief Pauses @a mediacodecsync.
172  * @since_tizen 5.5
173  * @param[in] mediacodecsync The handle to mediacodecsync
174  * @return @c 0 on success, otherwise a negative error value
175  * @retval #MEDIACODEC_ERROR_NONE Successful
176  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
177  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
178  * @pre The state should be #MEDIACODECSYNC_STATE_RUN.
179  * @post   If it succeeds, the state will be #MEDIACODECSYNC_STATE_PAUSED.
180  */
181 int mediacodecsync_pause(mediacodecsync_h mediacodecsync);
182
183 /**
184  * @brief Pushes packets to render.
185  * @since_tizen 5.5
186  * @param[in] mediacodecsync The handle to mediacodecsync
187  * @param[in] packet The packet to render
188  * @param[in] type The type of packet
189  * @return @c 0 on success, otherwise a negative error value
190  * @retval #MEDIACODEC_ERROR_NONE Successful
191  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
192  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
193  * @pre The state should be #MEDIACODECSYNC_STATE_RUN.
194  */
195 int mediacodecsync_push_packet(mediacodecsync_h mediacodecsync, media_packet_h packet, mediacodecsync_packet_type_e type);
196
197 /**
198  * @brief Gets state of @a mediacodecsync.
199  * @since_tizen 5.5
200  * @param[in] mediacodecsync The handle to mediacodecsync
201  * @param[out] state The state of mediacodecsync
202  * @return @c 0 on success, otherwise a negative error value
203  * @retval #MEDIACODEC_ERROR_NONE Successful
204  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
205  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
206  */
207 int mediacodecsync_get_state(mediacodecsync_h mediacodecsync, mediacodecsync_state_e *state);
208
209 /**
210  * @}
211  */
212 #ifdef __cplusplus
213 }
214 #endif
215 #endif /*__TIZEN_MEDIA_CODEC_INTERNAL_H__*/