[DMABUF] dmabuf changes according to the IPC3.X
authorChandramohan <a0131763@ti.com>
Thu, 5 Sep 2013 13:21:40 +0000 (18:51 +0530)
committerChandramohan <a0131763@ti.com>
Thu, 5 Sep 2013 13:21:40 +0000 (18:51 +0530)
1. Changed vidde3test app to pass dmabuf fd for inbuf/outbuf.
2. buffer lock and unlock is added for outbuf.
3. X11 dependencies removed.
4. added dce_init/dce_deinit API exposed by libdce

Signed-off-by: Chandramohan <a0131763@ti.com>
Makefile.am
configure.ac
util/Makefile.am
util/display-kms.c
util/util.h
viddec3test.c

index 53eb33601d2d813a58b8c26fb6bf6f978fa0ac29..c22c8cba5560d68f264417e0256ebb33eb69bb41 100644 (file)
@@ -26,8 +26,8 @@ if ENABLE_DCE
 bin_PROGRAMS += viddec3test
 endif
 
-LDADD_COMMON = util/libutil.la @DRM_LIBS@ @X11_LIBS@ @DCE_LIBS@ @GBM_LIBS@ @EGL_LIBS@ @GLES2_LIBS@
-AM_CFLAGS = @DRM_CFLAGS@ @X11_CFLAGS@ @DCE_CFLAGS@ @GBM_CFLAGS@ @EGL_CFLAGS@ @GLES2_CFLAGS@ @WARN_CFLAGS@ -I$(top_srcdir)/util
+LDADD_COMMON = util/libutil.la @DRM_LIBS@ @DCE_LIBS@ @GBM_LIBS@ @EGL_LIBS@ @GLES2_LIBS@
+AM_CFLAGS = @DRM_CFLAGS@ @DCE_CFLAGS@ @GBM_CFLAGS@ @EGL_CFLAGS@ @GLES2_CFLAGS@ @WARN_CFLAGS@ -I$(top_srcdir)/util
 
 fliptest_SOURCES = fliptest.c
 fliptest_LDADD = $(LDADD_COMMON)
index 332030478be8fa71afb975e1744a312922a20a37..679375f07c8e934806ba884c58b773ed7f7560fd 100644 (file)
@@ -65,16 +65,6 @@ else
 fi
 AM_CONDITIONAL(ENABLE_V4L2_DMABUF, [test "x$HAVE_V4L2_DMABUF" = xyes])
 
-# Check optional X11:
-AC_ARG_ENABLE([x11], AS_HELP_STRING([--disable-x11], [disable x11/dri2video support]))
-AS_IF([test "x$enable_x11" != "xno"], [PKG_CHECK_MODULES(X11, x11 dri2, [HAVE_X11=yes])])
-if test "x$HAVE_X11" = "xyes"; then
-       AC_DEFINE(HAVE_X11, 1, [Have X11 support])
-else
-       AC_MSG_WARN([No X11 support detected, disabling X11 support])
-fi
-AM_CONDITIONAL(ENABLE_X11, [test "x$HAVE_X11" = xyes])
-
 # Check optional KMSCUBE:
 AC_ARG_ENABLE([kmscube], AS_HELP_STRING([--disable-kmscube], [disable kmscube display support]))
 AS_IF([test "x$enable_kmscube" != "xno"], [PKG_CHECK_EXISTS(gbm egl glesv2, [HAVE_KMSCUBE=yes], [HAVE_KMSCUBE=no])])
index 7a8ab3c9867cd392e688b2167b281ee7bd25a756..099845b447e041fd2fb7885212febe8a3a9eb292 100644 (file)
@@ -21,10 +21,6 @@ libutil_la_SOURCES = \
        display-kms.c \
        util.c
 
-if ENABLE_X11
-libutil_la_SOURCES += display-x11.c
-endif
-
 if ENABLE_V4L2_DMABUF
 libutil_la_SOURCES += v4l2.c
 endif
