Fixed frame length discrepancy between ASIT and decoder.
authorJianzhong Xu <a0869574@ti.com>
Wed, 31 Jan 2018 17:18:16 +0000 (12:18 -0500)
committerJianzhong Xu <a0869574@ti.com>
Wed, 31 Jan 2018 17:18:16 +0000 (12:18 -0500)
pasdk/test_dsp/framework/audioStreamInpDec.c
pasdk/test_dsp/framework/audioStreamInpProc.h
pasdk/test_dsp/framework/audioStreamInpProcNewIO.c
pasdk/test_dsp/io/ioData.c

index b15f928e78aef531858bdbc3683fecc2491cece5..bb0813c249a7bc8d02f33fd422c1b55440b8e9a6 100644 (file)
@@ -372,11 +372,11 @@ static Int decDecodeInit(
 
             // Compute decoder frame length based on source selection
             // JXU: what does this function do? why does it only return PCM frame length?
-            frameLength = getFrameLengthSourceSel(pP, sourceSelect);
+            /*frameLength = getFrameLengthSourceSel(pP, sourceSelect);
 
             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
-            pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
+            pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;*/
 
 /*
             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
@@ -385,9 +385,6 @@ static Int decDecodeInit(
                 }
             }
 */
-            // JXU: who changes sourceSelect? why not use sourceSelect passed to this function?
-            pInp[z].sourceSelect = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
-                                                     GATEMP_INDEX_DEC);
 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
             ioDataCtl.param.frameLengthPcm = frameLength;
@@ -703,15 +700,10 @@ static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
 #endif
 
             // Compute decoder frame length based on source selection
