/*
 *  ======== smain ========
 */
Int smain(Int argc, String argv[])
{
    Engine_Handle ce = NULL;
    AUDDEC1_Handle dec = NULL;
    AUDENC1_Handle enc = NULL;
    FILE *in = NULL;
    FILE *out = NULL;
    String inFile, outFile;
    Memory_AllocParams allocParams;

    if (argc <= 1) {
        inFile = "./in.dat";
        outFile = "./out.dat";
        createInFileIfMissing(inFile);
    }
    else if (argc == 3) {
        progName = argv[0];
        inFile = argv[1];
        outFile = argv[2];
    }
    else {
        fprintf(stderr, usage, argv[0]);
        exit(1);
    }

    GT_0trace(curMask, GT_1CLASS, "App-> Application started.\n");

    /* allocate buffers */
    allocParams.type = Memory_CONTIGPOOL;
    allocParams.flags = Memory_NONCACHED;
    allocParams.align = BUFALIGN;
    allocParams.seg = 0;

    inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams);
    encodedBuf = (XDAS_Int8 *)Memory_alloc(EFRAMESIZE, &allocParams);
    outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams);
    versionBuf = (XDAS_Int8 *)Memory_alloc(MAXVERSIONSIZE, &allocParams);

#if USE_ANCDATA
    ancBuf = (XDAS_Int8 *)Memory_alloc(ENCANCBUFSIZE, &allocParams);
    if (ancBuf == NULL) {
        goto end;
    }
#endif

    if ((inBuf == NULL) || (encodedBuf == NULL) || (outBuf == NULL) ||
        (versionBuf == NULL)) {

        goto end;
    }

    /* open file streams for input and output */
    if ((in = fopen(inFile, "rb")) == NULL) {
        printf("App-> ERROR: can't read file %s\n", inFile);
        goto end;
    }
    if ((out = fopen(outFile, "wb")) == NULL) {
        printf("App-> ERROR: can't write to file %s\n", outFile);
        goto end;
    }

    /* reset, load, and start DSP Engine */
    if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) {
        fprintf(stderr, "%s: error: can't open engine %s\n",
            progName, engineName);
        goto end;
    }

    /* allocate and initialize video decoder on the engine */
    dec = AUDDEC1_create(ce, decoderName, NULL);
    if (dec == NULL) {
        printf( "App-> ERROR: can't open codec %s\n", decoderName);
        goto end;
    }

    /* allocate and initialize video encoder on the engine */
    enc = AUDENC1_create(ce, encoderName, NULL);
    if (enc == NULL) {
        fprintf(stderr, "%s: error: can't open codec %s\n",
            progName, encoderName);
        goto end;
    }

    /* use engine to encode, then decode the data */
    encode_decode(enc, dec, in, out);

end:
    /* teardown the codecs */
    if (enc) {
        AUDENC1_delete(enc);
    }
    if (dec) {
        AUDDEC1_delete(dec);
    }

    /* close the engine */
    if (ce) {
        Engine_close(ce);
    }

    /* close the files */
    if (in) {
        fclose(in);
    }
    if (out) {
        fclose(out);
    }

    /* free buffers */
    if (inBuf) {
        Memory_free(inBuf, IFRAMESIZE, &allocParams);
    }
    if (encodedBuf) {
        Memory_free(encodedBuf, EFRAMESIZE, &allocParams);
    }
    if (outBuf) {
        Memory_free(outBuf, OFRAMESIZE, &allocParams);
    }
    if (versionBuf) {
        Memory_free(versionBuf, MAXVERSIONSIZE, &allocParams);
    }

#if USE_ANCDATA
    if (ancBuf) {
        Memory_free(ancBuf, ENCANCBUFSIZE, &allocParams);
    }
#endif

    GT_0trace(curMask, GT_1CLASS, "app done.\n");
    return (0);
}
Ejemplo n.º 2
0
DvevmStRetCode
dvtb_wmaEnc1Init(DvevmStWmaEnc1Info *ae)
{
    DvevmStRetCode retCode = DVEVM_ST_SUCCESS;
    ASSERT(ae != NULL);
    ASSERT(ae->ceHdl != NULL);
    ASSERT(ae->aenc1Name[0] != 0);

    ae->ancBuf.start = NULL;
    ae->inBuf.numBufs = 0;
    ae->outBuf.numBufs = 0;

    dvtb_wmaCreateDebug(ae);
    if (NULL == (ae->aenc1Hdl = (AUDENC1_Handle) AUDENC1_create(ae->ceHdl, ae->aenc1Name, (IAUDENC1_Params *) &ae->aenc1Params)))
    {
        SYS_ERROR("Unable to initialize Audio Encoder\n");
        retCode = DVEVM_ST_FAIL;
    }
    else
    {
        ae->ancBuf.size = 14;

#if 1
        ae->aenc1Cmd = XDM_SETPARAMS;
        if (DVEVM_ST_FAIL == dvtb_wmaEnc1Control(ae))
        {
            SYS_ERROR("Unable to set the dynamic parameters \n");
            retCode = DVEVM_ST_FAIL;
        }
        else
#endif
        {
            ae->aenc1Cmd = XDM_GETBUFINFO;
            if (DVEVM_ST_FAIL == dvtb_wmaEnc1Control(ae))
            {
                SYS_ERROR("Unable to get the input/output buffer information\n");
                retCode = DVEVM_ST_FAIL;
            }
            else if (DVEVM_ST_FAIL == dvtb_allocCmemXdm1BufDesc(&ae->inBuf))
            {
                SYS_ERROR("Unable to allocate memory for In Buffer\n");
                retCode = DVEVM_ST_FAIL;
            }
            else if (DVEVM_ST_FAIL == dvtb_allocCmemXdm1BufDesc(&ae->outBuf))
            {
                SYS_ERROR("Unable to allocate memory for Out Buffer\n");
                retCode = DVEVM_ST_FAIL;
            }
            else if (NULL == (ae->ancBuf.start = Memory_contigAlloc(ae->ancBuf.size, Memory_DEFAULTALIGNMENT)))
            {
                SYS_ERROR("Unable to allocate memory for Out Buffer\n");
                retCode = DVEVM_ST_FAIL;
            }
            else
            {
                SYS_DEBUG("\tAudio Encoder %s initialized.\n", ae->aenc1Name);
                memcpy(ae->ancBuf.start, "DVTB Encoded", ae->ancBuf.size);
                SYS_DEBUG("\tancBuf.start :%x\n", (unsigned int) ae->ancBuf.start);
            }
        }
    }
    if(DVEVM_ST_FAIL == retCode)
        dvtb_wmaEnc1Cleanup(ae);
    return retCode;
}
Ejemplo n.º 3
0
/*
 *  ======== smain ========
 */
