]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_arm/framework/audioStreamDecodeProc.c
PASDK-376:Remove GPIO debug for release
[processor-sdk/performance-audio-sr.git] / pasdk / test_arm / framework / audioStreamDecodeProc.c
index b8b6ba122600a576301a39c9ef807dbb2f0f3fd3..65ab36c70e03c92af5a2d0eae686f43016121c8f 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"
@@ -77,6 +78,11 @@ All rights reserved.
 
 #define __TASK_NAME__  "TaskAsdp"
 
+// Check decoder sync using information in INFO audio frame 
+static Int8 checkDecSync(
+    PAF_AudioFrame *pAf
+);
+
 extern struct {
     Int size;
     IALG_Status *pStatus[512];
@@ -93,7 +99,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
 };
 
@@ -131,6 +138,7 @@ Uint32 tempCap_frameCnt = 0;
 int tempCap_decSampleOut[CAP_FRAME_MAX] = {0};
 #endif
 
+
 /*
  *  ======== taskAsdpFxn ========
  *  Audio Stream Decode Processing task function
@@ -141,11 +149,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 +161,25 @@ 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_AudioFrame *pDecCtrlAf;         // pointer to Dec Control audio frame
+    PAF_AST_OutInitSyncCtl *pOutIsCtl;  // OutIS control
+    Int8 outIsDecInfo1Flag;             // indicates whether Dec Info Init-Sync has executed
+    Int8 outIsDecDecode1Flag;           // indicates whether Dec Decode1 Init-Sync has executed
+    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 +212,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 +398,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 +458,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 +485,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 +510,6 @@ Void taskAsdpFxn(
                     }
 
                     // Start writes to circular buffer
-                    //pCb = &pAstCfg->xDecOpCb[z];
                     cbErrno = cbWriteStart(pCbCtl, z);
                     if (cbErrno < 0)
                     {
@@ -509,12 +519,16 @@ 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 flags
+                    outIsDecInfo1Flag = 0;      // OutIS Dec Info1 hasn't executed
+                    outIsDecDecode1Flag = 0;    // OutIS Dec Decode1 hasn't executed
+                    
                     // send dec activate complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
@@ -531,8 +545,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];
@@ -542,7 +554,23 @@ Void taskAsdpFxn(
                     errno = 0;
                     if (dec->fxns->reset)
                     {
+                        //
+                        // Execute decode reset
+                        //
                         errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
+
+                        // Get pointer to Dec Reset output audio frame
+                        pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
+
+                        // Perform Dec Reset Init-Sync
+                        //  - Write Dec Reset output audio frame
+                        //  - Set Dec Reset decoder stage flag
+                        outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
+                            ASP_OUTIS_DEC_STAGE_RESET_IDX, 1, pDecCtrlAf);
+                        if (outIsErrno < 0)
+                        {
+                            SW_BREAKPOINT; // debug
+                        }
                     }
 
                     // write back Dec configuration
@@ -558,7 +586,7 @@ 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();*/
-                    
+
                     // send dec reset complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
