]> git.sesse.net Git - vlc/blobdiff - modules/codec/omxil/utils.c
omxil: Signal the right AMR frame format
[vlc] / modules / codec / omxil / utils.c
index 468ba9346ed2c4af6becd8a6319ba1c993966af5..7f93dc784666f9cc2c75d5d1464d8ab2c0c22400 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * utils.c: helper functions
  *****************************************************************************
- * Copyright (C) 2010 the VideoLAN team
+ * Copyright (C) 2010 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -35,6 +35,7 @@
 #include <vlc_cpu.h>
 
 #include "omxil.h"
+#include "qcom.h"
 
 /*****************************************************************************
  * Events utility functions
@@ -118,27 +119,29 @@ OMX_ERRORTYPE WaitForSpecificOmxEvent(decoder_t *p_dec,
 /*****************************************************************************
  * Picture utility functions
  *****************************************************************************/
-void CopyOmxPicture( decoder_t *p_dec, picture_t *p_pic,
-                     OMX_BUFFERHEADERTYPE *p_header, int i_slice_height )
+void CopyOmxPicture( int i_color_format, picture_t *p_pic,
+                     int i_slice_height,
+                     int i_src_stride, uint8_t *p_src, int i_chroma_div )
 {
-    decoder_sys_t *p_sys = p_dec->p_sys;
-    int i_src_stride, i_dst_stride;
+    uint8_t *p_dst;
+    int i_dst_stride;
     int i_plane, i_width, i_line;
-    uint8_t *p_dst, *p_src;
-
-    i_src_stride  = p_sys->out.i_frame_stride;
-    p_src = p_header->pBuffer + p_header->nOffset;
+    if( i_color_format == QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka )
+    {
+        qcom_convert(p_src, p_pic);
+        return;
+    }
 
     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
     {
-        if(i_plane == 1) i_src_stride /= p_sys->out.i_frame_stride_chroma_div;
+        if(i_plane == 1) i_src_stride /= i_chroma_div;
         p_dst = p_pic->p[i_plane].p_pixels;
         i_dst_stride = p_pic->p[i_plane].i_pitch;
         i_width = p_pic->p[i_plane].i_visible_pitch;
 
         for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ )
         {
-            vlc_memcpy( p_dst, p_src, i_width );
+            memcpy( p_dst, p_src, i_width );
             p_src += i_src_stride;
             p_dst += i_dst_stride;
         }
@@ -172,13 +175,42 @@ void CopyVlcPicture( decoder_t *p_dec, OMX_BUFFERHEADERTYPE *p_header,
 
         for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ )
         {
-            vlc_memcpy( p_dst, p_src, i_width );
+            memcpy( p_dst, p_src, i_width );
             p_src += i_src_stride;
             p_dst += i_dst_stride;
         }
     }
 }
 
+int IgnoreOmxDecoderPadding(const char *name)
+{
+    // The list of decoders that signal padding properly is not necessary,
+    // since that is the default, but keep it here for reference. (This is
+    // only relevant for manufacturers that are known to have decoders with
+    // this kind of bug.)
+/*
+    static const char *padding_decoders[] = {
+        "OMX.SEC.AVC.Decoder",
+        "OMX.SEC.wmv7.dec",
+        "OMX.SEC.wmv8.dec",
+        NULL
+    };
+*/
+    static const char *nopadding_decoders[] = {
+        "OMX.SEC.avc.dec",
+        "OMX.SEC.avcdec",
+        "OMX.SEC.MPEG4.Decoder",
+        "OMX.SEC.mpeg4.dec",
+        "OMX.SEC.vc1.dec",
+        NULL
+    };
+    for (const char **ptr = nopadding_decoders; *ptr; ptr++) {
+        if (!strcmp(*ptr, name))
+            return 1;
+    }
+    return 0;
+}
+
 /*****************************************************************************
  * Logging utility functions
  *****************************************************************************/
@@ -244,7 +276,7 @@ const char *ErrorToString(OMX_ERRORTYPE error)
         "OMX_ErrorFormatNotDetected", "OMX_ErrorContentPipeOpenFailed",
         "OMX_ErrorContentPipeCreationFailed", "OMX_ErrorSeperateTablesUsed",
         "OMX_ErrorTunnelingUnsupported",
-        "OMX_Error unkown"
+        "OMX_Error unknown"
     };
 
     if(error == OMX_ErrorNone) return "OMX_ErrorNone";
@@ -271,10 +303,12 @@ static const struct
     { VLC_CODEC_MP4V, OMX_VIDEO_CodingMPEG4, "video_decoder.mpeg4" },
     { VLC_CODEC_H264, OMX_VIDEO_CodingAVC,   "video_decoder.avc"   },
     { VLC_CODEC_H263, OMX_VIDEO_CodingH263,  "video_decoder.h263"  },
