qt: playlist: use item title if available
[vlc.git] / modules / codec / omxil / omxil_utils.h
blobbeb2c40d02ac3e413d981c1cd649e110d47cf2b9
1 /*****************************************************************************
2 * omxil_utils.h: helper functions
3 *****************************************************************************
4 * Copyright (C) 2010 VLC authors and VideoLAN
6 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #include <vlc_es.h>
25 /*****************************************************************************
26 * OMX macros
27 *****************************************************************************/
28 #ifdef __ANDROID__
29 #define OMX_VERSION_MAJOR 1
30 #define OMX_VERSION_MINOR 0
31 #define OMX_VERSION_REV 0
32 #define OMX_VERSION_STEP 0
33 #elif defined(RPI_OMX)
34 #define OMX_VERSION_MAJOR 1
35 #define OMX_VERSION_MINOR 1
36 #define OMX_VERSION_REV 2
37 #define OMX_VERSION_STEP 0
38 #else
39 #define OMX_VERSION_MAJOR 1
40 #define OMX_VERSION_MINOR 1
41 #define OMX_VERSION_REV 1
42 #define OMX_VERSION_STEP 0
43 #endif
45 #define OMX_INIT_COMMON(a) \
46 (a).nSize = sizeof(a); \
47 (a).nVersion.s.nVersionMajor = OMX_VERSION_MAJOR; \
48 (a).nVersion.s.nVersionMinor = OMX_VERSION_MINOR; \
49 (a).nVersion.s.nRevision = OMX_VERSION_REV; \
50 (a).nVersion.s.nStep = OMX_VERSION_STEP
52 #define OMX_INIT_STRUCTURE(a) \
53 memset(&(a), 0, sizeof(a)); \
54 OMX_INIT_COMMON(a)
56 #define OMX_ComponentRoleEnum(hComponent, cRole, nIndex) \
57 ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum ? \
58 ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum( \
59 hComponent, cRole, nIndex ) : OMX_ErrorNotImplemented
61 #define CHECK_ERROR(a, ...) \
62 if(a != OMX_ErrorNone) {msg_Dbg( p_dec, __VA_ARGS__ ); goto error;}
64 #ifdef OMX_SKIP64BIT
65 static inline int64_t FromOmxTicks(OMX_TICKS value)
67 return (((int64_t)value.nHighPart) << 32) | value.nLowPart;
69 static inline OMX_TICKS ToOmxTicks(int64_t value)
71 OMX_TICKS s;
72 s.nLowPart = value;
73 s.nHighPart = value >> 32;
74 return s;
76 #else
77 #define FromOmxTicks(x) (x)
78 #define ToOmxTicks(x) (x)
79 #endif
81 /*****************************************************************************
82 * OMX buffer FIFO macros
83 *****************************************************************************/
84 #define OMX_FIFO_INIT(p_fifo, next) \
85 do { vlc_mutex_init( &(p_fifo)->lock ); \
86 vlc_cond_init( &(p_fifo)->wait ); \
87 (p_fifo)->offset = offsetof(OMX_BUFFERHEADERTYPE, next) / sizeof(void *); \
88 (p_fifo)->pp_last = &(p_fifo)->p_first; } while(0)
90 #define OMX_FIFO_DESTROY(p_fifo) \
91 while(0) { }
93 #define OMX_FIFO_PEEK(p_fifo, p_buffer) \
94 p_buffer = (p_fifo)->p_first;
96 #define OMX_FIFO_GET(p_fifo, p_buffer) \
97 do { vlc_mutex_lock( &(p_fifo)->lock ); \
98 while( !(p_fifo)->p_first ) \
99 vlc_cond_wait( &(p_fifo)->wait, &(p_fifo)->lock ); \
100 p_buffer = (p_fifo)->p_first; \
101 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
102 ((void **)p_buffer + (p_fifo)->offset); \
103 (p_fifo)->p_first = *pp_next; *pp_next = 0; \
104 if( !(p_fifo)->p_first ) (p_fifo)->pp_last = &(p_fifo)->p_first; \
105 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
107 #define OMX_FIFO_GET_TIMEOUT(p_fifo, p_buffer, timeout) \
108 do { vlc_mutex_lock( &(p_fifo)->lock ); \
109 vlc_tick_t end = vlc_tick_now() + timeout; \
110 if( !(p_fifo)->p_first ) \
111 vlc_cond_timedwait( &(p_fifo)->wait, &(p_fifo)->lock, end ); \
112 p_buffer = (p_fifo)->p_first; \
113 if( p_buffer ) { \
114 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
115 ((void **)p_buffer + (p_fifo)->offset); \
116 (p_fifo)->p_first = *pp_next; *pp_next = 0; \
117 if( !(p_fifo)->p_first ) (p_fifo)->pp_last = &(p_fifo)->p_first; \
119 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
121 #define OMX_FIFO_PUT(p_fifo, p_buffer) \
122 do { vlc_mutex_lock (&(p_fifo)->lock); \
123 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
124 ((void **)p_buffer + (p_fifo)->offset); \
125 *(p_fifo)->pp_last = p_buffer; \
126 (p_fifo)->pp_last = pp_next; *pp_next = 0; \
127 vlc_cond_signal( &(p_fifo)->wait ); \
128 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
130 /*****************************************************************************
131 * OMX format parameters
132 *****************************************************************************/
133 typedef union {
134 OMX_PARAM_U32TYPE common;
135 OMX_AUDIO_PARAM_PCMMODETYPE pcm;
136 OMX_AUDIO_PARAM_MP3TYPE mp3;
137 OMX_AUDIO_PARAM_AACPROFILETYPE aac;
138 OMX_AUDIO_PARAM_VORBISTYPE vorbis;
139 OMX_AUDIO_PARAM_WMATYPE wma;
140 OMX_AUDIO_PARAM_RATYPE ra;
141 OMX_AUDIO_PARAM_ADPCMTYPE adpcm;
142 OMX_AUDIO_PARAM_G723TYPE g723;
143 OMX_AUDIO_PARAM_G726TYPE g726;
144 OMX_AUDIO_PARAM_G729TYPE g729;
145 OMX_AUDIO_PARAM_AMRTYPE amr;
147 OMX_VIDEO_PARAM_H263TYPE h263;
148 OMX_VIDEO_PARAM_MPEG2TYPE mpeg2;
149 OMX_VIDEO_PARAM_MPEG4TYPE mpeg4;
150 OMX_VIDEO_PARAM_WMVTYPE wmv;
151 OMX_VIDEO_PARAM_RVTYPE rv;
152 OMX_VIDEO_PARAM_AVCTYPE avc;
154 } OmxFormatParam;
156 /*****************************************************************************
157 * Events utility functions
158 *****************************************************************************/
159 typedef struct OmxEvent
161 OMX_EVENTTYPE event;
162 OMX_U32 data_1;
163 OMX_U32 data_2;
164 OMX_PTR event_data;
166 struct OmxEvent *next;
167 } OmxEvent;
169 typedef struct OmxEventQueue
171 OmxEvent *p_events;
172 OmxEvent **pp_last_event;
174 vlc_mutex_t mutex;
175 vlc_cond_t cond;
176 } OmxEventQueue;
178 void InitOmxEventQueue(OmxEventQueue *queue);
179 void DeinitOmxEventQueue(OmxEventQueue *queue);
180 OMX_ERRORTYPE PostOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE event,
181 OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data);
182 OMX_ERRORTYPE WaitForOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE *event,
183 OMX_U32 *data_1, OMX_U32 *data_2, OMX_PTR *event_data);
184 OMX_ERRORTYPE WaitForSpecificOmxEvent(OmxEventQueue *queue,
185 OMX_EVENTTYPE specific_event, OMX_U32 *data_1, OMX_U32 *data_2,
186 OMX_PTR *event_data);
187 void PrintOmxEvent(vlc_object_t *p_this, OMX_EVENTTYPE event, OMX_U32 data_1,
188 OMX_U32 data_2, OMX_PTR event_data);
190 /*****************************************************************************
191 * Picture utility functions
192 *****************************************************************************/
193 typedef struct ArchitectureSpecificCopyData
195 void *data;
196 } ArchitectureSpecificCopyData;
198 void ArchitectureSpecificCopyHooks( decoder_t *p_dec, int i_color_format,
199 int i_slice_height, int i_src_stride,
200 ArchitectureSpecificCopyData *p_architecture_specific );
202 void ArchitectureSpecificCopyHooksDestroy( int i_color_format,
203 ArchitectureSpecificCopyData *p_architecture_specific );
205 void CopyOmxPicture( int i_color_format, picture_t *p_pic,
206 int i_slice_height,
207 int i_src_stride, uint8_t *p_src, int i_chroma_div,
208 ArchitectureSpecificCopyData *p_architecture_specific );
210 void CopyVlcPicture( decoder_t *, OMX_BUFFERHEADERTYPE *, picture_t * );
212 /*****************************************************************************
213 * Logging utility functions
214 *****************************************************************************/
215 const char *StateToString(OMX_STATETYPE state);
216 const char *CommandToString(OMX_COMMANDTYPE command);
217 const char *EventToString(OMX_EVENTTYPE event);
218 const char *ErrorToString(OMX_ERRORTYPE error);
220 void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port);
222 /*****************************************************************************
223 * Utility functions
224 *****************************************************************************/
225 bool OMXCodec_IsBlacklisted( const char *p_name, unsigned int i_name_len );
227 enum {
228 OMXCODEC_NO_QUIRKS = 0,
229 OMXCODEC_QUIRKS_NEED_CSD = 0x1,
230 OMXCODEC_VIDEO_QUIRKS_IGNORE_PADDING = 0x2,
231 OMXCODEC_VIDEO_QUIRKS_SUPPORT_INTERLACED = 0x4,
232 OMXCODEC_AUDIO_QUIRKS_NEED_CHANNELS = 0x8,
234 int OMXCodec_GetQuirks( enum es_format_category_e i_cat, vlc_fourcc_t i_codec,
235 const char *p_name, unsigned int i_name_len );
237 /*****************************************************************************
238 * fourcc -> omx id mapping
239 *****************************************************************************/
240 int GetOmxVideoFormat( vlc_fourcc_t i_fourcc,
241 OMX_VIDEO_CODINGTYPE *pi_omx_codec,
242 const char **ppsz_name );
243 int GetVlcVideoFormat( OMX_VIDEO_CODINGTYPE i_omx_codec,
244 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
245 int GetOmxAudioFormat( vlc_fourcc_t i_fourcc,
246 OMX_AUDIO_CODINGTYPE *pi_omx_codec,
247 const char **ppsz_name );
248 int OmxToVlcAudioFormat( OMX_AUDIO_CODINGTYPE i_omx_codec,
249 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
250 const char *GetOmxRole( vlc_fourcc_t i_fourcc, enum es_format_category_e i_cat,
251 bool b_enc );
252 int GetOmxChromaFormat( vlc_fourcc_t i_fourcc,
253 OMX_COLOR_FORMATTYPE *pi_omx_codec,
254 const char **ppsz_name );
255 int GetVlcChromaFormat( OMX_COLOR_FORMATTYPE i_omx_codec,
256 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
257 int GetVlcChromaSizes( vlc_fourcc_t i_fourcc,
258 unsigned int width, unsigned int height,
259 unsigned int *size, unsigned int *pitch,
260 unsigned int *chroma_pitch_div );
262 /*****************************************************************************
263 * Functions to deal with audio format parameters
264 *****************************************************************************/
265 OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
266 OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
267 vlc_fourcc_t i_codec, uint8_t i_channels, unsigned int i_samplerate,
268 unsigned int i_bitrate, unsigned int i_bps, unsigned int i_blocksize);
269 OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
270 OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
271 uint8_t *pi_channels, unsigned int *pi_samplerate,
272 unsigned int *pi_bitrate, unsigned int *pi_bps, unsigned int *pi_blocksize);
273 unsigned int GetAudioParamSize(OMX_INDEXTYPE index);
275 /*****************************************************************************
276 * Vendor specific color formats
277 *****************************************************************************/
278 #define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00
279 #define OMX_TI_COLOR_FormatYUV420PackedSemiPlanar 0x7F000100
280 #define QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka 0x7FA30C03
281 #define OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar32m 0x7FA30C04
282 #define OMX_IndexVendorSetYUV420pMode 0x7f000003
284 /*****************************************************************************
285 * H264 specific code
286 *****************************************************************************/
287 size_t convert_omx_to_profile_idc(OMX_VIDEO_AVCPROFILETYPE profile_type);
289 size_t convert_omx_to_level_idc(OMX_VIDEO_AVCLEVELTYPE level_type);