]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpDec.c
Merge remote-tracking branch 'origin/PASDK-136-new-i-o-integration-into-pasdk-1-x...
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpDec.c
1 /*
2 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
3 All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * Neither the name of Texas Instruments Incorporated nor the names of
18 * its contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
35 /*
36  *  ======== audioStreamInpDec.c ========
37  */
38 #include <ti/sysbios/hal/Cache.h>
39 #include <xdc/runtime/Log.h>
41 #include "procsdk_audio_typ.h"
42 #include "audioStreamInpProc.h"
43 #include "audioStreamProc_common.h"
44 #include "aspMsg_common.h"
45 #include "aspMsg_master.h"
46 #include "asperr.h"
47 #include "common.h"
48 #include "as1-f2.h"
50 #include "ioConfig.h"    //TODO: remove this header
51 #include "ioBuff.h"
52 #include "ioPhy.h"
53 #include "ioData.h"
56 extern void asitPostInfoEvent();    // TODO: remove
57 extern void asitPostDecEvent();     // TODO: remove
59 enum {
60     DEC_STATE_INFO_SND,
61     DEC_STATE_INFO_ACK_DECODE_SND,
62     DEC_STATE_DECODE_ACK,
63     DEC_STATE_QUIT
64 };
66 static Int decodeInit(const PAF_ASIT_Params *pP, PAF_ASIT_Config *pAsitCfg,
67                       Int sourceSelect);
69 static Int decDecodeComplete(const PAF_ASIT_Params *pP,
70                              PAF_ASIT_Config *pAsitCfg);
72 static Int decErrorCheck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
73                          PAF_ASIT_Config *pAsitCfg, Int sourceSelect);
74 static Int decInfoSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
75                          PAF_ASIT_Config *pAsitCfg);
76 static Int decInfoAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
77                          PAF_ASIT_Config *pAsitCfg);
78 static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
79                            PAF_ASIT_Config *pAsitCfg);
80 static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
81                            PAF_ASIT_Config *pAsitCfg);
82 static Int decDecodeFinalTest(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
83                               PAF_ASIT_Config *pAsitCfg);
84 Int decCheckMajorAu(PAF_AST_Config *pAstCfg);
86 extern UInt32 gCbWrtAfErrCnt;
89 Int decDecodeInit(
90         const PAF_ASIT_Params *pP,
91         PAF_ASIT_Config *pAsitCfg,
92         Int sourceSelect)
93 {
94     Int errno;
96     errno = decodeInit(pP, pAsitCfg, sourceSelect);
98     if(errno) {
99         decDecodeComplete(pP, pAsitCfg);
101         return ASIP_ERR_DECODE_INIT;
102     }
104     pAsitCfg->inpDec.majorAuFound = FALSE;
105     
106     return ASIP_NO_ERR;
110 // -----------------------------------------------------------------------------
111 // -----------------------------------------------------------------------------
112 Int decDecodeFsm(
113         const PAF_ASIT_Params *pP,
114         const PAF_ASIT_Patchs *pQ,
115         PAF_ASIT_Config *pAsitCfg,
116         Int sourceSelect,
117         UInt decMsg)
119     asipDecProc_t  *pDec;
120     Int decErr, decDone;
122     pDec = &pAsitCfg->inpDec;
124     TRACE_VERBOSE1("Entering decDecodeFsm with decMsg %d.", decMsg);
126     decErr = decErrorCheck(pP, pQ, pAsitCfg, sourceSelect);
127     if(decErr == DEC_ERR_ASPERR_ABORT) {
128         return decErr;
129     }
130     else if(decErr != DEC_NO_ERR) {
131         pDec->state = DEC_STATE_QUIT;
132     }
133     else {
134         ; // No error
135     }
137     // It is possible to go through the FSM multiple times:
138     //    - Multiple messages may be received, INPDATA and DECACK. In this case,
139     //      the FSM will process DECACK in state DEC_STATE_DECODE_ACK and then 
140     //      INPDATA in state DEC_STATE_INFO_SND.
141     //    - DECACK is received after INPDATA. In this case, after DECACK is 
142     //      processed, we will spoof decMsg with INPDATA so that FSM will run 
143     //      again and process INPDATA in DEC_STATE_INFO_SND.
144     do {
145         switch(pDec->state)
146         {
147         case DEC_STATE_INFO_SND:
148             if(decMsg != DEC_MSGMSK_INPDATA) {
149                 // Only DEC_MSGMSK_INPDATA is expected in this state
150                 decErr = DEC_ERR_WRONG_MSG;
151             }
152             else {
153                 decMsg &= ~DEC_MSGMSK_INPDATA;   // clear bit mask
155                 // Prepare and send INFO to decoder
156                 decErr = decInfoSnd(pP, pQ, pAsitCfg);
157                 if(decErr == DEC_NO_ERR) {
158                     pDec->state = DEC_STATE_INFO_ACK_DECODE_SND;
159                     TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_SND done.");
160                 }
161             }
162         break;
164         case DEC_STATE_INFO_ACK_DECODE_SND:
165             //if(decMsg != DEC_MSGMSK_INFOACK) {
166                 // only DEC_MSGMSK_INFOACK is expected in this state
167             //if((decMsg&DEC_MSGMSK_INFOACK) != DEC_MSGMSK_INFOACK) {
168             //    // During debugging, it is possible that INPDATA and INFOACK
169             //    // come at the same time (e.g. due to breaking point).
170             //    decErr = DEC_ERR_WRONG_MSG;
171             //}
172             //else {
173                 
174             if (decMsg & DEC_MSGMSK_RXACK) {
175                 decMsg &= ~DEC_MSGMSK_RXACK;  // clear the bit mask
177                 // Process the INFO acknowledgment from decoder
178                 decErr = decInfoAck(pP, pQ, pAsitCfg);
179                 if(decErr == DEC_NO_ERR) {
180                     // Don't start decode until major access unit is found.
181                     if(!pDec->majorAuFound) {
182                         // Do we want to still check major AU after it is found?
183                         // In old code, it was not checked again after it was found. 
184                         pDec->majorAuFound = decCheckMajorAu(pAsitCfg->pAstCfg);    
185                     }
186                     
187                     if(pDec->majorAuFound) {
188                         // Major access unit is found. Send message to decoder to decode now.
189                         decErr = decDecodeSnd(pP, pQ, pAsitCfg);
190                         if(decErr == DEC_NO_ERR) {
191                             pDec->state = DEC_STATE_DECODE_ACK;
193                             // Initialize decodeAckDelayed to FALSE - normally
194                             // DECODE ACK comes after INPDATA. 
195                             pDec->decodeAckDelayed = FALSE;
197                             TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_ACK_DECODE_SND done and going to DEC_STATE_DECODE_ACK.");
198                         }
199                     }
200                     else {
201                         // No major access unit - go back to INFO.
202                         pDec->frame++;
203                         pDec->state = DEC_STATE_INFO_SND;
204                         TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_ACK_DECODE_SND done and going to DEC_STATE_INFO_SND.");
205                     }
206                 }
207             }
208             
209             if (decMsg != 0) {
210                 decErr = DEC_ERR_WRONG_MSG;
211             }            
212         break;
214         case DEC_STATE_DECODE_ACK:
215             // Two different messages may be received: DECACK (decode acknowledgment)
216             // or INPDATA (input data ready).
217             //if(decMsg & DEC_MSGMSK_DECACK) {
218             //    decMsg &= ~DEC_MSGMSK_DECACK;
219             
220             if (decMsg & DEC_MSGMSK_RXACK)
221             {
222                 decMsg &= ~DEC_MSGMSK_RXACK;  // clear the bit mask
223                 
224                 // Process DECODE ACK from decoder
225                 decErr = decDecodeAck(pP, pQ, pAsitCfg);
226                 if(decErr == DEC_NO_ERR) {
227                     // Decode finishes. Conduct final test.
228                     decErr = decDecodeFinalTest(pP, pQ, pAsitCfg);
229                     if(decErr == DEC_NO_ERR) {
230                         pDec->frame++;
231                         pDec->state = DEC_STATE_INFO_SND;
232                         TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_DECODE_ACK done and going to DEC_STATE_INFO_SND.");
234                         // Check if DECACK comes late (after INPDATA)
235                         if(pDec->decodeAckDelayed) {
236                             pDec->decodeAckDelayed = FALSE;
238                             // Need to prepare and send INFO to decoder immediately.
239                             // Because INPUT_DATA message is already received,
240                             // we're just spoofing the message with INPDATA to 
241                             // run the FSM one more time. 
242                             decMsg |= DEC_MSGMSK_INPDATA;
244                             TRACE_VERBOSE0("decDecodeFsm: Info was delayed.");
245                         }
246                     }
247                 }
248             }
249             
250             if (decMsg & DEC_MSGMSK_INPDATA) {
251                 // If we're here, it means decode acknowledgment from decoder
252                 // is delayed, i.e., a new frame of input data is ready before
253                 // current frame decoding is finished.
254                 decMsg &= ~DEC_MSGMSK_INPDATA;
256                 // Do nothing but set a flag to postpone action.
257                 pDec->decodeAckDelayed = TRUE;
259                 TRACE_VERBOSE0("decDecodeFsm: receiving INPDATA in DEC_STATE_DECODE_ACK");
260             }
261             
262             if (decMsg != 0) {
263                 decErr = DEC_ERR_WRONG_MSG;
264             }
265         break;
267         case DEC_STATE_QUIT:
268             //gAsipQuitCnt++;
269             TRACE_VERBOSE0("decDecodeFsm: state: DEC_STATE_QUIT");
270         break;
272         default:
273         break;
274         } /* switch */
276         // Loop through the FSM one more time if:
277         //    - there are more real or spoofed messages to process, 
278         //    - and there is no error.
279         if((decMsg==0) || (decErr!=DEC_NO_ERR)) {
280             decDone = TRUE;
281         }
282         else {
283             decDone = FALSE;
284         }
285     } while(!decDone);
287     // Error handling - complete decoding
288     if(decErr != DEC_NO_ERR) {
289         TRACE_VERBOSE1("decDecodeFsm: decErr %d, calling decDecodeComplete.", decErr);
290         decDecodeComplete(pP, pAsitCfg);
291         TRACE_VERBOSE0("decDecodeFsm: decDecodeComplete done.");
292     }
294     return decErr;
295 } /* decDecodeFsm */
298 Int decErrorCheck(const PAF_ASIT_Params *pP,
299                   const PAF_ASIT_Patchs *pQ,
300                   PAF_ASIT_Config *pAsitCfg,
301                   Int sourceSelect
304     Int retVal, getVal, zMD;
305     Int8 sourceConfig;
307     retVal = DEC_NO_ERR;
309     // Check if source has configured to NONE
310     zMD = pAsitCfg->pAstCfg->masterDec;
311     sourceConfig = sharedMemReadInt8(&(pAsitCfg->pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
312                                      GATEMP_INDEX_DEC);
313     if (sourceConfig == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
314         TRACE_VERBOSE0("decDecodeFsm: sourceSelect == PAF_SOURCE_NONE");
315         retVal = DEC_ERR_SOURCE_NONE;
316     }
318     // Process commands (decode)
319     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
320     if (getVal == ASPERR_QUIT) {
321         TRACE_VERBOSE0("decDecodeFsm. %d: state = QUIT");
322         retVal = DEC_ERR_ASPERR_QUIT;
323     }
324     else if (getVal == ASPERR_ABORT) {
325         TRACE_VERBOSE0("decDecodeFsm. %d: return getVal");
327         // Return here if ASPERR_ABORT
328         retVal = DEC_ERR_ASPERR_ABORT;
329     }
330     else {
331         ;  // No error
332     }
334     return retVal;
335 }  /* decErrorCheck */
338 Int decCheckMajorAu(PAF_AST_Config *pAstCfg)
340     Int8 sourceDecode, sampleRate;
341     Int zMD;
343     zMD = pAstCfg->masterDec;
345     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
346                                      GATEMP_INDEX_DEC);
347     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
348                                      GATEMP_INDEX_DEC);
349     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
350            (sourceDecode == PAF_SOURCE_DXP)     ||
351            (sourceDecode == PAF_SOURCE_DTSHD)
352          )
353        &&( sampleRate == PAF_SAMPLERATE_UNKNOWN)
354        ) {
355         return FALSE;
356     }
357     else {
358         return TRUE;
359     }
360 } /* decCheckMajorAu*/
363 // -----------------------------------------------------------------------------
364 // ASIT Decoding Function - Reinitialization of Decode
365 //
366 //   Name:      decDecodeInit
367 //   Purpose:   Decoding Function for reinitializing the decoding process.
368 //   From:      AST Parameter Function -> decodeProcessing
369 //   Uses:      See code.
370 //   States:    x
371 //   Return:    Error number in standard or SIO form (0 on success).
372 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
373 //              * State information as per parent.
374 //
375 // -----------------------------------------------------------------------------
376 static Int decodeInit(
377         const PAF_ASIT_Params *pP,
378         PAF_ASIT_Config *pAsitCfg,
379         Int sourceSelect)
381     PAF_AST_Config *pAstCfg;
382     PAF_AST_IoInp  *pInp;
383     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
384     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
385     Int as;                             /* Audio Stream Number (1, 2, etc.) */
386     Int z;                              /* decode/encode counter */
387     Int errno;                          /* error number */
388     Int zI, zS;
389     Int argIdx;
390     Int8 tempVar8;
391     char decMsgBuf[ASP_MSG_BUF_LEN];
392     Int status;
394     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
395     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
396     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
398     as = pAstCfg->as;
399     (void)as;  // clear compiler warning in case not used with tracing disabled
401     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
403     // reset frameCount
404     for (z=DECODE1; z < DECODEN; z++)
405     {
406         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
407                                      GATEMP_INDEX_DEC);
408         if (tempVar8)
409         {
410             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
411                               (Int)0, GATEMP_INDEX_DEC);
412         }
413     }
415     // loop through all supported inputs
416     for (z=DECODE1; z < DECODEN; z++)
417     {
418         zI = pP->inputsFromDecodes[z];
419         zS = pP->streamsFromDecodes[z];
420         (void)zS; // clear compiler warning in case not used with tracing disabled
421         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
422                                      GATEMP_INDEX_DEC);
423         if (pInp[zI].hIoPhy && tempVar8)
424         {
425             Uns gear;
426             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
428             // write back Dec configuration
429             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
430             Cache_wait();
432             // send dec activate message to slave
433             argIdx = 0; // set decIdx (zone index)
434             *(Int32 *)&decMsgBuf[argIdx] = z;
435             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_ACTIVATE, decMsgBuf);
436             if (status != ASP_MSG_NO_ERR)
437             {
438                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
439                 SW_BREAKPOINT; // temporary
440                 return ASIP_ERR_DECODE_MSG; // temporary
441             }
442             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_ACTIVATE_DONE, NULL, TRUE);
443             if (status != ASP_MSG_NO_ERR)
444             {
445                 TRACE_TERSE0("decodeInit: error in receiving DEC_ACTIVATE_DONE ack message ");
446                 SW_BREAKPOINT; // temporary
447                 return ASIP_ERR_DECODE_MSG; // temporary
448             }
450             // send dec reset message to slave
451             argIdx = 0; // set decIdx
452             *(Int32 *)&decMsgBuf[argIdx] = z;
453             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_RESET, decMsgBuf);
454             if (status != ASP_MSG_NO_ERR)
455             {
456                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
457                 SW_BREAKPOINT; // temporary
458                 return ASIP_ERR_DECODE_MSG; // temporary
459             }
460             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_RESET_DONE, decMsgBuf, TRUE);
461             if (status != ASP_MSG_NO_ERR)
462             {
463                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
464                 SW_BREAKPOINT; // temporary
465                 return ASIP_ERR_DECODE_MSG; // temporary
466             }
467             else
468             {
469                 argIdx = 0; // get decErrno
470                 errno = *(Int32 *)&decMsgBuf[argIdx];
471             }
473             // invalidate Dec configuration
474             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
475             Cache_wait();
477             if (errno != 0) {
478                 return ASIP_ERR_DECODE_MSG;
479             }
481             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
482                                           GATEMP_INDEX_DEC);
483             tempVar8 = gear < GEARS ? gear : 0;
484             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
485                                tempVar8, GATEMP_INDEX_DEC);
487             // Compute decoder frame length based on source selection
488             // JXU: what does this function do? why does it only return PCM frame length?
489             /*frameLength = getFrameLengthSourceSel(pP, sourceSelect);
491             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
492             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
493             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;*/
495 /*
496             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
497                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
498                     return errno;
499                 }
500             }
501 */
502 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
503             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
504             ioDataCtl.param.frameLengthPcm = frameLength;
505             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
506 */
507             //JXTODO: do we need to update input status here again?
508             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
509                                               &pAstCfg->xInp[zI].inpBufStatus,
510                                               &pAstCfg->xInp[zI].inpBufConfig)) {
511                 return ASIP_ERR_INPUT_CFG;
512             }
513         } /* end of if(hIoPhy && decodeStatus.mode) */
514     } /* end of for (z=DECODE1; z < DECODEN; z++) */
516     pAsitCfg->inpDec.frame = 0;
517     pAsitCfg->inpDec.block = 0;
518     pAsitCfg->inpDec.state = DEC_STATE_INFO_SND;
520     return ASIP_NO_ERR;
521 }  /* decDecodeInit */
525 Int decDecodeComplete( const PAF_ASIT_Params *pP,
526                        PAF_ASIT_Config *pAsitCfg)
528     PAF_AST_Config *pAstCfg;
529     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
530     Int as;                     /* Audio Stream Number (1, 2, etc.) */
531     Int z;                      /* decode/encode counter */
532     Int argIdx;
533     Int8 tempVar8;
534     char decMsgBuf[ASP_MSG_BUF_LEN];
535     Int status;
537     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
538     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
539     as = pAstCfg->as;
540     (void)as;  // clear compiler warning in case not used with tracing disabled
542     for (z=DECODE1; z < DECODEN; z++)
543     {
544         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
545                                      GATEMP_INDEX_DEC);
546         if (pAsitCfg->pIoInp[z].hIoPhy && tempVar8)
547         {
548             TRACE_VERBOSE1("decDecodeComplete: AS%d: finalizing decode", as+z);
550             // send dec deactivate message to slave
551             argIdx = 0; // set decIdx
552             *(Int32 *)&decMsgBuf[argIdx] = z;
553             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DEACTIVATE, decMsgBuf);
554             if (status != ASP_MSG_NO_ERR)
555             {
556                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
557                 SW_BREAKPOINT;
558                 return DEC_ERR_COMPLETE_MSG;
559             }
560             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DEACTIVATE_DONE, NULL, TRUE);
561             if (status != ASP_MSG_NO_ERR)
562             {
563                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
564                 SW_BREAKPOINT;
565                 return DEC_ERR_COMPLETE_MSG;
566             }
567         }
568         else
569         {
570             TRACE_VERBOSE1("decDecodeComplete: AS%d: processing decode <ignored>", as+z);
571         }
572     }
574     return DEC_NO_ERR;
575 }  /* decDecodeComplete */
578 // -----------------------------------------------------------------------------
579 // Decoding Function - Frame-Final Processing
580 //
581 //   Name:      decDecodeFinalTest
582 //   Purpose:   Decoding Function for determining whether processing of the
583 //              current frame is complete.
584 //   From:      AST Parameter Function -> decodeProcessing
585 //   Uses:      See code.
586 //   States:    x
587 //   Return:    0 if incomplete, and 1 if complete.
588 //   Trace:     None.
589 //
591 Int
592 decDecodeFinalTest(
593     const PAF_ASIT_Params *pP,
594     const PAF_ASIT_Patchs *pQ,
595     PAF_ASIT_Config *pAsitCfg
598     PAF_AST_Config *pAstCfg;
599     Int zMD;
600     Int sourceSelect;
601     Int sourceProgram;
602     Int8 tempVar8, temp2Var8;
604     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
605     zMD = pAstCfg->masterDec;
607     sourceSelect  = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
608                                            GATEMP_INDEX_DEC);
609     sourceProgram = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
610                                            GATEMP_INDEX_DEC);
612     if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
613     {
614         return DEC_ERR_DECODE_FINAL;
615     }
617     // The following allows for Force modes to switch without command deferral. This might
618     // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
619     if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
620     {
621         if (sourceSelect == PAF_SOURCE_DTSALL)
622         {
623             if (sourceProgram != PAF_SOURCE_DTS11 &&
624                 sourceProgram != PAF_SOURCE_DTS12 &&
625                 sourceProgram != PAF_SOURCE_DTS13 &&
626                 sourceProgram != PAF_SOURCE_DTS14 &&
627                 sourceProgram != PAF_SOURCE_DTS16 &&
628                 sourceProgram != PAF_SOURCE_DTSHD)
629             {
630                 return DEC_ERR_DECODE_FINAL;
631             }
632         }
633         else if (sourceSelect == PAF_SOURCE_PCMAUTO)
634         {
635             if (sourceProgram != PAF_SOURCE_PCM)
636             {
637                 return DEC_ERR_DECODE_FINAL;
638             }
639         }
640         else
641         {
642             tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
643                                           GATEMP_INDEX_DEC);
644             temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
645                                           GATEMP_INDEX_DEC);
646             if (temp2Var8 != tempVar8)
647             {
648                 return DEC_ERR_DECODE_FINAL;
649             }
650         }
651     }
653     return DEC_NO_ERR;
654 } //decDecodeFinalTest
656 Int decInfoSnd(
657         const PAF_ASIT_Params *pP,
658         const PAF_ASIT_Patchs *pQ,
659         PAF_ASIT_Config *pAsitCfg
662     PAF_AST_Config *pAstCfg;
663     PAF_AST_IoInp  *pInp;
664     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
665     Int as;                    /* Audio Stream Number (1, 2, etc.) */
666     Int z;                     /* input/decode/stream counter */
667     Int errno;                 /* error number */
668     Int zD, zI, zS, zX;
669     Int argIdx;
670     Int8 tempVar8;
671     char decMsgBuf[ASP_MSG_BUF_LEN];
672     Int status;
674     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
675     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
676     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
677     as = pAstCfg->as;
679     // Set decode control: sample rate, emphasis
680     for (z=INPUT1; z < INPUTN; z++)
681     {
682         zD = z;
683         for (zX = DECODE1; zX < DECODEN; zX++)
684         {
685             if (pP->inputsFromDecodes[zX] == z) {
686                 zD = zX;
687                 break;
688             }
689         }
691         if (pInp[z].hIoPhy) {
692             //determine associated decoder
693             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
694                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
695                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
696                     pAstCfg->xDec[zD].decodeControl.sampleRate =
697                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
698                 }
699                 else {
700                     //TRACE_TERSE1("decDecodeInfo: AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
701                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
702                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
703                         pAstCfg->xDec[zD].decodeControl.sampleRate);
704                     // return (ASPERR_INFO_RATECHANGE);
705                 }
706             }
708             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
709                                          GATEMP_INDEX_DEC);
710             pAstCfg->xDec[zD].decodeControl.emphasis =
711                 tempVar8 != PAF_SOURCE_PCM
712                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
713                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
714         }
715         else {
716             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
717             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
718         }
719     } /* end of for (z=INPUT1; z < INPUTN; z++) */
721     // Decode info
722     for (z=DECODE1; z < DECODEN; z++)
723     {
724         zI = pP->inputsFromDecodes[z];
725         zS = pP->streamsFromDecodes[z];
726         (void)zS; // clear compiler warning in case not used with tracing disabled
728         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
729                                      GATEMP_INDEX_DEC);
730         if (pInp[zI].hIoPhy  && tempVar8)
731         {
732             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
734             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
735                                               &pAstCfg->xInp[zI].inpBufStatus,
736                                               &pAstCfg->xInp[zI].inpBufConfig)) {
737                 TRACE_TERSE1("asitUpdateInputStatus return error errno 0x%x.", errno);
738                 return DEC_ERR_INFO_SNDMSG;
739             }
741 #if 0 // debug
742             // capture input buffer
743             capIb(pAstCfg->xInp[zI].pInpBuf);
744             gCapIb_cnt++;
745 #endif
747             // write back Inp configuration
748             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
749             // write back Dec configuration
750             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
751             Cache_wait();
753             // send info message to slave
754             argIdx = 0; // set decIdx
755             *(Int32 *)&decMsgBuf[argIdx] = z;
756             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_INFO, decMsgBuf);
757             if (status != ASP_MSG_NO_ERR)
758             {
759                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
760                 SW_BREAKPOINT; // temporary
761                 return -1;     // temporary
762             }
763 /*            else
764             {
765                 argIdx = 0; // get decErrno
766                 errno = *(Int32 *)&decMsgBuf[argIdx];
767             }
769             if (errno) {
770                 TRACE_TERSE1("decInfoSndMSg return error errno 0x%x.", errno);
771                 return DEC_ERR_INFO_SNDMSG;
772             }
773 */
774         }
775     } // z=DECODE1 to DECODEN
777 //////////////////////////////////////////////////////////////////////////////
778     //asitPostInfoEvent(); // simulation
779 //////////////////////////////////////////////////////////////////////////////
781     return ASIP_NO_ERR;
782 }  /* decInfoSnd() */
785 Int decInfoAck(
786         const PAF_ASIT_Params *pP,
787         const PAF_ASIT_Patchs *pQ,
788         PAF_ASIT_Config *pAsitCfg
791     PAF_AST_Config *pAstCfg;
792     PAF_AST_IoInp  *pInp;
793     AspMsgMaster_Handle hAspMsgMaster;
794     Int as;                    /* Audio Stream Number (1, 2, etc.) */
795     Int z;                     /* input/decode/stream counter */
796     Int errno;                 /* error number */
797     Int zI, zS;
798     Int zMD;
799     Int zMS;
800     Int argIdx;
801     Int8 tempVar8;
802     Int tempVar;
803     char decMsgBuf[ASP_MSG_BUF_LEN];
804     Int status;
806     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
807     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
808     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
809     as = pAstCfg->as;
810     zMD = pAstCfg->masterDec;
811     zMS = pAstCfg->masterStr;
812     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
814     // Decode info
815     for (z=DECODE1; z < DECODEN; z++)
816     {
817         zI = pP->inputsFromDecodes[z];
818         zS = pP->streamsFromDecodes[z];
819         (void)zS; // clear compiler warning in case not used with tracing disabled
821         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
822                                      GATEMP_INDEX_DEC);
823         if (pInp[zI].hIoPhy  && tempVar8)
824         {
825             // acknowledge info message from slave
826             errno  = 0;
827             //argIdx = 0; // set decIdx
828             //*(Int32 *)&decMsgBuf[argIdx] = z;
829             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_INFO_DONE, decMsgBuf, FALSE);
830             if (status != ASP_MSG_NO_ERR)
831             {
832                 TRACE_TERSE0("decodeInfo: error in receiving DEC_INFO_DONE ack message ");
833                 SW_BREAKPOINT; // temporary
834                 errno = -1;    // temporary error return value
835                 return errno;     // temporary
836             }
837             else
838             {
839                 argIdx = 0; // get decErrno
840                 errno = *(Int32 *)&decMsgBuf[argIdx];
841             }
843             // invalidate Dec configuration
844             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
845             Cache_wait();
847             if (errno) {
848                 TRACE_TERSE1("decInfoAck return error errno 0x%x.", errno);
849                 return DEC_ERR_INFO_ACKMSG;
850             }
852             // increment decoded frame count
853             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
854                                        GATEMP_INDEX_DEC);
855             tempVar += 1;
856             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
857                               tempVar, GATEMP_INDEX_DEC);
858         }
859     } // z=DECODE1 to DECODEN
861     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
862     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
863                                  GATEMP_INDEX_DEC);
864     if (tempVar8)
865     {
866         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
867                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
868     }
870     // since now decoding update decode status for all enabled decoders
871     for (z=DECODE1; z < DECODEN; z++)
872     {
873         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
874                                      GATEMP_INDEX_DEC);
875         if (tempVar8)
876         {
877             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
878                                          GATEMP_INDEX_DEC);
879             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
880                                tempVar8, GATEMP_INDEX_DEC);
882             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
883                                          GATEMP_INDEX_DEC);
884             if (tempVar8 == PAF_SOURCE_SNG)
885             {
886                 tempVar8 = PAF_SOURCE_SNG;
887                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
888                                    tempVar8, GATEMP_INDEX_DEC);
889             }
890         }
891     }
893     return ASIP_NO_ERR;
897 static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
898                            PAF_ASIT_Config *pAsitCfg)
900     PAF_AST_Config *pAstCfg;
901     PAF_AST_IoInp  *pInp;
902     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
903     Int as;                     /* Audio Stream Number (1, 2, etc.) */
904     Int z;                      /* decode/stream counter */
905     Int argIdx;
906     Int cbErrno, errno;
907     char decMsgBuf[ASP_MSG_BUF_LEN];
908     Int status;
910     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
911     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
912     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
913     as = pAstCfg->as;
914     (void)as; // clear compiler warning in case not used with tracing disabled
916     // Decode data
917     for (z=DECODE1; z < DECODEN; z++)
918     {
919         Int zI = pP->inputsFromDecodes[z];
920         Int zS = pP->streamsFromDecodes[z];
921         (void)zS; // clear compiler warning in case not used with tracing disabled
922         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
923         {
924             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
926             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
927                     as+zS,
928                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
929                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
931 #if 0 // debug
932             // capture input buffer
933             capIbPcm(pAstCfg->xInp[z].pInpBuf);
934 #endif
935             
936             // write back Dec configuration
937             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
938             Cache_wait();
940             // send decode message to slave
941             errno  = 0;
942             argIdx = 0; // set decIdx
943             *(Int32 *)&decMsgBuf[argIdx] = z;
944             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DECODE, decMsgBuf);
945             if (status != ASP_MSG_NO_ERR)
946             {
947                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
948                 SW_BREAKPOINT; // temporary
949                 return -1;     // temporary
950             }
951 /*            else
952             {
953                 argIdx = 0; // get decErrno
954                 errno = *(Int32 *)&decMsgBuf[argIdx];
955                 argIdx += sizeof(Int32); // get cbErrno
956                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
957                 if (cbErrno != 0)
958                 {
959                     gCbWrtAfErrCnt++;
960                     TRACE_TERSE1("CB write error=%d", cbErrno);
961                     //SW_BREAKPOINT; // temporary
962                 }
964                 if(errno) {
965                     TRACE_TERSE1("decDecodeSnd return error errno 0x%x.", errno);
966                     return DEC_ERR_DECODE_SNDMSG;
967                 }
968             }*/
970         } // hIoPhy && decodeStatus.mode
971         else {
972             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
973         }
974     } // z=DECODE1 to DECODEN
976 //////////////////////////////////////////////////////////////////////////////
977     //asitPostDecEvent(); // simulation
978 //////////////////////////////////////////////////////////////////////////////
980     return ASIP_NO_ERR;
981 } /* decDecodeSnd() */
984 static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
985                            PAF_ASIT_Config *pAsitCfg)
987     PAF_AST_Config *pAstCfg;
988     PAF_AST_IoInp  *pInp;
989     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
990     Int as;                     /* Audio Stream Number (1, 2, etc.) */
991     Int z;                      /* decode/stream counter */
992     Int errno;                  /* error number */
993     Int argIdx;
994     Int cbErrno;
995     char decMsgBuf[ASP_MSG_BUF_LEN];
996     Int status;
998     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
999     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
1000     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
1001     as = pAstCfg->as;
1002     (void)as; // clear compiler warning in case not used with tracing disabled
1004     // Decode data
1005     for (z=DECODE1; z < DECODEN; z++)
1006     {
1007         Int zI = pP->inputsFromDecodes[z];
1008         Int zS = pP->streamsFromDecodes[z];
1009         (void)zS; // clear compiler warning in case not used with tracing disabled
1010         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
1011         {
1012             // receive decode ack message from slave
1013             errno  = 0;
1014             //argIdx = 0; // set decIdx
1015             //*(Int32 *)&decMsgBuf[argIdx] = z;
1016             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DECODE_DONE, decMsgBuf, FALSE);
1017             if (status != ASP_MSG_NO_ERR)
1018             {
1019                 TRACE_TERSE0("decodeDecode: error in receiving DEC_DECODE_DONE ack message ");
1020                 SW_BREAKPOINT; // temporary
1021                 errno = -1; // temporary error return value
1022                 return errno;
1023             }
1024             else
1025             {
1026                 argIdx = 0; // get decErrno
1027                 errno = *(Int32 *)&decMsgBuf[argIdx];
1028                 argIdx += sizeof(Int32); // get cbErrno
1029                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
1030                 if (cbErrno != 0)
1031                 {
1032                     gCbWrtAfErrCnt++;
1033                     TRACE_TERSE1("CB write error=%d", cbErrno);
1034                     //SW_BREAKPOINT; // temporary
1035                 }
1036             }
1038             // invalidate Dec configuration
1039             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1040             Cache_wait();
1042             if(errno) {
1043                 TRACE_TERSE1("decDecodeAck return error errno 0x%x.", errno);
1044                 return DEC_ERR_DECODE_ACKMSG;
1045             }
1047 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
1048             as_traceChannels(pAsitCfg, z);
1049 #endif
1050         } // hIoPhy && decodeStatus.mode
1051         else {
1052             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
1053         }
1054     } // z=DECODE1 to DECODEN
1056     return ASIP_NO_ERR;
1057 } /* decDecodeAck */
1060 #if 0
1061 Int asipDecodeProcessing(
1062         const PAF_ASIT_Params *pP,
1063         const PAF_ASIT_Patchs *pQ,
1064         PAF_ASIT_Config *pC,
1065         Int sourceSelect)
1067     PAF_AST_Config *pAstCfg;
1068     Int errno, retVal;                          /* error number */
1069     Int zMD;
1071     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1072     zMD = pAstCfg->masterDec;
1073     retVal = ASIP_NO_ERR;
1075     //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
1076     errno = decDecodeInfo(pP, pQ, pC);
1077     if (errno != ASIP_NO_ERR) {
1078         //gAsipInfo1_PrimaryErrCnt++;
1079         TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1080         retVal =  ASIP_ERR_DECODE_INFO;
1081     }
1082     else {
1083         // Don't start decode until major access unit is found.
1084         Int8 sourceDecode, sampleRate;
1085         sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1086                                          GATEMP_INDEX_DEC);
1087         sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1088                                          GATEMP_INDEX_DEC);
1089         if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1090                (sourceDecode == PAF_SOURCE_DXP)     ||
1091                (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1092              ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1093             /* do nothing and return - waiting for major access unit */
1094             pC->inpDec.frame++;
1095             retVal =  ASIP_NO_ERR;
1096         }
1097         else {
1098             errno = decDecodeData(pP, pQ, pC, sourceSelect);
1099             if (errno != ASIP_NO_ERR) {
1100                 //gAsipDecodeErrCnt++;
1101                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
1102                 retVal = ASIP_ERR_DECODE_DATA;
1103             }
1104             else {
1105                 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pC->inpDec.frame, pC->inpDec.block);
1106                 if (errno) {
1107                     retVal = ASIP_ERR_DECODE_FINAL;
1108                 }
1109                 else {
1110                     retVal = ASIP_NO_ERR;
1111                 }
1112             }
1113         }
1114     }
1116     return retVal;
1117 }  /* asipDecodeProcessing */
1118 #endif
1121 #if 0
1122 // -----------------------------------------------------------------------------
1123 // ASIT Processing Function - Decode Processing
1124 //
1125 //   Name:      asipDecodeProcessing
1126 //   Purpose:
1127 //   Return:    Error number in standard form (0 on success).
1128 // -----------------------------------------------------------------------------
1129 Int asipDecodeProcessing(
1130         const PAF_ASIT_Params *pP,
1131         const PAF_ASIT_Patchs *pQ,
1132         PAF_ASIT_Config *pAsitCfg,
1133         Int sourceSelect)
1135     PAF_AST_Config *pAstCfg;
1136     asipDecProc_t  *pDec;
1137     Int decError, retVal, getVal;                          /* error number */
1138     Int zMD, decDone;
1139     Int8 tempVar8;
1141     pAstCfg = pAsitCfg->pAstCfg;     // get pointer to common (shared) configuration
1142     zMD = pAstCfg->masterDec;
1143     pDec = &pAsitCfg->inpDec;
1145     retVal = ASIP_NO_ERR;
1147     // Initialization for decode processing
1148     if(!pDec->initDone) {
1149         // Initialize decoder and send message to decoder
1150         retVal = decDecodeInit(pP, pAsitCfg, pAsitCfg->pIoInp[zMD].sourceSelect);
1151         if(retVal != ASIP_NO_ERR) {
1152             decDecodeComplete(pP, pAsitCfg);
1154             return retVal;
1155         }
1157         pDec->initDone = TRUE;
1158     }
1160     // Check if source has configured to NONE
1161     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1162                                  GATEMP_INDEX_DEC);
1163     if (tempVar8 == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
1164         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1165         pAsitCfg->inpDec.state = QUIT;   // skip processing, quit decoding
1166         retVal = ASIP_ERR_DECODE_QUIT;
1167     }
1169     // Process commands (decode)
1170     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
1171     if (getVal) {
1172         retVal = ASIP_ERR_DECODE_COMMAND;
1173         if (getVal == ASPERR_QUIT) {
1174             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1176             // Don't return if ASPERR_QUIT, but skip decode processing and quit
1177             pAsitCfg->inpDec.state = QUIT;
1178         }
1179         else if (getVal == ASPERR_ABORT) {
1180             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1182             // Return here if ASPERR_ABORT
1183             return retVal;
1184         }
1185         else {
1186             /* ignore */;
1187         }
1188     }
1190     do {
1191         decDone = TRUE;
1193         switch(pAsitCfg->inpDec.state)
1194         {
1195             case INFO1:
1196                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1197                 if (decError) {
1198                     //gAsipInfo1_PrimaryErrCnt++;
1199                     TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
1200                     retVal = ASIP_ERR_DECODE_INFO1;
1201                 }
1202                 else {
1203                     // Don't start decode until major access unit is found.
1204                     Int8 sourceDecode, sampleRate;
1206                     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1207                                                      GATEMP_INDEX_DEC);
1208                     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1209                                                      GATEMP_INDEX_DEC);
1210                     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1211                            (sourceDecode == PAF_SOURCE_DXP)     ||
1212                            (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1213                          ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1214                         //gMajorAuMissed++; // debug
1215                         pAsitCfg->inpDec.frame++;
1216                         //pAsitCfg->inpDec.state = INFO1;    // stay in this state
1217                     }
1218                     else {
1219                         decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1220                         if(decError) {
1221                             retVal = ASIP_ERR_DECODE_INFO1;
1222                         }
1223                         else {
1224                             pAsitCfg->inpDec.state = DECODE;
1225                             decDone = FALSE;    // go to DECODE state before return
1226                         }
1227                     }
1228                 }
1229                 break;
1231             case INFO2:
1232                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1233                 if (decError) {
1234                     //gAsipInfo1_PrimaryErrCnt++;
1235                     TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
1236                     retVal = ASIP_ERR_DECODE_INFO2;
1237                 }
1238                 else {
1239                     pAsitCfg->inpDec.state = DECODE;
1240                     decDone = FALSE;     // go to DECODE state before return
1241                 }
1242                 break;
1244             case DECODE:
1245                 decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
1246                 if (decError) {
1247                     //gAsipDecodeErrCnt++;
1248                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
1249                     retVal = ASIP_ERR_DECODE_DATA;
1250                 }
1251                 else {
1252                     decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1253                     if (decError) {
1254                         retVal = ASIP_ERR_DECODE_FINAL;
1255                     }
1256                     else {
1257                         pAsitCfg->inpDec.frame++;
1258                         pAsitCfg->inpDec.state = INFO2;
1259                     }
1260                 }
1261                 break;
1263             case QUIT:
1264                 //gAsipQuitCnt++;
1265                 Log_info0("TaskAsip: state=QUIT");
1267                 // Quit:
1268                 // - Set error number registers.
1269                 // - Exit state machine to "decode complete" processing.
1270                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
1271                 break;
1273             default:
1274                 break;
1276         }  /* switch */
1278     } while (!decDone);
1280     if(retVal != ASIP_NO_ERR) {
1281         decDecodeComplete(pP, pAsitCfg);
1282     }
1284     return retVal;
1285 }  /* asipDecodeProcessing */
1287 #endif
1290 /* Nothing past this line */