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