Int smain(Int argc, String argv[])
{
    Engine_Handle ce = NULL;
    AUDDEC1_Handle dec = NULL;
    AUDENC1_Handle enc = NULL;
    FILE *in = NULL;
    FILE *out = NULL;
    String inFile, outFile;
    Int i;

    if (argc <= 1) {
        inFile = "../in.dat";
        outFile = "../out.dat";
    }
    else if (argc == 3) {
        progName = argv[0];
        inFile = argv[1];
        outFile = argv[2];
    }
    else {
        fprintf(stderr, usage, argv[0]);
        exit(1);
    }

    GT_0trace(curMask, GT_1CLASS, "App-> Application started.\n");

    /* allocate input, encoded, output, and version buffers */
    for (i = 0; i < NBUFFERS; i++) {
        inBuf[i] = (XDAS_Int8 *)Memory_contigAlloc(IFRAMESIZE, BUFALIGN);
        encodedBuf[i] = (XDAS_Int8 *)Memory_contigAlloc(EFRAMESIZE, BUFALIGN);
        outBuf[i] = (XDAS_Int8 *)Memory_contigAlloc(OFRAMESIZE, BUFALIGN);
#if USE_ANCDATA
        ancBuf[i] = (XDAS_Int8 *)Memory_contigAlloc(ENCANCBUFSIZE, BUFALIGN);
        if (ancBuf[i] == NULL) {
            goto end;
        }
#endif

        if ((inBuf[i] == NULL) || (encodedBuf[i] == NULL) ||
            (outBuf[i] == NULL)) {

            goto end;
        }
    }
    /* we need one more encoded buffer than the others */
    encodedBuf[NBUFFERS] = (XDAS_Int8 *)Memory_contigAlloc(EFRAMESIZE,
                                        BUFALIGN);
    if (encodedBuf[NBUFFERS] == NULL) {
        goto end;
    }

    versionBuf = (XDAS_Int8 *)Memory_contigAlloc(MAXVERSIONSIZE, BUFALIGN);
    if (versionBuf == NULL) {
        goto end;
    }

    /* open file streams for input and output */
    if ((in = fopen(inFile, "rb")) == NULL) {
        printf("App-> ERROR: can't read file %s\n", inFile);
        goto end;
    }
    if ((out = fopen(outFile, "wb")) == NULL) {
        printf("App-> ERROR: can't write to file %s\n", outFile);
        goto end;
    }

    /* reset, load, and start DSP Engine */
    if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) {
        fprintf(stderr, "%s: error: can't open engine %s\n",
            progName, engineName);
        goto end;
    }

    /* allocate and initialize video decoder on the engine */
    dec = AUDDEC1_create(ce, decoderName, NULL);
    if (dec == NULL) {
        printf( "App-> ERROR: can't open codec %s\n", decoderName);
        goto end;
    }

    /* allocate and initialize video encoder on the engine */
    enc = AUDENC1_create(ce, encoderName, NULL);
    if (enc == NULL) {
        fprintf(stderr, "%s: error: can't open codec %s\n",
            progName, encoderName);
        goto end;
    }

    /* use engine to encode, then decode the data */
    encode_decode(enc, dec, in, out);

end:
    /* teardown the codecs */
    if (enc) {
        AUDENC1_delete(enc);
    }
    if (dec) {
        AUDDEC1_delete(dec);
    }

    /* close the engine */
    if (ce) {
        Engine_close(ce);
    }

    /* close the files */
    if (in) {
        fclose(in);
    }
    if (out) {
        fclose(out);
    }

    /* free buffers */
    for (i = 0; i < NBUFFERS; i++) {
        if (inBuf[i]) {
            Memory_contigFree(inBuf[i], IFRAMESIZE);
        }
        if (encodedBuf[i]) {
            Memory_contigFree(encodedBuf[i], EFRAMESIZE);
        }
        if (outBuf[i]) {
            Memory_contigFree(outBuf[i], OFRAMESIZE);
        }
#if USE_ANCDATA
        if (ancBuf[i]) {
            Memory_contigFree(ancBuf[i], ENCANCBUFSIZE);
        }
#endif
    }
    if (encodedBuf[NBUFFERS]) {
        Memory_contigFree(encodedBuf[NBUFFERS], EFRAMESIZE);
    }
    if (versionBuf) {
        Memory_contigFree(versionBuf, MAXVERSIONSIZE);
    }

    GT_0trace(curMask, GT_1CLASS, "app done.\n");
    return (0);
}