예제 #1
0
/**
 *  @brief      The BIOS main() entry point.
 *
 *  @remark     The purpose of this function is to create a BIOS worker task
 *              to house our example.
 *
 *  @remark     This is called during BIOS_init, but before the scheduler
 *              has begun running.
 */
Int main(Int argc, String argv[])
{
    TSK_Attrs attrs = TSK_ATTRS;
    attrs.stacksize = 6 * 1024;
    attrs.name = taskName;

    /* init Codec Engine */
    CERuntime_init();

    /* init trace */
    GT_init();

    /* create a mask to allow a trace-print welcome message below */
    GT_create(&curMask, MOD_NAME);

    /* Enable all trace for this module */
    GT_set(MOD_NAME "=01234567");

    GT_0trace(curMask, GT_2CLASS, "main> " MOD_NAME "\n");

    if (TSK_create((Fxn)smain, &attrs, argc, argv) == NULL) {
        SYS_abort("main: failed to create smain thread.");
    }

    return (0);
}
예제 #2
0
/*
 *  ======== main ========
 */
Void main(Int argc, Char *argv[])
{
    /* init Codec Engine */
    CERuntime_init();

    /* init trace */
    GT_init();

    /* create a mask to allow a trace-print welcome message below */
    GT_create(&gtMask, "audio1_ires_server");

    /* ...and initialize all masks in this module to "on" */
    GT_set("audio1_ires_server=01234567");

    GT_0trace(gtMask, GT_4CLASS, "main> Welcome to DSP server's main().\n");

    /* Configure and register BUFRES resource with RMAN */

    /*
     * Note that we can't use RMAN's auto-register with the BUFRES resource
     * because it takes runtime config params that don't have logical
     * defaults.
     */
    config.iresConfig.size = sizeof(BUFRES_Params);
    config.iresConfig.allocFxn = DSKT2_allocPersistent;
    config.iresConfig.freeFxn = DSKT2_freePersistent;

    config.base = (Void *)&BUFMEM_base;
    config.length = (UInt32)&BUFMEM_end - (UInt32)&BUFMEM_base + 1;

    RMAN_register(&BUFRES_MGRFXNS, (IRESMAN_Params *)&config);
}
예제 #3
0
/*
 *  ======== main ========
 */
Void main(Int argc, Char *argv[])
{
    Int status;

    do {
        /* init IPC */
        status = Ipc_start();
    } while (status < 0);

    /* init Codec Engine */
    CERuntime_init();


    Log_print0(Diags_USER4, "[+4] main> Welcome to DSP server's main().");

    /* Configure and register BUFRES resource with RMAN */
    config.iresConfig.size = sizeof(BUFRES_Params);
    config.iresConfig.allocFxn = DSKT2_allocPersistent;
    config.iresConfig.freeFxn = DSKT2_freePersistent;

    config.base = Memory_alloc(BUFSIZE, NULL);
    config.length = BUFSIZE;

    RMAN_register(&BUFRES_MGRFXNS, (IRESMAN_Params *)&config);

    BIOS_start();
}
예제 #4
0
파일: ce.c 프로젝트: guyz/dsp
static int ce_open(const char *name, AVCodecContext *cc,
                    struct frame_format *ff)
{
    char decName[16];

    switch (cc->codec_id) {
	case CODEC_ID_H264:
	     codecModule = &h264_codec;
	     strcpy(decName, "h264dec");
	     break;
	case CODEC_ID_MPEG4:
	     codecModule = &mpeg4_codec;
	     strcpy(decName, "mpeg4dec");
	     break;
	default:
             fprintf(stderr, "ERROR: unsupported CE codec %d\n", cc->codec_id);
             return -1;
    }

    /* init Codec Engine */
    CERuntime_init();

    if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) {
        fprintf(stderr, "ERROR: can't open engine ceEngine\n");
        return -1;
    }

    // Debug
    GT_set(Memory_GTNAME "+5");

    return codecModule->open(decName, cc, ff);
}
예제 #5
0
DvevmStRetCode
dvtb_ceRuntimeInit(DvevmStEngineInfo *ce)
{
	CERuntime_init( );
	SYS_DEBUG("Codec Engine Runtime initialized\n");
	return DVEVM_ST_SUCCESS;
}
예제 #6
0
/* Register of all the elements of the plugin */
static gboolean
TIPlugin_init (GstPlugin * plugin)
{

  gboolean ret;
  GST_DEBUG_CATEGORY_INIT (tiplugin, "ti", 0,
      "TI plugin for CodecEngine debugging");

  /* Init the CMEM allocator */
  gst_cmem_allocator_initialize ();

  /* Init the CMEM meta data */
  gst_cmem_meta_register ();

  /* Initialize the codec engine run time */
  CERuntime_init ();

  /* Register the encoders */
  ret =
      gst_element_register (plugin, "ceenc_h264", GST_RANK_PRIMARY,
      GST_TYPE_CE_H264_ENCODER);
  if (!ret) {
    g_warning ("Failed to register h264 encoder element");
  }

  ret =
      gst_element_register (plugin, "ceenc_mpeg4", GST_RANK_PRIMARY,
      GST_TYPE_CE_MPEG4_ENCODER);
  if (!ret) {
    g_warning ("Failed to register mpeg4 encoder element");
  }

  return ret;
}
예제 #7
0
int codecEngineInit(bool _verbose)
{
  CERuntime_init(); /* init Codec Engine */

  if (_verbose)
  {
    Diags_setMask("xdc.runtime.Main+EX1234567");
    Diags_setMask(Engine_MODNAME"+EX1234567");
  }

  return 0;
}
예제 #8
0
/*
 *  ======== main ========
 */
Int main(Int argc, String argv[])
{
    CERuntime_init();

    GT_create(&curMask, "ZZ");

    /* Enable all trace for this "ZZ" module */
    GT_set("ZZ=01234567");

    GT_0trace(curMask, GT_2CLASS, "main> Welcome to app's main().\n");

    return (smain(argc, argv));
}
예제 #9
0
int main()
{
    CERuntime_init();
    CMEM_init();

#ifdef CE_TEST
    CERuntime_init();
    CERuntime_exit();
    CERuntime_init();
    CERuntime_exit();
#endif

    /* initialize libavcodec, and register all codecs and formats */
    av_register_all();

    /* TODO: can't run both yet, some problem with CE init and exit */
    ff_example("test.avi", "avi");
//    decode_example("test.mkv");

    CMEM_exit();
    CERuntime_exit();
    return 0;
}
예제 #10
0
/* entry point to initialize the plug-in
 * initialize the plug-in itself
 * register the element factories and other features
 */
static gboolean
TICodecPlugin_init (GstPlugin * TICodecPlugin)
{
    /* Initialize the codec engine run time */
    CERuntime_init();

    /* Initialize DMAI */
    Dmai_init();
    
    if (!probe_codec_server_decoders (TICodecPlugin)) {
        return FALSE;
    }

    if (!probe_codec_server_encoders (TICodecPlugin)) {
        return FALSE;
    }

    if (!gst_element_register(TICodecPlugin, "dmaiaccel",
        GST_RANK_PRIMARY,GST_TYPE_TIDMAIACCEL))
        return FALSE;

    if (!gst_element_register(TICodecPlugin, "priority",
        GST_RANK_PRIMARY,GST_TYPE_TIPRIORITY))
        return FALSE;

    if (!gst_element_register(TICodecPlugin, "dmaiperf",
        GST_RANK_PRIMARY,GST_TYPE_DMAIPERF))
        return FALSE;

    if (!gst_element_register(TICodecPlugin, "TIDmaiVideoSink",
        GST_RANK_PRIMARY,GST_TYPE_TIDMAIVIDEOSINK))
        return FALSE;

    if (!gst_element_register(TICodecPlugin, "dmairesizer",
        GST_RANK_PRIMARY,GST_TYPE_DMAI_RESIZER))
        return FALSE;

    if (!gst_element_register(TICodecPlugin, "dmaidualenc_h264",
        GST_RANK_PRIMARY,GST_TYPE_TI_DMAI_H264_DUALENCODER)) 
        return FALSE;

    /*
    if (!gst_element_register(TICodecPlugin, "dm365facedetect",
        GST_RANK_PRIMARY,GST_TYPE_DM365_FACEDETECT))
        return FALSE;
    */

    return TRUE;
}
예제 #11
0
/*
 *  ======== main ========
 */
Void main(Int argc, Char *argv[])
{
    /* init Codec Engine */
    CERuntime_init();

    /* init trace */
    GT_init();

    /* create a mask to allow a trace-print welcome message below */
    GT_create(&gtMask, "ti.sdo.ce.examples.servers.all_codecs");

    /* ...and initialize all masks in this module to "on" */
    GT_set("ti.sdo.ce.examples.servers.all_codecs=01234567");

    GT_0trace(gtMask, GT_4CLASS, "main> Welcome to DSP server's main().\n");
}
예제 #12
0
파일: main_native.c 프로젝트: sv99/DVSDK
/*
 *  ======== main ========
 */
Int main(Int argc, String argv[])
{
#ifdef LOCAL
    BUFRES_Params  config;
    IRES_Status     status;
#endif

    /* init Codec Engine */
    CERuntime_init();

    /* init trace */
    GT_init();

    /* create a mask to allow a trace-print welcome message below */
    GT_create(&curMask, MOD_NAME);

    /* Enable all trace for this module */
    GT_set(MOD_NAME "=01234567");

    GT_0trace(curMask, GT_2CLASS, "main> " MOD_NAME "\n");

#ifdef LOCAL
    RMAN_init();

    /*
     *  Configure and register BUFRES resource. This code is used for both
     *  local and remote Linux apps. In the remote case, registering will
     *  not have any affect, since the IRES codec will be run on the DSP.
     *
     *  This particular resource cannot be auto-registered, since it needs
     *  to be configured with a buffer.
     */
    config.iresConfig.size = sizeof(BUFRES_Params);
    config.iresConfig.allocFxn = _ALG_allocMemory;
    config.iresConfig.freeFxn = _ALG_freeMemory;

    config.base = (Void *)buffer;
    config.length = BUFLEN;

    status = RMAN_register(&BUFRES_MGRFXNS, (IRESMAN_Params *)&config);
    GT_1trace(curMask, GT_2CLASS, "main>  RMAN_register returned 0x%x\n",
              (IArg)status);
#endif
    return (smain(argc, argv));
}
/**
 *  @brief      The main() entry point.
 */
Int main(Int argc, String argv[])
{
    /* init Codec Engine */
    CERuntime_init();

    /* init trace */
    GT_init();

    /* create a mask to allow a trace-print welcome message below */
    GT_create(&curMask, MOD_NAME);

    /* Enable all trace for this module */
    GT_set(MOD_NAME "=01234567");

    GT_0trace(curMask, GT_2CLASS, "main> " MOD_NAME "\n");

    return (smain(argc, argv));
}
예제 #14
0
/**
 *  @brief      The BIOS main() entry point.
 *
 *  @remark     The purpose of this function is to create a BIOS worker task
 *              to house our example.
 *
 *  @remark     This is called during BIOS_init, but before the scheduler
 *              has begun running.
 */
Void main(Int argc, String argv[])
{
    Thread_Params threadParams;

    /* init Codec Engine */
    CERuntime_init();

    /* Enable all trace for xdc.runtime.Main */
    Diags_setMask("xdc.runtime.Main+EX1234567");

    Log_print0(Diags_USER2, "[+2] main> ti.sdo.ce.examples.apps.image_copy");

    Thread_Params_init(&threadParams);
    threadParams.stackSize = 6 * 1024;
    threadParams.instance->name = taskName;

    if (Thread_create(workerFxn, &threadParams, NULL) == NULL) {
        System_abort("main: failed to create smain thread.");
    }

    BIOS_start();
}
예제 #15
0
/**
 *  @brief      The BIOS main() entry point.
 *
 *  @remark     The purpose of this function is to create a BIOS worker task
 *              to house our example.
 *
 *  @remark     This is called during BIOS_init, but before the scheduler
 *              has begun running.
 */
Void main(Int argc, String argv[])
{
    Thread_Params threadParams;

    /* init Codec Engine */
    CERuntime_init();

    /* Enable all trace for this module */
    Diags_setMask("xdc.runtime.Main+EX012345678");

    Log_print0(Diags_USER2, "[+2] main> Welcome to app's main().");

    Thread_Params_init(&threadParams);
    threadParams.stackSize = 6 * 1024;
    threadParams.instance->name = taskName;

    if (Thread_create(workerFxn, &threadParams, NULL) == NULL) {
        System_abort("main: failed to create smain thread.");
    }

    BIOS_start();
}
예제 #16
0
/*
 *  ======== 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;
}
예제 #17
0
파일: main.c 프로젝트: aCayF/encode
/******************************************************************************
 * main
 ******************************************************************************/