-            frameLength = getFrameLengthSourceSel(pP, sourceSelect);
-
-            pAstCfg->xDec[z].decodeControl.frameLength  = frameLength;
-            pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
-/* //JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
-            ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
-            ioDataCtl.param.frameLengthPcm = frameLength;
-            ioDataControl(pInp[zI].hIoData, &ioDataCtl);
-*/
+            // This is unnecessary as sourceSelect won't change until input changes
+            //frameLength = getFrameLengthSourceSel(pP, sourceSelect);
+            //pAstCfg->xDec[z].decodeControl.frameLength  = frameLength;
+            //pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
         } // hIoPhy && decodeStatus.mode
         else {
             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
index 2a3cb65b7ba16a1f8b5f1c155cca0afd8754dfa6..1801cb70910fdc368e70fbbaa9cfa8090884c9c9 100644 (file)
@@ -200,6 +200,31 @@ enum {
     ASIP_ERR_ABORT
 };
 
+enum {
+    ASIT_NO_ERR,
+    ASIT_ERR_AUTO_DETECION,
+    ASIT_ERR_NO_MATCHING_SOURCE,
+    ASIT_ERR_SWITCH_TO_PCM,
+    ASIT_ERR_D10_CFG,
+    ASIT_ERR_MCASP_CFG,
+    ASIT_ERR_INPUT_CFG,
+    ASIT_ERR_DECODE_INIT,
+    ASIT_ERR_DECODE_COMMAND,
+    ASIT_ERR_DECODE_INFO1,
+    ASIT_ERR_DECODE_INFO2,
+    ASIT_ERR_DECODE_DATA,
+    ASIT_ERR_DECODE_FINAL,
+    ASIT_ERR_DECODE_COMPLETE,
+    ASIT_ERR_DECODE_MSG,
+    ASIT_ERR_DECODE_QUIT,
+    ASIT_ERR_ABORT
+};
+
+#define DEC_MSGMSK_INPDATA   0x1
+#define DEC_MSGMSK_INFOACK   0x2
+#define DEC_MSGMSK_DECACK    0x4
+
+
 // Input I/O structure
 typedef struct PAF_AST_InpIO {
     ioPhyHandle_t        hIoPhy;     /* handle to I/O physical layer */
@@ -233,7 +258,7 @@ typedef struct PAF_AST_InpIO {
     uint32_t numPcmFrameReceived;
 
     size_t         phyXferSize;
-    int_fast32_t   switchHangOver;
+    int_fast32_t   pcmSwitchHangOver;
     uint_least16_t asipState;
     uint_least16_t asipProcState;
     bool           buffReadComplete;
@@ -577,6 +602,14 @@ Int asipDecodeProcessing(
         PAF_ASIT_Config *pAsitCfg,
         Int sourceSelect);
 
+Int decDecodeInit(
+        const PAF_ASIT_Params *pP,
+        PAF_ASIT_Config *pAsitCfg,
+        Int sourceSelect);
+Int getFrameLengthSourceSel(
+        const PAF_ASIT_Params *pP,
+        Int8 sourceSelect);
+
 Int rxDecodePcm(PAF_AST_IoInp  *pInp);
 
 Int rxDecodeBitStream(PAF_AST_IoInp  *pInp);
index 4d95b8b4bd579144d7b9c4d114d1a59a57157707..7113d92622ac95d9f84e51e347843d042a369a92 100644 (file)
@@ -677,103 +677,6 @@ Int asipUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
     return 0;
 }
 
-/*==============================================================================
- * After SYNC is found, i.e. either bitstream preamble is detected or it times
- * out to PCM, update input buffer config and I/o components accordingly.
- ==============================================================================*/
-Int asipUpdateIoComps(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
-                      ioDataAutoDetStat_t *autoDetStatus)
-{
-    Int sourceConfig;
-    Int zMD, deliverZeros;
-    int frameLength;
-    PAF_InpBufConfig *pBufConfig;
-    Audk2g_STATUS mcaspStatus;
-    ioPhyCtl_t  ioPhyCtl;
-
-    zMD = pAstCfg->masterDec;
-    pBufConfig = &pAstCfg->xInp[zMD].inpBufConfig;
-
-    // Get the configured source
-    sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
-                                          GATEMP_INDEX_DEC);
-
-    if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
-        // Bitstream preamble is not found and it times out -> assume this is PCM
-        deliverZeros = autoDetStatus->deliverZeros;
-        if (sourceConfig == PAF_SOURCE_PCM || sourceConfig == PAF_SOURCE_DSD1 ||
-            sourceConfig == PAF_SOURCE_DSD2 || sourceConfig == PAF_SOURCE_DSD3) {
-            // set to one -- ensures that PCM decode calls made before data is
-            // available will result in zero output.
-            // (mostly needed for PA15 since, currently, all other frameworks
-            // require a frame of data before the first decode call.
-            deliverZeros = TRUE;  // override deliverZeros returned by ioDataControl
-        }
-
-        // update input buffer config structure
-        pBufConfig->deliverZeros  = deliverZeros;
-        pBufConfig->sizeofElement = WORD_SIZE_PCM;
-        pBufConfig->frameLength   = pBufConfig->lengthofData = INPUT_FRAME_LENGTH;
-
-        // reconfigure McASP LLD to transfer 32-bit unpacked data
-        //mcaspStatus = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_32);
-        //if(mcaspStatus != Audk2g_EOK) {
-        //    return ASIP_ERR_MCASP_CFG;
-        //}
-
-        // Change I/O PHY transfer size to PCM frame size
-        pInp->phyXferSize = (INPUT_FRAME_LENGTH)*(WORD_SIZE_PCM);
-
-        // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
-        // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
-        // Adjust delay and don't mark input buffer as read complete
-        ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
-
-        // Stop swapping data
-        pInp->swapData = FALSE;
-
-    } /* IODATA_SYNC_PCM */
-
-    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];
-
-        // update input buffer config structure
-        pBufConfig->sizeofElement = WORD_SIZE_BITSTREAM;
-        pBufConfig->frameLength   = frameLength;
-        pBufConfig->lengthofData  = frameLength - IEC_HEADER_LENGTH;
-
-/*
-        if (pc == 0x11 && DTSHDSubType == 3 && (PAF_ASP_sampleRateHzTable[pBufConfig->pBufStatus->sampleRateStatus][PAF_SAMPLERATEHZ_STD] <=48000.0))
-            pDevExt->sourceProgram = PAF_SOURCE_DXP;    // LBR is 23
-*/
-
-/*        if (pc == 1)
-            pDevExt->elementSize = 4288;
-        else if (pc == 0x11) {
-            pDevExt->frameLength = (pDevExt->pIECFrameLength[pc] << DTSHDSubType);
-            pDevExt->lengthofData = pDevExt->frameLength;
-        }
-*/
-
-        // Change I/O PHY transfer size to bitstream frame size
-        pInp->phyXferSize = frameLength*WORD_SIZE_BITSTREAM;
-    }
-
-    pBufConfig->stride = INPUT_STRIDE;   // common for PCM and bitstream
-
-    //JXTODO: decide what to do with hRxSio
-    pAstCfg->xInp[zMD].hRxSio = pInp->hIoData; //temporary - does ARM use hRxSio or just check if it is not NULL?
-    pAstCfg->xInp[zMD].pInpBuf = &(pAstCfg->xInp[zMD].inpBufConfig);
-
-    // Update I/O PHY transfer size accordingly
-    ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-    ioPhyCtl.params.xferFrameSize = pInp->phyXferSize;
-    ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
-
-    return ASIP_NO_ERR;
-} /* asipUpdateIoComps */
 
 void asipUpdateInpBufConfig(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp)
 {
@@ -915,6 +818,112 @@ Int asipDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
     return ASIP_NO_ERR;
 } /* asipDecideSource */
 
