Refactored input decoding processing. Updated input task. Not tested.
[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     Int decError, retVal, getVal;                          /* error number */
111     Int zMD;
112     Int8 tempVar8;
114     pAstCfg = pAsitCfg->pAstCfg;     // get pointer to common (shared) configuration
115     zMD = pAstCfg->masterDec;
117     retVal = ASIP_NO_ERR;
119     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
120                                  GATEMP_INDEX_DEC);
121     if (tempVar8 == PAF_SOURCE_NONE) {
122         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
123         pAsitCfg->inpDec.state = QUIT;   // skip processing, quit decoding
124     }
126     // Process commands (decode)
127     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
128     if (getVal) {
129         if (getVal == ASPERR_QUIT) {
130             pAsitCfg->inpDec.state = QUIT;  // skip processing, quit decoding
131             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
132         }
133         else if (getVal == ASPERR_ABORT) {
134             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
136             // PFP end -- outside of PFP for errors, EOS, or Input SIO change
137             //pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
138             //gNumPfpAsit2--;
140             return ASIP_ERR_DECODE_COMMAND;
141         }
142         else {
143             /* ignore */;
144         }
145     }
147     retVal = ASIP_NO_ERR;
149     switch(pAsitCfg->inpDec.state)
150     {
151         case INFO1:
152             decError = decDecodeInfo(pP, pQ, pAsitCfg);
153             if (decError) {
154                 //gAsipInfo1_PrimaryErrCnt++;
155                 TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
156                 retVal = ASIP_ERR_DECODE_INFO1;
157             }
158             else {
159                 // Don't start decode until major access unit is found.
160                 Int8 sourceDecode, sampleRate;
162                 sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
163                                                  GATEMP_INDEX_DEC);
164                 sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
165                                                  GATEMP_INDEX_DEC);
166                 if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
167                        (sourceDecode == PAF_SOURCE_DXP)     ||
168                        (sourceDecode == PAF_SOURCE_DTSHD) ) &&
169                      ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
170                     //gMajorAuMissed++; // debug
171                     pAsitCfg->inpDec.frame++;
172                     //pAsitCfg->inpDec.state = INFO1;    // stay in this state
173                 }
174                 else {
175                     decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
176                     if(decError) {
177                         retVal = ASIP_ERR_DECODE_INFO1;
178                     }
179                     else {
180                         pAsitCfg->inpDec.state = DECODE;
181                     }
182                 }
183             }
184             break;
186         case INFO2:
187             decError = decDecodeInfo(pP, pQ, pAsitCfg);
188             if (decError) {
189                 //gAsipInfo1_PrimaryErrCnt++;
190                 TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
191                 retVal = ASIP_ERR_DECODE_INFO2;
192             }
193             else {
194                 pAsitCfg->inpDec.state= DECODE;
195             }
196             break;
198         case DECODE:
199             decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
200             if (decError) {
201                 //gAsipDecodeErrCnt++;
202                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
203                 retVal = ASIP_ERR_DECODE_DATA;
204             }
205             else {
206                 decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
207                 if (decError) {
208                     retVal = ASIP_ERR_DECODE_FINAL;
209                 }
210                 else {
211                     pAsitCfg->inpDec.frame++;
212                     pAsitCfg->inpDec.state = INFO2;
213                 }
214             }
215             break;
217         case QUIT:
218             //gAsipQuitCnt++;
219             Log_info0("TaskAsip: state=QUIT");
221             // Quit:
222             // - Set error number registers.
223             // - Exit state machine to "decode complete" processing.
224             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
225             retVal = ASIP_ERR_DECODE_QUIT;
226             break;
228         default:
229             break;
231     }
233     if(retVal != ASIP_NO_ERR) {
234         decDecodeComplete(pP, pAsitCfg);
235     }
237     return retVal;
238 }  /* asipDecodeProcessing */
241 // -----------------------------------------------------------------------------
242 // ASIT Decoding Function - Reinitialization of Decode
243 //
244 //   Name:      decDecodeInit
245 //   Purpose:   Decoding Function for reinitializing the decoding process.
246 //   From:      AST Parameter Function -> decodeProcessing
247 //   Uses:      See code.
248 //   States:    x
249 //   Return:    Error number in standard or SIO form (0 on success).
250 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
251 //              * State information as per parent.
252 //
253 // -----------------------------------------------------------------------------
254 static Int decDecodeInit(
255         const PAF_ASIT_Params *pP,
256         PAF_ASIT_Config *pAsitCfg,
257         Int sourceSelect)
259     PAF_AST_Config *pAstCfg;
260     PAF_AST_IoInp  *pInp;
261     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
262     Int as;                             /* Audio Stream Number (1, 2, etc.) */
263     Int z;                              /* decode/encode counter */
264     Int errno;                          /* error number */
265     Int zI, zS;
266     Int argIdx;
267     Int8 tempVar8;
268     char decMsgBuf[ASP_MSG_BUF_LEN];
269     ioPhyCtl_t ioPhyCtl;
270     ioDataCtl_t ioDataCtl;
272     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
273     pInp    = pAsitCfg->pIoInp;
275     as = pAstCfg->as;
276     (void)as;  // clear compiler warning in case not used with tracing disabled
278     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
280     // reset frameCount
281     for (z=DECODE1; z < DECODEN; z++)
282     {
283         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
284                                      GATEMP_INDEX_DEC);
285         if (tempVar8)
286         {
287             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
288                               (Int)0, GATEMP_INDEX_DEC);
289         }
290     }
292     // loop through all supported inputs
293     for (z=DECODE1; z < DECODEN; z++)
294     {
295         zI = pP->inputsFromDecodes[z];
296         zS = pP->streamsFromDecodes[z];
297         (void)zS; // clear compiler warning in case not used with tracing disabled
298         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
299                                      GATEMP_INDEX_DEC);
300         if (pInp[zI].hIoPhy && tempVar8)
301         {
302             Uns gear;
303             Int frameLength;
304             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
306             // write back Dec configuration
307             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
308             Cache_wait();
310             // FL: send dec activate message to slave
311             argIdx = 0; // set decIdx (zone index)
312             *(Int32 *)&decMsgBuf[argIdx] = z;
313             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
314                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
315             {
316                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
317                 SW_BREAKPOINT; // temporary
318                 return ASIP_ERR_DECODE_MSG; // temporary
319             }
321             // FL: send dec reset message to slave
322             argIdx = 0; // set decIdx
323             *(Int32 *)&decMsgBuf[argIdx] = z;
324             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
325                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
326             {
327                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
328                 SW_BREAKPOINT; // temporary
329                 return ASIP_ERR_DECODE_MSG; // temporary
330             }
331             else
332             {
333                 argIdx = 0; // get decErrno
334                 errno = *(Int32 *)&decMsgBuf[argIdx];
335             }
337             // (***) FL: revisit
338             // invalidate Dec configuration
339             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
340             Cache_wait();
342             if (errno != 0) {
343                 return ASIP_ERR_DECODE_MSG;
344             }
346             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
347                                           GATEMP_INDEX_DEC);
348             tempVar8 = gear < GEARS ? gear : 0;
349             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
350                                tempVar8, GATEMP_INDEX_DEC);
352             // Compute decoder frame length based on source selection
353             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
355             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
356             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
357             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
360 /*
361             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
362                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
363                     return errno;
364                 }
365             }
366 */
367             pInp[z].sourceSelect = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
368                                                      GATEMP_INDEX_DEC);
370             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
371             ioDataCtl.param.frameLengthPcm = frameLength;
372             errno = ioDataControl(pInp[zI].hIoData, &ioDataCtl);
374             ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
375             ioPhyCtl.params.xferFrameSize = frameLength * (WORD_SIZE_PCM);
376             ioPhyControl(pInp[zI].hIoPhy, &ioPhyCtl);
378             pInp[zI].phyXferSize = ioPhyCtl.params.xferFrameSize;
380             //JXTODO: do we need to update input status here again?
381             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
382                                               &pAstCfg->xInp[zI].inpBufStatus,
383                                               &pAstCfg->xInp[zI].inpBufConfig)) {
384                 return ASIP_ERR_INPUT_CFG;
385             }
386         } /* end of if(hIoPhy && decodeStatus.mode) */
387     } /* end of for (z=DECODE1; z < DECODEN; z++) */
389     pAsitCfg->inpDec.frame = 0;
390     pAsitCfg->inpDec.block = 0;
391     pAsitCfg->inpDec.state = INFO1;
393     return ASIP_NO_ERR;
394 }  /* decDecodeInit */
397 // -----------------------------------------------------------------------------
398 // ASIT Decoding Function - Info Processing, Common
399 //
400 //   Name:      PAF_ASIT_decodeInfo
401 //   Purpose:   Decoding Function for processing information in a manner that
402 //              is common for both initial and subsequent frames of input data.
403 //   From:      AST Parameter Function -> decodeProcessing
404 //   Uses:      See code.
405 //   States:    x
406 //   Return:    Error number in standard form (0 on success).
407 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
408 //              * State information as per parent.
409 // -----------------------------------------------------------------------------
410 Int
411 decDecodeInfo(
412     const PAF_ASIT_Params *pP,
413     const PAF_ASIT_Patchs *pQ,
414     PAF_ASIT_Config *pAsitCfg
417     PAF_AST_Config *pAstCfg;
418     PAF_AST_IoInp  *pInp;
419     Int as;                    /* Audio Stream Number (1, 2, etc.) */
420     Int z;                     /* input/decode/stream counter */
421     Int errno;                 /* error number */
422     Int zD, zI, zS, zX;
423     Int zMD;
424     Int zMS;
425     Int argIdx;
426     Int8 tempVar8;
427     Int tempVar;
428     char decMsgBuf[ASP_MSG_BUF_LEN];
430     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
431     pInp    = pAsitCfg->pIoInp;
432     as = pAstCfg->as;
433     zMD = pAstCfg->masterDec;
434     zMS = pAstCfg->masterStr;
435     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
437     // Set decode control: sample rate, emphasis
438     for (z=INPUT1; z < INPUTN; z++)
439     {
440         zD = z;
441         for (zX = DECODE1; zX < DECODEN; zX++)
442         {
443             if (pP->inputsFromDecodes[zX] == z) {
444                 zD = zX;
445                 break;
446             }
447         }
449         if (pInp[z].hIoPhy) {
450             //determine associated decoder
451             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
452                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
453                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
454                     pAstCfg->xDec[zD].decodeControl.sampleRate =
455                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
456                 }
457                 else {
458                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
459                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
460                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
461                         pAstCfg->xDec[zD].decodeControl.sampleRate);
462                     // return (ASPERR_INFO_RATECHANGE);
463                 }
464             }
466             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
467                                          GATEMP_INDEX_DEC);
468             pAstCfg->xDec[zD].decodeControl.emphasis =
469                 tempVar8 != PAF_SOURCE_PCM
470                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
471                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
472         }
473         else {
474             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
475             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
476         }
477     } /* end of for (z=INPUT1; z < INPUTN; z++) */
479     // Wait for info input: (JX) all SIO_reclaim does is pend on data, and do sync scan or sync check,
480     //                           which is done in autoDetection routine now.
481     //if (pAstCfg->xInp[zMI].hRxSio)
482     //    sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
483     // FL: debug, capture input buffer
484     //capIb(pAstCfg->xInp[zMI].pInpBuf);
485     //gCapIb_cnt++;
487     // Decode info
488     for (z=DECODE1; z < DECODEN; z++)
489     {
490         zI = pP->inputsFromDecodes[z];
491         zS = pP->streamsFromDecodes[z];
492         (void)zS; // clear compiler warning in case not used with tracing disabled
494         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
495                                      GATEMP_INDEX_DEC);
496         if (pInp[zI].hIoPhy  && tempVar8)
497         {
498             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
500             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
501                                               &pAstCfg->xInp[zI].inpBufStatus,
502                                               &pAstCfg->xInp[zI].inpBufConfig)) {
503                 TRACE_TERSE1("return error errno 0x%x.", errno);
504                 return errno;
505             }
507             // debug, capture input buffer
508             //capIb(pAstCfg->xInp[zI].pInpBuf);
509             //gCapIb_cnt++;
511 #if 1
512             // (***) FL: revisit
513             // write back Inp configuration
514             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
515             // write back Dec configuration
516             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
517             Cache_wait();
518 #endif
520             // FL: send info message to slave
521             argIdx = 0; // set decIdx
522             *(Int32 *)&decMsgBuf[argIdx] = z;
523             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE,
524                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
525             {
526                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
527                 SW_BREAKPOINT; // temporary
528                 return -1;     // temporary
529             }
530             else
531             {
532                 argIdx = 0; // get decErrno
533                 errno = *(Int32 *)&decMsgBuf[argIdx];
534             }
536 #if 1
537             // (***) FL: revisit
538             // invalidate Dec configuration
539             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
540             Cache_wait();
541 #endif
543             if (errno) {
544                 TRACE_TERSE1("return error errno 0x%x.", errno);
545                 return errno;
546             }
548             // increment decoded frame count
549             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
550                                        GATEMP_INDEX_DEC);
551             tempVar += 1;
552             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
553                               tempVar, GATEMP_INDEX_DEC);
554         }
555     } // z=DECODE1 to DECODEN
557     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
558     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
559                                  GATEMP_INDEX_DEC);
560     if (tempVar8)
561     {
562         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
563                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
564     }
566     // since now decoding update decode status for all enabled decoders
567     for (z=DECODE1; z < DECODEN; z++)
568     {
569         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
570                                      GATEMP_INDEX_DEC);
571         if (tempVar8)
572         {
573             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
574                                          GATEMP_INDEX_DEC);
575             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
576                                tempVar8, GATEMP_INDEX_DEC);
578             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
579                                          GATEMP_INDEX_DEC);
580             if (tempVar8 == PAF_SOURCE_SNG)
581             {
582                 tempVar8 = PAF_SOURCE_SNG;
583                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
584                                    tempVar8, GATEMP_INDEX_DEC);
585             }
586         }
587     }
589     return ASIP_NO_ERR;
590 } /* decDecodeInfo */
593 // -----------------------------------------------------------------------------
594 // ASIT Decoding Function - Decode Processing
595 //
596 //   Name:      PAF_ASIT_decodeDecode
597 //   Purpose:   Decoding Function for processing of input data by the
598 //              Decode Algorithm.
599 //   From:      AST Parameter Function -> decodeProcessing
600 //   Uses:      See code.
601 //   States:    x
602 //   Return:    Error number in standard form (0 on success).
603 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
604 //              * State information as per parent.
605 // -----------------------------------------------------------------------------
606 static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
607                          PAF_ASIT_Config *pAsitCfg, Int sourceSelect)
609     PAF_AST_Config *pAstCfg;
610     PAF_AST_IoInp  *pInp;
611     Int as;                     /* Audio Stream Number (1, 2, etc.) */
612     Int z;                      /* decode/stream counter */
613     Int errno;                  /* error number */
614     Int argIdx;
615     Int cbErrno;
616     Int frameLength;
617     char decMsgBuf[ASP_MSG_BUF_LEN];
618     ioPhyCtl_t  ioPhyCtl;
619     ioDataCtl_t ioDataCtl;
621     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
622     pInp    = pAsitCfg->pIoInp;
623     as = pAstCfg->as;
624     (void)as; // clear compiler warning in case not used with tracing disabled
626     // Decode data
627     for (z=DECODE1; z < DECODEN; z++)
628     {
629         Int zI = pP->inputsFromDecodes[z];
630         Int zS = pP->streamsFromDecodes[z];
631         (void)zS; // clear compiler warning in case not used with tracing disabled
632         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
633         {
634             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
636             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
637                     as+zS,
638                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
639                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
641             // FL: debug, capture input buffer
642             //capIbPcm(pAstCfg->xInp[z].pInpBuf);
644             // (***) FL: revisit
645             // write back Dec configuration
646             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
647             Cache_wait();
649             // FL: send decode message to slave
650             errno  = 0;
651             argIdx = 0; // set decIdx
652             *(Int32 *)&decMsgBuf[argIdx] = z;
653             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE,
654                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
655             {
656                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
657                 SW_BREAKPOINT; // temporary
658                 return -1;     // temporary
659             }
660             else
661             {
662                 argIdx = 0; // get decErrno
663                 errno = *(Int32 *)&decMsgBuf[argIdx];
664                 argIdx += sizeof(Int32); // get cbErrno
665                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
666                 if (cbErrno != 0)
667                 {
668                     gCbWrtAfErrCnt++;
669                     TRACE_TERSE1("CB write error=%d", cbErrno);
670                     //SW_BREAKPOINT; // temporary
671                 }
672             }
674             // (***) FL: revisit
675             // invalidate Dec configuration
676             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
677             Cache_wait();
679             if (errno)
680             {
681                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
682                 return errno;
683             }
685 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
686             as_traceChannels(pAsitCfg, z);
687 #endif
689             // Compute decoder frame length based on source selection
690             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
692             pAstCfg->xDec[z].decodeControl.frameLength  = frameLength;
693             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
695             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
696             ioDataCtl.param.frameLengthPcm = frameLength;
697             errno = ioDataControl(pInp[zI].hIoData, &ioDataCtl);
699             ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
700             ioPhyCtl.params.xferFrameSize = frameLength * (WORD_SIZE_PCM);
701             ioPhyControl(pInp[zI].hIoPhy, &ioPhyCtl);
703             pInp[zI].phyXferSize = ioPhyCtl.params.xferFrameSize;
705             //JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
706         } // hIoPhy && decodeStatus.mode
707         else {
708             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
709         }
710     } // z=DECODE1 to DECODEN
712     return ASIP_NO_ERR;
714 } /* decDecodeData */
717 Int decDecodeComplete( const PAF_ASIT_Params *pP,
718                        PAF_ASIT_Config *pAsitCfg)
720     int z, zMD, decError;
721     ALG_Handle alg[DECODEN_MAX];
723     zMD = pAsitCfg->pAstCfg->masterDec;
725     for (z=DECODE1; z < DECODEN; z++)
726     {
727         alg[z] = pAsitCfg->pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
728     }
729     alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
731     // Call decodeComplete: 2nd argument is NOT used inside the function
732     decError = pP->fxns->decodeComplete(pP, NULL, pAsitCfg, alg,
733                                         pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
735     if(decError) {
736         return ASIP_ERR_DECODE_COMPLETE;
737     }
739     return ASIP_NO_ERR;
740 }  /* decDecodeComplete */
743 #if 0
744 Int asipDecodeProcessing(
745         const PAF_ASIT_Params *pP,
746         const PAF_ASIT_Patchs *pQ,
747         PAF_ASIT_Config *pC,
748         Int sourceSelect)
750     PAF_AST_Config *pAstCfg;
751     Int errno, retVal;                          /* error number */
752     Int zMD;
754     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
755     zMD = pAstCfg->masterDec;
756     retVal = ASIP_NO_ERR;
758     //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
759     errno = decDecodeInfo(pP, pQ, pC);
760     if (errno != ASIP_NO_ERR) {
761         //gAsipInfo1_PrimaryErrCnt++;
762         TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
763         retVal =  ASIP_ERR_DECODE_INFO;
764     }
765     else {
766         // Don't start decode until major access unit is found.
767         Int8 sourceDecode, sampleRate;
768         sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
769                                          GATEMP_INDEX_DEC);
770         sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
771                                          GATEMP_INDEX_DEC);
772         if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
773                (sourceDecode == PAF_SOURCE_DXP)     ||
774                (sourceDecode == PAF_SOURCE_DTSHD) ) &&
775              ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
776             /* do nothing and return - waiting for major access unit */
777             pC->inpDec.frame++;
778             retVal =  ASIP_NO_ERR;
779         }
780         else {
781             errno = decDecodeData(pP, pQ, pC, sourceSelect);
782             if (errno != ASIP_NO_ERR) {
783                 //gAsipDecodeErrCnt++;
784                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
785                 retVal = ASIP_ERR_DECODE_DATA;
786             }
787             else {
788                 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pC->inpDec.frame, pC->inpDec.block);
789                 if (errno) {
790                     retVal = ASIP_ERR_DECODE_FINAL;
791                 }
792                 else {
793                     retVal = ASIP_NO_ERR;
794                 }
795             }
796         }
797     }
799     return retVal;
800 }  /* asipDecodeProcessing */
801 #endif
803 /* Nothing past this line */