MediaCodec: use SSE copy function from the avcodec module if the CPU supports it.
[vlc.git] / modules / codec / omxil / utils.c
1 /*****************************************************************************
2  * utils.c: helper functions
3  *****************************************************************************
4  * Copyright (C) 2010 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
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 Lesser General Public License for more details.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_codec.h>
34 #include <vlc_block_helper.h>
35 #include <vlc_cpu.h>
36
37 #include "omxil.h"
38 #include "qcom.h"
39 #include "../../video_chroma/copy.h"
40
41 /*****************************************************************************
42  * Events utility functions
43  *****************************************************************************/
44 void InitOmxEventQueue(OmxEventQueue *queue)
45 {
46     queue->pp_last_event = &queue->p_events;
47     vlc_mutex_init(&queue->mutex);
48     vlc_cond_init(&queue->cond);
49 }
50
51 void DeinitOmxEventQueue(OmxEventQueue *queue)
52 {
53     vlc_mutex_destroy(&queue->mutex);
54     vlc_cond_destroy(&queue->cond);
55 }
56
57 OMX_ERRORTYPE PostOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE event,
58     OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data)
59 {
60     OmxEvent *p_event;
61
62     p_event = malloc(sizeof(OmxEvent));
63     if(!p_event) return OMX_ErrorInsufficientResources;
64
65     p_event->event = event;
66     p_event->data_1 = data_1;
67     p_event->data_2 = data_2;
68     p_event->event_data = event_data;
69     p_event->next = 0;
70
71     vlc_mutex_lock(&queue->mutex);
72     *queue->pp_last_event = p_event;
73     queue->pp_last_event = &p_event->next;
74     vlc_cond_signal(&queue->cond);
75     vlc_mutex_unlock(&queue->mutex);
76     return OMX_ErrorNone;
77 }
78
79 OMX_ERRORTYPE WaitForOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE *event,
80     OMX_U32 *data_1, OMX_U32 *data_2, OMX_PTR *event_data)
81 {
82     OmxEvent *p_event;
83
84     vlc_mutex_lock(&queue->mutex);
85
86     if(!queue->p_events)
87         vlc_cond_timedwait(&queue->cond, &queue->mutex, mdate()+CLOCK_FREQ);
88
89     p_event = queue->p_events;
90     if(p_event)
91     {
92         queue->p_events = p_event->next;
93         if(!queue->p_events) queue->pp_last_event = &queue->p_events;
94     }
95
96     vlc_mutex_unlock(&queue->mutex);
97
98     if(p_event)
99     {
100         if(event) *event = p_event->event;
101         if(data_1) *data_1 = p_event->data_1;
102         if(data_2) *data_2 = p_event->data_2;
103         if(event_data) *event_data = p_event->event_data;
104         free(p_event);
105         return OMX_ErrorNone;
106     }
107
108     return OMX_ErrorTimeout;
109 }
110
111 OMX_ERRORTYPE WaitForSpecificOmxEvent(OmxEventQueue *queue,
112     OMX_EVENTTYPE specific_event, OMX_U32 *data_1, OMX_U32 *data_2,
113     OMX_PTR *event_data)
114 {
115     OMX_ERRORTYPE status;
116     OMX_EVENTTYPE event;
117     mtime_t before =  mdate();
118
119     while(1)
120     {
121         status = WaitForOmxEvent(queue, &event, data_1, data_2, event_data);
122         if(status != OMX_ErrorNone) return status;
123
124         if(event == specific_event) break;
125         if(mdate() - before > CLOCK_FREQ) return OMX_ErrorTimeout;
126     }
127
128     return OMX_ErrorNone;
129 }
130
131 void PrintOmxEvent(vlc_object_t *p_this, OMX_EVENTTYPE event, OMX_U32 data_1,
132     OMX_U32 data_2, OMX_PTR event_data)
133 {
134     switch (event)
135     {
136     case OMX_EventCmdComplete:
137         switch ((OMX_STATETYPE)data_1)
138         {
139         case OMX_CommandStateSet:
140             msg_Dbg( p_this, "OmxEventHandler (%s, %s, %s)", EventToString(event),
141                      CommandToString(data_1), StateToString(data_2) );
142             break;
143
144         default:
145             msg_Dbg( p_this, "OmxEventHandler (%s, %s, %u)", EventToString(event),
146                      CommandToString(data_1), (unsigned int)data_2 );
147             break;
148         }
149         break;
150
151     case OMX_EventError:
152         msg_Dbg( p_this, "OmxEventHandler (%s, %s, %u, %s)", EventToString(event),
153                  ErrorToString((OMX_ERRORTYPE)data_1), (unsigned int)data_2,
154                  (const char *)event_data);
155         break;
156
157     default:
158         msg_Dbg( p_this, "OmxEventHandler (%s, %u, %u)", EventToString(event),
159                  (unsigned int)data_1, (unsigned int)data_2 );
160         break;
161     }
162 }
163
164 /*****************************************************************************
165  * Picture utility functions
166  *****************************************************************************/
167 void ArchitectureSpecificCopyHooks( decoder_t *p_dec, int i_color_format,
168                                     int i_slice_height, int i_src_stride,
169                                     ArchitectureSpecificCopyData *p_architecture_specific )
170 {
171     (void)i_slice_height;
172
173 #ifdef CAN_COMPILE_SSE2
174     if( i_color_format == OMX_COLOR_FormatYUV420SemiPlanar && vlc_CPU_SSE2() )
175     {
176         copy_cache_t *p_surface_cache = malloc( sizeof(copy_cache_t) );
177         if( !p_surface_cache || CopyInitCache( p_surface_cache, i_src_stride ) )
178         {
179             free( p_surface_cache );
180             return;
181         }
182         p_architecture_specific->data = p_surface_cache;
183         p_dec->fmt_out.i_codec = VLC_CODEC_YV12;
184     }
185 #endif
186 }
187
188 void ArchitectureSpecificCopyHooksDestroy( int i_color_format,
189                                            ArchitectureSpecificCopyData *p_architecture_specific )
190 {
191     if (!p_architecture_specific->data)
192         return;
193 #ifdef CAN_COMPILE_SSE2
194     if( i_color_format == OMX_COLOR_FormatYUV420SemiPlanar && vlc_CPU_SSE2() )
195     {
196         copy_cache_t *p_surface_cache = (copy_cache_t*)p_architecture_specific->data;
197         CopyCleanCache(p_surface_cache);
198     }
199 #endif
200     free(p_architecture_specific->data);
201     p_architecture_specific->data = NULL;
202 }
203
204 void CopyOmxPicture( int i_color_format, picture_t *p_pic,
205                      int i_slice_height,
206                      int i_src_stride, uint8_t *p_src, int i_chroma_div,
207                      ArchitectureSpecificCopyData *p_architecture_specific )
208 {
209     uint8_t *p_dst;
210     int i_dst_stride;
211     int i_plane, i_width, i_line;
212     if( i_color_format == QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka )
213     {
214         qcom_convert(p_src, p_pic);
215         return;
216     }
217 #ifdef CAN_COMPILE_SSE2
218     if( i_color_format == OMX_COLOR_FormatYUV420SemiPlanar
219         && vlc_CPU_SSE2() && p_architecture_specific->data )
220     {
221         copy_cache_t *p_surface_cache = (copy_cache_t*)p_architecture_specific->data;
222         uint8_t *ppi_src_pointers[2] = { p_src, p_src + i_src_stride * i_slice_height };
223         size_t pi_src_strides[2] = { i_src_stride, i_src_stride };
224         CopyFromNv12( p_pic, ppi_src_pointers, pi_src_strides, i_src_stride, i_slice_height, p_surface_cache );
225         return;
226     }
227 #endif
228
229     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
230     {
231         if(i_plane == 1) i_src_stride /= i_chroma_div;
232         p_dst = p_pic->p[i_plane].p_pixels;
233         i_dst_stride = p_pic->p[i_plane].i_pitch;
234         i_width = p_pic->p[i_plane].i_visible_pitch;
235
236         for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ )
237         {
238             memcpy( p_dst, p_src, i_width );
239             p_src += i_src_stride;
240             p_dst += i_dst_stride;
241         }
242         /* Handle plane height, which may be indicated via nSliceHeight in OMX.
243          * The handling for chroma planes currently assumes vertically
244          * subsampled chroma, e.g. 422 planar wouldn't work right. */
245         if( i_plane == 0 && i_slice_height > p_pic->p[i_plane].i_visible_lines )
246             p_src += i_src_stride * (i_slice_height - p_pic->p[i_plane].i_visible_lines);
247         else if ( i_plane > 0 && i_slice_height/2 > p_pic->p[i_plane].i_visible_lines )
248             p_src += i_src_stride * (i_slice_height/2 - p_pic->p[i_plane].i_visible_lines);
249     }
250 }
251
252 void CopyVlcPicture( decoder_t *p_dec, OMX_BUFFERHEADERTYPE *p_header,
253                      picture_t *p_pic)
254 {
255     decoder_sys_t *p_sys = p_dec->p_sys;
256     int i_src_stride, i_dst_stride;
257     int i_plane, i_width, i_line;
258     uint8_t *p_dst, *p_src;
259
260     i_dst_stride  = p_sys->out.i_frame_stride;
261     p_dst = p_header->pBuffer + p_header->nOffset;
262
263     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
264     {
265         if(i_plane == 1) i_dst_stride /= p_sys->in.i_frame_stride_chroma_div;
266         p_src = p_pic->p[i_plane].p_pixels;
267         i_src_stride = p_pic->p[i_plane].i_pitch;
268         i_width = p_pic->p[i_plane].i_visible_pitch;
269
270         for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ )
271         {
272             memcpy( p_dst, p_src, i_width );
273             p_src += i_src_stride;
274             p_dst += i_dst_stride;
275         }
276     }
277 }
278
279 int IgnoreOmxDecoderPadding(const char *name)
280 {
281     // The list of decoders that signal padding properly is not necessary,
282     // since that is the default, but keep it here for reference. (This is
283     // only relevant for manufacturers that are known to have decoders with
284     // this kind of bug.)
285 /*
286     static const char *padding_decoders[] = {
287         "OMX.SEC.AVC.Decoder",
288         "OMX.SEC.wmv7.dec",
289         "OMX.SEC.wmv8.dec",
290         NULL
291     };
292 */
293     static const char *nopadding_decoders[] = {
294         "OMX.SEC.avc.dec",
295         "OMX.SEC.avcdec",
296         "OMX.SEC.MPEG4.Decoder",
297         "OMX.SEC.mpeg4.dec",
298         "OMX.SEC.vc1.dec",
299         NULL
300     };
301     for (const char **ptr = nopadding_decoders; *ptr; ptr++) {
302         if (!strcmp(*ptr, name))
303             return 1;
304     }
305     return 0;
306 }
307
308 /*****************************************************************************
309  * Logging utility functions
310  *****************************************************************************/
311 const char *StateToString(OMX_STATETYPE state)
312 {
313     static const char *psz_names[] = {
314         "OMX_StateInvalid", "OMX_StateLoaded", "OMX_StateIdle",
315         "OMX_StateExecuting", "OMX_StatePause", "OMX_StateWaitForResources",
316         "OMX_State unknown"
317     };
318
319     if((unsigned int)state > sizeof(psz_names)/sizeof(char*)-1)
320         state = (OMX_STATETYPE)(sizeof(psz_names)/sizeof(char*)-1);
321     return psz_names[state];
322 }
323
324 const char *CommandToString(OMX_COMMANDTYPE command)
325 {
326     static const char *psz_names[] = {
327         "OMX_CommandStateSet", "OMX_CommandFlush", "OMX_CommandPortDisable",
328         "OMX_CommandPortEnable", "OMX_CommandMarkBuffer",
329         "OMX_Command unknown"
330     };
331
332     if((unsigned int)command > sizeof(psz_names)/sizeof(char*)-1)
333         command = (OMX_COMMANDTYPE)(sizeof(psz_names)/sizeof(char*)-1);
334     return psz_names[command];
335 }
336
337 const char *EventToString(OMX_EVENTTYPE event)
338 {
339     static const char *psz_names[] = {
340         "OMX_EventCmdComplete", "OMX_EventError", "OMX_EventMark",
341         "OMX_EventPortSettingsChanged", "OMX_EventBufferFlag",
342         "OMX_EventResourcesAcquired", "OMX_EventComponentResumed",
343         "OMX_EventDynamicResourcesAvailable", "OMX_EventPortFormatDetected",
344         "OMX_Event unknown"
345     };
346
347     if((unsigned int)event > sizeof(psz_names)/sizeof(char*)-1)
348         event = (OMX_EVENTTYPE)(sizeof(psz_names)/sizeof(char*)-1);
349     return psz_names[event];
350 }
351
352 const char *ErrorToString(OMX_ERRORTYPE error)
353 {
354     static const char *psz_names[] = {
355         "OMX_ErrorInsufficientResources", "OMX_ErrorUndefined",
356         "OMX_ErrorInvalidComponentName", "OMX_ErrorComponentNotFound",
357         "OMX_ErrorInvalidComponent", "OMX_ErrorBadParameter",
358         "OMX_ErrorNotImplemented", "OMX_ErrorUnderflow",
359         "OMX_ErrorOverflow", "OMX_ErrorHardware", "OMX_ErrorInvalidState",
360         "OMX_ErrorStreamCorrupt", "OMX_ErrorPortsNotCompatible",
361         "OMX_ErrorResourcesLost", "OMX_ErrorNoMore", "OMX_ErrorVersionMismatch",
362         "OMX_ErrorNotReady", "OMX_ErrorTimeout", "OMX_ErrorSameState",
363         "OMX_ErrorResourcesPreempted", "OMX_ErrorPortUnresponsiveDuringAllocation",
364         "OMX_ErrorPortUnresponsiveDuringDeallocation",
365         "OMX_ErrorPortUnresponsiveDuringStop", "OMX_ErrorIncorrectStateTransition",
366         "OMX_ErrorIncorrectStateOperation", "OMX_ErrorUnsupportedSetting",
367         "OMX_ErrorUnsupportedIndex", "OMX_ErrorBadPortIndex",
368         "OMX_ErrorPortUnpopulated", "OMX_ErrorComponentSuspended",
369         "OMX_ErrorDynamicResourcesUnavailable", "OMX_ErrorMbErrorsInFrame",
370         "OMX_ErrorFormatNotDetected", "OMX_ErrorContentPipeOpenFailed",
371         "OMX_ErrorContentPipeCreationFailed", "OMX_ErrorSeperateTablesUsed",
372         "OMX_ErrorTunnelingUnsupported",
373         "OMX_Error unknown"
374     };
375
376     if(error == OMX_ErrorNone) return "OMX_ErrorNone";
377
378     error -= OMX_ErrorInsufficientResources;
379
380     if((unsigned int)error > sizeof(psz_names)/sizeof(char*)-1)
381         error = (OMX_STATETYPE)(sizeof(psz_names)/sizeof(char*)-1);
382     return psz_names[error];
383 }
384
385 /*****************************************************************************
386  * fourcc -> omx id mapping
387  *****************************************************************************/
388 static const struct
389 {
390     vlc_fourcc_t i_fourcc;
391     OMX_VIDEO_CODINGTYPE i_codec;
392     const char *psz_role;
393
394 } video_format_table[] =
395 {
396     { VLC_CODEC_MPGV, OMX_VIDEO_CodingMPEG2, "video_decoder.mpeg2" },
397     { VLC_CODEC_MP4V, OMX_VIDEO_CodingMPEG4, "video_decoder.mpeg4" },
398     { VLC_CODEC_H264, OMX_VIDEO_CodingAVC,   "video_decoder.avc"   },
399     { VLC_CODEC_H263, OMX_VIDEO_CodingH263,  "video_decoder.h263"  },
400     { VLC_CODEC_WMV1, OMX_VIDEO_CodingWMV,   "video_decoder.wmv1"  },
401     { VLC_CODEC_WMV2, OMX_VIDEO_CodingWMV,   "video_decoder.wmv2"  },
402     { VLC_CODEC_WMV3, OMX_VIDEO_CodingWMV,   "video_decoder.wmv"   },
403     { VLC_CODEC_VC1,  OMX_VIDEO_CodingWMV,   "video_decoder.wmv"   },
404     { VLC_CODEC_MJPG, OMX_VIDEO_CodingMJPEG, "video_decoder.jpeg"  },
405     { VLC_CODEC_MJPG, OMX_VIDEO_CodingMJPEG, "video_decoder.mjpeg" },
406     { VLC_CODEC_RV10, OMX_VIDEO_CodingRV,    "video_decoder.rv"    },
407     { VLC_CODEC_RV20, OMX_VIDEO_CodingRV,    "video_decoder.rv"    },
408     { VLC_CODEC_RV30, OMX_VIDEO_CodingRV,    "video_decoder.rv"    },
409     { VLC_CODEC_RV40, OMX_VIDEO_CodingRV,    "video_decoder.rv"    },
410     { 0, 0, 0 }
411 };
412
413 static const struct
414 {
415     vlc_fourcc_t i_fourcc;
416     OMX_AUDIO_CODINGTYPE i_codec;
417     const char *psz_role;
418
419 } audio_format_table[] =
420 {
421     { VLC_CODEC_AMR_NB, OMX_AUDIO_CodingAMR, "audio_decoder.amrnb" },
422     { VLC_CODEC_AMR_WB, OMX_AUDIO_CodingAMR, "audio_decoder.amrwb" },
423     { VLC_CODEC_MP4A,   OMX_AUDIO_CodingAAC, "audio_decoder.aac" },
424     { VLC_CODEC_S16N,   OMX_AUDIO_CodingPCM, "audio_decoder.pcm" },
425     { VLC_CODEC_MP3,    OMX_AUDIO_CodingMP3, "audio_decoder.mp3" },
426     { 0, 0, 0 }
427 };
428
429 static const struct
430 {
431     vlc_fourcc_t i_fourcc;
432     OMX_VIDEO_CODINGTYPE i_codec;
433     const char *psz_role;
434
435 } video_enc_format_table[] =
436 {
437     { VLC_CODEC_MPGV, OMX_VIDEO_CodingMPEG2, "video_encoder.mpeg2" },
438     { VLC_CODEC_MP4V, OMX_VIDEO_CodingMPEG4, "video_encoder.mpeg4" },
439     { VLC_CODEC_H264, OMX_VIDEO_CodingAVC,   "video_encoder.avc"   },
440     { VLC_CODEC_H263, OMX_VIDEO_CodingH263,  "video_encoder.h263"  },
441     { VLC_CODEC_WMV1, OMX_VIDEO_CodingWMV,   "video_encoder.wmv"   },
442     { VLC_CODEC_WMV2, OMX_VIDEO_CodingWMV,   "video_encoder.wmv"   },
443     { VLC_CODEC_WMV3, OMX_VIDEO_CodingWMV,   "video_encoder.wmv"   },
444     { VLC_CODEC_MJPG, OMX_VIDEO_CodingMJPEG, "video_encoder.jpeg"  },
445     { VLC_CODEC_RV10, OMX_VIDEO_CodingRV,    "video_encoder.rv"    },
446     { VLC_CODEC_RV20, OMX_VIDEO_CodingRV,    "video_encoder.rv"    },
447     { VLC_CODEC_RV30, OMX_VIDEO_CodingRV,    "video_encoder.rv"    },
448     { VLC_CODEC_RV40, OMX_VIDEO_CodingRV,    "video_encoder.rv"    },
449     { 0, 0, 0 }
450 };
451
452 static const struct
453 {
454     vlc_fourcc_t i_fourcc;
455     OMX_AUDIO_CODINGTYPE i_codec;
456     const char *psz_role;
457
458 } audio_enc_format_table[] =
459 {
460     { VLC_CODEC_AMR_NB, OMX_AUDIO_CodingAMR, "audio_encoder.amrnb" },
461     { VLC_CODEC_AMR_WB, OMX_AUDIO_CodingAMR, "audio_encoder.amrwb" },
462     { VLC_CODEC_MP4A,   OMX_AUDIO_CodingAAC, "audio_encoder.aac" },
463     { VLC_CODEC_S16N,   OMX_AUDIO_CodingPCM, "audio_encoder.pcm" },
464     { 0, 0, 0 }
465 };
466
467 static const struct
468 {
469     vlc_fourcc_t i_fourcc;
470     OMX_COLOR_FORMATTYPE i_codec;
471     unsigned int i_size_mul;
472     unsigned int i_line_mul;
473     unsigned int i_line_chroma_div;
474
475 } chroma_format_table[] =
476 {
477     { VLC_CODEC_I420, OMX_COLOR_FormatYUV420Planar, 3, 1, 2 },
478     { VLC_CODEC_I420, OMX_COLOR_FormatYUV420PackedPlanar, 3, 1, 2 },
479     { VLC_CODEC_NV12, OMX_COLOR_FormatYUV420SemiPlanar, 3, 1, 1 },
480     { VLC_CODEC_NV21, OMX_QCOM_COLOR_FormatYVU420SemiPlanar, 3, 1, 1 },
481     { VLC_CODEC_NV12, OMX_TI_COLOR_FormatYUV420PackedSemiPlanar, 3, 1, 1 },
482     { VLC_CODEC_NV12, QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka, 3, 1, 1 },
483     { VLC_CODEC_NV12, OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar32m, 3, 1, 1 },
484     { VLC_CODEC_YUYV, OMX_COLOR_FormatYCbYCr, 4, 2, 0 },
485     { VLC_CODEC_YVYU, OMX_COLOR_FormatYCrYCb, 4, 2, 0 },
486     { VLC_CODEC_UYVY, OMX_COLOR_FormatCbYCrY, 4, 2, 0 },
487     { VLC_CODEC_VYUY, OMX_COLOR_FormatCrYCbY, 4, 2, 0 },
488     { 0, 0, 0, 0, 0 }
489 };
490
491 int GetOmxVideoFormat( vlc_fourcc_t i_fourcc,
492                        OMX_VIDEO_CODINGTYPE *pi_omx_codec,
493                        const char **ppsz_name )
494 {
495     unsigned int i;
496
497     i_fourcc = vlc_fourcc_GetCodec( VIDEO_ES, i_fourcc );
498
499     for( i = 0; video_format_table[i].i_codec != 0; i++ )
500         if( video_format_table[i].i_fourcc == i_fourcc ) break;
501
502     if( pi_omx_codec ) *pi_omx_codec = video_format_table[i].i_codec;
503     if( ppsz_name ) *ppsz_name = vlc_fourcc_GetDescription( VIDEO_ES, i_fourcc );
504     return !!video_format_table[i].i_codec;
505 }
506
507 int GetVlcVideoFormat( OMX_VIDEO_CODINGTYPE i_omx_codec,
508                        vlc_fourcc_t *pi_fourcc, const char **ppsz_name )
509 {
510     unsigned int i;
511
512     for( i = 0; video_format_table[i].i_codec != 0; i++ )
513         if( video_format_table[i].i_codec == i_omx_codec ) break;
514
515     if( pi_fourcc ) *pi_fourcc = video_format_table[i].i_fourcc;
516     if( ppsz_name ) *ppsz_name = vlc_fourcc_GetDescription( VIDEO_ES,
517                                      video_format_table[i].i_fourcc );
518     return !!video_format_table[i].i_fourcc;
519 }
520
521 static const char *GetOmxVideoRole( vlc_fourcc_t i_fourcc )
522 {
523     unsigned int i;
524
525     i_fourcc = vlc_fourcc_GetCodec( VIDEO_ES, i_fourcc );
526
527     for( i = 0; video_format_table[i].i_codec != 0; i++ )
528         if( video_format_table[i].i_fourcc == i_fourcc ) break;
529
530     return video_format_table[i].psz_role;
531 }
532
533 static const char *GetOmxVideoEncRole( vlc_fourcc_t i_fourcc )
534 {
535     unsigned int i;
536
537     i_fourcc = vlc_fourcc_GetCodec( VIDEO_ES, i_fourcc );
538
539     for( i = 0; video_enc_format_table[i].i_codec != 0; i++ )
540         if( video_enc_format_table[i].i_fourcc == i_fourcc ) break;
541
542     return video_enc_format_table[i].psz_role;
543 }
544
545 int GetOmxAudioFormat( vlc_fourcc_t i_fourcc,
546                        OMX_AUDIO_CODINGTYPE *pi_omx_codec,
547                        const char **ppsz_name )
548 {
549     unsigned int i;
550
551     i_fourcc = vlc_fourcc_GetCodec( AUDIO_ES, i_fourcc );
552
553     for( i = 0; audio_format_table[i].i_codec != 0; i++ )
554         if( audio_format_table[i].i_fourcc == i_fourcc ) break;
555
556     if( pi_omx_codec ) *pi_omx_codec = audio_format_table[i].i_codec;
557     if( ppsz_name ) *ppsz_name = vlc_fourcc_GetDescription( AUDIO_ES, i_fourcc );
558     return !!audio_format_table[i].i_codec;
559 }
560
561 int OmxToVlcAudioFormat( OMX_AUDIO_CODINGTYPE i_omx_codec,
562                        vlc_fourcc_t *pi_fourcc, const char **ppsz_name )
563 {
564     unsigned int i;
565
566     for( i = 0; audio_format_table[i].i_codec != 0; i++ )
567         if( audio_format_table[i].i_codec == i_omx_codec ) break;
568
569     if( pi_fourcc ) *pi_fourcc = audio_format_table[i].i_fourcc;
570     if( ppsz_name ) *ppsz_name = vlc_fourcc_GetDescription( AUDIO_ES,
571                                      audio_format_table[i].i_fourcc );
572     return !!audio_format_table[i].i_fourcc;
573 }
574
575 static const char *GetOmxAudioRole( vlc_fourcc_t i_fourcc )
576 {
577     unsigned int i;
578
579     i_fourcc = vlc_fourcc_GetCodec( AUDIO_ES, i_fourcc );
580
581     for( i = 0; audio_format_table[i].i_codec != 0; i++ )
582         if( audio_format_table[i].i_fourcc == i_fourcc ) break;
583
584     return audio_format_table[i].psz_role;
585 }
586
587 static const char *GetOmxAudioEncRole( vlc_fourcc_t i_fourcc )
588 {
589     unsigned int i;
590
591     i_fourcc = vlc_fourcc_GetCodec( AUDIO_ES, i_fourcc );
592
593     for( i = 0; audio_enc_format_table[i].i_codec != 0; i++ )
594         if( audio_enc_format_table[i].i_fourcc == i_fourcc ) break;
595
596     return audio_enc_format_table[i].psz_role;
597 }
598
599 const char *GetOmxRole( vlc_fourcc_t i_fourcc, int i_cat, bool b_enc )
600 {
601     if(b_enc)
602         return i_cat == VIDEO_ES ?
603             GetOmxVideoEncRole( i_fourcc ) : GetOmxAudioEncRole( i_fourcc );
604     else
605         return i_cat == VIDEO_ES ?
606             GetOmxVideoRole( i_fourcc ) : GetOmxAudioRole( i_fourcc );
607 }
608
609 int GetOmxChromaFormat( vlc_fourcc_t i_fourcc,
610                         OMX_COLOR_FORMATTYPE *pi_omx_codec,
611                         const char **ppsz_name )
612 {
613     unsigned int i;
614
615     i_fourcc = vlc_fourcc_GetCodec( VIDEO_ES, i_fourcc );
616
617     for( i = 0; chroma_format_table[i].i_codec != 0; i++ )
618         if( chroma_format_table[i].i_fourcc == i_fourcc ) break;
619
620     if( pi_omx_codec ) *pi_omx_codec = chroma_format_table[i].i_codec;
621     if( ppsz_name ) *ppsz_name = vlc_fourcc_GetDescription( VIDEO_ES, i_fourcc );
622     return !!chroma_format_table[i].i_codec;
623 }
624
625 int GetVlcChromaFormat( OMX_COLOR_FORMATTYPE i_omx_codec,
626                         vlc_fourcc_t *pi_fourcc, const char **ppsz_name )
627 {
628     unsigned int i;
629
630     for( i = 0; chroma_format_table[i].i_codec != 0; i++ )
631         if( chroma_format_table[i].i_codec == i_omx_codec ) break;
632
633     if( pi_fourcc ) *pi_fourcc = chroma_format_table[i].i_fourcc;
634     if( ppsz_name ) *ppsz_name = vlc_fourcc_GetDescription( VIDEO_ES,
635                                      chroma_format_table[i].i_fourcc );
636     return !!chroma_format_table[i].i_fourcc;
637 }
638
639 int GetVlcChromaSizes( vlc_fourcc_t i_fourcc,
640                        unsigned int width, unsigned int height,
641                        unsigned int *size, unsigned int *pitch,
642                        unsigned int *chroma_pitch_div )
643 {
644     unsigned int i;
645
646     i_fourcc = vlc_fourcc_GetCodec( VIDEO_ES, i_fourcc );
647
648     for( i = 0; chroma_format_table[i].i_codec != 0; i++ )
649         if( chroma_format_table[i].i_fourcc == i_fourcc ) break;
650
651     /* Align on macroblock boundary */
652     width = (width + 15) & ~0xF;
653     height = (height + 15) & ~0xF;
654
655     if( size ) *size = width * height * chroma_format_table[i].i_size_mul / 2;
656     if( pitch ) *pitch = width * chroma_format_table[i].i_line_mul;
657     if( chroma_pitch_div )
658         *chroma_pitch_div = chroma_format_table[i].i_line_chroma_div;
659     return !!chroma_format_table[i].i_codec;
660 }
661
662 /*****************************************************************************
663  * Functions to deal with audio format parameters
664  *****************************************************************************/
665 static const struct {
666     OMX_AUDIO_CODINGTYPE encoding;
667     OMX_INDEXTYPE index;
668     int size;
669 } audio_encoding_param[] =
670 {   { OMX_AUDIO_CodingPCM, OMX_IndexParamAudioPcm,
671       sizeof(OMX_AUDIO_PARAM_PCMMODETYPE) },
672     { OMX_AUDIO_CodingADPCM, OMX_IndexParamAudioAdpcm,
673       sizeof(OMX_AUDIO_PARAM_ADPCMTYPE) },
674     { OMX_AUDIO_CodingAMR, OMX_IndexParamAudioAmr,
675       sizeof(OMX_AUDIO_PARAM_AMRTYPE) },
676     { OMX_AUDIO_CodingG711, OMX_IndexParamAudioPcm,
677       sizeof(OMX_AUDIO_PARAM_PCMMODETYPE) },
678     { OMX_AUDIO_CodingG723, OMX_IndexParamAudioG723,
679       sizeof(OMX_AUDIO_PARAM_G723TYPE) },
680     { OMX_AUDIO_CodingG726, OMX_IndexParamAudioG726,
681       sizeof(OMX_AUDIO_PARAM_G726TYPE) },
682     { OMX_AUDIO_CodingG729, OMX_IndexParamAudioG729,
683       sizeof(OMX_AUDIO_PARAM_G729TYPE) },
684     { OMX_AUDIO_CodingAAC, OMX_IndexParamAudioAac,
685       sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE) },
686     { OMX_AUDIO_CodingMP3, OMX_IndexParamAudioMp3,
687       sizeof(OMX_AUDIO_PARAM_MP3TYPE) },
688     { OMX_AUDIO_CodingSBC, OMX_IndexParamAudioSbc,
689       sizeof(OMX_AUDIO_PARAM_SBCTYPE) },
690     { OMX_AUDIO_CodingVORBIS, OMX_IndexParamAudioVorbis,
691       sizeof(OMX_AUDIO_PARAM_VORBISTYPE) },
692     { OMX_AUDIO_CodingWMA, OMX_IndexParamAudioWma,
693       sizeof(OMX_AUDIO_PARAM_WMATYPE) },
694     { OMX_AUDIO_CodingRA, OMX_IndexParamAudioRa,
695       sizeof(OMX_AUDIO_PARAM_RATYPE) },
696     { OMX_AUDIO_CodingUnused, 0, 0 }
697 };
698
699 static OMX_INDEXTYPE GetAudioParamFormatIndex(OMX_AUDIO_CODINGTYPE encoding)
700 {
701   int i;
702
703   for(i = 0; audio_encoding_param[i].encoding != OMX_AUDIO_CodingUnused &&
704       audio_encoding_param[i].encoding != encoding; i++);
705
706   return audio_encoding_param[i].index;
707 }
708
709 unsigned int GetAudioParamSize(OMX_INDEXTYPE index)
710 {
711   int i;
712
713   for(i = 0; audio_encoding_param[i].encoding != OMX_AUDIO_CodingUnused &&
714       audio_encoding_param[i].index != index; i++);
715
716   return audio_encoding_param[i].size;
717 }
718
719 OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
720     OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
721     vlc_fourcc_t i_codec, uint8_t i_channels, unsigned int i_samplerate,
722     unsigned int i_bitrate, unsigned int i_bps, unsigned int i_blocksize)
723 {
724     OMX_INDEXTYPE index;
725
726     switch(encoding)
727     {
728     case OMX_AUDIO_CodingPCM:
729     case OMX_AUDIO_CodingG711:
730         OMX_INIT_STRUCTURE(param->pcm);
731         param->pcm.nChannels = i_channels;
732         param->pcm.nSamplingRate = i_samplerate;
733         param->pcm.eNumData = OMX_NumericalDataSigned;
734         param->pcm.ePCMMode = OMX_AUDIO_PCMModeLinear;
735         param->pcm.eEndian = OMX_EndianLittle;
736         param->pcm.bInterleaved = OMX_TRUE;
737         param->pcm.nBitPerSample = i_bps;
738         param->pcm.eChannelMapping[0] = OMX_AUDIO_ChannelCF;
739         if(i_channels == 2)
740         {
741             param->pcm.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
742             param->pcm.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
743         }
744         break;
745     case OMX_AUDIO_CodingADPCM:
746         OMX_INIT_STRUCTURE(param->adpcm);
747         param->adpcm.nChannels = i_channels;
748         param->adpcm.nSampleRate = i_samplerate;
749         param->adpcm.nBitsPerSample = i_bps;
750         break;
751     case OMX_AUDIO_CodingAMR:
752         OMX_INIT_STRUCTURE(param->amr);
753         param->amr.nChannels = i_channels;
754         param->amr.nBitRate = i_bitrate;
755         if (i_codec == VLC_CODEC_AMR_WB)
756             param->amr.eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
757         else
758             param->amr.eAMRBandMode = OMX_AUDIO_AMRBandModeNB0;
759         param->amr.eAMRDTXMode = OMX_AUDIO_AMRDTXModeOff;
760         param->amr.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
761         break;
762     case OMX_AUDIO_CodingG723:
763         OMX_INIT_STRUCTURE(param->g723);
764         param->g723.nChannels = i_channels;
765         param->g723.bDTX = OMX_FALSE;
766         param->g723.eBitRate = OMX_AUDIO_G723ModeUnused;
767         param->g723.bHiPassFilter = OMX_TRUE;
768         param->g723.bPostFilter = OMX_TRUE;
769         break;
770     case OMX_AUDIO_CodingG726:
771         OMX_INIT_STRUCTURE(param->g726);
772         param->g726.nChannels = i_channels;
773         param->g726.eG726Mode = OMX_AUDIO_G726ModeUnused;
774         break;
775     case OMX_AUDIO_CodingG729:
776         OMX_INIT_STRUCTURE(param->g729);
777         param->g729.nChannels = i_channels;
778         param->g729.bDTX = OMX_FALSE;
779         param->g729.eBitType = OMX_AUDIO_G729;
780         break;
781     case OMX_AUDIO_CodingAAC:
782         OMX_INIT_STRUCTURE(param->aac);
783         param->aac.nChannels = i_channels;
784         param->aac.nSampleRate = i_samplerate;
785         param->aac.nBitRate = i_bitrate;
786         param->aac.nAudioBandWidth = 0;
787         param->aac.nFrameLength = 1024;
788         param->aac.nAACtools = OMX_AUDIO_AACToolAll;
789         param->aac.nAACERtools = OMX_AUDIO_AACERAll;
790         param->aac.eAACProfile = OMX_AUDIO_AACObjectLC;
791         param->aac.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4FF;
792         param->aac.eChannelMode = i_channels > 1 ?
793             OMX_AUDIO_ChannelModeStereo : OMX_AUDIO_ChannelModeMono;
794         break;
795     case OMX_AUDIO_CodingMP3:
796         OMX_INIT_STRUCTURE(param->mp3);
797         param->mp3.nChannels = i_channels;
798         param->mp3.nSampleRate = i_samplerate;
799         param->mp3.nBitRate = i_bitrate;
800         param->mp3.eChannelMode = i_channels > 1 ?
801             OMX_AUDIO_ChannelModeStereo : OMX_AUDIO_ChannelModeMono;
802         param->mp3.eFormat = OMX_AUDIO_MP3StreamFormatMP1Layer3;
803         break;
804     case OMX_AUDIO_CodingWMA:
805         OMX_INIT_STRUCTURE(param->wma);
806         param->wma.nChannels = i_channels;
807         param->wma.nBitRate = i_bitrate;
808         param->wma.eFormat = OMX_AUDIO_WMAFormatUnused;
809         param->wma.eProfile = OMX_AUDIO_WMAProfileUnused;
810         param->wma.nSamplingRate = i_samplerate;
811         param->wma.nBlockAlign = i_blocksize;
812         param->wma.nEncodeOptions = 0;
813         param->wma.nSuperBlockAlign = 0;
814         break;
815     case OMX_AUDIO_CodingRA:
816         OMX_INIT_STRUCTURE(param->ra);
817         param->ra.nChannels = i_channels;
818         param->ra.nSamplingRate = i_samplerate;
819         param->ra.nBitsPerFrame = i_bps;
820         param->ra.nSamplePerFrame = 0;
821         param->ra.nCouplingQuantBits = 0;
822         param->ra.nCouplingStartRegion = 0;
823         param->ra.nNumRegions = 0;
824         param->ra.eFormat = OMX_AUDIO_RAFormatUnused;
825         break;
826     case OMX_AUDIO_CodingVORBIS:
827         OMX_INIT_STRUCTURE(param->vorbis);
828         param->vorbis.nChannels = i_channels;
829         param->vorbis.nBitRate = i_bitrate;
830         param->vorbis.nMinBitRate = 0;
831         param->vorbis.nMaxBitRate = i_bitrate;
832         param->vorbis.nSampleRate = i_samplerate;
833         param->vorbis.nAudioBandWidth = 0;
834         param->vorbis.nQuality = 3;
835         param->vorbis.bManaged = OMX_FALSE;
836         param->vorbis.bDownmix = OMX_FALSE;
837         break;
838     default:
839         return OMX_ErrorBadParameter;
840     }
841
842     param->common.nPortIndex = i_port;
843
844     index = GetAudioParamFormatIndex(encoding);
845     return OMX_SetParameter(handle, index, param);
846 }
847
848 OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
849     OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
850     uint8_t *pi_channels, unsigned int *pi_samplerate,
851     unsigned int *pi_bitrate, unsigned int *pi_bps, unsigned int *pi_blocksize)
852 {
853     int i_channels = 0, i_samplerate = 0, i_bitrate = 0;
854     int i_bps = 0, i_blocksize = 0;
855     OMX_ERRORTYPE omx_error;
856     OMX_INDEXTYPE index;
857
858     OMX_INIT_COMMON(param->common);
859     param->common.nPortIndex = i_port;
860     index = GetAudioParamFormatIndex(encoding);
861     if(!index) return OMX_ErrorNotImplemented;
862
863     param->common.nSize = GetAudioParamSize(index);
864     omx_error = OMX_GetParameter(handle, index, param);
865     if(omx_error != OMX_ErrorNone) return omx_error;
866
867     switch(encoding)
868     {
869     case OMX_AUDIO_CodingPCM:
870     case OMX_AUDIO_CodingG711:
871         i_channels = param->pcm.nChannels;
872         i_samplerate = param->pcm.nSamplingRate;
873         i_bps = param->pcm.nBitPerSample;
874         break;
875     case OMX_AUDIO_CodingADPCM:
876         i_channels = param->adpcm.nChannels;
877         i_samplerate = param->adpcm.nSampleRate;
878         i_bps = param->adpcm.nBitsPerSample;
879         break;
880     case OMX_AUDIO_CodingAMR:
881         i_channels = param->amr.nChannels;
882         i_bitrate = param->amr.nBitRate;
883         i_samplerate = 8000;
884         break;
885     case OMX_AUDIO_CodingG723:
886         i_channels = param->g723.nChannels;
887         break;
888     case OMX_AUDIO_CodingG726:
889         i_channels = param->g726.nChannels;
890         break;
891     case OMX_AUDIO_CodingG729:
892         i_channels = param->g729.nChannels;
893         break;
894     case OMX_AUDIO_CodingAAC:
895         i_channels = param->aac.nChannels;
896         i_samplerate = param->aac.nSampleRate;
897         i_bitrate = param->aac.nBitRate;
898         i_channels = param->aac.eChannelMode == OMX_AUDIO_ChannelModeStereo ? 2 : 1;
899         break;
900     case OMX_AUDIO_CodingMP3:
901         i_channels = param->mp3.nChannels;
902         i_samplerate = param->mp3.nSampleRate;
903         i_bitrate = param->mp3.nBitRate;
904         i_channels = param->mp3.eChannelMode == OMX_AUDIO_ChannelModeStereo ? 2 : 1;
905         break;
906     case OMX_AUDIO_CodingVORBIS:
907         i_channels = param->vorbis.nChannels;
908         i_bitrate = param->vorbis.nBitRate;
909         i_samplerate = param->vorbis.nSampleRate;
910         break;
911     case OMX_AUDIO_CodingWMA:
912         i_channels = param->wma.nChannels;
913         i_bitrate = param->wma.nBitRate;
914         i_samplerate = param->wma.nSamplingRate;
915         i_blocksize = param->wma.nBlockAlign;
916         break;
917     case OMX_AUDIO_CodingRA:
918         i_channels = param->ra.nChannels;
919         i_samplerate = param->ra.nSamplingRate;
920         i_bps = param->ra.nBitsPerFrame;
921         break;
922     default:
923         return OMX_ErrorBadParameter;
924     }
925
926     if(pi_channels) *pi_channels = i_channels;
927     if(pi_samplerate) *pi_samplerate = i_samplerate;
928     if(pi_bitrate) *pi_bitrate = i_bitrate;
929     if(pi_bps) *pi_bps = i_bps;
930     if(pi_blocksize) *pi_blocksize = i_blocksize;
931     return OMX_ErrorNone;
932 }
933
934 /*****************************************************************************
935  * PrintOmx: print component summary 
936  *****************************************************************************/
937 void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port)
938 {
939     OMX_PARAM_PORTDEFINITIONTYPE definition;
940     OMX_PORT_PARAM_TYPE param;
941     OMX_ERRORTYPE omx_error;
942     unsigned int i, j;
943
944     /* Find the input / output ports */
945     OMX_INIT_STRUCTURE(param);
946     OMX_INIT_STRUCTURE(definition);
947
948     for(i = 0; i < 3; i++)
949     {
950         omx_error = OMX_GetParameter(omx_handle, OMX_IndexParamAudioInit + i, &param);
951         if(omx_error != OMX_ErrorNone) continue;
952
953         if(i_port == OMX_ALL)
954             msg_Dbg( p_dec, "found %i %s ports", (int)param.nPorts,
955                      i == 0 ? "audio" : i == 1 ? "image" : "video" );
956
957         for(j = 0; j < param.nPorts; j++)
958         {
959             unsigned int i_samplerate, i_bitrate;
960             unsigned int i_bitspersample, i_blockalign;
961             uint8_t i_channels;
962             OmxFormatParam format_param;
963             vlc_fourcc_t i_fourcc;
964             const char *psz_name;
965             OMX_CONFIG_RECTTYPE crop_rect;
966
967             if(i_port != OMX_ALL && i_port != param.nStartPortNumber + j)
968                 continue;
969
970             /* Get port definition */
971             definition.nPortIndex = param.nStartPortNumber + j;
972             omx_error = OMX_GetParameter(omx_handle, OMX_IndexParamPortDefinition,
973                                       &definition);
974             if(omx_error != OMX_ErrorNone) continue;
975
976             OMX_PARAM_U32TYPE u32param;
977             OMX_INIT_STRUCTURE(u32param);
978             u32param.nPortIndex = param.nStartPortNumber + j;
979             omx_error = OMX_GetParameter(omx_handle, OMX_IndexParamNumAvailableStreams,
980                                          (OMX_PTR)&u32param);
981
982             msg_Dbg( p_dec, "-> %s %i (%i streams) (%i:%i:%i buffers) (%i,%i) %s",
983                      definition.eDir == OMX_DirOutput ? "output" : "input",
984                      (int)definition.nPortIndex, (int)u32param.nU32,
985                      (int)definition.nBufferCountActual,
986                      (int)definition.nBufferCountMin, (int)definition.nBufferSize,
987                      (int)definition.bBuffersContiguous,
988                      (int)definition.nBufferAlignment,
989                      definition.bEnabled ? "enabled" : "disabled" );
990
991             switch(definition.eDomain)
992             {
993             case OMX_PortDomainVideo:
994
995                 if(definition.format.video.eCompressionFormat)
996                     GetVlcVideoFormat( definition.format.video.eCompressionFormat,
997                                        &i_fourcc, &psz_name );
998                 else
999                     GetVlcChromaFormat( definition.format.video.eColorFormat,
1000                                         &i_fourcc, &psz_name );
1001
1002                 OMX_INIT_STRUCTURE(crop_rect);
1003                 crop_rect.nPortIndex = definition.nPortIndex;
1004                 omx_error = OMX_GetConfig(omx_handle, OMX_IndexConfigCommonOutputCrop, &crop_rect);
1005                 if (omx_error != OMX_ErrorNone)
1006                 {
1007                     crop_rect.nLeft = crop_rect.nTop = 0;
1008                     crop_rect.nWidth  = definition.format.video.nFrameWidth;
1009                     crop_rect.nHeight = definition.format.video.nFrameHeight;
1010                 }
1011
1012                 msg_Dbg( p_dec, "  -> video %s %ix%i@%.2f (%i,%i) (%i,%i) (%i,%i,%i,%i)", psz_name,
1013                          (int)definition.format.video.nFrameWidth,
1014                          (int)definition.format.video.nFrameHeight,
1015                          (float)definition.format.video.xFramerate/(float)(1<<16),
1016                          (int)definition.format.video.eCompressionFormat,
1017                          (int)definition.format.video.eColorFormat,
1018                          (int)definition.format.video.nStride,
1019                          (int)definition.format.video.nSliceHeight,
1020                          (int)crop_rect.nLeft, (int)crop_rect.nTop,
1021                          (int)crop_rect.nWidth, (int)crop_rect.nHeight);
1022                 break;
1023
1024             case OMX_PortDomainAudio:
1025
1026                 OmxToVlcAudioFormat( definition.format.audio.eEncoding,
1027                                    &i_fourcc, &psz_name );
1028
1029                 GetAudioParameters(omx_handle, &format_param,
1030                                    definition.nPortIndex,
1031                                    definition.format.audio.eEncoding,
1032                                    &i_channels, &i_samplerate, &i_bitrate,
1033                                    &i_bitspersample, &i_blockalign);
1034
1035                 msg_Dbg( p_dec, "  -> audio %s (%i) %i,%i,%i,%i,%i", psz_name,
1036                          (int)definition.format.audio.eEncoding,
1037                          i_channels, i_samplerate, i_bitrate, i_bitspersample,
1038                          i_blockalign);
1039                 break;
1040
1041             default: break;
1042             }
1043         }
1044     }
1045 }