/* * ======== 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[]) { Char newTraceMask[MAXTRACESTRING]; Server_Handle server = NULL; Bool finished = FALSE; Uns mode = PULLTRACE; Server_Status status; Int traceToken; String mask; Uns rate; /* interpret PULLTRACE mode args */ if (argc == 3) { rate = atoi(argv[1]); mask = argv[2]; } /* else, if no args, set mode to TRACEUTIL */ else if (argc == 1) { mode = TRACEUTIL; } /* else, show usage */ else { fprintf(stderr, usage, argv[0]); goto done; } /* reset, load, and start DSP Engine */ if ((engine = Engine_open(engineName, NULL, NULL)) == NULL) { fprintf(stderr, "Error: can't open engine %s!\n", engineName); goto done; } /* setup file descriptor mask for checking for user key input */ FD_ZERO(&fdMask); FD_SET(STDIN_FILENO, &fdMask); /* if standard output mode... */ if (mode == PULLTRACE) { printf("Trace polling rate: %d msec\n", rate); rate *= 1000; printf("DSP trace mask: %s\n", mask); /* get server handle */ server = Engine_getServer(engine); if (server == NULL) { fprintf(stderr, "Error: can't get server handle!\n"); goto closeEngine; } /* connect for server trace data */ status = Server_connectTrace(server, &traceToken); if (status == Server_EINUSE) { fprintf(stderr, "Error: server trace already in use by another process!\n"); goto closeEngine; } else if (status != Server_EOK) { fprintf(stderr, "Error: server connect failed, status = 0x%x!\n", status); goto closeEngine; } /* server trace mask */ status = Server_setTrace(server, mask); if (status != (Int) Engine_EOK) { fprintf(stderr, "Error: unable to set trace mask, status = 0x%x!\n", status); goto closeEngine; } printf("Hit <Enter> to exit, or, new trace mask and then <Enter>...\n"); while (finished == FALSE) { dumpTrace(server); usleep(rate); if (checkInput(newTraceMask) == TRUE) { if (strlen(newTraceMask) == 0) { finished = TRUE; } else { printf("setting new trace mask: %s\n", newTraceMask); status = Server_setTrace(server, newTraceMask); if (status != (Int) Engine_EOK) { fprintf(stderr, "Error updating trace mask, status = 0x%x!\n", status); } } } }; /* discconnect from server trace data */ status = Server_disconnectTrace(server, traceToken); if (status != Server_EOK) { fprintf(stderr, "Error: unable to disconnect from server trace, status = 0x%x!\n", status); } } /* else, startup TraceUtil to retrieve trace/LOG data and write to files */ else { TraceUtil_start(engineName); printf("Started TraceUtil thread\nHit <Enter> to exit...\n"); getchar(); TraceUtil_stop(); } printf("Done.\n"); closeEngine: /* close the engine */ if (engine) { Engine_close(engine); } done: return (0); }