@@ -37,5 +33,5 @@ if ENABLE_KMSCUBE
 libutil_la_SOURCES += display-kmscube.c esTransform.c
 endif
 
-libutil_la_LIBADD = @DRM_LIBS@ @X11_LIBS@ @DCE_LIBS@ @GBM_LIBS@ @EGL_LIBS@ @GLES2_LIBS@
-libutil_la_CFLAGS = @DRM_CFLAGS@ @X11_CFLAGS@ @DCE_CFLAGS@ @WARN_CFLAGS@ @GBM_CFLAGS@ @EGL_CFLAGS@ @GLES2_CFLAGS@
+libutil_la_LIBADD = @DRM_LIBS@ @DCE_LIBS@ @GBM_LIBS@ @EGL_LIBS@ @GLES2_LIBS@
+libutil_la_CFLAGS = @DRM_CFLAGS@ @DCE_CFLAGS@ @WARN_CFLAGS@ @GBM_CFLAGS@ @EGL_CFLAGS@ @GLES2_CFLAGS@
index 26ec275f5e6f3f464e24973ea8b6bea7c0d16af2..3af3195165c7a899b801ab6e578507abd26b97af 100644 (file)
@@ -81,7 +81,6 @@ alloc_bo(struct display *disp, uint32_t bpp, uint32_t width, uint32_t height,
                        bo_flags |= OMAP_BO_TILED_32;
                }
        }