Int main(Int argc, Char *argv[])
{
    Args                args                = DEFAULT_ARGS;
    Uns                 initMask            = 0;
    Int                 status              = EXIT_SUCCESS;
    Pause_Attrs         pAttrs              = Pause_Attrs_DEFAULT;
    Rendezvous_Attrs    rzvAttrs            = Rendezvous_Attrs_DEFAULT;
    Fifo_Attrs          fAttrs              = Fifo_Attrs_DEFAULT;
    Rendezvous_Handle   hRendezvousCapStd   = NULL;
    Rendezvous_Handle   hRendezvousInit     = NULL;
    Rendezvous_Handle   hRendezvousWriter   = NULL;
    Rendezvous_Handle   hRendezvousCleanup  = NULL;
    Pause_Handle        hPauseProcess       = NULL;
    UI_Handle           hUI                 = NULL;
    struct sched_param  schedParam;
    pthread_t           captureThread;
    pthread_t           writerThread;
    pthread_t           videoThread;
    pthread_t           speechThread;
    CaptureEnv          captureEnv;
    WriterEnv           writerEnv;
    VideoEnv            videoEnv;
    SpeechEnv           speechEnv;
    CtrlEnv             ctrlEnv;
    Int                 numThreads;
    pthread_attr_t      attr;
    Void               *ret;

    /* Zero out the thread environments */
    Dmai_clear(captureEnv);
    Dmai_clear(writerEnv);
    Dmai_clear(videoEnv);
    Dmai_clear(speechEnv);
    Dmai_clear(ctrlEnv);

    /* Parse the arguments given to the app and set the app environment */
    parseArgs(argc, argv, &args);

    printf("Encode demo started.\n");

    /* Initialize the mutex which protects the global data */
    pthread_mutex_init(&gbl.mutex, NULL);

    /* Set the priority of this whole process to max (requires root) */
    setpriority(PRIO_PROCESS, 0, -20);

    /* Initialize Codec Engine runtime */
    CERuntime_init();

    /* Initialize signal handler for SIGINT */
    signal(SIGINT, signalHandler);
    
    /* Initialize Davinci Multimedia Application Interface */
    Dmai_init();

    initMask |= LOGSINITIALIZED;

    /* Set up the user interface */
    hUI = uiSetup(&args);

    if (hUI == NULL) {
        cleanup(EXIT_FAILURE);
    }

    /* Create the Pause object */
    hPauseProcess = Pause_create(&pAttrs);

    if (hPauseProcess == NULL) {
        ERR("Failed to create Pause object\n");
        cleanup(EXIT_FAILURE);
    }

    /* Determine the number of threads needing synchronization */
    numThreads = 1;

    if (args.videoFile) {
        numThreads += 3;
    }

    if (args.speechFile) {
        numThreads += 1;
    }
    /* Create the objects which synchronizes the thread init and cleanup */
    hRendezvousCapStd  = Rendezvous_create(2, &rzvAttrs);
    hRendezvousInit = Rendezvous_create(numThreads, &rzvAttrs);
    hRendezvousCleanup = Rendezvous_create(numThreads, &rzvAttrs);
    hRendezvousWriter = Rendezvous_create(2, &rzvAttrs);

    if (hRendezvousCapStd  == NULL || hRendezvousInit == NULL || 
        hRendezvousCleanup == NULL || hRendezvousWriter == NULL) {
        ERR("Failed to create Rendezvous objects\n");
        cleanup(EXIT_FAILURE);
    }

    /* Initialize the thread attributes */
    if (pthread_attr_init(&attr)) {
        ERR("Failed to initialize thread attrs\n");
        cleanup(EXIT_FAILURE);
    }

    /* Force the thread to use custom scheduling attributes */
    if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) {
        ERR("Failed to set schedule inheritance attribute\n");
        cleanup(EXIT_FAILURE);
    }

    /* Set the thread to be fifo real time scheduled */
    if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) {
        ERR("Failed to set FIFO scheduling policy\n");
        cleanup(EXIT_FAILURE);
    }

    /* Create the video threads if a file name is supplied */
    if (args.videoFile) {
        /* Create the capture fifos */
        captureEnv.hInFifo = Fifo_create(&fAttrs);
        captureEnv.hOutFifo = Fifo_create(&fAttrs);

        if (captureEnv.hInFifo == NULL || captureEnv.hOutFifo == NULL) {
            ERR("Failed to open display fifos\n");
            cleanup(EXIT_FAILURE);
        }

        /* Set the capture thread priority */
        schedParam.sched_priority = CAPTURE_THREAD_PRIORITY;
        if (pthread_attr_setschedparam(&attr, &schedParam)) {
            ERR("Failed to set scheduler parameters\n");
            cleanup(EXIT_FAILURE);
        }

        /* Create the capture thread */
        captureEnv.hRendezvousInit    = hRendezvousInit;
        captureEnv.hRendezvousCapStd  = hRendezvousCapStd;
        captureEnv.hRendezvousCleanup = hRendezvousCleanup;
        captureEnv.hPauseProcess      = hPauseProcess;
        captureEnv.videoStd           = args.videoStd;
        captureEnv.videoInput         = args.videoInput;
        captureEnv.imageWidth         = args.imageWidth;
        captureEnv.imageHeight        = args.imageHeight;
        /* TODO */
        VideoStd_getResolution(VideoStd_CIF, &captureEnv.resizeWidth,
                                             &captureEnv.resizeHeight);

        if (pthread_create(&captureThread, &attr, captureThrFxn, &captureEnv)) {
            ERR("Failed to create capture thread\n");
            cleanup(EXIT_FAILURE);
        }

        initMask |= CAPTURETHREADCREATED;

        /*
         * Once the capture thread has detected the video standard, make it
         * available to other threads. The capture thread will set the
         * resolution of the buffer to encode in the environment (derived
         * from the video standard if the user hasn't passed a resolution).
         */
        Rendezvous_meet(hRendezvousCapStd);

        /* Create the writer fifos */
        writerEnv.hInFifo = Fifo_create(&fAttrs);
        writerEnv.hOutFifo = Fifo_create(&fAttrs);

        if (writerEnv.hInFifo == NULL || writerEnv.hOutFifo == NULL) {
            ERR("Failed to open display fifos\n");
            cleanup(EXIT_FAILURE);
        }

        /* Set the video thread priority */
        schedParam.sched_priority = VIDEO_THREAD_PRIORITY;
        if (pthread_attr_setschedparam(&attr, &schedParam)) {
            ERR("Failed to set scheduler parameters\n");
            cleanup(EXIT_FAILURE);
        }

        /* Create the video thread */
        videoEnv.hRendezvousInit    = hRendezvousInit;
        videoEnv.hRendezvousCleanup = hRendezvousCleanup;
        videoEnv.hRendezvousWriter  = hRendezvousWriter;
        videoEnv.hPauseProcess      = hPauseProcess;
        videoEnv.hCaptureOutFifo    = captureEnv.hOutFifo;
        videoEnv.hCaptureInFifo     = captureEnv.hInFifo;
        videoEnv.hWriterOutFifo     = writerEnv.hOutFifo;
        videoEnv.hWriterInFifo      = writerEnv.hInFifo;
        videoEnv.videoEncoder       = args.videoEncoder->codecName;
        videoEnv.params             = args.videoEncoder->params;
        videoEnv.dynParams          = args.videoEncoder->dynParams;
        videoEnv.videoBitRate       = args.videoBitRate;
        videoEnv.imageWidth         = captureEnv.imageWidth;
        videoEnv.imageHeight        = captureEnv.imageHeight;
        videoEnv.resizeWidth        = captureEnv.resizeWidth;
        videoEnv.resizeHeight       = captureEnv.resizeHeight;
        videoEnv.imgEncoder         = "jpegenc";
        videoEnv.engineName         = engine->engineName;
        if (args.videoStd == VideoStd_D1_PAL) {
            videoEnv.videoFrameRate     = 25000;
        } else {
            videoEnv.videoFrameRate     = 30000;
        }

        if (pthread_create(&videoThread, &attr, videoThrFxn, &videoEnv)) {
            ERR("Failed to create video thread\n");
            cleanup(EXIT_FAILURE);
        }

        initMask |= VIDEOTHREADCREATED;

        /*
         * Wait for the codec to be created in the video thread before
         * launching the writer thread (otherwise we don't know which size
         * of buffers to use).
         */
        Rendezvous_meet(hRendezvousWriter);

        /* Set the writer thread priority */
        schedParam.sched_priority = WRITER_THREAD_PRIORITY;
        if (pthread_attr_setschedparam(&attr, &schedParam)) {
            ERR("Failed to set scheduler parameters\n");
            cleanup(EXIT_FAILURE);
        }

        /* Create the writer thread */
        writerEnv.hRendezvousInit    = hRendezvousInit;
        writerEnv.hRendezvousCleanup = hRendezvousCleanup;
        writerEnv.hPauseProcess      = hPauseProcess;
        writerEnv.videoFile          = args.videoFile;
        writerEnv.outBufSize         = videoEnv.outBufSize;
        writerEnv.outsBufSize        = videoEnv.outsBufSize;

        if (pthread_create(&writerThread, &attr, writerThrFxn, &writerEnv)) {
            ERR("Failed to create writer thread\n");
            cleanup(EXIT_FAILURE);
        }

        initMask |= WRITERTHREADCREATED;

    }

    /* Create the speech thread if a file name is supplied */
    if (args.speechFile) {
        /* Set the thread priority */
        schedParam.sched_priority = SPEECH_THREAD_PRIORITY;
        if (pthread_attr_setschedparam(&attr, &schedParam)) {
            ERR("Failed to set scheduler parameters\n");
            cleanup(EXIT_FAILURE);
        }

        /* Create the speech thread */
        speechEnv.hRendezvousInit    = hRendezvousInit;
        speechEnv.hRendezvousCleanup = hRendezvousCleanup;
        speechEnv.hPauseProcess      = hPauseProcess;
        speechEnv.speechFile         = args.speechFile;
        speechEnv.soundInput         = args.soundInput;
        speechEnv.speechEncoder      = args.speechEncoder->codecName;
        speechEnv.params             = args.speechEncoder->params;
        speechEnv.dynParams          = args.speechEncoder->dynParams;
        speechEnv.engineName         = engine->engineName;

        if (pthread_create(&speechThread, &attr, speechThrFxn, &speechEnv)) {
            ERR("Failed to create speech thread\n");
            cleanup(EXIT_FAILURE);
        }

        initMask |= SPEECHTHREADCREATED;
    }

    /* Main thread becomes the control thread */
    ctrlEnv.hRendezvousInit    = hRendezvousInit;
    ctrlEnv.hRendezvousCleanup = hRendezvousCleanup;
    ctrlEnv.hPauseProcess      = hPauseProcess;
    ctrlEnv.keyboard           = args.keyboard;
    ctrlEnv.time               = args.time;
    ctrlEnv.hUI                = hUI;
    ctrlEnv.engineName         = engine->engineName;

    ret = ctrlThrFxn(&ctrlEnv);

    if (ret == THREAD_FAILURE) {
        status = EXIT_FAILURE;
    }

cleanup:
    /* Make sure the other threads aren't waiting for init to complete */
    if (hRendezvousCapStd) Rendezvous_force(hRendezvousCapStd);
    if (hRendezvousWriter) Rendezvous_force(hRendezvousWriter);
    if (hRendezvousInit) Rendezvous_force(hRendezvousInit);
    if (hPauseProcess) Pause_off(hPauseProcess);

    /* Wait until the other threads terminate */
    if (initMask & SPEECHTHREADCREATED) {
        if (pthread_join(speechThread, &ret) == 0) {
            if (ret == THREAD_FAILURE) {
                status = EXIT_FAILURE;
            }
        }
    }

    if (initMask & VIDEOTHREADCREATED) {
        if (pthread_join(videoThread, &ret) == 0) {
            if (ret == THREAD_FAILURE) {
                status = EXIT_FAILURE;
            }
        }
    }

    if (initMask & WRITERTHREADCREATED) {
        if (pthread_join(writerThread, &ret) == 0) {
            if (ret == THREAD_FAILURE) {
                status = EXIT_FAILURE;
            }
        }
    }

    if (writerEnv.hOutFifo) {
        Fifo_delete(writerEnv.hOutFifo);
    }

    if (writerEnv.hInFifo) {
        Fifo_delete(writerEnv.hInFifo);
    }

    if (initMask & CAPTURETHREADCREATED) {
        if (pthread_join(captureThread, &ret) == 0) {
            if (ret == THREAD_FAILURE) {
                status = EXIT_FAILURE;
            }
        }
    }

    if (captureEnv.hOutFifo) {
        Fifo_delete(captureEnv.hOutFifo);
    }

    if (captureEnv.hInFifo) {
        Fifo_delete(captureEnv.hInFifo);
    }

    if (hRendezvousCleanup) {
        Rendezvous_delete(hRendezvousCleanup);
    }

    if (hRendezvousInit) {
        Rendezvous_delete(hRendezvousInit);
    }

    if (hPauseProcess) {
        Pause_delete(hPauseProcess);
    }

    if (hUI) {
        UI_delete(hUI);
    }

    system("sync");
    system("echo 3 > /proc/sys/vm/drop_caches");


    pthread_mutex_destroy(&gbl.mutex);

    if (args.interface) {
        /* Launch the demo selection interface when exiting */
        if (execl("./interface", "interface", "-l 3", (char *) NULL) == -1) {
            status = EXIT_FAILURE;
        }
    }

    exit(status);
}
예제 #18
0
/*
 *  ======== main ========
 */
