Added buf_lock and buf_unlock APIs in copycodec and yuvcopy test cases.
[glsdk/omapdrmtest.git] / copycodectest.c
index e842f88652e65910892ba53768f2fc4a050ddfae..b54bf14ba52704d0b92170c4fc689ae242f52fc2 100644 (file)
 
 #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;
 
+extern void *dsp_dce_alloc(int sz);
+extern void dsp_dce_free(void *ptr);
+
 struct decoder {
        Engine_Handle engine;
        VIDDEC2_Handle codec;
@@ -55,29 +47,43 @@ struct decoder {
        VIDDEC2_OutArgs *outArgs;
        char *input;
        char *output;
-        int input_sz, output_sz;
-        XDAS_Int8 **outBuffer;
-        XDAS_Int32 *outBufSizes;
+       struct omap_bo *input_bo;
+       struct omap_bo *output_bo;
+    int input_sz, output_sz;
+    XDAS_Int8 **outBuffer;
+    XDAS_Int32 *outBufSizes;
 };
 
 static void
 decoder_close(struct decoder *decoder)
 {
+    if(!decoder) goto bailout;
+       if (decoder->params)         dsp_dce_free(decoder->params);
+       if (decoder->dynParams)      dsp_dce_free(decoder->dynParams);
+       if (decoder->status)         dsp_dce_free(decoder->status);
+       if (decoder->inBufs)
+    {
+        dsp_dce_buf_unlock(1, &(decoder->inBufs->descs[0].buf));
+        close(decoder->inBufs->descs[0].buf);
+        dsp_dce_free(decoder->inBufs);
+    }
+       if (decoder->outBufs)        dsp_dce_free(decoder->outBufs);
+       if (decoder->inArgs)         dsp_dce_free(decoder->inArgs);
+       if (decoder->outArgs)        dsp_dce_free(decoder->outArgs);
+       if (decoder->input_bo)       omap_bo_del(decoder->input_bo);
+       if (decoder->output_bo)      omap_bo_del(decoder->output_bo);
+
+       if (decoder->outBuffer)
+    {
+        close(decoder->outBuffer[0]);
+        dsp_dce_free(decoder->outBuffer);
+    }
+       if (decoder->outBufSizes)    dsp_dce_free(decoder->outBufSizes);
        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);
 
+       free(decoder);
+bailout:
        if (dev)                             dce_deinit(dev);
 }
 
@@ -106,12 +112,14 @@ decoder_open(int pattern)
                goto fail;
        }
        decoder->input_sz = width * height;
-       decoder->input = dce_alloc(decoder->input_sz);
+       decoder->input_bo = omap_bo_new(dev, decoder->input_sz, OMAP_BO_WC);
+       decoder->input = omap_bo_map(decoder->input_bo);
 
        decoder->output_sz = width * height;
-       decoder->output = dce_alloc(decoder->output_sz);
+       decoder->output_bo = omap_bo_new(dev, decoder->output_sz, OMAP_BO_WC);
+       decoder->output = omap_bo_map(decoder->output_bo);
 
-       decoder->params = dce_alloc(sizeof(IVIDDEC2_Params));
+       decoder->params = dsp_dce_alloc(sizeof(IVIDDEC2_Params));
        decoder->params->size = sizeof(IVIDDEC2_Params);
 
        decoder->codec = VIDDEC2_create(decoder->engine,
@@ -122,10 +130,10 @@ decoder_open(int pattern)
                goto fail;
        }
     MSG("Created dsp_universalCopy \n");
-       decoder->dynParams = dce_alloc(sizeof(IVIDDEC2_DynamicParams));
+       decoder->dynParams = dsp_dce_alloc(sizeof(IVIDDEC2_DynamicParams));
        decoder->dynParams->size = sizeof(IVIDDEC2_DynamicParams);
 
