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