]> git.sesse.net Git - vlc/blob - modules/codec/omxil/omxil_utils.h
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / codec / omxil / omxil_utils.h
1 /*****************************************************************************
2  * omxil_utils.h: helper functions
3  *****************************************************************************
4  * Copyright (C) 2010 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * OMX macros
26  *****************************************************************************/
27 #define OMX_INIT_COMMON(a) \
28   (a).nSize = sizeof(a); \
29   (a).nVersion.s.nVersionMajor = 1; \
30   (a).nVersion.s.nVersionMinor = 1; \
31   (a).nVersion.s.nRevision = 1; \
32   (a).nVersion.s.nStep = 0
33
34 #define OMX_INIT_STRUCTURE(a) \
35   memset(&(a), 0, sizeof(a)); \
36   OMX_INIT_COMMON(a)
37
38 #define OMX_ComponentRoleEnum(hComponent, cRole, nIndex) \
39     ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum ? \
40     ((OMX_COMPONENTTYPE*)hComponent)->ComponentRoleEnum(  \
41         hComponent, cRole, nIndex ) : OMX_ErrorNotImplemented
42
43 #define CHECK_ERROR(a, ...) \
44     if(a != OMX_ErrorNone) {msg_Dbg( p_dec, __VA_ARGS__ ); goto error;}
45
46 /*****************************************************************************
47  * OMX buffer FIFO macros
48  *****************************************************************************/
49 #define OMX_FIFO_PEEK(p_fifo, p_buffer) \
50          p_buffer = (p_fifo)->p_first;
51
52 #define OMX_FIFO_GET(p_fifo, p_buffer) \
53     do { vlc_mutex_lock( &(p_fifo)->lock ); \
54          while( !(p_fifo)->p_first ) \
55              vlc_cond_wait( &(p_fifo)->wait, &(p_fifo)->lock ); \
56          p_buffer = (p_fifo)->p_first; \
57          OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
58              ((void **)p_buffer + (p_fifo)->offset); \
59          (p_fifo)->p_first = *pp_next; *pp_next = 0; \
60          if( !(p_fifo)->p_first ) (p_fifo)->pp_last = &(p_fifo)->p_first; \
61          vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
62
63 #define OMX_FIFO_PUT(p_fifo, p_buffer) \
64     do { vlc_mutex_lock (&(p_fifo)->lock);              \
65          OMX_BUFFERHEADERTYPE **pp_next = (OMX_BUFFERHEADERTYPE **) \
66              ((void **)p_buffer + (p_fifo)->offset); \
67          *(p_fifo)->pp_last = p_buffer; \
68          (p_fifo)->pp_last = pp_next; *pp_next = 0; \
69          vlc_cond_signal( &(p_fifo)->wait ); \
70          vlc_mutex_unlock( &(p_fifo)->lock ); } while(0)
71
72 /*****************************************************************************
73  * OMX format parameters
74  *****************************************************************************/
75 typedef union {
76     OMX_PARAM_U32TYPE common;
77     OMX_AUDIO_PARAM_PCMMODETYPE pcm;
78     OMX_AUDIO_PARAM_MP3TYPE mp3;
79     OMX_AUDIO_PARAM_AACPROFILETYPE aac;
80     OMX_AUDIO_PARAM_VORBISTYPE vorbis;
81     OMX_AUDIO_PARAM_WMATYPE wma;
82     OMX_AUDIO_PARAM_RATYPE ra;
83     OMX_AUDIO_PARAM_ADPCMTYPE adpcm;
84     OMX_AUDIO_PARAM_G723TYPE g723;
85     OMX_AUDIO_PARAM_G726TYPE g726;
86     OMX_AUDIO_PARAM_G729TYPE g729;
87     OMX_AUDIO_PARAM_AMRTYPE amr;
88
89     OMX_VIDEO_PARAM_H263TYPE h263;
90     OMX_VIDEO_PARAM_MPEG2TYPE mpeg2;
91     OMX_VIDEO_PARAM_MPEG4TYPE mpeg4;
92     OMX_VIDEO_PARAM_WMVTYPE wmv;
93     OMX_VIDEO_PARAM_RVTYPE rv;
94     OMX_VIDEO_PARAM_AVCTYPE avc;
95
96 } OmxFormatParam;
97
98 /*****************************************************************************
99  * Events utility functions
100  *****************************************************************************/
101 typedef struct OmxEvent
102 {
103     OMX_EVENTTYPE event;
104     OMX_U32 data_1;
105     OMX_U32 data_2;
106     OMX_PTR event_data;
107
108     struct OmxEvent *next;
109 } OmxEvent;
110
111 OMX_ERRORTYPE PostOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE event,
112     OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data);
113 OMX_ERRORTYPE WaitForOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE *event,
114     OMX_U32 *data_1, OMX_U32 *data_2, OMX_PTR *event_data);
115 OMX_ERRORTYPE WaitForSpecificOmxEvent(decoder_t *p_dec,
116     OMX_EVENTTYPE specific_event, OMX_U32 *data_1, OMX_U32 *data_2,
117     OMX_PTR *event_data);
118
119 /*****************************************************************************
120  * Picture utility functions
121  *****************************************************************************/
122 void CopyOmxPicture( decoder_t *, picture_t *, OMX_BUFFERHEADERTYPE * );
123 void CopyVlcPicture( decoder_t *, OMX_BUFFERHEADERTYPE *, picture_t * );
124
125 /*****************************************************************************
126  * Logging utility functions
127  *****************************************************************************/
128 const char *StateToString(OMX_STATETYPE state);
129 const char *CommandToString(OMX_COMMANDTYPE command);
130 const char *EventToString(OMX_EVENTTYPE event);
131 const char *ErrorToString(OMX_ERRORTYPE error);
132
133 void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port);
134
135 /*****************************************************************************
136  * fourcc -> omx id mapping
137  *****************************************************************************/
138 int GetOmxVideoFormat( vlc_fourcc_t i_fourcc,
139                        OMX_VIDEO_CODINGTYPE *pi_omx_codec,
140                        const char **ppsz_name );
141 int GetVlcVideoFormat( OMX_VIDEO_CODINGTYPE i_omx_codec,
142                        vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
143 int GetOmxAudioFormat( vlc_fourcc_t i_fourcc,
144                        OMX_AUDIO_CODINGTYPE *pi_omx_codec,
145                        const char **ppsz_name );
146 int GetVlcAudioFormat( OMX_AUDIO_CODINGTYPE i_omx_codec,
147                        vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
148 const char *GetOmxRole( vlc_fourcc_t i_fourcc, int i_cat, bool b_enc );
149 int GetOmxChromaFormat( vlc_fourcc_t i_fourcc,
150                         OMX_COLOR_FORMATTYPE *pi_omx_codec,
151                         const char **ppsz_name );
152 int GetVlcChromaFormat( OMX_COLOR_FORMATTYPE i_omx_codec,
153                         vlc_fourcc_t *pi_fourcc, const char **ppsz_name );
154 int GetVlcChromaSizes( vlc_fourcc_t i_fourcc,
155                        unsigned int width, unsigned int height,
156                        unsigned int *size, unsigned int *pitch,
157                        unsigned int *chroma_pitch_div );
158
159 /*****************************************************************************
160  * Functions to deal with audio format parameters
161  *****************************************************************************/
162 OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
163     OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
164     uint8_t i_channels, unsigned int i_samplerate, unsigned int i_bitrate,
165     unsigned int i_bps, unsigned int i_blocksize);
166 OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
167     OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
168     uint8_t *pi_channels, unsigned int *pi_samplerate,
169     unsigned int *pi_bitrate, unsigned int *pi_bps, unsigned int *pi_blocksize);