-       decoder->status = dce_alloc(sizeof(IVIDDEC2_Status));
+       decoder->status = dsp_dce_alloc(sizeof(IVIDDEC2_Status));
        decoder->status->size = sizeof(IVIDDEC2_Status);
 
        err = VIDDEC2_control(decoder->codec, XDM_SETPARAMS,
@@ -141,35 +149,34 @@ decoder_open(int pattern)
                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->outBuffer = dsp_dce_alloc(sizeof(XDAS_Int8*) * MAX_IO_BUFS);
+    decoder->outBufSizes = dsp_dce_alloc(sizeof(XDAS_Int32)* MAX_IO_BUFS);
+    decoder->inBufs = dsp_dce_alloc(sizeof(XDM1_BufDesc));
+    decoder->inBufs->numBufs = 1;
+    decoder->inBufs->descs[0].buf =    (XDAS_Int8 *)omap_bo_dmabuf((struct omap_bo*) decoder->input_bo);
+    decoder->inBufs->descs[0].bufSize = width * height;
+    dsp_dce_buf_lock(1, &(decoder->inBufs->descs[0].buf));
+
+    decoder->outBuffer[0] = (XDAS_Int8*)omap_bo_dmabuf((struct omap_bo*) decoder->output_bo);
+    decoder->outBuffer[1] = decoder->outBuffer[0];
+    decoder->outBufSizes[0] = width * height;
+    decoder->outBufSizes[1] = decoder->outBufSizes[0];
+    decoder->outBufs = dsp_dce_alloc(sizeof(XDM_BufDesc));
        decoder->outBufs->numBufs = 2;
        decoder->outBufs->bufs = (XDAS_Int8**)decoder->outBuffer;
-        decoder->outBufs->bufSizes = &decoder->outBufSizes[0];
+    decoder->outBufs->bufSizes = &decoder->outBufSizes[0];
+    dsp_dce_buf_lock(1, &decoder->outBuffer[0]);
 
-       decoder->inArgs = dce_alloc(sizeof(IVIDDEC2_InArgs));
+       decoder->inArgs = dsp_dce_alloc(sizeof(IVIDDEC2_InArgs));
        decoder->inArgs->size = sizeof(IVIDDEC2_InArgs);
 
-       decoder->outArgs = dce_alloc(sizeof(IVIDDEC2_OutArgs));
+       decoder->outArgs = dsp_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;
+    // Fill input buffer with a pattern for testing */
+    MSG("Fill input buffer with pattern %d\n", pattern);
+    for(i = 0; i < decoder->input_sz ; i++)
+        decoder->input[i] = pattern;
 
        return decoder;
 
@@ -189,7 +196,8 @@ decoder_process(struct decoder *decoder)
     XDM_BufDesc *outBufs = decoder->outBufs;
     VIDDEC2_InArgs *inArgs = decoder->inArgs;
     VIDDEC2_OutArgs *outArgs = decoder->outArgs;
-    XDAS_Int32 err = XDM_EOK, i,j;
+    XDAS_Int32 err = XDM_EOK, j,success = XDAS_TRUE;
+    char *src,*dst;
 
     err = VIDDEC2_process(decoder->codec, inBufs, outBufs, inArgs, outArgs);
     if (err) {
@@ -197,14 +205,24 @@ decoder_process(struct decoder *decoder)
        return -1;
       }
 
+    dsp_dce_buf_unlock(1, &decoder->outBuffer[0]);
+
     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]);
+    src = (char*)decoder->input;
+    dst = (char*)decoder->output;
+    for(j= 0 ; j < decoder->input_sz ; j++){
+       if(*src != *dst){
+            MSG("copycodectest failed at %d, 0x%x, 0x%x\n", j, *src, *dst);
+            success = XDAS_FALSE;
+            break;
+          }
+          src++;
+          dst++;
      }
+      if(success ==XDAS_TRUE)
+           MSG("copycodectest executed successfully\n");
 
-    MSG("Tested UniversalCopy successfully\n");
        return 0;
 }