]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpDec.c
Fixed problem of input task being stuck when input stream stops:
[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 || 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     switch(pAsitCfg->inpDec.state)
165     {
166         case INFO1:
167             decError = decDecodeInfo(pP, pQ, pAsitCfg);
168             if (decError) {
169                 //gAsipInfo1_PrimaryErrCnt++;
170                 TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
171                 retVal = ASIP_ERR_DECODE_INFO1;
172             }
173             else {
174                 // Don't start decode until major access unit is found.
175                 Int8 sourceDecode, sampleRate;
177                 sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
178                                                  GATEMP_INDEX_DEC);
179                 sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
180                                                  GATEMP_INDEX_DEC);
181                 if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
182                        (sourceDecode == PAF_SOURCE_DXP)     ||
183                        (sourceDecode == PAF_SOURCE_DTSHD) ) &&
184                      ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
185                     //gMajorAuMissed++; // debug
186                     pAsitCfg->inpDec.frame++;
187                     //pAsitCfg->inpDec.state = INFO1;    // stay in this state
188                 }
189                 else {
190                     decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
191                     if(decError) {
192                         retVal = ASIP_ERR_DECODE_INFO1;
193                     }
194                     else {
195                         pAsitCfg->inpDec.state = DECODE;
196                     }
197                 }
198             }
199             break;
201         case INFO2:
202             decError = decDecodeInfo(pP, pQ, pAsitCfg);
203             if (decError) {
204                 //gAsipInfo1_PrimaryErrCnt++;
205                 TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
206                 retVal = ASIP_ERR_DECODE_INFO2;
207             }
208             else {
209                 pAsitCfg->inpDec.state= DECODE;
210             }
211             break;
213         case DECODE:
214             decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
215             if (decError) {
216                 //gAsipDecodeErrCnt++;
217                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
218                 retVal = ASIP_ERR_DECODE_DATA;
219             }
220             else {
221                 decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
222                 if (decError) {
223                     retVal = ASIP_ERR_DECODE_FINAL;
224                 }
225                 else {
226                     pAsitCfg->inpDec.frame++;
227                     pAsitCfg->inpDec.state = INFO2;
228                 }
229             }
230             break;
232         case QUIT:
233             //gAsipQuitCnt++;
234             Log_info0("TaskAsip: state=QUIT");
236             // Quit:
237             // - Set error number registers.
238             // - Exit state machine to "decode complete" processing.
239             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
240             break;
242         default:
243             break;
245     }
247     if(retVal != ASIP_NO_ERR) {
248         decDecodeComplete(pP, pAsitCfg);
249     }
251     return retVal;
252 }  /* asipDecodeProcessing */
255 // -----------------------------------------------------------------------------
256 // ASIT Decoding Function - Reinitialization of Decode
257 //
258 //   Name:      decDecodeInit
259 //   Purpose:   Decoding Function for reinitializing the decoding process.
260 //   From:      AST Parameter Function -> decodeProcessing
261 //   Uses:      See code.
262 //   States:    x
263 //   Return:    Error number in standard or SIO form (0 on success).
264 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
265 //              * State information as per parent.
266 //
267 // -----------------------------------------------------------------------------
268 static Int decDecodeInit(
269         const PAF_ASIT_Params *pP,
270         PAF_ASIT_Config *pAsitCfg,
271         Int sourceSelect)
273     PAF_AST_Config *pAstCfg;
274     PAF_AST_IoInp  *pInp;
275     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
276     Int as;                             /* Audio Stream Number (1, 2, etc.) */
277     Int z;                              /* decode/encode counter */
278     Int errno;                          /* error number */
279     Int zI, zS;
280     Int argIdx;
281     Int8 tempVar8;
282     char decMsgBuf[ASP_MSG_BUF_LEN];
283     ioPhyCtl_t ioPhyCtl;
284     ioDataCtl_t ioDataCtl;
286     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
287     pInp    = pAsitCfg->pIoInp;
289     as = pAstCfg->as;
290     (void)as;  // clear compiler warning in case not used with tracing disabled
292     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
294     // reset frameCount
295     for (z=DECODE1; z < DECODEN; z++)
296     {
297         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
298                                      GATEMP_INDEX_DEC);
299         if (tempVar8)
300         {
301             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
302                               (Int)0, GATEMP_INDEX_DEC);
303         }
304     }
306     // loop through all supported inputs
307     for (z=DECODE1; z < DECODEN; z++)
308     {
309         zI = pP->inputsFromDecodes[z];
310         zS = pP->streamsFromDecodes[z];
311         (void)zS; // clear compiler warning in case not used with tracing disabled
312         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
313                                      GATEMP_INDEX_DEC);
314         if (pInp[zI].hIoPhy && tempVar8)
315         {
316             Uns gear;
317             Int frameLength;
318             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
320             // write back Dec configuration
321             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
322             Cache_wait();
324             // FL: send dec activate message to slave
325             argIdx = 0; // set decIdx (zone index)
326             *(Int32 *)&decMsgBuf[argIdx] = z;
327             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
328                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
329             {
330                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
331                 SW_BREAKPOINT; // temporary
332                 return ASIP_ERR_DECODE_MSG; // temporary
333             }
335             // FL: send dec reset message to slave
336             argIdx = 0; // set decIdx
337             *(Int32 *)&decMsgBuf[argIdx] = z;
338             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
339                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
340             {
341                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
342                 SW_BREAKPOINT; // temporary
343                 return ASIP_ERR_DECODE_MSG; // temporary
344             }
345             else
346             {
347                 argIdx = 0; // get decErrno
348                 errno = *(Int32 *)&decMsgBuf[argIdx];
349             }
351             // (***) FL: revisit
352             // invalidate Dec configuration
353             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
354             Cache_wait();
356             if (errno != 0) {
357                 return ASIP_ERR_DECODE_MSG;
358             }
360             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
361                                           GATEMP_INDEX_DEC);
362             tempVar8 = gear < GEARS ? gear : 0;
363             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
364                                tempVar8, GATEMP_INDEX_DEC);
366             // Compute decoder frame length based on source selection
367             // JXU: what does this function do? why does it only return PCM frame length?
368             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
370             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
371             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
372             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
374 /*
375             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
376                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
377                     return errno;
378                 }
379             }
380 */
381             // JXU: who changes sourceSelect? why not use sourceSelect passed to this function?
382             pInp[z].sourceSelect = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
383                                                      GATEMP_INDEX_DEC);
384 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
385             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
386             ioDataCtl.param.frameLengthPcm = frameLength;
387             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
388 */
389             //JXTODO: do we need to update input status here again?
390             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
391                                               &pAstCfg->xInp[zI].inpBufStatus,
392                                               &pAstCfg->xInp[zI].inpBufConfig)) {
393                 return ASIP_ERR_INPUT_CFG;
394             }
395         } /* end of if(hIoPhy && decodeStatus.mode) */
396     } /* end of for (z=DECODE1; z < DECODEN; z++) */
398     pAsitCfg->inpDec.frame = 0;
399     pAsitCfg->inpDec.block = 0;
400     pAsitCfg->inpDec.state = INFO1;
402     return ASIP_NO_ERR;
403 }  /* decDecodeInit */
406 // -----------------------------------------------------------------------------
407 // ASIT Decoding Function - Info Processing, Common
408 //
409 //   Name:      PAF_ASIT_decodeInfo
410 //   Purpose:   Decoding Function for processing information in a manner that
411 //              is common for both initial and subsequent frames of input data.
412 //   From:      AST Parameter Function -> decodeProcessing
413 //   Uses:      See code.
414 //   States:    x
415 //   Return:    Error number in standard form (0 on success).
416 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
417 //              * State information as per parent.
418 // -----------------------------------------------------------------------------
419 Int
420 decDecodeInfo(
421     const PAF_ASIT_Params *pP,
422     const PAF_ASIT_Patchs *pQ,
423     PAF_ASIT_Config *pAsitCfg
426     PAF_AST_Config *pAstCfg;
427     PAF_AST_IoInp  *pInp;
428     Int as;                    /* Audio Stream Number (1, 2, etc.) */
429     Int z;                     /* input/decode/stream counter */
430     Int errno;                 /* error number */
431     Int zD, zI, zS, zX;
432     Int zMD;
433     Int zMS;
434     Int argIdx;
435     Int8 tempVar8;
436     Int tempVar;
437     char decMsgBuf[ASP_MSG_BUF_LEN];
439     pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
440     pInp    = pAsitCfg->pIoInp;
441     as = pAstCfg->as;
442     zMD = pAstCfg->masterDec;
443     zMS = pAstCfg->masterStr;
444     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
446     // Set decode control: sample rate, emphasis
447     for (z=INPUT1; z < INPUTN; z++)
448     {
449         zD = z;
450         for (zX = DECODE1; zX < DECODEN; zX++)
451         {
452             if (pP->inputsFromDecodes[zX] == z) {
453                 zD = zX;
454                 break;
455             }
456         }
458         if (pInp[z].hIoPhy) {
459             //determine associated decoder
460             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
461                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
462                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
463                     pAstCfg->xDec[zD].decodeControl.sampleRate =
464                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
465                 }
466                 else {
467                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
468                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
469                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
470                         pAstCfg->xDec[zD].decodeControl.sampleRate);
471                     // return (ASPERR_INFO_RATECHANGE);
472                 }
473             }
475             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
476                                          GATEMP_INDEX_DEC);
477             pAstCfg->xDec[zD].decodeControl.emphasis =
478                 tempVar8 != PAF_SOURCE_PCM
479                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
480                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
481         }
482         else {
483             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
484             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
485         }
486     } /* end of for (z=INPUT1; z < INPUTN; z++) */
488     // Wait for info input: (JX) all SIO_reclaim does is pend on data, and do sync scan or sync check,
489     //                           which is done in autoDetection routine now.
490     //if (pAstCfg->xInp[zMI].hRxSio)
491     //    sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
492     // FL: debug, capture input buffer
493     //capIb(pAstCfg->xInp[zMI].pInpBuf);
494     //gCapIb_cnt++;
496     // Decode info
497     for (z=DECODE1; z < DECODEN; z++)
498     {
499         zI = pP->inputsFromDecodes[z];
500         zS = pP->streamsFromDecodes[z];
501         (void)zS; // clear compiler warning in case not used with tracing disabled
503         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
504                                      GATEMP_INDEX_DEC);
505         if (pInp[zI].hIoPhy  && tempVar8)
506         {
507             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
509             if (errno = asipUpdateInputStatus(pInp[zI].pRxParams,
510                                               &pAstCfg->xInp[zI].inpBufStatus,
511                                               &pAstCfg->xInp[zI].inpBufConfig)) {
512                 TRACE_TERSE1("return error errno 0x%x.", errno);
513                 return errno;
514             }
516             // debug, capture input buffer
517             //capIb(pAstCfg->xInp[zI].pInpBuf);
518             //gCapIb_cnt++;
520 #if 1
521             // (***) FL: revisit
522             // write back Inp configuration
523             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
524             // write back Dec configuration
525             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
526             Cache_wait();
527 #endif
529             // FL: send info message to slave
530             argIdx = 0; // set decIdx
531             *(Int32 *)&decMsgBuf[argIdx] = z;
532             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE,
533                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
534             {
535                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
536                 SW_BREAKPOINT; // temporary
537                 return -1;     // temporary
538             }
539             else
540             {
541                 argIdx = 0; // get decErrno
542                 errno = *(Int32 *)&decMsgBuf[argIdx];
543             }
545 #if 1
546             // (***) FL: revisit
547             // invalidate Dec configuration
548             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
549             Cache_wait();
550 #endif
552             if (errno) {
553                 TRACE_TERSE1("return error errno 0x%x.", errno);
554                 return errno;
555             }
557             // increment decoded frame count
558             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
559                                        GATEMP_INDEX_DEC);
560             tempVar += 1;
561             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
562                               tempVar, GATEMP_INDEX_DEC);
563         }
564     } // z=DECODE1 to DECODEN
566     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
567     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
568                                  GATEMP_INDEX_DEC);
569     if (tempVar8)
570     {
571         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
572                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
573     }
575     // since now decoding update decode status for all enabled decoders
576     for (z=DECODE1; z < DECODEN; z++)
577     {
578         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
579                                      GATEMP_INDEX_DEC);
580         if (tempVar8)
581         {
582             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
583                                          GATEMP_INDEX_DEC);
584             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
585                                tempVar8, GATEMP_INDEX_DEC);
587             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
588                                          GATEMP_INDEX_DEC);
589             if (tempVar8 == PAF_SOURCE_SNG)
590             {
591                 tempVar8 = PAF_SOURCE_SNG;
592                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
593                                    tempVar8, GATEMP_INDEX_DEC);
594             }
595         }
596     }
598     return ASIP_NO_ERR;
599 } /* decDecodeInfo */
602 // -----------------------------------------------------------------------------
603 // ASIT Decoding Function - Decode Processing
604 //
605 //   Name:      PAF_ASIT_decodeDecode
606 //   Purpose:   Decoding Function for processing of input data by the
607 //              Decode Algorithm.
608 //   From:      AST Parameter Function -> decodeProcessing
609 //   Uses:      See code.
610 //   States:    x
611 //   Return:    Error number in standard form (0 on success).
612 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
613 //              * State information as per parent.
614 // -----------------------------------------------------------------------------
615 static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
616                          PAF_ASIT_Config *pAsitCfg, Int sourceSelect)
618     PAF_AST_Config *pAstCfg;
619     PAF_AST_IoInp  *pInp;
620     Int as;                     /* Audio Stream Number (1, 2, etc.) */
621     Int z;                      /* decode/stream counter */
622     Int errno;                  /* error number */
623     Int argIdx;
624     Int cbErrno;
625     Int frameLength;
626     char decMsgBuf[ASP_MSG_BUF_LEN];
627     ioPhyCtl_t  ioPhyCtl;
628     ioDataCtl_t ioDataCtl;
630     pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
631     pInp    = pAsitCfg->pIoInp;
632     as = pAstCfg->as;
633     (void)as; // clear compiler warning in case not used with tracing disabled
635     // Decode data
636     for (z=DECODE1; z < DECODEN; z++)
637     {
638         Int zI = pP->inputsFromDecodes[z];
639         Int zS = pP->streamsFromDecodes[z];
640         (void)zS; // clear compiler warning in case not used with tracing disabled
641         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
642         {
643             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
645             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
646                     as+zS,
647                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
648                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
650             // FL: debug, capture input buffer
651             //capIbPcm(pAstCfg->xInp[z].pInpBuf);
653             // (***) FL: revisit
654             // write back Dec configuration
655             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
656             Cache_wait();
658             // FL: send decode message to slave
659             errno  = 0;
660             argIdx = 0; // set decIdx
661             *(Int32 *)&decMsgBuf[argIdx] = z;
662             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE,
663                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
664             {
665                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
666                 SW_BREAKPOINT; // temporary
667                 return -1;     // temporary
668             }
669             else
670             {
671                 argIdx = 0; // get decErrno
672                 errno = *(Int32 *)&decMsgBuf[argIdx];
673                 argIdx += sizeof(Int32); // get cbErrno
674                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
675                 if (cbErrno != 0)
676                 {
677                     gCbWrtAfErrCnt++;
678                     TRACE_TERSE1("CB write error=%d", cbErrno);
679                     //SW_BREAKPOINT; // temporary
680                 }
681             }
683             // (***) FL: revisit
684             // invalidate Dec configuration
685             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
686             Cache_wait();
688             if (errno)
689             {
690                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
691                 return errno;
692             }
694 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
695             as_traceChannels(pAsitCfg, z);
696 #endif
698             // Compute decoder frame length based on source selection
699             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
701             pAstCfg->xDec[z].decodeControl.frameLength  = frameLength;
702             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
703 /* //JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
704             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
705             ioDataCtl.param.frameLengthPcm = frameLength;
706             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
707 */
708         } // hIoPhy && decodeStatus.mode
709         else {
710             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
711         }
712     } // z=DECODE1 to DECODEN
714     return ASIP_NO_ERR;
716 } /* decDecodeData */
719 Int decDecodeComplete( const PAF_ASIT_Params *pP,
720                        PAF_ASIT_Config *pAsitCfg)
722     int z, zMD, decError;
723     ALG_Handle alg[DECODEN_MAX];
725     zMD = pAsitCfg->pAstCfg->masterDec;
727     for (z=DECODE1; z < DECODEN; z++)
728     {
729         alg[z] = pAsitCfg->pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
730     }
731     alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
733     // Call decodeComplete: 2nd argument is NOT used inside the function
734     decError = pP->fxns->decodeComplete(pP, NULL, pAsitCfg, alg,
735                                         pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
737     if(decError) {
738         return ASIP_ERR_DECODE_COMPLETE;
739     }
741     return ASIP_NO_ERR;
742 }  /* decDecodeComplete */
745 #if 0
746 Int asipDecodeProcessing(
747         const PAF_ASIT_Params *pP,
748         const PAF_ASIT_Patchs *pQ,
749         PAF_ASIT_Config *pC,
750         Int sourceSelect)
752     PAF_AST_Config *pAstCfg;
753     Int errno, retVal;                          /* error number */
754     Int zMD;
756     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
757     zMD = pAstCfg->masterDec;
758     retVal = ASIP_NO_ERR;
760     //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
761     errno = decDecodeInfo(pP, pQ, pC);
762     if (errno != ASIP_NO_ERR) {
763         //gAsipInfo1_PrimaryErrCnt++;
764         TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
765         retVal =  ASIP_ERR_DECODE_INFO;
766     }
767     else {
768         // Don't start decode until major access unit is found.
769         Int8 sourceDecode, sampleRate;
770         sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
771                                          GATEMP_INDEX_DEC);
772         sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
773                                          GATEMP_INDEX_DEC);
774         if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
775                (sourceDecode == PAF_SOURCE_DXP)     ||
776                (sourceDecode == PAF_SOURCE_DTSHD) ) &&
777              ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
778             /* do nothing and return - waiting for major access unit */
779             pC->inpDec.frame++;
780             retVal =  ASIP_NO_ERR;
781         }
782         else {
783             errno = decDecodeData(pP, pQ, pC, sourceSelect);
784             if (errno != ASIP_NO_ERR) {
785                 //gAsipDecodeErrCnt++;
786                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
787                 retVal = ASIP_ERR_DECODE_DATA;
788             }
789             else {
790                 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pC->inpDec.frame, pC->inpDec.block);
791                 if (errno) {
792                     retVal = ASIP_ERR_DECODE_FINAL;
793                 }
794                 else {
795                     retVal = ASIP_NO_ERR;
796                 }
797             }
798         }
799     }
801     return retVal;
802 }  /* asipDecodeProcessing */
803 #endif
805 /* Nothing past this line */