3da417719d40e4faba5164440da8cfb89a931b8e
[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;
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) {
138         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
139         pAsitCfg->inpDec.state = QUIT;   // skip processing, quit decoding
140     }
142     // Process commands (decode)
143     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
144     if (getVal) {
145         retVal = ASIP_ERR_DECODE_COMMAND;
146         if (getVal == ASPERR_QUIT) {
147             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
149             // Don't return if ASPERR_QUIT, but skip decode processing and quit
150             pAsitCfg->inpDec.state = QUIT;
151         }
152         else if (getVal == ASPERR_ABORT) {
153             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
155             // Return here if ASPERR_ABORT
156             return retVal;
157         }
158         else {
159             /* ignore */;
160         }
161     }
163     switch(pAsitCfg->inpDec.state)
164     {
165         case INFO1:
166             decError = decDecodeInfo(pP, pQ, pAsitCfg);
167             if (decError) {
168                 //gAsipInfo1_PrimaryErrCnt++;
169                 TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
170                 retVal = ASIP_ERR_DECODE_INFO1;
171             }
172             else {
173                 // Don't start decode until major access unit is found.
174                 Int8 sourceDecode, sampleRate;
176                 sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
177                                                  GATEMP_INDEX_DEC);
178                 sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
179                                                  GATEMP_INDEX_DEC);
180                 if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
181                        (sourceDecode == PAF_SOURCE_DXP)     ||
182                        (sourceDecode == PAF_SOURCE_DTSHD) ) &&
183                      ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
184                     //gMajorAuMissed++; // debug
185                     pAsitCfg->inpDec.frame++;
186                     //pAsitCfg->inpDec.state = INFO1;    // stay in this state
187                 }
188                 else {
189                     decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
190                     if(decError) {
191                         retVal = ASIP_ERR_DECODE_INFO1;
192                     }
193                     else {
194                         pAsitCfg->inpDec.state = DECODE;
195                     }
196                 }
197             }
198             break;
200         case INFO2:
201             decError = decDecodeInfo(pP, pQ, pAsitCfg);
202             if (decError) {
203                 //gAsipInfo1_PrimaryErrCnt++;
204                 TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
205                 retVal = ASIP_ERR_DECODE_INFO2;
206             }
207             else {
208                 pAsitCfg->inpDec.state= DECODE;
209             }
210             break;
212         case DECODE:
213             decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
214             if (decError) {
215                 //gAsipDecodeErrCnt++;
216                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
217                 retVal = ASIP_ERR_DECODE_DATA;
218             }
219             else {
220                 decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
221                 if (decError) {
222                     retVal = ASIP_ERR_DECODE_FINAL;
223                 }
224                 else {
225                     pAsitCfg->inpDec.frame++;
226                     pAsitCfg->inpDec.state = INFO2;
227                 }
228             }
229             break;
231         case QUIT:
232             //gAsipQuitCnt++;
233             Log_info0("TaskAsip: state=QUIT");
235             // Quit:
236             // - Set error number registers.
237             // - Exit state machine to "decode complete" processing.
238             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
239             break;
241         default:
242             break;
244     }
246     if(retVal != ASIP_NO_ERR) {
247         decDecodeComplete(pP, pAsitCfg);
248     }
250     return retVal;
251 }  /* asipDecodeProcessing */
254 // -----------------------------------------------------------------------------
255 // ASIT Decoding Function - Reinitialization of Decode
256 //
257 //   Name:      decDecodeInit
258 //   Purpose:   Decoding Function for reinitializing the decoding process.
259 //   From:      AST Parameter Function -> decodeProcessing
260 //   Uses:      See code.
261 //   States:    x
262 //   Return:    Error number in standard or SIO form (0 on success).
263 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
264 //              * State information as per parent.
265 //
266 // -----------------------------------------------------------------------------
267 static Int decDecodeInit(
268         const PAF_ASIT_Params *pP,
269         PAF_ASIT_Config *pAsitCfg,
270         Int sourceSelect)
272     PAF_AST_Config *pAstCfg;
273     PAF_AST_IoInp  *pInp;
274     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
275     Int as;                             /* Audio Stream Number (1, 2, etc.) */
276     Int z;                              /* decode/encode counter */
277     Int errno;                          /* error number */
278     Int zI, zS;
279     Int argIdx;
280     Int8 tempVar8;
281     char decMsgBuf[ASP_MSG_BUF_LEN];
282     ioPhyCtl_t ioPhyCtl;
283     ioDataCtl_t ioDataCtl;
285     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
286     pInp    = pAsitCfg->pIoInp;
288     as = pAstCfg->as;
289     (void)as;  // clear compiler warning in case not used with tracing disabled
291     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
293     // reset frameCount
294     for (z=DECODE1; z < DECODEN; z++)
295     {
296         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
297                                      GATEMP_INDEX_DEC);
298         if (tempVar8)
299         {
300             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
301                               (Int)0, GATEMP_INDEX_DEC);
302         }
303     }
305     // loop through all supported inputs
306     for (z=DECODE1; z < DECODEN; z++)
307     {
308         zI = pP->inputsFromDecodes[z];
309         zS = pP->streamsFromDecodes[z];
310         (void)zS; // clear compiler warning in case not used with tracing disabled
311         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
312                                      GATEMP_INDEX_DEC);
313         if (pInp[zI].hIoPhy && tempVar8)
314         {
315             Uns gear;
316             Int frameLength;
317             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
319             // write back Dec configuration
320             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
321             Cache_wait();
323             // FL: send dec activate message to slave
324             argIdx = 0; // set decIdx (zone index)
325             *(Int32 *)&decMsgBuf[argIdx] = z;
326             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
327                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
328             {
329                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
330                 SW_BREAKPOINT; // temporary
331                 return ASIP_ERR_DECODE_MSG; // temporary
332             }
334             // FL: send dec reset message to slave
335             argIdx = 0; // set decIdx
336             *(Int32 *)&decMsgBuf[argIdx] = z;
337             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
338                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
339             {
340                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
341                 SW_BREAKPOINT; // temporary
342                 return ASIP_ERR_DECODE_MSG; // temporary
343             }
344             else
345             {
346                 argIdx = 0; // get decErrno
347                 errno = *(Int32 *)&decMsgBuf[argIdx];
348             }
350             // (***) FL: revisit
351             // invalidate Dec configuration
352             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
353             Cache_wait();
355             if (errno != 0) {
356                 return ASIP_ERR_DECODE_MSG;
357             }
359             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
360                                           GATEMP_INDEX_DEC);
361             tempVar8 = gear < GEARS ? gear : 0;
362             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
363                                tempVar8, GATEMP_INDEX_DEC);
365             // Compute decoder frame length based on source selection
366             // JXU: what does this function do? why does it only return PCM frame length?
367             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
369             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
370             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
371             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
373 /*
374             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
375                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
376                     return errno;
377                 }
378             }
379 */
380             // JXU: who changes sourceSelect? why not use sourceSelect passed to this function?
381             pInp[z].sourceSelect = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
382                                                      GATEMP_INDEX_DEC);
383 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
384             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
385             ioDataCtl.param.frameLengthPcm = frameLength;
386             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
387 */
388             //JXTODO: do we need to update input status here again?
389             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
390                                               &pAstCfg->xInp[zI].inpBufStatus,
391                                               &pAstCfg->xInp[zI].inpBufConfig)) {
392                 return ASIP_ERR_INPUT_CFG;
393             }
394         } /* end of if(hIoPhy && decodeStatus.mode) */
395     } /* end of for (z=DECODE1; z < DECODEN; z++) */
397     pAsitCfg->inpDec.frame = 0;
398     pAsitCfg->inpDec.block = 0;
399     pAsitCfg->inpDec.state = INFO1;
401     return ASIP_NO_ERR;
402 }  /* decDecodeInit */
405 // -----------------------------------------------------------------------------
406 // ASIT Decoding Function - Info Processing, Common
407 //
408 //   Name:      PAF_ASIT_decodeInfo
409 //   Purpose:   Decoding Function for processing information in a manner that
410 //              is common for both initial and subsequent frames of input data.
411 //   From:      AST Parameter Function -> decodeProcessing
412 //   Uses:      See code.
413 //   States:    x
414 //   Return:    Error number in standard form (0 on success).
415 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
416 //              * State information as per parent.
417 // -----------------------------------------------------------------------------
418 Int
419 decDecodeInfo(
420     const PAF_ASIT_Params *pP,
421     const PAF_ASIT_Patchs *pQ,
422     PAF_ASIT_Config *pAsitCfg
425     PAF_AST_Config *pAstCfg;
426     PAF_AST_IoInp  *pInp;
427     Int as;                    /* Audio Stream Number (1, 2, etc.) */
428     Int z;                     /* input/decode/stream counter */
429     Int errno;                 /* error number */
430     Int zD, zI, zS, zX;
431     Int zMD;
432     Int zMS;
433     Int argIdx;
434     Int8 tempVar8;
435     Int tempVar;
436     char decMsgBuf[ASP_MSG_BUF_LEN];
438     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
439     pInp    = pAsitCfg->pIoInp;
440     as = pAstCfg->as;
441     zMD = pAstCfg->masterDec;
442     zMS = pAstCfg->masterStr;
443     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
445     // Set decode control: sample rate, emphasis
446     for (z=INPUT1; z < INPUTN; z++)
447     {
448         zD = z;
449         for (zX = DECODE1; zX < DECODEN; zX++)
450         {
451             if (pP->inputsFromDecodes[zX] == z) {
452                 zD = zX;
453                 break;
454             }
455         }
457         if (pInp[z].hIoPhy) {
458             //determine associated decoder
459             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
460                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
461                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
462                     pAstCfg->xDec[zD].decodeControl.sampleRate =
463                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
464                 }
465                 else {
466                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
467                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
468                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
469                         pAstCfg->xDec[zD].decodeControl.sampleRate);
470                     // return (ASPERR_INFO_RATECHANGE);
471                 }
472             }
474             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
475                                          GATEMP_INDEX_DEC);
476             pAstCfg->xDec[zD].decodeControl.emphasis =
477                 tempVar8 != PAF_SOURCE_PCM
478                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
479                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
480         }
481         else {
482             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
483             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
484         }
485     } /* end of for (z=INPUT1; z < INPUTN; z++) */
487     // Wait for info input: (JX) all SIO_reclaim does is pend on data, and do sync scan or sync check,
488     //                           which is done in autoDetection routine now.
489     //if (pAstCfg->xInp[zMI].hRxSio)
490     //    sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
491     // FL: debug, capture input buffer
492     //capIb(pAstCfg->xInp[zMI].pInpBuf);
493     //gCapIb_cnt++;
495     // Decode info
496     for (z=DECODE1; z < DECODEN; z++)
497     {
498         zI = pP->inputsFromDecodes[z];
499         zS = pP->streamsFromDecodes[z];
500         (void)zS; // clear compiler warning in case not used with tracing disabled
502         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
503                                      GATEMP_INDEX_DEC);
504         if (pInp[zI].hIoPhy  && tempVar8)
505         {
506             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
508             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
509                                               &pAstCfg->xInp[zI].inpBufStatus,
510                                               &pAstCfg->xInp[zI].inpBufConfig)) {
511                 TRACE_TERSE1("return error errno 0x%x.", errno);
512                 return errno;
513             }
515             // debug, capture input buffer
516             //capIb(pAstCfg->xInp[zI].pInpBuf);
517             //gCapIb_cnt++;
519 #if 1
520             // (***) FL: revisit
521             // write back Inp configuration
522             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
523             // write back Dec configuration
524             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
525             Cache_wait();
526 #endif
528             // FL: send info message to slave
529             argIdx = 0; // set decIdx
530             *(Int32 *)&decMsgBuf[argIdx] = z;
531             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE,
532                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
533             {
534                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
535                 SW_BREAKPOINT; // temporary
536                 return -1;     // temporary
537             }
538             else
539             {
540                 argIdx = 0; // get decErrno
541                 errno = *(Int32 *)&decMsgBuf[argIdx];
542             }
544 #if 1
545             // (***) FL: revisit
546             // invalidate Dec configuration
547             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
548             Cache_wait();
549 #endif
551             if (errno) {
552                 TRACE_TERSE1("return error errno 0x%x.", errno);
553                 return errno;
554             }
556             // increment decoded frame count
557             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
558                                        GATEMP_INDEX_DEC);
559             tempVar += 1;
560             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
561                               tempVar, GATEMP_INDEX_DEC);
562         }
563     } // z=DECODE1 to DECODEN
565     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
566     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
567                                  GATEMP_INDEX_DEC);
568     if (tempVar8)
569     {
570         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
571                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
572     }
574     // since now decoding update decode status for all enabled decoders
575     for (z=DECODE1; z < DECODEN; z++)
576     {
577         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
578                                      GATEMP_INDEX_DEC);
579         if (tempVar8)
580         {
581             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
582                                          GATEMP_INDEX_DEC);
583             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
584                                tempVar8, GATEMP_INDEX_DEC);
586             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
587                                          GATEMP_INDEX_DEC);
588             if (tempVar8 == PAF_SOURCE_SNG)
589             {
590                 tempVar8 = PAF_SOURCE_SNG;
591                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
592                                    tempVar8, GATEMP_INDEX_DEC);
593             }
594         }
595     }
597     return ASIP_NO_ERR;
598 } /* decDecodeInfo */
601 // -----------------------------------------------------------------------------
602 // ASIT Decoding Function - Decode Processing
603 //
604 //   Name:      PAF_ASIT_decodeDecode
605 //   Purpose:   Decoding Function for processing of input data by the
606 //              Decode Algorithm.
607 //   From:      AST Parameter Function -> decodeProcessing
608 //   Uses:      See code.
609 //   States:    x
610 //   Return:    Error number in standard form (0 on success).
611 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
612 //              * State information as per parent.
613 // -----------------------------------------------------------------------------
614 static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
615                          PAF_ASIT_Config *pAsitCfg, Int sourceSelect)
617     PAF_AST_Config *pAstCfg;
618     PAF_AST_IoInp  *pInp;
619     Int as;                     /* Audio Stream Number (1, 2, etc.) */
620     Int z;                      /* decode/stream counter */
621     Int errno;                  /* error number */
622     Int argIdx;
623     Int cbErrno;
624     Int frameLength;
625     char decMsgBuf[ASP_MSG_BUF_LEN];
626     ioPhyCtl_t  ioPhyCtl;
627     ioDataCtl_t ioDataCtl;
629     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
630     pInp    = pAsitCfg->pIoInp;
631     as = pAstCfg->as;
632     (void)as; // clear compiler warning in case not used with tracing disabled
634     // Decode data
635     for (z=DECODE1; z < DECODEN; z++)
636     {
637         Int zI = pP->inputsFromDecodes[z];
638         Int zS = pP->streamsFromDecodes[z];
639         (void)zS; // clear compiler warning in case not used with tracing disabled
640         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
641         {
642             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
644             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
645                     as+zS,
646                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
647                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
649             // FL: debug, capture input buffer
650             //capIbPcm(pAstCfg->xInp[z].pInpBuf);
652             // (***) FL: revisit
653             // write back Dec configuration
654             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
655             Cache_wait();
657             // FL: send decode message to slave
658             errno  = 0;
659             argIdx = 0; // set decIdx
660             *(Int32 *)&decMsgBuf[argIdx] = z;
661             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE,
662                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
663             {
664                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
665                 SW_BREAKPOINT; // temporary
666                 return -1;     // temporary
667             }
668             else
669             {
670                 argIdx = 0; // get decErrno
671                 errno = *(Int32 *)&decMsgBuf[argIdx];
672                 argIdx += sizeof(Int32); // get cbErrno
673                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
674                 if (cbErrno != 0)
675                 {
676                     gCbWrtAfErrCnt++;
677                     TRACE_TERSE1("CB write error=%d", cbErrno);
678                     //SW_BREAKPOINT; // temporary
679                 }
680             }
682             // (***) FL: revisit
683             // invalidate Dec configuration
684             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
685             Cache_wait();
687             if (errno)
688             {
689                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
690                 return errno;
691             }
693 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
694             as_traceChannels(pAsitCfg, z);
695 #endif
697             // Compute decoder frame length based on source selection
698             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
700             pAstCfg->xDec[z].decodeControl.frameLength  = frameLength;
701             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
702 /* //JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
703             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
704             ioDataCtl.param.frameLengthPcm = frameLength;
705             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
706 */
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 */