omxil: add conversion functions from OMX H264 profile/levels to profile_idc/level_idc
[vlc.git] / modules / codec / omxil / omxil_utils.h
blob0a5dc17e77fed0008ad87124acfb091af1fe8835
1 /*****************************************************************************
2 * omxil_utils.h: helper functions
3 *****************************************************************************
4 * Copyright (C) 2010 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * OMX macros
26 *****************************************************************************/
27 #ifdef __ANDROID__
28 #define OMX_VERSION_MAJOR 1
29 #define OMX_VERSION_MINOR 0
30 #define OMX_VERSION_REV 0
31 #define OMX_VERSION_STEP 0
32 #elif defined(RPI_OMX)
33 #define OMX_VERSION_MAJOR 1
34 #define OMX_VERSION_MINOR 1
35 #define OMX_VERSION_REV 2
36 #define OMX_VERSION_STEP 0
37 #else
38 #define OMX_VERSION_MAJOR 1
39 #define OMX_VERSION_MINOR 1
40 #define OMX_VERSION_REV 1
41 #define OMX_VERSION_STEP 0
42 #endif
44 #define OMX_INIT_COMMON(a) \
45 (a).nSize = sizeof(a); \
46 (a).nVersion.s.nVersionMajor = OMX_VERSION_MAJOR; \
47 (a).nVersion.s.nVersionMinor = OMX_VERSION_MINOR; \
48 (a).nVersion.s.nRevision = OMX_VERSION_REV; \
49 (a).nVersion.s.nStep = OMX_VERSION_STEP
51 #define OMX_INIT_STRUCTURE(a) \
52 memset(&(a), 0, sizeof(a)); \
53 OMX_INIT_COMMON(a)
55 #define OMX_ComponentRoleEnum(hComponent, cRole, nIndex) \
56 ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum ? \
57 ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum( \
58 hComponent, cRole, nIndex ) : OMX_ErrorNotImplemented
60 #define CHECK_ERROR(a, ...) \
61 if(a != OMX_ErrorNone) {msg_Dbg( p_dec, __VA_ARGS__ ); goto error;}
63 #ifdef OMX_SKIP64BIT
64 static inline int64_t FromOmxTicks(OMX_TICKS value)
66 return (((int64_t)value.nHighPart) << 32) | value.nLowPart;
68 static inline OMX_TICKS ToOmxTicks(int64_t value)
70 OMX_TICKS s;
71 s.nLowPart = value;
72 s.nHighPart = value >> 32;
73 return s;
75 #else
76 #define FromOmxTicks(x) (x)
77 #define ToOmxTicks(x) (x)
78 #endif
80 /*****************************************************************************
81 * OMX buffer FIFO macros
82 *****************************************************************************/
83 #define OMX_FIFO_PEEK(p_fifo, p_buffer) \
84 p_buffer = (p_fifo)->p_first;
86 #define OMX_FIFO_GET(p_fifo, p_buffer) \
87 do { vlc_mutex_lock( &(p_fifo)->lock ); \
88 while( !(p_fifo)->p_first ) \
89 vlc_cond_wait( &(p_fifo)->wait, &(p_fifo)->lock ); \
90 p_buffer = (p_fifo)->p_first; \
91 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
92 ((void **)p_buffer + (p_fifo)->offset); \
93 (p_fifo)->p_first = *pp_next; *pp_next = 0; \
94 if( !(p_fifo)->p_first ) (p_fifo)->pp_last = &(p_fifo)->p_first; \
95 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
97 #define OMX_FIFO_GET_TIMEOUT(p_fifo, p_buffer, timeout) \
98 do { vlc_mutex_lock( &(p_fifo)->lock ); \
99 mtime_t end = mdate() + timeout; \
100 if( !(p_fifo)->p_first ) \
101 vlc_cond_timedwait( &(p_fifo)->wait, &(p_fifo)->lock, end ); \
102 p_buffer = (p_fifo)->p_first; \
103 if( p_buffer ) { \
104 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
105 ((void **)p_buffer + (p_fifo)->offset); \
106 (p_fifo)->p_first = *pp_next; *pp_next = 0; \
107 if( !(p_fifo)->p_first ) (p_fifo)->pp_last = &(p_fifo)->p_first; \
109 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
111 #define OMX_FIFO_PUT(p_fifo, p_buffer) \
112 do { vlc_mutex_lock (&(p_fifo)->lock); \
113 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
114 ((void **)p_buffer + (p_fifo)->offset); \
115 *(p_fifo)->pp_last = p_buffer; \
116 (p_fifo)->pp_last = pp_next; *pp_next = 0; \
117 vlc_cond_signal( &(p_fifo)->wait ); \
118 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
120 /*****************************************************************************
121 * OMX format parameters
122 *****************************************************************************/
123 typedef union {
124 OMX_PARAM_U32TYPE common;
125 OMX_AUDIO_PARAM_PCMMODETYPE pcm;
126 OMX_AUDIO_PARAM_MP3TYPE mp3;
127 OMX_AUDIO_PARAM_AACPROFILETYPE aac;
128 OMX_AUDIO_PARAM_VORBISTYPE vorbis;
129 OMX_AUDIO_PARAM_WMATYPE wma;
130 OMX_AUDIO_PARAM_RATYPE ra;
131 OMX_AUDIO_PARAM_ADPCMTYPE adpcm;
132 OMX_AUDIO_PARAM_G723TYPE g723;
133 OMX_AUDIO_PARAM_G726TYPE g726;
134 OMX_AUDIO_PARAM_G729TYPE g729;
135 OMX_AUDIO_PARAM_AMRTYPE amr;
137 OMX_VIDEO_PARAM_H263TYPE h263;
138 OMX_VIDEO_PARAM_MPEG2TYPE mpeg2;
139 OMX_VIDEO_PARAM_MPEG4TYPE mpeg4;
140 OMX_VIDEO_PARAM_WMVTYPE wmv;
141 OMX_VIDEO_PARAM_RVTYPE rv;
142 OMX_VIDEO_PARAM_AVCTYPE avc;
144 } OmxFormatParam;
146 /*****************************************************************************
147 * Events utility functions
148 *****************************************************************************/
149 typedef struct OmxEvent
151 OMX_EVENTTYPE event;
152 OMX_U32 data_1;
153 OMX_U32 data_2;
154 OMX_PTR event_data;
156 struct OmxEvent *next;
157 } OmxEvent;
159 typedef struct OmxEventQueue
161 OmxEvent *p_events;
162 OmxEvent **pp_last_event;
164 vlc_mutex_t mutex;
165 vlc_cond_t cond;
166 } OmxEventQueue;
168 void InitOmxEventQueue(OmxEventQueue *queue);
169 void DeinitOmxEventQueue(OmxEventQueue *queue);
170 OMX_ERRORTYPE PostOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE event,
171 OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data);
172 OMX_ERRORTYPE WaitForOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE *event,
173 OMX_U32 *data_1, OMX_U32 *data_2, OMX_PTR *event_data);
174 OMX_ERRORTYPE WaitForSpecificOmxEvent(OmxEventQueue *queue,
175 OMX_EVENTTYPE specific_event, OMX_U32 *data_1, OMX_U32 *data_2,
176 OMX_PTR *event_data);
177 void PrintOmxEvent(vlc_object_t *p_this, OMX_EVENTTYPE event, OMX_U32 data_1,
178 OMX_U32 data_2, OMX_PTR event_data);
180 /*****************************************************************************
181 * Picture utility functions
182 *****************************************************************************/
183 typedef struct ArchitectureSpecificCopyData
185 void *data;
186 } ArchitectureSpecificCopyData;
188 void ArchitectureSpecificCopyHooks( decoder_t *p_dec, int i_color_format,
189 int i_slice_height, int i_src_stride,
190 ArchitectureSpecificCopyData *p_architecture_specific );
192 void ArchitectureSpecificCopyHooksDestroy( int i_color_format,
193 ArchitectureSpecificCopyData *p_architecture_specific );
195 void CopyOmxPicture( int i_color_format, picture_t *p_pic,
196 int i_slice_height,
197 int i_src_stride, uint8_t *p_src, int i_chroma_div,
198 ArchitectureSpecificCopyData *p_architecture_specific );
200 void CopyVlcPicture( decoder_t *, OMX_BUFFERHEADERTYPE *, picture_t * );
202 int IgnoreOmxDecoderPadding(const char *psz_name);
204 /*****************************************************************************
205 * Logging utility functions
206 *****************************************************************************/
207 const char *StateToString(OMX_STATETYPE state);
208 const char *CommandToString(OMX_COMMANDTYPE command);
209 const char *EventToString(OMX_EVENTTYPE event);
210 const char *ErrorToString(OMX_ERRORTYPE error);
212 void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port);
214 /*****************************************************************************
215 * fourcc -> omx id mapping
216 *****************************************************************************/
217 int GetOmxVideoFormat( vlc_fourcc_t i_fourcc,
218 OMX_VIDEO_CODINGTYPE *pi_omx_codec,
219 const char **ppsz_name );
220 int GetVlcVideoFormat( OMX_VIDEO_CODINGTYPE i_omx_codec,
221 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
222 int GetOmxAudioFormat( vlc_fourcc_t i_fourcc,
223 OMX_AUDIO_CODINGTYPE *pi_omx_codec,
224 const char **ppsz_name );
225 int OmxToVlcAudioFormat( OMX_AUDIO_CODINGTYPE i_omx_codec,
226 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
227 const char *GetOmxRole( vlc_fourcc_t i_fourcc, int i_cat, bool b_enc );
228 int GetOmxChromaFormat( vlc_fourcc_t i_fourcc,
229 OMX_COLOR_FORMATTYPE *pi_omx_codec,
230 const char **ppsz_name );
231 int GetVlcChromaFormat( OMX_COLOR_FORMATTYPE i_omx_codec,
232 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
233 int GetVlcChromaSizes( vlc_fourcc_t i_fourcc,
234 unsigned int width, unsigned int height,
235 unsigned int *size, unsigned int *pitch,
236 unsigned int *chroma_pitch_div );
238 /*****************************************************************************
239 * Functions to deal with audio format parameters
240 *****************************************************************************/
241 OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
242 OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
243 vlc_fourcc_t i_codec, uint8_t i_channels, unsigned int i_samplerate,
244 unsigned int i_bitrate, unsigned int i_bps, unsigned int i_blocksize);
245 OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
246 OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
247 uint8_t *pi_channels, unsigned int *pi_samplerate,
248 unsigned int *pi_bitrate, unsigned int *pi_bps, unsigned int *pi_blocksize);
249 unsigned int GetAudioParamSize(OMX_INDEXTYPE index);
251 /*****************************************************************************
252 * Vendor specific color formats
253 *****************************************************************************/
254 #define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00
255 #define OMX_TI_COLOR_FormatYUV420PackedSemiPlanar 0x7F000100
256 #define QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka 0x7FA30C03
257 #define OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar32m 0x7FA30C04
258 #define OMX_IndexVendorSetYUV420pMode 0x7f000003
260 /*****************************************************************************
261 * H264 specific code
262 *****************************************************************************/
263 bool h264_get_profile_level(const es_format_t *p_fmt, size_t *p_profile, size_t *p_level, size_t *p_nal_size);
265 size_t convert_omx_to_profile_idc(OMX_VIDEO_AVCPROFILETYPE profile_type);
267 size_t convert_omx_to_level_idc(OMX_VIDEO_AVCLEVELTYPE level_type);