]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
Add Decoder Output Circular Buffer reset function
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_arm / framework / aspDecOpCircBuf_slave.c
index 16010b8eb3617b675205cf6fdea3f8eaf44d98cd..3af87fc8a1183d0d2cf51033f0dab69919cf298a 100644 (file)
@@ -35,8 +35,9 @@ All rights reserved.
 
 #include <string.h> // for memset
 #include <xdc/std.h>
-#include <ti/sysbios/hal/Cache.h>
 #include <xdc/runtime/Log.h>
+#include <ti/sysbios/hal/Cache.h>
+#include <ti/uia/events/UIAEvt.h>
 
 #include "common.h"
 #include "paftyp.h"
@@ -47,19 +48,26 @@ All rights reserved.
 // Initialize circular buffer control
 Int cbCtlInit(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
-    PAF_AST_DecOpCircBuf *xDecOpCb      // decoder output circular buffer base pointer
+    PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
 )
 {
     GateMP_Handle gateHandle;
     Int status;
     
-    status = GateMP_open(ASP_DECODE_CB_GATE_NAME, &gateHandle);
-    if (status < 0)
+    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->xDecOpCb = xDecOpCb;
+    pCbCtl->pXDecOpCb = pXDecOpCb;
     
     return ASP_DECOP_CB_SOK;
     
@@ -84,7 +92,7 @@ Int cbWriteStart(
     key = GateMP_enter(gateHandle);
 
     // Get circular buffer base pointer
-    pCb = &pCbCtl->xDecOpCb[cbIdx];
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
 
     // (***) FL: revisit
     // Invalidate circular buffer configuration.
@@ -92,6 +100,8 @@ Int cbWriteStart(
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
     
+    //Log_info1("cbWriteStart:afCb=0x%04x", (IArg)pCb->afCb); // FL: debug
+    
     // Invalidate AF circular buffer
     Cache_inv(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
     for (n=0; n<pCb->maxNumAfCb; n++)
@@ -137,11 +147,13 @@ Int cbWriteStop(
     key = GateMP_enter(gateHandle);
 
     // Get circular buffer base pointer
-    pCb = &pCbCtl->xDecOpCb[cbIdx];
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
 
     // Invalidate circular buffer configuration
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
+
+    //Log_info1("cbWriteStop:afCb=0x%04x", (IArg)pCb->afCb);  // FL: debug
     
     // update flags
     pCb->writerActiveFlag = 0;
@@ -178,8 +190,11 @@ Int cbWriteAf(
     // Enter gate
     key = GateMP_enter(gateHandle);
 
+    //Log_info2("cbWriteAf:gate enter, gateHandle=0x%04x, key=%d", (IArg)gateHandle, (IArg)key); // FL: debug
+    
     // Get circular buffer base pointer
-    pCb = &pCbCtl->xDecOpCb[cbIdx];
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
+    //Log_info1("cbWriteAf:pCb=0x%04x", (IArg)pCb); // FL: debug
 
     // (***) FL: revisit
     // Invalidate circular buffer configuration.
@@ -187,6 +202,9 @@ Int cbWriteAf(
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
     
+    //Log_info1("cbWriteAf:afCb=0x%04x", (IArg)pCb->afCb); // FL: debug
+    //Log_info2("cbWriteAf:pCb->readerActiveFlag=%d, pCb->writerActiveFlag=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->writerActiveFlag); // FL: debug
+
     if (pCb->readerActiveFlag == 1)
     {
         //
@@ -209,7 +227,10 @@ Int cbWriteAf(
         }
 #endif        
 
+        //Log_info2("cbWriteAf:pCb->numAfCb=%d, pCb->maxNumAfCb=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->maxNumAfCb); // FL: debug
+    
         // check overflow
+        //while (pCb->numAfCb >= pCb->maxNumAfCb); // FL: debug
         if (pCb->numAfCb >= pCb->maxNumAfCb)
         {
             pCb->errOvrCnt++;
@@ -217,14 +238,21 @@ Int cbWriteAf(
             //SW_BREAKPOINT;
             Log_info1("cbWriteAf: ERROR: overflow, numAfCb=%d", pCb->numAfCb);
 
+            // Write back circular buffer configuration
+            Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+
             // Leave the gate
             GateMP_leave(gateHandle, key);
 
+            //Log_info2("cbWriteAf:gate leave, gateHandle=0x%04x, key=%d", (IArg)gateHandle, (IArg)key); // FL: debug
+            
             return ASP_DECOP_CB_WRITE_OVERFLOW;
         }
         
         // get pointer to current audio frame in circular buffer
+        //Log_info2("cbWriteAf:afCb=0x%04x, pCb->afWrtIdx=%d", (IArg)pCb->afCb, (IArg)pCb->afWrtIdx); // FL: debug
         pAfCb = &pCb->afCb[pCb->afWrtIdx];
+        //Log_info1("cbWriteAf:pAfCb=0x%04x", (IArg)pAfCb); // FL: debug
            
         // write audio frame information updated by decoder
         pAfCb->sampleDecode = pAfWrt->sampleDecode;
@@ -240,6 +268,10 @@ Int cbWriteAf(
         pAfCb->bsMetadata_offset   = pAfWrt->bsMetadata_offset;      /* offset into audio frame for change in bsMetadata_type field */
         // write PCM samples
         streamMask = pAfWrt->fxns->channelMask(pAfWrt, pAfCb->channelConfigurationStream);
+        //Log_info1("cbWriteAf:streamMask=0x%04x", (IArg)streamMask); // FL: debug
+        //Log_info1("cbWriteAf:pCb->decOpFrameLen=%d", (IArg)pCb->decOpFrameLen); // FL: debug
+        //Log_info2("cbWriteAf:pAfCb->data.sample=0x%04x, pAfWrt->data.sample=0x%04x", (IArg)pAfCb->data.sample, (IArg)pAfWrt->data.sample); // FL: debug
+        //Log_info2("cbWriteAf:pAfCb->data.samsiz=0x%04x, pAfWrt->data.samsiz=0x%04x", (IArg)pAfCb->data.samsiz, (IArg)pAfWrt->data.samsiz); // FL: debug
         for (i = 0; i < ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
         {
             if ((streamMask >> i) & 0x1)
@@ -253,6 +285,7 @@ Int cbWriteAf(
             }
         }
         
+        //Log_info1("cbWriteAf:pAfCb->numPrivateMetadata=%d", (IArg)pAfCb->numPrivateMetadata); // FL: debug
         // Write metadata to circular buffer
         for (i = 0; i < pAfCb->numPrivateMetadata; i++) // FL: only copy numPrivateMetadata
         {
@@ -262,14 +295,18 @@ Int cbWriteAf(
         }
         
         // update audio frame write index
+        //Log_info2("cbWriteAf:pCb->afWrtIdx=%d, pCb->maxNumAfCb", (IArg)pCb->afWrtIdx, (IArg)pCb->maxNumAfCb); // FL: debug
         pCb->afWrtIdx++;
         if (pCb->afWrtIdx >= pCb->maxNumAfCb)
         {
             pCb->afWrtIdx = 0;
         }
+        //Log_info2("cbWriteAf:pCb->afWrtIdx=%d, pCb->maxNumAfCb", (IArg)pCb->afWrtIdx, (IArg)pCb->maxNumAfCb); // FL: debug
         
         // update number of audio frames in circular buffer
+        //Log_info1("cbWriteAf:pCb->numAfCb=%d", (IArg)pCb->numAfCb); // FL: debug
         pCb->numAfCb++;
+        //Log_info1("cbWriteAf:pCb->numAfCb=%d", (IArg)pCb->numAfCb); // FL: debug
 
         // (***) FL: revisit
         // Write back circular buffer configuration
@@ -298,6 +335,8 @@ Int cbWriteAf(
     // Leave the gate
     GateMP_leave(gateHandle, key);
 
+    //Log_info2("cbWriteAf:gate leave, gateHandle=0x%04x, key=%d", (IArg)gateHandle, (IArg)key); // FL: debug
+    
     return ASP_DECOP_CB_SOK;
 }
 
@@ -318,7 +357,7 @@ Int cbGetNextWriteAf(
     key = GateMP_enter(gateHandle);
 
     // Get circular buffer base pointer
-    pCb = &pCbCtl->xDecOpCb[cbIdx];
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
 
     // get pointer to current audio frame in circular buffer
     *ppAfWrt = &pCb->afCb[pCb->afWrtIdx];