Int main(Int argc, String argv[])
{
    String procId;
    String procSuffix;
    String engineName;
    String mapFileName = NULL;
    String inFile;
    String outFile;
    Char defaultEngineName[32];
    Bool useExtLoader = FALSE;  /* Set to TRUE if using external loader */
    Engine_Error status;
    String options = "e:m:p:s:";
    Int option;
    Engine_Desc desc;

    /* Initialize defaults. */
    procId = "DSP";
    procSuffix = "x64P";
    engineName = defaultEngineName;
    sprintf(defaultEngineName, "remote_copy_%s", procId);
    inFile = "./in.dat";
    outFile = "./out.dat";

    while ((option = getopt(argc, argv, options)) != -1) {
        switch (option) {
          case 'e':
            engineName = optarg;

            break;

          case 'm':
              /*
               *  If specifying the slave's memory mapping, then assume that
               *  Codec Engine will be loading the slave.
               */
            mapFileName = optarg;
            useExtLoader = FALSE;

            break;

          case 'p':
            procId = optarg;
            sprintf(defaultEngineName, "remote_copy_%s", procId);

            break;

          case 's':
            procSuffix = optarg;

            break;

          default:
            Log_print1(Diags_USER7, " unrecognized option '%c'\n", option);

            break;
        }
    }

    if (argc == (optind + 1)) {
        inFile = argv[optind];
    }
    else if (argc == (optind + 2)) {
        inFile = argv[optind];
        outFile = argv[optind + 1];
    }
    else if (argc != optind) {
        fprintf(stderr, usage, argv[0]);
        exit(1);
    }

    /* init Codec Engine */
    CERuntime_init();

    /* Enable all trace for this "xdc.runtime.Main" module */
    Diags_setMask("xdc.runtime.Main+EX1234567");

    Log_print0(Diags_USER2, "[+2] main> Welcome to app's main().");

    /*
     *  Set the memory map in the engine's descriptor, and change to use
     *  (or not use) an external loader for loading.  If using an external
     *  loader, then desc.memMap should be set to NULL;
     */
    status = Engine_getDesc(engineName, &desc);
    desc.useExtLoader = useExtLoader;
    desc.memMap = mapFileName;

    status = Engine_setDesc(engineName, &desc);
    if (status != Engine_EOK) {
        Log_print2(Diags_USER6, "[+2] main> Unable to change \'useExtLoader\' "
                "in descriptor for engine %s to %s", (IArg)engineName,
                (IArg)(useExtLoader ? "TRUE" : "FALSE"));
    }

    return (smain(argv[0], procId, engineName, inFile, outFile));
}
예제 #19
0
파일: main.c 프로젝트: Lichanglu/ENC-1260
/*
##############################################
##Int ModuleResize(Int argc, Char *argv[])
##############################################
*/
Int ModuleResize(Int argc, Char *argv[])
{
	Uns                 initMask            = 0;
	Int                 status              = EXIT_SUCCESS;
	Rendezvous_Attrs    rzvAttrs            = Rendezvous_Attrs_DEFAULT;
	Fifo_Attrs          fAttrs              = Fifo_Attrs_DEFAULT;
	Rendezvous_Handle   hRendezvousInit     = NULL;
	Rendezvous_Handle   hRendezvousWriter   = NULL;
	Rendezvous_Handle   hRendezvousCleanup  = NULL;
	Int                 numThreads			= 0;
	pthread_t 			id_listen[5] 		= {0};
	Void               *ret;

	char 				devicebuf[16] 		= {0};

	CaptureEnv          captureEnv;
	WriterEnv           writerEnv;
	WriterEnv			writerLowRateEnv;
	DetectEnv			detectEnv;
	VideoEnv            videoEnv;
	VideoEnv            videoLowRateEnv;//dd
	VideoEnv            LowRateResize;
	AudioEnv            audioEnv;
	CtrlEnv             ctrlEnv;
	char box_version[64] = {0};
	OutputVideoInfo		outputhandle;
	textinfo			*texthandle;
	int 				DHCPVAL = 0, tmp = 0;
	char 				gateway[255] = {0};

	struct sched_param  schedParam;
	pthread_t           captureThread;
	pthread_t           detectThread;
	pthread_t           writerThread;
	pthread_t			writerLowThread;
	pthread_t           videoThread;
	pthread_t           audioThread;
	pthread_t			videoLowThread;
	pthread_t			resizeLowThread;
#ifdef DSS_ENC_1100_1200
	pthread_t           webListenThread;
#endif
	pthread_attr_t      attr;
	int       index = 0;
	int result = 0;
	char ts_version[128] = {0};
	/* Zero out the thread environments */
	Dmai_clear(captureEnv);
	Dmai_clear(writerEnv);
	Dmai_clear(videoEnv);
	Dmai_clear(audioEnv);
	Dmai_clear(ctrlEnv);

	mid_task_init();
	trace_init();
	open_gpio_port();

	ts_build_get_version(ts_version, sizeof(ts_version));

	strcpy(box_version, BOX_VER);
	strcat(box_version, CODE_TYPE);
	strcat(box_version, DEUBG);
	printf("[%s] Module Encode Program %s V%s\n", CODE_COND, BOARD_TYPE, box_version);
	printf("the build time is %s,the git vesion is %s.the ts version is %s\n\n", g_make_build_date, _VERSION, ts_version);

	initMutexPthread();
	InitgblCommonMutex();
	InitSysParams();
	initOutputVideoParam();
	InitHVTable(&gHVTable);
	//	webgetDHCPFlag(tmp, &DHCPVAL);
	//	readDHCPValue(DHCPCONFIG_FILE, &DHCPVAL);
	//	setDHCPFlag(DHCPVAL);
	gLogoinfo = initLogoMod();
	initTextinfo();

	ReadEncodeParamTable(CONFIG_NAME, &gSysParaT);
	DHCPVAL = gSysParaT.sysPara.nTemp[0];
	printf("----mic=%x:%x:%x:%x:%x:%x\n",gSysParaT.sysPara.szMacAddr[0],gSysParaT.sysPara.szMacAddr[1],gSysParaT.sysPara.szMacAddr[2],
			gSysParaT.sysPara.szMacAddr[3],gSysParaT.sysPara.szMacAddr[4],gSysParaT.sysPara.szMacAddr[5]);

	ReadLowbitParamTable(LOWBIT_PARAM, &gSysParaT);

	memset(&outputhandle, 0, sizeof(OutputVideoInfo));
	getOutputvideohandle(&outputhandle);

	readOutputVideoParam(VIDEOENCODE_FILE, &outputhandle);

	setOutputvideohandle(&outputhandle);
	//sleep(10);
	ReadLogoinfo(LOGOCONFIGNAME, gLogoinfo);
	//setLogoInfoHandle(logoEnv);
	//sleep(10);
	texthandle = getTextInfoHandle();
	readTextFromfile(ADDTEXT_FILE, texthandle);
	//	DEBUG(DL_DEBUG, "%d,%d,%d,%d,%d,%d,%s\n", DHCPVAL, texthandle->xpos, texthandle->ypos,
	//	      texthandle->enable, texthandle->showtime, texthandle->alpha, texthandle->msgtext);
	//	sleep(10);
#ifdef DSS_ENC_1100_1200
	ReadProtocolIni(PROTOCOL_NAME, &gProtocol);
#endif

	ReadRemoteCtrlIndex(REMOTE_NAME, &index);
	/*Read I frames Interval*/
	ReadIframeInterval(IFRAMES_NAME);
	/*green Save Module*/
	app_init_green_adjust_module();
#ifdef CL4000_DVI
	app_init_screen_adjust_module();
#endif
	gblSetRemoteIndex(index);
	ReadHVTable(&gHVTable, 0);
	ReadHVTable(&gHVTable, 1);
#ifdef CL4000_DVI_SDI
	ReadIPParamTable(IP_PARAM, &gSysParaT);
#endif

	if(DHCPVAL) {
		printf("i will set dhcp.\n");
#if 1
		system("kill -1 `cat /var/run/dhcpcd-eth0.pid`");
		system("/sbin/dhcpcd eth0");
		system("ifconfig eth0");
#endif
		gSysParaT.sysPara.dwNetMark = GetNetmask("eth0");
		gSysParaT.sysPara.dwAddr = GetIPaddr("eth0");
		get_gateway(gateway);
		gSysParaT.sysPara.dwGateWay = 	get_gateway(gateway);
		DEBUG(DL_DEBUG, "gateway =%s\n", gateway);
	} else {
		printf("i will set static ip.\n");
		SetEthConfigIP(gSysParaT.sysPara.dwAddr, gSysParaT.sysPara.dwNetMark);
		SetEthConfigGW(gSysParaT.sysPara.dwGateWay);
	}

	system("ifconfig");

	strcpy(gSysParaT.sysPara.strVer, box_version);
	initSetParam();
	DEBUG(DL_DEBUG, "logo=%d text=%d ,texthandle->enable=%d,texthandle->showtime=%d\n", outputhandle.logo_show, outputhandle.text_show, texthandle->enable, texthandle->showtime);
#ifdef DSS_ENC_1100_1200
	/*open lcd initial*/
	OpenLCDCom(); //matchbox ++
	gblLoadIDX(); //matchbox ++

	if(-2 == ReadDeviceType(DTYPECONFIG_NAME, 1)) {
		ReadDeviceType(DTYPECONFIG_NAME, 0);
	}

	GetDeviceType(devicebuf);
	DEBUG(DL_DEBUG, "DTYPECONFIG_NAME gDeviceType = %s\n", devicebuf);
#endif

	/*取消PIPE坏的信号*/
	Signal(SIGPIPE, SIG_IGN);
	/* Set the priority of this whole process to max (requires root) */
	setpriority(PRIO_PROCESS, 0, -20);
	/*初始化高码流视频编码库参数*/
	InitVideoEncParams(&gSysParaT.videoPara[PORT_ONE]);
	/*初始化低码流视频编码库参数*/
	InitLowRateParams(&gSysParaT.videoPara[PORT_TWO]);
	/*初始化音频编码库参数*/
	InitAudioEncParams(&gSysParaT.audioPara[PORT_ONE]);
	/* Initialize the mutex which protects the global data */
	pthread_mutex_init(&gbl.mutex, NULL);
	/* Initialize Codec Engine runtime */
	CERuntime_init();
	/* Initialize Davinci Multimedia Application Interface */
	Dmai_init();
	closeWatchDog();

	mid_timer_init();
		
	initWatchDog();
#ifdef CL4000_DVI_SDI

	if(gblGetRemoteIndex() < MAX_FAR_CTRL_NUM) {
		result = InitRemoteStruct(gblGetRemoteIndex());
	}

	gRemoteFD = CameraCtrlInit(PORT_COM2);

	if(gRemoteFD <= 0) {
		DEBUG(DL_ERROR, "Initial CameraCtrlInit() Error\n");
	}

#else
#ifndef ENABLE_DEUBG

	if(gblGetRemoteIndex() < MAX_FAR_CTRL_NUM) {
		result = InitRemoteStruct(gblGetRemoteIndex());
	}

	gRemoteFD = CameraCtrlInit(PORT_COM1);

	if(gRemoteFD <= 0) {
		DEBUG(DL_ERROR, "Initial CameraCtrlInit() Error\n");
	}

#endif
#endif
	CreateTCPTask(id_listen);
	/* Initialize the logs. Must be done after CERuntime_init() */
	/*  if(TraceUtil_start(engine->engineName) != TRACEUTIL_SUCCESS)
		{
		    ERR("Failed to TraceUtil_start\n");
			cleanup(EXIT_FAILURE);
		}	*/
	//initMask |= LOGSINITIALIZED;
	app_set_logoshow_flag(outputhandle.logo_show);
	app_set_textshow_flag(outputhandle.text_show)	;
	//setShowLogoTextFlag(outputhandle->logotext);
	addtextdisplay(texthandle);
	/* Determine the number of threads needing synchronization */
	numThreads = 1;
	/*视频线程个数*/
	numThreads += 7;
	/*音频线程个数*/
	numThreads += 1;

	/* Create the objects which synchronizes the thread init and cleanup */
	hRendezvousInit = Rendezvous_create(numThreads, &rzvAttrs);
	hRendezvousCleanup = Rendezvous_create(numThreads, &rzvAttrs);
	hRendezvousWriter = Rendezvous_create(3, &rzvAttrs);

	if(hRendezvousInit == NULL ||
	   hRendezvousCleanup == NULL ||
	   hRendezvousWriter == NULL) {
		ERR("Failed to create Rendezvous objects\n");
		cleanup(EXIT_FAILURE);
	}

	/* Initialize the thread attributes */
	if(pthread_attr_init(&attr)) {
		ERR("Failed to initialize thread attrs\n");
		cleanup(EXIT_FAILURE);
	}

	/* Force the thread to use custom scheduling attributes */
	if(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) {
		ERR("Failed to set schedule inheritance attribute\n");
		cleanup(EXIT_FAILURE);
	}

	/* Set the thread to be fifo real time scheduled */
	if(pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) {
		ERR("Failed to set FIFO scheduling policy\n");
		cleanup(EXIT_FAILURE);
	}


	/* Create the capture fifos */
	captureEnv.to_video_c = Fifo_create(&fAttrs);
	captureEnv.from_video_c = Fifo_create(&fAttrs);
	captureEnv.to_resize_c = Fifo_create(&fAttrs);
	captureEnv.from_resize_c = Fifo_create(&fAttrs);

	if(captureEnv.to_video_c == NULL || captureEnv.from_video_c == NULL ||
	   captureEnv.to_resize_c == NULL || captureEnv.from_resize_c == NULL) {
		ERR("Failed to open display fifos\n");
		cleanup(EXIT_FAILURE);
	}

	LowRateResize.to_videoresize_c = Fifo_create(&fAttrs);
	LowRateResize.from_videoresize_c = Fifo_create(&fAttrs);

	if(LowRateResize.to_videoresize_c == NULL || LowRateResize.from_videoresize_c == NULL) {
		ERR("Failed to open Resize fifos\n");
		cleanup(EXIT_FAILURE);
	}

	/* Set the capture thread priority */
	schedParam.sched_priority = CAPTURE_THREAD_PRIORITY;

	if(pthread_attr_setschedparam(&attr, &schedParam)) {
		ERR("Failed to set scheduler parameters\n");
		cleanup(EXIT_FAILURE);
	}

	/* Create the capture thread */
	captureEnv.hRendezvousInit    = hRendezvousInit;
	captureEnv.hRendezvousCleanup = hRendezvousCleanup;
	DEBUG(DL_DEBUG, "captureThrFxn thread!!!!\n");


	if(pthread_create(&captureThread, &attr, captureThrFxn, &captureEnv)) {
		ERR("Failed to create capture thread\n");
		cleanup(EXIT_FAILURE);
	}

	/* Create the writer fifos */
	writerEnv.to_video_c = Fifo_create(&fAttrs);
	writerEnv.from_video_c = Fifo_create(&fAttrs);
	writerLowRateEnv.to_writelow_c = Fifo_create(&fAttrs);
	writerLowRateEnv.from_writelow_c = Fifo_create(&fAttrs);

	if(writerEnv.to_video_c == NULL || writerEnv.from_video_c == NULL ||
	   writerLowRateEnv.to_writelow_c == NULL || writerLowRateEnv.from_writelow_c == NULL) {
		ERR("Failed to open display fifos\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= CAPTURETHREADCREATED ;
	/*detect thread*/
	detectEnv.hRendezvousInit	  = hRendezvousInit;
	detectEnv.hRendezvousCleanup  = hRendezvousCleanup;

	/* Set the video thread priority */
	schedParam.sched_priority = DETECT_THREAD_PRIORITY;

	if(pthread_attr_setschedparam(&attr, &schedParam)) {
		ERR("Failed to set scheduler parameters\n");
		cleanup(EXIT_FAILURE);
	}

	if(pthread_create(&detectThread, &attr, detectThrFxn, &detectEnv)) {
		ERR("Failed to create detect thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= DETECTTHREADCREATED ;

	/* Set the video thread priority */
	schedParam.sched_priority = VIDEO_THREAD_PRIORITY;

	if(pthread_attr_setschedparam(&attr, &schedParam)) {
		ERR("Failed to set scheduler parameters\n");
		cleanup(EXIT_FAILURE);
	}

	DEBUG(DL_DEBUG, "videoThrFxn thread!!!!\n");

	/* Create the video thread */
	videoEnv.hRendezvousInit    = hRendezvousInit;
	videoEnv.hRendezvousCleanup = hRendezvousCleanup;
	videoEnv.hRendezvousWriter  = hRendezvousWriter;
	videoEnv.to_capture    		= captureEnv.from_video_c;
	videoEnv.from_capture     	= captureEnv.to_video_c;
	videoEnv.to_writer     		= writerEnv.from_video_c;
	videoEnv.from_writer     	= writerEnv.to_video_c;
	videoEnv.videoEncoder       = engine->videoEncoders->codecName;
	videoEnv.engineName         = engine->engineName;


	if(pthread_create(&videoThread, &attr, videoThrFxn, &videoEnv)) {
		ERR("Failed to create video thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= VIDEOTHREADCREATED;

	/* Create the videoResize thread */
	videoLowRateEnv.hRendezvousInit    = hRendezvousInit;
	videoLowRateEnv.hRendezvousCleanup = hRendezvousCleanup;
	videoLowRateEnv.hRendezvousWriter  = hRendezvousWriter;
	videoLowRateEnv.to_resize		  = LowRateResize.from_videoresize_c;
	videoLowRateEnv.from_resize		  = LowRateResize.to_videoresize_c;
	videoLowRateEnv.from_writer    	  = writerLowRateEnv.to_writelow_c;
	videoLowRateEnv.to_writer          = writerLowRateEnv.from_writelow_c;
	videoLowRateEnv.videoEncoder       = engine->videoEncoders->codecName;
	videoLowRateEnv.engineName         = engine->engineName;
	DEBUG(DL_DEBUG, "videoLowRateThrFxn thread!!!!\n");

	if(pthread_create(&videoLowThread, &attr, videoLowRateThrFxn, &videoLowRateEnv)) {
		ERR("Failed to create video thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= VIDEOLOWRATETHREAD;

	/* Create the video thread */
	LowRateResize.hRendezvousInit    = hRendezvousInit;
	LowRateResize.hRendezvousCleanup = hRendezvousCleanup;
	LowRateResize.hRendezvousWriter  = hRendezvousWriter;
	LowRateResize.from_capture		 = captureEnv.to_resize_c;
	LowRateResize.to_capture		 = captureEnv.from_resize_c;
	LowRateResize.videoEncoder       = engine->videoEncoders->codecName;
	LowRateResize.engineName         = engine->engineName;
	/* Set the video thread priority */
	schedParam.sched_priority = VIDEO_THREAD_PRIORITY;

	if(pthread_attr_setschedparam(&attr, &schedParam)) {
		ERR("Failed to set scheduler parameters\n");
		cleanup(EXIT_FAILURE);
	}

	DEBUG(DL_DEBUG, "ResizeLowThrFxn thread!!!!\n");

	if(pthread_create(&resizeLowThread, &attr, ResizeLowThrFxn, &LowRateResize)) {
		ERR("Failed to create video thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= RESIZELOWRATETHREAD;

	Rendezvous_meet(hRendezvousWriter);

	/* Set the writer thread priority */
	schedParam.sched_priority = WRITER_THREAD_PRIORITY;

	if(pthread_attr_setschedparam(&attr, &schedParam)) {
		ERR("Failed to set scheduler parameters\n");
		cleanup(EXIT_FAILURE);
	}

	/* Create the writer thread */
	writerEnv.hRendezvousInit    = hRendezvousInit;
	writerEnv.hRendezvousCleanup = hRendezvousCleanup;
	writerEnv.outBufSize         = videoEnv.outBufSize;

	DEBUG(DL_DEBUG, "writerThrFxn thread!!!!\n");

	if(pthread_create(&writerThread, &attr, writerThrFxn, &writerEnv)) {
		ERR("Failed to create writer thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= WRITERTHREADCREATED;

	/* Create the writer thread */
	writerLowRateEnv.hRendezvousInit         = hRendezvousInit;
	writerLowRateEnv.hRendezvousCleanup      = hRendezvousCleanup;
	writerLowRateEnv.outBufSize              = videoLowRateEnv.outBufSize;

	DEBUG(DL_DEBUG, "writerLowThrFxn thread!!!!\n");

	if(pthread_create(&writerLowThread, &attr, writerLowThrFxn, &writerLowRateEnv)) {
		ERR("Failed to create writerResize thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= WRITELOWRATETHREAD;

	/* Set the thread priority */
	schedParam.sched_priority = AUDIO_THREAD_PRIORITY;

	if(pthread_attr_setschedparam(&attr, &schedParam)) {
		ERR("Failed to set scheduler parameters\n");
		cleanup(EXIT_FAILURE);
	}

	DEBUG(DL_DEBUG, "Audio thread Function!!!!\n");
	/* Create the audio thread */
	audioEnv.hRendezvousInit    = hRendezvousInit;
	audioEnv.hRendezvousCleanup = hRendezvousCleanup;
	audioEnv.engineName         = engine->engineName;
	audioEnv.audioEncoder       = engine->audioEncoders->codecName;

	if(pthread_create(&audioThread, &attr, audioThrFxn, &audioEnv)) {
		ERR("Failed to create speech thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= AUDIOTHREADCREATED;
#ifdef DSS_ENC_1100_1200

	if(pthread_create(&webListenThread, &attr, weblistenThrFxn, NULL)) {
		ERR("Failed to create web listen thread\n");
		cleanup(EXIT_FAILURE);
	}

	initMask |= WEBLISTENCREATED;
#endif
	/* Main thread becomes the control thread */
	ctrlEnv.hRendezvousInit    = hRendezvousInit;
	ctrlEnv.hRendezvousCleanup = hRendezvousCleanup;
	ctrlEnv.engineName         = engine->engineName;
	ret = ctrlThrFxn(&ctrlEnv);

	if(ret == THREAD_FAILURE) {
		status = EXIT_FAILURE;
	}

	DEBUG(DL_DEBUG, "Exit All Thread!!\n");
cleanup:

	/* Make sure the other threads aren't waiting for init to complete */
	if(hRendezvousWriter) {
		Rendezvous_force(hRendezvousWriter);
	}

	if(hRendezvousInit) {
		Rendezvous_force(hRendezvousInit);
	}

	DEBUG(DL_DEBUG, "EXIT Common Mutex!!!\n");
	DestorygblCommonMutex();
	DEBUG(DL_DEBUG, "EXIT pthread Mutex!!!\n");
	DestroyMutexPthread();

	if(initMask & AUDIOTHREADCREATED) {
		if(pthread_join(audioThread, &ret) == 0) {
			if(ret == THREAD_FAILURE) {
				status = EXIT_FAILURE;
			}
		}
	}

	DEBUG(DL_DEBUG, "EXIT audio pThread!!!\n");

	if(initMask & VIDEOTHREADCREATED) {
		if(pthread_join(videoThread, &ret) == 0) {
			if(ret == THREAD_FAILURE) {
				status = EXIT_FAILURE;
			}
		}
	}

	DEBUG(DL_DEBUG, "EXIT video pThread!!!\n");

	if(initMask & WRITERTHREADCREATED) {
		if(pthread_join(writerThread, &ret) == 0) {
			if(ret == THREAD_FAILURE) {
				status = EXIT_FAILURE;
			}
		}
	}

	DEBUG(DL_DEBUG, "EXIT write pThread!!!\n");

	if(initMask & CAPTURETHREADCREATED) {
		if(pthread_join(captureThread, &ret) == 0) {
			if(ret == THREAD_FAILURE) {
				status = EXIT_FAILURE;
			}
		}
	}

	DEBUG(DL_DEBUG, "EXIT capture pThread!!!\n");

	if(initMask & VIDEOLOWRATETHREAD) {
		if(pthread_join(videoLowThread, &ret) == 0) {
			if(ret == THREAD_FAILURE) {
				status = EXIT_FAILURE;
			}
		}
	}

	if(initMask & RESIZELOWRATETHREAD) {
		if(pthread_join(resizeLowThread, &ret) == 0) {
			if(ret == THREAD_FAILURE) {
				status = EXIT_FAILURE;
			}
		}
	}

	if(initMask & WRITELOWRATETHREAD) {
		if(pthread_join(writerLowThread, &ret) == 0) {
			if(ret == THREAD_FAILURE) {
				status = EXIT_FAILURE;
			}
		}
	}

	if(pthread_join(id_listen[PORT_ONE], &ret) == 0) {
		if(ret == THREAD_FAILURE) {
			status = EXIT_FAILURE;
		}
	}

	if(captureEnv.to_video_c) {
		Fifo_delete(captureEnv.to_video_c);
	}

	if(captureEnv.from_video_c) {
		Fifo_delete(captureEnv.from_video_c);
	}

	if(captureEnv.to_resize_c) {
		Fifo_delete(captureEnv.to_resize_c);
	}

	if(captureEnv.from_resize_c) {
		Fifo_delete(captureEnv.from_resize_c);
	}

	if(writerEnv.to_video_c) {
		Fifo_delete(writerEnv.to_video_c);
	}

	if(writerEnv.from_video_c) {
		Fifo_delete(writerEnv.from_video_c);
	}

	if(writerLowRateEnv.from_writelow_c) {
		Fifo_delete(writerLowRateEnv.from_video_c);
	}

	if(writerLowRateEnv.to_writelow_c) {
		Fifo_delete(writerLowRateEnv.to_writelow_c);
	}

	if(LowRateResize.to_videoresize_c) {
		Fifo_delete(LowRateResize.to_videoresize_c);
	}

	if(LowRateResize.from_videoresize_c) {
		Fifo_delete(LowRateResize.from_videoresize_c);
	}

	DEBUG(DL_DEBUG, "EXIT Rendezvous cleanup pThread!!!\n");

	if(hRendezvousCleanup) {
		Rendezvous_delete(hRendezvousCleanup);
	}

	DEBUG(DL_DEBUG, "EXIT Rendezvous init pThread!!!\n");

	if(hRendezvousInit) {
		Rendezvous_delete(hRendezvousInit);
	}

	DEBUG(DL_DEBUG, "EXIT Rendezvous cleanup pThread!!!\n");
	/*
	    if (initMask & LOGSINITIALIZED) {
	        TraceUtil_stop();
		}	*/
	DEBUG(DL_DEBUG, "EXIT TraceUtil_stop !!!\n");
	pthread_mutex_destroy(&gbl.mutex);
	DEBUG(DL_DEBUG, "process EXIT!!!\n");
	exit(1);
}
/*
 *  ======== main ========
 */
Int main(Int argc, String argv[])
{
    CERuntime_init();

    return (smain(argc, argv));
}
예제 #21
0
파일: appMain.c 프로젝트: sv99/DVSDK
/******************************************************************************
 * appMain
 ******************************************************************************/
Int appMain(Args * args)
{
    VIDENC1_Params         params    = Venc1_Params_DEFAULT;
    VIDENC1_DynamicParams  dynParams = Venc1_DynamicParams_DEFAULT;
    BufferGfx_Attrs        gfxAttrs  = BufferGfx_Attrs_DEFAULT;
    Buffer_Attrs           bAttrs    = Buffer_Attrs_DEFAULT;
    Time_Attrs             tAttrs    = Time_Attrs_DEFAULT;
    Venc1_Handle           hVe1      = NULL;
    FILE                  *outFile   = NULL;
    FILE                  *reconFile = NULL;
    FILE                  *inFile    = NULL;
    Engine_Handle          hEngine   = NULL;
    Time_Handle            hTime     = NULL;
    Bool                   flushed   = FALSE;
    Bool                   mustExit  = FALSE;
    BufTab_Handle          hBufTab   = NULL;
    Buffer_Handle          hOutBuf   = NULL;
    Buffer_Handle          hFreeBuf  = NULL;
    Buffer_Handle          hInBuf    = NULL;
    Buffer_Handle          hReconBuf = NULL;
    Int                    numFrame  = 0;
    Int                    flushCntr = 1;
    Int                    bufIdx;
    Int                    inBufSize, outBufSize;
    Cpu_Device             device;
    Int                    numBufs;
    ColorSpace_Type        colorSpace;
    UInt32                 time;
    Int                    ret = Dmai_EOK;

    printf("Starting application...\n");

    /* Initialize the codec engine run time */
    CERuntime_init();

    /* Initialize DMAI */
    Dmai_init();

    /* Determine which device the application is running on */
    if (Cpu_getDevice(NULL, &device) < 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to determine target board\n");
        goto cleanup;
    }

    if (args->benchmark) {
        hTime = Time_create(&tAttrs);

        if (hTime == NULL) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to create Time object\n");
            goto cleanup;
        }
    }

    /* Open the input file with raw yuv data */
    inFile = fopen(args->inFile, "rb");

    if (inFile == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to open input file %s\n", args->inFile);
        goto cleanup;
    }

    /* Using a larger vbuf to enhance performance of file i/o */
    if (setvbuf(inFile, vbufferIn, _IOFBF, sizeof(vbufferIn)) != 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to setvbuf on input file descriptor\n");
        goto cleanup;
    }

    /* Open the output file where to put encoded data */
    outFile = fopen(args->outFile, "wb");

    if (outFile == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to open output file %s\n", args->outFile);
        goto cleanup;
    }

    /* Using a larger vbuf to enhance performance of file i/o */
    if (setvbuf(outFile, vbufferOut, _IOFBF, sizeof(vbufferOut)) != 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to setvbuf on output file descriptor\n");
        goto cleanup;
    }

    /* Open the output file where to put reconstructed frames */
    if (args->writeReconFrames) {
        reconFile = fopen(args->reconFile, "wb");

        if (reconFile == NULL) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to open output file %s\n", args->reconFile);
            goto cleanup;
        }

        /* Using a larger vbuf to enhance performance of file i/o */
        if (setvbuf(reconFile, vbufferRecon, _IOFBF,
                    sizeof(vbufferRecon)) != 0) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to setvbuf on output file descriptor\n");
            goto cleanup;
        }
    }

    /* Open the codec engine */
    hEngine = Engine_open(args->engineName, NULL, NULL);

    if (hEngine == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to open codec engine: %s\n", args->engineName);
        goto cleanup;
    }

    /* Set up codec parameters depending on bit rate */
    if (args->bitRate < 0) {
        /* Variable bit rate */
        params.rateControlPreset = IVIDEO_NONE;

        /*
         * If variable bit rate use a bogus bit rate value (> 0)
         * since it will be ignored.
         */
        params.maxBitRate        = 2000000;
    }
    else {
        /* Constant bit rate */
        params.rateControlPreset = IVIDEO_LOW_DELAY;
        params.maxBitRate        = args->bitRate;
    }

    /* Set up codec parameters depending on device */
    switch (device) {
    case Cpu_Device_DM6467:
        params.inputChromaFormat = XDM_YUV_420SP;
        params.reconChromaFormat = XDM_CHROMA_NA;
        break;
    case Cpu_Device_DM355:
        params.inputChromaFormat = XDM_YUV_422ILE;
        params.reconChromaFormat = XDM_YUV_420P;
        break;
    case Cpu_Device_DM365:
    case Cpu_Device_DM368:
        params.inputChromaFormat = XDM_YUV_420SP;
        params.reconChromaFormat = XDM_YUV_420SP;
        break;
    case Cpu_Device_DM3730:
        params.rateControlPreset = IVIDEO_STORAGE;
        params.inputChromaFormat = XDM_YUV_422ILE;
        break;
    default:
        params.inputChromaFormat = XDM_YUV_422ILE;
        break;
    }

    params.maxWidth              = args->width;
    params.maxHeight             = args->height;

    /* Workaround for SDOCM00068944: h264fhdvenc fails
       to create codec when params.dataEndianness is
       set as XDM_BYTE */
    if(device == Cpu_Device_DM6467) {
        if (!strcmp(args->codecName, "h264fhdvenc")) {
            params.dataEndianness        = XDM_LE_32;
        }
    }

    params.maxInterFrameInterval = 1;
    dynParams.targetBitRate      = params.maxBitRate;
    dynParams.inputWidth         = params.maxWidth;
    dynParams.inputHeight        = params.maxHeight;

    /* Create the video encoder */
    hVe1 = Venc1_create(hEngine, args->codecName, &params, &dynParams);

    if (hVe1 == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to create video encoder: %s\n", args->codecName);
        goto cleanup;
    }

    /* Ask the codec how much input data it needs */
    inBufSize = Venc1_getInBufSize(hVe1);

    /* Ask the codec how much space it needs for output data */
    outBufSize = Venc1_getOutBufSize(hVe1);

    /* Which color space to use in the graphics buffers depends on the device */
    colorSpace = ((device == Cpu_Device_DM6467)||
                  (device == Cpu_Device_DM365) ||
                  (device == Cpu_Device_DM368)) ? ColorSpace_YUV420PSEMI :
                 ColorSpace_UYVY;

    /* Align buffers to cache line boundary */
    gfxAttrs.bAttrs.memParams.align = bAttrs.memParams.align = BUFSIZEALIGN;

    /* Use cached buffers if requested */
    if (args->cache) {
        gfxAttrs.bAttrs.memParams.flags = bAttrs.memParams.flags
                                          = Memory_CACHED;
    }

    gfxAttrs.dim.width      = args->width;
    gfxAttrs.dim.height     = args->height;
    if ((device == Cpu_Device_DM6467) || (device == Cpu_Device_DM365)
            || (device == Cpu_Device_DM368)) {
        gfxAttrs.dim.height = Dmai_roundUp(gfxAttrs.dim.height, CODECHEIGHTALIGN);
    }
    gfxAttrs.dim.lineLength = BufferGfx_calcLineLength(args->width, colorSpace);
    gfxAttrs.colorSpace     = colorSpace;

    if (inBufSize < 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to calculate buffer attributes\n");
        goto cleanup;
    }

    /* Number of input buffers required */
    if(params.maxInterFrameInterval>1) {
        /* B frame support */
        numBufs = params.maxInterFrameInterval;
    }
    else {
        numBufs = 1;
    }

    /* Create a table of input buffers of the size requested by the codec */
    hBufTab =
        BufTab_create(numBufs, Dmai_roundUp(inBufSize, BUFSIZEALIGN),
                      BufferGfx_getBufferAttrs(&gfxAttrs));

    if (hBufTab == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to allocate contiguous buffers\n");
        goto cleanup;
    }

    /* Set input buffer table */
    Venc1_setBufTab(hVe1, hBufTab);

    /* Create the reconstructed frame buffer for raw yuv data */
    if (args->writeReconFrames) {
        hReconBuf =
            Buffer_create(Dmai_roundUp(inBufSize, BUFSIZEALIGN),
                          BufferGfx_getBufferAttrs(&gfxAttrs));

        if (hReconBuf == NULL) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to allocate contiguous buffer\n");
            goto cleanup;
        }
    }

    /* Create the output buffer for encoded video data */
    hOutBuf = Buffer_create(Dmai_roundUp(outBufSize, BUFSIZEALIGN), &bAttrs);

    if (hOutBuf == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to create contiguous buffer\n");
        goto cleanup;
    }

    while (1) {

        /* Get a buffer for input */
        hInBuf = BufTab_getFreeBuf(hBufTab);

        if (hInBuf == NULL) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to get a free contiguous buffer from BufTab\n");
            BufTab_print(hBufTab);
            goto cleanup;
        }

        if (args->benchmark) {
            if (Time_reset(hTime) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr,"Failed to reset timer\n");
                goto cleanup;
            }
        }

        /* Read a yuv input frame */
        printf("\n Frame %d: ", numFrame);
        if ((device == Cpu_Device_DM6467)||
                (device == Cpu_Device_DM365) ||
                (device == Cpu_Device_DM368)) {
            if(args->sp) {
                if (readFrame420SP(hInBuf, inFile, args->height) < 0) {
                    ret = Dmai_EFAIL;
                    goto cleanup;
                }
            } else {
                if (readFrame420P(hInBuf, inFile, args->height) < 0) {
                    ret = Dmai_EFAIL;
                    goto cleanup;
                }
            }
        }
        else {
            if (readFrameUYVY(hInBuf, inFile) < 0) {
                ret = Dmai_EFAIL;
                mustExit = TRUE;
            }
        }

        if (++numFrame == args->numFrames||mustExit == TRUE) {
            if(!(params.maxInterFrameInterval>1)) {
                /* No B-frame support */
                printf("... exiting \n");
                goto cleanup;
            }

            /*
             * When encoding a stream with B-frames, ending the processing
             * requires to free the buffer held by the encoder. This is done by
             * flushing the encoder and performing a last process() call
             * with a dummy input buffer.
             */
            printf("\n... exiting with flush (B-frame stream) \n");
            flushCntr = params.maxInterFrameInterval-1;
            flushed = TRUE;
            Venc1_flush(hVe1);
        }

        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr,"Failed to get timer delta\n");
                goto cleanup;
            }

            printf("Read time: %uus\n", (Uns)time);
        }

        /*
         * Following flushing loop will iterate more than one time only
         * when the encoder completes processing by flushing the frames
         * held by the encoder. All flushed frames will be encoded as P
         * or I frames.
         */

        for(bufIdx = 0; bufIdx < flushCntr; bufIdx++) {

            if (args->cache) {
                /*
                *  To meet xDAIS DMA Rule 7, when input buffers are cached, we
                *  must writeback the cache into physical memory.  Also, per DMA
                *  Rule 7, we must invalidate the output buffer from
                *  cache before providing it to any xDAIS algorithm.
                */
                Memory_cacheWbInv(Buffer_getUserPtr(hInBuf),
                                  Buffer_getSize(hInBuf));

                /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
                Memory_cacheInv(Buffer_getUserPtr(hOutBuf),
                                Buffer_getSize(hOutBuf));

                if (args->benchmark) {
                    if (Time_delta(hTime, &time) < 0) {
                        ret = Dmai_EFAIL;
                        fprintf(stderr,"Failed to get timer delta\n");
                        goto cleanup;
                    }

                    printf("Pre-process cache maintenance: %uus \n", (Uns) time);
                }
            }

            /* Make sure the whole buffer is used for input */
            BufferGfx_resetDimensions(hInBuf);

            /* Encode the video buffer */
            if (Venc1_process(hVe1, hInBuf, hOutBuf) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr,"Failed to encode video buffer\n");
                goto cleanup;
            }

            /* if encoder generated output content, free released buffer */
            if (Buffer_getNumBytesUsed(hOutBuf)>0) {
                /* Get free buffer */
                hFreeBuf = Venc1_getFreeBuf(hVe1);
                /* Free buffer */
                BufTab_freeBuf(hFreeBuf);
            }
            /* if encoder did not generate output content */
            else {
                /* if non B frame sequence */
                /* encoder skipped frame probably exceeding target bitrate */
                if (params.maxInterFrameInterval<=1) {
                    /* free buffer */
                    printf(" Encoder generated 0 size frame\n");
                    BufTab_freeBuf(hInBuf);
                }
            }

            if (args->benchmark) {
                if (Time_delta(hTime, &time) < 0) {
                    ret = Dmai_EFAIL;
                    fprintf(stderr,"Failed to get encode time\n");
                    goto cleanup;
                }

                printf("[%d] Encode: %uus\n", numFrame, (Uns)time);
            }

            if (args->cache) {
                /* Writeback the outBuf. */
                Memory_cacheWb(Buffer_getUserPtr(hOutBuf),
                               Buffer_getSize(hOutBuf));

                if (args->benchmark) {
                    if (Time_delta(hTime, &time) < 0) {
                        ret = Dmai_EFAIL;
                        fprintf(stderr,"Failed to get timer delta\n");
                        goto cleanup;
                    }

                    printf("Post-process cache write back: %uus \n", (Uns) time);
                }
            }

            /* Write the encoded frame to the file system */
            if (Buffer_getNumBytesUsed(hOutBuf)) {
                if (fwrite(Buffer_getUserPtr(hOutBuf),
                           Buffer_getNumBytesUsed(hOutBuf), 1, outFile) != 1) {
                    ret = Dmai_EFAIL;
                    fprintf(stderr,"Failed to write encoded video data to file\n");
                    goto cleanup;
                }
            }

            /* Write the reconstructed frame to the file system */
            if (args->writeReconFrames) {
                processReconData(Venc1_getReconBufs(hVe1), hInBuf, hReconBuf);

                if (Buffer_getNumBytesUsed(hReconBuf)) {
                    if (fwrite(Buffer_getUserPtr(hReconBuf),
                               Buffer_getNumBytesUsed(hReconBuf), 1, reconFile) != 1) {
                        ret = Dmai_EFAIL;
                        fprintf(stderr,"Failed to write reconstructed frame to file\n");
                        goto cleanup;
                    }
                }
            }

            if (args->benchmark) {
                if (Time_delta(hTime, &time) < 0) {
                    ret = Dmai_EFAIL;
                    printf("Failed to get timer delta\n");
                    goto cleanup;
                }

                printf("File write time: %uus\n", (Uns)time);

                if (Time_total(hTime, &time) < 0) {
                    ret = Dmai_EFAIL;
                    fprintf(stderr,"Failed to get timer total\n");
                    goto cleanup;
                }

                printf("Total: %uus\n", (Uns)time);
            }
        }

        /* If the codec flushing completed, exit main thread */
        if (flushed) {
            /* Free dummy input buffer used for flushing process() calls */
            printf("freeing dummy input buffer ... \n");
            BufTab_freeBuf(hInBuf);
            break;
        }
    }

cleanup:
    /* Clean up the application */
    if (hOutBuf) {
        Buffer_delete(hOutBuf);
    }

    if (hReconBuf) {
        Buffer_delete(hReconBuf);
    }

    if (hVe1) {
        Venc1_delete(hVe1);
    }

    if (hBufTab) {
        BufTab_delete(hBufTab);
    }

    if (hEngine) {
        Engine_close(hEngine);
    }

    if (inFile) {
        fclose(inFile);
    }

    if (outFile) {
        fclose(outFile);
    }

    if (reconFile) {
        fclose(reconFile);
    }

    if (hTime) {
        Time_delete(hTime);
    }

    printf("End of application.\n");

    if (ret == Dmai_EFAIL)
        return 1;
    else
        return 0;
}
예제 #22
0
/******************************************************************************
 * main
 ******************************************************************************/
Int appMain(Args * args)
{
    Buffer_Attrs            bAttrs      = Buffer_Attrs_DEFAULT;
    Loader_Attrs            lAttrs      = Loader_Attrs_DEFAULT;
    AUDDEC1_Params          params      = Adec1_Params_DEFAULT;
    AUDDEC1_DynamicParams   dynParams   = Adec1_DynamicParams_DEFAULT;
    Time_Attrs              tAttrs      = Time_Attrs_DEFAULT;
    Adec1_Handle            hAd1        = NULL;
    Loader_Handle           hLoader     = NULL;
    Engine_Handle           hEngine     = NULL;
    Buffer_Handle           hOutBuf     = NULL;
    Time_Handle             hTime       = NULL;
    Buffer_Handle           hInBuf      = NULL;
    FILE                   *outFile     = NULL;
    Int                     numFrame    = 0;
    UInt32                  time;
    Int                     ret         = Dmai_EOK;
    Cpu_Device              device;

    printf("Starting application...\n");
        
    if (args->benchmark) {
        hTime = Time_create(&tAttrs);

        if (hTime == NULL) {
            ret = Dmai_EFAIL;
            fprintf(stderr, "Failed to create Time object\n");
            goto cleanup;
        }
    }

    /* Initialize the codec engine run time */
    CERuntime_init();

    /* Initialize DMAI */
    Dmai_init();

    /* Determine which device the application is running on */
    if (Cpu_getDevice(NULL, &device) < 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr, "Failed to determine target board\n");
        goto cleanup;
    }

    /* Open the output file */
    outFile = fopen(args->outFile, "wb");

    if (outFile == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to create output file %s\n", args->outFile);
        goto cleanup;
    }

    /* Using a larger vbuf to enhance performance of file i/o */
    if (setvbuf(outFile, vbuffer, _IOFBF, sizeof(vbuffer)) != 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr, "Failed to setvbuf on file descriptor\n");
        goto cleanup;
    }

    /* Open the codec engine */
    hEngine = Engine_open(args->engineName, NULL, NULL);

    if (hEngine == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr, "Failed to open codec engine %s\n", args->engineName);
        goto cleanup;
    }

    if (device == Cpu_Device_DM365 || device == Cpu_Device_OMAP3530 ||
        device == Cpu_Device_DM368 || device == Cpu_Device_DM3730) {
        params.dataEndianness = XDM_LE_16;
    }


    /* Create the AUDDEC1 based audio decoder */
    hAd1 = Adec1_create(hEngine, args->codecName, &params, &dynParams);

    if (hAd1 == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr, "Failed to create audio decoder\n");
        goto cleanup;
    }

    /* Align buffers to cache line boundary */    
    bAttrs.memParams.align = lAttrs.mParams.align = BUFSIZEALIGN; 
    
    /* Use cached buffers if requested */    
    if (args->cache) {
        bAttrs.memParams.flags = lAttrs.mParams.flags = Memory_CACHED;
    } 
    
    /* Ask the codec how much input data it needs */
    lAttrs.readSize = Adec1_getInBufSize(hAd1);

    /* Make the total ring buffer larger */
    lAttrs.readBufSize = Dmai_roundUp(lAttrs.readSize * 10, BUFSIZEALIGN);

    /* Increase the stdio buffer size for loader for better RTDX performance */
    lAttrs.vBufSize = VBUFSIZE;

    /* Create the file loader */
    hLoader = Loader_create(args->inFile, &lAttrs);

    if (hLoader == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr, "Failed to create loader\n");
        goto cleanup;
    }

    /* Create an output buffer for decoded data */
    hOutBuf = Buffer_create(
        Dmai_roundUp(Adec1_getOutBufSize(hAd1), BUFSIZEALIGN), &bAttrs);

    if (hOutBuf == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr, "Failed to create contiguous buffers\n");
        goto cleanup;
    }

    /* Prime the file loader */
    Loader_prime(hLoader, &hInBuf);

    while (numFrame++ < args->numFrames) {
        if (args->benchmark) {
            if (Time_reset(hTime) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr, "Failed to reset timer\n");
                goto cleanup;
            }
        }

        if (args->cache) {
            /*
             *  To meet xDAIS DMA Rule 7, when input buffers are cached, we
             *  must writeback the cache into physical memory.  Also, per DMA
             *  Rule 7, we must invalidate the output buffer from
             *  cache before providing it to any xDAIS algorithm.
             */
            Memory_cacheWbInv(Buffer_getUserPtr(hInBuf),Buffer_getSize(hInBuf));

            /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
            Memory_cacheInv(Buffer_getUserPtr(hOutBuf),Buffer_getSize(hOutBuf));

            if (args->benchmark) {
                if (Time_delta(hTime, &time) < 0) {
                    ret = Dmai_EFAIL;
                    fprintf(stderr,"Failed to get timer delta\n");
                    goto cleanup;
                }

                printf("Pre-process cache maintenance: %uus ", (Uns) time);
            }
        }

        /* Decode the audio buffer */
        ret = Adec1_process(hAd1, hInBuf, hOutBuf);

        if ((ret == Dmai_EFAIL)||
            (ret == Dmai_EBITERROR && Buffer_getNumBytesUsed(hInBuf) == 0)) {
            ret = Dmai_EFAIL;
            fprintf(stderr, "Failed to decode audio buffer\n");
            goto cleanup;
        }

        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr, "Failed to get timer delta\n");
                goto cleanup;
            }

            printf("Decode: %uus ", (Uns) time);
        }

        if (args->cache) {
            /* Writeback the outBuf. */
            Memory_cacheWb(Buffer_getUserPtr(hOutBuf), Buffer_getSize(hOutBuf));

            if (args->benchmark) {
                if (Time_delta(hTime, &time) < 0) {
                    ret = Dmai_EFAIL;
                    fprintf(stderr, "Failed to get timer delta\n");
                    goto cleanup;
                }

                printf("Post-process cache write back: %uus ", (Uns) time);
            }
        }

        /* Load a new frame from the file system */
        Loader_getFrame(hLoader, hInBuf);

        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr,"Failed to get timer delta\n");
                goto cleanup;
            }

            printf("Loader: %uus\n", (Uns) time);
        }

        if (Buffer_getNumBytesUsed(hOutBuf)) {
            if (numFrame >= args->startFrame) {
                printf("Frame %d: ", numFrame);
                if (writeFrame(hOutBuf, outFile) < 0) {
                    ret = Dmai_EFAIL;
                    goto cleanup;
                }
            }
        }

        if (Buffer_getUserPtr(hInBuf) == NULL) {
            printf("Loader returned null, clip finished\n");
            break;
        }

        if (args->benchmark) {
            if (Time_total(hTime, &time) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr,"Failed to get timer total\n");
                goto cleanup;
            }

            printf("Total: %uus\n", (unsigned int)time);
        }
    }