@@ -577,8 +605,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];
@@ -633,9 +659,38 @@ Void taskAsdpFxn(
                     errno = 0;
                     if (dec->fxns->info)
                     {
+                        //
+                        // Execute decode info
+                        //
                         pfpBegin(PFP_ID_ASDT_1, pAsdtCfg->taskHandle);
-                        errno = dec->fxns->info(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
+                        errno = dec->fxns->info(dec, NULL, 
+                            &pAstCfg->xDec[z].decodeControl, 
+                            &pAstCfg->xDec[z].decodeStatus);
                         pfpEnd(PFP_ID_ASDT_1, PFP_FINISH_MEAS);
+
+                        //
+                        // Execute Dec Info1 Init-Sync if required
+                        //
+                        if (outIsDecInfo1Flag == 0)
+                        {
+                            // Get pointer to Dec Info1 output audio frame
+                            pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
+
+                            if (checkDecSync(pDecCtrlAf) == 1)
+                            {
+                                // Perform Dec Info1 Init-Sync
+                                //  - Write Dec Info1 output audio frame
+                                //  - Set Dec Info1 decoder stage flag
+                                outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
+                                    ASP_OUTIS_DEC_STAGE_INFO1_IDX, 1, pDecCtrlAf);
+                                if (outIsErrno < 0)
+                                {
+                                    SW_BREAKPOINT; // debug
+                                }
+
+                                outIsDecInfo1Flag = 1;  // OutIS Dec Info1 has executed
+                            }
+                        }
                     }
                     
                     // write back Dec configuration
@@ -680,8 +735,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];
@@ -692,7 +745,7 @@ Void taskAsdpFxn(
                     // Reset AF samsiz
                     resetAfSamsiz(z);
                     
-                    // invalidate Dec configuration
+                    // Invalidate Dec configuration
                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
                     Cache_wait();
                     //TRACE_TERSE0("Dec:cache wb done");
@@ -704,9 +757,12 @@ Void taskAsdpFxn(
                     cbErrno = 0;
                     if (dec->fxns->decode)
                     {
-                        // FL: debug, capture input buffer
+                        // Capture input buffer (debug)
                         //capIb(pAstCfg->xInp[z].pInpBuf);
-                    
+                        
+                        //
+                        // Execute decode
+                        //
                         pfpBegin(PFP_ID_ASDT_2, pAsdtCfg->taskHandle);
                         errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
                         pfpEnd(PFP_ID_ASDT_2, PFP_FINISH_MEAS);
@@ -715,23 +771,18 @@ Void taskAsdpFxn(
                             //SW_BREAKPOINT;
                         }
                         TRACE_TERSE0("Dec:decode done");
+
+                        // Get pointer to Dec Decode output audio frame
+                        pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;                           
+                        TRACE_TERSE2("Dec:pAfWrt=0x%04x, nSamples=%d", (IArg)pAfWrt, pAfWrt->data.nSamples);
                         
-                        // copy decoder output to decoder output circular buffers
-                        //pCb = &pAstCfg->xDecOpCb[z];
-                        //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
-                        
-                        pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
-                        TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
-                        //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
-                        
-                        // FL: debug, capture audio frame
-                        //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
+                        // Capture audio frame (debug)
+                        //if (capAfWrite(pAfWrt, PAF_LEFT) != CAP_AF_SOK)
                         //{
                         //    Log_info0("capAfWrite() error");
-                        //}                        
+                        //}
 
                         #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
-
                         if (tempCap_frameCnt < CAP_FRAME_MAX)
                         {
                             tempCap_decSampleOut[tempCap_frameCnt] = pAfWrt->sampleCount;
@@ -739,16 +790,61 @@ Void taskAsdpFxn(
                         }
                         #endif
 
-                        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
+                        //
+                        // Execute Dec Decode1 Init-Sync if required
+                        //
+                        if (outIsDecDecode1Flag == 0)
+                        {
+                            //
+                            // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
+                            //  frameLength: changed to decodeControl.frameLength.
+                            //    Written by ASIT:decodeInit:getFrameLengthSourceSel().
+                            
+                            // Initialize decoder output circular buffer
+                            errno = cbInitDecWrite(pCbCtl, z, sourceSelect,
+                                pAstCfg->xDec[z].decodeControl.frameLength, 
+                                0, pAfWrt);
+                            if (errno)
+                            {
+                                SW_BREAKPOINT; // debug
+                            }
+                            // debug
+                            cbLog(pCbCtl, z, 1, "cbInitSourceSel");
+                            
+                            // Perform Dec Decode1 Init-Sync
+                            //  - Set Dec Decode1 decoder stage flag
+                            outIsErrno = outIsWriteDecStageFlag(pOutIsCtl, z, 
+                                ASP_OUTIS_DEC_STAGE_DECODE1_IDX, 1);
+                            if (outIsErrno < 0)
+                            {
+                                SW_BREAKPOINT; // debug
+                            }
+
+                            outIsDecDecode1Flag = 1;    // OutIS Dec Decode1 has executed
+                        }
+
+                        //
+                        // Write decoder output audio frame to circular buffer
+                        //
+
+                        // debug
+                        //pCb = &pAstCfg->xDecOpCb[z];
+                        //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);                                                
+
+                        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);      // debug
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
-                        if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
+                        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);    // debug
+                        if ((cbErrno < 0) && 
+                            (cbErrno != ASP_DECOP_CB_AF_WRITE_OVERFLOW) && 
+                            (cbErrno != ASP_DECOP_CB_PCM_WRITE_OVERFLOW))
                         {
                             gCbWrtAfErrCnt++;
-                            //SW_BREAKPOINT; // FL: debug
+                            //SW_BREAKPOINT; // debug
                         }
                         
-                        // Handle overflows
-                        if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
+                        // Handle circular buffer overflows
+                        if ((cbErrno == ASP_DECOP_CB_AF_WRITE_OVERFLOW) ||
+                            (cbErrno == ASP_DECOP_CB_PCM_WRITE_OVERFLOW))
                         {
                             gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
                             if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
@@ -776,7 +872,7 @@ Void taskAsdpFxn(
                             
                             cbErrno = 0; // don't return error condition
                         }
-                        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
+                        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);   // debug
                         TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
 #if 0 // (***) FL: shows timing of CB write
@@ -791,7 +887,7 @@ Void taskAsdpFxn(
                         }
 #endif        
                         
-                        // FL: debug, log circular buffer control variables
+                        // Log circular buffer control variables (debug)
                         cbLog(pCbCtl, z, 1, "cbWriteAf");
                     }
                     
@@ -838,8 +934,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 +945,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;
@@ -1522,12 +1622,13 @@ Int resetAf(
     }
 
     // Reinitialize audio frame elements
-    pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
-    pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
+    pAudioFrame->sampleDecode = PAF_SOURCE_UNKNOWN;
     pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
     pAudioFrame->sampleCount = 0;
-    pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
+    pAudioFrame->channelConfigurationRequest.full = PAF_CC_UNKNOWN;
+    pAudioFrame->channelConfigurationStream.full = PAF_CC_UNKNOWN;
     
+    pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
     switch (sourceSelect)
     {
         case PAF_SOURCE_PCM:
@@ -1558,7 +1659,7 @@ Int resetAf(
     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
     pAudioFrame->numPrivateMetadata = 0;
     pAudioFrame->bsMetadata_offset = 0;
-    pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
+    pAudioFrame->bsMetadata_type = PAF_bsMetadata_none;
     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
     {
         pAudioFrame->pafPrivateMetadata[i].offset = 0;
@@ -1591,3 +1692,20 @@ Int resetAfSamsiz(
 
     return 0;
 }
+
+// (***) FL: Check correct behavior for other decs, esp DTSHD & DXP
+// Check decoder sync using information in INFO audio frame
+static Int8 checkDecSync(
+    PAF_AudioFrame *pAf
+)
+{
+    if ((pAf->sampleDecode == PAF_SOURCE_THD) &&
+        (pAf->sampleRate == PAF_SAMPLERATE_UNKNOWN))
+    {
+        return 0;
+    }
+    else
+    {
+        return 1;
+    }
+}