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