cleanup:
    /* Clean up the application */
    if (hLoader) {
        Loader_delete(hLoader);
    }

    if (hAd1) {
        Adec1_delete(hAd1);
    }

    if (hOutBuf) {
        Buffer_delete(hOutBuf);
    }

    if (hEngine) {
        Engine_close(hEngine);
    }

    if (hTime) {
        Time_delete(hTime);
    }

    if (outFile) {
        fclose(outFile);
    }

    printf("End of application.\n");

    if (ret == Dmai_EFAIL)
        return 1;
    else
        return 0;
}
예제 #23
0
/******************************************************************************
 * appMain
 ******************************************************************************/
Int appMain(Args * args)
{
    IMGDEC1_Params          params       = Idec1_Params_DEFAULT;
    IMGDEC1_DynamicParams   dynParams    = Idec1_DynamicParams_DEFAULT;
    Buffer_Attrs            bAttrs       = Buffer_Attrs_DEFAULT;
    BufferGfx_Attrs         gfxAttrs     = BufferGfx_Attrs_DEFAULT;
    Time_Attrs              tAttrs       = Time_Attrs_DEFAULT;   
    Idec1_Handle            hId          = NULL;
    Engine_Handle           hEngine      = NULL;
    Time_Handle             hTime        = NULL;
    Buffer_Handle           hInBuf       = NULL;
    Buffer_Handle           hOutBuf      = NULL;
    FILE                   *outFile      = NULL;
    FILE                   *inFile       = NULL;
    Int                     numBytes     = 0;
    Int                     ret          = Dmai_EOK;
    Cpu_Device              device;
    UInt32                  time;

    printf("Starting application...\n");
     
    if (args->benchmark) {
        hTime = Time_create(&tAttrs);

        if (hTime == NULL) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to create Time object\n");
            goto cleanup;
        }
    }

    /* Initialize the codec engine run time */
    CERuntime_init();

    /* Initialize DMAI */
    Dmai_init();

    /* Determine which device the application is running on */
    if (Cpu_getDevice(NULL, &device) < 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to determine target board\n");
        goto cleanup;
    }

    /* Open input file */
    inFile = fopen(args->inFile, "rb");

    if (inFile == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to open file %s\n", args->inFile);
        goto cleanup;
    }
    
    /* Open output file */
    outFile = fopen(args->outFile, "wb");
    
    if (outFile == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to create output file %s\n", args->outFile);
        goto cleanup;
    }

    /* Using a larger vbuf to enhance performance of file i/o */
    if (setvbuf(outFile, vbuffer, _IOFBF, sizeof(vbuffer)) != 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to setvbuf on file descriptor\n");
        goto cleanup;   
    }
    
    /* Open the codec engine */
    hEngine = Engine_open(args->engineName, NULL, NULL);

    if (hEngine == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to open codec engine %s\n", args->engineName);
        goto cleanup;
    }

    /*
     * Set output color format to UYVY or Planar output.
     * Here XDM_DEFUALT sets the output planar format to
     * the planar fromat of the encoded image.
     *           
     */
    switch (args->oColorSpace) {
        case ColorSpace_UYVY:
            params.forceChromaFormat = XDM_YUV_422ILE;
            break;
        case ColorSpace_NOTSET:
            params.forceChromaFormat = XDM_CHROMAFORMAT_DEFAULT;
            break;
        case ColorSpace_YUV444P:
            params.forceChromaFormat = XDM_YUV_444P;
            break;
        case ColorSpace_YUV422P:
            params.forceChromaFormat = XDM_YUV_422P;
            break;
        case ColorSpace_YUV420P:
            params.forceChromaFormat = XDM_YUV_420P;
            break;
        case ColorSpace_YUV420PSEMI:
            params.forceChromaFormat = XDM_YUV_420SP;
            break;
        case ColorSpace_GRAY:
            params.forceChromaFormat = ColorSpace_GRAY;
            break;
        default:
            ret = Dmai_EFAIL;
            fprintf(stderr,"Unsupported output color space %d.\n", args->oColorSpace);
            goto cleanup;
    }

    if ((device == Cpu_Device_DM365) || (device == Cpu_Device_DM368)) {
        params.maxHeight = VideoStd_720P_HEIGHT;
        params.maxWidth  = VideoStd_720P_WIDTH;
    }

    if (device == Cpu_Device_DM6467) {
        params.maxHeight = VideoStd_720P_HEIGHT;
        params.maxWidth  = VideoStd_720P_WIDTH;
    }

    /* Create the image decoder */
    hId = Idec1_create(hEngine, args->codecName, &params, &dynParams);

    if (hId == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to create image decoder: %s\n", args->codecName);
        goto cleanup;
    }

    /* Align buffers to cache line boundary */    
    gfxAttrs.bAttrs.memParams.align = bAttrs.memParams.align = BUFSIZEALIGN; 
    
    /* Use cached buffers if requested */    
    if (args->cache) {
        gfxAttrs.bAttrs.memParams.flags = bAttrs.memParams.flags 
            = Memory_CACHED;
    } 
    
    gfxAttrs.colorSpace     = args->oColorSpace;
    gfxAttrs.dim.width      = params.maxWidth;
    gfxAttrs.dim.height     = params.maxHeight;
    gfxAttrs.dim.lineLength = BufferGfx_calcLineLength(params.maxWidth,
                                                       gfxAttrs.colorSpace);
    
    /* Create an output buffer for decoded data */
    hOutBuf = Buffer_create(
        Dmai_roundUp(Idec1_getOutBufSize(hId), BUFSIZEALIGN), 
        BufferGfx_getBufferAttrs(&gfxAttrs));

    if (hOutBuf == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to create contiguous buffers\n");
        goto cleanup;
    }

    /* Create an input buffer for encoded data */
    hInBuf = Buffer_create(Dmai_roundUp(Idec1_getInBufSize(hId), BUFSIZEALIGN), 
        &bAttrs);

    if (hInBuf == NULL) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to create contiguous buffers\n");
        goto cleanup;
    }
   
    /* Read encoded image data */
    numBytes = fread(Buffer_getUserPtr(hInBuf), 1,
                     Idec1_getInBufSize(hId), inFile);
                     
    Buffer_setNumBytesUsed(hInBuf, numBytes);

    if (args->benchmark) {
        if (Time_reset(hTime) < 0) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to reset timer\n");
            goto cleanup;
        }
    }

    if (args->cache) {
        /*  
         *  To meet xDAIS DMA Rule 7, when input buffers are cached, we 
         *  must writeback the cache into physical memory.  Also, per DMA 
         *  Rule 7, we must invalidate the output buffer from
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(Buffer_getUserPtr(hInBuf), Buffer_getSize(hInBuf));
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(Buffer_getUserPtr(hOutBuf), Buffer_getSize(hOutBuf));
        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr,"Failed to get timer delta\n");
                goto cleanup;
            }
    
            printf("Pre-process cache maintenance: %uus \n", (Uns) time);
        }
    }

    printf("Decoding image...\n");
        
    /* Decode the image frame */
    ret = Idec1_process(hId, hInBuf, hOutBuf);
    
    if (ret < 0) {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Failed to decode image buffer\n");
        goto cleanup;
    }
    
    if (args->benchmark) {
        if (Time_delta(hTime, &time) < 0) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to get timer delta\n");
            goto cleanup;
        }
    
        printf("Frame - Decode: %uus \n", (unsigned int)time);
    }
    
    if (args->cache) {
        /* Writeback the outBuf. */
        Memory_cacheWb(Buffer_getUserPtr(hOutBuf), Buffer_getSize(hOutBuf));
    
        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                ret = Dmai_EFAIL;
                fprintf(stderr,"Failed to get timer delta\n");
                goto cleanup;
            }
    
            printf("Post-process cache write back: %uus ", (Uns) time);
        }
    }

    /* Write decoded image to a file */
   if (BufferGfx_getColorSpace(hOutBuf) == ColorSpace_UYVY){
        if (writeFrameUYVY(hOutBuf, outFile) < 0) {
           ret = Dmai_EFAIL;
           fprintf(stderr,"Failed to write image to file\n");
           goto cleanup; 
       }
    } else if (BufferGfx_getColorSpace(hOutBuf) == ColorSpace_YUV420PSEMI) {
        if (writeFrameSemiPlanar(hOutBuf, outFile) < 0) {
           ret = Dmai_EFAIL;
           fprintf(stderr,"Failed to write image to file\n");
           goto cleanup; 
       }
    }
    else if (BufferGfx_getColorSpace(hOutBuf) == ColorSpace_YUV420P
             || ColorSpace_YUV422P || ColorSpace_YUV444P || ColorSpace_GRAY){
        /* For XDM_GRAY ignoring the color planes */
        if (args->oColorSpace == ColorSpace_GRAY){
            BufferGfx_setColorSpace (hOutBuf, ColorSpace_GRAY); 
        }        
        if (writeFramePlanar(hOutBuf, outFile) < 0) {
           ret = Dmai_EFAIL;
           fprintf(stderr,"Failed to write image to file\n");
           goto cleanup; 
       }
    }
    else {
        ret = Dmai_EFAIL;
        fprintf(stderr,"Invalid output colorspace.\n");
        goto cleanup;     
    }

    if (args->benchmark) {
        if (Time_total(hTime, &time) < 0) {
            ret = Dmai_EFAIL;
            fprintf(stderr,"Failed to get timer total\n");
            goto cleanup;
        }
    
        printf("Total: %uus\n", (unsigned int)time);
    }
       
