[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / audioStreamInpProc.c
1 /*
2 * ======== audioStreamInpProc.c ========
3 */
5 #include <xdc/std.h>
6 #include <xdc/cfg/global.h>
7 #include <xdc/runtime/Diags.h>
8 #include <xdc/runtime/Error.h>
9 #include <xdc/runtime/Log.h>
10 #include <xdc/runtime/Memory.h>
11 #include <xdc/runtime/System.h>
12 #include <ti/sysbios/BIOS.h>
13 #include <ti/sysbios/hal/Hwi.h>
14 #include <ti/sysbios/hal/Cache.h>
15 #include <ti/sysbios/knl/Clock.h>
16 #include <ti/sysbios/knl/Task.h>
17 #include <ti/ipc/Ipc.h>
18 #include <ti/ipc/MessageQ.h>
19 #include <ti/ipc/MultiProc.h>
21 #include <sio.h>
22 #include <pafsio_ialg.h>
24 #include "common.h"
25 #include "paf_heapMgr.h"
26 #include "aspMsg_common.h"
27 #include "aspMsg_master.h"
28 #include "audioStreamProc_common.h"
29 #include "audioStreamInpProc.h"
31 // FL: porting
32 #include "fwkSim.h"
33 //#include "fwkPort.h"
34 // FL: debug
35 #include "dbgCapAf.h"
38 // -----------------------------------------------------------------------------
39 // Debugging Trace Control, local to this file.
40 //
41 #include "logp.h"
43 #define TRACE_ARC(a)
45 // allows you to set a different trace module in pa.cfg
46 #define TR_MOD trace
48 // Allow a developer to selectively enable tracing.
49 #define CURRENT_TRACE_MASK 0x21
51 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
52 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
53 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
54 #define TRACE_MASK_DATA 0x08 // Show data
55 #define TRACE_MASK_TIME 0x10 // Timing related traces
56 #define TRACE_MASK_MSG 0x20 // Message related traces
58 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
59 #undef TRACE_TERSE0
60 #undef TRACE_TERSE1
61 #undef TRACE_TERSE2
62 #undef TRACE_TERSE3
63 #undef TRACE_TERSE4
64 #define TRACE_TERSE0(a)
65 #define TRACE_TERSE1(a,b)
66 #define TRACE_TERSE2(a,b,c)
67 #define TRACE_TERSE3(a,b,c,d)
68 #define TRACE_TERSE4(a,b,c,d,e)
69 #endif
71 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
72 #undef TRACE_GEN0
73 #undef TRACE_GEN1
74 #undef TRACE_GEN2
75 #undef TRACE_GEN3
76 #undef TRACE_GEN4
77 #define TRACE_GEN0(a)
78 #define TRACE_GEN1(a,b)
79 #define TRACE_GEN2(a,b,c)
80 #define TRACE_GEN3(a,b,c,d)
81 #define TRACE_GEN4(a,b,c,d,e)
82 #endif
84 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
85 // consolidate list of processing strings, indexed by PAF_SOURCE
86 static char *procName[] =
87 {
88 "", //PAF_SOURCE_UNKNOWN
89 "", //PAF_SOURCE_NONE
90 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
91 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
92 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
93 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
94 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
95 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
96 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
97 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
98 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
99 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
100 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
101 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
102 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
103 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
104 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
105 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
106 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
107 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
108 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
109 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
110 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
111 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
112 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
113 "AS%d: THD processing ...", //PAF_SOURCE_THD
114 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
115 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
116 };
118 #else
119 #undef TRACE_VERBOSE0
120 #undef TRACE_VERBOSE1
121 #undef TRACE_VERBOSE2
122 #undef TRACE_VERBOSE3
123 #undef TRACE_VERBOSE4
124 #define TRACE_VERBOSE0(a)
125 #define TRACE_VERBOSE1(a,b)
126 #define TRACE_VERBOSE2(a,b,c)
127 #define TRACE_VERBOSE3(a,b,c,d)
128 #define TRACE_VERBOSE4(a,b,c,d,e)
129 #endif
131 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
132 #define TRACE_DATA(a) LOG_printf a
133 #else
134 #define TRACE_DATA(a)
135 #endif
137 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
138 #define TRACE_TIME(a) LOG_printf a
139 #define TIME_MOD trace // this could be different
140 static Int dtime()
141 {
142 static Int old_time = 0;
143 Int time = TSK_time();
144 Int delta_time = time - old_time;
145 old_time = time;
146 return( delta_time);
147 }
149 static char *stateName[11] =
150 {
151 "INIT",
152 "INFO1",
153 "AGAIN",
154 "INFO2",
155 "CONT",
156 "TIME",
157 "DECODE",
158 "STREAM",
159 "ENCODE",
160 "FINAL",
161 "QUIT"
162 };
164 #else
165 #define TRACE_TIME(a)
166 #endif
168 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
169 #undef TRACE_MSG0
170 #undef TRACE_MSG1
171 #undef TRACE_MSG2
172 #undef TRACE_MSG3
173 #undef TRACE_MSG4
174 #define TRACE_MSG0(a)
175 #define TRACE_MSG1(a,b)
176 #define TRACE_MSG2(a,b,c)
177 #define TRACE_MSG3(a,b,c,d)
178 #define TRACE_MSG4(a,b,c,d,e)
179 #endif
182 // .............................................................................
184 #include <pafsio.h>
185 #include "paferr.h"
187 #include <acp_mds.h>
189 #include <pcm.h>
191 #include <pce.h>
193 #include <doberr.h>
195 #include <diberr.h>
197 #include <stdasp.h>
199 #include "as0.h"
200 #include "asperr.h"
202 #include "audioStreamProc_params.h"
203 #include "audioStreamProc_patchs.h"
204 #include "audioStreamProc_config.h"
206 //
207 // Audio Stream Definitions
208 //
210 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
211 #define MINFRAMELENGTH 24
212 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
214 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
215 Int PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error);
216 #endif
219 //
220 // Decoder Definitions
221 //
222 //#define decLinkInit pQ->i_decLinkInit
224 //
225 // Audio Stream Processing Definitions
226 //
227 //#define aspLinkInit pQ->i_aspLinkInit
229 //
230 // Encoder Definitions
231 //
232 #define encLinkInit pQ->i_encLinkInit
234 //
235 // Input, Output Definitions
236 //
237 #define inpLinkInit pP->i_inpLinkInit
238 //#define outLinkInit pP->i_outLinkInit
240 /* ---------------------------------------------------------------- */
241 /* Parameter macro definitions end here. */
242 /* ---------------------------------------------------------------- */
244 //
245 // Standardized Definitions
246 //
248 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
249 //#define ENC_Handle PCE_Handle /* works for all: PCE */
251 #define __TASK_NAME__ "TaskAsip"
253 LINNO_DEFN(TaskAsip); /* Line number macros */
254 ERRNO_DEFN(TaskAsip); /* Error number macros */
256 // Global debug counters */
257 UInt32 gTaskAsipCnt=0; // debug
258 UInt32 gAsipInitCnt =0;
259 UInt32 gAsipInfo1Cnt =0;
260 UInt32 gAsipInfo2Cnt =0;
261 UInt32 gAsipDecodeCnt =0;
262 UInt32 gAsipFinalCnt =0;
263 UInt32 gAsipQuitCnt =0;
264 #include "dbgDib.h"
266 extern struct {
267 Int size;
268 IALG_Status *pStatus[512];
269 } IACP_STD_BETA_TABLE;
272 /*
273 * ======== taskAsipFxn ========
274 * Audio Stream Input Processing task function
275 */
276 Void taskAsipFxn(
277 // Int betaPrimeValue, // FL: revisit
278 const PAF_AST_Params *pP,
279 const PAF_AST_Patchs *pQ
280 )
281 {
282 // Task data
283 //PAF_AST_Config PAF_AST_config; /* Local configuration */
284 //PAF_AST_Config *pC; /* Local configuration pointer */
285 // Local data
286 Int as; /* Audio Stream Number (1, 2, etc.) */
287 Int z; /* input/encode/stream/decode/output counter */
288 Int i; /* phase */
289 Int errno; /* error number */
290 Int zMD, zMI, zMS, zX;
291 Int loopCount = 0; // used to stop trace to see startup behavior.
292 UInt32 curTime;
293 Int size;
294 // Messaging
295 ASP_Msg *pAspMsg;
296 Int status;
298 Log_info0("Enter taskAsipFxn()");
300 #ifdef SIMULATE_SIO
301 /* Start simulation */
302 simStart();
303 #endif // SIMULATE_SIO
305 //
306 // Audio Framework Configuration (*pC):
307 //
308 pC = &gPAF_AST_config;
310 TRACE_TERSE1("TaskAsip: Started with betaPrimeValue=%d.", gBetaPrimeValue);
311 as = gBetaPrimeValue + 1; /* Audio Stream Number (1, 2, etc.) */
312 pC->as = as;
314 //
315 // Audio Framework Parameters & Patch (*pP, *pQ)
316 //
317 if (!pP)
318 {
319 TRACE_TERSE1("TaskAsip: AS%d: No Parameters defined. Exiting.", as);
320 LINNO_RPRT(TaskAsip, -1);
321 return;
322 }
324 if (!pQ)
325 {
326 TRACE_TERSE1("TaskAsip: AS%d: No Patchs defined. Exiting.", as);
327 LINNO_RPRT(TaskAsip, -1);
328 return;
329 }
331 //
332 // Initialize message log trace and line number reporting
333 //
334 for (z=STREAM1; z < STREAMN; z++)
335 {
336 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
337 }
338 LINNO_RPRT(TaskAsip, -1);
340 //
341 // Determine decoder and stream indices associated with the master input
342 //
343 zMI = pP->zone.master;
344 pC->masterDec = zMI;
345 pC->masterStr = zMI;
346 for (zX = DECODE1; zX < DECODEN; zX++)
347 {
348 if (pP->inputsFromDecodes[zX] == zMI)
349 {
350 pC->masterDec = zX;
351 pC->masterStr = pP->streamsFromDecodes[zX];
352 break;
353 }
354 }
355 zMD = pC->masterDec;
356 zMS = pC->masterStr;
358 // Initialize as per parametrized phases:
359 //
360 // In standard form these are:
361 // - Malloc: Memory Allocation
362 // - Config: Configuration Initialization
363 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
364 // - Common: Common Memory Initialization
365 // - AlgKey: Dec/Enc chain to Array Initialization
366 // - Device: I/O Device Initialization
367 // - Unused: (available)
368 // - Unused: (available)
369 //
370 LINNO_RPRT(TaskAsip, -2);
371 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
372 {
373 Int linno;
374 if (pP->fxns->initPhase[i])
375 {
376 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
377 {
378 LINNO_RPRT(TaskAsip, linno);
379 return;
380 }
381 }
382 else
383 {
384 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
385 }
386 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
387 LINNO_RPRT(TaskAsip, -i-3);
388 }
390 //
391 // End of Initialization -- display memory usage report.
392 //
393 if (pP->fxns->memStatusPrint)
394 {
395 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
396 }
398 // (***) FL: revisit
399 // write back configuration
400 Cache_wb(&gPAF_AST_config, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
401 Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
402 Cache_wait();
404 // (***) FL: revisit
405 // write Dec configuration
406 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
407 Cache_wait();
409 // (***) FL: revisit
410 // write back entire beta table
411 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
412 Cache_wait();
414 // FL: send start initialization message to slave
415 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
416 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
417 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
418 pAspMsg->procId = hAspMsgMaster->masterProcId;
419 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
420 pAspMsg->expectResp = TRUE;
421 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
422 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
423 if (status != MessageQ_S_SUCCESS)
424 {
425 SW_BREAKPOINT;
426 }
427 // wait for initialization complete message from slave
428 do {
429 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
430 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
431 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
432 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
433 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
434 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
435 {
436 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
437 SW_BREAKPOINT;
438 }
439 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
440 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
441 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
442 if (status != MessageQ_S_SUCCESS)
443 {
444 SW_BREAKPOINT;
445 }
447 // (***) FL: revisit
448 // invalidate Status structure addresses for Beta Units initialized on Slave
449 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
450 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
451 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
452 //Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
453 //Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
454 Cache_wait();
455 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
456 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
457 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
458 //if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
459 //if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
461 // (***) FL: revisit
462 // invalidate Status structures for Beta Units initialized on Slave
463 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
464 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
465 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
466 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
467 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
468 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
469 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
470 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
471 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
472 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
473 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
474 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
475 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
476 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
477 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
478 Cache_wait();
480 // (***) FL: revisit
481 // invalidate Dec configuration
482 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
483 Cache_wait();
485 //
486 // Main processing loop
487 //
488 for (z=STREAM1; z < STREAMN; z++)
489 {
490 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
491 }
493 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
495 errno = 0;
496 for (;;)
497 {
498 Int sourceSelect;
499 XDAS_Int8 sourceProgram;
501 loopCount++;
503 #if 0 // enable and tune to see startup behavior.
504 // this is an alternative to fixed/circular setting in pa.cfg.
505 // If you are searching for a memory allocation failure, disable on first round.
506 // All allocation has already happened.
507 // This is the outer loop. This loop count goes up when the stream resets.
508 // If the stream is running without problems, this does not increment.
509 // If the stream is repeatedly resetting, this loop count will go up rapidly.
510 if (loopCount > 10) // see traces for a few of the passes through the main loop.
511 {
512 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
513 LOG_disable(&TR_MOD); // stop tracing
514 }
515 #endif
517 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
518 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
520 // since not decoding indicate such
521 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
523 // any error forces idling of input
524 if (errno)
525 {
526 for (z=INPUT1; z < INPUTN; z++)
527 {
528 if (pC->xInp[z].hRxSio)
529 {
530 SIO_idle(pC->xInp[z].hRxSio);
531 }
532 }
534 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
535 ERRNO_RPRT(TaskAsip, errno);
536 }
538 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
539 // up to allow lower priority tasks to run. This may seem odd to be at the top
540 // of the state machine but provides for a cleaner flow even though the very
541 // first time we enter we do a sleep which is non-intuitive.
542 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
543 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
544 Task_sleep(1);
546 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
547 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
548 {
549 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
550 continue;
551 }
553 // if no master input selected then we don't know what may be at the input
554 // so set to unknown and skip any remaining processing
555 if (!pC->xInp[zMI].hRxSio)
556 {
557 pC->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
558 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
559 continue;
560 }
562 // if here then we have a valid input so query its status
563 if (errno = pP->fxns->updateInputStatus(pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufStatus, &pC->xInp[zMI].inpBufConfig))
564 {
565 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
566 continue;
567 }
569 // If master decoder is not enabled, or the input is unlocked, then do nothing
570 if (!pC->xDec[zMD].decodeStatus.mode || !pC->xInp[zMI].inpBufStatus.lock)
571 {
572 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
573 continue;
574 }
576 // If no source selected then do nothing
577 if (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
578 {
579 pC->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
580 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
581 continue;
582 }
584 // If we want pass processing then proceed directly
585 if (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
586 {
587 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
588 pC->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
589 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
590 if (pP->fxns->passProcessing)
591 {
592 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
593 }
594 else
595 {
596 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
597 errno = ASPERR_PASS;
598 }
599 TRACE_VERBOSE0("TaskAsip: continue");
600 continue;
601 }
603 // .....................................................................
604 // At this point we have an enabled input and want to decode something.
605 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
606 // when no decoder is selected there are no calls to IB
607 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
608 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, NULL)) // (***) FL: hard-coded to use PCM framelength inside function
609 {
610 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
611 continue;
612 }
614 // query for input type
615 if (errno = SIO_ctrl(pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
616 {
617 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
618 errno = ASPERR_AUTO_PROGRAM;
619 continue;
620 }
621 pC->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
623 // if input is unclassifiable then do nothing
624 if (sourceProgram == PAF_SOURCE_UNKNOWN)
625 {
626 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
627 continue;
628 }
630 // now that we have some input classification, and possibly an outstanding
631 // input frame, we determine whether or not to call decodeProcessing and with
632 // what decAlg.
633 sourceSelect = PAF_SOURCE_NONE;
634 switch (pC->xDec[zMD].decodeStatus.sourceSelect)
635 {
636 // If autodetecting, decoding everything, and input is something
637 // (i.e. bitstream or PCM) then decode.
638 case PAF_SOURCE_AUTO:
639 if (sourceProgram >= PAF_SOURCE_PCM)
640 {
641 sourceSelect = sourceProgram;
642 }
643 break;
645 // If autodetecting, decoding only PCM, and input is PCM then decode.
646 case PAF_SOURCE_PCMAUTO:
647 if (sourceProgram == PAF_SOURCE_PCM)
648 {
649 sourceSelect = sourceProgram;
650 }
651 break;
653 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
654 case PAF_SOURCE_BITSTREAM:
655 if (sourceProgram >= PAF_SOURCE_AC3)
656 {
657 sourceSelect = sourceProgram;
658 }
659 break;
661 // If autodetecting, decoding only DTS, and input is DTS then decode.
662 case PAF_SOURCE_DTSALL:
663 switch (sourceProgram)
664 {
665 case PAF_SOURCE_DTS11:
666 case PAF_SOURCE_DTS12:
667 case PAF_SOURCE_DTS13:
668 case PAF_SOURCE_DTS14:
669 case PAF_SOURCE_DTS16:
670 case PAF_SOURCE_DTSHD:
671 sourceSelect = sourceProgram;
672 break;
673 }
674 break;
676 // All others, e.g., force modes, fall through to here.
677 // If user made specific selection then program must match select.
678 // (NB: this compare relies on ordering of PAF_SOURCE)
679 default:
680 sourceSelect = pC->xDec[zMD].decodeStatus.sourceSelect;
681 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
682 {
683 if (sourceProgram != sourceSelect)
684 {
685 sourceSelect = PAF_SOURCE_NONE;
686 }
687 }
688 break;
689 }
691 // if we didn't find any matches then skip
692 if (sourceSelect == PAF_SOURCE_NONE)
693 {
694 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
695 continue;
696 }
698 // FL: debug, reset IB capture buffer
699 //capIbReset();
700 //Log_info0("capIbReset()");
702 // FL: send source select message to slave
703 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
704 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
705 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
706 pAspMsg->procId = hAspMsgMaster->masterProcId;
707 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
708 pAspMsg->expectResp = TRUE;
709 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
710 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
711 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
712 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
713 if (status != MessageQ_S_SUCCESS)
714 {
715 SW_BREAKPOINT;
716 }
717 // wait for source select complete message from slave
718 //do {
719 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
720 //} while (status != MessageQ_S_SUCCESS);
721 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
722 if (status != MessageQ_S_SUCCESS)
723 {
724 TRACE_TERSE0("MessageQ_get() failure.");
725 SW_BREAKPOINT; // temporary
726 }
727 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
728 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
729 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
730 {
731 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
732 SW_BREAKPOINT;
733 }
734 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
735 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
736 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
737 if (status != MessageQ_S_SUCCESS)
738 {
739 SW_BREAKPOINT;
740 }
742 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
743 // iff we are in this top level state machine and specifically not in decodeProcessing
744 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
746 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
748 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
749 //errno = pP->fxns->decodeProcessing(pP, pQ, pC, pC->xDec[zMD].decAlg[sourceSelect]);
750 //errno = pP->fxns->decodeProcessing(pP, pQ, pC, NULL); // (***) FL: dec handle doesn't exist on Master (DSP)
751 //errno = pP->fxns->decodeProcessing(pP, pQ, pC, NULL, sourceSelect);
752 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
753 if (errno)
754 {
755 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
756 }
757 else
758 {
759 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
760 }
762 // FL: send dec exit message to slave
763 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
764 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
765 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
766 pAspMsg->procId = hAspMsgMaster->masterProcId;
767 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
768 pAspMsg->expectResp = TRUE;
769 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
770 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
771 if (status != MessageQ_S_SUCCESS)
772 {
773 SW_BREAKPOINT;
774 }
775 // wait for dec exit complete message from slave
776 //do {
777 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
778 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
779 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
780 if (status != MessageQ_S_SUCCESS)
781 {
782 TRACE_TERSE0("MessageQ_get() failure.");
783 SW_BREAKPOINT; // temporary
784 }
785 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
786 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
787 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
788 {
789 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
790 SW_BREAKPOINT;
791 }
792 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
793 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
794 // free the message
795 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
796 if (status != MessageQ_S_SUCCESS)
797 {
798 SW_BREAKPOINT;
799 }
800 } // End of main processing loop for (;;)
802 Log_info0("Exit taskAsipFxn()");
803 }
805 // -----------------------------------------------------------------------------
806 // ASIT Initialization Function - Memory Allocation
807 //
808 // Name: PAF_ASIT_initPhaseMalloc
809 // Purpose: Audio Stream Input Task Function for initialization of data pointers
810 // by allocation of memory.
811 // From: audioStream1Task or equivalent
812 // Uses: See code.
813 // States: x
814 // Return: 0 on success.
815 // Source code line number on MEM_calloc failure.
816 // Trace: Message Log "trace" in Debug Project Configuration reports:
817 // * State information as per parent.
818 // * Memory allocation errors.
819 //
820 Int
821 PAF_ASIT_initPhaseMalloc(
822 const PAF_AST_Params *pP,
823 const PAF_AST_Patchs *pQ,
824 PAF_AST_Config *pC
825 )
826 {
827 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
828 Int zMS = pC->masterStr;
829 Error_Block eb;
830 Int i;
832 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
834 // Initialize error block
835 Error_init(&eb);
837 /* Input memory */
838 if (!(pC->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, INPUTN * sizeof (*pC->xInp), 4, &eb)))
839 {
840 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
841 SW_BREAKPOINT;
842 return __LINE__;
843 }
844 TRACE_TERSE3("PAF_AST_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
845 INPUTN * sizeof (*pC->xInp),
846 HEAP_ID_INTERNAL1_SHM, (IArg)pC->xInp);
848 /* Decode memory */
849 if (!(pC->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, DECODEN * sizeof (*pC->xDec), 4, &eb)))
850 {
851 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
852 SW_BREAKPOINT;
853 return __LINE__;
854 }
855 TRACE_TERSE3("PAF_AST_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
856 DECODEN * sizeof (*pC->xDec),
857 HEAP_ID_INTERNAL1_SHM, (IArg)pC->xDec);
859 {
860 // FL: added for decode output circular buffer
861 // FL: (***)revisit
862 Int z; /* decode counter */
864 for (z=DECODE1; z < DECODEN; z++)
865 {
866 // allocate audio frame circular buffer
867 if (!(pC->xDec[z].decOpCb.afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
868 {
869 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
870 SW_BREAKPOINT;
871 }
872 // allocate audio frame PCM sample pointer array
873 for (i = 0; i<PAF_DECOP_CB_MAX_NUM_AF; i++)
874 {
875 if (!(pC->xDec[z].decOpCb.afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioData *), 4, &eb)))
876 {
877 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
878 SW_BREAKPOINT;
879 }
880 if (!(pC->xDec[z].decOpCb.afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioSize), 4, &eb)))
881 {
882 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
883 SW_BREAKPOINT;
884 }
885 }
886 // allocate PCM sample buffer
887 if (!(pC->xDec[z].decOpCb.pcmBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
888 {
889 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
890 SW_BREAKPOINT;
891 }
892 // allocate Metadata buffers //QIN
893 if (!(pC->xDec[z].decOpCb.metaBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
894 {
895 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
896 SW_BREAKPOINT;
897 }
898 }
899 }
901 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
902 return 0;
903 } //PAF_ASIT_initPhaseMalloc
905 // -----------------------------------------------------------------------------
906 // ASIT Initialization Function - Memory Initialization from Configuration
907 //
908 // Name: PAF_ASIT_initPhaseConfig
909 // Purpose: Audio Stream Task Function for initialization of data values
910 // from parameters.
911 // From: audioStream1Task or equivalent
912 // Uses: See code.
913 // States: x
914 // Return: 0 on success.
915 // Other as per initFrame0 and initFrame1.
916 // Trace: Message Log "trace" in Debug Project Configuration reports:
917 // * State information as per parent.
918 //
919 Int
920 PAF_ASIT_initPhaseConfig(
921 const PAF_AST_Params *pP,
922 const PAF_AST_Patchs *pQ,
923 PAF_AST_Config *pC
924 )
925 {
926 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
927 Int z; /* input/encode/stream/decode/output counter */
928 Int zMS = pC->masterStr;
929 Int errno; /* error number */
930 PAF_DecodeOpCircBuf *pCb; /* Decoder output circular buffer */
932 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
934 //
935 // Unspecified elements have been initialized to zero during alloc
936 //
938 for (z=INPUT1; z < INPUTN; z++)
939 {
940 pC->xInp[z].inpBufStatus = *pP->pInpBufStatus;
941 pC->xInp[z].inpBufConfig.pBufStatus = &pC->xInp[z].inpBufStatus;
942 }
944 for (z=DECODE1; z < DECODEN; z++)
945 {
946 Int zI = pP->inputsFromDecodes[z];
947 pC->xDec[z].decodeControl.size = sizeof(pC->xDec[z].decodeControl);
948 pC->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pC->xInp[zI].inpBufConfig;
949 pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
951 // Initialize decoder output circular buffer
952 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
953 pCb = &pC->xDec[z].decOpCb;
954 errno = cbInit(PAF_SOURCE_PCM, 256, FRAMELENGTH, pCb);
955 if (errno)
956 {
957 return errno;
958 }
959 }
961 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
962 return 0;
963 } //PAF_ASIT_initPhaseConfig
965 // -----------------------------------------------------------------------------
966 // ASIT Initialization Function - ACP Algorithm Instantiation
967 //
968 // Name: PAF_ASIT_initPhaseAcpAlg
969 // Purpose: Audio Stream Input Task Function for initialization of ACP by
970 // instantiation of the algorithm.
971 // From: audioStream1Task or equivalent
972 // Uses: See code.
973 // States: x
974 // Return: 0 on success.
975 // Source code line number on ACP Algorithm creation failure.
976 // Trace: Message Log "trace" in Debug Project Configuration reports:
977 // * State information as per parent.
978 // * Memory allocation errors.
979 //
980 Int
981 PAF_ASIT_initPhaseAcpAlg(
982 const PAF_AST_Params *pP,
983 const PAF_AST_Patchs *pQ,
984 PAF_AST_Config *pC
985 )
986 {
987 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
988 Int z; /* input/encode/stream/decode/output counter */
989 Int betaPrimeOffset;
990 ACP_Handle acp;
991 Int zMS = pC->masterStr;
992 Int zS, zX;
994 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
996 ACP_MDS_init();
998 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
999 {
1000 TRACE_TERSE1("PAF_AST_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1001 return __LINE__;
1002 }
1003 pC->acp = acp;
1005 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1006 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1008 for (z=INPUT1; z < INPUTN; z++)
1009 {
1010 zS = z;
1011 for (zX = DECODE1; zX < DECODEN; zX++)
1012 {
1013 if (pP->inputsFromDecodes[zX] == z)
1014 {
1015 zS = pP->streamsFromDecodes[zX];
1016 break;
1017 }
1018 }
1019 acp->fxns->attach(acp, ACP_SERIES_STD,
1020 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1021 (IALG_Status *)&pC->xInp[z].inpBufStatus);
1022 /* Ignore errors, not reported. */
1023 }
1025 #if 0 // FL: slave
1026 for (z=DECODE1; z < DECODEN; z++)
1027 {
1028 zS = pP->streamsFromDecodes[z];
1029 acp->fxns->attach(acp, ACP_SERIES_STD,
1030 STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1031 (IALG_Status *)&pC->xDec[z].decodeStatus);
1032 /* Ignore errors, not reported. */
1033 }
1034 #endif
1036 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1038 return 0;
1039 } //PAF_ASIT_initPhaseAcpAlg
1041 // -----------------------------------------------------------------------------
1042 // ASIT Initialization Function - Common Memory
1043 //
1044 // Name: PAF_ASIT_initPhaseCommon
1045 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1046 // From: audioStream1Task or equivalent
1047 // Uses: See code.
1048 // States: x
1049 // Return: 0 on success.
1050 // Source code line number on PAF_ALG_alloc failure.
1051 // Source code line number on PAF_ALG_mallocMemory failure.
1052 // Source code line number on Decode Chain initialization failure.
1053 // Source code line number on ASP Chain initialization failure.
1054 // Source code line number on Encode Chain initialization failure.
1055 // Trace: Message Log "trace" in Debug Project Configuration reports:
1056 // * State information as per parent.
1057 // * Memory allocation errors.
1058 //
1059 Int
1060 PAF_ASIT_initPhaseCommon(
1061 const PAF_AST_Params *pP,
1062 const PAF_AST_Patchs *pQ,
1063 PAF_AST_Config *pC
1064 )
1065 {
1066 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1067 Int z; /* stream counter */
1068 //Int g; /* gear */
1069 ACP_Handle acp = pC->acp;
1070 PAF_IALG_Config pafAlgConfig;
1071 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1073 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1075 //
1076 // Determine memory needs and instantiate algorithms across audio streams
1077 //
1078 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1079 PAF_ALG_setup(&pafAlgConfig,
1080 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1081 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1082 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1083 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1084 HEAP_CLEAR);
1086 if (pP->fxns->headerPrint)
1087 {
1088 pP->fxns->headerPrint();
1089 }
1091 for (z = STREAM1; z < STREAMN; z++)
1092 {
1093 //Int zD, zE, zX;
1095 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1097 //
1098 // Determine common memory for:
1099 // (1) Logical Input drivers
1100 //
1101 // Decode Algorithms common memory determined in ASP Slave.
1102 //
1103 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1105 #if 0 // FL: slave
1106 zD = -1;
1107 for (zX = DECODE1; zX < DECODEN; zX++)
1108 {
1109 if (pP->streamsFromDecodes[zX] == z)
1110 {
1111 zD = zX;
1112 break;
1113 }
1114 }
1115 #endif
1117 #if 0 // FL: slave
1118 if (zD >= 0)
1119 {
1120 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for decoder common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1121 if (PAF_ALG_ALLOC(decLinkInit[zD-DECODE1], common[z]))
1122 {
1123 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1124 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1126 SW_BREAKPOINT;
1127 return __LINE__;
1128 }
1129 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1130 if (pP->fxns->allocPrint)
1131 {
1132 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1133 }
1134 }
1135 #endif
1137 //
1138 // Determine common memory needs of Logical Input driver
1139 //
1141 // really need to loop over all inputs for this stream using the tables
1142 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1143 // patch, and not needed for FS11, since there is only one input.
1144 if (INPUT1 <= z && z < INPUTN)
1145 {
1146 TRACE_TERSE2("AS%d: PAF_ASIT_initPhaseCommon: alloc inpLinkInit common[%d]", as+z, z);
1147 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1148 {
1149 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
1150 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1151 SW_BREAKPOINT;
1152 return __LINE__;
1153 }
1154 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1155 if (pP->fxns->allocPrint)
1156 {
1157 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1158 }
1159 }
1160 }
1161 {
1162 // Changes made to share scratch between zones
1163 // Assume maximum 3 zones and scratch common memory is at offset 0;
1164 int max=0;
1165 for (z=STREAM1; z<STREAMN; z++)
1166 {
1167 if (max < common[z][0].size)
1168 {
1169 max = common[z][0].size;
1170 }
1171 }
1172 common[STREAM1][0].size=max;
1173 for (z=STREAM1+1; z<STREAMN; z++)
1174 {
1175 common[z][0].size = 0;
1176 }
1177 }
1179 //
1180 // Allocate common memory for:
1181 // (1) Logical Input drivers
1182 //
1183 for (z = STREAM1; z < STREAMN; z++)
1184 {
1185 //Int zD, zE, zX;
1187 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1188 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1189 {
1190 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
1191 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1192 SW_BREAKPOINT;
1193 return __LINE__;
1194 }
1195 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1196 // share zone0 scratch with all zones
1197 common[z][0].base = common[0][0].base;
1198 if (pP->fxns->commonPrint)
1199 {
1200 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1201 }
1203 #if 0 // FL: slave
1204 zD = -1;
1205 for (zX = DECODE1; zX < DECODEN; zX++)
1206 {
1207 if (pP->streamsFromDecodes[zX] == z)
1208 {
1209 zD = zX;
1210 break;
1211 }
1212 }
1213 #endif
1215 #if 0 // FL: slave
1216 if (zD >= 0)
1217 {
1218 PAF_ASP_Chain *chain;
1219 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1220 chain = PAF_ASP_chainInit(&pC->xDec[zD].decChainData, pP->pChainFxns,
1221 HEAP_INTERNAL, as+z, acp, &trace,
1222 decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1223 if (!chain)
1224 {
1225 TRACE_TERSE1("AS%d: Decode chain initialization failed", as+z);
1226 return __LINE__;
1227 }
1228 }
1229 #endif
1231 //
1232 // Allocate non-common memories for Logical IO drivers
1233 // Since these structures are used at run-time we allocate from external memory
1234 if (INPUT1 <= z && z < INPUTN)
1235 {
1236 PAF_ASP_Chain *chain;
1237 TRACE_TERSE2("PAF_AST_initPhaseMalloc: AS%d: non-common input chain init for %d",
1238 as+z, z);
1239 chain = PAF_ASP_chainInit(&pC->xInp[z].inpChainData, pP->pChainFxns,
1240 HEAP_EXTERNAL, as+z, acp, &trace,
1241 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1242 if (!chain)
1243 {
1244 TRACE_TERSE1("AS%d: Input chain initialization failed", as+z);
1245 return __LINE__;
1246 }
1247 }
1248 }
1249 TRACE_TERSE1("AS%d: PAF_ASIT_initPhaseCommon: Returning complete.", as+z);
1251 return 0;
1252 } //PAF_ASIT_initPhaseCommon
1254 // -----------------------------------------------------------------------------
1255 // ASIT Initialization Function - Algorithm Keys
1256 //
1257 // Name: PAF_ASIT_initPhaseAlgKey
1258 // Purpose: Audio Stream Input Task Function for initialization of data values
1259 // from parameters for Algorithm Keys.
1260 // From: audioStream1Task or equivalent
1261 // Uses: See code.
1262 // States: x
1263 // Return: 0.
1264 // Trace: Message Log "trace" in Debug Project Configuration reports:
1265 // * State information as per parent.
1266 //
1267 // .............................................................................
1268 Int
1269 PAF_ASIT_initPhaseAlgKey(
1270 const PAF_AST_Params *pP,
1271 const PAF_AST_Patchs *pQ,
1272 PAF_AST_Config *pC
1273 )
1274 {
1275 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1276 #if 0
1277 Int z; /* decode/encode counter */
1278 Int s; /* key number */
1279 PAF_ASP_Link *that;
1280 #endif
1282 (void)as; // clear compiler warning in case not used with tracing disabled
1284 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1286 #if 0 // FL: slave
1287 for (z=DECODE1; z < DECODEN; z++)
1288 {
1289 for (s=0; s < pP->pDecAlgKey->length; s++)
1290 {
1291 if ((pP->pDecAlgKey->code[s].full != 0) &&
1292 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1293 {
1294 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1295 /* Cast in interface, for now --Kurt */
1296 }
1297 else
1298 {
1299 pC->xDec[z].decAlg[s] = NULL;
1300 }
1301 }
1302 }
1303 #endif
1305 return 0;
1306 } //PAF_ASIT_initPhaseAlgKey
1308 // -----------------------------------------------------------------------------
1309 // ASIT Initialization Function - I/O Devices
1310 //
1311 // Name: PAF_ASIT_initPhaseDevice
1312 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1313 // From: audioStream1Task or equivalent
1314 // Uses: See code.
1315 // States: x
1316 // Return: 0 on success.
1317 // Source code line number on device allocation failure.
1318 // Trace: Message Log "trace" in Debug Project Configuration reports:
1319 // * State information as per parent.
1320 // * Memory allocation errors.
1321 //
1322 Int
1323 PAF_ASIT_initPhaseDevice(
1324 const PAF_AST_Params *pP,
1325 const PAF_AST_Patchs *pQ,
1326 PAF_AST_Config *pC
1327 )
1328 {
1329 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1330 Int z; /* input/output counter */
1331 PAF_SIO_IALG_Obj *pObj;
1332 PAF_SIO_IALG_Config *pAlgConfig;
1333 PAF_IALG_Config pafAlgConfig;
1335 (void)as; // clear compiler warning in case not used with tracing disabled
1337 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1339 if(pP->fxns->bufMemPrint)
1340 {
1341 PAF_ALG_setup (&pafAlgConfig,
1342 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1343 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1344 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1345 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1346 HEAP_CLEAR);
1347 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1348 }
1350 for (z=INPUT1; z < INPUTN; z++)
1351 {
1352 PAF_InpBufConfig *pConfig = &pC->xInp[z].inpBufConfig;
1354 pObj = (PAF_SIO_IALG_Obj *)pC->xInp[z].inpChainData.head->alg;
1355 pAlgConfig = &pObj->config;
1357 pC->xInp[z].hRxSio = NULL;
1359 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1360 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1361 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1362 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1363 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1364 pConfig->sizeofElement = 2;
1365 pConfig->precision = 16;
1367 if(pP->fxns->bufMemPrint)
1368 {
1369 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),0);
1370 }
1371 }
1372 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1374 return 0;
1375 } //PAF_ASIT_initPhaseDevice
1377 #if 0
1378 // -----------------------------------------------------------------------------
1379 // AST Processing Function - Pass-Through Processing
1380 //
1381 // Name: PAF_AST_passProcessing
1382 // Purpose: Audio Stream Task Function for processing audio data as a
1383 // pass-through from the input driver to the output driver
1384 // for development and testing.
1385 // From: audioStream1Task or equivalent
1386 // Uses: See code.
1387 // States: x
1388 // Return: Error number in standard form (0 on success).
1389 // Trace: Message Log "trace" in Debug Project Configuration reports:
1390 // * State information on initialization.
1391 // * State information on processing.
1392 //
1394 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1395 /* Pass Processing is often omitted from builds to save memory, */
1396 /* and CODE_SECTION/clink constructs facilitate this omission. */
1398 Int
1399 PAF_AST_passProcessing (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1400 {
1401 Int z; /* input/output counter */
1402 Int errno = 0; /* error number */
1403 Int getVal;
1404 Int rxNumChan, txNumChan;
1405 Int first;
1406 Int zMD = pC->masterDec;
1407 Int zMI = pP->zone.master;
1410 #ifndef __TI_EABI__
1411 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1412 #endif
1414 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1416 //
1417 // Determine that receive/transmit channels are compatible
1418 //
1420 // Can handle handle only master input
1421 for (z=INPUT1; z < INPUTN; z++) {
1422 if (z != zMI && pC->xInp[z].hRxSio)
1423 return (ASPERR_PASS + 0x01);
1424 }
1426 /* Number of receive/transmit channels */
1428 if (! pC->xInp[zMI].hRxSio)
1429 return (ASPERR_PASS + 0x11);
1430 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1431 return (ASPERR_PASS + 0x12);
1432 if (rxNumChan > NUM_TX_CHAN(zMI))
1433 return (ASPERR_PASS + 0x13);
1435 for (z=OUTPUT1; z < OUTPUTN; z++) {
1436 if (! pC->xOut[zMI].hTxSio)
1437 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1438 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1439 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1440 if (txNumChan > NUM_TX_CHAN(zMI))
1441 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1442 }
1444 //
1445 // Set up receive/transmit
1446 //
1448 SIO_idle (pC->xInp[zMI].hRxSio);
1449 for (z=OUTPUT1; z < OUTPUTN; z++) {
1450 if(SIO_idle (pC->xOut[z].hTxSio))
1451 return ASPERR_IDLE;
1452 }
1454 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1455 return (ASPERR_PASS + 0x14);
1457 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1458 return (ASPERR_PASS + 0x15);
1460 for (z=OUTPUT1; z < OUTPUTN; z++)
1461 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1463 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1464 return ASPERR_PASS + 0x16;
1466 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1467 return ASPERR_PASS + 0x17;
1469 //
1470 // Receive and transmit the data in single-frame buffers
1471 //
1473 first = 1;
1474 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1475 PAF_OutBufConfig *pOutBuf;
1476 PAF_InpBufConfig *pInpBuf;
1478 if (first) {
1479 first = 0;
1481 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1483 for (z=OUTPUT1; z < OUTPUTN; z++) {
1484 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1485 if (getVal > 0) {
1486 errno = ASPERR_ISSUE;
1487 break;
1488 }
1489 else if (getVal < 0) {
1490 errno = -getVal;
1491 break;
1492 }
1494 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1495 return (getVal & 0xff) | ASPERR_MUTE;
1496 }
1497 if (errno)
1498 break;
1500 }
1502 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1503 if (getVal > 0) {
1504 errno = ASPERR_ISSUE;
1505 break;
1506 }
1508 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1510 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1511 if (getVal < 0) {
1512 errno = -getVal;
1513 break;
1514 }
1516 for (z=OUTPUT1; z < OUTPUTN; z++) {
1517 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1518 if (getVal < 0) {
1519 errno = -getVal;
1520 break;
1521 }
1522 }
1523 if( errno )
1524 break;
1526 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1528 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1529 break;
1531 for (z=OUTPUT1; z < OUTPUTN; z++) {
1532 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1533 if (getVal > 0) {
1534 errno = ASPERR_ISSUE;
1535 break;
1536 }
1537 else if (getVal < 0) {
1538 errno = -getVal;
1539 break;
1540 }
1541 }
1542 if( errno )
1543 break;
1544 }
1546 //
1547 // Close down receive/transmit
1548 //
1550 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1552 for (z=OUTPUT1; z < OUTPUTN; z++) {
1553 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1554 if (! errno)
1555 errno = (getVal & 0xff) | ASPERR_MUTE;
1556 /* convert to sensical errno */
1557 }
1558 }
1560 SIO_idle (pC->xInp[zMI].hRxSio);
1561 for (z=OUTPUT1; z < OUTPUTN; z++)
1562 SIO_idle (pC->xOut[z].hTxSio);
1564 return errno;
1566 } //PAF_AST_passProcessing
1567 #endif
1569 #if 0
1570 // -----------------------------------------------------------------------------
1571 // AST Processing Function Helper - Pass-Through Processing Patch Point
1572 //
1573 // Name: PAF_AST_passProcessingCopy
1574 // Purpose: Pass-Through Processing Function for copying audio data
1575 // from the input buffer to the output buffer.
1576 // From: AST Parameter Function -> passProcessing
1577 // Uses: See code.
1578 // States: x
1579 // Return: Error number in standard form (0 on success).
1580 // Trace: Message Log "trace" in Debug Project Configuration reports:
1581 // x
1582 //
1584 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1585 /* Pass Processing is often omitted from builds to save memory, */
1586 /* and CODE_SECTION/clink constructs facilitate this omission. */
1588 Int
1589 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1590 {
1591 Int z; /* output counter */
1592 Int errno; /* error number */
1593 Int i;
1594 Int rxNumChan, txNumChan;
1595 Int zMI = pP->zone.master;
1598 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1600 // Copy data from input channels to output channels one of two ways:
1602 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1603 return (ASPERR_PASS + 0x12);
1605 for (z=OUTPUT1; z < OUTPUTN; z++) {
1606 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1607 return (ASPERR_PASS + 0x22);
1609 if( txNumChan <= rxNumChan ) {
1611 // Copy one to one, ignoring later rx channels as needed.
1613 for( i=0; i < txNumChan; i++ ) {
1614 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1615 if( errno )
1616 return errno;
1617 }
1618 }
1619 else {
1621 // Copy one to many, repeating earlier rx channels as needed.
1623 Int from, to;
1625 from = 0;
1626 to = 0;
1627 while( to < txNumChan ) {
1628 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1629 if( errno )
1630 return errno;
1632 from++;
1633 to++;
1634 if( from == rxNumChan )
1635 from = 0;
1636 }
1637 }
1638 }
1640 return 0;
1641 } //PAF_AST_passProcessingCopy
1642 #endif
1644 // -----------------------------------------------------------------------------
1645 // ASIT Processing Function - Auto Processing
1646 //
1647 // Name: PAF_ASIT_autoProcessing
1648 // Purpose: Audio Stream Input Task Function for processing audio data to
1649 // determine the input type without output.
1650 // From: audioStream1Task or equivalent
1651 // Uses: See code.
1652 // States: x
1653 // Return: Error number in standard or SIO form (0 on success).
1654 // Trace: Message Log "trace" in Debug Project Configuration reports:
1655 // * State information on initialization.
1656 //
1658 #define DECSIOMAP(X) \
1659 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1661 Int
1662 PAF_ASIT_autoProcessing(
1663 const PAF_AST_Params *pP,
1664 const PAF_AST_Patchs *pQ,
1665 PAF_AST_Config *pC,
1666 Int inputTypeSelect,
1667 ALG_Handle pcmAlgMaster
1668 )
1669 {
1670 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1671 Int errno = 0; /* error number */
1672 Int nbytes;
1673 Int frameLength;
1674 Int zMD = pC->masterDec;
1675 Int zMI = pP->zone.master;
1676 Int zMS = pC->masterStr;
1678 TRACE_VERBOSE1("PAF_AST_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1680 if (errno = SIO_ctrl (pC->xInp[zMI].hRxSio,
1681 PAF_SIO_CONTROL_SET_SOURCESELECT,
1682 DECSIOMAP (pC->xDec[zMD].decodeStatus.sourceSelect)))
1683 {
1684 TRACE_VERBOSE2("PAF_AST_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1685 return errno;
1686 }
1687 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1688 // pC->xDec[zMD].decodeStatus.bufferRatio);
1689 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1691 if (errno = SIO_ctrl (pC->xInp[zMI].hRxSio,
1692 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1693 {
1694 TRACE_VERBOSE2("PAF_AST_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1695 errno, ASPERR_AUTO_LENGTH);
1696 return ASPERR_AUTO_LENGTH;
1697 }
1699 if (errno = SIO_issue (pC->xInp[zMI].hRxSio,
1700 &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig),
1701 PAF_SIO_REQUEST_SYNC))
1702 {
1703 TRACE_VERBOSE2("PAF_AST_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1704 errno, ASPERR_ISSUE);
1705 return ASPERR_ISSUE;
1706 }
1708 TRACE_VERBOSE1("PAF_AST_autoProcessing: AS%d: awaiting sync", as+zMS);
1710 // all of the sync scan work is done in this call. If the error returned
1711 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1712 // error so we mask it off.
1713 nbytes = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL);
1714 if (nbytes == -DIBERR_SYNC)
1715 {
1716 TRACE_TERSE2("PAF_AST_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1717 return 0;
1718 }
1719 if (nbytes != sizeof (PAF_InpBufConfig))
1720 {
1721 TRACE_TERSE3("PAF_AST_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1722 nbytes, sizeof (PAF_InpBufConfig), ASPERR_RECLAIM);
1723 return ASPERR_RECLAIM;
1724 }
1725 if (errno)
1726 {
1727 TRACE_TERSE2("PAF_AST_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1728 }
1729 return errno;
1730 } //PAF_ASIT_autoProcessing
1732 // -----------------------------------------------------------------------------
1733 // ASIT Processing Function - Decode Processing
1734 //
1735 // Name: PAF_ASIT_decodeProcessing
1736 // Purpose: Audio Stream Input Task Function for processing audio data.
1737 // From: audioStream1Task or equivalent
1738 // Uses: See code.
1739 // States: x
1740 // Return: Error number in standard form (0 on success).
1741 // Trace: Message Log "trace" in Debug Project Configuration reports:
1742 // * State information on initialization (via children).
1743 // * State information on processing (via children).
1744 // * Decode warnings.
1745 //
1746 // When "writeDECModeContinuous" is used for zMI input/decode:
1747 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1748 // (a) if "writeDECCommandRestart" is used
1749 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1750 // (b) if "writeDECSourceSelectNone" is used
1751 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1752 // (c) if an error occurs in
1753 // INIT
1754 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1755 // -> PAF_AST_decodeCont(): "Await slave inputs"
1756 // STREAM (errno |= PAF_COMPONENT_ASP)
1757 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1758 // [ the latter errors lead to "switch_break:"
1759 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1760 //
1761 // [ Notably, in FINAL ("frame-finalization state")
1762 // -> PAF_AST_decodeFinalTest() is *not* called,
1763 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1764 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1765 //
1766 // States in which error can't occur:
1767 // AGAIN ("subsequent initial state")
1768 //
1769 // States in which (some) errors must be handled:
1770 // INFO1 ("first frame state")
1771 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1772 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1773 // ?*? but what about ASPERR_RESYNC from same call ?*?
1774 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1775 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1776 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1777 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1778 // - enc->fxns->info()
1779 // - pP->fxns->setCheckRateX()
1780 // - pP->fxns->startOutput()
1781 // - "Start slave inputs if necessary"
1782 // INFO2 ("subsequent frame state")
1783 // -> PAF_AST_decodeInfo(): (see above)
1784 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1785 // - pP->fxns->setCheckRateX()
1786 // TIME ("timing state")
1787 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1788 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1789 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1790 // (*OK* don't try to recover from this*)
1791 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1792 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1793 // possibly in PAF_AST_decodeProcessing() itself **
1794 // DECODE ("decode state")
1795 // -> PAF_AST_decodeDecode(): pass on error from
1796 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1797 // - dec->fxns->reset()
1798 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1799 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
1800 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1801 Int
1802 PAF_ASIT_decodeProcessing(
1803 const PAF_AST_Params *pP,
1804 const PAF_AST_Patchs *pQ,
1805 PAF_AST_Config *pC,
1806 Int sourceSelect
1807 )
1808 {
1809 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1810 Int z; /* decode counter */
1811 Int errno; /* error number */
1812 Int getVal;
1813 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1814 ALG_Handle alg[DECODEN_MAX];
1815 Int zMD = pC->masterDec;
1816 Int zMS = pC->masterStr;
1817 Int size;
1818 //PAF_InpBufConfig *pIpBufConfig;
1819 Int frame; // decoder input frame count
1820 Int block; // (***) FL: formerly -- decoder output block count / input frame
1823 for (z=DECODE1; z < DECODEN; z++)
1824 alg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
1825 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1827 //
1828 // Receive and process the data in single-frame buffers
1829 //
1831 state = INIT;
1832 errno = 0; /* error number */
1834 TRACE_TERSE1("PAF_AST_decodeProcessing: sourceSelect is %d", pC->xDec[zMD].decodeStatus.sourceSelect);
1836 for (;;)
1837 {
1838 if (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
1839 {
1840 TRACE_VERBOSE0("PAF_AST_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1841 state = QUIT;
1842 }
1844 // Process commands (decode)
1845 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
1846 {
1847 if (state != INIT) // no need to restart/abort if not yet started
1848 {
1849 if (getVal == ASPERR_QUIT)
1850 {
1851 state = QUIT;
1852 TRACE_VERBOSE0("PAF_AST_decodeProcessing. %d: state = QUIT");
1853 }
1854 else if (getVal == ASPERR_ABORT)
1855 {
1856 TRACE_VERBOSE0("PAF_AST_decodeProcessing. %d: return getVal");
1857 return getVal;
1858 }
1859 else
1860 {
1861 /* ignore */;
1862 }
1863 }
1864 TRACE_VERBOSE0("PAF_AST_decodeProcessing: state == INIT");
1865 }
1867 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
1868 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
1870 // Process state (decode)
1871 switch (state)
1872 {
1873 case INIT: // initial state
1874 gAsipInitCnt++;
1875 Log_info0("TaskAsip: state=INIT");
1877 // (***) FL: revisit
1878 #if 0 // status for shared beta units can change (e.g. at-boot or alpha)
1879 // write back Status structures for shared Beta Units
1880 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1881 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1882 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1883 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1884 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1885 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1886 Cache_wait();
1887 #endif
1888 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1889 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1890 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1891 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1892 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1893 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1894 Cache_wait();
1896 //if (errno = pP->fxns->decodeInit (pP, pQ, pC, alg))
1897 //if (errno = pP->fxns->decodeInit(pP, pQ, pC, alg, sourceSelect))
1898 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1899 {
1900 TRACE_VERBOSE1("AF_AST_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1901 break;
1902 }
1904 #if 0
1905 // (***) FL: revisit
1906 // invalidate Status structures for shared Beta Units
1907 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1908 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1909 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1910 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1911 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1912 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1913 Cache_wait();
1914 #endif
1916 frame = 0;
1917 block = 0;
1919 TRACE_VERBOSE0("AF_AST_decodeProcessing: state: INIT->INFO1");
1920 state = INFO1;
1921 continue;
1923 case INFO1: // first frame state
1924 gAsipInfo1Cnt++;
1925 Log_info0("TaskAsip: state=INFO1");
1927 #if 0
1928 // (***) FL: revisit
1929 // write back Inp configuration
1930 Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
1931 // write back input data
1932 pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
1933 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
1934 Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
1935 // write back Dec configuration
1936 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1937 Cache_wait();
1938 #endif
1940 // Establish primary timing
1941 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
1942 {
1943 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1944 break;
1945 }
1947 #if 0
1948 // (***) FL: revisit
1949 // invalidate Dec configuration
1950 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1951 Cache_wait();
1952 #endif
1954 // Don't start decode until major access unit is found.
1955 if (((pC->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
1956 (pC->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
1957 (pC->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
1958 (pC->xStr[zMS].pAudioFrame->sampleRate == PAF_SAMPLERATE_UNKNOWN))
1959 {
1960 Int z;
1961 for (z=DECODE1; z < DECODEN; z++)
1962 {
1963 Int zI = pP->inputsFromDecodes[z];
1964 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
1965 {
1966 TRACE_VERBOSE0("TaskAsip: PAF_AST_decodeProcessing: INFO1, SIO_issue");
1967 if (SIO_issue (pC->xInp[zI].hRxSio, &pC->xInp[zI].inpBufConfig,
1968 sizeof (pC->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
1969 {
1970 TRACE_TERSE0("PAF_AST_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
1971 return (ASPERR_ISSUE);
1972 }
1973 }
1974 }
1975 TRACE_VERBOSE1("PAF_AST_decodeProcessing: INFO1: frame %d, not major access unit", frame);
1976 frame++;
1977 state = INFO1;
1978 continue;
1979 }
1980 TRACE_VERBOSE1("PAF_AST_decodeProcessing: INFO1: frame %d, major access unit found", frame);
1982 // Establish secondary timing
1983 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
1984 {
1985 TRACE_VERBOSE1("PAF_AST_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
1986 break;
1987 }
1989 TRACE_VERBOSE0("PAF_AST_decodeProcessing: state: INFO1->DECODE");
1990 state = DECODE;
1991 continue;
1993 case INFO2: // subsequent frame state
1994 gAsipInfo2Cnt++;
1995 Log_info0("TaskAsip: state=INFO2");
1997 #if 0
1998 // (***) FL: revisit
1999 // write back Inp configuration
2000 Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2001 // write back input data
2002 pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2003 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2004 Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2005 // write back Dec configuration
2006 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2007 Cache_wait();
2008 #endif
2010 // Establish primary timing
2011 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2012 {
2013 TRACE_TERSE1("PAF_AST_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2014 break;
2015 }
2017 #if 0
2018 // (***) FL: revisit
2019 // invalidate Dec configuration
2020 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2021 Cache_wait();
2022 #endif
2024 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2025 {
2026 TRACE_TERSE1("PAF_AST_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2027 break;
2028 }
2030 TRACE_VERBOSE0("PAF_AST_decodeProcessing: state: INFO2->DECODE");
2031 state = DECODE;
2032 continue;
2034 case DECODE: // decode state
2035 gAsipDecodeCnt++;
2036 Log_info0("TaskAsip: state=DECODE");
2038 #if 0
2039 // (***) FL: revisit
2040 // write back Dec configuration
2041 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2042 Cache_wait();
2043 #endif
2045 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2046 {
2047 TRACE_TERSE1("PAF_AST_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2048 break;
2049 }
2051 #if 0
2052 // (***) FL: revisit
2053 // invalidate Dec configuration
2054 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2055 Cache_wait();
2056 #endif
2058 TRACE_VERBOSE0("PAF_AST_decodeProcessing: state: DECODE->FINAL");
2059 state = FINAL;
2060 continue;
2062 case FINAL: // frame-finalization state
2063 gAsipFinalCnt++;
2064 Log_info0("TaskAsip: state=FINAL");
2066 // Check for final frame, and if indicated:
2067 // - Exit state machine to "complete" processing.
2068 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2069 {
2070 break;
2071 }
2073 frame++;
2074 TRACE_VERBOSE0("PAF_AST_decodeProcessing: state: FINAL->AGAIN");
2075 state = INFO2;
2076 continue;
2078 case QUIT: // exit state
2079 gAsipQuitCnt++;
2080 Log_info0("TaskAsip: state=QUIT");
2082 // Quit:
2083 // - Set error number registers.
2084 // - Exit state machine to "decode complete" processing.
2085 TRACE_VERBOSE0("PAF_AST_decodeProcessing: state: QUIT");
2086 errno = ASPERR_QUIT;
2087 break;
2089 default: // unknown state
2091 // Unknown:
2092 // - Set error number registers.
2093 // - Exit state machine to "decode complete" processing.
2095 TRACE_TERSE1("PAF_AST_decodeProcessing: state: unknown, 0x%x", state);
2096 errno = ASPERR_UNKNOWNSTATE;
2097 break;
2099 } // End of switch (state).
2101 TRACE_VERBOSE0("PAF_AST_decodeProcessing: Calling decode complete");
2102 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2103 {
2104 /* ignored? */;
2105 }
2107 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2109 return errno;
2110 } // End of for (;;) to Receive, process, and transmit the data.
2111 } //PAF_ASIT_decodeProcessing
2113 // -----------------------------------------------------------------------------
2114 // ASIT Decoding Function - Decode Command Processing
2115 //
2116 // Name: PAF_ASIT_decodeCommand
2117 // Purpose: Decoding Function for processing Decode Commands.
2118 // From: AST Parameter Function -> decodeProcessing
2119 // Uses: See code.
2120 // States: x
2121 // Return: Error number in standard form (0 on success).
2122 // Trace: Message Log "trace" in Debug Project Configuration reports:
2123 // * Command execution.
2124 //
2126 Int
2127 PAF_ASIT_decodeCommand(
2128 const PAF_AST_Params *pP,
2129 const PAF_AST_Patchs *pQ,
2130 PAF_AST_Config *pC
2131 )
2132 {
2133 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2134 Int z; /* decode counter */
2135 Int zS;
2138 for (z=DECODE1; z < DECODEN; z++)
2139 {
2140 zS = pP->streamsFromDecodes[z];
2141 if (!(pC->xDec[z].decodeStatus.command2 & 0x80))
2142 {
2143 switch (pC->xDec[z].decodeStatus.command2)
2144 {
2145 case 0: // command none - process
2146 pC->xDec[z].decodeStatus.command2 |= 0x80;
2147 break;
2148 case 1: // command abort - leave now
2149 TRACE_TERSE2("AS%d: PAF_AST_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2150 pC->xDec[z].decodeStatus.command2 |= 0x80;
2151 return (ASPERR_ABORT);
2152 case 2: // command restart - leave later
2153 TRACE_TERSE2("AS%d: PAF_AST_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2154 pC->xDec[z].decodeStatus.command2 |= 0x80;
2155 return (ASPERR_QUIT);
2156 default: // command unknown - ignore
2157 break;
2158 }
2159 }
2160 }
2162 return 0;
2163 } //PAF_ASIT_decodeCommand
2165 // -----------------------------------------------------------------------------
2166 // ASIT Decoding Function - Reinitialization of Decode
2167 //
2168 // Name: PAF_ASIT_decodeInit
2169 // Purpose: Decoding Function for reinitializing the decoding process.
2170 // From: AST Parameter Function -> decodeProcessing
2171 // Uses: See code.
2172 // States: x
2173 // Return: Error number in standard or SIO form (0 on success).
2174 // Trace: Message Log "trace" in Debug Project Configuration reports:
2175 // * State information as per parent.
2176 //
2177 Int
2178 PAF_ASIT_decodeInit(
2179 const PAF_AST_Params *pP,
2180 const PAF_AST_Patchs *pQ,
2181 PAF_AST_Config *pC,
2182 Int sourceSelect
2183 )
2184 {
2185 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2186 Int z; /* decode/encode counter */
2187 Int errno; /* error number */
2188 Int zI, zS;
2189 Int zMD = pC->masterDec;
2190 Int zMI = pP->zone.master;
2191 ASP_Msg* pAspMsg; /* Messaging */
2192 Int argIdx;
2193 Int decErrno;
2194 Int status;
2195 PAF_DecodeOpCircBuf *pCb; /* Decoder output circular buffer */
2197 (void)as; // clear compiler warning in case not used with tracing disabled
2199 // reset frameCount
2200 for (z=DECODE1; z < DECODEN; z++)
2201 {
2202 if (pC->xDec[z].decodeStatus.mode)
2203 {
2204 pC->xDec[z].decodeStatus.frameCount = 0;
2205 }
2206 }
2208 for (z=DECODE1; z < DECODEN; z++)
2209 {
2210 zI = pP->inputsFromDecodes[z];
2211 zS = pP->streamsFromDecodes[z];
2212 (void)zS; // clear compiler warning in case not used with tracing disabled
2213 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
2214 {
2215 Uns gear;
2216 Int frameLength;
2217 TRACE_VERBOSE1("AS%d: PAF_AST_decodeInit: initializing decode", as+zS);
2219 // FL: send dec activate message to slave
2220 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2221 if (pAspMsg == NULL)
2222 {
2223 TRACE_TERSE0("MessageQ_alloc() failure.");
2224 SW_BREAKPOINT; // temporary
2225 return -1; // temporary
2226 }
2227 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2228 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2229 pAspMsg->procId = hAspMsgMaster->masterProcId;
2230 pAspMsg->expectResp = TRUE;
2231 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2232 argIdx = 0; // set decIdx (zone index)
2233 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2234 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2235 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2236 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2237 if (status != MessageQ_S_SUCCESS)
2238 {
2239 SW_BREAKPOINT;
2240 }
2241 // wait for dec activate complete message from slave
2242 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2243 if (status != MessageQ_S_SUCCESS)
2244 {
2245 TRACE_TERSE0("MessageQ_get() failure.");
2246 SW_BREAKPOINT; // temporary
2247 return -1; // temporary
2248 }
2249 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2250 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2251 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2252 {
2253 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2254 SW_BREAKPOINT; // temporary
2255 return -1; // temporary
2256 }
2257 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2258 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2259 // free the message
2260 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2261 if (status != MessageQ_S_SUCCESS)
2262 {
2263 SW_BREAKPOINT;
2264 }
2266 #if 0 // FL: decoder activate call, slave
2267 if (decAlg[z]->fxns->algActivate)
2268 decAlg[z]->fxns->algActivate (decAlg[z]);
2269 #endif
2271 // (***) FL: revisit
2272 // write back Dec configuration
2273 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2274 Cache_wait();
2276 // FL: send dec reset message to slave
2277 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2278 if (pAspMsg == NULL)
2279 {
2280 TRACE_TERSE0("MessageQ_alloc() failure.");
2281 SW_BREAKPOINT; // temporary
2282 return -1; // temporary
2283 }
2284 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2285 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2286 pAspMsg->procId = hAspMsgMaster->masterProcId;
2287 pAspMsg->expectResp = TRUE;
2288 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2289 argIdx = 0; // set decIdx
2290 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2291 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2292 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2293 // wait for dec reset complete message from slave
2294 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2295 if (status != MessageQ_S_SUCCESS)
2296 {
2297 SW_BREAKPOINT;
2298 }
2299 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2300 if (status != MessageQ_S_SUCCESS)
2301 {
2302 TRACE_TERSE0("MessageQ_get() failure.");
2303 SW_BREAKPOINT; // temporary
2304 return -1; // temporary
2305 }
2306 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2307 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2308 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2309 {
2310 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2311 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2312 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2314 argIdx = 0; // get decErrno
2315 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2316 if (decErrno != 0)
2317 {
2318 return decErrno;
2319 }
2320 }
2321 else
2322 {
2323 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2324 SW_BREAKPOINT; // temporary
2325 return -1; // temporary
2326 }
2327 // free the message
2328 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2329 if (status != MessageQ_S_SUCCESS)
2330 {
2331 SW_BREAKPOINT;
2332 }
2334 // (***) FL: revisit
2335 // invalidate Dec configuration
2336 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2337 Cache_wait();
2339 #if 0 // FL: decoder reset call, slave
2340 if (dec->fxns->reset
2341 && (errno = dec->fxns->reset (dec, NULL,
2342 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2343 return errno;
2344 #endif
2346 pC->xDec[z].decodeStatus.aspGearControl = 0;//QIN, aspGearControl seems un-initialized
2347 gear = pC->xDec[z].decodeStatus.aspGearControl;
2348 pC->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2350 #if 0 // FL: change handle to decIdx (zone index)
2351 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2352 FRAMELENGTH,
2353 pC->xDec[z].decodeStatus.bufferRatio);
2354 #endif
2355 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2356 frameLength = pP->fxns->computeFrameLength(z,
2357 FRAMELENGTH,
2358 pC->xDec[z].decodeStatus.bufferRatio);
2359 #else
2360 if (sourceSelect == PAF_SOURCE_PCM)
2361 {
2362 frameLength = 256;
2363 }
2364 else if (sourceSelect == PAF_SOURCE_DDP)
2365 {
2366 frameLength = 1536;
2367 }
2368 else
2369 {
2370 frameLength = 256;
2371 }
2372 #endif
2374 pC->xDec[z].decodeControl.frameLength = frameLength;
2375 pC->xDec[z].decodeInStruct.sampleCount = frameLength;
2376 pC->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2378 // (***) FL: revisit. Count samples for DDP.
2379 // Add framework frame length and running sample count to decoder control.
2380 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2381 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2383 // Start decoder output circular buffer writes
2384 pCb = &pC->xDec[z].decOpCb;
2385 errno = cbInit(sourceSelect, frameLength, FRAMELENGTH, pCb);
2386 if (errno)
2387 {
2388 return errno;
2389 }
2390 errno = cbReadWriteRestore(pCb); //QIN
2391 if (errno)
2392 {
2393 return errno;
2394 }
2395 // FL: debug
2396 cbLog(pCb, 1);
2398 if (z != zMD)
2399 {
2400 if (errno = SIO_idle(pC->xInp[zI].hRxSio))
2401 {
2402 return errno;
2403 }
2404 }
2406 if (errno = SIO_ctrl(pC->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2407 DECSIOMAP(pC->xDec[z].decodeStatus.sourceSelect)))
2408 {
2409 return errno;
2410 }
2411 if (errno = SIO_ctrl(pC->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2412 frameLength))
2413 {
2414 return errno;
2415 }
2416 if (errno = pP->fxns->updateInputStatus(pC->xInp[zI].hRxSio, &pC->xInp[zI].inpBufStatus,
2417 &pC->xInp[zI].inpBufConfig))
2418 {
2419 return errno;
2420 }
2421 }
2422 }
2424 if (pC->xInp[zMI].hRxSio)
2425 {
2426 errno = SIO_issue(pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig,
2427 sizeof(pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2428 if (errno)
2429 {
2430 return errno;
2431 }
2432 }
2434 return 0;
2435 } //PAF_AST_decodeInit
2437 // -----------------------------------------------------------------------------
2438 // ASIT Decoding Function - Info Processing, Common
2439 //
2440 // Name: PAF_ASIT_decodeInfo
2441 // Purpose: Decoding Function for processing information in a manner that
2442 // is common for both initial and subsequent frames of input data.
2443 // From: AST Parameter Function -> decodeProcessing
2444 // Uses: See code.
2445 // States: x
2446 // Return: Error number in standard form (0 on success).
2447 // Trace: Message Log "trace" in Debug Project Configuration reports:
2448 // * State information as per parent.
2449 //
2450 Int
2451 PAF_ASIT_decodeInfo(
2452 const PAF_AST_Params *pP,
2453 const PAF_AST_Patchs *pQ,
2454 PAF_AST_Config *pC,
2455 Int frame,
2456 Int block
2457 )
2458 {
2459 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2460 Int z; /* input/decode/stream counter */
2461 Int errno; /* error number */
2462 Int sioErr; /* error number, SIO */
2463 Int zD, zI, zS, zX;
2464 Int zMD = pC->masterDec;
2465 Int zMI = pP->zone.master;
2466 Int zMS = pC->masterStr;
2467 UInt32 curTime;
2468 ASP_Msg *pAspMsg; /* Messaging */
2469 Int argIdx;
2470 Int status;
2471 // FL: revisit
2472 //Int size;
2473 //PAF_InpBufConfig *pIpBufConfig;
2475 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2477 // Set decode control: sample rate, emphasis
2478 for (z=INPUT1; z < INPUTN; z++)
2479 {
2480 zD = z;
2481 for (zX = DECODE1; zX < DECODEN; zX++)
2482 {
2483 if (pP->inputsFromDecodes[zX] == z)
2484 {
2485 zD = zX;
2486 break;
2487 }
2488 }
2490 if (pC->xInp[z].hRxSio)
2491 {
2492 //determine associated decoder
2493 if (pC->xInp[z].inpBufStatus.sampleRateStatus !=
2494 pC->xDec[zD].decodeControl.sampleRate)
2495 {
2496 if (pC->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2497 {
2498 pC->xDec[zD].decodeControl.sampleRate =
2499 pC->xInp[z].inpBufStatus.sampleRateStatus;
2500 }
2501 else
2502 {
2503 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pC->masterStr);
2504 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2505 pC->xInp[z].inpBufStatus.sampleRateStatus,
2506 pC->xDec[zD].decodeControl.sampleRate);
2507 // return (ASPERR_INFO_RATECHANGE);
2508 }
2509 }
2510 pC->xDec[zD].decodeControl.emphasis =
2511 pC->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2512 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2513 : pC->xInp[z].inpBufStatus.emphasisStatus;
2514 }
2515 else
2516 {
2517 pC->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2518 pC->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2519 }
2520 }
2522 // Wait for info input
2523 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2524 if (pC->xInp[zMI].hRxSio)
2525 {
2526 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2527 sioErr = SIO_reclaim(pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL);
2528 if (sioErr != sizeof(pC->xInp[zMI].inpBufConfig))
2529 {
2530 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2531 return ASPERR_RECLAIM;
2532 }
2534 // FL: debug, capture input buffer
2535 //capIb(pC->xInp[zMI].pInpBuf);
2537 //
2538 // Simulate Rx SIO_reclaim() pend
2539 //
2540 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2541 gTaskAsipCnt++;
2542 curTime = Clock_getTicks();
2543 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2544 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2545 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2546 } //pC->xInp[zMI].hRxSio
2548 // Decode info
2549 for (z=DECODE1; z < DECODEN; z++)
2550 {
2551 zI = pP->inputsFromDecodes[z];
2552 zS = pP->streamsFromDecodes[z];
2553 (void)zS; // clear compiler warning in case not used with tracing disabled
2554 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
2555 {
2556 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2558 if (errno = pP->fxns->updateInputStatus(pC->xInp[zI].hRxSio,
2559 &pC->xInp[zI].inpBufStatus, &pC->xInp[zI].inpBufConfig))
2560 {
2561 TRACE_TERSE1("return error errno 0x%x.", errno);
2562 return errno;
2563 }
2565 #if 1
2566 // (***) FL: revisit
2567 // write back Inp configuration
2568 Cache_wb(&gPAF_AST_config.xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2569 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2570 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2571 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2572 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2573 // write back Dec configuration
2574 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2575 Cache_wait();
2576 #endif
2578 // FL: send info message to slave
2579 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2580 if (pAspMsg == NULL)
2581 {
2582 TRACE_TERSE0("MessageQ_alloc() failure.");
2583 SW_BREAKPOINT; // temporary
2584 return -1; // temporary
2585 }
2586 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2587 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
2588 pAspMsg->procId = hAspMsgMaster->masterProcId;
2589 pAspMsg->expectResp = TRUE;
2590 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2591 argIdx = 0; // set decIdx
2592 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2593 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2594 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2595 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
2596 if (status != MessageQ_S_SUCCESS)
2597 {
2598 SW_BREAKPOINT;
2599 }
2600 // wait for dec info complete message from slave -- temporary
2601 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2602 if (status != MessageQ_S_SUCCESS)
2603 {
2604 TRACE_TERSE0("MessageQ_get() failure.");
2605 SW_BREAKPOINT;
2606 return -1; // temporary
2607 }
2608 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2609 (pAspMsg->cmd != ASP_MASTER_DEC_INFO_DONE) ||
2610 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2611 {
2612 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2613 SW_BREAKPOINT; // temporary
2614 }
2615 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2616 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2617 // free the message
2618 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2619 if (status != MessageQ_S_SUCCESS)
2620 {
2621 SW_BREAKPOINT;
2622 }
2624 #if 1
2625 // (***) FL: revisit
2626 // invalidate Dec configuration
2627 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2628 Cache_wait();
2629 #endif
2631 #if 0 // FL: decoder info call, slave
2632 if (dec->fxns->info
2633 && (errno = dec->fxns->info (dec, NULL,
2634 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2635 #endif
2636 if (errno)
2637 {
2638 TRACE_TERSE1("return error errno 0x%x.", errno);
2639 return errno;
2640 }
2641 // increment decoded frame count
2642 pC->xDec[z].decodeStatus.frameCount += 1;
2643 }
2644 } // z=DECODE1 to DECODEN
2646 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2647 if (pC->xDec[zMD].decodeStatus.mode)
2648 {
2649 XDAS_Int8 sourceProgram;
2650 if (errno = SIO_ctrl(pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2651 (Arg)&sourceProgram))
2652 {
2653 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2654 return ASPERR_AUTO_PROGRAM;
2655 }
2656 pC->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
2658 #if 0
2659 // (***) FL: revisit
2660 Cache_wb((Ptr)&pC->xDec[zMD].decodeStatus.sourceProgram,
2661 sizeof(pC->xDec[zMD].decodeStatus.sourceProgram), Cache_Type_ALLD, 0);
2662 Cache_wait();
2663 #endif
2664 }
2666 // since now decoding update decode status for all enabled decoders
2667 for (z=DECODE1; z < DECODEN; z++)
2668 {
2669 if (pC->xDec[z].decodeStatus.mode)
2670 {
2671 pC->xDec[z].decodeStatus.sourceDecode = pC->xDec[z].decodeStatus.sourceProgram;
2672 if (pC->xDec[z].decodeStatus.sourceSelect == PAF_SOURCE_SNG)
2673 {
2674 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_SNG;
2675 }
2677 #if 0
2678 // (***) FL: revisit
2679 Cache_wb((Ptr)&pC->xDec[z].decodeStatus.sourceDecode,
2680 sizeof(pC->xDec[z].decodeStatus.sourceDecode), Cache_Type_ALLD, 0);
2681 Cache_wait();
2682 #endif
2683 }
2684 }
2686 #if 0 // FL: ASDT (slave)
2687 // TODO: move this to start of this function so that it doesn't affect IO timing
2688 // Initialize audio frame(s)
2689 // Re-initialize audio frame if there is an associated decode and
2690 // that decode doesn't have a valid input or is turned off
2691 for (z=STREAM1; z < STREAMN; z++)
2692 {
2693 Int reset = 0;
2694 for (zX = DECODE1; zX < DECODEN; zX++)
2695 {
2696 if (pP->streamsFromDecodes[zX] == z)
2697 {
2698 zI = pP->inputsFromDecodes[zX];
2699 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2700 {
2701 reset = 1;
2702 }
2703 }
2704 }
2705 if (reset)
2706 {
2707 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2708 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2709 }
2710 else
2711 {
2712 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2713 }
2714 }
2715 #endif
2717 return 0;
2718 } //PAF_ASIT_decodeInfo
2720 // -----------------------------------------------------------------------------
2721 // ASIT Decoding Function - Info Processing, Initial
2722 //
2723 // Name: PAF_ASIT_decodeInfo1
2724 // Purpose: Decoding Function for processing information in a manner that
2725 // is unique to initial frames of input data.
2726 // From: AST Parameter Function -> decodeProcessing
2727 // Uses: See code.
2728 // States: x
2729 // Return: Error number in standard or SIO form (0 on success).
2730 // Trace: Message Log "trace" in Debug Project Configuration reports:
2731 // * State information as per parent.
2732 //
2733 Int
2734 PAF_ASIT_decodeInfo1(
2735 const PAF_AST_Params *pP,
2736 const PAF_AST_Patchs *pQ,
2737 PAF_AST_Config *pC,
2738 Int frame,
2739 Int block
2740 )
2741 {
2742 return 0;
2743 } //PAF_ASIT_decodeInfo1
2745 // -----------------------------------------------------------------------------
2746 // AST Decoding Function - Info Processing, Subsequent
2747 //
2748 // Name: PAF_AST_decodeInfo2
2749 // Purpose: Decoding Function for processing information in a manner that
2750 // is unique to frames of input data other than the initial one.
2751 // From: AST Parameter Function -> decodeProcessing
2752 // Uses: See code.
2753 // States: x
2754 // Return: Error number in standard form (0 on success).
2755 // Trace: None.
2756 //
2757 Int
2758 PAF_ASIT_decodeInfo2(
2759 const PAF_AST_Params *pP,
2760 const PAF_AST_Patchs *pQ,
2761 PAF_AST_Config *pC,
2762 Int frame,
2763 Int block
2764 )
2765 {
2766 return 0;
2767 } //PAF_ASIT_decodeInfo2
2769 // -----------------------------------------------------------------------------
2770 // AST Decoding Function - Continuation Processing
2771 //
2772 // Name: PAF_AST_decodeCont
2773 // Purpose: Decoding Function for processing that occurs subsequent to
2774 // information processing but antecedent to timing processing
2775 // for frames of input data other than the initial one.
2776 // From: AST Parameter Function -> decodeProcessing
2777 // Uses: See code.
2778 // States: x
2779 // Return: Error number in standard form (0 on success).
2780 // Trace: Message Log "trace" in Debug Project Configuration reports:
2781 // * State information as per parent.
2782 //
2784 Int
2785 PAF_AST_decodeCont (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int frame, Int block)
2786 {
2787 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2788 Int z; /* decode counter */
2789 Int zI, zS;
2790 Int zMD = pC->masterDec;
2792 (void)as; // clear compiler warning in case not used with tracing disabled
2794 // Await slave inputs
2795 for (z=DECODE1; z < DECODEN; z++) {
2796 zI = pP->inputsFromDecodes[z];
2797 zS = pP->streamsFromDecodes[z];
2798 (void)zS;
2799 if (z == zMD
2800 || ! pC->xInp[zI].hRxSio
2801 || ! pC->xDec[z].decodeStatus.mode)
2802 continue;
2803 TRACE_VERBOSE2("as1-f2: PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2804 if (SIO_reclaim (pC->xInp[zI].hRxSio, (Ptr)&pC->xInp[zI].pInpBuf, NULL)
2805 != sizeof (pC->xInp[zI].inpBufConfig))
2806 return (ASPERR_RECLAIM);
2807 }
2809 return 0;
2810 } //PAF_AST_decodeCont
2812 // -----------------------------------------------------------------------------
2813 // ASIT Decoding Function - Decode Processing
2814 //
2815 // Name: PAF_ASIT_decodeDecode
2816 // Purpose: Decoding Function for processing of input data by the
2817 // Decode Algorithm.
2818 // From: AST Parameter Function -> decodeProcessing
2819 // Uses: See code.
2820 // States: x
2821 // Return: Error number in standard form (0 on success).
2822 // Trace: Message Log "trace" in Debug Project Configuration reports:
2823 // * State information as per parent.
2824 //
2825 Int
2826 PAF_ASIT_decodeDecode(
2827 const PAF_AST_Params *pP,
2828 const PAF_AST_Patchs *pQ,
2829 PAF_AST_Config *pC,
2830 Int sourceSelect,
2831 Int frame,
2832 Int block
2833 )
2834 {
2835 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2836 Int z; /* decode/stream counter */
2837 Int errno; /* error number */
2838 //Int ch;
2839 ASP_Msg *pAspMsg; /* Messaging */
2840 Int argIdx;
2841 Int status;
2842 Int cbErrno;
2843 Int frameLength;
2845 (void)as; // clear compiler warning in case not used with tracing disabled
2847 #if 0 // FL: slave
2848 // Clear samsiz for all channels - MID 208.
2849 for (z=STREAM1; z < STREAMN; z++)
2850 {
2851 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
2852 {
2853 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
2854 }
2855 }
2856 #endif
2858 // Decode data
2859 for (z=DECODE1; z < DECODEN; z++)
2860 {
2861 Int zI = pP->inputsFromDecodes[z];
2862 Int zS = pP->streamsFromDecodes[z];
2863 (void)zS; // clear compiler warning in case not used with tracing disabled
2864 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
2865 {
2866 TRACE_GEN2("AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
2868 TRACE_VERBOSE3("as1-f2: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
2869 as+zS,
2870 (IArg)pC->xInp[z].pInpBuf->base.pVoid,
2871 (IArg)pC->xInp[z].pInpBuf->head.pVoid);
2873 // FL: debug, capture input buffer
2874 //capIbPcm(pC->xInp[z].pInpBuf);
2876 // (***) FL: revisit
2877 // write back Dec configuration
2878 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2879 Cache_wait();
2881 // FL: send decode message to slave
2882 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2883 if (pAspMsg == NULL)
2884 {
2885 TRACE_TERSE0("MessageQ_alloc() failure.");
2886 SW_BREAKPOINT; // temporary
2887 return -1; // temporary
2888 }
2889 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2890 pAspMsg->cmd = ASP_SLAVE_DEC_DECODE; /* fill in message payload */
2891 pAspMsg->procId = hAspMsgMaster->masterProcId;
2892 pAspMsg->expectResp = TRUE;
2893 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2894 argIdx = 0; // set decIdx
2895 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2896 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2897 TRACE_MSG1("decIdx=%d", pAspMsg->buf[argIdx]);
2898 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2899 if (status != MessageQ_S_SUCCESS)
2900 {
2901 SW_BREAKPOINT;
2902 }
2903 // wait for decode complete message from slave -- temporary
2904 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2905 if (status != MessageQ_S_SUCCESS)
2906 {
2907 TRACE_TERSE0("MessageQ_get() failure.");
2908 SW_BREAKPOINT; // temporary
2909 return -1; // temporary
2910 }
2911 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2912 (pAspMsg->cmd == ASP_MASTER_DEC_DECODE_DONE) &&
2913 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2914 {
2915 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2916 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2918 argIdx = 0;
2919 errno = *(Int32 *)&pAspMsg->buf[argIdx];
2920 argIdx += sizeof(Int32);
2921 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2922 if (cbErrno != 0)
2923 {
2924 TRACE_TERSE1("CB write error=%d", cbErrno);
2925 SW_BREAKPOINT; // temporary
2926 }
2927 }
2928 else
2929 {
2930 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2931 SW_BREAKPOINT; // temporary
2932 }
2933 // free the message
2934 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2935 if (status != MessageQ_S_SUCCESS)
2936 {
2937 SW_BREAKPOINT;
2938 }
2940 // (***) FL: revisit
2941 // invalidate Dec configuration
2942 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2943 Cache_wait();
2945 #if 0 // FL: decoder decode call, slave
2946 if (dec->fxns->decode
2947 && (errno = dec->fxns->decode (dec, NULL,
2948 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
2949 #endif
2950 if (errno)
2951 {
2952 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
2953 return errno;
2954 }
2956 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2957 as_traceChannels(pC, z);
2958 #endif
2960 #if 0 // FL: change handle to decIdx (zone index)
2961 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2962 FRAMELENGTH,
2963 pC->xDec[z].decodeStatus.bufferRatio);
2964 #endif
2965 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2966 frameLength = pP->fxns->computeFrameLength(z,
2967 FRAMELENGTH,
2968 pC->xDec[z].decodeStatus.bufferRatio);
2969 #else
2970 if (sourceSelect == PAF_SOURCE_PCM)
2971 frameLength = 256;
2972 else if (sourceSelect == PAF_SOURCE_DDP)
2973 frameLength = 1536;
2974 else
2975 frameLength = 256;
2976 #endif
2978 // ............................................................................
2980 pC->xDec[z].decodeControl.frameLength = frameLength;
2981 pC->xDec[z].decodeInStruct.sampleCount = frameLength;
2982 if (errno = SIO_ctrl(pC->xInp[zI].hRxSio,