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"
74 #include "statusOp_common.h"
77 // -----------------------------------------------------------------------------
78 // Debugging Trace Control, local to this file.
79 //
80 #include "logp.h"
82 #define TRACE_ARC(a)
84 // allows you to set a different trace module in pa.cfg
85 #define TR_MOD trace
87 // Allow a developer to selectively enable tracing.
88 #define CURRENT_TRACE_MASK 0x21
90 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
91 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
92 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
93 #define TRACE_MASK_DATA 0x08 // Show data
94 #define TRACE_MASK_TIME 0x10 // Timing related traces
95 #define TRACE_MASK_MSG 0x20 // Message related traces
97 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
98 #undef TRACE_TERSE0
99 #undef TRACE_TERSE1
100 #undef TRACE_TERSE2
101 #undef TRACE_TERSE3
102 #undef TRACE_TERSE4
103 #define TRACE_TERSE0(a)
104 #define TRACE_TERSE1(a,b)
105 #define TRACE_TERSE2(a,b,c)
106 #define TRACE_TERSE3(a,b,c,d)
107 #define TRACE_TERSE4(a,b,c,d,e)
108 #endif
110 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
111 #undef TRACE_GEN0
112 #undef TRACE_GEN1
113 #undef TRACE_GEN2
114 #undef TRACE_GEN3
115 #undef TRACE_GEN4
116 #define TRACE_GEN0(a)
117 #define TRACE_GEN1(a,b)
118 #define TRACE_GEN2(a,b,c)
119 #define TRACE_GEN3(a,b,c,d)
120 #define TRACE_GEN4(a,b,c,d,e)
121 #endif
123 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
124 // consolidate list of processing strings, indexed by PAF_SOURCE
125 static char *procName[] =
126 {
127 "", //PAF_SOURCE_UNKNOWN
128 "", //PAF_SOURCE_NONE
129 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
130 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
131 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
132 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
133 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
134 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
135 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
136 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
137 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
138 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
139 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
140 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
142 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
143 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
144 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
145 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
146 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
147 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
148 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
149 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
150 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
151 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
152 "AS%d: THD processing ...", //PAF_SOURCE_THD
153 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
154 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
155 };
157 #else
158 #undef TRACE_VERBOSE0
159 #undef TRACE_VERBOSE1
160 #undef TRACE_VERBOSE2
161 #undef TRACE_VERBOSE3
162 #undef TRACE_VERBOSE4
163 #define TRACE_VERBOSE0(a)
164 #define TRACE_VERBOSE1(a,b)
165 #define TRACE_VERBOSE2(a,b,c)
166 #define TRACE_VERBOSE3(a,b,c,d)
167 #define TRACE_VERBOSE4(a,b,c,d,e)
168 #endif
170 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
171 #define TRACE_DATA(a) LOG_printf a
172 #else
173 #define TRACE_DATA(a)
174 #endif
176 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
177 #define TRACE_TIME(a) LOG_printf a
178 #define TIME_MOD trace // this could be different
179 static Int dtime()
180 {
181 static Int old_time = 0;
182 Int time = TSK_time();
183 Int delta_time = time - old_time;
184 old_time = time;
185 return( delta_time);
186 }
188 static char *stateName[11] =
189 {
190 "INIT",
191 "INFO1",
192 "AGAIN",
193 "INFO2",
194 "CONT",
195 "TIME",
196 "DECODE",
197 "STREAM",
198 "ENCODE",
199 "FINAL",
200 "QUIT"
201 };
203 #else
204 #define TRACE_TIME(a)
205 #endif
207 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
208 #undef TRACE_MSG0
209 #undef TRACE_MSG1
210 #undef TRACE_MSG2
211 #undef TRACE_MSG3
212 #undef TRACE_MSG4
213 #define TRACE_MSG0(a)
214 #define TRACE_MSG1(a,b)
215 #define TRACE_MSG2(a,b,c)
216 #define TRACE_MSG3(a,b,c,d)
217 #define TRACE_MSG4(a,b,c,d,e)
218 #endif
221 // .............................................................................
223 #include <pafsio.h>
224 #include "paferr.h"
226 #include <acp_mds.h>
228 #include <pcm.h>
230 #include <pce.h>
232 #include <doberr.h>
234 #include <diberr.h>
236 #include <stdasp.h>
238 #include "as0.h"
239 #include "asperr.h"
241 #include "audioStreamProc_params.h"
242 #include "audioStreamProc_patchs.h"
243 #include "audioStreamProc_config.h"
244 #include "audioStreamInpProc.h"
246 //
247 // Audio Stream Definitions
248 //
250 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
251 #define MINFRAMELENGTH 24
252 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
255 //
256 // Decoder Definitions
257 //
258 //#define decLinkInit pQ->i_decLinkInit
260 //
261 // Audio Stream Processing Definitions
262 //
263 //#define aspLinkInit pQ->i_aspLinkInit
265 //
266 // Encoder Definitions
267 //
268 #define encLinkInit pQ->i_encLinkInit
270 //
271 // Input, Output Definitions
272 //
273 #define inpLinkInit pP->i_inpLinkInit
274 //#define outLinkInit pP->i_outLinkInit
276 /* ---------------------------------------------------------------- */
277 /* Parameter macro definitions end here. */
278 /* ---------------------------------------------------------------- */
280 //
281 // Standardized Definitions
282 //
284 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
285 //#define ENC_Handle PCE_Handle /* works for all: PCE */
287 #define __TASK_NAME__ "TaskAsip"
289 LINNO_DEFN(TaskAsip); /* Line number macros */
290 ERRNO_DEFN(TaskAsip); /* Error number macros */
292 // ASIT configuration
293 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
294 PAF_ASIT_Config gPAF_ASIT_config = {
295 NULL, // acp
296 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
297 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
298 };
300 // Global debug counters */
301 UInt32 gTaskAsipCnt=0; // debug
302 UInt32 gAsipInitCnt =0;
303 UInt32 gAsipInfo1Cnt =0;
304 UInt32 gAsipInfo2Cnt =0;
305 UInt32 gAsipDecodeCnt =0;
306 UInt32 gAsipDecodeErrCnt =0;
307 UInt32 gAsipFinalCnt =0;
308 UInt32 gAsipQuitCnt =0;
309 UInt32 gIbReset_cnt =0;
310 UInt32 gcapIb_cnt =0;
311 UInt32 gAsipInfo2_PrimaryErrCnt =0;
312 UInt32 gAsipInfo2_ErrCnt =0;
314 #include "dbgDib.h"
316 extern struct {
317 Int size;
318 IALG_Status *pStatus[512];
319 } IACP_STD_BETA_TABLE;
321 // FL: debug
322 #include "evmc66x_pinmux.h"
323 #include "evmc66x_gpio_dbg.h"
325 /*
326 * ======== taskAsipFxn ========
327 * Audio Stream Input Processing task function
328 */
329 Void taskAsipFxn(
330 // Int betaPrimeValue, // FL: revisit
331 const PAF_ASIT_Params *pP,
332 const PAF_ASIT_Patchs *pQ
333 )
334 {
335 PAF_ASIT_Config *pC; /* Local configuration pointer */
336 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
337 Int as; /* Audio Stream Number (1, 2, etc.) */
338 Int z; /* input/encode/stream/decode/output counter */
339 Int i; /* phase */
340 Int errno; /* error number */
341 Int zMD, zMI, zMS, zX;
342 Int loopCount = 0; // used to stop trace to see startup behavior.
343 UInt32 curTime;
344 Int size;
345 // Messaging
346 ASP_Msg *pAspMsg;
347 Int status;
348 #ifdef NON_CACHE_STATUS
349 Int8 tempVar8;
350 #endif
352 Log_info0("Enter taskAsipFxn()");
354 #ifdef SIMULATE_SIO
355 /* Start simulation */
356 simStart();
357 #endif // SIMULATE_SIO
359 //
360 // Audio Framework Parameters & Patch (*pP, *pQ)
361 //
362 if (!pP)
363 {
364 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
365 LINNO_RPRT(TaskAsip, -1);
366 return;
367 }
369 if (!pQ)
370 {
371 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
372 LINNO_RPRT(TaskAsip, -1);
373 return;
374 }
376 //
377 // Audio Framework Configuration (*pC):
378 //
379 pC = &gPAF_ASIT_config;
380 pAstCfg = pC->pAstCfg;
382 /* Set Audio Stream Number (1, 2, etc.) */
383 as = gBetaPrimeValue + 1;
384 pAstCfg->as = as;
385 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
387 //
388 // Initialize message log trace and line number reporting
389 //
390 for (z=STREAM1; z < STREAMN; z++)
391 {
392 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
393 }
394 LINNO_RPRT(TaskAsip, -1);
396 //
397 // Determine decoder and stream indices associated with the master input
398 //
399 zMI = pP->zone.master;
400 pAstCfg->masterDec = zMI;
401 pAstCfg->masterStr = zMI;
402 for (zX = DECODE1; zX < DECODEN; zX++)
403 {
404 if (pP->inputsFromDecodes[zX] == zMI)
405 {
406 pAstCfg->masterDec = zX;
407 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
408 break;
409 }
410 }
411 zMD = pAstCfg->masterDec;
412 zMS = pAstCfg->masterStr;
414 // Initialize as per parametrized phases:
415 //
416 // In standard form these are:
417 // - Malloc: Memory Allocation
418 // - Config: Configuration Initialization
419 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
420 // - Common: Common Memory Initialization
421 // - AlgKey: Dec/Enc chain to Array Initialization
422 // - Device: I/O Device Initialization
423 // - DecOpCircBuf: Decoder Output Circular Buffer
424 // - Unused: (available)
425 //
426 LINNO_RPRT(TaskAsip, -2);
427 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
428 {
429 Int linno;
430 if (pP->fxns->initPhase[i])
431 {
432 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
433 {
434 LINNO_RPRT(TaskAsip, linno);
435 return;
436 }
437 }
438 else
439 {
440 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
441 }
442 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
443 LINNO_RPRT(TaskAsip, -i-3);
444 }
446 //
447 // End of Initialization -- display memory usage report.
448 //
449 if (pP->fxns->memStatusPrint)
450 {
451 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
452 }
454 // (***) FL: revisit
455 // write back AST shared configuration
456 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
457 // FL: no need to share this pointer, can be local
458 //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
459 Cache_wait();
461 // (***) FL: revisit
462 // write back Dec configuration
463 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
464 Cache_wait();
466 // (***) FL: revisit
467 // write back entire beta table
468 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
469 Cache_wait();
471 // FL: send start initialization message to slave
472 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
473 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
474 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
475 pAspMsg->procId = hAspMsgMaster->masterProcId;
476 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
477 pAspMsg->expectResp = TRUE;
478 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
479 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
480 if (status != MessageQ_S_SUCCESS)
481 {
482 SW_BREAKPOINT;
483 }
484 // wait for initialization complete message from slave
485 do {
486 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
487 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
488 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
489 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
490 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
491 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
492 {
493 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
494 SW_BREAKPOINT;
495 }
496 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
497 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
498 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
499 if (status != MessageQ_S_SUCCESS)
500 {
501 SW_BREAKPOINT;
502 }
504 // (***) FL: revisit
505 // invalidate Status structure addresses for Beta Units initialized on Slave
506 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
507 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
508 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
509 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
510 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
511 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
512 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
513 Cache_wait();
514 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
515 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
516 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
517 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
518 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
519 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
520 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
522 // (***) FL: revisit
523 // invalidate Status structures for Beta Units initialized on Slave
524 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
525 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
526 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
527 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
528 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
529 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
530 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
531 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
532 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
533 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
534 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
535 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
536 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
537 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
538 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
539 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
540 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
541 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
542 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
543 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
544 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
545 Cache_wait();
547 #ifdef NON_CACHE_STATUS
548 // Get the shared status structure GateMP handles. Initialized at slave.
549 if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
550 {
551 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
552 }
553 if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
554 {
555 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
556 }
557 if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
558 {
559 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
560 }
561 if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
562 {
563 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
564 }
565 #endif
567 // (***) FL: revisit
568 // invalidate Dec configuration
569 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
570 Cache_wait();
572 //
573 // Main processing loop
574 //
575 for (z=STREAM1; z < STREAMN; z++)
576 {
577 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
578 }
580 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
582 errno = 0;
583 for (;;)
584 {
585 Int sourceSelect;
586 XDAS_Int8 sourceProgram;
588 loopCount++;
590 #if 0 // enable and tune to see startup behavior.
591 // this is an alternative to fixed/circular setting in pa.cfg.
592 // If you are searching for a memory allocation failure, disable on first round.
593 // All allocation has already happened.
594 // This is the outer loop. This loop count goes up when the stream resets.
595 // If the stream is running without problems, this does not increment.
596 // If the stream is repeatedly resetting, this loop count will go up rapidly.
597 if (loopCount > 10) // see traces for a few of the passes through the main loop.
598 {
599 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
600 LOG_disable(&TR_MOD); // stop tracing
601 }
602 #endif
604 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
605 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
607 // since not decoding indicate such
608 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
610 // any error forces idling of input
611 if (errno)
612 {
613 for (z=INPUT1; z < INPUTN; z++)
614 {
615 if (pAstCfg->xInp[z].hRxSio)
616 {
617 SIO_idle(pAstCfg->xInp[z].hRxSio);
618 }
619 }
621 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
622 ERRNO_RPRT(TaskAsip, errno);
623 }
625 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
626 // up to allow lower priority tasks to run. This may seem odd to be at the top
627 // of the state machine but provides for a cleaner flow even though the very
628 // first time we enter we do a sleep which is non-intuitive.
629 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
630 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
631 Task_sleep(1);
633 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
634 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
635 {
636 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
637 continue;
638 }
640 // if no master input selected then we don't know what may be at the input
641 // so set to unknown and skip any remaining processing
642 if (!pAstCfg->xInp[zMI].hRxSio)
643 {
644 #ifdef NON_CACHE_STATUS
645 tempVar8 = PAF_SOURCE_UNKNOWN;
646 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
647 &tempVar8,
648 sizeof(tempVar8),
649 GATEMP_INDEX_DEC);
650 #else
651 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
652 #endif
653 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
654 continue;
655 }
657 // if here then we have a valid input so query its status
658 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
659 {
660 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
661 continue;
662 }
664 #ifdef NON_CACHE_STATUS
665 statusOp_read(&tempVar8,
666 &(pAstCfg->xDec[zMD].decodeStatus.mode),
667 sizeof(tempVar8),
668 GATEMP_INDEX_DEC);
669 // If master decoder is not enabled, or the input is unlocked, then do nothing
670 if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
671 {
672 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
673 continue;
674 }
675 #else
676 // If master decoder is not enabled, or the input is unlocked, then do nothing
677 if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
678 {
679 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
680 continue;
681 }
682 #endif
684 #ifdef NON_CACHE_STATUS
685 statusOp_read(&tempVar8,
686 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
687 sizeof(tempVar8),
688 GATEMP_INDEX_DEC);
689 // If no source selected then do nothing
690 if (tempVar8 == PAF_SOURCE_NONE)
691 {
692 tempVar8 = PAF_SOURCE_NONE;
693 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
694 &tempVar8,
695 sizeof(tempVar8),
696 GATEMP_INDEX_DEC);
697 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
698 continue;
699 }
700 #else
701 // If no source selected then do nothing
702 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
703 {
704 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
705 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
706 continue;
707 }
708 #endif
710 #ifdef NON_CACHE_STATUS
711 statusOp_read(&tempVar8,
712 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
713 sizeof(tempVar8),
714 GATEMP_INDEX_DEC);
715 // If we want pass processing then proceed directly
716 if (tempVar8 == PAF_SOURCE_PASS)
717 {
718 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
720 tempVar8 = PAF_SOURCE_PASS;
721 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
722 &tempVar8,
723 sizeof(tempVar8),
724 GATEMP_INDEX_DEC);
725 #else
726 // If we want pass processing then proceed directly
727 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
728 {
729 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
730 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
731 #endif
732 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
733 if (pP->fxns->passProcessing)
734 {
735 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
736 }
737 else
738 {
739 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
740 errno = ASPERR_PASS;
741 }
742 TRACE_VERBOSE0("TaskAsip: continue");
743 continue;
744 }
746 #ifdef NON_CACHE_STATUS
747 statusOp_read(&tempVar8,
748 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
749 sizeof(tempVar8),
750 GATEMP_INDEX_DEC);
751 // .....................................................................
752 // At this point we have an enabled input and want to decode something.
753 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
754 // when no decoder is selected there are no calls to IB
755 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
756 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, tempVar8, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
757 {
758 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
759 continue;
760 }
761 #else
762 // .....................................................................
763 // At this point we have an enabled input and want to decode something.
764 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
765 // when no decoder is selected there are no calls to IB
766 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
767 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
768 {
769 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
770 continue;
771 }
772 #endif
774 // query for input type
775 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
776 {
777 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
778 errno = ASPERR_AUTO_PROGRAM;
779 continue;
780 }
781 #ifdef NON_CACHE_STATUS
782 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
783 &(sourceProgram),
784 sizeof(sourceProgram),
785 GATEMP_INDEX_DEC);
786 #else
787 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
788 #endif
790 // if input is unclassifiable then do nothing
791 if (sourceProgram == PAF_SOURCE_UNKNOWN)
792 {
793 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
794 continue;
795 }
797 // now that we have some input classification, and possibly an outstanding
798 // input frame, we determine whether or not to call decodeProcessing and with
799 // what decAlg.
800 sourceSelect = PAF_SOURCE_NONE;
801 #ifdef NON_CACHE_STATUS
802 statusOp_read(&tempVar8,
803 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
804 sizeof(tempVar8),
805 GATEMP_INDEX_DEC);
806 switch (tempVar8)
807 {
808 #else
809 switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect)
810 {
811 #endif
812 // If autodetecting, decoding everything, and input is something
813 // (i.e. bitstream or PCM) then decode.
814 case PAF_SOURCE_AUTO:
815 if (sourceProgram >= PAF_SOURCE_PCM)
816 {
817 sourceSelect = sourceProgram;
818 }
819 break;
821 // If autodetecting, decoding only PCM, and input is PCM then decode.
822 case PAF_SOURCE_PCMAUTO:
823 if (sourceProgram == PAF_SOURCE_PCM)
824 {
825 sourceSelect = sourceProgram;
826 }
827 break;
829 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
830 case PAF_SOURCE_BITSTREAM:
831 if (sourceProgram >= PAF_SOURCE_AC3)
832 {
833 sourceSelect = sourceProgram;
834 }
835 break;
837 // If autodetecting, decoding only DTS, and input is DTS then decode.
838 case PAF_SOURCE_DTSALL:
839 switch (sourceProgram)
840 {
841 case PAF_SOURCE_DTS11:
842 case PAF_SOURCE_DTS12:
843 case PAF_SOURCE_DTS13:
844 case PAF_SOURCE_DTS14:
845 case PAF_SOURCE_DTS16:
846 case PAF_SOURCE_DTSHD:
847 sourceSelect = sourceProgram;
848 break;
849 }
850 break;
852 // All others, e.g., force modes, fall through to here.
853 // If user made specific selection then program must match select.
854 // (NB: this compare relies on ordering of PAF_SOURCE)
855 default:
856 #ifdef NON_CACHE_STATUS
857 sourceSelect = 0; // due to size difference
858 statusOp_read(&sourceSelect,
859 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
860 sizeof(Int8),
861 GATEMP_INDEX_DEC);
862 #else
863 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
864 #endif
865 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
866 {
867 if (sourceProgram != sourceSelect)
868 {
869 sourceSelect = PAF_SOURCE_NONE;
870 }
871 }
872 break;
873 }
875 // if we didn't find any matches then skip
876 if (sourceSelect == PAF_SOURCE_NONE)
877 {
878 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
879 continue;
880 }
882 // FL: debug, reset IB capture buffer
883 capIbReset();
884 gIbReset_cnt++;
885 Log_info0("capIbReset()");
887 // FL: send source select message to slave
888 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
889 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
890 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
891 pAspMsg->procId = hAspMsgMaster->masterProcId;
892 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
893 pAspMsg->expectResp = TRUE;
894 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
895 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
896 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
897 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
898 if (status != MessageQ_S_SUCCESS)
899 {
900 SW_BREAKPOINT;
901 }
902 // wait for source select complete message from slave
903 //do {
904 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
905 //} while (status != MessageQ_S_SUCCESS);
906 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
907 if (status != MessageQ_S_SUCCESS)
908 {
909 TRACE_TERSE0("MessageQ_get() failure.");
910 SW_BREAKPOINT; // temporary
911 }
912 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
913 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
914 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
915 {
916 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
917 SW_BREAKPOINT;
918 }
919 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
920 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
921 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
922 if (status != MessageQ_S_SUCCESS)
923 {
924 SW_BREAKPOINT;
925 }
927 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
928 // iff we are in this top level state machine and specifically not in decodeProcessing
929 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
931 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
933 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
934 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
935 if (errno)
936 {
937 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
938 }
939 else
940 {
941 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
942 }
944 // FL: send dec exit message to slave
945 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
946 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
947 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
948 pAspMsg->procId = hAspMsgMaster->masterProcId;
949 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
950 pAspMsg->expectResp = TRUE;
951 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
952 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
953 if (status != MessageQ_S_SUCCESS)
954 {
955 SW_BREAKPOINT;
956 }
957 // wait for dec exit complete message from slave
958 //do {
959 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
960 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
961 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
962 if (status != MessageQ_S_SUCCESS)
963 {
964 TRACE_TERSE0("MessageQ_get() failure.");
965 SW_BREAKPOINT; // temporary
966 }
967 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
968 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
969 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
970 {
971 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
972 SW_BREAKPOINT;
973 }
974 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
975 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
976 // free the message
977 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
978 if (status != MessageQ_S_SUCCESS)
979 {
980 SW_BREAKPOINT;
981 }
982 } // End of main processing loop for (;;)
984 Log_info0("Exit taskAsipFxn()");
985 }
987 // -----------------------------------------------------------------------------
988 // ASIT Initialization Function - Memory Allocation
989 //
990 // Name: PAF_ASIT_initPhaseMalloc
991 // Purpose: Audio Stream Input Task Function for initialization of data pointers
992 // by allocation of memory.
993 // From: audioStream1Task or equivalent
994 // Uses: See code.
995 // States: x
996 // Return: 0 on success.
997 // Source code line number on MEM_calloc failure.
998 // Trace: Message Log "trace" in Debug Project Configuration reports:
999 // * State information as per parent.
1000 // * Memory allocation errors.
1001 //
1002 Int
1003 PAF_ASIT_initPhaseMalloc(
1004 const PAF_ASIT_Params *pP,
1005 const PAF_ASIT_Patchs *pQ,
1006 PAF_ASIT_Config *pC
1007 )
1008 {
1009 PAF_AST_Config *pAstCfg;
1010 Int as; /* Audio Stream Number (1, 2, etc.) */
1011 Int zMS;
1012 Error_Block eb;
1014 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1015 as = pAstCfg->as;
1016 zMS = pAstCfg->masterStr;
1018 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1020 // Initialize error block
1021 Error_init(&eb);
1023 /* Input memory */
1024 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1025 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
1026 {
1027 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1028 SW_BREAKPOINT;
1029 return __LINE__;
1030 }
1031 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
1032 INPUTN * sizeof (*pAstCfg->xInp),
1033 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
1035 #ifdef NON_CACHE_STATUS
1036 /* Decode memory */
1037 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM,
1038 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1039 {
1040 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1041 SW_BREAKPOINT;
1042 return __LINE__;
1043 }
1044 #else
1045 /* Decode memory */
1046 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1047 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1048 {
1049 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1050 SW_BREAKPOINT;
1051 return __LINE__;
1052 }
1053 #endif
1054 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
1055 DECODEN * sizeof (*pAstCfg->xDec),
1056 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
1058 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1059 return 0;
1060 } //PAF_ASIT_initPhaseMalloc
1062 // -----------------------------------------------------------------------------
1063 // ASIT Initialization Function - Memory Initialization from Configuration
1064 //
1065 // Name: PAF_ASIT_initPhaseConfig
1066 // Purpose: Audio Stream Task Function for initialization of data values
1067 // from parameters.
1068 // From: audioStream1Task or equivalent
1069 // Uses: See code.
1070 // States: x
1071 // Return: 0 on success.
1072 // Other as per initFrame0 and initFrame1.
1073 // Trace: Message Log "trace" in Debug Project Configuration reports:
1074 // * State information as per parent.
1075 //
1076 Int
1077 PAF_ASIT_initPhaseConfig(
1078 const PAF_ASIT_Params *pP,
1079 const PAF_ASIT_Patchs *pQ,
1080 PAF_ASIT_Config *pC
1081 )
1082 {
1083 PAF_AST_Config *pAstCfg;
1084 Int as; /* Audio Stream Number (1, 2, etc.) */
1085 Int z; /* input/encode/stream/decode/output counter */
1086 Int zMS;
1088 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1089 as = pAstCfg->as;
1090 zMS = pAstCfg->masterStr;
1092 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1094 //
1095 // Unspecified elements have been initialized to zero during alloc
1096 //
1098 for (z=INPUT1; z < INPUTN; z++)
1099 {
1100 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
1101 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
1102 }
1104 for (z=DECODE1; z < DECODEN; z++)
1105 {
1106 Int zI = pP->inputsFromDecodes[z];
1107 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1108 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1109 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1110 }
1112 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1113 return 0;
1114 } //PAF_ASIT_initPhaseConfig
1116 // -----------------------------------------------------------------------------
1117 // ASIT Initialization Function - ACP Algorithm Instantiation
1118 //
1119 // Name: PAF_ASIT_initPhaseAcpAlg
1120 // Purpose: Audio Stream Input Task Function for initialization of ACP by
1121 // instantiation of the algorithm.
1122 // From: audioStream1Task or equivalent
1123 // Uses: See code.
1124 // States: x
1125 // Return: 0 on success.
1126 // Source code line number on ACP Algorithm creation failure.
1127 // Trace: Message Log "trace" in Debug Project Configuration reports:
1128 // * State information as per parent.
1129 // * Memory allocation errors.
1130 //
1131 Int
1132 PAF_ASIT_initPhaseAcpAlg(
1133 const PAF_ASIT_Params *pP,
1134 const PAF_ASIT_Patchs *pQ,
1135 PAF_ASIT_Config *pC
1136 )
1137 {
1138 PAF_AST_Config *pAstCfg;
1139 Int as; /* Audio Stream Number (1, 2, etc.) */
1140 Int z; /* input/encode/stream/decode/output counter */
1141 Int betaPrimeOffset;
1142 ACP_Handle acp;
1143 Int zMS;
1144 Int zS, zX;
1146 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1147 as = pAstCfg->as;
1148 zMS = pAstCfg->masterStr;
1150 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1152 ACP_MDS_init();
1154 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1155 {
1156 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1157 return __LINE__;
1158 }
1159 pC->acp = acp;
1161 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1162 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1164 for (z=INPUT1; z < INPUTN; z++)
1165 {
1166 zS = z;
1167 for (zX = DECODE1; zX < DECODEN; zX++)
1168 {
1169 if (pP->inputsFromDecodes[zX] == z)
1170 {
1171 zS = pP->streamsFromDecodes[zX];
1172 break;
1173 }
1174 }
1175 acp->fxns->attach(acp, ACP_SERIES_STD,
1176 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1177 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1178 /* Ignore errors, not reported. */
1179 }
1181 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1183 return 0;
1184 } //PAF_ASIT_initPhaseAcpAlg
1186 // -----------------------------------------------------------------------------
1187 // ASIT Initialization Function - Common Memory
1188 //
1189 // Name: PAF_ASIT_initPhaseCommon
1190 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1191 // From: audioStream1Task or equivalent
1192 // Uses: See code.
1193 // States: x
1194 // Return: 0 on success.
1195 // Source code line number on PAF_ALG_alloc failure.
1196 // Source code line number on PAF_ALG_mallocMemory failure.
1197 // Source code line number on Decode Chain initialization failure.
1198 // Source code line number on ASP Chain initialization failure.
1199 // Source code line number on Encode Chain initialization failure.
1200 // Trace: Message Log "trace" in Debug Project Configuration reports:
1201 // * State information as per parent.
1202 // * Memory allocation errors.
1203 //
1204 Int
1205 PAF_ASIT_initPhaseCommon(
1206 const PAF_ASIT_Params *pP,
1207 const PAF_ASIT_Patchs *pQ,
1208 PAF_ASIT_Config *pC
1209 )
1210 {
1211 PAF_AST_Config *pAstCfg;
1212 Int as; /* Audio Stream Number (1, 2, etc.) */
1213 Int z; /* stream counter */
1214 ACP_Handle acp;
1215 PAF_IALG_Config pafAlgConfig;
1216 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1218 acp = pC->acp;
1219 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1220 as = pAstCfg->as;
1222 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1224 //
1225 // Determine memory needs and instantiate algorithms across audio streams
1226 //
1227 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1228 PAF_ALG_setup(&pafAlgConfig,
1229 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1230 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1231 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1232 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1233 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1234 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1235 HEAP_CLEAR);
1237 if (pP->fxns->headerPrint)
1238 {
1239 pP->fxns->headerPrint();
1240 }
1242 for (z = STREAM1; z < STREAMN; z++)
1243 {
1244 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1246 //
1247 // Determine common memory for:
1248 // (1) Logical Input drivers
1249 //
1250 // Decode Algorithms common memory determined in ASP Slave.
1251 //
1252 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1254 //
1255 // Determine common memory needs of Logical Input driver
1256 //
1258 // really need to loop over all inputs for this stream using the tables
1259 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1260 // patch, and not needed for FS11, since there is only one input.
1261 if (INPUT1 <= z && z < INPUTN)
1262 {
1263 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1264 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1265 {
1266 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1267 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1268 SW_BREAKPOINT;
1269 return __LINE__;
1270 }
1271 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1272 if (pP->fxns->allocPrint)
1273 {
1274 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1275 }
1276 }
1277 }
1278 {
1279 // Changes made to share scratch between zones
1280 // Assume maximum 3 zones and scratch common memory is at offset 0;
1281 int max=0;
1282 for (z=STREAM1; z<STREAMN; z++)
1283 {
1284 if (max < common[z][0].size)
1285 {
1286 max = common[z][0].size;
1287 }
1288 }
1289 common[STREAM1][0].size=max;
1290 for (z=STREAM1+1; z<STREAMN; z++)
1291 {
1292 common[z][0].size = 0;
1293 }
1294 }
1296 //
1297 // Allocate common memory for:
1298 // (1) Logical Input drivers
1299 //
1300 for (z = STREAM1; z < STREAMN; z++)
1301 {
1302 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1303 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1304 {
1305 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1306 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1307 SW_BREAKPOINT;
1308 return __LINE__;
1309 }
1310 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1311 // share zone0 scratch with all zones
1312 common[z][0].base = common[0][0].base;
1313 if (pP->fxns->commonPrint)
1314 {
1315 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1316 }
1318 //
1319 // Allocate non-common memories for Logical IO drivers
1320 // Since these structures are used at run-time we allocate from external memory
1321 if (INPUT1 <= z && z < INPUTN)
1322 {
1323 PAF_ASP_Chain *chain;
1324 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1325 as+z, z);
1326 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1327 HEAP_EXTERNAL, as+z, acp, &trace,
1328 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1329 if (!chain)
1330 {
1331 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1332 return __LINE__;
1333 }
1334 }
1335 }
1336 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1338 return 0;
1339 } //PAF_ASIT_initPhaseCommon
1341 // (***) FL: candidate for removal
1342 // -----------------------------------------------------------------------------
1343 // ASIT Initialization Function - Algorithm Keys
1344 //
1345 // Name: PAF_ASIT_initPhaseAlgKey
1346 // Purpose: Audio Stream Input Task Function for initialization of data values
1347 // from parameters for Algorithm Keys.
1348 // From: audioStream1Task or equivalent
1349 // Uses: See code.
1350 // States: x
1351 // Return: 0.
1352 // Trace: Message Log "trace" in Debug Project Configuration reports:
1353 // * State information as per parent.
1354 //
1355 // .............................................................................
1356 Int
1357 PAF_ASIT_initPhaseAlgKey(
1358 const PAF_ASIT_Params *pP,
1359 const PAF_ASIT_Patchs *pQ,
1360 PAF_ASIT_Config *pC
1361 )
1362 {
1363 PAF_AST_Config *pAstCfg;
1364 Int as; /* Audio Stream Number (1, 2, etc.) */
1367 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1368 as = pAstCfg->as;
1369 (void)as; // clear compiler warning in case not used with tracing disabled
1371 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1373 #if 0 // FL: slave
1374 for (z=DECODE1; z < DECODEN; z++)
1375 {
1376 for (s=0; s < pP->pDecAlgKey->length; s++)
1377 {
1378 if ((pP->pDecAlgKey->code[s].full != 0) &&
1379 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1380 {
1381 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1382 /* Cast in interface, for now --Kurt */
1383 }
1384 else
1385 {
1386 pC->xDec[z].decAlg[s] = NULL;
1387 }
1388 }
1389 }
1390 #endif
1392 return 0;
1393 } //PAF_ASIT_initPhaseAlgKey
1395 // -----------------------------------------------------------------------------
1396 // ASIT Initialization Function - I/O Devices
1397 //
1398 // Name: PAF_ASIT_initPhaseDevice
1399 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1400 // From: audioStream1Task or equivalent
1401 // Uses: See code.
1402 // States: x
1403 // Return: 0 on success.
1404 // Source code line number on device allocation failure.
1405 // Trace: Message Log "trace" in Debug Project Configuration reports:
1406 // * State information as per parent.
1407 // * Memory allocation errors.
1408 //
1409 Int
1410 PAF_ASIT_initPhaseDevice(
1411 const PAF_ASIT_Params *pP,
1412 const PAF_ASIT_Patchs *pQ,
1413 PAF_ASIT_Config *pC
1414 )
1415 {
1416 PAF_AST_Config *pAstCfg;
1417 Int as; /* Audio Stream Number (1, 2, etc.) */
1418 Int z; /* input/output counter */
1419 PAF_SIO_IALG_Obj *pObj;
1420 PAF_SIO_IALG_Config *pAlgConfig;
1421 PAF_IALG_Config pafAlgConfig;
1424 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1425 as = pAstCfg->as;
1426 (void)as; // clear compiler warning in case not used with tracing disabled
1428 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1430 if (pP->fxns->bufMemPrint)
1431 {
1432 PAF_ALG_setup (&pafAlgConfig,
1433 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1434 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1435 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1436 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1437 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1438 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1439 HEAP_CLEAR);
1440 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1441 }
1443 for (z=INPUT1; z < INPUTN; z++)
1444 {
1445 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1447 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1448 pAlgConfig = &pObj->config;
1450 pAstCfg->xInp[z].hRxSio = NULL;
1452 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1453 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1454 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1455 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1456 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1457 pConfig->sizeofElement = 2;
1458 pConfig->precision = 16;
1460 if (pP->fxns->bufMemPrint)
1461 {
1462 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1463 }
1464 }
1466 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1468 return 0;
1469 } //PAF_ASIT_initPhaseDevice
1471 // -----------------------------------------------------------------------------
1472 // ASIT Initialization Function - Decoder Output Circular Buffer
1473 //
1474 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1475 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1476 // From: audioStream1Task or equivalent
1477 // Uses: See code.
1478 // States: x
1479 // Return: 0 on success.
1480 // Source code line number on device allocation failure.
1481 // Trace: Message Log "trace" in Debug Project Configuration reports:
1482 // * State information as per parent.
1483 // * Memory allocation errors.
1484 //
1485 Int
1486 PAF_ASIT_initPhaseDecOpCircBuf(
1487 const PAF_ASIT_Params *pP,
1488 const PAF_ASIT_Patchs *pQ,
1489 PAF_ASIT_Config *pC
1490 )
1491 {
1492 PAF_AST_Config *pAstCfg;
1493 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1494 Int as; /* Audio Stream Number (1, 2, etc.) */
1495 Int zMS;
1496 Int z; /* decode counter */
1497 Int errno; /* error number */
1498 Error_Block eb;
1499 Int i;
1501 // FL: (***)revisit
1502 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1503 as = pAstCfg->as;
1504 zMS = pAstCfg->masterStr;
1506 /* Decode output circular buffer memory */
1507 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1508 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1509 {
1510 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1511 SW_BREAKPOINT;
1512 return __LINE__;
1513 }
1515 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1516 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1517 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1519 for (z=DECODE1; z < DECODEN; z++)
1520 {
1521 pCb = &pAstCfg->xDecOpCb[z];
1523 // allocate audio frame circular buffer
1524 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1525 {
1526 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1527 SW_BREAKPOINT;
1528 }
1529 // allocate audio frame PCM sample pointer array
1530 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1531 {
1532 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)))
1533 {
1534 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1535 SW_BREAKPOINT;
1536 }
1537 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)))
1538 {
1539 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1540 SW_BREAKPOINT;
1541 }
1542 }
1543 // allocate PCM sample buffer
1544 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1545 {
1546 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1547 SW_BREAKPOINT;
1548 }
1549 pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1550 // allocate Metadata buffers //QIN
1551 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)))
1552 {
1553 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1554 SW_BREAKPOINT;
1555 }
1556 pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1557 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1558 // Initialize decoder output circular buffer for PCM
1559 errno = cbInit(pCb);
1560 if (errno)
1561 {
1562 SW_BREAKPOINT; // FL: debug
1563 return errno;
1564 }
1565 }
1567 return 0;
1568 } //PAF_ASIT_initPhaseDecOpCircBuf
1571 #if 0
1572 // -----------------------------------------------------------------------------
1573 // AST Processing Function - Pass-Through Processing
1574 //
1575 // Name: PAF_AST_passProcessing
1576 // Purpose: Audio Stream Task Function for processing audio data as a
1577 // pass-through from the input driver to the output driver
1578 // for development and testing.
1579 // From: audioStream1Task or equivalent
1580 // Uses: See code.
1581 // States: x
1582 // Return: Error number in standard form (0 on success).
1583 // Trace: Message Log "trace" in Debug Project Configuration reports:
1584 // * State information on initialization.
1585 // * State information on processing.
1586 //
1588 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1589 /* Pass Processing is often omitted from builds to save memory, */
1590 /* and CODE_SECTION/clink constructs facilitate this omission. */
1592 Int
1593 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1594 {
1595 Int z; /* input/output counter */
1596 Int errno = 0; /* error number */
1597 Int getVal;
1598 Int rxNumChan, txNumChan;
1599 Int first;
1600 Int zMD = pC->masterDec;
1601 Int zMI = pP->zone.master;
1604 #ifndef __TI_EABI__
1605 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1606 #endif
1608 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1610 //
1611 // Determine that receive/transmit channels are compatible
1612 //
1614 // Can handle handle only master input
1615 for (z=INPUT1; z < INPUTN; z++) {
1616 if (z != zMI && pC->xInp[z].hRxSio)
1617 return (ASPERR_PASS + 0x01);
1618 }
1620 /* Number of receive/transmit channels */
1622 if (! pC->xInp[zMI].hRxSio)
1623 return (ASPERR_PASS + 0x11);
1624 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1625 return (ASPERR_PASS + 0x12);
1626 if (rxNumChan > NUM_TX_CHAN(zMI))
1627 return (ASPERR_PASS + 0x13);
1629 for (z=OUTPUT1; z < OUTPUTN; z++) {
1630 if (! pC->xOut[zMI].hTxSio)
1631 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1632 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1633 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1634 if (txNumChan > NUM_TX_CHAN(zMI))
1635 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1636 }
1638 //
1639 // Set up receive/transmit
1640 //
1642 SIO_idle (pC->xInp[zMI].hRxSio);
1643 for (z=OUTPUT1; z < OUTPUTN; z++) {
1644 if(SIO_idle (pC->xOut[z].hTxSio))
1645 return ASPERR_IDLE;
1646 }
1648 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1649 return (ASPERR_PASS + 0x14);
1651 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1652 return (ASPERR_PASS + 0x15);
1654 for (z=OUTPUT1; z < OUTPUTN; z++)
1655 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1657 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1658 return ASPERR_PASS + 0x16;
1660 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1661 return ASPERR_PASS + 0x17;
1663 //
1664 // Receive and transmit the data in single-frame buffers
1665 //
1667 first = 1;
1668 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1669 PAF_OutBufConfig *pOutBuf;
1670 PAF_InpBufConfig *pInpBuf;
1672 if (first) {
1673 first = 0;
1675 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1677 for (z=OUTPUT1; z < OUTPUTN; z++) {
1678 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1679 if (getVal > 0) {
1680 errno = ASPERR_ISSUE;
1681 break;
1682 }
1683 else if (getVal < 0) {
1684 errno = -getVal;
1685 break;
1686 }
1688 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1689 return (getVal & 0xff) | ASPERR_MUTE;
1690 }
1691 if (errno)
1692 break;
1694 }
1696 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1697 if (getVal > 0) {
1698 errno = ASPERR_ISSUE;
1699 break;
1700 }
1702 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1704 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1705 if (getVal < 0) {
1706 errno = -getVal;
1707 break;
1708 }
1710 for (z=OUTPUT1; z < OUTPUTN; z++) {
1711 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1712 if (getVal < 0) {
1713 errno = -getVal;
1714 break;
1715 }
1716 }
1717 if( errno )
1718 break;
1720 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1722 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1723 break;
1725 for (z=OUTPUT1; z < OUTPUTN; z++) {
1726 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1727 if (getVal > 0) {
1728 errno = ASPERR_ISSUE;
1729 break;
1730 }
1731 else if (getVal < 0) {
1732 errno = -getVal;
1733 break;
1734 }
1735 }
1736 if( errno )
1737 break;
1738 }
1740 //
1741 // Close down receive/transmit
1742 //
1744 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1746 for (z=OUTPUT1; z < OUTPUTN; z++) {
1747 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1748 if (! errno)
1749 errno = (getVal & 0xff) | ASPERR_MUTE;
1750 /* convert to sensical errno */
1751 }
1752 }
1754 SIO_idle (pC->xInp[zMI].hRxSio);
1755 for (z=OUTPUT1; z < OUTPUTN; z++)
1756 SIO_idle (pC->xOut[z].hTxSio);
1758 return errno;
1760 } //PAF_AST_passProcessing
1761 #endif // #if 0
1763 #if 0
1764 // -----------------------------------------------------------------------------
1765 // AST Processing Function Helper - Pass-Through Processing Patch Point
1766 //
1767 // Name: PAF_AST_passProcessingCopy
1768 // Purpose: Pass-Through Processing Function for copying audio data
1769 // from the input buffer to the output buffer.
1770 // From: AST Parameter Function -> passProcessing
1771 // Uses: See code.
1772 // States: x
1773 // Return: Error number in standard form (0 on success).
1774 // Trace: Message Log "trace" in Debug Project Configuration reports:
1775 // x
1776 //
1778 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1779 /* Pass Processing is often omitted from builds to save memory, */
1780 /* and CODE_SECTION/clink constructs facilitate this omission. */
1782 Int
1783 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1784 {
1785 Int z; /* output counter */
1786 Int errno; /* error number */
1787 Int i;
1788 Int rxNumChan, txNumChan;
1789 Int zMI = pP->zone.master;
1792 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1794 // Copy data from input channels to output channels one of two ways:
1796 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1797 return (ASPERR_PASS + 0x12);
1799 for (z=OUTPUT1; z < OUTPUTN; z++) {
1800 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1801 return (ASPERR_PASS + 0x22);
1803 if( txNumChan <= rxNumChan ) {
1805 // Copy one to one, ignoring later rx channels as needed.
1807 for( i=0; i < txNumChan; i++ ) {
1808 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1809 if( errno )
1810 return errno;
1811 }
1812 }
1813 else {
1815 // Copy one to many, repeating earlier rx channels as needed.
1817 Int from, to;
1819 from = 0;
1820 to = 0;
1821 while( to < txNumChan ) {
1822 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1823 if( errno )
1824 return errno;
1826 from++;
1827 to++;
1828 if( from == rxNumChan )
1829 from = 0;
1830 }
1831 }
1832 }
1834 return 0;
1835 } //PAF_AST_passProcessingCopy
1836 #endif // #if 0
1838 // -----------------------------------------------------------------------------
1839 // ASIT Processing Function - Auto Processing
1840 //
1841 // Name: PAF_ASIT_autoProcessing
1842 // Purpose: Audio Stream Input Task Function for processing audio data to
1843 // determine the input type without output.
1844 // From: audioStream1Task or equivalent
1845 // Uses: See code.
1846 // States: x
1847 // Return: Error number in standard or SIO form (0 on success).
1848 // Trace: Message Log "trace" in Debug Project Configuration reports:
1849 // * State information on initialization.
1850 //
1852 #define DECSIOMAP(X) \
1853 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1855 Int
1856 PAF_ASIT_autoProcessing(
1857 const PAF_ASIT_Params *pP,
1858 const PAF_ASIT_Patchs *pQ,
1859 PAF_ASIT_Config *pC,
1860 Int inputTypeSelect,
1861 ALG_Handle pcmAlgMaster
1862 )
1863 {
1864 PAF_AST_Config *pAstCfg;
1865 Int as; /* Audio Stream Number (1, 2, etc.) */
1866 Int errno = 0; /* error number */
1867 Int nbytes;
1868 Int frameLength;
1869 Int zMD;
1870 Int zMI;
1871 Int zMS;
1873 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1874 as = pAstCfg->as;
1875 zMD = pAstCfg->masterDec;
1876 zMS = pAstCfg->masterStr;
1877 zMI = pP->zone.master;
1879 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1881 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1882 PAF_SIO_CONTROL_SET_SOURCESELECT,
1883 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1884 {
1885 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1886 return errno;
1887 }
1888 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1889 // pC->xDec[zMD].decodeStatus.bufferRatio);
1890 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1892 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1893 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1894 {
1895 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1896 errno, ASPERR_AUTO_LENGTH);
1897 return ASPERR_AUTO_LENGTH;
1898 }
1900 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1901 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1902 PAF_SIO_REQUEST_SYNC))
1903 {
1904 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1905 errno, ASPERR_ISSUE);
1906 return ASPERR_ISSUE;
1907 }
1909 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1911 // all of the sync scan work is done in this call. If the error returned
1912 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1913 // error so we mask it off.
1914 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1915 if (nbytes == -DIBERR_SYNC)
1916 {
1917 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1918 return 0;
1919 }
1920 if (nbytes != sizeof(PAF_InpBufConfig))
1921 {
1922 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1923 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1924 return ASPERR_RECLAIM;
1925 }
1926 if (errno)
1927 {
1928 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1929 }
1930 return errno;
1931 } //PAF_ASIT_autoProcessing
1933 UInt32 gProbe1Err=0;
1934 UInt32 gProbe2Err=0;
1935 UInt32 gMajorAuMissed=0;
1937 // -----------------------------------------------------------------------------
1938 // ASIT Processing Function - Decode Processing
1939 //
1940 // Name: PAF_ASIT_decodeProcessing
1941 // Purpose: Audio Stream Input Task Function for processing audio data.
1942 // From: audioStream1Task or equivalent
1943 // Uses: See code.
1944 // States: x
1945 // Return: Error number in standard form (0 on success).
1946 // Trace: Message Log "trace" in Debug Project Configuration reports:
1947 // * State information on initialization (via children).
1948 // * State information on processing (via children).
1949 // * Decode warnings.
1950 //
1951 // When "writeDECModeContinuous" is used for zMI input/decode:
1952 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1953 // (a) if "writeDECCommandRestart" is used
1954 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1955 // (b) if "writeDECSourceSelectNone" is used
1956 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1957 // (c) if an error occurs in
1958 // INIT
1959 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1960 // -> PAF_AST_decodeCont(): "Await slave inputs"
1961 // STREAM (errno |= PAF_COMPONENT_ASP)
1962 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1963 // [ the latter errors lead to "switch_break:"
1964 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1965 //
1966 // [ Notably, in FINAL ("frame-finalization state")
1967 // -> PAF_AST_decodeFinalTest() is *not* called,
1968 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1969 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1970 //
1971 // States in which error can't occur:
1972 // AGAIN ("subsequent initial state")
1973 //
1974 // States in which (some) errors must be handled:
1975 // INFO1 ("first frame state")
1976 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1977 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1978 // ?*? but what about ASPERR_RESYNC from same call ?*?
1979 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1980 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1981 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1982 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1983 // - enc->fxns->info()
1984 // - pP->fxns->setCheckRateX()
1985 // - pP->fxns->startOutput()
1986 // - "Start slave inputs if necessary"
1987 // INFO2 ("subsequent frame state")
1988 // -> PAF_AST_decodeInfo(): (see above)
1989 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1990 // - pP->fxns->setCheckRateX()
1991 // TIME ("timing state")
1992 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1993 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1994 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1995 // (*OK* don't try to recover from this*)
1996 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1997 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1998 // possibly in PAF_AST_decodeProcessing() itself **
1999 // DECODE ("decode state")
2000 // -> PAF_AST_decodeDecode(): pass on error from
2001 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
2002 // - dec->fxns->reset()
2003 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
2004 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
2005 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
2006 Int
2007 PAF_ASIT_decodeProcessing(
2008 const PAF_ASIT_Params *pP,
2009 const PAF_ASIT_Patchs *pQ,
2010 PAF_ASIT_Config *pC,
2011 Int sourceSelect
2012 )
2013 {
2014 PAF_AST_Config *pAstCfg;
2015 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2016 Int z; /* decode counter */
2017 Int errno; /* error number */
2018 Int getVal;
2019 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
2020 ALG_Handle alg[DECODEN_MAX];
2021 Int zMD;
2022 Int zMS;
2023 Int size;
2024 //PAF_InpBufConfig *pIpBufConfig;
2025 Int frame; // decoder input frame count
2026 Int block; // (***) FL: formerly -- decoder output block count / input frame
2027 #ifdef NON_CACHE_STATUS
2028 Int8 tempVar8, temp2Var8;
2029 #endif
2031 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2032 zMD = pAstCfg->masterDec;
2033 zMS = pAstCfg->masterStr;
2035 for (z=DECODE1; z < DECODEN; z++)
2036 {
2037 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
2038 }
2039 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
2041 //
2042 // Receive and process the data in single-frame buffers
2043 //
2045 state = INIT;
2046 errno = 0; /* error number */
2048 #ifdef NON_CACHE_STATUS
2049 statusOp_read(&tempVar8,
2050 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2051 sizeof(tempVar8),
2052 GATEMP_INDEX_DEC);
2053 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
2055 for (;;)
2056 {
2057 if (tempVar8 == PAF_SOURCE_NONE)
2058 {
2059 #else
2060 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
2062 for (;;)
2063 {
2064 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
2065 {
2066 #endif
2067 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
2068 state = QUIT;
2069 }
2071 // Process commands (decode)
2072 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
2073 {
2074 if (state != INIT) // no need to restart/abort if not yet started
2075 {
2076 if (getVal == ASPERR_QUIT)
2077 {
2078 state = QUIT;
2079 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
2080 }
2081 else if (getVal == ASPERR_ABORT)
2082 {
2083 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
2084 return getVal;
2085 }
2086 else
2087 {
2088 /* ignore */;
2089 }
2090 }
2091 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
2092 }
2094 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
2095 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
2097 // Process state (decode)
2098 switch (state)
2099 {
2100 case INIT: // initial state
2101 gAsipInitCnt++;
2102 Log_info0("TaskAsip: state=INIT");
2104 // (***) FL: revisit
2105 #if 1 // status for shared beta units can change (e.g. at-boot or alpha)
2106 // write back Status structures for shared Beta Units
2107 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2108 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2109 /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2110 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2111 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2112 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2113 Cache_wait();*/
2114 #endif
2115 #if 0
2116 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2117 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2118 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2119 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2120 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2121 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2122 //Cache_wait();
2123 #endif
2125 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
2126 {
2127 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
2128 break;
2129 }
2131 #if 1
2132 // (***) FL: revisit
2133 // invalidate Status structures for shared Beta Units
2134 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2135 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2136 /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2137 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2138 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2139 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2140 Cache_wait();*/
2141 #endif
2143 frame = 0;
2144 block = 0;
2146 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2147 state = INFO1;
2148 continue;
2150 case INFO1: // first frame state
2151 gAsipInfo1Cnt++;
2152 Log_info0("TaskAsip: state=INFO1");
2154 #if 0
2155 //// (***) FL: revisit
2156 //// write back Inp configuration
2157 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2158 //// write back input data
2159 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2160 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2161 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2162 //// write back Dec configuration
2163 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2164 //Cache_wait();
2165 #endif
2167 // Establish primary timing
2168 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2169 {
2170 gProbe1Err++;
2171 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2172 break;
2173 }
2175 #if 0
2176 //// (***) FL: revisit
2177 //// invalidate Dec configuration
2178 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2179 //Cache_wait();
2180 #endif
2183 #ifdef NON_CACHE_STATUS
2184 statusOp_read(&tempVar8,
2185 &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2186 sizeof(tempVar8),
2187 GATEMP_INDEX_DEC);
2188 statusOp_read(&temp2Var8,
2189 &(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
2190 sizeof(tempVar8),
2191 GATEMP_INDEX_DEC);
2192 // Don't start decode until major access unit is found.
2193 if (((tempVar8 == PAF_SOURCE_THD) ||
2194 (tempVar8 == PAF_SOURCE_DXP) ||
2195 (tempVar8 == PAF_SOURCE_DTSHD)) &&
2196 (temp2Var8 == PAF_SAMPLERATE_UNKNOWN))
2197 #else
2198 // Don't start decode until major access unit is found.
2199 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
2200 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
2201 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2202 (pAstCfg->xDec[zMD].decodeStatus.sampleRate == PAF_SAMPLERATE_UNKNOWN))
2203 #endif
2204 {
2205 Int z;
2206 for (z=DECODE1; z < DECODEN; z++)
2207 {
2208 Int zI = pP->inputsFromDecodes[z];
2209 #ifdef NON_CACHE_STATUS
2210 statusOp_read(&tempVar8,
2211 &(pAstCfg->xDec[z].decodeStatus.mode),
2212 sizeof(tempVar8),
2213 GATEMP_INDEX_DEC);
2214 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2215 {
2216 #else
2217 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2218 {
2219 #endif
2220 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2221 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2222 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2223 {
2224 gProbe2Err++;
2225 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2226 return (ASPERR_ISSUE);
2227 }
2228 }
2229 }
2230 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2231 gMajorAuMissed++; // debug
2232 frame++;
2233 state = INFO1;
2234 continue;
2235 }
2236 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2238 // Establish secondary timing
2239 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2240 {
2241 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2242 break;
2243 }
2245 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2246 state = DECODE;
2247 continue;
2249 case INFO2: // subsequent frame state
2250 gAsipInfo2Cnt++;
2251 Log_info0("TaskAsip: state=INFO2");
2253 #if 0
2254 //// (***) FL: revisit
2255 //// write back Inp configuration
2256 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2257 //// write back input data
2258 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2259 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2260 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2261 //// write back Dec configuration
2262 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2263 //Cache_wait();
2264 #endif
2266 // Establish primary timing
2267 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2268 {
2269 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2270 gAsipInfo2_PrimaryErrCnt++;
2271 break;
2272 }
2274 #if 0
2275 //// (***) FL: revisit
2276 //// invalidate Dec configuration
2277 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2278 //Cache_wait();
2279 #endif
2281 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2282 {
2283 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2284 gAsipInfo2_ErrCnt++;
2285 break;
2286 }
2288 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2289 state = DECODE;
2290 continue;
2292 case DECODE: // decode state
2293 gAsipDecodeCnt++;
2294 Log_info0("TaskAsip: state=DECODE");
2296 #if 0
2297 //// (***) FL: revisit
2298 //// write back Dec configuration
2299 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2300 //Cache_wait();
2301 #endif
2303 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2304 {
2305 gAsipDecodeErrCnt++;
2306 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2307 break;
2308 }
2310 #if 0
2311 //// (***) FL: revisit
2312 //// invalidate Dec configuration
2313 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2314 //Cache_wait();
2315 #endif
2317 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2318 state = FINAL;
2319 continue;
2321 case FINAL: // frame-finalization state
2322 gAsipFinalCnt++;
2323 Log_info0("TaskAsip: state=FINAL");
2325 // Check for final frame, and if indicated:
2326 // - Exit state machine to "complete" processing.
2327 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2328 {
2329 break;
2330 }
2332 frame++;
2333 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2334 state = INFO2;
2335 continue;
2337 case QUIT: // exit state
2338 gAsipQuitCnt++;
2339 Log_info0("TaskAsip: state=QUIT");
2341 // Quit:
2342 // - Set error number registers.
2343 // - Exit state machine to "decode complete" processing.
2344 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2345 errno = ASPERR_QUIT;
2346 break;
2348 default: // unknown state
2350 // Unknown:
2351 // - Set error number registers.
2352 // - Exit state machine to "decode complete" processing.
2354 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2355 errno = ASPERR_UNKNOWNSTATE;
2356 break;
2358 } // End of switch (state).
2360 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2361 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2362 {
2363 /* ignored? */;
2364 }
2366 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2368 return errno;
2369 } // End of for (;;) to Receive, process, and transmit the data.
2370 } //PAF_ASIT_decodeProcessing
2372 // -----------------------------------------------------------------------------
2373 // ASIT Decoding Function - Decode Command Processing
2374 //
2375 // Name: PAF_ASIT_decodeCommand
2376 // Purpose: Decoding Function for processing Decode Commands.
2377 // From: AST Parameter Function -> decodeProcessing
2378 // Uses: See code.
2379 // States: x
2380 // Return: Error number in standard form (0 on success).
2381 // Trace: Message Log "trace" in Debug Project Configuration reports:
2382 // * Command execution.
2383 //
2385 Int
2386 PAF_ASIT_decodeCommand(
2387 const PAF_ASIT_Params *pP,
2388 const PAF_ASIT_Patchs *pQ,
2389 PAF_ASIT_Config *pC
2390 )
2391 {
2392 PAF_AST_Config *pAstCfg;
2393 Int as; /* Audio Stream Number (1, 2, etc.) */
2394 Int z; /* decode counter */
2395 Int zS;
2396 #ifdef NON_CACHE_STATUS
2397 Int8 tempVar8;
2398 #endif
2400 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2401 as = pAstCfg->as;
2403 for (z=DECODE1; z < DECODEN; z++)
2404 {
2405 zS = pP->streamsFromDecodes[z];
2406 #ifdef NON_CACHE_STATUS
2407 statusOp_read(&tempVar8,
2408 &(pAstCfg->xDec[z].decodeStatus.command2),
2409 sizeof(tempVar8),
2410 GATEMP_INDEX_DEC);
2411 if (!(tempVar8 & 0x80))
2412 {
2413 switch (tempVar8)
2414 {
2415 case 0: // command none - process
2416 tempVar8 |= 0x80;
2417 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2418 &tempVar8,
2419 sizeof(tempVar8),
2420 GATEMP_INDEX_DEC);
2421 break;
2422 case 1: // command abort - leave now
2423 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2424 tempVar8 |= 0x80;
2425 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2426 &tempVar8,
2427 sizeof(tempVar8),
2428 GATEMP_INDEX_DEC);
2429 return (ASPERR_ABORT);
2430 case 2: // command restart - leave later
2431 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2432 tempVar8 |= 0x80;
2433 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2434 &tempVar8,
2435 sizeof(tempVar8),
2436 GATEMP_INDEX_DEC);
2437 return (ASPERR_QUIT);
2438 default: // command unknown - ignore
2439 break;
2440 }
2441 }
2442 #else
2443 if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2444 {
2445 switch (pAstCfg->xDec[z].decodeStatus.command2)
2446 {
2447 case 0: // command none - process
2448 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2449 break;
2450 case 1: // command abort - leave now
2451 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2452 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2453 return (ASPERR_ABORT);
2454 case 2: // command restart - leave later
2455 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2456 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2457 return (ASPERR_QUIT);
2458 default: // command unknown - ignore
2459 break;
2460 }
2461 }
2462 #endif
2463 }
2465 return 0;
2466 } //PAF_ASIT_decodeCommand
2468 // -----------------------------------------------------------------------------
2469 // ASIT Decoding Function - Reinitialization of Decode
2470 //
2471 // Name: PAF_ASIT_decodeInit
2472 // Purpose: Decoding Function for reinitializing the decoding process.
2473 // From: AST Parameter Function -> decodeProcessing
2474 // Uses: See code.
2475 // States: x
2476 // Return: Error number in standard or SIO form (0 on success).
2477 // Trace: Message Log "trace" in Debug Project Configuration reports:
2478 // * State information as per parent.
2479 //
2480 Int
2481 PAF_ASIT_decodeInit(
2482 const PAF_ASIT_Params *pP,
2483 const PAF_ASIT_Patchs *pQ,
2484 PAF_ASIT_Config *pC,
2485 Int sourceSelect
2486 )
2487 {
2488 PAF_AST_Config *pAstCfg;
2489 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2490 Int as; /* Audio Stream Number (1, 2, etc.) */
2491 Int z; /* decode/encode counter */
2492 Int errno; /* error number */
2493 Int zI, zS;
2494 Int zMD;
2495 Int zMI;
2496 ASP_Msg* pAspMsg; /* Messaging */
2497 Int argIdx;
2498 Int decErrno;
2499 Int status;
2500 #ifdef NON_CACHE_STATUS
2501 Int8 tempVar8;
2502 #endif
2504 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2505 as = pAstCfg->as;
2506 zMD = pAstCfg->masterDec;
2507 zMI = pP->zone.master;
2508 (void)as; // clear compiler warning in case not used with tracing disabled
2510 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2512 #ifdef NON_CACHE_STATUS
2513 // reset frameCount
2514 for (z=DECODE1; z < DECODEN; z++)
2515 {
2516 statusOp_read(&tempVar8,
2517 &(pAstCfg->xDec[z].decodeStatus.mode),
2518 sizeof(tempVar8),
2519 GATEMP_INDEX_DEC);
2520 if (tempVar8)
2521 {
2522 tempVar8 = 0;
2523 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2524 &tempVar8,
2525 sizeof(tempVar8),
2526 GATEMP_INDEX_DEC);
2527 }
2528 }
2530 for (z=DECODE1; z < DECODEN; z++)
2531 {
2532 zI = pP->inputsFromDecodes[z];
2533 zS = pP->streamsFromDecodes[z];
2534 (void)zS; // clear compiler warning in case not used with tracing disabled
2535 statusOp_read(&tempVar8,
2536 &(pAstCfg->xDec[z].decodeStatus.mode),
2537 sizeof(tempVar8),
2538 GATEMP_INDEX_DEC);
2539 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2540 {
2541 #else
2542 // reset frameCount
2543 for (z=DECODE1; z < DECODEN; z++)
2544 {
2545 if (pAstCfg->xDec[z].decodeStatus.mode)
2546 {
2547 pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2548 }
2549 }
2551 for (z=DECODE1; z < DECODEN; z++)
2552 {
2553 zI = pP->inputsFromDecodes[z];
2554 zS = pP->streamsFromDecodes[z];
2555 (void)zS; // clear compiler warning in case not used with tracing disabled
2556 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2557 {
2558 #endif
2559 Uns gear;
2560 Int frameLength;
2561 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2563 // write back Dec configuration
2564 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2565 Cache_wait();
2567 // FL: send dec activate message to slave
2568 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2569 if (pAspMsg == NULL)
2570 {
2571 TRACE_TERSE0("MessageQ_alloc() failure.");
2572 SW_BREAKPOINT; // temporary
2573 return -1; // temporary
2574 }
2575 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2576 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2577 pAspMsg->procId = hAspMsgMaster->masterProcId;
2578 pAspMsg->expectResp = TRUE;
2579 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2580 argIdx = 0; // set decIdx (zone index)
2581 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2582 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2583 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2584 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2585 if (status != MessageQ_S_SUCCESS)
2586 {
2587 SW_BREAKPOINT;
2588 }
2589 // wait for dec activate complete message from slave
2590 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2591 if (status != MessageQ_S_SUCCESS)
2592 {
2593 TRACE_TERSE0("MessageQ_get() failure.");
2594 SW_BREAKPOINT; // temporary
2595 return -1; // temporary
2596 }
2597 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2598 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2599 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2600 {
2601 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2602 SW_BREAKPOINT; // temporary
2603 return -1; // temporary
2604 }
2605 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2606 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2607 // free the message
2608 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2609 if (status != MessageQ_S_SUCCESS)
2610 {
2611 SW_BREAKPOINT;
2612 }
2614 #if 0 // FL: decoder activate call, slave
2615 if (decAlg[z]->fxns->algActivate)
2616 decAlg[z]->fxns->algActivate (decAlg[z]);
2617 #endif
2619 // FL: send dec reset message to slave
2620 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2621 if (pAspMsg == NULL)
2622 {
2623 TRACE_TERSE0("MessageQ_alloc() failure.");
2624 SW_BREAKPOINT; // temporary
2625 return -1; // temporary
2626 }
2627 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2628 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2629 pAspMsg->procId = hAspMsgMaster->masterProcId;
2630 pAspMsg->expectResp = TRUE;
2631 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2632 argIdx = 0; // set decIdx
2633 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2634 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2635 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2636 // wait for dec reset complete message from slave
2637 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2638 if (status != MessageQ_S_SUCCESS)
2639 {
2640 SW_BREAKPOINT;
2641 }
2642 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2643 if (status != MessageQ_S_SUCCESS)
2644 {
2645 TRACE_TERSE0("MessageQ_get() failure.");
2646 SW_BREAKPOINT; // temporary
2647 return -1; // temporary
2648 }
2649 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2650 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2651 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2652 {
2653 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2654 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2655 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2657 argIdx = 0; // get decErrno
2658 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2659 if (decErrno != 0)
2660 {
2661 return decErrno;
2662 }
2663 }
2664 else
2665 {
2666 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2667 SW_BREAKPOINT; // temporary
2668 return -1; // temporary
2669 }
2670 // free the message
2671 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2672 if (status != MessageQ_S_SUCCESS)
2673 {
2674 SW_BREAKPOINT;
2675 }
2677 // (***) FL: revisit
2678 // invalidate Dec configuration
2679 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2680 Cache_wait();
2682 #if 0 // FL: decoder reset call, slave
2683 if (dec->fxns->reset
2684 && (errno = dec->fxns->reset (dec, NULL,
2685 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2686 return errno;
2687 #endif
2689 #ifdef NON_CACHE_STATUS
2690 gear = 0; // due to size difference
2691 statusOp_read(&gear,
2692 &(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2693 sizeof(Int8),
2694 GATEMP_INDEX_DEC);
2695 tempVar8 = gear < GEARS ? gear : 0;
2696 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2697 &tempVar8,
2698 sizeof(tempVar8),
2699 GATEMP_INDEX_DEC);
2700 #else
2701 gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2702 pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2703 #endif
2705 #if 0 // FL: change handle to decIdx (zone index)
2706 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2707 FRAMELENGTH,
2708 pC->xDec[z].decodeStatus.bufferRatio);
2709 #endif
2710 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2711 frameLength = pP->fxns->computeFrameLength(z,
2712 FRAMELENGTH,
2713 pC->xDec[z].decodeStatus.bufferRatio);
2714 #else
2715 if (sourceSelect == PAF_SOURCE_PCM)
2716 {
2717 frameLength = 256;
2718 }
2719 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2720 {
2721 frameLength = 1536;
2722 }
2723 else if (sourceSelect == PAF_SOURCE_THD)
2724 {
2725 frameLength = 1536; //QIN FIX ME
2726 }
2727 else
2728 {
2729 frameLength = 256;
2730 }
2731 #endif
2733 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2734 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2735 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2737 // (***) FL: revisit. Count samples for DDP.
2738 // Add framework frame length and running sample count to decoder control.
2739 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2740 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2742 // Initialize decoder output circular buffer for selected source
2743 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2744 if (errno)
2745 {
2746 SW_BREAKPOINT; // FL: debug
2747 return errno;
2748 }
2749 // FL: debug
2750 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2752 if (z != zMD)
2753 {
2754 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2755 {
2756 return errno;
2757 }
2758 }
2760 #ifdef NON_CACHE_STATUS
2761 statusOp_read(&tempVar8,
2762 &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2763 sizeof(Int8),
2764 GATEMP_INDEX_DEC);
2765 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2766 DECSIOMAP(tempVar8)))
2767 {
2768 return errno;
2769 }
2770 #else
2771 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2772 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2773 {
2774 return errno;
2775 }
2776 #endif
2777 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2778 frameLength))
2779 {
2780 return errno;
2781 }
2782 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2783 &pAstCfg->xInp[zI].inpBufConfig))
2784 {
2785 return errno;
2786 }
2787 }
2788 }
2790 if (pAstCfg->xInp[zMI].hRxSio)
2791 {
2792 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2793 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2794 if (errno)
2795 {
2796 return errno;
2797 }
2798 }
2800 return 0;
2801 } //PAF_AST_decodeInit
2803 // -----------------------------------------------------------------------------
2804 // ASIT Decoding Function - Info Processing, Common
2805 //
2806 // Name: PAF_ASIT_decodeInfo
2807 // Purpose: Decoding Function for processing information in a manner that
2808 // is common for both initial and subsequent frames of input data.
2809 // From: AST Parameter Function -> decodeProcessing
2810 // Uses: See code.
2811 // States: x
2812 // Return: Error number in standard form (0 on success).
2813 // Trace: Message Log "trace" in Debug Project Configuration reports:
2814 // * State information as per parent.
2815 //
2816 Int
2817 PAF_ASIT_decodeInfo(
2818 const PAF_ASIT_Params *pP,
2819 const PAF_ASIT_Patchs *pQ,
2820 PAF_ASIT_Config *pC,
2821 Int frame,
2822 Int block
2823 )
2824 {
2825 PAF_AST_Config *pAstCfg;
2826 Int as; /* Audio Stream Number (1, 2, etc.) */
2827 Int z; /* input/decode/stream counter */
2828 Int errno; /* error number */
2829 Int sioErr; /* error number, SIO */
2830 Int zD, zI, zS, zX;
2831 Int zMD;
2832 Int zMI;
2833 Int zMS;
2834 UInt32 curTime;
2835 ASP_Msg *pAspMsg; /* Messaging */
2836 Int argIdx;
2837 Int status;
2838 #ifdef NON_CACHE_STATUS
2839 Int8 tempVar8;
2840 Int tempVar;
2841 #endif
2842 // FL: revisit
2843 //Int size;
2844 //PAF_InpBufConfig *pIpBufConfig;
2846 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2847 as = pAstCfg->as;
2848 zMD = pAstCfg->masterDec;
2849 zMS = pAstCfg->masterStr;
2850 zMI = pP->zone.master;
2851 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2853 // Set decode control: sample rate, emphasis
2854 for (z=INPUT1; z < INPUTN; z++)
2855 {
2856 zD = z;
2857 for (zX = DECODE1; zX < DECODEN; zX++)
2858 {
2859 if (pP->inputsFromDecodes[zX] == z)
2860 {
2861 zD = zX;
2862 break;
2863 }
2864 }
2866 if (pAstCfg->xInp[z].hRxSio)
2867 {
2868 //determine associated decoder
2869 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2870 pAstCfg->xDec[zD].decodeControl.sampleRate)
2871 {
2872 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2873 {
2874 pAstCfg->xDec[zD].decodeControl.sampleRate =
2875 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2876 }
2877 else
2878 {
2879 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2880 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2881 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2882 pAstCfg->xDec[zD].decodeControl.sampleRate);
2883 // return (ASPERR_INFO_RATECHANGE);
2884 }
2885 }
2886 #ifdef NON_CACHE_STATUS
2887 statusOp_read(&tempVar8,
2888 &(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2889 sizeof(Int8),
2890 GATEMP_INDEX_DEC);
2891 pAstCfg->xDec[zD].decodeControl.emphasis =
2892 tempVar8 != PAF_SOURCE_PCM
2893 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2894 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2895 #else
2896 pAstCfg->xDec[zD].decodeControl.emphasis =
2897 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2898 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2899 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2900 #endif
2901 }
2902 else
2903 {
2904 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2905 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2906 }
2907 }
2909 // Wait for info input
2910 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2911 if (pAstCfg->xInp[zMI].hRxSio)
2912 {
2913 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2914 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2915 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2916 {
2917 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2918 return ASPERR_RECLAIM;
2919 }
2921 // FL: debug, capture input buffer
2923 capIb(pAstCfg->xInp[zMI].pInpBuf);
2924 gcapIb_cnt++;
2926 {
2927 static Uint8 toggleState = 0;
2928 if (toggleState == 0)
2929 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
2930 else
2931 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
2932 toggleState = ~(toggleState);
2933 }
2935 //
2936 // Simulate Rx SIO_reclaim() pend
2937 //
2938 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2939 gTaskAsipCnt++;
2940 curTime = Clock_getTicks();
2941 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2942 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2943 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2944 } //pC->xInp[zMI].hRxSio
2946 // Decode info
2947 for (z=DECODE1; z < DECODEN; z++)
2948 {
2949 zI = pP->inputsFromDecodes[z];
2950 zS = pP->streamsFromDecodes[z];
2951 (void)zS; // clear compiler warning in case not used with tracing disabled
2952 #ifdef NON_CACHE_STATUS
2953 statusOp_read(&tempVar8,
2954 &(pAstCfg->xDec[z].decodeStatus.mode),
2955 sizeof(Int8),
2956 GATEMP_INDEX_DEC);
2957 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2958 {
2959 #else
2960 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2961 {
2962 #endif
2963 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2965 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2966 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2967 {
2968 TRACE_TERSE1("return error errno 0x%x.", errno);
2969 return errno;
2970 }
2972 #if 1
2973 // (***) FL: revisit
2974 // write back Inp configuration
2975 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2976 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2977 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2978 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2979 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2980 // write back Dec configuration
2981 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2982 Cache_wait();
2983 #endif
2985 // FL: send info message to slave
2986 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2987 if (pAspMsg == NULL)
2988 {
2989 TRACE_TERSE0("MessageQ_alloc() failure.");
2990 SW_BREAKPOINT; // temporary
2991 return -1; // temporary
2992 }
2993 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2994 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
2995 pAspMsg->procId = hAspMsgMaster->masterProcId;
2996 pAspMsg->expectResp = TRUE;
2997 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2998 argIdx = 0; // set decIdx
2999 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3000 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3001 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3002 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
3003 if (status != MessageQ_S_SUCCESS)
3004 {
3005 SW_BREAKPOINT;
3006 }
3007 // wait for dec info complete message from slave -- temporary
3008 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3009 if (status != MessageQ_S_SUCCESS)
3010 {
3011 TRACE_TERSE0("MessageQ_get() failure.");
3012 SW_BREAKPOINT;
3013 return -1; // temporary
3014 }
3015 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
3016 (pAspMsg->cmd != ASP_MASTER_DEC_INFO_DONE) ||
3017 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3018 {
3019 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3020 SW_BREAKPOINT; // temporary
3021 }
3022 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3023 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3024 // free the message
3025 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3026 if (status != MessageQ_S_SUCCESS)
3027 {
3028 SW_BREAKPOINT;
3029 }
3031 #if 1
3032 // (***) FL: revisit
3033 // invalidate Dec configuration
3034 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3035 Cache_wait();
3036 #endif
3038 #if 0 // FL: decoder info call, slave
3039 if (dec->fxns->info
3040 && (errno = dec->fxns->info (dec, NULL,
3041 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3042 #endif
3043 if (errno)
3044 {
3045 TRACE_TERSE1("return error errno 0x%x.", errno);
3046 return errno;
3047 }
3048 #ifdef NON_CACHE_STATUS
3049 statusOp_read(&tempVar,
3050 &(pAstCfg->xDec[z].decodeStatus.frameCount),
3051 sizeof(Int),
3052 GATEMP_INDEX_DEC);
3053 // increment decoded frame count
3054 tempVar += 1;
3055 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
3056 &tempVar,
3057 sizeof(Int),
3058 GATEMP_INDEX_DEC);
3059 #else
3060 // increment decoded frame count
3061 pAstCfg->xDec[z].decodeStatus.frameCount += 1;
3062 #endif
3063 }
3064 } // z=DECODE1 to DECODEN
3066 #ifdef NON_CACHE_STATUS
3067 statusOp_read(&tempVar8,
3068 &(pAstCfg->xDec[zMD].decodeStatus.mode),
3069 sizeof(Int8),
3070 GATEMP_INDEX_DEC);
3071 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
3072 if (tempVar8)
3073 {
3074 XDAS_Int8 sourceProgram;
3075 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
3076 (Arg)&sourceProgram))
3077 {
3078 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
3079 return ASPERR_AUTO_PROGRAM;
3080 }
3081 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3082 &(sourceProgram),
3083 sizeof(Int8),
3084 GATEMP_INDEX_DEC);
3085 }
3087 // since now decoding update decode status for all enabled decoders
3088 for (z=DECODE1; z < DECODEN; z++)
3089 {
3090 statusOp_read(&tempVar8,
3091 &(pAstCfg->xDec[z].decodeStatus.mode),
3092 sizeof(Int8),
3093 GATEMP_INDEX_DEC);
3094 if (tempVar8)
3095 {
3096 statusOp_read(&tempVar8,
3097 &(pAstCfg->xDec[z].decodeStatus.sourceProgram),
3098 sizeof(Int8),
3099 GATEMP_INDEX_DEC);
3100 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3101 &tempVar8,
3102 sizeof(Int8),
3103 GATEMP_INDEX_DEC);
3104 statusOp_read(&tempVar8,
3105 &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
3106 sizeof(Int8),
3107 GATEMP_INDEX_DEC);
3108 if (tempVar8 == PAF_SOURCE_SNG)
3109 {
3110 tempVar8 = PAF_SOURCE_SNG;
3111 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3112 &tempVar8,
3113 sizeof(Int8),
3114 GATEMP_INDEX_DEC);
3115 }
3116 }
3117 }
3118 #else
3119 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
3120 if (pAstCfg->xDec[zMD].decodeStatus.mode)
3121 {
3122 XDAS_Int8 sourceProgram;
3123 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
3124 (Arg)&sourceProgram))
3125 {
3126 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
3127 return ASPERR_AUTO_PROGRAM;
3128 }
3129 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
3130 }
3132 // since now decoding update decode status for all enabled decoders
3133 for (z=DECODE1; z < DECODEN; z++)
3134 {
3135 if (pAstCfg->xDec[z].decodeStatus.mode)
3136 {
3137 pAstCfg->xDec[z].decodeStatus.sourceDecode = pAstCfg->xDec[z].decodeStatus.sourceProgram;
3138 if (pAstCfg->xDec[z].decodeStatus.sourceSelect == PAF_SOURCE_SNG)
3139 {
3140 pAstCfg->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_SNG;
3141 }
3142 }
3143 }
3144 #endif
3146 #if 0 // FL: ASDT (slave)
3147 // TODO: move this to start of this function so that it doesn't affect IO timing
3148 // Initialize audio frame(s)
3149 // Re-initialize audio frame if there is an associated decode and
3150 // that decode doesn't have a valid input or is turned off
3151 for (z=STREAM1; z < STREAMN; z++)
3152 {
3153 Int reset = 0;
3154 for (zX = DECODE1; zX < DECODEN; zX++)
3155 {
3156 if (pP->streamsFromDecodes[zX] == z)
3157 {
3158 zI = pP->inputsFromDecodes[zX];
3159 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3160 {
3161 reset = 1;
3162 }
3163 }
3164 }
3165 if (reset)
3166 {
3167 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
3168 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3169 }
3170 else
3171 {
3172 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
3173 }
3174 }
3175 #endif
3177 return 0;
3178 } //PAF_ASIT_decodeInfo
3180 // -----------------------------------------------------------------------------
3181 // ASIT Decoding Function - Info Processing, Initial
3182 //
3183 // Name: PAF_ASIT_decodeInfo1
3184 // Purpose: Decoding Function for processing information in a manner that
3185 // is unique to initial frames of input data.
3186 // From: AST Parameter Function -> decodeProcessing
3187 // Uses: See code.
3188 // States: x
3189 // Return: Error number in standard or SIO form (0 on success).
3190 // Trace: Message Log "trace" in Debug Project Configuration reports:
3191 // * State information as per parent.
3192 //
3193 Int
3194 PAF_ASIT_decodeInfo1(
3195 const PAF_ASIT_Params *pP,
3196 const PAF_ASIT_Patchs *pQ,
3197 PAF_ASIT_Config *pC,
3198 Int frame,
3199 Int block
3200 )
3201 {
3202 return 0;
3203 } //PAF_ASIT_decodeInfo1
3205 // -----------------------------------------------------------------------------
3206 // AST Decoding Function - Info Processing, Subsequent
3207 //
3208 // Name: PAF_AST_decodeInfo2
3209 // Purpose: Decoding Function for processing information in a manner that
3210 // is unique to frames of input data other than the initial one.
3211 // From: AST Parameter Function -> decodeProcessing
3212 // Uses: See code.
3213 // States: x
3214 // Return: Error number in standard form (0 on success).
3215 // Trace: None.
3216 //
3217 Int
3218 PAF_ASIT_decodeInfo2(
3219 const PAF_ASIT_Params *pP,
3220 const PAF_ASIT_Patchs *pQ,
3221 PAF_ASIT_Config *pC,
3222 Int frame,
3223 Int block
3224 )
3225 {
3226 return 0;
3227 } //PAF_ASIT_decodeInfo2
3229 // -----------------------------------------------------------------------------
3230 // AST Decoding Function - Continuation Processing
3231 //
3232 // Name: PAF_AST_decodeCont
3233 // Purpose: Decoding Function for processing that occurs subsequent to
3234 // information processing but antecedent to timing processing
3235 // for frames of input data other than the initial one.
3236 // From: AST Parameter Function -> decodeProcessing
3237 // Uses: See code.
3238 // States: x
3239 // Return: Error number in standard form (0 on success).
3240 // Trace: Message Log "trace" in Debug Project Configuration reports:
3241 // * State information as per parent.
3242 //
3244 Int
3245 PAF_AST_decodeCont(
3246 const PAF_ASIT_Params *pP,
3247 const PAF_ASIT_Patchs *pQ,
3248 PAF_ASIT_Config *pC,
3249 ALG_Handle decAlg[],
3250 Int frame,
3251 Int block
3252 )
3253 {
3254 PAF_AST_Config *pAstCfg;
3255 Int as; /* Audio Stream Number (1, 2, etc.) */
3256 Int z; /* decode counter */
3257 Int zI, zS;
3258 Int zMD;
3259 #ifdef NON_CACHE_STATUS
3260 Int8 tempVar8;
3261 #endif
3264 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3265 as = pAstCfg->as;
3266 zMD = pAstCfg->masterDec;
3267 (void)as; // clear compiler warning in case not used with tracing disabled
3269 // Await slave inputs
3270 for (z=DECODE1; z < DECODEN; z++)
3271 {
3272 zI = pP->inputsFromDecodes[z];
3273 zS = pP->streamsFromDecodes[z];
3274 (void)zS;
3275 #ifdef NON_CACHE_STATUS
3276 statusOp_read(&tempVar8,
3277 &(pAstCfg->xDec[z].decodeStatus.mode),
3278 sizeof(Int8),
3279 GATEMP_INDEX_DEC);
3280 if (z == zMD
3281 || ! pAstCfg->xInp[zI].hRxSio
3282 || ! tempVar8)
3283 continue;
3284 #else
3285 if (z == zMD
3286 || ! pAstCfg->xInp[zI].hRxSio
3287 || ! pAstCfg->xDec[z].decodeStatus.mode)
3288 continue;
3289 #endif
3290 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
3291 if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
3292 != sizeof (pAstCfg->xInp[zI].inpBufConfig))
3293 return (ASPERR_RECLAIM);
3294 }
3296 return 0;
3297 } //PAF_AST_decodeCont
3299 // -----------------------------------------------------------------------------
3300 // ASIT Decoding Function - Decode Processing
3301 //
3302 // Name: PAF_ASIT_decodeDecode
3303 // Purpose: Decoding Function for processing of input data by the
3304 // Decode Algorithm.
3305 // From: AST Parameter Function -> decodeProcessing
3306 // Uses: See code.
3307 // States: x
3308 // Return: Error number in standard form (0 on success).
3309 // Trace: Message Log "trace" in Debug Project Configuration reports:
3310 // * State information as per parent.
3311 //
3312 Int
3313 PAF_ASIT_decodeDecode(
3314 const PAF_ASIT_Params *pP,
3315 const PAF_ASIT_Patchs *pQ,
3316 PAF_ASIT_Config *pC,
3317 Int sourceSelect,
3318 Int frame,
3319 Int block
3320 )
3321 {
3322 PAF_AST_Config *pAstCfg;
3323 Int as; /* Audio Stream Number (1, 2, etc.) */
3324 Int z; /* decode/stream counter */
3325 Int errno; /* error number */
3326 //Int ch;
3327 ASP_Msg *pAspMsg; /* Messaging */
3328 Int argIdx;
3329 Int status;
3330 Int cbErrno;
3331 Int frameLength;
3333 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3334 as = pAstCfg->as;
3335 (void)as; // clear compiler warning in case not used with tracing disabled
3337 #if 0 // FL: slave
3338 // Clear samsiz for all channels - MID 208.
3339 for (z=STREAM1; z < STREAMN; z++)
3340 {
3341 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
3342 {
3343 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
3344 }
3345 }
3346 #endif
3348 // Decode data
3349 for (z=DECODE1; z < DECODEN; z++)
3350 {
3351 Int zI = pP->inputsFromDecodes[z];
3352 Int zS = pP->streamsFromDecodes[z];
3353 (void)zS; // clear compiler warning in case not used with tracing disabled
3354 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3355 {
3356 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
3358 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
3359 as+zS,
3360 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
3361 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
3363 // FL: debug, capture input buffer
3364 //capIbPcm(pAstCfg->xInp[z].pInpBuf);
3366 // (***) FL: revisit
3367 // write back Dec configuration
3368 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3369 Cache_wait();
3371 // FL: send decode message to slave
3372 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3373 if (pAspMsg == NULL)
3374 {
3375 TRACE_TERSE0("MessageQ_alloc() failure.");
3376 SW_BREAKPOINT; // temporary
3377 return -1; // temporary
3378 }
3379 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3380 pAspMsg->cmd = ASP_SLAVE_DEC_DECODE; /* fill in message payload */
3381 pAspMsg->procId = hAspMsgMaster->masterProcId;
3382 pAspMsg->expectResp = TRUE;
3383 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3384 argIdx = 0; // set decIdx
3385 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3386 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3387 TRACE_MSG1("decIdx=%d", pAspMsg->buf[argIdx]);
3388 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3389 if (status != MessageQ_S_SUCCESS)
3390 {
3391 SW_BREAKPOINT;
3392 }
3393 // wait for decode complete message from slave -- temporary
3394 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3395 if (status != MessageQ_S_SUCCESS)
3396 {
3397 TRACE_TERSE0("MessageQ_get() failure.");
3398 SW_BREAKPOINT; // temporary
3399 return -1; // temporary
3400 }
3401 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
3402 (pAspMsg->cmd == ASP_MASTER_DEC_DECODE_DONE) &&
3403 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3404 {
3405 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3406 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3408 argIdx = 0;
3409 errno = *(Int32 *)&pAspMsg->buf[argIdx];
3410 argIdx += sizeof(Int32);
3411 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
3412 if (cbErrno != 0)
3413 {
3414 TRACE_TERSE1("CB write error=%d", cbErrno);
3415 SW_BREAKPOINT; // temporary
3416 }
3417 }
3418 else
3419 {
3420 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3421 SW_BREAKPOINT; // temporary
3422 }
3423 // free the message
3424 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3425 if (status != MessageQ_S_SUCCESS)
3426 {
3427 SW_BREAKPOINT;
3428 }
3430 // (***) FL: revisit
3431 // invalidate Dec configuration
3432 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3433 Cache_wait();
3435 #if 0 // FL: decoder decode call, slave
3436 if (dec->fxns->decode
3437 && (errno = dec->fxns->decode (dec, NULL,
3438 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
3439 #endif
3440 if (errno)
3441 {
3442 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
3443 return errno;
3444 }
3446 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3447 as_traceChannels(pC, z);
3448 #endif
3450 #if 0 // FL: change handle to decIdx (zone index)
3451 frameLength = pP->fxns->computeFrameLength(decAlg[z],
3452 FRAMELENGTH,
3453 pC->xDec[z].decodeStatus.bufferRatio);
3454 #endif
3455 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
3456 frameLength = pP->fxns->computeFrameLength(z,
3457 FRAMELENGTH,
3458 pC->xDec[z].decodeStatus.bufferRatio);
3459 #else
3460 if (sourceSelect == PAF_SOURCE_PCM)
3461 {
3462 frameLength = 256;
3463 }
3464 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
3465 {
3466 frameLength = 1536;
3467 }
3468 else if (sourceSelect == PAF_SOURCE_THD)
3469 {
3470 frameLength = 1536; //QIN FIX ME
3471 }
3472 else
3473 {
3474 frameLength = 256;
3475 }
3476 #endif
3478 // ............................................................................
3480 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3481 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3482 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3483 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3484 {
3485 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3486 return errno;
3487 }
3489 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3490 if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3491 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3492 PAF_SIO_REQUEST_NEWFRAME))
3493 {
3494 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3495 return (ASPERR_ISSUE);
3496 }
3497 } // hRxSio && decodeStatus.mode
3498 else
3499 {
3500 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3501 }
3502 } // z=DECODE1 to DECODEN
3504 #if 0 // FL: ASDT (slave)
3505 // Set up audio frames not decoded into
3506 // Re-initialize audio frame if there is an assocatiated decode and
3507 // that decode doesn't have a valid input or is turned off
3508 for (z=STREAM1; z < STREAMN; z++)
3509 {
3510 Int zX;
3511 Int reset = 0;
3512 for (zX = DECODE1; zX < DECODEN; zX++)
3513 {
3514 if (pP->streamsFromDecodes[zX] == z)
3515 {
3516 Int zI = pP->inputsFromDecodes[zX];
3517 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3518 reset = 1;
3519 }
3520 }
3521 if (reset)
3522 {
3523 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3524 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3525 }
3526 else
3527 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3528 }
3529 #endif
3531 return 0;
3532 } //PAF_ASIT_decodeDecode
3534 // -----------------------------------------------------------------------------
3535 // ASIT Decoding Function - Frame-Final Processing
3536 //
3537 // Name: PAF_ASIT_decodeFinalTest
3538 // Purpose: Decoding Function for determining whether processing of the
3539 // current frame is complete.
3540 // From: AST Parameter Function -> decodeProcessing
3541 // Uses: See code.
3542 // States: x
3543 // Return: 0 if incomplete, and 1 if complete.
3544 // Trace: None.
3545 //
3547 Int
3548 PAF_ASIT_decodeFinalTest(
3549 const PAF_ASIT_Params *pP,
3550 const PAF_ASIT_Patchs *pQ,
3551 PAF_ASIT_Config *pC,
3552 Int frame,
3553 Int block
3554 )
3555 {
3556 PAF_AST_Config *pAstCfg;
3557 Int zMD;
3558 Int sourceSelect;
3559 Int sourceProgram;
3560 #ifdef NON_CACHE_STATUS
3561 Int8 tempVar8, temp2Var8;
3562 #endif
3564 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3565 zMD = pAstCfg->masterDec;
3567 #ifdef NON_CACHE_STATUS
3568 statusOp_read(&tempVar8,
3569 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3570 sizeof(Int8),
3571 GATEMP_INDEX_DEC);
3572 sourceSelect = tempVar8;
3573 statusOp_read(&tempVar8,
3574 &(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3575 sizeof(Int8),
3576 GATEMP_INDEX_DEC);
3577 sourceProgram = tempVar8;
3578 #else
3579 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
3580 sourceProgram = pAstCfg->xDec[zMD].decodeStatus.sourceProgram;
3581 #endif
3583 if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3584 {
3585 return 1;
3586 }
3588 // The following allows for Force modes to switch without command deferral. This might
3589 // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3590 if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
3591 {
3592 if (sourceSelect == PAF_SOURCE_DTSALL)
3593 {
3594 if (sourceProgram != PAF_SOURCE_DTS11 &&
3595 sourceProgram != PAF_SOURCE_DTS12 &&
3596 sourceProgram != PAF_SOURCE_DTS13 &&
3597 sourceProgram != PAF_SOURCE_DTS14 &&
3598 sourceProgram != PAF_SOURCE_DTS16 &&
3599 sourceProgram != PAF_SOURCE_DTSHD)
3600 {
3601 return 1;
3602 }
3603 }
3604 else if (sourceSelect == PAF_SOURCE_PCMAUTO)
3605 {
3606 if (sourceProgram != PAF_SOURCE_PCM)
3607 {
3608 return 1;
3609 }
3610 }
3611 else
3612 {
3613 #ifdef NON_CACHE_STATUS
3614 statusOp_read(&tempVar8,
3615 &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
3616 sizeof(Int8),
3617 GATEMP_INDEX_DEC);
3618 statusOp_read(&temp2Var8,
3619 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3620 sizeof(Int8),
3621 GATEMP_INDEX_DEC);
3622 if (temp2Var8 != tempVar8)
3623 {
3624 return 1;
3625 }
3626 #else
3627 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect != pAstCfg->xDec[zMD].decodeStatus.sourceDecode)
3628 {
3629 return 1;
3630 }
3631 #endif
3632 }
3633 }
3635 return 0;
3636 } //PAF_ASIT_decodeFinalTest
3638 // -----------------------------------------------------------------------------
3639 // ASIT Decoding Function - Stream-Final Processing
3640 //
3641 // Name: PAF_ASIT_decodeComplete
3642 // Purpose: Decoding Function for terminating the decoding process.
3643 // From: AST Parameter Function -> decodeProcessing
3644 // Uses: See code.
3645 // States: x
3646 // Return: 0.
3647 // Trace: Message Log "trace" in Debug Project Configuration reports:
3648 // * State information as per parent.
3649 //
3650 Int
3651 PAF_ASIT_decodeComplete(
3652 const PAF_ASIT_Params *pP,
3653 const PAF_ASIT_Patchs *pQ,
3654 PAF_ASIT_Config *pC,
3655 ALG_Handle decAlg[],
3656 Int frame,
3657 Int block
3658 )
3659 {
3660 PAF_AST_Config *pAstCfg;
3661 Int as; /* Audio Stream Number (1, 2, etc.) */
3662 Int z; /* decode/encode counter */
3663 ASP_Msg* pAspMsg;
3664 Int argIdx;
3665 Int errno; /* error number */
3666 Int status;
3667 #ifdef NON_CACHE_STATUS
3668 Int8 tempVar8;
3669 #endif
3672 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3673 as = pAstCfg->as;
3674 (void)as; // clear compiler warning in case not used with tracing disabled
3676 #ifdef PAF_ASP_FINAL
3677 /* This material is currently not utilized */
3678 #endif /* PAF_ASP_FINAL */
3679 for (z=DECODE1; z < DECODEN; z++)
3680 {
3681 #ifdef PAF_ASP_FINAL
3682 DEC_Handle dec = (DEC_Handle )decAlg[z];
3683 #endif /* PAF_ASP_FINAL */
3684 Int zI = pP->inputsFromDecodes[z];
3685 #ifdef NON_CACHE_STATUS
3686 statusOp_read(&tempVar8,
3687 &(pAstCfg->xDec[z].decodeStatus.mode),
3688 sizeof(Int8),
3689 GATEMP_INDEX_DEC);
3690 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
3691 {
3692 #else
3693 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3694 {
3695 #endif
3696 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3697 #ifdef PAF_ASP_FINAL
3698 if (dec->fxns->final)
3699 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3700 &pAstCfg->xDec[z].decodeStatus);
3701 #endif /* PAF_ASP_FINAL */
3702 // FL: send dec deactivate message to slave
3703 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3704 if (pAspMsg == NULL)
3705 {
3706 TRACE_TERSE0("MessageQ_alloc() failure.");
3707 errno = -1; // temporary
3708 return errno;
3709 }
3710 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3711 pAspMsg->cmd = ASP_SLAVE_DEC_DEACTIVATE; /* fill in message payload */
3712 pAspMsg->procId = hAspMsgMaster->masterProcId;
3713 pAspMsg->expectResp = TRUE;
3714 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3715 argIdx = 0; // set decIdx
3716 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3717 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3718 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3719 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3720 if (status != MessageQ_S_SUCCESS)
3721 {
3722 SW_BREAKPOINT;
3723 }
3724 // wait for dec deactivate complete message from slave
3725 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3726 if (status != MessageQ_S_SUCCESS)
3727 {
3728 TRACE_TERSE0("MessageQ_get() failure.");
3729 return errno;
3730 }
3731 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
3732 (pAspMsg->cmd != ASP_MASTER_DEC_DEACTIVATE_DONE) ||
3733 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3734 {
3735 TRACE_MSG3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3736 SW_BREAKPOINT; // temporary
3737 }
3738 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3739 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3740 // free the message
3741 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3742 if (status != MessageQ_S_SUCCESS)
3743 {
3744 SW_BREAKPOINT;
3745 }
3747 #if 0 // FL: decoder deactivate call, slave
3748 if (decAlg[z]->fxns->algDeactivate)
3749 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3750 #endif
3751 }
3752 else
3753 {
3754 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3755 }
3756 }
3757 return 0;
3758 } //PAF_ASIT_decodeComplete
3760 // -----------------------------------------------------------------------------
3761 // ASIT Selection Function - Input Device Selection
3762 //
3763 // Name: PAF_ASIT_selectDevices
3764 // Purpose: Audio Stream Input Task Function for selecting the devices used
3765 // for input.
3766 // From: audioStream1Task or equivalent
3767 // Uses: See code.
3768 // States: x
3769 // Return: Error number in standard form (0 on success).
3770 // Trace: Message Log "trace" in Debug Project Configuration reports:
3771 // * State information as per parent.
3772 //
3773 Int
3774 PAF_ASIT_selectDevices(
3775 const PAF_ASIT_Params *pP,
3776 const PAF_ASIT_Patchs *pQ,
3777 PAF_ASIT_Config *pC
3778 )
3779 {
3780 PAF_AST_Config *pAstCfg;
3781 Int as; /* Audio Stream Number (1, 2, etc.) */
3782 Int z; /* input/output counter */
3783 Int errno = 0; /* error number */
3784 Int errme; /* error number, local */
3785 Int device;
3786 Int zMD;
3788 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3789 as = pAstCfg->as;
3790 zMD = pAstCfg->masterDec;
3791 (void)as; // clear compiler warning in case not used with tracing disabled
3793 // Select input devices
3794 for (z=INPUT1; z < INPUTN; z++)
3795 {
3796 if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0)
3797 {
3798 TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3800 // check for valid index into device array
3801 if (device >= pQ->devinp->n)
3802 {
3803 device = 0; /* treat as device None */
3804 }
3806 errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3807 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3809 if (errme)
3810 {
3811 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3812 if (!errno)
3813 {
3814 errno = ASPERR_DEVINP + errme;
3815 }
3816 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3817 }
3818 else
3819 {
3820 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3821 // register decodeStatus pointer with input devices
3822 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3823 // Use zMIs decodeStatus for all inputs
3824 if (pAstCfg->xInp[z].hRxSio)
3825 {
3826 // register PAF_SIO_IALG object address
3827 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR,
3828 (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3829 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR,
3830 (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3831 }
3832 }
3833 }
3834 }
3836 return errno;
3837 } //PAF_ASIT_selectDevices
3839 // -----------------------------------------------------------------------------
3840 // ASIT Selection Function - Source Selection
3841 //
3842 // Name: PAF_ASIT_sourceDecode
3843 // Purpose: Audio Input Stream Task Function for selecting the sources used
3844 // for decoding of input to output.
3845 // From: audioStream1Task or equivalent
3846 // Uses: See code.
3847 // States: x
3848 // Return: 0.
3849 // Trace: None.
3850 //
3851 Int
3852 PAF_ASIT_sourceDecode(
3853 const PAF_ASIT_Params *pP,
3854 const PAF_ASIT_Patchs *pQ,
3855 PAF_ASIT_Config *pC,
3856 Int x
3857 )
3858 {
3859 PAF_AST_Config *pAstCfg;
3860 Int z; /* decode counter */
3861 #ifdef NON_CACHE_STATUS
3862 Int8 tempVar8;
3863 #endif
3865 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3867 for (z=DECODE1; z < DECODEN; z++)
3868 {
3869 #ifdef NON_CACHE_STATUS
3870 statusOp_read(&tempVar8,
3871 &(pAstCfg->xDec[z].decodeStatus.mode),
3872 sizeof(Int8),
3873 GATEMP_INDEX_DEC);
3874 if (tempVar8)
3875 {
3876 tempVar8 = x;
3877 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3878 &tempVar8,
3879 sizeof(Int8),
3880 GATEMP_INDEX_DEC);
3881 }
3882 #else
3883 if (pAstCfg->xDec[z].decodeStatus.mode)
3884 {
3885 pAstCfg->xDec[z].decodeStatus.sourceDecode = x;
3886 }
3887 #endif
3888 }
3890 return 0;
3891 } //PAF_ASIT_sourceDecode
3893 // -----------------------------------------------------------------------------
3895 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3896 Int
3897 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3898 {
3899 Int errno = 0;
3900 Int zMD = pC->masterDec;
3901 Int zI = pP->inputsFromDecodes[z];
3903 // only handle real errors, on primary input, for writeDECModeContinuous
3904 if ( !( error &&
3905 z == zMD ))
3906 return error;
3908 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3909 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3911 if (pC->xInp[zI].hRxSio) {
3912 DEC_Handle dec;
3914 if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3915 return errno;
3917 // indicates (primary) input not running
3918 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3920 pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3922 // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3923 pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3925 if (decAlg[z]->fxns->algDeactivate)
3926 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3928 decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3929 dec = (DEC_Handle )decAlg[z];
3931 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3932 pC->as+z));
3934 if (decAlg[z]->fxns->algActivate)
3935 decAlg[z]->fxns->algActivate (decAlg[z]);
3937 if (dec->fxns->reset
3938 && (errno = dec->fxns->reset (dec, NULL,
3939 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3940 return errno;
3941 }
3943 return errno;
3944 } //PAF_AST_decodeHandleErrorInput
3945 #endif
3947 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3949 //------------------------------------------------------------------------------
3950 static int sSkipCount = 0;
3951 int gReportBuffers = 0;
3952 void as_traceChannels(PAF_AST_Config *pC, int z)
3953 {
3954 PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3955 int i;
3957 // #ifdef THIS_IS_DSPA
3958 sSkipCount++;
3959 if (sSkipCount<1)
3960 return;
3961 sSkipCount = 0;
3962 // #endif
3964 #ifdef THIS_IS_DSPB
3965 if (!gReportBuffers)
3966 return;
3967 gReportBuffers = 0;
3968 #endif
3970 dp(NULL, "\n");
3971 for (i=0; i<PAF_MAXNUMCHAN; i++)
3972 {
3973 if (pAudioFrame->data.sample[i] != 0)
3974 {
3975 float *wp = (float*)pAudioFrame->data.sample[i];
3976 dp(NULL, "i: %d. p: 0x%x. %f, %f, %f, %f\n",
3977 i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
3978 }
3979 }
3980 }
3981 #endif