+/*==============================================================================
+ * After SYNC is found, i.e. either bitstream preamble is detected or it times
+ * out to PCM, update input buffer config and I/o components accordingly.
+ ==============================================================================*/
+Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
+                      PAF_AST_IoInp  *pInp, ioDataAutoDetStat_t *autoDetStatus)
+{
+    Int sourceConfig;
+    Int zMD, deliverZeros;
+    int ioFrameLength, decFrameLength;
+    PAF_InpBufConfig *pBufConfig;
+    ioPhyCtl_t  ioPhyCtl;
+    ioDataCtl_t ioDataCtl;
+
+    zMD = pAstCfg->masterDec;
+    pBufConfig = &pAstCfg->xInp[zMD].inpBufConfig;
+
+    // Compute decoder frame length based on source selection
+    decFrameLength = getFrameLengthSourceSel(pP, pInp->sourceSelect);
+
+    pAstCfg->xDec[zMD].decodeControl.frameLength  = decFrameLength;
+    pAstCfg->xDec[zMD].decodeInStruct.sampleCount = decFrameLength;
+    pAstCfg->xDec[zMD].decodeControl.sampleRate   = PAF_SAMPLERATE_UNKNOWN;
+
+    // Decide frame length for I/O DATA and I/O PHY
+    if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
+        // For PCM, I/O frame length is decode frame length multiplied by stride
+        ioFrameLength = decFrameLength * INPUT_STRIDE;
+
+        pBufConfig->sizeofElement = WORD_SIZE_PCM;
+        pBufConfig->frameLength   = pBufConfig->lengthofData = ioFrameLength;
+
+        // Configure I/O DATA PCM frame length
+        ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
+        ioDataCtl.param.frameLengthPcm = ioFrameLength;
+        ioDataControl(pInp->hIoData, &ioDataCtl);
+
+        // Change I/O PHY transfer size to PCM frame size
+        pInp->phyXferSize = ioFrameLength*(WORD_SIZE_PCM);
+
+        // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
+        // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
+        // Adjust delay and don't mark input buffer as read complete
+        //ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
+
+        // Stop swapping data
+        pInp->swapData = FALSE;
+    }
+    else {
+        // For bitstream, I/O frame length is the frame length of the bitstream
+        uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
+        ioFrameLength = iecFrameLength[pc];
+
+        /*
+                if (pc == 0x11 && DTSHDSubType == 3 && (PAF_ASP_sampleRateHzTable[pBufConfig->pBufStatus->sampleRateStatus][PAF_SAMPLERATEHZ_STD] <=48000.0))
+                    pDevExt->sourceProgram = PAF_SOURCE_DXP;    // LBR is 23
+
+                if (pc == 1)
+                    pDevExt->elementSize = 4288;
+                else if (pc == 0x11) {
+                    pDevExt->frameLength = (pDevExt->pIECFrameLength[pc] << DTSHDSubType);
+                    pDevExt->lengthofData = pDevExt->frameLength;
+                }
+        */
+
+        pBufConfig->sizeofElement = WORD_SIZE_BITSTREAM;
+        pBufConfig->frameLength   = ioFrameLength;
+        pBufConfig->lengthofData  = ioFrameLength - IEC_HEADER_LENGTH;
+
+        // Change I/O PHY transfer size to bitstream frame size
+        pInp->phyXferSize = ioFrameLength*WORD_SIZE_BITSTREAM;
+    }
+
+    pBufConfig->stride = INPUT_STRIDE;   // common for PCM and bitstream
+
+    // Configure I/O PHY transfer size
+    ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+    ioPhyCtl.params.xferFrameSize = pInp->phyXferSize;
+    ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
+
+    // Decide if zeros should be delivered based on the configured source
+    sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
+                                          GATEMP_INDEX_DEC);
+
+    if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
+        // Bitstream preamble is not found and it times out -> assume this is PCM
+        deliverZeros = autoDetStatus->deliverZeros;
+        if (sourceConfig == PAF_SOURCE_PCM || sourceConfig == PAF_SOURCE_DSD1 ||
+            sourceConfig == PAF_SOURCE_DSD2 || sourceConfig == PAF_SOURCE_DSD3) {
+            // set to one -- ensures that PCM decode calls made before data is
+            // available will result in zero output.
+            // (mostly needed for PA15 since, currently, all other frameworks
+            // require a frame of data before the first decode call.
+            deliverZeros = TRUE;  // override deliverZeros returned by ioDataControl
+        }
+
+        // update input buffer config structure
+        pBufConfig->deliverZeros  = deliverZeros;
+    }
+
+    //JXTODO: decide what to do with hRxSio
+    pAstCfg->xInp[zMD].hRxSio = pInp->hIoData; //temporary - does ARM use hRxSio or just check if it is not NULL?
+    pAstCfg->xInp[zMD].pInpBuf = &(pAstCfg->xInp[zMD].inpBufConfig);
+
+    return ASIP_NO_ERR;
+} /* asitUpdateIoComps */
 
 Int asipBypassIoData(PAF_AST_IoInp *pInp)
 {
@@ -932,8 +941,10 @@ Int asipBypassIoData(PAF_AST_IoInp *pInp)
     if (ioBuffGetReadPtrs(pInp->hIoBuff, pInp->phyXferSize,
                           &buff1, &size1, &buff2, &size2)
         == IOBUFF_ERR_UNDERFLOW) {
-        //printf("Input buffer underflows during switch hangover!\n");
-        return ASIP_ERR_SWITCH_TO_PCM;
+        pInp->numUnderflow += 1;
+
+        // Return since there is no enough data to process
+        return ASIP_NO_ERR;
     }
 
     ioBuffReadComplete(pInp->hIoBuff, buff1, size1);
@@ -1003,17 +1014,20 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
         // zero out the output buffer
         rxDecodePlayZero(pInp);
 
+        // Mark I/O DATA read complete as auto-detection finishes reading input data now.
+        ioDataReadComplete(pInp->hIoData);
+
         if(   autoDetStatus.syncState == IODATA_SYNC_BITSTREAM
            || autoDetStatus.syncState == IODATA_SYNC_PCM) {
-            // Update I/O components and input buffer config
-            asipUpdateIoComps(pAstCfg, pInp, &autoDetStatus);
-
             // Decide input source and inform decoder
             asipStatus = asipDecideSource(pAstCfg, pInp, &autoDetStatus);
             if(asipStatus != ASIP_NO_ERR) {
                 return asipStatus;
             }
             else {
+                // Update I/O components and input buffer config
+                asitUpdateIoComps(pP, pAstCfg, pInp, &autoDetStatus);
+
                 // 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
@@ -1035,9 +1049,13 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
                         return ASIP_ERR_MCASP_CFG;
                     }
 
+                    // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
+                    // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
+                    ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
+
                     // Go to transition state to switch to PCM
                     pInp->asipProcState = ASIP_SWITCH_TO_PCM;
-                    pInp->switchHangOver = INPUT_SWITCH_HANGOVER;
+                    pInp->pcmSwitchHangOver = INPUT_SWITCH_HANGOVER;
                     //pInp->numPcmFrameReceived = 0;
                 }
             }
