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 gAsipDecodeErrCnt =0;
305 UInt32 gAsipFinalCnt =0;
306 UInt32 gAsipQuitCnt =0;
307 UInt32 gIbReset_cnt =0;
308 UInt32 gcapIb_cnt =0;
309 UInt32 gAsipInfo2_PrimaryErrCnt =0;
310 UInt32 gAsipInfo2_ErrCnt =0;
312 #include "dbgDib.h"
314 extern struct {
315 Int size;
316 IALG_Status *pStatus[512];
317 } IACP_STD_BETA_TABLE;
320 /*
321 * ======== taskAsipFxn ========
322 * Audio Stream Input Processing task function
323 */
324 Void taskAsipFxn(
325 // Int betaPrimeValue, // FL: revisit
326 const PAF_ASIT_Params *pP,
327 const PAF_ASIT_Patchs *pQ
328 )
329 {
330 PAF_ASIT_Config *pC; /* Local configuration pointer */
331 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
332 Int as; /* Audio Stream Number (1, 2, etc.) */
333 Int z; /* input/encode/stream/decode/output counter */
334 Int i; /* phase */
335 Int errno; /* error number */
336 Int zMD, zMI, zMS, zX;
337 Int loopCount = 0; // used to stop trace to see startup behavior.
338 UInt32 curTime;
339 Int size;
340 // Messaging
341 ASP_Msg *pAspMsg;
342 Int status;
344 Log_info0("Enter taskAsipFxn()");
346 #ifdef SIMULATE_SIO
347 /* Start simulation */
348 simStart();
349 #endif // SIMULATE_SIO
351 //
352 // Audio Framework Parameters & Patch (*pP, *pQ)
353 //
354 if (!pP)
355 {
356 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
357 LINNO_RPRT(TaskAsip, -1);
358 return;
359 }
361 if (!pQ)
362 {
363 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
364 LINNO_RPRT(TaskAsip, -1);
365 return;
366 }
368 //
369 // Audio Framework Configuration (*pC):
370 //
371 pC = &gPAF_ASIT_config;
372 pAstCfg = pC->pAstCfg;
374 /* Set Audio Stream Number (1, 2, etc.) */
375 as = gBetaPrimeValue + 1;
376 pAstCfg->as = as;
377 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
379 //
380 // Initialize message log trace and line number reporting
381 //
382 for (z=STREAM1; z < STREAMN; z++)
383 {
384 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
385 }
386 LINNO_RPRT(TaskAsip, -1);
388 //
389 // Determine decoder and stream indices associated with the master input
390 //
391 zMI = pP->zone.master;
392 pAstCfg->masterDec = zMI;
393 pAstCfg->masterStr = zMI;
394 for (zX = DECODE1; zX < DECODEN; zX++)
395 {
396 if (pP->inputsFromDecodes[zX] == zMI)
397 {
398 pAstCfg->masterDec = zX;
399 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
400 break;
401 }
402 }
403 zMD = pAstCfg->masterDec;
404 zMS = pAstCfg->masterStr;
406 // Initialize as per parametrized phases:
407 //
408 // In standard form these are:
409 // - Malloc: Memory Allocation
410 // - Config: Configuration Initialization
411 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
412 // - Common: Common Memory Initialization
413 // - AlgKey: Dec/Enc chain to Array Initialization
414 // - Device: I/O Device Initialization
415 // - DecOpCircBuf: Decoder Output Circular Buffer
416 // - Unused: (available)
417 //
418 LINNO_RPRT(TaskAsip, -2);
419 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
420 {
421 Int linno;
422 if (pP->fxns->initPhase[i])
423 {
424 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
425 {
426 LINNO_RPRT(TaskAsip, linno);
427 return;
428 }
429 }
430 else
431 {
432 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
433 }
434 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
435 LINNO_RPRT(TaskAsip, -i-3);
436 }
438 //
439 // End of Initialization -- display memory usage report.
440 //
441 if (pP->fxns->memStatusPrint)
442 {
443 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
444 }
446 // (***) FL: revisit
447 // write back AST shared configuration
448 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
449 // FL: no need to share this pointer, can be local
450 //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
451 Cache_wait();
453 // (***) FL: revisit
454 // write back Dec configuration
455 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
456 Cache_wait();
458 // (***) FL: revisit
459 // write back entire beta table
460 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
461 Cache_wait();
463 // FL: send start initialization message to slave
464 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
465 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
466 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
467 pAspMsg->procId = hAspMsgMaster->masterProcId;
468 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
469 pAspMsg->expectResp = TRUE;
470 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
471 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
472 if (status != MessageQ_S_SUCCESS)
473 {
474 SW_BREAKPOINT;
475 }
476 // wait for initialization complete message from slave
477 do {
478 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
479 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
480 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
481 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
482 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
483 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
484 {
485 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
486 SW_BREAKPOINT;
487 }
488 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
489 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
490 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
491 if (status != MessageQ_S_SUCCESS)
492 {
493 SW_BREAKPOINT;
494 }
496 // (***) FL: revisit
497 // invalidate Status structure addresses for Beta Units initialized on Slave
498 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
499 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
500 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
501 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
502 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
503 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
504 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
505 Cache_wait();
506 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
507 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
508 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
509 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
510 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
511 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
512 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
514 // (***) FL: revisit
515 // invalidate Status structures for Beta Units initialized on Slave
516 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
517 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
518 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
519 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
520 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
521 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
522 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
523 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
524 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
525 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
526 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
527 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
528 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
529 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
530 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
531 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
532 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
533 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
534 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
535 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
536 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
537 Cache_wait();
539 // (***) FL: revisit
540 // invalidate Dec configuration
541 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
542 Cache_wait();
544 //
545 // Main processing loop
546 //
547 for (z=STREAM1; z < STREAMN; z++)
548 {
549 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
550 }
552 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
554 errno = 0;
555 for (;;)
556 {
557 Int sourceSelect;
558 XDAS_Int8 sourceProgram;
560 loopCount++;
562 #if 0 // enable and tune to see startup behavior.
563 // this is an alternative to fixed/circular setting in pa.cfg.
564 // If you are searching for a memory allocation failure, disable on first round.
565 // All allocation has already happened.
566 // This is the outer loop. This loop count goes up when the stream resets.
567 // If the stream is running without problems, this does not increment.
568 // If the stream is repeatedly resetting, this loop count will go up rapidly.
569 if (loopCount > 10) // see traces for a few of the passes through the main loop.
570 {
571 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
572 LOG_disable(&TR_MOD); // stop tracing
573 }
574 #endif
576 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
577 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
579 // since not decoding indicate such
580 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
582 // any error forces idling of input
583 if (errno)
584 {
585 for (z=INPUT1; z < INPUTN; z++)
586 {
587 if (pAstCfg->xInp[z].hRxSio)
588 {
589 SIO_idle(pAstCfg->xInp[z].hRxSio);
590 }
591 }
593 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
594 ERRNO_RPRT(TaskAsip, errno);
595 }
597 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
598 // up to allow lower priority tasks to run. This may seem odd to be at the top
599 // of the state machine but provides for a cleaner flow even though the very
600 // first time we enter we do a sleep which is non-intuitive.
601 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
602 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
603 Task_sleep(1);
605 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
606 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
607 {
608 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
609 continue;
610 }
612 // if no master input selected then we don't know what may be at the input
613 // so set to unknown and skip any remaining processing
614 if (!pAstCfg->xInp[zMI].hRxSio)
615 {
616 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
617 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
618 continue;
619 }
621 // if here then we have a valid input so query its status
622 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
623 {
624 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
625 continue;
626 }
628 // If master decoder is not enabled, or the input is unlocked, then do nothing
629 if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
630 {
631 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
632 continue;
633 }
635 // If no source selected then do nothing
636 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
637 {
638 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
639 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
640 continue;
641 }
643 // If we want pass processing then proceed directly
644 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
645 {
646 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
647 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
648 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
649 if (pP->fxns->passProcessing)
650 {
651 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
652 }
653 else
654 {
655 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
656 errno = ASPERR_PASS;
657 }
658 TRACE_VERBOSE0("TaskAsip: continue");
659 continue;
660 }
662 // .....................................................................
663 // At this point we have an enabled input and want to decode something.
664 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
665 // when no decoder is selected there are no calls to IB
666 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
667 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
668 {
669 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
670 continue;
671 }
673 // query for input type
674 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
675 {
676 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
677 errno = ASPERR_AUTO_PROGRAM;
678 continue;
679 }
680 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
682 // if input is unclassifiable then do nothing
683 if (sourceProgram == PAF_SOURCE_UNKNOWN)
684 {
685 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
686 continue;
687 }
689 // now that we have some input classification, and possibly an outstanding
690 // input frame, we determine whether or not to call decodeProcessing and with
691 // what decAlg.
692 sourceSelect = PAF_SOURCE_NONE;
693 switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect)
694 {
695 // If autodetecting, decoding everything, and input is something
696 // (i.e. bitstream or PCM) then decode.
697 case PAF_SOURCE_AUTO:
698 if (sourceProgram >= PAF_SOURCE_PCM)
699 {
700 sourceSelect = sourceProgram;
701 }
702 break;
704 // If autodetecting, decoding only PCM, and input is PCM then decode.
705 case PAF_SOURCE_PCMAUTO:
706 if (sourceProgram == PAF_SOURCE_PCM)
707 {
708 sourceSelect = sourceProgram;
709 }
710 break;
712 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
713 case PAF_SOURCE_BITSTREAM:
714 if (sourceProgram >= PAF_SOURCE_AC3)
715 {
716 sourceSelect = sourceProgram;
717 }
718 break;
720 // If autodetecting, decoding only DTS, and input is DTS then decode.
721 case PAF_SOURCE_DTSALL:
722 switch (sourceProgram)
723 {
724 case PAF_SOURCE_DTS11:
725 case PAF_SOURCE_DTS12:
726 case PAF_SOURCE_DTS13:
727 case PAF_SOURCE_DTS14:
728 case PAF_SOURCE_DTS16:
729 case PAF_SOURCE_DTSHD:
730 sourceSelect = sourceProgram;
731 break;
732 }
733 break;
735 // All others, e.g., force modes, fall through to here.
736 // If user made specific selection then program must match select.
737 // (NB: this compare relies on ordering of PAF_SOURCE)
738 default:
739 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
740 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
741 {
742 if (sourceProgram != sourceSelect)
743 {
744 sourceSelect = PAF_SOURCE_NONE;
745 }
746 }
747 break;
748 }
750 // if we didn't find any matches then skip
751 if (sourceSelect == PAF_SOURCE_NONE)
752 {
753 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
754 continue;
755 }
757 // FL: debug, reset IB capture buffer
758 capIbReset();
759 gIbReset_cnt++;
760 Log_info0("capIbReset()");
762 // FL: send source select message to slave
763 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
764 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
765 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
766 pAspMsg->procId = hAspMsgMaster->masterProcId;
767 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
768 pAspMsg->expectResp = TRUE;
769 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
770 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
771 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
772 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
773 if (status != MessageQ_S_SUCCESS)
774 {
775 SW_BREAKPOINT;
776 }
777 // wait for source select complete message from slave
778 //do {
779 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
780 //} while (status != MessageQ_S_SUCCESS);
781 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
782 if (status != MessageQ_S_SUCCESS)
783 {
784 TRACE_TERSE0("MessageQ_get() failure.");
785 SW_BREAKPOINT; // temporary
786 }
787 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
788 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
789 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
790 {
791 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
792 SW_BREAKPOINT;
793 }
794 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
795 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
796 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
797 if (status != MessageQ_S_SUCCESS)
798 {
799 SW_BREAKPOINT;
800 }
802 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
803 // iff we are in this top level state machine and specifically not in decodeProcessing
804 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
806 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
808 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
809 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
810 if (errno)
811 {
812 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
813 }
814 else
815 {
816 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
817 }
819 // FL: send dec exit message to slave
820 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
821 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
822 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
823 pAspMsg->procId = hAspMsgMaster->masterProcId;
824 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
825 pAspMsg->expectResp = TRUE;
826 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
827 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
828 if (status != MessageQ_S_SUCCESS)
829 {
830 SW_BREAKPOINT;
831 }
832 // wait for dec exit complete message from slave
833 //do {
834 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
835 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
836 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
837 if (status != MessageQ_S_SUCCESS)
838 {
839 TRACE_TERSE0("MessageQ_get() failure.");
840 SW_BREAKPOINT; // temporary
841 }
842 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
843 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
844 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
845 {
846 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
847 SW_BREAKPOINT;
848 }
849 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
850 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
851 // free the message
852 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
853 if (status != MessageQ_S_SUCCESS)
854 {
855 SW_BREAKPOINT;
856 }
857 } // End of main processing loop for (;;)
859 Log_info0("Exit taskAsipFxn()");
860 }
862 // -----------------------------------------------------------------------------
863 // ASIT Initialization Function - Memory Allocation
864 //
865 // Name: PAF_ASIT_initPhaseMalloc
866 // Purpose: Audio Stream Input Task Function for initialization of data pointers
867 // by allocation of memory.
868 // From: audioStream1Task or equivalent
869 // Uses: See code.
870 // States: x
871 // Return: 0 on success.
872 // Source code line number on MEM_calloc failure.
873 // Trace: Message Log "trace" in Debug Project Configuration reports:
874 // * State information as per parent.
875 // * Memory allocation errors.
876 //
877 Int
878 PAF_ASIT_initPhaseMalloc(
879 const PAF_ASIT_Params *pP,
880 const PAF_ASIT_Patchs *pQ,
881 PAF_ASIT_Config *pC
882 )
883 {
884 PAF_AST_Config *pAstCfg;
885 Int as; /* Audio Stream Number (1, 2, etc.) */
886 Int zMS;
887 Error_Block eb;
889 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
890 as = pAstCfg->as;
891 zMS = pAstCfg->masterStr;
893 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
895 // Initialize error block
896 Error_init(&eb);
898 /* Input memory */
899 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
900 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
901 {
902 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
903 SW_BREAKPOINT;
904 return __LINE__;
905 }
906 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
907 INPUTN * sizeof (*pAstCfg->xInp),
908 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
910 /* Decode memory */
911 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
912 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
913 {
914 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
915 SW_BREAKPOINT;
916 return __LINE__;
917 }
918 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
919 DECODEN * sizeof (*pAstCfg->xDec),
920 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
922 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
923 return 0;
924 } //PAF_ASIT_initPhaseMalloc
926 // -----------------------------------------------------------------------------
927 // ASIT Initialization Function - Memory Initialization from Configuration
928 //
929 // Name: PAF_ASIT_initPhaseConfig
930 // Purpose: Audio Stream Task Function for initialization of data values
931 // from parameters.
932 // From: audioStream1Task or equivalent
933 // Uses: See code.
934 // States: x
935 // Return: 0 on success.
936 // Other as per initFrame0 and initFrame1.
937 // Trace: Message Log "trace" in Debug Project Configuration reports:
938 // * State information as per parent.
939 //
940 Int
941 PAF_ASIT_initPhaseConfig(
942 const PAF_ASIT_Params *pP,
943 const PAF_ASIT_Patchs *pQ,
944 PAF_ASIT_Config *pC
945 )
946 {
947 PAF_AST_Config *pAstCfg;
948 Int as; /* Audio Stream Number (1, 2, etc.) */
949 Int z; /* input/encode/stream/decode/output counter */
950 Int zMS;
952 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
953 as = pAstCfg->as;
954 zMS = pAstCfg->masterStr;
956 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
958 //
959 // Unspecified elements have been initialized to zero during alloc
960 //
962 for (z=INPUT1; z < INPUTN; z++)
963 {
964 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
965 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
966 }
968 for (z=DECODE1; z < DECODEN; z++)
969 {
970 Int zI = pP->inputsFromDecodes[z];
971 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
972 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
973 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
974 }
976 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
977 return 0;
978 } //PAF_ASIT_initPhaseConfig
980 // -----------------------------------------------------------------------------
981 // ASIT Initialization Function - ACP Algorithm Instantiation
982 //
983 // Name: PAF_ASIT_initPhaseAcpAlg
984 // Purpose: Audio Stream Input Task Function for initialization of ACP by
985 // instantiation of the algorithm.
986 // From: audioStream1Task or equivalent
987 // Uses: See code.
988 // States: x
989 // Return: 0 on success.
990 // Source code line number on ACP Algorithm creation failure.
991 // Trace: Message Log "trace" in Debug Project Configuration reports:
992 // * State information as per parent.
993 // * Memory allocation errors.
994 //
995 Int
996 PAF_ASIT_initPhaseAcpAlg(
997 const PAF_ASIT_Params *pP,
998 const PAF_ASIT_Patchs *pQ,
999 PAF_ASIT_Config *pC
1000 )
1001 {
1002 PAF_AST_Config *pAstCfg;
1003 Int as; /* Audio Stream Number (1, 2, etc.) */
1004 Int z; /* input/encode/stream/decode/output counter */
1005 Int betaPrimeOffset;
1006 ACP_Handle acp;
1007 Int zMS;
1008 Int zS, zX;
1010 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1011 as = pAstCfg->as;
1012 zMS = pAstCfg->masterStr;
1014 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1016 ACP_MDS_init();
1018 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1019 {
1020 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1021 return __LINE__;
1022 }
1023 pC->acp = acp;
1025 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1026 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1028 for (z=INPUT1; z < INPUTN; z++)
1029 {
1030 zS = z;
1031 for (zX = DECODE1; zX < DECODEN; zX++)
1032 {
1033 if (pP->inputsFromDecodes[zX] == z)
1034 {
1035 zS = pP->streamsFromDecodes[zX];
1036 break;
1037 }
1038 }
1039 acp->fxns->attach(acp, ACP_SERIES_STD,
1040 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1041 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1042 /* Ignore errors, not reported. */
1043 }
1045 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1047 return 0;
1048 } //PAF_ASIT_initPhaseAcpAlg
1050 // -----------------------------------------------------------------------------
1051 // ASIT Initialization Function - Common Memory
1052 //
1053 // Name: PAF_ASIT_initPhaseCommon
1054 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1055 // From: audioStream1Task or equivalent
1056 // Uses: See code.
1057 // States: x
1058 // Return: 0 on success.
1059 // Source code line number on PAF_ALG_alloc failure.
1060 // Source code line number on PAF_ALG_mallocMemory failure.
1061 // Source code line number on Decode Chain initialization failure.
1062 // Source code line number on ASP Chain initialization failure.
1063 // Source code line number on Encode Chain initialization failure.
1064 // Trace: Message Log "trace" in Debug Project Configuration reports:
1065 // * State information as per parent.
1066 // * Memory allocation errors.
1067 //
1068 Int
1069 PAF_ASIT_initPhaseCommon(
1070 const PAF_ASIT_Params *pP,
1071 const PAF_ASIT_Patchs *pQ,
1072 PAF_ASIT_Config *pC
1073 )
1074 {
1075 PAF_AST_Config *pAstCfg;
1076 Int as; /* Audio Stream Number (1, 2, etc.) */
1077 Int z; /* stream counter */
1078 ACP_Handle acp;
1079 PAF_IALG_Config pafAlgConfig;
1080 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1082 acp = pC->acp;
1083 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1084 as = pAstCfg->as;
1086 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1088 //
1089 // Determine memory needs and instantiate algorithms across audio streams
1090 //
1091 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1092 PAF_ALG_setup(&pafAlgConfig,
1093 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1094 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1095 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1096 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1097 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1098 HEAP_CLEAR);
1100 if (pP->fxns->headerPrint)
1101 {
1102 pP->fxns->headerPrint();
1103 }
1105 for (z = STREAM1; z < STREAMN; z++)
1106 {
1107 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1109 //
1110 // Determine common memory for:
1111 // (1) Logical Input drivers
1112 //
1113 // Decode Algorithms common memory determined in ASP Slave.
1114 //
1115 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1117 //
1118 // Determine common memory needs of Logical Input driver
1119 //
1121 // really need to loop over all inputs for this stream using the tables
1122 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1123 // patch, and not needed for FS11, since there is only one input.
1124 if (INPUT1 <= z && z < INPUTN)
1125 {
1126 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1127 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1128 {
1129 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1130 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1131 SW_BREAKPOINT;
1132 return __LINE__;
1133 }
1134 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1135 if (pP->fxns->allocPrint)
1136 {
1137 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1138 }
1139 }
1140 }
1141 {
1142 // Changes made to share scratch between zones
1143 // Assume maximum 3 zones and scratch common memory is at offset 0;
1144 int max=0;
1145 for (z=STREAM1; z<STREAMN; z++)
1146 {
1147 if (max < common[z][0].size)
1148 {
1149 max = common[z][0].size;
1150 }
1151 }
1152 common[STREAM1][0].size=max;
1153 for (z=STREAM1+1; z<STREAMN; z++)
1154 {
1155 common[z][0].size = 0;
1156 }
1157 }
1159 //
1160 // Allocate common memory for:
1161 // (1) Logical Input drivers
1162 //
1163 for (z = STREAM1; z < STREAMN; z++)
1164 {
1165 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1166 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1167 {
1168 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1169 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1170 SW_BREAKPOINT;
1171 return __LINE__;
1172 }
1173 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1174 // share zone0 scratch with all zones
1175 common[z][0].base = common[0][0].base;
1176 if (pP->fxns->commonPrint)
1177 {
1178 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1179 }
1181 //
1182 // Allocate non-common memories for Logical IO drivers
1183 // Since these structures are used at run-time we allocate from external memory
1184 if (INPUT1 <= z && z < INPUTN)
1185 {
1186 PAF_ASP_Chain *chain;
1187 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1188 as+z, z);
1189 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1190 HEAP_EXTERNAL, as+z, acp, &trace,
1191 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1192 if (!chain)
1193 {
1194 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1195 return __LINE__;
1196 }
1197 }
1198 }
1199 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1201 return 0;
1202 } //PAF_ASIT_initPhaseCommon
1204 // (***) FL: candidate for removal
1205 // -----------------------------------------------------------------------------
1206 // ASIT Initialization Function - Algorithm Keys
1207 //
1208 // Name: PAF_ASIT_initPhaseAlgKey
1209 // Purpose: Audio Stream Input Task Function for initialization of data values
1210 // from parameters for Algorithm Keys.
1211 // From: audioStream1Task or equivalent
1212 // Uses: See code.
1213 // States: x
1214 // Return: 0.
1215 // Trace: Message Log "trace" in Debug Project Configuration reports:
1216 // * State information as per parent.
1217 //
1218 // .............................................................................
1219 Int
1220 PAF_ASIT_initPhaseAlgKey(
1221 const PAF_ASIT_Params *pP,
1222 const PAF_ASIT_Patchs *pQ,
1223 PAF_ASIT_Config *pC
1224 )
1225 {
1226 PAF_AST_Config *pAstCfg;
1227 Int as; /* Audio Stream Number (1, 2, etc.) */
1230 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1231 as = pAstCfg->as;
1232 (void)as; // clear compiler warning in case not used with tracing disabled
1234 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1236 #if 0 // FL: slave
1237 for (z=DECODE1; z < DECODEN; z++)
1238 {
1239 for (s=0; s < pP->pDecAlgKey->length; s++)
1240 {
1241 if ((pP->pDecAlgKey->code[s].full != 0) &&
1242 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1243 {
1244 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1245 /* Cast in interface, for now --Kurt */
1246 }
1247 else
1248 {
1249 pC->xDec[z].decAlg[s] = NULL;
1250 }
1251 }
1252 }
1253 #endif
1255 return 0;
1256 } //PAF_ASIT_initPhaseAlgKey
1258 // -----------------------------------------------------------------------------
1259 // ASIT Initialization Function - I/O Devices
1260 //
1261 // Name: PAF_ASIT_initPhaseDevice
1262 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1263 // From: audioStream1Task or equivalent
1264 // Uses: See code.
1265 // States: x
1266 // Return: 0 on success.
1267 // Source code line number on device allocation failure.
1268 // Trace: Message Log "trace" in Debug Project Configuration reports:
1269 // * State information as per parent.
1270 // * Memory allocation errors.
1271 //
1272 Int
1273 PAF_ASIT_initPhaseDevice(
1274 const PAF_ASIT_Params *pP,
1275 const PAF_ASIT_Patchs *pQ,
1276 PAF_ASIT_Config *pC
1277 )
1278 {
1279 PAF_AST_Config *pAstCfg;
1280 Int as; /* Audio Stream Number (1, 2, etc.) */
1281 Int z; /* input/output counter */
1282 PAF_SIO_IALG_Obj *pObj;
1283 PAF_SIO_IALG_Config *pAlgConfig;
1284 PAF_IALG_Config pafAlgConfig;
1287 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1288 as = pAstCfg->as;
1289 (void)as; // clear compiler warning in case not used with tracing disabled
1291 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1293 if (pP->fxns->bufMemPrint)
1294 {
1295 PAF_ALG_setup (&pafAlgConfig,
1296 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1297 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1298 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1299 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1300 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1301 HEAP_CLEAR);
1302 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1303 }
1305 for (z=INPUT1; z < INPUTN; z++)
1306 {
1307 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1309 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1310 pAlgConfig = &pObj->config;
1312 pAstCfg->xInp[z].hRxSio = NULL;
1314 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1315 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1316 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1317 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1318 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1319 pConfig->sizeofElement = 2;
1320 pConfig->precision = 16;
1322 if (pP->fxns->bufMemPrint)
1323 {
1324 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1325 }
1326 }
1328 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1330 return 0;
1331 } //PAF_ASIT_initPhaseDevice
1333 // -----------------------------------------------------------------------------
1334 // ASIT Initialization Function - Decoder Output Circular Buffer
1335 //
1336 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1337 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1338 // From: audioStream1Task or equivalent
1339 // Uses: See code.
1340 // States: x
1341 // Return: 0 on success.
1342 // Source code line number on device allocation failure.
1343 // Trace: Message Log "trace" in Debug Project Configuration reports:
1344 // * State information as per parent.
1345 // * Memory allocation errors.
1346 //
1347 Int
1348 PAF_ASIT_initPhaseDecOpCircBuf(
1349 const PAF_ASIT_Params *pP,
1350 const PAF_ASIT_Patchs *pQ,
1351 PAF_ASIT_Config *pC
1352 )
1353 {
1354 PAF_AST_Config *pAstCfg;
1355 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1356 Int as; /* Audio Stream Number (1, 2, etc.) */
1357 Int zMS;
1358 Int z; /* decode counter */
1359 Int errno; /* error number */
1360 Error_Block eb;
1361 Int i;
1363 // FL: (***)revisit
1364 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1365 as = pAstCfg->as;
1366 zMS = pAstCfg->masterStr;
1368 /* Decode output circular buffer memory */
1369 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1370 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1371 {
1372 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1373 SW_BREAKPOINT;
1374 return __LINE__;
1375 }
1376 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1377 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1378 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1380 for (z=DECODE1; z < DECODEN; z++)
1381 {
1382 pCb = &pAstCfg->xDecOpCb[z];
1384 // allocate audio frame circular buffer
1385 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1386 {
1387 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1388 SW_BREAKPOINT;
1389 }
1390 // allocate audio frame PCM sample pointer array
1391 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1392 {
1393 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)))
1394 {
1395 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1396 SW_BREAKPOINT;
1397 }
1398 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)))
1399 {
1400 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1401 SW_BREAKPOINT;
1402 }
1403 }
1404 // allocate PCM sample buffer
1405 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1406 {
1407 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1408 SW_BREAKPOINT;
1409 }
1410 pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1411 // allocate Metadata buffers //QIN
1412 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)))
1413 {
1414 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1415 SW_BREAKPOINT;
1416 }
1417 pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1418 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1419 // Initialize decoder output circular buffer for PCM
1420 errno = cbInit(pCb);
1421 if (errno)
1422 {
1423 SW_BREAKPOINT; // FL: debug
1424 return errno;
1425 }
1426 }
1428 return 0;
1429 } //PAF_ASIT_initPhaseDecOpCircBuf
1432 #if 0
1433 // -----------------------------------------------------------------------------
1434 // AST Processing Function - Pass-Through Processing
1435 //
1436 // Name: PAF_AST_passProcessing
1437 // Purpose: Audio Stream Task Function for processing audio data as a
1438 // pass-through from the input driver to the output driver
1439 // for development and testing.
1440 // From: audioStream1Task or equivalent
1441 // Uses: See code.
1442 // States: x
1443 // Return: Error number in standard form (0 on success).
1444 // Trace: Message Log "trace" in Debug Project Configuration reports:
1445 // * State information on initialization.
1446 // * State information on processing.
1447 //
1449 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1450 /* Pass Processing is often omitted from builds to save memory, */
1451 /* and CODE_SECTION/clink constructs facilitate this omission. */
1453 Int
1454 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1455 {
1456 Int z; /* input/output counter */
1457 Int errno = 0; /* error number */
1458 Int getVal;
1459 Int rxNumChan, txNumChan;
1460 Int first;
1461 Int zMD = pC->masterDec;
1462 Int zMI = pP->zone.master;
1465 #ifndef __TI_EABI__
1466 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1467 #endif
1469 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1471 //
1472 // Determine that receive/transmit channels are compatible
1473 //
1475 // Can handle handle only master input
1476 for (z=INPUT1; z < INPUTN; z++) {
1477 if (z != zMI && pC->xInp[z].hRxSio)
1478 return (ASPERR_PASS + 0x01);
1479 }
1481 /* Number of receive/transmit channels */
1483 if (! pC->xInp[zMI].hRxSio)
1484 return (ASPERR_PASS + 0x11);
1485 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1486 return (ASPERR_PASS + 0x12);
1487 if (rxNumChan > NUM_TX_CHAN(zMI))
1488 return (ASPERR_PASS + 0x13);
1490 for (z=OUTPUT1; z < OUTPUTN; z++) {
1491 if (! pC->xOut[zMI].hTxSio)
1492 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1493 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1494 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1495 if (txNumChan > NUM_TX_CHAN(zMI))
1496 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1497 }
1499 //
1500 // Set up receive/transmit
1501 //
1503 SIO_idle (pC->xInp[zMI].hRxSio);
1504 for (z=OUTPUT1; z < OUTPUTN; z++) {
1505 if(SIO_idle (pC->xOut[z].hTxSio))
1506 return ASPERR_IDLE;
1507 }
1509 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1510 return (ASPERR_PASS + 0x14);
1512 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1513 return (ASPERR_PASS + 0x15);
1515 for (z=OUTPUT1; z < OUTPUTN; z++)
1516 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1518 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1519 return ASPERR_PASS + 0x16;
1521 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1522 return ASPERR_PASS + 0x17;
1524 //
1525 // Receive and transmit the data in single-frame buffers
1526 //
1528 first = 1;
1529 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1530 PAF_OutBufConfig *pOutBuf;
1531 PAF_InpBufConfig *pInpBuf;
1533 if (first) {
1534 first = 0;
1536 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1538 for (z=OUTPUT1; z < OUTPUTN; z++) {
1539 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1540 if (getVal > 0) {
1541 errno = ASPERR_ISSUE;
1542 break;
1543 }
1544 else if (getVal < 0) {
1545 errno = -getVal;
1546 break;
1547 }
1549 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1550 return (getVal & 0xff) | ASPERR_MUTE;
1551 }
1552 if (errno)
1553 break;
1555 }
1557 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1558 if (getVal > 0) {
1559 errno = ASPERR_ISSUE;
1560 break;
1561 }
1563 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1565 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1566 if (getVal < 0) {
1567 errno = -getVal;
1568 break;
1569 }
1571 for (z=OUTPUT1; z < OUTPUTN; z++) {
1572 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1573 if (getVal < 0) {
1574 errno = -getVal;
1575 break;
1576 }
1577 }
1578 if( errno )
1579 break;
1581 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1583 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1584 break;
1586 for (z=OUTPUT1; z < OUTPUTN; z++) {
1587 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1588 if (getVal > 0) {
1589 errno = ASPERR_ISSUE;
1590 break;
1591 }
1592 else if (getVal < 0) {
1593 errno = -getVal;
1594 break;
1595 }
1596 }
1597 if( errno )
1598 break;
1599 }
1601 //
1602 // Close down receive/transmit
1603 //
1605 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1607 for (z=OUTPUT1; z < OUTPUTN; z++) {
1608 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1609 if (! errno)
1610 errno = (getVal & 0xff) | ASPERR_MUTE;
1611 /* convert to sensical errno */
1612 }
1613 }
1615 SIO_idle (pC->xInp[zMI].hRxSio);
1616 for (z=OUTPUT1; z < OUTPUTN; z++)
1617 SIO_idle (pC->xOut[z].hTxSio);
1619 return errno;
1621 } //PAF_AST_passProcessing
1622 #endif // #if 0
1624 #if 0
1625 // -----------------------------------------------------------------------------
1626 // AST Processing Function Helper - Pass-Through Processing Patch Point
1627 //
1628 // Name: PAF_AST_passProcessingCopy
1629 // Purpose: Pass-Through Processing Function for copying audio data
1630 // from the input buffer to the output buffer.
1631 // From: AST Parameter Function -> passProcessing
1632 // Uses: See code.
1633 // States: x
1634 // Return: Error number in standard form (0 on success).
1635 // Trace: Message Log "trace" in Debug Project Configuration reports:
1636 // x
1637 //
1639 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1640 /* Pass Processing is often omitted from builds to save memory, */
1641 /* and CODE_SECTION/clink constructs facilitate this omission. */
1643 Int
1644 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1645 {
1646 Int z; /* output counter */
1647 Int errno; /* error number */
1648 Int i;
1649 Int rxNumChan, txNumChan;
1650 Int zMI = pP->zone.master;
1653 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1655 // Copy data from input channels to output channels one of two ways:
1657 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1658 return (ASPERR_PASS + 0x12);
1660 for (z=OUTPUT1; z < OUTPUTN; z++) {
1661 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1662 return (ASPERR_PASS + 0x22);
1664 if( txNumChan <= rxNumChan ) {
1666 // Copy one to one, ignoring later rx channels as needed.
1668 for( i=0; i < txNumChan; i++ ) {
1669 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1670 if( errno )
1671 return errno;
1672 }
1673 }
1674 else {
1676 // Copy one to many, repeating earlier rx channels as needed.
1678 Int from, to;
1680 from = 0;
1681 to = 0;
1682 while( to < txNumChan ) {
1683 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1684 if( errno )
1685 return errno;
1687 from++;
1688 to++;
1689 if( from == rxNumChan )
1690 from = 0;
1691 }
1692 }
1693 }
1695 return 0;
1696 } //PAF_AST_passProcessingCopy
1697 #endif // #if 0
1699 // -----------------------------------------------------------------------------
1700 // ASIT Processing Function - Auto Processing
1701 //
1702 // Name: PAF_ASIT_autoProcessing
1703 // Purpose: Audio Stream Input Task Function for processing audio data to
1704 // determine the input type without output.
1705 // From: audioStream1Task or equivalent
1706 // Uses: See code.
1707 // States: x
1708 // Return: Error number in standard or SIO form (0 on success).
1709 // Trace: Message Log "trace" in Debug Project Configuration reports:
1710 // * State information on initialization.
1711 //
1713 #define DECSIOMAP(X) \
1714 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1716 Int
1717 PAF_ASIT_autoProcessing(
1718 const PAF_ASIT_Params *pP,
1719 const PAF_ASIT_Patchs *pQ,
1720 PAF_ASIT_Config *pC,
1721 Int inputTypeSelect,
1722 ALG_Handle pcmAlgMaster
1723 )
1724 {
1725 PAF_AST_Config *pAstCfg;
1726 Int as; /* Audio Stream Number (1, 2, etc.) */
1727 Int errno = 0; /* error number */
1728 Int nbytes;
1729 Int frameLength;
1730 Int zMD;
1731 Int zMI;
1732 Int zMS;
1734 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1735 as = pAstCfg->as;
1736 zMD = pAstCfg->masterDec;
1737 zMS = pAstCfg->masterStr;
1738 zMI = pP->zone.master;
1740 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1742 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1743 PAF_SIO_CONTROL_SET_SOURCESELECT,
1744 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1745 {
1746 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1747 return errno;
1748 }
1749 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1750 // pC->xDec[zMD].decodeStatus.bufferRatio);
1751 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1753 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1754 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1755 {
1756 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1757 errno, ASPERR_AUTO_LENGTH);
1758 return ASPERR_AUTO_LENGTH;
1759 }
1761 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1762 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1763 PAF_SIO_REQUEST_SYNC))
1764 {
1765 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1766 errno, ASPERR_ISSUE);
1767 return ASPERR_ISSUE;
1768 }
1770 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1772 // all of the sync scan work is done in this call. If the error returned
1773 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1774 // error so we mask it off.
1775 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1776 if (nbytes == -DIBERR_SYNC)
1777 {
1778 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1779 return 0;
1780 }
1781 if (nbytes != sizeof(PAF_InpBufConfig))
1782 {
1783 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1784 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1785 return ASPERR_RECLAIM;
1786 }
1787 if (errno)
1788 {
1789 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1790 }
1791 return errno;
1792 } //PAF_ASIT_autoProcessing
1794 // -----------------------------------------------------------------------------
1795 // ASIT Processing Function - Decode Processing
1796 //
1797 // Name: PAF_ASIT_decodeProcessing
1798 // Purpose: Audio Stream Input Task Function for processing audio data.
1799 // From: audioStream1Task or equivalent
1800 // Uses: See code.
1801 // States: x
1802 // Return: Error number in standard form (0 on success).
1803 // Trace: Message Log "trace" in Debug Project Configuration reports:
1804 // * State information on initialization (via children).
1805 // * State information on processing (via children).
1806 // * Decode warnings.
1807 //
1808 // When "writeDECModeContinuous" is used for zMI input/decode:
1809 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1810 // (a) if "writeDECCommandRestart" is used
1811 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1812 // (b) if "writeDECSourceSelectNone" is used
1813 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1814 // (c) if an error occurs in
1815 // INIT
1816 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1817 // -> PAF_AST_decodeCont(): "Await slave inputs"
1818 // STREAM (errno |= PAF_COMPONENT_ASP)
1819 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1820 // [ the latter errors lead to "switch_break:"
1821 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1822 //
1823 // [ Notably, in FINAL ("frame-finalization state")
1824 // -> PAF_AST_decodeFinalTest() is *not* called,
1825 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1826 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1827 //
1828 // States in which error can't occur:
1829 // AGAIN ("subsequent initial state")
1830 //
1831 // States in which (some) errors must be handled:
1832 // INFO1 ("first frame state")
1833 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1834 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1835 // ?*? but what about ASPERR_RESYNC from same call ?*?
1836 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1837 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1838 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1839 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1840 // - enc->fxns->info()
1841 // - pP->fxns->setCheckRateX()
1842 // - pP->fxns->startOutput()
1843 // - "Start slave inputs if necessary"
1844 // INFO2 ("subsequent frame state")
1845 // -> PAF_AST_decodeInfo(): (see above)
1846 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1847 // - pP->fxns->setCheckRateX()
1848 // TIME ("timing state")
1849 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1850 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1851 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1852 // (*OK* don't try to recover from this*)
1853 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1854 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1855 // possibly in PAF_AST_decodeProcessing() itself **
1856 // DECODE ("decode state")
1857 // -> PAF_AST_decodeDecode(): pass on error from
1858 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1859 // - dec->fxns->reset()
1860 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1861 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
1862 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1863 Int
1864 PAF_ASIT_decodeProcessing(
1865 const PAF_ASIT_Params *pP,
1866 const PAF_ASIT_Patchs *pQ,
1867 PAF_ASIT_Config *pC,
1868 Int sourceSelect
1869 )
1870 {
1871 PAF_AST_Config *pAstCfg;
1872 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1873 Int z; /* decode counter */
1874 Int errno; /* error number */
1875 Int getVal;
1876 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1877 ALG_Handle alg[DECODEN_MAX];
1878 Int zMD;
1879 Int zMS;
1880 Int size;
1881 //PAF_InpBufConfig *pIpBufConfig;
1882 Int frame; // decoder input frame count
1883 Int block; // (***) FL: formerly -- decoder output block count / input frame
1886 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1887 zMD = pAstCfg->masterDec;
1888 zMS = pAstCfg->masterStr;
1890 for (z=DECODE1; z < DECODEN; z++)
1891 {
1892 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
1893 }
1894 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1896 //
1897 // Receive and process the data in single-frame buffers
1898 //
1900 state = INIT;
1901 errno = 0; /* error number */
1903 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
1905 for (;;)
1906 {
1907 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
1908 {
1909 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1910 state = QUIT;
1911 }
1913 // Process commands (decode)
1914 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
1915 {
1916 if (state != INIT) // no need to restart/abort if not yet started
1917 {
1918 if (getVal == ASPERR_QUIT)
1919 {
1920 state = QUIT;
1921 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1922 }
1923 else if (getVal == ASPERR_ABORT)
1924 {
1925 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1926 return getVal;
1927 }
1928 else
1929 {
1930 /* ignore */;
1931 }
1932 }
1933 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
1934 }
1936 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
1937 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
1939 // Process state (decode)
1940 switch (state)
1941 {
1942 case INIT: // initial state
1943 gAsipInitCnt++;
1944 Log_info0("TaskAsip: state=INIT");
1946 // (***) FL: revisit
1947 #if 1 // status for shared beta units can change (e.g. at-boot or alpha)
1948 // write back Status structures for shared Beta Units
1949 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1950 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1951 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1952 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1953 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1954 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1955 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
1956 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
1957 Cache_wait();
1958 #endif
1959 #if 0
1960 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1961 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1962 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1963 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1964 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1965 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1966 //Cache_wait();
1967 #endif
1969 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1970 {
1971 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1972 break;
1973 }
1975 #if 1
1976 // (***) FL: revisit
1977 // invalidate Status structures for shared Beta Units
1978 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1979 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1980 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1981 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1982 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1983 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1984 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
1985 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
1986 Cache_wait();
1987 #endif
1989 frame = 0;
1990 block = 0;
1992 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
1993 state = INFO1;
1994 continue;
1996 case INFO1: // first frame state
1997 gAsipInfo1Cnt++;
1998 Log_info0("TaskAsip: state=INFO1");
2000 #if 0
2001 //// (***) FL: revisit
2002 //// write back Inp configuration
2003 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2004 //// write back input data
2005 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2006 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2007 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2008 //// write back Dec configuration
2009 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2010 //Cache_wait();
2011 #endif
2013 // Establish primary timing
2014 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2015 {
2016 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2017 break;
2018 }
2020 #if 0
2021 //// (***) FL: revisit
2022 //// invalidate Dec configuration
2023 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2024 //Cache_wait();
2025 #endif
2027 // Don't start decode until major access unit is found.
2028 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
2029 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
2030 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2031 (pAstCfg->xStr[zMS].pAudioFrame->sampleRate == PAF_SAMPLERATE_UNKNOWN))
2032 {
2033 Int z;
2034 for (z=DECODE1; z < DECODEN; z++)
2035 {
2036 Int zI = pP->inputsFromDecodes[z];
2037 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2038 {
2039 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2040 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2041 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2042 {
2043 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2044 return (ASPERR_ISSUE);
2045 }
2046 }
2047 }
2048 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2049 frame++;
2050 state = INFO1;
2051 continue;
2052 }
2053 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2055 // Establish secondary timing
2056 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2057 {
2058 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2059 break;
2060 }
2062 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2063 state = DECODE;
2064 continue;
2066 case INFO2: // subsequent frame state
2067 gAsipInfo2Cnt++;
2068 Log_info0("TaskAsip: state=INFO2");
2070 #if 0
2071 //// (***) FL: revisit
2072 //// write back Inp configuration
2073 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2074 //// write back input data
2075 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2076 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2077 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2078 //// write back Dec configuration
2079 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2080 //Cache_wait();
2081 #endif
2083 // Establish primary timing
2084 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2085 {
2086 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2087 gAsipInfo2_PrimaryErrCnt++;
2088 break;
2089 }
2091 #if 0
2092 //// (***) FL: revisit
2093 //// invalidate Dec configuration
2094 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2095 //Cache_wait();
2096 #endif
2098 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2099 {
2100 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2101 gAsipInfo2_ErrCnt++;
2102 break;
2103 }
2105 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2106 state = DECODE;
2107 continue;
2109 case DECODE: // decode state
2110 gAsipDecodeCnt++;
2111 Log_info0("TaskAsip: state=DECODE");
2113 #if 0
2114 //// (***) FL: revisit
2115 //// write back Dec configuration
2116 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2117 //Cache_wait();
2118 #endif
2120 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2121 {
2122 gAsipDecodeErrCnt++;
2123 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2124 break;
2125 }
2127 #if 0
2128 //// (***) FL: revisit
2129 //// invalidate Dec configuration
2130 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2131 //Cache_wait();
2132 #endif
2134 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2135 state = FINAL;
2136 continue;
2138 case FINAL: // frame-finalization state
2139 gAsipFinalCnt++;
2140 Log_info0("TaskAsip: state=FINAL");
2142 // Check for final frame, and if indicated:
2143 // - Exit state machine to "complete" processing.
2144 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2145 {
2146 break;
2147 }
2149 frame++;
2150 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2151 state = INFO2;
2152 continue;
2154 case QUIT: // exit state
2155 gAsipQuitCnt++;
2156 Log_info0("TaskAsip: state=QUIT");
2158 // Quit:
2159 // - Set error number registers.
2160 // - Exit state machine to "decode complete" processing.
2161 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2162 errno = ASPERR_QUIT;
2163 break;
2165 default: // unknown state
2167 // Unknown:
2168 // - Set error number registers.
2169 // - Exit state machine to "decode complete" processing.
2171 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2172 errno = ASPERR_UNKNOWNSTATE;
2173 break;
2175 } // End of switch (state).
2177 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2178 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2179 {
2180 /* ignored? */;
2181 }
2183 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2185 return errno;
2186 } // End of for (;;) to Receive, process, and transmit the data.
2187 } //PAF_ASIT_decodeProcessing
2189 // -----------------------------------------------------------------------------
2190 // ASIT Decoding Function - Decode Command Processing
2191 //
2192 // Name: PAF_ASIT_decodeCommand
2193 // Purpose: Decoding Function for processing Decode Commands.
2194 // From: AST Parameter Function -> decodeProcessing
2195 // Uses: See code.
2196 // States: x
2197 // Return: Error number in standard form (0 on success).
2198 // Trace: Message Log "trace" in Debug Project Configuration reports:
2199 // * Command execution.
2200 //
2202 Int
2203 PAF_ASIT_decodeCommand(
2204 const PAF_ASIT_Params *pP,
2205 const PAF_ASIT_Patchs *pQ,
2206 PAF_ASIT_Config *pC
2207 )
2208 {
2209 PAF_AST_Config *pAstCfg;
2210 Int as; /* Audio Stream Number (1, 2, etc.) */
2211 Int z; /* decode counter */
2212 Int zS;
2214 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2215 as = pAstCfg->as;
2217 for (z=DECODE1; z < DECODEN; z++)
2218 {
2219 zS = pP->streamsFromDecodes[z];
2220 if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2221 {
2222 switch (pAstCfg->xDec[z].decodeStatus.command2)
2223 {
2224 case 0: // command none - process
2225 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2226 break;
2227 case 1: // command abort - leave now
2228 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2229 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2230 return (ASPERR_ABORT);
2231 case 2: // command restart - leave later
2232 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2233 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2234 return (ASPERR_QUIT);
2235 default: // command unknown - ignore
2236 break;
2237 }
2238 }
2239 }
2241 return 0;
2242 } //PAF_ASIT_decodeCommand
2244 // -----------------------------------------------------------------------------
2245 // ASIT Decoding Function - Reinitialization of Decode
2246 //
2247 // Name: PAF_ASIT_decodeInit
2248 // Purpose: Decoding Function for reinitializing the decoding process.
2249 // From: AST Parameter Function -> decodeProcessing
2250 // Uses: See code.
2251 // States: x
2252 // Return: Error number in standard or SIO form (0 on success).
2253 // Trace: Message Log "trace" in Debug Project Configuration reports:
2254 // * State information as per parent.
2255 //
2256 Int
2257 PAF_ASIT_decodeInit(
2258 const PAF_ASIT_Params *pP,
2259 const PAF_ASIT_Patchs *pQ,
2260 PAF_ASIT_Config *pC,
2261 Int sourceSelect
2262 )
2263 {
2264 PAF_AST_Config *pAstCfg;
2265 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2266 Int as; /* Audio Stream Number (1, 2, etc.) */
2267 Int z; /* decode/encode counter */
2268 Int errno; /* error number */
2269 Int zI, zS;
2270 Int zMD;
2271 Int zMI;
2272 ASP_Msg* pAspMsg; /* Messaging */
2273 Int argIdx;
2274 Int decErrno;
2275 Int status;
2277 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2278 as = pAstCfg->as;
2279 zMD = pAstCfg->masterDec;
2280 zMI = pP->zone.master;
2281 (void)as; // clear compiler warning in case not used with tracing disabled
2283 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2285 // reset frameCount
2286 for (z=DECODE1; z < DECODEN; z++)
2287 {
2288 if (pAstCfg->xDec[z].decodeStatus.mode)
2289 {
2290 pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2291 }
2292 }
2294 for (z=DECODE1; z < DECODEN; z++)
2295 {
2296 zI = pP->inputsFromDecodes[z];
2297 zS = pP->streamsFromDecodes[z];
2298 (void)zS; // clear compiler warning in case not used with tracing disabled
2299 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2300 {
2301 Uns gear;
2302 Int frameLength;
2303 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2305 // write back Dec configuration
2306 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2307 Cache_wait();
2309 // FL: send dec activate message to slave
2310 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2311 if (pAspMsg == NULL)
2312 {
2313 TRACE_TERSE0("MessageQ_alloc() failure.");
2314 SW_BREAKPOINT; // temporary
2315 return -1; // temporary
2316 }
2317 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2318 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2319 pAspMsg->procId = hAspMsgMaster->masterProcId;
2320 pAspMsg->expectResp = TRUE;
2321 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2322 argIdx = 0; // set decIdx (zone index)
2323 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2324 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2325 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2326 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2327 if (status != MessageQ_S_SUCCESS)
2328 {
2329 SW_BREAKPOINT;
2330 }
2331 // wait for dec activate complete message from slave
2332 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2333 if (status != MessageQ_S_SUCCESS)
2334 {
2335 TRACE_TERSE0("MessageQ_get() failure.");
2336 SW_BREAKPOINT; // temporary
2337 return -1; // temporary
2338 }
2339 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2340 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2341 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2342 {
2343 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2344 SW_BREAKPOINT; // temporary
2345 return -1; // temporary
2346 }
2347 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2348 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2349 // free the message
2350 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2351 if (status != MessageQ_S_SUCCESS)
2352 {
2353 SW_BREAKPOINT;
2354 }
2356 #if 0 // FL: decoder activate call, slave
2357 if (decAlg[z]->fxns->algActivate)
2358 decAlg[z]->fxns->algActivate (decAlg[z]);
2359 #endif
2361 // FL: send dec reset message to slave
2362 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2363 if (pAspMsg == NULL)
2364 {
2365 TRACE_TERSE0("MessageQ_alloc() failure.");
2366 SW_BREAKPOINT; // temporary
2367 return -1; // temporary
2368 }
2369 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2370 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2371 pAspMsg->procId = hAspMsgMaster->masterProcId;
2372 pAspMsg->expectResp = TRUE;
2373 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2374 argIdx = 0; // set decIdx
2375 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2376 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2377 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2378 // wait for dec reset complete message from slave
2379 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2380 if (status != MessageQ_S_SUCCESS)
2381 {
2382 SW_BREAKPOINT;
2383 }
2384 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2385 if (status != MessageQ_S_SUCCESS)
2386 {
2387 TRACE_TERSE0("MessageQ_get() failure.");
2388 SW_BREAKPOINT; // temporary
2389 return -1; // temporary
2390 }
2391 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2392 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2393 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2394 {
2395 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2396 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2397 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2399 argIdx = 0; // get decErrno
2400 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2401 if (decErrno != 0)
2402 {
2403 return decErrno;
2404 }
2405 }
2406 else
2407 {
2408 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2409 SW_BREAKPOINT; // temporary
2410 return -1; // temporary
2411 }
2412 // free the message
2413 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2414 if (status != MessageQ_S_SUCCESS)
2415 {
2416 SW_BREAKPOINT;
2417 }
2419 // (***) FL: revisit
2420 // invalidate Dec configuration
2421 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2422 Cache_wait();
2424 #if 0 // FL: decoder reset call, slave
2425 if (dec->fxns->reset
2426 && (errno = dec->fxns->reset (dec, NULL,
2427 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2428 return errno;
2429 #endif
2431 gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2432 pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2434 #if 0 // FL: change handle to decIdx (zone index)
2435 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2436 FRAMELENGTH,
2437 pC->xDec[z].decodeStatus.bufferRatio);
2438 #endif
2439 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2440 frameLength = pP->fxns->computeFrameLength(z,
2441 FRAMELENGTH,
2442 pC->xDec[z].decodeStatus.bufferRatio);
2443 #else
2444 if (sourceSelect == PAF_SOURCE_PCM)
2445 {
2446 frameLength = 256;
2447 }
2448 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2449 {
2450 frameLength = 1536;
2451 }
2452 else if (sourceSelect == PAF_SOURCE_THD)
2453 {
2454 frameLength = 1536; //QIN FIX ME
2455 }
2456 else
2457 {
2458 frameLength = 256;
2459 }
2460 #endif
2462 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2463 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2464 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2466 // (***) FL: revisit. Count samples for DDP.
2467 // Add framework frame length and running sample count to decoder control.
2468 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2469 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2471 // Initialize decoder output circular buffer for selected source
2472 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2473 if (errno)
2474 {
2475 SW_BREAKPOINT; // FL: debug
2476 return errno;
2477 }
2478 // FL: debug
2479 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2481 if (z != zMD)
2482 {
2483 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2484 {
2485 return errno;
2486 }
2487 }
2489 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2490 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2491 {
2492 return errno;
2493 }
2494 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2495 frameLength))
2496 {
2497 return errno;
2498 }
2499 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2500 &pAstCfg->xInp[zI].inpBufConfig))
2501 {
2502 return errno;
2503 }
2504 }
2505 }
2507 if (pAstCfg->xInp[zMI].hRxSio)
2508 {
2509 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2510 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2511 if (errno)
2512 {
2513 return errno;
2514 }
2515 }
2517 return 0;
2518 } //PAF_AST_decodeInit
2520 // -----------------------------------------------------------------------------
2521 // ASIT Decoding Function - Info Processing, Common
2522 //
2523 // Name: PAF_ASIT_decodeInfo
2524 // Purpose: Decoding Function for processing information in a manner that
2525 // is common for both initial and subsequent frames of input data.
2526 // From: AST Parameter Function -> decodeProcessing
2527 // Uses: See code.
2528 // States: x
2529 // Return: Error number in standard form (0 on success).
2530 // Trace: Message Log "trace" in Debug Project Configuration reports:
2531 // * State information as per parent.
2532 //
2533 Int
2534 PAF_ASIT_decodeInfo(
2535 const PAF_ASIT_Params *pP,
2536 const PAF_ASIT_Patchs *pQ,
2537 PAF_ASIT_Config *pC,
2538 Int frame,
2539 Int block
2540 )
2541 {
2542 PAF_AST_Config *pAstCfg;
2543 Int as; /* Audio Stream Number (1, 2, etc.) */
2544 Int z; /* input/decode/stream counter */
2545 Int errno; /* error number */
2546 Int sioErr; /* error number, SIO */
2547 Int zD, zI, zS, zX;
2548 Int zMD;
2549 Int zMI;
2550 Int zMS;
2551 UInt32 curTime;
2552 ASP_Msg *pAspMsg; /* Messaging */
2553 Int argIdx;
2554 Int status;
2555 // FL: revisit
2556 Int size;
2557 PAF_InpBufConfig *pIpBufConfig;
2559 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2560 as = pAstCfg->as;
2561 zMD = pAstCfg->masterDec;
2562 zMS = pAstCfg->masterStr;
2563 zMI = pP->zone.master;
2564 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2566 // Set decode control: sample rate, emphasis
2567 for (z=INPUT1; z < INPUTN; z++)
2568 {
2569 zD = z;
2570 for (zX = DECODE1; zX < DECODEN; zX++)
2571 {
2572 if (pP->inputsFromDecodes[zX] == z)
2573 {
2574 zD = zX;
2575 break;
2576 }
2577 }
2579 if (pAstCfg->xInp[z].hRxSio)
2580 {
2581 //determine associated decoder
2582 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2583 pAstCfg->xDec[zD].decodeControl.sampleRate)
2584 {
2585 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2586 {
2587 pAstCfg->xDec[zD].decodeControl.sampleRate =
2588 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2589 }
2590 else
2591 {
2592 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2593 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2594 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2595 pAstCfg->xDec[zD].decodeControl.sampleRate);
2596 // return (ASPERR_INFO_RATECHANGE);
2597 }
2598 }
2599 pAstCfg->xDec[zD].decodeControl.emphasis =
2600 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2601 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2602 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2603 }
2604 else
2605 {
2606 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2607 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2608 }
2609 }
2611 // Wait for info input
2612 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2613 if (pAstCfg->xInp[zMI].hRxSio)
2614 {
2615 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2616 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2617 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2618 {
2619 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2620 return ASPERR_RECLAIM;
2621 }
2623 // FL: debug, capture input buffer AFTER cache_inv
2624 //Cache_inv (pAstCfg->xInp[zMI].pInpBuf->pntr.pSmInt, (pAstCfg->xInp[zMI].pInpBuf->frameLength * pAstCfg->xInp[zMI].pInpBuf->sizeofElement), Cache_Type_ALLD, 0);
2625 //Cache_wait();
2627 capIb(pAstCfg->xInp[zMI].pInpBuf);
2628 gcapIb_cnt++;
2630 //
2631 // Simulate Rx SIO_reclaim() pend
2632 //
2633 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2634 gTaskAsipCnt++;
2635 curTime = Clock_getTicks();
2636 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2637 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2638 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2639 } //pC->xInp[zMI].hRxSio
2641 // Decode info
2642 for (z=DECODE1; z < DECODEN; z++)
2643 {
2644 zI = pP->inputsFromDecodes[z];
2645 zS = pP->streamsFromDecodes[z];
2646 (void)zS; // clear compiler warning in case not used with tracing disabled
2647 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2648 {
2649 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2651 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2652 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2653 {
2654 TRACE_TERSE1("return error errno 0x%x.", errno);
2655 return errno;
2656 }
2658 #if 1
2659 // (***) FL: revisit
2660 // write back Inp configuration
2661 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2662 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2663 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2664 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2665 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2666 // write back Dec configuration
2667 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2668 Cache_wait();
2669 #endif
2671 // FL: send info message to slave
2672 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2673 if (pAspMsg == NULL)
2674 {
2675 TRACE_TERSE0("MessageQ_alloc() failure.");
2676 SW_BREAKPOINT; // temporary
2677 return -1; // temporary
2678 }
2679 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2680 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
2681 pAspMsg->procId = hAspMsgMaster->masterProcId;
2682 pAspMsg->expectResp = TRUE;
2683 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2684 argIdx = 0; // set decIdx
2685 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2686 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2687 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2688 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
2689 if (status != MessageQ_S_SUCCESS)
2690 {
2691 SW_BREAKPOINT;
2692 }
2693 // wait for dec info complete message from slave -- temporary
2694 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2695 if (status != MessageQ_S_SUCCESS)
2696 {
2697 TRACE_TERSE0("MessageQ_get() failure.");
2698 SW_BREAKPOINT;
2699 return -1; // temporary
2700 }
2701 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2702 (pAspMsg->cmd != ASP_MASTER_DEC_INFO_DONE) ||
2703 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2704 {
2705 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2706 SW_BREAKPOINT; // temporary
2707 }
2708 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2709 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2710 // free the message
2711 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2712 if (status != MessageQ_S_SUCCESS)
2713 {
2714 SW_BREAKPOINT;
2715 }
2717 #if 1
2718 // (***) FL: revisit
2719 // invalidate Dec configuration
2720 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2721 Cache_wait();
2722 #endif
2724 #if 0 // FL: decoder info call, slave
2725 if (dec->fxns->info
2726 && (errno = dec->fxns->info (dec, NULL,
2727 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2728 #endif
2729 if (errno)
2730 {
2731 TRACE_TERSE1("return error errno 0x%x.", errno);
2732 return errno;
2733 }
2734 // increment decoded frame count
2735 pAstCfg->xDec[z].decodeStatus.frameCount += 1;
2736 }
2737 } // z=DECODE1 to DECODEN
2739 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2740 if (pAstCfg->xDec[zMD].decodeStatus.mode)
2741 {
2742 XDAS_Int8 sourceProgram;
2743 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2744 (Arg)&sourceProgram))
2745 {
2746 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2747 return ASPERR_AUTO_PROGRAM;
2748 }
2749 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
2750 }
2752 // since now decoding update decode status for all enabled decoders
2753 for (z=DECODE1; z < DECODEN; z++)
2754 {
2755 if (pAstCfg->xDec[z].decodeStatus.mode)
2756 {
2757 pAstCfg->xDec[z].decodeStatus.sourceDecode = pAstCfg->xDec[z].decodeStatus.sourceProgram;
2758 if (pAstCfg->xDec[z].decodeStatus.sourceSelect == PAF_SOURCE_SNG)
2759 {
2760 pAstCfg->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_SNG;
2761 }
2762 }
2763 }
2765 #if 0 // FL: ASDT (slave)
2766 // TODO: move this to start of this function so that it doesn't affect IO timing
2767 // Initialize audio frame(s)
2768 // Re-initialize audio frame if there is an associated decode and
2769 // that decode doesn't have a valid input or is turned off
2770 for (z=STREAM1; z < STREAMN; z++)
2771 {
2772 Int reset = 0;
2773 for (zX = DECODE1; zX < DECODEN; zX++)
2774 {
2775 if (pP->streamsFromDecodes[zX] == z)
2776 {
2777 zI = pP->inputsFromDecodes[zX];
2778 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2779 {
2780 reset = 1;
2781 }
2782 }
2783 }
2784 if (reset)
2785 {
2786 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2787 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2788 }
2789 else
2790 {
2791 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2792 }
2793 }
2794 #endif
2796 return 0;
2797 } //PAF_ASIT_decodeInfo
2799 // -----------------------------------------------------------------------------
2800 // ASIT Decoding Function - Info Processing, Initial
2801 //
2802 // Name: PAF_ASIT_decodeInfo1
2803 // Purpose: Decoding Function for processing information in a manner that
2804 // is unique to initial frames of input data.
2805 // From: AST Parameter Function -> decodeProcessing
2806 // Uses: See code.
2807 // States: x
2808 // Return: Error number in standard or SIO form (0 on success).
2809 // Trace: Message Log "trace" in Debug Project Configuration reports:
2810 // * State information as per parent.
2811 //
2812 Int
2813 PAF_ASIT_decodeInfo1(
2814 const PAF_ASIT_Params *pP,
2815 const PAF_ASIT_Patchs *pQ,
2816 PAF_ASIT_Config *pC,
2817 Int frame,
2818 Int block
2819 )
2820 {
2821 return 0;
2822 } //PAF_ASIT_decodeInfo1
2824 // -----------------------------------------------------------------------------
2825 // AST Decoding Function - Info Processing, Subsequent
2826 //
2827 // Name: PAF_AST_decodeInfo2
2828 // Purpose: Decoding Function for processing information in a manner that
2829 // is unique to frames of input data other than the initial one.
2830 // From: AST Parameter Function -> decodeProcessing
2831 // Uses: See code.
2832 // States: x
2833 // Return: Error number in standard form (0 on success).
2834 // Trace: None.
2835 //
2836 Int
2837 PAF_ASIT_decodeInfo2(
2838 const PAF_ASIT_Params *pP,
2839 const PAF_ASIT_Patchs *pQ,
2840 PAF_ASIT_Config *pC,
2841 Int frame,
2842 Int block
2843 )
2844 {
2845 return 0;
2846 } //PAF_ASIT_decodeInfo2
2848 // -----------------------------------------------------------------------------
2849 // AST Decoding Function - Continuation Processing
2850 //
2851 // Name: PAF_AST_decodeCont
2852 // Purpose: Decoding Function for processing that occurs subsequent to
2853 // information processing but antecedent to timing processing
2854 // for frames of input data other than the initial one.
2855 // From: AST Parameter Function -> decodeProcessing
2856 // Uses: See code.
2857 // States: x
2858 // Return: Error number in standard form (0 on success).
2859 // Trace: Message Log "trace" in Debug Project Configuration reports:
2860 // * State information as per parent.
2861 //
2863 Int
2864 PAF_AST_decodeCont(
2865 const PAF_ASIT_Params *pP,
2866 const PAF_ASIT_Patchs *pQ,
2867 PAF_ASIT_Config *pC,
2868 ALG_Handle decAlg[],
2869 Int frame,
2870 Int block
2871 )
2872 {
2873 PAF_AST_Config *pAstCfg;
2874 Int as; /* Audio Stream Number (1, 2, etc.) */
2875 Int z; /* decode counter */
2876 Int zI, zS;
2877 Int zMD;
2880 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2881 as = pAstCfg->as;
2882 zMD = pAstCfg->masterDec;
2883 (void)as; // clear compiler warning in case not used with tracing disabled
2885 // Await slave inputs
2886 for (z=DECODE1; z < DECODEN; z++) {
2887 zI = pP->inputsFromDecodes[z];
2888 zS = pP->streamsFromDecodes[z];
2889 (void)zS;
2890 if (z == zMD
2891 || ! pAstCfg->xInp[zI].hRxSio
2892 || ! pAstCfg->xDec[z].decodeStatus.mode)
2893 continue;
2894 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2895 if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
2896 != sizeof (pAstCfg->xInp[zI].inpBufConfig))
2897 return (ASPERR_RECLAIM);
2898 }
2900 return 0;
2901 } //PAF_AST_decodeCont
2903 // -----------------------------------------------------------------------------
2904 // ASIT Decoding Function - Decode Processing
2905 //
2906 // Name: PAF_ASIT_decodeDecode
2907 // Purpose: Decoding Function for processing of input data by the
2908 // Decode Algorithm.
2909 // From: AST Parameter Function -> decodeProcessing
2910 // Uses: See code.
2911 // States: x
2912 // Return: Error number in standard form (0 on success).
2913 // Trace: Message Log "trace" in Debug Project Configuration reports:
2914 // * State information as per parent.
2915 //
2916 Int
2917 PAF_ASIT_decodeDecode(
2918 const PAF_ASIT_Params *pP,
2919 const PAF_ASIT_Patchs *pQ,
2920 PAF_ASIT_Config *pC,
2921 Int sourceSelect,
2922 Int frame,
2923 Int block
2924 )
2925 {
2926 PAF_AST_Config *pAstCfg;
2927 Int as; /* Audio Stream Number (1, 2, etc.) */
2928 Int z; /* decode/stream counter */
2929 Int errno; /* error number */
2930 //Int ch;
2931 ASP_Msg *pAspMsg; /* Messaging */
2932 Int argIdx;
2933 Int status;
2934 Int cbErrno;
2935 Int frameLength;
2937 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2938 as = pAstCfg->as;
2939 (void)as; // clear compiler warning in case not used with tracing disabled
2941 #if 0 // FL: slave
2942 // Clear samsiz for all channels - MID 208.
2943 for (z=STREAM1; z < STREAMN; z++)
2944 {
2945 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
2946 {
2947 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
2948 }
2949 }
2950 #endif
2952 // Decode data
2953 for (z=DECODE1; z < DECODEN; z++)
2954 {
2955 Int zI = pP->inputsFromDecodes[z];
2956 Int zS = pP->streamsFromDecodes[z];
2957 (void)zS; // clear compiler warning in case not used with tracing disabled
2958 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2959 {
2960 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
2962 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
2963 as+zS,
2964 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
2965 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
2967 // FL: debug, capture input buffer
2968 //capIbPcm(pAstCfg->xInp[z].pInpBuf);
2970 // (***) FL: revisit
2971 // write back Dec configuration
2972 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2973 Cache_wait();
2975 // FL: send decode message to slave
2976 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2977 if (pAspMsg == NULL)
2978 {
2979 TRACE_TERSE0("MessageQ_alloc() failure.");
2980 SW_BREAKPOINT; // temporary
2981 return -1; // temporary
2982 }
2983 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2984 pAspMsg->cmd = ASP_SLAVE_DEC_DECODE; /* fill in message payload */
2985 pAspMsg->procId = hAspMsgMaster->masterProcId;
2986 pAspMsg->expectResp = TRUE;
2987 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2988 argIdx = 0; // set decIdx
2989 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2990 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2991 TRACE_MSG1("decIdx=%d", pAspMsg->buf[argIdx]);
2992 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2993 if (status != MessageQ_S_SUCCESS)
2994 {
2995 SW_BREAKPOINT;
2996 }
2997 // wait for decode complete message from slave -- temporary
2998 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2999 if (status != MessageQ_S_SUCCESS)
3000 {
3001 TRACE_TERSE0("MessageQ_get() failure.");
3002 SW_BREAKPOINT; // temporary
3003 return -1; // temporary
3004 }
3005 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
3006 (pAspMsg->cmd == ASP_MASTER_DEC_DECODE_DONE) &&
3007 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3008 {
3009 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3010 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3012 argIdx = 0;
3013 errno = *(Int32 *)&pAspMsg->buf[argIdx];
3014 argIdx += sizeof(Int32);
3015 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
3016 if (cbErrno != 0)
3017 {
3018 TRACE_TERSE1("CB write error=%d", cbErrno);
3019 SW_BREAKPOINT; // temporary
3020 }
3021 }
3022 else
3023 {
3024 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3025 SW_BREAKPOINT; // temporary
3026 }
3027 // free the message
3028 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3029 if (status != MessageQ_S_SUCCESS)
3030 {
3031 SW_BREAKPOINT;
3032 }
3034 // (***) FL: revisit
3035 // invalidate Dec configuration
3036 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3037 Cache_wait();
3039 #if 0 // FL: decoder decode call, slave
3040 if (dec->fxns->decode
3041 && (errno = dec->fxns->decode (dec, NULL,
3042 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
3043 #endif
3044 if (errno)
3045 {
3046 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
3047 return errno;
3048 }
3050 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3051 as_traceChannels(pC, z);
3052 #endif
3054 #if 0 // FL: change handle to decIdx (zone index)
3055 frameLength = pP->fxns->computeFrameLength(decAlg[z],
3056 FRAMELENGTH,
3057 pC->xDec[z].decodeStatus.bufferRatio);
3058 #endif
3059 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
3060 frameLength = pP->fxns->computeFrameLength(z,
3061 FRAMELENGTH,
3062 pC->xDec[z].decodeStatus.bufferRatio);
3063 #else
3064 if (sourceSelect == PAF_SOURCE_PCM)
3065 {
3066 frameLength = 256;
3067 }
3068 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
3069 {
3070 frameLength = 1536;
3071 }
3072 else if (sourceSelect == PAF_SOURCE_THD)
3073 {
3074 frameLength = 1536; //QIN FIX ME
3075 }
3076 else
3077 {
3078 frameLength = 256;
3079 }
3080 #endif
3082 // ............................................................................
3084 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3085 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3086 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3087 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3088 {
3089 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3090 return errno;
3091 }
3093 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3094 if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3095 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3096 PAF_SIO_REQUEST_NEWFRAME))
3097 {
3098 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3099 return (ASPERR_ISSUE);
3100 }
3101 } // hRxSio && decodeStatus.mode
3102 else
3103 {
3104 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3105 }
3106 } // z=DECODE1 to DECODEN
3108 #if 0 // FL: ASDT (slave)
3109 // Set up audio frames not decoded into
3110 // Re-initialize audio frame if there is an assocatiated decode and
3111 // that decode doesn't have a valid input or is turned off
3112 for (z=STREAM1; z < STREAMN; z++)
3113 {
3114 Int zX;
3115 Int reset = 0;
3116 for (zX = DECODE1; zX < DECODEN; zX++)
3117 {
3118 if (pP->streamsFromDecodes[zX] == z)
3119 {
3120 Int zI = pP->inputsFromDecodes[zX];
3121 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3122 reset = 1;
3123 }
3124 }
3125 if (reset)
3126 {
3127 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3128 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3129 }
3130 else
3131 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3132 }
3133 #endif
3135 return 0;
3136 } //PAF_ASIT_decodeDecode
3138 // -----------------------------------------------------------------------------
3139 // ASIT Decoding Function - Frame-Final Processing
3140 //
3141 // Name: PAF_ASIT_decodeFinalTest
3142 // Purpose: Decoding Function for determining whether processing of the
3143 // current frame is complete.
3144 // From: AST Parameter Function -> decodeProcessing
3145 // Uses: See code.
3146 // States: x
3147 // Return: 0 if incomplete, and 1 if complete.
3148 // Trace: None.
3149 //
3151 Int
3152 PAF_ASIT_decodeFinalTest(
3153 const PAF_ASIT_Params *pP,
3154 const PAF_ASIT_Patchs *pQ,
3155 PAF_ASIT_Config *pC,
3156 Int frame,
3157 Int block
3158 )
3159 {
3160 PAF_AST_Config *pAstCfg;
3161 Int zMD;
3162 Int sourceSelect;
3163 Int sourceProgram;
3165 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3166 zMD = pAstCfg->masterDec;
3168 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
3169 sourceProgram = pAstCfg->xDec[zMD].decodeStatus.sourceProgram;
3171 if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3172 {
3173 return 1;
3174 }
3176 // The following allows for Force modes to switch without command deferral. This might
3177 // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3178 if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
3179 {
3180 if (sourceSelect == PAF_SOURCE_DTSALL)
3181 {
3182 if (sourceProgram != PAF_SOURCE_DTS11 &&
3183 sourceProgram != PAF_SOURCE_DTS12 &&
3184 sourceProgram != PAF_SOURCE_DTS13 &&
3185 sourceProgram != PAF_SOURCE_DTS14 &&
3186 sourceProgram != PAF_SOURCE_DTS16 &&
3187 sourceProgram != PAF_SOURCE_DTSHD)
3188 {
3189 return 1;
3190 }
3191 }
3192 else if (sourceSelect == PAF_SOURCE_PCMAUTO)
3193 {
3194 if (sourceProgram != PAF_SOURCE_PCM)
3195 {
3196 return 1;
3197 }
3198 }
3199 else
3200 {
3201 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect != pAstCfg->xDec[zMD].decodeStatus.sourceDecode)
3202 {
3203 return 1;
3204 }
3205 }
3206 }
3208 return 0;
3209 } //PAF_ASIT_decodeFinalTest
3211 // -----------------------------------------------------------------------------
3212 // ASIT Decoding Function - Stream-Final Processing
3213 //
3214 // Name: PAF_ASIT_decodeComplete
3215 // Purpose: Decoding Function for terminating the decoding process.
3216 // From: AST Parameter Function -> decodeProcessing
3217 // Uses: See code.
3218 // States: x
3219 // Return: 0.
3220 // Trace: Message Log "trace" in Debug Project Configuration reports:
3221 // * State information as per parent.
3222 //
3223 Int
3224 PAF_ASIT_decodeComplete(
3225 const PAF_ASIT_Params *pP,
3226 const PAF_ASIT_Patchs *pQ,
3227 PAF_ASIT_Config *pC,
3228 ALG_Handle decAlg[],
3229 Int frame,
3230 Int block
3231 )
3232 {
3233 PAF_AST_Config *pAstCfg;
3234 Int as; /* Audio Stream Number (1, 2, etc.) */
3235 Int z; /* decode/encode counter */
3236 ASP_Msg* pAspMsg;
3237 Int argIdx;
3238 Int errno; /* error number */
3239 Int status;
3242 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3243 as = pAstCfg->as;
3244 (void)as; // clear compiler warning in case not used with tracing disabled
3246 #ifdef PAF_ASP_FINAL
3247 /* This material is currently not utilized */
3248 #endif /* PAF_ASP_FINAL */
3249 for (z=DECODE1; z < DECODEN; z++)
3250 {
3251 #ifdef PAF_ASP_FINAL
3252 DEC_Handle dec = (DEC_Handle )decAlg[z];
3253 #endif /* PAF_ASP_FINAL */
3254 Int zI = pP->inputsFromDecodes[z];
3255 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3256 {
3257 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3258 #ifdef PAF_ASP_FINAL
3259 if (dec->fxns->final)
3260 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3261 &pAstCfg->xDec[z].decodeStatus);
3262 #endif /* PAF_ASP_FINAL */
3263 // FL: send dec deactivate message to slave
3264 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3265 if (pAspMsg == NULL)
3266 {
3267 TRACE_TERSE0("MessageQ_alloc() failure.");
3268 errno = -1; // temporary
3269 return errno;
3270 }
3271 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3272 pAspMsg->cmd = ASP_SLAVE_DEC_DEACTIVATE; /* fill in message payload */
3273 pAspMsg->procId = hAspMsgMaster->masterProcId;
3274 pAspMsg->expectResp = TRUE;
3275 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3276 argIdx = 0; // set decIdx
3277 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3278 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3279 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3280 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3281 if (status != MessageQ_S_SUCCESS)
3282 {
3283 SW_BREAKPOINT;
3284 }
3285 // wait for dec deactivate complete message from slave
3286 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3287 if (status != MessageQ_S_SUCCESS)
3288 {
3289 TRACE_TERSE0("MessageQ_get() failure.");
3290 return errno;
3291 }
3292 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
3293 (pAspMsg->cmd != ASP_MASTER_DEC_DEACTIVATE_DONE) ||
3294 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3295 {
3296 TRACE_MSG3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3297 SW_BREAKPOINT; // temporary
3298 }
3299 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3300 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3301 // free the message
3302 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3303 if (status != MessageQ_S_SUCCESS)
3304 {
3305 SW_BREAKPOINT;
3306 }
3308 #if 0 // FL: decoder deactivate call, slave
3309 if (decAlg[z]->fxns->algDeactivate)
3310 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3311 #endif
3312 }
3313 else
3314 {
3315 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3316 }
3317 }
3318 return 0;
3319 } //PAF_ASIT_decodeComplete
3321 // -----------------------------------------------------------------------------
3322 // ASIT Selection Function - Input Device Selection
3323 //
3324 // Name: PAF_ASIT_selectDevices
3325 // Purpose: Audio Stream Input Task Function for selecting the devices used
3326 // for input.
3327 // From: audioStream1Task or equivalent
3328 // Uses: See code.
3329 // States: x
3330 // Return: Error number in standard form (0 on success).
3331 // Trace: Message Log "trace" in Debug Project Configuration reports:
3332 // * State information as per parent.
3333 //
3334 Int
3335 PAF_ASIT_selectDevices(
3336 const PAF_ASIT_Params *pP,
3337 const PAF_ASIT_Patchs *pQ,
3338 PAF_ASIT_Config *pC
3339 )
3340 {
3341 PAF_AST_Config *pAstCfg;
3342 Int as; /* Audio Stream Number (1, 2, etc.) */
3343 Int z; /* input/output counter */
3344 Int errno = 0; /* error number */
3345 Int errme; /* error number, local */
3346 Int device;
3347 Int zMD;
3349 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3350 as = pAstCfg->as;
3351 zMD = pAstCfg->masterDec;
3352 (void)as; // clear compiler warning in case not used with tracing disabled
3354 // Select input devices
3355 for (z=INPUT1; z < INPUTN; z++)
3356 {
3357 if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0)
3358 {
3359 TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3361 // check for valid index into device array
3362 if (device >= pQ->devinp->n)
3363 {
3364 device = 0; /* treat as device None */
3365 }
3367 errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3368 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3370 if (errme)
3371 {
3372 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3373 if (!errno)
3374 {
3375 errno = ASPERR_DEVINP + errme;
3376 }
3377 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3378 }
3379 else
3380 {
3381 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3382 // register decodeStatus pointer with input devices
3383 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3384 // Use zMIs decodeStatus for all inputs
3385 if (pAstCfg->xInp[z].hRxSio)
3386 {
3387 // register PAF_SIO_IALG object address
3388 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR,
3389 (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3390 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR,
3391 (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3392 }
3393 }
3394 }
3395 }
3397 return errno;
3398 } //PAF_ASIT_selectDevices
3400 // -----------------------------------------------------------------------------
3401 // ASIT Selection Function - Source Selection
3402 //
3403 // Name: PAF_ASIT_sourceDecode
3404 // Purpose: Audio Input Stream Task Function for selecting the sources used
3405 // for decoding of input to output.
3406 // From: audioStream1Task or equivalent
3407 // Uses: See code.
3408 // States: x
3409 // Return: 0.
3410 // Trace: None.
3411 //
3412 Int
3413 PAF_ASIT_sourceDecode(
3414 const PAF_ASIT_Params *pP,
3415 const PAF_ASIT_Patchs *pQ,
3416 PAF_ASIT_Config *pC,
3417 Int x
3418 )
3419 {
3420 PAF_AST_Config *pAstCfg;
3421 Int z; /* decode counter */
3423 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3425 for (z=DECODE1; z < DECODEN; z++)
3426 {
3427 if (pAstCfg->xDec[z].decodeStatus.mode)
3428 {
3429 pAstCfg->xDec[z].decodeStatus.sourceDecode = x;
3430 }
3431 }
3433 return 0;
3434 } //PAF_ASIT_sourceDecode
3436 // -----------------------------------------------------------------------------
3438 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3439 Int
3440 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3441 {
3442 Int errno = 0;
3443 Int zMD = pC->masterDec;
3444 Int zI = pP->inputsFromDecodes[z];
3446 // only handle real errors, on primary input, for writeDECModeContinuous
3447 if ( !( error &&
3448 z == zMD ))
3449 return error;
3451 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3452 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3454 if (pC->xInp[zI].hRxSio) {
3455 DEC_Handle dec;
3457 if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3458 return errno;
3460 // indicates (primary) input not running
3461 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3463 pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3465 // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3466 pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3468 if (decAlg[z]->fxns->algDeactivate)
3469 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3471 decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3472 dec = (DEC_Handle )decAlg[z];
3474 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3475 pC->as+z));
3477 if (decAlg[z]->fxns->algActivate)
3478 decAlg[z]->fxns->algActivate (decAlg[z]);
3480 if (dec->fxns->reset
3481 && (errno = dec->fxns->reset (dec, NULL,
3482 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3483 return errno;
3484 }
3486 return errno;
3487 } //PAF_AST_decodeHandleErrorInput
3488 #endif
3490 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3492 //------------------------------------------------------------------------------
3493 static int sSkipCount = 0;
3494 int gReportBuffers = 0;
3495 void as_traceChannels(PAF_AST_Config *pC, int z)
3496 {
3497 PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3498 int i;
3500 // #ifdef THIS_IS_DSPA
3501 sSkipCount++;
3502 if (sSkipCount<1)
3503 return;
3504 sSkipCount = 0;
3505 // #endif
3507 #ifdef THIS_IS_DSPB
3508 if (!gReportBuffers)
3509 return;
3510 gReportBuffers = 0;
3511 #endif
3513 dp(NULL, "\n");
3514 for (i=0; i<PAF_MAXNUMCHAN; i++)
3515 {
3516 if (pAudioFrame->data.sample[i] != 0)
3517 {
3518 float *wp = (float*)pAudioFrame->data.sample[i];
3519 dp(NULL, "i: %d. p: 0x%x. %f, %f, %f, %f\n",
3520 i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
3521 }
3522 }
3523 }
3524 #endif