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 "aspOutInitSync_master.h"
65 #include "audioStreamProc_common.h"
66 #include "audioStreamProc_master.h"
67 #include "audioStreamInpProc.h"
68 #include "statusOp_common.h"
70 #include "pfp/pfp.h"
71 #include "pfp_app.h" /* contains all PFP ID's */
72 Int32 gNumPfpAsit1=0; // debug
73 Int32 gNumPfpAsit2=0;
77 // FL: debug
78 #include "dbgCapAf.h"
81 // -----------------------------------------------------------------------------
82 // Debugging Trace Control, local to this file.
83 //
84 #include "logp.h"
86 #define TRACE_ARC(a)
88 // allows you to set a different trace module in pa.cfg
89 #define TR_MOD trace
91 // Allow a developer to selectively enable tracing.
92 #define CURRENT_TRACE_MASK 0x27
94 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
95 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
96 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
97 #define TRACE_MASK_DATA 0x08 // Show data
98 #define TRACE_MASK_TIME 0x10 // Timing related traces
99 #define TRACE_MASK_MSG 0x20 // Message related traces
101 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
102 #undef TRACE_TERSE0
103 #undef TRACE_TERSE1
104 #undef TRACE_TERSE2
105 #undef TRACE_TERSE3
106 #undef TRACE_TERSE4
107 #define TRACE_TERSE0(a)
108 #define TRACE_TERSE1(a,b)
109 #define TRACE_TERSE2(a,b,c)
110 #define TRACE_TERSE3(a,b,c,d)
111 #define TRACE_TERSE4(a,b,c,d,e)
112 #endif
114 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
115 #undef TRACE_GEN0
116 #undef TRACE_GEN1
117 #undef TRACE_GEN2
118 #undef TRACE_GEN3
119 #undef TRACE_GEN4
120 #define TRACE_GEN0(a)
121 #define TRACE_GEN1(a,b)
122 #define TRACE_GEN2(a,b,c)
123 #define TRACE_GEN3(a,b,c,d)
124 #define TRACE_GEN4(a,b,c,d,e)
125 #endif
127 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
128 // consolidate list of processing strings, indexed by PAF_SOURCE
129 static char *procName[] =
130 {
131 "", //PAF_SOURCE_UNKNOWN
132 "", //PAF_SOURCE_NONE
133 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
134 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
135 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
136 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
137 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
138 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
139 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
140 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
141 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
142 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
143 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
144 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
145 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
146 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
147 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
148 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
149 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
150 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
151 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
152 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
153 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
154 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
155 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
156 "AS%d: THD processing ...", //PAF_SOURCE_THD
157 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
158 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
159 };
161 #else
162 #undef TRACE_VERBOSE0
163 #undef TRACE_VERBOSE1
164 #undef TRACE_VERBOSE2
165 #undef TRACE_VERBOSE3
166 #undef TRACE_VERBOSE4
167 #define TRACE_VERBOSE0(a)
168 #define TRACE_VERBOSE1(a,b)
169 #define TRACE_VERBOSE2(a,b,c)
170 #define TRACE_VERBOSE3(a,b,c,d)
171 #define TRACE_VERBOSE4(a,b,c,d,e)
172 #endif
174 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
175 #define TRACE_DATA(a) LOG_printf a
176 #else
177 #define TRACE_DATA(a)
178 #endif
180 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
181 #define TRACE_TIME(a) LOG_printf a
182 #define TIME_MOD trace // this could be different
183 static Int dtime()
184 {
185 static Int old_time = 0;
186 Int time = TSK_time();
187 Int delta_time = time - old_time;
188 old_time = time;
189 return( delta_time);
190 }
192 static char *stateName[11] =
193 {
194 "INIT",
195 "INFO1",
196 "AGAIN",
197 "INFO2",
198 "CONT",
199 "TIME",
200 "DECODE",
201 "STREAM",
202 "ENCODE",
203 "FINAL",
204 "QUIT"
205 };
207 #else
208 #define TRACE_TIME(a)
209 #endif
211 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
212 #undef TRACE_MSG0
213 #undef TRACE_MSG1
214 #undef TRACE_MSG2
215 #undef TRACE_MSG3
216 #undef TRACE_MSG4
217 #define TRACE_MSG0(a)
218 #define TRACE_MSG1(a,b)
219 #define TRACE_MSG2(a,b,c)
220 #define TRACE_MSG3(a,b,c,d)
221 #define TRACE_MSG4(a,b,c,d,e)
222 #endif
225 // .............................................................................
227 #include <pafsio.h>
228 #include "paferr.h"
230 #include <acp_mds.h>
232 #include <pcm.h>
234 #include <pce.h>
236 #include <doberr.h>
238 #include <diberr.h>
240 #include <stdasp.h>
242 #include "as0.h"
243 #include "asperr.h"
245 #include "audioStreamProc_params.h"
246 #include "audioStreamProc_patchs.h"
247 #include "audioStreamProc_config.h"
248 #include "audioStreamInpProc.h"
251 #include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
252 #ifdef _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
253 //
254 // Performing PCM high-sampling rate + SRC + CAR benchmarking
255 //
257 #define PROFILER
258 #endif
260 #ifdef PROFILER
261 extern UInt32 start_profiling;
262 #endif
264 extern UInt32 gAspProfileEnable;
266 //
267 // Audio Stream Definitions
268 //
270 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
271 #define MINFRAMELENGTH 24
272 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
275 //
276 // Decoder Definitions
277 //
278 //#define decLinkInit pQ->i_decLinkInit
280 //
281 // Audio Stream Processing Definitions
282 //
283 //#define aspLinkInit pQ->i_aspLinkInit
285 //
286 // Encoder Definitions
287 //
288 #define encLinkInit pQ->i_encLinkInit
290 //
291 // Input, Output Definitions
292 //
293 #define inpLinkInit pP->i_inpLinkInit
294 //#define outLinkInit pP->i_outLinkInit
296 /* ---------------------------------------------------------------- */
297 /* Parameter macro definitions end here. */
298 /* ---------------------------------------------------------------- */
300 //
301 // Standardized Definitions
302 //
304 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
305 //#define ENC_Handle PCE_Handle /* works for all: PCE */
307 #define __TASK_NAME__ "TaskAsip"
310 //
311 // Audio Stream Input Task definitions
312 //
314 #define ASIP_FRAMELEN_SS_DEFAULT ( 256 )
315 // FL: pP->frameLength
316 //#define ASIP_FRAMELEN_SS_PCM ( FRAMELENGTH )
317 // FL: (***) hard-coded
318 #define ASIP_FRAMELEN_SS_DDP_AC3 ( 1536 )
319 // FL: (***) hard-coded
320 #define ASIP_FRAMELEN_SS_THD ( 1536 )
322 #define ASIP_FRAMELEN_SS_DTS ( 512 )
324 // Compute decoder frame length based on selected source
325 static Int getFrameLengthSourceSel(
326 const PAF_ASIT_Params *pP,
327 Int8 sourceSelect
328 );
330 LINNO_DEFN(TaskAsip); /* Line number macros */
331 ERRNO_DEFN(TaskAsip); /* Error number macros */
333 // ASIT configuration
334 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
335 PAF_ASIT_Config gPAF_ASIT_config = {
336 NULL, // taskHandle
337 NULL, // acp
338 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
339 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
340 };
342 // Global debug counters */
343 UInt32 gTaskAsipCnt =0;
344 UInt32 gAsipInitCnt =0;
345 UInt32 gAsipInfo1Cnt =0;
346 UInt32 gAsipInfo2Cnt =0;
347 UInt32 gAsipDecodeCnt =0;
348 UInt32 gAsipDecodeErrCnt =0;
349 UInt32 gAsipFinalCnt =0;
350 UInt32 gAsipQuitCnt =0;
351 UInt32 gAsipInfo1_PrimaryErrCnt =0;
352 UInt32 gAsipInfo1_ErrCnt =0;
353 UInt32 gAsipInfo2_PrimaryErrCnt =0;
354 UInt32 gAsipInfo2_ErrCnt =0;
355 UInt32 gCapIbReset_cnt =0;
356 UInt32 gCapIb_cnt =0;
357 // debug
358 UInt32 gCbWrtAfErrCnt =0; // decoder output circular buffer write error count (returned from ARM to DSP)
361 #include "dbgDib.h" // debug
363 extern struct {
364 Int size;
365 IALG_Status *pStatus[512];
366 } IACP_STD_BETA_TABLE;
368 // FL: debug
369 #include "evmc66x_gpio_dbg.h"
371 /*
372 * ======== taskAsipFxn ========
373 * Audio Stream Input Processing task function
374 */
375 Void taskAsipFxn(
376 // Int betaPrimeValue, // FL: revisit
377 const PAF_ASIT_Params *pP,
378 const PAF_ASIT_Patchs *pQ
379 )
380 {
381 PAF_ASIT_Config *pAsitCfg; /* ASIT configuration pointer */
382 PAF_AST_Config *pAstCfg; /* AST Common (shared) configuration pointer */
383 Int as; /* Audio Stream Number (1, 2, etc.) */
384 Int z; /* input/encode/stream/decode/output counter */
385 Int i; /* phase */
386 Int errno; /* error number */
387 Int zMD, zMI, zMS, zX;
388 Int loopCount = 0; // used to stop trace to see startup behavior.
389 UInt32 curTime;
390 Int size;
391 // Messaging
392 ASP_Msg *pAspMsg;
393 Int status;
394 Int8 tempVar8;
395 char asipMsgBuf[ASP_MSG_BUF_LEN];
397 Log_info0("Enter taskAsipFxn()");
399 //
400 // Audio Stream Input Task Parameters & Patch (*pP, *pQ)
401 //
402 if (!pP)
403 {
404 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
405 LINNO_RPRT(TaskAsip, -1);
406 return;
407 }
409 if (!pQ)
410 {
411 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
412 LINNO_RPRT(TaskAsip, -1);
413 return;
414 }
416 //
417 // Audio Stream Input Task Configuration (*pAsitCfg):
418 //
419 pAsitCfg = &gPAF_ASIT_config; // initialize pointer to task configuration
420 pAsitCfg->taskHandle = Task_self(); // set task handle
421 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
423 /* Set Audio Stream Number (1, 2, etc.) */
424 as = gBetaPrimeValue + 1;
425 pAstCfg->as = as;
426 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
428 //
429 // Initialize message log trace and line number reporting
430 //
431 for (z=STREAM1; z < STREAMN; z++)
432 {
433 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
434 }
435 LINNO_RPRT(TaskAsip, -1);
437 //
438 // Determine decoder and stream indices associated with the master input
439 //
440 zMI = pP->zone.master;
441 pAstCfg->masterDec = zMI;
442 pAstCfg->masterStr = zMI;
443 for (zX = DECODE1; zX < DECODEN; zX++)
444 {
445 if (pP->inputsFromDecodes[zX] == zMI)
446 {
447 pAstCfg->masterDec = zX;
448 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
449 break;
450 }
451 }
452 zMD = pAstCfg->masterDec;
453 zMS = pAstCfg->masterStr;
455 // Initialize as per parametrized phases:
456 //
457 // In standard form these are:
458 // - Malloc: Memory Allocation
459 // - Config: Configuration Initialization
460 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
461 // - Common: Common Memory Initialization
462 // - AlgKey: Dec/Enc chain to Array Initialization
463 // - Device: I/O Device Initialization
464 // - DecOpCircBuf: Decoder Output Circular Buffer
465 // - Unused: (available)
466 //
467 LINNO_RPRT(TaskAsip, -2);
468 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
469 {
470 Int linno;
471 if (pP->fxns->initPhase[i])
472 {
473 linno = pP->fxns->initPhase[i](pP, pQ, pAsitCfg);
474 if (linno)
475 {
476 LINNO_RPRT(TaskAsip, linno);
477 return;
478 }
479 }
480 else
481 {
482 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
483 }
484 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
485 LINNO_RPRT(TaskAsip, -i-3);
486 }
488 //
489 // End of Initialization -- display memory usage report.
490 //
491 if (pP->fxns->memStatusPrint)
492 {
493 pP->fxns->memStatusPrint("ASIT MEMSTAT REPORT",
494 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
495 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
496 }
498 // (***) FL: revisit
499 // write back AST shared configuration
500 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
501 Cache_wait();
503 // (***) FL: revisit
504 // write back Dec configuration
505 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
506 Cache_wait();
508 // (***) FL: revisit
509 // write back entire beta table
510 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
511 Cache_wait();
513 // FL: send start initialization message to slave
514 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
515 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
516 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
517 pAspMsg->procId = hAspMsgMaster->masterProcId;
518 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
519 pAspMsg->expectResp = TRUE;
520 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
521 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
522 if (status != MessageQ_S_SUCCESS)
523 {
524 SW_BREAKPOINT;
525 }
526 // wait for initialization complete message from slave
527 do {
528 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
529 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
530 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
531 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
532 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
533 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
534 {
535 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
536 SW_BREAKPOINT;
537 }
538 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
539 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
540 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
541 if (status != MessageQ_S_SUCCESS)
542 {
543 SW_BREAKPOINT;
544 }
546 // (***) FL: revisit
547 // invalidate Status structure addresses for Beta Units initialized on Slave
548 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
549 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
550 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
551 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
552 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
553 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
554 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
555 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DTSUHDA]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
556 Cache_wait();
557 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
558 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
559 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
560 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
561 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
562 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
563 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
564 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DTSUHDA]) Log_info0("ERROR: beta unit for Dec==NULL");
566 // (***) FL: revisit
567 // invalidate Status structures for Beta Units initialized on Slave
568 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
569 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
570 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
571 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
572 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
573 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
574 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
575 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
576 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
577 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
578 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
579 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
580 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
581 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
582 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
583 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
584 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
585 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
586 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
587 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
588 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
589 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DTSUHDA]->size;
590 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DTSUHDA]), size, Cache_Type_ALLD, 0);
591 Cache_wait();
593 #ifdef NON_CACHE_STATUS
594 // Get the shared status structure GateMP handles. Initialized at slave.
595 if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
596 {
597 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
598 }
599 if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
600 {
601 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
602 }
603 if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
604 {
605 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
606 }
607 if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
608 {
609 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
610 }
611 if (statusOp_Init(GATEMP_INDEX_DTS) == STATUSOP_INIT_FAIL)
612 {
613 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DTS);
614 }
615 #endif
616 // (***) FL: revisit
617 // invalidate Dec configuration
618 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
619 Cache_wait();
621 //
622 // Main processing loop
623 //
624 for (z=STREAM1; z < STREAMN; z++)
625 {
626 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
627 }
629 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
631 errno = 0;
632 for (;;)
633 {
634 Int sourceSelect;
635 XDAS_Int8 sourceProgram;
637 loopCount++;
639 #if 0 // enable and tune to see startup behavior.
640 // this is an alternative to fixed/circular setting in pa.cfg.
641 // If you are searching for a memory allocation failure, disable on first round.
642 // All allocation has already happened.
643 // This is the outer loop. This loop count goes up when the stream resets.
644 // If the stream is running without problems, this does not increment.
645 // If the stream is repeatedly resetting, this loop count will go up rapidly.
646 if (loopCount > 10) // see traces for a few of the passes through the main loop.
647 {
648 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
649 LOG_disable(&TR_MOD); // stop tracing
650 }
651 #endif
653 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
654 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
656 // since not decoding indicate such
657 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
659 // any error forces idling of input
660 if (errno)
661 {
662 for (z=INPUT1; z < INPUTN; z++)
663 {
664 if (pAstCfg->xInp[z].hRxSio)
665 {
666 SIO_idle(pAstCfg->xInp[z].hRxSio);
667 }
668 }
670 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
671 ERRNO_RPRT(TaskAsip, errno);
672 }
674 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
675 // up to allow lower priority tasks to run. This may seem odd to be at the top
676 // of the state machine but provides for a cleaner flow even though the very
677 // first time we enter we do a sleep which is non-intuitive.
678 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
679 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
680 Task_sleep(1);
682 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
683 errno = pP->fxns->selectDevices(pP, pQ, pAsitCfg);
684 if (errno)
685 {
686 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
687 continue;
688 }
690 // if no master input selected then we don't know what may be at the input
691 // so set to unknown and skip any remaining processing
692 if (!pAstCfg->xInp[zMI].hRxSio)
693 {
694 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
695 (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
697 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
698 continue;
699 }
701 // if here then we have a valid input so query its status
702 errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig);
703 if (errno)
704 {
705 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
706 continue;
707 }
709 // If master decoder is not enabled, or the input is unlocked, then do nothing
710 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
711 GATEMP_INDEX_DEC);
712 if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
713 {
714 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
715 continue;
716 }
718 // If no source selected then do nothing
719 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
720 GATEMP_INDEX_DEC);
721 if (tempVar8 == PAF_SOURCE_NONE)
722 {
723 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
724 (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
725 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
726 continue;
727 }
729 // If we want pass processing then proceed directly
730 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
731 GATEMP_INDEX_DEC);
732 if (tempVar8 == PAF_SOURCE_PASS)
733 {
734 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
735 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
736 (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
738 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_PASS);
739 if (pP->fxns->passProcessing)
740 {
741 errno = pP->fxns->passProcessing(pP, pQ, pAsitCfg, NULL);
742 }
743 else
744 {
745 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
746 errno = ASPERR_PASS;
747 }
748 TRACE_VERBOSE0("TaskAsip: continue");
749 continue;
750 }
752 // .....................................................................
753 // At this point we have an enabled input and want to decode something.
754 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
755 // when no decoder is selected there are no calls to IB
756 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
757 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
758 GATEMP_INDEX_DEC);
759 pfpBegin(PFP_ID_ASIT_1, pAsitCfg->taskHandle); // PFP begin
760 gNumPfpAsit1++;
761 // (***) FL: re-visit, hard-coded to use FRAMELENGTH (pP->frameLength) inside function
762 errno = pP->fxns->autoProcessing(pP, pQ, pAsitCfg, tempVar8, NULL);
763 pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS); // PFP end
764 gNumPfpAsit1--;
766 if (errno)
767 {
768 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
769 continue;
770 }
772 // query for input type
773 errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram);
774 if (errno)
775 {
776 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
777 errno = ASPERR_AUTO_PROGRAM;
778 continue;
779 }
781 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
782 sourceProgram, GATEMP_INDEX_DEC);
784 // if input is unclassifiable then do nothing
785 if (sourceProgram == PAF_SOURCE_UNKNOWN)
786 {
787 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
788 continue;
789 }
791 // now that we have some input classification, and possibly an outstanding
792 // input frame, we determine whether or not to call decodeProcessing and with
793 // what decAlg.
794 sourceSelect = PAF_SOURCE_NONE;
795 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
796 GATEMP_INDEX_DEC);
797 switch (tempVar8)
798 {
799 // If autodetecting, decoding everything, and input is something
800 // (i.e. bitstream or PCM) then decode.
801 case PAF_SOURCE_AUTO:
802 if (sourceProgram >= PAF_SOURCE_PCM)
803 {
804 sourceSelect = sourceProgram;
805 }
806 break;
808 // If autodetecting, decoding only PCM, and input is PCM then decode.
809 case PAF_SOURCE_PCMAUTO:
810 if (sourceProgram == PAF_SOURCE_PCM)
811 {
812 sourceSelect = sourceProgram;
813 }
814 break;
816 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
817 case PAF_SOURCE_BITSTREAM:
818 if (sourceProgram >= PAF_SOURCE_AC3)
819 {
820 sourceSelect = sourceProgram;
821 }
822 break;
824 // If autodetecting, decoding only DTS, and input is DTS then decode.
825 case PAF_SOURCE_DTSALL:
826 switch (sourceProgram)
827 {
828 case PAF_SOURCE_DTS11:
829 case PAF_SOURCE_DTS12:
830 case PAF_SOURCE_DTS13:
831 case PAF_SOURCE_DTS14:
832 case PAF_SOURCE_DTS16:
833 case PAF_SOURCE_DTSHD:
834 sourceSelect = sourceProgram;
835 break;
836 }
837 break;
839 // All others, e.g., force modes, fall through to here.
840 // If user made specific selection then program must match select.
841 // (NB: this compare relies on ordering of PAF_SOURCE)
842 default:
843 sourceSelect = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
844 GATEMP_INDEX_DEC);
845 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
846 {
847 if (sourceProgram != sourceSelect)
848 {
849 sourceSelect = PAF_SOURCE_NONE;
850 }
851 }
852 break;
853 }
855 // if we didn't find any matches then skip
856 if (sourceSelect == PAF_SOURCE_NONE)
857 {
858 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
859 continue;
860 }
862 // FL: debug, reset IB capture buffer
863 capIbReset();
864 gCapIbReset_cnt++;
865 Log_info0("capIbReset()");
867 // FL: send source select message to slave
868 *(Int32 *)&asipMsgBuf[0] = sourceSelect;
869 if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
870 asipMsgBuf, NULL) != ASP_MSG_NO_ERR)
871 {
872 TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
873 SW_BREAKPOINT;
874 }
876 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
877 // iff we are in this top level state machine and specifically not in decodeProcessing
878 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
880 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
882 // Reduce priority level since autodetection complete
883 Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)-1);
885 gAspProfileEnable=1; // enable ASP profiling
887 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
888 errno = pP->fxns->decodeProcessing(pP, pQ, pAsitCfg, sourceSelect);
889 if (errno)
890 {
891 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
892 }
893 else
894 {
895 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
896 }
898 gAspProfileEnable=0; // disable ASP profiling
900 // Increase priority level since decoding complete
901 Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)+1);
903 // FL: send dec exit message to slave
904 if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
905 != ASP_MSG_NO_ERR)
906 {
907 TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
908 SW_BREAKPOINT;
909 }
911 } // End of main processing loop for (;;)
913 //Log_info0("Exit taskAsipFxn()");
914 }
916 // -----------------------------------------------------------------------------
917 // ASIT Initialization Function - Memory Allocation
918 //
919 // Name: PAF_ASIT_initPhaseMalloc
920 // Purpose: Audio Stream Input Task Function for initialization of data pointers
921 // by allocation of memory.
922 // From: audioStream1Task or equivalent
923 // Uses: See code.
924 // States: x
925 // Return: 0 on success.
926 // Source code line number on MEM_calloc failure.
927 // Trace: Message Log "trace" in Debug Project Configuration reports:
928 // * State information as per parent.
929 // * Memory allocation errors.
930 //
931 Int
932 PAF_ASIT_initPhaseMalloc(
933 const PAF_ASIT_Params *pP,
934 const PAF_ASIT_Patchs *pQ,
935 PAF_ASIT_Config *pAsitCfg
936 )
937 {
938 PAF_AST_Config *pAstCfg;
939 Int as; /* Audio Stream Number (1, 2, etc.) */
940 Int zMS;
941 Error_Block eb;
942 IHeap_Handle decHeapHandle;
944 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
945 as = pAstCfg->as;
946 zMS = pAstCfg->masterStr;
948 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
950 // Initialize error block
951 Error_init(&eb);
953 /* Input memory */
954 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
955 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
956 {
957 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
958 SW_BREAKPOINT;
959 return __LINE__;
960 }
961 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xInp) %d bytes from space %d at 0x%x.",
962 INPUTN * sizeof (*pAstCfg->xInp),
963 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
965 /* Decode memory */
966 #ifdef NON_CACHE_STATUS
967 decHeapHandle = (IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM;
968 #else
969 decHeapHandle = (IHeap_Handle)HEAP_INTERNAL1_SHM;
970 #endif
971 if (!(pAstCfg->xDec = Memory_calloc(decHeapHandle,
972 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
973 {
974 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
975 SW_BREAKPOINT;
976 return __LINE__;
977 }
979 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xDec) %d bytes from space %d at 0x%x.",
980 DECODEN * sizeof (*pAstCfg->xDec),
981 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
983 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
984 return 0;
985 } //PAF_ASIT_initPhaseMalloc
987 // -----------------------------------------------------------------------------
988 // ASIT Initialization Function - Memory Initialization from Configuration
989 //
990 // Name: PAF_ASIT_initPhaseConfig
991 // Purpose: Audio Stream Task Function for initialization of data values
992 // from parameters.
993 // From: audioStream1Task or equivalent
994 // Uses: See code.
995 // States: x
996 // Return: 0 on success.
997 // Other as per initFrame0 and initFrame1.
998 // Trace: Message Log "trace" in Debug Project Configuration reports:
999 // * State information as per parent.
1000 //
1001 Int
1002 PAF_ASIT_initPhaseConfig(
1003 const PAF_ASIT_Params *pP,
1004 const PAF_ASIT_Patchs *pQ,
1005 PAF_ASIT_Config *pAsitCfg
1006 )
1007 {
1008 PAF_AST_Config *pAstCfg;
1009 Int as; /* Audio Stream Number (1, 2, etc.) */
1010 Int z; /* input/encode/stream/decode/output counter */
1011 Int zMS;
1013 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1014 as = pAstCfg->as;
1015 zMS = pAstCfg->masterStr;
1017 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1019 //
1020 // Unspecified elements have been initialized to zero during alloc
1021 //
1023 for (z=INPUT1; z < INPUTN; z++)
1024 {
1025 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
1026 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
1027 }
1029 for (z=DECODE1; z < DECODEN; z++)
1030 {
1031 Int zI = pP->inputsFromDecodes[z];
1032 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1033 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1034 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1035 }
1037 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1038 return 0;
1039 } //PAF_ASIT_initPhaseConfig
1041 // -----------------------------------------------------------------------------
1042 // ASIT Initialization Function - ACP Algorithm Instantiation
1043 //
1044 // Name: PAF_ASIT_initPhaseAcpAlg
1045 // Purpose: Audio Stream Input Task Function for initialization of ACP by
1046 // instantiation of the algorithm.
1047 // From: audioStream1Task or equivalent
1048 // Uses: See code.
1049 // States: x
1050 // Return: 0 on success.
1051 // Source code line number on ACP Algorithm creation failure.
1052 // Trace: Message Log "trace" in Debug Project Configuration reports:
1053 // * State information as per parent.
1054 // * Memory allocation errors.
1055 //
1056 Int
1057 PAF_ASIT_initPhaseAcpAlg(
1058 const PAF_ASIT_Params *pP,
1059 const PAF_ASIT_Patchs *pQ,
1060 PAF_ASIT_Config *pAsitCfg
1061 )
1062 {
1063 PAF_AST_Config *pAstCfg;
1064 Int as; /* Audio Stream Number (1, 2, etc.) */
1065 Int z; /* input/encode/stream/decode/output counter */
1066 Int betaPrimeOffset;
1067 ACP_Handle acp;
1068 Int zMS;
1069 Int zS, zX;
1071 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1072 as = pAstCfg->as;
1073 zMS = pAstCfg->masterStr;
1075 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1077 ACP_MDS_init();
1079 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1080 {
1081 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1082 return __LINE__;
1083 }
1084 pAsitCfg->acp = acp;
1086 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1087 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1089 for (z=INPUT1; z < INPUTN; z++)
1090 {
1091 zS = z;
1092 for (zX = DECODE1; zX < DECODEN; zX++)
1093 {
1094 if (pP->inputsFromDecodes[zX] == z)
1095 {
1096 zS = pP->streamsFromDecodes[zX];
1097 break;
1098 }
1099 }
1100 acp->fxns->attach(acp, ACP_SERIES_STD,
1101 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1102 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1103 /* Ignore errors, not reported. */
1104 }
1106 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1108 return 0;
1109 } //PAF_ASIT_initPhaseAcpAlg
1111 // -----------------------------------------------------------------------------
1112 // ASIT Initialization Function - Common Memory
1113 //
1114 // Name: PAF_ASIT_initPhaseCommon
1115 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1116 // From: audioStream1Task or equivalent
1117 // Uses: See code.
1118 // States: x
1119 // Return: 0 on success.
1120 // Source code line number on PAF_ALG_alloc failure.
1121 // Source code line number on PAF_ALG_mallocMemory failure.
1122 // Source code line number on Decode Chain initialization failure.
1123 // Source code line number on ASP Chain initialization failure.
1124 // Source code line number on Encode Chain initialization failure.
1125 // Trace: Message Log "trace" in Debug Project Configuration reports:
1126 // * State information as per parent.
1127 // * Memory allocation errors.
1128 //
1129 Int
1130 PAF_ASIT_initPhaseCommon(
1131 const PAF_ASIT_Params *pP,
1132 const PAF_ASIT_Patchs *pQ,
1133 PAF_ASIT_Config *pAsitCfg
1134 )
1135 {
1136 PAF_AST_Config *pAstCfg;
1137 Int as; /* Audio Stream Number (1, 2, etc.) */
1138 Int z; /* stream counter */
1139 ACP_Handle acp;
1140 PAF_IALG_Config pafAlgConfig;
1141 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1143 acp = pAsitCfg->acp;
1144 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1145 as = pAstCfg->as;
1147 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1149 //
1150 // Determine memory needs and instantiate algorithms across audio streams
1151 //
1152 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1153 PAF_ALG_setup(&pafAlgConfig,
1154 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1155 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1156 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1157 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1158 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1159 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1160 HEAP_CLEAR);
1162 if (pP->fxns->headerPrint)
1163 {
1164 pP->fxns->headerPrint();
1165 }
1167 for (z = STREAM1; z < STREAMN; z++)
1168 {
1169 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1171 //
1172 // Determine common memory for:
1173 // (1) Logical Input drivers
1174 //
1175 // Decode Algorithms common memory determined in ASP Slave.
1176 //
1177 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1179 //
1180 // Determine common memory needs of Logical Input driver
1181 //
1183 // really need to loop over all inputs for this stream using the tables
1184 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1185 // patch, and not needed for FS11, since there is only one input.
1186 if (INPUT1 <= z && z < INPUTN)
1187 {
1188 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1189 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1190 {
1191 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1192 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1193 SW_BREAKPOINT;
1194 return __LINE__;
1195 }
1196 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1197 if (pP->fxns->allocPrint)
1198 {
1199 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1200 }
1201 }
1202 }
1203 {
1204 // Changes made to share scratch between zones
1205 // Assume maximum 3 zones and scratch common memory is at offset 0;
1206 int max=0;
1207 for (z=STREAM1; z<STREAMN; z++)
1208 {
1209 if (max < common[z][0].size)
1210 {
1211 max = common[z][0].size;
1212 }
1213 }
1214 common[STREAM1][0].size=max;
1215 for (z=STREAM1+1; z<STREAMN; z++)
1216 {
1217 common[z][0].size = 0;
1218 }
1219 }
1221 //
1222 // Allocate common memory for:
1223 // (1) Logical Input drivers
1224 //
1225 for (z = STREAM1; z < STREAMN; z++)
1226 {
1227 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1228 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1229 {
1230 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1231 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1232 SW_BREAKPOINT;
1233 return __LINE__;
1234 }
1235 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1236 // share zone0 scratch with all zones
1237 common[z][0].base = common[0][0].base;
1238 if (pP->fxns->commonPrint)
1239 {
1240 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1241 }
1243 //
1244 // Allocate non-common memories for Logical IO drivers
1245 // Since these structures are used at run-time we allocate from external memory
1246 if (INPUT1 <= z && z < INPUTN)
1247 {
1248 PAF_ASP_Chain *chain;
1249 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1250 as+z, z);
1251 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1252 HEAP_EXTERNAL, as+z, acp, &trace,
1253 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1254 if (!chain)
1255 {
1256 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1257 return __LINE__;
1258 }
1259 }
1260 }
1261 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1263 return 0;
1264 } //PAF_ASIT_initPhaseCommon
1266 // (***) FL: candidate for removal
1267 // -----------------------------------------------------------------------------
1268 // ASIT Initialization Function - Algorithm Keys
1269 //
1270 // Name: PAF_ASIT_initPhaseAlgKey
1271 // Purpose: Audio Stream Input Task Function for initialization of data values
1272 // from parameters for Algorithm Keys.
1273 // From: audioStream1Task or equivalent
1274 // Uses: See code.
1275 // States: x
1276 // Return: 0.
1277 // Trace: Message Log "trace" in Debug Project Configuration reports:
1278 // * State information as per parent.
1279 //
1280 // .............................................................................
1281 Int
1282 PAF_ASIT_initPhaseAlgKey(
1283 const PAF_ASIT_Params *pP,
1284 const PAF_ASIT_Patchs *pQ,
1285 PAF_ASIT_Config *pAsitCfg
1286 )
1287 {
1288 PAF_AST_Config *pAstCfg;
1289 Int as; /* Audio Stream Number (1, 2, etc.) */
1292 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1293 as = pAstCfg->as;
1294 (void)as; // clear compiler warning in case not used with tracing disabled
1296 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1298 #if 0 // FL: slave
1299 for (z=DECODE1; z < DECODEN; z++)
1300 {
1301 for (s=0; s < pP->pDecAlgKey->length; s++)
1302 {
1303 if ((pP->pDecAlgKey->code[s].full != 0) &&
1304 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1305 {
1306 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1307 /* Cast in interface, for now --Kurt */
1308 }
1309 else
1310 {
1311 pC->xDec[z].decAlg[s] = NULL;
1312 }
1313 }
1314 }
1315 #endif
1317 return 0;
1318 } //PAF_ASIT_initPhaseAlgKey
1320 // -----------------------------------------------------------------------------
1321 // ASIT Initialization Function - I/O Devices
1322 //
1323 // Name: PAF_ASIT_initPhaseDevice
1324 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1325 // From: audioStream1Task or equivalent
1326 // Uses: See code.
1327 // States: x
1328 // Return: 0 on success.
1329 // Source code line number on device allocation failure.
1330 // Trace: Message Log "trace" in Debug Project Configuration reports:
1331 // * State information as per parent.
1332 // * Memory allocation errors.
1333 //
1334 Int
1335 PAF_ASIT_initPhaseDevice(
1336 const PAF_ASIT_Params *pP,
1337 const PAF_ASIT_Patchs *pQ,
1338 PAF_ASIT_Config *pAsitCfg
1339 )
1340 {
1341 PAF_AST_Config *pAstCfg;
1342 Int as; /* Audio Stream Number (1, 2, etc.) */
1343 Int z; /* input/output counter */
1344 PAF_SIO_IALG_Obj *pObj;
1345 PAF_SIO_IALG_Config *pAlgConfig;
1346 PAF_IALG_Config pafAlgConfig;
1349 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1350 as = pAstCfg->as;
1351 (void)as; // clear compiler warning in case not used with tracing disabled
1353 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1355 if (pP->fxns->bufMemPrint)
1356 {
1357 PAF_ALG_setup (&pafAlgConfig,
1358 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1359 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1360 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1361 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1362 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1363 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1364 HEAP_CLEAR);
1365 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1366 }
1368 for (z=INPUT1; z < INPUTN; z++)
1369 {
1370 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1372 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1373 pAlgConfig = &pObj->config;
1375 pAstCfg->xInp[z].hRxSio = NULL;
1377 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1378 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1379 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1380 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1381 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1382 pConfig->sizeofElement = 2;
1383 pConfig->precision = 16;
1385 if (pP->fxns->bufMemPrint)
1386 {
1387 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1388 }
1389 }
1391 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1393 return 0;
1394 } //PAF_ASIT_initPhaseDevice
1396 // (***) FL: move to ASOT
1397 // -----------------------------------------------------------------------------
1398 // ASIT Initialization Function - Decoder Output Circular Buffer
1399 //
1400 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1401 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1402 // From: audioStream1Task or equivalent
1403 // Uses: See code.
1404 // States: x
1405 // Return: 0 on success.
1406 // Source code line number on device allocation failure.
1407 // Trace: Message Log "trace" in Debug Project Configuration reports:
1408 // * State information as per parent.
1409 // * Memory allocation errors.
1410 //
1411 Int
1412 PAF_ASIT_initPhaseDecOpCircBuf(
1413 const PAF_ASIT_Params *pP,
1414 const PAF_ASIT_Patchs *pQ,
1415 PAF_ASIT_Config *pAsitCfg
1416 )
1417 {
1418 PAF_AST_Config *pAstCfg;
1419 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1420 Int as; /* Audio Stream Number (1, 2, etc.) */
1421 Int zMS;
1422 Int z; /* decode counter */
1423 Int errno; /* error number */
1424 Error_Block eb;
1425 Int i;
1426 ACP_Handle acp;
1427 Int betaPrimeOffset;
1428 Int zS;
1430 // FL: (***)revisit
1431 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1432 as = pAstCfg->as;
1433 zMS = pAstCfg->masterStr;
1435 // Decode output circular buffer memory
1436 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1437 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1438 {
1439 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1440 SW_BREAKPOINT;
1441 return __LINE__;
1442 }
1444 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pAsitCfg->xDecOpCb) %d bytes from space %d at 0x%x.",
1445 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1446 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1448 for (z=DECODE1; z < DECODEN; z++)
1449 {
1450 pCb = &pAstCfg->xDecOpCb[z];
1452 // allocate audio frame circular buffer
1453 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1454 {
1455 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1456 SW_BREAKPOINT;
1457 }
1458 // allocate audio frame PCM sample pointer array
1459 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1460 {
1461 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)))
1462 {
1463 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1464 SW_BREAKPOINT;
1465 }
1466 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)))
1467 {
1468 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1469 SW_BREAKPOINT;
1470 }
1471 }
1472 // allocate PCM sample buffer
1473 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1474 {
1475 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1476 SW_BREAKPOINT;
1477 }
1478 pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1479 // allocate Metadata buffers
1480 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)))
1481 {
1482 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1483 SW_BREAKPOINT;
1484 }
1485 pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1487 #ifdef CB_RW_OP_CAP_PP // debug
1488 // allocate debug buffer
1489 if (!(pCb->cb_samples_op = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt32), 4, &eb)))
1490 {
1491 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1492 SW_BREAKPOINT;
1493 }
1495 // allocate debug buffer
1496 if (!(pCb->cb_op_owner = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1497 {
1498 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1499 SW_BREAKPOINT;
1500 }
1502 // allocate debug buffer
1503 if (!(pCb->cb_afRdIdx = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1504 {
1505 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1506 SW_BREAKPOINT;
1507 }
1509 // allocate debug buffer
1510 if (!(pCb->cb_afWrtIdx = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1511 {
1512 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1513 SW_BREAKPOINT;
1514 }
1516 // allocate debug buffer
1517 if (!(pCb->cb_numAfCb = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1518 {
1519 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1520 SW_BREAKPOINT;
1521 }
1522 #endif
1523 }
1525 for (z = DECODE1; z < DECODEN; z++)
1526 {
1527 //
1528 // Initialize decoder output circular
1529 //
1531 // Initialize status
1532 pAstCfg->xDecOpCb[z].cbStatus = *pP->z_pDecOpCircBufStatus[z];
1534 // Default initialization
1535 errno = cbInit(pCb);
1536 if (errno)
1537 {
1538 SW_BREAKPOINT; // FL: debug
1539 return errno;
1540 }
1541 }
1543 // Get ASIT ACP handle
1544 acp = pAsitCfg->acp;
1545 if (!acp)
1546 {
1547 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: ACP algorithm instance creation failed", as+zMS);
1548 return __LINE__;
1549 }
1551 // Get Beta Prime offset
1552 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1553 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1555 for (z = DECODE1; z < DECODEN; z++)
1556 {
1557 // ACP attach CB
1558 zS = pP->streamsFromDecodes[z];
1559 acp->fxns->attach(acp, ACP_SERIES_STD,
1560 STD_BETA_DECOPCB + betaPrimeOffset * (as-1+zS),
1561 (IALG_Status *)&pAstCfg->xDecOpCb[z].cbStatus);
1562 }
1564 return 0;
1565 } //PAF_ASIT_initPhaseDecOpCircBuf
1568 // -----------------------------------------------------------------------------
1569 // ASIT Initialization Function - Output Init-Sync
1570 //
1571 // Name: PAF_ASIT_initPhaseOutIS
1572 // Purpose: Audio Stream Input Task Function for initialization of Output Init-Sync.
1573 //
1574 Int
1575 PAF_ASIT_initPhaseOutIS(
1576 const PAF_ASIT_Params *pP,
1577 const PAF_ASIT_Patchs *pQ,
1578 PAF_ASIT_Config *pAsitCfg
1579 )
1580 {
1581 PAF_AST_Config *pAstCfg;
1582 Int as; /* Audio Stream Number (1, 2, etc.) */
1583 Int z; /* decode counter */
1584 PAF_AST_OutInitSyncInfo *pOutISI;
1585 Error_Block eb;
1586 Int i;
1589 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1590 as = pAstCfg->as;
1592 /* Output Init-Sync memory */
1593 if (!(pAstCfg->xOutIsi = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM,
1594 DECODEN * sizeof (*pAstCfg->xOutIsi), 4, &eb)))
1595 {
1596 TRACE_TERSE1("PAF_ASIT_initPhaseOutIS: AS%d: Memory_calloc failed", as);
1597 SW_BREAKPOINT;
1598 return __LINE__;
1599 }
1601 // Reset all decoder stage flags
1602 for (z=DECODE1; z < DECODEN; z++)
1603 {
1604 // Get address of Output Init-Sync Info
1605 pOutISI = &pAstCfg->xOutIsi[z];
1606 for (i = 0; i < ASP_OUTIS_NUM_DEC_STAGES; i++)
1607 {
1608 // Reset flag value
1609 pOutISI->decStageOutInitSyncInfo[i].decFlag = 0;
1610 }
1611 }
1613 return 0;
1614 } // PAF_ASIT_initPhaseOutIS
1617 #if 0
1618 // -----------------------------------------------------------------------------
1619 // AST Processing Function - Pass-Through Processing
1620 //
1621 // Name: PAF_AST_passProcessing
1622 // Purpose: Audio Stream Task Function for processing audio data as a
1623 // pass-through from the input driver to the output driver
1624 // for development and testing.
1625 // From: audioStream1Task or equivalent
1626 // Uses: See code.
1627 // States: x
1628 // Return: Error number in standard form (0 on success).
1629 // Trace: Message Log "trace" in Debug Project Configuration reports:
1630 // * State information on initialization.
1631 // * State information on processing.
1632 //
1634 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1635 /* Pass Processing is often omitted from builds to save memory, */
1636 /* and CODE_SECTION/clink constructs facilitate this omission. */
1638 Int
1639 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1640 {
1641 Int z; /* input/output counter */
1642 Int errno = 0; /* error number */
1643 Int getVal;
1644 Int rxNumChan, txNumChan;
1645 Int first;
1646 Int zMD = pC->masterDec;
1647 Int zMI = pP->zone.master;
1650 #ifndef __TI_EABI__
1651 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1652 #endif
1654 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1656 //
1657 // Determine that receive/transmit channels are compatible
1658 //
1660 // Can handle handle only master input
1661 for (z=INPUT1; z < INPUTN; z++) {
1662 if (z != zMI && pC->xInp[z].hRxSio)
1663 return (ASPERR_PASS + 0x01);
1664 }
1666 /* Number of receive/transmit channels */
1668 if (! pC->xInp[zMI].hRxSio)
1669 return (ASPERR_PASS + 0x11);
1670 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1671 return (ASPERR_PASS + 0x12);
1672 if (rxNumChan > NUM_TX_CHAN(zMI))
1673 return (ASPERR_PASS + 0x13);
1675 for (z=OUTPUT1; z < OUTPUTN; z++) {
1676 if (! pC->xOut[zMI].hTxSio)
1677 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1678 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1679 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1680 if (txNumChan > NUM_TX_CHAN(zMI))
1681 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1682 }
1684 //
1685 // Set up receive/transmit
1686 //
1688 SIO_idle (pC->xInp[zMI].hRxSio);
1689 for (z=OUTPUT1; z < OUTPUTN; z++) {
1690 if(SIO_idle (pC->xOut[z].hTxSio))
1691 return ASPERR_IDLE;
1692 }
1694 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1695 return (ASPERR_PASS + 0x14);
1697 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1698 return (ASPERR_PASS + 0x15);
1700 for (z=OUTPUT1; z < OUTPUTN; z++)
1701 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1703 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1704 return ASPERR_PASS + 0x16;
1706 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1707 return ASPERR_PASS + 0x17;
1709 //
1710 // Receive and transmit the data in single-frame buffers
1711 //
1713 first = 1;
1714 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1715 PAF_OutBufConfig *pOutBuf;
1716 PAF_InpBufConfig *pInpBuf;
1718 if (first) {
1719 first = 0;
1721 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1723 for (z=OUTPUT1; z < OUTPUTN; z++) {
1724 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1725 if (getVal > 0) {
1726 errno = ASPERR_ISSUE;
1727 break;
1728 }
1729 else if (getVal < 0) {
1730 errno = -getVal;
1731 break;
1732 }
1734 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1735 return (getVal & 0xff) | ASPERR_MUTE;
1736 }
1737 if (errno)
1738 break;
1740 }
1742 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1743 if (getVal > 0) {
1744 errno = ASPERR_ISSUE;
1745 break;
1746 }
1748 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1750 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1751 if (getVal < 0) {
1752 errno = -getVal;
1753 break;
1754 }
1756 for (z=OUTPUT1; z < OUTPUTN; z++) {
1757 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1758 if (getVal < 0) {
1759 errno = -getVal;
1760 break;
1761 }
1762 }
1763 if( errno )
1764 break;
1766 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1768 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1769 break;
1771 for (z=OUTPUT1; z < OUTPUTN; z++) {
1772 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1773 if (getVal > 0) {
1774 errno = ASPERR_ISSUE;
1775 break;
1776 }
1777 else if (getVal < 0) {
1778 errno = -getVal;
1779 break;
1780 }
1781 }
1782 if( errno )
1783 break;
1784 }
1786 //
1787 // Close down receive/transmit
1788 //
1790 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1792 for (z=OUTPUT1; z < OUTPUTN; z++) {
1793 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1794 if (! errno)
1795 errno = (getVal & 0xff) | ASPERR_MUTE;
1796 /* convert to sensical errno */
1797 }
1798 }
1800 SIO_idle (pC->xInp[zMI].hRxSio);
1801 for (z=OUTPUT1; z < OUTPUTN; z++)
1802 SIO_idle (pC->xOut[z].hTxSio);
1804 return errno;
1806 } //PAF_AST_passProcessing
1807 #endif // #if 0
1809 #if 0
1810 // -----------------------------------------------------------------------------
1811 // AST Processing Function Helper - Pass-Through Processing Patch Point
1812 //
1813 // Name: PAF_AST_passProcessingCopy
1814 // Purpose: Pass-Through Processing Function for copying audio data
1815 // from the input buffer to the output buffer.
1816 // From: AST Parameter Function -> passProcessing
1817 // Uses: See code.
1818 // States: x
1819 // Return: Error number in standard form (0 on success).
1820 // Trace: Message Log "trace" in Debug Project Configuration reports:
1821 // x
1822 //
1824 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1825 /* Pass Processing is often omitted from builds to save memory, */
1826 /* and CODE_SECTION/clink constructs facilitate this omission. */
1828 Int
1829 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1830 {
1831 Int z; /* output counter */
1832 Int errno; /* error number */
1833 Int i;
1834 Int rxNumChan, txNumChan;
1835 Int zMI = pP->zone.master;
1838 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1840 // Copy data from input channels to output channels one of two ways:
1842 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1843 return (ASPERR_PASS + 0x12);
1845 for (z=OUTPUT1; z < OUTPUTN; z++) {
1846 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1847 return (ASPERR_PASS + 0x22);
1849 if( txNumChan <= rxNumChan ) {
1851 // Copy one to one, ignoring later rx channels as needed.
1853 for( i=0; i < txNumChan; i++ ) {
1854 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1855 if( errno )
1856 return errno;
1857 }
1858 }
1859 else {
1861 // Copy one to many, repeating earlier rx channels as needed.
1863 Int from, to;
1865 from = 0;
1866 to = 0;
1867 while( to < txNumChan ) {
1868 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1869 if( errno )
1870 return errno;
1872 from++;
1873 to++;
1874 if( from == rxNumChan )
1875 from = 0;
1876 }
1877 }
1878 }
1880 return 0;
1881 } //PAF_AST_passProcessingCopy
1882 #endif // #if 0
1884 // -----------------------------------------------------------------------------
1885 // ASIT Processing Function - Auto Processing
1886 //
1887 // Name: PAF_ASIT_autoProcessing
1888 // Purpose: Audio Stream Input Task Function for processing audio data to
1889 // determine the input type without output.
1890 // From: audioStream1Task or equivalent
1891 // Uses: See code.
1892 // States: x
1893 // Return: Error number in standard or SIO form (0 on success).
1894 // Trace: Message Log "trace" in Debug Project Configuration reports:
1895 // * State information on initialization.
1896 //
1898 #define DECSIOMAP(X) \
1899 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1901 Int
1902 PAF_ASIT_autoProcessing(
1903 const PAF_ASIT_Params *pP,
1904 const PAF_ASIT_Patchs *pQ,
1905 PAF_ASIT_Config *pAsitCfg,
1906 Int inputTypeSelect,
1907 ALG_Handle pcmAlgMaster
1908 )
1909 {
1910 PAF_AST_Config *pAstCfg;
1911 Int as; /* Audio Stream Number (1, 2, etc.) */
1912 Int errno = 0; /* error number */
1913 Int nbytes;
1914 Int frameLength;
1915 Int zMD;
1916 Int zMI;
1917 Int zMS;
1919 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1920 as = pAstCfg->as;
1921 zMD = pAstCfg->masterDec;
1922 zMS = pAstCfg->masterStr;
1923 zMI = pP->zone.master;
1925 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1927 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1928 PAF_SIO_CONTROL_SET_SOURCESELECT,
1929 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1930 {
1931 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1932 return errno;
1933 }
1934 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1935 // pC->xDec[zMD].decodeStatus.bufferRatio);
1936 frameLength = FRAMELENGTH; // (***) FL: fix PCM frameLength
1938 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1939 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1940 {
1941 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1942 errno, ASPERR_AUTO_LENGTH);
1943 return ASPERR_AUTO_LENGTH;
1944 }
1946 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1947 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1948 PAF_SIO_REQUEST_SYNC))
1949 {
1950 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1951 errno, ASPERR_ISSUE);
1952 return ASPERR_ISSUE;
1953 }
1955 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1957 // all of the sync scan work is done in this call. If the error returned
1958 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1959 // error so we mask it off.
1960 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1961 if (nbytes == -DIBERR_SYNC)
1962 {
1963 #if 0 // (***) FL: shows timing of autosync restart
1964 // (***) debug // B5
1965 {
1966 static Uint8 toggleState = 0;
1967 if (toggleState == 0)
1968 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
1969 else
1970 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
1971 toggleState = ~(toggleState);
1972 }
1973 #endif
1974 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1975 return nbytes;
1976 }
1977 if (nbytes != sizeof(PAF_InpBufConfig))
1978 {
1979 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1980 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1981 return ASPERR_RECLAIM;
1982 }
1983 if (errno)
1984 {
1985 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1986 }
1987 return errno;
1988 } //PAF_ASIT_autoProcessing
1990 UInt32 gProbe1Err=0;
1991 UInt32 gProbe2Err=0;
1992 UInt32 gMajorAuMissed=0;
1994 // -----------------------------------------------------------------------------
1995 // ASIT Processing Function - Decode Processing
1996 //
1997 // Name: PAF_ASIT_decodeProcessing
1998 // Purpose: Audio Stream Input Task Function for processing audio data.
1999 // From: audioStream1Task or equivalent
2000 // Uses: See code.
2001 // States: x
2002 // Return: Error number in standard form (0 on success).
2003 // Trace: Message Log "trace" in Debug Project Configuration reports:
2004 // * State information on initialization (via children).
2005 // * State information on processing (via children).
2006 // * Decode warnings.
2007 //
2008 // When "writeDECModeContinuous" is used for zMI input/decode:
2009 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
2010 // (a) if "writeDECCommandRestart" is used
2011 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
2012 // (b) if "writeDECSourceSelectNone" is used
2013 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
2014 // (c) if an error occurs in
2015 // INIT
2016 // CONT ("subsequent block state", which "Establish[es] secondary timing")
2017 // -> PAF_AST_decodeCont(): "Await slave inputs"
2018 // STREAM (errno |= PAF_COMPONENT_ASP)
2019 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
2020 // [ the latter errors lead to "switch_break:"
2021 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
2022 //
2023 // [ Notably, in FINAL ("frame-finalization state")
2024 // -> PAF_AST_decodeFinalTest() is *not* called,
2025 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
2026 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
2027 //
2028 // States in which error can't occur:
2029 // AGAIN ("subsequent initial state")
2030 //
2031 // States in which (some) errors must be handled:
2032 // INFO1 ("first frame state")
2033 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
2034 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
2035 // ?*? but what about ASPERR_RESYNC from same call ?*?
2036 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
2037 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
2038 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
2039 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
2040 // - enc->fxns->info()
2041 // - pP->fxns->setCheckRateX()
2042 // - pP->fxns->startOutput()
2043 // - "Start slave inputs if necessary"
2044 // INFO2 ("subsequent frame state")
2045 // -> PAF_AST_decodeInfo(): (see above)
2046 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
2047 // - pP->fxns->setCheckRateX()
2048 // TIME ("timing state")
2049 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
2050 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
2051 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
2052 // (*OK* don't try to recover from this*)
2053 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
2054 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
2055 // possibly in PAF_AST_decodeProcessing() itself **
2056 // DECODE ("decode state")
2057 // -> PAF_AST_decodeDecode(): pass on error from
2058 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
2059 // - dec->fxns->reset()
2060 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
2061 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
2062 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
2063 Int
2064 PAF_ASIT_decodeProcessing(
2065 const PAF_ASIT_Params *pP,
2066 const PAF_ASIT_Patchs *pQ,
2067 PAF_ASIT_Config *pAsitCfg,
2068 Int sourceSelect
2069 )
2070 {
2071 PAF_AST_Config *pAstCfg;
2072 //Int as = pAsitCfg->as; /* Audio Stream Number (1, 2, etc.) */
2073 Int z; /* decode counter */
2074 Int errno; /* error number */
2075 Int getVal;
2076 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
2077 ALG_Handle alg[DECODEN_MAX];
2078 Int zMD;
2079 Int zMS;
2080 Int size;
2081 //PAF_InpBufConfig *pIpBufConfig;
2082 Int frame; // decoder input frame count
2083 Int block; // (***) FL: formerly -- decoder output block count / input frame
2084 Int8 tempVar8, temp2Var8;
2086 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2087 zMD = pAstCfg->masterDec;
2088 zMS = pAstCfg->masterStr;
2090 for (z=DECODE1; z < DECODEN; z++)
2091 {
2092 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
2093 }
2094 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
2096 //
2097 // Receive and process the data in single-frame buffers
2098 //
2100 state = INIT;
2101 errno = 0; /* error number */
2103 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2104 GATEMP_INDEX_DEC);
2105 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
2107 for (;;)
2108 {
2109 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2110 GATEMP_INDEX_DEC);
2111 if (tempVar8 == PAF_SOURCE_NONE)
2112 {
2113 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
2114 state = QUIT;
2115 }
2117 // Process commands (decode)
2118 getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
2119 if (getVal)
2120 {
2121 if (state != INIT) // no need to restart/abort if not yet started
2122 {
2123 if (getVal == ASPERR_QUIT)
2124 {
2125 state = QUIT;
2126 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
2127 }
2128 else if (getVal == ASPERR_ABORT)
2129 {
2130 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
2132 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2133 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2134 gNumPfpAsit2--;
2136 return getVal;
2137 }
2138 else
2139 {
2140 /* ignore */;
2141 }
2142 }
2143 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
2144 }
2146 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
2147 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
2149 // Process state (decode)
2150 switch (state)
2151 {
2152 case INIT: // initial state
2153 gAsipInitCnt++;
2154 Log_info0("TaskAsip: state=INIT");
2156 errno = pP->fxns->decodeInit(pP, pQ, pAsitCfg, sourceSelect);
2157 if (errno)
2158 {
2159 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
2160 break;
2161 }
2163 frame = 0;
2164 block = 0;
2166 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2167 state = INFO1;
2168 continue;
2170 case INFO1: // first frame state
2171 gAsipInfo1Cnt++;
2172 Log_info0("TaskAsip: state=INFO1");
2174 // Establish primary timing
2175 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2176 if (errno)
2177 {
2178 gAsipInfo1_PrimaryErrCnt++;
2179 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2180 break;
2181 }
2183 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2184 GATEMP_INDEX_DEC);
2185 temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
2186 GATEMP_INDEX_DEC);
2187 // Don't start decode until major access unit is found.
2188 if (((tempVar8 == PAF_SOURCE_THD) ||
2189 (tempVar8 == PAF_SOURCE_DXP) ||
2190 (tempVar8 == PAF_SOURCE_DTSHD)) &&
2191 (temp2Var8 == PAF_SAMPLERATE_UNKNOWN))
2192 {
2193 Int z;
2194 for (z=DECODE1; z < DECODEN; z++)
2195 {
2196 Int zI = pP->inputsFromDecodes[z];
2197 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2198 GATEMP_INDEX_DEC);
2199 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2200 {
2201 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2202 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2203 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2204 {
2205 gProbe2Err++;
2206 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2208 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2209 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2210 gNumPfpAsit2--;
2212 return (ASPERR_ISSUE);
2213 }
2214 }
2215 }
2216 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2217 gMajorAuMissed++; // debug
2218 frame++;
2219 state = INFO1;
2220 continue;
2221 }
2222 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2224 // Establish secondary timing
2225 errno = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, frame, block);
2226 if (errno)
2227 {
2228 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2229 gAsipInfo1_ErrCnt++;
2230 break;
2231 }
2233 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2234 state = DECODE;
2235 continue;
2237 case INFO2: // subsequent frame state
2238 gAsipInfo2Cnt++;
2239 Log_info0("TaskAsip: state=INFO2");
2241 // Establish primary timing
2242 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2243 if (errno)
2244 {
2245 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2246 gAsipInfo2_PrimaryErrCnt++;
2247 break;
2248 }
2250 // Measure cycles in decode processing loop.
2251 // Only measures cycles spent in loop.
2252 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS); // PFP end
2253 gNumPfpAsit2--;
2254 pfpBegin(PFP_ID_ASIT_2, pAsitCfg->taskHandle); // PFP begin
2255 gNumPfpAsit2++;
2257 errno = pP->fxns->decodeInfo2(pP, pQ, pAsitCfg, frame, block);
2258 if (errno)
2259 {
2260 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2261 gAsipInfo2_ErrCnt++;
2262 break;
2263 }
2265 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2266 state = DECODE;
2267 continue;
2269 case DECODE: // decode state
2270 gAsipDecodeCnt++;
2271 Log_info0("TaskAsip: state=DECODE");
2273 errno = pP->fxns->decodeDecode(pP, pQ, pAsitCfg, sourceSelect, frame, block);
2274 if (errno)
2275 {
2276 gAsipDecodeErrCnt++;
2277 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2278 break;
2279 }
2281 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2282 state = FINAL;
2283 continue;
2285 case FINAL: // frame-finalization state
2286 gAsipFinalCnt++;
2287 Log_info0("TaskAsip: state=FINAL");
2289 // Check for final frame, and if indicated:
2290 // - Exit state machine to "complete" processing.
2291 if (pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, frame, block))
2292 {
2293 break;
2294 }
2296 frame++;
2297 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2298 state = INFO2;
2299 continue;
2301 case QUIT: // exit state
2302 gAsipQuitCnt++;
2303 Log_info0("TaskAsip: state=QUIT");
2305 // Quit:
2306 // - Set error number registers.
2307 // - Exit state machine to "decode complete" processing.
2308 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2309 errno = ASPERR_QUIT;
2310 break;
2312 default: // unknown state
2314 // Unknown:
2315 // - Set error number registers.
2316 // - Exit state machine to "decode complete" processing.
2318 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2319 errno = ASPERR_UNKNOWNSTATE;
2320 break;
2322 } // End of switch (state).
2324 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2325 if (pP->fxns->decodeComplete(pP, pQ, pAsitCfg, alg, frame, block))
2326 {
2327 /* ignored? */;
2328 }
2330 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2332 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2333 //pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2334 //gNumPfpAsit2--;
2336 //return errno;
2337 break;
2338 } // End of for (;;) to Receive, process, and transmit the data.
2340 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2341 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2342 gNumPfpAsit2--;
2344 return errno;
2345 } //PAF_ASIT_decodeProcessing
2347 // -----------------------------------------------------------------------------
2348 // ASIT Decoding Function - Decode Command Processing
2349 //
2350 // Name: PAF_ASIT_decodeCommand
2351 // Purpose: Decoding Function for processing Decode Commands.
2352 // From: AST Parameter Function -> decodeProcessing
2353 // Uses: See code.
2354 // States: x
2355 // Return: Error number in standard form (0 on success).
2356 // Trace: Message Log "trace" in Debug Project Configuration reports:
2357 // * Command execution.
2358 //
2360 Int
2361 PAF_ASIT_decodeCommand(
2362 const PAF_ASIT_Params *pP,
2363 const PAF_ASIT_Patchs *pQ,
2364 PAF_ASIT_Config *pAsitCfg
2365 )
2366 {
2367 PAF_AST_Config *pAstCfg;
2368 Int as; /* Audio Stream Number (1, 2, etc.) */
2369 Int z; /* decode counter */
2370 Int zS;
2371 Int8 tempVar8;
2373 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2374 as = pAstCfg->as;
2376 for (z=DECODE1; z < DECODEN; z++)
2377 {
2378 zS = pP->streamsFromDecodes[z];
2379 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2380 GATEMP_INDEX_DEC);
2381 if (!(tempVar8 & 0x80))
2382 {
2383 switch (tempVar8)
2384 {
2385 case 0: // command none - process
2386 tempVar8 |= 0x80;
2387 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2388 tempVar8, GATEMP_INDEX_DEC);
2389 break;
2390 case 1: // command abort - leave now
2391 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2392 tempVar8 |= 0x80;
2393 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2394 tempVar8, GATEMP_INDEX_DEC);
2395 return (ASPERR_ABORT);
2396 case 2: // command restart - leave later
2397 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2398 tempVar8 |= 0x80;
2399 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2400 tempVar8, GATEMP_INDEX_DEC);
2401 return (ASPERR_QUIT);
2402 default: // command unknown - ignore
2403 break;
2404 }
2405 }
2406 }
2408 return 0;
2409 } //PAF_ASIT_decodeCommand
2411 // -----------------------------------------------------------------------------
2412 // ASIT Decoding Function - Reinitialization of Decode
2413 //
2414 // Name: PAF_ASIT_decodeInit
2415 // Purpose: Decoding Function for reinitializing the decoding process.
2416 // From: AST Parameter Function -> decodeProcessing
2417 // Uses: See code.
2418 // States: x
2419 // Return: Error number in standard or SIO form (0 on success).
2420 // Trace: Message Log "trace" in Debug Project Configuration reports:
2421 // * State information as per parent.
2422 //
2423 Int
2424 PAF_ASIT_decodeInit(
2425 const PAF_ASIT_Params *pP,
2426 const PAF_ASIT_Patchs *pQ,
2427 PAF_ASIT_Config *pAsitCfg,
2428 Int sourceSelect
2429 )
2430 {
2431 PAF_AST_Config *pAstCfg;
2432 //PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2433 Int as; /* Audio Stream Number (1, 2, etc.) */
2434 Int z; /* decode/encode counter */
2435 Int errno; /* error number */
2436 Int zI, zS;
2437 Int zMD;
2438 Int zMI;
2439 Int argIdx;
2440 Int8 tempVar8;
2441 char decMsgBuf[ASP_MSG_BUF_LEN];
2443 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2444 as = pAstCfg->as;
2445 zMD = pAstCfg->masterDec;
2446 zMI = pP->zone.master;
2447 (void)as; // clear compiler warning in case not used with tracing disabled
2449 //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2451 // reset frameCount
2452 for (z=DECODE1; z < DECODEN; z++)
2453 {
2454 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2455 GATEMP_INDEX_DEC);
2456 if (tempVar8)
2457 {
2458 sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2459 (Int)0, GATEMP_INDEX_DEC);
2460 }
2461 }
2463 for (z=DECODE1; z < DECODEN; z++)
2464 {
2465 zI = pP->inputsFromDecodes[z];
2466 zS = pP->streamsFromDecodes[z];
2467 (void)zS; // clear compiler warning in case not used with tracing disabled
2468 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2469 GATEMP_INDEX_DEC);
2470 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2471 {
2473 Uns gear;
2474 Int frameLength;
2475 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2477 // write back Dec configuration
2478 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2479 Cache_wait();
2481 // FL: send dec activate message to slave
2482 argIdx = 0; // set decIdx (zone index)
2483 *(Int32 *)&decMsgBuf[argIdx] = z;
2484 if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
2485 decMsgBuf, NULL) != ASP_MSG_NO_ERR)
2486 {
2487 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
2488 SW_BREAKPOINT; // temporary
2489 return -1; // temporary
2490 }
2492 #if 0 // FL: decoder activate call, slave
2493 if (decAlg[z]->fxns->algActivate)
2494 decAlg[z]->fxns->algActivate (decAlg[z]);
2495 #endif
2496 // FL: send dec reset message to slave
2497 argIdx = 0; // set decIdx
2498 *(Int32 *)&decMsgBuf[argIdx] = z;
2499 if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
2500 decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2501 {
2502 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
2503 SW_BREAKPOINT; // temporary
2504 return -1; // temporary
2505 }
2506 else
2507 {
2508 argIdx = 0; // get decErrno
2509 errno = *(Int32 *)&decMsgBuf[argIdx];
2510 }
2512 // (***) FL: revisit
2513 // invalidate Dec configuration
2514 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2515 Cache_wait();
2517 #if 0 // FL: decoder reset call, slave
2518 if (dec->fxns->reset
2519 && (errno = dec->fxns->reset (dec, NULL,
2520 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2521 return errno;
2522 #endif
2523 if (errno != 0)
2524 {
2525 return errno;
2526 }
2528 gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2529 GATEMP_INDEX_DEC);
2530 tempVar8 = gear < GEARS ? gear : 0;
2531 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2532 tempVar8, GATEMP_INDEX_DEC);
2534 #if 0 // FL: change handle to decIdx (zone index)
2535 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2536 FRAMELENGTH,
2537 pC->xDec[z].decodeStatus.bufferRatio);
2538 #endif
2539 #if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
2540 frameLength = pP->fxns->computeFrameLength(z,
2541 FRAMELENGTH,
2542 pC->xDec[z].decodeStatus.bufferRatio);
2543 #else
2544 // Compute decoder frame length based on source selection
2545 frameLength = getFrameLengthSourceSel(pP, sourceSelect);
2546 #endif
2548 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2549 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2550 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2552 #if 0 // FL: Moved to ARM:ASDT:INFO
2553 // Initialize decoder output circular buffer for selected source
2554 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2555 if (errno)
2556 {
2557 SW_BREAKPOINT; // debug
2558 return errno;
2559 }
2560 // debug
2561 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2562 #endif
2564 if (z != zMD)
2565 {
2566 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2567 {
2568 return errno;
2569 }
2570 }
2572 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2573 GATEMP_INDEX_DEC);
2574 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2575 DECSIOMAP(tempVar8)))
2576 {
2577 return errno;
2578 }
2580 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2581 frameLength))
2582 {
2583 return errno;
2584 }
2585 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2586 &pAstCfg->xInp[zI].inpBufConfig))
2587 {
2588 return errno;
2589 }
2590 }
2591 }
2593 if (pAstCfg->xInp[zMI].hRxSio)
2594 {
2595 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2596 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2597 if (errno)
2598 {
2599 return errno;
2600 }
2601 }
2603 return 0;
2604 } //PAF_AST_decodeInit
2606 // -----------------------------------------------------------------------------
2607 // ASIT Decoding Function - Info Processing, Common
2608 //
2609 // Name: PAF_ASIT_decodeInfo
2610 // Purpose: Decoding Function for processing information in a manner that
2611 // is common for both initial and subsequent frames of input data.
2612 // From: AST Parameter Function -> decodeProcessing
2613 // Uses: See code.
2614 // States: x
2615 // Return: Error number in standard form (0 on success).
2616 // Trace: Message Log "trace" in Debug Project Configuration reports:
2617 // * State information as per parent.
2618 //
2619 Int
2620 PAF_ASIT_decodeInfo(
2621 const PAF_ASIT_Params *pP,
2622 const PAF_ASIT_Patchs *pQ,
2623 PAF_ASIT_Config *pAsitCfg,
2624 Int frame,
2625 Int block
2626 )
2627 {
2628 PAF_AST_Config *pAstCfg;
2629 Int as; /* Audio Stream Number (1, 2, etc.) */
2630 Int z; /* input/decode/stream counter */
2631 Int errno; /* error number */
2632 Int sioErr; /* error number, SIO */
2633 Int zD, zI, zS, zX;
2634 Int zMD;
2635 Int zMI;
2636 Int zMS;
2637 UInt32 curTime;
2638 Int argIdx;
2639 Int8 tempVar8;
2640 Int tempVar;
2641 char decMsgBuf[ASP_MSG_BUF_LEN];
2642 // FL: revisit
2643 //Int size;
2644 //PAF_InpBufConfig *pIpBufConfig;
2646 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2647 as = pAstCfg->as;
2648 zMD = pAstCfg->masterDec;
2649 zMS = pAstCfg->masterStr;
2650 zMI = pP->zone.master;
2651 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2653 // Set decode control: sample rate, emphasis
2654 for (z=INPUT1; z < INPUTN; z++)
2655 {
2656 zD = z;
2657 for (zX = DECODE1; zX < DECODEN; zX++)
2658 {
2659 if (pP->inputsFromDecodes[zX] == z)
2660 {
2661 zD = zX;
2662 break;
2663 }
2664 }
2665 #ifdef PROFILER
2666 // modify for different sampling rate
2667 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus == PAF_SAMPLERATE_96000HZ)
2668 {
2669 start_profiling = 1;
2670 }
2671 else
2672 {
2673 start_profiling = 0;
2674 }
2675 #endif
2676 if (pAstCfg->xInp[z].hRxSio)
2677 {
2678 //determine associated decoder
2679 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2680 pAstCfg->xDec[zD].decodeControl.sampleRate)
2681 {
2682 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2683 {
2684 pAstCfg->xDec[zD].decodeControl.sampleRate =
2685 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2686 }
2687 else
2688 {
2689 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2690 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2691 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2692 pAstCfg->xDec[zD].decodeControl.sampleRate);
2693 // return (ASPERR_INFO_RATECHANGE);
2694 }
2695 }
2697 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2698 GATEMP_INDEX_DEC);
2699 pAstCfg->xDec[zD].decodeControl.emphasis =
2700 tempVar8 != PAF_SOURCE_PCM
2701 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2702 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2703 }
2704 else
2705 {
2706 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2707 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2708 }
2709 }
2711 // Wait for info input
2712 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2713 if (pAstCfg->xInp[zMI].hRxSio)
2714 {
2715 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2716 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2717 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2718 {
2719 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2720 return ASPERR_RECLAIM;
2721 }
2723 //// FL: debug, capture input buffer
2724 //capIb(pAstCfg->xInp[zMI].pInpBuf);
2725 //gCapIb_cnt++;
2727 #if 0 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
2728 // (***) debug // B5
2729 {
2730 static Uint8 toggleState = 0;
2731 if (toggleState == 0)
2732 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
2733 else
2734 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
2735 toggleState = ~(toggleState);
2736 }
2737 #endif
2739 //
2740 // Simulate Rx SIO_reclaim() pend
2741 //
2742 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2743 gTaskAsipCnt++;
2744 curTime = Clock_getTicks();
2745 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2746 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2747 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2748 } //pAstCfg->xInp[zMI].hRxSio
2750 // Decode info
2751 for (z=DECODE1; z < DECODEN; z++)
2752 {
2753 zI = pP->inputsFromDecodes[z];
2754 zS = pP->streamsFromDecodes[z];
2755 (void)zS; // clear compiler warning in case not used with tracing disabled
2757 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2758 GATEMP_INDEX_DEC);
2759 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2760 {
2761 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2763 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2764 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2765 {
2766 TRACE_TERSE1("return error errno 0x%x.", errno);
2767 return errno;
2768 }
2770 #if 1
2771 // (***) FL: revisit
2772 // write back Inp configuration
2773 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2774 // write back Dec configuration
2775 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2776 Cache_wait();
2777 #endif
2779 // FL: send info message to slave
2780 argIdx = 0; // set decIdx
2781 *(Int32 *)&decMsgBuf[argIdx] = z;
2782 if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE,
2783 decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2784 {
2785 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
2786 SW_BREAKPOINT; // temporary
2787 return -1; // temporary
2788 }
2789 else
2790 {
2791 argIdx = 0; // get decErrno
2792 errno = *(Int32 *)&decMsgBuf[argIdx];
2793 }
2795 #if 1
2796 // (***) FL: revisit
2797 // invalidate Dec configuration
2798 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2799 Cache_wait();
2800 #endif
2802 #if 0 // FL: decoder info call, slave
2803 if (dec->fxns->info
2804 && (errno = dec->fxns->info (dec, NULL,
2805 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2806 #endif
2807 if (errno)
2808 {
2809 TRACE_TERSE1("return error errno 0x%x.", errno);
2810 return errno;
2811 }
2813 // increment decoded frame count
2814 tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2815 GATEMP_INDEX_DEC);
2816 tempVar += 1;
2817 sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2818 tempVar, GATEMP_INDEX_DEC);
2819 }
2820 } // z=DECODE1 to DECODEN
2822 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2823 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
2824 GATEMP_INDEX_DEC);
2825 if (tempVar8)
2826 {
2827 XDAS_Int8 sourceProgram;
2828 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2829 (Arg)&sourceProgram))
2830 {
2831 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2832 return ASPERR_AUTO_PROGRAM;
2833 }
2835 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
2836 sourceProgram, GATEMP_INDEX_DEC);
2837 }
2839 // since now decoding update decode status for all enabled decoders
2840 for (z=DECODE1; z < DECODEN; z++)
2841 {
2842 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2843 GATEMP_INDEX_DEC);
2844 if (tempVar8)
2845 {
2846 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
2847 GATEMP_INDEX_DEC);
2848 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2849 tempVar8, GATEMP_INDEX_DEC);
2851 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2852 GATEMP_INDEX_DEC);
2853 if (tempVar8 == PAF_SOURCE_SNG)
2854 {
2855 tempVar8 = PAF_SOURCE_SNG;
2856 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2857 tempVar8, GATEMP_INDEX_DEC);
2858 }
2859 }
2860 }
2862 #if 0 // FL: ASDT (slave)
2863 // TODO: move this to start of this function so that it doesn't affect IO timing
2864 // Initialize audio frame(s)
2865 // Re-initialize audio frame if there is an associated decode and
2866 // that decode doesn't have a valid input or is turned off
2867 for (z=STREAM1; z < STREAMN; z++)
2868 {
2869 Int reset = 0;
2870 for (zX = DECODE1; zX < DECODEN; zX++)
2871 {
2872 if (pP->streamsFromDecodes[zX] == z)
2873 {
2874 zI = pP->inputsFromDecodes[zX];
2875 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2876 {
2877 reset = 1;
2878 }
2879 }
2880 }
2881 if (reset)
2882 {
2883 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2884 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2885 }
2886 else
2887 {
2888 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2889 }
2890 }
2891 #endif
2893 return 0;
2894 } //PAF_ASIT_decodeInfo
2896 // -----------------------------------------------------------------------------
2897 // ASIT Decoding Function - Info Processing, Initial
2898 //
2899 // Name: PAF_ASIT_decodeInfo1
2900 // Purpose: Decoding Function for processing information in a manner that
2901 // is unique to initial frames of input data.
2902 // From: AST Parameter Function -> decodeProcessing
2903 // Uses: See code.
2904 // States: x
2905 // Return: Error number in standard or SIO form (0 on success).
2906 // Trace: Message Log "trace" in Debug Project Configuration reports:
2907 // * State information as per parent.
2908 //
2909 Int
2910 PAF_ASIT_decodeInfo1(
2911 const PAF_ASIT_Params *pP,
2912 const PAF_ASIT_Patchs *pQ,
2913 PAF_ASIT_Config *pAsitCfg,
2914 Int frame,
2915 Int block
2916 )
2917 {
2918 return 0;
2919 } //PAF_ASIT_decodeInfo1
2921 // -----------------------------------------------------------------------------
2922 // AST Decoding Function - Info Processing, Subsequent
2923 //
2924 // Name: PAF_AST_decodeInfo2
2925 // Purpose: Decoding Function for processing information in a manner that
2926 // is unique to frames of input data other than the initial one.
2927 // From: AST Parameter Function -> decodeProcessing
2928 // Uses: See code.
2929 // States: x
2930 // Return: Error number in standard form (0 on success).
2931 // Trace: None.
2932 //
2933 Int
2934 PAF_ASIT_decodeInfo2(
2935 const PAF_ASIT_Params *pP,
2936 const PAF_ASIT_Patchs *pQ,
2937 PAF_ASIT_Config *pAsitCfg,
2938 Int frame,
2939 Int block
2940 )
2941 {
2942 return 0;
2943 } //PAF_ASIT_decodeInfo2
2945 #if 0
2946 // -----------------------------------------------------------------------------
2947 // AST Decoding Function - Continuation Processing
2948 //
2949 // Name: PAF_AST_decodeCont
2950 // Purpose: Decoding Function for processing that occurs subsequent to
2951 // information processing but antecedent to timing processing
2952 // for frames of input data other than the initial one.
2953 // From: AST Parameter Function -> decodeProcessing
2954 // Uses: See code.
2955 // States: x
2956 // Return: Error number in standard form (0 on success).
2957 // Trace: Message Log "trace" in Debug Project Configuration reports:
2958 // * State information as per parent.
2959 //
2961 Int
2962 PAF_AST_decodeCont(
2963 const PAF_ASIT_Params *pP,
2964 const PAF_ASIT_Patchs *pQ,
2965 PAF_ASIT_Config *pAsitCfg,
2966 ALG_Handle decAlg[],
2967 Int frame,
2968 Int block
2969 )
2970 {
2971 PAF_AST_Config *pAstCfg;
2972 Int as; /* Audio Stream Number (1, 2, etc.) */
2973 Int z; /* decode counter */
2974 Int zI, zS;
2975 Int zMD;
2976 Int8 tempVar8;
2979 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2980 as = pAstCfg->as;
2981 zMD = pAstCfg->masterDec;
2982 (void)as; // clear compiler warning in case not used with tracing disabled
2984 // Await slave inputs
2985 for (z=DECODE1; z < DECODEN; z++)
2986 {
2987 zI = pP->inputsFromDecodes[z];
2988 zS = pP->streamsFromDecodes[z];
2989 (void)zS;
2990 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2991 GATEMP_INDEX_DEC);
2992 if (z == zMD
2993 || ! pAstCfg->xInp[zI].hRxSio
2994 || ! tempVar8)
2995 continue;
2996 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2997 if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
2998 != sizeof (pAstCfg->xInp[zI].inpBufConfig))
2999 return (ASPERR_RECLAIM);
3000 }
3002 return 0;
3003 } //PAF_AST_decodeCont
3004 #endif
3006 // -----------------------------------------------------------------------------
3007 // ASIT Decoding Function - Decode Processing
3008 //
3009 // Name: PAF_ASIT_decodeDecode
3010 // Purpose: Decoding Function for processing of input data by the
3011 // Decode Algorithm.
3012 // From: AST Parameter Function -> decodeProcessing
3013 // Uses: See code.
3014 // States: x
3015 // Return: Error number in standard form (0 on success).
3016 // Trace: Message Log "trace" in Debug Project Configuration reports:
3017 // * State information as per parent.
3018 //
3019 Int
3020 PAF_ASIT_decodeDecode(
3021 const PAF_ASIT_Params *pP,
3022 const PAF_ASIT_Patchs *pQ,
3023 PAF_ASIT_Config *pAsitCfg,
3024 Int sourceSelect,
3025 Int frame,
3026 Int block
3027 )
3028 {
3029 PAF_AST_Config *pAstCfg;
3030 Int as; /* Audio Stream Number (1, 2, etc.) */
3031 Int z; /* decode/stream counter */
3032 Int errno; /* error number */
3033 //Int ch;
3034 Int argIdx;
3035 Int cbErrno;
3036 Int frameLength;
3037 char decMsgBuf[ASP_MSG_BUF_LEN];
3039 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3040 as = pAstCfg->as;
3041 (void)as; // clear compiler warning in case not used with tracing disabled
3043 #if 0 // FL: slave
3044 // Clear samsiz for all channels - MID 208.
3045 for (z=STREAM1; z < STREAMN; z++)
3046 {
3047 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
3048 {
3049 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
3050 }
3051 }
3052 #endif
3054 // Decode data
3055 for (z=DECODE1; z < DECODEN; z++)
3056 {
3057 Int zI = pP->inputsFromDecodes[z];
3058 Int zS = pP->streamsFromDecodes[z];
3059 (void)zS; // clear compiler warning in case not used with tracing disabled
3060 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3061 {
3062 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
3064 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
3065 as+zS,
3066 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
3067 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
3069 // FL: debug, capture input buffer
3070 //capIbPcm(pAstCfg->xInp[z].pInpBuf);
3072 // (***) FL: revisit
3073 // write back Dec configuration
3074 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3075 Cache_wait();
3077 // FL: send decode message to slave
3078 argIdx = 0; // set decIdx
3079 *(Int32 *)&decMsgBuf[argIdx] = z;
3080 if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE,
3081 decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
3082 {
3083 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
3084 SW_BREAKPOINT; // temporary
3085 return -1; // temporary
3086 }
3087 else
3088 {
3089 argIdx = 0; // get decErrno
3090 errno = *(Int32 *)&decMsgBuf[argIdx];
3091 argIdx += sizeof(Int32); // get cbErrno
3092 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
3093 if (cbErrno != 0)
3094 {
3095 gCbWrtAfErrCnt++;
3096 TRACE_TERSE1("CB write error=%d", cbErrno);
3097 //SW_BREAKPOINT; // temporary
3098 }
3099 }
3101 // (***) FL: revisit
3102 // invalidate Dec configuration
3103 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3104 Cache_wait();
3106 #if 0 // FL: decoder decode call, slave
3107 if (dec->fxns->decode
3108 && (errno = dec->fxns->decode (dec, NULL,
3109 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
3110 #endif
3111 if (errno)
3112 {
3113 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
3114 return errno;
3115 }
3117 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3118 as_traceChannels(pC, z);
3119 #endif
3121 #if 0 // FL: change handle to decIdx (zone index)
3122 frameLength = pP->fxns->computeFrameLength(decAlg[z],
3123 FRAMELENGTH,
3124 pC->xDec[z].decodeStatus.bufferRatio);
3125 #endif
3126 #if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
3127 frameLength = pP->fxns->computeFrameLength(z,
3128 FRAMELENGTH,
3129 pC->xDec[z].decodeStatus.bufferRatio);
3130 #else
3131 // Compute decoder frame length based on source selection
3132 frameLength = getFrameLengthSourceSel(pP, sourceSelect);
3133 #endif
3136 //#ifdef PROFILER
3137 // // modify for different decoders
3138 // if (sourceSelect == PAF_SOURCE_THD)
3139 // {
3140 // start_profiling = 1;
3141 // }
3142 // else
3143 // {
3144 // start_profiling = 0;
3145 // }
3146 //#endif
3149 // ............................................................................
3151 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3152 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3153 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3154 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3155 {
3156 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3157 return errno;
3158 }
3160 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3161 if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3162 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3163 PAF_SIO_REQUEST_NEWFRAME))
3164 {
3165 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3166 return (ASPERR_ISSUE);
3167 }
3168 } // hRxSio && decodeStatus.mode
3169 else
3170 {
3171 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3172 }
3173 } // z=DECODE1 to DECODEN
3175 #if 0 // FL: ASDT (slave)
3176 // Set up audio frames not decoded into
3177 // Re-initialize audio frame if there is an assocatiated decode and
3178 // that decode doesn't have a valid input or is turned off
3179 for (z=STREAM1; z < STREAMN; z++)
3180 {
3181 Int zX;
3182 Int reset = 0;
3183 for (zX = DECODE1; zX < DECODEN; zX++)
3184 {
3185 if (pP->streamsFromDecodes[zX] == z)
3186 {
3187 Int zI = pP->inputsFromDecodes[zX];
3188 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3189 reset = 1;
3190 }
3191 }
3192 if (reset)
3193 {
3194 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3195 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3196 }
3197 else
3198 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3199 }
3200 #endif
3202 return 0;
3203 } //PAF_ASIT_decodeDecode
3205 // -----------------------------------------------------------------------------
3206 // ASIT Decoding Function - Frame-Final Processing
3207 //
3208 // Name: PAF_ASIT_decodeFinalTest
3209 // Purpose: Decoding Function for determining whether processing of the
3210 // current frame is complete.
3211 // From: AST Parameter Function -> decodeProcessing
3212 // Uses: See code.
3213 // States: x
3214 // Return: 0 if incomplete, and 1 if complete.
3215 // Trace: None.
3216 //
3218 Int
3219 PAF_ASIT_decodeFinalTest(
3220 const PAF_ASIT_Params *pP,
3221 const PAF_ASIT_Patchs *pQ,
3222 PAF_ASIT_Config *pAsitCfg,
3223 Int frame,
3224 Int block
3225 )
3226 {
3227 PAF_AST_Config *pAstCfg;
3228 Int zMD;
3229 Int sourceSelect;
3230 Int sourceProgram;
3231 Int8 tempVar8, temp2Var8;
3233 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3234 zMD = pAstCfg->masterDec;
3236 sourceSelect = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3237 GATEMP_INDEX_DEC);
3238 sourceProgram = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3239 GATEMP_INDEX_DEC);
3241 if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3242 {
3243 return 1;
3244 }
3246 // The following allows for Force modes to switch without command deferral. This might
3247 // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3248 if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
3249 {
3250 if (sourceSelect == PAF_SOURCE_DTSALL)
3251 {
3252 if (sourceProgram != PAF_SOURCE_DTS11 &&
3253 sourceProgram != PAF_SOURCE_DTS12 &&
3254 sourceProgram != PAF_SOURCE_DTS13 &&
3255 sourceProgram != PAF_SOURCE_DTS14 &&
3256 sourceProgram != PAF_SOURCE_DTS16 &&
3257 sourceProgram != PAF_SOURCE_DTSHD)
3258 {
3259 return 1;
3260 }
3261 }
3262 else if (sourceSelect == PAF_SOURCE_PCMAUTO)
3263 {
3264 if (sourceProgram != PAF_SOURCE_PCM)
3265 {
3266 return 1;
3267 }
3268 }
3269 else
3270 {
3271 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
3272 GATEMP_INDEX_DEC);
3273 temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3274 GATEMP_INDEX_DEC);
3275 if (temp2Var8 != tempVar8)
3276 {
3277 return 1;
3278 }
3279 }
3280 }
3282 return 0;
3283 } //PAF_ASIT_decodeFinalTest
3285 // -----------------------------------------------------------------------------
3286 // ASIT Decoding Function - Stream-Final Processing
3287 //
3288 // Name: PAF_ASIT_decodeComplete
3289 // Purpose: Decoding Function for terminating the decoding process.
3290 // From: AST Parameter Function -> decodeProcessing
3291 // Uses: See code.
3292 // States: x
3293 // Return: 0.
3294 // Trace: Message Log "trace" in Debug Project Configuration reports:
3295 // * State information as per parent.
3296 //
3297 Int
3298 PAF_ASIT_decodeComplete(
3299 const PAF_ASIT_Params *pP,
3300 const PAF_ASIT_Patchs *pQ,
3301 PAF_ASIT_Config *pAsitCfg,
3302 ALG_Handle decAlg[],
3303 Int frame,
3304 Int block
3305 )
3306 {
3307 PAF_AST_Config *pAstCfg;
3308 Int as; /* Audio Stream Number (1, 2, etc.) */
3309 Int z; /* decode/encode counter */
3310 Int argIdx;
3311 Int errno; /* error number */
3312 Int8 tempVar8;
3313 char decMsgBuf[ASP_MSG_BUF_LEN];
3315 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3316 as = pAstCfg->as;
3317 (void)as; // clear compiler warning in case not used with tracing disabled
3319 #ifdef PAF_ASP_FINAL
3320 /* This material is currently not utilized */
3321 #endif /* PAF_ASP_FINAL */
3322 for (z=DECODE1; z < DECODEN; z++)
3323 {
3324 #ifdef PAF_ASP_FINAL
3325 DEC_Handle dec = (DEC_Handle )decAlg[z];
3326 #endif /* PAF_ASP_FINAL */
3327 Int zI = pP->inputsFromDecodes[z];
3328 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
3329 GATEMP_INDEX_DEC);
3330 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
3331 {
3332 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3333 #ifdef PAF_ASP_FINAL
3334 if (dec->fxns->final)
3335 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3336 &pAstCfg->xDec[z].decodeStatus);
3337 #endif /* PAF_ASP_FINAL */
3339 // FL: send dec deactivate message to slave
3340 argIdx = 0; // set decIdx
3341 *(Int32 *)&decMsgBuf[argIdx] = z;
3342 if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
3343 decMsgBuf, NULL) != ASP_MSG_NO_ERR)
3344 {
3345 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
3346 SW_BREAKPOINT;
3347 return -1;
3348 }
3350 #if 0 // FL: decoder deactivate call, slave
3351 if (decAlg[z]->fxns->algDeactivate)
3352 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3353 #endif
3354 }
3355 else
3356 {
3357 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3358 }
3359 }
3360 return 0;
3361 } //PAF_ASIT_decodeComplete
3363 // -----------------------------------------------------------------------------
3364 // ASIT Selection Function - Input Device Selection
3365 //
3366 // Name: PAF_ASIT_selectDevices
3367 // Purpose: Audio Stream Input Task Function for selecting the devices used
3368 // for input.
3369 // From: audioStream1Task or equivalent
3370 // Uses: See code.
3371 // States: x
3372 // Return: Error number in standard form (0 on success).
3373 // Trace: Message Log "trace" in Debug Project Configuration reports:
3374 // * State information as per parent.
3375 //
3376 Int
3377 PAF_ASIT_selectDevices(
3378 const PAF_ASIT_Params *pP,
3379 const PAF_ASIT_Patchs *pQ,
3380 PAF_ASIT_Config *pAsitCfg
3381 )
3382 {
3383 PAF_AST_Config *pAstCfg;
3384 Int as; /* Audio Stream Number (1, 2, etc.) */
3385 Int z; /* input/output counter */
3386 Int errno = 0; /* error number */
3387 Int errme; /* error number, local */
3388 Int device;
3389 Int zMD;
3391 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3392 as = pAstCfg->as;
3393 zMD = pAstCfg->masterDec;
3394 (void)as; // clear compiler warning in case not used with tracing disabled
3396 // Select input devices
3397 for (z=INPUT1; z < INPUTN; z++)
3398 {
3399 if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0)
3400 {
3401 TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3403 // check for valid index into device array
3404 if (device >= pQ->devinp->n)
3405 {
3406 device = 0; /* treat as device None */
3407 }
3409 errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3410 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3412 if (errme)
3413 {
3414 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3415 if (!errno)
3416 {
3417 errno = ASPERR_DEVINP + errme;
3418 }
3419 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3420 }
3421 else
3422 {
3423 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3424 // register decodeStatus pointer with input devices
3425 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3426 // Use zMIs decodeStatus for all inputs
3427 if (pAstCfg->xInp[z].hRxSio)
3428 {
3429 // register PAF_SIO_IALG object address
3430 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR,
3431 (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3432 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR,
3433 (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3434 }
3435 }
3436 }
3437 }
3439 return errno;
3440 } //PAF_ASIT_selectDevices
3442 // -----------------------------------------------------------------------------
3443 // ASIT Selection Function - Source Selection
3444 //
3445 // Name: PAF_ASIT_sourceDecode
3446 // Purpose: Audio Input Stream Task Function for selecting the sources used
3447 // for decoding of input to output.
3448 // From: audioStream1Task or equivalent
3449 // Uses: See code.
3450 // States: x
3451 // Return: 0.
3452 // Trace: None.
3453 //
3454 Int
3455 PAF_ASIT_sourceDecode(
3456 const PAF_ASIT_Params *pP,
3457 const PAF_ASIT_Patchs *pQ,
3458 PAF_ASIT_Config *pAsitCfg,
3459 Int x
3460 )
3461 {
3462 PAF_AST_Config *pAstCfg;
3463 Int z; /* decode counter */
3464 Int8 tempVar8;
3466 pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3468 for (z=DECODE1; z < DECODEN; z++)
3469 {
3470 tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
3471 GATEMP_INDEX_DEC);
3472 if (tempVar8)
3473 {
3474 tempVar8 = x;
3475 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3476 tempVar8, GATEMP_INDEX_DEC);
3477 }
3478 }
3480 return 0;
3481 } //PAF_ASIT_sourceDecode
3483 // -----------------------------------------------------------------------------
3485 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3486 Int
3487 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3488 {
3489 Int errno = 0;
3490 Int zMD = pC->masterDec;
3491 Int zI = pP->inputsFromDecodes[z];
3493 // only handle real errors, on primary input, for writeDECModeContinuous
3494 if ( !( error &&
3495 z == zMD ))
3496 return error;
3498 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3499 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3501 if (pC->xInp[zI].hRxSio) {
3502 DEC_Handle dec;
3504 if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3505 return errno;
3507 // indicates (primary) input not running
3508 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3510 pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3512 // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3513 pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3515 if (decAlg[z]->fxns->algDeactivate)
3516 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3518 decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3519 dec = (DEC_Handle )decAlg[z];
3521 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3522 pC->as+z));
3524 if (decAlg[z]->fxns->algActivate)
3525 decAlg[z]->fxns->algActivate (decAlg[z]);
3527 if (dec->fxns->reset
3528 && (errno = dec->fxns->reset (dec, NULL,
3529 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3530 return errno;
3531 }
3533 return errno;
3534 } //PAF_AST_decodeHandleErrorInput
3535 #endif
3537 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3539 //------------------------------------------------------------------------------
3540 static int sSkipCount = 0;
3541 int gReportBuffers = 0;
3542 void as_traceChannels(PAF_AST_Config *pC, int z)
3543 {
3544 PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3545 int i;
3547 // #ifdef THIS_IS_DSPA
3548 sSkipCount++;
3549 if (sSkipCount<1)
3550 return;
3551 sSkipCount = 0;
3552 // #endif
3554 #ifdef THIS_IS_DSPB
3555 if (!gReportBuffers)
3556 return;
3557 gReportBuffers = 0;
3558 #endif
3560 dp(NULL, "\n");
3561 for (i=0; i<PAF_MAXNUMCHAN; i++)
3562 {
3563 if (pAudioFrame->data.sample[i] != 0)
3564 {
3565 float *wp = (float*)pAudioFrame->data.sample[i];
3566 dp(NULL, "i: %d. p: 0x%x. %f, %f, %f, %f\n",
3567 i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
3568 }
3569 }
3570 }
3571 #endif
3573 // Compute decoder frame length based on selected source
3574 static Int getFrameLengthSourceSel(
3575 const PAF_ASIT_Params *pP,
3576 Int8 sourceSelect
3577 )
3578 {
3579 Int frameLength;
3581 switch(sourceSelect)
3582 {
3583 case PAF_SOURCE_PCM:
3584 frameLength = FRAMELENGTH;
3585 break;
3586 case PAF_SOURCE_AC3:
3587 case PAF_SOURCE_DDP:
3588 frameLength = ASIP_FRAMELEN_SS_DDP_AC3;
3589 break;
3590 case PAF_SOURCE_THD:
3591 frameLength = ASIP_FRAMELEN_SS_THD;
3592 break;
3593 case PAF_SOURCE_DTS:
3594 case PAF_SOURCE_DTSHD:
3595 case PAF_SOURCE_DTS12:
3596 case PAF_SOURCE_DTS13:
3597 case PAF_SOURCE_DTS14:
3598 case PAF_SOURCE_DTS16:
3599 case PAF_SOURCE_DTSALL:
3600 frameLength = ASIP_FRAMELEN_SS_DTS;
3601 break;
3602 default:
3603 frameLength = ASIP_FRAMELEN_SS_DEFAULT;
3604 break;
3605 }
3607 return frameLength;
3608 }