viddec3test: Removed print statement for all cases except in inloop case
[glsdk/omapdrmtest.git] / copycodectest.c
1 /*
2  * Copyright (C) 2012 Texas Instruments
3  * Author: Ramprasad(x0038811@ti.com)
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdio.h>
24 #include <libdce.h>
25 #include <xf86drm.h>
26 #include <omap_drm.h>
27 #include <omap_drmif.h>
28 #include "util.h"
30 #define MAX_IO_BUFS 16
32 /* omap drm device handle */
33 struct omap_device *dev = NULL;
35 extern void *dsp_dce_alloc(int sz);
36 extern void dsp_dce_free(void *ptr);
38 struct decoder {
39         Engine_Handle engine;
40         VIDDEC2_Handle codec;
41         VIDDEC2_Params *params;
42         VIDDEC2_DynamicParams *dynParams;
43         VIDDEC2_Status *status;
44         XDM1_BufDesc *inBufs;
45         XDM_BufDesc *outBufs;
46         VIDDEC2_InArgs *inArgs;
47         VIDDEC2_OutArgs *outArgs;
48         char *input;
49         char *output;
50         int input_sz, output_sz;
51         XDAS_Int8 **outBuffer;
52         XDAS_Int32 *outBufSizes;
53 };
55 static void
56 decoder_close(struct decoder *decoder)
57 {
58     if(!decoder) goto bailout;
59         if (decoder->params)         dsp_dce_free(decoder->params);
60         if (decoder->dynParams)      dsp_dce_free(decoder->dynParams);
61         if (decoder->status)         dsp_dce_free(decoder->status);
62         if (decoder->inBufs) 
63     {
64         close(decoder->inBufs->descs[0].buf);
65         dsp_dce_free(decoder->inBufs);
66     }
67         if (decoder->outBufs)        dsp_dce_free(decoder->outBufs);
68         if (decoder->inArgs)         dsp_dce_free(decoder->inArgs);
69         if (decoder->outArgs)        dsp_dce_free(decoder->outArgs);
70         if (decoder->input)          dsp_dce_free(decoder->input);
71         if (decoder->output)         dsp_dce_free(decoder->output);
72         if (decoder->outBuffer)
73     {
74         close(decoder->outBuffer[0]);
75         dsp_dce_free(decoder->outBuffer);
76     }
77         if (decoder->outBufSizes)    dsp_dce_free(decoder->outBufSizes);
78         if (decoder->codec)          VIDDEC2_delete(decoder->codec);
79         if (decoder->engine)         Engine_close(decoder->engine);
80         free(decoder);
81 bailout:
82         if (dev)                             dce_deinit(dev);
83 }
85 static struct decoder *
86 decoder_open(int pattern)
87 {
88         struct decoder *decoder;
89         int i;
90         int width = 176, height = 144;
91         Engine_Error ec;
92         XDAS_Int32 err;
94         decoder = calloc(1, sizeof(*decoder));
95         if (!decoder)
96                 return NULL;
98         MSG("%p: Opening Engine..", decoder);
99         dev = dce_init();
100         if(dev == NULL) {
101                 ERROR("%p: dce init failed", dev);
102                 goto fail;
103         }
104         decoder->engine = Engine_open("dsp_vidsvr", NULL, &ec);
105         if (!decoder->engine) {
106                 ERROR("%p: could not open engine", decoder);
107                 goto fail;
108         }
109         decoder->input_sz = width * height;
110         decoder->input = omap_bo_new(dev, decoder->input_sz, OMAP_BO_WC);
112         decoder->output_sz = width * height;
113         decoder->output = omap_bo_new(dev, decoder->output_sz, OMAP_BO_WC);
115         decoder->params = dsp_dce_alloc(sizeof(IVIDDEC2_Params));
116         decoder->params->size = sizeof(IVIDDEC2_Params);
118         decoder->codec = VIDDEC2_create(decoder->engine,
119                                         "dsp_universalCopy", decoder->params);
121         if (!decoder->codec) {
122                 ERROR("%p: could not create codec", decoder);
123                 goto fail;
124         }
125     MSG("Created dsp_universalCopy \n");
126         decoder->dynParams = dsp_dce_alloc(sizeof(IVIDDEC2_DynamicParams));
127         decoder->dynParams->size = sizeof(IVIDDEC2_DynamicParams);
129         decoder->status = dsp_dce_alloc(sizeof(IVIDDEC2_Status));
130         decoder->status->size = sizeof(IVIDDEC2_Status);
132         err = VIDDEC2_control(decoder->codec, XDM_SETPARAMS,
133                         decoder->dynParams, decoder->status);
134         if (err) {
135                 ERROR("%p: fail: %d", decoder, err);
136                 goto fail;
137         }
138         /* not entirely sure why we need to call this here.. just copying omx.. */
139         err = VIDDEC2_control(decoder->codec, XDM_GETBUFINFO,
140                         decoder->dynParams, decoder->status);
141         if (err) {
142                 ERROR("%p: fail: %d", decoder, err);
143                 goto fail;
144         }
145     decoder->outBuffer = dsp_dce_alloc(sizeof(XDAS_Int8*) * MAX_IO_BUFS);
146     decoder->outBufSizes = dsp_dce_alloc(sizeof(XDAS_Int32)* MAX_IO_BUFS);
147     decoder->inBufs = dsp_dce_alloc(sizeof(XDM1_BufDesc)); 
148     decoder->inBufs->numBufs = 1;
149     decoder->inBufs->descs[0].buf =     (XDAS_Int8 *)omap_bo_dmabuf((struct omap_bo*) decoder->input);
150     decoder->inBufs->descs[0].bufSize = width * height;
151     decoder->outBuffer[0] = (XDAS_Int8*)omap_bo_dmabuf((struct omap_bo*) decoder->output);
152     decoder->outBuffer[1] = decoder->outBuffer[0];
153     decoder->outBufSizes[0] = width * height;
154     decoder->outBufSizes[1] = decoder->outBufSizes[0];
155     decoder->outBufs = dsp_dce_alloc(sizeof(XDM_BufDesc));
156         decoder->outBufs->numBufs = 2;
157         decoder->outBufs->bufs = (XDAS_Int8**)decoder->outBuffer;
158     decoder->outBufs->bufSizes = &decoder->outBufSizes[0];
160         decoder->inArgs = dsp_dce_alloc(sizeof(IVIDDEC2_InArgs));
161         decoder->inArgs->size = sizeof(IVIDDEC2_InArgs);
163         decoder->outArgs = dsp_dce_alloc(sizeof(IVIDDEC2_OutArgs));
164         decoder->outArgs->size = sizeof(IVIDDEC2_OutArgs);
166     // Fill input buffer with a pattern for testing */
167     MSG("Fill first 10 bytes of input buffer with pattern %d\n", pattern);
168     for(i = 0; i < 10 ; i++)
169         decoder->input[i] = pattern;
171         return decoder;
174 usage:
175         MSG("Fail\n");
176 fail:
177         if (decoder)
178            decoder_close(decoder);
179         return NULL;
182 static int
183 decoder_process(struct decoder *decoder)
185     XDM1_BufDesc *inBufs = decoder->inBufs;
186     XDM_BufDesc *outBufs = decoder->outBufs;
187     VIDDEC2_InArgs *inArgs = decoder->inArgs;
188     VIDDEC2_OutArgs *outArgs = decoder->outArgs;
189     XDAS_Int32 err = XDM_EOK, j;
191     err = VIDDEC2_process(decoder->codec, inBufs, outBufs, inArgs, outArgs);
192     if (err) {
193        ERROR("%p: process returned error: %d", decoder, err);
194        return -1;
195       }
197     MSG("Verifing the UniversalCopy algorithm\n");
198     MSG("First 10 bytes of Output buffer\n");
200     for(j= 0 ; j < 10 ; j++){
201         MSG("%d\t", decoder->output[j]);
202      }
204     MSG("Tested UniversalCopy successfully\n");
205         return 0;
208 int
209 main(int argc, char **argv)
211     struct decoder *decoder = NULL;
212     int pattern;
213     if(argc != 2){
214        MSG("Usage: copycodectest pattern(0 to 255) \t");
215        MSG("Example: copycodectest 100\n");
216        exit(0);
217     }
218     pattern = atoi(argv[1]);
219     decoder = decoder_open(pattern);
221     if(decoder)
222        decoder_process(decoder);
224     if(decoder)
225        decoder_close(decoder);
227     return 0;