2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 #ifndef _ASP_DECOP_CB_COMMON_H_
37 #define _ASP_DECOP_CB_COMMON_H_
39 #include <xdc/std.h>
40 #include <ti/ipc/GateMP.h>
41 #include "paftyp.h"
42 #include "pafdec.h"
43 #define ASP_DECOP_CB_SOK ( 0 ) // ok
44 #define ASP_DECOP_CB_CTL_INIT_INV_GATE ( ASP_DECOP_CB_SOK-1 ) // error: invalid gate handle
45 #define ASP_DECOP_CB_ERR_START ( ASP_DECOP_CB_CTL_INIT_INV_GATE )
46 #define ASP_DECOP_CB_MAX_NUM_AF ( 10 ) // decoder output circular buffer maximum number audio frames
47 #define ASP_DECOP_CB_MAX_NUM_PCM_CH ( 16 ) // decoder output circular buffer maximum number audio PCM channels
48 #define ASP_DECOP_CB_MAX_NUM_PCM_FRAMES ( 10 ) // decoder output circular buffer maximum number PCM frames //Qin - Increased to prevent cb overflow for ddp.
49 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN ( 6*256 ) // decoder output circular buffer maximum PCM frame length
51 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_DDP ( 16 ) // decoder output circular buffer maximum number audio PCM channels for DDP
52 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kDDP ( 6*256 ) // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
54 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT ( 32 ) // decoder output circular buffer maximum number audio PCM channels for MAT
55 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT ( 4*256 ) // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
57 #define ASP_DECOP_CB_PCM_BUF_SZ ( ASP_DECOP_CB_MAX_NUM_PCM_CH * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN )
58 #define ASP_DECOP_CB_PCM_BUF_SZ_32CH48kMAT ( ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT )
60 #define ASP_DECOP_CB_MAX_NUM_AF_PCM ( 4 )
61 #define ASP_DECOP_CB_INIT_LAG_PCM ( 2 ) // 1...3
62 #define ASP_DECOP_CB_INIT_WRTIDX_PCM ( ASP_DECOP_CB_INIT_LAG_PCM )
63 #define ASP_DECOP_CB_INIT_RDIDX_PCM ( 0 )
65 #define ASP_DECOP_CB_MAX_NUM_AF_DDP ( 2 )
66 #define ASP_DECOP_CB_INIT_LAG_DDP ( 4 ) // 0...5
67 #define ASP_DECOP_CB_INIT_WRTIDX_DDP ( 1 )
68 #define ASP_DECOP_CB_INIT_RDIDX_DDP ( 0 )
70 #define ASP_DECOP_CB_MAX_NUM_AF_THD ( 10 )
71 #define ASP_DECOP_CB_INIT_LAG_THD ( 6 )
72 #define ASP_DECOP_CB_INIT_WRTIDX_THD ( ASP_DECOP_CB_INIT_LAG_THD )
73 #define ASP_DECOP_CB_INIT_RDIDX_THD ( 0 )
74 #define ASP_DECODE_CB_GATE_NAME ( "AspDecOpCbGate" )
75 #define ASP_DECODE_CB_GATE_REGION_ID ( 0 )
78 // Decoder output circular buffer
79 typedef struct PAF_AST_DecOpCircBuf
80 {
81 PAF_AudioFrame *afCb; // audio frame CB
82 PAF_AudioData *pcmBuf; // PCM buffer, contains PCM data associated with audio frames
83 UInt8 *metaBuf; // metadata buffer, contains metadata associated with audio frames
84 Int8 sourceSel; // selected source
85 Int8 afRdIdx; // audio frame CB read index
86 Int8 afWrtIdx; // audio frame CB write index
87 Int16 pcmRdIdx; // pcm buffer read index
88 Int8 numAfCb; // current number frames in CB
89 Int8 maxNumAfCb; // maximum number of audio frames in CB
90 Int16 decOpFrameLen; // selected decoder output frame length (input transaction size)
91 Int16 strFrameLen; // stream frame length (output transaction size)
92 Int8 writerActiveFlag; // flag indicates whether CB writer is active
93 Int8 readerActiveFlag; // flag indicates whether CB reader is active
94 Int8 emptyFlag; // flag indicates whether reader should empty (drain) remaining frames in CB
95 Int8 errUndCnt; // underflow count
96 Int8 errOvrCnt; // overflow count
97 PAF_AudioData *pcmBufEnd; // PCM buffer, contains PCM data associated with audio frames end
98 UInt8 *metaBufEnd; // metadata buffer, contains metadata associated with audio frames end
99 Int8 maxAFChanNum; // maximum number of audio data channels in audio frame
100 Int16 maxAFSampCount; // maximum number of sample counts in audio frame
101 PAF_AudioFrame lastAf; // used to store the last valid read out audio frame info to generate mute frame
102 } PAF_AST_DecOpCircBuf;
104 // Decoder output circular buffer control
105 typedef struct PAF_AST_DecOpCircBufCtl
106 {
107 GateMP_Handle gateHandle; // circular buffer gate handle
108 PAF_AST_DecOpCircBuf **pXDecOpCb; // address of decoder output circular buffer base pointer
109 } PAF_AST_DecOpCircBufCtl;
111 // Initialize circular buffer control
112 Int cbCtlInit(
113 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
114 PAF_AST_DecOpCircBuf **pXDecOpCb // address of decoder output circular buffer base pointer
115 );
117 // Reset circular buffer
118 Int cbReset(
119 PAF_AST_DecOpCircBufCtl *pCbCtl,
120 Int8 cbIdx
121 );
123 // Output log of circular buffer control variables (debug)
124 Int cbLog(
125 PAF_AST_DecOpCircBufCtl *pCbCtl,
126 Int8 cbIdx,
127 Int8 fullLog,
128 char *locInfo
129 );
131 #endif /* _ASP_DECOP_CB_COMMON_H_ */