cleanup:
    /* Clean up the application */
    if (hId) {
        Idec1_delete(hId);
    }
    
    if (hInBuf) {
        Buffer_delete(hInBuf);
    }

    if (hOutBuf) {
        Buffer_delete(hOutBuf);
    }

    if (hEngine) {
        Engine_close(hEngine);
    }

    if (hTime) {
        Time_delete(hTime);
    }

    if (inFile) {
        fclose(inFile);
    }
 
    if (outFile) {
        fclose(outFile);
    }
    
    printf("End of application.\n");

    if (ret == Dmai_EFAIL) 
        return 1;
    else    
        return 0;
}
예제 #24
0
/**
 *  @brief      The BIOS main() entry point.
 *
 *  @remark     The purpose of this function is to create several BIOS worker
 *              tasks, one for each core including the one running this app,
 *              each of which will execute this simple example.
 *
 *  @remark     This is called during initialization, but before the BIOS
 *              scheduler has begun running.
 */
Void main(Int argc, String argv[])
{
    Thread_Params threadParams;
    int i;
    int numCores;

    sprintf(ti_sdo_ce_osal_bios_Global_CE_DEBUG, "1");
    ti_sdo_ce_osal_bios_Global_CE_DEBUG[0] = '2';
    ti_sdo_ce_osal_bios_Global_CE_DEBUG[1] = '\0';

    /* init Codec Engine */
    CERuntime_init();

    /* Enable all trace for xdc.runtime.Main */
    Diags_setMask("xdc.runtime.Main+EX1234567");

    Log_print0(Diags_USER2, "main> ti.sdo.ce.examples.apps.audio1_copy.sync");

    /* Determine number of cores on this device */
    numCores = MultiProc_getNumProcessors();

    /* Unfortunately, the rts library pre-built with CCS only supports 10
     * open files at a time (and 3 are reserved for stdin, stdout, stderr.
     * This app creates a thread for each core, and each thread requires 2
     * file handles.  So, if numCores is > 3, we will run out of file handles
     * _with the prebuilt rtslib.  You can modify the rtslib to support more
     * than 10 handles, and link that lib in, but that's beyond the scope of
     * this app.  We limit the number to 3 cores here.
     *
     * If you rebuild rtslib to support more open file handles, you can remove
     * the following numCores limiting assignment.
     */
    if (numCores > 3) {
        numCores = 3;
    }

    /* create a thread to communicate with each remote core */
    for (i = 0; i < numCores; i++) {
        Thread_Params_init(&threadParams);

        /* 6K stack size */
        threadParams.stackSize = 6 * 1024;

        /* priority - thread 0 gets lower pri as it uses a local alg */
        threadParams.priority = (i == 0) ? Thread_Priority_BELOW_NORMAL :
            Thread_Priority_ABOVE_NORMAL;

        /* task name */
        /* TODO, would be better if this taskName were unique for each task */
        threadParams.instance->name = taskName;

        /* unique arg for each thread - so in/out file names are unique */
        threadParams.arg = i;

        if (Thread_create(workerFxn, &threadParams, NULL) == NULL) {
            System_abort("main: failed to create smain thread.");
        }
    }

    BIOS_start();
}
예제 #25
0
/******************************************************************************
 * appMain
 ******************************************************************************/
