]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/commitdiff
PASDK-218:Update Circular Buffer
authorFrank Livingston <frank-livingston@ti.com>
Fri, 30 Jun 2017 21:06:33 +0000 (16:06 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Fri, 30 Jun 2017 21:06:33 +0000 (16:06 -0500)
1) Remove CB drain indicator from cbReadAf().
2) Add check CB drain function.
3) Add # CBs to CB control.
4) Move ARM/DSP code w/ common API to common source file (cbCtlInit()).

pasdk/common/aspDecOpCircBuf_common.c
pasdk/common/aspDecOpCircBuf_common.h
pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
pasdk/test_dsp/framework/aspDecOpCircBuf_master.c
pasdk/test_dsp/framework/aspDecOpCircBuf_master.h

index 193e04fc926dad70b151ac9bebcb2136dba97aa3..15cf1342e3c3996cf7dd652595c2e28fefed17d5 100644 (file)
@@ -41,6 +41,66 @@ All rights reserved.
 
 #include "aspDecOpCircBuf_common.h"
 
 
 #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,
 // Reset circular buffer
 Int cbReset(
     PAF_AST_DecOpCircBufCtl *pCbCtl,
index a5fb33d660f7f520dc300212ed6b8346fd3fb78c..bdaa50ef975fdefb4370cb82569de44612904e47 100644 (file)
@@ -155,12 +155,14 @@ typedef struct PAF_AST_DecOpCircBufStats
 typedef struct PAF_AST_DecOpCircBufCtl
 {
     GateMP_Handle gateHandle;           // circular buffer gate handle
 typedef struct PAF_AST_DecOpCircBufCtl
 {
     GateMP_Handle gateHandle;           // circular buffer gate handle
+    Int8 numDecOpCb;                    // number of circular buffers
     PAF_AST_DecOpCircBuf **pXDecOpCb;   // address of decoder output circular buffer base pointer
 } PAF_AST_DecOpCircBufCtl;
 
 // Initialize circular buffer control
 Int cbCtlInit(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
     PAF_AST_DecOpCircBuf **pXDecOpCb;   // address of decoder output circular buffer base pointer
 } PAF_AST_DecOpCircBufCtl;
 
 // 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
 );
 
     PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
 );
 
index 36fdccc4ee65594472eab6e6dc5feab13221dc6d..806f1dbf57c7f2bf5d6445a8c69fdcd5350df188 100644 (file)
@@ -47,6 +47,7 @@ All rights reserved.
 
 #include "evmc66x_gpio_dbg.h" // Debug
 
 
 #include "evmc66x_gpio_dbg.h" // Debug
 
+#if 0
 // Initialize circular buffer control
 Int cbCtlInit(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
 // Initialize circular buffer control
 Int cbCtlInit(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
@@ -65,15 +66,16 @@ Int cbCtlInit(
     }
     else
     {
     }
     else
     {
-       pCbCtl->gateHandle = NULL;
+        pCbCtl->gateHandle = NULL;
         return ASP_DECOP_CB_CTL_INIT_INV_GATE;
     }
     
         return ASP_DECOP_CB_CTL_INIT_INV_GATE;
     }
     
-    pCbCtl->pXDecOpCb = pXDecOpCb;
+    pCbCtl->numCb = numCb;          // init number of circular buffers
+    pCbCtl->pXDecOpCb = pXDecOpCb;  // init base address of circular buffers
     
     return ASP_DECOP_CB_SOK;
     
     return ASP_DECOP_CB_SOK;
-    
 }
 }
+#endif
 
 //Int8 gCbWriteStartCnt=0; // debug
 
 
 //Int8 gCbWriteStartCnt=0; // debug
 
index d40165830109863a82893321c12b0f2f727d6383..040b8ace19a8612887b5e18aef6ca1a663a9282b 100644 (file)
@@ -82,9 +82,11 @@ static Void cbReadMuteWithLastAfInfo (
     PAF_AudioFrame *pAfRd         // audio frame into which to read
 );
 
     PAF_AudioFrame *pAfRd         // audio frame into which to read
 );
 
+#if 0
 // Initialize circular buffer control
 Int cbCtlInit(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
 // Initialize circular buffer control
 Int cbCtlInit(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 numCb,                         // number of circular buffers
     PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
 )
 {
     PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
 )
 {
@@ -107,11 +109,12 @@ Int cbCtlInit(
         return ASP_DECOP_CB_CTL_INIT_INV_GATE;
     }
     
         return ASP_DECOP_CB_CTL_INIT_INV_GATE;
     }
     
-    pCbCtl->pXDecOpCb = pXDecOpCb;
-    
-    return ASP_DECOP_CB_SOK;
+    pCbCtl->numCb = numCb;          // init number of circular buffers
+    pCbCtl->pXDecOpCb = pXDecOpCb;  // init base address of circular buffers
     
     
+    return ASP_DECOP_CB_SOK;    
 }
 }
