2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __TIZEN_MEDIA_CODEC_SYNC_INTERNAL_H__
18 #define __TIZEN_MEDIA_CODEC_SYNC_INTERNAL_H__
20 #include <media_codec.h>
27 * @file media_codec_sync_internal.h
28 * @brief This file contains the internal capi media codec sync API.
32 * @addtogroup CAPI_MEDIA_CODEC_SYNC_MODULE
37 * @brief Media Codec Sync type handle.
40 typedef struct mediacodecsync_s *mediacodecsync_h;
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;
51 MEDIACODECSYNC_PACKET_TYPE_AUDIO = 0,
52 MEDIACODECSYNC_PACKET_TYPE_VIDEO
53 } mediacodecsync_packet_type_e;
55 typedef void (*mediacodecsync_buffer_used_cb)(media_packet_h packet, mediacodecsync_packet_type_e type, void *user_data);
58 * @brief Creates a mediacodecsync handle for synchronous AV rendering.
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.
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.
75 int mediacodecsync_create(mediacodecsync_buffer_used_cb callback, void *userdata, mediacodecsync_h *mediacodecsync);
78 * @brief Destroys the mediacodecsync handle and releases all its resources.
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.
87 int mediacodecsync_destroy(mediacodecsync_h mediacodecsync);
90 * @brief Sets the media format to be rendered.
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()
112 int mediacodecsync_set_format(mediacodecsync_h mediacodecsync, media_format_h audio_format, media_format_h video_format);
115 * @brief Prepares @a mediacodecsync for synchronous rendering.
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.
129 int mediacodecsync_prepare(mediacodecsync_h mediacodecsync);
132 * @brief Unprepares @a mediacodecsync.
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.
142 int mediacodecsync_unprepare(mediacodecsync_h mediacodecsync);
145 * @brief Runs @a mediacodecsync.
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.
155 int mediacodecsync_run(mediacodecsync_h mediacodecsync);
158 * @brief Stops @a mediacodecsync.
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.
168 int mediacodecsync_stop(mediacodecsync_h mediacodecsync);
171 * @brief Pauses @a mediacodecsync.
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.
181 int mediacodecsync_pause(mediacodecsync_h mediacodecsync);
184 * @brief Pushes packets to render.
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.
195 int mediacodecsync_push_packet(mediacodecsync_h mediacodecsync, media_packet_h packet, mediacodecsync_packet_type_e type);
198 * @brief Gets state of @a mediacodecsync.
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
207 int mediacodecsync_get_state(mediacodecsync_h mediacodecsync, mediacodecsync_state_e *state);
215 #endif /*__TIZEN_MEDIA_CODEC_INTERNAL_H__*/