[vlc-commits] omx: decode qualcomm-specific tiled nv12 format

Rafaël Carré git at videolan.org
Mon Jun 25 21:31:41 CEST 2012


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon Jun 25 21:27:35 2012 +0200| [cd14febde554a0f36b07e7f16b618920da1afc22] | committer: Rafaël Carré

omx: decode qualcomm-specific tiled nv12 format

Tested on HP Touchpad up to 1280x720

1920x1080 gives:
E/OMX-VDEC-1080P: ERROR: IP Requirements(#1: 2097152) Requested(#2: 4177920)
Which probably means that provided buffers are too small for the decoder
to operate

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cd14febde554a0f36b07e7f16b618920da1afc22
---

 modules/codec/omxil/Modules.am    |    3 +-
 modules/codec/omxil/omxil.c       |    2 +
 modules/codec/omxil/omxil_utils.h |    2 +-
 modules/codec/omxil/qcom.c        |  124 +++++++++++++++++++++++++++++++++++++
 modules/codec/omxil/qcom.h        |    3 +
 modules/codec/omxil/utils.c       |    8 +++
 6 files changed, 140 insertions(+), 2 deletions(-)

diff --git a/modules/codec/omxil/Modules.am b/modules/codec/omxil/Modules.am
index a33b2e7..b22c0a9 100644
--- a/modules/codec/omxil/Modules.am
+++ b/modules/codec/omxil/Modules.am
@@ -1,6 +1,7 @@
 SOURCES_omxil = omxil.c utils.c omxil.h omxil_utils.h \
 	OMX_Component.h OMX_Core.h OMX_Image.h OMX_IVCommon.h OMX_Types.h \
-        OMX_Audio.h OMX_Index.h OMX_Other.h OMX_Video.h ../h264_nal.h
+	OMX_Audio.h OMX_Index.h OMX_Other.h OMX_Video.h ../h264_nal.h \
+	qcom.h qcom.c
 
 CPPFLAGS_iomx = -DUSE_IOMX
 SOURCES_iomx = $(SOURCES_omxil)
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 8e6ebf9..f65c85c 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -272,6 +272,7 @@ static OMX_ERRORTYPE ImplementationSpecificWorkarounds(decoder_t *p_dec,
             def->format.video.xFramerate >>= 16;
         }
     }
+#if 0 /* FIXME: doesn't apply for HP Touchpad */
     else if (!strncmp(p_sys->psz_component, "OMX.qcom.video.decoder.",
                       strlen("OMX.qcom.video.decoder")))
     {
@@ -282,6 +283,7 @@ static OMX_ERRORTYPE ImplementationSpecificWorkarounds(decoder_t *p_dec,
             p_port->i_frame_size = def->nBufferSize;
         }
     }
+#endif
 
     return OMX_ErrorNone;
 }
diff --git a/modules/codec/omxil/omxil_utils.h b/modules/codec/omxil/omxil_utils.h
index 79b7406..635951c 100644
--- a/modules/codec/omxil/omxil_utils.h
+++ b/modules/codec/omxil/omxil_utils.h
@@ -186,5 +186,5 @@ unsigned int GetAudioParamSize(OMX_INDEXTYPE index);
  *****************************************************************************/
 #define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00
 #define OMX_TI_COLOR_FormatYUV420PackedSemiPlanar 0x7F000100
-
+#define QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka 0x7FA30C03
 #define OMX_IndexVendorSetYUV420pMode 0x7f000003
