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