DvevmStRetCode dvtb_audEncEncode(DvevmStAudEncInfo *ae, int *encDuration) { int i = 0; XDM_BufDesc inBufDesc, outBufDesc; XDAS_Int32 status = -1; IAUDENC_InArgs encInArgs; IAUDENC_OutArgs encOutArgs; DvevmStRetCode retCode = DVEVM_ST_SUCCESS; DvevmStTime timeStmpBfrEnc, timeStmpAftrEnc; ASSERT(ae != NULL); ASSERT(ae->ceHdl != NULL); ASSERT(ae->aencHdl != NULL); for (i = 0; i < ae->inBuf.numBufs; i++) ASSERT(ae->inBuf.bufs[i] != NULL); inBufDesc.bufSizes = (XDAS_Int32 *) &ae->inBuf.bufSizes; for (i = 0; i < ae->outBuf.numBufs; i++) ASSERT(ae->outBuf.bufs[i] != NULL); outBufDesc.bufSizes = (XDAS_Int32 *) &ae->outBuf.bufSizes; inBufDesc.numBufs = ae->inBuf.numBufs; outBufDesc.numBufs = ae->outBuf.numBufs; inBufDesc.bufs = (XDAS_Int8 **) ae->inBuf.bufs; outBufDesc.bufs = (XDAS_Int8 **) ae->outBuf.bufs; encInArgs.size = sizeof(encInArgs); encOutArgs.size = sizeof(encOutArgs); timeStmpBfrEnc = dvtb_getTime( ); status = AUDENC_process(ae->aencHdl, &inBufDesc, &outBufDesc, &encInArgs, &encOutArgs); timeStmpAftrEnc = dvtb_getTime( ); *encDuration = ((timeStmpAftrEnc.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpAftrEnc.tv_usec) - ((timeStmpBfrEnc.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpBfrEnc.tv_usec); if (status != AUDENC_EOK) { SYS_ERROR("Error (%d) in Audio Encoder Process\n", (int) status); retCode = DVEVM_ST_FAIL; } return retCode; }
/* * ======== call ======== */ static VISA_Status call(VISA_Handle visaHandle, VISA_Msg visaMsg) { _AUDENC_Msg *msg = (_AUDENC_Msg *)visaMsg; AUDENC_Handle handle = (AUDENC_Handle)visaHandle; Int i; XDM_BufDesc inBufs, outBufs; IAUDENC_OutArgs *pOutArgs; IAUDENC_Status *pStatus; /* perform the requested AUDENC operation by parsing message. */ switch (msg->visa.cmd) { case _AUDENC_CPROCESS: { /* unmarshall inBufs and outBufs since they differ in shape * from what their flattened versions passed in the message */ inBufs.bufs = msg->cmd.process.inBufs; inBufs.numBufs = msg->cmd.process.numInBufs; inBufs.bufSizes = msg->cmd.process.inBufSizes; outBufs.bufs = msg->cmd.process.outBufs; outBufs.numBufs = msg->cmd.process.numOutBufs; outBufs.bufSizes = msg->cmd.process.outBufSizes; if (SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB) { /* invalidate cache for all input buffers */ for (i = 0; i < inBufs.numBufs; i++) { Memory_cacheInv(inBufs.bufs[i], inBufs.bufSizes[i]); } /* invalidate cache for all output buffers */ for (i = 0; i < outBufs.numBufs; i++) { Memory_cacheInv(outBufs.bufs[i], outBufs.bufSizes[i]); } } /* unmarshall outArgs based on the "size" of inArgs */ pOutArgs = (IAUDENC_OutArgs *)((UInt)(&(msg->cmd.process.inArgs)) + msg->cmd.process.inArgs.size); /* make the process call */ msg->visa.status = AUDENC_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; i < outBufs.numBufs; i++) { Memory_cacheWb(outBufs.bufs[i], outBufs.bufSizes[i]); } } /* * 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 _AUDENC_CCONTROL: { /* unmarshall status based on the "size" of params */ pStatus = (IAUDENC_Status *)((UInt)(&(msg->cmd.control.params)) + msg->cmd.control.params.size); msg->visa.status = AUDENC_control(handle, msg->cmd.control.id, &(msg->cmd.control.params), pStatus); break; } default: { msg->visa.status = VISA_EFAIL; break; } } return (VISA_EOK); }
/* * ======== encode_decode ======== */ static Void encode_decode(AUDENC_Handle enc, AUDDEC_Handle dec, FILE *in, FILE *out) { Int n; Int32 status; AUDDEC_InArgs decInArgs; AUDDEC_OutArgs decOutArgs; AUDDEC_DynamicParams decDynParams; AUDDEC_Status decStatus; AUDENC_InArgs encInArgs; AUDENC_OutArgs encOutArgs; AUDENC_DynamicParams encDynParams; AUDENC_Status encStatus; XDM_BufDesc inBufDesc; XDAS_Int8 *src[XDM_MAX_IO_BUFFERS]; XDAS_Int32 inBufSizes[XDM_MAX_IO_BUFFERS]; XDM_BufDesc encodedBufDesc; XDAS_Int8 *encoded[XDM_MAX_IO_BUFFERS]; XDAS_Int32 encBufSizes[XDM_MAX_IO_BUFFERS]; XDM_BufDesc outBufDesc; XDAS_Int8 *dst[XDM_MAX_IO_BUFFERS]; XDAS_Int32 outBufSizes[XDM_MAX_IO_BUFFERS]; /* clear and initialize the buffer descriptors */ memset(src, 0, sizeof(src[0]) * XDM_MAX_IO_BUFFERS); memset(encoded, 0, sizeof(encoded[0]) * XDM_MAX_IO_BUFFERS); memset(dst, 0, sizeof(dst[0]) * XDM_MAX_IO_BUFFERS); src[0] = inBuf; encoded[0] = encodedBuf; dst[0] = outBuf; inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1; inBufDesc.bufSizes = inBufSizes; encodedBufDesc.bufSizes = encBufSizes; outBufDesc.bufSizes = outBufSizes; inBufSizes[0] = encBufSizes[0] = outBufSizes[0] = NSAMPLES; inBufDesc.bufs = src; encodedBufDesc.bufs = encoded; outBufDesc.bufs = dst; /* 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); /* * Query the encoder and decoder. * 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 = AUDENC_control(enc, XDM_GETSTATUS, &encDynParams, &encStatus); if (status != AUDENC_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 = AUDDEC_control(dec, XDM_GETSTATUS, &decDynParams, &decStatus); if (status != AUDDEC_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++) { /* 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 /* 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 */ status = AUDENC_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 != AUDENC_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 = AUDDEC_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs, &decOutArgs); GT_2trace(curMask, GT_2CLASS, "App-> Decoder frame %d process returned - 0x%x)\n", n, status); if (status != AUDDEC_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(dst[0], OFRAMESIZE, 1, out); } GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n); }