Void appMain(Args * args)
{
    Buffer_Attrs            bAttrs      = Buffer_Attrs_DEFAULT;
    Time_Attrs              tAttrs      = Time_Attrs_DEFAULT;
    SPHENC1_Params          params      = Senc1_Params_DEFAULT;
    SPHENC1_DynamicParams   dynParams   = Senc1_DynamicParams_DEFAULT;
    Senc1_Handle            hSe1        = NULL;
    Engine_Handle           hEngine     = NULL;
    Buffer_Handle           hOutBuf     = NULL;
    Buffer_Handle           hInBuf      = NULL;
    Time_Handle             hTime       = NULL;
    FILE                   *inFile      = NULL;
    FILE                   *outFile     = NULL;
    Int                     numFrame    = 0;
    Int32                   bytesRead;
    UInt32                  time;

   printf("Starting application...\n");

   if (args->benchmark) {
        hTime = Time_create(&tAttrs);

        if (hTime == NULL) {
            printf("Failed to create Time object\n");
            goto cleanup;
        }
    }

    /* Initialize the codec engine run time */
    CERuntime_init();

    /* Initialize DMAI */
    Dmai_init();

    /* Open the output file */
    outFile = fopen(args->outFile, "wb");

    if (outFile == NULL) {
        printf("Failed to create output file %s\n", args->outFile);
        goto cleanup;
    }

    /* Open the input file */
    inFile = fopen(args->inFile, "rb");

    if (inFile == NULL) {
        printf("Failed to open input file %s\n", args->inFile);
        goto cleanup;
    }

    /* Using a larger vbuf to enhance performance of file i/o */
        if (setvbuf(outFile, vbuffer, _IOFBF, sizeof(vbuffer)) != 0) {
            printf("Failed to setvbuf on file descriptor\n");
            goto cleanup;
    }

    /* Open the codec engine */
    hEngine = Engine_open(args->engineName, NULL, NULL);

    if (hEngine == NULL) {
        printf("Failed to open codec engine %s\n", args->engineName);
        goto cleanup;
    }
    
    params.compandingLaw = args->compandingLaw;

    /* Create the SPHENC1 based speech encoder */
    hSe1 = Senc1_create(hEngine, args->codecName, &params, &dynParams);

    if (hSe1 == NULL) {
        printf("Failed to create %s\n", args->codecName);
        goto cleanup;
    }

    /* Align buffers to cache line boundary */    
    bAttrs.memParams.align = BUFSIZEALIGN; 
    
    /* Use cached buffers if requested */  
    if (args->cache) {
        bAttrs.memParams.flags = Memory_CACHED;
    } 
    
    /* Create an output buffer for encoded data */
    hOutBuf = Buffer_create(
        Dmai_roundUp(Senc1_getOutBufSize(hSe1), BUFSIZEALIGN), &bAttrs); 

    if (hOutBuf == NULL) {
        printf("Failed to create contiguous buffer\n");
        goto cleanup;
    }

    /* Create an input buffer for input data */
    hInBuf = Buffer_create(Dmai_roundUp(Senc1_getInBufSize(hSe1), BUFSIZEALIGN),
                           &bAttrs);

    if (hInBuf == NULL) {
        printf("Failed to create contiguous buffer\n");
        goto cleanup;
    }

    while (numFrame++ < args->numFrames) {
        printf("Frame %d: ", numFrame);
        if (args->benchmark) {
            if (Time_reset(hTime) < 0) {
                printf("Failed to reset timer\n");
                goto cleanup;
            }
        }

        /* Read raw PCM data from input file */
        bytesRead = fread(Buffer_getUserPtr(hInBuf), 1,
                          Senc1_getInBufSize(hSe1), inFile);

        if (bytesRead < Senc1_getInBufSize(hSe1)) {
            if (ferror(inFile)) {
                printf("Failed to read data from input file\n");
                goto cleanup;
            }
             printf("Failed to read full frame %ld bytes, read %ld bytes\n",
                                    Senc1_getInBufSize(hSe1),bytesRead);
             goto cleanup;
        }

        Buffer_setNumBytesUsed(hInBuf, bytesRead);

        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                printf("Failed to get timer delta\n");
                goto cleanup;
            }
            printf("Read: %uus ", (Uns) time);
        }

        if (args->cache) {
            /*
             *  To meet xDAIS DMA Rule 7, when input buffers are cached, we
             *  must writeback the cache into physical memory.  Also, per DMA
             *  Rule 7, we must invalidate the output buffer from
             *  cache before providing it to any xDAIS algorithm.
             */
            Memory_cacheWbInv(Buffer_getUserPtr(hInBuf),
                              Buffer_getSize(hInBuf));

            /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
            Memory_cacheInv(Buffer_getUserPtr(hOutBuf),
                            Buffer_getSize(hOutBuf));

            if (args->benchmark) {
                if (Time_delta(hTime, &time) < 0) {
                    printf("Failed to get timer delta\n");
                    goto cleanup;
                }
                printf("Pre-process cache maintenance: %uus ", (Uns) time);
            }
        }

        /* Encode the speech buffer */
        if (Senc1_process(hSe1, hInBuf, hOutBuf) < 0) {
            printf("Failed to encode speech buffer\n");
            goto cleanup;
        }

        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                printf("Failed to get timer delta\n");
                goto cleanup;
            }
            printf("Encode: %uus ", (Uns) time);
        }

        if (args->cache) {
            /* Writeback the outBuf. */
            Memory_cacheWb(Buffer_getUserPtr(hOutBuf), Buffer_getSize(hOutBuf));

            if (args->benchmark) {
                if (Time_delta(hTime, &time) < 0) {
                    printf("Failed to get timer delta\n");
                    goto cleanup;
                }
                printf("Post-process cache write back: %uus ", (Uns) time);
            }
        }

        printf("Write encoded speech data to output file \n");

        /* Write the encoded frame to the file system */
        if (Buffer_getNumBytesUsed(hOutBuf)) {
            if (fwrite(Buffer_getUserPtr(hOutBuf),
                       Buffer_getNumBytesUsed(hOutBuf), 1, outFile) != 1) {
                printf("Failed to write encoded speech data to file\n");
                goto cleanup;
            }
        }

        if (args->benchmark) {
            if (Time_delta(hTime, &time) < 0) {
                printf("Failed to get timer delta\n");
                goto cleanup;
            }
            printf("Write: %uus ", (Uns) time);

            if (Time_total(hTime, &time) < 0) {
                printf("Failed to get timer total\n");
                goto cleanup;
            }

            printf("Total: %uus\n", (unsigned int)time);
        }
    }
