PASDK-218:Add Out Init-Sync to ASOT (DSP) and ASDT (ARM)
authorFrank Livingston <frank-livingston@ti.com>
Fri, 30 Jun 2017 21:23:33 +0000 (16:23 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Fri, 30 Jun 2017 21:23:33 +0000 (16:23 -0500)
12 files changed:
pasdk/common/audioStreamProc_config.h
pasdk/test_arm/framework/aspMsg_slave.h
pasdk/test_arm/framework/audioStreamDecodeProc.c
pasdk/test_arm/framework/audioStreamDecodeProc.h
pasdk/test_dsp/framework/audioStreamInpProc.c
pasdk/test_dsp/framework/audioStreamInpProc.h
pasdk/test_dsp/framework/audioStreamInpProc_paramsFxns.c
pasdk/test_dsp/framework/audioStreamOutProc.c
pasdk/test_dsp/framework/audioStreamOutProc.h
pasdk/test_dsp/framework/audioStreamOutProc_paramsFxns.c
pasdk/test_dsp/framework/audioStreamProc_master.c
pasdk/test_dsp/framework/audioStreamProc_master.h

index 7e7a1cceb13d7d30b83cdfa7776de7c138bf5bf6..f186a5324b8de0332c6cc891238ec15c3a01fd58 100644 (file)
@@ -60,6 +60,7 @@ All rights reserved.
 #include "asp0.h"
 
 #include "aspDecOpCircBuf_common.h"
+#include "aspOutInitSync_common.h"
 
 #ifdef HSE_MSGQ
 #include <msgq.h>
@@ -124,21 +125,20 @@ typedef struct PAF_AST_MQ {
 #endif
 
 typedef struct PAF_AST_Config {
-    Int                  as;
-    PAF_AST_InpBuf       *xInp;     /* INPUT1 -INPUTN  */
-    PAF_AST_Decode       *xDec;     /* DECODE1-DECODEN */
-    PAF_AST_Stream       *xStr;     /* STREAM1-STREAMN */
-    PAF_AST_Encode       *xEnc;     /* ENCODE1-ENCODEN */
-    PAF_AST_OutBuf       *xOut;     /* OUTPUT1-OUTPUTN */
-    PAF_AST_DecOpCircBuf *xDecOpCb; /* DECODE1-DECODEN */
-    SmInt                masterDec; // these two are computed based on MASTER input
-    SmInt                masterStr;
+    Int                     as;
+    PAF_AST_InpBuf          *xInp;      /* INPUT1 -INPUTN  */
+    PAF_AST_Decode          *xDec;      /* DECODE1-DECODEN */
+    PAF_AST_Stream          *xStr;      /* STREAM1-STREAMN */
+    PAF_AST_Encode          *xEnc;      /* ENCODE1-ENCODEN */
+    PAF_AST_OutBuf          *xOut;      /* OUTPUT1-OUTPUTN */
+    PAF_AST_DecOpCircBuf    *xDecOpCb;  /* DECODE1-DECODEN */
+    PAF_AST_OutInitSyncInfo *xOutIsi;   /* DECODE1-DECODEN */
+    SmInt                   masterDec;  // these two are computed based on MASTER input
+    SmInt                   masterStr;
 #ifdef HSE_MSGQ
-    PAF_AST_MQ           mq;
+    PAF_AST_MQ              mq;
 #endif
 } PAF_AST_Config;
 
-extern PAF_AST_Config *pC;  /* Global configuration pointer */
-
 
 #endif  /* _ASP_CONFIG_H_ */
index aa40a46d724333de4be188915285d3dcc62e850e..51d3e656f743537b5df21e7c075f50d8aa6aae56 100644 (file)
@@ -39,6 +39,8 @@ All rights reserved.
 #include <xdc/std.h>
 #include <ti/ipc/MessageQ.h>
 
+#include "aspOutInitSync_common.h"
+
 #define ASP_MSG_SLAVE_DEF_NUMMSGS ( 4 )
 
 /* module structure */
@@ -63,4 +65,3 @@ extern AspMsgSlave_Handle hAspMsgSlave;
 
 
 #endif /* _ASP_MSG_SLAVE_H_ */
-
index b8b6ba122600a576301a39c9ef807dbb2f0f3fd3..b2bb68430321e5d19f643ab2c471baa729da8702 100644 (file)
@@ -58,6 +58,7 @@ All rights reserved.
 #include "aspMsg_common.h"
 #include "aspMsg_slave.h"
 #include "aspDecOpCircBuf_slave.h"
+#include "aspOutInitSync_slave.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamDecodeProc.h"
 #include "statusOp_common.h"
@@ -93,7 +94,8 @@ PAF_ASDT_Config gPAF_ASDT_config
 __attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
     NULL,               // taskHandle
     NULL,               // acp
-    {NULL, NULL},       // decOpCircBufCtl
+    {NULL, 0, NULL},    // decOpCircBufCtl
+    {NULL, NULL},       // outIsCtl
     &gPAF_AST_config    // ASIT/ASOT/ASDT shared configuration
 };
 
@@ -141,11 +143,11 @@ Void taskAsdpFxn(
     const PAF_ASDT_Patchs *pQ
 )
 {
-    PAF_ASDT_Config *pAsdtCfg;      /* ASDT configuration pointer */
-    PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
-    Int as;                         /* Audio Stream Number (1, 2, etc.) */
-    Int z;                          /* input/encode/stream/decode/output counter */
-    Int i;                          /* phase */
+    PAF_ASDT_Config *pAsdtCfg;          // ASDT configuration pointer
+    PAF_AST_Config *pAstCfg;            // Common (shared) configuration pointer
+    Int as;                             // Audio Stream Number (1, 2, etc.)
+    Int z;                              // input/encode/stream/decode/output counter
+    Int i;                              // phase
     Int zMD, zMS;
     Bool done;
     Bool decDone;
@@ -153,19 +155,24 @@ Void taskAsdpFxn(
     ASP_Slave_Cmd slaveCmd;
     Int sourceSelect;
     DEC_Handle dec;
-    IALG_Cmd decCtrlCmd;            // decoder control command
-    Int decCtrlRet;                 // decoder control return
-    Int errno;                      /* error number */
+    IALG_Cmd decCtrlCmd;                // decoder control command
+    Int decCtrlRet;                     // decoder control return
+    Int errno;                          // error number
     Int size;
     Int argIdx;
     // Decoder output circular buffer
-    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
-    PAF_AudioFrame *pAfWrt;
-    Int cbErrno;    
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    // Decoder output Circular Buffer control
+    PAF_AudioFrame *pAfWrt;             // pointer to audio frame written to CB
+    Int cbErrno;                        // CB error number
+    // Output Init-Sync
+    PAF_AST_OutInitSyncCtl *pOutIsCtl;  // OutIS control
+    Int8 outIsDecInfo1Flag;             // indicates whether Dec Info Init-Sync has executed
+    PAF_AudioFrame *pOutIsAfWrt;        // pointer to audio frame written to OutIS Info
+    Int outIsErrno;                     // OutIS error number
     // Messaging
-    PAF_InpBufConfig *pIpBufConfig;
-    ASP_Msg *pAspMsg;
-    MessageQ_QueueId queId;
+    PAF_InpBufConfig *pIpBufConfig;     // IB buffer configuration
+    ASP_Msg *pAspMsg;                   // Rx/Tx MessageQ message
+    MessageQ_QueueId queId;             // MessageQ ID
     Int status;
     Int zI;
     Int bufEnd, wrapSize, currentBufSize, chunkSize;
@@ -198,7 +205,8 @@ Void taskAsdpFxn(
     pAsdtCfg->taskHandle = Task_self();     // set task handle
     pAstCfg = pAsdtCfg->pAstCfg;            // get pointer to AST common (shared) configuration 
     pCbCtl = &pAsdtCfg->decOpCircBufCtl;    // get pointer to circular buffer control
-
+    pOutIsCtl = &pAsdtCfg->outIsCtl;        // get pointer to output init-sync control
+    
     // wait for initialization message from master
     do {
         status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
@@ -383,10 +391,10 @@ Void taskAsdpFxn(
         }
         alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
 
-        // FL: debug, reset IB capture buffer
+        // Reset IB capture buffer (debug)
         //capIbReset();
         //Log_info0("capIbReset()");
-        // FL: debug, reset audio frame capture buffer
+        // Reset audio frame capture buffer (debug)
         //capAfReset();
         
         decDone = FALSE;
@@ -443,8 +451,6 @@ Void taskAsdpFxn(
                     
                 case ASP_SLAVE_DEC_CONTROL:
                     gSlaveDecControlCnt++;
-                    // simulate dec control load
-                    //simLoad(DEC_CONTROL_LOAD);
                     
                     argIdx = 0; // get decIdx
                     z = *(Int32 *)&pAspMsg->buf[argIdx];
@@ -472,8 +478,6 @@ Void taskAsdpFxn(
                     
                 case ASP_SLAVE_DEC_ACTIVATE:
                     gSlaveDecActivateCnt++;
-                    // simulate dec activate load
-                    //simLoad(DEC_ACTIVATE_LOAD);
                     
                     // (***) FL: revisit
                     // invalidate Status structures for shared Beta Units
@@ -499,7 +503,6 @@ Void taskAsdpFxn(
                     }
 
                     // Start writes to circular buffer
-                    //pCb = &pAstCfg->xDecOpCb[z];
                     cbErrno = cbWriteStart(pCbCtl, z);
                     if (cbErrno < 0)
                     {
@@ -509,12 +512,15 @@ Void taskAsdpFxn(
                     gDecOpCbWrtAfOvr=0;     // reset decoder output circular buffer overflow count
                     gMaxDecOpCbWrtAfOvr=0;  // reset max decoder output circular buffer overflow count
                     gSlaveCbResetCnt=0;     // reset slave circular buffer reset count
-                    // FL: debug, log circular buffer control variables
+                    // Log circular buffer control variables (debug)
                     cbLog(pCbCtl, z, 1, "cbWriteStart");
                     
                     // Reset audio frame
                     resetAf(pP, z, sourceSelect);
                     
+                    // Initialize OutIS Dec Info1 flag -- OutIS Dec Info hasn't executed
+                    outIsDecInfo1Flag = 0;
+                    
                     // send dec activate complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
@@ -531,8 +537,6 @@ Void taskAsdpFxn(
                     
                 case ASP_SLAVE_DEC_RESET:
                     gSlaveDecResetCnt++;
-                    // simulate dec reset load
-                    //simLoad(DEC_RESET_LOAD);
                     
                     argIdx = 0; // get decIdx
                     z = *(Int32 *)&pAspMsg->buf[argIdx];
@@ -558,6 +562,17 @@ Void taskAsdpFxn(
                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
                     Cache_wait();*/
+
+                    // Perform Dec Reset Init-Sync
+                    //  - Write Dec Reset output audio frame
+                    //  - Set Dec Reset decoder stage flag
+                    pOutIsAfWrt = pAstCfg->xDec[z].decodeControl.pAudioFrame; // get pointer to audio frame to write
+                    outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
+                        ASP_OUTIS_DEC_STAGE_RESET_IDX, 1, pOutIsAfWrt);
+                    if (outIsErrno < 0)
+                    {
+                        SW_BREAKPOINT; // debug
+                    }
                     
                     // send dec reset complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
@@ -577,8 +592,6 @@ Void taskAsdpFxn(
                     
                 case ASP_SLAVE_DEC_INFO:
                     gSlaveDecInfoCnt++;
-                    // simulate dec info load
-                    //simLoad(DEC_INFO_LOAD);
                     
                     argIdx = 0; // get decIdx
                     z = *(Int32 *)&pAspMsg->buf[argIdx];
@@ -662,6 +675,21 @@ Void taskAsdpFxn(
                     }
 #endif
 
+                    if (outIsDecInfo1Flag == 0)
+                    {
+                        // Perform Dec Info Init-Sync
+                        //  - Write Dec Info1 output audio frame
+                        //  - Set Dec Info1 decoder stage flag
+                        pOutIsAfWrt = pAstCfg->xDec[z].decodeControl.pAudioFrame; // get pointer to audio frame to write
+                        outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
+                            ASP_OUTIS_DEC_STAGE_INFO1_IDX, 1, pOutIsAfWrt);
+                        if (outIsErrno < 0)
+                        {
+                            SW_BREAKPOINT; // debug
+                        }
+                        outIsDecInfo1Flag = 1; // set flag to indicate OutIS Dec Info has executed
+                    }
+
                     // send dec info complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
@@ -680,8 +708,6 @@ Void taskAsdpFxn(
                     
                 case ASP_SLAVE_DEC_DECODE:
                     gSlaveDecDecodeCnt++;
-                    // simulate dec info load
-                    //simLoad(DEC_DECODE_LOAD);
                     
                     argIdx = 0; // get decIdx
                     z = *(Int32 *)&pAspMsg->buf[argIdx];
@@ -704,7 +730,7 @@ Void taskAsdpFxn(
                     cbErrno = 0;
                     if (dec->fxns->decode)
                     {
-                        // FL: debug, capture input buffer
+                        // Capture input buffer (debug)
                         //capIb(pAstCfg->xInp[z].pInpBuf);
                     
                         pfpBegin(PFP_ID_ASDT_2, pAsdtCfg->taskHandle);
@@ -724,14 +750,13 @@ Void taskAsdpFxn(
                         TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
                         //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
                         
-                        // FL: debug, capture audio frame
+                        // Capture audio frame (debug)
                         //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
                         //{
                         //    Log_info0("capAfWrite() error");
                         //}                        
 
                         #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
-
                         if (tempCap_frameCnt < CAP_FRAME_MAX)
                         {
                             tempCap_decSampleOut[tempCap_frameCnt] = pAfWrt->sampleCount;
@@ -744,7 +769,7 @@ Void taskAsdpFxn(
                         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
                         {
                             gCbWrtAfErrCnt++;
-                            //SW_BREAKPOINT; // FL: debug
+                            //SW_BREAKPOINT; // debug
                         }
                         
                         // Handle overflows
@@ -791,7 +816,7 @@ Void taskAsdpFxn(
                         }
 #endif        
                         
-                        // FL: debug, log circular buffer control variables
+                        // Log circular buffer control variables (debug)
                         cbLog(pCbCtl, z, 1, "cbWriteAf");
                     }
                     
@@ -838,8 +863,6 @@ Void taskAsdpFxn(
                     
                 case ASP_SLAVE_DEC_DEACTIVATE:
                     gSlaveDecDeactivateCnt++;
-                    // simulate dec info load
-                    //simLoad(DEC_DEACTIVATE_LOAD);
                     
                     argIdx = 0; // get decIdx
                     z = *(Int32 *)&pAspMsg->buf[argIdx];
@@ -851,15 +874,21 @@ Void taskAsdpFxn(
                     }
                     
                     // Stop writes to circular buffer
-                    //pCb = &pAstCfg->xDecOpCb[z];
                     cbErrno = cbWriteStop(pCbCtl, z);
                     if (cbErrno < 0)
                     {
-                        SW_BREAKPOINT;
+                        SW_BREAKPOINT; // debug
                     }
-                    // FL: debug, log circular buffer control variables
+                    // Log circular buffer control variables (debug)
                     cbLog(pCbCtl, z, 1, "cbWriteStop");
                     
+                    // Reset Output Init-Sync decoder stage flags
+                    outIsErrno = outIsResetDecStageFlags(pOutIsCtl, z);
+                    if (outIsErrno < 0)
+                    {
+                        SW_BREAKPOINT; // debug
+                    }
+                    
                     // send dec deactivate complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
index 51916d98b02c605b49c0f46329881f533f4050b9..272dc890f2a9f36172619ee83e5bab45a8c2916b 100644 (file)
@@ -34,7 +34,7 @@ All rights reserved.
 */
 
 /*
- *  ======== audioStreamDecdeProc.h ========
+ *  ======== audioStreamDecodeProc.h ========
  */
 
 #ifndef _ASDP_H_
@@ -121,6 +121,7 @@ typedef struct PAF_ASDT_Config
     Task_Handle taskHandle;                     // ASDT handle
     ACP_Handle acp;                             // ASDT local ACP handle
     PAF_AST_DecOpCircBufCtl decOpCircBufCtl;    // decoder output circular buffer control
+    PAF_AST_OutInitSyncCtl outIsCtl;            // output init-sync control
     PAF_AST_Config *pAstCfg;                    // ASIT/ASOT/ASDT shared configuration
 } PAF_ASDT_Config;
 
index af3fa9ed4df3c525f3423cfddc27305e43bb2362..fc677b05eb842126caea8d9b98ba01af22975782 100644 (file)
@@ -61,6 +61,7 @@ All rights reserved.
 #include "aspMsg_common.h"
 #include "aspMsg_master.h"
 #include "aspDecOpCircBuf_master.h"
+#include "aspOutInitSync_master.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamProc_master.h"
 #include "audioStreamInpProc.h"
@@ -1022,7 +1023,7 @@ Void taskAsipFxn(
         }
     } // End of main processing loop for (;;)
     
-    Log_info0("Exit taskAsipFxn()");
+    //Log_info0("Exit taskAsipFxn()");
 }
 
 // -----------------------------------------------------------------------------
@@ -1647,6 +1648,55 @@ PAF_ASIT_initPhaseDecOpCircBuf(
 } //PAF_ASIT_initPhaseDecOpCircBuf
 
 
+// -----------------------------------------------------------------------------
+// ASIT Initialization Function - Output Init-Sync
+//
+//   Name:      PAF_ASIT_initPhaseOutIS
+//   Purpose:   Audio Stream Input Task Function for initialization of Output Init-Sync.
+//
+Int
+PAF_ASIT_initPhaseOutIS(
+    const PAF_ASIT_Params *pP, 
+    const PAF_ASIT_Patchs *pQ, 
+    PAF_ASIT_Config *pAsitCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode counter */
+    PAF_AST_OutInitSyncInfo *pOutISI;
+    Error_Block    eb;
+    Int i;
+
+
+    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    
+    /* Output Init-Sync memory */
+    if (!(pAstCfg->xOutIsi = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, 
+        DECODEN * sizeof (*pAstCfg->xOutIsi), 4, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASIT_initPhaseOutIS: AS%d: Memory_calloc failed", as);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+
+    // Reset all decoder stage flags
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        // Get address of Output Init-Sync Info
+        pOutISI = &pAstCfg->xOutIsi[z];
+        for (i = 0; i < ASP_OUTIS_NUM_DEC_STAGES; i++)
+        {
+            // Reset flag value
+            pOutISI->decStageOutInitSyncInfo[i].decFlag = 0;
+        }
+    }    
+    
+    return 0;
+} // PAF_ASIT_initPhaseOutIS
+
+
 #if 0
 // -----------------------------------------------------------------------------
 // AST Processing Function - Pass-Through Processing
@@ -2340,8 +2390,8 @@ PAF_ASIT_decodeProcessing(
                 errno = pP->fxns->decodeDecode(pP, pQ, pAsitCfg, sourceSelect, frame, block);
                 if (errno)
                 {
-                       gAsipDecodeErrCnt++;
-                       TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
+                    gAsipDecodeErrCnt++;
+                    TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
                     break;
                 }
                 
@@ -2540,6 +2590,7 @@ PAF_ASIT_decodeInit(
     Int status;
 #ifdef NON_CACHE_STATUS
     Int8 tempVar8;
+    Int tempVar;
 #endif
     
     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
@@ -2560,10 +2611,10 @@ PAF_ASIT_decodeInit(
                       GATEMP_INDEX_DEC);
         if (tempVar8)
         {
-            tempVar8 = 0;
+            tempVar = 0;
             statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
-                          &tempVar8,
-                          sizeof(tempVar8),
+                          &tempVar,
+                          sizeof(tempVar),
                           GATEMP_INDEX_DEC);
         }
     }
index c29c95f3a17e352f927918dc2a25874fb21e2795..d8d5469d6de4da87d3b4b4489acbadc3e749c380 100644 (file)
@@ -254,6 +254,15 @@ PAF_ASIT_initPhaseDevice(
     PAF_ASIT_Config *pAsitCfg
 );
 
+//   Purpose:   Audio Stream Input Task Function for initialization of Output Init-Sync.
+Int
+PAF_ASIT_initPhaseOutIS(
+    const PAF_ASIT_Params *pP, 
+    const PAF_ASIT_Patchs *pQ, 
+    PAF_ASIT_Config *pAsdtCfg
+);
+
+
 #if 0
 //   Purpose:   Audio Stream Task Function for initialization or reinitiali-
 //              zation of the Audio Frame(s) by loading of data values of a
index 1a521e70228ddd63b5812d65592e32174fa32912..90c8baf54f4110fba62383d26371bf558c49ee35 100644 (file)
@@ -56,14 +56,14 @@ All rights reserved.
 const PAF_ASIT_Fxns PAF_ASIT_params_fxns =
 {
     {   // initPhase[8]
-        PAF_ASIT_initPhaseMalloc,
-        PAF_ASIT_initPhaseConfig,
-        PAF_ASIT_initPhaseAcpAlg,
-        PAF_ASIT_initPhaseCommon,
-        PAF_ASIT_initPhaseAlgKey,
-        PAF_ASIT_initPhaseDevice,
-        PAF_ASIT_initPhaseDecOpCircBuf,
-        NULL
+        PAF_ASIT_initPhaseMalloc,           // initPhaseMalloc,
+        PAF_ASIT_initPhaseConfig,           // initPhaseConfig,
+        PAF_ASIT_initPhaseAcpAlg,           // initPhaseAcpAlg,
+        PAF_ASIT_initPhaseCommon,           // initPhaseCommon,
+        PAF_ASIT_initPhaseAlgKey,           // initPhaseAlgKey,
+        PAF_ASIT_initPhaseDevice,           // initPhaseDevice,
+        PAF_ASIT_initPhaseDecOpCircBuf,     // initPhaseDecOpCircBuf,
+        PAF_ASIT_initPhaseOutIS,            // initPhaseOutIS
     },
     NULL,                                   // passProcessing
     PAF_ASIT_autoProcessing,                // autoProcessing
index 80b7bbaf5f7dbd7cc6043b82190dbfe94bddc5e5..58e692840fdcc2dac6c0a80d6e13d61c1c20e7a8 100644 (file)
@@ -57,6 +57,7 @@ All rights reserved.
 #include "aspMsg_common.h"
 #include "aspMsg_master.h"
 #include "aspDecOpCircBuf_master.h"
+#include "aspOutInitSync_master.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamOutProc.h"
 
@@ -102,6 +103,29 @@ Int32 gNumPfpAsot1=0; // debug
 #define __TASK_NAME__  "TaskAsop"
 
 
+//
+// Audio Stream Output Task definitions
+//
+
+// status codes
+// Output FSM
+#define ASOP_INITSYNC_NOTREADY  (  1 )  // ok, init-sync not ready
+#define ASOP_SOK                (  0 )  // ok
+#define ASOP_FORWARD_ERR        ( -1 )  // forward (ASIT) error
+#define ASOP_ENCRESET_ERR       ( -2 )  // enc reset error
+#define ASOP_DECINFO1_ERR       ( -3 )  // dec info1 error
+// Decode Processing
+#define ASOP_DP_OUT_SIO_UPDATE  (  3 )  // new output selected
+#define ASOP_DP_CB_DRAINED      (  2 )  // circular buffer drained
+#define ASOP_DP_SOK             (  0 )  // ok
+#define ASOP_DP_FORWARD_ERR     ( -1 )  // forward (ASIT) error
+#define ASOP_DP_DECINIT_ERR     ( -2 )  // decode init error
+#define ASOP_DP_DECSTREAM_ERR   ( -3 )  // decode stream error
+#define ASOP_DP_DECENC_ERR      ( -4 )  // decode encode error
+#define ASOP_DP_DECFINAL_ERR    ( -5 )  // decode final error
+
+
+
 /* Check if at least one output selected */
 static Int checkOutSel(
     const PAF_ASOT_Params *pP, 
@@ -116,6 +140,58 @@ static Int checkOutSio(
     Int *pOutSioUpdate
 );
 
+// Initialize Output Processing state function
+static Int PAF_ASOT_initOutProc(
+    const PAF_ASOT_Params *pP, 
+    PAF_AST_Stream *xStr
+);
+
+// Initialize Output Processing state function
+static Int PAF_ASOT_initSyncDecReset(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecResetAf
+);
+
+//   Purpose:   ASOT Function for resetting output processing.
+static Int PAF_ASOT_outputReset(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+//   Purpose:   Init-Sync Dec Info1 state function.
+//              Performes Dec Info1 Init-Sync.
+static Int PAF_ASOT_initSyncDecInfo1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecInfo1Af
+);
+
+//   Purpose:   Init-Sync Re-Sync state function.
+//              Peformed Init-Sync using stored Dec Reset/Info1 AFs.
+static Int PAF_ASOT_initSyncResync(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecResetAf,
+    PAF_AudioFrame *pDecInfo1Af  
+);
+
+// Init-Sync update audio frame
+static Int initSyncUpdateAf(
+    PAF_AudioFrame *dstAf, 
+    PAF_AudioFrame *srcAf
+);
+
+// Reset audio frames
+static Void resetAfs(
+    const PAF_ASOT_Params *pP, 
+    PAF_AST_Stream *xStr
+);
+
 // Reset audio frame pointers to original values
 static Void resetAfPointers(
     const PAF_ASOT_Params *pP, 
@@ -137,6 +213,7 @@ ERRNO_DEFN(TaskAsop); /* Error number macros */
 PAF_ASOT_Config gPAF_ASOT_config = {
     NULL,               // taskHandle
     NULL,               // acp
+    0,0,0,              // CB drained flags (size DECODE_MAXN)
     &gPAF_ASPM_config,  // pAspmCfg
     &gPAF_AST_config    // pAstCfg
 };
@@ -155,6 +232,7 @@ UInt32 gAsopStreamCnt       =0;
 UInt32 gAsopEncodeCnt       =0;
 UInt32 gAsopFinalCnt        =0;
 UInt32 gAsopQuitCnt         =0;
+UInt32 gAsopOutSioUpdateCnt =0;
 
 
 /*
@@ -176,6 +254,10 @@ Void taskAsopFxn(
     Int zMS;
     Int loopCount = 0;  // used to stop trace to see startup behavior.        
     Int outSel;
+    enum { INIT_OUT_PROC_STATE, INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_RESYNC_STATE, OUT_PROC_STATE } state;
+    PAF_AudioFrame decResetAf;
+    PAF_AudioFrame decInfo1Af;
+    
 
     Log_info0("Enter taskAsopFxn()");    
 
@@ -272,6 +354,7 @@ Void taskAsopFxn(
         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
     }
     
+    state = INIT_OUT_PROC_STATE;    // initialize state
     errno = 0;                      // reset error indicator
     for (;;)
     {
@@ -307,7 +390,7 @@ Void taskAsopFxn(
 
         // if no output selected skip remaining processing
         errno = checkOutSel(pP, pAsotCfg, &outSel);
-        if (errno)
+        if (errno < 0)
         {
             TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
             continue;
@@ -318,19 +401,160 @@ Void taskAsopFxn(
             continue;
         }
         
-        TRACE_VERBOSE0("TaskAsop: calling outputProcessing.");
-        errno = pP->fxns->decodeProcessing(pP, pQ, pAsotCfg);
-        if (errno) 
+        switch (state)
         {
-            TRACE_TERSE1("TaskAsop: outputProcessing returns 0x%x, continue", errno);
+            case INIT_OUT_PROC_STATE:
+                //
+                // Output Processing initialization.
+                //
+                errno = PAF_ASOT_initOutProc(pP, pAstCfg->xStr);
+                if (errno < 0)
+                {
+                    state = INIT_OUT_PROC_STATE;
+                }
+                else
+                {
+                    state = INITSYNC_DEC_RESET_STATE;
+                }
+            
+                break;
+                
+            case INITSYNC_DEC_RESET_STATE:
+                //
+                // Dec Reset Init-Sync.
+                //  
+                
+                // Perform Dec Reset init-sync.
+                // Latch Dec Reset AF.
+                errno = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, &decResetAf);
+                if (errno < 0)
+                {
+                    // sync error -- start over
+                    state = INIT_OUT_PROC_STATE;
+                }
+                else if (errno == ASOP_INITSYNC_NOTREADY)
+                {
+                    // sync not ready -- try again
+                    state = INITSYNC_DEC_RESET_STATE;
+                }
+                else
+                {
+                    // sync'd -- move on
+                    state = INITSYNC_DEC_INFO1_STATE;
+                }
+                
+                break;
+            
+            case INITSYNC_DEC_INFO1_STATE:
+                //
+                // Dec Info1 Init-Sync.
+                //
+
+                // Perform Dec Info1 init-sync.
+                // Latch Dec Info1 AF.
+                errno = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af);
+                if (errno < 0)
+                {
+                    // sync error -- start over
+                    state = INIT_OUT_PROC_STATE;
+                }
+                else if (errno == ASOP_INITSYNC_NOTREADY)
+                {
+                    // sync not ready -- try again
+                    state = INITSYNC_DEC_INFO1_STATE;
+                }
+                else
+                {
+                    // sync'd -- move on
+                    state = OUT_PROC_STATE;
+                }
+                
+                break;
+            
+            case INITSYNC_RESYNC_STATE:
+                //
+                // Re-Sync.
+                // Use stored AF info from init-sync.
+                // This is done in case of local error.
+                //
+                
+                // Perform Dec Info1 init-sync.
+                errno = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf, 
+                    &decInfo1Af);
+                if (errno < 0)
+                {
+                    // sync error -- start over
+                    state = INIT_OUT_PROC_STATE;
+                }
+                else
+                {
+                    // re-sync'd -- move on
+                    state = OUT_PROC_STATE;
+                }
+                    
+                break;
+            
+            case OUT_PROC_STATE:        
+                //
+                // Output Processing.
+                //
+
+                TRACE_VERBOSE0("TaskAsop: calling outputProcessing.");
+                errno = pP->fxns->decodeProcessing(pP, pQ, pAsotCfg);
+                if (errno < 0)
+                {
+                    //
+                    // Output Processing exit, due to error
+                    //
+                    
+                    TRACE_TERSE1("TaskAsop: outputProcessing returns 0x%x, continue", errno);
+                    if (errno == ASOP_DP_FORWARD_ERR)
+                    {
+                        // forward (ASIT) error -- start over
+                        state = INIT_OUT_PROC_STATE;
+                    }
+                    else
+                    {
+                        // local (ASOT) error
+                        state = INITSYNC_RESYNC_STATE;    
+                    }        
+                }
+                else if (errno > 0)
+                {
+                    //
+                    // Output Processing exit, not due to error
+                    //
+
+                    TRACE_TERSE1("TaskAsop: outputProcessing returns 0x%x, continue", errno);                    
+                    if (errno == ASOP_DP_OUT_SIO_UPDATE)
+                    {
+                        // skip re-sync
+                        // resume output processing after new output selected
+                        state = OUT_PROC_STATE;
+                    }
+                }
+                else
+                {
+                    //
+                    // Output Processing exit, normal
+                    //
+                    
+                    TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
+                    
+                    // no error returned if CB drained 
+                    // (i.e. CB drained is normal behavior)
+                    state = OUT_PROC_STATE;
+                }
+                
+                break;
+            
+            default: // unknown state
+                TRACE_TERSE2("TaskAsop: AS%d: state: unknown, 0x%x", as+zMS, state);
+                break;
         }
-        else
-        {
-            TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
-        }        
     } // End of main processing loop for (;;)
     
-    Log_info0("Exit taskAsopFxn()");
+    //Log_info0("Exit taskAsopFxn()");
 }
 
 // -----------------------------------------------------------------------------
@@ -1356,7 +1580,7 @@ PAF_ASOT_decodeProcessing(
     PAF_AST_Config *pAstCfg;
     Int errno;                          /* error number */
     Int getVal;
-    enum { INIT, STREAM, ENCODE, FINAL, QUIT } state;
+    enum { INIT, STREAM, ENCODE, FINAL, QUIT, OUT_SIO_UPDATE } state;
     state = INIT;
     errno = 0; /* error number */
     Int frame; // (***) FL: formerly -- decoder input frame count
@@ -1370,7 +1594,7 @@ PAF_ASOT_decodeProcessing(
         // FL: Check if any change in output SIO, e.g. from Output shortcut.
         // Changes will break FSM and allow Output reconfiguration.
         errno = checkOutSio(pP, pAsotCfg, &outSioUpdate);
-        if (errno)
+        if (errno < 0)
         {
             TRACE_TERSE1("PAF_ASOT_decodeProcessing: checkOutSio returned errno = 0x%04x", errno);
             break;
@@ -1378,7 +1602,7 @@ PAF_ASOT_decodeProcessing(
         else if (outSioUpdate)
         {
             TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Change in Output SIO selection");
-            state = QUIT;
+            state = OUT_SIO_UPDATE;
         }
         
         // Process commands (encode)
@@ -1395,21 +1619,29 @@ PAF_ASOT_decodeProcessing(
                 gAsopInitCnt++;
                 Log_info0("TaskAsop: state=INIT");
             
+                frame = 0;
+                block = 0;
+
+#if 0 // FL: moved to PAF_ASOT_initOutProc()
                 // Reset audio frame pointers to original values
                 // (may be needed if error occurred).
                 resetAfPointers(pP, pAstCfg->xStr);
                 // Reset audio frame meta data elements
                 resetAfMetadata(pP, pAstCfg->xStr);
+#endif
 
                 errno = pP->fxns->decodeInit(pP, pQ, pAsotCfg);
                 if (errno)
                 {
                     TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x.  break after decodeInit", errno);
+                    errno = ASOP_DP_DECINIT_ERR;
                     break;
                 }
                 
-                // (***) FL: setup output (ASP chain reset, ENC reset, setCheckRateX, start output)
-                //           Contained in INFO1 in combined FSM.
+#if 0 // FL: moved to PAF_ASOT_initSyncDecInfo1()
+                //
+                // Setup output: ASP chain reset, ENC reset, setCheckRateX, start output
+                //
                 // Establish secondary timing
                 errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, frame, block);
                 if (errno)
@@ -1417,10 +1649,8 @@ PAF_ASOT_decodeProcessing(
                     TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x.  break after decodeInfo1", errno);
                     break;
                 }
-
-                frame = 0;
-                block = 0;
-
+#endif
+                
                 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: INIT->STREAM");                
                 state = STREAM;
                 continue;
@@ -1433,6 +1663,7 @@ PAF_ASOT_decodeProcessing(
                 if (errno)
                 {
                     TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: STREAM.  decodeStream err 0x%x", errno);
+                    errno = ASOP_DP_DECSTREAM_ERR;
                     break;
                 }
 
@@ -1448,6 +1679,7 @@ PAF_ASOT_decodeProcessing(
                 if (errno)
                 {
                     TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: ENCODE.  decodeEncode err 0x%x", errno);
+                    errno = ASOP_DP_DECENC_ERR;
                     break;
                 }
                 
@@ -1471,6 +1703,7 @@ PAF_ASOT_decodeProcessing(
                 if (errno)
                 {
                     TRACE_TERSE1("PAF_ASOT_decodeProcessing: ENCODE break on decodeInfo2. errno 0x%x", errno);
+                    errno = ASOP_DP_DECENC_ERR;
                     break;
                 }
 
@@ -1490,11 +1723,11 @@ PAF_ASOT_decodeProcessing(
                 //              will probably always exit FSM if only Output running
                 //       (2) Checking Dec Status info asych to input events (maybe ok)
                 //
-#if 0
                 // Check for final frame, and if indicated:
                 // - Update audio flag to cause output buffer flush rather than
                 //   the default truncate in "complete" processing.
                 // - Exit state machine to "complete" processing.
+#if 0
                 if (pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block)) 
                 {
                     for (z=OUTPUT1; z < OUTPUTN; z++)
@@ -1507,12 +1740,34 @@ PAF_ASOT_decodeProcessing(
                     }
                     break;
                 }
-#endif                
+#endif
+                errno = pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block);
+                if (errno < 0)
+                {
+                    TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL break. errno 0x%x", errno);
+                    errno = ASOP_DP_DECFINAL_ERR;
+                    break;
+                }
+                else if (errno == ASOP_DP_CB_DRAINED)
+                {
+                    // EOS, exit normally
+                    TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL normal exit. errno 0x%x", errno);
+                    errno = ASOP_DP_SOK;
+                    break;
+                }
 
                 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: FINAL->STREAM");
                 state = STREAM;
                 continue;
                 
+            case OUT_SIO_UPDATE:
+                gAsopOutSioUpdateCnt++;
+                Log_info0("TaskAsop: state=OUT_SIO_UPDATE");
+
+                TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: OUT_SIO_UPDATE");
+                errno = ASOP_DP_OUT_SIO_UPDATE;
+                break;
+                
             case QUIT:
                 gAsopQuitCnt++;
                 Log_info0("TaskAsop: state=QUIT");
@@ -1646,16 +1901,15 @@ PAF_ASOT_decodeInit(
     PAF_ASOT_Config *pAsotCfg
 )
 {
-    PAF_AST_Config *pAstCfg;
+    //PAF_AST_Config *pAstCfg;
     PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
-    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    //Int as;                             /* Audio Stream Number (1, 2, etc.) */
     Int z;                              /* decode/encode counter */
     Int errno;                          /* error number */
-    Int zO, zS;
-
+    //Int zO, zS;
 
-    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
-    as = pAstCfg->as;
+    //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    //as = pAstCfg->as;
 
     pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
 
@@ -1678,6 +1932,7 @@ PAF_ASOT_decodeInit(
         cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
     }
     
+#if 0 // moved to PAF_ASOT_outputReset()
     // TODO: move this to start of this function so that it doesn't affect IO timing
     for (z=ENCODE1; z < ENCODEN; z++) 
     {
@@ -1693,15 +1948,18 @@ PAF_ASOT_decodeInit(
             {
                 encAlg->fxns->algActivate (encAlg);
             }
-            if (enc->fxns->reset
-                && (errno = enc->fxns->reset(enc, NULL,
-                    &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus)))
+            if (enc->fxns->reset)
             {
-                return errno;
+                errno = enc->fxns->reset(enc, NULL, 
+                    &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus);
+                if (errno)
+                {
+                    return errno;
+                }
             }
         }
     }
-    
+#endif
     
     return 0;
 }
@@ -1736,8 +1994,9 @@ PAF_ASOT_decodeInfo1(
 
     // run the chain of ASP's on the stream.
     TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
-    if (errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg, 
-        PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame))
+    errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg, 
+        PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame);
+    if (errno)
     {
         TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
         return errno;
@@ -1752,17 +2011,23 @@ PAF_ASOT_decodeInfo1(
             Int select = pAstCfg->xEnc[z].encodeStatus.select;
             ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
             ENC_Handle enc = (ENC_Handle )encAlg;
-            if (enc->fxns->info
-                && (errno = enc->fxns->info(enc, NULL,
-                    &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus)))
+            
+            if (enc->fxns->info)
             {
-                TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
-                return errno;
+                errno = enc->fxns->info(enc, NULL,
+                    &pAstCfg->xEnc[z].encodeControl, 
+                    &pAstCfg->xEnc[z].encodeStatus);
+                if (errno)
+                {
+                    TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
+                    return errno;
+                }
             }
         }
     }
 
-    if (errno = pP->fxns->setCheckRateX(pP, pQ, pAsotCfg, 0))
+    errno = pP->fxns->setCheckRateX(pP, pQ, pAsotCfg, 0);
+    if (errno)
     {
         // ignore if rateX has changed since we haven't, but are about to,
         // start the output. If we didn't ignore this case then the state machine
@@ -1779,7 +2044,8 @@ PAF_ASOT_decodeInfo1(
         }
     }
 
-    if (errno = pP->fxns->startOutput(pP, pQ, pAsotCfg)) 
+    errno = pP->fxns->startOutput(pP, pQ, pAsotCfg);
+    if (errno) 
     {
         if (errno == 0x105) 
         {
@@ -1857,14 +2123,13 @@ PAF_ASOT_decodeStream(
     PAF_AudioFrame *pAfRd;
     Int cbErrno;
     PAF_AST_DecOpCircBufStats cbStats;  /* circular buffer statistics */
-    Int8 cbDrained;
     Int errno;
 
 
     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
     
     pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
-
+    
     for (z=DECODE1; z < DECODEN; z++) 
     {
         Int zS = pP->streamsFromDecodes[z];
@@ -1874,7 +2139,7 @@ PAF_ASOT_decodeStream(
         //
         pAfRd = pAstCfg->xStr[zS].pAudioFrame;
         //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
-        cbErrno = cbReadAf(pCbCtl, z, pAfRd, &cbDrained);
+        cbErrno = cbReadAf(pCbCtl, z, pAfRd);
         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_READ_UNDERFLOW))
         {
             gCbReadAfErr++;
@@ -2721,7 +2986,7 @@ static Int checkOutSel(
     
     *pOutSel = outSel;
 
-    return 0;
+    return ASOP_SOK;
 }
 
 /* Check if at least one output sio changed */
@@ -2749,7 +3014,20 @@ static Int checkOutSio(
     
     *pOutSioUpdate = outSioUpdate;
 
-    return 0;    
+    return ASOP_SOK;
+}
+
+// Reset audio frames
+static Void resetAfs(
+    const PAF_ASOT_Params *pP, 
+    PAF_AST_Stream *xStr
+)
+{
+    // Reset audio frame pointers to original values
+    // (may be needed if error occurred).
+    resetAfPointers(pP, xStr);
+    // Reset audio frame meta data elements
+    resetAfMetadata(pP, xStr);
 }
 
 // Reset audio frame pointers to original values
@@ -2798,3 +3076,303 @@ static Void resetAfMetadata(
         }
     }
 }
+
+// Initialize Output Processing state function
+static Int PAF_ASOT_initOutProc(
+    const PAF_ASOT_Params *pP, 
+    PAF_AST_Stream *xStr
+)
+{
+    // Reset audio frames
+    resetAfs(pP, xStr);
+    
+    return ASOP_SOK;
+}
+
+// Init-Sync update audio frame
+static Int initSyncUpdateAf(
+    PAF_AudioFrame *dstAf, 
+    PAF_AudioFrame *srcAf
+)
+{
+    memcpy(dstAf, srcAf, sizeof(PAF_AudioFrame));
+    
+    return ASOP_SOK;
+}
+
+//   Purpose:   Init-Sync Dec Reset state function.
+//              Performes Dec Reset Init-Sync.
+static Int PAF_ASOT_initSyncDecReset(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecResetAf
+)
+{
+    PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
+    Int zMD, zMS;                       // Dec and Stream Master indices
+    PAF_AudioFrame *pStrAf;             // stream audio frame
+    PAF_AST_OutInitSyncCtl *pOutIsCtl;  // Output Init-Sync control
+    Int8 decFlag;                       // dec stage flag
+    Int errno;                          // error number
+
+    
+    pAstCfg = pAsotCfg->pAstCfg;
+    zMD = pAstCfg->masterDec;
+    pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
+    
+    // check for Dec Reset
+    // store dec reset AF
+    errno = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
+        ASP_OUTIS_DEC_STAGE_RESET_IDX, &decFlag, pDecResetAf);
+    if (errno < 0)
+    {
+        return errno;
+    }
+    
+    if (decFlag == 0)
+    {
+        return ASOP_INITSYNC_NOTREADY;
+    }
+    else
+    {
+        zMS = pAstCfg->masterStr;
+        pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
+        
+        // Update Stream Audio Frame.
+        // Copy Dec Reset AF to Stream AF.
+        errno = initSyncUpdateAf(pStrAf, pDecResetAf);
+        if (errno < 0)
+        {
+            return errno;
+        }
+        
+        // Enc activate
+        // Enc reset
+        errno = PAF_ASOT_outputReset(pP, pQ, pAsotCfg);
+        if (errno < 0)
+        {
+            return errno;
+        }
+        
+        return ASOP_SOK;
+    }
+}
+
+//   Purpose:   ASOT Function for resetting output processing.
+static Int PAF_ASOT_outputReset(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    Int as;                     // Audio Stream Number (1, 2, etc.) */
+    Int z;                      // encode counter
+    Int errno;                  // error number
+    Int zO, zS;
+
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+
+    for (z=ENCODE1; z < ENCODEN; z++) 
+    {
+        zO = pP->outputsFromEncodes[z];
+        zS = pP->streamsFromEncodes[z];
+        if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode) 
+        {
+            Int select = pAstCfg->xEnc[z].encodeStatus.select;
+            ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
+            ENC_Handle enc = (ENC_Handle )encAlg;
+
+            TRACE_VERBOSE1("AS%d: PAF_ASOT_outputReset: initializing encode", as+zS);
+
+            if (encAlg->fxns->algActivate)
+            {
+                encAlg->fxns->algActivate(encAlg);
+            }
+            
+            if (enc->fxns->reset)
+            {
+                errno = enc->fxns->reset(enc, NULL, 
+                    &pAstCfg->xEnc[z].encodeControl, 
+                    &pAstCfg->xEnc[z].encodeStatus);
+                if (errno)
+                {
+                    return ASOP_ENCRESET_ERR;
+                }
+            }
+        }
+    }    
+    
+    return ASOP_SOK;
+}
+
+//   Purpose:   Init-Sync Dec Info1 state function.
+//              Performes Dec Info1 Init-Sync.
+static Int PAF_ASOT_initSyncDecInfo1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecInfo1Af
+)
+{
+    PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
+    Int zMD, zMS;                       // Dec and Stream Master indices
+    PAF_AudioFrame *pStrAf;             // stream audio frame
+    PAF_AST_OutInitSyncCtl *pOutIsCtl;  // Output Init-Sync control
+    Int8 decFlag;                       // dec stage flag
+    Int errno;                          // error number
+
+    
+    pAstCfg = pAsotCfg->pAstCfg;
+    zMD = pAstCfg->masterDec;
+    pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
+    
+    // Check for Dec Reset, 
+    // Store dec reset AF
+    errno = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
+        ASP_OUTIS_DEC_STAGE_INFO1_IDX, &decFlag, pDecInfo1Af);
+    if (errno < 0)
+    {
+        return errno;
+    }
+    
+    if (decFlag == 0)
+    {
+        return ASOP_INITSYNC_NOTREADY;
+    }
+    else
+    {
+        zMS = pAstCfg->masterStr;
+        pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
+        
+        // Update Stream Audio Frame.
+        // Copy Dec Reset AF to Stream AF.
+        errno = initSyncUpdateAf(pStrAf, pDecInfo1Af);
+        if (errno < 0)
+        {
+            return errno;
+        }
+        
+        // decodeInfo1():
+        //      - ASP chain reset,
+        //      - Enc Info,
+        //      - setCheckRateX,
+        //      - startOutput
+        // frame and block parameters set to 0
+        errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, 0, 0);
+        if (errno)
+        {
+            return ASOP_DECINFO1_ERR;
+        }
+        
+        return ASOP_SOK;
+    }
+}
+
+//   Purpose:   Init-Sync Re-Sync state function.
+//              Peformed Init-Sync using stored Dec Reset/Info1 AFs.
+static Int PAF_ASOT_initSyncResync(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecResetAf,
+    PAF_AudioFrame *pDecInfo1Af    
+)
+{
+    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    Int zMS;                    // Stream Master index
+    PAF_AudioFrame *pStrAf;     // stream audio frame
+    Int errno;                  // error number
+
+    
+    pAstCfg = pAsotCfg->pAstCfg;
+    zMS = pAstCfg->masterStr;
+    pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
+        
+    // Reset audio frames
+    resetAfs(pP, pAstCfg->xStr);
+    
+    //
+    // Dec Reset re-sync using stored Dec Reset AF
+    //
+    
+    // Update Stream Audio Frame.
+    // Copy Dec Reset AF to Stream AF.
+    errno = initSyncUpdateAf(pStrAf, pDecResetAf);
+    if (errno < 0)
+    {
+        return errno;
+    }
+    
+    // Enc activate,
+    // Enc reset
+    errno = PAF_ASOT_outputReset(pP, pQ, pAsotCfg);
+    if (errno)
+    {
+        return errno;
+    }
+    
+    //
+    // Dec Info1 re-sync using sotred Dec Info1 AF
+    //
+    
+    // Update Stream Audio Frame.
+    // Copy Dec Info1 AF to Stream AF.
+    errno = initSyncUpdateAf(pStrAf, pDecInfo1Af);
+    if (errno < 0)
+    {
+        return errno;
+    }
+    
+    // decodeInfo1():
+    //      - ASP chain reset,
+    //      - Enc Info,
+    //      - setCheckRateX,
+    //      - startOutput
+    // frame and block parameters set to 0
+    errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, 0, 0);
+    if (errno)
+    {
+        return errno;
+    }
+    
+    return ASOP_SOK;    
+}
+
+//   Purpose:   Decoding Function for determining whether processing of the
+//              current stream is complete.
+Int
+PAF_ASOT_decodeFinalTest(
+    const struct PAF_ASOT_Params *pP, 
+    const struct PAF_ASOT_Patchs *pQ, 
+    struct PAF_ASOT_Config *pAsotCfg, 
+    Int frame, 
+    Int block
+)
+{
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    // decoder output circular buffer control
+    Int8 drainedFlag;                   // CB drained indicator flag
+    Int zMD;                            // master Dec index
+    Int errno;                          // error number
+
+    
+    pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+    zMD = pAsotCfg->pAstCfg->masterDec; // get master Dec index
+
+    // Check circular buffer drain state
+    errno = cbCheckDrainState(pCbCtl, zMD, &drainedFlag);
+    if (errno < 0)
+    {
+        return errno;
+    }
+    
+    if (drainedFlag == 0)
+    {
+        return ASOP_DP_CB_DRAINED;
+    }
+    
+    return ASOP_DP_SOK;
+}    
index 47661ddb36dca37aa777ec106308d5b4026ecb1f..e1a42ac8f77c49776ce4e8d4a82c404fcc4e3a56 100644 (file)
@@ -80,7 +80,10 @@ typedef struct PAF_ASOT_Fxns {
     //Int (*decodeDecode) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int, Int);
     Int (*decodeStream) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
     Int (*decodeEncode) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
+
     //Int (*decodeFinalTest) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int);    
+    Int (*decodeFinalTest) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);    
+
     Int (*decodeComplete) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, ALG_Handle *, Int, Int);
     Int (*selectDevices) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
     //Int (*sourceDecode) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int);
@@ -183,10 +186,11 @@ typedef struct PAF_ASOT_Patchs {
 
 // Audio Stream Input Task (ASOT) configuration
 typedef struct PAF_ASOT_Config {
-    Task_Handle taskHandle;     // ASOT handle
-    ACP_Handle acp;             // ASOT local ACP handle
-    PAF_ASPM_Config *pAspmCfg;  // ASIT/ASOT shared configuration
-    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    Task_Handle taskHandle;             // ASOT handle
+    ACP_Handle acp;                     // ASOT local ACP handle
+    Int8 cbDrainedFlag[DECODEN_MAX];    // CB drained flags
+    PAF_ASPM_Config *pAspmCfg;          // ASIT/ASOT shared configuration
+    PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
 } PAF_ASOT_Config;
 
 
@@ -411,5 +415,15 @@ PAF_ASOT_streamChainFunction(
     Int logArg
 );
 
-#endif /* _ASOP_H_ */
+//   Purpose:   Decoding Function for determining whether processing of the
+//              current stream is complete.
+Int
+PAF_ASOT_decodeFinalTest(
+    const struct PAF_ASOT_Params *pP, 
+    const struct PAF_ASOT_Patchs *pQ, 
+    struct PAF_ASOT_Config *pAsotCfg, 
+    Int frame, 
+    Int block
+);
 
+#endif /* _ASOP_H_ */
index 0fdb01cdaba22923d7fa70f70622063790afed04..32a9dbfa487b5df3b887132e147fd8818bd48ec9 100644 (file)
@@ -74,6 +74,7 @@ const PAF_ASOT_Fxns PAF_ASOT_params_fxns =
     PAF_ASOT_decodeInfo2,                   // decodeInfo2
     PAF_ASOT_decodeStream,                  // decodeStream
     PAF_ASOT_decodeEncode,                  // decodeEncode
+    PAF_ASOT_decodeFinalTest,               // decodeFinalTest
     PAF_ASOT_decodeComplete,                // decodeComplete
     PAF_ASOT_selectDevices,                 // selectDevices
     PAF_ASOT_startOutput,                   // startOutput
index 18562cbe80e6367fdc87ac814142534a187c6ca3..ad453a8aff0de288a9cbce9be29bf111dc38d6b6 100644 (file)
@@ -44,5 +44,6 @@ All rights reserved.
 // ASPM configuration-- ASIT/ASOT shared
 #pragma DATA_SECTION(gPAF_ASPM_config, ".globalSectionPafAspmConfig")
 PAF_ASPM_Config gPAF_ASPM_config = {
-    { NULL, NULL }   // gateHandle, xDecOpCb
+    { NULL, 0, NULL }, // gateHandle, numCb, xDecOpCb
+    { NULL, NULL }, // gateHandle, xOutIsi
 };
index 3a458a5645f36de1e6dd94d56e0fc3483b879540..c5a3c0b968e2eb39e081514d1bbb97de5b00457c 100644 (file)
@@ -42,12 +42,14 @@ All rights reserved.
  
 #include <xdc/std.h>
 #include "aspDecOpCircBuf_common.h"
+#include "aspOutInitSync_common.h"
 
 // Audio Stream Processing Master configuration--
 // Audio Stream Input/Output Task shared
 typedef struct PAF_ASPM_Config 
 {
-    PAF_AST_DecOpCircBufCtl decOpCircBufCtl; // decoder output circular buffer control
+    PAF_AST_DecOpCircBufCtl decOpCircBufCtl;    // decoder output circular buffer control
+    PAF_AST_OutInitSyncCtl outIsCtl;            // output init-sync control
 } PAF_ASPM_Config;
 
 extern PAF_ASPM_Config gPAF_ASPM_config;