@@ -1055,8 +1073,8 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
         // zero out the output buffer
         rxDecodePlayZero(pInp);
 
-        pInp->switchHangOver--;
-        if(pInp->switchHangOver == 0) {
+        pInp->pcmSwitchHangOver--;
+        if(pInp->pcmSwitchHangOver == 0) {
             pInp->asipProcState = ASIP_DECODE;
         }
         break;
@@ -1112,16 +1130,15 @@ Int asipProcessing(const PAF_ASIT_Params *pP,
             rxDecodePcm(pInp);     // for PCM loopback testing
         }
 #endif
+        // Mark I/O DATA read complete as decoder finishes reading input now.
+        ioDataReadComplete(pInp->hIoData);
+
         break;
 
     default:
         break;
     }
 
-    if(pInp->asipProcState != ASIP_SWITCH_TO_PCM) {
-        ioDataReadComplete(pInp->hIoData);
-    }
-
     return 0;
 } /* asipProcessing */
 
index cdc44d27a1a4f5c057d701dbe7b2b2f98b386838..015c5570966bd8cb8cf1b577e2d3aba127ffcd92 100644 (file)
@@ -313,7 +313,7 @@ int ioDataControl(ioDataHandle_t ioDataHandle, ioDataCtl_t *ioDataCtl)
 //      break;
 
     case IODATA_CTL_SET_PCM_FRAME_LENGTH:
-       pIoDataInst->frameLengthPCM = ioDataCtl->param.frameLengthPcm;
+        pIoDataInst->numElementsRead = pIoDataInst->frameLengthPCM = ioDataCtl->param.frameLengthPcm;
       break;
 
     case IODATA_CTL_GET_INPBUFFINFO: