]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/common/aspDecOpCircBuf_common.c
Merge branch 'dev_pasdk_frank_pasdk376Beta3Release' of ssh://git@bitbucket.itg.ti...
[processor-sdk/performance-audio-sr.git] / pasdk / common / aspDecOpCircBuf_common.c
index 095ebb4f842caec80ab2a7c1655e44aed3a36c0d..74e570a2021e3861f7fb4072e554bf4a0da8de2a 100644 (file)
@@ -41,6 +41,66 @@ All rights reserved.
 
 #include "aspDecOpCircBuf_common.h"
 
+// Initialize circular buffer control
+Int cbCtlInit(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 numDecOpCb,                    // number of circular buffers
+    PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
+)
+{
+#ifdef _TMS320C6X
+    GateMP_Params gateParams;
+    GateMP_Handle gateHandle;
+    
+    GateMP_Params_init(&gateParams);
+    gateParams.localProtect = GateMP_LocalProtect_THREAD;
+    gateParams.remoteProtect = GateMP_RemoteProtect_SYSTEM;
+    gateParams.name = ASP_DECODE_CB_GATE_NAME;
+    gateParams.regionId = ASP_DECODE_CB_GATE_REGION_ID;
+    gateHandle = GateMP_create(&gateParams);
+    if (gateHandle != NULL)
+    {
+        pCbCtl->gateHandle = gateHandle;
+    }
+    else
+    {
+        pCbCtl->gateHandle = NULL;
+        return ASP_DECOP_CB_CTL_INIT_INV_GATE;
+    }
+    
+    pCbCtl->numDecOpCb = numDecOpCb;    // init number of circular buffers
+    pCbCtl->pXDecOpCb = pXDecOpCb;      // init base address of circular buffers
+    
+    return ASP_DECOP_CB_SOK;    
+
+#elif defined(ARMCOMPILE)
+    GateMP_Handle gateHandle;
+    Int status;
+    
+    do {
+        status = GateMP_open(ASP_DECODE_CB_GATE_NAME, &gateHandle);
+    } while (status == GateMP_E_NOTFOUND);
+    if (status == GateMP_S_SUCCESS)
+    {
+        pCbCtl->gateHandle = gateHandle;
+    }
+    else
+    {
+        pCbCtl->gateHandle = NULL;
+        return ASP_DECOP_CB_CTL_INIT_INV_GATE;
+    }
+    
+    pCbCtl->numDecOpCb = numDecOpCb;    // init number of circular buffers
+    pCbCtl->pXDecOpCb = pXDecOpCb;      // init base address of circular buffers
+    
+    return ASP_DECOP_CB_SOK;
+
+#else
+    #error "Unsupported platform"
+
+#endif
+}
+
 // Reset circular buffer
 Int cbReset(
     PAF_AST_DecOpCircBufCtl *pCbCtl,
@@ -66,26 +126,27 @@ Int cbReset(
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
 
+    // Initialize CB primed flag
+    pCb->primedFlag = 0;
+    // Initialize delta samples
+    pCb->deltaSamps = 0;
+    
+    // Reset circular buffer:
+    //  - AF write, read indices
     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) ||
@@ -101,6 +162,21 @@ Int cbReset(
         pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DTS;
         pCb->pcmRdIdx = pCb->decOpFrameLen - ASP_DECOP_CB_INIT_LAG_DTS*pCb->strFrameLen;
     }
+    else
+    {
+        //
+        // Currently unsupported source select
+        //
+        return ASP_DECOP_CB_RESET_INV_SOURCE_SEL;
+    }
+        
+    // Reset circular buffer:
+    //  - PCM read index
+    //  - Private metadata read index
+    //  - number of PCM samples in CB
+    pCb->pcmRdIdx = 0;
+    pCb->prvMdRdIdx = 0;
+    pCb->numPcmSampsPerCh = 0;
 
     // initialize circular buffer current number of frames
     pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
@@ -109,19 +185,34 @@ Int cbReset(
     {
         pAfCb = &pCb->afCb[n];
         
-        // clear PCM data
+        // Clear PCM data
         for (i=0; i<pCb->maxAFChanNum; i++)
         {
             memset(pAfCb->data.sample[i], 0, pCb->maxAFSampCount);
+            pAfCb->data.samsiz[i] = 0;
         }
         
-        // clear metadata
-        pAfCb->numPrivateMetadata = 0;
+        // Clear metadata
+        pAfCb->bsMetadata_type     = PAF_bsMetadata_none;           /* non zero if metadata is attached. */
+        pAfCb->pafBsMetadataUpdate = 0;                             /* indicates whether bit-stream metadata update */
+        pAfCb->numPrivateMetadata  = 0;                             /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
+        pAfCb->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
+        for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
+        {
+            pAfCb->pafPrivateMetadata[i].offset = 0; 
+            pAfCb->pafPrivateMetadata[i].size   = 0;
+        }
     }
     
-    // reset error counts
-    pCb->errUndCnt = 0;
-    pCb->errOvrCnt = 0;
+    // reset stats
+    pCb->readAfWriterInactiveCnt = 0;
+    pCb->readAfNdCnt = 0;
+    pCb->wrtAfReaderInactiveCnt = 0;
+    pCb->wrtAfZeroSampsCnt = 0;
+    pCb->errAfUndCnt = 0;
+    pCb->errAfOvrCnt = 0;
+    pCb->errPcmUndCnt = 0;
+    pCb->errPcmOvrCnt = 0;
 
     // Write back circular buffer configuration
     Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
@@ -144,6 +235,47 @@ Int cbReset(
     return ASP_DECOP_CB_SOK;
 }
 
+// Get circular buffer statistics
+Int cbGetStats(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    PAF_AST_DecOpCircBufStats *pCbStats // decoder output circular buffer statistics
+    
+)
+{
+    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();
+
+    // Populate statistics
+    pCbStats->readAfWriterInactiveCnt = pCb->readAfWriterInactiveCnt;
+    pCbStats->readAfNdCnt = pCb->readAfNdCnt;
+    pCbStats->wrtAfReaderInactiveCnt = pCb->wrtAfReaderInactiveCnt;
+    pCbStats->wrtAfZeroSampsCnt = pCb->wrtAfZeroSampsCnt;
+    pCbStats->errAfUndCnt = pCb->errAfUndCnt;
+    pCbStats->errAfOvrCnt = pCb->errAfOvrCnt;
+    pCbStats->errPcmUndCnt = pCb->errPcmUndCnt;
+    pCbStats->errPcmOvrCnt = pCb->errPcmOvrCnt;
+    
+    // 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,
@@ -169,10 +301,8 @@ Int cbLog(
     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);
+    Log_info3("CB: readerActiveFlag=%d, writerActiveFlag=%d, drainFlag=%d", pCb->readerActiveFlag, pCb->writerActiveFlag, pCb->drainFlag);
+    Log_info5("CB: afRdIdx=%d, pcmRdIdx=%d, prvMdRdIdx=%d, afWrtIdx=%d, numAfCb=%d", pCb->afRdIdx, pCb->pcmRdIdx, pCb->prvMdRdIdx, pCb->afWrtIdx, pCb->numAfCb);
     if (fullLog)
     {
         Log_info1("CB: maxNumAfCb=%d", pCb->maxNumAfCb);