/* 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. * */ #ifndef _DEC_OP_CIRC_BUF_H_ #define _DEC_OP_CIRC_BUF_H_ #include #include "paftyp.h" #define PAF_DECOP_CB_SOK ( 0 ) // ok #define PAF_DECOP_CB_INIT_INV_SOURCE_SEL ( -1 ) // error: invalid source selection on init #define PAF_DECOP_CB_WRITE_OVERFLOW ( -2 ) // error: write overflow #define PAF_DECOP_CB_READ_UNDERFLOW ( -3 ) // error: read underflow #define PAF_DECOP_CB_READ_INVSTATE ( -4 ) // error: circular buffer invalid state on read #define PAF_DECOP_CB_MAX_NUM_AF ( 4 ) // decoder output circular buffer maximum number audio frames #define PAF_DECOP_CB_MAX_NUM_PCM_CH ( 16 ) // decoder output circular buffer maximum number audio PCM channels #define PAF_DECOP_CB_MAX_NUM_PCM_FRAMES ( 2 ) // decoder output circular buffer maximum number PCM frames //Qin - Increased to prevent cb overflow for ddp. #define PAF_DECOP_CB_MAX_PCM_FRAME_LEN ( 6*256 ) // decoder output circular buffer maximum PCM frame length #define PAF_DECOP_CB_PCM_BUF_SZ ( PAF_DECOP_CB_MAX_NUM_PCM_CH * PAF_DECOP_CB_MAX_NUM_PCM_FRAMES * PAF_DECOP_CB_MAX_PCM_FRAME_LEN ) // Decoder output circular buffer typedef struct PAF_AST_DecOpCircBuf { PAF_AudioFrame *afCb; // audio frame CB PAF_AudioData *pcmBuf; // PCM buffer, contains PCM data associated with audio frames UInt8 *metaBuf; // metafdata buffer, contains metadata associated with audio frames //QIN Int8 afRdIdx; // audio frame CB read index Int8 afWrtIdx; // audio frame CB write index Int16 pcmRdIdx; // pcm buffer read index Int8 numAfCb; // current number frames in CB Int8 maxNumAfCb; // maximum number of audio frames in CB Int16 decOpFrameLen; // selected decoder output frame length (input transaction size) Int16 strFrameLen; // stream frame length (output transaction size) Int8 writerActiveFlag; // flag indicates whether CB writer is active Int8 readerActiveFlag; // flag indicates whether CB reader is active Int8 emptyFlag; // flag indicates whether reader should empty (drain) remaining frames in CB Int8 errUndCnt; // underflow count Int8 errOvrCnt; // overflow count } PAF_AST_DecOpCircBuf; // Initialize circular buffer Int cbInit( Int8 sourceSelect, // source select (PCM, DDP, etc.) Int16 decOpFrameLen, // decoder output frame length (PCM samples) Int16 strFrameLen, // stream frame length (PCM samples) PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer Int8 resetRwFlags // whether to reset reader, writer, and empty flags ); // Start writes to circular buffer Int cbWriteStart( PAF_AST_DecOpCircBuf *pCb // decoder output circular buffer ); // Stop writes to circular buffer Int cbWriteStop( PAF_AST_DecOpCircBuf *pCb // decoder output circular buffer ); // Start reads from circular buffer Int cbReadStart( PAF_AST_DecOpCircBuf *pCb // decoder output circular buffer ); // Stop reads from circular buffer Int cbReadStop( PAF_AST_DecOpCircBuf *pCb // decoder output circular buffer ); // Read audio frame from circular buffer Int cbReadAf( PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer PAF_AudioFrame *pAfRd // audio frame into which to read ); // Write audio frame to circular buffer Int cbWriteAf( PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer PAF_AudioFrame *pAfWrt // audio frame from which to write ); // Get next audio frame to write in circular buffer Int cbGetNextWriteAf( PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer PAF_AudioFrame **ppAfWrt // audio frame next to be written ); // Output log of circular buffer control variables (debug) Int cbLog( PAF_AST_DecOpCircBuf *pCb, Int8 fullLog, char *locInfo ); #endif /* _DEC_OP_CIRC_BUF_H_ */