cleanup:
    /* Clean up the application */
    if (hSe1) {
        Senc1_delete(hSe1);
    }

    if (hInBuf) {
        Buffer_delete(hInBuf);
    }

    if (hOutBuf) {
        Buffer_delete(hOutBuf);
    }

    if (hEngine) {
        Engine_close(hEngine);
    }

    if (hTime) {
        Time_delete(hTime);
    }

    if (inFile) {
        fclose(inFile);
    }

    if (outFile) {
        fclose(outFile);
    }

    printf("End of application.\n");

    return;
}
예제 #26
0
/**
 *  @brief      The BIOS main() entry point.
 *
 *  @remark     The purpose of this function is to create a BIOS worker task
 *              to house our example.
 *
 *  @remark     This is called during BIOS_init, but before the scheduler
 *              has begun running.
 */
Void main(Int argc, String argv[])
{
    Thread_Params threadParams;
    Engine_Desc    engDesc;
    Engine_AlgDesc algDesc;
    Engine_Error status;

    sprintf(ti_sdo_ce_osal_bios_Global_CE_DEBUG, "1");
    ti_sdo_ce_osal_bios_Global_CE_DEBUG[0] = '2';
    ti_sdo_ce_osal_bios_Global_CE_DEBUG[1] = '\0';

    /* init Codec Engine */
    CERuntime_init();

    /* Enable all trace for xdc.runtime.Main */
    Diags_setMask("xdc.runtime.Main+EX1234567");

    Log_print0(Diags_USER2, "main> ti.sdo.ce.examples.apps.speech1_copy");

    /*
     *  Create the Engine and add our sphdec1_copy and sphenc1_copy algs to
     *  it.  Note, this can also be done in a config script.
     */
     Engine_initDesc(&engDesc);
     engDesc.name = "speech1_copy";
     engDesc.remoteName = NULL;

    status = Engine_add(&engDesc);
    if (status != Engine_EOK) {
        Log_print1(Diags_ERROR, "main-> ERROR: Runtime Engine_add() "
                "failed (0x%x)\n", status);
        /* don't continue */
        while (1) {}
    }

    /*
         *  Add the "sphdecl_copy" and "sphenc1_copy" algs to the
         *  "speech1_copy" engine.
         */

    Engine_initAlgDesc(&algDesc); /* Set fields to defaults */

    algDesc.name = "sphdec1_copy";
    algDesc.fxns = (IALG_Fxns *)&SPHDEC1COPY_TI_ISPHDEC1COPY;
    algDesc.idmaFxns = NULL;
    algDesc.isLocal = TRUE;
    algDesc.groupId = 0;
    algDesc.iresFxns = NULL;
    algDesc.types = SPHDEC1_VISATYPE;

    status = Engine_addAlg("speech1_copy", NULL, NULL, &algDesc);

    if (status != Engine_EOK) {
        Log_print1(Diags_USER7, "App-> ERROR: can't add Alg (0x%x)\n",
                (IArg)status);
        /* don't continue */
        while (1) {}
    }

    algDesc.name = "sphenc1_copy";
    algDesc.fxns = (IALG_Fxns *)&SPHENC1COPY_TI_ISPHENC1COPY;
    algDesc.idmaFxns = NULL;
    algDesc.isLocal = TRUE;
    algDesc.groupId = 0;
    algDesc.iresFxns = NULL;
    algDesc.types = SPHENC1_VISATYPE;

    status = Engine_addAlg("speech1_copy", NULL, NULL, &algDesc);

    if (status != Engine_EOK) {
        Log_print1(Diags_USER7, "App-> ERROR: can't add Alg (0x%x)\n",
                (IArg)status);
        /* don't continue */
        while (1) {}
    }

    /* Spawn a task to run once the BIOS scheduler is started */
    Thread_Params_init(&threadParams);

    /* 6K stack size */
    threadParams.stackSize = 6 * 1024;
    /* task name */
    threadParams.instance->name = taskName;

    /* used for in/out file names */
    threadParams.arg = 0;

    if (Thread_create(workerFxn, &threadParams, NULL) == NULL) {
        System_abort("main: failed to create smain thread.");
    }

    /* Start the BIOS scheduler */
    BIOS_start();
}
/*
 *  ======== main ========
 */
