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