Fixed loss of SYNC problem and restart problem. ASIT FSM works fine with
[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 Int AspMsgSnd(UInt32 sndCmd, char *sndMsgBuf);
87 Int AspMsgAck(UInt32 ackCmd, char *ackMsgBuf);
89 extern UInt32 gCbWrtAfErrCnt;
92 Int decDecodeInit(
93         const PAF_ASIT_Params *pP,
94         PAF_ASIT_Config *pAsitCfg,
95         Int sourceSelect)
96 {
97     Int errno;
99     errno = decodeInit(pP, pAsitCfg, sourceSelect);
101     if(errno) {
102         decDecodeComplete(pP, pAsitCfg);
104         return ASIP_ERR_DECODE_INIT;
105     }
107     pAsitCfg->inpDec.majorAuFound = FALSE;
108     
109     return ASIP_NO_ERR;
113 // -----------------------------------------------------------------------------
114 // -----------------------------------------------------------------------------
115 Int decDecodeFsm(
116         const PAF_ASIT_Params *pP,
117         const PAF_ASIT_Patchs *pQ,
118         PAF_ASIT_Config *pAsitCfg,
119         Int sourceSelect,
120         UInt decMsg)
122     asipDecProc_t  *pDec;
123     Int decErr, decDone;
125     pDec = &pAsitCfg->inpDec;
127     TRACE_VERBOSE1("Entering decDecodeFsm with decMsg %d.", decMsg);
129     decErr = decErrorCheck(pP, pQ, pAsitCfg, sourceSelect);
130     if(decErr == DEC_ERR_ASPERR_ABORT) {
131         return decErr;
132     }
133     else if(decErr != DEC_NO_ERR) {
134         pDec->state = DEC_STATE_QUIT;
135     }
136     else {
137         ; // No error
138     }
140     // It is possible to go through the FSM multiple times:
141     //    - Multiple messages may be received, INPDATA and DECACK. In this case,
142     //      the FSM will process DECACK in state DEC_STATE_DECODE_ACK and then 
143     //      INPDATA in state DEC_STATE_INFO_SND.
144     //    - DECACK is received after INPDATA. In this case, after DECACK is 
145     //      processed, we will spoof decMsg with INPDATA so that FSM will run 
146     //      again and process INPDATA in DEC_STATE_INFO_SND.
147     do {
148         switch(pDec->state)
149         {
150         case DEC_STATE_INFO_SND:
151             if(decMsg != DEC_MSGMSK_INPDATA) {
152                 // Only DEC_MSGMSK_INPDATA is expected in this state
153                 decErr = DEC_ERR_WRONG_MSG;
154             }
155             else {
156                 decMsg &= ~DEC_MSGMSK_INPDATA;   // clear bit mask
158                 // Prepare and send INFO to decoder
159                 decErr = decInfoSnd(pP, pQ, pAsitCfg);
160                 if(decErr == DEC_NO_ERR) {
161                     pDec->state = DEC_STATE_INFO_ACK_DECODE_SND;
162                     TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_SND done.");
163                 }
164             }
165         break;
167         case DEC_STATE_INFO_ACK_DECODE_SND:
168             //if(decMsg != DEC_MSGMSK_INFOACK) {
169                 // only DEC_MSGMSK_INFOACK is expected in this state
170             if((decMsg&DEC_MSGMSK_INFOACK) != DEC_MSGMSK_INFOACK) {
171                 // During debugging, it is possible that INPDATA and INFOACK
172                 // come at the same time (e.g. due to breaking point).
173                 decErr = DEC_ERR_WRONG_MSG;
174             }
175             else {
176                 decMsg &= ~DEC_MSGMSK_INFOACK;  // clear the bit mask
178                 // Process the INFO acknowledgment from decoder
179                 decErr = decInfoAck(pP, pQ, pAsitCfg);
180                 if(decErr == DEC_NO_ERR) {
181                     // Don't start decode until major access unit is found.
182                     if(!pDec->majorAuFound) {
183                         // Do we want to still check major AU after it is found?
184                         // In old code, it was not checked again after it was found. 
185                         pDec->majorAuFound = decCheckMajorAu(pAsitCfg->pAstCfg);    
186                     }
187                     
188                     if(pDec->majorAuFound) {
189                         // Major access unit is found. Send message to decoder to decode now.
190                         decErr = decDecodeSnd(pP, pQ, pAsitCfg);
191                         if(decErr == DEC_NO_ERR) {
192                             pDec->state = DEC_STATE_DECODE_ACK;
194                             // Initialize decodeAckDelayed to FALSE - normally
195                             // DECODE ACK comes after INPDATA. 
196                             pDec->decodeAckDelayed = FALSE;
198                             TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_ACK_DECODE_SND done and going to DEC_STATE_DECODE_ACK.");
199                         }
200                     }
201                     else {
202                         // No major access unit - go back to INFO.
203                         pDec->frame++;
204                         pDec->state = DEC_STATE_INFO_SND;
205                         TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_ACK_DECODE_SND done and going to DEC_STATE_INFO_SND.");
206                     }
207                 }
208             }
209         break;
211         case DEC_STATE_DECODE_ACK:
212             // Two different messages may be received: DECACK (decode acknowledgment)
213             // or INPDATA (input data ready).
214             if(decMsg & DEC_MSGMSK_DECACK) {
215                 decMsg &= ~DEC_MSGMSK_DECACK;
217                 // Process DECODE ACK from decoder
218                 decErr = decDecodeAck(pP, pQ, pAsitCfg);
219                 if(decErr == DEC_NO_ERR) {
220                     // Decode finishes. Conduct final test.
221                     decErr = decDecodeFinalTest(pP, pQ, pAsitCfg);
222                     if(decErr == DEC_NO_ERR) {
223                         pDec->frame++;
224                         pDec->state = DEC_STATE_INFO_SND;
225                         TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_DECODE_ACK done and going to DEC_STATE_INFO_SND.");
227                         // Check if DECACK comes late (after INPDATA)
228                         if(pDec->decodeAckDelayed) {
229                             pDec->decodeAckDelayed = FALSE;
231                             // Need to prepare and send INFO to decoder immediately.
232                             // Becuase INPUT_DATA message is already received, 
233                             // we're just spoofing the message with INPDATA to 
234                             // run the FSM one more time. 
235                             decMsg |= DEC_MSGMSK_INPDATA;
237                             TRACE_VERBOSE0("decDecodeFsm: Info was delayed.");
238                         }
239                     }
240                 }
241             }
242             else if(decMsg & DEC_MSGMSK_INPDATA) {
243                 // If we're here, it means decode acknowledgment from decoder
244                 // is delayed, i.e., a new frame of input data is ready before
245                 // current frame decoding is finished.
246                 decMsg &= ~DEC_MSGMSK_INPDATA;
248                 // Do nothing but set a flag to postpone action.
249                 pDec->decodeAckDelayed = TRUE;
251                 TRACE_VERBOSE0("decDecodeFsm: receiving INPDATA in DEC_STATE_DECODE_ACK");
252             }
253             else {
254                 decErr = DEC_ERR_WRONG_MSG;
255             }
256         break;
258         case DEC_STATE_QUIT:
259             //gAsipQuitCnt++;
260             TRACE_VERBOSE0("decDecodeFsm: state: DEC_STATE_QUIT");
261         break;
263         default:
264         break;
265         } /* switch */
267         // Loop through the FSM one more time if:
268         //    - there are more real or spoofed messages to process, 
269         //    - and there is no error.
270         if((decMsg==0) || (decErr!=DEC_NO_ERR)) {
271             decDone = TRUE;
272         }
273         else {
274             decDone = FALSE;
275         }
276     } while(!decDone);
278     // Error handling - complete decoding
279     if(decErr != DEC_NO_ERR) {
280         TRACE_VERBOSE1("decDecodeFsm: decErr %d, calling decDecodeComplete.", decErr);
281         decDecodeComplete(pP, pAsitCfg);
282         TRACE_VERBOSE0("decDecodeFsm: decDecodeComplete done.");
283     }
285     return decErr;
286 } /* decDecodeFsm */
289 Int decErrorCheck(const PAF_ASIT_Params *pP,
290                   const PAF_ASIT_Patchs *pQ,
291                   PAF_ASIT_Config *pAsitCfg,
292                   Int sourceSelect
295     Int retVal, getVal, zMD;
296     Int8 sourceConfig;
298     retVal = DEC_NO_ERR;
300     // Check if source has configured to NONE
301     zMD = pAsitCfg->pAstCfg->masterDec;
302     sourceConfig = sharedMemReadInt8(&(pAsitCfg->pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
303                                      GATEMP_INDEX_DEC);
304     if (sourceConfig == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
305         TRACE_VERBOSE0("decDecodeFsm: sourceSelect == PAF_SOURCE_NONE");
306         retVal = DEC_ERR_SOURCE_NONE;
307     }
309     // Process commands (decode)
310     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
311     if (getVal == ASPERR_QUIT) {
312         TRACE_VERBOSE0("decDecodeFsm. %d: state = QUIT");
313         retVal = DEC_ERR_ASPERR_QUIT;
314     }
315     else if (getVal == ASPERR_ABORT) {
316         TRACE_VERBOSE0("decDecodeFsm. %d: return getVal");
318         // Return here if ASPERR_ABORT
319         retVal = DEC_ERR_ASPERR_ABORT;
320     }
321     else {
322         ;  // No error
323     }
325     return retVal;
326 }  /* decErrorCheck */
329 Int decCheckMajorAu(PAF_AST_Config *pAstCfg)
331     Int8 sourceDecode, sampleRate;
332     Int zMD;
334     zMD = pAstCfg->masterDec;
336     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
337                                      GATEMP_INDEX_DEC);
338     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
339                                      GATEMP_INDEX_DEC);
340     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
341            (sourceDecode == PAF_SOURCE_DXP)     ||
342            (sourceDecode == PAF_SOURCE_DTSHD)
343          )
344        &&( sampleRate == PAF_SAMPLERATE_UNKNOWN)
345        ) {
346         return FALSE;
347     }
348     else {
349         return TRUE;
350     }
351 } /* decCheckMajorAu*/
354 // -----------------------------------------------------------------------------
355 // ASIT Decoding Function - Reinitialization of Decode
356 //
357 //   Name:      decDecodeInit
358 //   Purpose:   Decoding Function for reinitializing the decoding process.
359 //   From:      AST Parameter Function -> decodeProcessing
360 //   Uses:      See code.
361 //   States:    x
362 //   Return:    Error number in standard or SIO form (0 on success).
363 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
364 //              * State information as per parent.
365 //
366 // -----------------------------------------------------------------------------
367 static Int decodeInit(
368         const PAF_ASIT_Params *pP,
369         PAF_ASIT_Config *pAsitCfg,
370         Int sourceSelect)
372     PAF_AST_Config *pAstCfg;
373     PAF_AST_IoInp  *pInp;
374     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
375     Int as;                             /* Audio Stream Number (1, 2, etc.) */
376     Int z;                              /* decode/encode counter */
377     Int errno;                          /* error number */
378     Int zI, zS;
379     Int argIdx;
380     Int8 tempVar8;
381     char decMsgBuf[ASP_MSG_BUF_LEN];
383     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
384     pInp    = pAsitCfg->pIoInp;
386     as = pAstCfg->as;
387     (void)as;  // clear compiler warning in case not used with tracing disabled
389     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
391     // reset frameCount
392     for (z=DECODE1; z < DECODEN; z++)
393     {
394         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
395                                      GATEMP_INDEX_DEC);
396         if (tempVar8)
397         {
398             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
399                               (Int)0, GATEMP_INDEX_DEC);
400         }
401     }
403     // loop through all supported inputs
404     for (z=DECODE1; z < DECODEN; z++)
405     {
406         zI = pP->inputsFromDecodes[z];
407         zS = pP->streamsFromDecodes[z];
408         (void)zS; // clear compiler warning in case not used with tracing disabled
409         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
410                                      GATEMP_INDEX_DEC);
411         if (pInp[zI].hIoPhy && tempVar8)
412         {
413             Uns gear;
414             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
416             // write back Dec configuration
417             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
418             Cache_wait();
420             // FL: send dec activate message to slave
421             argIdx = 0; // set decIdx (zone index)
422             *(Int32 *)&decMsgBuf[argIdx] = z;
423             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
424                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
425             {
426                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
427                 SW_BREAKPOINT; // temporary
428                 return ASIP_ERR_DECODE_MSG; // temporary
429             }
431             // FL: send dec reset message to slave
432             argIdx = 0; // set decIdx
433             *(Int32 *)&decMsgBuf[argIdx] = z;
434             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
435                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
436             {
437                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
438                 SW_BREAKPOINT; // temporary
439                 return ASIP_ERR_DECODE_MSG; // temporary
440             }
441             else
442             {
443                 argIdx = 0; // get decErrno
444                 errno = *(Int32 *)&decMsgBuf[argIdx];
445             }
447             // (***) FL: revisit
448             // invalidate Dec configuration
449             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
450             Cache_wait();
452             if (errno != 0) {
453                 return ASIP_ERR_DECODE_MSG;
454             }
456             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
457                                           GATEMP_INDEX_DEC);
458             tempVar8 = gear < GEARS ? gear : 0;
459             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
460                                tempVar8, GATEMP_INDEX_DEC);
462             // Compute decoder frame length based on source selection
463             // JXU: what does this function do? why does it only return PCM frame length?
464             /*frameLength = getFrameLengthSourceSel(pP, sourceSelect);
466             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
467             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
468             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;*/
470 /*
471             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
472                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
473                     return errno;
474                 }
475             }
476 */
477 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
478             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
479             ioDataCtl.param.frameLengthPcm = frameLength;
480             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
481 */
482             //JXTODO: do we need to update input status here again?
483             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
484                                               &pAstCfg->xInp[zI].inpBufStatus,
485                                               &pAstCfg->xInp[zI].inpBufConfig)) {
486                 return ASIP_ERR_INPUT_CFG;
487             }
488         } /* end of if(hIoPhy && decodeStatus.mode) */
489     } /* end of for (z=DECODE1; z < DECODEN; z++) */
491     pAsitCfg->inpDec.frame = 0;
492     pAsitCfg->inpDec.block = 0;
493     pAsitCfg->inpDec.state = DEC_STATE_INFO_SND;
495     return ASIP_NO_ERR;
496 }  /* decDecodeInit */
500 Int decDecodeComplete( const PAF_ASIT_Params *pP,
501                        PAF_ASIT_Config *pAsitCfg)
503     PAF_AST_Config *pAstCfg;
504     Int as;                     /* Audio Stream Number (1, 2, etc.) */
505     Int z;                      /* decode/encode counter */
506     Int argIdx;
507     Int8 tempVar8;
508     char decMsgBuf[ASP_MSG_BUF_LEN];
510     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
511     as = pAstCfg->as;
512     (void)as;  // clear compiler warning in case not used with tracing disabled
514     for (z=DECODE1; z < DECODEN; z++)
515     {
516         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
517                                      GATEMP_INDEX_DEC);
518         if (pAsitCfg->pIoInp[z].hIoPhy && tempVar8)
519         {
520             TRACE_VERBOSE1("decDecodeComplete: AS%d: finalizing decode", as+z);
522             // FL: send dec deactivate message to slave
523             argIdx = 0; // set decIdx
524             *(Int32 *)&decMsgBuf[argIdx] = z;
525             if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
526                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
527             {
528                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
529                 SW_BREAKPOINT;
530                 return DEC_ERR_COMPLETE_MSG;
531             }
532         }
533         else
534         {
535             TRACE_VERBOSE1("decDecodeComplete: AS%d: processing decode <ignored>", as+z);
536         }
537     }
539     return DEC_NO_ERR;
540 }  /* decDecodeComplete */
543 // -----------------------------------------------------------------------------
544 // Decoding Function - Frame-Final Processing
545 //
546 //   Name:      decDecodeFinalTest
547 //   Purpose:   Decoding Function for determining whether processing of the
548 //              current frame is complete.
549 //   From:      AST Parameter Function -> decodeProcessing
550 //   Uses:      See code.
551 //   States:    x
552 //   Return:    0 if incomplete, and 1 if complete.
553 //   Trace:     None.
554 //
556 Int
557 decDecodeFinalTest(
558     const PAF_ASIT_Params *pP,
559     const PAF_ASIT_Patchs *pQ,
560     PAF_ASIT_Config *pAsitCfg
563     PAF_AST_Config *pAstCfg;
564     Int zMD;
565     Int sourceSelect;
566     Int sourceProgram;
567     Int8 tempVar8, temp2Var8;
569     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
570     zMD = pAstCfg->masterDec;
572     sourceSelect  = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
573                                            GATEMP_INDEX_DEC);
574     sourceProgram = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
575                                            GATEMP_INDEX_DEC);
577     if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
578     {
579         return DEC_ERR_DECODE_FINAL;
580     }
582     // The following allows for Force modes to switch without command deferral. This might
583     // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
584     if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
585     {
586         if (sourceSelect == PAF_SOURCE_DTSALL)
587         {
588             if (sourceProgram != PAF_SOURCE_DTS11 &&
589                 sourceProgram != PAF_SOURCE_DTS12 &&
590                 sourceProgram != PAF_SOURCE_DTS13 &&
591                 sourceProgram != PAF_SOURCE_DTS14 &&
592                 sourceProgram != PAF_SOURCE_DTS16 &&
593                 sourceProgram != PAF_SOURCE_DTSHD)
594             {
595                 return DEC_ERR_DECODE_FINAL;
596             }
597         }
598         else if (sourceSelect == PAF_SOURCE_PCMAUTO)
599         {
600             if (sourceProgram != PAF_SOURCE_PCM)
601             {
602                 return DEC_ERR_DECODE_FINAL;
603             }
604         }
605         else
606         {
607             tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
608                                           GATEMP_INDEX_DEC);
609             temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
610                                           GATEMP_INDEX_DEC);
611             if (temp2Var8 != tempVar8)
612             {
613                 return DEC_ERR_DECODE_FINAL;
614             }
615         }
616     }
618     return DEC_NO_ERR;
619 } //decDecodeFinalTest
621 Int decInfoSnd(
622         const PAF_ASIT_Params *pP,
623         const PAF_ASIT_Patchs *pQ,
624         PAF_ASIT_Config *pAsitCfg
627     PAF_AST_Config *pAstCfg;
628     PAF_AST_IoInp  *pInp;
629     Int as;                    /* Audio Stream Number (1, 2, etc.) */
630     Int z;                     /* input/decode/stream counter */
631     Int errno;                 /* error number */
632     Int zD, zI, zS, zX;
633     Int argIdx;
634     Int8 tempVar8;
635     char decMsgBuf[ASP_MSG_BUF_LEN];
637     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
638     pInp    = pAsitCfg->pIoInp;
639     as = pAstCfg->as;
641     // Set decode control: sample rate, emphasis
642     for (z=INPUT1; z < INPUTN; z++)
643     {
644         zD = z;
645         for (zX = DECODE1; zX < DECODEN; zX++)
646         {
647             if (pP->inputsFromDecodes[zX] == z) {
648                 zD = zX;
649                 break;
650             }
651         }
653         if (pInp[z].hIoPhy) {
654             //determine associated decoder
655             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
656                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
657                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
658                     pAstCfg->xDec[zD].decodeControl.sampleRate =
659                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
660                 }
661                 else {
662                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
663                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
664                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
665                         pAstCfg->xDec[zD].decodeControl.sampleRate);
666                     // return (ASPERR_INFO_RATECHANGE);
667                 }
668             }
670             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
671                                          GATEMP_INDEX_DEC);
672             pAstCfg->xDec[zD].decodeControl.emphasis =
673                 tempVar8 != PAF_SOURCE_PCM
674                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
675                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
676         }
677         else {
678             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
679             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
680         }
681     } /* end of for (z=INPUT1; z < INPUTN; z++) */
683     // Decode info
684     for (z=DECODE1; z < DECODEN; z++)
685     {
686         zI = pP->inputsFromDecodes[z];
687         zS = pP->streamsFromDecodes[z];
688         (void)zS; // clear compiler warning in case not used with tracing disabled
690         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
691                                      GATEMP_INDEX_DEC);
692         if (pInp[zI].hIoPhy  && tempVar8)
693         {
694             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
696             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
697                                               &pAstCfg->xInp[zI].inpBufStatus,
698                                               &pAstCfg->xInp[zI].inpBufConfig)) {
699                 TRACE_TERSE1("asitUpdateInputStatus return error errno 0x%x.", errno);
700                 return DEC_ERR_INFO_SNDMSG;
701             }
703             // debug, capture input buffer
704             //capIb(pAstCfg->xInp[zI].pInpBuf);
705             //gCapIb_cnt++;
707 #if 1
708             // (***) FL: revisit
709             // write back Inp configuration
710             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
711             // write back Dec configuration
712             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
713             Cache_wait();
714 #endif
716             // FL: send info message to slave
717             argIdx = 0; // set decIdx
718             *(Int32 *)&decMsgBuf[argIdx] = z;
719             if(AspMsgSnd(ASP_SLAVE_DEC_INFO, decMsgBuf) != ASP_MSG_NO_ERR)
720             {
721                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
722                 SW_BREAKPOINT; // temporary
723                 return -1;     // temporary
724             }
725 /*            else
726             {
727                 argIdx = 0; // get decErrno
728                 errno = *(Int32 *)&decMsgBuf[argIdx];
729             }
731             if (errno) {
732                 TRACE_TERSE1("decInfoSndMSg return error errno 0x%x.", errno);
733                 return DEC_ERR_INFO_SNDMSG;
734             }
735 */
736         }
737     } // z=DECODE1 to DECODEN
739 //////////////////////////////////////////////////////////////////////////////
740     asitPostInfoEvent();
741 //////////////////////////////////////////////////////////////////////////////
743     return ASIP_NO_ERR;
744 }  /* decInfoSnd() */
747 Int decInfoAck(
748         const PAF_ASIT_Params *pP,
749         const PAF_ASIT_Patchs *pQ,
750         PAF_ASIT_Config *pAsitCfg
753     PAF_AST_Config *pAstCfg;
754     PAF_AST_IoInp  *pInp;
755     Int as;                    /* Audio Stream Number (1, 2, etc.) */
756     Int z;                     /* input/decode/stream counter */
757     Int errno;                 /* error number */
758     Int zI, zS;
759     Int zMD;
760     Int zMS;
761     Int argIdx;
762     Int8 tempVar8;
763     Int tempVar;
764     char decMsgBuf[ASP_MSG_BUF_LEN];
766     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
767     pInp    = pAsitCfg->pIoInp;
768     as = pAstCfg->as;
769     zMD = pAstCfg->masterDec;
770     zMS = pAstCfg->masterStr;
771     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
773     // Decode info
774     for (z=DECODE1; z < DECODEN; z++)
775     {
776         zI = pP->inputsFromDecodes[z];
777         zS = pP->streamsFromDecodes[z];
778         (void)zS; // clear compiler warning in case not used with tracing disabled
780         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
781                                      GATEMP_INDEX_DEC);
782         if (pInp[zI].hIoPhy  && tempVar8)
783         {
784             // FL: acknowledge info message from slave
785             argIdx = 0; // set decIdx
786             *(Int32 *)&decMsgBuf[argIdx] = z;
787             if(AspMsgAck(ASP_MASTER_DEC_INFO_DONE,
788                          decMsgBuf) != ASP_MSG_NO_ERR)
789             {
790                 TRACE_TERSE0("decodeInfo: error in receiving DEC_INFO message ");
791                 SW_BREAKPOINT; // temporary
792                 return -1;     // temporary
793             }
794             else
795             {
796                 argIdx = 0; // get decErrno
797                 errno = *(Int32 *)&decMsgBuf[argIdx];
798             }
800 #if 1
801             // (***) FL: revisit
802             // invalidate Dec configuration
803             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
804             Cache_wait();
805 #endif
807             if (errno) {
808                 TRACE_TERSE1("decInfoAck return error errno 0x%x.", errno);
809                 return DEC_ERR_INFO_ACKMSG;
810             }
812             // increment decoded frame count
813             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
814                                        GATEMP_INDEX_DEC);
815             tempVar += 1;
816             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
817                               tempVar, GATEMP_INDEX_DEC);
818         }
819     } // z=DECODE1 to DECODEN
821     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
822     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
823                                  GATEMP_INDEX_DEC);
824     if (tempVar8)
825     {
826         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
827                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
828     }
830     // since now decoding update decode status for all enabled decoders
831     for (z=DECODE1; z < DECODEN; z++)
832     {
833         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
834                                      GATEMP_INDEX_DEC);
835         if (tempVar8)
836         {
837             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
838                                          GATEMP_INDEX_DEC);
839             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
840                                tempVar8, GATEMP_INDEX_DEC);
842             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
843                                          GATEMP_INDEX_DEC);
844             if (tempVar8 == PAF_SOURCE_SNG)
845             {
846                 tempVar8 = PAF_SOURCE_SNG;
847                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
848                                    tempVar8, GATEMP_INDEX_DEC);
849             }
850         }
851     }
853     return ASIP_NO_ERR;
857 static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
858                            PAF_ASIT_Config *pAsitCfg)
860     PAF_AST_Config *pAstCfg;
861     PAF_AST_IoInp  *pInp;
862     Int as;                     /* Audio Stream Number (1, 2, etc.) */
863     Int z;                      /* decode/stream counter */
864     Int argIdx;
865     Int cbErrno, errno;
866     char decMsgBuf[ASP_MSG_BUF_LEN];
868     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
869     pInp    = pAsitCfg->pIoInp;
870     as = pAstCfg->as;
871     (void)as; // clear compiler warning in case not used with tracing disabled
873     // Decode data
874     for (z=DECODE1; z < DECODEN; z++)
875     {
876         Int zI = pP->inputsFromDecodes[z];
877         Int zS = pP->streamsFromDecodes[z];
878         (void)zS; // clear compiler warning in case not used with tracing disabled
879         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
880         {
881             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
883             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
884                     as+zS,
885                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
886                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
888             // FL: debug, capture input buffer
889             //capIbPcm(pAstCfg->xInp[z].pInpBuf);
891             // (***) FL: revisit
892             // write back Dec configuration
893             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
894             Cache_wait();
896             // FL: send decode message to slave
897             errno  = 0;
898             argIdx = 0; // set decIdx
899             *(Int32 *)&decMsgBuf[argIdx] = z;
900             if(AspMsgSnd(ASP_SLAVE_DEC_DECODE, decMsgBuf) != ASP_MSG_NO_ERR)
901             {
902                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
903                 SW_BREAKPOINT; // temporary
904                 return -1;     // temporary
905             }
906 /*            else
907             {
908                 argIdx = 0; // get decErrno
909                 errno = *(Int32 *)&decMsgBuf[argIdx];
910                 argIdx += sizeof(Int32); // get cbErrno
911                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
912                 if (cbErrno != 0)
913                 {
914                     gCbWrtAfErrCnt++;
915                     TRACE_TERSE1("CB write error=%d", cbErrno);
916                     //SW_BREAKPOINT; // temporary
917                 }
919                 if(errno) {
920                     TRACE_TERSE1("decDecodeSnd return error errno 0x%x.", errno);
921                     return DEC_ERR_DECODE_SNDMSG;
922                 }
923             }*/
925         } // hIoPhy && decodeStatus.mode
926         else {
927             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
928         }
929     } // z=DECODE1 to DECODEN
931 //////////////////////////////////////////////////////////////////////////////
932     asitPostDecEvent();
933 //////////////////////////////////////////////////////////////////////////////
935     return ASIP_NO_ERR;
936 } /* decDecodeSnd() */
939 static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
940                            PAF_ASIT_Config *pAsitCfg)
942     PAF_AST_Config *pAstCfg;
943     PAF_AST_IoInp  *pInp;
944     Int as;                     /* Audio Stream Number (1, 2, etc.) */
945     Int z;                      /* decode/stream counter */
946     Int errno;                  /* error number */
947     Int argIdx;
948     Int cbErrno;
949     char decMsgBuf[ASP_MSG_BUF_LEN];
951     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
952     pInp    = pAsitCfg->pIoInp;
953     as = pAstCfg->as;
954     (void)as; // clear compiler warning in case not used with tracing disabled
956     // Decode data
957     for (z=DECODE1; z < DECODEN; z++)
958     {
959         Int zI = pP->inputsFromDecodes[z];
960         Int zS = pP->streamsFromDecodes[z];
961         (void)zS; // clear compiler warning in case not used with tracing disabled
962         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
963         {
964             // FL: send decode message to slave
965             errno  = 0;
966             argIdx = 0; // set decIdx
967             *(Int32 *)&decMsgBuf[argIdx] = z;
968             errno = AspMsgAck(ASP_MASTER_DEC_DECODE_DONE, decMsgBuf);
969             if(errno != ASP_MSG_NO_ERR)
970             {
971                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
972                 SW_BREAKPOINT; // temporary
973                 return -1;     // temporary
974             }
975             else
976             {
977                 argIdx = 0; // get decErrno
978                 errno = *(Int32 *)&decMsgBuf[argIdx];
979                 argIdx += sizeof(Int32); // get cbErrno
980                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
981                 if (cbErrno != 0)
982                 {
983                     gCbWrtAfErrCnt++;
984                     TRACE_TERSE1("CB write error=%d", cbErrno);
985                     //SW_BREAKPOINT; // temporary
986                 }
987             }
989             // (***) FL: revisit
990             // invalidate Dec configuration
991             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
992             Cache_wait();
994             if(errno) {
995                 TRACE_TERSE1("decDecodeAck return error errno 0x%x.", errno);
996                 return DEC_ERR_DECODE_ACKMSG;
997             }
999 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
1000             as_traceChannels(pAsitCfg, z);
1001 #endif
1002         } // hIoPhy && decodeStatus.mode
1003         else {
1004             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
1005         }
1006     } // z=DECODE1 to DECODEN
1008     return ASIP_NO_ERR;
1009 } /* decDecodeAck */
1013 /************************************************************************************
1014  * ASP message sending function. Refer to aspMsg_master.h for detailed description.
1015 ************************************************************************************/
1016 Int AspMsgSnd(UInt32 sndCmd, char *sndMsgBuf)
1018     ASP_Msg* pAspMsg;                   /* Messaging */
1019     Int status;
1021     // allocate message
1022     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
1023     if (pAspMsg == NULL) {
1024         TRACE_TERSE0("MessageQ_alloc() failure.");
1025         return (ASP_MSG_ERR_QUEUE_ALLOC);
1026     }
1028     // set the return address in the message header and fill in message payload
1029     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);
1030     pAspMsg->cmd = sndCmd;
1031     pAspMsg->procId = hAspMsgMaster->masterProcId;
1032     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
1033     pAspMsg->expectResp = TRUE;
1035     // copy the message provided by caller
1036     if(sndMsgBuf != NULL) {
1037         memcpy(pAspMsg->buf, sndMsgBuf, ASP_MSG_BUF_LEN*sizeof(char));
1038     }
1040     // send the message
1041     TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1042     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);
1043     if (status != MessageQ_S_SUCCESS) {
1044         TRACE_TERSE0("MessageQ_put() failure.");
1045         MessageQ_free((MessageQ_Msg)pAspMsg);
1046         return (ASP_MSG_ERR_QUEUE_PUT);
1047     }
1049     status = MessageQ_free((MessageQ_Msg)pAspMsg);
1050     if (status != MessageQ_S_SUCCESS) {
1051         TRACE_TERSE0("MessageQ_free() failure.");
1052         return (ASP_MSG_ERR_QUEUE_FREE);
1053     }
1055     // No error in messaging operation, even though there
1056     // may be error in returned (acknowledgement) message.
1057     return (ASP_MSG_NO_ERR);
1058 } /* AspMsgSnd */
1060 /************************************************************************************
1061  * ASP message sending function. Refer to aspMsg_master.h for detailed description.
1062 ************************************************************************************/
1063 Int AspMsgAck(UInt32 ackCmd, char *ackMsgBuf)
1065     ASP_Msg* pAspMsg;                   /* Messaging */
1066     Int status;
1068     // allocate message
1069     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
1070     if (pAspMsg == NULL) {
1071         TRACE_TERSE0("MessageQ_alloc() failure.");
1072         return (ASP_MSG_ERR_QUEUE_ALLOC);
1073     }
1075     // wait for complete message from slave
1076     status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
1077     if (status != MessageQ_S_SUCCESS) {
1078         TRACE_TERSE0("MessageQ_get() failure.");
1079         MessageQ_free((MessageQ_Msg)pAspMsg);
1080         return (ASP_MSG_ERR_QUEUE_GET);
1081     }
1083     // check if returned message is valid
1084     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
1085         (pAspMsg->cmd != ackCmd) ||
1086         (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31)))) {
1087         TRACE_TERSE3("ERROR: ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1088         MessageQ_free((MessageQ_Msg)pAspMsg);
1089         return(ASP_MSG_ERR_ACKNOWLEDGE);
1090     }
1092     hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
1093     TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1095     // get the returned message
1096     if(ackMsgBuf != NULL) {
1097         memcpy(ackMsgBuf, pAspMsg->buf, ASP_MSG_BUF_LEN*sizeof(char));
1098     }
1100     // free the message
1101     status = MessageQ_free((MessageQ_Msg)pAspMsg);
1102     if (status != MessageQ_S_SUCCESS) {
1103         TRACE_TERSE0("MessageQ_free() failure.");
1104         return (ASP_MSG_ERR_QUEUE_FREE);
1105     }
1107     // No error in messaging operation, even though there
1108     // may be error in returned (acknowledgement) message.
1109     return (ASP_MSG_NO_ERR);
1110 } /* AspMsgAck */
1113 #if 0
1114 Int asipDecodeProcessing(
1115         const PAF_ASIT_Params *pP,
1116         const PAF_ASIT_Patchs *pQ,
1117         PAF_ASIT_Config *pC,
1118         Int sourceSelect)
1120     PAF_AST_Config *pAstCfg;
1121     Int errno, retVal;                          /* error number */
1122     Int zMD;
1124     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1125     zMD = pAstCfg->masterDec;
1126     retVal = ASIP_NO_ERR;
1128     //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
1129     errno = decDecodeInfo(pP, pQ, pC);
1130     if (errno != ASIP_NO_ERR) {
1131         //gAsipInfo1_PrimaryErrCnt++;
1132         TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1133         retVal =  ASIP_ERR_DECODE_INFO;
1134     }
1135     else {
1136         // Don't start decode until major access unit is found.
1137         Int8 sourceDecode, sampleRate;
1138         sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1139                                          GATEMP_INDEX_DEC);
1140         sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1141                                          GATEMP_INDEX_DEC);
1142         if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1143                (sourceDecode == PAF_SOURCE_DXP)     ||
1144                (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1145              ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1146             /* do nothing and return - waiting for major access unit */
1147             pC->inpDec.frame++;
1148             retVal =  ASIP_NO_ERR;
1149         }
1150         else {
1151             errno = decDecodeData(pP, pQ, pC, sourceSelect);
1152             if (errno != ASIP_NO_ERR) {
1153                 //gAsipDecodeErrCnt++;
1154                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
1155                 retVal = ASIP_ERR_DECODE_DATA;
1156             }
1157             else {
1158                 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pC->inpDec.frame, pC->inpDec.block);
1159                 if (errno) {
1160                     retVal = ASIP_ERR_DECODE_FINAL;
1161                 }
1162                 else {
1163                     retVal = ASIP_NO_ERR;
1164                 }
1165             }
1166         }
1167     }
1169     return retVal;
1170 }  /* asipDecodeProcessing */
1171 #endif
1174 #if 0
1175 // -----------------------------------------------------------------------------
1176 // ASIT Processing Function - Decode Processing
1177 //
1178 //   Name:      asipDecodeProcessing
1179 //   Purpose:
1180 //   Return:    Error number in standard form (0 on success).
1181 // -----------------------------------------------------------------------------
1182 Int asipDecodeProcessing(
1183         const PAF_ASIT_Params *pP,
1184         const PAF_ASIT_Patchs *pQ,
1185         PAF_ASIT_Config *pAsitCfg,
1186         Int sourceSelect)
1188     PAF_AST_Config *pAstCfg;
1189     asipDecProc_t  *pDec;
1190     Int decError, retVal, getVal;                          /* error number */
1191     Int zMD, decDone;
1192     Int8 tempVar8;
1194     pAstCfg = pAsitCfg->pAstCfg;     // get pointer to common (shared) configuration
1195     zMD = pAstCfg->masterDec;
1196     pDec = &pAsitCfg->inpDec;
1198     retVal = ASIP_NO_ERR;
1200     // Initialization for decode processing
1201     if(!pDec->initDone) {
1202         // Initialize decoder and send message to decoder
1203         retVal = decDecodeInit(pP, pAsitCfg, pAsitCfg->pIoInp[zMD].sourceSelect);
1204         if(retVal != ASIP_NO_ERR) {
1205             decDecodeComplete(pP, pAsitCfg);
1207             return retVal;
1208         }
1210         pDec->initDone = TRUE;
1211     }
1213     // Check if source has configured to NONE
1214     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1215                                  GATEMP_INDEX_DEC);
1216     if (tempVar8 == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
1217         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1218         pAsitCfg->inpDec.state = QUIT;   // skip processing, quit decoding
1219         retVal = ASIP_ERR_DECODE_QUIT;
1220     }
1222     // Process commands (decode)
1223     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
1224     if (getVal) {
1225         retVal = ASIP_ERR_DECODE_COMMAND;
1226         if (getVal == ASPERR_QUIT) {
1227             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1229             // Don't return if ASPERR_QUIT, but skip decode processing and quit
1230             pAsitCfg->inpDec.state = QUIT;
1231         }
1232         else if (getVal == ASPERR_ABORT) {
1233             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1235             // Return here if ASPERR_ABORT
1236             return retVal;
1237         }
1238         else {
1239             /* ignore */;
1240         }
1241     }
1243     do {
1244         decDone = TRUE;
1246         switch(pAsitCfg->inpDec.state)
1247         {
1248             case INFO1:
1249                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1250                 if (decError) {
1251                     //gAsipInfo1_PrimaryErrCnt++;
1252                     TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
1253                     retVal = ASIP_ERR_DECODE_INFO1;
1254                 }
1255                 else {
1256                     // Don't start decode until major access unit is found.
1257                     Int8 sourceDecode, sampleRate;
1259                     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1260                                                      GATEMP_INDEX_DEC);
1261                     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1262                                                      GATEMP_INDEX_DEC);
1263                     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1264                            (sourceDecode == PAF_SOURCE_DXP)     ||
1265                            (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1266                          ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1267                         //gMajorAuMissed++; // debug
1268                         pAsitCfg->inpDec.frame++;
1269                         //pAsitCfg->inpDec.state = INFO1;    // stay in this state
1270                     }
1271                     else {
1272                         decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1273                         if(decError) {
1274                             retVal = ASIP_ERR_DECODE_INFO1;
1275                         }
1276                         else {
1277                             pAsitCfg->inpDec.state = DECODE;
1278                             decDone = FALSE;    // go to DECODE state before return
1279                         }
1280                     }
1281                 }
1282                 break;
1284             case INFO2:
1285                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1286                 if (decError) {
1287                     //gAsipInfo1_PrimaryErrCnt++;
1288                     TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
1289                     retVal = ASIP_ERR_DECODE_INFO2;
1290                 }
1291                 else {
1292                     pAsitCfg->inpDec.state = DECODE;
1293                     decDone = FALSE;     // go to DECODE state before return
1294                 }
1295                 break;
1297             case DECODE:
1298                 decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
1299                 if (decError) {
1300                     //gAsipDecodeErrCnt++;
1301                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
1302                     retVal = ASIP_ERR_DECODE_DATA;
1303                 }
1304                 else {
1305                     decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1306                     if (decError) {
1307                         retVal = ASIP_ERR_DECODE_FINAL;
1308                     }
1309                     else {
1310                         pAsitCfg->inpDec.frame++;
1311                         pAsitCfg->inpDec.state = INFO2;
1312                     }
1313                 }
1314                 break;
1316             case QUIT:
1317                 //gAsipQuitCnt++;
1318                 Log_info0("TaskAsip: state=QUIT");
1320                 // Quit:
1321                 // - Set error number registers.
1322                 // - Exit state machine to "decode complete" processing.
1323                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
1324                 break;
1326             default:
1327                 break;
1329         }  /* switch */
1331     } while (!decDone);
1333     if(retVal != ASIP_NO_ERR) {
1334         decDecodeComplete(pP, pAsitCfg);
1335     }
1337     return retVal;
1338 }  /* asipDecodeProcessing */
1340 #endif
1343 /* Nothing past this line */