MacOS X: fix preferences for ModulesConfig
[vlc.git] / modules / codec / omxil / omxil_utils.h
blob4294170041332ab67211baa0be1664164521017b
1 /*****************************************************************************
2 * omxil_utils.h: helper functions
3 *****************************************************************************
4 * Copyright (C) 2010 the VideoLAN team
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, 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 #else
33 #define OMX_VERSION_MAJOR 1
34 #define OMX_VERSION_MINOR 1
35 #define OMX_VERSION_REV 1
36 #define OMX_VERSION_STEP 0
37 #endif
39 #define OMX_INIT_COMMON(a) \
40 (a).nSize = sizeof(a); \
41 (a).nVersion.s.nVersionMajor = OMX_VERSION_MAJOR; \
42 (a).nVersion.s.nVersionMinor = OMX_VERSION_MINOR; \
43 (a).nVersion.s.nRevision = OMX_VERSION_REV; \
44 (a).nVersion.s.nStep = OMX_VERSION_STEP
46 #define OMX_INIT_STRUCTURE(a) \
47 memset(&(a), 0, sizeof(a)); \
48 OMX_INIT_COMMON(a)
50 #define OMX_ComponentRoleEnum(hComponent, cRole, nIndex) \
51 ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum ? \
52 ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum( \
53 hComponent, cRole, nIndex ) : OMX_ErrorNotImplemented
55 #define CHECK_ERROR(a, ...) \
56 if(a != OMX_ErrorNone) {msg_Dbg( p_dec, __VA_ARGS__ ); goto error;}
58 /*****************************************************************************
59 * OMX buffer FIFO macros
60 *****************************************************************************/
61 #define OMX_FIFO_PEEK(p_fifo, p_buffer) \
62 p_buffer = (p_fifo)->p_first;
64 #define OMX_FIFO_GET(p_fifo, p_buffer) \
65 do { vlc_mutex_lock( &(p_fifo)->lock ); \
66 while( !(p_fifo)->p_first ) \
67 vlc_cond_wait( &(p_fifo)->wait, &(p_fifo)->lock ); \
68 p_buffer = (p_fifo)->p_first; \
69 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
70 ((void **)p_buffer + (p_fifo)->offset); \
71 (p_fifo)->p_first = *pp_next; *pp_next = 0; \
72 if( !(p_fifo)->p_first ) (p_fifo)->pp_last = &(p_fifo)->p_first; \
73 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
75 #define OMX_FIFO_PUT(p_fifo, p_buffer) \
76 do { vlc_mutex_lock (&(p_fifo)->lock); \
77 OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
78 ((void **)p_buffer + (p_fifo)->offset); \
79 *(p_fifo)->pp_last = p_buffer; \
80 (p_fifo)->pp_last = pp_next; *pp_next = 0; \
81 vlc_cond_signal( &(p_fifo)->wait ); \
82 vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
84 /*****************************************************************************
85 * OMX format parameters
86 *****************************************************************************/
87 typedef union {
88 OMX_PARAM_U32TYPE common;
89 OMX_AUDIO_PARAM_PCMMODETYPE pcm;
90 OMX_AUDIO_PARAM_MP3TYPE mp3;
91 OMX_AUDIO_PARAM_AACPROFILETYPE aac;
92 OMX_AUDIO_PARAM_VORBISTYPE vorbis;
93 OMX_AUDIO_PARAM_WMATYPE wma;
94 OMX_AUDIO_PARAM_RATYPE ra;
95 OMX_AUDIO_PARAM_ADPCMTYPE adpcm;
96 OMX_AUDIO_PARAM_G723TYPE g723;
97 OMX_AUDIO_PARAM_G726TYPE g726;
98 OMX_AUDIO_PARAM_G729TYPE g729;
99 OMX_AUDIO_PARAM_AMRTYPE amr;
101 OMX_VIDEO_PARAM_H263TYPE h263;
102 OMX_VIDEO_PARAM_MPEG2TYPE mpeg2;
103 OMX_VIDEO_PARAM_MPEG4TYPE mpeg4;
104 OMX_VIDEO_PARAM_WMVTYPE wmv;
105 OMX_VIDEO_PARAM_RVTYPE rv;
106 OMX_VIDEO_PARAM_AVCTYPE avc;
108 } OmxFormatParam;
110 /*****************************************************************************
111 * Events utility functions
112 *****************************************************************************/
113 typedef struct OmxEvent
115 OMX_EVENTTYPE event;
116 OMX_U32 data_1;
117 OMX_U32 data_2;
118 OMX_PTR event_data;
120 struct OmxEvent *next;
121 } OmxEvent;
123 OMX_ERRORTYPE PostOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE event,
124 OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data);
125 OMX_ERRORTYPE WaitForOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE *event,
126 OMX_U32 *data_1, OMX_U32 *data_2, OMX_PTR *event_data);
127 OMX_ERRORTYPE WaitForSpecificOmxEvent(decoder_t *p_dec,
128 OMX_EVENTTYPE specific_event, OMX_U32 *data_1, OMX_U32 *data_2,
129 OMX_PTR *event_data);
131 /*****************************************************************************
132 * Picture utility functions
133 *****************************************************************************/
134 void CopyOmxPicture( decoder_t *, picture_t *, OMX_BUFFERHEADERTYPE *, int );
135 void CopyVlcPicture( decoder_t *, OMX_BUFFERHEADERTYPE *, picture_t * );
137 /*****************************************************************************
138 * Logging utility functions
139 *****************************************************************************/
140 const char *StateToString(OMX_STATETYPE state);
141 const char *CommandToString(OMX_COMMANDTYPE command);
142 const char *EventToString(OMX_EVENTTYPE event);
143 const char *ErrorToString(OMX_ERRORTYPE error);
145 void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port);
147 /*****************************************************************************
148 * fourcc -> omx id mapping
149 *****************************************************************************/
150 int GetOmxVideoFormat( vlc_fourcc_t i_fourcc,
151 OMX_VIDEO_CODINGTYPE *pi_omx_codec,
152 const char **ppsz_name );
153 int GetVlcVideoFormat( OMX_VIDEO_CODINGTYPE i_omx_codec,
154 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
155 int GetOmxAudioFormat( vlc_fourcc_t i_fourcc,
156 OMX_AUDIO_CODINGTYPE *pi_omx_codec,
157 const char **ppsz_name );
158 int OmxToVlcAudioFormat( OMX_AUDIO_CODINGTYPE i_omx_codec,
159 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
160 const char *GetOmxRole( vlc_fourcc_t i_fourcc, int i_cat, bool b_enc );
161 int GetOmxChromaFormat( vlc_fourcc_t i_fourcc,
162 OMX_COLOR_FORMATTYPE *pi_omx_codec,
163 const char **ppsz_name );
164 int GetVlcChromaFormat( OMX_COLOR_FORMATTYPE i_omx_codec,
165 vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
166 int GetVlcChromaSizes( vlc_fourcc_t i_fourcc,
167 unsigned int width, unsigned int height,
168 unsigned int *size, unsigned int *pitch,
169 unsigned int *chroma_pitch_div );
171 /*****************************************************************************
172 * Functions to deal with audio format parameters
173 *****************************************************************************/
174 OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
175 OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
176 uint8_t i_channels, unsigned int i_samplerate, unsigned int i_bitrate,
177 unsigned int i_bps, unsigned int i_blocksize);
178 OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
179 OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
180 uint8_t *pi_channels, unsigned int *pi_samplerate,
181 unsigned int *pi_bitrate, unsigned int *pi_bps, unsigned int *pi_blocksize);
182 unsigned int GetAudioParamSize(OMX_INDEXTYPE index);
184 /*****************************************************************************
185 * Vendor specific color formats
186 *****************************************************************************/
187 #define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00