summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 82fe186)
raw | patch | inline | side by side (parent: 82fe186)
author | Pradeep Venkatasubbarao <pradeepv@ti.com> | |
Fri, 13 Dec 2013 06:12:57 +0000 (11:42 +0530) | ||
committer | Chandramohan <chandramohan.c@ti.com> | |
Fri, 13 Dec 2013 09:25:50 +0000 (14:55 +0530) |
Signed-off-by: Pradeep Venkatasubbarao <pradeepv@ti.com>
copycodectest.c | [new file with mode: 0644] | patch | blob |
yuvcopytest.c | [new file with mode: 0644] | patch | blob |
diff --git a/copycodectest.c b/copycodectest.c
--- /dev/null
+++ b/copycodectest.c
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2012 Texas Instruments
+ * Author: Ramprasad(x0038811@ti.com)
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <libdce.h>
+#include <xf86drm.h>
+#include <omap_drm.h>
+#include <omap_drmif.h>
+#include "util.h"
+
+#define MAX_IO_BUFS 16
+
+typedef struct MemHeader {
+ unsigned int size;
+ void *ptr; /* vptr/handle for mpu access */
+ unsigned int dma_buf_fd; /* shared dma buf fd */
+ unsigned int region; /* mem region the buffer allocated from */
+ /* internal meta data for the buffer */
+ unsigned int offset; /* offset for the actual data with in the buffer */
+ unsigned int map_fd; /* mmapped fd */
+ void * handle; /*custom handle for the HLOS memallocator*/
+} MemHeader;
+#define P2H(p) (&(((MemHeader *)(p))[-1]))
+/* omap drm device handle */
+struct omap_device *dev = NULL;
+
+struct decoder {
+ Engine_Handle engine;
+ VIDDEC2_Handle codec;
+ VIDDEC2_Params *params;
+ VIDDEC2_DynamicParams *dynParams;
+ VIDDEC2_Status *status;
+ XDM1_BufDesc *inBufs;
+ XDM_BufDesc *outBufs;
+ VIDDEC2_InArgs *inArgs;
+ VIDDEC2_OutArgs *outArgs;
+ char *input;
+ char *output;
+ int input_sz, output_sz;
+ XDAS_Int8 **outBuffer;
+ XDAS_Int32 *outBufSizes;
+};
+
+static void
+decoder_close(struct decoder *decoder)
+{
+ if (decoder->codec) VIDDEC2_delete(decoder->codec);
+ if (decoder->engine) Engine_close(decoder->engine);
+ if (decoder->params) dce_free(decoder->params);
+ if (decoder->dynParams) dce_free(decoder->dynParams);
+ if (decoder->status) dce_free(decoder->status);
+ 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) dce_free(decoder->input);
+ if (decoder->output) dce_free(decoder->output);
+ if (decoder->outBuffer) dce_free(decoder->outBuffer);
+ if (decoder->outBufSizes) dce_free(decoder->outBufSizes);
+ free(decoder);
+
+ if (dev) dce_deinit(dev);
+}
+
+static struct decoder *
+decoder_open(int pattern)
+{
+ struct decoder *decoder;
+ int i;
+ int width = 176, height = 144;
+ Engine_Error ec;
+ XDAS_Int32 err;
+
+ decoder = calloc(1, sizeof(*decoder));
+ if (!decoder)
+ return NULL;
+
+ MSG("%p: Opening Engine..", decoder);
+ dev = dce_init();
+ if(dev == NULL) {
+ ERROR("%p: dce init failed", dev);
+ goto fail;
+ }
+ decoder->engine = Engine_open("dsp_vidsvr", NULL, &ec);
+ if (!decoder->engine) {
+ ERROR("%p: could not open engine", decoder);
+ goto fail;
+ }
+ decoder->input_sz = width * height;
+ decoder->input = dce_alloc(decoder->input_sz);
+
+ decoder->output_sz = width * height;
+ decoder->output = dce_alloc(decoder->output_sz);
+
+ decoder->params = dce_alloc(sizeof(IVIDDEC2_Params));
+ decoder->params->size = sizeof(IVIDDEC2_Params);
+
+ decoder->codec = VIDDEC2_create(decoder->engine,
+ "dsp_universalCopy", decoder->params);
+
+ if (!decoder->codec) {
+ ERROR("%p: could not create codec", decoder);
+ goto fail;
+ }
+ MSG("Created dsp_universalCopy \n");
+ decoder->dynParams = dce_alloc(sizeof(IVIDDEC2_DynamicParams));
+ decoder->dynParams->size = sizeof(IVIDDEC2_DynamicParams);
+
+ decoder->status = dce_alloc(sizeof(IVIDDEC2_Status));
+ decoder->status->size = sizeof(IVIDDEC2_Status);
+
+ err = VIDDEC2_control(decoder->codec, XDM_SETPARAMS,
+ decoder->dynParams, decoder->status);
+ if (err) {
+ ERROR("%p: fail: %d", decoder, err);
+ goto fail;
+ }
+ /* not entirely sure why we need to call this here.. just copying omx.. */
+ err = VIDDEC2_control(decoder->codec, XDM_GETBUFINFO,
+ decoder->dynParams, decoder->status);
+ if (err) {
+ ERROR("%p: fail: %d", decoder, err);
+ goto fail;
+ }
+
+ decoder->outBuffer = dce_alloc(sizeof(XDAS_Int8*) * MAX_IO_BUFS);
+ decoder->outBufSizes = dce_alloc(sizeof(XDAS_Int32)* MAX_IO_BUFS);
+
+ decoder->inBufs = dce_alloc(sizeof(XDM1_BufDesc));
+ decoder->inBufs->numBufs = 1;
+ decoder->inBufs->descs[0].buf = (XDAS_Int8 *)omap_bo_dmabuf((P2H(decoder->input))->ptr);
+ decoder->inBufs->descs[0].bufSize = (P2H(decoder->input))->size;
+
+ decoder->outBuffer[0] = (XDAS_Int8*)(omap_bo_dmabuf((P2H(decoder->output))->ptr));
+ decoder->outBuffer[1] = decoder->outBuffer[0];
+ decoder->outBufSizes[0] = (XDAS_Int32)((P2H(decoder->output))->size);
+ decoder->outBufSizes[1] = decoder->outBufSizes[0];
+
+ decoder->outBufs = dce_alloc(sizeof(XDM_BufDesc));
+ decoder->outBufs->numBufs = 2;
+ decoder->outBufs->bufs = (XDAS_Int8**)decoder->outBuffer;
+ decoder->outBufs->bufSizes = &decoder->outBufSizes[0];
+
+ decoder->inArgs = dce_alloc(sizeof(IVIDDEC2_InArgs));
+ decoder->inArgs->size = sizeof(IVIDDEC2_InArgs);
+
+ decoder->outArgs = dce_alloc(sizeof(IVIDDEC2_OutArgs));
+ decoder->outArgs->size = sizeof(IVIDDEC2_OutArgs);
+
+ // Fill input buffer with a pattern for testing */
+ MSG("Fill first 10 bytes of input buffer with pattern %d\n", pattern);
+ for(i = 0; i < 10 ; i++)
+ decoder->input[i] = pattern;
+
+ return decoder;
+
+
+usage:
+ MSG("Fail\n");
+fail:
+ if (decoder)
+ decoder_close(decoder);
+ return NULL;
+}
+
+static int
+decoder_process(struct decoder *decoder)
+{
+ XDM1_BufDesc *inBufs = decoder->inBufs;
+ XDM_BufDesc *outBufs = decoder->outBufs;
+ VIDDEC2_InArgs *inArgs = decoder->inArgs;
+ VIDDEC2_OutArgs *outArgs = decoder->outArgs;
+ XDAS_Int32 err = XDM_EOK, i,j;
+
+ err = VIDDEC2_process(decoder->codec, inBufs, outBufs, inArgs, outArgs);
+ if (err) {
+ ERROR("%p: process returned error: %d", decoder, err);
+ return -1;
+ }
+
+ MSG("Verifing the UniversalCopy algorithm\n");
+ MSG("First 10 bytes of Output buffer\n");
+
+ for(j= 0 ; j < 10 ; j++){
+ MSG("%d\t", decoder->output[j]);
+ }
+
+ MSG("Tested UniversalCopy successfully\n");
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ struct decoder *decoder = NULL;
+ int pattern;
+ if(argc != 2){
+ MSG("Usage: copycodectest pattern(0 to 255) \t");
+ MSG("Example: copycodectest 100\n");
+ exit(0);
+ }
+ pattern = atoi(argv[1]);
+ decoder = decoder_open(pattern);
+
+ if(decoder)
+ decoder_process(decoder);
+
+ if(decoder)
+ decoder_close(decoder);
+
+ return 0;
+}
diff --git a/yuvcopytest.c b/yuvcopytest.c
--- /dev/null
+++ b/yuvcopytest.c
@@ -0,0 +1,333 @@
+/*
+ * Copyright (C) 2012 Texas Instruments
+ * Author: Ramprasad <x0038811@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <libdce.h>
+#include <xf86drm.h>
+#include <omap_drm.h>
+#include <omap_drmif.h>
+
+#include "util.h"
+
+#define MAX_IO_BUFS 8
+/* Used for mpeg4 esds data copy */
+
+/* omap drm device handle */
+struct omap_device *dev = NULL;
+
+struct decoder {
+ struct display *disp;
+ struct buffer *framebuf;
+ Engine_Handle engine;
+ VIDDEC2_Handle codec;
+ VIDDEC2_Params *params;
+ VIDDEC2_DynamicParams *dynParams;
+ VIDDEC2_Status *status;
+ XDM1_BufDesc *inBufs;
+ XDM_BufDesc *outBufs;
+ VIDDEC2_InArgs *inArgs;
+ VIDDEC2_OutArgs *outArgs;
+ XDAS_Int8 **outBuffer;
+ XDAS_Int32 *outBufSizes;
+ char *input;
+ struct omap_bo *input_bo;
+ int input_sz, uv_offset;
+ int padded_width;
+ int padded_height;
+ int num_outBuf;
+
+};
+
+static void
+usage(char *name)
+{
+ MSG("Usage: %s -s <connector_id>:<mode> INFILE -w width -h height", name);
+ MSG("example: %s -s 4:800x480 file.yuv -w 176 -h 144", name);
+ MSG("Test of universalCopy .");
+ MSG("");
+ MSG("yuvcopytest options:");
+ MSG("\t --help: Print this help and exit.");
+ MSG("");
+ disp_usage();
+}
+
+static void
+decoder_close(struct decoder *decoder)
+{
+ /* free output buffers allocated by display */
+ disp_free_buffers(decoder->disp,decoder->num_outBuf);
+
+ if (decoder->codec) VIDDEC2_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) 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->outBuffer) dce_free(decoder->outBuffer);
+ if (decoder->outBufSizes) dce_free(decoder->outBufSizes);
+ if (decoder->input_bo) omap_bo_del(decoder->input_bo);
+ if (decoder->disp) disp_close(decoder->disp);
+
+ free(decoder);
+}
+
+static struct decoder *
+decoder_open(int argc, char** argv)
+{
+ struct decoder *decoder;
+ char *infile = NULL;
+ int i;
+ int width , height ,padded_width, padded_height;
+ Engine_Error ec;
+ XDAS_Int32 err;
+
+ decoder = calloc(1, sizeof(*decoder));
+ if (!decoder)
+ return NULL;
+
+ MSG("%p: Opening Display..", decoder);
+ decoder->disp = disp_open(argc, argv);
+ if (!decoder->disp)
+ goto usage;
+
+ /* loop thru args, find input file.. */
+ for (i = 1; i < argc; i++) {
+ int fd;
+ if (!argv[i]) {
+ continue;
+ }
+ fd = open(argv[i], 0);
+ if (fd > 0) {
+ infile = argv[i];
+ argv[i] = NULL;
+ close(fd);
+ break;
+ }
+ break;
+ }
+ for(i = 1; i < argc; i++){
+ if(!argv[i])
+ continue;
+
+ if(!strcmp(argv[i],"-w")){
+ argv[i] = NULL;
+ width = atoi(argv[i+1]);
+ argv[i+1] = NULL;
+ continue;
+ }
+ if(!strcmp(argv[i], "-h")){
+ argv[i] = NULL;
+ height = atoi(argv[i+1]);
+ argv[i+1] = NULL;
+ }
+ }
+
+ MSG("width = %d, height = %d\n", width, height);
+ if (check_args(argc, argv) || !infile)
+ goto usage;
+
+ /* calculate output buffer parameters: */
+ width = ALIGN2 (width, 4); /* round up to macroblocks */
+ height = ALIGN2 (height, 4); /* round up to macroblocks */
+
+ padded_width = width;
+ padded_height= height;
+
+ decoder->num_outBuf = 2;
+ decoder->padded_width = padded_width;
+ decoder->padded_height = padded_height;
+
+ 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);
+
+ MSG("Fill input buffer with yuv luma data\n");
+ {
+ FILE *fd;
+ fd = fopen(infile, "rb");
+ fread(decoder->input, width*height, sizeof(char), fd);
+ fclose(fd);
+ }
+
+ 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;
+ }
+
+ 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("dsp_vidsvr", NULL, &ec);
+ if (!decoder->engine) {
+ ERROR("%p: could not open engine", decoder);
+ goto fail;
+ }
+
+ decoder->params = dce_alloc(sizeof(IVIDDEC2_Params));
+ decoder->params->size = sizeof(IVIDDEC2_Params);
+
+ decoder->codec = VIDDEC2_create(decoder->engine,
+ "dsp_universalCopy", decoder->params);
+ if (!decoder->codec) {
+ ERROR("%p: could not create codec", decoder);
+ goto fail;
+ }
+
+ decoder->dynParams = dce_alloc(sizeof(IVIDDEC2_DynamicParams));
+ decoder->dynParams->size = sizeof(IVIDDEC2_DynamicParams);
+
+ decoder->status = dce_alloc(sizeof(IVIDDEC2_Status));
+ decoder->status->size = sizeof(IVIDDEC2_Status);
+
+ err = VIDDEC2_control(decoder->codec, XDM_SETPARAMS,
+ decoder->dynParams, decoder->status);
+ if (err) {
+ ERROR("%p: fail: %d", decoder, err);
+ goto fail;
+ }
+
+ /* not entirely sure why we need to call this here.. just copying omx.. */
+ err = VIDDEC2_control(decoder->codec, XDM_GETBUFINFO,
+ decoder->dynParams, decoder->status);
+ if (err) {
+ ERROR("%p: fail: %d", decoder, err);
+ goto fail;
+ }
+
+ decoder->outBuffer = dce_alloc(sizeof(XDAS_Int8*) * MAX_IO_BUFS);
+ decoder->outBufSizes = dce_alloc(sizeof(XDAS_Int32)* MAX_IO_BUFS);
+
+ decoder->inBufs = dce_alloc(sizeof(XDM1_BufDesc));
+ decoder->inBufs->numBufs = 1;
+ decoder->inBufs->descs[0].buf = (XDAS_Int8 *)omap_bo_dmabuf(decoder->input_bo);
+ decoder->inBufs->descs[0].bufSize = omap_bo_size(decoder->input_bo);
+
+ decoder->outBufs = dce_alloc(sizeof(XDM_BufDesc));
+ decoder->outBufs->numBufs = 2;
+ decoder->outBufs->bufs = (XDAS_Int8**)decoder->outBuffer;
+ decoder->outBufs->bufSizes = &decoder->outBufSizes[0];
+
+ decoder->inArgs = dce_alloc(sizeof(IVIDDEC2_InArgs));
+ decoder->inArgs->size = sizeof(IVIDDEC2_InArgs);
+
+ decoder->outArgs = dce_alloc(sizeof(IVIDDEC2_OutArgs));
+ decoder->outArgs->size = sizeof(IVIDDEC2_OutArgs);
+
+ return decoder;
+
+usage:
+ usage(argv[0]);
+fail:
+ if (decoder)
+ decoder_close(decoder);
+ return NULL;
+ }
+
+static int
+decoder_process(struct decoder *decoder)
+{
+ XDM1_BufDesc *inBufs = decoder->inBufs;
+ XDM_BufDesc *outBufs = decoder->outBufs;
+ VIDDEC2_InArgs *inArgs = decoder->inArgs;
+ VIDDEC2_OutArgs *outArgs = decoder->outArgs;
+ struct buffer *buf;
+ XDAS_Int32 width = decoder->padded_width;
+ XDAS_Int32 height = decoder->padded_height;
+ XDAS_Int32 err;
+ char *src,*dst;
+ XDAS_Int32 i, success = XDAS_TRUE;
+
+ buf = disp_get_vid_buffer(decoder->disp);
+ if (!buf) {
+ ERROR("%p: fail: out of buffers", decoder);
+ return -1;
+ }
+
+ decoder->outBuffer[0] = buf->fd[0];
+ decoder->outBuffer[1] = (buf->multiplanar) ? buf->fd[1]:(XDAS_Int8 *)((decoder->outBuffer[0]));
+
+ decoder->outBufSizes[0] = decoder->padded_width * decoder->padded_height;
+ decoder->outBufSizes[1] = decoder->padded_width * (decoder->padded_height/2);
+
+ err = VIDDEC2_process(decoder->codec, inBufs, outBufs, inArgs, outArgs);
+
+ if (err) {
+ ERROR("%p: process returned error: %d", decoder, err);
+ return -1;
+ }
+
+ disp_post_vid_buffer(decoder->disp, buf, 0, 0, width, height);
+ /* Display the output buffer for 10 seconds */
+ sleep(10);
+
+ disp_put_vid_buffer(decoder->disp, buf);
+
+ src = (char*)decoder->input;
+ dst = (char*)omap_bo_map(buf->bo[0]);
+
+ MSG("Comparing output buffer with input buffer\n");
+
+ for(i = 0; i < decoder->input_sz; i++){
+ if(*src != *dst){
+ MSG("yuvcopytest failed at %d, 0x%x, 0x%x\n", i, *src, *dst);
+ success = XDAS_FALSE;
+ break;
+ }
+ src++;
+ dst++;
+ }
+
+ if(success ==XDAS_TRUE)
+ MSG("yuvcopytest executed successfully\n");
+
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ struct decoder *decoder = NULL;
+ int i;
+ for (i = 1; i < argc; i++)
+ if ( !strcmp(argv[i], "--help")) {
+ usage(argv[0]);
+ exit(0);
+ }
+ decoder = decoder_open(argc,argv);
+
+ if(decoder)
+ decoder_process(decoder);
+
+ if(decoder)
+ decoder_close(decoder);
+
+ decoder = NULL;
+
+ return 0;
+}