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