aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaurabh Bipin Chandra2013-04-22 11:42:19 -0500
committerSaurabh Bipin Chandra2013-04-26 09:14:28 -0500
commit6647d1f16d70b9d867ce5b7aef92705939aa5975 (patch)
tree73b154f99e7ceff809c8a98be6489e4ee11d0877 /test_qnx
downloadrepo-libdce-6647d1f16d70b9d867ce5b7aef92705939aa5975.tar.gz
repo-libdce-6647d1f16d70b9d867ce5b7aef92705939aa5975.tar.xz
repo-libdce-6647d1f16d70b9d867ce5b7aef92705939aa5975.zip
[libDCE] Add IPC 3.x Adapted code to Repository3.00.01.00
This patch adds libdce code to the repository. LibDCE has been adapted to use the MmRpc layer of IPC 3.x. This version of LibDCE is expected to work on QNX. Patchset 2 adds/modifies: 1. Removes Tiler 2D allocation/free for now. 2. Corrects memplugin_free() for Tiler 1D. 3. Modifies dce_test app to dump output till 30 frames. 4. Renamed dce.h to libdce.h. 5. Corrected header files across all files. 6. Build configuration for QNX 7. Removes build warnings. 8. Add README for Build instructions 9. Takes care of comments of Buddy and Pradeep. Patchset 3 adds/modifies: 1. Reduced Stack usage of each function. 2. Add ptr check in memplugin and remove from libdce. 3. Add DCE_Assert macros. 4. Add DCE_error_status enum. 5. Comments Cleanup 6. Make some functions static. 7. process() cleanup including removing reply_buf. 8. Add else if (for codec_type == Encoder type) 9. Converted Macros to Inline functions. 10.Converted init and deinit to dce_init and dce_deinit functions. 11. Removed dce_init() and dce_deinit() declarations Patchset 4 adds/modifies: 1. Assert Input function arguments. 2. Correct copyright year. 3. Correct memplugin_free for Shared memory. 4. Create dce_priv.h and move trace and assert macros to the header. 5. Redeclare mem_type enum and add mem_error_status enum in memplugin.h and make corresponding changes. 6. Add asserts in memplugin. Intention of some of the changes above is to move towards delinking Libdce and Memplugin. Patchset 5: 1. Missed to add dce_priv.h file. Patchset 6: 1. Take care Pradeep's comment. Change-Id: I6e5e37b7088362e7bad66200fc3454bb828e0eff Signed-off-by: Saurabh Bipin Chandra <a0131926@ti.com>
Diffstat (limited to 'test_qnx')
-rw-r--r--test_qnx/Makefile2
-rw-r--r--test_qnx/arm/Makefile8
-rw-r--r--test_qnx/arm/le.v7/Makefile1
-rw-r--r--test_qnx/common.mk50
-rw-r--r--test_qnx/dce_test.c1437
-rw-r--r--test_qnx/dce_test.use38
6 files changed, 1536 insertions, 0 deletions
diff --git a/test_qnx/Makefile b/test_qnx/Makefile
new file mode 100644
index 0000000..5323e99
--- /dev/null
+++ b/test_qnx/Makefile
@@ -0,0 +1,2 @@
1LIST=CPU
2include recurse.mk
diff --git a/test_qnx/arm/Makefile b/test_qnx/arm/Makefile
new file mode 100644
index 0000000..6a18617
--- /dev/null
+++ b/test_qnx/arm/Makefile
@@ -0,0 +1,8 @@
1LIST=VARIANT
2ifndef QRECURSE
3QRECURSE=recurse.mk
4ifdef QCONFIG
5QRDIR=$(dir $(QCONFIG))
6endif
7endif
8include $(QRDIR)$(QRECURSE)
diff --git a/test_qnx/arm/le.v7/Makefile b/test_qnx/arm/le.v7/Makefile
new file mode 100644
index 0000000..cc39927
--- /dev/null
+++ b/test_qnx/arm/le.v7/Makefile
@@ -0,0 +1 @@
include ../../common.mk
diff --git a/test_qnx/common.mk b/test_qnx/common.mk
new file mode 100644
index 0000000..be901c0
--- /dev/null
+++ b/test_qnx/common.mk
@@ -0,0 +1,50 @@
1###################### QNX DCE Test App Build Config #######################
2
3#### Include qconfig.mk
4ifndef QCONFIG
5QCONFIG=qconfig.mk
6endif
7include $(QCONFIG)
8
9define PINFO
10PINFO DESCRIPTION=DCE Test
11endef
12
13NAME = dce_test
14INSTALLDIR = bin
15
16# Different tool versions can easily be programmed by defining below variables
17# in your environment.
18CEVERSION ?= codec_engine_3_23_00_07
19FCVERSION ?= framework_components_3_23_03_17
20XDAISVERSION ?= xdais_7_23_00_06
21XDCVERSION ?= xdctools_3_25_00_48
22IPCHEADERS ?= $(INSTALL_ROOT_nto)
23IVAHDCODECS ?= ipumm/extrel/ti/ivahd_codecs
24
25# Generate the full package paths for tools
26CEPROD = $(TIVIDEOTOOLSROOT)/$(CEVERSION)
27FCPROD = $(TIVIDEOTOOLSROOT)/$(FCVERSION)
28XDAISPROD = $(TITOOLSROOT)/$(XDAISVERSION)
29XDCPROD = $(TITOOLSROOT)/$(XDCVERSION)
30
31#Add extra include path
32EXTRA_INCVPATH += $(CEPROD)/packages
33EXTRA_INCVPATH += $(FCPROD)/packages
34EXTRA_INCVPATH += $(XDAISPROD)/packages
35EXTRA_INCVPATH += $(XDCPROD)/packages
36EXTRA_INCVPATH += $(IVAHDCODECS)/packages
37EXTRA_INCVPATH += $(PROJECT_ROOT)/../
38EXTRA_INCVPATH += $(IPCHEADERS)/usr/include/memmgr
39EXTRA_INCVPATH += $(IPCHEADERS)/usr/include/ti/syslink
40EXTRA_INCVPATH += $(IPCHEADERS)/usr/include
41
42CCOPTS+=-g -O0 -Dxdc_target_types__=qnx/targets/arm/std.h
43
44EXTRA_LIBVPATH += $(PROJECT_ROOT)/../nto/arm/so.le.v7 \
45 $(INSTALL_ROOT_nto)/armle-v7/usr/lib
46
47LDOPTS+= -ldce -lmemmgr -ltilerusr -lsyslink_client -lsharedmemallocator
48
49include $(MKFILES_ROOT)/qtargets.mk
50
diff --git a/test_qnx/dce_test.c b/test_qnx/dce_test.c
new file mode 100644
index 0000000..805b240
--- /dev/null
+++ b/test_qnx/dce_test.c
@@ -0,0 +1,1437 @@
1/*
2 * Copyright (c) 2013, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32#include <xdc/std.h>
33#include <stdlib.h>
34#include <string.h>
35#include <stdio.h>
36#include <stdint.h>
37#include <sys/types.h>
38#include <sys/stat.h>
39#include <sys/time.h>
40#include <fcntl.h>
41#include <errno.h>
42#include <time.h>
43#include <sys/mman.h>
44
45#include <tilermem.h>
46#include <memmgr.h>
47#include <xdc/std.h>
48#include <ti/sdo/ce/Engine.h>
49#include <ti/sdo/ce/video3/viddec3.h>
50#include <ti/sdo/codecs/h264vdec/ih264vdec.h>
51#include <ti/sdo/codecs/mpeg4vdec/impeg4vdec.h>
52#include <ti/sdo/codecs/vc1vdec/ivc1vdec.h>
53#include <ti/sdo/codecs/jpegvdec/ijpegvdec.h>
54#ifdef ENABLE_MPEG2
55#include <ti/sdo/codecs/mpeg2vdec/impeg2vdec.h>
56#endif
57#include "ti/shmemallocator/SharedMemoryAllocatorUsr.h"
58#include "libdce.h"
59
60#define OMAP5
61
62#define PRINT_DEBUG
63#define ERROR(FMT, ...) printf("%s:%d:\t%s\terror: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
64// enable below to print debug information
65#ifdef PRINT_DEBUG
66#define DEBUG(FMT, ...) printf("%s:%d:\t%s\tdebug: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
67#else
68#define DEBUG(FMT, ...)
69#endif
70#define INFO(FMT, ...) printf("%s:%d:\t%s\tinfo: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
71#define MIN(a, b) (((a) < (b)) ? (a) : (b))
72
73/* align x to next highest multiple of 2^n */
74#define ALIGN2(x, n) (((x) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
75
76// Profile the init and decode calls
77//#define PROFILE_TIME
78
79enum {
80 IVAHD_AVC1_DECODE,
81 IVAHD_H264_DECODE,
82 IVAHD_MP4V_DECODE,
83 IVAHD_S263_DECODE,
84 IVAHD_VC1AP_DECODE,
85 IVAHD_VC1SMP_DECODE,
86 IVAHD_VP6V_DECODE,
87 IVAHD_MP2V_DECODE,
88 IVAHD_JPEGV_DECODE
89};
90
91/*
92 * A very simple VIDDEC3 client which will decode h264 frames (one per file),
93 * and write out raw (unstrided) nv12 frames (one per file).
94 */
95
96int width, height, padded_width, padded_height, num_buffers, tiler;
97Engine_Handle engine = NULL;
98VIDDEC3_Handle codec = NULL;
99VIDDEC3_Params *params = NULL;
100VIDDEC3_DynamicParams *dynParams = NULL;
101VIDDEC3_Status *status = NULL;
102XDM2_BufDesc *inBufs = NULL;
103XDM2_BufDesc *outBufs = NULL;
104VIDDEC3_InArgs *inArgs = NULL;
105VIDDEC3_OutArgs *outArgs = NULL;
106
107IH264VDEC_Params *h264_params = NULL;
108IH264VDEC_DynamicParams *h264_dynParams = NULL;
109IH264VDEC_Status *h264_status = NULL;
110
111IMPEG4VDEC_Params *mpeg4_params = NULL;
112IMPEG4VDEC_DynamicParams *mpeg4_dynParams = NULL;
113IMPEG4VDEC_Status *mpeg4_status = NULL;
114
115IVC1VDEC_Params *vc1_params = NULL;
116IVC1VDEC_DynamicParams *vc1_dynParams = NULL;
117IVC1VDEC_Status *vc1_status = NULL;
118
119IJPEGVDEC_Params *mjpeg_params = NULL;
120IJPEGVDEC_DynamicParams *mjpeg_dynParams = NULL;
121IJPEGVDEC_Status *mjpeg_status = NULL;
122#ifdef ENABLE_MPEG2
123IMPEG2VDEC_Params *mpeg2_params = NULL;
124IMPEG2VDEC_DynamicParams *mpeg2_dynParams = NULL;
125IMPEG2VDEC_Status *mpeg2_status = NULL;
126#endif
127unsigned int frameSize[64000]; /* Buffer for keeping frame sizes */
128static int input_offset = 0;
129
130/*! Padding for width as per Codec Requirement */
131#define PADX_H264 32
132#define PADX_MPEG4 32
133#define PADX_VC1 32
134/*! Padding for height as per Codec Requirement */
135#define PADY_H264 24
136#define PADY_MPEG4 32
137#define PADY_VC1 40
138
139static void *tiler_alloc(int width, int height)
140{
141 int dimensions;
142 void *bufPtr = NULL;
143 MemAllocBlock block;
144 MemAllocBlock blocks[2];
145
146 memset(&block, 0, sizeof(MemAllocBlock));
147 memset(blocks, 0, sizeof(MemAllocBlock) * 2);
148
149 if( !height ) {
150 DEBUG("tiler alloc 1D allocation width=%d", width);
151 /* 1d allocation: */
152 dimensions = 1;
153
154 block.pixelFormat = PIXEL_FMT_PAGE;
155 block.dim.len = width;
156 block.stride = 0;
157
158 bufPtr = MemMgr_Alloc(&block, dimensions);
159 } else {
160 DEBUG("tiler alloc 2D allocation width=%d height=%d", width, height);
161 /* 2d allocation: */
162 dimensions = 2;
163 blocks[0].pixelFormat = PIXEL_FMT_8BIT;
164 blocks[0].dim.area.width = width;
165 blocks[0].dim.area.height = height;
166 blocks[0].stride = 0;
167
168 blocks[1].pixelFormat = PIXEL_FMT_16BIT;
169 blocks[1].dim.area.width = width >> 1;
170 blocks[1].dim.area.height = height >> 1;
171 blocks[1].stride = 0;
172
173 bufPtr = MemMgr_Alloc(blocks, dimensions);
174 }
175 DEBUG("tiler alloc return bufPtr %p", bufPtr);
176
177 return (bufPtr);
178}
179
180/* ************************************************************************* */
181/* utilities to allocate/manage 2d output buffers */
182
183typedef struct OutputBuffer OutputBuffer;
184
185struct OutputBuffer {
186 char *buf; /* virtual address for local access, 4kb stride */
187 uint32_t y, uv; /* virtual address of Y and UV for remote access */
188 OutputBuffer *next; /* next free buffer */
189 bool tiler;
190 uint32_t len;
191 shm_buf shmBuf;
192};
193
194static XDAS_Int16
195get_mem_type (uint32_t paddr)
196{
197 if((0x60000000 <= paddr) && (paddr < 0x68000000)) {
198 return (XDM_MEMTYPE_TILED8);
199 }
200 if((0x68000000 <= paddr) && (paddr < 0x70000000)) {
201 return (XDM_MEMTYPE_TILED16);
202 }
203 if((0x70000000 <= paddr) && (paddr < 0x78000000)) {
204 return (XDM_MEMTYPE_TILED32);
205 }
206 if((0x78000000 <= paddr) && (paddr < 0x80000000)) {
207 return (XDM_MEMTYPE_RAW);
208 }
209 return (-1);
210}
211
212/* list of free buffers, not locked by codec! */
213static OutputBuffer *head = NULL;
214
215#if 0
216/*! @brief Start address of DDR region for 1GB RAM */
217#define DDR_1G_ADDRESS_START 0x80000000
218/*! @brief End address of DDR region for 1GB RAM */
219#define DDR_1G_ADDRESS_END 0xBFFFFFFF
220#define DDR_1G_DUCATI_OFFSET 0x40000000
221
222/*! @brief Start address of DDR region for 2GB RAM */
223#define DDR_2G_ADDRESS_START 0xC0000000
224/*! @brief End address of DDR region for 2GB RAM */
225#define DDR_2G_ADDRESS_END 0xFFFFFFFF
226#define DDR_2G_DUCATI_OFFSET 0xA0000000
227
228static Int
229SysLinkMemUtils_translateAddr (UInt32 physAddr)
230{
231 Int ret = 0;
232
233 if( physAddr >= DDR_1G_ADDRESS_START && physAddr <= DDR_1G_ADDRESS_END ) {
234 ret = physAddr + DDR_1G_DUCATI_OFFSET;
235 } else if( physAddr >= DDR_2G_ADDRESS_START && physAddr <= DDR_2G_ADDRESS_END ) {
236 ret = physAddr - DDR_2G_DUCATI_OFFSET;
237 }
238
239 return (ret);
240}
241
242#endif
243
244int output_allocate(XDM2_BufDesc *outBufs, int cnt,
245 int width, int height, int stride)
246{
247 int tw, th;
248
249 outBufs->numBufs = 2;
250
251 if( stride != 4096 ) {
252 /* non-2d allocation! */
253 int size_y = stride * height;
254 int size_uv = stride * height / 2;
255 tw = size_y + size_uv;
256 th = 0;
257 outBufs->descs[0].memType = XDM_MEMTYPE_TILEDPAGE;
258 outBufs->descs[0].bufSize.bytes = size_y;
259 outBufs->descs[1].memType = XDM_MEMTYPE_TILEDPAGE;
260 outBufs->descs[1].bufSize.bytes = size_uv;
261 } else {
262 tw = width;
263 th = height;
264 outBufs->descs[0].memType = XDM_MEMTYPE_TILED8;
265 outBufs->descs[0].bufSize.tileMem.width = width;
266 outBufs->descs[0].bufSize.tileMem.height = height;
267 outBufs->descs[1].memType = XDM_MEMTYPE_TILED16;
268 outBufs->descs[1].bufSize.tileMem.width = width; /* UV interleaved width is same a Y */
269 outBufs->descs[1].bufSize.tileMem.height = height / 2;
270 }
271
272 while( cnt ) {
273 OutputBuffer *buf = calloc(sizeof(OutputBuffer), 1);
274
275 DEBUG(" ----------------- create TILER buf 0x%x --------------------", (unsigned int)buf);
276
277 buf->buf = tiler_alloc(tw, th);
278 if( buf->buf ) {
279 buf->y = (uint32_t) buf->buf;
280 buf->uv = (uint32_t)(buf->buf + (height * stride));
281
282 DEBUG("cnt=%d buf=%p, y=%08x, uv=%08x", cnt, buf, buf->y, buf->uv);
283
284 buf->tiler = TRUE;
285 buf->next = head;
286 head = buf;
287 } else {
288 ERROR(" ---------------- tiler_alloc failed --------------------");
289 free(buf);
290 return (-EAGAIN);
291 }
292 cnt--;
293 }
294
295 return (0);
296}
297
298int output_allocate_nonTiler(XDM2_BufDesc *outBufs, int cnt,
299 int width, int height, int stride)
300{
301 int tw;
302 XDAS_Int16 y_type, uv_type;
303
304 outBufs->numBufs = 2;
305
306 while( cnt ) {
307 OutputBuffer *buf = calloc(sizeof(OutputBuffer), 1);
308
309 DEBUG(" ----------------- create nonTILER buf 0x%x --------------------", (unsigned int)buf);
310 int size_y = width * height;
311 int size_uv = width * height * 1 / 2;
312 tw = size_y + size_uv;
313
314 // Allocation through mmap
315 uint64_t *vaddr;
316 int32_t ret, len = 0;
317 int64_t paddr = 0;
318 uint32_t uv_addr;
319
320 //vaddr = mmap64(0, tw, PROT_NOCACHE | PROT_READ | PROT_WRITE, MAP_ANON | MAP_PHYS | MAP_SHARED, NOFD, 0);
321 ret = SHM_alloc(tw, &buf->shmBuf);
322 //if (vaddr == MAP_FAILED) {
323 if( ret < 0 ) {
324 //ERROR("Failed to do memory mapping\n");
325 ERROR("Failed to alloc shmem buffer\n");
326 free(buf);
327 return (-ENOMEM);
328 }
329 vaddr = (uint64_t *)buf->shmBuf.vir_addr;
330
331 // Make sure the memory is contiguous
332 ret = mem_offset64(vaddr, NOFD, (size_t) tw, &paddr, (size_t *) &len);
333 if( ret ) {
334 ERROR("Failed to check memory contiguous ret %d errno %d\n", ret, errno);
335 //munmap(vaddr, tw);
336 SHM_release(&buf->shmBuf);
337 free(buf);
338 return (-ENOMEM);
339 } else if( len != (tw)) {
340 ERROR("Failed to check len %d != %d\n", len, tw);
341 //munmap(vaddr, tw);
342 SHM_release(&buf->shmBuf);
343 free(buf);
344 return (-ENOMEM);
345 }
346
347 buf->buf = (char *) vaddr;
348 buf->y = (uint32_t)vaddr;
349 uv_addr = (uint32_t) vaddr + (width * height);
350 buf->uv = uv_addr;
351
352 DEBUG("cnt=%d nonTILER buf=%p, y=%08x, uv=%08x paddr=%08x", cnt, buf, buf->y, buf->uv, (unsigned int) paddr);
353
354 y_type = get_mem_type(buf->y);
355 uv_type = get_mem_type(buf->uv);
356
357 if((y_type < 0) || (uv_type < 0)) {
358 DEBUG("non TILER buffer address translation buf->y %x buf->uv %x", buf->y, buf->uv);
359 //buf->y = SysLinkMemUtils_translateAddr(buf->y);
360 //buf->uv = SysLinkMemUtils_translateAddr(buf->uv);
361 y_type = XDM_MEMTYPE_RAW;
362 uv_type = XDM_MEMTYPE_RAW;
363 DEBUG("buf->y %x buf->uv %x", buf->y, buf->uv);
364 if( !buf->y || !buf->uv ) {
365 //munmap(vaddr, tw);
366 SHM_release(&buf->shmBuf);
367 free(buf);
368 return (-ENOMEM);
369 }
370 }
371
372 buf->next = head;
373 buf->tiler = FALSE;
374 buf->len = tw;
375 head = buf;
376
377 cnt--;
378 }
379
380 if((y_type == XDM_MEMTYPE_RAW) && (uv_type == XDM_MEMTYPE_RAW)) {
381 outBufs->descs[0].memType = y_type;
382 outBufs->descs[0].bufSize.bytes = width * height;
383 outBufs->descs[1].memType = uv_type;
384 outBufs->descs[1].bufSize.bytes = width * height * 1 / 2;
385 }
386
387 return (0);
388}
389
390void output_free(void)
391{
392 OutputBuffer *buf = head;
393
394 while((buf=head)) {
395 if( buf->tiler ) {
396 MemMgr_Free(buf->buf);
397 } else {
398 //munmap(buf->buf, buf->len);
399 SHM_release(&buf->shmBuf);
400 }
401 head = buf->next;
402 free(buf);
403 }
404}
405
406OutputBuffer *output_get(void)
407{
408 OutputBuffer *buf = head;
409
410 if( buf ) {
411 head = buf->next;
412 }
413 DEBUG("output_get: %p", buf);
414 return (buf);
415}
416
417void output_release(OutputBuffer *buf)
418{
419 DEBUG("output_release: %p", buf);
420 buf->next = head;
421 head = buf;
422}
423
424/* ************************************************************************* */
425
426/* get file path.. return path is only valid until next time this is called */
427static const char *get_path(const char *pattern, int cnt)
428{
429 static int len = 0;
430 static char *path = NULL;
431
432 /* It would be better to not assume the pattern doesn't expand to
433 * less than 10 chars it's original length..
434 */
435 if((strlen(pattern) + 10) > len ) {
436 len = strlen(pattern) + 10;
437 path = realloc(path, len);
438 }
439
440 snprintf(path, len - 1, pattern, cnt);
441
442 return (path);
443}
444
445/* helper to read one frame of input */
446int read_input(const char *pattern, int cnt, char *input)
447{
448 int sz = 0, n = 0;
449 const char *path = get_path(pattern, cnt);
450 int fd = open(path, O_RDONLY);
451
452 //DEBUG("Open file fd %d errno %d", fd, errno);
453 /* if we can't find the file, then at the end of stream */
454 if( fd < 0 ) {
455 DEBUG("open input file failed");
456 return (0);
457 }
458
459 if( frameSize[cnt] && (frameSize[cnt] != -1)) {
460 lseek(fd, input_offset, SEEK_SET);
461 n = read(fd, input, frameSize[cnt]);
462 //DEBUG("reading input frameSize[%d] = n =%d", cnt, n);
463 sz += n;
464 input_offset += n;
465 } else if((frameSize[cnt] == -1)) {
466 // This happens to indicate flush command
467 DEBUG("Flush requested from file size -1,frameSize[%d] is %d", cnt, frameSize[cnt]);
468 sz = -1;
469 }
470
471 close(fd);
472
473 DEBUG("sz=%d", sz);
474 return (sz);
475}
476
477/* helper to write one frame of output */
478int write_output(const char *pattern, int cnt, char *y, char *uv, int stride)
479{
480 int sz = 0, n, i;
481 const char *path = get_path(pattern, cnt);
482 int fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644);
483
484 if( fd < 0 ) {
485 ERROR("could open output file: %s (%d)", path, errno);
486 return (0);
487 }
488
489 for( i = 0; i < height; i++ ) {
490 char *p = y;
491 int len = width;
492
493 while( len && ((n = write(fd, p, len)) > 0)) {
494 sz += n;
495 p += n;
496 len -= n;
497 }
498
499 if( n < 0 ) {
500 ERROR("couldn't write to output file: (%d)", errno);
501 break;
502 }
503 y += stride;
504 }
505
506 if( n >= 0 ) {
507 for( i = 0; i < height / 2; i++ ) {
508 char *p = uv;
509 int len = width;
510
511 while( len && ((n = write(fd, p, len)) > 0)) {
512 sz += n;
513 p += n;
514 len -= n;
515 }
516
517 if( n < 0 ) {
518 ERROR("couldn't write to output file: (%d)", errno);
519 break;
520 }
521 uv += stride;
522 }
523 }
524
525 close(fd);
526
527 return (sz);
528}
529
530#ifdef PROFILE_TIME
531/* for timing in microsecond */
532uint64_t mark_microsecond(uint64_t *last)
533{
534#if 0
535 struct timespec time;
536 uint64_t t1 = 0;
537
538 clock_gettime(CLOCK_REALTIME, &time);
539 t1 = timespec2nsec(&time);
540 t1 = t1 / 1000;
541#else
542 uint64_t t1 = 0;
543
544 t1 = ClockCycles();
545 t1 = t1 * 1000000000 / SYSPAGE_ENTRY(qtime)->cycles_per_sec;
546 t1 = t1 / 1000;
547#endif
548 if( last ) {
549 return (t1 - *last);
550 }
551 return (t1);
552}
553
554#endif
555//#define DUMPINPUTDATA
556
557#ifdef DUMPINPUTDATA
558FILE *inputDump;
559#endif
560
561#define VERSION_SIZE 128
562static char version_buffer[VERSION_SIZE];
563
564/* decoder body */
565int main(int argc, char * *argv)
566{
567 Engine_Error ec;
568 XDAS_Int32 err;
569 char *input = NULL;
570 char *in_pattern, *out_pattern, *frameData;
571 int in_cnt = 0, out_cnt = 0;
572 int oned, stride;
573 unsigned int frameCount = 0;
574 FILE *frameFile;
575 unsigned char frameinput[10] = { "\0" };
576 int eof = 0;
577 int ivahd_decode_type;
578 char vid_codec[10];
579 char tilerbuffer[10];
580 unsigned int codec_switch = 0;
581 unsigned int vc1_flush = 0;
582 Bool outBufsInUse = FALSE;
583
584#ifdef PROFILE_TIME
585 uint64_t init_start_time = 0;
586 uint64_t codec_process_time = 0;
587 uint64_t total_init_time = 0;
588 uint64_t output_alloc_time = 0;
589#endif
590
591#if 0
592 int loop = 0;
593
594 while( loop == 0 ) {
595 loop = 0;
596 }
597
598#endif
599
600 if((argc >= 2) && !strcmp(argv[1], "-1")) {
601 oned = TRUE;
602 argc--;
603 argv++;
604 } else {
605 oned = FALSE;
606 }
607
608 if( argc != 8 ) {
609 printf("usage: %s width height framefile inpattern outpattern codec tilerbuffer\n", argv[0]);
610 printf("example: %s 320 240 frame.txt in.h264 out.yuv h264 tiler\n", argv[0]);
611 printf("example: %s 640 480 frame.txt in.m4v out.yuv mpeg4 nontiler\n", argv[0]);
612 printf("example: %s 720 480 frame.txt in.vc1 out.yuv vc1ap tiler\n", argv[0]);
613 printf("example: %s 320 240 frame.txt in.vc1 out.yuv vc1smp nontiler\n", argv[0]);
614 printf("example: %s 1280 720 frame.txt in.bin out.yuv mjpeg tiler\n", argv[0]);
615 printf("example: %s 1920 1088 frame.txt in.bin out.yuv mpeg2 nontiler\n", argv[0]);
616 printf("Currently supported codecs: h264, mpeg4, vc1ap, vc1smp, mjpeg, mpeg2\n");
617 return (1);
618 }
619
620 /* error checking? */
621 width = atoi(argv[1]);
622 height = atoi(argv[2]);
623 frameData = argv[3];
624 in_pattern = argv[4];
625 out_pattern = argv[5];
626 strcpy(vid_codec, argv[6]);
627 strcpy(tilerbuffer, argv[7]);
628
629 printf("Selected codec: %s\n", vid_codec);
630 printf("Selected buffer: %s\n", tilerbuffer);
631
632 enum {
633 DCE_TEST_H264 = 1,
634 DCE_TEST_MPEG4 = 2,
635 DCE_TEST_VC1SMP = 3,
636 DCE_TEST_VC1AP = 4,
637 DCE_TEST_MJPEG = 5,
638 DCE_TEST_MPEG2 = 6
639 };
640
641 if((!(strcmp(vid_codec, "h264")))) {
642 ivahd_decode_type = IVAHD_H264_DECODE;
643 codec_switch = DCE_TEST_H264;
644
645 } else if((!(strcmp(vid_codec, "mpeg4")))) {
646 ivahd_decode_type = IVAHD_MP4V_DECODE;
647 codec_switch = DCE_TEST_MPEG4;
648
649 } else if((!(strcmp(vid_codec, "vc1smp")))) {
650 ivahd_decode_type = IVAHD_VC1SMP_DECODE;
651 codec_switch = DCE_TEST_VC1SMP;
652 vc1_flush = 1;
653
654 } else if((!(strcmp(vid_codec, "vc1ap")))) {
655 ivahd_decode_type = IVAHD_VC1AP_DECODE;
656 codec_switch = DCE_TEST_VC1AP;
657 vc1_flush = 1;
658
659 } else if((!(strcmp(vid_codec, "mjpeg")))) {
660 ivahd_decode_type = IVAHD_JPEGV_DECODE;
661 codec_switch = DCE_TEST_MJPEG;
662
663 } else if((!(strcmp(vid_codec, "mpeg2")))) {
664 ivahd_decode_type = IVAHD_MP2V_DECODE;
665 codec_switch = DCE_TEST_MPEG2;
666
667 } else {
668 printf("No valid codec entry. Please use: h264, mpeg4, vc1ap, vc1smp, mjpeg or mpeg2\n");
669 return (1);
670 }
671
672 DEBUG("Storing frame size data");
673 frameFile = fopen(frameData, "rb");
674 DEBUG("frameFile open %p errno %d", frameFile, errno);
675 if( frameFile == NULL ) {
676 DEBUG("Opening framesize file FAILED");
677 }
678
679 /* Read the frame Size from the frame size file */
680 while( NULL != fgets((char *)frameinput, 10, frameFile)) {
681 frameSize[frameCount] = atoi((char *)frameinput);
682 //DEBUG("frameSize[%d] = %d \n", frameCount, frameSize[frameCount]);
683
684 if( frameCount > 64000 ) {
685 DEBUG("Num Frames %d exceeded MAX limit %d \n", frameCount, 64000);
686 goto out;
687 }
688 frameCount++;
689 }
690
691 DEBUG("Num Frames is %d width=%d, height=%d", frameCount, width, height);
692
693 /* calculate output buffer parameters: */
694 width = ALIGN2(width, 4); /* round up to MB */
695 height = ALIGN2(height, 4); /* round up to MB */
696
697 switch( codec_switch ) {
698 case DCE_TEST_H264 :
699 padded_width = ALIGN2(width + (2 * PADX_H264), 7);
700 padded_height = height + 4 * PADY_H264;
701 // Some clips don't have enough buffers based on N+3 formula
702 // Need sps->num_ref_frames data to match filter precisely
703 //num_buffers = 2 * (MIN(16, 32768 / ((width / 16) * (height / 16)))) + 1;
704 num_buffers = (MIN(16, 32768 / ((width / 16) * (height / 16)))) + 3;
705 break;
706 case DCE_TEST_MPEG4 :
707 padded_width = ALIGN2(width + PADX_MPEG4, 7);
708 padded_height = height + PADY_MPEG4;
709 num_buffers = 8;
710 break;
711 case DCE_TEST_VC1SMP :
712 case DCE_TEST_VC1AP :
713 padded_width = ALIGN2(width + (2 * PADX_VC1), 7);
714 padded_height = (ALIGN2(height / 2, 4) * 2) + 4 * PADY_VC1;
715 num_buffers = 5;
716 break;
717 case DCE_TEST_MJPEG :
718 padded_width = ALIGN2(width, 4);
719 padded_height = ALIGN2(height, 4);
720 num_buffers = 5;
721 break;
722 case DCE_TEST_MPEG2 :
723 padded_width = ALIGN2(width, 7);
724 padded_height = height;
725 num_buffers = 4;
726 break;
727 }
728
729 if( oned ) {
730 stride = padded_width;
731 } else {
732 stride = 4096;
733 }
734
735 DEBUG("padded_width=%d, padded_height=%d, stride=%d, num_buffers=%d",
736 padded_width, padded_height, stride, num_buffers);
737#ifdef PROFILE_TIME
738 init_start_time = mark_microsecond(NULL);
739#endif
740 engine = Engine_open("ivahd_vidsvr", NULL, &ec);
741
742 if( !engine ) {
743 ERROR("fail");
744 goto out;
745 }
746
747 DEBUG("Engine_open successful engine=%p", engine);
748
749 switch( codec_switch ) {
750 case DCE_TEST_H264 :
751 params = dce_alloc(sizeof(IH264VDEC_Params));
752 if( !params ) {
753 ERROR("dce_alloc fail");
754 goto out;
755 }
756 params->size = sizeof(IH264VDEC_Params);
757 params->maxBitRate = 10000000;
758 params->displayDelay = IVIDDEC3_DISPLAY_DELAY_AUTO;
759 params->numOutputDataUnits = 0;
760 params->maxWidth = width;
761 break;
762 case DCE_TEST_MPEG4 :
763 params = dce_alloc(sizeof(IMPEG4VDEC_Params));
764 if( !params ) {
765 ERROR("dce_alloc fail");
766 goto out;
767 }
768 params->size = sizeof(IMPEG4VDEC_Params);
769 params->maxBitRate = 10000000;
770 params->displayDelay = IVIDDEC3_DISPLAY_DELAY_1;
771 params->numOutputDataUnits = 0;
772 params->maxWidth = width;
773 break;
774 case DCE_TEST_VC1SMP :
775 case DCE_TEST_VC1AP :
776 params = dce_alloc(sizeof(IVC1VDEC_Params));
777 if( !params ) {
778 ERROR("dce_alloc fail");
779 goto out;
780 }
781 params->size = sizeof(IVC1VDEC_Params);
782 params->maxBitRate = 45000000;
783 params->displayDelay = IVIDDEC3_DISPLAY_DELAY_1;
784 params->numOutputDataUnits = 0;
785 params->maxWidth = width;
786 break;
787 case DCE_TEST_MJPEG :
788 params = dce_alloc(sizeof(IJPEGVDEC_Params));
789 if( !params ) {
790 ERROR("dce_alloc fail");
791 goto out;
792 }
793 params->size = sizeof(IJPEGVDEC_Params);
794 params->maxBitRate = 10000000;
795 params->displayDelay = IVIDDEC3_DISPLAY_DELAY_1;
796 params->numOutputDataUnits = 1;
797 params->maxWidth = width;
798 break;
799#ifdef ENABLE_MPEG2
800 case DCE_TEST_MPEG2 :
801 params = dce_alloc(sizeof(IMPEG2VDEC_Params));
802 if( !params ) {
803 ERROR("dce_alloc fail");
804 goto out;
805 }
806 params->size = sizeof(IMPEG2VDEC_Params);
807 params->maxBitRate = 10000000;
808 params->displayDelay = IVIDDEC3_DISPLAY_DELAY_1;
809 params->numOutputDataUnits = 0;
810 params->maxWidth = padded_width;
811 break;
812#endif
813 }
814
815 params->maxHeight = height;
816 params->maxFrameRate = 30000;
817 params->dataEndianness = XDM_BYTE;
818 params->forceChromaFormat = XDM_YUV_420SP;
819 params->operatingMode = IVIDEO_DECODE_ONLY;
820 //params->displayDelay = IVIDDEC3_DECODE_ORDER;
821 params->displayBufsMode = IVIDDEC3_DISPLAYBUFS_EMBEDDED;
822 params->inputDataMode = IVIDEO_ENTIREFRAME;
823 params->metadataType[0] = IVIDEO_METADATAPLANE_NONE;
824 params->metadataType[1] = IVIDEO_METADATAPLANE_NONE;
825 params->metadataType[2] = IVIDEO_METADATAPLANE_NONE;
826 params->outputDataMode = IVIDEO_ENTIREFRAME;
827 params->numInputDataUnits = 0;
828 params->errorInfoMode = IVIDEO_ERRORINFO_OFF;
829
830 DEBUG("dce_alloc VIDDEC3_Params successful params=%p", params);
831
832 switch( codec_switch ) {
833 case DCE_TEST_H264 :
834 h264_params = (IH264VDEC_Params *) params;
835 h264_params->dpbSizeInFrames = IH264VDEC_DPB_NUMFRAMES_AUTO;
836 h264_params->pConstantMemory = 0;
837 h264_params->presetLevelIdc = IH264VDEC_LEVEL41;
838 h264_params->errConcealmentMode = IH264VDEC_APPLY_CONCEALMENT;
839 h264_params->temporalDirModePred = TRUE;
840 h264_params->detectCabacAlignErr = IH264VDEC_DISABLE_CABACALIGNERR_DETECTION;
841
842 DEBUG("dce_alloc VIDDEC3_Params successful h264_params=%p", h264_params);
843
844 err = msync((Ptr)h264_params, sizeof(IH264VDEC_Params), MS_CACHE_ONLY | MS_SYNC);
845
846 codec = VIDDEC3_create(engine, "ivahd_h264dec", (VIDDEC3_Params *)h264_params);
847 break;
848
849 case DCE_TEST_MPEG4 :
850 mpeg4_params = (IMPEG4VDEC_Params *) params;
851 mpeg4_params->outloopDeBlocking = TRUE;
852 mpeg4_params->sorensonSparkStream = FALSE;
853 mpeg4_params->errorConcealmentEnable = FALSE;
854 mpeg4_params->debugTraceLevel = 0;
855 mpeg4_params->lastNFramesToLog = 0;
856 mpeg4_params->paddingMode = IMPEG4VDEC_DEFAULT_MODE_PADDING;
857
858 DEBUG("dce_alloc VIDDEC3_Params successful mpeg4_params=%p", mpeg4_params);
859
860 err = msync((Ptr)mpeg4_params, sizeof(IMPEG4VDEC_Params), MS_CACHE_ONLY | MS_SYNC);
861#ifdef OMAP5
862 codec = VIDDEC3_create(engine, "ivahd_mpeg4dec", (VIDDEC3_Params *)mpeg4_params);
863#else
864 codec = VIDDEC3_create(engine, "ivahd_mpeg4vdec", (VIDDEC3_Params *)mpeg4_params);
865#endif
866 break;
867
868 case DCE_TEST_VC1SMP :
869 case DCE_TEST_VC1AP :
870 vc1_params = (IVC1VDEC_Params *) params;
871
872 DEBUG("dce_alloc VIDDEC3_Params successful vc1_params=%p", vc1_params);
873
874 err = msync((Ptr)vc1_params, sizeof(IVC1VDEC_Params), MS_CACHE_ONLY | MS_SYNC);
875
876 codec = VIDDEC3_create(engine, "ivahd_vc1vdec", (VIDDEC3_Params *)vc1_params);
877 break;
878
879 case DCE_TEST_MJPEG :
880 mjpeg_params = (IJPEGVDEC_Params *) params;
881 mjpeg_params->ErrorConcealmentON = TRUE;
882 mjpeg_params->debugTraceLevel = 0;
883 mjpeg_params->lastNFramesToLog = 0;
884 mjpeg_params->sliceSwitchON = 0;
885 mjpeg_params->numSwitchPerFrame = 0;
886 mjpeg_params->numRestartMarkerPerSwitch = 0;
887
888 DEBUG("dce_alloc VIDDEC3_Params successful mjpeg_params=%p", mjpeg_params);
889
890 err = msync((Ptr)mjpeg_params, sizeof(IJPEGVDEC_Params), MS_CACHE_ONLY | MS_SYNC);
891
892 codec = VIDDEC3_create(engine, "ivahd_jpegvdec", (VIDDEC3_Params *)mjpeg_params);
893 break;
894#ifdef ENABLE_MPEG2
895 case DCE_TEST_MPEG2 :
896 mpeg2_params = (IMPEG2VDEC_Params *) params;
897 mpeg2_params->outloopDeBlocking = TRUE;
898 mpeg2_params->ErrorConcealmentON = FALSE;
899 mpeg2_params->debugTraceLevel = 0;
900 mpeg2_params->lastNFramesToLog = 0;
901
902 DEBUG("dce_alloc VIDDEC3_Params successful mpeg2_params=%p", mpeg2_params);
903
904 err = msync((Ptr)mpeg2_params, sizeof(IMPEG2VDEC_Params), MS_CACHE_ONLY | MS_SYNC);
905
906 codec = VIDDEC3_create(engine, "ivahd_mpeg2vdec", (VIDDEC3_Params *)mpeg2_params);
907 break;
908#endif
909 }
910
911 if( !codec ) {
912 ERROR("fail");
913 goto out;
914 }
915
916 DEBUG("VIDDEC3_create successful codec=%p", codec);
917
918 switch( codec_switch ) {
919 case DCE_TEST_H264 :
920 dynParams = dce_alloc(sizeof(IH264VDEC_DynamicParams));
921 dynParams->size = sizeof(IH264VDEC_DynamicParams);
922 break;
923 case DCE_TEST_MPEG4 :
924 dynParams = dce_alloc(sizeof(IMPEG4VDEC_DynamicParams));
925 dynParams->size = sizeof(IMPEG4VDEC_DynamicParams);
926 dynParams->lateAcquireArg = -1;
927 break;
928 case DCE_TEST_VC1SMP :
929 case DCE_TEST_VC1AP :
930 dynParams = dce_alloc(sizeof(IVC1VDEC_DynamicParams));
931 dynParams->size = sizeof(IVC1VDEC_DynamicParams);
932 dynParams->lateAcquireArg = -1;
933 break;
934 case DCE_TEST_MJPEG :
935 dynParams = dce_alloc(sizeof(IJPEGVDEC_DynamicParams));
936 dynParams->size = sizeof(IJPEGVDEC_DynamicParams);
937 dynParams->lateAcquireArg = -1;
938 break;
939#ifdef ENABLE_MPEG2
940 case DCE_TEST_MPEG2 :
941 dynParams = dce_alloc(sizeof(IMPEG2VDEC_DynamicParams));
942 dynParams->size = sizeof(IMPEG2VDEC_DynamicParams);
943 dynParams->lateAcquireArg = -1;
944 break;
945#endif
946 }
947
948 dynParams->decodeHeader = XDM_DECODE_AU;
949 /*Not Supported: Set default*/
950 dynParams->displayWidth = 0;
951 dynParams->frameSkipMode = IVIDEO_NO_SKIP;
952 dynParams->newFrameFlag = XDAS_TRUE;
953
954
955 //Testing XDM_GETVERSION
956 // NOT WORKING
957#if 0
958
959 switch( codec_switch ) {
960 case DCE_TEST_H264 :
961
962 DEBUG("dce_alloc IH264VDEC_DynamicParams successful dynParams=%p", dynParams);
963 h264_dynParams = (IH264VDEC_DynamicParams *) dynParams;
964 DEBUG("dce_alloc IH264VDEC_DynamicParams successful h264_dynParams=%p", h264_dynParams);
965
966 status = dce_alloc(sizeof(IH264VDEC_Status));
967 status->size = sizeof(IH264VDEC_Status);
968 DEBUG("dce_alloc IH264VDEC_Status successful status=%p", status);
969
970 status->data.buf = (XDAS_Int8 *) version_buffer;
971 h264_status = (IH264VDEC_Status *) status;
972 DEBUG("dce_alloc IH264VDEC_Status successful h264_status=%p", h264_status);
973
974 //((IH264VDEC_Status*)h264_status)->viddec3Status->data.buf = version_buffer;
975 err = VIDDEC3_control(codec, XDM_GETVERSION, (VIDDEC3_DynamicParams *) h264_dynParams, (VIDDEC3_Status *) h264_status);
976
977 DEBUG("dce_alloc IH264VDEC_Status get_version h264_status=%s", (((VIDDEC3_Status *)h264_status)->data.buf));
978 break;
979 default :
980 DEBUG("Not implemented or supported codec_switch %d", codec_switch);
981 }
982
983 if( status ) {
984 dce_free(status);
985 }
986#endif
987
988 switch( codec_switch ) {
989 case DCE_TEST_H264 :
990
991 DEBUG("dce_alloc IH264VDEC_DynamicParams successful dynParams=%p", dynParams);
992 h264_dynParams = (IH264VDEC_DynamicParams *) dynParams;
993 DEBUG("dce_alloc IH264VDEC_DynamicParams successful h264_dynParams=%p", h264_dynParams);
994
995 status = dce_alloc(sizeof(IH264VDEC_Status));
996 status->size = sizeof(IH264VDEC_Status);
997 DEBUG("dce_alloc IH264VDEC_Status successful status=%p", status);
998
999 h264_status = (IH264VDEC_Status *) status;
1000 DEBUG("dce_alloc IH264VDEC_Status successful h264_status=%p", h264_status);
1001 err = VIDDEC3_control(codec, XDM_SETPARAMS, (VIDDEC3_DynamicParams *) h264_dynParams, (VIDDEC3_Status *) h264_status);
1002 break;
1003
1004 case DCE_TEST_MPEG4 :
1005
1006 DEBUG("dce_alloc IMPEG4VDEC_DynamicParams successful dynParams=%p", dynParams);
1007 mpeg4_dynParams = (IMPEG4VDEC_DynamicParams *) dynParams;
1008 DEBUG("dce_alloc IMPEG4VDEC_DynamicParams successful mpeg4_dynParams=%p", mpeg4_dynParams);
1009
1010 status = dce_alloc(sizeof(IMPEG4VDEC_Status));
1011 status->size = sizeof(IMPEG4VDEC_Status);
1012 DEBUG("dce_alloc IMPEG4VDEC_Status successful status=%p", status);
1013
1014 mpeg4_status = (IMPEG4VDEC_Status *) status;
1015 DEBUG("dce_alloc IMPEG4VDEC_Status successful mpeg4_status=%p", mpeg4_status);
1016 err = VIDDEC3_control(codec, XDM_SETPARAMS, (VIDDEC3_DynamicParams *) mpeg4_dynParams, (VIDDEC3_Status *) mpeg4_status);
1017 break;
1018
1019 case DCE_TEST_VC1SMP :
1020 case DCE_TEST_VC1AP :
1021
1022 DEBUG("dce_alloc IVC1VDEC_DynamicParams successful dynParams=%p", dynParams);
1023 vc1_dynParams = (IVC1VDEC_DynamicParams *) dynParams;
1024 DEBUG("dce_alloc IVC1VDEC_DynamicParams successful vc1_dynParams=%p", vc1_dynParams);
1025
1026 status = dce_alloc(sizeof(IVC1VDEC_Status));
1027 status->size = sizeof(IVC1VDEC_Status);
1028 DEBUG("dce_alloc IVC1VDEC_Status successful status=%p", status);
1029
1030 vc1_status = (IVC1VDEC_Status *) status;
1031 DEBUG("dce_alloc IVC1VDEC_Status successful vc1_status=%p", vc1_status);
1032 err = VIDDEC3_control(codec, XDM_SETPARAMS, (VIDDEC3_DynamicParams *) vc1_dynParams, (VIDDEC3_Status *) vc1_status);
1033 break;
1034
1035 case DCE_TEST_MJPEG :
1036
1037 DEBUG("dce_alloc IJPEGVDEC_DynamicParams successful dynParams=%p", dynParams);
1038 mjpeg_dynParams = (IJPEGVDEC_DynamicParams *) dynParams;
1039 mjpeg_dynParams->decodeThumbnail = 0;
1040 mjpeg_dynParams->thumbnailMode = IJPEGVDEC_THUMBNAIL_DOWNSAMPLE;
1041 mjpeg_dynParams->downsamplingFactor = IJPEGVDEC_NODOWNSAMPLE;
1042 mjpeg_dynParams->streamingCompliant = 1;
1043
1044 DEBUG("dce_alloc IJPEGVDEC_DynamicParams successful mjpeg_dynParams=%p", mjpeg_dynParams);
1045
1046 status = dce_alloc(sizeof(IVC1VDEC_Status));
1047 status->size = sizeof(IJPEGVDEC_Status);
1048 DEBUG("dce_alloc IVC1VDEC_Status successful status=%p", status);
1049
1050 mjpeg_status = (IJPEGVDEC_Status *) status;
1051 DEBUG("dce_alloc IJPEGVDEC_Status successful mjpeg_status=%p", mjpeg_status);
1052 err = VIDDEC3_control(codec, XDM_SETPARAMS, (VIDDEC3_DynamicParams *) mjpeg_dynParams, (VIDDEC3_Status *) mjpeg_status);
1053 break;
1054#ifdef ENABLE_MPEG2
1055 case DCE_TEST_MPEG2 :
1056
1057 DEBUG("dce_alloc IMPEG2VDEC_DynamicParams successful dynParams=%p", dynParams);
1058 mpeg2_dynParams = (IMPEG2VDEC_DynamicParams *) dynParams;
1059 //MPEG2 buffer width should be 128 byte aligned for non TILER (atleast)
1060 //If displayWidth=0 then MPEG2 codec does not have a way to calculate
1061 //the stride as compared to other codecs which can calculate it from
1062 //buffer size and image height.stride=buffersize/(height*1.5)
1063 mpeg2_dynParams->viddecDynamicParams.displayWidth = padded_width;
1064
1065 DEBUG("dce_alloc IMPEG2VDEC_DynamicParams successful mpeg2_dynParams=%p", mpeg2_dynParams);
1066
1067 status = dce_alloc(sizeof(IMPEG2VDEC_Status));
1068 status->size = sizeof(IMPEG2VDEC_Status);
1069 DEBUG("dce_alloc IMPEG2VDEC_Status successful status=%p", status);
1070
1071 mpeg2_status = (IMPEG2VDEC_Status *) status;
1072 DEBUG("dce_alloc IMPEG2VDEC_Status successful mpeg2_status=%p", mpeg2_status);
1073 err = VIDDEC3_control(codec, XDM_SETPARAMS, (VIDDEC3_DynamicParams *) mpeg2_dynParams, (VIDDEC3_Status *) mpeg2_status);
1074 break;
1075#endif
1076 default :
1077 DEBUG("Not implemented or supported codec_switch %d", codec_switch);
1078 }
1079
1080 if( err ) {
1081 ERROR("fail: %d", err);
1082 goto shutdown;
1083 }
1084
1085 DEBUG("VIDDEC3_control XDM_SETPARAMS successful");
1086
1087 DEBUG("input buffer configuration width %d height %d", width, height);
1088 inBufs = dce_alloc(sizeof(XDM2_BufDesc));
1089 inBufs->numBufs = 1;
1090 input = tiler_alloc(width * height, 0);
1091 inBufs->descs[0].buf = (XDAS_Int8 *)input;
1092 inBufs->descs[0].memType = XDM_MEMTYPE_RAW;
1093
1094 DEBUG("inBufs->descs[0].buf %p input %p", inBufs->descs[0].buf, input);
1095
1096 outBufs = dce_alloc(sizeof(XDM2_BufDesc));
1097
1098 DEBUG("output buffer configuration num_buffers %d padded_width %d padded_height %d", num_buffers, padded_width, padded_height);
1099
1100#ifdef PROFILE_TIME
1101 uint64_t alloc_time_start = mark_microsecond(NULL);
1102#endif
1103
1104 if( !(strcmp(tilerbuffer, "tiler"))) {
1105 DEBUG("Output allocate through tiler");
1106 tiler = 1;
1107 err = output_allocate(outBufs, num_buffers,
1108 padded_width, padded_height, stride);
1109 } else {
1110 DEBUG("Output allocate through non-tiler");
1111 tiler = 0;
1112 err = output_allocate_nonTiler(outBufs, num_buffers,
1113 padded_width, padded_height, stride);
1114 }
1115
1116#ifdef PROFILE_TIME
1117 output_alloc_time = mark_microsecond(&alloc_time_start);
1118#endif
1119
1120 if( err ) {
1121 ERROR("fail: %d", err);
1122 goto shutdown;
1123 }
1124
1125 inArgs = dce_alloc(sizeof(IVIDDEC3_InArgs));
1126 inArgs->size = sizeof(IVIDDEC3_InArgs);
1127
1128 outArgs = dce_alloc(sizeof(IVIDDEC3_OutArgs));
1129 outArgs->size = sizeof(IVIDDEC3_OutArgs);
1130
1131#ifdef PROFILE_TIME
1132 total_init_time = (uint64_t)mark_microsecond(&init_start_time);
1133 INFO("total_init_time %llu output_alloc_time %llu actual init time in: %lld us", total_init_time, output_alloc_time, total_init_time - output_alloc_time);
1134#endif
1135
1136 while( inBufs->numBufs && outBufs->numBufs ) {
1137 OutputBuffer *buf;
1138 int n, i;
1139
1140 if( !outBufsInUse ) {
1141 buf = output_get();
1142 if( !buf ) {
1143 ERROR("fail: out of buffers");
1144 goto shutdown;
1145 }
1146 } else {
1147 buf = 0;
1148 }
1149
1150 n = read_input(in_pattern, in_cnt, input);
1151 if( n && (n != -1)) {
1152 eof = 0;
1153 inBufs->numBufs = 1;
1154 inBufs->descs[0].buf = (XDAS_Int8 *)input;
1155 inBufs->descs[0].bufSize.bytes = n;
1156 inArgs->numBytes = n;
1157 DEBUG("push: %d (%d bytes) (%p)", in_cnt, n, buf);
1158 in_cnt++;
1159
1160 /*
1161 * Input buffer has data to be decoded.
1162 */
1163 inArgs->inputID = (XDAS_Int32)buf;
1164 if( !outBufsInUse ) {
1165 outBufs->numBufs = 2;
1166 outBufs->descs[0].buf = (XDAS_Int8 *)buf->y;
1167 outBufs->descs[1].buf = (XDAS_Int8 *)buf->uv;
1168 }
1169 } else if( n == -1 ) {
1170
1171 // Set EOF as 1 to ensure flush completes
1172 eof = 1;
1173 in_cnt++;
1174
1175 switch( codec_switch ) {
1176 case DCE_TEST_H264 :
1177 DEBUG("Calling VIDDEC3_control XDM_FLUSH h264_dynParams %p h264_status %p", h264_dynParams, h264_status);
1178 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) h264_dynParams, (VIDDEC3_Status *) h264_status);
1179 break;
1180 case DCE_TEST_MPEG4 :
1181 DEBUG("Calling VIDDEC3_control XDM_FLUSH mpeg4_dynParams %p mpeg4_status %p", mpeg4_dynParams, mpeg4_status);
1182 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) mpeg4_dynParams, (VIDDEC3_Status *) mpeg4_status);
1183 break;
1184 case DCE_TEST_VC1SMP :
1185 case DCE_TEST_VC1AP :
1186 DEBUG("Calling VIDDEC3_control XDM_FLUSH vc1_dynParams %p vc1_status %p", vc1_dynParams, vc1_status);
1187 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) vc1_dynParams, (VIDDEC3_Status *) vc1_status);
1188 break;
1189 case DCE_TEST_MJPEG :
1190 DEBUG("Calling VIDDEC3_control XDM_FLUSH mjpeg_dynParams %p mjpeg_status %p", mjpeg_dynParams, mjpeg_status);
1191 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) mjpeg_dynParams, (VIDDEC3_Status *) mjpeg_status);
1192 break;
1193#ifdef ENABLE_MPEG2
1194 case DCE_TEST_MPEG2 :
1195 DEBUG("Calling VIDDEC3_control XDM_FLUSH mpeg2_dynParams %p mpeg2_status %p", mpeg2_dynParams, mpeg2_status);
1196 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) mpeg2_dynParams, (VIDDEC3_Status *) mpeg2_status);
1197 break;
1198#endif
1199 }
1200
1201 /* We have sent the XDM_FLUSH, call VIDDEC3_process until we get
1202 * an error of XDM_EFAIL which tells us there are no more buffers
1203 * at codec level.
1204 */
1205
1206 inArgs->inputID = 0;
1207 inArgs->numBytes = 0;
1208 inBufs->descs[0].buf = NULL;
1209 inBufs->descs[0].bufSize.bytes = 0;
1210 outBufs->numBufs = 0;
1211 outBufs->descs[0].buf = NULL;
1212 outBufs->descs[1].buf = NULL;
1213 if( buf ) {
1214 output_release(buf);
1215 }
1216 outBufsInUse = 0;
1217
1218
1219 } else {
1220 /* end of input.. */
1221 inBufs->numBufs = 0;
1222 eof = 1;
1223
1224 switch( codec_switch ) {
1225 case DCE_TEST_H264 :
1226 DEBUG("Calling VIDDEC3_control XDM_FLUSH h264_dynParams %p h264_status %p", h264_dynParams, h264_status);
1227 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) h264_dynParams, (VIDDEC3_Status *) h264_status);
1228 break;
1229 case DCE_TEST_MPEG4 :
1230 DEBUG("Calling VIDDEC3_control XDM_FLUSH mpeg4_dynParams %p mpeg4_status %p", mpeg4_dynParams, mpeg4_status);
1231 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) mpeg4_dynParams, (VIDDEC3_Status *) mpeg4_status);
1232 break;
1233 case DCE_TEST_VC1SMP :
1234 case DCE_TEST_VC1AP :
1235 DEBUG("Calling VIDDEC3_control XDM_FLUSH vc1_dynParams %p vc1_status %p", vc1_dynParams, vc1_status);
1236 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) vc1_dynParams, (VIDDEC3_Status *) vc1_status);
1237 break;
1238 case DCE_TEST_MJPEG :
1239 DEBUG("Calling VIDDEC3_control XDM_FLUSH mjpeg_dynParams %p mjpeg_status %p", mjpeg_dynParams, mjpeg_status);
1240 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) mjpeg_dynParams, (VIDDEC3_Status *) mjpeg_status);
1241 break;
1242#ifdef ENABLE_MPEG2
1243 case DCE_TEST_MPEG2 :
1244 DEBUG("Calling VIDDEC3_control XDM_FLUSH mpeg2_dynParams %p mpeg2_status %p", mpeg2_dynParams, mpeg2_status);
1245 err = VIDDEC3_control(codec, XDM_FLUSH, (VIDDEC3_DynamicParams *) mpeg2_dynParams, (VIDDEC3_Status *) mpeg2_status);
1246 break;
1247#endif
1248 }
1249
1250 /* We have sent the XDM_FLUSH, call VIDDEC3_process until we get
1251 * an error of XDM_EFAIL which tells us there are no more buffers
1252 * at codec level.
1253 */
1254
1255 inArgs->inputID = 0;
1256 inArgs->numBytes = 0;
1257 inBufs->numBufs = 0;
1258 inBufs->descs[0].buf = NULL;
1259 inBufs->descs[0].bufSize.bytes = 0;
1260 outBufs->numBufs = 0;
1261 outBufs->descs[0].buf = NULL;
1262 outBufs->descs[1].buf = NULL;
1263 if( buf ) {
1264 output_release(buf);
1265 }
1266 }
1267
1268#ifdef DUMPINPUTDATA
1269 DEBUG("input data dump inArgs->numBytes[%d] inputDump[%p]", inArgs->numBytes, inputDump);
1270
1271 //Dump the file
1272 if( inputDump == NULL ) {
1273 inputDump = fopen("/tmp/inputdump.h264", "ab");
1274 DEBUG("input data dump file open %p errno %d", inputDump, errno);
1275 if( inputDump == NULL ) {
1276 DEBUG("Opening input Dump /tmp/inputdump.h264 file FAILED");
1277 }
1278 }
1279 DEBUG("input data dump file open %p Successful", inputDump);
1280
1281 fwrite(input, sizeof(char), inArgs->numBytes, inputDump);
1282 DEBUG("Dumping input file with size = %d ", inArgs->numBytes);
1283 fflush(inputDump);
1284 fclose(inputDump);
1285 inputDump = NULL;
1286 #endif
1287
1288 int iters = 0;
1289
1290 do {
1291 DEBUG("Calling VIDDEC3_process inArgs->inputID=%x inBufs->descs[0].buf %p inBufs->descs.bufSize %d input %p",
1292 inArgs->inputID, inBufs->descs[0].buf, (int) inBufs->descs[0].bufSize.bytes, input);
1293#ifdef PROFILE_TIME
1294 codec_process_time = mark_microsecond(NULL);
1295#endif
1296 err = VIDDEC3_process(codec, inBufs, outBufs, inArgs, outArgs);
1297#ifdef PROFILE_TIME
1298 INFO("processed returned in: %llu us", (uint64_t) mark_microsecond(&codec_process_time));
1299#endif
1300 if( err ) {
1301 if( XDM_ISFATALERROR(outArgs->extendedError)) {
1302 ERROR("process returned error: %d\n", err);
1303 ERROR("extendedError: %08x", outArgs->extendedError);
1304 goto shutdown;
1305 } else if( eof ) {
1306 /*
1307 * Flush has been ordered, processing the returned output from codec.
1308 * For H.264, bit 18 - IH264VDEC_ERR_STREAM_END indicates flush is completed.
1309 * For MPEG4, bit 24 - IMPEG4VDEC_ERR_STREAM_END indicates flush is completed.
1310 * Only return XDM_EFAIL, when those bit are set.
1311 */
1312 ERROR("Codec_process returned err=%d, extendedError=%08x", err, outArgs->extendedError);
1313 err = XDM_EFAIL;
1314
1315 if((!(((outArgs->extendedError) >> 24) & 0x1)) &&
1316 ((ivahd_decode_type == 2 /*IVAHD_MP4V_DECODE*/) ||
1317 (ivahd_decode_type == 3 /*IVAHD_S263_DECODE*/))) {
1318 err = XDM_EOK;
1319 }
1320
1321 if((!(((outArgs->extendedError) >> 18) & 0x1)) &&
1322 ((ivahd_decode_type == 1 /*IVAHD_H264_DECODE*/) ||
1323 (ivahd_decode_type == 0 /*IVAHD_AVC1_DECODE*/))) {
1324 err = XDM_EOK;
1325 }
1326
1327 if( err == XDM_EFAIL ) {
1328 DEBUG("-------------------- Flush completed------------------------");
1329 }
1330 } else {
1331 DEBUG("Non-fatal err=%d, extendedError=%08x", err, outArgs->extendedError);
1332 err = XDM_EOK;
1333 }
1334 }
1335
1336 /*
1337 * Handling of output data from codec
1338 */
1339 if( tiler ) {
1340 for( i = 0; outArgs->outputID[i]; i++ ) {
1341 /* calculate offset to region of interest */
1342 XDM_Rect *r = &(outArgs->displayBufs.bufDesc[0].activeFrameRegion);
1343
1344 int yoff = (r->topLeft.y * stride) + r->topLeft.x;
1345 int uvoff = (r->topLeft.y * stride / 2) + (stride * padded_height) + r->topLeft.x;
1346
1347 /* get the output buffer and write it to file */
1348 buf = (OutputBuffer *)outArgs->outputID[i];
1349 DEBUG("pop: %d (%p)", out_cnt, buf);
1350
1351 if( out_cnt < 30 ) { // write first 30 frames to output file out_cnt < 300
1352 write_output(out_pattern, out_cnt++, buf->buf + yoff,
1353 buf->buf + uvoff, stride);
1354 } else {
1355 out_cnt++;
1356 }
1357 }
1358 } else {
1359 for( i = 0; outArgs->outputID[i]; i++ ) {
1360 /* calculate offset to region of interest */
1361 XDM_Rect *r = &(outArgs->displayBufs.bufDesc[0].activeFrameRegion);
1362
1363 int yoff = (r->topLeft.y * padded_width) + r->topLeft.x;
1364 int uvoff = (r->topLeft.y * padded_width / 2) + (padded_height * padded_width) + r->topLeft.x;
1365
1366 /* get the output buffer and write it to file */
1367 buf = (OutputBuffer *)outArgs->outputID[i];
1368 DEBUG("pop: %d (%p)", out_cnt, buf);
1369
1370 if( out_cnt < 300 ) { // write first 300 frames to output file
1371 write_output(out_pattern, out_cnt++, buf->buf + yoff,
1372 buf->buf + uvoff, padded_width);
1373 } else {
1374 out_cnt++;
1375 }
1376 }
1377 }
1378
1379 for( i = 0; outArgs->freeBufID[i]; i++ ) {
1380 DEBUG("freeBufID[%d] = %d", i, outArgs->freeBufID[i]);
1381 buf = (OutputBuffer *)outArgs->freeBufID[i];
1382 output_release(buf);
1383 }
1384
1385 if( outArgs->outBufsInUseFlag ) {
1386 outBufsInUse = TRUE;
1387 DEBUG("outBufsInUseFlag is SET. Not sending a new output buffer to codec on the next Codec_process ");
1388 } else {
1389 outBufsInUse = FALSE;
1390 }
1391
1392 ++iters; // Guard for infinite VIDDEC3_PROCESS loop when codec never return XDM_EFAIL
1393 } while( eof && (err != XDM_EFAIL) && (iters < 100)); // Multiple VIDDEC3_process when eof until err == XDM_EFAIL
1394
1395 }
1396
1397shutdown:
1398
1399 printf("\nDeleting codec...\n");
1400 VIDDEC3_delete(codec);
1401
1402out:
1403 if( engine ) {
1404 Engine_close(engine);
1405 }
1406 if( params ) {
1407 dce_free(params);
1408 }
1409 if( dynParams ) {
1410 dce_free(dynParams);
1411 }
1412 if( status ) {
1413 dce_free(status);
1414 }
1415 if( inBufs ) {
1416 dce_free(inBufs);
1417 }
1418 if( outBufs ) {
1419 dce_free(outBufs);
1420 }
1421 if( inArgs ) {
1422 dce_free(inArgs);
1423 }
1424 if( outArgs ) {
1425 dce_free(outArgs);
1426 }
1427 if( input ) {
1428 MemMgr_Free(input);
1429 }
1430
1431 output_free();
1432
1433 printf("DCE test completed...\n");
1434
1435 return (0);
1436}
1437
diff --git a/test_qnx/dce_test.use b/test_qnx/dce_test.use
new file mode 100644
index 0000000..413d849
--- /dev/null
+++ b/test_qnx/dce_test.use
@@ -0,0 +1,38 @@
1/*
2 * $QNXLicenseC:
3 */
4
5
6%C dce test application to test libdce
7
8Syntax:
9%C [options]
10Options:
11 -h Print out the help information
12
13Examples:
141. decoding h.264
15 dce_test width height framesize inpattern outpattern codec tiler/nontiler
16 dce_test 320 240 framesize.txt inputfile.h264 outputfile.yuv h264 tiler
17
182. decoding mpeg4
19 dce_test width height framesize inpattern outpattern codec tiler/nontiler
20 dce_test 640 480 framesize.txt inputfile.m4v outputfile.yuv mpeg4 nontiler
21
223. decoding vc1ap
23 dce_test width height framesize inpattern outpattern codec tiler/nontiler
24 dce_test 720 480 framesize.txt inputfile.vc1 outputfile.yuv vc1ap tiler
25
264. decoding vc1smp
27 dce_test width height framesize inpattern outpattern codec tiler/nontiler
28 dce_test 320 240 framesize.txt inputfile.vc1 outputfile.yuv vc1smp nontiler
29
305. decoding mjpeg
31 dce_test width height framesize inpattern outpattern codec tiler/nontiler
32 dce_test 1280 720 framesize.txt inputfile.bin outputfile.yuv mjpeg tiler
33
346. decoding mpeg2
35 dce_test width height framesize inpattern outpattern codec tiler/nontiler
36 dce_test 1920 1088 framesize.txt inputfile.bin outputfile.yuv mpeg2 nontiler
37
38Currently supported codecs: h264, mpeg4, vc1ap, vc1smp, mjpeg, mpeg2