/*
 *  ======== encode_decode ========
 */
static Void encode_decode(AUDENC1_Handle enc, AUDDEC1_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    AUDDEC1_InArgs              decInArgs;
    AUDDEC1_OutArgs             decOutArgs;
    AUDDEC1_DynamicParams       decDynParams;
    AUDDEC1_Status              decStatus;

    AUDENC1_InArgs              encInArgs;
    AUDENC1_OutArgs             encOutArgs;
    AUDENC1_DynamicParams       encDynParams;
    AUDENC1_Status              encStatus;

    XDM1_BufDesc                inBufDesc;
    XDM1_BufDesc                encodedBufDesc;
    XDM1_BufDesc                outBufDesc;

    /* initialize the buffer descriptors */
    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;
    inBufDesc.descs[0].bufSize = encodedBufDesc.descs[0].bufSize =
        outBufDesc.descs[0].bufSize = NSAMPLES;

    inBufDesc.descs[0].buf      = inBuf;
    encodedBufDesc.descs[0].buf = encodedBuf;
    outBufDesc.descs[0].buf     = outBuf;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /* ancillary data to encode */
#if USE_ANCDATA
    encInArgs.ancData.buf = ancBuf;
    encInArgs.ancData.bufSize = ENCANCBUFSIZE;
#else
    /* Be sure to initialize these to NULL! */
    encInArgs.ancData.buf = NULL;
    encInArgs.ancData.bufSize = 0;
#endif
    /*
     * Note that we use versionBuf in both the encoder and decoder.  In this
     * application, this is okay, as there is always only one user of
     * the buffer.  Not all applications can make this assumption.
     */
    encStatus.data.buf     = decStatus.data.buf     = versionBuf;
    encStatus.data.bufSize = decStatus.data.bufSize = MAXVERSIONSIZE;

    /* if the codecs support it, dump their versions */
    status = AUDDEC1_control(dec, XDM_GETVERSION, &decDynParams, &decStatus);
    GT_1trace(curMask, GT_1CLASS, "Decoder version:  %s\n",
        (status == AUDDEC1_EOK ? ((char *)decStatus.data.buf) : "[unknown]"));

    status = AUDENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus);
    GT_1trace(curMask, GT_1CLASS, "Encoder version:  %s\n",
        (status == AUDENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]"));

    /*
     * This app expects the encoder to accept 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = AUDENC1_control(enc, XDM_GETBUFINFO, &encDynParams, &encStatus);
    if (status != AUDENC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = %ld\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }

    status = AUDDEC1_control(dec, XDM_GETBUFINFO, &decDynParams, &decStatus);
    if (status != AUDDEC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = %ld\n", status);
        return;
    }

    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) {

#if USE_ANCDATA
        /* we send the same data as inBuf as ancillory data */
        memcpy(ancBuf, inBuf, ENCANCBUFSIZE);
#endif

        /* Deal with cache issues, if necessary */
#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif

#if USE_ANCDATA
        /* ancBuf is an inBuf, filled via memcpy (i.e. CPU writes) */
        Memory_cacheWbInv(ancBuf, ENCANCBUFSIZE);
#endif

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, EFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n);

        /*
         * Encode the frame.  Note that .numInSamples is the number of
         * _samples_ not bytes.  IFRAMESIZE is in 8-bit bytes, so there's a
         * little math here to get .numInSamples right.
         */
        encInArgs.numInSamples =
            (IFRAMESIZE / (ENCBITSPERSAMPLE / (8 /* bits per byte */)));
        status = AUDENC1_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x)\n",
            n, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, EFRAMESIZE);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        if (status != AUDENC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, encOutArgs.extendedError);
            break;
        }

        /* decode the frame */
        decInArgs.numBytes = EFRAMESIZE;
        status = AUDDEC1_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x)\n",
            n, status);

        if (status != AUDDEC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }

#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, OFRAMESIZE);
#endif
        /* write to file */
        fwrite(outBuf, OFRAMESIZE, 1, out);
    }

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}
Ejemplo n.º 2
0
DvevmStRetCode
dvtb_wmaEnc1Encode(DvevmStWmaEnc1Info *ae, int *encDuration)
{
    XDAS_Int32 status = -1;
    ITTIAM_WMAENC_InArgs enc1InArgs;
    ITTIAM_WMAENC_OutArgs enc1OutArgs;
    DvevmStTime timeStmpBfrEnc, timeStmpAftrEnc;
    DvevmStRetCode retCode = DVEVM_ST_SUCCESS;
    ASSERT(ae != NULL);
    ASSERT(ae->ceHdl != NULL);
    ASSERT(ae->aenc1Hdl != NULL);

    enc1OutArgs.audenc_outArgs.size = sizeof(ITTIAM_WMAENC_OutArgs);

    enc1InArgs.audenc_inArgs.size = sizeof(ITTIAM_WMAENC_InArgs);
    enc1InArgs.audenc_inArgs.numInSamples = ae->insamples;
    if (ae->aenc1Params.audenc_params.ancFlag)
    {
        enc1InArgs.audenc_inArgs.ancData.bufSize = ae->ancBuf.size;
        enc1InArgs.audenc_inArgs.ancData.buf = (XDAS_Int8 *) ae->ancBuf.start;
    }
    else
    {
        enc1InArgs.audenc_inArgs.ancData.bufSize = 0;
        enc1InArgs.audenc_inArgs.ancData.buf = NULL;
    }

    dvtb_wmaProcessDebug(ae);

    timeStmpBfrEnc = dvtb_getTime( );
    status = AUDENC1_process((AUDENC1_Handle) ae->aenc1Hdl, &ae->inBuf, &ae->outBuf, (IAUDENC1_InArgs *) &enc1InArgs, (IAUDENC1_OutArgs *) &enc1OutArgs);
    timeStmpAftrEnc = dvtb_getTime( );

    *encDuration = ((timeStmpAftrEnc.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpAftrEnc.tv_usec) - ((timeStmpBfrEnc.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpBfrEnc.tv_usec);

    ae->Framenum++;

    SYS_DEBUG("\tCurr frame number : %d\n", ae->Framenum);

    ae->outsamples = enc1OutArgs.audenc_outArgs.bytesGenerated;

    if (status != IAUDENC1_EOK)
    {
        SYS_ERROR("Error (%d) in Audio Encoder Process\n", (int) status);
        SYS_ERROR("Codec Error => %d\n", (int) enc1OutArgs.audenc_outArgs.extendedError);
        SYS_ERROR("End of execution                => %d\n", (int) enc1OutArgs.i_exec_done);
        SYS_ERROR("i_num_samples_in_packet         => %d\n", (int) enc1OutArgs.i_num_samples_in_packet);

        retCode = DVEVM_ST_FAIL;
    }
    if (DVEVM_ST_FAIL != retCode)
    {

        ae->aenc1Cmd = XDM_GETSTATUS;

        if (DVEVM_ST_FAIL == dvtb_wmaEnc1Control(ae))
        {
            SYS_ERROR("Unable to get status info\n");
        }
        SYS_DEBUG("\tBytes Generated after STATUSCALL=> %d\n", (int) enc1OutArgs.audenc_outArgs.bytesGenerated);
        SYS_DEBUG("\tEnd of execution                => %d\n", (int) enc1OutArgs.i_exec_done);
        ae->consumedSamples = enc1OutArgs.audenc_outArgs.numInSamples;

    }

    return retCode;
}
Ejemplo n.º 3
0
/*
 *  ======== call ========
 */
static VISA_Status call(VISA_Handle visaHandle, VISA_Msg visaMsg)
{
    _AUDENC1_Msg *msg  = (_AUDENC1_Msg *)visaMsg;
    AUDENC1_Handle handle = (AUDENC1_Handle)visaHandle;
    Int i;
    XDM1_BufDesc inBufs, outBufs;
    IAUDENC1_OutArgs *pOutArgs;
    IAUDENC1_Status *pStatus;
    Int numBufs;

    /* perform the requested AUDENC1 operation by parsing message. */
    switch (msg->visa.cmd) {

        case _AUDENC1_CPROCESS: {
            /* unmarshal inBufs and outBufs */
            inBufs = msg->cmd.process.inBufs;
            outBufs = msg->cmd.process.outBufs;
            if (SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB) {
                /* invalidate cache for all input buffers */
                for (i = 0, numBufs = 0; i < XDM_MAX_IO_BUFFERS; i++) {
                    if (inBufs.descs[i].buf != NULL) {
                        /* valid member of sparse array, manage it */
                        Memory_cacheInv(inBufs.descs[i].buf,
                                inBufs.descs[i].bufSize);

                        if (++numBufs == inBufs.numBufs) {
                            break;
                        }
                    }
                }

                /* invalidate cache for buffers in inArgs */
                if (msg->cmd.process.inArgs.ancData.buf != NULL) {
                    Memory_cacheInv(msg->cmd.process.inArgs.ancData.buf,
                            msg->cmd.process.inArgs.ancData.bufSize);
                }

                /* invalidate cache for all output buffers */
                for (i = 0, numBufs = 0; i < XDM_MAX_IO_BUFFERS; i++) {
                    if (outBufs.descs[i].buf != NULL) {
                        /* valid member of sparse array, manage it */
                        Memory_cacheInv(outBufs.descs[i].buf,
                                outBufs.descs[i].bufSize);

                        if (++numBufs == outBufs.numBufs) {
                            break;
                        }
                    }
                }
            }

            /* unmarshall outArgs based on the "size" of inArgs */
            pOutArgs = (IAUDENC1_OutArgs *)((UInt)(&(msg->cmd.process.inArgs)) +
                msg->cmd.process.inArgs.size);

            /* make the process call */
            msg->visa.status = AUDENC1_process(handle,
                &inBufs, &outBufs, &(msg->cmd.process.inArgs), pOutArgs);

            if (SKEL_cachingPolicy == SKEL_WBINVALL) {
                Memory_cacheWbInvAll();
            }
            else if (SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB) {
                /* writeback cache for all output buffers  */
                for (i = 0, numBufs = 0; i < XDM_MAX_IO_BUFFERS; i++) {
                    if ((outBufs.descs[i].buf != NULL) &&
                        XDM_ISACCESSMODE_WRITE(outBufs.descs[i].accessMask)) {

                        /* valid member of sparse array, written to via CPU */
                        Memory_cacheWb(outBufs.descs[i].buf,
                                outBufs.descs[i].bufSize);

                        /*
                         * Since we've cacheWb this buffer, we arguably should
                         * reflect this cache state and clear the WRITE bit in
                         * the .accessMask field.  However, we know the stub
                         * doesn't propogate this field to the calling app, so
                         * this extra buffer management detail isn't necessary:
                         *
                         * XDM_CLEARACCESSMODE_WRITE(outBufs.descs[i].accessMask);
                         */

                        if (++numBufs == outBufs.numBufs) {
                            break;
                        }
                    }
                }
            }

            /*
             * Note that any changes to individual outBufs[i] values made by
             * the codec will automatically update msg->cmd.process.outBufs
             * as we pass the outBufs array by reference.
             */

            break;
        }

        case _AUDENC1_CCONTROL: {
            /* unmarshall status based on the "size" of params */
            pStatus = (IAUDENC1_Status *)((UInt)(&(msg->cmd.control.params)) +
                msg->cmd.control.params.size);

            /* invalidate data buffer */
            if (pStatus->data.buf != NULL) {
                Memory_cacheInv(pStatus->data.buf, pStatus->data.bufSize);
            }

            msg->visa.status = AUDENC1_control(handle, msg->cmd.control.id,
                &(msg->cmd.control.params), pStatus);

            /* writeback data buffer */
            if ((pStatus->data.buf != NULL) &&
                XDM_ISACCESSMODE_WRITE(pStatus->data.accessMask)) {

                Memory_cacheWb(pStatus->data.buf, pStatus->data.bufSize);

                /*
                 * Since we've cacheWb this buffer, we arguably should
                 * reflect this cache state and clear the WRITE bit in
                 * the .accessMask field.  However, we know the stub
                 * doesn't propogate this field to the calling app, so
                 * this extra buffer management detail isn't necessary:
                 *
                 * XDM_CLEARACCESSMODE_WRITE(pStatus->data.accessMask);
                 */
            }

            break;
        }

        default: {
            msg->visa.status = VISA_EFAIL;

            break;
        }
    }
    return (VISA_EOK);
}