PASDK-218:Move CB init source select to after first decoded frame
authorFrank Livingston <frank-livingston@ti.com>
Fri, 7 Jul 2017 16:36:43 +0000 (11:36 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Fri, 7 Jul 2017 16:36:43 +0000 (11:36 -0500)
pasdk/common/aspOutInitSync_common.h
pasdk/test_arm/framework/audioStreamDecodeProc.c
pasdk/test_dsp/framework/audioStreamInpProc.c
pasdk/test_dsp/framework/audioStreamOutProc.c

index 993972cdc05f2f0aed74622ab883595d493d7afb..2026581501f436b3b43872cfb3d291c693bcf867 100644 (file)
@@ -47,11 +47,12 @@ All rights reserved.
 
 // Output Init-Sync number of decoder stages
 // 2 stages: Dec Reset, Dec Info
-#define ASP_OUTIS_NUM_DEC_STAGES            ( 2 )                                         
+#define ASP_OUTIS_NUM_DEC_STAGES            ( 3 )
 
 // Output Init-Sync decoder stages indices
 #define ASP_OUTIS_DEC_STAGE_RESET_IDX       ( 0 )
 #define ASP_OUTIS_DEC_STAGE_INFO1_IDX       ( ASP_OUTIS_DEC_STAGE_RESET_IDX+1 )
+#define ASP_OUTIS_DEC_STAGE_DECODE1_IDX     ( ASP_OUTIS_DEC_STAGE_INFO1_IDX+1 )
 
 #define ASP_OUTIS_GATE_NAME                 ( "AspOutISGate" )  // name of GateMP used OutIS info protection
 #define ASP_OUTIS_GATE_REGION_ID            ( 0 )               // IPC shared region ID used for OutIS gate allocation   
index 3f82143e3d251e40ebcf9c014e3d909f04d60403..388cdbc6781aec8964e636b634b6312c788b27d5 100644 (file)
@@ -139,8 +139,16 @@ int tempCap_decSampleOut[CAP_FRAME_MAX] = {0};
 #endif
 
 // debug
-//PAF_AudioFrame gAfCap[20];
-//gAfCapIdx=0;
+PAF_AudioFrame gDecInfoAfCap1[20];
+UInt8 gDecInfoAfCap1Idx=0;
+PAF_AudioFrame gDecInfoAfCap2[20];
+UInt8 gDecInfoAfCap2Idx=0;
+
+PAF_AudioFrame gDecDecodeAfCap1[20];
+UInt8 gDecDecodeAfCap1Idx=0;
+PAF_AudioFrame gDecDecodeAfCap2[20];
+UInt8 gDecDecodeAfCap2Idx=0;
+
 
 /*
  *  ======== taskAsdpFxn ========
@@ -177,6 +185,7 @@ Void taskAsdpFxn(
     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;     // IB buffer configuration
@@ -527,8 +536,9 @@ Void taskAsdpFxn(
                     // Reset audio frame
                     resetAf(pP, z, sourceSelect);
                     
-                    // Initialize OutIS Dec Info1 flag -- OutIS Dec Info hasn't executed
-                    outIsDecInfo1Flag = 0;
+                    // 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);
@@ -555,9 +565,12 @@ 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
+                        // Get pointer to Dec Reset output audio frame
                         pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
 
                         // Perform Dec Reset Init-Sync
@@ -657,6 +670,16 @@ Void taskAsdpFxn(
                     errno = 0;
                     if (dec->fxns->info)
                     {
+                        // debug
+                        if (gDecInfoAfCap1Idx < 20)
+                        {
+                            gDecInfoAfCap1[gDecInfoAfCap1Idx] = *pAstCfg->xDec[z].decodeControl.pAudioFrame;
+                            gDecInfoAfCap1Idx++;
+                        }
+                        
+                        //
+                        // Execute decode info
+                        //
                         pfpBegin(PFP_ID_ASDT_1, pAsdtCfg->taskHandle);
                         errno = dec->fxns->info(dec, NULL, 
                             &pAstCfg->xDec[z].decodeControl, 
@@ -664,44 +687,28 @@ Void taskAsdpFxn(
                         pfpEnd(PFP_ID_ASDT_1, PFP_FINISH_MEAS);
 
                         // debug
-                        //if (gAfCapIdx < 20)
-                        //{
-                        //    gAfCap[gAfCapIdx] = *pAstCfg->xDec[z].decodeControl.pAudioFrame;
-                        //    gAfCapIdx++;
-                        //}
+                        if (gDecInfoAfCap2Idx < 20)
+                        {
+                            gDecInfoAfCap2[gDecInfoAfCap2Idx] = *pAstCfg->xDec[z].decodeControl.pAudioFrame;
+                            gDecInfoAfCap2Idx++;
+                        }
                         
                         // debug
                         //if (outIsDecInfo1Flag < 10) 
                         //    outIsDecInfo1Flag++;
                         //if (outIsDecInfo1Flag == 10)
                         
+                        //
+                        // Execute Dec Info1 Init-Sync if required
+                        //
                         if (outIsDecInfo1Flag == 0)
                         {
-                            // get pointer to Dec Info1 output audio frame
+                            // Get pointer to Dec Info1 output audio frame
                             pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
 
                             if (checkDecSync(pDecCtrlAf) == 1)
                             {
-                                //
-                                // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
-                                //  frameLength: changed to decodeControl.frameLength.
-                                //    Written by ASIT:decodeInit:getFrameLengthSourceSel().
-                                //  FRAMELENGTH: pP->frameLength.
-                                //    Formerly ASIT, now ASDT but same value (PAF_SYS_FRAMELENGTH).
-                                //
-                                
-                                // Initialize decoder output circular buffer for selected source
-                                errno = cbInitSourceSel(pCbCtl, z, sourceSelect, 
-                                    pAstCfg->xDec[z].decodeControl.frameLength, 
-                                    FRAMELENGTH, 0, pDecCtrlAf);
-                                if (errno)
-                                {
-                                    SW_BREAKPOINT; // debug
-                                }
-                                // debug
-                                cbLog(pCbCtl, z, 1, "cbInitSourceSel");
-
-                                // Perform Dec Info Init-Sync
+                                // Perform Dec Info1 Init-Sync
                                 //  - Write Dec Info1 output audio frame
                                 //  - Set Dec Info1 decoder stage flag
                                 outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
@@ -711,7 +718,7 @@ Void taskAsdpFxn(
                                     SW_BREAKPOINT; // debug
                                 }
 
-                                outIsDecInfo1Flag = 1; // set flag to indicate OutIS Dec Info has executed                             
+                                outIsDecInfo1Flag = 1;  // OutIS Dec Info1 has executed
                             }
                         }
                     }
@@ -768,7 +775,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");
@@ -782,7 +789,17 @@ Void taskAsdpFxn(
                     {
                         // Capture input buffer (debug)
                         //capIb(pAstCfg->xInp[z].pInpBuf);
+                        
+                        // debug
+                        if (gDecDecodeAfCap1Idx < 20)
+                        {
+                            gDecDecodeAfCap1[gDecDecodeAfCap1Idx] = *pAstCfg->xDec[z].decodeInStruct.pAudioFrame;
+                            gDecDecodeAfCap1Idx++;
+                        }                       
                     
+                        //
+                        // 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);
@@ -791,14 +808,17 @@ Void taskAsdpFxn(
                             //SW_BREAKPOINT;
                         }
                         TRACE_TERSE0("Dec:decode done");
+
+                        // debug
+                        if (gDecDecodeAfCap2Idx < 20)
+                        {
+                            gDecDecodeAfCap2[gDecDecodeAfCap2Idx] = *pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
+                            gDecDecodeAfCap2Idx++;
+                        }                       
                         
-                        // 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);
+                        // 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);
                         
                         // Capture audio frame (debug)
                         //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
@@ -814,7 +834,51 @@ 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().
+                            //  FRAMELENGTH: pP->frameLength.
+                            //    Formerly ASIT, now ASDT but same value (PAF_SYS_FRAMELENGTH).
+                            //
+                            
+                            // Initialize decoder output circular buffer for selected source
+                            errno = cbInitSourceSel(pCbCtl, z, sourceSelect, 
+                                pAstCfg->xDec[z].decodeControl.frameLength, 
+                                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_107); // debug
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
                         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
                         {
@@ -822,7 +886,7 @@ Void taskAsdpFxn(
                             //SW_BREAKPOINT; // debug
                         }
                         
-                        // Handle overflows
+                        // Handle circular buffer overflows
                         if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
                         {
                             gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
@@ -1601,12 +1665,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:
@@ -1637,7 +1702,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;
index 4c8dfc333c97e7184a259c38ade6c3da48512798..dabd0ed8e7a8fae733dcffb1490af681228dfbbe 100644 (file)
@@ -2600,7 +2600,7 @@ PAF_ASIT_decodeInit(
 )
 {
     PAF_AST_Config *pAstCfg;
-    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
     Int as;                             /* Audio Stream Number (1, 2, etc.) */
     Int z;                              /* decode/encode counter */
     Int errno;                          /* error number */
@@ -2621,7 +2621,7 @@ PAF_ASIT_decodeInit(
     zMI = pP->zone.master;
     (void)as;  // clear compiler warning in case not used with tracing disabled
     
-    pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+    //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
 
 #ifdef NON_CACHE_STATUS
     // reset frameCount
index 9b63f8ad271e70534a21aa102f1cb82963bc9453..975ea2753fba16d6244bc5f56368f07b833a1c7f 100644 (file)
@@ -171,6 +171,14 @@ static Int PAF_ASOT_initSyncDecInfo1(
     PAF_AudioFrame *pDecInfo1Af
 );
 
+//   Purpose:   Init-Sync Dec Decode1 state function.
+//              Performes Dec Decode1 Init-Sync.
+static Int PAF_ASOT_initSyncDecDecode1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
 //   Purpose:   Init-Sync Re-Sync state function.
 //              Peformed Init-Sync using stored Dec Reset/Info1 AFs.
 static Int PAF_ASOT_initSyncResync(
@@ -181,11 +189,13 @@ static Int PAF_ASOT_initSyncResync(
     PAF_AudioFrame *pDecInfo1Af  
 );
 
+#if 0
 // Init-Sync update audio frame
 static Int initSyncUpdateAf(
     PAF_AudioFrame *dstAf, 
     PAF_AudioFrame *srcAf
 );
+#endif
 
 // Reset audio frames
 static Void resetAfs(
@@ -255,7 +265,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;
+    enum { INIT_OUT_PROC_STATE, 
+           INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE, 
+           INITSYNC_RESYNC_STATE, 
+           OUT_PROC_STATE } state;
     PAF_AudioFrame decResetAf;
     PAF_AudioFrame decInfo1Af;
     
@@ -447,6 +460,7 @@ Void taskAsopFxn(
                     Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE not sync'd errno=%d", errno);
                     // sync not ready -- try again
                     state = INITSYNC_DEC_RESET_STATE;
+                    errno=0; // FL: temp hack
                 }
                 else // errno==0
                 {
@@ -478,11 +492,44 @@ Void taskAsopFxn(
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE not sync'd errno=%d", errno);
                     // sync not ready -- try again
                     state = INITSYNC_DEC_INFO1_STATE;
+                    errno=0; // FL: temp hack
                 }
                 else // errno = 0
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE sync'd errno=%d", errno);
                     // sync'd -- move on
+                    state = INITSYNC_DEC_DECODE1_STATE;
+                }
+                
+                break;
+            
+            case INITSYNC_DEC_DECODE1_STATE:
+                Log_info0("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE");
+                
+                //
+                // Dec Info1 Init-Sync.
+                //
+
+                // Perform Dec Info1 init-sync.
+                // Latch Dec Info1 AF.
+                errno = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg);
+                if (errno < 0)
+                {
+                    Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE errno=%d", errno);
+                    // sync error -- start over
+                    state = INIT_OUT_PROC_STATE;
+                }
+                else if (errno == ASOP_INITSYNC_NOTREADY)
+                {
+                    Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE not sync'd errno=%d", errno);
+                    // sync not ready -- try again
+                    state = INITSYNC_DEC_DECODE1_STATE;
+                    errno=0; // FL: temp hack
+                }
+                else // errno = 0
+                {
+                    Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE sync'd errno=%d", errno);
+                    // sync'd -- move on
                     state = OUT_PROC_STATE;
                 }
                 
@@ -3125,6 +3172,7 @@ static Int PAF_ASOT_initOutProc(
     return ASOP_SOK;
 }
 
+#if 0
 // Init-Sync update audio frame
 static Int initSyncUpdateAf(
     PAF_AudioFrame *dstAf, 
@@ -3135,6 +3183,7 @@ static Int initSyncUpdateAf(
     
     return ASOP_SOK;
 }
+#endif
 
 //   Purpose:   Init-Sync Dec Reset state function.
 //              Performes Dec Reset Init-Sync.
@@ -3310,6 +3359,44 @@ static Int PAF_ASOT_initSyncDecInfo1(
     }
 }
 
+//   Purpose:   Init-Sync Dec Decode1 state function.
+//              Performes Dec Decode1 Init-Sync.
+static Int PAF_ASOT_initSyncDecDecode1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
+    Int zMD, zMS;                       // Dec and Stream Master indices
+    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 = outIsReadDecStageFlag(pOutIsCtl, zMD,
+        ASP_OUTIS_DEC_STAGE_DECODE1_IDX, &decFlag);
+    if (errno < 0)
+    {
+        return errno;
+    }
+    
+    if (decFlag == 0)
+    {
+        return ASOP_INITSYNC_NOTREADY;
+    }
+    else
+    {
+        return ASOP_SOK;
+    }
+}
+
 //   Purpose:   Init-Sync Re-Sync state function.
 //              Peformed Init-Sync using stored Dec Reset/Info1 AFs.
 static Int PAF_ASOT_initSyncResync(
@@ -3355,7 +3442,7 @@ static Int PAF_ASOT_initSyncResync(
     }
     
     //
-    // Dec Info1 re-sync using sotred Dec Info1 AF
+    // Dec Info1 re-sync using stored Dec Info1 AF
     //
     
     // Update Stream Audio Frame.