-    { VLC_CODEC_WMV1, OMX_VIDEO_CodingWMV,   "video_decoder.wmv  },
-    { VLC_CODEC_WMV2, OMX_VIDEO_CodingWMV,   "video_decoder.wmv  },
+    { VLC_CODEC_WMV1, OMX_VIDEO_CodingWMV,   "video_decoder.wmv1"  },
+    { VLC_CODEC_WMV2, OMX_VIDEO_CodingWMV,   "video_decoder.wmv2"  },
     { VLC_CODEC_WMV3, OMX_VIDEO_CodingWMV,   "video_decoder.wmv"   },
+    { VLC_CODEC_VC1,  OMX_VIDEO_CodingWMV,   "video_decoder.wmv"   },
     { VLC_CODEC_MJPG, OMX_VIDEO_CodingMJPEG, "video_decoder.jpeg"  },
+    { VLC_CODEC_MJPG, OMX_VIDEO_CodingMJPEG, "video_decoder.mjpeg" },
     { VLC_CODEC_RV10, OMX_VIDEO_CodingRV,    "video_decoder.rv"    },
     { VLC_CODEC_RV20, OMX_VIDEO_CodingRV,    "video_decoder.rv"    },
     { VLC_CODEC_RV30, OMX_VIDEO_CodingRV,    "video_decoder.rv"    },
@@ -290,10 +324,11 @@ static const struct
 
 } audio_format_table[] =
 {
-    { VLC_CODEC_AMR_NB, OMX_AUDIO_CodingAMR, "audio_decoder.amr" },
-    { VLC_CODEC_AMR_WB, OMX_AUDIO_CodingAMR, "audio_decoder.amr" },
+    { VLC_CODEC_AMR_NB, OMX_AUDIO_CodingAMR, "audio_decoder.amrnb" },
+    { VLC_CODEC_AMR_WB, OMX_AUDIO_CodingAMR, "audio_decoder.amrwb" },
     { VLC_CODEC_MP4A,   OMX_AUDIO_CodingAAC, "audio_decoder.aac" },
     { VLC_CODEC_S16N,   OMX_AUDIO_CodingPCM, "audio_decoder.pcm" },
+    { VLC_CODEC_MP3,    OMX_AUDIO_CodingMP3, "audio_decoder.mp3" },
     { 0, 0, 0 }
 };
 
@@ -328,8 +363,8 @@ static const struct
 
 } audio_enc_format_table[] =
 {
-    { VLC_CODEC_AMR_NB, OMX_AUDIO_CodingAMR, "audio_encoder.amr" },
-    { VLC_CODEC_AMR_WB, OMX_AUDIO_CodingAMR, "audio_encoder.amr" },
+    { VLC_CODEC_AMR_NB, OMX_AUDIO_CodingAMR, "audio_encoder.amrnb" },
+    { VLC_CODEC_AMR_WB, OMX_AUDIO_CodingAMR, "audio_encoder.amrwb" },
     { VLC_CODEC_MP4A,   OMX_AUDIO_CodingAAC, "audio_encoder.aac" },
     { VLC_CODEC_S16N,   OMX_AUDIO_CodingPCM, "audio_encoder.pcm" },
     { 0, 0, 0 }
@@ -347,6 +382,10 @@ static const struct
 {
     { VLC_CODEC_I420, OMX_COLOR_FormatYUV420Planar, 3, 1, 2 },
     { VLC_CODEC_I420, OMX_COLOR_FormatYUV420PackedPlanar, 3, 1, 2 },
+    { VLC_CODEC_NV12, OMX_COLOR_FormatYUV420SemiPlanar, 3, 1, 1 },
+    { VLC_CODEC_NV21, OMX_QCOM_COLOR_FormatYVU420SemiPlanar, 3, 1, 1 },
+    { VLC_CODEC_NV12, OMX_TI_COLOR_FormatYUV420PackedSemiPlanar, 3, 1, 2 },
+    { VLC_CODEC_NV12, QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka, 3, 1, 1 },
     { VLC_CODEC_YUYV, OMX_COLOR_FormatYCbYCr, 4, 2, 0 },
     { VLC_CODEC_YVYU, OMX_COLOR_FormatYCrYCb, 4, 2, 0 },
     { VLC_CODEC_UYVY, OMX_COLOR_FormatCbYCrY, 4, 2, 0 },
@@ -424,7 +463,7 @@ int GetOmxAudioFormat( vlc_fourcc_t i_fourcc,
     return !!audio_format_table[i].i_codec;
 }
 
-int GetVlcAudioFormat( OMX_AUDIO_CODINGTYPE i_omx_codec,
+int OmxToVlcAudioFormat( OMX_AUDIO_CODINGTYPE i_omx_codec,
                        vlc_fourcc_t *pi_fourcc, const char **ppsz_name )
 {
     unsigned int i;
@@ -572,7 +611,7 @@ static OMX_INDEXTYPE GetAudioParamFormatIndex(OMX_AUDIO_CODINGTYPE encoding)
   return audio_encoding_param[i].index;
 }
 
-static unsigned int GetAudioParamSize(OMX_INDEXTYPE index)
+unsigned int GetAudioParamSize(OMX_INDEXTYPE index)
 {
   int i;
 
@@ -620,7 +659,7 @@ OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
         param->amr.nBitRate = i_bitrate;
         param->amr.eAMRBandMode = OMX_AUDIO_AMRBandModeUnused;
         param->amr.eAMRDTXMode = OMX_AUDIO_AMRDTXModeOff;
-        param->amr.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatConformance;
+        param->amr.eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
         break;
     case OMX_AUDIO_CodingG723:
         OMX_INIT_STRUCTURE(param->g723);
@@ -651,8 +690,8 @@ OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
         param->aac.nAACtools = OMX_AUDIO_AACToolAll;
         param->aac.nAACERtools = OMX_AUDIO_AACERAll;
         param->aac.eAACProfile = OMX_AUDIO_AACObjectLC;
-        param->aac.eAACStreamFormat = OMX_AUDIO_AACStreamFormatRAW;
-        param->aac.eChannelMode = i_channels ?
+        param->aac.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4FF;
+        param->aac.eChannelMode = i_channels > 1 ?
             OMX_AUDIO_ChannelModeStereo : OMX_AUDIO_ChannelModeMono;
         break;
     case OMX_AUDIO_CodingMP3:
@@ -660,7 +699,7 @@ OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
         param->mp3.nChannels = i_channels;
         param->mp3.nSampleRate = i_samplerate;
         param->mp3.nBitRate = i_bitrate;
-        param->mp3.eChannelMode = i_channels ?
+        param->mp3.eChannelMode = i_channels > 1 ?
             OMX_AUDIO_ChannelModeStereo : OMX_AUDIO_ChannelModeMono;
         param->mp3.eFormat = OMX_AUDIO_MP3StreamFormatMP1Layer3;
         break;
@@ -825,6 +864,7 @@ void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port)
             OmxFormatParam format_param;
             vlc_fourcc_t i_fourcc;
             const char *psz_name;
+            OMX_CONFIG_RECTTYPE crop_rect;
 
             if(i_port != OMX_ALL && i_port != param.nStartPortNumber + j)
                 continue;
@@ -861,19 +901,31 @@ void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port)
                     GetVlcChromaFormat( definition.format.video.eColorFormat,
                                         &i_fourcc, &psz_name );
 
-                msg_Dbg( p_dec, "  -> video %s %ix%i@%.2f (%i,%i) (%i,%i)", psz_name,
+                OMX_INIT_STRUCTURE(crop_rect);
+                crop_rect.nPortIndex = definition.nPortIndex;
+                omx_error = OMX_GetConfig(omx_handle, OMX_IndexConfigCommonOutputCrop, &crop_rect);
+                if (omx_error != OMX_ErrorNone)
+                {
+                    crop_rect.nLeft = crop_rect.nTop = 0;
+                    crop_rect.nWidth  = definition.format.video.nFrameWidth;
+                    crop_rect.nHeight = definition.format.video.nFrameHeight;
+                }
+
+                msg_Dbg( p_dec, "  -> video %s %ix%i@%.2f (%i,%i) (%i,%i) (%i,%i,%i,%i)", psz_name,
                          (int)definition.format.video.nFrameWidth,
                          (int)definition.format.video.nFrameHeight,
                          (float)definition.format.video.xFramerate/(float)(1<<16),
                          (int)definition.format.video.eCompressionFormat,
                          (int)definition.format.video.eColorFormat,
                          (int)definition.format.video.nStride,
-                         (int)definition.format.video.nSliceHeight);
+                         (int)definition.format.video.nSliceHeight,
+                         (int)crop_rect.nLeft, (int)crop_rect.nTop,
+                         (int)crop_rect.nWidth, (int)crop_rect.nHeight);
                 break;
 
             case OMX_PortDomainAudio:
 
-                GetVlcAudioFormat( definition.format.audio.eEncoding,
+                OmxToVlcAudioFormat( definition.format.audio.eEncoding,
                                    &i_fourcc, &psz_name );
 
                 GetAudioParameters(omx_handle, &format_param,