Int main(Int argc, String argv[])
{
    String procId;
    String procSuffix;
    String engineName;
    String mapFileName = NULL;
    String inFile;
    String outFile;
    Char defaultEngineName[32];
    Bool useExtLoader = FALSE;  /* Set to TRUE if using external loader */
    String options = "e:m:p:s:";
    Int option;
    char serverName[MAXSERVERNAMELEN];
    Engine_Error retVal;
    Engine_Desc engDesc;

    /* Initialize defaults. */
    procId = "DSP";
    procSuffix = "x64P";
    engineName = defaultEngineName;
    sprintf(defaultEngineName, "remote_copy_%s", procId);
    inFile = "./in.dat";
    outFile = "./out.dat";

    while ((option = getopt(argc, argv, options)) != -1) {
        switch (option) {
          case 'e':
            engineName = optarg;

            break;

          case 'm':
              /*
               *  If specifying the slave's memory mapping, then assume that
               *  Codec Engine will be loading the slave.
               */
            mapFileName = optarg;
            useExtLoader = FALSE;

            break;

          case 'p':
            procId = optarg;
            sprintf(defaultEngineName, "remote_copy_%s", procId);

            break;

          case 's':
            procSuffix = optarg;

            break;

          default:
            Log_print1(Diags_USER7, " unrecognized option '%c'\n", option);

            break;
        }
    }

    if (argc == (optind + 1)) {
        inFile = argv[optind];
    }
    else if (argc == (optind + 2)) {
        inFile = argv[optind];
        outFile = argv[optind + 1];
    }
    else if (argc != optind) {
        fprintf(stderr, usage, argv[0]);
        exit(1);
    }

    /* init Codec Engine */
    CERuntime_init();

    /* Enable all trace for xdc.runtime.Main */
    Diags_setMask("xdc.runtime.Main+EX1234567");

    Log_print0(Diags_USER2, "main> ti.sdo.ce.examples.apps.universal_copy");

    /*
     * Create the Engine with a remote Server and add register the
     * appropriate stub functions.
     *
     * Note, this can also be done in a config script.
     */
    retVal = Engine_addStubFxns("UNIVERSAL_STUBS",
            (IALG_Fxns *)&UNIVERSAL_STUBS);
    if (retVal != Engine_EOK) {
        printf("App-> ERROR: Runtime Engine_addStubFxns() failed (0x%x)\n",
                retVal);
        /* don't continue */
        while (1) {}
    }

    Engine_initDesc(&engDesc);
    engDesc.name = engineName;
    engDesc.memMap = mapFileName;
    engDesc.useExtLoader = useExtLoader;
    sprintf(serverName, "all_%s.%s", procId, procSuffix);
    engDesc.remoteName = serverName;

    retVal = Engine_add(&engDesc);
    if (retVal != Engine_EOK) {
        Log_print1(Diags_ERROR, "main-> ERROR: Runtime Engine_add() "
                "failed (0x%x)\n", retVal);
        /* don't continue */
        while (1) {}
    }

    return (smain(argv[0], procId, engineName, inFile, outFile));
}
예제 #28
0
파일: rtcfg.c 프로젝트: mobiaqua/ti-ce
/* for backward compatibility with xdc-m based tools */
Void ti_sdo_ce_CERuntime_init__F(Void) {
    CERuntime_init();
}
/* entry point to initialize the plug-in
 * initialize the plug-in itself
 * register the element factories and other features
 */
static gboolean
TICodecPlugin_init (GstPlugin * TICodecPlugin)
{
    Char    *env_value;

    /* Initialize the codec engine run time */
    CERuntime_init();

    /* Initialize DMAI */
    Dmai_init(); 

    env_value = getenv("GST_TI_TIVidenc1_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIVidenc1", GST_RANK_PRIMARY,
        GST_TYPE_TIVIDENC1))
        return FALSE;

    env_value = getenv("GST_TI_TIViddec2_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIViddec2", GST_RANK_PRIMARY,
        GST_TYPE_TIVIDDEC2))
        return FALSE;

    env_value = getenv("GST_TI_TIImgenc1_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIImgenc1", GST_RANK_PRIMARY,
        GST_TYPE_TIIMGENC1))
        return FALSE;

    env_value = getenv("GST_TI_TIImgdec1_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIImgdec1", GST_RANK_PRIMARY,
        GST_TYPE_TIIMGDEC1))
        return FALSE;

    env_value = getenv("GST_TI_TIAuddec1_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIAuddec1", GST_RANK_PRIMARY,
        GST_TYPE_TIAUDDEC1))
        return FALSE;

    env_value = getenv("GST_TI_TIAudenc1_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIAudenc1", GST_RANK_PRIMARY,
        GST_TYPE_TIAUDENC1))
        return FALSE;

    env_value = getenv("GST_TI_TIDmaiVideoSink_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIDmaiVideoSink", GST_RANK_PRIMARY,
        GST_TYPE_TIDMAIVIDEOSINK))
        return FALSE;

    env_value = getenv("GST_TI_TIVidResize_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIVidResize", GST_RANK_PRIMARY,
        GST_TYPE_TIVIDRESIZE))
        return FALSE;

    env_value = getenv("GST_TI_TIPrepEncBuf_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIPrepEncBuf", GST_RANK_PRIMARY,
        GST_TYPE_TIPREPENCBUF))
        return FALSE;

    env_value = getenv("GST_TI_TIDmaiPerf_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "dmaiperf", GST_RANK_PRIMARY,
        GST_TYPE_DMAIPERF))
        return FALSE;

#ifdef HAVE_C6ACCEL
    env_value = getenv("GST_TI_TIC6xColorspace_DISABLE");

    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "TIC6xColorspace", GST_RANK_PRIMARY,
        GST_TYPE_TIC6XCOLORSPACE))
        return FALSE;
#endif

    env_value = getenv("GST_TI_tidisplaysink2_DISABLE");
    if ((!env_value || strcmp(env_value,"1")) && !gst_element_register(
        TICodecPlugin, "tidisplaysink2", GST_RANK_PRIMARY,
        GST_TYPE_TIDISPLAYSINK2))
        return FALSE;

    return TRUE;
}
/******************************************************************************
 * appMain
 ******************************************************************************/
Int main(Int argc, Char *argv[])
{
    UInt32 framesize;
    Memory_AllocParams memParams = Memory_DEFAULTPARAMS;
    
    printf("******************************************************************************\n");
    printf("Sample application for testing kernels in C6Accel started.\n");
    printf("******************************************************************************\n");
    /* This call must be made before the Memory_xxx() functions as it is required for the tracing functions
     in all the codec engine APIs that are used*/
    CERuntime_init();

    /* Reset timeObj used for benchmarking*/
    Time_reset(&sTime);

    /* Create call generates a C6ACCEL handle */
    hC6 = C6accel_create(engineName, NULL,algName, NULL);

    /*Check for failure*/
    if ( hC6 == NULL)
       {printf("%s: C6accel_create() failed \n",progName);
        goto end;
    }

    /* Create buffers for use by algorithms */

    /* Want to use cached & contiguous memory to get best performance from cortex when it also uses the buffers.*/
    memParams.flags = Memory_CACHED;
    memParams.type = Memory_CONTIGHEAP;

    /* Size all buffers for 6 bytes, to cope with worst case 16 bit 422Planar*/
    framesize = (MAX_WIDTH * MAX_HEIGHT * sizeof(Int32)*3/2);

    /* Create 16bit buffers for use by algorithms*/
    pSrcBuf_16bpp = Memory_alloc(framesize, &memParams);
    if (pSrcBuf_16bpp == NULL) {
        goto end;
    }
    else {
       Memory_cacheWbInv(pSrcBuf_16bpp, framesize);
    }
    
      pOutBuf_16bpp = Memory_alloc(framesize, &memParams);
    if (pOutBuf_16bpp == NULL) {
        goto end;
    }
    else {
       Memory_cacheWbInv(pOutBuf_16bpp, framesize);
    }
    
    pRefBuf_16bpp = Memory_alloc(framesize, &memParams);
    if (pRefBuf_16bpp == NULL) {
        goto end;
    }
    else {
       Memory_cacheWbInv(pRefBuf_16bpp, framesize);
    }

      pWorkingBuf_16bpp = Memory_alloc(framesize, &memParams);
    if (pWorkingBuf_16bpp == NULL) {
        goto end;
    }
    else {
       Memory_cacheWbInv(pWorkingBuf_16bpp, framesize);
    }
    
    pWorkingBuf2_16bpp = Memory_alloc(framesize, &memParams);
    if (pWorkingBuf2_16bpp == NULL) {
        goto end;
    }
    else {
       Memory_cacheWbInv(pWorkingBuf2_16bpp, framesize);
    }
  
   #ifdef DEVICE_FLOAT
   pWorkingBuf3_16bpp = Memory_alloc(framesize, &memParams);
    if (pWorkingBuf3_16bpp == NULL) {
        goto end;
    }
    else {
       Memory_cacheWbInv(pWorkingBuf3_16bpp, framesize);
    }
    #endif
    
    /* open file for csv output*/
    OPEN_LOG_FILE("benchmarking.txt");
   
    /* Call test functions for kernels in C6accel*/
    LOG_STRING("IMGLib Functions\n");
    LOG_STRING("640x480 8bit/pixel b/w Test Image \n");
    
    printf("-----------------------------------------------------------------------------\n");
    printf("Test for Image processing functions in C6Accel: \n");
    printf("-----------------------------------------------------------------------------\n");

    c6accel_test_IMG_histogram(hC6,WIDTH,HEIGHT);
    c6accel_test_IMG_median(hC6,WIDTH,HEIGHT);
    c6accel_test_IMG_conv(hC6,WIDTH,HEIGHT);
    c6accel_test_IMG_corr(hC6,WIDTH,HEIGHT);
    c6accel_test_IMG_sobel(hC6,WIDTH,HEIGHT);
    c6accel_test_IMG_muls(hC6,WIDTH,HEIGHT);
    c6accel_test_IMG_adds(hC6,WIDTH,HEIGHT);
    c6accel_test_IMG_subs(hC6,WIDTH,HEIGHT);
    LOG_STRING("800x600 YUYV Test Image \n");
    c6accel_test_IMG_YC_demux(hC6,YUV_WIDTH,YUV_HEIGHT);
    c6accel_test_IMG_YUV422PLtoYUV422SP(hC6,2,16,16,16, 8);
    c6accel_test_IMG_YUV422SPtoYUV422ILE( hC6,2,16,16,32);
    c6accel_test_IMG_YUV422SPtoYUV420PL(hC6,2,16,16,16, 8);
    LOG_STRING("DSPLib Functions\n");
    LOG_STRING("64k sample FFT \n");
    
    printf("-----------------------------------------------------------------------------\n");
    printf("Test for Fixed point Signal processing functions in C6Accel \n");
    printf("-----------------------------------------------------------------------------\n");
    c6accel_test_DSP_FFT(hC6,N);
    c6accel_test_DSP_IFFT(hC6,N);
    c6accel_test_DSP_AUTOCOR(hC6,Nx,Nr);
    c6accel_test_DSP_DOTPROD(hC6,Nr);

    /* Implementation of this function limits
    the rows and columns of matrices to be multiples of 4 and r1 >8 */
    c6accel_test_DSP_MATMUL(hC6,ROW1,COL1,COL2,SHIFT);
    c6accel_test_DSP_FIR(hC6,NOUT,NCOEFF);
    c6accel_test_DSP_IIR(hC6,NXIN,NCOEFF);

  // No need to use these on floating point devices
  #ifndef DEVICE_FLOAT
    LOG_STRING_P1("MATH kernels tested with size of data block %d \n", NMAX+1);
    printf("-----------------------------------------------------------------------------\n");
    printf("Test for Fixed point Math functions in C6Accel\n");
    printf("-----------------------------------------------------------------------------\n");
    c6accel_test_MATH_RTSARITH(hC6,NMAX);
    c6accel_test_MATH_RTSCONV(hC6,NMAX);
    c6accel_test_MATH_IQCONV(hC6,NMAX,GLOBAL_Q, Q1);
    c6accel_test_MATH_IQMATH(hC6,NMAX,GLOBAL_Q);
    c6accel_test_MATH_IQARITH(hC6,NMAX,GLOBAL_Q);
    c6accel_test_MATH_IQTRIG(hC6,NMAX,GLOBAL_Q);
  #endif
  
  #ifdef DEVICE_FLOAT
  /*Test function calls for floating point kernels in C6accel*/ 
    printf("-----------------------------------------------------------------------------\n");
    printf("Test for Floating point Math Functions in C6Accel \n");
    printf("-----------------------------------------------------------------------------\n");
    c6accel_test_MATH_RTSARITH(hC6,NMAX);
    c6accel_test_MATH_RTSCONV(hC6,NMAX); 
    c6accel_test_MATH_RTSFLT(hC6,BUFSIZE) ;
    c6accel_test_MATH_RTSFLTDP(hC6,BUFSIZE) ;
    
    printf("-----------------------------------------------------------------------------\n");
    printf("Test for Floating point Signal processing Functions in C6accel\n");
    printf("-----------------------------------------------------------------------------\n");
    c6accel_test_DSPF_sp_fftSPxSP(hC6, Npt, rad, 0, Npt);
    c6accel_test_DSPF_VECMUL(hC6,  BUFSIZE );
    c6accel_test_DSPF_VECRECIP(hC6,  NumX );
    c6accel_test_DSPF_VECSUM_SQ(hC6,  Nelements );
    c6accel_test_DSPF_W_VEC(hC6, Mfactor,   BUFSIZE );
    c6accel_test_DSPF_DOTPRODFXNS(hC6,  Nelements);
    c6accel_test_DSPF_MATFXNS(hC6,  16,  16,  16 );
    c6accel_test_DSPF_MAT_MUL_CPLX(hC6,  4,  8,  8 ); 
    c6accel_test_DSPF_MAT_TRANS(hC6,  NumR,  NumR );
    c6accel_test_DSPF_AUTOCOR(hC6,NumX,NumR);
    c6accel_test_DSPF_CONVOL(hC6,NumH,NumR); 
    //c6accel_test_DSPF_IIR(hC6,  NumX);
    c6accel_test_DSPF_FIR(hC6, 128,  4);
    c6accel_test_DSPF_sp_ifftSPxSP(hC6, Npt, rad, 0, Npt);
    c6accel_test_DSPF_BIQUAD(hC6,  BUFSIZE);
  #endif   

    CLOSE_LOG_FILE();

end:
     // Tear down C6ACCEL
    if (hC6)
       C6accel_delete(hC6);

    if(pSrcBuf_16bpp)
        Memory_free(pSrcBuf_16bpp, framesize, &memParams);

    if(pOutBuf_16bpp)
        Memory_free(pOutBuf_16bpp, framesize, &memParams);

    if(pRefBuf_16bpp)
        Memory_free(pRefBuf_16bpp, framesize, &memParams);

    if(pWorkingBuf_16bpp)
        Memory_free(pWorkingBuf_16bpp, framesize, &memParams);

    if(pWorkingBuf2_16bpp)
        Memory_free(pWorkingBuf2_16bpp, framesize, &memParams);

    #ifdef DEVICE_FLOAT
    if(pWorkingBuf3_16bpp)
        Memory_free(pWorkingBuf3_16bpp, framesize, &memParams);
    #endif

    printf("******************************************************************************\n");
    printf("All tests done.\n");
    printf("******************************************************************************\n");
    printf("\n");

   return (0);
}