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