Fixed problem of input task being stuck when input stream stops:
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProcNewIO.c
index 977fbf17c9913032d783933e091d9baf0aabc7f6..4d95b8b4bd579144d7b9c4d114d1a59a57157707 100644 (file)
@@ -114,7 +114,7 @@ extern XDAS_Int32 D10_RxControl(const void *pD10RxParams,
  */
 int asipPrepareProcessing();
 int asipIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo);
-void asipProcInit(PAF_AST_IoInp  *pInp);
+void asipProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec);
 void asipIoPhyPrime(PAF_AST_IoInp *pInpIo);
 void asipPhyTransferPend(void);
 void asipPhyTransferComplete(PAF_AST_IoInp * pInpIo);
@@ -190,6 +190,8 @@ Int asipErrno;
 Int inputReadyForProcessing;
 #endif
 
+    Int firstTimeInit = TRUE;
+
     Log_info0("Enter taskAsipFxn()");
 
     taskAsipFxnInit(pP, pQ);  // initialization of input task
@@ -240,14 +242,21 @@ Int inputReadyForProcessing;
 
             inputReadyForProcessing = asipPrepareProcessing(pP, pQ, pAsitCfg, &asipErrno);
             if (inputReadyForProcessing) {
-                // Input is ready for processing, so we initialize the I/O components
-                asipIoCompsInit(&pAstCfg->xInp[zMI], pInp);
+                // Input is ready for processing, so we initialize the I/O components.
+                // Note that the I/O components init. and I/O PHY prime are performed only at the
+                // first time. This should be changed later - init. and prime should be done whenever
+                // input interface has changed.
+                if(firstTimeInit) {
+                    asipIoCompsInit(&pAstCfg->xInp[zMI], pInp);
 
-                // Initialize ASIP processing
-                asipProcInit(pInp);
+                    // Start I/O physical layer by priming McASP LLD for input
+                    asipIoPhyPrime(pInp);
 
-                // Start I/O physical layer by priming McASP LLD for input
-                asipIoPhyPrime(pInp);
+                    firstTimeInit = FALSE;
+                }
+
+                // Initialize ASIP processing
+                asipProcInit(pInp, &pAsitCfg->inpDec);
 
                 pInp->asipState = ASIP_INPUT_PROCESSING;
             }
@@ -418,7 +427,7 @@ int asipIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
 
     pInpIo->numPrimeXfers  = NUM_PRIME_XFERS;
     pInpIo->phyXferSize    = ioPhyParams.xferFrameSize;
-    pInpIo->switchHangOver = 0;
+    //pInpIo->switchHangOver = 0;
     pInpIo->preSyncState   = IODATA_SYNC_NONE;
 
     return 0;
@@ -427,11 +436,13 @@ int asipIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
 /*======================================================================================
  *  This function initializes ASIP processing
  *====================================================================================*/
-void asipProcInit(PAF_AST_IoInp  *pInp)
+void asipProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec)
 {
     pInp->swapData = SWAP_INPUT_DATA;
     pInp->asipProcState = ASIP_SOURCE_DETECTION;
-    pInp->switchHangOver = 0;
+    //pInp->switchHangOver = 0;
+
+    pDec->initDone = FALSE;
 }
 
 /*======================================================================================
@@ -726,7 +737,7 @@ Int asipUpdateIoComps(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
     if(autoDetStatus->syncState == IODATA_SYNC_BITSTREAM) {
         // Change I/O PHY transfer size to be the same as the bitstream frame size
         uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
-        frameLength = iecFrameLength[pc] * WORD_SIZE_BITSTREAM;
+        frameLength = iecFrameLength[pc];
 
         // update input buffer config structure
         pBufConfig->sizeofElement = WORD_SIZE_BITSTREAM;
@@ -888,6 +899,7 @@ Int asipDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
         return ASIP_ERR_NO_MATCHING_SOURCE;
     }
 
+#ifndef PCM_LOOPBACK_TEST
     // send source select message to slave
     *(Int32 *)&asipMsgBuf[0] = sourceSelect;
     if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
@@ -895,6 +907,7 @@ Int asipDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
         TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
         SW_BREAKPOINT;
     }
+#endif
 
     pInp->sourceSelect  = sourceSelect;
     pInp->sourceProgram = sourceProgram;
@@ -1003,12 +1016,14 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
             else {
                 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
                 // iff we are in this top level state machine and specifically not in decodeProcessing
+#ifndef PCM_LOOPBACK_TEST
                 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
+#endif
 
                 if(autoDetStatus.syncState == IODATA_SYNC_BITSTREAM) {
                     // Input is bit stream: go to decoding
                     pInp->asipProcState = ASIP_DECODE;
-                    pInp->numFrameReceived = 1;
+                    //pInp->numFrameReceived = 1;
                 }
                 else  {
                     // Input is PCM: stop swapping data
@@ -1023,16 +1038,11 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
                     // Go to transition state to switch to PCM
                     pInp->asipProcState = ASIP_SWITCH_TO_PCM;
                     pInp->switchHangOver = INPUT_SWITCH_HANGOVER;
-                    pInp->numPcmFrameReceived = 0;
-                }
-
-                // Initialize decoder
-                asipStatus = asipDecodeInit(pP, pAsitCfg, pInp->sourceSelect);
-                if(asipStatus != ASIP_NO_ERR) {
-                    return asipStatus;
+                    //pInp->numPcmFrameReceived = 0;
                 }
             }
 
+            pInp->numFrameReceived = 0;
             pInp->preSyncState = autoDetStatus.syncState;
         }
         else {
@@ -1048,12 +1058,6 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
         pInp->switchHangOver--;
         if(pInp->switchHangOver == 0) {
             pInp->asipProcState = ASIP_DECODE;
-
-            // Init decoder and send message to decoder
-            //asipStatus = asipDecodeInit(pP, pAsitCfg, pInp->sourceSelect);
-            //if(asipStatus != ASIP_NO_ERR) {
-            //    return asipStatus;
-            //}
         }
         break;
 
@@ -1077,24 +1081,37 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
             }
 
             // Inform decoder to complete decoding previous frame
-            pInp->sourceSelect = PAF_SOURCE_UNKNOWN;
+            pInp->sourceSelect = PAF_SOURCE_NONE;
 
             pInp->numFrameReceived = 0;
             pInp->asipProcState  = ASIP_SOURCE_DETECTION;
         }
         else {
-            pInp->numFrameReceived += 1;
+            pInp->numFrameReceived += 1;    // for debugging
 
             // Communicate input stream information to decoder through input buffer configuration
             asipUpdateInpBufConfig(pAstCfg, pInp);
         }
 
+#ifndef PCM_LOOPBACK_TEST
         asipStatus = asipDecodeProcessing(pP, pQ, pAsitCfg, pInp->sourceSelect);
         if(asipStatus != ASIP_NO_ERR) {
+
+            // FL: send dec exit message to slave
+            if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
+                != ASP_MSG_NO_ERR)
+            {
+                TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
+                SW_BREAKPOINT;
+            }
+
             return asipStatus;
         }
-
-        //rxDecodePcm(pInp);     // for PCM loopback testing
+#else
+        if(autoDetStatus.syncState == IODATA_SYNC_PCM) {
+            rxDecodePcm(pInp);     // for PCM loopback testing
+        }
+#endif
         break;
 
     default: