Further cleanup of CB overflow handling
authorFrank Livingston <frank-livingston@ti.com>
Wed, 1 Mar 2017 19:13:18 +0000 (13:13 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Wed, 1 Mar 2017 19:13:18 +0000 (13:13 -0600)
pasdk/test_arm/framework/audioStreamDecodeProc.c

index e4a25538d81f1d38655c995b91322caf6f54d471..3ed8e1483f8118f7abce63dc1bc535fa8a092c73 100644 (file)
@@ -101,9 +101,11 @@ PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 
-// Underflow threshold before circular buffer reset and return error to Top-Level FSM
+// Overflow threshold before circular buffer reset and return error to Top-Level FSM
 #define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
-UInt32 gDecOpCbWrtAfOvr  =0; // decoder output circular buffer overflow count
+UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count, not including overflows
+UInt32 gDecOpCbWrtAfOvr         =0; // decoder output circular buffer overflow count
+UInt32 gMaxDecOpCbWrtAfOvr      =0; // max (consecutive) decoder output circular buffer overflow count
 
 // Global debug counters */
 UInt32 gSlaveStartErrCnt        =0;
@@ -118,8 +120,6 @@ UInt32 gSlaveDecInfoCnt         =0;
 UInt32 gSlaveDecDecodeCnt       =0;
 UInt32 gSlaveDecDeactivateCnt   =0;
 
-// debug
-UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count
 
 // FL: (***) debug
 #include "evmc66x_gpio_dbg.h"
@@ -499,8 +499,9 @@ Void taskAsdpFxn(
                     {
                         SW_BREAKPOINT;
                     }
-                    gCbWrtAfErrCnt=0;   // debug
-                    gDecOpCbWrtAfOvr=0; // decoder output circular buffer overflow count
+                    gCbWrtAfErrCnt=0;       // reset write circular buffer error count
+                    gDecOpCbWrtAfOvr=0;     // reset decoder output circular buffer overflow count
+                    gMaxDecOpCbWrtAfOvr=0;  // reset max decoder output circular buffer overflow count
                     // FL: debug, log circular buffer control variables
                     cbLog(pCbCtl, z, 1, "cbWriteStart");
                     // Reset audio frame
@@ -718,27 +719,38 @@ Void taskAsdpFxn(
                         //}                        
 
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
-                        if (cbErrno < 0)
+                        if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
                         {
                             gCbWrtAfErrCnt++;
                             //SW_BREAKPOINT; // FL: debug
+                        }
+                        
+                        // Handle overflows
+                        if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
+                        {
+                            gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
+                            if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
+                            {
+                                gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
+                                gDecOpCbWrtAfOvr = 0; // reset overflow count
+                                
+                                // Reset circular buffer
+                                cbReset(pCbCtl, z);
+                            }
+                        }
+                        else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
+                        {
+                            // No overflow detected.
+                            // update max overflow count,
+                            // reset overflow count
                             
-                            if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
+                            if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
                             {
-                                // Update underflow count.
-                                // If above underflow threshold, reset circular buffer underflow count.
-                                gDecOpCbWrtAfOvr++;
-                                if (gDecOpCbWrtAfOvr < DEC_OP_CB_WRTAF_OVR_THR)
-                                {
-                                    cbErrno = 0;
-                                }
-                                else 
-                                {
-                                    // Reset circular buffer
-                                    cbReset(pCbCtl, z);
-                                    gDecOpCbWrtAfOvr = 0; // reset underflow count
-                                }
+                                gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
                             }
+                            gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
+                            
+                            cbErrno = 0; // don't return error condition
                         }
                         TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
@@ -754,7 +766,6 @@ Void taskAsdpFxn(
                         }
 #endif        
                         
-                        
                         // FL: debug, log circular buffer control variables
                         cbLog(pCbCtl, z, 1, "cbWriteAf");
                     }