+#endif
 
 // Initialize circular buffer
 Int cbInit(
 
 // Initialize circular buffer
 Int cbInit(
@@ -572,8 +575,7 @@ Int cbReadStop(
 Int cbReadAf(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
     Int8 cbIdx,                         // decoder output circular buffer index
 Int cbReadAf(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
     Int8 cbIdx,                         // decoder output circular buffer index
-    PAF_AudioFrame *pAfRd,              // audio frame into which to read
-    Int8 *pCbDrained                    // pointer to boolean, indicates if circular buffer drained: FALSE - not drained, TRUE - drained
+    PAF_AudioFrame *pAfRd               // audio frame into which to read
 )
 {
     IArg key;
 )
 {
     IArg key;
@@ -585,8 +587,6 @@ Int cbReadAf(
     Int16 j;
     Int8 numMetadata = 0;
     
     Int16 j;
     Int8 numMetadata = 0;
     
-    *pCbDrained = 0; // initialize drained indicator
-    
     // Get gate handle
     gateHandle = pCbCtl->gateHandle;
     // Enter gate
     // Get gate handle
     gateHandle = pCbCtl->gateHandle;
     // Enter gate
@@ -874,7 +874,6 @@ Int cbReadAf(
         if (pCb->numAfCb <= 0)
         {
             pCb->drainFlag = 0;
         if (pCb->numAfCb <= 0)
         {
             pCb->drainFlag = 0;
-            *pCbDrained = 1; // update drained indicator
         }
     }
     
         }
     }
     
@@ -988,3 +987,65 @@ static Void cbReadMuteWithLastAfInfo (
     pAfRd->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
 }
 
     pAfRd->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
 }
 
+// Check circular buffer drain state
+Int cbCheckDrainState(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index, or indicator combined drain state desired
+    Int8 *pDrainedFlag                  // output drain state indicator (combined or for selected circular buffer)
+)
+{
+    IArg key;
+    GateMP_Handle gateHandle;
+    PAF_AST_DecOpCircBuf *pCb;
+    Int8 drainedFlag;
+    Int8 i;
+    
+    // Get gate handle
+    gateHandle = pCbCtl->gateHandle;
+    // Enter gate
+    key = GateMP_enter(gateHandle);
+
+    if (cbIdx != ASP_DECOP_CHECK_DRAINSTATE_ALL)
+    {
+        //
+        // Check drain state for selected circular buffer
+        //
+        
+        // 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();
+
+        drainedFlag = !pCb->writerActiveFlag && !pCb->drainFlag;
+    }
+    else
+    {
+        //
+        // Check combined drain state for all circular buffers.
+        // Combined drain state is logical AND of drain state for all circular buffers.
+        //
+
+        drainedFlag = 1; // init combined drained flag to TRUE
+        for (i = 0; i < pCbCtl->numDecOpCb; i++)
+        {
+            // Get circular buffer base pointer
+            pCb = &((*pCbCtl->pXDecOpCb)[i]);
+
+            // Invalidate circular buffer configuration
+            Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+            Cache_wait();
+            
+            // Update combined drain state
+            drainedFlag = drainedFlag && (!pCb->writerActiveFlag && !pCb->drainFlag);
+        }
+    }
+    
+    *pDrainedFlag = drainedFlag;
+    
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+
+    return ASP_DECOP_CB_SOK;
+}
index 81104a5cda131e3958450319df99460b8405ad66..e2c39025d91f9a45df27144314d161c7f812224f 100644 (file)
@@ -44,6 +44,8 @@ All rights reserved.
 #define ASP_DECOP_CB_READ_UNDERFLOW         ( ASP_DECOP_CB_ERR_START-2 )  // error: read underflow
 #define ASP_DECOP_CB_READ_INVSTATE          ( ASP_DECOP_CB_ERR_START-3 )  // error: circular buffer invalid state on read
 
 #define ASP_DECOP_CB_READ_UNDERFLOW         ( ASP_DECOP_CB_ERR_START-2 )  // error: read underflow
 #define ASP_DECOP_CB_READ_INVSTATE          ( ASP_DECOP_CB_ERR_START-3 )  // error: circular buffer invalid state on read
 
+#define ASP_DECOP_CHECK_DRAINSTATE_ALL      ( -1 )  // check circular buffer combined drain state      
+
 
 // Initialize circular buffer
 Int cbInit(
 
 // Initialize circular buffer
 Int cbInit(
@@ -76,8 +78,15 @@ Int cbReadStop(
 Int cbReadAf(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
     Int8 cbIdx,                         // decoder output circular buffer index
 Int cbReadAf(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
     Int8 cbIdx,                         // decoder output circular buffer index
-    PAF_AudioFrame *pAfRd,              // audio frame into which to read
-    Int8 *pCbDrained                    // pointer to boolean, indicates if circular buffer drained: FALSE - not drained, TRUE - drained
+    PAF_AudioFrame *pAfRd               // audio frame into which to read
 );
 
 );
 
+// Check circular buffer drain state
+Int cbCheckDrainState(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index, or indicator combined drain state desired
+    Int8 *pDrainedFlag                  // output drain state indicator (combined or for selected circular buffer)
+);
+
+
 #endif /* _ASP_DECOP_CB_MASTER_H_ */
 #endif /* _ASP_DECOP_CB_MASTER_H_ */