diff --git a/modules/codec/omxil/qcom.c b/modules/codec/omxil/qcom.c
new file mode 100644
index 0000000..9f530b2
--- /dev/null
+++ b/modules/codec/omxil/qcom.c
@@ -0,0 +1,124 @@
+/*****************************************************************************
+ * qcom.c : pixel format translation for Qualcomm tiled nv12
+ *****************************************************************************
+ * Copyright © 2012 Rafaël Carré
+ *
+ * Authors: Rafaël Carré <funman at videolanorg>
+ *
+ * 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
+ * (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.
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_picture.h>
+
+#include <string.h>
+#include <stdint.h>
+
+#include "qcom.h"
+
+
+/*
+ * The format is called QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka.
+ * First wtf: why call it YUV420? It is NV12 (interleaved U&V).
+ * Second wtf: why this format at all?
+ */
+#define TILE_WIDTH 64
+#define TILE_HEIGHT 32
+#define TILE_SIZE (TILE_WIDTH * TILE_HEIGHT)
+
+/* get frame tile coordinate. XXX: nothing to be understood here, don't try. */
+static size_t tile_pos(size_t x, size_t y, size_t w, size_t h)
+{
+    size_t flim = x + (y & ~1) * w;
+
+    if (y & 1) {
+        flim += (x & ~3) + 2;
+    } else if ((h & 1) == 0 || y != (h - 1)) {
+        flim += (x + 2) & ~3;
+    }
+
+    return flim;
+}
+
+void qcom_convert(const uint8_t *src, picture_t *pic)
+{
+    size_t width = pic->format.i_width;
+    size_t pitch = pic->p[0].i_pitch;
+    size_t height = pic->format.i_height;
+
+    const size_t tile_w = (width - 1) / TILE_WIDTH + 1;
+    const size_t tile_w_align = (tile_w + 1) & ~1;
+
+    const size_t tile_h_luma = (height - 1) / TILE_HEIGHT + 1;
+    const size_t tile_h_chroma = (height / 2 - 1) / TILE_HEIGHT + 1;
+
+    size_t luma_size = tile_w_align * tile_h_luma * TILE_SIZE;
+
+#define TILE_GROUP_SIZE (4 * TILE_SIZE)
+    if((luma_size % TILE_GROUP_SIZE) != 0)
+        luma_size = (((luma_size - 1) / TILE_GROUP_SIZE) + 1) * TILE_GROUP_SIZE;
+
+    for(size_t y = 0; y < tile_h_luma; y++) {
+        size_t row_width = width;
+        for(size_t x = 0; x < tile_w; x++) {
+            /* luma source pointer for this tile */
+            const uint8_t *src_luma  = src
+                + tile_pos(x, y,tile_w_align, tile_h_luma) * TILE_SIZE;
+
+            /* chroma source pointer for this tile */
+            const uint8_t *src_chroma = src + luma_size
+                + tile_pos(x, y/2, tile_w_align, tile_h_chroma) * TILE_SIZE;
+            if (y & 1)
+                src_chroma += TILE_SIZE/2;
+
+            /* account for right columns */
+            size_t tile_width = row_width;
+            if (tile_width > TILE_WIDTH)
+                tile_width = TILE_WIDTH;
+
+            /* account for bottom rows */
+            size_t tile_height = height;
+            if (tile_height > TILE_HEIGHT)
+                tile_height = TILE_HEIGHT;
+
+            /* dest luma memory index for this tile */
+            size_t luma_idx = y * TILE_HEIGHT * pitch + x * TILE_WIDTH;
+
+            /* dest chroma memory index for this tile */
+            /* XXX: remove divisions */
+            size_t chroma_idx = (luma_idx / pitch) * pitch/2 + (luma_idx % pitch);
+
+            tile_height /= 2; // we copy 2 luma lines at once
+            while (tile_height--) {
+                memcpy(&pic->p[0].p_pixels[luma_idx], src_luma, tile_width);
+                src_luma += TILE_WIDTH;
+                luma_idx += pitch;
+
+                memcpy(&pic->p[0].p_pixels[luma_idx], src_luma, tile_width);
+                src_luma += TILE_WIDTH;
+                luma_idx += pitch;
+
+                memcpy(&pic->p[1].p_pixels[chroma_idx], src_chroma, tile_width);
+                src_chroma += TILE_WIDTH;
+                chroma_idx += pitch;
+            }
+            row_width -= TILE_WIDTH;
+        }
+        height -= TILE_HEIGHT;
+    }
+}
diff --git a/modules/codec/omxil/qcom.h b/modules/codec/omxil/qcom.h
new file mode 100644
index 0000000..0286a91
--- /dev/null
+++ b/modules/codec/omxil/qcom.h
@@ -0,0 +1,3 @@
+#include <vlc_picture.h>
+
+void qcom_convert(const uint8_t *src, picture_t *pic);
diff --git a/modules/codec/omxil/utils.c b/modules/codec/omxil/utils.c
index 1061fba..96deb46 100644
--- a/modules/codec/omxil/utils.c
+++ b/modules/codec/omxil/utils.c
@@ -35,6 +35,7 @@
 #include <vlc_cpu.h>
 
 #include "omxil.h"
+#include "qcom.h"
 
 /*****************************************************************************
  * Events utility functions
@@ -129,6 +130,12 @@ void CopyOmxPicture( decoder_t *p_dec, picture_t *p_pic,
     i_src_stride  = p_sys->out.i_frame_stride;
     p_src = p_header->pBuffer + p_header->nOffset;
 
+    if( p_dec->p_sys->out.definition.format.video.eColorFormat == 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;
@@ -350,6 +357,7 @@ static const struct
     { 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 },



More information about the vlc-commits mailing list