2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamInpProc.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Diags.h>
43 #include <xdc/runtime/Error.h>
44 #include <xdc/runtime/Log.h>
45 #include <xdc/runtime/Memory.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/hal/Hwi.h>
49 #include <ti/sysbios/hal/Cache.h>
50 #include <ti/sysbios/knl/Clock.h>
51 #include <ti/sysbios/knl/Task.h>
52 #include <ti/ipc/Ipc.h>
53 #include <ti/ipc/MessageQ.h>
54 #include <ti/ipc/MultiProc.h>
56 #include <sio.h>
57 #include <pafsio_ialg.h>
59 #include "common.h"
60 #include "paf_heapMgr.h"
61 #include "aspMsg_common.h"
62 #include "aspMsg_master.h"
63 #include "aspDecOpCircBuf_master.h"
64 #include "audioStreamProc_common.h"
65 #include "audioStreamProc_master.h"
66 #include "audioStreamInpProc.h"
68 // FL: porting
69 #include "fwkSim.h"
70 //#include "fwkPort.h"
71 // FL: debug
72 #include "dbgCapAf.h"
75 // -----------------------------------------------------------------------------
76 // Debugging Trace Control, local to this file.
77 //
78 #include "logp.h"
80 #define TRACE_ARC(a)
82 // allows you to set a different trace module in pa.cfg
83 #define TR_MOD trace
85 // Allow a developer to selectively enable tracing.
86 #define CURRENT_TRACE_MASK 0x21
88 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
89 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
90 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
91 #define TRACE_MASK_DATA 0x08 // Show data
92 #define TRACE_MASK_TIME 0x10 // Timing related traces
93 #define TRACE_MASK_MSG 0x20 // Message related traces
95 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
96 #undef TRACE_TERSE0
97 #undef TRACE_TERSE1
98 #undef TRACE_TERSE2
99 #undef TRACE_TERSE3
100 #undef TRACE_TERSE4
101 #define TRACE_TERSE0(a)
102 #define TRACE_TERSE1(a,b)
103 #define TRACE_TERSE2(a,b,c)
104 #define TRACE_TERSE3(a,b,c,d)
105 #define TRACE_TERSE4(a,b,c,d,e)
106 #endif
108 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
109 #undef TRACE_GEN0
110 #undef TRACE_GEN1
111 #undef TRACE_GEN2
112 #undef TRACE_GEN3
113 #undef TRACE_GEN4
114 #define TRACE_GEN0(a)
115 #define TRACE_GEN1(a,b)
116 #define TRACE_GEN2(a,b,c)
117 #define TRACE_GEN3(a,b,c,d)
118 #define TRACE_GEN4(a,b,c,d,e)
119 #endif
121 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
122 // consolidate list of processing strings, indexed by PAF_SOURCE
123 static char *procName[] =
124 {
125 "", //PAF_SOURCE_UNKNOWN
126 "", //PAF_SOURCE_NONE
127 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
128 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
129 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
130 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
131 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
132 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
133 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
134 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
135 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
136 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
137 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
138 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
139 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
140 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
142 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
143 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
144 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
145 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
146 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
147 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
148 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
149 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
150 "AS%d: THD processing ...", //PAF_SOURCE_THD
151 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
152 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
153 };
155 #else
156 #undef TRACE_VERBOSE0
157 #undef TRACE_VERBOSE1
158 #undef TRACE_VERBOSE2
159 #undef TRACE_VERBOSE3
160 #undef TRACE_VERBOSE4
161 #define TRACE_VERBOSE0(a)
162 #define TRACE_VERBOSE1(a,b)
163 #define TRACE_VERBOSE2(a,b,c)
164 #define TRACE_VERBOSE3(a,b,c,d)
165 #define TRACE_VERBOSE4(a,b,c,d,e)
166 #endif
168 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
169 #define TRACE_DATA(a) LOG_printf a
170 #else
171 #define TRACE_DATA(a)
172 #endif
174 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
175 #define TRACE_TIME(a) LOG_printf a
176 #define TIME_MOD trace // this could be different
177 static Int dtime()
178 {
179 static Int old_time = 0;
180 Int time = TSK_time();
181 Int delta_time = time - old_time;
182 old_time = time;
183 return( delta_time);
184 }
186 static char *stateName[11] =
187 {
188 "INIT",
189 "INFO1",
190 "AGAIN",
191 "INFO2",
192 "CONT",
193 "TIME",
194 "DECODE",
195 "STREAM",
196 "ENCODE",
197 "FINAL",
198 "QUIT"
199 };
201 #else
202 #define TRACE_TIME(a)
203 #endif
205 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
206 #undef TRACE_MSG0
207 #undef TRACE_MSG1
208 #undef TRACE_MSG2
209 #undef TRACE_MSG3
210 #undef TRACE_MSG4
211 #define TRACE_MSG0(a)
212 #define TRACE_MSG1(a,b)
213 #define TRACE_MSG2(a,b,c)
214 #define TRACE_MSG3(a,b,c,d)
215 #define TRACE_MSG4(a,b,c,d,e)
216 #endif
219 // .............................................................................
221 #include <pafsio.h>
222 #include "paferr.h"
224 #include <acp_mds.h>
226 #include <pcm.h>
228 #include <pce.h>
230 #include <doberr.h>
232 #include <diberr.h>
234 #include <stdasp.h>
236 #include "as0.h"
237 #include "asperr.h"
239 #include "audioStreamProc_params.h"
240 #include "audioStreamProc_patchs.h"
241 #include "audioStreamProc_config.h"
242 #include "audioStreamInpProc.h"
244 //
245 // Audio Stream Definitions
246 //
248 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
249 #define MINFRAMELENGTH 24
250 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
253 //
254 // Decoder Definitions
255 //
256 //#define decLinkInit pQ->i_decLinkInit
258 //
259 // Audio Stream Processing Definitions
260 //
261 //#define aspLinkInit pQ->i_aspLinkInit
263 //
264 // Encoder Definitions
265 //
266 #define encLinkInit pQ->i_encLinkInit
268 //
269 // Input, Output Definitions
270 //
271 #define inpLinkInit pP->i_inpLinkInit
272 //#define outLinkInit pP->i_outLinkInit
274 /* ---------------------------------------------------------------- */
275 /* Parameter macro definitions end here. */
276 /* ---------------------------------------------------------------- */
278 //
279 // Standardized Definitions
280 //
282 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
283 //#define ENC_Handle PCE_Handle /* works for all: PCE */
285 #define __TASK_NAME__ "TaskAsip"
287 LINNO_DEFN(TaskAsip); /* Line number macros */
288 ERRNO_DEFN(TaskAsip); /* Error number macros */
290 // ASIT configuration
291 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
292 PAF_ASIT_Config gPAF_ASIT_config = {
293 NULL, // acp
294 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
295 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
296 };
298 // Global debug counters */
299 UInt32 gTaskAsipCnt=0; // debug
300 UInt32 gAsipInitCnt =0;
301 UInt32 gAsipInfo1Cnt =0;
302 UInt32 gAsipInfo2Cnt =0;
303 UInt32 gAsipDecodeCnt =0;
304 UInt32 gAsipFinalCnt =0;
305 UInt32 gAsipQuitCnt =0;
306 #include "dbgDib.h"
308 extern struct {
309 Int size;
310 IALG_Status *pStatus[512];
311 } IACP_STD_BETA_TABLE;
314 /*
315 * ======== taskAsipFxn ========
316 * Audio Stream Input Processing task function
317 */
318 Void taskAsipFxn(
319 // Int betaPrimeValue, // FL: revisit
320 const PAF_ASIT_Params *pP,
321 const PAF_ASIT_Patchs *pQ
322 )
323 {
324 PAF_ASIT_Config *pC; /* Local configuration pointer */
325 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
326 Int as; /* Audio Stream Number (1, 2, etc.) */
327 Int z; /* input/encode/stream/decode/output counter */
328 Int i; /* phase */
329 Int errno; /* error number */
330 Int zMD, zMI, zMS, zX;
331 Int loopCount = 0; // used to stop trace to see startup behavior.
332 UInt32 curTime;
333 Int size;
334 // Messaging
335 ASP_Msg *pAspMsg;
336 Int status;
338 Log_info0("Enter taskAsipFxn()");
340 #ifdef SIMULATE_SIO
341 /* Start simulation */
342 simStart();
343 #endif // SIMULATE_SIO
345 //
346 // Audio Framework Parameters & Patch (*pP, *pQ)
347 //
348 if (!pP)
349 {
350 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
351 LINNO_RPRT(TaskAsip, -1);
352 return;
353 }
355 if (!pQ)
356 {
357 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
358 LINNO_RPRT(TaskAsip, -1);
359 return;
360 }
362 //
363 // Audio Framework Configuration (*pC):
364 //
365 pC = &gPAF_ASIT_config;
366 pAstCfg = pC->pAstCfg;
368 /* Set Audio Stream Number (1, 2, etc.) */
369 as = gBetaPrimeValue + 1;
370 pAstCfg->as = as;
371 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
373 //
374 // Initialize message log trace and line number reporting
375 //
376 for (z=STREAM1; z < STREAMN; z++)
377 {
378 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
379 }
380 LINNO_RPRT(TaskAsip, -1);
382 //
383 // Determine decoder and stream indices associated with the master input
384 //
385 zMI = pP->zone.master;
386 pAstCfg->masterDec = zMI;
387 pAstCfg->masterStr = zMI;
388 for (zX = DECODE1; zX < DECODEN; zX++)
389 {
390 if (pP->inputsFromDecodes[zX] == zMI)
391 {
392 pAstCfg->masterDec = zX;
393 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
394 break;
395 }
396 }
397 zMD = pAstCfg->masterDec;
398 zMS = pAstCfg->masterStr;
400 // Initialize as per parametrized phases:
401 //
402 // In standard form these are:
403 // - Malloc: Memory Allocation
404 // - Config: Configuration Initialization
405 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
406 // - Common: Common Memory Initialization
407 // - AlgKey: Dec/Enc chain to Array Initialization
408 // - Device: I/O Device Initialization
409 // - DecOpCircBuf: Decoder Output Circular Buffer
410 // - Unused: (available)
411 //
412 LINNO_RPRT(TaskAsip, -2);
413 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
414 {
415 Int linno;
416 if (pP->fxns->initPhase[i])
417 {
418 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
419 {
420 LINNO_RPRT(TaskAsip, linno);
421 return;
422 }
423 }
424 else
425 {
426 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
427 }
428 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
429 LINNO_RPRT(TaskAsip, -i-3);
430 }
432 //
433 // End of Initialization -- display memory usage report.
434 //
435 if (pP->fxns->memStatusPrint)
436 {
437 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
438 }
440 // (***) FL: revisit
441 // write back AST shared configuration
442 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
443 // FL: no need to share this pointer, can be local
444 //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
445 Cache_wait();
447 // (***) FL: revisit
448 // write back Dec configuration
449 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
450 Cache_wait();
452 // (***) FL: revisit
453 // write back entire beta table
454 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
455 Cache_wait();
457 // FL: send start initialization message to slave
458 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
459 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
460 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
461 pAspMsg->procId = hAspMsgMaster->masterProcId;
462 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
463 pAspMsg->expectResp = TRUE;
464 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
465 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
466 if (status != MessageQ_S_SUCCESS)
467 {
468 SW_BREAKPOINT;
469 }
470 // wait for initialization complete message from slave
471 do {
472 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
473 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
474 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
475 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
476 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
477 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
478 {
479 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
480 SW_BREAKPOINT;
481 }
482 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
483 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
484 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
485 if (status != MessageQ_S_SUCCESS)
486 {
487 SW_BREAKPOINT;
488 }
490 // (***) FL: revisit
491 // invalidate Status structure addresses for Beta Units initialized on Slave
492 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
493 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
494 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
495 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
496 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
497 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
498 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
499 Cache_wait();
500 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
501 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
502 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
503 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
504 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
505 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
506 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
508 // (***) FL: revisit
509 // invalidate Status structures for Beta Units initialized on Slave
510 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
511 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
512 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
513 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
514 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
515 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
516 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
517 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
518 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
519 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
520 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
521 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
522 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
523 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
524 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
525 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
526 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
527 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
528 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
529 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
530 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
531 Cache_wait();
533 // (***) FL: revisit
534 // invalidate Dec configuration
535 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
536 Cache_wait();
538 //
539 // Main processing loop
540 //
541 for (z=STREAM1; z < STREAMN; z++)
542 {
543 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
544 }
546 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
548 errno = 0;
549 for (;;)
550 {
551 Int sourceSelect;
552 XDAS_Int8 sourceProgram;
554 loopCount++;
556 #if 0 // enable and tune to see startup behavior.
557 // this is an alternative to fixed/circular setting in pa.cfg.
558 // If you are searching for a memory allocation failure, disable on first round.
559 // All allocation has already happened.
560 // This is the outer loop. This loop count goes up when the stream resets.
561 // If the stream is running without problems, this does not increment.
562 // If the stream is repeatedly resetting, this loop count will go up rapidly.
563 if (loopCount > 10) // see traces for a few of the passes through the main loop.
564 {
565 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
566 LOG_disable(&TR_MOD); // stop tracing
567 }
568 #endif
570 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
571 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
573 // since not decoding indicate such
574 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
576 // any error forces idling of input
577 if (errno)
578 {
579 for (z=INPUT1; z < INPUTN; z++)
580 {
581 if (pAstCfg->xInp[z].hRxSio)
582 {
583 SIO_idle(pAstCfg->xInp[z].hRxSio);
584 }
585 }
587 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
588 ERRNO_RPRT(TaskAsip, errno);
589 }
591 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
592 // up to allow lower priority tasks to run. This may seem odd to be at the top
593 // of the state machine but provides for a cleaner flow even though the very
594 // first time we enter we do a sleep which is non-intuitive.
595 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
596 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
597 Task_sleep(1);
599 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
600 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
601 {
602 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
603 continue;
604 }
606 // if no master input selected then we don't know what may be at the input
607 // so set to unknown and skip any remaining processing
608 if (!pAstCfg->xInp[zMI].hRxSio)
609 {
610 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
611 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
612 continue;
613 }
615 // if here then we have a valid input so query its status
616 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
617 {
618 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
619 continue;
620 }
622 // If master decoder is not enabled, or the input is unlocked, then do nothing
623 if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
624 {
625 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
626 continue;
627 }
629 // If no source selected then do nothing
630 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
631 {
632 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
633 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
634 continue;
635 }
637 // If we want pass processing then proceed directly
638 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
639 {
640 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
641 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
642 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
643 if (pP->fxns->passProcessing)
644 {
645 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
646 }
647 else
648 {
649 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
650 errno = ASPERR_PASS;
651 }
652 TRACE_VERBOSE0("TaskAsip: continue");
653 continue;
654 }
656 // .....................................................................
657 // At this point we have an enabled input and want to decode something.
658 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
659 // when no decoder is selected there are no calls to IB
660 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
661 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pAstCfg->xDec[zMD].decodeStatus.sourceSelect, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
662 {
663 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
664 continue;
665 }
667 // query for input type
668 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
669 {
670 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
671 errno = ASPERR_AUTO_PROGRAM;
672 continue;
673 }
674 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
676 // if input is unclassifiable then do nothing
677 if (sourceProgram == PAF_SOURCE_UNKNOWN)
678 {
679 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
680 continue;
681 }
683 // now that we have some input classification, and possibly an outstanding
684 // input frame, we determine whether or not to call decodeProcessing and with
685 // what decAlg.
686 sourceSelect = PAF_SOURCE_NONE;
687 switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect)
688 {
689 // If autodetecting, decoding everything, and input is something
690 // (i.e. bitstream or PCM) then decode.
691 case PAF_SOURCE_AUTO:
692 if (sourceProgram >= PAF_SOURCE_PCM)
693 {
694 sourceSelect = sourceProgram;
695 }
696 break;
698 // If autodetecting, decoding only PCM, and input is PCM then decode.
699 case PAF_SOURCE_PCMAUTO:
700 if (sourceProgram == PAF_SOURCE_PCM)
701 {
702 sourceSelect = sourceProgram;
703 }
704 break;
706 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
707 case PAF_SOURCE_BITSTREAM:
708 if (sourceProgram >= PAF_SOURCE_AC3)
709 {
710 sourceSelect = sourceProgram;
711 }
712 break;
714 // If autodetecting, decoding only DTS, and input is DTS then decode.
715 case PAF_SOURCE_DTSALL:
716 switch (sourceProgram)
717 {
718 case PAF_SOURCE_DTS11:
719 case PAF_SOURCE_DTS12:
720 case PAF_SOURCE_DTS13:
721 case PAF_SOURCE_DTS14:
722 case PAF_SOURCE_DTS16:
723 case PAF_SOURCE_DTSHD:
724 sourceSelect = sourceProgram;
725 break;
726 }
727 break;
729 // All others, e.g., force modes, fall through to here.
730 // If user made specific selection then program must match select.
731 // (NB: this compare relies on ordering of PAF_SOURCE)
732 default:
733 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
734 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
735 {
736 if (sourceProgram != sourceSelect)
737 {
738 sourceSelect = PAF_SOURCE_NONE;
739 }
740 }
741 break;
742 }
744 // if we didn't find any matches then skip
745 if (sourceSelect == PAF_SOURCE_NONE)
746 {
747 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
748 continue;
749 }
751 // FL: debug, reset IB capture buffer
752 //capIbReset();
753 //Log_info0("capIbReset()");
755 // FL: send source select message to slave
756 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
757 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
758 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
759 pAspMsg->procId = hAspMsgMaster->masterProcId;
760 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
761 pAspMsg->expectResp = TRUE;
762 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
763 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
764 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
765 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
766 if (status != MessageQ_S_SUCCESS)
767 {
768 SW_BREAKPOINT;
769 }
770 // wait for source select complete message from slave
771 //do {
772 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
773 //} while (status != MessageQ_S_SUCCESS);
774 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
775 if (status != MessageQ_S_SUCCESS)
776 {
777 TRACE_TERSE0("MessageQ_get() failure.");
778 SW_BREAKPOINT; // temporary
779 }
780 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
781 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
782 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
783 {
784 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
785 SW_BREAKPOINT;
786 }
787 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
788 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
789 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
790 if (status != MessageQ_S_SUCCESS)
791 {
792 SW_BREAKPOINT;
793 }
795 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
796 // iff we are in this top level state machine and specifically not in decodeProcessing
797 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
799 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
801 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
802 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
803 if (errno)
804 {
805 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
806 }
807 else
808 {
809 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
810 }
812 // FL: send dec exit message to slave
813 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
814 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
815 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
816 pAspMsg->procId = hAspMsgMaster->masterProcId;
817 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
818 pAspMsg->expectResp = TRUE;
819 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
820 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
821 if (status != MessageQ_S_SUCCESS)
822 {
823 SW_BREAKPOINT;
824 }
825 // wait for dec exit complete message from slave
826 //do {
827 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
828 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
829 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
830 if (status != MessageQ_S_SUCCESS)
831 {
832 TRACE_TERSE0("MessageQ_get() failure.");
833 SW_BREAKPOINT; // temporary
834 }
835 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
836 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
837 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
838 {
839 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
840 SW_BREAKPOINT;
841 }
842 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
843 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
844 // free the message
845 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
846 if (status != MessageQ_S_SUCCESS)
847 {
848 SW_BREAKPOINT;
849 }
850 } // End of main processing loop for (;;)
852 Log_info0("Exit taskAsipFxn()");
853 }
855 // -----------------------------------------------------------------------------
856 // ASIT Initialization Function - Memory Allocation
857 //
858 // Name: PAF_ASIT_initPhaseMalloc
859 // Purpose: Audio Stream Input Task Function for initialization of data pointers
860 // by allocation of memory.
861 // From: audioStream1Task or equivalent
862 // Uses: See code.
863 // States: x
864 // Return: 0 on success.
865 // Source code line number on MEM_calloc failure.
866 // Trace: Message Log "trace" in Debug Project Configuration reports:
867 // * State information as per parent.
868 // * Memory allocation errors.
869 //
870 Int
871 PAF_ASIT_initPhaseMalloc(
872 const PAF_ASIT_Params *pP,
873 const PAF_ASIT_Patchs *pQ,
874 PAF_ASIT_Config *pC
875 )
876 {
877 PAF_AST_Config *pAstCfg;
878 Int as; /* Audio Stream Number (1, 2, etc.) */
879 Int zMS;
880 Error_Block eb;
882 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
883 as = pAstCfg->as;
884 zMS = pAstCfg->masterStr;
886 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
888 // Initialize error block
889 Error_init(&eb);
891 /* Input memory */
892 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
893 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
894 {
895 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
896 SW_BREAKPOINT;
897 return __LINE__;
898 }
899 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
900 INPUTN * sizeof (*pAstCfg->xInp),
901 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
903 /* Decode memory */
904 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
905 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
906 {
907 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
908 SW_BREAKPOINT;
909 return __LINE__;
910 }
911 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
912 DECODEN * sizeof (*pAstCfg->xDec),
913 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
915 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
916 return 0;
917 } //PAF_ASIT_initPhaseMalloc
919 // -----------------------------------------------------------------------------
920 // ASIT Initialization Function - Memory Initialization from Configuration
921 //
922 // Name: PAF_ASIT_initPhaseConfig
923 // Purpose: Audio Stream Task Function for initialization of data values
924 // from parameters.
925 // From: audioStream1Task or equivalent
926 // Uses: See code.
927 // States: x
928 // Return: 0 on success.
929 // Other as per initFrame0 and initFrame1.
930 // Trace: Message Log "trace" in Debug Project Configuration reports:
931 // * State information as per parent.
932 //
933 Int
934 PAF_ASIT_initPhaseConfig(
935 const PAF_ASIT_Params *pP,
936 const PAF_ASIT_Patchs *pQ,
937 PAF_ASIT_Config *pC
938 )
939 {
940 PAF_AST_Config *pAstCfg;
941 Int as; /* Audio Stream Number (1, 2, etc.) */
942 Int z; /* input/encode/stream/decode/output counter */
943 Int zMS;
945 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
946 as = pAstCfg->as;
947 zMS = pAstCfg->masterStr;
949 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
951 //
952 // Unspecified elements have been initialized to zero during alloc
953 //
955 for (z=INPUT1; z < INPUTN; z++)
956 {
957 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
958 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
959 }
961 for (z=DECODE1; z < DECODEN; z++)
962 {
963 Int zI = pP->inputsFromDecodes[z];
964 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
965 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
966 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
967 }
969 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
970 return 0;
971 } //PAF_ASIT_initPhaseConfig
973 // -----------------------------------------------------------------------------
974 // ASIT Initialization Function - ACP Algorithm Instantiation
975 //
976 // Name: PAF_ASIT_initPhaseAcpAlg
977 // Purpose: Audio Stream Input Task Function for initialization of ACP by
978 // instantiation of the algorithm.
979 // From: audioStream1Task or equivalent
980 // Uses: See code.
981 // States: x
982 // Return: 0 on success.
983 // Source code line number on ACP Algorithm creation failure.
984 // Trace: Message Log "trace" in Debug Project Configuration reports:
985 // * State information as per parent.
986 // * Memory allocation errors.
987 //
988 Int
989 PAF_ASIT_initPhaseAcpAlg(
990 const PAF_ASIT_Params *pP,
991 const PAF_ASIT_Patchs *pQ,
992 PAF_ASIT_Config *pC
993 )
994 {
995 PAF_AST_Config *pAstCfg;
996 Int as; /* Audio Stream Number (1, 2, etc.) */
997 Int z; /* input/encode/stream/decode/output counter */
998 Int betaPrimeOffset;
999 ACP_Handle acp;
1000 Int zMS;
1001 Int zS, zX;
1003 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1004 as = pAstCfg->as;
1005 zMS = pAstCfg->masterStr;
1007 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1009 ACP_MDS_init();
1011 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1012 {
1013 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1014 return __LINE__;
1015 }
1016 pC->acp = acp;
1018 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1019 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1021 for (z=INPUT1; z < INPUTN; z++)
1022 {
1023 zS = z;
1024 for (zX = DECODE1; zX < DECODEN; zX++)
1025 {
1026 if (pP->inputsFromDecodes[zX] == z)
1027 {
1028 zS = pP->streamsFromDecodes[zX];
1029 break;
1030 }
1031 }
1032 acp->fxns->attach(acp, ACP_SERIES_STD,
1033 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1034 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1035 /* Ignore errors, not reported. */
1036 }
1038 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1040 return 0;
1041 } //PAF_ASIT_initPhaseAcpAlg
1043 // -----------------------------------------------------------------------------
1044 // ASIT Initialization Function - Common Memory
1045 //
1046 // Name: PAF_ASIT_initPhaseCommon
1047 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1048 // From: audioStream1Task or equivalent
1049 // Uses: See code.
1050 // States: x
1051 // Return: 0 on success.
1052 // Source code line number on PAF_ALG_alloc failure.
1053 // Source code line number on PAF_ALG_mallocMemory failure.
1054 // Source code line number on Decode Chain initialization failure.
1055 // Source code line number on ASP Chain initialization failure.
1056 // Source code line number on Encode Chain initialization failure.
1057 // Trace: Message Log "trace" in Debug Project Configuration reports:
1058 // * State information as per parent.
1059 // * Memory allocation errors.
1060 //
1061 Int
1062 PAF_ASIT_initPhaseCommon(
1063 const PAF_ASIT_Params *pP,
1064 const PAF_ASIT_Patchs *pQ,
1065 PAF_ASIT_Config *pC
1066 )
1067 {
1068 PAF_AST_Config *pAstCfg;
1069 Int as; /* Audio Stream Number (1, 2, etc.) */
1070 Int z; /* stream counter */
1071 ACP_Handle acp;
1072 PAF_IALG_Config pafAlgConfig;
1073 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1075 acp = pC->acp;
1076 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1077 as = pAstCfg->as;
1079 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1081 //
1082 // Determine memory needs and instantiate algorithms across audio streams
1083 //
1084 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1085 PAF_ALG_setup(&pafAlgConfig,
1086 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1087 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1088 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1089 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1090 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1091 HEAP_CLEAR);
1093 if (pP->fxns->headerPrint)
1094 {
1095 pP->fxns->headerPrint();
1096 }
1098 for (z = STREAM1; z < STREAMN; z++)
1099 {
1100 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1102 //
1103 // Determine common memory for:
1104 // (1) Logical Input drivers
1105 //
1106 // Decode Algorithms common memory determined in ASP Slave.
1107 //
1108 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1110 //
1111 // Determine common memory needs of Logical Input driver
1112 //
1114 // really need to loop over all inputs for this stream using the tables
1115 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1116 // patch, and not needed for FS11, since there is only one input.
1117 if (INPUT1 <= z && z < INPUTN)
1118 {
1119 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1120 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1121 {
1122 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1123 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1124 SW_BREAKPOINT;
1125 return __LINE__;
1126 }
1127 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1128 if (pP->fxns->allocPrint)
1129 {
1130 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1131 }
1132 }
1133 }
1134 {
1135 // Changes made to share scratch between zones
1136 // Assume maximum 3 zones and scratch common memory is at offset 0;
1137 int max=0;
1138 for (z=STREAM1; z<STREAMN; z++)
1139 {
1140 if (max < common[z][0].size)
1141 {
1142 max = common[z][0].size;
1143 }
1144 }
1145 common[STREAM1][0].size=max;
1146 for (z=STREAM1+1; z<STREAMN; z++)
1147 {
1148 common[z][0].size = 0;
1149 }
1150 }
1152 //
1153 // Allocate common memory for:
1154 // (1) Logical Input drivers
1155 //
1156 for (z = STREAM1; z < STREAMN; z++)
1157 {
1158 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1159 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1160 {
1161 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1162 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1163 SW_BREAKPOINT;
1164 return __LINE__;
1165 }
1166 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1167 // share zone0 scratch with all zones
1168 common[z][0].base = common[0][0].base;
1169 if (pP->fxns->commonPrint)
1170 {
1171 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1172 }
1174 //
1175 // Allocate non-common memories for Logical IO drivers
1176 // Since these structures are used at run-time we allocate from external memory
1177 if (INPUT1 <= z && z < INPUTN)
1178 {
1179 PAF_ASP_Chain *chain;
1180 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1181 as+z, z);
1182 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1183 HEAP_EXTERNAL, as+z, acp, &trace,
1184 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1185 if (!chain)
1186 {
1187 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1188 return __LINE__;
1189 }
1190 }
1191 }
1192 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1194 return 0;
1195 } //PAF_ASIT_initPhaseCommon
1197 // (***) FL: candidate for removal
1198 // -----------------------------------------------------------------------------
1199 // ASIT Initialization Function - Algorithm Keys
1200 //
1201 // Name: PAF_ASIT_initPhaseAlgKey
1202 // Purpose: Audio Stream Input Task Function for initialization of data values
1203 // from parameters for Algorithm Keys.
1204 // From: audioStream1Task or equivalent
1205 // Uses: See code.
1206 // States: x
1207 // Return: 0.
1208 // Trace: Message Log "trace" in Debug Project Configuration reports:
1209 // * State information as per parent.
1210 //
1211 // .............................................................................
1212 Int
1213 PAF_ASIT_initPhaseAlgKey(
1214 const PAF_ASIT_Params *pP,
1215 const PAF_ASIT_Patchs *pQ,
1216 PAF_ASIT_Config *pC
1217 )
1218 {
1219 PAF_AST_Config *pAstCfg;
1220 Int as; /* Audio Stream Number (1, 2, etc.) */
1223 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1224 as = pAstCfg->as;
1225 (void)as; // clear compiler warning in case not used with tracing disabled
1227 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1229 #if 0 // FL: slave
1230 for (z=DECODE1; z < DECODEN; z++)
1231 {
1232 for (s=0; s < pP->pDecAlgKey->length; s++)
1233 {
1234 if ((pP->pDecAlgKey->code[s].full != 0) &&
1235 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1236 {
1237 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1238 /* Cast in interface, for now --Kurt */
1239 }
1240 else
1241 {
1242 pC->xDec[z].decAlg[s] = NULL;
1243 }
1244 }
1245 }
1246 #endif
1248 return 0;
1249 } //PAF_ASIT_initPhaseAlgKey
1251 // -----------------------------------------------------------------------------
1252 // ASIT Initialization Function - I/O Devices
1253 //
1254 // Name: PAF_ASIT_initPhaseDevice
1255 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1256 // From: audioStream1Task or equivalent
1257 // Uses: See code.
1258 // States: x
1259 // Return: 0 on success.
1260 // Source code line number on device allocation failure.
1261 // Trace: Message Log "trace" in Debug Project Configuration reports:
1262 // * State information as per parent.
1263 // * Memory allocation errors.
1264 //
1265 Int
1266 PAF_ASIT_initPhaseDevice(
1267 const PAF_ASIT_Params *pP,
1268 const PAF_ASIT_Patchs *pQ,
1269 PAF_ASIT_Config *pC
1270 )
1271 {
1272 PAF_AST_Config *pAstCfg;
1273 Int as; /* Audio Stream Number (1, 2, etc.) */
1274 Int z; /* input/output counter */
1275 PAF_SIO_IALG_Obj *pObj;
1276 PAF_SIO_IALG_Config *pAlgConfig;
1277 PAF_IALG_Config pafAlgConfig;
1280 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1281 as = pAstCfg->as;
1282 (void)as; // clear compiler warning in case not used with tracing disabled
1284 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1286 if (pP->fxns->bufMemPrint)
1287 {
1288 PAF_ALG_setup (&pafAlgConfig,
1289 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1290 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1291 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1292 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1293 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1294 HEAP_CLEAR);
1295 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1296 }
1298 for (z=INPUT1; z < INPUTN; z++)
1299 {
1300 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1302 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1303 pAlgConfig = &pObj->config;
1305 pAstCfg->xInp[z].hRxSio = NULL;
1307 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1308 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1309 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1310 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1311 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1312 pConfig->sizeofElement = 2;
1313 pConfig->precision = 16;
1315 if (pP->fxns->bufMemPrint)
1316 {
1317 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1318 }
1319 }
1321 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1323 return 0;
1324 } //PAF_ASIT_initPhaseDevice
1326 // -----------------------------------------------------------------------------
1327 // ASIT Initialization Function - Decoder Output Circular Buffer
1328 //
1329 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1330 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1331 // From: audioStream1Task or equivalent
1332 // Uses: See code.
1333 // States: x
1334 // Return: 0 on success.
1335 // Source code line number on device allocation failure.
1336 // Trace: Message Log "trace" in Debug Project Configuration reports:
1337 // * State information as per parent.
1338 // * Memory allocation errors.
1339 //
1340 Int
1341 PAF_ASIT_initPhaseDecOpCircBuf(
1342 const PAF_ASIT_Params *pP,
1343 const PAF_ASIT_Patchs *pQ,
1344 PAF_ASIT_Config *pC
1345 )
1346 {
1347 PAF_AST_Config *pAstCfg;
1348 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1349 Int as; /* Audio Stream Number (1, 2, etc.) */
1350 Int zMS;
1351 Int z; /* decode counter */
1352 Int errno; /* error number */
1353 Error_Block eb;
1354 Int i;
1356 // FL: (***)revisit
1357 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1358 as = pAstCfg->as;
1359 zMS = pAstCfg->masterStr;
1361 /* Decode output circular buffer memory */
1362 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1363 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1364 {
1365 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1366 SW_BREAKPOINT;
1367 return __LINE__;
1368 }
1369 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1370 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1371 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1373 for (z=DECODE1; z < DECODEN; z++)
1374 {
1375 pCb = &pAstCfg->xDecOpCb[z];
1377 // allocate audio frame circular buffer
1378 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1379 {
1380 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1381 SW_BREAKPOINT;
1382 }
1383 // allocate audio frame PCM sample pointer array
1384 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1385 {
1386 if (!(pCb->afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioData *), 4, &eb)))
1387 {
1388 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1389 SW_BREAKPOINT;
1390 }
1391 if (!(pCb->afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioSize), 4, &eb)))
1392 {
1393 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1394 SW_BREAKPOINT;
1395 }
1396 }
1397 // allocate PCM sample buffer
1398 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1399 {
1400 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1401 SW_BREAKPOINT;
1402 }
1403 pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1404 // allocate Metadata buffers //QIN
1405 if (!(pCb->metaBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
1406 {
1407 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1408 SW_BREAKPOINT;
1409 }
1410 pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1411 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1412 // Initialize decoder output circular buffer for PCM
1413 errno = cbInit(pCb);
1414 if (errno)
1415 {
1416 SW_BREAKPOINT; // FL: debug
1417 return errno;
1418 }
1419 }
1421 return 0;
1422 } //PAF_ASIT_initPhaseDecOpCircBuf
1425 #if 0
1426 // -----------------------------------------------------------------------------
1427 // AST Processing Function - Pass-Through Processing
1428 //
1429 // Name: PAF_AST_passProcessing
1430 // Purpose: Audio Stream Task Function for processing audio data as a
1431 // pass-through from the input driver to the output driver
1432 // for development and testing.
1433 // From: audioStream1Task or equivalent
1434 // Uses: See code.
1435 // States: x
1436 // Return: Error number in standard form (0 on success).
1437 // Trace: Message Log "trace" in Debug Project Configuration reports:
1438 // * State information on initialization.
1439 // * State information on processing.
1440 //
1442 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1443 /* Pass Processing is often omitted from builds to save memory, */
1444 /* and CODE_SECTION/clink constructs facilitate this omission. */
1446 Int
1447 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1448 {
1449 Int z; /* input/output counter */
1450 Int errno = 0; /* error number */
1451 Int getVal;
1452 Int rxNumChan, txNumChan;
1453 Int first;
1454 Int zMD = pC->masterDec;
1455 Int zMI = pP->zone.master;
1458 #ifndef __TI_EABI__
1459 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1460 #endif
1462 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1464 //
1465 // Determine that receive/transmit channels are compatible
1466 //
1468 // Can handle handle only master input
1469 for (z=INPUT1; z < INPUTN; z++) {
1470 if (z != zMI && pC->xInp[z].hRxSio)
1471 return (ASPERR_PASS + 0x01);
1472 }
1474 /* Number of receive/transmit channels */
1476 if (! pC->xInp[zMI].hRxSio)
1477 return (ASPERR_PASS + 0x11);
1478 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1479 return (ASPERR_PASS + 0x12);
1480 if (rxNumChan > NUM_TX_CHAN(zMI))
1481 return (ASPERR_PASS + 0x13);
1483 for (z=OUTPUT1; z < OUTPUTN; z++) {
1484 if (! pC->xOut[zMI].hTxSio)
1485 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1486 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1487 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1488 if (txNumChan > NUM_TX_CHAN(zMI))
1489 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1490 }
1492 //
1493 // Set up receive/transmit
1494 //
1496 SIO_idle (pC->xInp[zMI].hRxSio);
1497 for (z=OUTPUT1; z < OUTPUTN; z++) {
1498 if(SIO_idle (pC->xOut[z].hTxSio))
1499 return ASPERR_IDLE;
1500 }
1502 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1503 return (ASPERR_PASS + 0x14);
1505 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1506 return (ASPERR_PASS + 0x15);
1508 for (z=OUTPUT1; z < OUTPUTN; z++)
1509 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1511 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1512 return ASPERR_PASS + 0x16;
1514 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1515 return ASPERR_PASS + 0x17;
1517 //
1518 // Receive and transmit the data in single-frame buffers
1519 //
1521 first = 1;
1522 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1523 PAF_OutBufConfig *pOutBuf;
1524 PAF_InpBufConfig *pInpBuf;
1526 if (first) {
1527 first = 0;
1529 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1531 for (z=OUTPUT1; z < OUTPUTN; z++) {
1532 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1533 if (getVal > 0) {
1534 errno = ASPERR_ISSUE;
1535 break;
1536 }
1537 else if (getVal < 0) {
1538 errno = -getVal;
1539 break;
1540 }
1542 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1543 return (getVal & 0xff) | ASPERR_MUTE;
1544 }
1545 if (errno)
1546 break;
1548 }
1550 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1551 if (getVal > 0) {
1552 errno = ASPERR_ISSUE;
1553 break;
1554 }
1556 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1558 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1559 if (getVal < 0) {
1560 errno = -getVal;
1561 break;
1562 }
1564 for (z=OUTPUT1; z < OUTPUTN; z++) {
1565 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1566 if (getVal < 0) {
1567 errno = -getVal;
1568 break;
1569 }
1570 }
1571 if( errno )
1572 break;
1574 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1576 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1577 break;
1579 for (z=OUTPUT1; z < OUTPUTN; z++) {
1580 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1581 if (getVal > 0) {
1582 errno = ASPERR_ISSUE;
1583 break;
1584 }
1585 else if (getVal < 0) {
1586 errno = -getVal;
1587 break;
1588 }
1589 }
1590 if( errno )
1591 break;
1592 }
1594 //
1595 // Close down receive/transmit
1596 //
1598 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1600 for (z=OUTPUT1; z < OUTPUTN; z++) {
1601 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1602 if (! errno)
1603 errno = (getVal & 0xff) | ASPERR_MUTE;
1604 /* convert to sensical errno */
1605 }
1606 }
1608 SIO_idle (pC->xInp[zMI].hRxSio);
1609 for (z=OUTPUT1; z < OUTPUTN; z++)
1610 SIO_idle (pC->xOut[z].hTxSio);
1612 return errno;
1614 } //PAF_AST_passProcessing
1615 #endif // #if 0
1617 #if 0
1618 // -----------------------------------------------------------------------------
1619 // AST Processing Function Helper - Pass-Through Processing Patch Point
1620 //
1621 // Name: PAF_AST_passProcessingCopy
1622 // Purpose: Pass-Through Processing Function for copying audio data
1623 // from the input buffer to the output buffer.
1624 // From: AST Parameter Function -> passProcessing
1625 // Uses: See code.
1626 // States: x
1627 // Return: Error number in standard form (0 on success).
1628 // Trace: Message Log "trace" in Debug Project Configuration reports:
1629 // x
1630 //
1632 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1633 /* Pass Processing is often omitted from builds to save memory, */
1634 /* and CODE_SECTION/clink constructs facilitate this omission. */
1636 Int
1637 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1638 {
1639 Int z; /* output counter */
1640 Int errno; /* error number */
1641 Int i;
1642 Int rxNumChan, txNumChan;
1643 Int zMI = pP->zone.master;
1646 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1648 // Copy data from input channels to output channels one of two ways:
1650 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1651 return (ASPERR_PASS + 0x12);
1653 for (z=OUTPUT1; z < OUTPUTN; z++) {
1654 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1655 return (ASPERR_PASS + 0x22);
1657 if( txNumChan <= rxNumChan ) {
1659 // Copy one to one, ignoring later rx channels as needed.
1661 for( i=0; i < txNumChan; i++ ) {
1662 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1663 if( errno )
1664 return errno;
1665 }
1666 }
1667 else {
1669 // Copy one to many, repeating earlier rx channels as needed.
1671 Int from, to;
1673 from = 0;
1674 to = 0;
1675 while( to < txNumChan ) {
1676 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1677 if( errno )
1678 return errno;
1680 from++;
1681 to++;
1682 if( from == rxNumChan )
1683 from = 0;
1684 }
1685 }
1686 }
1688 return 0;
1689 } //PAF_AST_passProcessingCopy
1690 #endif // #if 0
1692 // -----------------------------------------------------------------------------
1693 // ASIT Processing Function - Auto Processing
1694 //
1695 // Name: PAF_ASIT_autoProcessing
1696 // Purpose: Audio Stream Input Task Function for processing audio data to
1697 // determine the input type without output.
1698 // From: audioStream1Task or equivalent
1699 // Uses: See code.
1700 // States: x
1701 // Return: Error number in standard or SIO form (0 on success).
1702 // Trace: Message Log "trace" in Debug Project Configuration reports:
1703 // * State information on initialization.
1704 //
1706 #define DECSIOMAP(X) \
1707 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1709 Int
1710 PAF_ASIT_autoProcessing(
1711 const PAF_ASIT_Params *pP,
1712 const PAF_ASIT_Patchs *pQ,
1713 PAF_ASIT_Config *pC,
1714 Int inputTypeSelect,
1715 ALG_Handle pcmAlgMaster
1716 )
1717 {
1718 PAF_AST_Config *pAstCfg;
1719 Int as; /* Audio Stream Number (1, 2, etc.) */
1720 Int errno = 0; /* error number */
1721 Int nbytes;
1722 Int frameLength;
1723 Int zMD;
1724 Int zMI;
1725 Int zMS;
1727 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1728 as = pAstCfg->as;
1729 zMD = pAstCfg->masterDec;
1730 zMS = pAstCfg->masterStr;
1731 zMI = pP->zone.master;
1733 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1735 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1736 PAF_SIO_CONTROL_SET_SOURCESELECT,
1737 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1738 {
1739 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1740 return errno;
1741 }
1742 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1743 // pC->xDec[zMD].decodeStatus.bufferRatio);
1744 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1746 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1747 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1748 {
1749 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1750 errno, ASPERR_AUTO_LENGTH);
1751 return ASPERR_AUTO_LENGTH;
1752 }
1754 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1755 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1756 PAF_SIO_REQUEST_SYNC))
1757 {
1758 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1759 errno, ASPERR_ISSUE);
1760 return ASPERR_ISSUE;
1761 }
1763 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1765 // all of the sync scan work is done in this call. If the error returned
1766 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1767 // error so we mask it off.
1768 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1769 if (nbytes == -DIBERR_SYNC)
1770 {
1771 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1772 return 0;
1773 }
1774 if (nbytes != sizeof(PAF_InpBufConfig))
1775 {
1776 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1777 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1778 return ASPERR_RECLAIM;
1779 }
1780 if (errno)
1781 {
1782 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1783 }
1784 return errno;
1785 } //PAF_ASIT_autoProcessing
1787 // -----------------------------------------------------------------------------
1788 // ASIT Processing Function - Decode Processing
1789 //
1790 // Name: PAF_ASIT_decodeProcessing
1791 // Purpose: Audio Stream Input Task Function for processing audio data.
1792 // From: audioStream1Task or equivalent
1793 // Uses: See code.
1794 // States: x
1795 // Return: Error number in standard form (0 on success).
1796 // Trace: Message Log "trace" in Debug Project Configuration reports:
1797 // * State information on initialization (via children).
1798 // * State information on processing (via children).
1799 // * Decode warnings.
1800 //
1801 // When "writeDECModeContinuous" is used for zMI input/decode:
1802 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1803 // (a) if "writeDECCommandRestart" is used
1804 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1805 // (b) if "writeDECSourceSelectNone" is used
1806 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1807 // (c) if an error occurs in
1808 // INIT
1809 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1810 // -> PAF_AST_decodeCont(): "Await slave inputs"
1811 // STREAM (errno |= PAF_COMPONENT_ASP)
1812 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1813 // [ the latter errors lead to "switch_break:"
1814 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1815 //
1816 // [ Notably, in FINAL ("frame-finalization state")
1817 // -> PAF_AST_decodeFinalTest() is *not* called,
1818 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1819 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1820 //
1821 // States in which error can't occur:
1822 // AGAIN ("subsequent initial state")
1823 //
1824 // States in which (some) errors must be handled:
1825 // INFO1 ("first frame state")
1826 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1827 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1828 // ?*? but what about ASPERR_RESYNC from same call ?*?
1829 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1830 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1831 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1832 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1833 // - enc->fxns->info()
1834 // - pP->fxns->setCheckRateX()
1835 // - pP->fxns->startOutput()
1836 // - "Start slave inputs if necessary"
1837 // INFO2 ("subsequent frame state")
1838 // -> PAF_AST_decodeInfo(): (see above)
1839 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1840 // - pP->fxns->setCheckRateX()
1841 // TIME ("timing state")
1842 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1843 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1844 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1845 // (*OK* don't try to recover from this*)
1846 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1847 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1848 // possibly in PAF_AST_decodeProcessing() itself **
1849 // DECODE ("decode state")
1850 // -> PAF_AST_decodeDecode(): pass on error from
1851 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1852 // - dec->fxns->reset()
1853 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1854 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
1855 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1856 Int
1857 PAF_ASIT_decodeProcessing(
1858 const PAF_ASIT_Params *pP,
1859 const PAF_ASIT_Patchs *pQ,
1860 PAF_ASIT_Config *pC,
1861 Int sourceSelect
1862 )
1863 {
1864 PAF_AST_Config *pAstCfg;
1865 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1866 Int z; /* decode counter */
1867 Int errno; /* error number */
1868 Int getVal;
1869 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1870 ALG_Handle alg[DECODEN_MAX];
1871 Int zMD;
1872 Int zMS;
1873 Int size;
1874 //PAF_InpBufConfig *pIpBufConfig;
1875 Int frame; // decoder input frame count
1876 Int block; // (***) FL: formerly -- decoder output block count / input frame
1879 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1880 zMD = pAstCfg->masterDec;
1881 zMS = pAstCfg->masterStr;
1883 for (z=DECODE1; z < DECODEN; z++)
1884 {
1885 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
1886 }
1887 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1889 //
1890 // Receive and process the data in single-frame buffers
1891 //
1893 state = INIT;
1894 errno = 0; /* error number */
1896 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
1898 for (;;)
1899 {
1900 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
1901 {
1902 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1903 state = QUIT;
1904 }
1906 // Process commands (decode)
1907 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
1908 {
1909 if (state != INIT) // no need to restart/abort if not yet started
1910 {
1911 if (getVal == ASPERR_QUIT)
1912 {
1913 state = QUIT;
1914 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1915 }
1916 else if (getVal == ASPERR_ABORT)
1917 {
1918 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1919 return getVal;
1920 }
1921 else
1922 {
1923 /* ignore */;
1924 }
1925 }
1926 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
1927 }
1929 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
1930 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
1932 // Process state (decode)
1933 switch (state)
1934 {
1935 case INIT: // initial state
1936 gAsipInitCnt++;
1937 Log_info0("TaskAsip: state=INIT");
1939 // (***) FL: revisit
1940 #if 1 // status for shared beta units can change (e.g. at-boot or alpha)
1941 // write back Status structures for shared Beta Units
1942 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1943 //Cache_wb((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_wb((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_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1948 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
1949 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
1950 Cache_wait();
1951 #endif
1952 #if 0
1953 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1954 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1955 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1956 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1957 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1958 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1959 //Cache_wait();
1960 #endif
1962 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1963 {
1964 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1965 break;
1966 }
1968 #if 1
1969 // (***) FL: revisit
1970 // invalidate Status structures for shared Beta Units
1971 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1972 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1973 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1974 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1975 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1976 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1977 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
1978 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
1979 Cache_wait();
1980 #endif
1982 frame = 0;
1983 block = 0;
1985 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
1986 state = INFO1;
1987 continue;
1989 case INFO1: // first frame state
1990 gAsipInfo1Cnt++;
1991 Log_info0("TaskAsip: state=INFO1");
1993 #if 0
1994 //// (***) FL: revisit
1995 //// write back Inp configuration
1996 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
1997 //// write back input data
1998 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
1999 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2000 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2001 //// write back Dec configuration
2002 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2003 //Cache_wait();
2004 #endif
2006 // Establish primary timing
2007 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2008 {
2009 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2010 break;
2011 }
2013 #if 0
2014 //// (***) FL: revisit
2015 //// invalidate Dec configuration
2016 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2017 //Cache_wait();
2018 #endif
2020 // Don't start decode until major access unit is found.
2021 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
2022 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
2023 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2024 (pAstCfg->xStr[zMS].pAudioFrame->sampleRate == PAF_SAMPLERATE_UNKNOWN))
2025 {
2026 Int z;
2027 for (z=DECODE1; z < DECODEN; z++)
2028 {
2029 Int zI = pP->inputsFromDecodes[z];
2030 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2031 {
2032 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2033 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2034 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2035 {
2036 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2037 return (ASPERR_ISSUE);
2038 }
2039 }
2040 }
2041 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2042 frame++;
2043 state = INFO1;
2044 continue;
2045 }
2046 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2048 // Establish secondary timing
2049 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2050 {
2051 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2052 break;
2053 }
2055 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2056 state = DECODE;
2057 continue;
2059 case INFO2: // subsequent frame state
2060 gAsipInfo2Cnt++;
2061 Log_info0("TaskAsip: state=INFO2");
2063 #if 0
2064 //// (***) FL: revisit
2065 //// write back Inp configuration
2066 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2067 //// write back input data
2068 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2069 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2070 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2071 //// write back Dec configuration
2072 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2073 //Cache_wait();
2074 #endif
2076 // Establish primary timing
2077 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2078 {
2079 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2080 break;
2081 }
2083 #if 0
2084 //// (***) FL: revisit
2085 //// invalidate Dec configuration
2086 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2087 //Cache_wait();
2088 #endif
2090 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2091 {
2092 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2093 break;
2094 }
2096 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2097 state = DECODE;
2098 continue;
2100 case DECODE: // decode state
2101 gAsipDecodeCnt++;
2102 Log_info0("TaskAsip: state=DECODE");
2104 #if 0
2105 //// (***) FL: revisit
2106 //// write back Dec configuration
2107 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2108 //Cache_wait();
2109 #endif
2111 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2112 {
2113 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2114 break;
2115 }
2117 #if 0
2118 //// (***) FL: revisit
2119 //// invalidate Dec configuration
2120 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2121 //Cache_wait();
2122 #endif
2124 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2125 state = FINAL;
2126 continue;
2128 case FINAL: // frame-finalization state
2129 gAsipFinalCnt++;
2130 Log_info0("TaskAsip: state=FINAL");
2132 // Check for final frame, and if indicated:
2133 // - Exit state machine to "complete" processing.
2134 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2135 {
2136 break;
2137 }
2139 frame++;
2140 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2141 state = INFO2;
2142 continue;
2144 case QUIT: // exit state
2145 gAsipQuitCnt++;
2146 Log_info0("TaskAsip: state=QUIT");
2148 // Quit:
2149 // - Set error number registers.
2150 // - Exit state machine to "decode complete" processing.
2151 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2152 errno = ASPERR_QUIT;
2153 break;
2155 default: // unknown state
2157 // Unknown:
2158 // - Set error number registers.
2159 // - Exit state machine to "decode complete" processing.
2161 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2162 errno = ASPERR_UNKNOWNSTATE;
2163 break;
2165 } // End of switch (state).
2167 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2168 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2169 {
2170 /* ignored? */;
2171 }
2173 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2175 return errno;
2176 } // End of for (;;) to Receive, process, and transmit the data.
2177 } //PAF_ASIT_decodeProcessing
2179 // -----------------------------------------------------------------------------
2180 // ASIT Decoding Function - Decode Command Processing
2181 //
2182 // Name: PAF_ASIT_decodeCommand
2183 // Purpose: Decoding Function for processing Decode Commands.
2184 // From: AST Parameter Function -> decodeProcessing
2185 // Uses: See code.
2186 // States: x
2187 // Return: Error number in standard form (0 on success).
2188 // Trace: Message Log "trace" in Debug Project Configuration reports:
2189 // * Command execution.
2190 //
2192 Int
2193 PAF_ASIT_decodeCommand(
2194 const PAF_ASIT_Params *pP,
2195 const PAF_ASIT_Patchs *pQ,
2196 PAF_ASIT_Config *pC
2197 )
2198 {
2199 PAF_AST_Config *pAstCfg;
2200 Int as; /* Audio Stream Number (1, 2, etc.) */
2201 Int z; /* decode counter */
2202 Int zS;
2204 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2205 as = pAstCfg->as;
2207 for (z=DECODE1; z < DECODEN; z++)
2208 {
2209 zS = pP->streamsFromDecodes[z];
2210 if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2211 {
2212 switch (pAstCfg->xDec[z].decodeStatus.command2)
2213 {
2214 case 0: // command none - process
2215 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2216 break;
2217 case 1: // command abort - leave now
2218 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2219 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2220 return (ASPERR_ABORT);
2221 case 2: // command restart - leave later
2222 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2223 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2224 return (ASPERR_QUIT);
2225 default: // command unknown - ignore
2226 break;
2227 }
2228 }
2229 }
2231 return 0;
2232 } //PAF_ASIT_decodeCommand
2234 // -----------------------------------------------------------------------------
2235 // ASIT Decoding Function - Reinitialization of Decode
2236 //
2237 // Name: PAF_ASIT_decodeInit
2238 // Purpose: Decoding Function for reinitializing the decoding process.
2239 // From: AST Parameter Function -> decodeProcessing
2240 // Uses: See code.
2241 // States: x
2242 // Return: Error number in standard or SIO form (0 on success).
2243 // Trace: Message Log "trace" in Debug Project Configuration reports:
2244 // * State information as per parent.
2245 //
2246 Int
2247 PAF_ASIT_decodeInit(
2248 const PAF_ASIT_Params *pP,
2249 const PAF_ASIT_Patchs *pQ,
2250 PAF_ASIT_Config *pC,
2251 Int sourceSelect
2252 )
2253 {
2254 PAF_AST_Config *pAstCfg;
2255 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2256 Int as; /* Audio Stream Number (1, 2, etc.) */
2257 Int z; /* decode/encode counter */
2258 Int errno; /* error number */
2259 Int zI, zS;
2260 Int zMD;
2261 Int zMI;
2262 ASP_Msg* pAspMsg; /* Messaging */
2263 Int argIdx;
2264 Int decErrno;
2265 Int status;
2267 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2268 as = pAstCfg->as;
2269 zMD = pAstCfg->masterDec;
2270 zMI = pP->zone.master;
2271 (void)as; // clear compiler warning in case not used with tracing disabled
2273 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2275 // reset frameCount
2276 for (z=DECODE1; z < DECODEN; z++)
2277 {
2278 if (pAstCfg->xDec[z].decodeStatus.mode)
2279 {
2280 pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2281 }
2282 }
2284 for (z=DECODE1; z < DECODEN; z++)
2285 {
2286 zI = pP->inputsFromDecodes[z];
2287 zS = pP->streamsFromDecodes[z];
2288 (void)zS; // clear compiler warning in case not used with tracing disabled
2289 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2290 {
2291 Uns gear;
2292 Int frameLength;
2293 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2295 // write back Dec configuration
2296 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2297 Cache_wait();
2299 // FL: send dec activate message to slave
2300 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2301 if (pAspMsg == NULL)
2302 {
2303 TRACE_TERSE0("MessageQ_alloc() failure.");
2304 SW_BREAKPOINT; // temporary
2305 return -1; // temporary
2306 }
2307 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2308 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2309 pAspMsg->procId = hAspMsgMaster->masterProcId;
2310 pAspMsg->expectResp = TRUE;
2311 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2312 argIdx = 0; // set decIdx (zone index)
2313 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2314 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2315 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2316 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2317 if (status != MessageQ_S_SUCCESS)
2318 {
2319 SW_BREAKPOINT;
2320 }
2321 // wait for dec activate complete message from slave
2322 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2323 if (status != MessageQ_S_SUCCESS)
2324 {
2325 TRACE_TERSE0("MessageQ_get() failure.");
2326 SW_BREAKPOINT; // temporary
2327 return -1; // temporary
2328 }
2329 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2330 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2331 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2332 {
2333 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2334 SW_BREAKPOINT; // temporary
2335 return -1; // temporary
2336 }
2337 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2338 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2339 // free the message
2340 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2341 if (status != MessageQ_S_SUCCESS)
2342 {
2343 SW_BREAKPOINT;
2344 }
2346 #if 0 // FL: decoder activate call, slave
2347 if (decAlg[z]->fxns->algActivate)
2348 decAlg[z]->fxns->algActivate (decAlg[z]);
2349 #endif
2351 // FL: send dec reset message to slave
2352 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2353 if (pAspMsg == NULL)
2354 {
2355 TRACE_TERSE0("MessageQ_alloc() failure.");
2356 SW_BREAKPOINT; // temporary
2357 return -1; // temporary
2358 }
2359 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2360 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2361 pAspMsg->procId = hAspMsgMaster->masterProcId;
2362 pAspMsg->expectResp = TRUE;
2363 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2364 argIdx = 0; // set decIdx
2365 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2366 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2367 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2368 // wait for dec reset complete message from slave
2369 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2370 if (status != MessageQ_S_SUCCESS)
2371 {
2372 SW_BREAKPOINT;
2373 }
2374 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2375 if (status != MessageQ_S_SUCCESS)
2376 {
2377 TRACE_TERSE0("MessageQ_get() failure.");
2378 SW_BREAKPOINT; // temporary
2379 return -1; // temporary
2380 }
2381 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2382 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2383 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2384 {
2385 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2386 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2387 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2389 argIdx = 0; // get decErrno
2390 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2391 if (decErrno != 0)
2392 {
2393 return decErrno;
2394 }
2395 }
2396 else
2397 {
2398 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2399 SW_BREAKPOINT; // temporary
2400 return -1; // temporary
2401 }
2402 // free the message
2403 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2404 if (status != MessageQ_S_SUCCESS)
2405 {
2406 SW_BREAKPOINT;
2407 }
2409 // (***) FL: revisit
2410 // invalidate Dec configuration
2411 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2412 Cache_wait();
2414 #if 0 // FL: decoder reset call, slave
2415 if (dec->fxns->reset
2416 && (errno = dec->fxns->reset (dec, NULL,
2417 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2418 return errno;
2419 #endif
2421 gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2422 pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2424 #if 0 // FL: change handle to decIdx (zone index)
2425 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2426 FRAMELENGTH,
2427 pC->xDec[z].decodeStatus.bufferRatio);
2428 #endif
2429 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2430 frameLength = pP->fxns->computeFrameLength(z,
2431 FRAMELENGTH,
2432 pC->xDec[z].decodeStatus.bufferRatio);
2433 #else
2434 if (sourceSelect == PAF_SOURCE_PCM)
2435 {
2436 frameLength = 256;
2437 }
2438 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2439 {
2440 frameLength = 1536;
2441 }
2442 else if (sourceSelect == PAF_SOURCE_THD)
2443 {
2444 frameLength = 1536; //QIN FIX ME
2445 }
2446 else
2447 {
2448 frameLength = 256;
2449 }
2450 #endif
2452 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2453 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2454 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2456 // (***) FL: revisit. Count samples for DDP.
2457 // Add framework frame length and running sample count to decoder control.
2458 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2459 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2461 // Initialize decoder output circular buffer for selected source
2462 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2463 if (errno)
2464 {
2465 SW_BREAKPOINT; // FL: debug
2466 return errno;
2467 }
2468 // FL: debug
2469 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2471 if (z != zMD)
2472 {
2473 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2474 {
2475 return errno;
2476 }
2477 }
2479 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2480 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2481 {
2482 return errno;
2483 }
2484 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2485 frameLength))
2486 {
2487 return errno;
2488 }
2489 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2490 &pAstCfg->xInp[zI].inpBufConfig))
2491 {
2492 return errno;
2493 }
2494 }
2495 }
2497 if (pAstCfg->xInp[zMI].hRxSio)
2498 {
2499 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2500 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2501 if (errno)
2502 {
2503 return errno;
2504 }
2505 }
2507 return 0;
2508 } //PAF_AST_decodeInit
2510 // -----------------------------------------------------------------------------
2511 // ASIT Decoding Function - Info Processing, Common
2512 //
2513 // Name: PAF_ASIT_decodeInfo
2514 // Purpose: Decoding Function for processing information in a manner that
2515 // is common for both initial and subsequent frames of input data.
2516 // From: AST Parameter Function -> decodeProcessing
2517 // Uses: See code.
2518 // States: x
2519 // Return: Error number in standard form (0 on success).
2520 // Trace: Message Log "trace" in Debug Project Configuration reports:
2521 // * State information as per parent.
2522 //
2523 Int
2524 PAF_ASIT_decodeInfo(
2525 const PAF_ASIT_Params *pP,
2526 const PAF_ASIT_Patchs *pQ,
2527 PAF_ASIT_Config *pC,
2528 Int frame,
2529 Int block
2530 )
2531 {
2532 PAF_AST_Config *pAstCfg;
2533 Int as; /* Audio Stream Number (1, 2, etc.) */
2534 Int z; /* input/decode/stream counter */
2535 Int errno; /* error number */
2536 Int sioErr; /* error number, SIO */
2537 Int zD, zI, zS, zX;
2538 Int zMD;
2539 Int zMI;
2540 Int zMS;
2541 UInt32 curTime;
2542 ASP_Msg *pAspMsg; /* Messaging */
2543 Int argIdx;
2544 Int status;
2545 // FL: revisit
2546 //Int size;
2547 //PAF_InpBufConfig *pIpBufConfig;
2549 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2550 as = pAstCfg->as;
2551 zMD = pAstCfg->masterDec;
2552 zMS = pAstCfg->masterStr;
2553 zMI = pP->zone.master;
2554 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2556 // Set decode control: sample rate, emphasis
2557 for (z=INPUT1; z < INPUTN; z++)
2558 {
2559 zD = z;
2560 for (zX = DECODE1; zX < DECODEN; zX++)
2561 {
2562 if (pP->inputsFromDecodes[zX] == z)
2563 {
2564 zD = zX;
2565 break;
2566 }
2567 }
2569 if (pAstCfg->xInp[z].hRxSio)
2570 {
2571 //determine associated decoder
2572 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2573 pAstCfg->xDec[zD].decodeControl.sampleRate)
2574 {
2575 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2576 {
2577 pAstCfg->xDec[zD].decodeControl.sampleRate =
2578 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2579 }
2580 else
2581 {
2582 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2583 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2584 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2585 pAstCfg->xDec[zD].decodeControl.sampleRate);
2586 // return (ASPERR_INFO_RATECHANGE);
2587 }
2588 }
2589 pAstCfg->xDec[zD].decodeControl.emphasis =
2590 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2591 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2592 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2593 }
2594 else
2595 {
2596 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2597 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2598 }
2599 }
2601 // Wait for info input
2602 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2603 if (pAstCfg->xInp[zMI].hRxSio)
2604 {
2605 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2606 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2607 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2608 {
2609 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2610 return ASPERR_RECLAIM;
2611 }
2613 // FL: debug, capture input buffer
2614 //capIb(pAstCfg->xInp[zMI].pInpBuf);
2616 //
2617 // Simulate Rx SIO_reclaim() pend
2618 //
2619 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2620 gTaskAsipCnt++;
2621 curTime = Clock_getTicks();
2622 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2623 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2624 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2625 } //pC->xInp[zMI].hRxSio
2627 // Decode info
2628 for (z=DECODE1; z < DECODEN; z++)
2629 {
2630 zI = pP->inputsFromDecodes[z];
2631 zS = pP->streamsFromDecodes[z];
2632 (void)zS; // clear compiler warning in case not used with tracing disabled
2633 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2634 {
2635 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2637 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2638 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2639 {
2640 TRACE_TERSE1("return error errno 0x%x.", errno);
2641 return errno;
2642 }
2644 #if 1
2645 // (***) FL: revisit
2646 // write back Inp configuration
2647 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2648 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2649 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2650 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2651 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2652 // write back Dec configuration
2653 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2654 Cache_wait();
2655 #endif
2657 // FL: send info message to slave
2658 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2659 if (pAspMsg == NULL)
2660 {
2661 TRACE_TERSE0("MessageQ_alloc() failure.");
2662 SW_BREAKPOINT; // temporary
2663 return -1; // temporary
2664 }
2665 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2666 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
2667 pAspMsg->procId = hAspMsgMaster->masterProcId;
2668 pAspMsg->expectResp = TRUE;
2669 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2670 argIdx = 0; // set decIdx
2671 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2672 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2673 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2674 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
2675 if (status != MessageQ_S_SUCCESS)
2676 {
2677 SW_BREAKPOINT;
2678 }
2679 // wait for dec info complete message from slave -- temporary
2680 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2681 if (status != MessageQ_S_SUCCESS)
2682 {
2683 TRACE_TERSE0("MessageQ_get() failure.");
2684 SW_BREAKPOINT;
2685 return -1; // temporary
2686 }
2687 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2688 (pAspMsg->cmd != ASP_MASTER_DEC_INFO_DONE) ||
2689 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2690 {
2691 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2692 SW_BREAKPOINT; // temporary
2693 }
2694 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2695 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2696 // free the message
2697 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2698 if (status != MessageQ_S_SUCCESS)
2699 {
2700 SW_BREAKPOINT;
2701 }
2703 #if 1
2704 // (***) FL: revisit
2705 // invalidate Dec configuration
2706 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2707 Cache_wait();
2708 #endif
2710 #if 0 // FL: decoder info call, slave
2711 if (dec->fxns->info
2712 && (errno = dec->fxns->info (dec, NULL,
2713 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2714 #endif
2715 if (errno)
2716 {
2717 TRACE_TERSE1("return error errno 0x%x.", errno);
2718 return errno;
2719 }
2720 // increment decoded frame count
2721 pAstCfg->xDec[z].decodeStatus.frameCount += 1;
2722 }
2723 } // z=DECODE1 to DECODEN
2725 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2726 if (pAstCfg->xDec[zMD].decodeStatus.mode)
2727 {
2728 XDAS_Int8 sourceProgram;
2729 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2730 (Arg)&sourceProgram))
2731 {
2732 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2733 return ASPERR_AUTO_PROGRAM;
2734 }
2735 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
2736 }
2738 // since now decoding update decode status for all enabled decoders
2739 for (z=DECODE1; z < DECODEN; z++)
2740 {
2741 if (pAstCfg->xDec[z].decodeStatus.mode)
2742 {
2743 pAstCfg->xDec[z].decodeStatus.sourceDecode = pAstCfg->xDec[z].decodeStatus.sourceProgram;
2744 if (pAstCfg->xDec[z].decodeStatus.sourceSelect == PAF_SOURCE_SNG)
2745 {
2746 pAstCfg->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_SNG;
2747 }
2748 }
2749 }
2751 #if 0 // FL: ASDT (slave)
2752 // TODO: move this to start of this function so that it doesn't affect IO timing
2753 // Initialize audio frame(s)
2754 // Re-initialize audio frame if there is an associated decode and
2755 // that decode doesn't have a valid input or is turned off
2756 for (z=STREAM1; z < STREAMN; z++)
2757 {
2758 Int reset = 0;
2759 for (zX = DECODE1; zX < DECODEN; zX++)
2760 {
2761 if (pP->streamsFromDecodes[zX] == z)
2762 {
2763 zI = pP->inputsFromDecodes[zX];
2764 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2765 {
2766 reset = 1;
2767 }
2768 }
2769 }
2770 if (reset)
2771 {
2772 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2773 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2774 }
2775 else
2776 {
2777 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2778 }
2779 }
2780 #endif
2782 return 0;
2783 } //PAF_ASIT_decodeInfo
2785 // -----------------------------------------------------------------------------
2786 // ASIT Decoding Function - Info Processing, Initial
2787 //
2788 // Name: PAF_ASIT_decodeInfo1
2789 // Purpose: Decoding Function for processing information in a manner that
2790 // is unique to initial frames of input data.
2791 // From: AST Parameter Function -> decodeProcessing
2792 // Uses: See code.
2793 // States: x
2794 // Return: Error number in standard or SIO form (0 on success).
2795 // Trace: Message Log "trace" in Debug Project Configuration reports:
2796 // * State information as per parent.
2797 //
2798 Int
2799 PAF_ASIT_decodeInfo1(
2800 const PAF_ASIT_Params *pP,
2801 const PAF_ASIT_Patchs *pQ,
2802 PAF_ASIT_Config *pC,
2803 Int frame,
2804 Int block
2805 )
2806 {
2807 return 0;
2808 } //PAF_ASIT_decodeInfo1
2810 // -----------------------------------------------------------------------------
2811 // AST Decoding Function - Info Processing, Subsequent
2812 //
2813 // Name: PAF_AST_decodeInfo2
2814 // Purpose: Decoding Function for processing information in a manner that
2815 // is unique to frames of input data other than the initial one.
2816 // From: AST Parameter Function -> decodeProcessing
2817 // Uses: See code.
2818 // States: x
2819 // Return: Error number in standard form (0 on success).
2820 // Trace: None.
2821 //
2822 Int
2823 PAF_ASIT_decodeInfo2(
2824 const PAF_ASIT_Params *pP,
2825 const PAF_ASIT_Patchs *pQ,
2826 PAF_ASIT_Config *pC,
2827 Int frame,
2828 Int block
2829 )
2830 {
2831 return 0;
2832 } //PAF_ASIT_decodeInfo2
2834 // -----------------------------------------------------------------------------
2835 // AST Decoding Function - Continuation Processing
2836 //
2837 // Name: PAF_AST_decodeCont
2838 // Purpose: Decoding Function for processing that occurs subsequent to
2839 // information processing but antecedent to timing processing
2840 // for frames of input data other than the initial one.
2841 // From: AST Parameter Function -> decodeProcessing
2842 // Uses: See code.
2843 // States: x
2844 // Return: Error number in standard form (0 on success).
2845 // Trace: Message Log "trace" in Debug Project Configuration reports:
2846 // * State information as per parent.
2847 //
2849 Int
2850 PAF_AST_decodeCont(
2851 const PAF_ASIT_Params *pP,
2852 const PAF_ASIT_Patchs *pQ,
2853 PAF_ASIT_Config *pC,
2854 ALG_Handle decAlg[],
2855 Int frame,
2856 Int block
2857 )
2858 {
2859 PAF_AST_Config *pAstCfg;
2860 Int as; /* Audio Stream Number (1, 2, etc.) */
2861 Int z; /* decode counter */
2862 Int zI, zS;
2863 Int zMD;
2866 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2867 as = pAstCfg->as;
2868 zMD = pAstCfg->masterDec;
2869 (void)as; // clear compiler warning in case not used with tracing disabled
2871 // Await slave inputs
2872 for (z=DECODE1; z < DECODEN; z++) {
2873 zI = pP->inputsFromDecodes[z];
2874 zS = pP->streamsFromDecodes[z];
2875 (void)zS;
2876 if (z == zMD
2877 || ! pAstCfg->xInp[zI].hRxSio
2878 || ! pAstCfg->xDec[z].decodeStatus.mode)
2879 continue;
2880 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2881 if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
2882 != sizeof (pAstCfg->xInp[zI].inpBufConfig))
2883 return (ASPERR_RECLAIM);
2884 }
2886 return 0;
2887 } //PAF_AST_decodeCont
2889 // -----------------------------------------------------------------------------
2890 // ASIT Decoding Function - Decode Processing
2891 //
2892 // Name: PAF_ASIT_decodeDecode
2893 // Purpose: Decoding Function for processing of input data by the
2894 // Decode Algorithm.
2895 // From: AST Parameter Function -> decodeProcessing
2896 // Uses: See code.
2897 // States: x
2898 // Return: Error number in standard form (0 on success).
2899 // Trace: Message Log "trace" in Debug Project Configuration reports:
2900 // * State information as per parent.
2901 //
2902 Int
2903 PAF_ASIT_decodeDecode(
2904 const PAF_ASIT_Params *pP,
2905 const PAF_ASIT_Patchs *pQ,
2906 PAF_ASIT_Config *pC,
2907 Int sourceSelect,
2908 Int frame,
2909 Int block
2910 )
2911 {
2912 PAF_AST_Config *pAstCfg;
2913 Int as; /* Audio Stream Number (1, 2, etc.) */
2914 Int z; /* decode/stream counter */
2915 Int errno; /* error number */
2916 //Int ch;
2917 ASP_Msg *pAspMsg; /* Messaging */
2918 Int argIdx;
2919 Int status;
2920 Int cbErrno;
2921 Int frameLength;
2923 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2924 as = pAstCfg->as;
2925 (void)as; // clear compiler warning in case not used with tracing disabled
2927 #if 0 // FL: slave
2928 // Clear samsiz for all channels - MID 208.
2929 for (z=STREAM1; z < STREAMN; z++)
2930 {
2931 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
2932 {
2933 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
2934 }
2935 }
2936 #endif
2938 // Decode data
2939 for (z=DECODE1; z < DECODEN; z++)
2940 {
2941 Int zI = pP->inputsFromDecodes[z];
2942 Int zS = pP->streamsFromDecodes[z];
2943 (void)zS; // clear compiler warning in case not used with tracing disabled
2944 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2945 {
2946 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
2948 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
2949 as+zS,
2950 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
2951 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
2953 // FL: debug, capture input buffer
2954 //capIbPcm(pAstCfg->xInp[z].pInpBuf);
2956 // (***) FL: revisit
2957 // write back Dec configuration
2958 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2959 Cache_wait();
2961 // FL: send decode message to slave
2962 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2963 if (pAspMsg == NULL)
2964 {
2965 TRACE_TERSE0("MessageQ_alloc() failure.");
2966 SW_BREAKPOINT; // temporary
2967 return -1; // temporary
2968 }
2969 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2970 pAspMsg->cmd = ASP_SLAVE_DEC_DECODE; /* fill in message payload */
2971 pAspMsg->procId = hAspMsgMaster->masterProcId;
2972 pAspMsg->expectResp = TRUE;
2973 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2974 argIdx = 0; // set decIdx
2975 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2976 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2977 TRACE_MSG1("decIdx=%d", pAspMsg->buf[argIdx]);
2978 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2979 if (status != MessageQ_S_SUCCESS)
2980 {
2981 SW_BREAKPOINT;
2982 }
2983 // wait for decode complete message from slave -- temporary
2984 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2985 if (status != MessageQ_S_SUCCESS)
2986 {
2987 TRACE_TERSE0("MessageQ_get() failure.");
2988 SW_BREAKPOINT; // temporary
2989 return -1; // temporary
2990 }
2991 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2992 (pAspMsg->cmd == ASP_MASTER_DEC_DECODE_DONE) &&
2993 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2994 {
2995 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2996 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2998 argIdx = 0;
2999 errno = *(Int32 *)&pAspMsg->buf[argIdx];
3000 argIdx += sizeof(Int32);
3001 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
3002 if (cbErrno != 0)
3003 {
3004 TRACE_TERSE1("CB write error=%d", cbErrno);
3005 SW_BREAKPOINT; // temporary
3006 }
3007 }
3008 else
3009 {
3010 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3011 SW_BREAKPOINT; // temporary
3012 }
3013 // free the message
3014 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3015 if (status != MessageQ_S_SUCCESS)
3016 {
3017 SW_BREAKPOINT;
3018 }
3020 // (***) FL: revisit
3021 // invalidate Dec configuration
3022 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3023 Cache_wait();
3025 #if 0 // FL: decoder decode call, slave
3026 if (dec->fxns->decode
3027 && (errno = dec->fxns->decode (dec, NULL,
3028 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
3029 #endif
3030 if (errno)
3031 {
3032 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
3033 return errno;
3034 }
3036 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3037 as_traceChannels(pC, z);
3038 #endif
3040 #if 0 // FL: change handle to decIdx (zone index)
3041 frameLength = pP->fxns->computeFrameLength(decAlg[z],
3042 FRAMELENGTH,
3043 pC->xDec[z].decodeStatus.bufferRatio);
3044 #endif
3045 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
3046 frameLength = pP->fxns->computeFrameLength(z,
3047 FRAMELENGTH,
3048 pC->xDec[z].decodeStatus.bufferRatio);
3049 #else
3050 if (sourceSelect == PAF_SOURCE_PCM)
3051 {
3052 frameLength = 256;
3053 }
3054 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
3055 {
3056 frameLength = 1536;
3057 }
3058 else if (sourceSelect == PAF_SOURCE_THD)
3059 {
3060 frameLength = 1536; //QIN FIX ME
3061 }
3062 else
3063 {
3064 frameLength = 256;
3065 }
3066 #endif
3068 // ............................................................................
3070 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3071 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3072 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3073 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3074 {
3075 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3076 return errno;
3077 }
3079 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3080 if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3081 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3082 PAF_SIO_REQUEST_NEWFRAME))
3083 {
3084 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3085 return (ASPERR_ISSUE);
3086 }
3087 } // hRxSio && decodeStatus.mode
3088 else
3089 {
3090 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3091 }
3092 } // z=DECODE1 to DECODEN
3094 #if 0 // FL: ASDT (slave)
3095 // Set up audio frames not decoded into
3096 // Re-initialize audio frame if there is an assocatiated decode and
3097 // that decode doesn't have a valid input or is turned off
3098 for (z=STREAM1; z < STREAMN; z++)
3099 {
3100 Int zX;
3101 Int reset = 0;
3102 for (zX = DECODE1; zX < DECODEN; zX++)
3103 {
3104 if (pP->streamsFromDecodes[zX] == z)
3105 {
3106 Int zI = pP->inputsFromDecodes[zX];
3107 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3108 reset = 1;
3109 }
3110 }
3111 if (reset)
3112 {
3113 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3114 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3115 }
3116 else
3117 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3118 }
3119 #endif
3121 return 0;
3122 } //PAF_ASIT_decodeDecode
3124 // -----------------------------------------------------------------------------
3125 // ASIT Decoding Function - Frame-Final Processing
3126 //
3127 // Name: PAF_ASIT_decodeFinalTest
3128 // Purpose: Decoding Function for determining whether processing of the
3129 // current frame is complete.
3130 // From: AST Parameter Function -> decodeProcessing
3131 // Uses: See code.
3132 // States: x
3133 // Return: 0 if incomplete, and 1 if complete.
3134 // Trace: None.
3135 //
3137 Int
3138 PAF_ASIT_decodeFinalTest(
3139 const PAF_ASIT_Params *pP,
3140 const PAF_ASIT_Patchs *pQ,
3141 PAF_ASIT_Config *pC,
3142 Int frame,
3143 Int block
3144 )
3145 {
3146 PAF_AST_Config *pAstCfg;
3147 Int zMD;
3148 Int sourceSelect;
3149 Int sourceProgram;
3151 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3152 zMD = pAstCfg->masterDec;
3154 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
3155 sourceProgram = pAstCfg->xDec[zMD].decodeStatus.sourceProgram;
3157 if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3158 {
3159 return 1;
3160 }
3162 // The following allows for Force modes to switch without command deferral. This might
3163 // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3164 if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
3165 {
3166 if (sourceSelect == PAF_SOURCE_DTSALL)
3167 {
3168 if (sourceProgram != PAF_SOURCE_DTS11 &&
3169 sourceProgram != PAF_SOURCE_DTS12 &&
3170 sourceProgram != PAF_SOURCE_DTS13 &&
3171 sourceProgram != PAF_SOURCE_DTS14 &&
3172 sourceProgram != PAF_SOURCE_DTS16 &&
3173 sourceProgram != PAF_SOURCE_DTSHD)
3174 {
3175 return 1;
3176 }
3177 }
3178 else if (sourceSelect == PAF_SOURCE_PCMAUTO)
3179 {
3180 if (sourceProgram != PAF_SOURCE_PCM)
3181 {
3182 return 1;
3183 }
3184 }
3185 else
3186 {
3187 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect != pAstCfg->xDec[zMD].decodeStatus.sourceDecode)
3188 {
3189 return 1;
3190 }
3191 }
3192 }
3194 return 0;
3195 } //PAF_ASIT_decodeFinalTest
3197 // -----------------------------------------------------------------------------
3198 // ASIT Decoding Function - Stream-Final Processing
3199 //
3200 // Name: PAF_ASIT_decodeComplete
3201 // Purpose: Decoding Function for terminating the decoding process.
3202 // From: AST Parameter Function -> decodeProcessing
3203 // Uses: See code.
3204 // States: x
3205 // Return: 0.
3206 // Trace: Message Log "trace" in Debug Project Configuration reports:
3207 // * State information as per parent.
3208 //
3209 Int
3210 PAF_ASIT_decodeComplete(
3211 const PAF_ASIT_Params *pP,
3212 const PAF_ASIT_Patchs *pQ,
3213 PAF_ASIT_Config *pC,
3214 ALG_Handle decAlg[],
3215 Int frame,
3216 Int block
3217 )
3218 {
3219 PAF_AST_Config *pAstCfg;
3220 Int as; /* Audio Stream Number (1, 2, etc.) */
3221 Int z; /* decode/encode counter */
3222 ASP_Msg* pAspMsg;
3223 Int argIdx;
3224 Int errno; /* error number */
3225 Int status;
3228 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3229 as = pAstCfg->as;
3230 (void)as; // clear compiler warning in case not used with tracing disabled
3232 #ifdef PAF_ASP_FINAL
3233 /* This material is currently not utilized */
3234 #endif /* PAF_ASP_FINAL */
3235 for (z=DECODE1; z < DECODEN; z++)
3236 {
3237 #ifdef PAF_ASP_FINAL
3238 DEC_Handle dec = (DEC_Handle )decAlg[z];
3239 #endif /* PAF_ASP_FINAL */
3240 Int zI = pP->inputsFromDecodes[z];
3241 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3242 {
3243 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3244 #ifdef PAF_ASP_FINAL
3245 if (dec->fxns->final)
3246 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3247 &pAstCfg->xDec[z].decodeStatus);
3248 #endif /* PAF_ASP_FINAL */
3249 // FL: send dec deactivate message to slave
3250 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3251 if (pAspMsg == NULL)
3252 {
3253 TRACE_TERSE0("MessageQ_alloc() failure.");
3254 errno = -1; // temporary
3255 return errno;
3256 }
3257 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3258 pAspMsg->cmd = ASP_SLAVE_DEC_DEACTIVATE; /* fill in message payload */
3259 pAspMsg->procId = hAspMsgMaster->masterProcId;
3260 pAspMsg->expectResp = TRUE;
3261 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3262 argIdx = 0; // set decIdx
3263 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3264 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3265 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3266 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3267 if (status != MessageQ_S_SUCCESS)
3268 {
3269 SW_BREAKPOINT;
3270 }
3271 // wait for dec deactivate complete message from slave
3272 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3273 if (status != MessageQ_S_SUCCESS)
3274 {
3275 TRACE_TERSE0("MessageQ_get() failure.");
3276 return errno;
3277 }
3278 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
3279 (pAspMsg->cmd != ASP_MASTER_DEC_DEACTIVATE_DONE) ||
3280 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3281 {
3282 TRACE_MSG3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3283 SW_BREAKPOINT; // temporary
3284 }
3285 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3286 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3287 // free the message
3288 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3289 if (status != MessageQ_S_SUCCESS)
3290 {
3291 SW_BREAKPOINT;
3292 }
3294 #if 0 // FL: decoder deactivate call, slave
3295 if (decAlg[z]->fxns->algDeactivate)
3296 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3297 #endif
3298 }
3299 else
3300 {
3301 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3302 }
3303 }
3304 return 0;
3305 } //PAF_ASIT_decodeComplete
3307 // -----------------------------------------------------------------------------
3308 // ASIT Selection Function - Input Device Selection
3309 //
3310 // Name: PAF_ASIT_selectDevices
3311 // Purpose: Audio Stream Input Task Function for selecting the devices used
3312 // for input.
3313 // From: audioStream1Task or equivalent
3314 // Uses: See code.
3315 // States: x
3316 // Return: Error number in standard form (0 on success).
3317 // Trace: Message Log "trace" in Debug Project Configuration reports:
3318 // * State information as per parent.
3319 //
3320 Int
3321 PAF_ASIT_selectDevices(
3322 const PAF_ASIT_Params *pP,
3323 const PAF_ASIT_Patchs *pQ,
3324 PAF_ASIT_Config *pC
3325 )
3326 {
3327 PAF_AST_Config *pAstCfg;
3328 Int as; /* Audio Stream Number (1, 2, etc.) */
3329 Int z; /* input/output counter */
3330 Int errno = 0; /* error number */
3331 Int errme; /* error number, local */
3332 Int device;
3333 Int zMD;
3335 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3336 as = pAstCfg->as;
3337 zMD = pAstCfg->masterDec;
3338 (void)as; // clear compiler warning in case not used with tracing disabled
3340 // Select input devices
3341 for (z=INPUT1; z < INPUTN; z++)
3342 {
3343 if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0)
3344 {
3345 TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3347 // check for valid index into device array
3348 if (device >= pQ->devinp->n)
3349 {
3350 device = 0; /* treat as device None */
3351 }
3353 errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3354 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3356 if (errme)
3357 {
3358 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3359 if (!errno)
3360 {
3361 errno = ASPERR_DEVINP + errme;
3362 }
3363 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3364 }
3365 else
3366 {
3367 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3368 // register decodeStatus pointer with input devices
3369 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3370 // Use zMIs decodeStatus for all inputs
3371 if (pAstCfg->xInp[z].hRxSio)
3372 {
3373 // register PAF_SIO_IALG object address
3374 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR,
3375 (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3376 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR,
3377 (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3378 }
3379 }
3380 }
3381 }
3383 return errno;
3384 } //PAF_ASIT_selectDevices
3386 // -----------------------------------------------------------------------------
3387 // ASIT Selection Function - Source Selection
3388 //
3389 // Name: PAF_ASIT_sourceDecode
3390 // Purpose: Audio Input Stream Task Function for selecting the sources used
3391 // for decoding of input to output.
3392 // From: audioStream1Task or equivalent
3393 // Uses: See code.
3394 // States: x
3395 // Return: 0.
3396 // Trace: None.
3397 //
3398 Int
3399 PAF_ASIT_sourceDecode(
3400 const PAF_ASIT_Params *pP,
3401 const PAF_ASIT_Patchs *pQ,
3402 PAF_ASIT_Config *pC,
3403 Int x
3404 )
3405 {
3406 PAF_AST_Config *pAstCfg;
3407 Int z; /* decode counter */
3409 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3411 for (z=DECODE1; z < DECODEN; z++)
3412 {
3413 if (pAstCfg->xDec[z].decodeStatus.mode)
3414 {
3415 pAstCfg->xDec[z].decodeStatus.sourceDecode = x;
3416 }
3417 }
3419 return 0;
3420 } //PAF_ASIT_sourceDecode
3422 // -----------------------------------------------------------------------------
3424 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3425 Int
3426 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3427 {
3428 Int errno = 0;
3429 Int zMD = pC->masterDec;
3430 Int zI = pP->inputsFromDecodes[z];
3432 // only handle real errors, on primary input, for writeDECModeContinuous
3433 if ( !( error &&
3434 z == zMD ))
3435 return error;
3437 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3438 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3440 if (pC->xInp[zI].hRxSio) {
3441 DEC_Handle dec;
3443 if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3444 return errno;
3446 // indicates (primary) input not running
3447 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3449 pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3451 // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3452 pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3454 if (decAlg[z]->fxns->algDeactivate)
3455 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3457 decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3458 dec = (DEC_Handle )decAlg[z];
3460 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3461 pC->as+z));
3463 if (decAlg[z]->fxns->algActivate)
3464 decAlg[z]->fxns->algActivate (decAlg[z]);
3466 if (dec->fxns->reset
3467 && (errno = dec->fxns->reset (dec, NULL,
3468 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3469 return errno;
3470 }
3472 return errno;
3473 } //PAF_AST_decodeHandleErrorInput
3474 #endif
3476 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3478 //------------------------------------------------------------------------------
3479 static int sSkipCount = 0;
3480 int gReportBuffers = 0;
3481 void as_traceChannels(PAF_AST_Config *pC, int z)
3482 {
3483 PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3484 int i;
3486 // #ifdef THIS_IS_DSPA
3487 sSkipCount++;
3488 if (sSkipCount<1)
3489 return;
3490 sSkipCount = 0;
3491 // #endif
3493 #ifdef THIS_IS_DSPB
3494 if (!gReportBuffers)
3495 return;
3496 gReportBuffers = 0;
3497 #endif
3499 dp(NULL, "\n");
3500 for (i=0; i<PAF_MAXNUMCHAN; i++)
3501 {
3502 if (pAudioFrame->data.sample[i] != 0)
3503 {
3504 float *wp = (float*)pAudioFrame->data.sample[i];
3505 dp(NULL, "i: %d. p: 0x%x. %f, %f, %f, %f\n",
3506 i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
3507 }
3508 }
3509 }
3510 #endif