2 /*
3 Copyright (c) 2017, 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"
67 #include "statusOp_common.h"
69 #include "pfp/pfp.h"
70 #include "pfp_app.h" /* contains all PFP ID's */
71 Int32 gNumPfpAsit1=0; // debug
72 Int32 gNumPfpAsit2=0;
76 // FL: debug
77 #include "dbgCapAf.h"
80 // -----------------------------------------------------------------------------
81 // Debugging Trace Control, local to this file.
82 //
83 #include "logp.h"
85 #define TRACE_ARC(a)
87 // allows you to set a different trace module in pa.cfg
88 #define TR_MOD trace
90 // Allow a developer to selectively enable tracing.
91 #define CURRENT_TRACE_MASK 0x21
93 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
94 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
95 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
96 #define TRACE_MASK_DATA 0x08 // Show data
97 #define TRACE_MASK_TIME 0x10 // Timing related traces
98 #define TRACE_MASK_MSG 0x20 // Message related traces
100 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
101 #undef TRACE_TERSE0
102 #undef TRACE_TERSE1
103 #undef TRACE_TERSE2
104 #undef TRACE_TERSE3
105 #undef TRACE_TERSE4
106 #define TRACE_TERSE0(a)
107 #define TRACE_TERSE1(a,b)
108 #define TRACE_TERSE2(a,b,c)
109 #define TRACE_TERSE3(a,b,c,d)
110 #define TRACE_TERSE4(a,b,c,d,e)
111 #endif
113 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
114 #undef TRACE_GEN0
115 #undef TRACE_GEN1
116 #undef TRACE_GEN2
117 #undef TRACE_GEN3
118 #undef TRACE_GEN4
119 #define TRACE_GEN0(a)
120 #define TRACE_GEN1(a,b)
121 #define TRACE_GEN2(a,b,c)
122 #define TRACE_GEN3(a,b,c,d)
123 #define TRACE_GEN4(a,b,c,d,e)
124 #endif
126 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
127 // consolidate list of processing strings, indexed by PAF_SOURCE
128 static char *procName[] =
129 {
130 "", //PAF_SOURCE_UNKNOWN
131 "", //PAF_SOURCE_NONE
132 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
133 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
134 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
135 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
136 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
137 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
138 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
139 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
140 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
142 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
143 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
144 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
145 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
146 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
147 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
148 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
149 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
150 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
151 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
152 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
153 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
154 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
155 "AS%d: THD processing ...", //PAF_SOURCE_THD
156 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
157 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
158 };
160 #else
161 #undef TRACE_VERBOSE0
162 #undef TRACE_VERBOSE1
163 #undef TRACE_VERBOSE2
164 #undef TRACE_VERBOSE3
165 #undef TRACE_VERBOSE4
166 #define TRACE_VERBOSE0(a)
167 #define TRACE_VERBOSE1(a,b)
168 #define TRACE_VERBOSE2(a,b,c)
169 #define TRACE_VERBOSE3(a,b,c,d)
170 #define TRACE_VERBOSE4(a,b,c,d,e)
171 #endif
173 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
174 #define TRACE_DATA(a) LOG_printf a
175 #else
176 #define TRACE_DATA(a)
177 #endif
179 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
180 #define TRACE_TIME(a) LOG_printf a
181 #define TIME_MOD trace // this could be different
182 static Int dtime()
183 {
184 static Int old_time = 0;
185 Int time = TSK_time();
186 Int delta_time = time - old_time;
187 old_time = time;
188 return( delta_time);
189 }
191 static char *stateName[11] =
192 {
193 "INIT",
194 "INFO1",
195 "AGAIN",
196 "INFO2",
197 "CONT",
198 "TIME",
199 "DECODE",
200 "STREAM",
201 "ENCODE",
202 "FINAL",
203 "QUIT"
204 };
206 #else
207 #define TRACE_TIME(a)
208 #endif
210 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
211 #undef TRACE_MSG0
212 #undef TRACE_MSG1
213 #undef TRACE_MSG2
214 #undef TRACE_MSG3
215 #undef TRACE_MSG4
216 #define TRACE_MSG0(a)
217 #define TRACE_MSG1(a,b)
218 #define TRACE_MSG2(a,b,c)
219 #define TRACE_MSG3(a,b,c,d)
220 #define TRACE_MSG4(a,b,c,d,e)
221 #endif
224 // .............................................................................
226 #include <pafsio.h>
227 #include "paferr.h"
229 #include <acp_mds.h>
231 #include <pcm.h>
233 #include <pce.h>
235 #include <doberr.h>
237 #include <diberr.h>
239 #include <stdasp.h>
241 #include "as0.h"
242 #include "asperr.h"
244 #include "audioStreamProc_params.h"
245 #include "audioStreamProc_patchs.h"
246 #include "audioStreamProc_config.h"
247 #include "audioStreamInpProc.h"
250 #include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
251 #ifdef _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
252 //
253 // Performing PCM high-sampling rate + SRC + CAR benchmarking
254 //
256 #define PROFILER
257 #endif
259 #ifdef PROFILER
260 extern UInt32 start_profiling;
261 #endif
263 extern UInt32 gAspProfileEnable;
265 //
266 // Audio Stream Definitions
267 //
269 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
270 #define MINFRAMELENGTH 24
271 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
274 //
275 // Decoder Definitions
276 //
277 //#define decLinkInit pQ->i_decLinkInit
279 //
280 // Audio Stream Processing Definitions
281 //
282 //#define aspLinkInit pQ->i_aspLinkInit
284 //
285 // Encoder Definitions
286 //
287 #define encLinkInit pQ->i_encLinkInit
289 //
290 // Input, Output Definitions
291 //
292 #define inpLinkInit pP->i_inpLinkInit
293 //#define outLinkInit pP->i_outLinkInit
295 /* ---------------------------------------------------------------- */
296 /* Parameter macro definitions end here. */
297 /* ---------------------------------------------------------------- */
299 //
300 // Standardized Definitions
301 //
303 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
304 //#define ENC_Handle PCE_Handle /* works for all: PCE */
306 #define __TASK_NAME__ "TaskAsip"
308 LINNO_DEFN(TaskAsip); /* Line number macros */
309 ERRNO_DEFN(TaskAsip); /* Error number macros */
311 // ASIT configuration
312 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
313 PAF_ASIT_Config gPAF_ASIT_config = {
314 NULL, // taskHandle
315 NULL, // acp
316 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
317 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
318 };
320 // Global debug counters */
321 UInt32 gTaskAsipCnt =0;
322 UInt32 gAsipInitCnt =0;
323 UInt32 gAsipInfo1Cnt =0;
324 UInt32 gAsipInfo2Cnt =0;
325 UInt32 gAsipDecodeCnt =0;
326 UInt32 gAsipDecodeErrCnt =0;
327 UInt32 gAsipFinalCnt =0;
328 UInt32 gAsipQuitCnt =0;
329 UInt32 gAsipInfo1_PrimaryErrCnt =0;
330 UInt32 gAsipInfo1_ErrCnt =0;
331 UInt32 gAsipInfo2_PrimaryErrCnt =0;
332 UInt32 gAsipInfo2_ErrCnt =0;
333 UInt32 gCapIbReset_cnt =0;
334 UInt32 gCapIb_cnt =0;
335 // debug
336 UInt32 gCbWrtAfErrCnt =0; // decoder output circular buffer write error count (returned from ARM to DSP)
339 #include "dbgDib.h" // debug
341 extern struct {
342 Int size;
343 IALG_Status *pStatus[512];
344 } IACP_STD_BETA_TABLE;
346 // FL: debug
347 #include "evmc66x_gpio_dbg.h"
349 /*
350 * ======== taskAsipFxn ========
351 * Audio Stream Input Processing task function
352 */
353 Void taskAsipFxn(
354 // Int betaPrimeValue, // FL: revisit
355 const PAF_ASIT_Params *pP,
356 const PAF_ASIT_Patchs *pQ
357 )
358 {
359 PAF_ASIT_Config *pAsitCfg; /* ASIT configuration pointer */
360 PAF_AST_Config *pAstCfg; /* AST Common (shared) configuration pointer */
361 Int as; /* Audio Stream Number (1, 2, etc.) */
362 Int z; /* input/encode/stream/decode/output counter */
363 Int i; /* phase */
364 Int errno; /* error number */
365 Int zMD, zMI, zMS, zX;
366 Int loopCount = 0; // used to stop trace to see startup behavior.
367 UInt32 curTime;
368 Int size;
369 // Messaging
370 ASP_Msg *pAspMsg;
371 Int status;
372 Int8 tempVar8;
373 char asipMsgBuf[ASP_MSG_BUF_LEN];
375 Log_info0("Enter taskAsipFxn()");
377 //
378 // Audio Stream Input Task Parameters & Patch (*pP, *pQ)
379 //
380 if (!pP)
381 {
382 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
383 LINNO_RPRT(TaskAsip, -1);
384 return;
385 }
387 if (!pQ)
388 {
389 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
390 LINNO_RPRT(TaskAsip, -1);
391 return;
392 }
394 //
395 // Audio Stream Input Task Configuration (*pAsitCfg):
396 //
397 pAsitCfg = &gPAF_ASIT_config; // initialize pointer to task configuration
398 pAsitCfg->taskHandle = Task_self(); // set task handle
399 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
401 /* Set Audio Stream Number (1, 2, etc.) */
402 as = gBetaPrimeValue + 1;
403 pAstCfg->as = as;
404 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
406 //
407 // Initialize message log trace and line number reporting
408 //
409 for (z=STREAM1; z < STREAMN; z++)
410 {
411 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
412 }
413 LINNO_RPRT(TaskAsip, -1);
415 //
416 // Determine decoder and stream indices associated with the master input
417 //
418 zMI = pP->zone.master;
419 pAstCfg->masterDec = zMI;
420 pAstCfg->masterStr = zMI;
421 for (zX = DECODE1; zX < DECODEN; zX++)
422 {
423 if (pP->inputsFromDecodes[zX] == zMI)
424 {
425 pAstCfg->masterDec = zX;
426 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
427 break;
428 }
429 }
430 zMD = pAstCfg->masterDec;
431 zMS = pAstCfg->masterStr;
433 // Initialize as per parametrized phases:
434 //
435 // In standard form these are:
436 // - Malloc: Memory Allocation
437 // - Config: Configuration Initialization
438 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
439 // - Common: Common Memory Initialization
440 // - AlgKey: Dec/Enc chain to Array Initialization
441 // - Device: I/O Device Initialization
442 // - DecOpCircBuf: Decoder Output Circular Buffer
443 // - Unused: (available)
444 //
445 LINNO_RPRT(TaskAsip, -2);
446 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
447 {
448 Int linno;
449 if (pP->fxns->initPhase[i])
450 {
451 linno = pP->fxns->initPhase[i](pP, pQ, pAsitCfg);
452 if (linno)
453 {
454 LINNO_RPRT(TaskAsip, linno);
455 return;
456 }
457 }
458 else
459 {
460 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
461 }
462 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
463 LINNO_RPRT(TaskAsip, -i-3);
464 }
466 //
467 // End of Initialization -- display memory usage report.
468 //
469 if (pP->fxns->memStatusPrint)
470 {
471 pP->fxns->memStatusPrint("ASIT MEMSTAT REPORT",
472 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
473 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
474 }
476 // (***) FL: revisit
477 // write back AST shared configuration
478 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
479 Cache_wait();
481 // (***) FL: revisit
482 // write back Dec configuration
483 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
484 Cache_wait();
486 // (***) FL: revisit
487 // write back entire beta table
488 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
489 Cache_wait();
491 // FL: send start initialization message to slave
492 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
493 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
494 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
495 pAspMsg->procId = hAspMsgMaster->masterProcId;
496 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
497 pAspMsg->expectResp = TRUE;
498 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
499 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
500 if (status != MessageQ_S_SUCCESS)
501 {
502 SW_BREAKPOINT;
503 }
504 // wait for initialization complete message from slave
505 do {
506 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
507 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
508 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
509 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
510 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
511 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
512 {
513 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
514 SW_BREAKPOINT;
515 }
516 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
517 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
518 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
519 if (status != MessageQ_S_SUCCESS)
520 {
521 SW_BREAKPOINT;
522 }
524 // (***) FL: revisit
525 // invalidate Status structure addresses for Beta Units initialized on Slave
526 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
527 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
528 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
529 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
530 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
531 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
532 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
533 Cache_wait();
534 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
535 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
536 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
537 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
538 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
539 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
540 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
542 // (***) FL: revisit
543 // invalidate Status structures for Beta Units initialized on Slave
544 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
545 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
546 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
547 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
548 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
549 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
550 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
551 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
552 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
553 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
554 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
555 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
556 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
557 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
558 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
559 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
560 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
561 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
562 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
563 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
564 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
565 Cache_wait();
567 #ifdef NON_CACHE_STATUS
568 // Get the shared status structure GateMP handles. Initialized at slave.
569 if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
570 {
571 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
572 }
573 if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
574 {
575 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
576 }
577 if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
578 {
579 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
580 }
581 if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
582 {
583 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
584 }
585 #endif
587 // (***) FL: revisit
588 // invalidate Dec configuration
589 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
590 Cache_wait();
592 //
593 // Main processing loop
594 //
595 for (z=STREAM1; z < STREAMN; z++)
596 {
597 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
598 }
600 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
602 errno = 0;
603 for (;;)
604 {
605 Int sourceSelect;
606 XDAS_Int8 sourceProgram;
608 loopCount++;
610 #if 0 // enable and tune to see startup behavior.
611 // this is an alternative to fixed/circular setting in pa.cfg.
612 // If you are searching for a memory allocation failure, disable on first round.
613 // All allocation has already happened.
614 // This is the outer loop. This loop count goes up when the stream resets.
615 // If the stream is running without problems, this does not increment.
616 // If the stream is repeatedly resetting, this loop count will go up rapidly.
617 if (loopCount > 10) // see traces for a few of the passes through the main loop.
618 {
619 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
620 LOG_disable(&TR_MOD); // stop tracing
621 }
622 #endif
624 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
625 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
627 // since not decoding indicate such
628 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
630 // any error forces idling of input
631 if (errno)
632 {
633 for (z=INPUT1; z < INPUTN; z++)
634 {
635 if (pAstCfg->xInp[z].hRxSio)
636 {
637 SIO_idle(pAstCfg->xInp[z].hRxSio);
638 }
639 }
641 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
642 ERRNO_RPRT(TaskAsip, errno);
643 }
645 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
646 // up to allow lower priority tasks to run. This may seem odd to be at the top
647 // of the state machine but provides for a cleaner flow even though the very
648 // first time we enter we do a sleep which is non-intuitive.
649 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
650 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
651 Task_sleep(1);
653 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
654 errno = pP->fxns->selectDevices(pP, pQ, pAsitCfg);
655 if (errno)
656 {
657 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
658 continue;
659 }
661 // if no master input selected then we don't know what may be at the input
662 // so set to unknown and skip any remaining processing
663 if (!pAstCfg->xInp[zMI].hRxSio)
664 {
665 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
666 (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
668 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
669 continue;
670 }
672 // if here then we have a valid input so query its status
673 errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig);
674 if (errno)
675 {
676 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
677 continue;
678 }
680 // If master decoder is not enabled, or the input is unlocked, then do nothing
681 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
682 GATEMP_INDEX_DEC);
683 if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
684 {
685 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
686 continue;
687 }
689 // If no source selected then do nothing
690 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
691 GATEMP_INDEX_DEC);
692 if (tempVar8 == PAF_SOURCE_NONE)
693 {
694 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
695 (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
696 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
697 continue;
698 }
700 // If we want pass processing then proceed directly
701 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
702 GATEMP_INDEX_DEC);
703 if (tempVar8 == PAF_SOURCE_PASS)
704 {
705 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
706 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
707 (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
709 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_PASS);
710 if (pP->fxns->passProcessing)
711 {
712 errno = pP->fxns->passProcessing(pP, pQ, pAsitCfg, NULL);
713 }
714 else
715 {
716 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
717 errno = ASPERR_PASS;
718 }
719 TRACE_VERBOSE0("TaskAsip: continue");
720 continue;
721 }
723 // .....................................................................
724 // At this point we have an enabled input and want to decode something.
725 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
726 // when no decoder is selected there are no calls to IB
727 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
728 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
729 GATEMP_INDEX_DEC);
730 pfpBegin(PFP_ID_ASIT_1, pAsitCfg->taskHandle); // PFP begin
731 gNumPfpAsit1++;
732 errno = pP->fxns->autoProcessing(pP, pQ, pAsitCfg, tempVar8, NULL);
733 pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS); // PFP end
734 gNumPfpAsit1--;
736 if (errno) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
737 {
738 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
739 continue;
740 }
742 // query for input type
743 errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram);
744 if (errno)
745 {
746 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
747 errno = ASPERR_AUTO_PROGRAM;
748 continue;
749 }
751 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
752 sourceProgram, GATEMP_INDEX_DEC);
754 // if input is unclassifiable then do nothing
755 if (sourceProgram == PAF_SOURCE_UNKNOWN)
756 {
757 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
758 continue;
759 }
761 // now that we have some input classification, and possibly an outstanding
762 // input frame, we determine whether or not to call decodeProcessing and with
763 // what decAlg.
764 sourceSelect = PAF_SOURCE_NONE;
765 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
766 GATEMP_INDEX_DEC);
767 switch (tempVar8)
768 {
769 // If autodetecting, decoding everything, and input is something
770 // (i.e. bitstream or PCM) then decode.
771 case PAF_SOURCE_AUTO:
772 if (sourceProgram >= PAF_SOURCE_PCM)
773 {
774 sourceSelect = sourceProgram;
775 }
776 break;
778 // If autodetecting, decoding only PCM, and input is PCM then decode.
779 case PAF_SOURCE_PCMAUTO:
780 if (sourceProgram == PAF_SOURCE_PCM)
781 {
782 sourceSelect = sourceProgram;
783 }
784 break;
786 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
787 case PAF_SOURCE_BITSTREAM:
788 if (sourceProgram >= PAF_SOURCE_AC3)
789 {
790 sourceSelect = sourceProgram;
791 }
792 break;
794 // If autodetecting, decoding only DTS, and input is DTS then decode.
795 case PAF_SOURCE_DTSALL:
796 switch (sourceProgram)
797 {
798 case PAF_SOURCE_DTS11:
799 case PAF_SOURCE_DTS12:
800 case PAF_SOURCE_DTS13:
801 case PAF_SOURCE_DTS14:
802 case PAF_SOURCE_DTS16:
803 case PAF_SOURCE_DTSHD:
804 sourceSelect = sourceProgram;
805 break;
806 }
807 break;
809 // All others, e.g., force modes, fall through to here.
810 // If user made specific selection then program must match select.
811 // (NB: this compare relies on ordering of PAF_SOURCE)
812 default:
813 sourceSelect = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
814 GATEMP_INDEX_DEC);
815 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
816 {
817 if (sourceProgram != sourceSelect)
818 {
819 sourceSelect = PAF_SOURCE_NONE;
820 }
821 }
822 break;
823 }
825 // if we didn't find any matches then skip
826 if (sourceSelect == PAF_SOURCE_NONE)
827 {
828 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
829 continue;
830 }
832 // FL: debug, reset IB capture buffer
833 capIbReset();
834 gCapIbReset_cnt++;
835 Log_info0("capIbReset()");
837 // FL: send source select message to slave
838 *(Int32 *)&asipMsgBuf[0] = sourceSelect;
839 if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
840 asipMsgBuf, NULL) != ASP_MSG_NO_ERR)
841 {
842 TRACE_VERBOSE0("TaskAsip: error in sending source select message");
843 }
845 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
846 // iff we are in this top level state machine and specifically not in decodeProcessing
847 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
849 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
851 // Reduce priority level since autodetection complete
852 Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)-1);
854 gAspProfileEnable=1; // enable ASP profiling
856 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
857 errno = pP->fxns->decodeProcessing(pP, pQ, pAsitCfg, sourceSelect);
858 if (errno)
859 {
860 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
861 }
862 else
863 {
864 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
865 }
867 gAspProfileEnable=0; // disable ASP profiling
869 // Increase priority level since decoding complete
870 Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)+1);
872 // FL: send dec exit message to slave
873 AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL);
875 } // End of main processing loop for (;;)
877 Log_info0("Exit taskAsipFxn()");
878 }
880 // -----------------------------------------------------------------------------
881 // ASIT Initialization Function - Memory Allocation
882 //
883 // Name: PAF_ASIT_initPhaseMalloc
884 // Purpose: Audio Stream Input Task Function for initialization of data pointers
885 // by allocation of memory.
886 // From: audioStream1Task or equivalent
887 // Uses: See code.
888 // States: x
889 // Return: 0 on success.
890 // Source code line number on MEM_calloc failure.
891 // Trace: Message Log "trace" in Debug Project Configuration reports:
892 // * State information as per parent.
893 // * Memory allocation errors.
894 //
895 Int
896 PAF_ASIT_initPhaseMalloc(
897 const PAF_ASIT_Params *pP,
898 const PAF_ASIT_Patchs *pQ,
899 PAF_ASIT_Config *pAsitCfg
900 )
901 {
902 PAF_AST_Config *pAstCfg;
903 Int as; /* Audio Stream Number (1, 2, etc.) */
904 Int zMS;
905 Error_Block eb;
906 IHeap_Handle decHeapHandle;
908 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
909 as = pAstCfg->as;
910 zMS = pAstCfg->masterStr;
912 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
914 // Initialize error block
915 Error_init(&eb);
917 /* Input memory */
918 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
919 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
920 {
921 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
922 SW_BREAKPOINT;
923 return __LINE__;
924 }
925 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xInp) %d bytes from space %d at 0x%x.",
926 INPUTN * sizeof (*pAstCfg->xInp),
927 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
929 /* Decode memory */
930 #ifdef NON_CACHE_STATUS
931 decHeapHandle = (IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM;
932 #else
933 decHeapHandle = (IHeap_Handle)HEAP_INTERNAL1_SHM;
934 #endif
935 if (!(pAstCfg->xDec = Memory_calloc(decHeapHandle,
936 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
937 {
938 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
939 SW_BREAKPOINT;
940 return __LINE__;
941 }
943 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xDec) %d bytes from space %d at 0x%x.",
944 DECODEN * sizeof (*pAstCfg->xDec),
945 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
947 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
948 return 0;
949 } //PAF_ASIT_initPhaseMalloc
951 // -----------------------------------------------------------------------------
952 // ASIT Initialization Function - Memory Initialization from Configuration
953 //
954 // Name: PAF_ASIT_initPhaseConfig
955 // Purpose: Audio Stream Task Function for initialization of data values
956 // from parameters.
957 // From: audioStream1Task or equivalent
958 // Uses: See code.
959 // States: x
960 // Return: 0 on success.
961 // Other as per initFrame0 and initFrame1.
962 // Trace: Message Log "trace" in Debug Project Configuration reports:
963 // * State information as per parent.
964 //
965 Int
966 PAF_ASIT_initPhaseConfig(
967 const PAF_ASIT_Params *pP,
968 const PAF_ASIT_Patchs *pQ,
969 PAF_ASIT_Config *pAsitCfg
970 )
971 {
972 PAF_AST_Config *pAstCfg;
973 Int as; /* Audio Stream Number (1, 2, etc.) */
974 Int z; /* input/encode/stream/decode/output counter */
975 Int zMS;
977 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
978 as = pAstCfg->as;
979 zMS = pAstCfg->masterStr;
981 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
983 //
984 // Unspecified elements have been initialized to zero during alloc
985 //
987 for (z=INPUT1; z < INPUTN; z++)
988 {
989 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
990 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
991 }
993 for (z=DECODE1; z < DECODEN; z++)
994 {
995 Int zI = pP->inputsFromDecodes[z];
996 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
997 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
998 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
999 }
1001 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1002 return 0;
1003 } //PAF_ASIT_initPhaseConfig
1005 // -----------------------------------------------------------------------------
1006 // ASIT Initialization Function - ACP Algorithm Instantiation
1007 //
1008 // Name: PAF_ASIT_initPhaseAcpAlg
1009 // Purpose: Audio Stream Input Task Function for initialization of ACP by
1010 // instantiation of the algorithm.
1011 // From: audioStream1Task or equivalent
1012 // Uses: See code.
1013 // States: x
1014 // Return: 0 on success.
1015 // Source code line number on ACP Algorithm creation failure.
1016 // Trace: Message Log "trace" in Debug Project Configuration reports:
1017 // * State information as per parent.
1018 // * Memory allocation errors.
1019 //
1020 Int
1021 PAF_ASIT_initPhaseAcpAlg(
1022 const PAF_ASIT_Params *pP,
1023 const PAF_ASIT_Patchs *pQ,
1024 PAF_ASIT_Config *pAsitCfg
1025 )
1026 {
1027 PAF_AST_Config *pAstCfg;
1028 Int as; /* Audio Stream Number (1, 2, etc.) */
1029 Int z; /* input/encode/stream/decode/output counter */
1030 Int betaPrimeOffset;
1031 ACP_Handle acp;
1032 Int zMS;
1033 Int zS, zX;
1035 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1036 as = pAstCfg->as;
1037 zMS = pAstCfg->masterStr;
1039 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1041 ACP_MDS_init();
1043 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1044 {
1045 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1046 return __LINE__;
1047 }
1048 pAsitCfg->acp = acp;
1050 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1051 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1053 for (z=INPUT1; z < INPUTN; z++)
1054 {
1055 zS = z;
1056 for (zX = DECODE1; zX < DECODEN; zX++)
1057 {
1058 if (pP->inputsFromDecodes[zX] == z)
1059 {
1060 zS = pP->streamsFromDecodes[zX];
1061 break;
1062 }
1063 }
1064 acp->fxns->attach(acp, ACP_SERIES_STD,
1065 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1066 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1067 /* Ignore errors, not reported. */
1068 }
1070 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1072 return 0;
1073 } //PAF_ASIT_initPhaseAcpAlg
1075 // -----------------------------------------------------------------------------
1076 // ASIT Initialization Function - Common Memory
1077 //
1078 // Name: PAF_ASIT_initPhaseCommon
1079 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1080 // From: audioStream1Task or equivalent
1081 // Uses: See code.
1082 // States: x
1083 // Return: 0 on success.
1084 // Source code line number on PAF_ALG_alloc failure.
1085 // Source code line number on PAF_ALG_mallocMemory failure.
1086 // Source code line number on Decode Chain initialization failure.
1087 // Source code line number on ASP Chain initialization failure.
1088 // Source code line number on Encode Chain initialization failure.
1089 // Trace: Message Log "trace" in Debug Project Configuration reports:
1090 // * State information as per parent.
1091 // * Memory allocation errors.
1092 //
1093 Int
1094 PAF_ASIT_initPhaseCommon(
1095 const PAF_ASIT_Params *pP,
1096 const PAF_ASIT_Patchs *pQ,
1097 PAF_ASIT_Config *pAsitCfg
1098 )
1099 {
1100 PAF_AST_Config *pAstCfg;
1101 Int as; /* Audio Stream Number (1, 2, etc.) */
1102 Int z; /* stream counter */
1103 ACP_Handle acp;
1104 PAF_IALG_Config pafAlgConfig;
1105 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1107 acp = pAsitCfg->acp;
1108 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1109 as = pAstCfg->as;
1111 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1113 //
1114 // Determine memory needs and instantiate algorithms across audio streams
1115 //
1116 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1117 PAF_ALG_setup(&pafAlgConfig,
1118 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1119 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1120 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1121 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1122 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1123 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1124 HEAP_CLEAR);
1126 if (pP->fxns->headerPrint)
1127 {
1128 pP->fxns->headerPrint();
1129 }
1131 for (z = STREAM1; z < STREAMN; z++)
1132 {
1133 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1135 //
1136 // Determine common memory for:
1137 // (1) Logical Input drivers
1138 //
1139 // Decode Algorithms common memory determined in ASP Slave.
1140 //
1141 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1143 //
1144 // Determine common memory needs of Logical Input driver
1145 //
1147 // really need to loop over all inputs for this stream using the tables
1148 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1149 // patch, and not needed for FS11, since there is only one input.
1150 if (INPUT1 <= z && z < INPUTN)
1151 {
1152 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1153 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1154 {
1155 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1156 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1157 SW_BREAKPOINT;
1158 return __LINE__;
1159 }
1160 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1161 if (pP->fxns->allocPrint)
1162 {
1163 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1164 }
1165 }
1166 }
1167 {
1168 // Changes made to share scratch between zones
1169 // Assume maximum 3 zones and scratch common memory is at offset 0;
1170 int max=0;
1171 for (z=STREAM1; z<STREAMN; z++)
1172 {
1173 if (max < common[z][0].size)
1174 {
1175 max = common[z][0].size;
1176 }
1177 }
1178 common[STREAM1][0].size=max;
1179 for (z=STREAM1+1; z<STREAMN; z++)
1180 {
1181 common[z][0].size = 0;
1182 }
1183 }
1185 //
1186 // Allocate common memory for:
1187 // (1) Logical Input drivers
1188 //
1189 for (z = STREAM1; z < STREAMN; z++)
1190 {
1191 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1192 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1193 {
1194 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1195 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1196 SW_BREAKPOINT;
1197 return __LINE__;
1198 }
1199 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1200 // share zone0 scratch with all zones
1201 common[z][0].base = common[0][0].base;
1202 if (pP->fxns->commonPrint)
1203 {
1204 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1205 }
1207 //
1208 // Allocate non-common memories for Logical IO drivers
1209 // Since these structures are used at run-time we allocate from external memory
1210 if (INPUT1 <= z && z < INPUTN)
1211 {
1212 PAF_ASP_Chain *chain;
1213 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1214 as+z, z);
1215 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1216 HEAP_EXTERNAL, as+z, acp, &trace,
1217 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1218 if (!chain)
1219 {
1220 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1221 return __LINE__;
1222 }
1223 }
1224 }
1225 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1227 return 0;
1228 } //PAF_ASIT_initPhaseCommon
1230 // (***) FL: candidate for removal
1231 // -----------------------------------------------------------------------------
1232 // ASIT Initialization Function - Algorithm Keys
1233 //
1234 // Name: PAF_ASIT_initPhaseAlgKey
1235 // Purpose: Audio Stream Input Task Function for initialization of data values
1236 // from parameters for Algorithm Keys.
1237 // From: audioStream1Task or equivalent
1238 // Uses: See code.
1239 // States: x
1240 // Return: 0.
1241 // Trace: Message Log "trace" in Debug Project Configuration reports:
1242 // * State information as per parent.
1243 //
1244 // .............................................................................
1245 Int
1246 PAF_ASIT_initPhaseAlgKey(
1247 const PAF_ASIT_Params *pP,
1248 const PAF_ASIT_Patchs *pQ,
1249 PAF_ASIT_Config *pAsitCfg
1250 )
1251 {
1252 PAF_AST_Config *pAstCfg;
1253 Int as; /* Audio Stream Number (1, 2, etc.) */
1256 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1257 as = pAstCfg->as;
1258 (void)as; // clear compiler warning in case not used with tracing disabled
1260 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1262 #if 0 // FL: slave
1263 for (z=DECODE1; z < DECODEN; z++)
1264 {
1265 for (s=0; s < pP->pDecAlgKey->length; s++)
1266 {
1267 if ((pP->pDecAlgKey->code[s].full != 0) &&
1268 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1269 {
1270 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1271 /* Cast in interface, for now --Kurt */
1272 }
1273 else
1274 {
1275 pC->xDec[z].decAlg[s] = NULL;
1276 }
1277 }
1278 }
1279 #endif
1281 return 0;
1282 } //PAF_ASIT_initPhaseAlgKey
1284 // -----------------------------------------------------------------------------
1285 // ASIT Initialization Function - I/O Devices
1286 //
1287 // Name: PAF_ASIT_initPhaseDevice
1288 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1289 // From: audioStream1Task or equivalent
1290 // Uses: See code.
1291 // States: x
1292 // Return: 0 on success.
1293 // Source code line number on device allocation failure.
1294 // Trace: Message Log "trace" in Debug Project Configuration reports:
1295 // * State information as per parent.
1296 // * Memory allocation errors.
1297 //
1298 Int
1299 PAF_ASIT_initPhaseDevice(
1300 const PAF_ASIT_Params *pP,
1301 const PAF_ASIT_Patchs *pQ,
1302 PAF_ASIT_Config *pAsitCfg
1303 )
1304 {
1305 PAF_AST_Config *pAstCfg;
1306 Int as; /* Audio Stream Number (1, 2, etc.) */
1307 Int z; /* input/output counter */
1308 PAF_SIO_IALG_Obj *pObj;
1309 PAF_SIO_IALG_Config *pAlgConfig;
1310 PAF_IALG_Config pafAlgConfig;
1313 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1314 as = pAstCfg->as;
1315 (void)as; // clear compiler warning in case not used with tracing disabled
1317 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1319 if (pP->fxns->bufMemPrint)
1320 {
1321 PAF_ALG_setup (&pafAlgConfig,
1322 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1323 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1324 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1325 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1326 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1327 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1328 HEAP_CLEAR);
1329 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1330 }
1332 for (z=INPUT1; z < INPUTN; z++)
1333 {
1334 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1336 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1337 pAlgConfig = &pObj->config;
1339 pAstCfg->xInp[z].hRxSio = NULL;
1341 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1342 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1343 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1344 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1345 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1346 pConfig->sizeofElement = 2;
1347 pConfig->precision = 16;
1349 if (pP->fxns->bufMemPrint)
1350 {
1351 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1352 }
1353 }
1355 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1357 return 0;
1358 } //PAF_ASIT_initPhaseDevice
1360 // -----------------------------------------------------------------------------
1361 // ASIT Initialization Function - Decoder Output Circular Buffer
1362 //
1363 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1364 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1365 // From: audioStream1Task or equivalent
1366 // Uses: See code.
1367 // States: x
1368 // Return: 0 on success.
1369 // Source code line number on device allocation failure.
1370 // Trace: Message Log "trace" in Debug Project Configuration reports:
1371 // * State information as per parent.
1372 // * Memory allocation errors.
1373 //
1374 Int
1375 PAF_ASIT_initPhaseDecOpCircBuf(
1376 const PAF_ASIT_Params *pP,
1377 const PAF_ASIT_Patchs *pQ,
1378 PAF_ASIT_Config *pAsitCfg
1379 )
1380 {
1381 PAF_AST_Config *pAstCfg;
1382 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1383 Int as; /* Audio Stream Number (1, 2, etc.) */
1384 Int zMS;
1385 Int z; /* decode counter */
1386 Int errno; /* error number */
1387 Error_Block eb;
1388 Int i;
1390 // FL: (***)revisit
1391 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1392 as = pAstCfg->as;
1393 zMS = pAstCfg->masterStr;
1395 /* Decode output circular buffer memory */
1396 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1397 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1398 {
1399 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1400 SW_BREAKPOINT;
1401 return __LINE__;
1402 }
1404 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pAsitCfg->xDecOpCb) %d bytes from space %d at 0x%x.",
1405 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1406 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1408 for (z=DECODE1; z < DECODEN; z++)
1409 {
1410 pCb = &pAstCfg->xDecOpCb[z];
1412 // allocate audio frame circular buffer
1413 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1414 {
1415 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1416 SW_BREAKPOINT;
1417 }
1418 // allocate audio frame PCM sample pointer array
1419 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1420 {
1421 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)))
1422 {
1423 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1424 SW_BREAKPOINT;
1425 }
1426 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)))
1427 {
1428 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1429 SW_BREAKPOINT;
1430 }
1431 }
1432 // allocate PCM sample buffer
1433 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1434 {
1435 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1436 SW_BREAKPOINT;
1437 }
1438 pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1439 // allocate Metadata buffers //QIN
1440 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)))
1441 {
1442 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1443 SW_BREAKPOINT;
1444 }
1445 pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1446 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1447 // Initialize decoder output circular buffer for PCM
1448 errno = cbInit(pCb);
1449 if (errno)
1450 {
1451 SW_BREAKPOINT; // FL: debug
1452 return errno;
1453 }
1454 }
1456 return 0;
1457 } //PAF_ASIT_initPhaseDecOpCircBuf
1460 #if 0
1461 // -----------------------------------------------------------------------------
1462 // AST Processing Function - Pass-Through Processing
1463 //
1464 // Name: PAF_AST_passProcessing
1465 // Purpose: Audio Stream Task Function for processing audio data as a
1466 // pass-through from the input driver to the output driver
1467 // for development and testing.
1468 // From: audioStream1Task or equivalent
1469 // Uses: See code.
1470 // States: x
1471 // Return: Error number in standard form (0 on success).
1472 // Trace: Message Log "trace" in Debug Project Configuration reports:
1473 // * State information on initialization.
1474 // * State information on processing.
1475 //
1477 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1478 /* Pass Processing is often omitted from builds to save memory, */
1479 /* and CODE_SECTION/clink constructs facilitate this omission. */
1481 Int
1482 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1483 {
1484 Int z; /* input/output counter */
1485 Int errno = 0; /* error number */
1486 Int getVal;
1487 Int rxNumChan, txNumChan;
1488 Int first;
1489 Int zMD = pC->masterDec;
1490 Int zMI = pP->zone.master;
1493 #ifndef __TI_EABI__
1494 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1495 #endif
1497 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1499 //
1500 // Determine that receive/transmit channels are compatible
1501 //
1503 // Can handle handle only master input
1504 for (z=INPUT1; z < INPUTN; z++) {
1505 if (z != zMI && pC->xInp[z].hRxSio)
1506 return (ASPERR_PASS + 0x01);
1507 }
1509 /* Number of receive/transmit channels */
1511 if (! pC->xInp[zMI].hRxSio)
1512 return (ASPERR_PASS + 0x11);
1513 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1514 return (ASPERR_PASS + 0x12);
1515 if (rxNumChan > NUM_TX_CHAN(zMI))
1516 return (ASPERR_PASS + 0x13);
1518 for (z=OUTPUT1; z < OUTPUTN; z++) {
1519 if (! pC->xOut[zMI].hTxSio)
1520 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1521 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1522 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1523 if (txNumChan > NUM_TX_CHAN(zMI))
1524 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1525 }
1527 //
1528 // Set up receive/transmit
1529 //
1531 SIO_idle (pC->xInp[zMI].hRxSio);
1532 for (z=OUTPUT1; z < OUTPUTN; z++) {
1533 if(SIO_idle (pC->xOut[z].hTxSio))
1534 return ASPERR_IDLE;
1535 }
1537 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1538 return (ASPERR_PASS + 0x14);
1540 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1541 return (ASPERR_PASS + 0x15);
1543 for (z=OUTPUT1; z < OUTPUTN; z++)
1544 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1546 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1547 return ASPERR_PASS + 0x16;
1549 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1550 return ASPERR_PASS + 0x17;
1552 //
1553 // Receive and transmit the data in single-frame buffers
1554 //
1556 first = 1;
1557 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1558 PAF_OutBufConfig *pOutBuf;
1559 PAF_InpBufConfig *pInpBuf;
1561 if (first) {
1562 first = 0;
1564 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1566 for (z=OUTPUT1; z < OUTPUTN; z++) {
1567 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1568 if (getVal > 0) {
1569 errno = ASPERR_ISSUE;
1570 break;
1571 }
1572 else if (getVal < 0) {
1573 errno = -getVal;
1574 break;
1575 }
1577 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1578 return (getVal & 0xff) | ASPERR_MUTE;
1579 }
1580 if (errno)
1581 break;
1583 }
1585 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1586 if (getVal > 0) {
1587 errno = ASPERR_ISSUE;
1588 break;
1589 }
1591 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1593 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1594 if (getVal < 0) {
1595 errno = -getVal;
1596 break;
1597 }
1599 for (z=OUTPUT1; z < OUTPUTN; z++) {
1600 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1601 if (getVal < 0) {
1602 errno = -getVal;
1603 break;
1604 }
1605 }
1606 if( errno )
1607 break;
1609 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1611 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1612 break;
1614 for (z=OUTPUT1; z < OUTPUTN; z++) {
1615 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1616 if (getVal > 0) {
1617 errno = ASPERR_ISSUE;
1618 break;
1619 }
1620 else if (getVal < 0) {
1621 errno = -getVal;
1622 break;
1623 }
1624 }
1625 if( errno )
1626 break;
1627 }
1629 //
1630 // Close down receive/transmit
1631 //
1633 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1635 for (z=OUTPUT1; z < OUTPUTN; z++) {
1636 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1637 if (! errno)
1638 errno = (getVal & 0xff) | ASPERR_MUTE;
1639 /* convert to sensical errno */
1640 }
1641 }
1643 SIO_idle (pC->xInp[zMI].hRxSio);
1644 for (z=OUTPUT1; z < OUTPUTN; z++)
1645 SIO_idle (pC->xOut[z].hTxSio);
1647 return errno;
1649 } //PAF_AST_passProcessing
1650 #endif // #if 0
1652 #if 0
1653 // -----------------------------------------------------------------------------
1654 // AST Processing Function Helper - Pass-Through Processing Patch Point
1655 //
1656 // Name: PAF_AST_passProcessingCopy
1657 // Purpose: Pass-Through Processing Function for copying audio data
1658 // from the input buffer to the output buffer.
1659 // From: AST Parameter Function -> passProcessing
1660 // Uses: See code.
1661 // States: x
1662 // Return: Error number in standard form (0 on success).
1663 // Trace: Message Log "trace" in Debug Project Configuration reports:
1664 // x
1665 //
1667 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1668 /* Pass Processing is often omitted from builds to save memory, */
1669 /* and CODE_SECTION/clink constructs facilitate this omission. */
1671 Int
1672 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1673 {
1674 Int z; /* output counter */
1675 Int errno; /* error number */
1676 Int i;
1677 Int rxNumChan, txNumChan;
1678 Int zMI = pP->zone.master;
1681 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1683 // Copy data from input channels to output channels one of two ways:
1685 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1686 return (ASPERR_PASS + 0x12);
1688 for (z=OUTPUT1; z < OUTPUTN; z++) {
1689 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1690 return (ASPERR_PASS + 0x22);
1692 if( txNumChan <= rxNumChan ) {
1694 // Copy one to one, ignoring later rx channels as needed.
1696 for( i=0; i < txNumChan; i++ ) {
1697 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1698 if( errno )
1699 return errno;
1700 }
1701 }
1702 else {
1704 // Copy one to many, repeating earlier rx channels as needed.
1706 Int from, to;
1708 from = 0;
1709 to = 0;
1710 while( to < txNumChan ) {
1711 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1712 if( errno )
1713 return errno;
1715 from++;
1716 to++;
1717 if( from == rxNumChan )
1718 from = 0;
1719 }
1720 }
1721 }
1723 return 0;
1724 } //PAF_AST_passProcessingCopy
1725 #endif // #if 0
1727 // -----------------------------------------------------------------------------
1728 // ASIT Processing Function - Auto Processing
1729 //
1730 // Name: PAF_ASIT_autoProcessing
1731 // Purpose: Audio Stream Input Task Function for processing audio data to
1732 // determine the input type without output.
1733 // From: audioStream1Task or equivalent
1734 // Uses: See code.
1735 // States: x
1736 // Return: Error number in standard or SIO form (0 on success).
1737 // Trace: Message Log "trace" in Debug Project Configuration reports:
1738 // * State information on initialization.
1739 //
1741 #define DECSIOMAP(X) \
1742 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1744 Int
1745 PAF_ASIT_autoProcessing(
1746 const PAF_ASIT_Params *pP,
1747 const PAF_ASIT_Patchs *pQ,
1748 PAF_ASIT_Config *pAsitCfg,
1749 Int inputTypeSelect,
1750 ALG_Handle pcmAlgMaster
1751 )
1752 {
1753 PAF_AST_Config *pAstCfg;
1754 Int as; /* Audio Stream Number (1, 2, etc.) */
1755 Int errno = 0; /* error number */
1756 Int nbytes;
1757 Int frameLength;
1758 Int zMD;
1759 Int zMI;
1760 Int zMS;
1762 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1763 as = pAstCfg->as;
1764 zMD = pAstCfg->masterDec;
1765 zMS = pAstCfg->masterStr;
1766 zMI = pP->zone.master;
1768 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1770 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1771 PAF_SIO_CONTROL_SET_SOURCESELECT,
1772 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1773 {
1774 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1775 return errno;
1776 }
1777 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1778 // pC->xDec[zMD].decodeStatus.bufferRatio);
1779 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1781 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1782 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1783 {
1784 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1785 errno, ASPERR_AUTO_LENGTH);
1786 return ASPERR_AUTO_LENGTH;
1787 }
1789 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1790 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1791 PAF_SIO_REQUEST_SYNC))
1792 {
1793 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1794 errno, ASPERR_ISSUE);
1795 return ASPERR_ISSUE;
1796 }
1798 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1800 // all of the sync scan work is done in this call. If the error returned
1801 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1802 // error so we mask it off.
1803 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1804 if (nbytes == -DIBERR_SYNC)
1805 {
1806 #if 1 // (***) FL: shows timing of autosync restart
1807 // (***) debug // B5
1808 {
1809 static Uint8 toggleState = 0;
1810 if (toggleState == 0)
1811 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
1812 else
1813 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
1814 toggleState = ~(toggleState);
1815 }
1816 #endif
1817 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1818 return nbytes;
1819 }
1820 if (nbytes != sizeof(PAF_InpBufConfig))
1821 {
1822 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1823 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1824 return ASPERR_RECLAIM;
1825 }
1826 if (errno)
1827 {
1828 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1829 }
1830 return errno;
1831 } //PAF_ASIT_autoProcessing
1833 UInt32 gProbe1Err=0;
1834 UInt32 gProbe2Err=0;
1835 UInt32 gMajorAuMissed=0;
1837 // -----------------------------------------------------------------------------
1838 // ASIT Processing Function - Decode Processing
1839 //
1840 // Name: PAF_ASIT_decodeProcessing
1841 // Purpose: Audio Stream Input Task Function for processing audio data.
1842 // From: audioStream1Task or equivalent
1843 // Uses: See code.
1844 // States: x
1845 // Return: Error number in standard form (0 on success).
1846 // Trace: Message Log "trace" in Debug Project Configuration reports:
1847 // * State information on initialization (via children).
1848 // * State information on processing (via children).
1849 // * Decode warnings.
1850 //
1851 // When "writeDECModeContinuous" is used for zMI input/decode:
1852 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1853 // (a) if "writeDECCommandRestart" is used
1854 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1855 // (b) if "writeDECSourceSelectNone" is used
1856 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1857 // (c) if an error occurs in
1858 // INIT
1859 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1860 // -> PAF_AST_decodeCont(): "Await slave inputs"
1861 // STREAM (errno |= PAF_COMPONENT_ASP)
1862 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1863 // [ the latter errors lead to "switch_break:"
1864 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1865 //
1866 // [ Notably, in FINAL ("frame-finalization state")
1867 // -> PAF_AST_decodeFinalTest() is *not* called,
1868 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1869 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1870 //
1871 // States in which error can't occur:
1872 // AGAIN ("subsequent initial state")
1873 //
1874 // States in which (some) errors must be handled:
1875 // INFO1 ("first frame state")
1876 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1877 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1878 // ?*? but what about ASPERR_RESYNC from same call ?*?
1879 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1880 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1881 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1882 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1883 // - enc->fxns->info()
1884 // - pP->fxns->setCheckRateX()
1885 // - pP->fxns->startOutput()
1886 // - "Start slave inputs if necessary"
1887 // INFO2 ("subsequent frame state")
1888 // -> PAF_AST_decodeInfo(): (see above)
1889 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1890 // - pP->fxns->setCheckRateX()
1891 // TIME ("timing state")
1892 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1893 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1894 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1895 // (*OK* don't try to recover from this*)
1896 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1897 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1898 // possibly in PAF_AST_decodeProcessing() itself **
1899 // DECODE ("decode state")
1900 // -> PAF_AST_decodeDecode(): pass on error from
1901 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1902 // - dec->fxns->reset()
1903 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1904 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
1905 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1906 Int
1907 PAF_ASIT_decodeProcessing(
1908 const PAF_ASIT_Params *pP,
1909 const PAF_ASIT_Patchs *pQ,
1910 PAF_ASIT_Config *pAsitCfg,
1911 Int sourceSelect
1912 )
1913 {
1914 PAF_AST_Config *pAstCfg;
1915 //Int as = pAsitCfg->as; /* Audio Stream Number (1, 2, etc.) */
1916 Int z; /* decode counter */
1917 Int errno; /* error number */
1918 Int getVal;
1919 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1920 ALG_Handle alg[DECODEN_MAX];
1921 Int zMD;
1922 Int zMS;
1923 Int size;
1924 //PAF_InpBufConfig *pIpBufConfig;
1925 Int frame; // decoder input frame count
1926 Int block; // (***) FL: formerly -- decoder output block count / input frame
1927 Int8 tempVar8, temp2Var8;
1929 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1930 zMD = pAstCfg->masterDec;
1931 zMS = pAstCfg->masterStr;
1933 for (z=DECODE1; z < DECODEN; z++)
1934 {
1935 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
1936 }
1937 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1939 //
1940 // Receive and process the data in single-frame buffers
1941 //
1943 state = INIT;
1944 errno = 0; /* error number */
1946 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1947 GATEMP_INDEX_DEC);
1948 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
1950 for (;;)
1951 {
1952 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1953 GATEMP_INDEX_DEC);
1954 if (tempVar8 == PAF_SOURCE_NONE)
1955 {
1956 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1957 state = QUIT;
1958 }
1960 // Process commands (decode)
1961 getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
1962 if (getVal)
1963 {
1964 if (state != INIT) // no need to restart/abort if not yet started
1965 {
1966 if (getVal == ASPERR_QUIT)
1967 {
1968 state = QUIT;
1969 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1970 }
1971 else if (getVal == ASPERR_ABORT)
1972 {
1973 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1975 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
1976 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
1977 gNumPfpAsit2--;
1979 return getVal;
1980 }
1981 else
1982 {
1983 /* ignore */;
1984 }
1985 }
1986 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
1987 }
1989 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
1990 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
1992 // Process state (decode)
1993 switch (state)
1994 {
1995 case INIT: // initial state
1996 gAsipInitCnt++;
1997 Log_info0("TaskAsip: state=INIT");
1999 errno = pP->fxns->decodeInit(pP, pQ, pAsitCfg, sourceSelect);
2000 if (errno)
2001 {
2002 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
2003 break;
2004 }
2006 frame = 0;
2007 block = 0;
2009 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2010 state = INFO1;
2011 continue;
2013 case INFO1: // first frame state
2014 gAsipInfo1Cnt++;
2015 Log_info0("TaskAsip: state=INFO1");
2017 // Establish primary timing
2018 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2019 if (errno)
2020 {
2021 gAsipInfo1_PrimaryErrCnt++;
2022 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2023 break;
2024 }
2026 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2027 GATEMP_INDEX_DEC);
2028 temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
2029 GATEMP_INDEX_DEC);
2030 // Don't start decode until major access unit is found.
2031 if (((tempVar8 == PAF_SOURCE_THD) ||
2032 (tempVar8 == PAF_SOURCE_DXP) ||
2033 (tempVar8 == PAF_SOURCE_DTSHD)) &&
2034 (temp2Var8 == PAF_SAMPLERATE_UNKNOWN))
2035 {
2036 Int z;
2037 for (z=DECODE1; z < DECODEN; z++)
2038 {
2039 Int zI = pP->inputsFromDecodes[z];
2040 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2041 GATEMP_INDEX_DEC);
2042 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2043 {
2044 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2045 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2046 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2047 {
2048 gProbe2Err++;
2049 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2051 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2052 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2053 gNumPfpAsit2--;
2055 return (ASPERR_ISSUE);
2056 }
2057 }
2058 }
2059 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2060 gMajorAuMissed++; // debug
2061 frame++;
2062 state = INFO1;
2063 continue;
2064 }
2065 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2067 // Establish secondary timing
2068 errno = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, frame, block);
2069 if (errno)
2070 {
2071 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2072 gAsipInfo1_ErrCnt++;
2073 break;
2074 }
2076 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2077 state = DECODE;
2078 continue;
2080 case INFO2: // subsequent frame state
2081 gAsipInfo2Cnt++;
2082 Log_info0("TaskAsip: state=INFO2");
2084 // Establish primary timing
2085 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2086 if (errno)
2087 {
2088 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2089 gAsipInfo2_PrimaryErrCnt++;
2090 break;
2091 }
2093 // Measure cycles in decode processing loop.
2094 // Only measures cycles spent in loop.
2095 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS); // PFP end
2096 gNumPfpAsit2--;
2097 pfpBegin(PFP_ID_ASIT_2, pAsitCfg->taskHandle); // PFP begin
2098 gNumPfpAsit2++;
2100 errno = pP->fxns->decodeInfo2(pP, pQ, pAsitCfg, frame, block);
2101 if (errno)
2102 {
2103 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2104 gAsipInfo2_ErrCnt++;
2105 break;
2106 }
2108 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2109 state = DECODE;
2110 continue;
2112 case DECODE: // decode state
2113 gAsipDecodeCnt++;
2114 Log_info0("TaskAsip: state=DECODE");
2116 errno = pP->fxns->decodeDecode(pP, pQ, pAsitCfg, sourceSelect, frame, block);
2117 if (errno)
2118 {
2119 gAsipDecodeErrCnt++;
2120 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2121 break;
2122 }
2124 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2125 state = FINAL;
2126 continue;
2128 case FINAL: // frame-finalization state
2129 gAsipFinalCnt++;
2130 Log_info0("TaskAsip: state=FINAL");
2132 // Check for final frame, and if indicated:
2133 // - Exit state machine to "complete" processing.
2134 if (pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, frame, block))
2135 {
2136 break;
2137 }
2139 frame++;
2140 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2141 state = INFO2;
2142 continue;
2144 case QUIT: // exit state
2145 gAsipQuitCnt++;
2146 Log_info0("TaskAsip: state=QUIT");
2148 // Quit:
2149 // - Set error number registers.
2150 // - Exit state machine to "decode complete" processing.
2151 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2152 errno = ASPERR_QUIT;
2153 break;
2155 default: // unknown state
2157 // Unknown:
2158 // - Set error number registers.
2159 // - Exit state machine to "decode complete" processing.
2161 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2162 errno = ASPERR_UNKNOWNSTATE;
2163 break;
2165 } // End of switch (state).
2167 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2168 if (pP->fxns->decodeComplete(pP, pQ, pAsitCfg, alg, frame, block))
2169 {
2170 /* ignored? */;
2171 }
2173 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2175 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2176 //pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2177 //gNumPfpAsit2--;
2179 //return errno;
2180 break;
2181 } // End of for (;;) to Receive, process, and transmit the data.
2183 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2184 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2185 gNumPfpAsit2--;
2187 return errno;
2188 } //PAF_ASIT_decodeProcessing
2190 // -----------------------------------------------------------------------------
2191 // ASIT Decoding Function - Decode Command Processing
2192 //
2193 // Name: PAF_ASIT_decodeCommand
2194 // Purpose: Decoding Function for processing Decode Commands.
2195 // From: AST Parameter Function -> decodeProcessing
2196 // Uses: See code.
2197 // States: x
2198 // Return: Error number in standard form (0 on success).
2199 // Trace: Message Log "trace" in Debug Project Configuration reports:
2200 // * Command execution.
2201 //
2203 Int
2204 PAF_ASIT_decodeCommand(
2205 const PAF_ASIT_Params *pP,
2206 const PAF_ASIT_Patchs *pQ,
2207 PAF_ASIT_Config *pAsitCfg
2208 )
2209 {
2210 PAF_AST_Config *pAstCfg;
2211 Int as; /* Audio Stream Number (1, 2, etc.) */
2212 Int z; /* decode counter */
2213 Int zS;
2214 Int8 tempVar8;
2216 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2217 as = pAstCfg->as;
2219 for (z=DECODE1; z < DECODEN; z++)
2220 {
2221 zS = pP->streamsFromDecodes[z];
2222 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2223 GATEMP_INDEX_DEC);
2224 if (!(tempVar8 & 0x80))
2225 {
2226 switch (tempVar8)
2227 {
2228 case 0: // command none - process
2229 tempVar8 |= 0x80;
2230 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2231 tempVar8, GATEMP_INDEX_DEC);
2232 break;
2233 case 1: // command abort - leave now
2234 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2235 tempVar8 |= 0x80;
2236 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2237 tempVar8, GATEMP_INDEX_DEC);
2238 return (ASPERR_ABORT);
2239 case 2: // command restart - leave later
2240 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2241 tempVar8 |= 0x80;
2242 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2243 tempVar8, GATEMP_INDEX_DEC);
2244 return (ASPERR_QUIT);
2245 default: // command unknown - ignore
2246 break;
2247 }
2248 }
2249 }
2251 return 0;
2252 } //PAF_ASIT_decodeCommand
2254 // -----------------------------------------------------------------------------
2255 // ASIT Decoding Function - Reinitialization of Decode
2256 //
2257 // Name: PAF_ASIT_decodeInit
2258 // Purpose: Decoding Function for reinitializing the decoding process.
2259 // From: AST Parameter Function -> decodeProcessing
2260 // Uses: See code.
2261 // States: x
2262 // Return: Error number in standard or SIO form (0 on success).
2263 // Trace: Message Log "trace" in Debug Project Configuration reports:
2264 // * State information as per parent.
2265 //
2266 Int
2267 PAF_ASIT_decodeInit(
2268 const PAF_ASIT_Params *pP,
2269 const PAF_ASIT_Patchs *pQ,
2270 PAF_ASIT_Config *pAsitCfg,
2271 Int sourceSelect
2272 )
2273 {
2274 PAF_AST_Config *pAstCfg;
2275 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2276 Int as; /* Audio Stream Number (1, 2, etc.) */
2277 Int z; /* decode/encode counter */
2278 Int errno; /* error number */
2279 Int zI, zS;
2280 Int zMD;
2281 Int zMI;
2282 Int argIdx;
2283 Int8 tempVar8;
2284 char decMsgBuf[ASP_MSG_BUF_LEN];
2286 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2287 as = pAstCfg->as;
2288 zMD = pAstCfg->masterDec;
2289 zMI = pP->zone.master;
2290 (void)as; // clear compiler warning in case not used with tracing disabled
2292 pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2294 // reset frameCount
2295 for (z=DECODE1; z < DECODEN; z++)
2296 {
2297 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2298 GATEMP_INDEX_DEC);
2299 if (tempVar8)
2300 {
2301 sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2302 (Int)0, GATEMP_INDEX_DEC);
2303 }
2304 }
2306 for (z=DECODE1; z < DECODEN; z++)
2307 {
2308 zI = pP->inputsFromDecodes[z];
2309 zS = pP->streamsFromDecodes[z];
2310 (void)zS; // clear compiler warning in case not used with tracing disabled
2311 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2312 GATEMP_INDEX_DEC);
2313 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2314 {
2316 Uns gear;
2317 Int frameLength;
2318 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2320 // write back Dec configuration
2321 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2322 Cache_wait();
2324 // FL: send dec activate message to slave
2325 argIdx = 0; // set decIdx (zone index)
2326 *(Int32 *)&decMsgBuf[argIdx] = z;
2327 if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
2328 decMsgBuf, NULL) != ASP_MSG_NO_ERR)
2329 {
2330 TRACE_TERSE0("decodeInit: error in sending dec activate message ");
2331 SW_BREAKPOINT; // temporary
2332 return -1; // temporary
2333 }
2335 #if 0 // FL: decoder activate call, slave
2336 if (decAlg[z]->fxns->algActivate)
2337 decAlg[z]->fxns->algActivate (decAlg[z]);
2338 #endif
2339 // FL: send dec reset message to slave
2340 argIdx = 0; // set decIdx
2341 *(Int32 *)&decMsgBuf[argIdx] = z;
2342 if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
2343 decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2344 {
2345 TRACE_TERSE0("decodeInit: error in sending dec reset message ");
2346 SW_BREAKPOINT; // temporary
2347 return -1; // temporary
2348 }
2349 else
2350 {
2351 argIdx = 0; // get decErrno
2352 errno = *(Int32 *)&decMsgBuf[argIdx];
2353 }
2355 // (***) FL: revisit
2356 // invalidate Dec configuration
2357 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2358 Cache_wait();
2360 #if 0 // FL: decoder reset call, slave
2361 if (dec->fxns->reset
2362 && (errno = dec->fxns->reset (dec, NULL,
2363 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2364 return errno;
2365 #endif
2366 if (errno != 0)
2367 {
2368 return errno;
2369 }
2371 gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2372 GATEMP_INDEX_DEC);
2373 tempVar8 = gear < GEARS ? gear : 0;
2374 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2375 tempVar8, GATEMP_INDEX_DEC);
2377 #if 0 // FL: change handle to decIdx (zone index)
2378 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2379 FRAMELENGTH,
2380 pC->xDec[z].decodeStatus.bufferRatio);
2381 #endif
2382 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2383 frameLength = pP->fxns->computeFrameLength(z,
2384 FRAMELENGTH,
2385 pC->xDec[z].decodeStatus.bufferRatio);
2386 #else
2387 if (sourceSelect == PAF_SOURCE_PCM)
2388 {
2389 frameLength = PAF_SYS_FRAMELENGTH;
2390 }
2391 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2392 {
2393 frameLength = 1536;
2394 }
2395 else if (sourceSelect == PAF_SOURCE_THD)
2396 {
2397 frameLength = 1536; //QIN FIX ME
2398 }
2399 else
2400 {
2401 frameLength = 256;
2402 }
2403 #endif
2405 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2406 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2407 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2409 // Initialize decoder output circular buffer for selected source
2410 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2411 if (errno)
2412 {
2413 SW_BREAKPOINT; // FL: debug
2414 return errno;
2415 }
2416 // FL: debug
2417 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2419 if (z != zMD)
2420 {
2421 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2422 {
2423 return errno;
2424 }
2425 }
2427 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2428 GATEMP_INDEX_DEC);
2429 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2430 DECSIOMAP(tempVar8)))
2431 {
2432 return errno;
2433 }
2435 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2436 frameLength))
2437 {
2438 return errno;
2439 }
2440 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2441 &pAstCfg->xInp[zI].inpBufConfig))
2442 {
2443 return errno;
2444 }
2445 }
2446 }
2448 if (pAstCfg->xInp[zMI].hRxSio)
2449 {
2450 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2451 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2452 if (errno)
2453 {
2454 return errno;
2455 }
2456 }
2458 return 0;
2459 } //PAF_AST_decodeInit
2461 // -----------------------------------------------------------------------------
2462 // ASIT Decoding Function - Info Processing, Common
2463 //
2464 // Name: PAF_ASIT_decodeInfo
2465 // Purpose: Decoding Function for processing information in a manner that
2466 // is common for both initial and subsequent frames of input data.
2467 // From: AST Parameter Function -> decodeProcessing
2468 // Uses: See code.
2469 // States: x
2470 // Return: Error number in standard form (0 on success).
2471 // Trace: Message Log "trace" in Debug Project Configuration reports:
2472 // * State information as per parent.
2473 //
2474 Int
2475 PAF_ASIT_decodeInfo(
2476 const PAF_ASIT_Params *pP,
2477 const PAF_ASIT_Patchs *pQ,
2478 PAF_ASIT_Config *pAsitCfg,
2479 Int frame,
2480 Int block
2481 )
2482 {
2483 PAF_AST_Config *pAstCfg;
2484 Int as; /* Audio Stream Number (1, 2, etc.) */
2485 Int z; /* input/decode/stream counter */
2486 Int errno; /* error number */
2487 Int sioErr; /* error number, SIO */
2488 Int zD, zI, zS, zX;
2489 Int zMD;
2490 Int zMI;
2491 Int zMS;
2492 UInt32 curTime;
2493 Int argIdx;
2494 Int8 tempVar8;
2495 Int tempVar;
2496 char decMsgBuf[ASP_MSG_BUF_LEN];
2497 // FL: revisit
2498 //Int size;
2499 //PAF_InpBufConfig *pIpBufConfig;
2501 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2502 as = pAstCfg->as;
2503 zMD = pAstCfg->masterDec;
2504 zMS = pAstCfg->masterStr;
2505 zMI = pP->zone.master;
2506 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2508 // Set decode control: sample rate, emphasis
2509 for (z=INPUT1; z < INPUTN; z++)
2510 {
2511 zD = z;
2512 for (zX = DECODE1; zX < DECODEN; zX++)
2513 {
2514 if (pP->inputsFromDecodes[zX] == z)
2515 {
2516 zD = zX;
2517 break;
2518 }
2519 }
2520 #ifdef PROFILER
2521 // modify for different sampling rate
2522 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus == PAF_SAMPLERATE_96000HZ)
2523 {
2524 start_profiling = 1;
2525 }
2526 else
2527 {
2528 start_profiling = 0;
2529 }
2530 #endif
2531 if (pAstCfg->xInp[z].hRxSio)
2532 {
2533 //determine associated decoder
2534 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2535 pAstCfg->xDec[zD].decodeControl.sampleRate)
2536 {
2537 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2538 {
2539 pAstCfg->xDec[zD].decodeControl.sampleRate =
2540 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2541 }
2542 else
2543 {
2544 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2545 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2546 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2547 pAstCfg->xDec[zD].decodeControl.sampleRate);
2548 // return (ASPERR_INFO_RATECHANGE);
2549 }
2550 }
2552 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2553 GATEMP_INDEX_DEC);
2554 pAstCfg->xDec[zD].decodeControl.emphasis =
2555 tempVar8 != PAF_SOURCE_PCM
2556 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2557 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2558 }
2559 else
2560 {
2561 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2562 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2563 }
2564 }
2566 // Wait for info input
2567 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2568 if (pAstCfg->xInp[zMI].hRxSio)
2569 {
2570 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2571 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2572 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2573 {
2574 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2575 return ASPERR_RECLAIM;
2576 }
2578 // FL: debug, capture input buffer
2579 capIb(pAstCfg->xInp[zMI].pInpBuf);
2580 gCapIb_cnt++;
2582 #if 1 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
2583 // (***) debug // B5
2584 {
2585 static Uint8 toggleState = 0;
2586 if (toggleState == 0)
2587 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
2588 else
2589 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
2590 toggleState = ~(toggleState);
2591 }
2592 #endif
2594 //
2595 // Simulate Rx SIO_reclaim() pend
2596 //
2597 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2598 gTaskAsipCnt++;
2599 curTime = Clock_getTicks();
2600 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2601 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2602 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2603 } //pAstCfg->xInp[zMI].hRxSio
2605 // Decode info
2606 for (z=DECODE1; z < DECODEN; z++)
2607 {
2608 zI = pP->inputsFromDecodes[z];
2609 zS = pP->streamsFromDecodes[z];
2610 (void)zS; // clear compiler warning in case not used with tracing disabled
2612 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2613 GATEMP_INDEX_DEC);
2614 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2615 {
2616 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2618 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2619 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2620 {
2621 TRACE_TERSE1("return error errno 0x%x.", errno);
2622 return errno;
2623 }
2625 #if 1
2626 // (***) FL: revisit
2627 // write back Inp configuration
2628 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2629 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2630 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2631 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2632 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2633 // write back Dec configuration
2634 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2635 Cache_wait();
2636 #endif
2638 // FL: send info message to slave
2639 argIdx = 0; // set decIdx
2640 *(Int32 *)&decMsgBuf[argIdx] = z;
2641 if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE,
2642 decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2643 {
2644 TRACE_TERSE0("decodeInfo: error in sending dec info message ");
2645 SW_BREAKPOINT; // temporary
2646 return -1; // temporary
2647 }
2648 else
2649 {
2650 argIdx = 0; // get decErrno
2651 errno = *(Int32 *)&decMsgBuf[argIdx];
2652 }
2654 #if 1
2655 // (***) FL: revisit
2656 // invalidate Dec configuration
2657 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2658 Cache_wait();
2659 #endif
2661 #if 0 // FL: decoder info call, slave
2662 if (dec->fxns->info
2663 && (errno = dec->fxns->info (dec, NULL,
2664 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2665 #endif
2666 if (errno)
2667 {
2668 TRACE_TERSE1("return error errno 0x%x.", errno);
2669 return errno;
2670 }
2672 // increment decoded frame count
2673 tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2674 GATEMP_INDEX_DEC);
2675 tempVar += 1;
2676 sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2677 tempVar, GATEMP_INDEX_DEC);
2678 }
2679 } // z=DECODE1 to DECODEN
2681 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2682 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
2683 GATEMP_INDEX_DEC);
2684 if (tempVar8)
2685 {
2686 XDAS_Int8 sourceProgram;
2687 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2688 (Arg)&sourceProgram))
2689 {
2690 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2691 return ASPERR_AUTO_PROGRAM;
2692 }
2694 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
2695 sourceProgram, GATEMP_INDEX_DEC);
2696 }
2698 // since now decoding update decode status for all enabled decoders
2699 for (z=DECODE1; z < DECODEN; z++)
2700 {
2701 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2702 GATEMP_INDEX_DEC);
2703 if (tempVar8)
2704 {
2705 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
2706 GATEMP_INDEX_DEC);
2707 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2708 tempVar8, GATEMP_INDEX_DEC);
2710 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2711 GATEMP_INDEX_DEC);
2712 if (tempVar8 == PAF_SOURCE_SNG)
2713 {
2714 tempVar8 = PAF_SOURCE_SNG;
2715 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2716 tempVar8, GATEMP_INDEX_DEC);
2717 }
2718 }
2719 }
2721 #if 0 // FL: ASDT (slave)
2722 // TODO: move this to start of this function so that it doesn't affect IO timing
2723 // Initialize audio frame(s)
2724 // Re-initialize audio frame if there is an associated decode and
2725 // that decode doesn't have a valid input or is turned off
2726 for (z=STREAM1; z < STREAMN; z++)
2727 {
2728 Int reset = 0;
2729 for (zX = DECODE1; zX < DECODEN; zX++)
2730 {
2731 if (pP->streamsFromDecodes[zX] == z)
2732 {
2733 zI = pP->inputsFromDecodes[zX];
2734 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2735 {
2736 reset = 1;
2737 }
2738 }
2739 }
2740 if (reset)
2741 {
2742 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2743 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2744 }
2745 else
2746 {
2747 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2748 }
2749 }
2750 #endif
2752 return 0;
2753 } //PAF_ASIT_decodeInfo
2755 // -----------------------------------------------------------------------------
2756 // ASIT Decoding Function - Info Processing, Initial
2757 //
2758 // Name: PAF_ASIT_decodeInfo1
2759 // Purpose: Decoding Function for processing information in a manner that
2760 // is unique to initial frames of input data.
2761 // From: AST Parameter Function -> decodeProcessing
2762 // Uses: See code.
2763 // States: x
2764 // Return: Error number in standard or SIO form (0 on success).
2765 // Trace: Message Log "trace" in Debug Project Configuration reports:
2766 // * State information as per parent.
2767 //
2768 Int
2769 PAF_ASIT_decodeInfo1(
2770 const PAF_ASIT_Params *pP,
2771 const PAF_ASIT_Patchs *pQ,
2772 PAF_ASIT_Config *pAsitCfg,
2773 Int frame,
2774 Int block
2775 )
2776 {
2777 return 0;
2778 } //PAF_ASIT_decodeInfo1
2780 // -----------------------------------------------------------------------------
2781 // AST Decoding Function - Info Processing, Subsequent
2782 //
2783 // Name: PAF_AST_decodeInfo2
2784 // Purpose: Decoding Function for processing information in a manner that
2785 // is unique to frames of input data other than the initial one.
2786 // From: AST Parameter Function -> decodeProcessing
2787 // Uses: See code.
2788 // States: x
2789 // Return: Error number in standard form (0 on success).
2790 // Trace: None.
2791 //
2792 Int
2793 PAF_ASIT_decodeInfo2(
2794 const PAF_ASIT_Params *pP,
2795 const PAF_ASIT_Patchs *pQ,
2796 PAF_ASIT_Config *pAsitCfg,
2797 Int frame,
2798 Int block
2799 )
2800 {
2801 return 0;
2802 } //PAF_ASIT_decodeInfo2
2804 #if 0
2805 // -----------------------------------------------------------------------------
2806 // AST Decoding Function - Continuation Processing
2807 //
2808 // Name: PAF_AST_decodeCont
2809 // Purpose: Decoding Function for processing that occurs subsequent to
2810 // information processing but antecedent to timing processing
2811 // for frames of input data other than the initial one.
2812 // From: AST Parameter Function -> decodeProcessing
2813 // Uses: See code.
2814 // States: x
2815 // Return: Error number in standard form (0 on success).
2816 // Trace: Message Log "trace" in Debug Project Configuration reports:
2817 // * State information as per parent.
2818 //
2820 Int
2821 PAF_AST_decodeCont(
2822 const PAF_ASIT_Params *pP,
2823 const PAF_ASIT_Patchs *pQ,
2824 PAF_ASIT_Config *pAsitCfg,
2825 ALG_Handle decAlg[],
2826 Int frame,
2827 Int block
2828 )
2829 {
2830 PAF_AST_Config *pAstCfg;
2831 Int as; /* Audio Stream Number (1, 2, etc.) */
2832 Int z; /* decode counter */
2833 Int zI, zS;
2834 Int zMD;
2835 Int8 tempVar8;
2838 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2839 as = pAstCfg->as;
2840 zMD = pAstCfg->masterDec;
2841 (void)as; // clear compiler warning in case not used with tracing disabled
2843 // Await slave inputs
2844 for (z=DECODE1; z < DECODEN; z++)
2845 {
2846 zI = pP->inputsFromDecodes[z];
2847 zS = pP->streamsFromDecodes[z];
2848 (void)zS;
2849 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2850 GATEMP_INDEX_DEC);
2851 if (z == zMD
2852 || ! pAstCfg->xInp[zI].hRxSio
2853 || ! tempVar8)
2854 continue;
2855 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2856 if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
2857 != sizeof (pAstCfg->xInp[zI].inpBufConfig))
2858 return (ASPERR_RECLAIM);
2859 }
2861 return 0;
2862 } //PAF_AST_decodeCont
2863 #endif
2865 // -----------------------------------------------------------------------------
2866 // ASIT Decoding Function - Decode Processing
2867 //
2868 // Name: PAF_ASIT_decodeDecode
2869 // Purpose: Decoding Function for processing of input data by the
2870 // Decode Algorithm.
2871 // From: AST Parameter Function -> decodeProcessing
2872 // Uses: See code.
2873 // States: x
2874 // Return: Error number in standard form (0 on success).
2875 // Trace: Message Log "trace" in Debug Project Configuration reports:
2876 // * State information as per parent.
2877 //
2878 Int
2879 PAF_ASIT_decodeDecode(
2880 const PAF_ASIT_Params *pP,
2881 const PAF_ASIT_Patchs *pQ,
2882 PAF_ASIT_Config *pAsitCfg,
2883 Int sourceSelect,
2884 Int frame,
2885 Int block
2886 )
2887 {
2888 PAF_AST_Config *pAstCfg;
2889 Int as; /* Audio Stream Number (1, 2, etc.) */
2890 Int z; /* decode/stream counter */
2891 Int errno; /* error number */
2892 //Int ch;
2893 Int argIdx;
2894 Int cbErrno;
2895 Int frameLength;
2896 char decMsgBuf[ASP_MSG_BUF_LEN];
2898 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2899 as = pAstCfg->as;
2900 (void)as; // clear compiler warning in case not used with tracing disabled
2902 #if 0 // FL: slave
2903 // Clear samsiz for all channels - MID 208.
2904 for (z=STREAM1; z < STREAMN; z++)
2905 {
2906 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
2907 {
2908 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
2909 }
2910 }
2911 #endif
2913 // Decode data
2914 for (z=DECODE1; z < DECODEN; z++)
2915 {
2916 Int zI = pP->inputsFromDecodes[z];
2917 Int zS = pP->streamsFromDecodes[z];
2918 (void)zS; // clear compiler warning in case not used with tracing disabled
2919 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2920 {
2921 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
2923 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
2924 as+zS,
2925 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
2926 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
2928 &nbs