Addition of new demo "kmscube with video"
authorKarthik Ramanan <a0393906@ti.com>
Fri, 13 Jun 2014 08:40:28 +0000 (14:10 +0530)
committerKarthik Ramanan <a0393906@ti.com>
Wed, 18 Jun 2014 12:25:26 +0000 (17:55 +0530)
This patch adds support for a new demo, which is to render video
on the face of the kmscube.

Usage:
   viddec3test <video_file> --kmscube --connector <connector id>

There are other options that are are supported, please refer to
viddec3test --help for further details

The main additions in this patch are:
 * Added support for allocation of the buffers via DRM
 * Added support for the allocated buffers
 * Added support for specifying the connector ID on the command line

Signed-off-by: Karthik Ramanan <a0393906@ti.com>
util/display-kmscube.c

index 97aac4d955d0782977cd81cf4672fd44dc6827c4..5c3b187137fbd240a928f1490da460733640436d 100644 (file)
@@ -137,6 +137,9 @@ struct display_kmscube {
                uint32_t connector_id;
                drmModePlaneRes *plane_resources;
        } drm;
+
+       //user specified connector id
+       uint32_t user_connector_id;
 };
 
 /* All our buffers are only vid buffers, and they all have an EGLImage. */
@@ -169,7 +172,8 @@ static int init_drm(struct display_kmscube *disp_kmsc)
        /* find a connected connector: */
        for (i = 0; i < resources->count_connectors; i++) {
                connector = drmModeGetConnector(disp_kmsc->base.fd, resources->connectors[i]);
-               if (connector->connection == DRM_MODE_CONNECTED) {
+               if (connector->connection == DRM_MODE_CONNECTED && \
+                   connector->connector_id == disp_kmsc->user_connector_id) {
                        /* it's connected, let's use this! */
                        break;
                }
@@ -216,6 +220,7 @@ static int init_drm(struct display_kmscube *disp_kmsc)
 
        disp_kmsc->drm.crtc_id = encoder->crtc_id;
        disp_kmsc->drm.connector_id = connector->connector_id;
+       printf("Chosen Connector ID = %d\n", disp_kmsc->drm.connector_id);
 
        return 0;
 }
@@ -761,7 +766,7 @@ alloc_buffer(struct display *disp, uint32_t fourcc, uint32_t w, uint32_t h)
        buf->fourcc = fourcc;
        buf->width = w;
        buf->height = h;
-       buf->multiplanar = false;
+       buf->multiplanar = true;
 
        buf->nbo = 1;
 
@@ -781,10 +786,25 @@ alloc_buffer(struct display *disp, uint32_t fourcc, uint32_t w, uint32_t h)
                                &bo_handles[0], &buf->pitches[0]);
                break;
        case FOURCC('N','V','1','2'):
-               buf->nbo = 1;
-               buf->bo[0] = alloc_bo(disp, 8, buf->width, (buf->height + buf->height/2),
-                               &bo_handles[0], &buf->pitches[0]);
-               break;
+                if (disp->multiplanar) {
+                        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;
+                        buf->multiplanar = false;
+                }
+                break;
        case FOURCC('I','4','2','0'):
                buf->nbo = 1;
                buf->bo[0] = alloc_bo(disp, 8, buf->width, (buf->height + buf->height/2),
@@ -846,6 +866,7 @@ alloc_buffers(struct display *disp, uint32_t n,
                }
        }
 
+       disp->buf = bufs;
        return bufs;
 
 fail:
@@ -853,6 +874,25 @@ fail:
        return NULL;
 }
 
+
+static void
+free_buffers(struct display *disp, uint32_t n)
+{
+        uint32_t i;
+        for (i = 0; i < n; i++) {
+                if (disp->buf[i]) {
+                        close(disp->buf[i]->fd[0]);
+                        omap_bo_del(disp->buf[i]->bo[0]);
+                        if(disp->multiplanar){
+                                close(disp->buf[i]->fd[1]);
+                                omap_bo_del(disp->buf[i]->bo[1]);
+                        }
+                }
+        }
+       free(disp->buf);
+}
+
+
 static struct buffer **
 get_buffers(struct display *disp, uint32_t n)
 {
@@ -1009,6 +1049,7 @@ disp_kmscube_usage(void)
        MSG("\t--distance <float>\tset cube distance (default 8.0)");
        MSG("\t--fov <float>\tset field of vision (default 45.0)");
        MSG("\t--kmscube\tEnable display kmscube (default: disabled)");
+       MSG("\t--connector <connector_id>\tset the connector ID (default: LCD)");
 }
 
 struct display *
@@ -1019,7 +1060,7 @@ disp_kmscube_open(int argc, char **argv)
        struct gbm_bo *bo;
        struct drm_fb *fb;
        int ret, i, enabled = 0;
-       float fov = 45, distance = 8;
+       float fov = 45, distance = 8, connector_id = 4;
 
        /* note: set args to NULL after we've parsed them so other modules know
         * that it is already parsed (since the arg parsing is decentralized)
@@ -1040,6 +1081,12 @@ disp_kmscube_open(int argc, char **argv)
                                ERROR("invalid arg: %s", argv[i]);
                                goto fail;
                        }
+               } else if (!strcmp("--connector", argv[i])) {
+                       argv[i++] = NULL;
+                       if (sscanf(argv[i], "%f", &connector_id) != 1) {
+                               ERROR("invalid arg: %s", argv[i]);
+                               goto fail;
+                       }
                } else if (!strcmp("--kmscube", argv[i])) {
                        enabled = 1;
                } else {
@@ -1060,6 +1107,7 @@ disp_kmscube_open(int argc, char **argv)
        }
        disp_kmsc->gl.distance = distance;
        disp_kmsc->gl.fov = fov;
+       disp_kmsc->user_connector_id = connector_id;
        disp = &disp_kmsc->base;
 
        disp->fd = drmOpen("omapdrm", NULL);
@@ -1079,6 +1127,8 @@ disp_kmscube_open(int argc, char **argv)
        disp->post_buffer = post_buffer;
        disp->post_vid_buffer = post_vid_buffer;
        disp->close = close_kmscube;
+       disp->disp_free_buf = free_buffers;
+
 
        if (init_drm(disp_kmsc)) {
                ERROR("couldn't init drm");