/* Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/ All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include // for memset() #include #include #include #include #include "aspDecOpCircBuf_common.h" // Reset circular buffer Int cbReset( PAF_AST_DecOpCircBufCtl *pCbCtl, Int8 cbIdx ) { IArg key; GateMP_Handle gateHandle; PAF_AST_DecOpCircBuf *pCb; PAF_AudioFrame *pAfCb; Int8 n; Int8 i; // Get gate handle gateHandle = pCbCtl->gateHandle; // Enter gate key = GateMP_enter(gateHandle); // Get circular buffer base pointer pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]); // Invalidate circular buffer configuration Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); Cache_wait(); if (pCb->sourceSel == PAF_SOURCE_PCM) { // 2*256 in behind pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM; pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_PCM; pCb->pcmRdIdx = 0; } else if (pCb->sourceSel == PAF_SOURCE_DDP) { // 4*256 in behind pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP; pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DDP; pCb->pcmRdIdx = pCb->decOpFrameLen - ASP_DECOP_CB_INIT_LAG_DDP*pCb->strFrameLen; } else if (pCb->sourceSel == PAF_SOURCE_THD) { // 0 in behind pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_THD; pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_THD; pCb->pcmRdIdx = 0; } else if ((pCb->sourceSel == PAF_SOURCE_DTS) || (pCb->sourceSel == PAF_SOURCE_DTSHD) || (pCb->sourceSel == PAF_SOURCE_DTS12) || (pCb->sourceSel == PAF_SOURCE_DTS13) || (pCb->sourceSel == PAF_SOURCE_DTS14) || (pCb->sourceSel == PAF_SOURCE_DTS16) || (pCb->sourceSel == PAF_SOURCE_DTSALL) ) { pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DTS; pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DTS; pCb->pcmRdIdx = pCb->decOpFrameLen - ASP_DECOP_CB_INIT_LAG_DTS*pCb->strFrameLen; } // initialize circular buffer current number of frames pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx; for (n=0; nmaxNumAfCb; n++) { pAfCb = &pCb->afCb[n]; // clear PCM data for (i=0; imaxAFChanNum; i++) { memset(pAfCb->data.sample[i], 0, pCb->maxAFSampCount); } // clear metadata pAfCb->numPrivateMetadata = 0; } // reset error counts pCb->errUndCnt = 0; pCb->errOvrCnt = 0; // Write back circular buffer configuration Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); // Write back AF circular buffer Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0); for (n=0; nmaxNumAfCb; n++) { pAfCb = &pCb->afCb[n]; for (i=0; imaxAFChanNum; i++) { Cache_wb(pAfCb->data.sample[i], pCb->maxAFSampCount*sizeof(PAF_AudioData), Cache_Type_ALLD, 0); } } Cache_wait(); // Leave the gate GateMP_leave(gateHandle, key); return ASP_DECOP_CB_SOK; } // Output log of circular buffer control variables (debug) Int cbLog( PAF_AST_DecOpCircBufCtl *pCbCtl, Int8 cbIdx, Int8 fullLog, char *locInfo ) { IArg key; GateMP_Handle gateHandle; PAF_AST_DecOpCircBuf *pCb; // Get gate handle gateHandle = pCbCtl->gateHandle; // Enter gate key = GateMP_enter(gateHandle); // Get circular buffer base pointer pCb = &(*pCbCtl->pXDecOpCb)[cbIdx]; // Invalidate circular buffer configuration. Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); Cache_wait(); Log_info1("CB: %s", (IArg)locInfo); Log_info3("CB: readerActiveFlag=%d, writerActiveFlag=%d, emptyFlag=%d", pCb->readerActiveFlag, pCb->writerActiveFlag, pCb->emptyFlag); Log_info4("CB: afRdIdx=%d, pcmRdIdx=%d, afWrtIdx=%d, numAfCb=%d", pCb->afRdIdx, pCb->pcmRdIdx, pCb->afWrtIdx, pCb->numAfCb); if (fullLog) { Log_info1("CB: maxNumAfCb=%d", pCb->maxNumAfCb); Log_info2("CB: decOpFrameLen=%d, strFrameLen=%d", pCb->decOpFrameLen, pCb->strFrameLen); //Log_info1("cbWriteInit=%d", pCb->cbWriteAfInit); } // Leave the gate GateMP_leave(gateHandle, key); return ASP_DECOP_CB_SOK; }