aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBuddy Liong2015-11-24 16:32:11 -0600
committerBuddy Liong2016-03-01 17:11:16 -0600
commit4cde6d994029b7a442bc2e32f161ca3aa284f6fa (patch)
treefa0c79a6f6fea7f64dcb512f11395a83eabe94a9 /test_qnx/dce_enc_test
parente05d0b506a8f5e9218449d3952ee6c1d327fddb5 (diff)
downloadhardware-ti-libdce-4cde6d994029b7a442bc2e32f161ca3aa284f6fa.tar.gz
hardware-ti-libdce-4cde6d994029b7a442bc2e32f161ca3aa284f6fa.tar.xz
hardware-ti-libdce-4cde6d994029b7a442bc2e32f161ca3aa284f6fa.zip
H.264 low latency with IVIDEO_NUMROWS
H.264 codec user guide describes the functionality of low latency. This functionality allows user to encode/decode a sub-frame level data communications. Without low latency, user can only encode/decode a complete/full frame only. More information about H264 low latency can be found in codec release package: * H.264 Encoder 2.0 on HDVICP2 and Media Controller Based Platform User's Guide (SPRUHG3), Appendix G - Low Latency / Sub Frame Level Synchronization * H.264 Decoder 2.0 on HDVICP2 and Media Controller Based Platform User's Guide (SPRUHF9), Appendix I - Low Latency / Sub Frame Level Synchronization This commit is only implemented low latency with IVIDEO_NUMROWS. H.264 encoder handles inputDataMode = IVIDEO_NUMROWS with getDataFxn as callback to get the numRows being filled into the inputBuffer pointer passed at process call. From H.264 encoder user guide Appendix G, more details can be found in sec. G2 H.264 Encoder Input with sub frame level synchronization H.264 decoder handles outputDataMode = IVIDEO_NUMROWS with putDataFxn as callback to notify client on the numRows/numBlocks being filled by codec into the outputBuffer pointer passed at process call. From H.264 decoder user guide Appendix I, more details can be found in sec. I.2 Details of using Sub Frame Level data sync at output side. The update is only valid on video codec on IVA-HD. This changes depend on the changes done on IPUMM DCE server. No low latency update is performed on video codec on DSP. This commit has dependencies on: IPC 3.42.00.02 or latest IPUMM commit ids: commit e37750cc921a9442c48e7212824b28850ac3aaa7 - H.264 low latency - IVIDEO_NUMROWS commit 266749c0b6a2584d563625f881f998c3d78ca873 - Handling when MPU crashes, eg. CTRL-C on MPU side. commit 030572aaa1964bb50a903852fab0ecc0149b6b7e - H.264 Low Latency - sync put_DataFxn to MPU side Change-Id: I308bc74a879099f38705df6e6dda4a86b6645986 Signed-off-by: Buddy Liong <buddy.liong@ti.com>
Diffstat (limited to 'test_qnx/dce_enc_test')
-rw-r--r--test_qnx/dce_enc_test/dce_enc_test.c766
-rw-r--r--test_qnx/dce_enc_test/dce_enc_test.use44
2 files changed, 550 insertions, 260 deletions
diff --git a/test_qnx/dce_enc_test/dce_enc_test.c b/test_qnx/dce_enc_test/dce_enc_test.c
index dc399fb..616859e 100644
--- a/test_qnx/dce_enc_test/dce_enc_test.c
+++ b/test_qnx/dce_enc_test/dce_enc_test.c
@@ -53,7 +53,12 @@
53#include "ti/shmemallocator/SharedMemoryAllocatorUsr.h" 53#include "ti/shmemallocator/SharedMemoryAllocatorUsr.h"
54 54
55#define PRINT_DEBUG 55#define PRINT_DEBUG
56//#define PRINT_DEBUG_LOW
57
56//#define H264_DEBUG 58//#define H264_DEBUG
59//#define DUMPINPUTDATA
60//#define DUMPOUTPUTDATA
61//#define ROWMODE_INPUTDUMP
57 62
58#define ERROR(FMT, ...) printf("%s:%d:\t%s\terror: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) 63#define ERROR(FMT, ...) printf("%s:%d:\t%s\terror: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
59// enable below to print debug information 64// enable below to print debug information
@@ -62,6 +67,13 @@
62#else 67#else
63#define DEBUG(FMT, ...) 68#define DEBUG(FMT, ...)
64#endif 69#endif
70
71#ifdef PRINT_DEBUG_LOW
72#define DEBUGLOW(FMT, ...) printf("%s:%d:\t%s\tdebug: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
73#else
74#define DEBUGLOW(FMT, ...)
75#endif
76
65#define INFO(FMT, ...) printf("%s:%d:\t%s\tinfo: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) 77#define INFO(FMT, ...) printf("%s:%d:\t%s\tinfo: " FMT "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
66#define MIN(a, b) (((a) < (b)) ? (a) : (b)) 78#define MIN(a, b) (((a) < (b)) ? (a) : (b))
67 79
@@ -74,6 +86,26 @@
74// Getting codec version through XDM_GETVERSION 86// Getting codec version through XDM_GETVERSION
75#define GETVERSION 87#define GETVERSION
76 88
89#ifdef GETVERSION
90#define VERSION_SIZE 128
91#endif
92
93/* ************************************************************************* */
94/* utilities to allocate/manage 2d input buffers */
95
96typedef struct InputBuffer InputBuffer;
97
98struct InputBuffer {
99 char *buf; /* virtual address for local access, 4kb stride */
100 SSPtr y, uv; /* physical addresses of Y and UV for remote access */
101 InputBuffer *next; /* next free buffer */
102 bool tiler;
103 uint32_t len;
104 shm_buf shmBuf;
105};
106
107static InputBuffer *head = NULL;
108
77enum { 109enum {
78 IVAHD_H264_ENCODE, 110 IVAHD_H264_ENCODE,
79 IVAHD_MPEG4_ENCODE, 111 IVAHD_MPEG4_ENCODE,
@@ -114,8 +146,30 @@ IMPEG4ENC_DynamicParams *mpeg4enc_dynParams = NULL;
114IMPEG4ENC_Status *mpeg4enc_status = NULL; 146IMPEG4ENC_Status *mpeg4enc_status = NULL;
115 147
116unsigned int frameSize[64000]; /* Buffer for keeping frame sizes */ 148unsigned int frameSize[64000]; /* Buffer for keeping frame sizes */
149int endOfFile = 0;
150char *in_pattern, *out_pattern;
151int in_cnt = 0, out_cnt = 0;
152InputBuffer *buf = NULL;
117static int input_offset = 0; 153static int input_offset = 0;
118 154
155#ifdef ROWMODE_INPUTDUMP
156FILE *inputDump;
157char Buff1[100];
158static int GlobalCount1 = 0;
159static int read_input_count = 0;
160#endif
161
162#ifdef DUMPOUTPUTDATA
163FILE *outputDump;
164#endif
165
166// This global only used in low latency IVIDEO_NUMROWS
167static int numBlock = 10;
168static int input_y_offset = 0;
169static int input_uv_offset = 0;
170static int dest_y_offset = 0;
171static int dest_uv_offset = 0;
172
119static void *tiler_alloc(int width, int height) 173static void *tiler_alloc(int width, int height)
120{ 174{
121 int dimensions; 175 int dimensions;
@@ -196,18 +250,136 @@ static void free_nonTiler(void *shmBuf)
196 SHM_release(shmBuf); 250 SHM_release(shmBuf);
197} 251}
198 252
199/* ************************************************************************* */ 253void input_free(void)
200/* utilities to allocate/manage 2d input buffers */ 254{
255 InputBuffer *buf = head;
201 256
202typedef struct InputBuffer InputBuffer; 257 while((buf=head)) {
258 DEBUG("input_free: %p", buf);
259 if( buf->tiler ) {
260 MemMgr_Free(buf->buf);
261 } else {
262 SHM_release(&buf->shmBuf);
263 }
264 head = buf->next;
265 free(buf);
266 }
267}
203 268
204struct InputBuffer { 269int input_allocate(IVIDEO2_BufDesc *inBufs, int cnt,
205 char *buf; /* virtual address for local access, 4kb stride */ 270 int width, int height)
206 SSPtr y, uv; /* physical addresses of Y and UV for remote access */ 271{
207 InputBuffer *next; /* next free buffer */ 272 inBufs->imagePitch[0] = 4096;
208 bool tiler; 273 inBufs->planeDesc[0].memType = XDM_MEMTYPE_TILED8;
209 uint32_t len; 274 inBufs->planeDesc[0].bufSize.tileMem.width = width;
210}; 275 inBufs->planeDesc[0].bufSize.tileMem.height = height;
276
277 inBufs->secondFieldOffsetWidth[1] = 1;
278 inBufs->secondFieldOffsetHeight[1] = 0;
279
280 inBufs->imagePitch[1] = 4096;
281 inBufs->planeDesc[1].memType = XDM_MEMTYPE_TILED16;
282 inBufs->planeDesc[1].bufSize.tileMem.width = width; /* UV interleaved width is same a Y */
283 inBufs->planeDesc[1].bufSize.tileMem.height = height / 2;
284
285 // INPUT BUFFER MUST BE in NV12.
286 while( cnt ) {
287 InputBuffer *buf = calloc(sizeof(InputBuffer), 1);
288 if( buf == NULL ) {
289 input_free();
290 return (-ENOMEM);
291 }
292
293 DEBUG(" ----------------- create input TILER buf 0x%x --------------------", (unsigned int)buf);
294
295 buf->buf = tiler_alloc(width, height);
296 if( buf->buf ) {
297 buf->y = (SSPtr) buf->buf;
298 buf->uv = (SSPtr)(buf->buf + (height * 4096));
299
300 DEBUG("INPUT TILER cnt=%d buf=%p, buf->buf=%p y=%08x, uv=%08x", cnt, buf, buf->buf, buf->y, buf->uv);
301
302 buf->tiler = TRUE;
303 buf->next = head;
304 head = buf;
305 } else {
306 ERROR("DCE_ENCODE_TEST_FAIL: TILER ALLOCATION FAILED");
307 free(buf);
308 return (-ENOMEM);
309 }
310 cnt--;
311 }
312
313 return (0);
314}
315
316int input_allocate_nonTiler(IVIDEO2_BufDesc *inBufs, int cnt,
317 int width, int height)
318{
319 int err = 0;
320
321 inBufs->imagePitch[0] = width;
322 inBufs->planeDesc[0].memType = XDM_MEMTYPE_RAW;
323 inBufs->planeDesc[0].bufSize.bytes = width * height;
324 inBufs->secondFieldOffsetWidth[1] = 1;
325 inBufs->secondFieldOffsetHeight[1] = 0;
326
327 inBufs->imagePitch[1] = width;
328 inBufs->planeDesc[1].memType = XDM_MEMTYPE_RAW;
329 inBufs->planeDesc[1].bufSize.bytes = width * height / 2;
330
331 while( cnt ) {
332 InputBuffer *buf = calloc(sizeof(InputBuffer), 1);
333 if( buf == NULL ) {
334 input_free();
335 return (-ENOMEM);
336 }
337
338 DEBUG(" ----------------- create NON INPUT TILER buf 0x%x --------------------", (unsigned int)buf);
339
340 err = allocate_nonTiler(&buf->shmBuf, width * height * 3/2);
341 if( err < 0 ) {
342 ERROR("DCE_ENCODE_TEST_FAIL: NON-TILER ALLOCATION FAILED");
343 free(buf);
344 return (-ENOMEM);
345 }
346 else
347 {
348 buf->buf = (char*)buf->shmBuf.vir_addr;
349 buf->y = (SSPtr)buf->shmBuf.vir_addr;
350 buf->uv = (SSPtr)buf->shmBuf.vir_addr + (height * width);
351
352 DEBUG("INPUT NON TILER buf=%p, buf->buf=%p y=%08x, uv=%08x", buf, buf->buf, buf->y, buf->uv);
353 }
354
355 buf->next = head;
356 buf->tiler = FALSE;
357 head = buf;
358
359 cnt--;
360 }
361
362 return (0);
363}
364
365InputBuffer *input_get(void)
366{
367 InputBuffer *buf = head;
368
369 if( buf ) {
370 head = buf->next;
371 }
372 DEBUG("input_get: %p buf->next %p", buf, buf->next);
373 DEBUG("input_get TEST buf->buf: %p", buf->buf);
374 return (buf);
375}
376
377void input_release(InputBuffer *buf)
378{
379 DEBUG("input_release: %p", buf);
380 buf->next = head;
381 head = buf;
382}
211 383
212/* ************************************************************************* */ 384/* ************************************************************************* */
213 385
@@ -232,20 +404,120 @@ static const char *get_path(const char *pattern, int cnt)
232 return (path); 404 return (path);
233} 405}
234 406
235//#define DUMPINPUTDATA 407int read_partial_input(const char *pattern, int cnt, char *input, int rowmode, int numBlock)
236//#define DUMPOUTPUTDATA 408{
409 int sz = 0, n = 0, num_planes, i, buf_height;
410 char *input_y = (char *) ((int) input + dest_y_offset);
411 char *input_uv = (char *) ((int) input + dest_uv_offset);
237 412
238#ifdef DUMPINPUTDATA 413 const char *path = get_path(pattern, cnt);
239FILE *inputDump; 414 if( path == NULL ) {
415 return (sz);
416 }
417
418 int fd = open(path, O_RDONLY);
419 if( fd < 0 ) {
420 ERROR("open input file failed");
421 return (-1);
422 }
423
424#ifdef ROWMODE_INPUTDUMP
425 ++read_input_count;
240#endif 426#endif
241 427
242#ifdef DUMPOUTPUTDATA 428 // For rowmode, filling the input in NV12 format per numBlock.
243FILE *outputDump; 429 // For numBlock = 1, that means application has written (provided)
430 // width * 16 (luma pixels) of input data in input buffer & width * 8 (chroma pixels).
431 for( num_planes = 0; num_planes < 2; num_planes++ ) {
432 if( num_planes ) { //UV location - num_plane = 1
433 buf_height = numBlock * 16 / 2;
434 } else { //Y location - num_plane = 0
435 buf_height = numBlock * 16;
436 }
437
438 for( i = 0; i < buf_height; i++ ) {
439 if( num_planes ) { // UV location - num_plane = 1
440 if( dest_uv_offset < (width * height * 1.5) ) {
441 lseek(fd, input_uv_offset, SEEK_SET);
442 n = read(fd, input_uv , width);
443 if( n ) {
444 sz += n;
445 input_uv_offset += n;
446 } else {
447 close(fd);
448 DEBUGLOW("Reading REACH EOF - return -1");
449 endOfFile = 1;
450 return (-1); //Cannot read anymore input
451 }
452
453 if( tiler ) {
454 input_uv = (char *) ((int)input_uv + 4096);
455 dest_uv_offset += 4096;
456 } else {
457 input_uv = (char *) ((int)input_uv + width);
458 dest_uv_offset += width;
459 }
460 } else {
461 //DEBUGLOW("dest_uv_offset %d >= width * height * 1.5 %d", (int)dest_uv_offset, (int) (width * height * 1.5));
462 }
463 } else { // Y location - num_plane = 0
464 if( dest_y_offset < (width * height) ) {
465 lseek(fd, input_y_offset, SEEK_SET);
466 n = read(fd, input_y , width);
467 if( n ) {
468 sz += n;
469 input_y_offset += n;
470 } else {
471 close(fd);
472 DEBUGLOW("Reading REACH EOF - return -1");
473 endOfFile = 1;
474 return (-1); //Cannot read anymore input
475 }
476
477 if( tiler ) {
478 input_y = (char *) ((int)input_y + 4096);
479 dest_y_offset += 4096;
480 } else {
481 input_y = (char *) ((int)input_y + width);
482 dest_y_offset += width;
483 }
484 } else {
485 //DEBUGLOW("dest_y_offset %d >= width * height %d", dest_y_offset, width * height);
486 }
487 }
488 }
489 }
490
491#ifdef ROWMODE_INPUTDUMP
492 if ( read_input_count % 68 == 0 ) {
493 //Dump the file
494 if( inputDump == NULL ) {
495 if( GlobalCount1 <= 50 ) {
496 sprintf(Buff1, "/tmp/dceinputdump%d.bin", GlobalCount1);
497 inputDump = fopen(Buff1, "wb+");
498 if( inputDump == NULL ) {
499 ERROR("Opening input Dump /tmp/dceinputdump%d.bin file FAILED", GlobalCount1);
500 } else {
501 GlobalCount1++;
502 fwrite(input, 1, width * height * 3 / 2, inputDump);
503 DEBUGLOW("Dumping input file of NV12 format with read data of %d inside buffersize = %d", n, width * height * 3 / 2);
504 fflush(inputDump);
505 fclose(inputDump);
506 inputDump = NULL;
507 }
508 }
509 }
510 }
244#endif 511#endif
512 DEBUGLOW("read_partial_input close fd");
513 close(fd);
245 514
515 DEBUGLOW("sz=%d", sz);
516 return (sz);
517}
246 518
247/* helper to read one frame NV12 of input */ 519/* helper to read one frame NV12 of input */
248int read_input(const char *pattern, int cnt, char *input) 520int read_input(const char *pattern, int cnt, char *input, int rowmode)
249{ 521{
250 int sz = 0, n = 0, num_planes, i, buf_height; 522 int sz = 0, n = 0, num_planes, i, buf_height;
251 523
@@ -255,23 +527,19 @@ int read_input(const char *pattern, int cnt, char *input)
255 } 527 }
256 528
257 int fd = open(path, O_RDONLY); 529 int fd = open(path, O_RDONLY);
258
259 //DEBUG("Open file fd %d errno %d", fd, errno);
260 if( fd < 0 ) { 530 if( fd < 0 ) {
261 DEBUG("open input file failed"); 531 DEBUG("open input file failed");
262 return (-1); 532 return (-1);
263 } 533 }
264 534
265 sz = width * height * 3 / 2;
266
267 // Filling the input in NV12 format; where 535 // Filling the input in NV12 format; where
268 // Luma has size of Stride "4096" * height for TILER or width * height 536 // Luma has size of Stride "4096" * height for TILER or width * height
269 // and Chroma has size of Stride "4096 * height / 2 for TILER or 537 // and Chroma has size of Stride "4096 * height / 2 for TILER or
270 // width * height / 2 538 // width * height / 2
271 for( num_planes = 0; num_planes < 2; num_planes++ ) { 539 for( num_planes = 0; num_planes < 2; num_planes++ ) {
272 if( num_planes ) { //UV location 540 if( num_planes ) { //UV location - num_plane = 1
273 buf_height = height / 2; 541 buf_height = height / 2;
274 } else { //Y location 542 } else { //Y location - num_plane = 0
275 buf_height = height; 543 buf_height = height;
276 } 544 }
277 545
@@ -279,10 +547,12 @@ int read_input(const char *pattern, int cnt, char *input)
279 lseek(fd, input_offset, SEEK_SET); 547 lseek(fd, input_offset, SEEK_SET);
280 n = read(fd, input, width); 548 n = read(fd, input, width);
281 if( n ) { 549 if( n ) {
550 sz += n;
282 input_offset += n; 551 input_offset += n;
283 } else { 552 } else {
284 close(fd); 553 close(fd);
285 DEBUG("Reading REACH EOF - return -1"); 554 DEBUG("Reading REACH EOF - return -1");
555 endOfFile = 1;
286 return (-1); //Cannot read anymore input 556 return (-1); //Cannot read anymore input
287 } 557 }
288 558
@@ -294,6 +564,7 @@ int read_input(const char *pattern, int cnt, char *input)
294 } 564 }
295 } 565 }
296 566
567 DEBUG("read_input close fd");
297 close(fd); 568 close(fd);
298 569
299 DEBUG("sz=%d", sz); 570 DEBUG("sz=%d", sz);
@@ -341,12 +612,43 @@ uint64_t mark_microsecond(uint64_t *last)
341 } 612 }
342 return (t1); 613 return (t1);
343} 614}
344
345#endif 615#endif
346 616
347#ifdef GETVERSION 617/* Function callback for low latency encoder with NUMROWS*/
348#define VERSION_SIZE 128 618/* Client is expected to fill the dataSyncDesc information especially numBlocks for codec to continue */
349#endif 619/* numBlocks is filled based on the input data being filled into the input buffer that was passed in VIDENC2_process */
620/* The return value of this function is NULL when okay; if there is a problem return value < 0, then LIBDCE will always retry */
621XDAS_Int32 H264E_MPU_GetDataFxn(XDM_DataSyncHandle dataSyncHandle, XDM_DataSyncDesc *dataSyncDesc)
622{
623 int n;
624
625 DEBUGLOW("-----------------------START--------------------------------");
626 //sleep(1); //instrument a 1s delay on the MPU side to get numblocks.
627 //DEBUGLOW("After 1sec Received H264E_MPU_GetDataFxn 0x%x", (unsigned int)dataSyncHandle);
628 // Need to read and write the amount put into the inputBuffer.
629 // Need to write numBlock into the inputBuffer and update the data here to be passed down to M4.
630
631 // Set NumBlock to be equal height/(16 * 2); eg. 1088 / (16 * 2) = 34 rows; meaning 34*16 height of data each time.
632 numBlock = ALIGN2(height, 4) / (16 * 2);
633
634 DEBUGLOW("Before read_partial_input numBlock %d buf->buf %p input_y_offset %d input_uv_offset %d dest_y_offset %d dest_uv_offset %d", numBlock, buf->buf, input_y_offset, input_uv_offset, dest_y_offset, dest_uv_offset);
635 n = read_partial_input(in_pattern, in_cnt, buf->buf, TRUE, numBlock);
636 DEBUGLOW("After read_partial_input buf->buf %p input_y_offset %d input_uv_offset %d dest_y_offset %d dest_uv_offset %d", buf->buf, input_y_offset, input_uv_offset, dest_y_offset, dest_uv_offset);
637 if( n > 0) {
638 if (dataSyncHandle == codec) {
639 dataSyncDesc->size = sizeof(XDM_DataSyncDesc); // Size of this structure
640 dataSyncDesc->scatteredBlocksFlag = XDAS_FALSE; // Flag indicates whether the individual data blocks may be scatttered in memory.
641 dataSyncDesc->baseAddr = (XDAS_Int32*) buf->buf;
642 dataSyncDesc->numBlocks = numBlock;
643 dataSyncDesc->varBlockSizesFlag = XDAS_FALSE;
644 dataSyncDesc->blockSizes= NULL;
645 DEBUGLOW("H264E_MPU_GetDataFxn dataSyncDesc->size %d dataSyncDesc->baseAddr 0x%x dataSyncDesc->numBlocks %d", (unsigned int)dataSyncDesc->size, (unsigned int)dataSyncDesc->baseAddr, (unsigned int)dataSyncDesc->numBlocks);
646 }
647 }
648 DEBUGLOW("read_partial_input is returning size of %d", n);
649 DEBUGLOW("-----------------------END--------------------------------");
650 return (0);
651}
350 652
351/* encoder body */ 653/* encoder body */
352int main(int argc, char * *argv) 654int main(int argc, char * *argv)
@@ -357,21 +659,18 @@ int main(int argc, char * *argv)
357 char *output_mvbuf = NULL; 659 char *output_mvbuf = NULL;
358 shm_buf output_mvbuf_nonTiler; 660 shm_buf output_mvbuf_nonTiler;
359 shm_buf output_nonTiler; 661 shm_buf output_nonTiler;
360 shm_buf input_nonTiler;
361 int output_size = 0; 662 int output_size = 0;
362 int mvbufinfo_size = 0; 663 int mvbufinfo_size = 0;
363 char *in_pattern, *out_pattern;
364 int in_cnt = 0, out_cnt = 0;
365 InputBuffer *buf = NULL;
366 char profile[10]; 664 char profile[10];
367 int profile_value; 665 int profile_value;
368 int level; 666 int level;
369 int eof = 0;
370 char vid_codec[10]; 667 char vid_codec[10];
371 char tilerbuffer[10]; 668 char tilerbuffer[10];
372 unsigned int codec_switch = 0; 669 unsigned int codec_switch = 0;
373 int bytesGenerated = 0; 670 int bytesGenerated = 0;
374 int frames_to_write = 0; 671 int frames_to_write = 0;
672 char row_mode[10];
673 int datamode;
375 674
376#ifdef PROFILE_TIME 675#ifdef PROFILE_TIME
377 uint64_t init_start_time = 0; 676 uint64_t init_start_time = 0;
@@ -394,12 +693,12 @@ int main(int argc, char * *argv)
394 argv++; 693 argv++;
395 } 694 }
396 695
397 if( argc != 10 ) { 696 if( argc != 11 ) {
398 printf("usage: %s width height frames_to_write inpattern outpattern codec baseline/high level buffertype\n", argv[0]); 697 printf("usage: %s width height frames_to_write inpattern outpattern codec baseline/high level buffertype mode\n", argv[0]);
399 printf("example: %s 1920 1088 300 in.yuv out.h264 h264 baseline 10 tiler\n", argv[0]); 698 printf("example: %s 1920 1088 300 in.yuv out.h264 h264 baseline 10 tiler numrow/slice/fixed/full\n", argv[0]);
400 printf("example: %s 176 144 300 in.yuv out.m4v mpeg4 simple/baseline 0 non-tiler\n", argv[0]); 699 printf("example: %s 176 144 300 in.yuv out.m4v mpeg4 simple/baseline 0 non-tiler full\n", argv[0]);
401 printf("example: %s 176 144 300 in.yuv out.m4v h263 simple/baseline 0 tiler\n", argv[0]); 700 printf("example: %s 176 144 300 in.yuv out.m4v h263 simple/baseline 0 tiler full\n", argv[0]);
402 printf("Currently supported codecs: h264 or mpeg4 or h263\n"); 701 printf("Currently supported codecs: h264 or mpeg4 or h263 full\n");
403 printf("Run this command for help on the use case: use dce_enc_test\n"); 702 printf("Run this command for help on the use case: use dce_enc_test\n");
404 return (1); 703 return (1);
405 } 704 }
@@ -413,9 +712,11 @@ int main(int argc, char * *argv)
413 strcpy(profile, argv[7]); 712 strcpy(profile, argv[7]);
414 level = atoi(argv[8]); 713 level = atoi(argv[8]);
415 strcpy(tilerbuffer, argv[9]); 714 strcpy(tilerbuffer, argv[9]);
715 strcpy(row_mode, argv[10]);
416 716
417 printf("Selected codec: %s\n", vid_codec); 717 printf("Selected codec: %s\n", vid_codec);
418 printf("Selected buffer: %s\n", tilerbuffer); 718 printf("Selected buffer: %s\n", tilerbuffer);
719 printf("Encode mode: %s\n", row_mode);
419 720
420 enum { 721 enum {
421 DCE_ENC_TEST_H264 = 1, 722 DCE_ENC_TEST_H264 = 1,
@@ -518,6 +819,27 @@ int main(int argc, char * *argv)
518 return (1); 819 return (1);
519 } 820 }
520 821
822 if((!(strcmp(row_mode, "full")))) {
823 datamode = IVIDEO_ENTIREFRAME;
824 } else if ((!(strcmp(row_mode, "numrow")))) {
825 datamode = IVIDEO_NUMROWS;
826 } else if ((!(strcmp(row_mode, "slice")))) {
827 datamode = IVIDEO_SLICEMODE;
828 ERROR("SLICE mode is not supported.");
829 goto shutdown;
830 } else if ((!(strcmp(row_mode, "fixed")))) {
831 datamode = IVIDEO_FIXEDLENGTH;
832 ERROR("FIXED LENGTH mode is not supported.");
833 goto shutdown;
834 } else {
835 ERROR("WRONG argument mode %s", row_mode);
836 goto shutdown;
837 }
838
839 if( (codec_switch != DCE_ENC_TEST_H264) && (datamode != IVIDEO_ENTIREFRAME) ) {
840 ERROR("WRONG argument codec type %s mode %s", vid_codec, row_mode);
841 goto shutdown;
842 }
521 DEBUG("width=%d, height=%d", width, height); 843 DEBUG("width=%d, height=%d", width, height);
522 844
523 /* output buffer parameters is aligned */ 845 /* output buffer parameters is aligned */
@@ -528,13 +850,13 @@ int main(int argc, char * *argv)
528 case DCE_ENC_TEST_H264 : 850 case DCE_ENC_TEST_H264 :
529 case DCE_ENC_TEST_MPEG4 : 851 case DCE_ENC_TEST_MPEG4 :
530 case DCE_ENC_TEST_H263 : 852 case DCE_ENC_TEST_H263 :
531 num_buffers = 1; 853 num_buffers = 2;
532 break; 854 break;
533 default : 855 default :
534 ERROR("Unrecognized codec to encode"); 856 ERROR("Unrecognized codec to encode");
535 } 857 }
536 858
537 DEBUG("width=%d, height=%d, num_buffers=%d", 859 DEBUG("After alignment width=%d, height=%d, num_buffers=%d",
538 width, height, num_buffers); 860 width, height, num_buffers);
539 861
540#ifdef PROFILE_TIME 862#ifdef PROFILE_TIME
@@ -550,104 +872,6 @@ int main(int argc, char * *argv)
550 DEBUG("Engine_open successful engine=%p", engine); 872 DEBUG("Engine_open successful engine=%p", engine);
551 873
552/* 874/*
553 * inBufs handling
554 */
555 DEBUG("input buffer configuration width %d height %d", width, height);
556 inBufs = dce_alloc(sizeof(IVIDEO2_BufDesc));
557
558 DEBUG("Input allocate through tiler");
559
560#ifdef PROFILE_TIME
561 uint64_t alloc_time_start = mark_microsecond(NULL);
562#endif
563
564 inBufs->numPlanes = 2;
565 inBufs->imageRegion.topLeft.x = 0;
566 inBufs->imageRegion.topLeft.y = 0;
567 inBufs->imageRegion.bottomRight.x = width;
568
569 inBufs->topFieldFirstFlag = 0; //Only valid for interlace content.
570 inBufs->contentType = IVIDEO_PROGRESSIVE;
571
572 inBufs->activeFrameRegion.topLeft.x = 0;
573 inBufs->activeFrameRegion.topLeft.y = 0;
574 inBufs->activeFrameRegion.bottomRight.x = width;
575 inBufs->activeFrameRegion.bottomRight.y = height;
576
577 inBufs->imageRegion.bottomRight.y = height;
578 inBufs->chromaFormat = XDM_YUV_420SP;
579
580 inBufs->secondFieldOffsetWidth[0] = 0;
581 inBufs->secondFieldOffsetHeight[0] = 0;
582
583 if( !(strcmp(tilerbuffer, "tiler")) ) {
584 DEBUG("Input allocate through TILER 2D");
585 tiler = 1;
586
587 inBufs->imagePitch[0] = 4096;
588 inBufs->planeDesc[0].memType = XDM_MEMTYPE_TILED8;
589 inBufs->planeDesc[0].bufSize.tileMem.width = width;
590 inBufs->planeDesc[0].bufSize.tileMem.height = height;
591
592 inBufs->secondFieldOffsetWidth[1] = 1;
593 inBufs->secondFieldOffsetHeight[1] = 0;
594
595 inBufs->imagePitch[1] = 4096;
596 inBufs->planeDesc[1].memType = XDM_MEMTYPE_TILED16;
597 inBufs->planeDesc[1].bufSize.tileMem.width = width; /* UV interleaved width is same a Y */
598 inBufs->planeDesc[1].bufSize.tileMem.height = height / 2;
599
600 // INPUT BUFFER MUST BE TILED NV12. Encoder codec doesn't support non TILED input buffer.
601 buf = calloc(sizeof(InputBuffer), 1);
602 DEBUG(" ----------------- create INPUT TILER buf 0x%x --------------------", (unsigned int)buf);
603 buf->buf = tiler_alloc(width, height);
604 if( buf->buf ) {
605 buf->y = (SSPtr)buf->buf;
606 buf->uv = (SSPtr)buf->buf + (height * 4096);
607
608 DEBUG("INPUT TILER buf=%p, buf->buf=%p y=%08x, uv=%08x", buf, buf->buf, buf->y, buf->uv);
609 } else {
610 ERROR("DCE_ENCODE_TEST_FAIL: TILER ALLOCATION FAILED");
611 goto shutdown;
612 }
613 } else {
614 DEBUG("Input allocate through NON-TILER");
615 tiler = 0;
616
617 inBufs->imagePitch[0] = width;
618 inBufs->planeDesc[0].memType = XDM_MEMTYPE_RAW;
619 inBufs->planeDesc[0].bufSize.bytes = width * height;
620 inBufs->secondFieldOffsetWidth[1] = 1;
621 inBufs->secondFieldOffsetHeight[1] = 0;
622
623 inBufs->imagePitch[1] = width;
624 inBufs->planeDesc[1].memType = XDM_MEMTYPE_RAW;
625 inBufs->planeDesc[1].bufSize.bytes = width * height / 2;
626 buf = calloc(sizeof(InputBuffer), 1);
627 DEBUG(" ----------------- create NON INPUT TILER buf 0x%x --------------------", (unsigned int)buf);
628 err = allocate_nonTiler(&input_nonTiler, width * height * 3/2);
629 if( err < 0 ) {
630 ERROR("DCE_ENCODE_TEST_FAIL: NON-TILER ALLOCATION FAILED");
631 free(buf);
632 goto shutdown;
633 }
634 else
635 {
636 buf->buf = (char*)input_nonTiler.vir_addr;
637 buf->y = (SSPtr)input_nonTiler.vir_addr;
638 buf->uv = (SSPtr)input_nonTiler.vir_addr + (height * width);
639
640 DEBUG("INPUT NON TILER buf=%p, buf->buf=%p y=%08x, uv=%08x", buf, buf->buf, buf->y, buf->uv);
641 }
642 }
643
644#ifdef PROFILE_TIME
645 input_alloc_time = mark_microsecond(&alloc_time_start);
646#endif
647
648 DEBUG("input buffer configuration num_buffers %d width %d height %d", num_buffers, width, height);
649
650/*
651 * inArgs and outArgs configuration for static parameter passed during codec creation. 875 * inArgs and outArgs configuration for static parameter passed during codec creation.
652 */ 876 */
653 switch( codec_switch ) { 877 switch( codec_switch ) {
@@ -690,7 +914,15 @@ int main(int argc, char * *argv)
690 params->operatingMode = IVIDEO_ENCODE_ONLY; //IVIDEO_OperatingMode 914 params->operatingMode = IVIDEO_ENCODE_ONLY; //IVIDEO_OperatingMode
691 params->profile = profile_value; 915 params->profile = profile_value;
692 params->level = level; 916 params->level = level;
693 params->inputDataMode = IVIDEO_ENTIREFRAME; //IVIDEO_DataMode 917
918 if (datamode == IVIDEO_NUMROWS) {
919 params->inputDataMode = IVIDEO_NUMROWS;
920 params->numInputDataUnits = 1;
921 } else {
922 params->inputDataMode = IVIDEO_ENTIREFRAME; //IVIDEO_DataMode
923 params->numInputDataUnits = 1;
924 }
925
694 params->outputDataMode = IVIDEO_ENTIREFRAME; //IVIDEO_DataMode 926 params->outputDataMode = IVIDEO_ENTIREFRAME; //IVIDEO_DataMode
695 params->numInputDataUnits = 1; 927 params->numInputDataUnits = 1;
696 params->numOutputDataUnits = 1; 928 params->numOutputDataUnits = 1;
@@ -698,7 +930,7 @@ int main(int argc, char * *argv)
698 params->metadataType[1] = IVIDEO_METADATAPLANE_NONE; 930 params->metadataType[1] = IVIDEO_METADATAPLANE_NONE;
699 params->metadataType[2] = IVIDEO_METADATAPLANE_NONE; 931 params->metadataType[2] = IVIDEO_METADATAPLANE_NONE;
700 932
701 DEBUG("dce_alloc VIDENC2_Params successful params=%p", params); 933 DEBUG("dce_alloc VIDENC2_Params successful params=%p inputDataMode(2=IVIDEO_NUMROWS) %d", params, params->inputDataMode);
702 934
703 switch( codec_switch ) { 935 switch( codec_switch ) {
704 case DCE_ENC_TEST_H264 : 936 case DCE_ENC_TEST_H264 :
@@ -980,7 +1212,14 @@ int main(int argc, char * *argv)
980 dynParams->ignoreOutbufSizeFlag = XDAS_FALSE; // If this is XDAS_TRUE then getBufferFxn and getBufferHandle needs to be set. 1212 dynParams->ignoreOutbufSizeFlag = XDAS_FALSE; // If this is XDAS_TRUE then getBufferFxn and getBufferHandle needs to be set.
981 dynParams->putDataFxn = NULL; 1213 dynParams->putDataFxn = NULL;
982 dynParams->putDataHandle = NULL; 1214 dynParams->putDataHandle = NULL;
983 dynParams->getDataFxn = NULL; 1215
1216 if (datamode == IVIDEO_NUMROWS) {
1217 dynParams->getDataFxn = (XDM_DataSyncGetFxn) H264E_MPU_GetDataFxn;
1218 DEBUGLOW("dynParams->getDataFxn %p", dynParams->getDataFxn);
1219 } else {
1220 dynParams->getDataFxn = NULL;
1221 }
1222
984 dynParams->getDataHandle = NULL; 1223 dynParams->getDataHandle = NULL;
985 dynParams->getBufferFxn = NULL; 1224 dynParams->getBufferFxn = NULL;
986 dynParams->getBufferHandle = NULL; 1225 dynParams->getBufferHandle = NULL;
@@ -1096,7 +1335,6 @@ int main(int argc, char * *argv)
1096 err = VIDENC2_control(codec, XDM_GETVERSION, (VIDENC2_DynamicParams *) h264enc_dynParams, (VIDENC2_Status *) h264enc_status); 1335 err = VIDENC2_control(codec, XDM_GETVERSION, (VIDENC2_DynamicParams *) h264enc_dynParams, (VIDENC2_Status *) h264enc_status);
1097 DEBUG("VIDENC2_control IH264ENC_Status XDM_GETVERSION h264enc_status->data.buf = %s", (((VIDENC2_Status *)h264enc_status)->data.buf)); 1336 DEBUG("VIDENC2_control IH264ENC_Status XDM_GETVERSION h264enc_status->data.buf = %s", (((VIDENC2_Status *)h264enc_status)->data.buf));
1098#endif 1337#endif
1099
1100 h264enc_status = (IH264ENC_Status *) status; 1338 h264enc_status = (IH264ENC_Status *) status;
1101 err = VIDENC2_control(codec, XDM_SETPARAMS, (VIDENC2_DynamicParams *) h264enc_dynParams, (VIDENC2_Status *) h264enc_status); 1339 err = VIDENC2_control(codec, XDM_SETPARAMS, (VIDENC2_DynamicParams *) h264enc_dynParams, (VIDENC2_Status *) h264enc_status);
1102 DEBUG("dce_alloc IH264ENC_Status successful h264enc_status=%p", h264enc_status); 1340 DEBUG("dce_alloc IH264ENC_Status successful h264enc_status=%p", h264enc_status);
@@ -1158,7 +1396,64 @@ int main(int argc, char * *argv)
1158 // XDM_GETBUFINFO 1396 // XDM_GETBUFINFO
1159 // Send Control cmd XDM_GETBUFINFO to get min output and output size 1397 // Send Control cmd XDM_GETBUFINFO to get min output and output size
1160 err = VIDENC2_control(codec, XDM_GETBUFINFO, dynParams, status); 1398 err = VIDENC2_control(codec, XDM_GETBUFINFO, dynParams, status);
1161 DEBUG("VIDENC2_control - XDM_GETBUFINFO err %d status numOutBuf %d OutBufSize %d MVBufInfo %d", err, status->bufInfo.minNumOutBufs, status->bufInfo.minOutBufSize[0].bytes, status->bufInfo.minOutBufSize[1].bytes); 1399 DEBUG("VIDENC2_control - XDM_GETBUFINFO err %d status numInBuf %d minInBufSize[0] %d minInBufSize[1] %d", err, status->bufInfo.minNumInBufs, status->bufInfo.minInBufSize[0].bytes, status->bufInfo.minInBufSize[1].bytes);
1400 num_buffers = status->bufInfo.minNumInBufs;
1401
1402/*
1403 * inBufs handling
1404 */
1405 DEBUG("input buffer configuration width %d height %d", width, height);
1406 inBufs = dce_alloc(sizeof(IVIDEO2_BufDesc));
1407
1408 DEBUG("Input inBufs 0x%x allocate through dce_alloc", (unsigned int) inBufs);
1409
1410#ifdef PROFILE_TIME
1411 uint64_t alloc_time_start = mark_microsecond(NULL);
1412#endif
1413
1414 inBufs->numPlanes = 2;
1415 inBufs->imageRegion.topLeft.x = 0;
1416 inBufs->imageRegion.topLeft.y = 0;
1417 inBufs->imageRegion.bottomRight.x = width;
1418
1419 inBufs->topFieldFirstFlag = 0; //Only valid for interlace content.
1420 inBufs->contentType = IVIDEO_PROGRESSIVE;
1421
1422 inBufs->activeFrameRegion.topLeft.x = 0;
1423 inBufs->activeFrameRegion.topLeft.y = 0;
1424 inBufs->activeFrameRegion.bottomRight.x = width;
1425 inBufs->activeFrameRegion.bottomRight.y = height;
1426
1427 inBufs->imageRegion.bottomRight.y = height;
1428 inBufs->chromaFormat = XDM_YUV_420SP;
1429
1430 inBufs->secondFieldOffsetWidth[0] = 0;
1431 inBufs->secondFieldOffsetHeight[0] = 0;
1432
1433 if( !(strcmp(tilerbuffer, "tiler")) ) {
1434 DEBUG("Input allocate through TILER 2D");
1435 tiler = 1;
1436 input_allocate(inBufs, num_buffers, width, height);
1437 } else {
1438 DEBUG("Input allocate through NON-TILER");
1439 tiler = 0;
1440 input_allocate_nonTiler(inBufs, num_buffers, width, height);
1441 }
1442
1443#ifdef PROFILE_TIME
1444 input_alloc_time = mark_microsecond(&alloc_time_start);
1445#endif
1446
1447 if (datamode == IVIDEO_NUMROWS) {
1448 if( tiler ) {
1449 input_uv_offset = input_y_offset + (4096 * height);
1450 } else {
1451 input_uv_offset = input_y_offset + (width * height);
1452 }
1453 DEBUG("input_y_offset %d input_uv_offset %d ", input_y_offset, input_uv_offset);
1454 }
1455
1456 DEBUG("input buffer configuration num_buffers %d width %d height %d", num_buffers, width, height);
1162 1457
1163/* 1458/*
1164 * outBufs handling 1459 * outBufs handling
@@ -1226,15 +1521,39 @@ int main(int argc, char * *argv)
1226/* 1521/*
1227 * codec process 1522 * codec process
1228 */ 1523 */
1229 while( inBufs->numPlanes && outBufs->numBufs ) { 1524 while ( !endOfFile) {
1230 int n; 1525 int n = 0;
1231 DEBUG("Looping on reading input inBufs->numPlanes %d outBufs->numBufs %d", inBufs->numPlanes, outBufs->numBufs); 1526 buf = input_get();
1527 DEBUG("input_get buf %p", buf);
1528 if( !buf ) {
1529 ERROR("DCE_TEST_FAIL: out of buffers");
1530 goto shutdown;
1531 }
1232 1532
1233 //Read the NV12 frame to input buffer to be encoded. 1533 if (datamode == IVIDEO_ENTIREFRAME) {
1234 n = read_input(in_pattern, in_cnt, buf->buf); 1534 //Read the NV12 frame to input buffer to be encoded.
1535 n = read_input(in_pattern, in_cnt, buf->buf, FALSE);
1536 } else if (datamode == IVIDEO_NUMROWS) {
1537 int cnt = 0;
1538 //Check if input has reached EOF - from the current input_uv_offset + 1 full frame
1539 const char *path = get_path(in_pattern, cnt);
1540 int fd = open(path, O_RDONLY);
1541 DEBUGLOW("CHECK Position %d", input_uv_offset - 1 + (width * height / 2));
1542 lseek(fd, input_uv_offset - 1 + (width * height / 2), SEEK_SET);
1543 char temp_buf[100];
1544 n = read(fd, temp_buf, sizeof(temp_buf));
1545 DEBUGLOW("CHECK on the next input full frame n %d", n);
1546 if (!n) {
1547 DEBUGLOW("CHECK - next input full frame is Empty as n is %d - REACH EOF", n);
1548 endOfFile = 1;
1549 n = -1;
1550 }
1551 } else {
1552 ERROR("NOT SUPPORTED MODE");
1553 goto shutdown;
1554 }
1235 1555
1236 if( n && (n != -1) ) { 1556 if( n && (n != -1) ) {
1237 eof = 0;
1238 inBufs->planeDesc[0].buf = (XDAS_Int8 *)buf->y; 1557 inBufs->planeDesc[0].buf = (XDAS_Int8 *)buf->y;
1239 inBufs->planeDesc[1].buf = (XDAS_Int8 *)buf->uv; 1558 inBufs->planeDesc[1].buf = (XDAS_Int8 *)buf->uv;
1240 DEBUG("inBufs->planeDesc[0].buf %p inBufs->planeDesc[1].buf %p", inBufs->planeDesc[0].buf, inBufs->planeDesc[1].buf); 1559 DEBUG("inBufs->planeDesc[0].buf %p inBufs->planeDesc[1].buf %p", inBufs->planeDesc[0].buf, inBufs->planeDesc[1].buf);
@@ -1242,95 +1561,28 @@ int main(int argc, char * *argv)
1242 in_cnt++; 1561 in_cnt++;
1243 1562
1244 /* 1563 /*
1245 * Input buffer has data to be encoded. 1564 * Input buffer has data to be encoded.
1246 */ 1565 */
1247 inArgs->inputID = (XDAS_Int32)buf; 1566 inArgs->inputID = (XDAS_Int32)buf;
1248 if( codec_switch == DCE_ENC_TEST_H264 ) { 1567 if( codec_switch == DCE_ENC_TEST_H264 ) {
1249 h264enc_inArgs = (IH264ENC_InArgs *) inArgs; 1568 h264enc_inArgs = (IH264ENC_InArgs *) inArgs;
1250 DEBUG("TEST inArgs->inputID %d h264enc_inArgs->videnc2InArgs.inputID %d", inArgs->inputID, h264enc_inArgs->videnc2InArgs.inputID); 1569 DEBUG("inArgs->inputID 0x%x h264enc_inArgs->videnc2InArgs.inputID %d", inArgs->inputID, h264enc_inArgs->videnc2InArgs.inputID);
1251 } else if( (codec_switch == DCE_ENC_TEST_MPEG4) || (codec_switch == DCE_ENC_TEST_H263) ) { 1570 } else if( (codec_switch == DCE_ENC_TEST_MPEG4) || (codec_switch == DCE_ENC_TEST_H263) ) {
1252 mpeg4enc_inArgs = (IMPEG4ENC_InArgs *) inArgs; 1571 mpeg4enc_inArgs = (IMPEG4ENC_InArgs *) inArgs;
1253 DEBUG("TEST inArgs->inputID %d mpeg4enc_inArgs->videnc2InArgs.inputID %d", inArgs->inputID, mpeg4enc_inArgs->videnc2InArgs.inputID); 1572 DEBUG("inArgs->inputID 0x%x mpeg4enc_inArgs->videnc2InArgs.inputID %d", inArgs->inputID, mpeg4enc_inArgs->videnc2InArgs.inputID);
1254 } 1573 }
1255 } else if( n == -1 ) { 1574 } else if( (n == -1) && (endOfFile) ) {
1256 1575
1257 // Set EOF as 1 to ensure flush completes
1258 eof = 1;
1259 in_cnt++; 1576 in_cnt++;
1260 1577
1261 DEBUG("n == -1 - go to shutdown"); 1578 DEBUG("n == -1 and IT IS EOF - go to shutdown");
1262
1263 goto shutdown; 1579 goto shutdown;
1264
1265 switch( codec_switch ) {
1266 case DCE_ENC_TEST_H264 :
1267 DEBUG("Calling VIDENC2_control XDM_FLUSH h264enc_dynParams %p h264enc_status %p", h264enc_dynParams, h264enc_status);
1268 err = VIDENC2_control(codec, XDM_FLUSH, (VIDENC2_DynamicParams *) h264enc_dynParams, (VIDENC2_Status *) h264enc_status);
1269 break;
1270 case DCE_ENC_TEST_MPEG4 :
1271 case DCE_ENC_TEST_H263 :
1272 DEBUG("Calling VIDENC2_control XDM_FLUSH mpeg4enc_dynParams %p mpeg4enc_status %p", mpeg4enc_dynParams, mpeg4enc_status);
1273 err = VIDENC2_control(codec, XDM_FLUSH, (VIDENC2_DynamicParams *) mpeg4enc_dynParams, (VIDENC2_Status *) mpeg4enc_status);
1274 break;
1275 default :
1276 ERROR("Unrecognized codec to encode");
1277 }
1278
1279 /* We have sent the XDM_FLUSH, call VIDENC2_process until we get
1280 * an error of XDM_EFAIL which tells us there are no more buffers
1281 * at codec level.
1282 */
1283
1284 inArgs->inputID = 0;
1285 if( codec_switch == DCE_ENC_TEST_H264 ) {
1286 h264enc_inArgs = (IH264ENC_InArgs *) inArgs;
1287 } else if( (codec_switch == DCE_ENC_TEST_MPEG4) || (codec_switch == DCE_ENC_TEST_H263) ) {
1288 mpeg4enc_inArgs = (IMPEG4ENC_InArgs *) inArgs;
1289 }
1290 inBufs->planeDesc[0].buf = NULL;
1291 inBufs->planeDesc[0].bufSize.bytes = 0;
1292 inBufs->planeDesc[1].buf = NULL;
1293 inBufs->planeDesc[1].bufSize.bytes = 0;
1294 outBufs->descs[0].buf = NULL;
1295 outBufs->descs[1].buf = NULL;
1296 } else { 1580 } else {
1297 /* end of input.. (n == 0) */ 1581 /* end of input.. (n == 0) */
1298 inBufs->numPlanes = 0; 1582 inBufs->numPlanes = 0;
1299 eof = 1; 1583 DEBUG("n == 0 and NOT slice mode - go to shutdown");
1300 DEBUG("n == 0 - go to shutdown");
1301 1584
1302 goto shutdown; 1585 goto shutdown;
1303
1304 switch( codec_switch ) {
1305 case DCE_ENC_TEST_H264 :
1306 DEBUG("Calling VIDENC2_control XDM_FLUSH h264enc_dynParams %p h264enc_status %p", h264enc_dynParams, h264enc_status);
1307 err = VIDENC2_control(codec, XDM_FLUSH, (VIDENC2_DynamicParams *) h264enc_dynParams, (VIDENC2_Status *) h264enc_status);
1308 break;
1309 case DCE_ENC_TEST_MPEG4 :
1310 case DCE_ENC_TEST_H263 :
1311 DEBUG("Calling VIDENC2_control XDM_FLUSH mpeg4enc_dynParams %p mpeg4enc_status %p", mpeg4enc_dynParams, mpeg4enc_status);
1312 err = VIDENC2_control(codec, XDM_FLUSH, (VIDENC2_DynamicParams *) mpeg4enc_dynParams, (VIDENC2_Status *) mpeg4enc_status);
1313 break;
1314 default :
1315 ERROR("Unrecognized codec to encode");
1316 }
1317
1318 /* We have sent the XDM_FLUSH, call VIDENC2_process until we get
1319 * an error of XDM_EFAIL which tells us there are no more buffers
1320 * at codec level.
1321 */
1322
1323 inArgs->inputID = 0;
1324 if( codec_switch == DCE_ENC_TEST_H264 ) {
1325 h264enc_inArgs = (IH264ENC_InArgs *) inArgs;
1326 } else if( (codec_switch == DCE_ENC_TEST_MPEG4) || (codec_switch == DCE_ENC_TEST_H263) ) {
1327 mpeg4enc_inArgs = (IMPEG4ENC_InArgs *) inArgs;
1328 }
1329 inBufs->planeDesc[0].buf = NULL;
1330 inBufs->planeDesc[0].bufSize.bytes = 0;
1331 inBufs->planeDesc[1].buf = NULL;
1332 inBufs->planeDesc[1].bufSize.bytes = 0;
1333 outBufs->descs[0].buf = NULL;
1334 } 1586 }
1335 1587
1336#ifdef DUMPINPUTDATA 1588#ifdef DUMPINPUTDATA
@@ -1338,14 +1590,12 @@ int main(int argc, char * *argv)
1338 1590
1339 //Dump the file 1591 //Dump the file
1340 if( inputDump == NULL ) { 1592 if( inputDump == NULL ) {
1341
1342 if( GlobalCount1 <= 50 ) { 1593 if( GlobalCount1 <= 50 ) {
1343 DEBUG("[DCE_ENC_TEST] GlobalCount1 %d\n", GlobalCount1); 1594 sprintf(Buff1, "/tmp/dceinputdump%d.bin", GlobalCount1);
1344 sprintf(Buff1, "/sd/dce_enc_dump/dceinputdump%d.bin", GlobalCount1);
1345 inputDump = fopen(Buff1, "wb+"); 1595 inputDump = fopen(Buff1, "wb+");
1346 //DEBUG("input data dump file open %p errno %d", inputDump, errno); 1596 //DEBUG("input data dump file open %p errno %d", inputDump, errno);
1347 if( inputDump == NULL ) { 1597 if( inputDump == NULL ) {
1348 DEBUG("Opening input Dump /sd/dce_enc_dump/dceinputdump.bin file FAILED"); 1598 DEBUG("Opening input Dump /tmp/dceinputdump%d.bin file FAILED", GlobalCount1);
1349 } else { 1599 } else {
1350 GlobalCount1++; 1600 GlobalCount1++;
1351 //DEBUG("Before Input [%p]\n", input); 1601 //DEBUG("Before Input [%p]\n", input);
@@ -1357,11 +1607,11 @@ int main(int argc, char * *argv)
1357 inputDump = NULL; 1607 inputDump = NULL;
1358 } 1608 }
1359 } 1609 }
1360 //DEBUG("input data dump file open %p Successful", inputDump);
1361 } 1610 }
1362#endif 1611#endif
1363 1612
1364 int iters = 0; 1613 int iters = 0;
1614 int i = 0;
1365 1615
1366 do { 1616 do {
1367 1617
@@ -1384,13 +1634,20 @@ int main(int argc, char * *argv)
1384 codec_process_time = mark_microsecond(NULL); 1634 codec_process_time = mark_microsecond(NULL);
1385#endif 1635#endif
1386 1636
1637 if (datamode == IVIDEO_NUMROWS) {
1638 dest_y_offset = 0;
1639 if(tiler) {
1640 dest_uv_offset = 4096 * height;
1641 } else {
1642 dest_uv_offset = width * height;
1643 }
1644 }
1645
1387 if( codec_switch == DCE_ENC_TEST_H264 ) { 1646 if( codec_switch == DCE_ENC_TEST_H264 ) {
1388 err = VIDENC2_process(codec, inBufs, outBufs, (VIDENC2_InArgs *) h264enc_inArgs, (VIDENC2_OutArgs *) h264enc_outArgs); 1647 err = VIDENC2_process(codec, inBufs, outBufs, (VIDENC2_InArgs *) h264enc_inArgs, (VIDENC2_OutArgs *) h264enc_outArgs);
1389 DEBUG("[DCE_ENC_TEST] VIDENC2_process - err %d", err); 1648 DEBUG("[DCE_ENC_TEST] VIDENC2_process - err %d", err);
1390 1649
1391 if( err == DCE_EXDM_FAIL ) { 1650 if( err == DCE_EXDM_FAIL ) {
1392 int i = 0;
1393
1394 for( i=0; i < IH264ENC_EXTERROR_NUM_MAXWORDS; i++ ) { 1651 for( i=0; i < IH264ENC_EXTERROR_NUM_MAXWORDS; i++ ) {
1395 DEBUG("DETAIL EXTENDED ERROR h264enc_outArgs->extErrorCode[%d]=%08x", i, (uint)h264enc_outArgs->extErrorCode[i]); 1652 DEBUG("DETAIL EXTENDED ERROR h264enc_outArgs->extErrorCode[%d]=%08x", i, (uint)h264enc_outArgs->extErrorCode[i]);
1396 } 1653 }
@@ -1407,7 +1664,7 @@ int main(int argc, char * *argv)
1407 ERROR("extendedError: %08x", h264enc_outArgs->videnc2OutArgs.extendedError); 1664 ERROR("extendedError: %08x", h264enc_outArgs->videnc2OutArgs.extendedError);
1408 ERROR("DCE_ENCODE_TEST_FAIL: CODEC FATAL ERROR"); 1665 ERROR("DCE_ENCODE_TEST_FAIL: CODEC FATAL ERROR");
1409 goto shutdown; 1666 goto shutdown;
1410 } else if( eof ) { 1667 } else if( endOfFile ) {
1411 ERROR("Codec_process returned err=%d, extendedError=%08x", err, h264enc_outArgs->videnc2OutArgs.extendedError); 1668 ERROR("Codec_process returned err=%d, extendedError=%08x", err, h264enc_outArgs->videnc2OutArgs.extendedError);
1412 DEBUG("-------------------- Flush completed------------------------"); 1669 DEBUG("-------------------- Flush completed------------------------");
1413 } else { 1670 } else {
@@ -1434,7 +1691,7 @@ int main(int argc, char * *argv)
1434 ERROR("extendedError: %08x", mpeg4enc_outArgs->videnc2OutArgs.extendedError); 1691 ERROR("extendedError: %08x", mpeg4enc_outArgs->videnc2OutArgs.extendedError);
1435 ERROR("DCE_ENCODE_TEST_FAIL: CODEC FATAL ERROR"); 1692 ERROR("DCE_ENCODE_TEST_FAIL: CODEC FATAL ERROR");
1436 goto shutdown; 1693 goto shutdown;
1437 } else if( eof ) { 1694 } else if( endOfFile ) {
1438 ERROR("Codec_process returned err=%d, extendedError=%08x", err, mpeg4enc_outArgs->videnc2OutArgs.extendedError); 1695 ERROR("Codec_process returned err=%d, extendedError=%08x", err, mpeg4enc_outArgs->videnc2OutArgs.extendedError);
1439 DEBUG("-------------------- Flush completed------------------------"); 1696 DEBUG("-------------------- Flush completed------------------------");
1440 } else { 1697 } else {
@@ -1479,11 +1736,11 @@ int main(int argc, char * *argv)
1479 if( outputDump == NULL ) { 1736 if( outputDump == NULL ) {
1480 if( GlobalCount2 <= 50 ) { 1737 if( GlobalCount2 <= 50 ) {
1481 DEBUG("DCE_ENC_TEST GlobalCount2 %d\n", GlobalCount2); 1738 DEBUG("DCE_ENC_TEST GlobalCount2 %d\n", GlobalCount2);
1482 sprintf(Buff2, "/sd/dce_enc_dump/dceoutputdump%d.bin", GlobalCount2); 1739 sprintf(Buff2, "/tmp/dceoutputdump%d.bin", GlobalCount2);
1483 outputDump = fopen(Buff2, "wb+"); 1740 outputDump = fopen(Buff2, "wb+");
1484 //DEBUG("output data dump file open %p errno %d", outputDump, errno); 1741 //DEBUG("output data dump file open %p errno %d", outputDump, errno);
1485 if( outputDump == NULL ) { 1742 if( outputDump == NULL ) {
1486 DEBUG("Opening output Dump /sd/dce_enc_dump/dceoutputdump.bin file FAILED"); 1743 DEBUG("Opening output Dump /tmp/dceoutputdump%d.bin file FAILED", GlobalCount2);
1487 } else { 1744 } else {
1488 GlobalCount2++; 1745 GlobalCount2++;
1489 fwrite(output, 1, bytesGenerated, outputDump); 1746 fwrite(output, 1, bytesGenerated, outputDump);
@@ -1504,15 +1761,34 @@ int main(int argc, char * *argv)
1504 } 1761 }
1505 } 1762 }
1506 1763
1764 for( i=0; outArgs->freeBufID[i]; i++ ) {
1765 DEBUG("freeBufID[%d] = %d", i, outArgs->freeBufID[i]);
1766 buf = (InputBuffer *)outArgs->freeBufID[i];
1767 input_release(buf);
1768 }
1769
1507 ++iters; // Guard for infinite VIDENC2_PROCESS loop when codec never return XDM_EFAIL 1770 ++iters; // Guard for infinite VIDENC2_PROCESS loop when codec never return XDM_EFAIL
1508 } while( eof && (err != XDM_EFAIL) && (iters < 100)); // Multiple VIDENC2_process when eof until err == XDM_EFAIL 1771 } while( endOfFile && (err != XDM_EFAIL) && (iters < 100)); // Multiple VIDENC2_process when endOfFile until err == XDM_EFAIL
1509 1772
1773 if (datamode == IVIDEO_NUMROWS) {
1774 // Reset to the next frame; when VIDENC2_process return; 1 input frame should be encoded.
1775 if( tiler ) {
1776 input_y_offset += (4096 * height/2);
1777 input_uv_offset += (4096 * height);
1778 } else {
1779 input_y_offset += (width * height/2);
1780 input_uv_offset += (width * height);
1781 }
1782 DEBUG("input_y_offset %d input_uv_offset %d", input_y_offset, input_uv_offset);
1783 }
1510 } 1784 }
1511 1785
1512shutdown: 1786shutdown:
1513 1787
1514 printf("\nDeleting encoder codec...\n"); 1788 printf("\nDeleting encoder codec 0x%x...\n", (unsigned int) codec);
1515 VIDENC2_delete(codec); 1789 if( codec ) {
1790 VIDENC2_delete(codec);
1791 }
1516 1792
1517out: 1793out:
1518 if( engine ) { 1794 if( engine ) {
@@ -1562,19 +1838,9 @@ out:
1562 } 1838 }
1563 } 1839 }
1564 1840
1565 printf("\nFreeing buf %p...\n", buf); 1841 printf("\nFreeing input...\n");
1566 if( buf ) { 1842 input_free();
1567 if( buf->buf ) { 1843
1568 if( tiler ) {
1569 printf("\nFreeing buf->buf %p...\n", buf->buf);
1570 MemMgr_Free(buf->buf);
1571 } else {
1572 printf("\nFreeing input_nonTiler %p...\n", &input_nonTiler);
1573 free_nonTiler(&input_nonTiler);
1574 }
1575 }
1576 free(buf);
1577 }
1578 printf("DCE ENC test completed...\n"); 1844 printf("DCE ENC test completed...\n");
1579 1845
1580 return (0); 1846 return (0);
diff --git a/test_qnx/dce_enc_test/dce_enc_test.use b/test_qnx/dce_enc_test/dce_enc_test.use
index aadf40a..92d543a 100644
--- a/test_qnx/dce_enc_test/dce_enc_test.use
+++ b/test_qnx/dce_enc_test/dce_enc_test.use
@@ -39,9 +39,9 @@ Options:
39 39
40Examples: 40Examples:
411. Encoding h.264 411. Encoding h.264
42 dce_enc_test width height inpattern outpattern codec profile level 42 dce_enc_test width height inpattern outpattern codec profile level buffertype mode
43 example to encode H.264 QCIF with Profile baseline and Level 1.0 43 example to encode H.264 QCIF with Profile baseline and Level 1.0; nontiler; full frame.
44 dce_enc_test 176 144 inputfile.yuv outputfile.h264 h264 baseline 10 44 dce_enc_test 176 144 inputfile.yuv outputfile.h264 h264 baseline 10 nontiler full
45 45
46 Acceptable input value for profile: 46 Acceptable input value for profile:
47 baseline 47 baseline
@@ -65,10 +65,20 @@ Examples:
65 50 - Level 5.0 65 50 - Level 5.0
66 51 - Level 5.1 66 51 - Level 5.1
67 67
68 Acceptable input value for buffertype:
69 tiler (beware of ERRATA i878)
70 nontiler
71
72 Acceptable input value for mode:
73 numrow
74 slice
75 fixed
76 full
77
682. encoding Mpeg4 782. encoding Mpeg4
69 dce_enc_test width height inpattern outpattern codec profile 0 79 dce_enc_test width height inpattern outpattern codec profile 0 buffertype mode
70 example to encode MPEG4 QCIF with profile simple level 0 80 example to encode MPEG4 QCIF with profile simple level 0; nontiler; full frame.
71 dce_enc_test 176 144 inputfile.yuv outputfile.mpeg4 mpeg4 0 0 81 dce_enc_test 176 144 inputfile.yuv outputfile.mpeg4 mpeg4 0 0 nontiler full
72 82
73 Acceptable input value for profile: 83 Acceptable input value for profile:
74 0 - MPEG4 SIMPLE PROFILE LEVEL 0 84 0 - MPEG4 SIMPLE PROFILE LEVEL 0
@@ -80,10 +90,17 @@ Examples:
80 5 - MPEG4 SIMPLE PROFILE LEVEL 5 90 5 - MPEG4 SIMPLE PROFILE LEVEL 5
81 6 - MPEG4 SIMPLE PROFILE LEVEL 6 91 6 - MPEG4 SIMPLE PROFILE LEVEL 6
82 92
93 Acceptable input value for buffertype:
94 tiler (beware of ERRATA i878)
95 nontiler
96
97 Acceptable input value for mode:
98 full
99
833. Encoding H.263 1003. Encoding H.263
84 dce_enc_test width height inpattern outpattern codec profile 0 101 dce_enc_test width height inpattern outpattern codec profile 0 buffertype mode
85 example to encode H.263 QCIF with profile simple level 0 102 example to encode H.263 QCIF with profile simple level 0; nontiler; full frame.
86 dce_enc_test 176 144 inputfile.yuv outputfile.h263 h263 0 0 103 dce_enc_test 176 144 inputfile.yuv outputfile.h263 h263 0 0 nontiler full
87 104
88 Acceptable input value for profile: 105 Acceptable input value for profile:
89 10 - H.263 BASELINE PROFILE LEVEL 10 106 10 - H.263 BASELINE PROFILE LEVEL 10
@@ -95,4 +112,11 @@ Examples:
95 60 - H.263 BASELINE PROFILE LEVEL 60 112 60 - H.263 BASELINE PROFILE LEVEL 60
96 70 - H.263 BASELINE PROFILE LEVEL 70 113 70 - H.263 BASELINE PROFILE LEVEL 70
97 114
98Currently supported codecs: h264 and mpeg4 115 Acceptable input value for buffertype:
116 tiler (beware of ERRATA i878)
117 nontiler
118
119 Acceptable input value for mode:
120 full
121
122Currently supported codecs: h264, mpeg4 and h263