-
        bo_flags |= OMAP_BO_WC;
 
        if (bo_flags & OMAP_BO_TILED) {
@@ -142,12 +141,15 @@ alloc_buffer(struct display *disp, uint32_t fourcc, uint32_t w, uint32_t h)
                        buf->nbo = 2;
                        buf->bo[0] = alloc_bo(disp, 8, buf->width, buf->height,
                                        &bo_handles[0], &buf->pitches[0]);
+                       buf->fd[0] = omap_bo_dmabuf(buf->bo[0]);
                        buf->bo[1] = alloc_bo(disp, 16, buf->width/2, buf->height/2,
                                        &bo_handles[1], &buf->pitches[1]);
+                       buf->fd[1] = omap_bo_dmabuf(buf->bo[1]);
                } else {
                        buf->nbo = 1;
                        buf->bo[0] = alloc_bo(disp, 8, buf->width, buf->height * 3 / 2,
                                        &bo_handles[0], &buf->pitches[0]);
+                       buf->fd[0] = omap_bo_dmabuf(buf->bo[0]);
                        bo_handles[1] = bo_handles[0];
                        buf->pitches[1] = buf->pitches[0];
                        offsets[1] = buf->width * buf->height;
index 985917a4965cb04ee1d50b4580d4328ffad96d2c..6ab000c44775dbe86636c7508a6d629b1f74ca23 100644 (file)
@@ -57,6 +57,7 @@ struct buffer {
        uint32_t pitches[4];
        struct list unlocked;
        bool multiplanar;       /* True when Y and U/V are in separate buffers. */
+       int fd[4];              /* dmabuf */ 
 };
 
 /* State variables, used to maintain the playback rate. */
index 1679981d018aa077554c2782c273dbd4b494e8da..ac93ceeb5bf6cdf83c0862f0b4127cc6b4087cf8 100644 (file)
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-
-#include <dce.h>
-#include <xdc/std.h>
-#include <ti/xdais/xdas.h>
-#include <ti/sdo/ce/Engine.h>
-#include <ti/sdo/ce/video3/viddec3.h>
+#include <libdce.h>
+#include <xf86drm.h>
+#include <omap_drm.h>
+#include <omap_drmif.h>
 
 #include "util.h"
 #include "demux.h"
 
+
 /* Padding for width as per Codec Requirement (for h264) */
 #define PADX  32
 /* Padding for height as per Codec requirement (for h264)*/
 #define PADY  24
+/* omap drm device handle */
+struct omap_device *dev = NULL;
 
 struct decoder {
        struct display *disp;
        struct demux *demux;
        struct buffer *framebuf;
-
        Engine_Handle engine;
        VIDDEC3_Handle codec;
        VIDDEC3_Params *params;
@@ -47,13 +46,14 @@ struct decoder {
        XDM2_BufDesc *outBufs;
        VIDDEC3_InArgs *inArgs;
        VIDDEC3_OutArgs *outArgs;
-
        char *input;
        struct omap_bo *input_bo;
        int input_sz, uv_offset;
-
+       int padded_width;
+       int padded_height;
+       int num_outBuf;
+       size_t *outBuf_fd;
        suseconds_t tdisp;
-
 };
 
 /* When true, do not actually call VIDDEC3_process. For benchmarking. */
@@ -79,19 +79,21 @@ usage(char *name)
 static void
 decoder_close(struct decoder *decoder)
 {
+
        if (decoder->codec)          VIDDEC3_delete(decoder->codec);
        if (decoder->engine)         Engine_close(decoder->engine);
+       if (dev)                     dce_deinit(dev);
        if (decoder->params)         dce_free(decoder->params);
        if (decoder->dynParams)      dce_free(decoder->dynParams);
        if (decoder->status)         dce_free(decoder->status);
-       if (decoder->inBufs)         free(decoder->inBufs);
-       if (decoder->outBufs)        free(decoder->outBufs);
+       if (decoder->inBufs)         dce_free(decoder->inBufs);
+       if (decoder->outBufs)        dce_free(decoder->outBufs);
        if (decoder->inArgs)         dce_free(decoder->inArgs);
        if (decoder->outArgs)        dce_free(decoder->outArgs);
        if (decoder->input_bo)       omap_bo_del(decoder->input_bo);
        if (decoder->demux)          demux_deinit(decoder->demux);
        if (decoder->disp)           disp_close(decoder->disp);
-
+       if (decoder->outBuf_fd)      free(decoder->outBuf_fd);
        free(decoder);
 }
 
@@ -100,7 +102,7 @@ decoder_open(int argc, char **argv)
 {
        struct decoder *decoder;
        char *infile = NULL;
-       int i, num_buffers;
+       int i;
        int width, height, padded_width, padded_height;
        Engine_Error ec;
        XDAS_Int32 err;
@@ -147,24 +149,28 @@ decoder_open(int argc, char **argv)
        height = ALIGN2 (height, 4);       /* round up to macroblocks */
        padded_width  = ALIGN2 (width + (2*PADX), 7);
        padded_height = height + 4*PADY;
-       num_buffers   = MIN(16, 32768 / ((width/16) * (height/16))) + 3;
-
+       decoder->num_outBuf   = MIN(16, 32768 / ((width/16) * (height/16))) + 3;
+       decoder->padded_width = padded_width;
+       decoder->padded_height = padded_height;
        MSG("%p: padded_width=%d, padded_height=%d, num_buffers=%d",
-                       decoder, padded_width, padded_height, num_buffers);
-
+                       decoder, padded_width, padded_height, decoder->num_outBuf);
        if (!decoder->disp->multiplanar) {
                decoder->uv_offset = padded_width * padded_height;
+               decoder->outBuf_fd = malloc(sizeof(int)*decoder->num_outBuf);
                MSG("%p: uv_offset=%d", decoder, decoder->uv_offset);
        }
+       else{
+               decoder->outBuf_fd = malloc(sizeof(int)*(decoder->num_outBuf*2));
+       }
 
        decoder->input_sz = width * height;
        decoder->input_bo = omap_bo_new(decoder->disp->dev,
                        decoder->input_sz, OMAP_BO_WC);
        decoder->input = omap_bo_map(decoder->input_bo);
-
        decoder->framebuf = disp_get_fb(decoder->disp);
 
-       if (! disp_get_vid_buffers(decoder->disp, num_buffers,
+       if (! disp_get_vid_buffers(decoder->disp, decoder->num_outBuf,
                        FOURCC_STR("NV12"), padded_width, padded_height)) {
                ERROR("%p: could not allocate buffers", decoder);
                goto fail;
@@ -172,6 +178,11 @@ decoder_open(int argc, char **argv)
 
        MSG("%p: Opening Engine..", decoder);
        dce_set_fd(decoder->disp->fd);
+       dev = dce_init();
+       if(dev == NULL) {
+               ERROR("%p: dce init failed", dev);
+               goto fail;
+       }
        decoder->engine = Engine_open("ivahd_vidsvr", NULL, &ec);
        if (!decoder->engine) {
                ERROR("%p: could not open engine", decoder);
@@ -190,7 +201,7 @@ decoder_open(int argc, char **argv)
        decoder->params->operatingMode    = IVIDEO_DECODE_ONLY;
        decoder->params->displayDelay     = IVIDDEC3_DISPLAY_DELAY_AUTO;
        decoder->params->displayBufsMode  = IVIDDEC3_DISPLAYBUFS_EMBEDDED;
-MSG("displayBufsMode: %d", decoder->params->displayBufsMode);
+       MSG("displayBufsMode: %d", decoder->params->displayBufsMode);
        decoder->params->inputDataMode    = IVIDEO_ENTIREFRAME;
        decoder->params->metadataType[0]  = IVIDEO_METADATAPLANE_NONE;
        decoder->params->metadataType[1]  = IVIDEO_METADATAPLANE_NONE;
@@ -200,8 +211,9 @@ MSG("displayBufsMode: %d", decoder->params->displayBufsMode);
        decoder->params->numOutputDataUnits = 0;
        decoder->params->errorInfoMode    = IVIDEO_ERRORINFO_OFF;
 
-       decoder->codec = VIDDEC3_create(decoder->engine,
-                       "ivahd_h264dec", decoder->params);
+        decoder->codec = VIDDEC3_create(decoder->engine,
+                                        "ivahd_h264dec", decoder->params);
+
        if (!decoder->codec) {
                ERROR("%p: could not create codec", decoder);
                goto fail;
@@ -235,23 +247,18 @@ MSG("displayBufsMode: %d", decoder->params->displayBufsMode);
                goto fail;
        }
 
-       decoder->inBufs = calloc(1, sizeof(XDM2_BufDesc));
+       decoder->inBufs = dce_alloc(sizeof(XDM2_BufDesc));
        decoder->inBufs->numBufs = 1;
-       decoder->inBufs->descs[0].buf =
-                       (XDAS_Int8 *)omap_bo_handle(decoder->input_bo);
+       decoder->inBufs->descs[0].buf = (XDAS_Int8 *)omap_bo_dmabuf(decoder->input_bo);
        decoder->inBufs->descs[0].bufSize.bytes = omap_bo_size(decoder->input_bo);
-       decoder->inBufs->descs[0].memType = XDM_MEMTYPE_BO;
+       decoder->inBufs->descs[0].memType = XDM_MEMTYPE_RAW;
 
-       decoder->outBufs = calloc(1, sizeof(XDM2_BufDesc));
-       decoder->outBufs->numBufs = 2;
-       decoder->outBufs->descs[0].memType = XDM_MEMTYPE_BO;
-
-       if (decoder->disp->multiplanar) {
-               decoder->outBufs->descs[1].memType = XDM_MEMTYPE_BO;
-       } else {
-               decoder->outBufs->descs[1].memType = XDM_MEMTYPE_BO_OFFSET;
-       }
 
+       decoder->outBufs = dce_alloc(sizeof(XDM2_BufDesc));
+       decoder->outBufs->numBufs = 2;
+       decoder->outBufs->descs[0].memType = XDM_MEMTYPE_RAW;
+       decoder->outBufs->descs[1].memType = XDM_MEMTYPE_RAW;
+       
        decoder->inArgs = dce_alloc(sizeof(IVIDDEC3_InArgs));
        decoder->inArgs->size = sizeof(IVIDDEC3_InArgs);
 
@@ -278,6 +285,7 @@ decoder_process(struct decoder *decoder)
        VIDDEC3_InArgs *inArgs = decoder->inArgs;
        VIDDEC3_OutArgs *outArgs = decoder->outArgs;
        struct buffer *buf;
+       int freeBufCount =0;
        int i, n;
 
        buf = disp_get_vid_buffer(decoder->disp);
@@ -290,6 +298,7 @@ decoder_process(struct decoder *decoder)
        for (i = 0; i < 2; i++) {
                n = demux_read(decoder->demux, decoder->input, decoder->input_sz);
                if (n) {
+
                        inBufs->descs[0].bufSize.bytes = n;
                        inArgs->numBytes = n;
                        DBG("%p: push: %d bytes (%p)", decoder, n, buf);
@@ -315,18 +324,24 @@ decoder_process(struct decoder *decoder)
                break;
        }
 
+
        inArgs->inputID = (XDAS_Int32)buf;
-       outBufs->descs[0].buf = (XDAS_Int8 *)omap_bo_handle(buf->bo[0]);
+       outBufs->descs[0].buf = buf->fd[0];
+       outBufs->descs[1].buf = (buf->multiplanar) ?buf->fd[1]:(XDAS_Int8 *)((outBufs->descs[0].buf));
 
-       if (buf->multiplanar) {
-               outBufs->descs[0].bufSize.bytes = omap_bo_size(buf->bo[0]);
-               outBufs->descs[1].buf = (XDAS_Int8 *)omap_bo_handle(buf->bo[1]);
-               outBufs->descs[1].bufSize.bytes = omap_bo_size(buf->bo[1]);
-       } else {
-               outBufs->descs[0].bufSize.bytes = decoder->uv_offset;
-               outBufs->descs[1].buf = (XDAS_Int8 *)decoder->uv_offset;
-               outBufs->descs[1].bufSize.bytes = omap_bo_size(buf->bo[0]) - decoder->uv_offset;
+
+       if(buf->multiplanar){
+               decoder->outBuf_fd[0] = buf->fd[0];
+               decoder->outBuf_fd[1] = buf->fd[1];
+               dce_buf_lock(2,decoder->outBuf_fd);
+       }
+       else{
+               decoder->outBuf_fd[0] = buf->fd[0];
+               dce_buf_lock(1,decoder->outBuf_fd);
        }
+        decoder->outBufs->descs[0].bufSize.bytes =decoder->padded_width*decoder->padded_height;
+        decoder->outBufs->descs[1].bufSize.bytes = decoder->padded_width* (decoder->padded_height/2);
+
 
        if (no_process) {
                /* Do not process. This is for benchmarking. We need to "fake"
@@ -357,21 +372,29 @@ decoder_process(struct decoder *decoder)
 
                /* get the output buffer and write it to file */
                buf = (struct buffer *)outArgs->outputID[i];
-               DBG("%p: post buffer: %p %d,%d %d,%d", decoder, buf,
-                               r->topLeft.x, r->topLeft.y,
-                               r->bottomRight.x, r->bottomRight.y);
                disp_post_vid_buffer(decoder->disp, buf,
                                r->topLeft.x, r->topLeft.y,
                                r->bottomRight.x - r->topLeft.x,
                                r->bottomRight.y - r->topLeft.y);
-               DBG("%p: display in: %ldus", decoder, (long int)mark(&decoder->tdisp));
        }
 
        for (i = 0; outArgs->freeBufID[i]; i++) {
                buf = (struct buffer *)outArgs->freeBufID[i];
                disp_put_vid_buffer(decoder->disp, buf);
+
+               if(buf->multiplanar){
+                       decoder->outBuf_fd[freeBufCount++] = buf->fd[0];
+                       decoder->outBuf_fd[freeBufCount++] = buf->fd[1];
+               }
+               else{
+                       decoder->outBuf_fd[freeBufCount++] = buf->fd[0];
+               }
        }
 
+       if(freeBufCount){
+               dce_buf_unlock(freeBufCount,decoder->outBuf_fd);        
+               freeBufCount =0;
+       }
        if (outArgs->outBufsInUseFlag) {
                MSG("%p: TODO... outBufsInUseFlag", decoder); // XXX
        }