bb0813c249a7bc8d02f33fd422c1b55440b8e9a6
[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"
55 enum {
56     INFO1,
57     INFO2,
58     DECODE,
59     QUIT
60 };
62 static Int decDecodeInit(const PAF_ASIT_Params *pP, PAF_ASIT_Config *pAsitCfg,
63                          Int sourceSelect);
64 static Int decDecodeInfo(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
65                          PAF_ASIT_Config *pAsitCfg);
66 static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
67                          PAF_ASIT_Config *pAsitCfg, Int sourceSelect);
68 static Int decDecodeComplete(const PAF_ASIT_Params *pP,
69                              PAF_ASIT_Config *pAsitCfg);
71 extern Int getFrameLengthSourceSel(const PAF_ASIT_Params *pP, Int8 sourceSelect);
73 extern UInt32 gCbWrtAfErrCnt;
77 Int asipDecodeInit(
78         const PAF_ASIT_Params *pP,
79         PAF_ASIT_Config *pAsitCfg,
80         Int sourceSelect)
81 {
82     Int errno;
84     errno = decDecodeInit(pP, pAsitCfg, sourceSelect);
86     if(errno) {
87         decDecodeComplete(pP, pAsitCfg);
89         return ASIP_ERR_DECODE_INIT;
90     }
92     return ASIP_NO_ERR;
93 }
96 // -----------------------------------------------------------------------------
97 // ASIT Processing Function - Decode Processing
98 //
99 //   Name:      asipDecodeProcessing
100 //   Purpose:
101 //   Return:    Error number in standard form (0 on success).
102 // -----------------------------------------------------------------------------
103 Int asipDecodeProcessing(
104         const PAF_ASIT_Params *pP,
105         const PAF_ASIT_Patchs *pQ,
106         PAF_ASIT_Config *pAsitCfg,
107         Int sourceSelect)
109     PAF_AST_Config *pAstCfg;
110     asipDecProc_t  *pDec;
111     Int decError, retVal, getVal;                          /* error number */
112     Int zMD, decProcDone;
113     Int8 tempVar8;
115     pAstCfg = pAsitCfg->pAstCfg;     // get pointer to common (shared) configuration
116     zMD = pAstCfg->masterDec;
117     pDec = &pAsitCfg->inpDec;
119     retVal = ASIP_NO_ERR;
121     // Initialization for decode processing
122     if(!pDec->initDone) {
123         // Initialize decoder and send message to decoder
124         retVal = decDecodeInit(pP, pAsitCfg, pAsitCfg->pIoInp[zMD].sourceSelect);
125         if(retVal != ASIP_NO_ERR) {
126             decDecodeComplete(pP, pAsitCfg);
128             return retVal;
129         }
131         pDec->initDone = TRUE;
132     }
134     // Check if source has configured to NONE
135     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
136                                  GATEMP_INDEX_DEC);
137     if (tempVar8 == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
138         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
139         pAsitCfg->inpDec.state = QUIT;   // skip processing, quit decoding
140         retVal = ASIP_ERR_DECODE_QUIT;
141     }
143     // Process commands (decode)
144     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
145     if (getVal) {
146         retVal = ASIP_ERR_DECODE_COMMAND;
147         if (getVal == ASPERR_QUIT) {
148             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
150             // Don't return if ASPERR_QUIT, but skip decode processing and quit
151             pAsitCfg->inpDec.state = QUIT;
152         }
153         else if (getVal == ASPERR_ABORT) {
154             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
156             // Return here if ASPERR_ABORT
157             return retVal;
158         }
159         else {
160             /* ignore */;
161         }
162     }
164     do {
165         decProcDone = TRUE;
167         switch(pAsitCfg->inpDec.state)
168         {
169             case INFO1:
170                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
171                 if (decError) {
172                     //gAsipInfo1_PrimaryErrCnt++;
173                     TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
174                     retVal = ASIP_ERR_DECODE_INFO1;
175                 }
176                 else {
177                     // Don't start decode until major access unit is found.
178                     Int8 sourceDecode, sampleRate;
180                     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
181                                                      GATEMP_INDEX_DEC);
182                     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
183                                                      GATEMP_INDEX_DEC);
184                     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
185                            (sourceDecode == PAF_SOURCE_DXP)     ||
186                            (sourceDecode == PAF_SOURCE_DTSHD) ) &&
187                          ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
188                         //gMajorAuMissed++; // debug
189                         pAsitCfg->inpDec.frame++;
190                         //pAsitCfg->inpDec.state = INFO1;    // stay in this state
191                     }
192                     else {
193                         decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
194                         if(decError) {
195                             retVal = ASIP_ERR_DECODE_INFO1;
196                         }
197                         else {
198                             pAsitCfg->inpDec.state = DECODE;
199                             decProcDone = FALSE;    // go to DECODE state before return
200                         }
201                     }
202                 }
203                 break;
205             case INFO2:
206                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
207                 if (decError) {
208                     //gAsipInfo1_PrimaryErrCnt++;
209                     TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
210                     retVal = ASIP_ERR_DECODE_INFO2;
211                 }
212                 else {
213                     pAsitCfg->inpDec.state = DECODE;
214                     decProcDone = FALSE;     // go to DECODE state before return
215                 }
216                 break;
218             case DECODE:
219                 decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
220                 if (decError) {
221                     //gAsipDecodeErrCnt++;
222                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
223                     retVal = ASIP_ERR_DECODE_DATA;
224                 }
225                 else {
226                     decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
227                     if (decError) {
228                         retVal = ASIP_ERR_DECODE_FINAL;
229                     }
230                     else {
231                         pAsitCfg->inpDec.frame++;
232                         pAsitCfg->inpDec.state = INFO2;
233                     }
234                 }
235                 break;
237             case QUIT:
238                 //gAsipQuitCnt++;
239                 Log_info0("TaskAsip: state=QUIT");
241                 // Quit:
242                 // - Set error number registers.
243                 // - Exit state machine to "decode complete" processing.
244                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
245                 break;
247             default:
248                 break;
250         }  /* switch */
252     } while (!decProcDone);
254     if(retVal != ASIP_NO_ERR) {
255         decDecodeComplete(pP, pAsitCfg);
256     }
258     return retVal;
259 }  /* asipDecodeProcessing */
262 // -----------------------------------------------------------------------------
263 // ASIT Decoding Function - Reinitialization of Decode
264 //
265 //   Name:      decDecodeInit
266 //   Purpose:   Decoding Function for reinitializing the decoding process.
267 //   From:      AST Parameter Function -> decodeProcessing
268 //   Uses:      See code.
269 //   States:    x
270 //   Return:    Error number in standard or SIO form (0 on success).
271 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
272 //              * State information as per parent.
273 //
274 // -----------------------------------------------------------------------------
275 static Int decDecodeInit(
276         const PAF_ASIT_Params *pP,
277         PAF_ASIT_Config *pAsitCfg,
278         Int sourceSelect)
280     PAF_AST_Config *pAstCfg;
281     PAF_AST_IoInp  *pInp;
282     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
283     Int as;                             /* Audio Stream Number (1, 2, etc.) */
284     Int z;                              /* decode/encode counter */
285     Int errno;                          /* error number */
286     Int zI, zS;
287     Int argIdx;
288     Int8 tempVar8;
289     char decMsgBuf[ASP_MSG_BUF_LEN];
290     ioPhyCtl_t ioPhyCtl;
291     ioDataCtl_t ioDataCtl;
293     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
294     pInp    = pAsitCfg->pIoInp;
296     as = pAstCfg->as;
297     (void)as;  // clear compiler warning in case not used with tracing disabled
299     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
301     // reset frameCount
302     for (z=DECODE1; z < DECODEN; z++)
303     {
304         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
305                                      GATEMP_INDEX_DEC);
306         if (tempVar8)
307         {
308             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
309                               (Int)0, GATEMP_INDEX_DEC);
310         }
311     }
313     // loop through all supported inputs
314     for (z=DECODE1; z < DECODEN; z++)
315     {
316         zI = pP->inputsFromDecodes[z];
317         zS = pP->streamsFromDecodes[z];
318         (void)zS; // clear compiler warning in case not used with tracing disabled
319         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
320                                      GATEMP_INDEX_DEC);
321         if (pInp[zI].hIoPhy && tempVar8)
322         {
323             Uns gear;
324             Int frameLength;
325             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
327             // write back Dec configuration
328             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
329             Cache_wait();
331             // FL: send dec activate message to slave
332             argIdx = 0; // set decIdx (zone index)
333             *(Int32 *)&decMsgBuf[argIdx] = z;
334             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
335                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
336             {
337                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
338                 SW_BREAKPOINT; // temporary
339                 return ASIP_ERR_DECODE_MSG; // temporary
340             }
342             // FL: send dec reset message to slave
343             argIdx = 0; // set decIdx
344             *(Int32 *)&decMsgBuf[argIdx] = z;
345             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
346                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
347             {
348                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
349                 SW_BREAKPOINT; // temporary
350                 return ASIP_ERR_DECODE_MSG; // temporary
351             }
352             else
353             {
354                 argIdx = 0; // get decErrno
355                 errno = *(Int32 *)&decMsgBuf[argIdx];
356             }
358             // (***) FL: revisit
359             // invalidate Dec configuration
360             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
361             Cache_wait();
363             if (errno != 0) {
364                 return ASIP_ERR_DECODE_MSG;
365             }
367             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
368                                           GATEMP_INDEX_DEC);
369             tempVar8 = gear < GEARS ? gear : 0;
370             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
371                                tempVar8, GATEMP_INDEX_DEC);
373             // Compute decoder frame length based on source selection
374             // JXU: what does this function do? why does it only return PCM frame length?
375             /*frameLength = getFrameLengthSourceSel(pP, sourceSelect);
377             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
378             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
379             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;*/
381 /*
382             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
383                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
384                     return errno;
385                 }
386             }
387 */
388 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
389             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
390             ioDataCtl.param.frameLengthPcm = frameLength;
391             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
392 */
393             //JXTODO: do we need to update input status here again?
394             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
395                                               &pAstCfg->xInp[zI].inpBufStatus,
396                                               &pAstCfg->xInp[zI].inpBufConfig)) {
397                 return ASIP_ERR_INPUT_CFG;
398             }
399         } /* end of if(hIoPhy && decodeStatus.mode) */
400     } /* end of for (z=DECODE1; z < DECODEN; z++) */
402     pAsitCfg->inpDec.frame = 0;
403     pAsitCfg->inpDec.block = 0;
404     pAsitCfg->inpDec.state = INFO1;
406     return ASIP_NO_ERR;
407 }  /* decDecodeInit */
410 // -----------------------------------------------------------------------------
411 // ASIT Decoding Function - Info Processing, Common
412 //
413 //   Name:      PAF_ASIT_decodeInfo
414 //   Purpose:   Decoding Function for processing information in a manner that
415 //              is common for both initial and subsequent frames of input data.
416 //   From:      AST Parameter Function -> decodeProcessing
417 //   Uses:      See code.
418 //   States:    x
419 //   Return:    Error number in standard form (0 on success).
420 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
421 //              * State information as per parent.
422 // -----------------------------------------------------------------------------
423 Int
424 decDecodeInfo(
425     const PAF_ASIT_Params *pP,
426     const PAF_ASIT_Patchs *pQ,
427     PAF_ASIT_Config *pAsitCfg
430     PAF_AST_Config *pAstCfg;
431     PAF_AST_IoInp  *pInp;
432     Int as;                    /* Audio Stream Number (1, 2, etc.) */
433     Int z;                     /* input/decode/stream counter */
434     Int errno;                 /* error number */
435     Int zD, zI, zS, zX;
436     Int zMD;
437     Int zMS;
438     Int argIdx;
439     Int8 tempVar8;
440     Int tempVar;
441     char decMsgBuf[ASP_MSG_BUF_LEN];
443     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
444     pInp    = pAsitCfg->pIoInp;
445     as = pAstCfg->as;
446     zMD = pAstCfg->masterDec;
447     zMS = pAstCfg->masterStr;
448     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
450     // Set decode control: sample rate, emphasis
451     for (z=INPUT1; z < INPUTN; z++)
452     {
453         zD = z;
454         for (zX = DECODE1; zX < DECODEN; zX++)
455         {
456             if (pP->inputsFromDecodes[zX] == z) {
457                 zD = zX;
458                 break;
459             }
460         }
462         if (pInp[z].hIoPhy) {
463             //determine associated decoder
464             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
465                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
466                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
467                     pAstCfg->xDec[zD].decodeControl.sampleRate =
468                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
469                 }
470                 else {
471                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
472                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
473                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
474                         pAstCfg->xDec[zD].decodeControl.sampleRate);
475                     // return (ASPERR_INFO_RATECHANGE);
476                 }
477             }
479             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
480                                          GATEMP_INDEX_DEC);
481             pAstCfg->xDec[zD].decodeControl.emphasis =
482                 tempVar8 != PAF_SOURCE_PCM
483                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
484                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
485         }
486         else {
487             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
488             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
489         }
490     } /* end of for (z=INPUT1; z < INPUTN; z++) */
492     // Wait for info input: (JX) all SIO_reclaim does is pend on data, and do sync scan or sync check,
493     //                           which is done in autoDetection routine now.
494     //if (pAstCfg->xInp[zMI].hRxSio)
495     //    sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
496     // FL: debug, capture input buffer
497     //capIb(pAstCfg->xInp[zMI].pInpBuf);
498     //gCapIb_cnt++;
500     // Decode info
501     for (z=DECODE1; z < DECODEN; z++)
502     {
503         zI = pP->inputsFromDecodes[z];
504         zS = pP->streamsFromDecodes[z];
505         (void)zS; // clear compiler warning in case not used with tracing disabled
507         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
508                                      GATEMP_INDEX_DEC);
509         if (pInp[zI].hIoPhy  && tempVar8)
510         {
511             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
513             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
514                                               &pAstCfg->xInp[zI].inpBufStatus,
515                                               &pAstCfg->xInp[zI].inpBufConfig)) {
516                 TRACE_TERSE1("return error errno 0x%x.", errno);
517                 return errno;
518             }
520             // debug, capture input buffer
521             //capIb(pAstCfg->xInp[zI].pInpBuf);
522             //gCapIb_cnt++;
524 #if 1
525             // (***) FL: revisit
526             // write back Inp configuration
527             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
528             // write back Dec configuration
529             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
530             Cache_wait();
531 #endif
533             // FL: send info message to slave
534             argIdx = 0; // set decIdx
535             *(Int32 *)&decMsgBuf[argIdx] = z;
536             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE,
537                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
538             {
539                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
540                 SW_BREAKPOINT; // temporary
541                 return -1;     // temporary
542             }
543             else
544             {
545                 argIdx = 0; // get decErrno
546                 errno = *(Int32 *)&decMsgBuf[argIdx];
547             }
549 #if 1
550             // (***) FL: revisit
551             // invalidate Dec configuration
552             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
553             Cache_wait();
554 #endif
556             if (errno) {
557                 TRACE_TERSE1("return error errno 0x%x.", errno);
558                 return errno;
559             }
561             // increment decoded frame count
562             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
563                                        GATEMP_INDEX_DEC);
564             tempVar += 1;
565             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
566                               tempVar, GATEMP_INDEX_DEC);
567         }
568     } // z=DECODE1 to DECODEN
570     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
571     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
572                                  GATEMP_INDEX_DEC);
573     if (tempVar8)
574     {
575         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
576                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
577     }
579     // since now decoding update decode status for all enabled decoders
580     for (z=DECODE1; z < DECODEN; z++)
581     {
582         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
583                                      GATEMP_INDEX_DEC);
584         if (tempVar8)
585         {
586             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
587                                          GATEMP_INDEX_DEC);
588             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
589                                tempVar8, GATEMP_INDEX_DEC);
591             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
592                                          GATEMP_INDEX_DEC);
593             if (tempVar8 == PAF_SOURCE_SNG)
594             {
595                 tempVar8 = PAF_SOURCE_SNG;
596                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
597                                    tempVar8, GATEMP_INDEX_DEC);
598             }
599         }
600     }
602     return ASIP_NO_ERR;
603 } /* decDecodeInfo */
606 // -----------------------------------------------------------------------------
607 // ASIT Decoding Function - Decode Processing
608 //
609 //   Name:      PAF_ASIT_decodeDecode
610 //   Purpose:   Decoding Function for processing of input data by the
611 //              Decode Algorithm.
612 //   From:      AST Parameter Function -> decodeProcessing
613 //   Uses:      See code.
614 //   States:    x
615 //   Return:    Error number in standard form (0 on success).
616 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
617 //              * State information as per parent.
618 // -----------------------------------------------------------------------------
619 static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
620                          PAF_ASIT_Config *pAsitCfg, Int sourceSelect)
622     PAF_AST_Config *pAstCfg;
623     PAF_AST_IoInp  *pInp;
624     Int as;                     /* Audio Stream Number (1, 2, etc.) */
625     Int z;                      /* decode/stream counter */
626     Int errno;                  /* error number */
627     Int argIdx;
628     Int cbErrno;
629     Int frameLength;
630     char decMsgBuf[ASP_MSG_BUF_LEN];
631     ioPhyCtl_t  ioPhyCtl;
632     ioDataCtl_t ioDataCtl;
634     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
635     pInp    = pAsitCfg->pIoInp;
636     as = pAstCfg->as;
637     (void)as; // clear compiler warning in case not used with tracing disabled
639     // Decode data
640     for (z=DECODE1; z < DECODEN; z++)
641     {
642         Int zI = pP->inputsFromDecodes[z];
643         Int zS = pP->streamsFromDecodes[z];
644         (void)zS; // clear compiler warning in case not used with tracing disabled
645         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
646         {
647             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
649             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
650                     as+zS,
651                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
652                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
654             // FL: debug, capture input buffer
655             //capIbPcm(pAstCfg->xInp[z].pInpBuf);
657             // (***) FL: revisit
658             // write back Dec configuration
659             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
660             Cache_wait();
662             // FL: send decode message to slave
663             errno  = 0;
664             argIdx = 0; // set decIdx
665             *(Int32 *)&decMsgBuf[argIdx] = z;
666             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE,
667                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
668             {
669                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
670                 SW_BREAKPOINT; // temporary
671                 return -1;     // temporary
672             }
673             else
674             {
675                 argIdx = 0; // get decErrno
676                 errno = *(Int32 *)&decMsgBuf[argIdx];
677                 argIdx += sizeof(Int32); // get cbErrno
678                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
679                 if (cbErrno != 0)
680                 {
681                     gCbWrtAfErrCnt++;
682                     TRACE_TERSE1("CB write error=%d", cbErrno);
683                     //SW_BREAKPOINT; // temporary
684                 }
685             }
687             // (***) FL: revisit
688             // invalidate Dec configuration
689             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
690             Cache_wait();
692             if (errno)
693             {
694                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
695                 return errno;
696             }
698 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
699             as_traceChannels(pAsitCfg, z);
700 #endif
702             // Compute decoder frame length based on source selection
703             // This is unnecessary as sourceSelect won't change until input changes
704             //frameLength = getFrameLengthSourceSel(pP, sourceSelect);
705             //pAstCfg->xDec[z].decodeControl.frameLength  = frameLength;
706             //pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
707         } // hIoPhy && decodeStatus.mode
708         else {
709             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
710         }
711     } // z=DECODE1 to DECODEN
713     return ASIP_NO_ERR;
715 } /* decDecodeData */
718 Int decDecodeComplete( const PAF_ASIT_Params *pP,
719                        PAF_ASIT_Config *pAsitCfg)
721     int z, zMD, decError;
722     ALG_Handle alg[DECODEN_MAX];
724     zMD = pAsitCfg->pAstCfg->masterDec;
726     for (z=DECODE1; z < DECODEN; z++)
727     {
728         alg[z] = pAsitCfg->pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
729     }
730     alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
732     // Call decodeComplete: 2nd argument is NOT used inside the function
733     decError = pP->fxns->decodeComplete(pP, NULL, pAsitCfg, alg,
734                                         pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
736     if(decError) {
737         return ASIP_ERR_DECODE_COMPLETE;
738     }
740     return ASIP_NO_ERR;
741 }  /* decDecodeComplete */
744 #if 0
745 Int asipDecodeProcessing(
746         const PAF_ASIT_Params *pP,
747         const PAF_ASIT_Patchs *pQ,
748         PAF_ASIT_Config *pC,
749         Int sourceSelect)
751     PAF_AST_Config *pAstCfg;
752     Int errno, retVal;                          /* error number */
753     Int zMD;
755     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
756     zMD = pAstCfg->masterDec;
757     retVal = ASIP_NO_ERR;
759     //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
760     errno = decDecodeInfo(pP, pQ, pC);
761     if (errno != ASIP_NO_ERR) {
762         //gAsipInfo1_PrimaryErrCnt++;
763         TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
764         retVal =  ASIP_ERR_DECODE_INFO;
765     }
766     else {
767         // Don't start decode until major access unit is found.
768         Int8 sourceDecode, sampleRate;
769         sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
770                                          GATEMP_INDEX_DEC);
771         sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
772                                          GATEMP_INDEX_DEC);
773         if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
774                (sourceDecode == PAF_SOURCE_DXP)     ||
775                (sourceDecode == PAF_SOURCE_DTSHD) ) &&
776              ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
777             /* do nothing and return - waiting for major access unit */
778             pC->inpDec.frame++;
779             retVal =  ASIP_NO_ERR;
780         }
781         else {
782             errno = decDecodeData(pP, pQ, pC, sourceSelect);
783             if (errno != ASIP_NO_ERR) {
784                 //gAsipDecodeErrCnt++;
785                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
786                 retVal = ASIP_ERR_DECODE_DATA;
787             }
788             else {
789                 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pC->inpDec.frame, pC->inpDec.block);
790                 if (errno) {
791                     retVal = ASIP_ERR_DECODE_FINAL;
792                 }
793                 else {
794                     retVal = ASIP_NO_ERR;
795                 }
796             }
797         }
798     }
800     return retVal;
801 }  /* asipDecodeProcessing */
802 #endif
804 /* Nothing past this line */