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