PASDK-53: Cleanup of CB underflow. Additional work needed as mentioned in comments.
authorFrank Livingston <frank-livingston@ti.com>
Tue, 28 Feb 2017 23:41:49 +0000 (17:41 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Tue, 28 Feb 2017 23:41:49 +0000 (17:41 -0600)
pasdk/test_dsp/framework/audioStreamOutProc.c

index eae79357db92cd1c75ef626540721e7f1774a0cd..8a9220bff54fdc50431769a72cd9e2b2eb19e0c2 100644 (file)
@@ -121,17 +121,17 @@ PAF_ASOT_Config gPAF_ASOT_config = {
 
 // Underflow threshold before circular buffer reset and return error to Top-Level FSM
 #define DEC_OP_CB_RDAF_UND_THR  ( 80 ) // FL: arbitrary setting
-UInt32 gDecOpCbRdAfUnd  =0; // decoder output circular buffer underflow count
+UInt32 gCbReadAfErr         =0; // read circular buffer error count
+UInt32 gDecOpCbRdAfUnd      =0; // decoder output circular buffer underflow count
+UInt32 gMaxDecOpCbRdAfUnd   =0; // max (consecutive) decoder output circular buffer underflow count
 
 // Global debug counters */
 UInt32 gTaskAsopCnt=0; // debug
-UInt32 gAsopInitCnt     =0;
-UInt32 gAsopStreamCnt   =0;
-UInt32 gAsopEncodeCnt   =0;
-UInt32 gAsopFinalCnt    =0;
-UInt32 gAsopQuitCnt     =0;
-//debug
-UInt32 gCbReadAfErr     =0;
+UInt32 gAsopInitCnt         =0;
+UInt32 gAsopStreamCnt       =0;
+UInt32 gAsopEncodeCnt       =0;
+UInt32 gAsopFinalCnt        =0;
+UInt32 gAsopQuitCnt         =0;
 
 // FL: (***) debug
 #include "evmc66x_gpio_dbg.h"
@@ -1665,8 +1665,9 @@ PAF_ASOT_decodeInit(
             SW_BREAKPOINT; // FL: debug
             return errno;
         }
-        gCbReadAfErr=0;     // debug
-        gDecOpCbRdAfUnd=0;  // decoder output circular buffer underflow count
+        gCbReadAfErr=0;         // reset read circular buffer error count
+        gDecOpCbRdAfUnd=0;      // reset decoder output circular buffer underflow count
+        gMaxDecOpCbRdAfUnd=0;   // reset max decoder output circular buffer underflow count
 
         // FL: debug
         cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
@@ -1869,29 +1870,47 @@ PAF_ASOT_decodeStream(
             gCbReadAfErr++;
             TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
             //SW_BREAKPOINT; // FL: debug
+        }
+
+        // Handle underflows
+        if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
+        {
+            // FL: some number of underflows alway occur on start of stream when ASOT only depends on configured Output.
+            //     DDP: ~2 underflows
+            //     MAT-THD: ~16 underflows
+            // Need to check behavior of cbReset().
+            // Need to check behavior on exit/re-entry into Output processing.
             
-            if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
+            gDecOpCbRdAfUnd++; // increment circular buffer underflow count
+            if (gDecOpCbRdAfUnd == DEC_OP_CB_RDAF_UND_THR) 
             {
-                // FL: some number of underflows alway occur on start of stream when ASOT only depends on configured Output.
-                //     DDP: ~2 underflows
-                //     MAT-THD: ~16 underflows
-                // Underflows are accumulated across streams since ASOT continues to run.
-                // This means underflow threshold will be reached if enough streams are run.
-                // Need to check behavior on exit/re-entry into Output processing.
+                // Underflow count above threshold.
+                // (1) set max underflow count to threshold
+                // (2) reset underflow count
+                // (3) reset circular buffer
                 
-                // Update underflow count.
-                // If above underflow threshold, reset circular buffer underflow count.
-                gDecOpCbRdAfUnd++;
-                //if (gDecOpCbRdAfUnd == DEC_OP_CB_RDAF_UND_THR) 
-                //{
-                //    // Reset circular buffer
-                //    cbReset(pCbCtl, z);
-                //    Log_info0("PAF_ASOT_decodeStream:cbReset");
-                //
-                //    gDecOpCbRdAfUnd = 0; // reset underflow count
-                //    return cbErrno;
-                //}
+                gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
+                gDecOpCbRdAfUnd = 0; // reset underflow count
+
+                // Reset circular buffer
+                cbReset(pCbCtl, z);
+                Log_info0("PAF_ASOT_decodeStream:cbReset");
+            
+                return cbErrno;
+            }
+        }
+        else if (gDecOpCbRdAfUnd > 0)
+        {
+            // No underflow detected.
+            // update max underflow count,
+            // reset underflow count
+            
+            // update max underflow count
+            if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
+            {
+                gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
             }
+            gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
         }
         //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");