[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / audioStreamInpProc.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamInpProc.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Diags.h>
43 #include <xdc/runtime/Error.h>
44 #include <xdc/runtime/Log.h>
45 #include <xdc/runtime/Memory.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/hal/Hwi.h>
49 #include <ti/sysbios/hal/Cache.h>
50 #include <ti/sysbios/knl/Clock.h>
51 #include <ti/sysbios/knl/Task.h>
52 #include <ti/ipc/Ipc.h>
53 #include <ti/ipc/MessageQ.h>
54 #include <ti/ipc/MultiProc.h>
56 #include <sio.h>
57 #include <pafsio_ialg.h>
59 #include "common.h"
60 #include "paf_heapMgr.h"
61 #include "aspMsg_common.h"
62 #include "aspMsg_master.h"
63 #include "aspDecOpCircBuf_master.h"
64 #include "audioStreamProc_common.h"
65 #include "audioStreamProc_master.h"
66 #include "audioStreamInpProc.h"
68 // FL: porting
69 #include "fwkSim.h"
70 //#include "fwkPort.h"
71 // FL: debug
72 #include "dbgCapAf.h"
75 // -----------------------------------------------------------------------------
76 // Debugging Trace Control, local to this file.
77 //
78 #include "logp.h"
80 #define TRACE_ARC(a)
82 // allows you to set a different trace module in pa.cfg
83 #define TR_MOD trace
85 // Allow a developer to selectively enable tracing.
86 #define CURRENT_TRACE_MASK 0x21
88 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
89 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
90 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
91 #define TRACE_MASK_DATA 0x08 // Show data
92 #define TRACE_MASK_TIME 0x10 // Timing related traces
93 #define TRACE_MASK_MSG 0x20 // Message related traces
95 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
96 #undef TRACE_TERSE0
97 #undef TRACE_TERSE1
98 #undef TRACE_TERSE2
99 #undef TRACE_TERSE3
100 #undef TRACE_TERSE4
101 #define TRACE_TERSE0(a)
102 #define TRACE_TERSE1(a,b)
103 #define TRACE_TERSE2(a,b,c)
104 #define TRACE_TERSE3(a,b,c,d)
105 #define TRACE_TERSE4(a,b,c,d,e)
106 #endif
108 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
109 #undef TRACE_GEN0
110 #undef TRACE_GEN1
111 #undef TRACE_GEN2
112 #undef TRACE_GEN3
113 #undef TRACE_GEN4
114 #define TRACE_GEN0(a)
115 #define TRACE_GEN1(a,b)
116 #define TRACE_GEN2(a,b,c)
117 #define TRACE_GEN3(a,b,c,d)
118 #define TRACE_GEN4(a,b,c,d,e)
119 #endif
121 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
122 // consolidate list of processing strings, indexed by PAF_SOURCE
123 static char *procName[] =
124 {
125 "", //PAF_SOURCE_UNKNOWN
126 "", //PAF_SOURCE_NONE
127 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
128 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
129 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
130 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
131 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
132 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
133 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
134 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
135 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
136 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
137 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
138 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
139 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
140 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
142 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
143 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
144 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
145 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
146 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
147 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
148 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
149 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
150 "AS%d: THD processing ...", //PAF_SOURCE_THD
151 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
152 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
153 };
155 #else
156 #undef TRACE_VERBOSE0
157 #undef TRACE_VERBOSE1
158 #undef TRACE_VERBOSE2
159 #undef TRACE_VERBOSE3
160 #undef TRACE_VERBOSE4
161 #define TRACE_VERBOSE0(a)
162 #define TRACE_VERBOSE1(a,b)
163 #define TRACE_VERBOSE2(a,b,c)
164 #define TRACE_VERBOSE3(a,b,c,d)
165 #define TRACE_VERBOSE4(a,b,c,d,e)
166 #endif
168 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
169 #define TRACE_DATA(a) LOG_printf a
170 #else
171 #define TRACE_DATA(a)
172 #endif
174 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
175 #define TRACE_TIME(a) LOG_printf a
176 #define TIME_MOD trace // this could be different
177 static Int dtime()
178 {
179 static Int old_time = 0;
180 Int time = TSK_time();
181 Int delta_time = time - old_time;
182 old_time = time;
183 return( delta_time);
184 }
186 static char *stateName[11] =
187 {
188 "INIT",
189 "INFO1",
190 "AGAIN",
191 "INFO2",
192 "CONT",
193 "TIME",
194 "DECODE",
195 "STREAM",
196 "ENCODE",
197 "FINAL",
198 "QUIT"
199 };
201 #else
202 #define TRACE_TIME(a)
203 #endif
205 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
206 #undef TRACE_MSG0
207 #undef TRACE_MSG1
208 #undef TRACE_MSG2
209 #undef TRACE_MSG3
210 #undef TRACE_MSG4
211 #define TRACE_MSG0(a)
212 #define TRACE_MSG1(a,b)
213 #define TRACE_MSG2(a,b,c)
214 #define TRACE_MSG3(a,b,c,d)
215 #define TRACE_MSG4(a,b,c,d,e)
216 #endif
219 // .............................................................................
221 #include <pafsio.h>
222 #include "paferr.h"
224 #include <acp_mds.h>
226 #include <pcm.h>
228 #include <pce.h>
230 #include <doberr.h>
232 #include <diberr.h>
234 #include <stdasp.h>
236 #include "as0.h"
237 #include "asperr.h"
239 #include "audioStreamProc_params.h"
240 #include "audioStreamProc_patchs.h"
241 #include "audioStreamProc_config.h"
242 #include "audioStreamInpProc.h"
244 //
245 // Audio Stream Definitions
246 //
248 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
249 #define MINFRAMELENGTH 24
250 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
253 //
254 // Decoder Definitions
255 //
256 //#define decLinkInit pQ->i_decLinkInit
258 //
259 // Audio Stream Processing Definitions
260 //
261 //#define aspLinkInit pQ->i_aspLinkInit
263 //
264 // Encoder Definitions
265 //
266 #define encLinkInit pQ->i_encLinkInit
268 //
269 // Input, Output Definitions
270 //
271 #define inpLinkInit pP->i_inpLinkInit
272 //#define outLinkInit pP->i_outLinkInit
274 /* ---------------------------------------------------------------- */
275 /* Parameter macro definitions end here. */
276 /* ---------------------------------------------------------------- */
278 //
279 // Standardized Definitions
280 //
282 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
283 //#define ENC_Handle PCE_Handle /* works for all: PCE */
285 #define __TASK_NAME__ "TaskAsip"
287 LINNO_DEFN(TaskAsip); /* Line number macros */
288 ERRNO_DEFN(TaskAsip); /* Error number macros */
290 // ASIT configuration
291 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
292 PAF_ASIT_Config gPAF_ASIT_config = {
293 NULL, // acp
294 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
295 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
296 };
298 // Global debug counters */
299 UInt32 gTaskAsipCnt=0; // debug
300 UInt32 gAsipInitCnt =0;
301 UInt32 gAsipInfo1Cnt =0;
302 UInt32 gAsipInfo2Cnt =0;
303 UInt32 gAsipDecodeCnt =0;
304 UInt32 gAsipFinalCnt =0;
305 UInt32 gAsipQuitCnt =0;
306 #include "dbgDib.h"
308 extern struct {
309 Int size;
310 IALG_Status *pStatus[512];
311 } IACP_STD_BETA_TABLE;
314 /*
315 * ======== taskAsipFxn ========
316 * Audio Stream Input Processing task function
317 */
318 Void taskAsipFxn(
319 // Int betaPrimeValue, // FL: revisit
320 const PAF_ASIT_Params *pP,
321 const PAF_ASIT_Patchs *pQ
322 )
323 {
324 PAF_ASIT_Config *pC; /* Local configuration pointer */
325 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
326 Int as; /* Audio Stream Number (1, 2, etc.) */
327 Int z; /* input/encode/stream/decode/output counter */
328 Int i; /* phase */
329 Int errno; /* error number */
330 Int zMD, zMI, zMS, zX;
331 Int loopCount = 0; // used to stop trace to see startup behavior.
332 UInt32 curTime;
333 Int size;
334 // Messaging
335 ASP_Msg *pAspMsg;
336 Int status;
338 Log_info0("Enter taskAsipFxn()");
340 #ifdef SIMULATE_SIO
341 /* Start simulation */
342 simStart();
343 #endif // SIMULATE_SIO
345 //
346 // Audio Framework Parameters & Patch (*pP, *pQ)
347 //
348 if (!pP)
349 {
350 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
351 LINNO_RPRT(TaskAsip, -1);
352 return;
353 }
355 if (!pQ)
356 {
357 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
358 LINNO_RPRT(TaskAsip, -1);
359 return;
360 }
362 //
363 // Audio Framework Configuration (*pC):
364 //
365 pC = &gPAF_ASIT_config;
366 pAstCfg = pC->pAstCfg;
368 /* Set Audio Stream Number (1, 2, etc.) */
369 as = gBetaPrimeValue + 1;
370 pAstCfg->as = as;
371 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
373 //
374 // Initialize message log trace and line number reporting
375 //
376 for (z=STREAM1; z < STREAMN; z++)
377 {
378 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
379 }
380 LINNO_RPRT(TaskAsip, -1);
382 //
383 // Determine decoder and stream indices associated with the master input
384 //
385 zMI = pP->zone.master;
386 pAstCfg->masterDec = zMI;
387 pAstCfg->masterStr = zMI;
388 for (zX = DECODE1; zX < DECODEN; zX++)
389 {
390 if (pP->inputsFromDecodes[zX] == zMI)
391 {
392 pAstCfg->masterDec = zX;
393 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
394 break;
395 }
396 }
397 zMD = pAstCfg->masterDec;
398 zMS = pAstCfg->masterStr;
400 // Initialize as per parametrized phases:
401 //
402 // In standard form these are:
403 // - Malloc: Memory Allocation
404 // - Config: Configuration Initialization
405 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
406 // - Common: Common Memory Initialization
407 // - AlgKey: Dec/Enc chain to Array Initialization
408 // - Device: I/O Device Initialization
409 // - DecOpCircBuf: Decoder Output Circular Buffer
410 // - Unused: (available)
411 //
412 LINNO_RPRT(TaskAsip, -2);
413 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
414 {
415 Int linno;
416 if (pP->fxns->initPhase[i])
417 {
418 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
419 {
420 LINNO_RPRT(TaskAsip, linno);
421 return;
422 }
423 }
424 else
425 {
426 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
427 }
428 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
429 LINNO_RPRT(TaskAsip, -i-3);
430 }
432 //
433 // End of Initialization -- display memory usage report.
434 //
435 if (pP->fxns->memStatusPrint)
436 {
437 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
438 }
440 // (***) FL: revisit
441 // write back AST shared configuration
442 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
443 // FL: no need to share this pointer, can be local
444 //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
445 Cache_wait();
447 // (***) FL: revisit
448 // write back Dec configuration
449 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
450 Cache_wait();
452 // (***) FL: revisit
453 // write back entire beta table
454 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
455 Cache_wait();
457 // FL: send start initialization message to slave
458 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
459 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
460 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
461 pAspMsg->procId = hAspMsgMaster->masterProcId;
462 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
463 pAspMsg->expectResp = TRUE;
464 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
465 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
466 if (status != MessageQ_S_SUCCESS)
467 {
468 SW_BREAKPOINT;
469 }
470 // wait for initialization complete message from slave
471 do {
472 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
473 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
474 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
475 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
476 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
477 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
478 {
479 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
480 SW_BREAKPOINT;
481 }
482 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
483 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
484 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
485 if (status != MessageQ_S_SUCCESS)
486 {
487 SW_BREAKPOINT;
488 }
490 // (***) FL: revisit
491 // invalidate Status structure addresses for Beta Units initialized on Slave
492 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
493 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
494 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
495 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
496 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
497 Cache_wait();
498 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
499 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
500 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
501 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
502 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
504 // (***) FL: revisit
505 // invalidate Status structures for Beta Units initialized on Slave
506 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
507 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
508 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
509 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
510 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
511 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
512 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
513 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
514 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
515 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
516 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
517 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
518 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
519 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
520 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
521 Cache_wait();
523 // (***) FL: revisit
524 // invalidate Dec configuration
525 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
526 Cache_wait();
528 //
529 // Main processing loop
530 //
531 for (z=STREAM1; z < STREAMN; z++)
532 {
533 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
534 }
536 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
538 errno = 0;
539 for (;;)
540 {
541 Int sourceSelect;
542 XDAS_Int8 sourceProgram;
544 loopCount++;
546 #if 0 // enable and tune to see startup behavior.
547 // this is an alternative to fixed/circular setting in pa.cfg.
548 // If you are searching for a memory allocation failure, disable on first round.
549 // All allocation has already happened.
550 // This is the outer loop. This loop count goes up when the stream resets.
551 // If the stream is running without problems, this does not increment.
552 // If the stream is repeatedly resetting, this loop count will go up rapidly.
553 if (loopCount > 10) // see traces for a few of the passes through the main loop.
554 {
555 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
556 LOG_disable(&TR_MOD); // stop tracing
557 }
558 #endif
560 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
561 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
563 // since not decoding indicate such
564 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
566 // any error forces idling of input
567 if (errno)
568 {
569 for (z=INPUT1; z < INPUTN; z++)
570 {
571 if (pAstCfg->xInp[z].hRxSio)
572 {
573 SIO_idle(pAstCfg->xInp[z].hRxSio);
574 }
575 }
577 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
578 ERRNO_RPRT(TaskAsip, errno);
579 }
581 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
582 // up to allow lower priority tasks to run. This may seem odd to be at the top
583 // of the state machine but provides for a cleaner flow even though the very
584 // first time we enter we do a sleep which is non-intuitive.
585 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
586 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
587 Task_sleep(1);
589 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
590 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
591 {
592 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
593 continue;
594 }
596 // if no master input selected then we don't know what may be at the input
597 // so set to unknown and skip any remaining processing
598 if (!pAstCfg->xInp[zMI].hRxSio)
599 {
600 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
601 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
602 continue;
603 }
605 // if here then we have a valid input so query its status
606 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
607 {
608 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
609 continue;
610 }
612 // If master decoder is not enabled, or the input is unlocked, then do nothing
613 if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
614 {
615 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
616 continue;
617 }
619 // If no source selected then do nothing
620 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
621 {
622 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
623 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
624 continue;
625 }
627 // If we want pass processing then proceed directly
628 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
629 {
630 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
631 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
632 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
633 if (pP->fxns->passProcessing)
634 {
635 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
636 }
637 else
638 {
639 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
640 errno = ASPERR_PASS;
641 }
642 TRACE_VERBOSE0("TaskAsip: continue");
643 continue;
644 }
646 // .....................................................................
647 // At this point we have an enabled input and want to decode something.
648 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
649 // when no decoder is selected there are no calls to IB
650 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
651 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pAstCfg->xDec[zMD].decodeStatus.sourceSelect, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
652 {
653 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
654 continue;
655 }
657 // query for input type
658 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
659 {
660 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
661 errno = ASPERR_AUTO_PROGRAM;
662 continue;
663 }
664 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
666 // if input is unclassifiable then do nothing
667 if (sourceProgram == PAF_SOURCE_UNKNOWN)
668 {
669 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
670 continue;
671 }
673 // now that we have some input classification, and possibly an outstanding
674 // input frame, we determine whether or not to call decodeProcessing and with
675 // what decAlg.
676 sourceSelect = PAF_SOURCE_NONE;
677 switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect)
678 {
679 // If autodetecting, decoding everything, and input is something
680 // (i.e. bitstream or PCM) then decode.
681 case PAF_SOURCE_AUTO:
682 if (sourceProgram >= PAF_SOURCE_PCM)
683 {
684 sourceSelect = sourceProgram;
685 }
686 break;
688 // If autodetecting, decoding only PCM, and input is PCM then decode.
689 case PAF_SOURCE_PCMAUTO:
690 if (sourceProgram == PAF_SOURCE_PCM)
691 {
692 sourceSelect = sourceProgram;
693 }
694 break;
696 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
697 case PAF_SOURCE_BITSTREAM:
698 if (sourceProgram >= PAF_SOURCE_AC3)
699 {
700 sourceSelect = sourceProgram;
701 }
702 break;
704 // If autodetecting, decoding only DTS, and input is DTS then decode.
705 case PAF_SOURCE_DTSALL:
706 switch (sourceProgram)
707 {
708 case PAF_SOURCE_DTS11:
709 case PAF_SOURCE_DTS12:
710 case PAF_SOURCE_DTS13:
711 case PAF_SOURCE_DTS14:
712 case PAF_SOURCE_DTS16:
713 case PAF_SOURCE_DTSHD:
714 sourceSelect = sourceProgram;
715 break;
716 }
717 break;
719 // All others, e.g., force modes, fall through to here.
720 // If user made specific selection then program must match select.
721 // (NB: this compare relies on ordering of PAF_SOURCE)
722 default:
723 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
724 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
725 {
726 if (sourceProgram != sourceSelect)
727 {
728 sourceSelect = PAF_SOURCE_NONE;
729 }
730 }
731 break;
732 }
734 // if we didn't find any matches then skip
735 if (sourceSelect == PAF_SOURCE_NONE)
736 {
737 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
738 continue;
739 }
741 // FL: debug, reset IB capture buffer
742 //capIbReset();
743 //Log_info0("capIbReset()");
745 // FL: send source select message to slave
746 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
747 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
748 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
749 pAspMsg->procId = hAspMsgMaster->masterProcId;
750 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
751 pAspMsg->expectResp = TRUE;
752 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
753 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
754 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
755 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
756 if (status != MessageQ_S_SUCCESS)
757 {
758 SW_BREAKPOINT;
759 }
760 // wait for source select complete message from slave
761 //do {
762 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
763 //} while (status != MessageQ_S_SUCCESS);
764 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
765 if (status != MessageQ_S_SUCCESS)
766 {
767 TRACE_TERSE0("MessageQ_get() failure.");
768 SW_BREAKPOINT; // temporary
769 }
770 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
771 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
772 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
773 {
774 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
775 SW_BREAKPOINT;
776 }
777 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
778 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
779 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
780 if (status != MessageQ_S_SUCCESS)
781 {
782 SW_BREAKPOINT;
783 }
785 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
786 // iff we are in this top level state machine and specifically not in decodeProcessing
787 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
789 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
791 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
792 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
793 if (errno)
794 {
795 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
796 }
797 else
798 {
799 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
800 }
802 // FL: send dec exit message to slave
803 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
804 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
805 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
806 pAspMsg->procId = hAspMsgMaster->masterProcId;
807 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
808 pAspMsg->expectResp = TRUE;
809 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
810 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
811 if (status != MessageQ_S_SUCCESS)
812 {
813 SW_BREAKPOINT;
814 }
815 // wait for dec exit complete message from slave
816 //do {
817 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
818 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
819 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
820 if (status != MessageQ_S_SUCCESS)
821 {
822 TRACE_TERSE0("MessageQ_get() failure.");
823 SW_BREAKPOINT; // temporary
824 }
825 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
826 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
827 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
828 {
829 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
830 SW_BREAKPOINT;
831 }
832 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
833 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
834 // free the message
835 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
836 if (status != MessageQ_S_SUCCESS)
837 {
838 SW_BREAKPOINT;
839 }
840 } // End of main processing loop for (;;)
842 Log_info0("Exit taskAsipFxn()");
843 }
845 // -----------------------------------------------------------------------------
846 // ASIT Initialization Function - Memory Allocation
847 //
848 // Name: PAF_ASIT_initPhaseMalloc
849 // Purpose: Audio Stream Input Task Function for initialization of data pointers
850 // by allocation of memory.
851 // From: audioStream1Task or equivalent
852 // Uses: See code.
853 // States: x
854 // Return: 0 on success.
855 // Source code line number on MEM_calloc failure.
856 // Trace: Message Log "trace" in Debug Project Configuration reports:
857 // * State information as per parent.
858 // * Memory allocation errors.
859 //
860 Int
861 PAF_ASIT_initPhaseMalloc(
862 const PAF_ASIT_Params *pP,
863 const PAF_ASIT_Patchs *pQ,
864 PAF_ASIT_Config *pC
865 )
866 {
867 PAF_AST_Config *pAstCfg;
868 Int as; /* Audio Stream Number (1, 2, etc.) */
869 Int zMS;
870 Error_Block eb;
872 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
873 as = pAstCfg->as;
874 zMS = pAstCfg->masterStr;
876 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
878 // Initialize error block
879 Error_init(&eb);
881 /* Input memory */
882 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
883 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
884 {
885 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
886 SW_BREAKPOINT;
887 return __LINE__;
888 }
889 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
890 INPUTN * sizeof (*pAstCfg->xInp),
891 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
893 /* Decode memory */
894 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
895 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
896 {
897 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
898 SW_BREAKPOINT;
899 return __LINE__;
900 }
901 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
902 DECODEN * sizeof (*pAstCfg->xDec),
903 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
905 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
906 return 0;
907 } //PAF_ASIT_initPhaseMalloc
909 // -----------------------------------------------------------------------------
910 // ASIT Initialization Function - Memory Initialization from Configuration
911 //
912 // Name: PAF_ASIT_initPhaseConfig
913 // Purpose: Audio Stream Task Function for initialization of data values
914 // from parameters.
915 // From: audioStream1Task or equivalent
916 // Uses: See code.
917 // States: x
918 // Return: 0 on success.
919 // Other as per initFrame0 and initFrame1.
920 // Trace: Message Log "trace" in Debug Project Configuration reports:
921 // * State information as per parent.
922 //
923 Int
924 PAF_ASIT_initPhaseConfig(
925 const PAF_ASIT_Params *pP,
926 const PAF_ASIT_Patchs *pQ,
927 PAF_ASIT_Config *pC
928 )
929 {
930 PAF_AST_Config *pAstCfg;
931 Int as; /* Audio Stream Number (1, 2, etc.) */
932 Int z; /* input/encode/stream/decode/output counter */
933 Int zMS;
935 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
936 as = pAstCfg->as;
937 zMS = pAstCfg->masterStr;
939 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
941 //
942 // Unspecified elements have been initialized to zero during alloc
943 //
945 for (z=INPUT1; z < INPUTN; z++)
946 {
947 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
948 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
949 }
951 for (z=DECODE1; z < DECODEN; z++)
952 {
953 Int zI = pP->inputsFromDecodes[z];
954 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
955 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
956 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
957 }
959 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
960 return 0;
961 } //PAF_ASIT_initPhaseConfig
963 // -----------------------------------------------------------------------------
964 // ASIT Initialization Function - ACP Algorithm Instantiation
965 //
966 // Name: PAF_ASIT_initPhaseAcpAlg
967 // Purpose: Audio Stream Input Task Function for initialization of ACP by
968 // instantiation of the algorithm.
969 // From: audioStream1Task or equivalent
970 // Uses: See code.
971 // States: x
972 // Return: 0 on success.
973 // Source code line number on ACP Algorithm creation failure.
974 // Trace: Message Log "trace" in Debug Project Configuration reports:
975 // * State information as per parent.
976 // * Memory allocation errors.
977 //
978 Int
979 PAF_ASIT_initPhaseAcpAlg(
980 const PAF_ASIT_Params *pP,
981 const PAF_ASIT_Patchs *pQ,
982 PAF_ASIT_Config *pC
983 )
984 {
985 PAF_AST_Config *pAstCfg;
986 Int as; /* Audio Stream Number (1, 2, etc.) */
987 Int z; /* input/encode/stream/decode/output counter */
988 Int betaPrimeOffset;
989 ACP_Handle acp;
990 Int zMS;
991 Int zS, zX;
993 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
994 as = pAstCfg->as;
995 zMS = pAstCfg->masterStr;
997 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
999 ACP_MDS_init();
1001 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1002 {
1003 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1004 return __LINE__;
1005 }
1006 pC->acp = acp;
1008 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1009 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1011 for (z=INPUT1; z < INPUTN; z++)
1012 {
1013 zS = z;
1014 for (zX = DECODE1; zX < DECODEN; zX++)
1015 {
1016 if (pP->inputsFromDecodes[zX] == z)
1017 {
1018 zS = pP->streamsFromDecodes[zX];
1019 break;
1020 }
1021 }
1022 acp->fxns->attach(acp, ACP_SERIES_STD,
1023 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1024 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1025 /* Ignore errors, not reported. */
1026 }
1028 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1030 return 0;
1031 } //PAF_ASIT_initPhaseAcpAlg
1033 // -----------------------------------------------------------------------------
1034 // ASIT Initialization Function - Common Memory
1035 //
1036 // Name: PAF_ASIT_initPhaseCommon
1037 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1038 // From: audioStream1Task or equivalent
1039 // Uses: See code.
1040 // States: x
1041 // Return: 0 on success.
1042 // Source code line number on PAF_ALG_alloc failure.
1043 // Source code line number on PAF_ALG_mallocMemory failure.
1044 // Source code line number on Decode Chain initialization failure.
1045 // Source code line number on ASP Chain initialization failure.
1046 // Source code line number on Encode Chain initialization failure.
1047 // Trace: Message Log "trace" in Debug Project Configuration reports:
1048 // * State information as per parent.
1049 // * Memory allocation errors.
1050 //
1051 Int
1052 PAF_ASIT_initPhaseCommon(
1053 const PAF_ASIT_Params *pP,
1054 const PAF_ASIT_Patchs *pQ,
1055 PAF_ASIT_Config *pC
1056 )
1057 {
1058 PAF_AST_Config *pAstCfg;
1059 Int as; /* Audio Stream Number (1, 2, etc.) */
1060 Int z; /* stream counter */
1061 ACP_Handle acp;
1062 PAF_IALG_Config pafAlgConfig;
1063 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1065 acp = pC->acp;
1066 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1067 as = pAstCfg->as;
1069 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1071 //
1072 // Determine memory needs and instantiate algorithms across audio streams
1073 //
1074 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1075 PAF_ALG_setup(&pafAlgConfig,
1076 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1077 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1078 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1079 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1080 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1081 HEAP_CLEAR);
1083 if (pP->fxns->headerPrint)
1084 {
1085 pP->fxns->headerPrint();
1086 }
1088 for (z = STREAM1; z < STREAMN; z++)
1089 {
1090 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1092 //
1093 // Determine common memory for:
1094 // (1) Logical Input drivers
1095 //
1096 // Decode Algorithms common memory determined in ASP Slave.
1097 //
1098 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1100 //
1101 // Determine common memory needs of Logical Input driver
1102 //
1104 // really need to loop over all inputs for this stream using the tables
1105 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1106 // patch, and not needed for FS11, since there is only one input.
1107 if (INPUT1 <= z && z < INPUTN)
1108 {
1109 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1110 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1111 {
1112 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1113 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1114 SW_BREAKPOINT;
1115 return __LINE__;
1116 }
1117 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1118 if (pP->fxns->allocPrint)
1119 {
1120 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1121 }
1122 }
1123 }
1124 {
1125 // Changes made to share scratch between zones
1126 // Assume maximum 3 zones and scratch common memory is at offset 0;
1127 int max=0;
1128 for (z=STREAM1; z<STREAMN; z++)
1129 {
1130 if (max < common[z][0].size)
1131 {
1132 max = common[z][0].size;
1133 }
1134 }
1135 common[STREAM1][0].size=max;
1136 for (z=STREAM1+1; z<STREAMN; z++)
1137 {
1138 common[z][0].size = 0;
1139 }
1140 }
1142 //
1143 // Allocate common memory for:
1144 // (1) Logical Input drivers
1145 //
1146 for (z = STREAM1; z < STREAMN; z++)
1147 {
1148 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1149 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1150 {
1151 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1152 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1153 SW_BREAKPOINT;
1154 return __LINE__;
1155 }
1156 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1157 // share zone0 scratch with all zones
1158 common[z][0].base = common[0][0].base;
1159 if (pP->fxns->commonPrint)
1160 {
1161 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1162 }
1164 //
1165 // Allocate non-common memories for Logical IO drivers
1166 // Since these structures are used at run-time we allocate from external memory
1167 if (INPUT1 <= z && z < INPUTN)
1168 {
1169 PAF_ASP_Chain *chain;
1170 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1171 as+z, z);
1172 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1173 HEAP_EXTERNAL, as+z, acp, &trace,
1174 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1175 if (!chain)
1176 {
1177 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1178 return __LINE__;
1179 }
1180 }
1181 }
1182 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1184 return 0;
1185 } //PAF_ASIT_initPhaseCommon
1187 // (***) FL: candidate for removal
1188 // -----------------------------------------------------------------------------
1189 // ASIT Initialization Function - Algorithm Keys
1190 //
1191 // Name: PAF_ASIT_initPhaseAlgKey
1192 // Purpose: Audio Stream Input Task Function for initialization of data values
1193 // from parameters for Algorithm Keys.
1194 // From: audioStream1Task or equivalent
1195 // Uses: See code.
1196 // States: x
1197 // Return: 0.
1198 // Trace: Message Log "trace" in Debug Project Configuration reports:
1199 // * State information as per parent.
1200 //
1201 // .............................................................................
1202 Int
1203 PAF_ASIT_initPhaseAlgKey(
1204 const PAF_ASIT_Params *pP,
1205 const PAF_ASIT_Patchs *pQ,
1206 PAF_ASIT_Config *pC
1207 )
1208 {
1209 PAF_AST_Config *pAstCfg;
1210 Int as; /* Audio Stream Number (1, 2, etc.) */
1213 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1214 as = pAstCfg->as;
1215 (void)as; // clear compiler warning in case not used with tracing disabled
1217 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1219 #if 0 // FL: slave
1220 for (z=DECODE1; z < DECODEN; z++)
1221 {
1222 for (s=0; s < pP->pDecAlgKey->length; s++)
1223 {
1224 if ((pP->pDecAlgKey->code[s].full != 0) &&
1225 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1226 {
1227 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1228 /* Cast in interface, for now --Kurt */
1229 }
1230 else
1231 {
1232 pC->xDec[z].decAlg[s] = NULL;
1233 }
1234 }
1235 }
1236 #endif
1238 return 0;
1239 } //PAF_ASIT_initPhaseAlgKey
1241 // -----------------------------------------------------------------------------
1242 // ASIT Initialization Function - I/O Devices
1243 //
1244 // Name: PAF_ASIT_initPhaseDevice
1245 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1246 // From: audioStream1Task or equivalent
1247 // Uses: See code.
1248 // States: x
1249 // Return: 0 on success.
1250 // Source code line number on device allocation failure.
1251 // Trace: Message Log "trace" in Debug Project Configuration reports:
1252 // * State information as per parent.
1253 // * Memory allocation errors.
1254 //
1255 Int
1256 PAF_ASIT_initPhaseDevice(
1257 const PAF_ASIT_Params *pP,
1258 const PAF_ASIT_Patchs *pQ,
1259 PAF_ASIT_Config *pC
1260 )
1261 {
1262 PAF_AST_Config *pAstCfg;
1263 Int as; /* Audio Stream Number (1, 2, etc.) */
1264 Int z; /* input/output counter */
1265 PAF_SIO_IALG_Obj *pObj;
1266 PAF_SIO_IALG_Config *pAlgConfig;
1267 PAF_IALG_Config pafAlgConfig;
1270 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1271 as = pAstCfg->as;
1272 (void)as; // clear compiler warning in case not used with tracing disabled
1274 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1276 if (pP->fxns->bufMemPrint)
1277 {
1278 PAF_ALG_setup (&pafAlgConfig,
1279 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1280 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1281 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1282 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1283 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1284 HEAP_CLEAR);
1285 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1286 }
1288 for (z=INPUT1; z < INPUTN; z++)
1289 {
1290 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1292 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1293 pAlgConfig = &pObj->config;
1295 pAstCfg->xInp[z].hRxSio = NULL;
1297 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1298 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1299 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1300 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1301 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1302 pConfig->sizeofElement = 2;
1303 pConfig->precision = 16;
1305 if (pP->fxns->bufMemPrint)
1306 {
1307 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1308 }
1309 }
1311 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1313 return 0;
1314 } //PAF_ASIT_initPhaseDevice
1316 // -----------------------------------------------------------------------------
1317 // ASIT Initialization Function - Decoder Output Circular Buffer
1318 //
1319 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1320 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1321 // From: audioStream1Task or equivalent
1322 // Uses: See code.
1323 // States: x
1324 // Return: 0 on success.
1325 // Source code line number on device allocation failure.
1326 // Trace: Message Log "trace" in Debug Project Configuration reports:
1327 // * State information as per parent.
1328 // * Memory allocation errors.
1329 //
1330 Int
1331 PAF_ASIT_initPhaseDecOpCircBuf(
1332 const PAF_ASIT_Params *pP,
1333 const PAF_ASIT_Patchs *pQ,
1334 PAF_ASIT_Config *pC
1335 )
1336 {
1337 PAF_AST_Config *pAstCfg;
1338 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1339 Int as; /* Audio Stream Number (1, 2, etc.) */
1340 Int zMS;
1341 Int z; /* decode counter */
1342 Int errno; /* error number */
1343 Error_Block eb;
1344 Int i;
1346 // FL: (***)revisit
1347 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1348 as = pAstCfg->as;
1349 zMS = pAstCfg->masterStr;
1351 /* Decode output circular buffer memory */
1352 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1353 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1354 {
1355 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1356 SW_BREAKPOINT;
1357 return __LINE__;
1358 }
1359 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1360 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1361 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1363 for (z=DECODE1; z < DECODEN; z++)
1364 {
1365 pCb = &pAstCfg->xDecOpCb[z];
1367 // allocate audio frame circular buffer
1368 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1369 {
1370 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1371 SW_BREAKPOINT;
1372 }
1373 // allocate audio frame PCM sample pointer array
1374 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1375 {
1376 if (!(pCb->afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioData *), 4, &eb)))
1377 {
1378 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1379 SW_BREAKPOINT;
1380 }
1381 if (!(pCb->afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioSize), 4, &eb)))
1382 {
1383 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1384 SW_BREAKPOINT;
1385 }
1386 }
1387 // allocate PCM sample buffer
1388 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1389 {
1390 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1391 SW_BREAKPOINT;
1392 }
1393 // allocate Metadata buffers //QIN
1394 if (!(pCb->metaBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
1395 {
1396 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1397 SW_BREAKPOINT;
1398 }
1400 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1401 // Initialize decoder output circular buffer for PCM
1402 errno = cbInit(pCb);
1403 if (errno)
1404 {
1405 SW_BREAKPOINT; // FL: debug
1406 return errno;
1407 }
1408 }
1410 return 0;
1411 } //PAF_ASIT_initPhaseDecOpCircBuf
1414 #if 0
1415 // -----------------------------------------------------------------------------
1416 // AST Processing Function - Pass-Through Processing
1417 //
1418 // Name: PAF_AST_passProcessing
1419 // Purpose: Audio Stream Task Function for processing audio data as a
1420 // pass-through from the input driver to the output driver
1421 // for development and testing.
1422 // From: audioStream1Task or equivalent
1423 // Uses: See code.
1424 // States: x
1425 // Return: Error number in standard form (0 on success).
1426 // Trace: Message Log "trace" in Debug Project Configuration reports:
1427 // * State information on initialization.
1428 // * State information on processing.
1429 //
1431 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1432 /* Pass Processing is often omitted from builds to save memory, */
1433 /* and CODE_SECTION/clink constructs facilitate this omission. */
1435 Int
1436 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1437 {
1438 Int z; /* input/output counter */
1439 Int errno = 0; /* error number */
1440 Int getVal;
1441 Int rxNumChan, txNumChan;
1442 Int first;
1443 Int zMD = pC->masterDec;
1444 Int zMI = pP->zone.master;
1447 #ifndef __TI_EABI__
1448 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1449 #endif
1451 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1453 //
1454 // Determine that receive/transmit channels are compatible
1455 //
1457 // Can handle handle only master input
1458 for (z=INPUT1; z < INPUTN; z++) {
1459 if (z != zMI && pC->xInp[z].hRxSio)
1460 return (ASPERR_PASS + 0x01);
1461 }
1463 /* Number of receive/transmit channels */
1465 if (! pC->xInp[zMI].hRxSio)
1466 return (ASPERR_PASS + 0x11);
1467 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1468 return (ASPERR_PASS + 0x12);
1469 if (rxNumChan > NUM_TX_CHAN(zMI))
1470 return (ASPERR_PASS + 0x13);
1472 for (z=OUTPUT1; z < OUTPUTN; z++) {
1473 if (! pC->xOut[zMI].hTxSio)
1474 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1475 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1476 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1477 if (txNumChan > NUM_TX_CHAN(zMI))
1478 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1479 }
1481 //
1482 // Set up receive/transmit
1483 //
1485 SIO_idle (pC->xInp[zMI].hRxSio);
1486 for (z=OUTPUT1; z < OUTPUTN; z++) {
1487 if(SIO_idle (pC->xOut[z].hTxSio))
1488 return ASPERR_IDLE;
1489 }
1491 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1492 return (ASPERR_PASS + 0x14);
1494 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1495 return (ASPERR_PASS + 0x15);
1497 for (z=OUTPUT1; z < OUTPUTN; z++)
1498 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1500 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1501 return ASPERR_PASS + 0x16;
1503 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1504 return ASPERR_PASS + 0x17;
1506 //
1507 // Receive and transmit the data in single-frame buffers
1508 //
1510 first = 1;
1511 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1512 PAF_OutBufConfig *pOutBuf;
1513 PAF_InpBufConfig *pInpBuf;
1515 if (first) {
1516 first = 0;
1518 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1520 for (z=OUTPUT1; z < OUTPUTN; z++) {
1521 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1522 if (getVal > 0) {
1523 errno = ASPERR_ISSUE;
1524 break;
1525 }
1526 else if (getVal < 0) {
1527 errno = -getVal;
1528 break;
1529 }
1531 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1532 return (getVal & 0xff) | ASPERR_MUTE;
1533 }
1534 if (errno)
1535 break;
1537 }
1539 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1540 if (getVal > 0) {
1541 errno = ASPERR_ISSUE;
1542 break;
1543 }
1545 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1547 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1548 if (getVal < 0) {
1549 errno = -getVal;
1550 break;
1551 }
1553 for (z=OUTPUT1; z < OUTPUTN; z++) {
1554 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1555 if (getVal < 0) {
1556 errno = -getVal;
1557 break;
1558 }
1559 }
1560 if( errno )
1561 break;
1563 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1565 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1566 break;
1568 for (z=OUTPUT1; z < OUTPUTN; z++) {
1569 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1570 if (getVal > 0) {
1571 errno = ASPERR_ISSUE;
1572 break;
1573 }
1574 else if (getVal < 0) {
1575 errno = -getVal;
1576 break;
1577 }
1578 }
1579 if( errno )
1580 break;
1581 }
1583 //
1584 // Close down receive/transmit
1585 //
1587 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1589 for (z=OUTPUT1; z < OUTPUTN; z++) {
1590 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1591 if (! errno)
1592 errno = (getVal & 0xff) | ASPERR_MUTE;
1593 /* convert to sensical errno */
1594 }
1595 }
1597 SIO_idle (pC->xInp[zMI].hRxSio);
1598 for (z=OUTPUT1; z < OUTPUTN; z++)
1599 SIO_idle (pC->xOut[z].hTxSio);
1601 return errno;
1603 } //PAF_AST_passProcessing
1604 #endif // #if 0
1606 #if 0
1607 // -----------------------------------------------------------------------------
1608 // AST Processing Function Helper - Pass-Through Processing Patch Point
1609 //
1610 // Name: PAF_AST_passProcessingCopy
1611 // Purpose: Pass-Through Processing Function for copying audio data
1612 // from the input buffer to the output buffer.
1613 // From: AST Parameter Function -> passProcessing
1614 // Uses: See code.
1615 // States: x
1616 // Return: Error number in standard form (0 on success).
1617 // Trace: Message Log "trace" in Debug Project Configuration reports:
1618 // x
1619 //
1621 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1622 /* Pass Processing is often omitted from builds to save memory, */
1623 /* and CODE_SECTION/clink constructs facilitate this omission. */
1625 Int
1626 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1627 {
1628 Int z; /* output counter */
1629 Int errno; /* error number */
1630 Int i;
1631 Int rxNumChan, txNumChan;
1632 Int zMI = pP->zone.master;
1635 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1637 // Copy data from input channels to output channels one of two ways:
1639 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1640 return (ASPERR_PASS + 0x12);
1642 for (z=OUTPUT1; z < OUTPUTN; z++) {
1643 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1644 return (ASPERR_PASS + 0x22);
1646 if( txNumChan <= rxNumChan ) {
1648 // Copy one to one, ignoring later rx channels as needed.
1650 for( i=0; i < txNumChan; i++ ) {
1651 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1652 if( errno )
1653 return errno;
1654 }
1655 }
1656 else {
1658 // Copy one to many, repeating earlier rx channels as needed.
1660 Int from, to;
1662 from = 0;
1663 to = 0;
1664 while( to < txNumChan ) {
1665 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1666 if( errno )
1667 return errno;
1669 from++;
1670 to++;
1671 if( from == rxNumChan )
1672 from = 0;
1673 }
1674 }
1675 }
1677 return 0;
1678 } //PAF_AST_passProcessingCopy
1679 #endif // #if 0
1681 // -----------------------------------------------------------------------------
1682 // ASIT Processing Function - Auto Processing
1683 //
1684 // Name: PAF_ASIT_autoProcessing
1685 // Purpose: Audio Stream Input Task Function for processing audio data to
1686 // determine the input type without output.
1687 // From: audioStream1Task or equivalent
1688 // Uses: See code.
1689 // States: x
1690 // Return: Error number in standard or SIO form (0 on success).
1691 // Trace: Message Log "trace" in Debug Project Configuration reports:
1692 // * State information on initialization.
1693 //
1695 #define DECSIOMAP(X) \
1696 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1698 Int
1699 PAF_ASIT_autoProcessing(
1700 const PAF_ASIT_Params *pP,
1701 const PAF_ASIT_Patchs *pQ,
1702 PAF_ASIT_Config *pC,
1703 Int inputTypeSelect,
1704 ALG_Handle pcmAlgMaster
1705 )
1706 {
1707 PAF_AST_Config *pAstCfg;
1708 Int as; /* Audio Stream Number (1, 2, etc.) */
1709 Int errno = 0; /* error number */
1710 Int nbytes;
1711 Int frameLength;
1712 Int zMD;
1713 Int zMI;
1714 Int zMS;
1716 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1717 as = pAstCfg->as;
1718 zMD = pAstCfg->masterDec;
1719 zMS = pAstCfg->masterStr;
1720 zMI = pP->zone.master;
1722 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1724 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1725 PAF_SIO_CONTROL_SET_SOURCESELECT,
1726 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1727 {
1728 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1729 return errno;
1730 }
1731 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1732 // pC->xDec[zMD].decodeStatus.bufferRatio);
1733 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1735 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1736 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1737 {
1738 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1739 errno, ASPERR_AUTO_LENGTH);
1740 return ASPERR_AUTO_LENGTH;
1741 }
1743 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1744 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1745 PAF_SIO_REQUEST_SYNC))
1746 {
1747 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1748 errno, ASPERR_ISSUE);
1749 return ASPERR_ISSUE;
1750 }
1752 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1754 // all of the sync scan work is done in this call. If the error returned
1755 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1756 // error so we mask it off.
1757 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1758 if (nbytes == -DIBERR_SYNC)
1759 {
1760 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1761 return 0;
1762 }
1763 if (nbytes != sizeof(PAF_InpBufConfig))
1764 {
1765 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1766 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1767 return ASPERR_RECLAIM;
1768 }
1769 if (errno)
1770 {
1771 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1772 }
1773 return errno;
1774 } //PAF_ASIT_autoProcessing
1776 // -----------------------------------------------------------------------------
1777 // ASIT Processing Function - Decode Processing
1778 //
1779 // Name: PAF_ASIT_decodeProcessing
1780 // Purpose: Audio Stream Input Task Function for processing audio data.
1781 // From: audioStream1Task or equivalent
1782 // Uses: See code.
1783 // States: x
1784 // Return: Error number in standard form (0 on success).
1785 // Trace: Message Log "trace" in Debug Project Configuration reports:
1786 // * State information on initialization (via children).
1787 // * State information on processing (via children).
1788 // * Decode warnings.
1789 //
1790 // When "writeDECModeContinuous" is used for zMI input/decode:
1791 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1792 // (a) if "writeDECCommandRestart" is used
1793 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1794 // (b) if "writeDECSourceSelectNone" is used
1795 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1796 // (c) if an error occurs in
1797 // INIT
1798 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1799 // -> PAF_AST_decodeCont(): "Await slave inputs"
1800 // STREAM (errno |= PAF_COMPONENT_ASP)
1801 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1802 // [ the latter errors lead to "switch_break:"
1803 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1804 //
1805 // [ Notably, in FINAL ("frame-finalization state")
1806 // -> PAF_AST_decodeFinalTest() is *not* called,
1807 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1808 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1809 //
1810 // States in which error can't occur:
1811 // AGAIN ("subsequent initial state")
1812 //
1813 // States in which (some) errors must be handled:
1814 // INFO1 ("first frame state")
1815 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1816 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1817 // ?*? but what about ASPERR_RESYNC from same call ?*?
1818 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1819 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1820 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1821 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1822 // - enc->fxns->info()
1823 // - pP->fxns->setCheckRateX()
1824 // - pP->fxns->startOutput()
1825 // - "Start slave inputs if necessary"
1826 // INFO2 ("subsequent frame state")
1827 // -> PAF_AST_decodeInfo(): (see above)
1828 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1829 // - pP->fxns->setCheckRateX()
1830 // TIME ("timing state")
1831 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1832 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1833 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1834 // (*OK* don't try to recover from this*)
1835 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1836 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1837 // possibly in PAF_AST_decodeProcessing() itself **
1838 // DECODE ("decode state")
1839 // -> PAF_AST_decodeDecode(): pass on error from
1840 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1841 // - dec->fxns->reset()
1842 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1843 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
1844 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1845 Int
1846 PAF_ASIT_decodeProcessing(
1847 const PAF_ASIT_Params *pP,
1848 const PAF_ASIT_Patchs *pQ,
1849 PAF_ASIT_Config *pC,
1850 Int sourceSelect
1851 )
1852 {
1853 PAF_AST_Config *pAstCfg;
1854 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1855 Int z; /* decode counter */
1856 Int errno; /* error number */
1857 Int getVal;
1858 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1859 ALG_Handle alg[DECODEN_MAX];
1860 Int zMD;
1861 Int zMS;
1862 Int size;
1863 //PAF_InpBufConfig *pIpBufConfig;
1864 Int frame; // decoder input frame count
1865 Int block; // (***) FL: formerly -- decoder output block count / input frame
1868 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1869 zMD = pAstCfg->masterDec;
1870 zMS = pAstCfg->masterStr;
1872 for (z=DECODE1; z < DECODEN; z++)
1873 {
1874 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
1875 }
1876 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1878 //
1879 // Receive and process the data in single-frame buffers
1880 //
1882 state = INIT;
1883 errno = 0; /* error number */
1885 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
1887 for (;;)
1888 {
1889 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
1890 {
1891 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1892 state = QUIT;
1893 }
1895 // Process commands (decode)
1896 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
1897 {
1898 if (state != INIT) // no need to restart/abort if not yet started
1899 {
1900 if (getVal == ASPERR_QUIT)
1901 {
1902 state = QUIT;
1903 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1904 }
1905 else if (getVal == ASPERR_ABORT)
1906 {
1907 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1908 return getVal;
1909 }
1910 else
1911 {
1912 /* ignore */;
1913 }
1914 }
1915 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
1916 }
1918 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
1919 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
1921 // Process state (decode)
1922 switch (state)
1923 {
1924 case INIT: // initial state
1925 gAsipInitCnt++;
1926 Log_info0("TaskAsip: state=INIT");
1928 // (***) FL: revisit
1929 #if 1 // status for shared beta units can change (e.g. at-boot or alpha)
1930 // write back Status structures for shared Beta Units
1931 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1932 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1933 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1934 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1935 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1936 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1937 Cache_wait();
1938 #endif
1939 #if 0
1940 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1941 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1942 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1943 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1944 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1945 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1946 //Cache_wait();
1947 #endif
1949 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1950 {
1951 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1952 break;
1953 }
1955 #if 1
1956 // (***) FL: revisit
1957 // invalidate Status structures for shared Beta Units
1958 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1959 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1960 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1961 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1962 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1963 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1964 Cache_wait();
1965 #endif
1967 frame = 0;
1968 block = 0;
1970 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
1971 state = INFO1;
1972 continue;
1974 case INFO1: // first frame state
1975 gAsipInfo1Cnt++;
1976 Log_info0("TaskAsip: state=INFO1");
1978 #if 0
1979 //// (***) FL: revisit
1980 //// write back Inp configuration
1981 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
1982 //// write back input data
1983 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
1984 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
1985 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
1986 //// write back Dec configuration
1987 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1988 //Cache_wait();
1989 #endif
1991 // Establish primary timing
1992 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
1993 {
1994 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1995 break;
1996 }
1998 #if 0
1999 //// (***) FL: revisit
2000 //// invalidate Dec configuration
2001 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2002 //Cache_wait();
2003 #endif
2005 // Don't start decode until major access unit is found.
2006 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
2007 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
2008 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2009 (pAstCfg->xStr[zMS].pAudioFrame->sampleRate == PAF_SAMPLERATE_UNKNOWN))
2010 {
2011 Int z;
2012 for (z=DECODE1; z < DECODEN; z++)
2013 {
2014 Int zI = pP->inputsFromDecodes[z];
2015 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2016 {
2017 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2018 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2019 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2020 {
2021 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2022 return (ASPERR_ISSUE);
2023 }
2024 }
2025 }
2026 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2027 frame++;
2028 state = INFO1;
2029 continue;
2030 }
2031 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2033 // Establish secondary timing
2034 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2035 {
2036 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2037 break;
2038 }
2040 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2041 state = DECODE;
2042 continue;
2044 case INFO2: // subsequent frame state
2045 gAsipInfo2Cnt++;
2046 Log_info0("TaskAsip: state=INFO2");
2048 #if 0
2049 //// (***) FL: revisit
2050 //// write back Inp configuration
2051 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2052 //// write back input data
2053 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2054 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2055 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2056 //// write back Dec configuration
2057 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2058 //Cache_wait();
2059 #endif
2061 // Establish primary timing
2062 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2063 {
2064 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2065 break;
2066 }
2068 #if 0
2069 //// (***) FL: revisit
2070 //// invalidate Dec configuration
2071 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2072 //Cache_wait();
2073 #endif
2075 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2076 {
2077 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2078 break;
2079 }
2081 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2082 state = DECODE;
2083 continue;
2085 case DECODE: // decode state
2086 gAsipDecodeCnt++;
2087 Log_info0("TaskAsip: state=DECODE");
2089 #if 0
2090 //// (***) FL: revisit
2091 //// write back Dec configuration
2092 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2093 //Cache_wait();
2094 #endif
2096 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2097 {
2098 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2099 break;
2100 }
2102 #if 0
2103 //// (***) FL: revisit
2104 //// invalidate Dec configuration
2105 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2106 //Cache_wait();
2107 #endif
2109 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2110 state = FINAL;
2111 continue;
2113 case FINAL: // frame-finalization state
2114 gAsipFinalCnt++;
2115 Log_info0("TaskAsip: state=FINAL");
2117 // Check for final frame, and if indicated:
2118 // - Exit state machine to "complete" processing.
2119 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2120 {
2121 break;
2122 }
2124 frame++;
2125 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2126 state = INFO2;
2127 continue;
2129 case QUIT: // exit state
2130 gAsipQuitCnt++;
2131 Log_info0("TaskAsip: state=QUIT");
2133 // Quit:
2134 // - Set error number registers.
2135 // - Exit state machine to "decode complete" processing.
2136 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2137 errno = ASPERR_QUIT;
2138 break;
2140 default: // unknown state
2142 // Unknown:
2143 // - Set error number registers.
2144 // - Exit state machine to "decode complete" processing.
2146 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2147 errno = ASPERR_UNKNOWNSTATE;
2148 break;
2150 } // End of switch (state).
2152 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2153 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2154 {
2155 /* ignored? */;
2156 }
2158 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2160 return errno;
2161 } // End of for (;;) to Receive, process, and transmit the data.
2162 } //PAF_ASIT_decodeProcessing
2164 // -----------------------------------------------------------------------------
2165 // ASIT Decoding Function - Decode Command Processing
2166 //
2167 // Name: PAF_ASIT_decodeCommand
2168 // Purpose: Decoding Function for processing Decode Commands.
2169 // From: AST Parameter Function -> decodeProcessing
2170 // Uses: See code.
2171 // States: x
2172 // Return: Error number in standard form (0 on success).
2173 // Trace: Message Log "trace" in Debug Project Configuration reports:
2174 // * Command execution.
2175 //
2177 Int
2178 PAF_ASIT_decodeCommand(
2179 const PAF_ASIT_Params *pP,
2180 const PAF_ASIT_Patchs *pQ,
2181 PAF_ASIT_Config *pC
2182 )
2183 {
2184 PAF_AST_Config *pAstCfg;
2185 Int as; /* Audio Stream Number (1, 2, etc.) */
2186 Int z; /* decode counter */
2187 Int zS;
2189 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2190 as = pAstCfg->as;
2192 for (z=DECODE1; z < DECODEN; z++)
2193 {
2194 zS = pP->streamsFromDecodes[z];
2195 if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2196 {
2197 switch (pAstCfg->xDec[z].decodeStatus.command2)
2198 {
2199 case 0: // command none - process
2200 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2201 break;
2202 case 1: // command abort - leave now
2203 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2204 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2205 return (ASPERR_ABORT);
2206 case 2: // command restart - leave later
2207 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2208 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2209 return (ASPERR_QUIT);
2210 default: // command unknown - ignore
2211 break;
2212 }
2213 }
2214 }
2216 return 0;
2217 } //PAF_ASIT_decodeCommand
2219 // -----------------------------------------------------------------------------
2220 // ASIT Decoding Function - Reinitialization of Decode
2221 //
2222 // Name: PAF_ASIT_decodeInit
2223 // Purpose: Decoding Function for reinitializing the decoding process.
2224 // From: AST Parameter Function -> decodeProcessing
2225 // Uses: See code.
2226 // States: x
2227 // Return: Error number in standard or SIO form (0 on success).
2228 // Trace: Message Log "trace" in Debug Project Configuration reports:
2229 // * State information as per parent.
2230 //
2231 Int
2232 PAF_ASIT_decodeInit(
2233 const PAF_ASIT_Params *pP,
2234 const PAF_ASIT_Patchs *pQ,
2235 PAF_ASIT_Config *pC,
2236 Int sourceSelect
2237 )
2238 {
2239 PAF_AST_Config *pAstCfg;
2240 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2241 Int as; /* Audio Stream Number (1, 2, etc.) */
2242 Int z; /* decode/encode counter */
2243 Int errno; /* error number */
2244 Int zI, zS;
2245 Int zMD;
2246 Int zMI;
2247 ASP_Msg* pAspMsg; /* Messaging */
2248 Int argIdx;
2249 Int decErrno;
2250 Int status;
2252 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2253 as = pAstCfg->as;
2254 zMD = pAstCfg->masterDec;
2255 zMI = pP->zone.master;
2256 (void)as; // clear compiler warning in case not used with tracing disabled
2258 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2260 // reset frameCount
2261 for (z=DECODE1; z < DECODEN; z++)
2262 {
2263 if (pAstCfg->xDec[z].decodeStatus.mode)
2264 {
2265 pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2266 }
2267 }
2269 for (z=DECODE1; z < DECODEN; z++)
2270 {
2271 zI = pP->inputsFromDecodes[z];
2272 zS = pP->streamsFromDecodes[z];
2273 (void)zS; // clear compiler warning in case not used with tracing disabled
2274 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2275 {
2276 Uns gear;
2277 Int frameLength;
2278 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2280 // write back Dec configuration
2281 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2282 Cache_wait();
2284 // FL: send dec activate message to slave
2285 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2286 if (pAspMsg == NULL)
2287 {
2288 TRACE_TERSE0("MessageQ_alloc() failure.");
2289 SW_BREAKPOINT; // temporary
2290 return -1; // temporary
2291 }
2292 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2293 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2294 pAspMsg->procId = hAspMsgMaster->masterProcId;
2295 pAspMsg->expectResp = TRUE;
2296 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2297 argIdx = 0; // set decIdx (zone index)
2298 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2299 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2300 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2301 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2302 if (status != MessageQ_S_SUCCESS)
2303 {
2304 SW_BREAKPOINT;
2305 }
2306 // wait for dec activate complete message from slave
2307 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2308 if (status != MessageQ_S_SUCCESS)
2309 {
2310 TRACE_TERSE0("MessageQ_get() failure.");
2311 SW_BREAKPOINT; // temporary
2312 return -1; // temporary
2313 }
2314 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2315 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2316 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2317 {
2318 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2319 SW_BREAKPOINT; // temporary
2320 return -1; // temporary
2321 }
2322 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2323 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2324 // free the message
2325 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2326 if (status != MessageQ_S_SUCCESS)
2327 {
2328 SW_BREAKPOINT;
2329 }
2331 #if 0 // FL: decoder activate call, slave
2332 if (decAlg[z]->fxns->algActivate)
2333 decAlg[z]->fxns->algActivate (decAlg[z]);
2334 #endif
2336 // FL: send dec reset message to slave
2337 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2338 if (pAspMsg == NULL)
2339 {
2340 TRACE_TERSE0("MessageQ_alloc() failure.");
2341 SW_BREAKPOINT; // temporary
2342 return -1; // temporary
2343 }
2344 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2345 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2346 pAspMsg->procId = hAspMsgMaster->masterProcId;
2347 pAspMsg->expectResp = TRUE;
2348 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2349 argIdx = 0; // set decIdx
2350 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2351 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2352 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2353 // wait for dec reset complete message from slave
2354 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2355 if (status != MessageQ_S_SUCCESS)
2356 {
2357 SW_BREAKPOINT;
2358 }
2359 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2360 if (status != MessageQ_S_SUCCESS)
2361 {
2362 TRACE_TERSE0("MessageQ_get() failure.");
2363 SW_BREAKPOINT; // temporary
2364 return -1; // temporary
2365 }
2366 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2367 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2368 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2369 {
2370 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2371 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2372 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2374 argIdx = 0; // get decErrno
2375 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2376 if (decErrno != 0)
2377 {
2378 return decErrno;
2379 }
2380 }
2381 else
2382 {
2383 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2384 SW_BREAKPOINT; // temporary
2385 return -1; // temporary
2386 }
2387 // free the message
2388 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2389 if (status != MessageQ_S_SUCCESS)
2390 {
2391 SW_BREAKPOINT;
2392 }
2394 // (***) FL: revisit
2395 // invalidate Dec configuration
2396 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2397 Cache_wait();
2399 #if 0 // FL: decoder reset call, slave
2400 if (dec->fxns->reset
2401 && (errno = dec->fxns->reset (dec, NULL,
2402 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2403 return errno;
2404 #endif
2406 gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2407 pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2409 #if 0 // FL: change handle to decIdx (zone index)
2410 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2411 FRAMELENGTH,
2412 pC->xDec[z].decodeStatus.bufferRatio);
2413 #endif
2414 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2415 frameLength = pP->fxns->computeFrameLength(z,
2416 FRAMELENGTH,
2417 pC->xDec[z].decodeStatus.bufferRatio);
2418 #else
2419 if (sourceSelect == PAF_SOURCE_PCM)
2420 {
2421 frameLength = 256;
2422 }
2423 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2424 {
2425 frameLength = 1536;
2426 }
2427 else
2428 {
2429 frameLength = 256;
2430 }
2431 #endif
2433 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2434 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2435 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2437 // (***) FL: revisit. Count samples for DDP.
2438 // Add framework frame length and running sample count to decoder control.
2439 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2440 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2442 // Initialize decoder output circular buffer for selected source
2443 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2444 if (errno)
2445 {
2446 SW_BREAKPOINT; // FL: debug
2447 return errno;
2448 }
2449 // FL: debug
2450 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2452 if (z != zMD)
2453 {
2454 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2455 {
2456 return errno;
2457 }
2458 }
2460 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2461 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2462 {
2463 return errno;
2464 }
2465 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2466 frameLength))
2467 {
2468 return errno;
2469 }
2470 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2471 &pAstCfg->xInp[zI].inpBufConfig))
2472 {
2473 return errno;
2474 }
2475 }
2476 }
2478 if (pAstCfg->xInp[zMI].hRxSio)
2479 {
2480 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2481 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2482 if (errno)
2483 {
2484 return errno;
2485 }
2486 }
2488 return 0;
2489 } //PAF_AST_decodeInit
2491 // -----------------------------------------------------------------------------
2492 // ASIT Decoding Function - Info Processing, Common
2493 //
2494 // Name: PAF_ASIT_decodeInfo
2495 // Purpose: Decoding Function for processing information in a manner that
2496 // is common for both initial and subsequent frames of input data.
2497 // From: AST Parameter Function -> decodeProcessing
2498 // Uses: See code.
2499 // States: x
2500 // Return: Error number in standard form (0 on success).
2501 // Trace: Message Log "trace" in Debug Project Configuration reports:
2502 // * State information as per parent.
2503 //
2504 Int
2505 PAF_ASIT_decodeInfo(
2506 const PAF_ASIT_Params *pP,
2507 const PAF_ASIT_Patchs *pQ,
2508 PAF_ASIT_Config *pC,
2509 Int frame,
2510 Int block
2511 )
2512 {
2513 PAF_AST_Config *pAstCfg;
2514 Int as; /* Audio Stream Number (1, 2, etc.) */
2515 Int z; /* input/decode/stream counter */
2516 Int errno; /* error number */
2517 Int sioErr; /* error number, SIO */
2518 Int zD, zI, zS, zX;
2519 Int zMD;
2520 Int zMI;
2521 Int zMS;
2522 UInt32 curTime;
2523 ASP_Msg *pAspMsg; /* Messaging */
2524 Int argIdx;
2525 Int status;
2526 // FL: revisit
2527 //Int size;
2528 //PAF_InpBufConfig *pIpBufConfig;
2530 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2531 as = pAstCfg->as;
2532 zMD = pAstCfg->masterDec;
2533 zMS = pAstCfg->masterStr;
2534 zMI = pP->zone.master;
2535 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2537 // Set decode control: sample rate, emphasis
2538 for (z=INPUT1; z < INPUTN; z++)
2539 {
2540 zD = z;
2541 for (zX = DECODE1; zX < DECODEN; zX++)
2542 {
2543 if (pP->inputsFromDecodes[zX] == z)
2544 {
2545 zD = zX;
2546 break;
2547 }
2548 }
2550 if (pAstCfg->xInp[z].hRxSio)
2551 {
2552 //determine associated decoder
2553 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2554 pAstCfg->xDec[zD].decodeControl.sampleRate)
2555 {
2556 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2557 {
2558 pAstCfg->xDec[zD].decodeControl.sampleRate =
2559 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2560 }
2561 else
2562 {
2563 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2564 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2565 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2566 pAstCfg->xDec[zD].decodeControl.sampleRate);
2567 // return (ASPERR_INFO_RATECHANGE);
2568 }
2569 }
2570 pAstCfg->xDec[zD].decodeControl.emphasis =
2571 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2572 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2573 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2574 }
2575 else
2576 {
2577 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2578 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2579 }
2580 }
2582 // Wait for info input
2583 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2584 if (pAstCfg->xInp[zMI].hRxSio)
2585 {
2586 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2587 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2588 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2589 {
2590 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2591 return ASPERR_RECLAIM;
2592 }
2594 // FL: debug, capture input buffer
2595 //capIb(pAstCfg->xInp[zMI].pInpBuf);
2597 //
2598 // Simulate Rx SIO_reclaim() pend
2599 //
2600 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2601 gTaskAsipCnt++;
2602 curTime = Clock_getTicks();
2603 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2604 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2605 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2606 } //pC->xInp[zMI].hRxSio
2608 // Decode info
2609 for (z=DECODE1; z < DECODEN; z++)
2610 {
2611 zI = pP->inputsFromDecodes[z];
2612 zS = pP->streamsFromDecodes[z];
2613 (void)zS; // clear compiler warning in case not used with tracing disabled
2614 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2615 {
2616 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2618 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2619 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2620 {
2621 TRACE_TERSE1("return error errno 0x%x.", errno);
2622 return errno;
2623 }
2625 #if 1
2626 // (***) FL: revisit
2627 // write back Inp configuration
2628 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2629 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2630 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2631 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2632 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2633 // write back Dec configuration
2634 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2635 Cache_wait();
2636 #endif
2638 // FL: send info message to slave
2639 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2640 if (pAspMsg == NULL)
2641 {
2642 TRACE_TERSE0("MessageQ_alloc() failure.");
2643 SW_BREAKPOINT; // temporary
2644 return -1; // temporary
2645 }
2646 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2647 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
2648 pAspMsg->procId = hAspMsgMaster->masterProcId;
2649 pAspMsg->expectResp = TRUE;
2650 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2651 argIdx = 0; // set decIdx
2652 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2653 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2654 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2655 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
2656 if (status != MessageQ_S_SUCCESS)
2657 {
2658 SW_BREAKPOINT;
2659 }
2660 // wait for dec info complete message from slave -- temporary
2661 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2662 if (status != MessageQ_S_SUCCESS)
2663 {
2664 TRACE_TERSE0("MessageQ_get() failure.");
2665 SW_BREAKPOINT;
2666 return -1; // temporary
2667 }
2668 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2669 &n