/* * ======== ceapp_init ======== */ int ceapp_init() { int status = -1; /* nonzero means failure */ /* initialize Codec Engine runtime first */ CERuntime_init(); /* reset, load, and start DSP Engine */ if ((ceHandle = Engine_open(engineName, NULL, NULL)) == NULL) { printf("CEapp-> ERROR: can't open engine %s\n", engineName); goto init_end; } /* activate DSP trace collection thread */ TraceUtil_start(engineName); /* allocate and initialize video encoder on the engine */ encHandle = VIDENC_create(ceHandle, encoderName, NULL); if (encHandle == NULL) { printf("CEapp-> ERROR: can't open codec %s\n", encoderName); goto init_end; } /* allocate and initialize video decoder on the engine */ decHandle = VIDDEC_create(ceHandle, decoderName, NULL); if (decHandle == NULL) { printf("CEapp-> ERROR: can't open codec %s\n", decoderName); goto init_end; } status = 0; /* success */ init_end: return status; }
/* * ======== smain ======== */ Int smain(Int argc, String argv[]) { Engine_Handle ce = NULL; VIDDEC_Handle dec = NULL; VIDENC_Handle enc = NULL; FILE *in = NULL; FILE *out = NULL; String inFile, outFile; Memory_AllocParams allocParams; #if 0 if (argc <= 1) { inFile = "./in.dat"; outFile = "./out.dat"; createInFileIfMissing(inFile); } else if (argc == 3) { progName = argv[0]; inFile = argv[1]; outFile = argv[2]; } else { fprintf(stderr, usage, argv[0]); exit(1); } #endif /*init uart*/ uart_init(fd.uart1); uart_init(fd.uart2); /*thread*/ pthread_t thread1 , thread2; pthread_create(&thread1, NULL , &read_uart1_task, NULL); pthread_create(&thread2, NULL , &read_uart2_task, NULL); GT_0trace(curMask, GT_1CLASS, "App-> Application started.\n"); /* allocate input, encoded, and output buffers */ allocParams.type = Memory_CONTIGPOOL; allocParams.flags = Memory_NONCACHED; allocParams.align = BUFALIGN; allocParams.seg = 0; inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams); encodedBuf = (XDAS_Int8 *)Memory_alloc(EFRAMESIZE, &allocParams); outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams); if ((inBuf == NULL) || (encodedBuf == NULL) || (outBuf == NULL)) { goto end; } /* open file streams for input and output */ if ((in = fopen(inFile, "rb")) == NULL) { printf("App-> ERROR: can't read file %s\n", inFile); goto end; } if ((out = fopen(outFile, "wb")) == NULL) { printf("App-> ERROR: can't write to file %s\n", outFile); goto end; } /* reset, load, and start DSP Engine */ if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) { fprintf(stderr, "%s: error: can't open engine %s\n", progName, engineName); goto end; } /* allocate and initialize video decoder on the engine */ dec = VIDDEC_create(ce, decoderName, NULL); if (dec == NULL) { printf( "App-> ERROR: can't open codec %s\n", decoderName); goto end; } /* allocate and initialize video encoder on the engine */ enc = VIDENC_create(ce, encoderName, NULL); if (enc == NULL) { fprintf(stderr, "%s: error: can't open codec %s\n", progName, encoderName); goto end; } /* use engine to encode, then decode the data */ encode_decode(enc, dec, in, out); end: /* teardown the codecs */ if (enc) { VIDENC_delete(enc); } if (dec) { VIDDEC_delete(dec); } /* close the engine */ if (ce) { Engine_close(ce); } /* close the files */ if (in) { fclose(in); } if (out) { fclose(out); } /* free buffers */ if (inBuf) { Memory_free(inBuf, IFRAMESIZE, &allocParams); } if (encodedBuf) { Memory_free(encodedBuf, EFRAMESIZE, &allocParams); } if (outBuf) { Memory_free(outBuf, OFRAMESIZE, &allocParams); } GT_0trace(curMask, GT_1CLASS, "app done.\n"); return (0); }