cc48d809c1e8f7b61042b22f8e5ee4d5da1a98e7
[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             // 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             // 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             // invalidate Dec configuration
448             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
449             Cache_wait();
451             if (errno != 0) {
452                 return ASIP_ERR_DECODE_MSG;
453             }
455             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
456                                           GATEMP_INDEX_DEC);
457             tempVar8 = gear < GEARS ? gear : 0;
458             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
459                                tempVar8, GATEMP_INDEX_DEC);
461             // Compute decoder frame length based on source selection
462             // JXU: what does this function do? why does it only return PCM frame length?
463             /*frameLength = getFrameLengthSourceSel(pP, sourceSelect);
465             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
466             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
467             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;*/
469 /*
470             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
471                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
472                     return errno;
473                 }
474             }
475 */
476 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
477             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
478             ioDataCtl.param.frameLengthPcm = frameLength;
479             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
480 */
481             //JXTODO: do we need to update input status here again?
482             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
483                                               &pAstCfg->xInp[zI].inpBufStatus,
484                                               &pAstCfg->xInp[zI].inpBufConfig)) {
485                 return ASIP_ERR_INPUT_CFG;
486             }
487         } /* end of if(hIoPhy && decodeStatus.mode) */
488     } /* end of for (z=DECODE1; z < DECODEN; z++) */
490     pAsitCfg->inpDec.frame = 0;
491     pAsitCfg->inpDec.block = 0;
492     pAsitCfg->inpDec.state = DEC_STATE_INFO_SND;
494     return ASIP_NO_ERR;
495 }  /* decDecodeInit */
499 Int decDecodeComplete( const PAF_ASIT_Params *pP,
500                        PAF_ASIT_Config *pAsitCfg)
502     PAF_AST_Config *pAstCfg;
503     Int as;                     /* Audio Stream Number (1, 2, etc.) */
504     Int z;                      /* decode/encode counter */
505     Int argIdx;
506     Int8 tempVar8;
507     char decMsgBuf[ASP_MSG_BUF_LEN];
509     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
510     as = pAstCfg->as;
511     (void)as;  // clear compiler warning in case not used with tracing disabled
513     for (z=DECODE1; z < DECODEN; z++)
514     {
515         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
516                                      GATEMP_INDEX_DEC);
517         if (pAsitCfg->pIoInp[z].hIoPhy && tempVar8)
518         {
519             TRACE_VERBOSE1("decDecodeComplete: AS%d: finalizing decode", as+z);
521             // FL: send dec deactivate message to slave
522             argIdx = 0; // set decIdx
523             *(Int32 *)&decMsgBuf[argIdx] = z;
524             if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
525                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
526             {
527                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
528                 SW_BREAKPOINT;
529                 return DEC_ERR_COMPLETE_MSG;
530             }
531         }
532         else
533         {
534             TRACE_VERBOSE1("decDecodeComplete: AS%d: processing decode <ignored>", as+z);
535         }
536     }
538     return DEC_NO_ERR;
539 }  /* decDecodeComplete */
542 // -----------------------------------------------------------------------------
543 // Decoding Function - Frame-Final Processing
544 //
545 //   Name:      decDecodeFinalTest
546 //   Purpose:   Decoding Function for determining whether processing of the
547 //              current frame is complete.
548 //   From:      AST Parameter Function -> decodeProcessing
549 //   Uses:      See code.
550 //   States:    x
551 //   Return:    0 if incomplete, and 1 if complete.
552 //   Trace:     None.
553 //
555 Int
556 decDecodeFinalTest(
557     const PAF_ASIT_Params *pP,
558     const PAF_ASIT_Patchs *pQ,
559     PAF_ASIT_Config *pAsitCfg
562     PAF_AST_Config *pAstCfg;
563     Int zMD;
564     Int sourceSelect;
565     Int sourceProgram;
566     Int8 tempVar8, temp2Var8;
568     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
569     zMD = pAstCfg->masterDec;
571     sourceSelect  = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
572                                            GATEMP_INDEX_DEC);
573     sourceProgram = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
574                                            GATEMP_INDEX_DEC);
576     if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
577     {
578         return DEC_ERR_DECODE_FINAL;
579     }
581     // The following allows for Force modes to switch without command deferral. This might
582     // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
583     if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
584     {
585         if (sourceSelect == PAF_SOURCE_DTSALL)
586         {
587             if (sourceProgram != PAF_SOURCE_DTS11 &&
588                 sourceProgram != PAF_SOURCE_DTS12 &&
589                 sourceProgram != PAF_SOURCE_DTS13 &&
590                 sourceProgram != PAF_SOURCE_DTS14 &&
591                 sourceProgram != PAF_SOURCE_DTS16 &&
592                 sourceProgram != PAF_SOURCE_DTSHD)
593             {
594                 return DEC_ERR_DECODE_FINAL;
595             }
596         }
597         else if (sourceSelect == PAF_SOURCE_PCMAUTO)
598         {
599             if (sourceProgram != PAF_SOURCE_PCM)
600             {
601                 return DEC_ERR_DECODE_FINAL;
602             }
603         }
604         else
605         {
606             tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
607                                           GATEMP_INDEX_DEC);
608             temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
609                                           GATEMP_INDEX_DEC);
610             if (temp2Var8 != tempVar8)
611             {
612                 return DEC_ERR_DECODE_FINAL;
613             }
614         }
615     }
617     return DEC_NO_ERR;
618 } //decDecodeFinalTest
620 Int decInfoSnd(
621         const PAF_ASIT_Params *pP,
622         const PAF_ASIT_Patchs *pQ,
623         PAF_ASIT_Config *pAsitCfg
626     PAF_AST_Config *pAstCfg;
627     PAF_AST_IoInp  *pInp;
628     Int as;                    /* Audio Stream Number (1, 2, etc.) */
629     Int z;                     /* input/decode/stream counter */
630     Int errno;                 /* error number */
631     Int zD, zI, zS, zX;
632     Int argIdx;
633     Int8 tempVar8;
634     char decMsgBuf[ASP_MSG_BUF_LEN];
636     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
637     pInp    = pAsitCfg->pIoInp;
638     as = pAstCfg->as;
640     // Set decode control: sample rate, emphasis
641     for (z=INPUT1; z < INPUTN; z++)
642     {
643         zD = z;
644         for (zX = DECODE1; zX < DECODEN; zX++)
645         {
646             if (pP->inputsFromDecodes[zX] == z) {
647                 zD = zX;
648                 break;
649             }
650         }
652         if (pInp[z].hIoPhy) {
653             //determine associated decoder
654             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
655                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
656                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
657                     pAstCfg->xDec[zD].decodeControl.sampleRate =
658                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
659                 }
660                 else {
661                     //TRACE_TERSE1("decDecodeInfo: AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
662                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
663                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
664                         pAstCfg->xDec[zD].decodeControl.sampleRate);
665                     // return (ASPERR_INFO_RATECHANGE);
666                 }
667             }
669             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
670                                          GATEMP_INDEX_DEC);
671             pAstCfg->xDec[zD].decodeControl.emphasis =
672                 tempVar8 != PAF_SOURCE_PCM
673                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
674                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
675         }
676         else {
677             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
678             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
679         }
680     } /* end of for (z=INPUT1; z < INPUTN; z++) */
682     // Decode info
683     for (z=DECODE1; z < DECODEN; z++)
684     {
685         zI = pP->inputsFromDecodes[z];
686         zS = pP->streamsFromDecodes[z];
687         (void)zS; // clear compiler warning in case not used with tracing disabled
689         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
690                                      GATEMP_INDEX_DEC);
691         if (pInp[zI].hIoPhy  && tempVar8)
692         {
693             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
695             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
696                                               &pAstCfg->xInp[zI].inpBufStatus,
697                                               &pAstCfg->xInp[zI].inpBufConfig)) {
698                 TRACE_TERSE1("asitUpdateInputStatus return error errno 0x%x.", errno);
699                 return DEC_ERR_INFO_SNDMSG;
700             }
702 #if 0 // debug
703             // capture input buffer
704             capIb(pAstCfg->xInp[zI].pInpBuf);
705             gCapIb_cnt++;
706 #endif
708             // write back Inp configuration
709             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
710             // write back Dec configuration
711             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
712             Cache_wait();
714             // send info message to slave
715             argIdx = 0; // set decIdx
716             *(Int32 *)&decMsgBuf[argIdx] = z;
717             if(AspMsgSnd(ASP_SLAVE_DEC_INFO, decMsgBuf) != ASP_MSG_NO_ERR)
718             {
719                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
720                 SW_BREAKPOINT; // temporary
721                 return -1;     // temporary
722             }
723 /*            else
724             {
725                 argIdx = 0; // get decErrno
726                 errno = *(Int32 *)&decMsgBuf[argIdx];
727             }
729             if (errno) {
730                 TRACE_TERSE1("decInfoSndMSg return error errno 0x%x.", errno);
731                 return DEC_ERR_INFO_SNDMSG;
732             }
733 */
734         }
735     } // z=DECODE1 to DECODEN
737 //////////////////////////////////////////////////////////////////////////////
738     asitPostInfoEvent();
739 //////////////////////////////////////////////////////////////////////////////
741     return ASIP_NO_ERR;
742 }  /* decInfoSnd() */
745 Int decInfoAck(
746         const PAF_ASIT_Params *pP,
747         const PAF_ASIT_Patchs *pQ,
748         PAF_ASIT_Config *pAsitCfg
751     PAF_AST_Config *pAstCfg;
752     PAF_AST_IoInp  *pInp;
753     Int as;                    /* Audio Stream Number (1, 2, etc.) */
754     Int z;                     /* input/decode/stream counter */
755     Int errno;                 /* error number */
756     Int zI, zS;
757     Int zMD;
758     Int zMS;
759     Int argIdx;
760     Int8 tempVar8;
761     Int tempVar;
762     char decMsgBuf[ASP_MSG_BUF_LEN];
764     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
765     pInp    = pAsitCfg->pIoInp;
766     as = pAstCfg->as;
767     zMD = pAstCfg->masterDec;
768     zMS = pAstCfg->masterStr;
769     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
771     // Decode info
772     for (z=DECODE1; z < DECODEN; z++)
773     {
774         zI = pP->inputsFromDecodes[z];
775         zS = pP->streamsFromDecodes[z];
776         (void)zS; // clear compiler warning in case not used with tracing disabled
778         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
779                                      GATEMP_INDEX_DEC);
780         if (pInp[zI].hIoPhy  && tempVar8)
781         {
782             // FL: acknowledge info message from slave
783             argIdx = 0; // set decIdx
784             *(Int32 *)&decMsgBuf[argIdx] = z;
785             if(AspMsgAck(ASP_MASTER_DEC_INFO_DONE,
786                          decMsgBuf) != ASP_MSG_NO_ERR)
787             {
788                 TRACE_TERSE0("decodeInfo: error in receiving DEC_INFO message ");
789                 SW_BREAKPOINT; // temporary
790                 return -1;     // temporary
791             }
792             else
793             {
794                 argIdx = 0; // get decErrno
795                 errno = *(Int32 *)&decMsgBuf[argIdx];
796             }
798             // invalidate Dec configuration
799             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
800             Cache_wait();
802             if (errno) {
803                 TRACE_TERSE1("decInfoAck return error errno 0x%x.", errno);
804                 return DEC_ERR_INFO_ACKMSG;
805             }
807             // increment decoded frame count
808             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
809                                        GATEMP_INDEX_DEC);
810             tempVar += 1;
811             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
812                               tempVar, GATEMP_INDEX_DEC);
813         }
814     } // z=DECODE1 to DECODEN
816     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
817     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
818                                  GATEMP_INDEX_DEC);
819     if (tempVar8)
820     {
821         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
822                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
823     }
825     // since now decoding update decode status for all enabled decoders
826     for (z=DECODE1; z < DECODEN; z++)
827     {
828         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
829                                      GATEMP_INDEX_DEC);
830         if (tempVar8)
831         {
832             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
833                                          GATEMP_INDEX_DEC);
834             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
835                                tempVar8, GATEMP_INDEX_DEC);
837             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
838                                          GATEMP_INDEX_DEC);
839             if (tempVar8 == PAF_SOURCE_SNG)
840             {
841                 tempVar8 = PAF_SOURCE_SNG;
842                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
843                                    tempVar8, GATEMP_INDEX_DEC);
844             }
845         }
846     }
848     return ASIP_NO_ERR;
852 static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
853                            PAF_ASIT_Config *pAsitCfg)
855     PAF_AST_Config *pAstCfg;
856     PAF_AST_IoInp  *pInp;
857     Int as;                     /* Audio Stream Number (1, 2, etc.) */
858     Int z;                      /* decode/stream counter */
859     Int argIdx;
860     Int cbErrno, errno;
861     char decMsgBuf[ASP_MSG_BUF_LEN];
863     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
864     pInp    = pAsitCfg->pIoInp;
865     as = pAstCfg->as;
866     (void)as; // clear compiler warning in case not used with tracing disabled
868     // Decode data
869     for (z=DECODE1; z < DECODEN; z++)
870     {
871         Int zI = pP->inputsFromDecodes[z];
872         Int zS = pP->streamsFromDecodes[z];
873         (void)zS; // clear compiler warning in case not used with tracing disabled
874         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
875         {
876             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
878             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
879                     as+zS,
880                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
881                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
883 #if 0 // debug
884             // capture input buffer
885             capIbPcm(pAstCfg->xInp[z].pInpBuf);
886 #endif
887             
888             // write back Dec configuration
889             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
890             Cache_wait();
892             // send decode message to slave
893             errno  = 0;
894             argIdx = 0; // set decIdx
895             *(Int32 *)&decMsgBuf[argIdx] = z;
896             if(AspMsgSnd(ASP_SLAVE_DEC_DECODE, decMsgBuf) != ASP_MSG_NO_ERR)
897             {
898                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
899                 SW_BREAKPOINT; // temporary
900                 return -1;     // temporary
901             }
902 /*            else
903             {
904                 argIdx = 0; // get decErrno
905                 errno = *(Int32 *)&decMsgBuf[argIdx];
906                 argIdx += sizeof(Int32); // get cbErrno
907                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
908                 if (cbErrno != 0)
909                 {
910                     gCbWrtAfErrCnt++;
911                     TRACE_TERSE1("CB write error=%d", cbErrno);
912                     //SW_BREAKPOINT; // temporary
913                 }
915                 if(errno) {
916                     TRACE_TERSE1("decDecodeSnd return error errno 0x%x.", errno);
917                     return DEC_ERR_DECODE_SNDMSG;
918                 }
919             }*/
921         } // hIoPhy && decodeStatus.mode
922         else {
923             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
924         }
925     } // z=DECODE1 to DECODEN
927 //////////////////////////////////////////////////////////////////////////////
928     asitPostDecEvent();
929 //////////////////////////////////////////////////////////////////////////////
931     return ASIP_NO_ERR;
932 } /* decDecodeSnd() */
935 static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
936                            PAF_ASIT_Config *pAsitCfg)
938     PAF_AST_Config *pAstCfg;
939     PAF_AST_IoInp  *pInp;
940     Int as;                     /* Audio Stream Number (1, 2, etc.) */
941     Int z;                      /* decode/stream counter */
942     Int errno;                  /* error number */
943     Int argIdx;
944     Int cbErrno;
945     char decMsgBuf[ASP_MSG_BUF_LEN];
947     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
948     pInp    = pAsitCfg->pIoInp;
949     as = pAstCfg->as;
950     (void)as; // clear compiler warning in case not used with tracing disabled
952     // Decode data
953     for (z=DECODE1; z < DECODEN; z++)
954     {
955         Int zI = pP->inputsFromDecodes[z];
956         Int zS = pP->streamsFromDecodes[z];
957         (void)zS; // clear compiler warning in case not used with tracing disabled
958         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
959         {
960             // FL: send decode message to slave
961             errno  = 0;
962             argIdx = 0; // set decIdx
963             *(Int32 *)&decMsgBuf[argIdx] = z;
964             errno = AspMsgAck(ASP_MASTER_DEC_DECODE_DONE, decMsgBuf);
965             if(errno != ASP_MSG_NO_ERR)
966             {
967                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
968                 SW_BREAKPOINT; // temporary
969                 return -1;     // temporary
970             }
971             else
972             {
973                 argIdx = 0; // get decErrno
974                 errno = *(Int32 *)&decMsgBuf[argIdx];
975                 argIdx += sizeof(Int32); // get cbErrno
976                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
977                 if (cbErrno != 0)
978                 {
979                     gCbWrtAfErrCnt++;
980                     TRACE_TERSE1("CB write error=%d", cbErrno);
981                     //SW_BREAKPOINT; // temporary
982                 }
983             }
985             // invalidate Dec configuration
986             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
987             Cache_wait();
989             if(errno) {
990                 TRACE_TERSE1("decDecodeAck return error errno 0x%x.", errno);
991                 return DEC_ERR_DECODE_ACKMSG;
992             }
994 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
995             as_traceChannels(pAsitCfg, z);
996 #endif
997         } // hIoPhy && decodeStatus.mode
998         else {
999             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
1000         }
1001     } // z=DECODE1 to DECODEN
1003     return ASIP_NO_ERR;
1004 } /* decDecodeAck */
1008 /************************************************************************************
1009  * ASP message sending function. Refer to aspMsg_master.h for detailed description.
1010 ************************************************************************************/
1011 Int AspMsgSnd(UInt32 sndCmd, char *sndMsgBuf)
1013     ASP_Msg* pAspMsg;                   /* Messaging */
1014     Int status;
1016     // allocate message
1017     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
1018     if (pAspMsg == NULL) {
1019         TRACE_TERSE0("MessageQ_alloc() failure.");
1020         return (ASP_MSG_ERR_QUEUE_ALLOC);
1021     }
1023     // set the return address in the message header and fill in message payload
1024     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);
1025     pAspMsg->cmd = sndCmd;
1026     pAspMsg->procId = hAspMsgMaster->masterProcId;
1027     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
1028     pAspMsg->expectResp = TRUE;
1030     // copy the message provided by caller
1031     if(sndMsgBuf != NULL) {
1032         memcpy(pAspMsg->buf, sndMsgBuf, ASP_MSG_BUF_LEN*sizeof(char));
1033     }
1035     // send the message
1036     TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1037     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);
1038     if (status != MessageQ_S_SUCCESS) {
1039         TRACE_TERSE0("MessageQ_put() failure.");
1040         MessageQ_free((MessageQ_Msg)pAspMsg);
1041         return (ASP_MSG_ERR_QUEUE_PUT);
1042     }
1044     status = MessageQ_free((MessageQ_Msg)pAspMsg);
1045     if (status != MessageQ_S_SUCCESS) {
1046         TRACE_TERSE0("MessageQ_free() failure.");
1047         return (ASP_MSG_ERR_QUEUE_FREE);
1048     }
1050     // No error in messaging operation, even though there
1051     // may be error in returned (acknowledgement) message.
1052     return (ASP_MSG_NO_ERR);
1053 } /* AspMsgSnd */
1055 /************************************************************************************
1056  * ASP message sending function. Refer to aspMsg_master.h for detailed description.
1057 ************************************************************************************/
1058 Int AspMsgAck(UInt32 ackCmd, char *ackMsgBuf)
1060     ASP_Msg* pAspMsg;                   /* Messaging */
1061     Int status;
1063     // allocate message
1064     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
1065     if (pAspMsg == NULL) {
1066         TRACE_TERSE0("MessageQ_alloc() failure.");
1067         return (ASP_MSG_ERR_QUEUE_ALLOC);
1068     }
1070     // wait for complete message from slave
1071     status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
1072     if (status != MessageQ_S_SUCCESS) {
1073         TRACE_TERSE0("MessageQ_get() failure.");
1074         MessageQ_free((MessageQ_Msg)pAspMsg);
1075         return (ASP_MSG_ERR_QUEUE_GET);
1076     }
1078     // check if returned message is valid
1079     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
1080         (pAspMsg->cmd != ackCmd) ||
1081         (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31)))) {
1082         TRACE_TERSE3("ERROR: ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1083         MessageQ_free((MessageQ_Msg)pAspMsg);
1084         return(ASP_MSG_ERR_ACKNOWLEDGE);
1085     }
1087     hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
1088     TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1090     // get the returned message
1091     if(ackMsgBuf != NULL) {
1092         memcpy(ackMsgBuf, pAspMsg->buf, ASP_MSG_BUF_LEN*sizeof(char));
1093     }
1095     // free the message
1096     status = MessageQ_free((MessageQ_Msg)pAspMsg);
1097     if (status != MessageQ_S_SUCCESS) {
1098         TRACE_TERSE0("MessageQ_free() failure.");
1099         return (ASP_MSG_ERR_QUEUE_FREE);
1100     }
1102     // No error in messaging operation, even though there
1103     // may be error in returned (acknowledgement) message.
1104     return (ASP_MSG_NO_ERR);
1105 } /* AspMsgAck */
1108 #if 0
1109 Int asipDecodeProcessing(
1110         const PAF_ASIT_Params *pP,
1111         const PAF_ASIT_Patchs *pQ,
1112         PAF_ASIT_Config *pC,
1113         Int sourceSelect)
1115     PAF_AST_Config *pAstCfg;
1116     Int errno, retVal;                          /* error number */
1117     Int zMD;
1119     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1120     zMD = pAstCfg->masterDec;
1121     retVal = ASIP_NO_ERR;
1123     //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
1124     errno = decDecodeInfo(pP, pQ, pC);
1125     if (errno != ASIP_NO_ERR) {
1126         //gAsipInfo1_PrimaryErrCnt++;
1127         TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1128         retVal =  ASIP_ERR_DECODE_INFO;
1129     }
1130     else {
1131         // Don't start decode until major access unit is found.
1132         Int8 sourceDecode, sampleRate;
1133         sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1134                                          GATEMP_INDEX_DEC);
1135         sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1136                                          GATEMP_INDEX_DEC);
1137         if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1138                (sourceDecode == PAF_SOURCE_DXP)     ||
1139                (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1140              ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1141             /* do nothing and return - waiting for major access unit */
1142             pC->inpDec.frame++;
1143             retVal =  ASIP_NO_ERR;
1144         }
1145         else {
1146             errno = decDecodeData(pP, pQ, pC, sourceSelect);
1147             if (errno != ASIP_NO_ERR) {
1148                 //gAsipDecodeErrCnt++;
1149                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
1150                 retVal = ASIP_ERR_DECODE_DATA;
1151             }
1152             else {
1153                 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pC->inpDec.frame, pC->inpDec.block);
1154                 if (errno) {
1155                     retVal = ASIP_ERR_DECODE_FINAL;
1156                 }
1157                 else {
1158                     retVal = ASIP_NO_ERR;
1159                 }
1160             }
1161         }
1162     }
1164     return retVal;
1165 }  /* asipDecodeProcessing */
1166 #endif
1169 #if 0
1170 // -----------------------------------------------------------------------------
1171 // ASIT Processing Function - Decode Processing
1172 //
1173 //   Name:      asipDecodeProcessing
1174 //   Purpose:
1175 //   Return:    Error number in standard form (0 on success).
1176 // -----------------------------------------------------------------------------
1177 Int asipDecodeProcessing(
1178         const PAF_ASIT_Params *pP,
1179         const PAF_ASIT_Patchs *pQ,
1180         PAF_ASIT_Config *pAsitCfg,
1181         Int sourceSelect)
1183     PAF_AST_Config *pAstCfg;
1184     asipDecProc_t  *pDec;
1185     Int decError, retVal, getVal;                          /* error number */
1186     Int zMD, decDone;
1187     Int8 tempVar8;
1189     pAstCfg = pAsitCfg->pAstCfg;     // get pointer to common (shared) configuration
1190     zMD = pAstCfg->masterDec;
1191     pDec = &pAsitCfg->inpDec;
1193     retVal = ASIP_NO_ERR;
1195     // Initialization for decode processing
1196     if(!pDec->initDone) {
1197         // Initialize decoder and send message to decoder
1198         retVal = decDecodeInit(pP, pAsitCfg, pAsitCfg->pIoInp[zMD].sourceSelect);
1199         if(retVal != ASIP_NO_ERR) {
1200             decDecodeComplete(pP, pAsitCfg);
1202             return retVal;
1203         }
1205         pDec->initDone = TRUE;
1206     }
1208     // Check if source has configured to NONE
1209     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1210                                  GATEMP_INDEX_DEC);
1211     if (tempVar8 == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
1212         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1213         pAsitCfg->inpDec.state = QUIT;   // skip processing, quit decoding
1214         retVal = ASIP_ERR_DECODE_QUIT;
1215     }
1217     // Process commands (decode)
1218     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
1219     if (getVal) {
1220         retVal = ASIP_ERR_DECODE_COMMAND;
1221         if (getVal == ASPERR_QUIT) {
1222             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1224             // Don't return if ASPERR_QUIT, but skip decode processing and quit
1225             pAsitCfg->inpDec.state = QUIT;
1226         }
1227         else if (getVal == ASPERR_ABORT) {
1228             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1230             // Return here if ASPERR_ABORT
1231             return retVal;
1232         }
1233         else {
1234             /* ignore */;
1235         }
1236     }
1238     do {
1239         decDone = TRUE;
1241         switch(pAsitCfg->inpDec.state)
1242         {
1243             case INFO1:
1244                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1245                 if (decError) {
1246                     //gAsipInfo1_PrimaryErrCnt++;
1247                     TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
1248                     retVal = ASIP_ERR_DECODE_INFO1;
1249                 }
1250                 else {
1251                     // Don't start decode until major access unit is found.
1252                     Int8 sourceDecode, sampleRate;
1254                     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1255                                                      GATEMP_INDEX_DEC);
1256                     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1257                                                      GATEMP_INDEX_DEC);
1258                     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1259                            (sourceDecode == PAF_SOURCE_DXP)     ||
1260                            (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1261                          ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1262                         //gMajorAuMissed++; // debug
1263                         pAsitCfg->inpDec.frame++;
1264                         //pAsitCfg->inpDec.state = INFO1;    // stay in this state
1265                     }
1266                     else {
1267                         decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1268                         if(decError) {
1269                             retVal = ASIP_ERR_DECODE_INFO1;
1270                         }
1271                         else {
1272                             pAsitCfg->inpDec.state = DECODE;
1273                             decDone = FALSE;    // go to DECODE state before return
1274                         }
1275                     }
1276                 }
1277                 break;
1279             case INFO2:
1280                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1281                 if (decError) {
1282                     //gAsipInfo1_PrimaryErrCnt++;
1283                     TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
1284                     retVal = ASIP_ERR_DECODE_INFO2;
1285                 }
1286                 else {
1287                     pAsitCfg->inpDec.state = DECODE;
1288                     decDone = FALSE;     // go to DECODE state before return
1289                 }
1290                 break;
1292             case DECODE:
1293                 decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
1294                 if (decError) {
1295                     //gAsipDecodeErrCnt++;
1296                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
1297                     retVal = ASIP_ERR_DECODE_DATA;
1298                 }
1299                 else {
1300                     decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1301                     if (decError) {
1302                         retVal = ASIP_ERR_DECODE_FINAL;
1303                     }
1304                     else {
1305                         pAsitCfg->inpDec.frame++;
1306                         pAsitCfg->inpDec.state = INFO2;
1307                     }
1308                 }
1309                 break;
1311             case QUIT:
1312                 //gAsipQuitCnt++;
1313                 Log_info0("TaskAsip: state=QUIT");
1315                 // Quit:
1316                 // - Set error number registers.
1317                 // - Exit state machine to "decode complete" processing.
1318                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
1319                 break;
1321             default:
1322                 break;
1324         }  /* switch */
1326     } while (!decDone);
1328     if(retVal != ASIP_NO_ERR) {
1329         decDecodeComplete(pP, pAsitCfg);
1330     }
1332     return retVal;
1333 }  /* asipDecodeProcessing */
1335 #endif
1338 /* Nothing past this line */