1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#include "mmal.h"
29#include "util/mmal_il.h"
30#include "interface/vmcs_host/khronos/IL/OMX_Broadcom.h"
31
32/*****************************************************************************/
33static struct {
34 MMAL_STATUS_T mmal;
35 OMX_ERRORTYPE omx;
36} mmal_omx_error[] =
37{
38 {MMAL_SUCCESS, OMX_ErrorNone},
39 {MMAL_ENOMEM, OMX_ErrorInsufficientResources},
40 {MMAL_ENOSPC, OMX_ErrorInsufficientResources},
41 {MMAL_EINVAL, OMX_ErrorBadParameter},
42 {MMAL_ENOSYS, OMX_ErrorNotImplemented},
43 {(MMAL_STATUS_T)-1, OMX_ErrorUndefined},
44};
45
46OMX_ERRORTYPE mmalil_error_to_omx(MMAL_STATUS_T status)
47{
48 unsigned int i;
49 for(i = 0; mmal_omx_error[i].mmal != (MMAL_STATUS_T)-1; i++)
50 if(mmal_omx_error[i].mmal == status) break;
51 return mmal_omx_error[i].omx;
52}
53
54MMAL_STATUS_T mmalil_error_to_mmal(OMX_ERRORTYPE error)
55{
56 unsigned int i;
57 for(i = 0; mmal_omx_error[i].mmal != (MMAL_STATUS_T)-1; i++)
58 if(mmal_omx_error[i].omx == error) break;
59 return mmal_omx_error[i].mmal;
60}
61
62/*****************************************************************************/
63OMX_U32 mmalil_buffer_flags_to_omx(uint32_t flags)
64{
65 OMX_U32 omx_flags = 0;
66
67 if(flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
68 omx_flags |= OMX_BUFFERFLAG_SYNCFRAME;
69 if(flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END)
70 omx_flags |= OMX_BUFFERFLAG_ENDOFFRAME;
71 if(flags & MMAL_BUFFER_HEADER_FLAG_EOS)
72 omx_flags |= OMX_BUFFERFLAG_EOS;
73 if(flags & MMAL_BUFFER_HEADER_FLAG_CONFIG)
74 omx_flags |= OMX_BUFFERFLAG_CODECCONFIG;
75 if(flags & MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY)
76 omx_flags |= OMX_BUFFERFLAG_DISCONTINUITY;
77 if (flags & MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO)
78 omx_flags |= OMX_BUFFERFLAG_CODECSIDEINFO;
79 if (flags & MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT)
80 omx_flags |= OMX_BUFFERFLAG_CAPTURE_PREVIEW;
81 if (flags & MMAL_BUFFER_HEADER_FLAG_CORRUPTED)
82 omx_flags |= OMX_BUFFERFLAG_DATACORRUPT;
83 if (flags & MMAL_BUFFER_HEADER_FLAG_DECODEONLY)
84 omx_flags |= OMX_BUFFERFLAG_DECODEONLY;
85 if (flags & MMAL_BUFFER_HEADER_VIDEO_FLAG_INTERLACED)
86 omx_flags |= OMX_BUFFERFLAG_INTERLACED;
87 if (flags & MMAL_BUFFER_HEADER_VIDEO_FLAG_TOP_FIELD_FIRST)
88 omx_flags |= OMX_BUFFERFLAG_TOP_FIELD_FIRST;
89 if (flags & MMAL_BUFFER_HEADER_FLAG_NAL_END)
90 omx_flags |= OMX_BUFFERFLAG_ENDOFNAL;
91
92 if (flags & MMAL_BUFFER_HEADER_FLAG_USER0)
93 omx_flags |= OMX_BUFFERFLAG_USR0;
94 if (flags & MMAL_BUFFER_HEADER_FLAG_USER1)
95 omx_flags |= OMX_BUFFERFLAG_USR1;
96 if (flags & MMAL_BUFFER_HEADER_FLAG_USER2)
97 omx_flags |= OMX_BUFFERFLAG_USR2;
98 if (flags & MMAL_BUFFER_HEADER_FLAG_USER3)
99 omx_flags |= OMX_BUFFERFLAG_USR3;
100
101 return omx_flags;
102}
103
104uint32_t mmalil_buffer_flags_to_mmal(OMX_U32 flags)
105{
106 uint32_t mmal_flags = 0;
107
108 if (flags & OMX_BUFFERFLAG_SYNCFRAME)
109 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_KEYFRAME;
110 if (flags & OMX_BUFFERFLAG_ENDOFFRAME)
111 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;
112 if (flags & OMX_BUFFERFLAG_EOS)
113 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_EOS;
114 if (flags & OMX_BUFFERFLAG_CODECCONFIG)
115 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG;
116 if (flags & OMX_BUFFERFLAG_DISCONTINUITY)
117 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY;
118 if (flags & OMX_BUFFERFLAG_CODECSIDEINFO)
119 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO;
120 if (flags & OMX_BUFFERFLAG_CAPTURE_PREVIEW)
121 mmal_flags |= MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT;
122 if (flags & OMX_BUFFERFLAG_DATACORRUPT)
123 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_CORRUPTED;
124 if (flags & OMX_BUFFERFLAG_DECODEONLY)
125 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_DECODEONLY;
126 if (flags & OMX_BUFFERFLAG_INTERLACED)
127 mmal_flags |= MMAL_BUFFER_HEADER_VIDEO_FLAG_INTERLACED;
128 if (flags & OMX_BUFFERFLAG_TOP_FIELD_FIRST)
129 mmal_flags |= MMAL_BUFFER_HEADER_VIDEO_FLAG_TOP_FIELD_FIRST;
130 if (flags & OMX_BUFFERFLAG_ENDOFNAL)
131 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_NAL_END;
132
133 if (flags & OMX_BUFFERFLAG_USR0)
134 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_USER0;
135 if (flags & OMX_BUFFERFLAG_USR1)
136 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_USER1;
137 if (flags & OMX_BUFFERFLAG_USR2)
138 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_USER2;
139 if (flags & OMX_BUFFERFLAG_USR3)
140 mmal_flags |= MMAL_BUFFER_HEADER_FLAG_USER3;
141
142 return mmal_flags;
143}
144
145OMX_U32 mmalil_video_buffer_flags_to_omx(uint32_t flags)
146{
147 OMX_U32 omx_flags = 0;
148
149 if (flags & MMAL_BUFFER_HEADER_VIDEO_FLAG_INTERLACED)
150 omx_flags |= OMX_BUFFERFLAG_INTERLACED;
151 if (flags & MMAL_BUFFER_HEADER_VIDEO_FLAG_TOP_FIELD_FIRST)
152 omx_flags |= OMX_BUFFERFLAG_TOP_FIELD_FIRST;
153
154 return omx_flags;
155}
156
157uint32_t mmalil_video_buffer_flags_to_mmal(OMX_U32 flags)
158{
159 uint32_t mmal_flags = 0;
160
161 if (flags & OMX_BUFFERFLAG_INTERLACED)
162 mmal_flags |= MMAL_BUFFER_HEADER_VIDEO_FLAG_INTERLACED;
163 if (flags & OMX_BUFFERFLAG_TOP_FIELD_FIRST)
164 mmal_flags |= MMAL_BUFFER_HEADER_VIDEO_FLAG_TOP_FIELD_FIRST;
165
166 return mmal_flags;
167}
168
169/*****************************************************************************/
170void mmalil_buffer_header_to_omx(OMX_BUFFERHEADERTYPE *omx, MMAL_BUFFER_HEADER_T *mmal)
171{
172 omx->pBuffer = mmal->data;
173 omx->nAllocLen = mmal->alloc_size;
174 omx->nFilledLen = mmal->length;
175 omx->nOffset = mmal->offset;
176 omx->nFlags = mmalil_buffer_flags_to_omx(mmal->flags);
177 omx->nTimeStamp = omx_ticks_from_s64(mmal->pts);
178 if (mmal->pts == MMAL_TIME_UNKNOWN)
179 {
180 if (mmal->dts == MMAL_TIME_UNKNOWN)
181 {
182 omx->nTimeStamp = omx_ticks_from_s64(0);
183 omx->nFlags |= OMX_BUFFERFLAG_TIME_UNKNOWN;
184 }
185 else
186 {
187 omx->nTimeStamp = omx_ticks_from_s64(mmal->dts);
188 omx->nFlags |= OMX_BUFFERFLAG_TIME_IS_DTS;
189 }
190 }
191}
192
193void mmalil_buffer_header_to_mmal(MMAL_BUFFER_HEADER_T *mmal, OMX_BUFFERHEADERTYPE *omx)
194{
195 mmal->cmd = 0;
196 mmal->data = omx->pBuffer;
197 mmal->alloc_size = omx->nAllocLen;
198 mmal->length = omx->nFilledLen;
199 mmal->offset = omx->nOffset;
200 if (omx->nFlags & OMX_BUFFERFLAG_TIME_IS_DTS)
201 {
202 mmal->dts = omx_ticks_to_s64(omx->nTimeStamp);
203 mmal->pts = MMAL_TIME_UNKNOWN;
204 }
205 else if (omx->nFlags & OMX_BUFFERFLAG_TIME_UNKNOWN)
206 {
207 mmal->dts = MMAL_TIME_UNKNOWN;
208 mmal->pts = MMAL_TIME_UNKNOWN;
209 }
210 else
211 {
212 mmal->dts = MMAL_TIME_UNKNOWN;
213 mmal->pts = omx_ticks_to_s64(omx->nTimeStamp);
214 }
215 mmal->flags = mmalil_buffer_flags_to_mmal(omx->nFlags);
216}
217
218/*****************************************************************************/
219static struct {
220 MMAL_ES_TYPE_T type;
221 OMX_PORTDOMAINTYPE domain;
222} mmal_omx_es_type_table[] =
223{
224 {MMAL_ES_TYPE_VIDEO, OMX_PortDomainVideo},
225 {MMAL_ES_TYPE_VIDEO, OMX_PortDomainImage},
226 {MMAL_ES_TYPE_AUDIO, OMX_PortDomainAudio},
227 {MMAL_ES_TYPE_UNKNOWN, OMX_PortDomainMax}
228};
229
230OMX_PORTDOMAINTYPE mmalil_es_type_to_omx_domain(MMAL_ES_TYPE_T type)
231{
232 unsigned int i;
233 for(i = 0; mmal_omx_es_type_table[i].type != MMAL_ES_TYPE_UNKNOWN; i++)
234 if(mmal_omx_es_type_table[i].type == type) break;
235 return mmal_omx_es_type_table[i].domain;
236}
237
238MMAL_ES_TYPE_T mmalil_omx_domain_to_es_type(OMX_PORTDOMAINTYPE domain)
239{
240 unsigned int i;
241 for(i = 0; mmal_omx_es_type_table[i].type != MMAL_ES_TYPE_UNKNOWN; i++)
242 if(mmal_omx_es_type_table[i].domain == domain) break;
243 return mmal_omx_es_type_table[i].type;
244}
245
246/*****************************************************************************/
247static struct {
248 uint32_t encoding;
249 OMX_AUDIO_CODINGTYPE coding;
250} mmal_omx_audio_coding_table[] =
251{
252 {MMAL_ENCODING_MP4A, OMX_AUDIO_CodingAAC},
253 {MMAL_ENCODING_MPGA, OMX_AUDIO_CodingMP3},
254 {MMAL_ENCODING_WMA2, OMX_AUDIO_CodingWMA},
255 {MMAL_ENCODING_WMA1, OMX_AUDIO_CodingWMA},
256 {MMAL_ENCODING_AMRNB, OMX_AUDIO_CodingAMR},
257 {MMAL_ENCODING_AMRWB, OMX_AUDIO_CodingAMR},
258 {MMAL_ENCODING_AMRWBP, OMX_AUDIO_CodingAMR},
259 {MMAL_ENCODING_VORBIS, OMX_AUDIO_CodingVORBIS},
260 {MMAL_ENCODING_ALAW, OMX_AUDIO_CodingPCM},
261 {MMAL_ENCODING_MULAW, OMX_AUDIO_CodingPCM},
262 {MMAL_ENCODING_PCM_SIGNED_LE, OMX_AUDIO_CodingPCM},
263 {MMAL_ENCODING_PCM_UNSIGNED_LE,OMX_AUDIO_CodingPCM},
264 {MMAL_ENCODING_PCM_SIGNED_BE, OMX_AUDIO_CodingPCM},
265 {MMAL_ENCODING_PCM_UNSIGNED_BE,OMX_AUDIO_CodingPCM},
266 {MMAL_ENCODING_AC3, OMX_AUDIO_CodingDDP},
267 {MMAL_ENCODING_EAC3, OMX_AUDIO_CodingDDP},
268 {MMAL_ENCODING_DTS, OMX_AUDIO_CodingDTS},
269 {MMAL_ENCODING_UNKNOWN, OMX_AUDIO_CodingUnused}
270};
271
272uint32_t mmalil_omx_audio_coding_to_encoding(OMX_AUDIO_CODINGTYPE coding)
273{
274 unsigned int i;
275 for(i = 0; mmal_omx_audio_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
276 if(mmal_omx_audio_coding_table[i].coding == coding) break;
277 return mmal_omx_audio_coding_table[i].encoding;
278}
279
280OMX_AUDIO_CODINGTYPE mmalil_encoding_to_omx_audio_coding(uint32_t encoding)
281{
282 unsigned int i;
283 for(i = 0; mmal_omx_audio_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
284 if(mmal_omx_audio_coding_table[i].encoding == encoding) break;
285 return mmal_omx_audio_coding_table[i].coding;
286}
287
288static struct {
289 OMX_AUDIO_CODINGTYPE coding;
290 OMX_INDEXTYPE index;
291 unsigned int size;
292} mmal_omx_audio_format_table[] =
293{
294 {OMX_AUDIO_CodingPCM, OMX_IndexParamAudioPcm, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)},
295 {OMX_AUDIO_CodingADPCM, OMX_IndexParamAudioAdpcm, sizeof(OMX_AUDIO_PARAM_ADPCMTYPE)},
296 {OMX_AUDIO_CodingAMR, OMX_IndexParamAudioAmr, sizeof(OMX_AUDIO_PARAM_AMRTYPE)},
297 {OMX_AUDIO_CodingGSMFR, OMX_IndexParamAudioGsm_FR, sizeof(OMX_AUDIO_PARAM_GSMFRTYPE)},
298 {OMX_AUDIO_CodingGSMEFR, OMX_IndexParamAudioGsm_EFR, sizeof(OMX_AUDIO_PARAM_GSMEFRTYPE)},
299 {OMX_AUDIO_CodingGSMHR, OMX_IndexParamAudioGsm_HR, sizeof(OMX_AUDIO_PARAM_GSMHRTYPE)},
300 {OMX_AUDIO_CodingPDCFR, OMX_IndexParamAudioPdc_FR, sizeof(OMX_AUDIO_PARAM_PDCFRTYPE)},
301 {OMX_AUDIO_CodingPDCEFR, OMX_IndexParamAudioPdc_EFR, sizeof(OMX_AUDIO_PARAM_PDCEFRTYPE)},
302 {OMX_AUDIO_CodingPDCHR, OMX_IndexParamAudioPdc_HR, sizeof(OMX_AUDIO_PARAM_PDCHRTYPE)},
303 {OMX_AUDIO_CodingTDMAFR, OMX_IndexParamAudioTdma_FR, sizeof(OMX_AUDIO_PARAM_TDMAFRTYPE)},
304 {OMX_AUDIO_CodingTDMAEFR, OMX_IndexParamAudioTdma_EFR, sizeof(OMX_AUDIO_PARAM_TDMAEFRTYPE)},
305 {OMX_AUDIO_CodingQCELP8, OMX_IndexParamAudioQcelp8, sizeof(OMX_AUDIO_PARAM_QCELP8TYPE)},
306 {OMX_AUDIO_CodingQCELP13, OMX_IndexParamAudioQcelp13, sizeof(OMX_AUDIO_PARAM_QCELP13TYPE)},
307 {OMX_AUDIO_CodingEVRC, OMX_IndexParamAudioEvrc, sizeof(OMX_AUDIO_PARAM_EVRCTYPE)},
308 {OMX_AUDIO_CodingSMV, OMX_IndexParamAudioSmv, sizeof(OMX_AUDIO_PARAM_SMVTYPE)},
309 {OMX_AUDIO_CodingG723, OMX_IndexParamAudioG723, sizeof(OMX_AUDIO_PARAM_G723TYPE)},
310 {OMX_AUDIO_CodingG726, OMX_IndexParamAudioG726, sizeof(OMX_AUDIO_PARAM_G726TYPE)},
311 {OMX_AUDIO_CodingG729, OMX_IndexParamAudioG729, sizeof(OMX_AUDIO_PARAM_G729TYPE)},
312 {OMX_AUDIO_CodingAAC, OMX_IndexParamAudioAac, sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE)},
313 {OMX_AUDIO_CodingMP3, OMX_IndexParamAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE)},
314 {OMX_AUDIO_CodingSBC, OMX_IndexParamAudioSbc, sizeof(OMX_AUDIO_PARAM_SBCTYPE)},
315 {OMX_AUDIO_CodingVORBIS, OMX_IndexParamAudioVorbis, sizeof(OMX_AUDIO_PARAM_VORBISTYPE)},
316 {OMX_AUDIO_CodingWMA, OMX_IndexParamAudioWma, sizeof(OMX_AUDIO_PARAM_WMATYPE)},
317 {OMX_AUDIO_CodingRA, OMX_IndexParamAudioRa, sizeof(OMX_AUDIO_PARAM_RATYPE)},
318 {OMX_AUDIO_CodingMIDI, OMX_IndexParamAudioMidi, sizeof(OMX_AUDIO_PARAM_MIDITYPE)},
319 {OMX_AUDIO_CodingDDP, OMX_IndexParamAudioDdp, sizeof(OMX_AUDIO_PARAM_DDPTYPE)},
320 {OMX_AUDIO_CodingDTS, OMX_IndexParamAudioDts, sizeof(OMX_AUDIO_PARAM_DTSTYPE)},
321 {OMX_AUDIO_CodingUnused, 0, 0}
322};
323
324OMX_AUDIO_CODINGTYPE mmalil_omx_audio_param_index_to_coding(OMX_INDEXTYPE index)
325{
326 unsigned int i;
327 for(i = 0; mmal_omx_audio_format_table[i].coding != OMX_AUDIO_CodingUnused; i++)
328 if(mmal_omx_audio_format_table[i].index == index) break;
329
330 return mmal_omx_audio_format_table[i].coding;
331}
332
333OMX_INDEXTYPE mmalil_omx_audio_param_index(OMX_AUDIO_CODINGTYPE coding, OMX_U32 *size)
334{
335 unsigned int i;
336 for(i = 0; mmal_omx_audio_format_table[i].coding != OMX_AUDIO_CodingUnused; i++)
337 if(mmal_omx_audio_format_table[i].coding == coding) break;
338
339 if(size) *size = mmal_omx_audio_format_table[i].size;
340 return mmal_omx_audio_format_table[i].index;
341}
342
343MMAL_STATUS_T mmalil_omx_default_channel_mapping(OMX_AUDIO_CHANNELTYPE *channel_mapping, unsigned int nchannels)
344{
345 static const OMX_AUDIO_CHANNELTYPE default_mapping[][8] = {
346 {OMX_AUDIO_ChannelNone},
347 {OMX_AUDIO_ChannelCF},
348 {OMX_AUDIO_ChannelLF, OMX_AUDIO_ChannelRF},
349 {OMX_AUDIO_ChannelLF, OMX_AUDIO_ChannelRF, OMX_AUDIO_ChannelCF},
350 {OMX_AUDIO_ChannelLF, OMX_AUDIO_ChannelRF, OMX_AUDIO_ChannelCF,
351 OMX_AUDIO_ChannelCS},
352 {OMX_AUDIO_ChannelLF, OMX_AUDIO_ChannelRF, OMX_AUDIO_ChannelCF,
353 OMX_AUDIO_ChannelLR, OMX_AUDIO_ChannelRR},
354 {OMX_AUDIO_ChannelLF, OMX_AUDIO_ChannelRF, OMX_AUDIO_ChannelCF,
355 OMX_AUDIO_ChannelLFE, OMX_AUDIO_ChannelLR, OMX_AUDIO_ChannelRR},
356 {OMX_AUDIO_ChannelLF, OMX_AUDIO_ChannelRF, OMX_AUDIO_ChannelCF,
357 OMX_AUDIO_ChannelLFE, OMX_AUDIO_ChannelLR, OMX_AUDIO_ChannelRR,
358 OMX_AUDIO_ChannelCS},
359 {OMX_AUDIO_ChannelLF, OMX_AUDIO_ChannelRF, OMX_AUDIO_ChannelCF,
360 OMX_AUDIO_ChannelLFE, OMX_AUDIO_ChannelLR, OMX_AUDIO_ChannelRR,
361 OMX_AUDIO_ChannelLS, OMX_AUDIO_ChannelRS}
362 };
363
364 if (!nchannels || nchannels >= MMAL_COUNTOF(default_mapping))
365 return MMAL_EINVAL;
366
367 memcpy(channel_mapping, default_mapping[nchannels],
368 sizeof(default_mapping[0][0]) * nchannels);
369 return MMAL_SUCCESS;
370}
371
372MMAL_FOURCC_T mmalil_omx_audio_param_to_format(MMAL_ES_FORMAT_T *format,
373 OMX_AUDIO_CODINGTYPE coding, OMX_FORMAT_PARAM_TYPE *param)
374{
375 MMAL_AUDIO_FORMAT_T *audio = &format->es->audio;
376 format->encoding = mmalil_omx_audio_coding_to_encoding(coding);
377 format->encoding_variant = 0;
378
379 switch(coding)
380 {
381 case OMX_AUDIO_CodingPCM:
382 audio->channels = param->pcm.nChannels;
383 audio->sample_rate = param->pcm.nSamplingRate;
384 audio->bits_per_sample = param->pcm.nBitPerSample;
385 if(param->pcm.ePCMMode == OMX_AUDIO_PCMModeLinear && param->pcm.bInterleaved)
386 {
387 if(param->pcm.eEndian == OMX_EndianBig &&
388 param->pcm.eNumData == OMX_NumericalDataSigned)
389 format->encoding = MMAL_ENCODING_PCM_SIGNED_BE;
390 else if(param->pcm.eEndian == OMX_EndianLittle &&
391 param->pcm.eNumData == OMX_NumericalDataSigned)
392 format->encoding = MMAL_ENCODING_PCM_SIGNED_LE;
393 if(param->pcm.eEndian == OMX_EndianBig &&
394 param->pcm.eNumData == OMX_NumericalDataUnsigned)
395 format->encoding = MMAL_ENCODING_PCM_UNSIGNED_BE;
396 if(param->pcm.eEndian == OMX_EndianLittle &&
397 param->pcm.eNumData == OMX_NumericalDataUnsigned)
398 format->encoding = MMAL_ENCODING_PCM_UNSIGNED_LE;
399 }
400 else if(param->pcm.ePCMMode == OMX_AUDIO_PCMModeALaw)
401 format->encoding = MMAL_ENCODING_ALAW;
402 else if(param->pcm.ePCMMode == OMX_AUDIO_PCMModeMULaw)
403 format->encoding = MMAL_ENCODING_MULAW;
404 break;
405 case OMX_AUDIO_CodingAAC:
406 audio->channels = param->aac.nChannels;
407 audio->sample_rate = param->aac.nSampleRate;
408 format->bitrate = param->aac.nBitRate;
409 switch(param->aac.eAACStreamFormat)
410 {
411 case OMX_AUDIO_AACStreamFormatMP2ADTS:
412 case OMX_AUDIO_AACStreamFormatMP4ADTS:
413 format->encoding = MMAL_ENCODING_MP4A;
414 format->encoding_variant = MMAL_ENCODING_VARIANT_MP4A_ADTS;
415 break;
416 case OMX_AUDIO_AACStreamFormatMP4FF:
417 case OMX_AUDIO_AACStreamFormatRAW:
418 format->encoding = MMAL_ENCODING_MP4A;
419 format->encoding_variant = MMAL_ENCODING_VARIANT_MP4A_DEFAULT;
420 break;
421 default: break;
422 }
423 break;
424 case OMX_AUDIO_CodingMP3:
425 format->encoding = MMAL_ENCODING_MPGA;
426 audio->channels = param->mp3.nChannels;
427 audio->sample_rate = param->mp3.nSampleRate;
428 format->bitrate = param->mp3.nBitRate;
429 break;
430 case OMX_AUDIO_CodingWMA:
431 audio->channels = param->wma.nChannels;
432 audio->sample_rate = param->wma.nSamplingRate;
433 audio->block_align = param->wma.nBlockAlign;
434 format->bitrate = param->wma.nBitRate;
435 switch(param->wma.eFormat)
436 {
437 case OMX_AUDIO_WMAFormat7:
438 format->encoding = MMAL_ENCODING_WMA1;
439 break;
440 case OMX_AUDIO_WMAFormat8:
441 case OMX_AUDIO_WMAFormat9:
442 format->encoding = MMAL_ENCODING_WMA2;
443 break;
444 default: break;
445 }
446 break;
447 case OMX_AUDIO_CodingVORBIS:
448 audio->channels = param->vorbis.nChannels;
449 audio->sample_rate = param->vorbis.nSampleRate;
450 format->bitrate = param->vorbis.nBitRate;
451 break;
452 case OMX_AUDIO_CodingAMR:
453 audio->channels = param->amr.nChannels;
454 audio->sample_rate = 8000;
455 format->bitrate = param->amr.nBitRate;
456 if(param->amr.eAMRBandMode >= OMX_AUDIO_AMRBandModeNB0 &&
457 param->amr.eAMRBandMode <= OMX_AUDIO_AMRBandModeNB7)
458 format->encoding = MMAL_ENCODING_AMRNB;
459 if(param->amr.eAMRBandMode >= OMX_AUDIO_AMRBandModeWB0 &&
460 param->amr.eAMRBandMode <= OMX_AUDIO_AMRBandModeWB8)
461 format->encoding = MMAL_ENCODING_AMRWB;
462 break;
463 case OMX_AUDIO_CodingDDP:
464 audio->channels = param->ddp.nChannels;
465 audio->sample_rate = param->ddp.nSampleRate;
466 if(param->ddp.eBitStreamId > OMX_AUDIO_DDPBitStreamIdAC3)
467 format->encoding = MMAL_ENCODING_EAC3;
468 break;
469 case OMX_AUDIO_CodingDTS:
470 audio->channels = param->dts.nChannels;
471 audio->sample_rate = param->dts.nSampleRate;
472 audio->block_align = param->dts.nDtsFrameSizeBytes;
473 break;
474
475 case OMX_AUDIO_CodingADPCM:
476 case OMX_AUDIO_CodingGSMFR:
477 case OMX_AUDIO_CodingGSMEFR:
478 case OMX_AUDIO_CodingGSMHR:
479 case OMX_AUDIO_CodingPDCFR:
480 case OMX_AUDIO_CodingPDCEFR:
481 case OMX_AUDIO_CodingPDCHR:
482 case OMX_AUDIO_CodingTDMAFR:
483 case OMX_AUDIO_CodingTDMAEFR:
484 case OMX_AUDIO_CodingQCELP8:
485 case OMX_AUDIO_CodingQCELP13:
486 case OMX_AUDIO_CodingEVRC:
487 case OMX_AUDIO_CodingSMV:
488 case OMX_AUDIO_CodingG711:
489 case OMX_AUDIO_CodingG723:
490 case OMX_AUDIO_CodingG726:
491 case OMX_AUDIO_CodingG729:
492 case OMX_AUDIO_CodingSBC:
493 case OMX_AUDIO_CodingRA:
494 case OMX_AUDIO_CodingMIDI:
495 default:
496 vcos_assert(0);
497 break;
498 }
499
500 return format->encoding;
501}
502
503OMX_AUDIO_CODINGTYPE mmalil_format_to_omx_audio_param(OMX_FORMAT_PARAM_TYPE *param,
504 OMX_INDEXTYPE *param_index, MMAL_ES_FORMAT_T *format)
505{
506 MMAL_AUDIO_FORMAT_T *audio = &format->es->audio;
507 OMX_AUDIO_CODINGTYPE coding = mmalil_encoding_to_omx_audio_coding(format->encoding);
508 OMX_U32 size = 0;
509 OMX_INDEXTYPE index = mmalil_omx_audio_param_index(coding, &size);
510
511 if(param_index) *param_index = index;
512 memset(param, 0, size);
513 param->common.nSize = size;
514
515 switch(coding)
516 {
517 case OMX_AUDIO_CodingPCM:
518 param->pcm.nChannels = audio->channels;
519 param->pcm.nSamplingRate = audio->sample_rate;
520 param->pcm.nBitPerSample = audio->bits_per_sample;
521 mmalil_omx_default_channel_mapping(param->pcm.eChannelMapping, audio->channels);
522 if(format->encoding == MMAL_ENCODING_PCM_SIGNED_BE ||
523 format->encoding == MMAL_ENCODING_PCM_SIGNED_LE ||
524 format->encoding == MMAL_ENCODING_PCM_UNSIGNED_BE ||
525 format->encoding == MMAL_ENCODING_PCM_UNSIGNED_LE)
526 {
527 param->pcm.ePCMMode = OMX_AUDIO_PCMModeLinear;
528 param->pcm.bInterleaved = OMX_TRUE;
529 param->pcm.eEndian = OMX_EndianLittle;
530 param->pcm.eNumData = OMX_NumericalDataSigned;
531 if(format->encoding == MMAL_ENCODING_PCM_SIGNED_BE ||
532 format->encoding == MMAL_ENCODING_PCM_UNSIGNED_BE)
533 param->pcm.eEndian = OMX_EndianBig;
534 if(format->encoding == MMAL_ENCODING_PCM_UNSIGNED_LE ||
535 format->encoding == MMAL_ENCODING_PCM_UNSIGNED_BE)
536 param->pcm.eNumData = OMX_NumericalDataUnsigned;
537 }
538 else if(format->encoding == MMAL_ENCODING_ALAW)
539 param->pcm.ePCMMode = OMX_AUDIO_PCMModeALaw;
540 else if(format->encoding == MMAL_ENCODING_MULAW)
541 param->pcm.ePCMMode = OMX_AUDIO_PCMModeMULaw;
542 break;
543 case OMX_AUDIO_CodingAAC:
544 param->aac.nChannels = audio->channels;
545 param->aac.nSampleRate = audio->sample_rate;
546 param->aac.nBitRate = format->bitrate;
547 switch(format->encoding_variant)
548 {
549 case MMAL_ENCODING_VARIANT_MP4A_ADTS:
550 param->aac.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4ADTS;
551 break;
552 case MMAL_ENCODING_VARIANT_MP4A_DEFAULT:
553 param->aac.eAACStreamFormat = OMX_AUDIO_AACStreamFormatRAW;
554 break;
555 default: break;
556 }
557 break;
558 case OMX_AUDIO_CodingMP3:
559 param->mp3.nChannels = audio->channels;
560 param->mp3.nSampleRate = audio->sample_rate;
561 param->mp3.nBitRate = format->bitrate;
562 break;
563 case OMX_AUDIO_CodingWMA:
564 param->wma.nChannels = audio->channels;
565 param->wma.nSamplingRate = audio->sample_rate;
566 param->wma.nBlockAlign = audio->block_align;
567 param->wma.nBitRate = format->bitrate;
568 switch(format->encoding)
569 {
570 case MMAL_ENCODING_WMA1:
571 param->wma.eFormat = OMX_AUDIO_WMAFormat7;
572 break;
573 case MMAL_ENCODING_WMA2:
574 param->wma.eFormat = OMX_AUDIO_WMAFormat8;
575 break;
576 default: break;
577 }
578 break;
579 case OMX_AUDIO_CodingVORBIS:
580 param->vorbis.nChannels = audio->channels;
581 param->vorbis.nSampleRate = audio->sample_rate;
582 param->vorbis.nBitRate = format->bitrate;
583 break;
584 case OMX_AUDIO_CodingAMR:
585 param->amr.nChannels = audio->channels;
586 param->amr.nBitRate = format->bitrate;
587 if(format->encoding == MMAL_ENCODING_AMRNB)
588 param->amr.eAMRBandMode = OMX_AUDIO_AMRBandModeNB0;
589 if(format->encoding == MMAL_ENCODING_AMRWB)
590 param->amr.eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
591 break;
592 case OMX_AUDIO_CodingDDP:
593 param->ddp.nChannels = audio->channels;
594 param->ddp.nSampleRate = audio->sample_rate;
595 param->ddp.eBitStreamId = OMX_AUDIO_DDPBitStreamIdAC3;
596 if(format->encoding == MMAL_ENCODING_EAC3)
597 param->ddp.eBitStreamId = OMX_AUDIO_DDPBitStreamIdEAC3;
598 param->ddp.eBitStreamMode = 0;
599 param->ddp.eDolbySurroundMode = 0;
600 mmalil_omx_default_channel_mapping(param->ddp.eChannelMapping, audio->channels);
601 break;
602 case OMX_AUDIO_CodingDTS:
603 param->dts.nChannels = audio->channels;
604 param->dts.nSampleRate = audio->sample_rate;
605 param->dts.nDtsFrameSizeBytes = audio->block_align;
606 param->dts.nDtsType = 1;
607 param->dts.nFormat = 0;
608 mmalil_omx_default_channel_mapping(param->dts.eChannelMapping, audio->channels);
609 break;
610 case OMX_AUDIO_CodingADPCM:
611 case OMX_AUDIO_CodingGSMFR:
612 case OMX_AUDIO_CodingGSMEFR:
613 case OMX_AUDIO_CodingGSMHR:
614 case OMX_AUDIO_CodingPDCFR:
615 case OMX_AUDIO_CodingPDCEFR:
616 case OMX_AUDIO_CodingPDCHR:
617 case OMX_AUDIO_CodingTDMAFR:
618 case OMX_AUDIO_CodingTDMAEFR:
619 case OMX_AUDIO_CodingQCELP8:
620 case OMX_AUDIO_CodingQCELP13:
621 case OMX_AUDIO_CodingEVRC:
622 case OMX_AUDIO_CodingSMV:
623 case OMX_AUDIO_CodingG711:
624 case OMX_AUDIO_CodingG723:
625 case OMX_AUDIO_CodingG726:
626 case OMX_AUDIO_CodingG729:
627 case OMX_AUDIO_CodingSBC:
628 case OMX_AUDIO_CodingRA:
629 case OMX_AUDIO_CodingMIDI:
630 default:
631 vcos_assert(0);
632 break;
633 }
634
635 return coding;
636}
637
638/*****************************************************************************/
639static struct {
640 uint32_t encoding;
641 OMX_VIDEO_CODINGTYPE coding;
642} mmal_omx_video_coding_table[] =
643{
644 {MMAL_ENCODING_H264, OMX_VIDEO_CodingAVC},
645 {MMAL_ENCODING_MVC, OMX_VIDEO_CodingMVC},
646 {MMAL_ENCODING_MP4V, OMX_VIDEO_CodingMPEG4},
647 {MMAL_ENCODING_MP2V, OMX_VIDEO_CodingMPEG2},
648 {MMAL_ENCODING_MP1V, OMX_VIDEO_CodingMPEG2},
649 {MMAL_ENCODING_H263, OMX_VIDEO_CodingH263},
650 {MMAL_ENCODING_WVC1, OMX_VIDEO_CodingWMV},
651 {MMAL_ENCODING_WMV3, OMX_VIDEO_CodingWMV},
652 {MMAL_ENCODING_WMV2, OMX_VIDEO_CodingWMV},
653 {MMAL_ENCODING_WMV1, OMX_VIDEO_CodingWMV},
654 {MMAL_ENCODING_VP6, OMX_VIDEO_CodingVP6},
655 {MMAL_ENCODING_VP7, OMX_VIDEO_CodingVP7},
656 {MMAL_ENCODING_VP8, OMX_VIDEO_CodingVP8},
657 {MMAL_ENCODING_SPARK, OMX_VIDEO_CodingSorenson},
658 {MMAL_ENCODING_THEORA, OMX_VIDEO_CodingTheora},
659 {MMAL_ENCODING_MJPEG, OMX_VIDEO_CodingMJPEG},
660 {MMAL_ENCODING_UNKNOWN, OMX_VIDEO_CodingUnused}
661};
662
663uint32_t mmalil_omx_video_coding_to_encoding(OMX_VIDEO_CODINGTYPE coding)
664{
665 unsigned int i;
666 for(i = 0; mmal_omx_video_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
667 if(mmal_omx_video_coding_table[i].coding == coding) break;
668 return mmal_omx_video_coding_table[i].encoding;
669}
670
671OMX_VIDEO_CODINGTYPE mmalil_encoding_to_omx_video_coding(uint32_t encoding)
672{
673 unsigned int i;
674 for(i = 0; mmal_omx_video_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
675 if(mmal_omx_video_coding_table[i].encoding == encoding) break;
676 return mmal_omx_video_coding_table[i].coding;
677}
678
679/*****************************************************************************/
680static struct {
681 uint32_t encoding;
682 OMX_IMAGE_CODINGTYPE coding;
683} mmal_omx_image_coding_table[] =
684{
685 {MMAL_ENCODING_JPEG, OMX_IMAGE_CodingJPEG},
686 {MMAL_ENCODING_GIF, OMX_IMAGE_CodingGIF},
687 {MMAL_ENCODING_PNG, OMX_IMAGE_CodingPNG},
688 {MMAL_ENCODING_BMP, OMX_IMAGE_CodingBMP},
689 {MMAL_ENCODING_TGA, OMX_IMAGE_CodingTGA},
690 {MMAL_ENCODING_PPM, OMX_IMAGE_CodingPPM},
691 {MMAL_ENCODING_UNKNOWN, OMX_IMAGE_CodingUnused}
692};
693
694uint32_t mmalil_omx_image_coding_to_encoding(OMX_IMAGE_CODINGTYPE coding)
695{
696 unsigned int i;
697 for(i = 0; mmal_omx_image_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
698 if(mmal_omx_image_coding_table[i].coding == coding) break;
699 return mmal_omx_image_coding_table[i].encoding;
700}
701
702OMX_IMAGE_CODINGTYPE mmalil_encoding_to_omx_image_coding(uint32_t encoding)
703{
704 unsigned int i;
705 for(i = 0; mmal_omx_image_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
706 if(mmal_omx_image_coding_table[i].encoding == encoding) break;
707 return mmal_omx_image_coding_table[i].coding;
708}
709
710uint32_t mmalil_omx_coding_to_encoding(uint32_t encoding, OMX_PORTDOMAINTYPE domain)
711{
712 if(domain == OMX_PortDomainVideo)
713 return mmalil_omx_video_coding_to_encoding((OMX_VIDEO_CODINGTYPE)encoding);
714 else if(domain == OMX_PortDomainAudio)
715 return mmalil_omx_audio_coding_to_encoding((OMX_AUDIO_CODINGTYPE)encoding);
716 else if(domain == OMX_PortDomainImage)
717 return mmalil_omx_image_coding_to_encoding((OMX_IMAGE_CODINGTYPE)encoding);
718 else
719 return MMAL_ENCODING_UNKNOWN;
720}
721
722/*****************************************************************************/
723static struct {
724 uint32_t encoding;
725 OMX_COLOR_FORMATTYPE coding;
726} mmal_omx_colorformat_coding_table[] =
727{
728 {MMAL_ENCODING_I420, OMX_COLOR_FormatYUV420PackedPlanar},
729 {MMAL_ENCODING_I422, OMX_COLOR_FormatYUV422PackedPlanar},
730 {MMAL_ENCODING_I420_SLICE, OMX_COLOR_FormatYUV420PackedPlanar},
731 {MMAL_ENCODING_I422_SLICE, OMX_COLOR_FormatYUV422PackedPlanar},
732 {MMAL_ENCODING_I420, OMX_COLOR_FormatYUV420Planar},
733 {MMAL_ENCODING_YV12, OMX_COLOR_FormatYVU420PackedPlanar},
734 {MMAL_ENCODING_NV12, OMX_COLOR_FormatYUV420PackedSemiPlanar},
735 {MMAL_ENCODING_NV12, OMX_COLOR_FormatYUV420SemiPlanar},
736 {MMAL_ENCODING_NV21, OMX_COLOR_FormatYVU420PackedSemiPlanar},
737 {MMAL_ENCODING_YUVUV128, OMX_COLOR_FormatYUVUV128},
738 {MMAL_ENCODING_YUYV, OMX_COLOR_FormatYCbYCr},
739 {MMAL_ENCODING_YVYU, OMX_COLOR_FormatYCrYCb},
740 {MMAL_ENCODING_UYVY, OMX_COLOR_FormatCbYCrY},
741 {MMAL_ENCODING_VYUY, OMX_COLOR_FormatCrYCbY},
742 {MMAL_ENCODING_RGB16, OMX_COLOR_Format16bitRGB565},
743 {MMAL_ENCODING_BGR24, OMX_COLOR_Format24bitRGB888},
744 {MMAL_ENCODING_BGRA, OMX_COLOR_Format32bitARGB8888},
745 {MMAL_ENCODING_BGR16, OMX_COLOR_Format16bitBGR565},
746 {MMAL_ENCODING_RGB24, OMX_COLOR_Format24bitBGR888},
747 {MMAL_ENCODING_ARGB, OMX_COLOR_Format32bitBGRA8888},
748 {MMAL_ENCODING_RGBA, OMX_COLOR_Format32bitABGR8888},
749 {MMAL_ENCODING_RGB16_SLICE, OMX_COLOR_Format16bitRGB565},
750 {MMAL_ENCODING_BGR24_SLICE, OMX_COLOR_Format24bitRGB888},
751 {MMAL_ENCODING_BGRA_SLICE, OMX_COLOR_Format32bitARGB8888},
752 {MMAL_ENCODING_BGR16_SLICE, OMX_COLOR_Format16bitBGR565},
753 {MMAL_ENCODING_RGB24_SLICE, OMX_COLOR_Format24bitBGR888},
754 {MMAL_ENCODING_ARGB_SLICE, OMX_COLOR_Format32bitBGRA8888},
755 {MMAL_ENCODING_RGBA_SLICE, OMX_COLOR_Format32bitABGR8888},
756 {MMAL_ENCODING_EGL_IMAGE, OMX_COLOR_FormatBRCMEGL},
757 {MMAL_ENCODING_BAYER_SBGGR8, OMX_COLOR_FormatRawBayer8bit},
758 {MMAL_ENCODING_BAYER_SGRBG8, OMX_COLOR_FormatRawBayer8bit},
759 {MMAL_ENCODING_BAYER_SGBRG8, OMX_COLOR_FormatRawBayer8bit},
760 {MMAL_ENCODING_BAYER_SRGGB8, OMX_COLOR_FormatRawBayer8bit},
761 {MMAL_ENCODING_BAYER_SBGGR10P, OMX_COLOR_FormatRawBayer10bit},
762 {MMAL_ENCODING_BAYER_SGRBG10P, OMX_COLOR_FormatRawBayer10bit},
763 {MMAL_ENCODING_BAYER_SGBRG10P, OMX_COLOR_FormatRawBayer10bit},
764 {MMAL_ENCODING_BAYER_SRGGB10P, OMX_COLOR_FormatRawBayer10bit},
765 {MMAL_ENCODING_BAYER_SBGGR12P, OMX_COLOR_FormatRawBayer12bit},
766 {MMAL_ENCODING_BAYER_SGRBG12P, OMX_COLOR_FormatRawBayer12bit},
767 {MMAL_ENCODING_BAYER_SGBRG12P, OMX_COLOR_FormatRawBayer12bit},
768 {MMAL_ENCODING_BAYER_SRGGB12P, OMX_COLOR_FormatRawBayer12bit},
769 {MMAL_ENCODING_BAYER_SBGGR16, OMX_COLOR_FormatRawBayer16bit},
770 {MMAL_ENCODING_BAYER_SGBRG16, OMX_COLOR_FormatRawBayer16bit},
771 {MMAL_ENCODING_BAYER_SGRBG16, OMX_COLOR_FormatRawBayer16bit},
772 {MMAL_ENCODING_BAYER_SRGGB16, OMX_COLOR_FormatRawBayer16bit},
773 {MMAL_ENCODING_BAYER_SBGGR10DPCM8,OMX_COLOR_FormatRawBayer8bitcompressed},
774 {MMAL_ENCODING_OPAQUE, OMX_COLOR_FormatBRCMOpaque},
775 {MMAL_ENCODING_I420_16, OMX_COLOR_FormatYUV420_16PackedPlanar},
776 {MMAL_ENCODING_I420_S, OMX_COLOR_FormatYUV420_UVSideBySide},
777 {MMAL_ENCODING_YUVUV64_16, OMX_COLOR_FormatYUVUV64_16},
778 {MMAL_ENCODING_I420_10, OMX_COLOR_FormatYUV420_10PackedPlanar},
779 {MMAL_ENCODING_YUVUV64_10, OMX_COLOR_FormatYUVUV64_10},
780 {MMAL_ENCODING_BGR32, OMX_COLOR_Format32bitXRGB8888},
781 {MMAL_ENCODING_RGB32, OMX_COLOR_Format32bitXBGR8888},
782 {MMAL_ENCODING_YUV10_COL, OMX_COLOR_FormatYUV10bitColumn},
783 {MMAL_ENCODING_UNKNOWN, OMX_COLOR_FormatUnused}
784};
785
786uint32_t mmalil_omx_color_format_to_encoding(OMX_COLOR_FORMATTYPE coding)
787{
788 unsigned int i;
789 for(i = 0; mmal_omx_colorformat_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
790 if(mmal_omx_colorformat_coding_table[i].coding == coding) break;
791 return mmal_omx_colorformat_coding_table[i].encoding;
792}
793
794OMX_COLOR_FORMATTYPE mmalil_encoding_to_omx_color_format(uint32_t encoding)
795{
796 unsigned int i;
797 for(i = 0; mmal_omx_colorformat_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
798 if(mmal_omx_colorformat_coding_table[i].encoding == encoding) break;
799 return mmal_omx_colorformat_coding_table[i].coding;
800}
801
802static struct {
803 uint32_t encoding;
804 OMX_COLOR_FORMATTYPE color_format;
805 OMX_BAYERORDERTYPE bayer_order;
806} mmal_omx_bayer_order_coding_table[] =
807{
808 //Colour format required for conversion from OMX to MMAL.
809 //Not used for MMAL encoding to OMX color format.
810 {MMAL_ENCODING_BAYER_SBGGR8, OMX_COLOR_FormatRawBayer8bit, OMX_BayerOrderBGGR},
811 {MMAL_ENCODING_BAYER_SGBRG8, OMX_COLOR_FormatRawBayer8bit, OMX_BayerOrderGBRG},
812 {MMAL_ENCODING_BAYER_SGRBG8, OMX_COLOR_FormatRawBayer8bit, OMX_BayerOrderGRBG},
813 {MMAL_ENCODING_BAYER_SRGGB8, OMX_COLOR_FormatRawBayer8bit, OMX_BayerOrderRGGB},
814
815 {MMAL_ENCODING_BAYER_SBGGR10P, OMX_COLOR_FormatRawBayer10bit, OMX_BayerOrderBGGR},
816 {MMAL_ENCODING_BAYER_SGRBG10P, OMX_COLOR_FormatRawBayer10bit, OMX_BayerOrderGRBG},
817 {MMAL_ENCODING_BAYER_SGBRG10P, OMX_COLOR_FormatRawBayer10bit, OMX_BayerOrderGBRG},
818 {MMAL_ENCODING_BAYER_SRGGB10P, OMX_COLOR_FormatRawBayer10bit, OMX_BayerOrderRGGB},
819
820 {MMAL_ENCODING_BAYER_SBGGR12P, OMX_COLOR_FormatRawBayer12bit, OMX_BayerOrderBGGR},
821 {MMAL_ENCODING_BAYER_SGRBG12P, OMX_COLOR_FormatRawBayer12bit, OMX_BayerOrderGRBG},
822 {MMAL_ENCODING_BAYER_SGBRG12P, OMX_COLOR_FormatRawBayer12bit, OMX_BayerOrderGBRG},
823 {MMAL_ENCODING_BAYER_SRGGB12P, OMX_COLOR_FormatRawBayer12bit, OMX_BayerOrderRGGB},
824
825 {MMAL_ENCODING_BAYER_SBGGR16, OMX_COLOR_FormatRawBayer16bit, OMX_BayerOrderBGGR},
826 {MMAL_ENCODING_BAYER_SGRBG16, OMX_COLOR_FormatRawBayer16bit, OMX_BayerOrderGRBG},
827 {MMAL_ENCODING_BAYER_SGBRG16, OMX_COLOR_FormatRawBayer16bit, OMX_BayerOrderGBRG},
828 {MMAL_ENCODING_BAYER_SRGGB16, OMX_COLOR_FormatRawBayer16bit, OMX_BayerOrderRGGB},
829
830 {MMAL_ENCODING_BAYER_SBGGR10DPCM8,OMX_COLOR_FormatRawBayer8bitcompressed, OMX_BayerOrderBGGR},
831 {MMAL_ENCODING_BAYER_SGRBG10DPCM8,OMX_COLOR_FormatRawBayer8bitcompressed, OMX_BayerOrderGRBG},
832 {MMAL_ENCODING_BAYER_SGBRG10DPCM8,OMX_COLOR_FormatRawBayer8bitcompressed, OMX_BayerOrderGBRG},
833 {MMAL_ENCODING_BAYER_SRGGB10DPCM8,OMX_COLOR_FormatRawBayer8bitcompressed, OMX_BayerOrderRGGB},
834
835 {MMAL_ENCODING_UNKNOWN, OMX_COLOR_FormatMax, OMX_BayerOrderMax}
836};
837
838uint32_t mmalil_omx_bayer_format_order_to_encoding(OMX_BAYERORDERTYPE bayer_order, OMX_COLOR_FORMATTYPE color_format)
839{
840 unsigned int i;
841 for(i = 0; mmal_omx_bayer_order_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
842 if(mmal_omx_bayer_order_coding_table[i].bayer_order == bayer_order &&
843 mmal_omx_bayer_order_coding_table[i].color_format == color_format)
844 break;
845 return mmal_omx_bayer_order_coding_table[i].encoding;
846}
847
848OMX_BAYERORDERTYPE mmalil_encoding_to_omx_bayer_order(uint32_t encoding)
849{
850 unsigned int i;
851 for(i = 0; mmal_omx_bayer_order_coding_table[i].encoding != MMAL_ENCODING_UNKNOWN; i++)
852 if(mmal_omx_bayer_order_coding_table[i].encoding == encoding) break;
853 return mmal_omx_bayer_order_coding_table[i].bayer_order;
854}
855
856/*****************************************************************************/
857static struct {
858 uint32_t mmal;
859 OMX_COLORSPACETYPE omx;
860} mmal_omx_colorspace_coding_table[] =
861{
862 {MMAL_COLOR_SPACE_ITUR_BT601, OMX_COLORSPACE_ITU_R_BT601},
863 {MMAL_COLOR_SPACE_ITUR_BT709, OMX_COLORSPACE_ITU_R_BT709},
864 {MMAL_COLOR_SPACE_JPEG_JFIF, OMX_COLORSPACE_JPEG_JFIF},
865 {MMAL_COLOR_SPACE_FCC, OMX_COLORSPACE_FCC},
866 {MMAL_COLOR_SPACE_SMPTE240M, OMX_COLORSPACE_SMPTE240M},
867 {MMAL_COLOR_SPACE_BT470_2_M, OMX_COLORSPACE_BT470_2_M},
868 {MMAL_COLOR_SPACE_BT470_2_BG, OMX_COLORSPACE_BT470_2_BG},
869 {MMAL_COLOR_SPACE_JFIF_Y16_255, OMX_COLORSPACE_JFIF_Y16_255},
870 {MMAL_COLOR_SPACE_REC2020, OMX_COLORSPACE_REC_2020},
871 {MMAL_COLOR_SPACE_UNKNOWN, OMX_COLORSPACE_UNKNOWN}
872};
873
874uint32_t mmalil_omx_color_space_to_mmal(OMX_COLORSPACETYPE coding)
875{
876 unsigned int i;
877 for(i = 0; mmal_omx_colorspace_coding_table[i].mmal != MMAL_COLOR_SPACE_UNKNOWN; i++)
878 if(mmal_omx_colorspace_coding_table[i].omx == coding) break;
879 return mmal_omx_colorspace_coding_table[i].mmal;
880}
881
882OMX_COLORSPACETYPE mmalil_color_space_to_omx(uint32_t coding)
883{
884 unsigned int i;
885 for(i = 0; mmal_omx_colorspace_coding_table[i].mmal != MMAL_COLOR_SPACE_UNKNOWN; i++)
886 if(mmal_omx_colorspace_coding_table[i].mmal == coding) break;
887 return mmal_omx_colorspace_coding_table[i].omx;
888}
889
890/*****************************************************************************/
891static struct {
892 uint32_t mmal;
893 OMX_U32 omx;
894 OMX_VIDEO_CODINGTYPE omx_coding;
895} mmal_omx_video_profile_table[] =
896{
897 { MMAL_VIDEO_PROFILE_H263_BASELINE, OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_CodingH263},
898 { MMAL_VIDEO_PROFILE_H263_H320CODING, OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_CodingH263},
899 { MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE, OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_CodingH263},
900 { MMAL_VIDEO_PROFILE_H263_ISWV2, OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_CodingH263},
901 { MMAL_VIDEO_PROFILE_H263_ISWV3, OMX_VIDEO_H263ProfileISWV3, OMX_VIDEO_CodingH263},
902 { MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION, OMX_VIDEO_H263ProfileHighCompression, OMX_VIDEO_CodingH263},
903 { MMAL_VIDEO_PROFILE_H263_INTERNET, OMX_VIDEO_H263ProfileInternet, OMX_VIDEO_CodingH263},
904 { MMAL_VIDEO_PROFILE_H263_INTERLACE, OMX_VIDEO_H263ProfileInterlace, OMX_VIDEO_CodingH263},
905 { MMAL_VIDEO_PROFILE_H263_HIGHLATENCY, OMX_VIDEO_H263ProfileHighLatency, OMX_VIDEO_CodingH263},
906 { MMAL_VIDEO_PROFILE_MP4V_SIMPLE, OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_CodingMPEG4},
907 { MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE, OMX_VIDEO_MPEG4ProfileSimpleScalable, OMX_VIDEO_CodingMPEG4},
908 { MMAL_VIDEO_PROFILE_MP4V_CORE, OMX_VIDEO_MPEG4ProfileCore, OMX_VIDEO_CodingMPEG4},
909 { MMAL_VIDEO_PROFILE_MP4V_MAIN, OMX_VIDEO_MPEG4ProfileMain, OMX_VIDEO_CodingMPEG4},
910 { MMAL_VIDEO_PROFILE_MP4V_NBIT, OMX_VIDEO_MPEG4ProfileNbit, OMX_VIDEO_CodingMPEG4},
911 { MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE, OMX_VIDEO_MPEG4ProfileScalableTexture, OMX_VIDEO_CodingMPEG4},
912 { MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE, OMX_VIDEO_MPEG4ProfileSimpleFace, OMX_VIDEO_CodingMPEG4},
913 { MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA, OMX_VIDEO_MPEG4ProfileSimpleFBA, OMX_VIDEO_CodingMPEG4},
914 { MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED, OMX_VIDEO_MPEG4ProfileBasicAnimated, OMX_VIDEO_CodingMPEG4},
915 { MMAL_VIDEO_PROFILE_MP4V_HYBRID, OMX_VIDEO_MPEG4ProfileHybrid, OMX_VIDEO_CodingMPEG4},
916 { MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME, OMX_VIDEO_MPEG4ProfileAdvancedRealTime, OMX_VIDEO_CodingMPEG4},
917 { MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE, OMX_VIDEO_MPEG4ProfileCoreScalable, OMX_VIDEO_CodingMPEG4},
918 { MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING, OMX_VIDEO_MPEG4ProfileAdvancedCoding, OMX_VIDEO_CodingMPEG4},
919 { MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE, OMX_VIDEO_MPEG4ProfileAdvancedCore, OMX_VIDEO_CodingMPEG4},
920 { MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE, OMX_VIDEO_MPEG4ProfileAdvancedScalable, OMX_VIDEO_CodingMPEG4},
921 { MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE, OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_CodingMPEG4},
922 { MMAL_VIDEO_PROFILE_H264_BASELINE, OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_CodingAVC},
923 { MMAL_VIDEO_PROFILE_H264_MAIN, OMX_VIDEO_AVCProfileMain, OMX_VIDEO_CodingAVC},
924 { MMAL_VIDEO_PROFILE_H264_EXTENDED, OMX_VIDEO_AVCProfileExtended, OMX_VIDEO_CodingAVC},
925 { MMAL_VIDEO_PROFILE_H264_HIGH, OMX_VIDEO_AVCProfileHigh, OMX_VIDEO_CodingAVC},
926 { MMAL_VIDEO_PROFILE_H264_HIGH10, OMX_VIDEO_AVCProfileHigh10, OMX_VIDEO_CodingAVC},
927 { MMAL_VIDEO_PROFILE_H264_HIGH422, OMX_VIDEO_AVCProfileHigh422, OMX_VIDEO_CodingAVC},
928 { MMAL_VIDEO_PROFILE_H264_HIGH444, OMX_VIDEO_AVCProfileHigh444, OMX_VIDEO_CodingAVC},
929 { MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE, OMX_VIDEO_AVCProfileConstrainedBaseline, OMX_VIDEO_CodingAVC},
930 { MMAL_VIDEO_PROFILE_DUMMY, OMX_VIDEO_AVCProfileMax, OMX_VIDEO_CodingAVC},
931};
932
933uint32_t mmalil_omx_video_profile_to_mmal(OMX_U32 profile, OMX_VIDEO_CODINGTYPE coding)
934{
935 unsigned int i;
936 for(i = 0; mmal_omx_video_profile_table[i].mmal != MMAL_VIDEO_PROFILE_DUMMY; i++)
937 if(mmal_omx_video_profile_table[i].omx == profile
938 && mmal_omx_video_profile_table[i].omx_coding == coding) break;
939 return mmal_omx_video_profile_table[i].mmal;
940}
941
942OMX_U32 mmalil_video_profile_to_omx(uint32_t profile)
943{
944 unsigned int i;
945 for(i = 0; mmal_omx_video_profile_table[i].mmal != MMAL_VIDEO_PROFILE_DUMMY; i++)
946 if(mmal_omx_video_profile_table[i].mmal == profile) break;
947 return mmal_omx_video_profile_table[i].omx;
948}
949
950/*****************************************************************************/
951static struct {
952 uint32_t mmal;
953 OMX_U32 omx;
954 OMX_VIDEO_CODINGTYPE omx_coding;
955} mmal_omx_video_level_table[] =
956{
957 { MMAL_VIDEO_LEVEL_H263_10, OMX_VIDEO_H263Level10, OMX_VIDEO_CodingH263},
958 { MMAL_VIDEO_LEVEL_H263_20, OMX_VIDEO_H263Level20, OMX_VIDEO_CodingH263},
959 { MMAL_VIDEO_LEVEL_H263_30, OMX_VIDEO_H263Level30, OMX_VIDEO_CodingH263},
960 { MMAL_VIDEO_LEVEL_H263_40, OMX_VIDEO_H263Level40, OMX_VIDEO_CodingH263},
961 { MMAL_VIDEO_LEVEL_H263_45, OMX_VIDEO_H263Level45, OMX_VIDEO_CodingH263},
962 { MMAL_VIDEO_LEVEL_H263_50, OMX_VIDEO_H263Level50, OMX_VIDEO_CodingH263},
963 { MMAL_VIDEO_LEVEL_H263_60, OMX_VIDEO_H263Level60, OMX_VIDEO_CodingH263},
964 { MMAL_VIDEO_LEVEL_H263_70, OMX_VIDEO_H263Level70, OMX_VIDEO_CodingH263},
965 { MMAL_VIDEO_LEVEL_MP4V_0, OMX_VIDEO_MPEG4Level0, OMX_VIDEO_CodingMPEG4},
966 { MMAL_VIDEO_LEVEL_MP4V_0b, OMX_VIDEO_MPEG4Level0b, OMX_VIDEO_CodingMPEG4},
967 { MMAL_VIDEO_LEVEL_MP4V_1, OMX_VIDEO_MPEG4Level1, OMX_VIDEO_CodingMPEG4},
968 { MMAL_VIDEO_LEVEL_MP4V_2, OMX_VIDEO_MPEG4Level2, OMX_VIDEO_CodingMPEG4},
969 { MMAL_VIDEO_LEVEL_MP4V_3, OMX_VIDEO_MPEG4Level3, OMX_VIDEO_CodingMPEG4},
970 { MMAL_VIDEO_LEVEL_MP4V_4, OMX_VIDEO_MPEG4Level4, OMX_VIDEO_CodingMPEG4},
971 { MMAL_VIDEO_LEVEL_MP4V_4a, OMX_VIDEO_MPEG4Level4a, OMX_VIDEO_CodingMPEG4},
972 { MMAL_VIDEO_LEVEL_MP4V_5, OMX_VIDEO_MPEG4Level5, OMX_VIDEO_CodingMPEG4},
973 { MMAL_VIDEO_LEVEL_MP4V_6, OMX_VIDEO_MPEG4Level6, OMX_VIDEO_CodingMPEG4},
974 { MMAL_VIDEO_LEVEL_H264_1, OMX_VIDEO_AVCLevel1, OMX_VIDEO_CodingAVC},
975 { MMAL_VIDEO_LEVEL_H264_1b, OMX_VIDEO_AVCLevel1b, OMX_VIDEO_CodingAVC},
976 { MMAL_VIDEO_LEVEL_H264_11, OMX_VIDEO_AVCLevel11, OMX_VIDEO_CodingAVC},
977 { MMAL_VIDEO_LEVEL_H264_12, OMX_VIDEO_AVCLevel12, OMX_VIDEO_CodingAVC},
978 { MMAL_VIDEO_LEVEL_H264_13, OMX_VIDEO_AVCLevel13, OMX_VIDEO_CodingAVC},
979 { MMAL_VIDEO_LEVEL_H264_2, OMX_VIDEO_AVCLevel2, OMX_VIDEO_CodingAVC},
980 { MMAL_VIDEO_LEVEL_H264_21, OMX_VIDEO_AVCLevel21, OMX_VIDEO_CodingAVC},
981 { MMAL_VIDEO_LEVEL_H264_22, OMX_VIDEO_AVCLevel22, OMX_VIDEO_CodingAVC},
982 { MMAL_VIDEO_LEVEL_H264_3, OMX_VIDEO_AVCLevel3, OMX_VIDEO_CodingAVC},
983 { MMAL_VIDEO_LEVEL_H264_31, OMX_VIDEO_AVCLevel31, OMX_VIDEO_CodingAVC},
984 { MMAL_VIDEO_LEVEL_H264_32, OMX_VIDEO_AVCLevel32, OMX_VIDEO_CodingAVC},
985 { MMAL_VIDEO_LEVEL_H264_4, OMX_VIDEO_AVCLevel4, OMX_VIDEO_CodingAVC},
986 { MMAL_VIDEO_LEVEL_H264_41, OMX_VIDEO_AVCLevel41, OMX_VIDEO_CodingAVC},
987 { MMAL_VIDEO_LEVEL_H264_42, OMX_VIDEO_AVCLevel42, OMX_VIDEO_CodingAVC},
988 { MMAL_VIDEO_LEVEL_H264_5, OMX_VIDEO_AVCLevel5, OMX_VIDEO_CodingAVC},
989 { MMAL_VIDEO_LEVEL_H264_51, OMX_VIDEO_AVCLevel51, OMX_VIDEO_CodingAVC},
990 { MMAL_VIDEO_LEVEL_DUMMY, OMX_VIDEO_AVCLevelMax, OMX_VIDEO_CodingMax},
991};
992
993uint32_t mmalil_omx_video_level_to_mmal(OMX_U32 level, OMX_VIDEO_CODINGTYPE coding)
994{
995 unsigned int i;
996 for(i = 0; mmal_omx_video_level_table[i].mmal != MMAL_VIDEO_LEVEL_DUMMY; i++)
997 if(mmal_omx_video_level_table[i].omx == level
998 && mmal_omx_video_level_table[i].omx_coding == coding) break;
999 return mmal_omx_video_level_table[i].mmal;
1000}
1001
1002OMX_U32 mmalil_video_level_to_omx(uint32_t level)
1003{
1004 unsigned int i;
1005 for(i = 0; mmal_omx_video_level_table[i].mmal != MMAL_VIDEO_LEVEL_DUMMY; i++)
1006 if(mmal_omx_video_level_table[i].mmal == level) break;
1007 return mmal_omx_video_level_table[i].omx;
1008}
1009
1010/*****************************************************************************/
1011static struct {
1012 MMAL_VIDEO_RATECONTROL_T mmal;
1013 OMX_VIDEO_CONTROLRATETYPE omx;
1014} mmal_omx_video_ratecontrol_table[] =
1015{
1016 { MMAL_VIDEO_RATECONTROL_DEFAULT, OMX_Video_ControlRateDisable},
1017 { MMAL_VIDEO_RATECONTROL_VARIABLE, OMX_Video_ControlRateVariable},
1018 { MMAL_VIDEO_RATECONTROL_CONSTANT, OMX_Video_ControlRateConstant},
1019 { MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES, OMX_Video_ControlRateVariableSkipFrames},
1020 { MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES, OMX_Video_ControlRateConstantSkipFrames},
1021 { MMAL_VIDEO_RATECONTROL_DUMMY, OMX_Video_ControlRateMax},
1022};
1023
1024MMAL_VIDEO_RATECONTROL_T mmalil_omx_video_ratecontrol_to_mmal(OMX_VIDEO_CONTROLRATETYPE omx)
1025{
1026 unsigned int i;
1027 for(i = 0; mmal_omx_video_ratecontrol_table[i].mmal != MMAL_VIDEO_RATECONTROL_DUMMY; i++)
1028 if(mmal_omx_video_ratecontrol_table[i].omx == omx) break;
1029 return mmal_omx_video_ratecontrol_table[i].mmal;
1030}
1031
1032OMX_VIDEO_CONTROLRATETYPE mmalil_video_ratecontrol_to_omx(MMAL_VIDEO_RATECONTROL_T mmal)
1033{
1034 unsigned int i;
1035 for(i = 0; mmal_omx_video_ratecontrol_table[i].mmal != MMAL_VIDEO_RATECONTROL_DUMMY; i++)
1036 if(mmal_omx_video_ratecontrol_table[i].mmal == mmal) break;
1037 return mmal_omx_video_ratecontrol_table[i].omx;
1038}
1039
1040/*****************************************************************************/
1041static struct {
1042 MMAL_VIDEO_INTRA_REFRESH_T mmal;
1043 OMX_VIDEO_INTRAREFRESHTYPE omx;
1044} mmal_omx_video_intrarefresh_table[] =
1045{
1046 { MMAL_VIDEO_INTRA_REFRESH_CYCLIC, OMX_VIDEO_IntraRefreshCyclic},
1047 { MMAL_VIDEO_INTRA_REFRESH_ADAPTIVE, OMX_VIDEO_IntraRefreshAdaptive},
1048 { MMAL_VIDEO_INTRA_REFRESH_BOTH, OMX_VIDEO_IntraRefreshBoth},
1049 { MMAL_VIDEO_INTRA_REFRESH_KHRONOSEXTENSIONS, OMX_VIDEO_IntraRefreshKhronosExtensions},
1050 { MMAL_VIDEO_INTRA_REFRESH_VENDORSTARTUNUSED, OMX_VIDEO_IntraRefreshVendorStartUnused},
1051 { MMAL_VIDEO_INTRA_REFRESH_DUMMY, OMX_VIDEO_IntraRefreshMax},
1052};
1053
1054MMAL_VIDEO_INTRA_REFRESH_T mmalil_omx_video_intrarefresh_to_mmal(OMX_VIDEO_INTRAREFRESHTYPE omx)
1055{
1056 unsigned int i;
1057 for(i = 0; mmal_omx_video_intrarefresh_table[i].mmal != MMAL_VIDEO_INTRA_REFRESH_DUMMY; i++)
1058 if(mmal_omx_video_intrarefresh_table[i].omx == omx) break;
1059 return mmal_omx_video_intrarefresh_table[i].mmal;
1060}
1061