]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_arm/framework/audioStreamDecodeProc.c
PASDK-218:Move CB init source select to after first decoded frame
[processor-sdk/performance-audio-sr.git] / pasdk / test_arm / framework / audioStreamDecodeProc.c
2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37  *  ======== audioStreamDecodeProc.c ========
38  */
40 #include <xdc/cfg/global.h>
41 #include <xdc/runtime/Error.h>
42 #include <xdc/runtime/Log.h>
43 #include <xdc/runtime/Memory.h>
44 #include <ti/sysbios/BIOS.h>
45 #include <ti/sysbios/hal/Cache.h>
46 #include <ti/sysbios/knl/Task.h>
47 #include <ti/ipc/Ipc.h>
48 #include <ti/ipc/MessageQ.h>
49 #include <ti/ipc/MultiProc.h>
51 #include <acp_mds.h>
52 #include <pcm.h>
53 #include "audioStreamProc_params.h"
54 #include "audioStreamProc_patchs.h"
55 #include "audioStreamProc_config.h"
57 #include "common.h"
58 #include "aspMsg_common.h"
59 #include "aspMsg_slave.h"
60 #include "aspDecOpCircBuf_slave.h"
61 #include "aspOutInitSync_slave.h"
62 #include "audioStreamProc_common.h"
63 #include "audioStreamDecodeProc.h"
64 #include "statusOp_common.h"
66 #include "pfp/pfp.h"
67 #include "pfp_app.h"        /* contains all PFP ID's */
69 // FL: debug
70 #include "dbgCapAf.h"
71 #include "dbgDib.h"
72 #include "evmc66x_gpio_dbg.h"
74 //
75 // Decoder Definitions
76 //
77 #define decLinkInit pQ->i_decLinkInit
79 #define __TASK_NAME__  "TaskAsdp"
81 // Check decoder sync using information in INFO audio frame 
82 static Int8 checkDecSync(
83     PAF_AudioFrame *pAf
84 );
86 extern struct {
87     Int size;
88     IALG_Status *pStatus[512];
89 } IACP_STD_BETA_TABLE;
91 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
92 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
94 LINNO_DEFN(TaskAsdp); /* Line number macros */
95 ERRNO_DEFN(TaskAsdp); /* Error number macros */
97 // ASDT configuration
98 PAF_ASDT_Config gPAF_ASDT_config 
99 __attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
100     NULL,               // taskHandle
101     NULL,               // acp
102     {NULL, 0, NULL},    // decOpCircBufCtl
103     {NULL, NULL},       // outIsCtl
104     &gPAF_AST_config    // ASIT/ASOT/ASDT shared configuration
105 };
107 PAF_AudioFrame *gpDecAudioFrame=NULL;
108 PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
109 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
110 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
112 // Overflow threshold before circular buffer reset and return error to Top-Level FSM
113 #define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
114 UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count, not including overflows
115 UInt32 gDecOpCbWrtAfOvr         =0; // decoder output circular buffer overflow count
116 UInt32 gMaxDecOpCbWrtAfOvr      =0; // max (consecutive) decoder output circular buffer overflow count
117 UInt32 gSlaveCbResetCnt         =0; // slave circular buffer reset count
119 // Global debug counters */
120 UInt32 gSlaveStartErrCnt        =0;
121 UInt32 gSlaveStartCnt           =0;
122 UInt32 gSlaveSourceSelectCnt    =0;
123 UInt32 gSlaveExitCnt            =0;
124 UInt32 gSlaveDecExitCnt         =0;
125 UInt32 gSlaveDecControlCnt      =0;
126 UInt32 gSlaveDecActivateCnt     =0;
127 UInt32 gSlaveDecResetCnt        =0;
128 UInt32 gSlaveDecInfoCnt         =0;
129 UInt32 gSlaveDecDecodeCnt       =0;
130 UInt32 gSlaveDecDeactivateCnt   =0;
133 //#define CAPTURE_DECODER_OUTSAMPLES_PP
134 #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
136 #define CAP_FRAME_MAX            2000
137 Uint32 tempCap_frameCnt = 0;
138 int tempCap_decSampleOut[CAP_FRAME_MAX] = {0};
139 #endif
141 // debug
142 PAF_AudioFrame gDecInfoAfCap1[20];
143 UInt8 gDecInfoAfCap1Idx=0;
144 PAF_AudioFrame gDecInfoAfCap2[20];
145 UInt8 gDecInfoAfCap2Idx=0;
147 PAF_AudioFrame gDecDecodeAfCap1[20];
148 UInt8 gDecDecodeAfCap1Idx=0;
149 PAF_AudioFrame gDecDecodeAfCap2[20];
150 UInt8 gDecDecodeAfCap2Idx=0;
153 /*
154  *  ======== taskAsdpFxn ========
155  *  Audio Stream Decode Processing task function
156  */
157 Void taskAsdpFxn(
158 //    Int betaPrimeValue, // FL: revisit
159     const PAF_ASDT_Params *pP,
160     const PAF_ASDT_Patchs *pQ
163     PAF_ASDT_Config *pAsdtCfg;          // ASDT configuration pointer
164     PAF_AST_Config *pAstCfg;            // Common (shared) configuration pointer
165     Int as;                             // Audio Stream Number (1, 2, etc.)
166     Int z;                              // input/encode/stream/decode/output counter
167     Int i;                              // phase
168     Int zMD, zMS;
169     Bool done;
170     Bool decDone;
171     ALG_Handle alg[DECODEN_MAX];
172     ASP_Slave_Cmd slaveCmd;
173     Int sourceSelect;
174     DEC_Handle dec;
175     IALG_Cmd decCtrlCmd;                // decoder control command
176     Int decCtrlRet;                     // decoder control return
177     Int errno;                          // error number
178     Int size;
179     Int argIdx;
180     // Decoder output circular buffer
181     PAF_AST_DecOpCircBufCtl *pCbCtl;    // Decoder output Circular Buffer control
182     PAF_AudioFrame *pAfWrt;             // pointer to audio frame written to CB
183     Int cbErrno;                        // CB error number
184     // Output Init-Sync
185     PAF_AudioFrame *pDecCtrlAf;         // pointer to Dec Control audio frame
186     PAF_AST_OutInitSyncCtl *pOutIsCtl;  // OutIS control
187     Int8 outIsDecInfo1Flag;             // indicates whether Dec Info Init-Sync has executed
188     Int8 outIsDecDecode1Flag;           // indicates whether Dec Decode1 Init-Sync has executed
189     Int outIsErrno;                     // OutIS error number
190     // Messaging
191     PAF_InpBufConfig *pIpBufConfig;     // IB buffer configuration
192     ASP_Msg *pAspMsg;                   // Rx/Tx MessageQ message
193     MessageQ_QueueId queId;             // MessageQ ID
194     Int status;
195     Int zI;
196     Int bufEnd, wrapSize, currentBufSize, chunkSize;
197     Int8 temp8;
199     Log_info0("Enter taskAsdpFxn()");
200     
201     
202     //
203     // Audio Framework Parameters & Patch (*pP, *pQ):
204     //
205     if (!pP) 
206     {
207         TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
208         LINNO_RPRT(TaskAsdp, -1);
209         return;
210     }
212     if (!pQ) 
213     {
214         TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
215         LINNO_RPRT(TaskAsdp, -1);
216         return;
217     }    
219     //
220     // Audio Stream Decode Task Configuration (*pAsdtCfg):
221     //
222     pAsdtCfg = &gPAF_ASDT_config;           // initialize pointer to task configuration
223     pAsdtCfg->taskHandle = Task_self();     // set task handle
224     pAstCfg = pAsdtCfg->pAstCfg;            // get pointer to AST common (shared) configuration 
225     pCbCtl = &pAsdtCfg->decOpCircBufCtl;    // get pointer to circular buffer control
226     pOutIsCtl = &pAsdtCfg->outIsCtl;        // get pointer to output init-sync control
227     
228     // wait for initialization message from master
229     do {
230         status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
231         //TRACE_TERSE1("Rx ASP message: status=%d", status);
232     //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
233     } while (status != MessageQ_S_SUCCESS);
234     if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
235         (pAspMsg->cmd != ASP_SLAVE_START))
236     {
237         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
238         SW_BREAKPOINT;
239     }
240     hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
241     gSlaveStartCnt++;
242     TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
244     // invalidate AST shared configuration
245     Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
246     Cache_wait();
247     
248     // (***) FL: revisit
249     // invalidate Dec configuration for all Decoder zones
250     Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
251     Cache_wait();
253     // (***) FL: revisit
254     // invalidate Beta Table status pointers
255     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
256     Cache_wait();
258     /* Obtain Audio Stream Number (1, 2, etc.) */
259     as = pAstCfg->as;
260     TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
261     
262     //
263     // Initialize message log trace and line number reporting
264     //
265     for (z=STREAM1; z < STREAMN; z++)
266     {
267         TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
268     }
269     LINNO_RPRT(TaskAsdp, -1);
271     // Get decoder and stream index associated with the master input
272     zMD = pAstCfg->masterDec;
273     zMS = pAstCfg->masterStr;
275     // 
276     // Initialize per parameterized phases.
277     //   - Malloc: Memory Allocation
278     //   - Config: Configuration Initialization
279     //   - AcpAlg: ACP Algorithm Initialization and Local Attachment
280     //   - Common: Common Algorithm Initialization
281     //   - AlgKey: Dec/Enc chain to Array Initialization
282     //   - Unused: (available)
283     //   - Unused: (available)
284     //   - Unused: (available)
285     //
286     LINNO_RPRT(TaskAsdp, -2);
287     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
288     {
289         Int linno;
290         if (pP->fxns->initPhase[i])
291         {
292             if ((linno = pP->fxns->initPhase[i](pP, pQ, pAsdtCfg)))
293             {
294                 LINNO_RPRT(TaskAsdp, linno);
295                 return;
296             }
297         }
298         else 
299         {
300             TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
301         }
302         TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
303         LINNO_RPRT(TaskAsdp, -i-3);
304     }
305       
306 #ifdef NON_CACHE_STATUS
307     //
308     // init Status structure Gate
309     //
310     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
311     {
312         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DEC);
313     }
314     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
315     {
316         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DDP);
317     }
318     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
319     {
320         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_PCM);
321     }
322     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
323     {
324         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_THD);
325     }
326 #endif
328     //
329     // End of Initialization -- final memory usage report.
330     //
331     if (pP->fxns->memStatusPrint)
332     {
333         pP->fxns->memStatusPrint("ASDT MEMSTAT REPORT",
334             HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, 
335             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
336     }
337     
338     // (***) FL: revisit
339     // write back Status structure addresses for Beta Units initialized on Slave
340     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
341     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
342     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
343     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
344     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
345     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
346     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
347     Cache_wait();
348     
349     // (***) FL: revisit
350     // write back Status structures for Beta Units initialized on Slave
351    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
352     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
353     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
354     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
355     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
356     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
357     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
358     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
359     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
360     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
361     Cache_wait();
363     // (***) FL: revisit
364     // write back Dec configuration
365     Cache_wbInv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
366     Cache_wait();*/
367     
368     // Send initialization complete message to master
369     queId = MessageQ_getReplyQueue(pAspMsg);
370     pAspMsg->procId = hAspMsgSlave->slaveProcId;
371     pAspMsg->cmd = ASP_MASTER_START_DONE;
372     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
373     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
374     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
375     if (status != MessageQ_S_SUCCESS)
376     {
377         SW_BREAKPOINT;
378     }
380     done = FALSE;
381     while (done==FALSE)
382     {
383         // wait for source select message from master
384         do {
385             status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
386         } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
387         if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
388             (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
389         {
390             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
391             SW_BREAKPOINT;
392         }            
393         hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
394         sourceSelect = *(Int32 *)&pAspMsg->buf[0];
395         TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
396         TRACE_MSG1("sourceSelect=%d.", sourceSelect);
397         // send source select complete message to master
398         queId = MessageQ_getReplyQueue(pAspMsg);
399         pAspMsg->procId = hAspMsgSlave->slaveProcId;
400         pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
401         pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
402         gSlaveSourceSelectCnt++;
403         TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
404         MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
405         
406         for (z=DECODE1; z < DECODEN; z++)
407         {
408             alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
409         }
410         alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
412         // Reset IB capture buffer (debug)
413         //capIbReset();
414         //Log_info0("capIbReset()");
415         // Reset audio frame capture buffer (debug)
416         //capAfReset();
417         
418         decDone = FALSE;
419         while (decDone==FALSE)
420         {
421             // wait for received message from master
422             do {
423                 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
424             } while (status < 0);
425             if (pAspMsg->procId != hAspMsgSlave->masterProcId)
426             {
427                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
428                 SW_BREAKPOINT;
429             }
430             hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
431             slaveCmd = pAspMsg->cmd;
432             TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
434             switch (slaveCmd)
435             {
436                 case ASP_SLAVE_NULL:
437                 case ASP_SLAVE_START:
438                     gSlaveStartErrCnt++;
439                     TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
440                     
441                     break;
442                     
443                 case ASP_SLAVE_EXIT:
444                     gSlaveExitCnt++;
445                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
446                     
447                     decDone = TRUE;
448                     done = TRUE;
449                     break;
450                     
451                 case ASP_SLAVE_DEC_EXIT:
452                     gSlaveDecExitCnt++;
453                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
454                     
455                     // send dec exit complete message to master
456                     queId = MessageQ_getReplyQueue(pAspMsg);
457                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
458                     pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
459                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
460                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
461                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
462                     if (status != MessageQ_S_SUCCESS)
463                     {
464                         SW_BREAKPOINT;
465                     }
466                     
467                     decDone=TRUE;
468                     break;
469                     
470                 case ASP_SLAVE_DEC_CONTROL:
471                     gSlaveDecControlCnt++;
472                     
473                     argIdx = 0; // get decIdx
474                     z = *(Int32 *)&pAspMsg->buf[argIdx];
475                     argIdx += sizeof(Int32);
476                     decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
477                     TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
478                     
479                     decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
481                     // send dec control complete message to master
482                     queId = MessageQ_getReplyQueue(pAspMsg);
483                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
484                     pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
485                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
486                     argIdx = 0; // set decCtrlRet
487                     *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
488                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
489                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
490                     if (status != MessageQ_S_SUCCESS)
491                     {
492                         SW_BREAKPOINT;
493                     }
495                     break;
496                     
497                 case ASP_SLAVE_DEC_ACTIVATE:
498                     gSlaveDecActivateCnt++;
499                     
500                     // (***) FL: revisit
501                     // invalidate Status structures for shared Beta Units
502                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
503                     //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
504                     /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
505                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
506                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
507                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
508                     Cache_wait();*/
509                     
510                     argIdx = 0; // get decIdx
511                     z = *(Int32 *)&pAspMsg->buf[argIdx];
512                     TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
513                     
514                     // invalidate Dec configuration
515                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
516                     Cache_wait();
517                     
518                     if (alg[z]->fxns->algActivate)
519                     {
520                         alg[z]->fxns->algActivate(alg[z]);
521                     }
523                     // Start writes to circular buffer
524                     cbErrno = cbWriteStart(pCbCtl, z);
525                     if (cbErrno < 0)
526                     {
527                         SW_BREAKPOINT;
528                     }
529                     gCbWrtAfErrCnt=0;       // reset write circular buffer error count
530                     gDecOpCbWrtAfOvr=0;     // reset decoder output circular buffer overflow count
531                     gMaxDecOpCbWrtAfOvr=0;  // reset max decoder output circular buffer overflow count
532                     gSlaveCbResetCnt=0;     // reset slave circular buffer reset count
533                     // Log circular buffer control variables (debug)
534                     cbLog(pCbCtl, z, 1, "cbWriteStart");
535                     
536                     // Reset audio frame
537                     resetAf(pP, z, sourceSelect);
538                     
539                     // Initialize OutIS Dec flags
540                     outIsDecInfo1Flag = 0;      // OutIS Dec Info1 hasn't executed
541                     outIsDecDecode1Flag = 0;    // OutIS Dec Decode1 hasn't executed
542                     
543                     // send dec activate complete message to master
544                     queId = MessageQ_getReplyQueue(pAspMsg);
545                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
546                     pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
547                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
548                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
549                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
550                     if (status != MessageQ_S_SUCCESS)
551                     {
552                         SW_BREAKPOINT;
553                     }
554                    
555                     break;
556                     
557                 case ASP_SLAVE_DEC_RESET:
558                     gSlaveDecResetCnt++;
559                     
560                     argIdx = 0; // get decIdx
561                     z = *(Int32 *)&pAspMsg->buf[argIdx];
562                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
563                     
564                     dec = (DEC_Handle)alg[z];
565                     errno = 0;
566                     if (dec->fxns->reset)
567                     {
568                         //
569                         // Execute decode reset
570                         //
571                         errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
573                         // Get pointer to Dec Reset output audio frame
574                         pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
576                         // Perform Dec Reset Init-Sync
577                         //  - Write Dec Reset output audio frame
578                         //  - Set Dec Reset decoder stage flag
579                         outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
580                             ASP_OUTIS_DEC_STAGE_RESET_IDX, 1, pDecCtrlAf);
581                         if (outIsErrno < 0)
582                         {
583                             SW_BREAKPOINT; // debug
584                         }
585                     }
587                     // write back Dec configuration
588                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
589                     Cache_wait();            
591                     // (***) FL: revisit
592                     // write back Status structures for shared Beta Units
593                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
594                     //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
595                    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
596                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
597                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
598                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
599                     Cache_wait();*/
601                     // send dec reset complete message to master
602                     queId = MessageQ_getReplyQueue(pAspMsg);
603                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
604                     pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
605                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
606                     argIdx = 0; // set decErrno
607                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
608                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
609                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
610                     if (status != MessageQ_S_SUCCESS)
611                     {
612                         SW_BREAKPOINT;
613                     }
615                     break;
616                     
617                 case ASP_SLAVE_DEC_INFO:
618                     gSlaveDecInfoCnt++;
619                     
620                     argIdx = 0; // get decIdx
621                     z = *(Int32 *)&pAspMsg->buf[argIdx];
622                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
623                     // Get input associated w/ decoder
624                     zI = pP->inputsFromDecodes[z];
626                     // (***) FL: revisit
627                     // invalidate Inp configuration
628                     Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
629                     Cache_wait();
630                     // invalidate input data
631                     pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
632                     size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
633                     if (sourceSelect == PAF_SOURCE_PCM)
634                     {
635                         size *= pIpBufConfig->stride;
636                     }
638                     bufEnd = (Int) pIpBufConfig->base.pVoid + pIpBufConfig->sizeofBuffer;
639                     currentBufSize = (bufEnd - (Int)pIpBufConfig->pntr.pSmInt);
640                     if (currentBufSize >= size)
641                     {
642                         chunkSize = size;
643                     }
644                     else
645                     {
646                         chunkSize = currentBufSize;
647                     }
648                     wrapSize = size - chunkSize;
649                     // invalidate input data
650                     Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
651                     // invalidate Dec configuration
652                     TRACE_MSG2("IBUF : pIpBufConfig->pntr.pSmInt: 0x%x and chunkSize: %d", (IArg)pIpBufConfig->pntr.pSmInt, chunkSize);
653                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
654                     // status for selected decoder should be invalidated
655                     Cache_wait();
657                     /* Circular buffer wrap condition*/
658                     //if(((Int) pIpBufConfig->head.pVoid + size)  > bufEnd)
659                     if(wrapSize > 0)
660                     {
661                         // invalidate input data
662                         Cache_inv((Ptr)pIpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
663                         TRACE_MSG2("IBUF : pIpBufConfig->base.pSmInt: 0x%x and wrapSize: %d", (IArg)pIpBufConfig->base.pSmInt, wrapSize);
664                         // status for selected decoder should be invalidated
665                         Cache_wait();
666                     }
667                     /* Circular buffer wrap condition */
669                     dec = (DEC_Handle)alg[z];
670                     errno = 0;
671                     if (dec->fxns->info)
672                     {
673                         // debug
674                         if (gDecInfoAfCap1Idx < 20)
675                         {
676                             gDecInfoAfCap1[gDecInfoAfCap1Idx] = *pAstCfg->xDec[z].decodeControl.pAudioFrame;
677                             gDecInfoAfCap1Idx++;
678                         }
679                         
680                         //
681                         // Execute decode info
682                         //
683                         pfpBegin(PFP_ID_ASDT_1, pAsdtCfg->taskHandle);
684                         errno = dec->fxns->info(dec, NULL, 
685                             &pAstCfg->xDec[z].decodeControl, 
686                             &pAstCfg->xDec[z].decodeStatus);
687                         pfpEnd(PFP_ID_ASDT_1, PFP_FINISH_MEAS);
689                         // debug
690                         if (gDecInfoAfCap2Idx < 20)
691                         {
692                             gDecInfoAfCap2[gDecInfoAfCap2Idx] = *pAstCfg->xDec[z].decodeControl.pAudioFrame;
693                             gDecInfoAfCap2Idx++;
694                         }
695                         
696                         // debug
697                         //if (outIsDecInfo1Flag < 10) 
698                         //    outIsDecInfo1Flag++;
699                         //if (outIsDecInfo1Flag == 10)
700                         
701                         //
702                         // Execute Dec Info1 Init-Sync if required
703                         //
704                         if (outIsDecInfo1Flag == 0)
705                         {
706                             // Get pointer to Dec Info1 output audio frame
707                             pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
709                             if (checkDecSync(pDecCtrlAf) == 1)
710                             {
711                                 // Perform Dec Info1 Init-Sync
712                                 //  - Write Dec Info1 output audio frame
713                                 //  - Set Dec Info1 decoder stage flag
714                                 outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
715                                     ASP_OUTIS_DEC_STAGE_INFO1_IDX, 1, pDecCtrlAf);
716                                 if (outIsErrno < 0)
717                                 {
718                                     SW_BREAKPOINT; // debug
719                                 }
721                                 outIsDecInfo1Flag = 1;  // OutIS Dec Info1 has executed
722                             }
723                         }
724                     }
725                     
726                     // write back Dec configuration
727                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
728                     Cache_wait();            
729                     
730 #ifdef NON_CACHE_STATUS
731                     statusOp_read(&(temp8),
732                                   &(pAstCfg->xDec[z].decodeStatus.mode),
733                                   sizeof(Int8),
734                                   GATEMP_INDEX_DEC);
735                     // Re-initialize audio frame if decoder is disabled or
736                     // doesn't have a valid input
737                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
738                     {
739                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
740                     }
741 #else
742                     // Re-initialize audio frame if decoder is disabled or
743                     // doesn't have a valid input
744                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
745                     {
746                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
747                     }
748 #endif
750                     // send dec info complete message to master
751                     queId = MessageQ_getReplyQueue(pAspMsg);
752                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
753                     pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
754                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
755                     argIdx = 0; // set decErrno
756                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
757                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
758                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
759                     if (status != MessageQ_S_SUCCESS)
760                     {
761                         SW_BREAKPOINT;
762                     }
763                     
764                     break;
765                     
766                 case ASP_SLAVE_DEC_DECODE:
767                     gSlaveDecDecodeCnt++;
768                     
769                     argIdx = 0; // get decIdx
770                     z = *(Int32 *)&pAspMsg->buf[argIdx];
771                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
772                     // Get input associated w/ decoder
773                     zI = pP->inputsFromDecodes[z];
774                     
775                     // Reset AF samsiz
776                     resetAfSamsiz(z);
777                     
778                     // Invalidate Dec configuration
779                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
780                     Cache_wait();
781                     //TRACE_TERSE0("Dec:cache wb done");
782             
783                     dec = (DEC_Handle)alg[z];
784                     //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
786                     errno = 0;
787                     cbErrno = 0;
788                     if (dec->fxns->decode)
789                     {
790                         // Capture input buffer (debug)
791                         //capIb(pAstCfg->xInp[z].pInpBuf);
792                         
793                         // debug
794                         if (gDecDecodeAfCap1Idx < 20)
795                         {
796                             gDecDecodeAfCap1[gDecDecodeAfCap1Idx] = *pAstCfg->xDec[z].decodeInStruct.pAudioFrame;
797                             gDecDecodeAfCap1Idx++;
798                         }                       
799                     
800                         //
801                         // Execute decode
802                         //
803                         pfpBegin(PFP_ID_ASDT_2, pAsdtCfg->taskHandle);
804                         errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
805                         pfpEnd(PFP_ID_ASDT_2, PFP_FINISH_MEAS);
806                         if (errno < 0)
807                         {
808                             //SW_BREAKPOINT;
809                         }
810                         TRACE_TERSE0("Dec:decode done");
812                         // debug
813                         if (gDecDecodeAfCap2Idx < 20)
814                         {
815                             gDecDecodeAfCap2[gDecDecodeAfCap2Idx] = *pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
816                             gDecDecodeAfCap2Idx++;
817                         }                       
818                         
819                         // Get pointer to Dec Decode output audio frame
820                         pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;                           
821                         TRACE_TERSE2("Dec:pAfWrt=0x%04x, nSamples=%d", (IArg)pAfWrt, pAfWrt->data.nSamples);
822                         
823                         // Capture audio frame (debug)
824                         //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
825                         //{
826                         //    Log_info0("capAfWrite() error");
827                         //}                        
829                         #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
830                         if (tempCap_frameCnt < CAP_FRAME_MAX)
831                         {
832                             tempCap_decSampleOut[tempCap_frameCnt] = pAfWrt->sampleCount;
833                             tempCap_frameCnt++;
834                         }
835                         #endif
837                         //
838                         // Execute Dec Decode1 Init-Sync if required
839                         //
840                         if (outIsDecDecode1Flag == 0)
841                         {
842                             //
843                             // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
844                             //  frameLength: changed to decodeControl.frameLength.
845                             //    Written by ASIT:decodeInit:getFrameLengthSourceSel().
846                             //  FRAMELENGTH: pP->frameLength.
847                             //    Formerly ASIT, now ASDT but same value (PAF_SYS_FRAMELENGTH).
848                             //
849                             
850                             // Initialize decoder output circular buffer for selected source
851                             errno = cbInitSourceSel(pCbCtl, z, sourceSelect, 
852                                 pAstCfg->xDec[z].decodeControl.frameLength, 
853                                 FRAMELENGTH, 0, pAfWrt);
854                             if (errno)
855                             {
856                                 SW_BREAKPOINT; // debug
857                             }
858                             // debug
859                             cbLog(pCbCtl, z, 1, "cbInitSourceSel");
860                             
861                             // Perform Dec Decode1 Init-Sync
862                             //  - Set Dec Decode1 decoder stage flag
863                             outIsErrno = outIsWriteDecStageFlag(pOutIsCtl, z, 
864                                 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, 1);
865                             if (outIsErrno < 0)
866                             {
867                                 SW_BREAKPOINT; // debug
868                             }
870                             outIsDecDecode1Flag = 1;    // OutIS Dec Decode1 has executed
871                         }
873                         //
874                         // Write decoder output audio frame to circular buffer
875                         //
877                         // debug
878                         //pCb = &pAstCfg->xDecOpCb[z];
879                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);                                                
881                         //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107); // debug
882                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
883                         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
884                         {
885                             gCbWrtAfErrCnt++;
886                             //SW_BREAKPOINT; // debug
887                         }
888                         
889                         // Handle circular buffer overflows
890                         if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
891                         {
892                             gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
893                             if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
894                             {
895                                 gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
896                                 gDecOpCbWrtAfOvr = 0; // reset overflow count
897                                 
898                                 // Reset circular buffer
899                                 cbReset(pCbCtl, z);
900                                 gSlaveCbResetCnt++; // increment slave circular buffer reset count
901                                 Log_info0("ASDT:cbReset");
902                             }
903                         }
904                         else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
905                         {
906                             // No overflow detected.
907                             // update max overflow count,
908                             // reset overflow count
909                             
910                             if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
911                             {
912                                 gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
913                             }
914                             gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
915                             
916                             cbErrno = 0; // don't return error condition
917                         }
918                         //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
919                         TRACE_TERSE0("Dec:cbWriteAf() complete");
920                         
921 #if 0 // (***) FL: shows timing of CB write
922                         // (***) debug // B9
923                         {
924                             static Uint8 toggleState = 0;
925                             if (toggleState == 0)
926                                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
927                             else
928                                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
929                             toggleState = ~(toggleState);
930                         }
931 #endif        
932                         
933                         // Log circular buffer control variables (debug)
934                         cbLog(pCbCtl, z, 1, "cbWriteAf");
935                     }
936                     
937                     // write back Dec configuration
938                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
939                     Cache_wait();
940                     
941 #ifdef NON_CACHE_STATUS
942                     statusOp_read(&(temp8),
943                                   &(pAstCfg->xDec[z].decodeStatus.mode),
944                                   sizeof(Int8),
945                                   GATEMP_INDEX_DEC);
946                     // Re-initialize audio frame if decoder is disabled or 
947                     // doesn't have a valid input 
948                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
949                     {
950                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
951                     }
952 #else
953                     // Re-initialize audio frame if decoder is disabled or
954                     // doesn't have a valid input
955                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
956                     {
957                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
958                     }
959 #endif
960                     // send dec info complete message to master
961                     queId = MessageQ_getReplyQueue(pAspMsg);
962                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
963                     pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
964                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
965                     argIdx = 0; // set decErrno
966                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
967                     argIdx += sizeof(Int32); // set cbErrno
968                     *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;                    
969                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
970                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
971                     if (status != MessageQ_S_SUCCESS)
972                     {
973                         SW_BREAKPOINT;
974                     }
975                     
976                     break;
977                     
978                 case ASP_SLAVE_DEC_DEACTIVATE:
979                     gSlaveDecDeactivateCnt++;
980                     
981                     argIdx = 0; // get decIdx
982                     z = *(Int32 *)&pAspMsg->buf[argIdx];
983                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
984                     
985                     if (alg[z]->fxns->algDeactivate)
986                     {
987                         alg[z]->fxns->algDeactivate(alg[z]);
988                     }
989                     
990                     // Stop writes to circular buffer
991                     cbErrno = cbWriteStop(pCbCtl, z);
992                     if (cbErrno < 0)
993                     {
994                         SW_BREAKPOINT; // debug
995                     }
996                     // Log circular buffer control variables (debug)
997                     cbLog(pCbCtl, z, 1, "cbWriteStop");
998                     
999                     // Reset Output Init-Sync decoder stage flags
1000                     outIsErrno = outIsResetDecStageFlags(pOutIsCtl, z);
1001                     if (outIsErrno < 0)
1002                     {
1003                         SW_BREAKPOINT; // debug
1004                     }
1005                     
1006                     // send dec deactivate complete message to master
1007                     queId = MessageQ_getReplyQueue(pAspMsg);
1008                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
1009                     pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
1010                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
1011                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1012                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
1013                     if (status != MessageQ_S_SUCCESS)
1014                     {
1015                         SW_BREAKPOINT;
1016                     }
1017                     
1018                     break;
1019                     
1020                 default:
1021                     TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
1022                     break;
1023             }
1024         }
1025     }
1026     
1027     Log_info0("exit taskAsdpFxn()");   
1031 // -----------------------------------------------------------------------------
1032 // AST Initialization Function - Memory Allocation
1033 //
1034 //   Name:      PAF_AST_initPhaseMalloc
1035 //   Purpose:   Audio Stream Task Function for initialization of data pointers
1036 //              by allocation of memory.
1037 //   From:      audioStream1Task or equivalent
1038 //   Uses:      See code.
1039 //   States:    x
1040 //   Return:    0 on success.
1041 //              Source code line number on MEM_calloc failure.
1042 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1043 //              * State information as per parent.
1044 //              * Memory allocation errors.
1045 //
1046 Int
1047 PAF_ASDT_initPhaseMalloc(
1048     const PAF_ASDT_Params *pP, 
1049     const PAF_ASDT_Patchs *pQ, 
1050     PAF_ASDT_Config *pAsdtCfg
1053     PAF_AST_Config *pAstCfg;
1054     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1055     Int zMS;
1056     Error_Block eb;
1058     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1059     as = pAstCfg->as;
1060     zMS = pAstCfg->masterStr;
1061     
1062     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1064     // Initialize error block
1065     Error_init(&eb); 
1067     if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL,
1068         DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
1069     {
1070         TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1071         SW_BREAKPOINT;
1072         return __LINE__;
1073     }
1074     TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
1075             DECODEN * sizeof (PAF_AudioFrame),
1076             HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
1078     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1079     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1080     return 0;
1081 } //PAF_ASDT_initPhaseMalloc
1083 // -----------------------------------------------------------------------------
1084 // AST Initialization Function - Memory Initialization from Configuration
1085 //
1086 //   Name:      PAF_AST_initPhaseConfig
1087 //   Purpose:   Audio Stream Task Function for initialization of data values
1088 //              from parameters.
1089 //   From:      audioStream1Task or equivalent
1090 //   Uses:      See code.
1091 //   States:    x
1092 //   Return:    0 on success.
1093 //              Other as per initFrame0 and initFrame1.
1094 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1095 //              * State information as per parent.
1096 //
1098 Int
1099 PAF_ASDT_initPhaseConfig(
1100     const PAF_ASDT_Params *pP, 
1101     const PAF_ASDT_Patchs *pQ, 
1102     PAF_ASDT_Config *pAsdtCfg
1105     PAF_AST_Config *pAstCfg;
1106     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1107     Int zMS;
1108     Int z;
1110     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1111     as = pAstCfg->as;
1112     zMS = pAstCfg->masterStr;
1113     
1114     TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1116     // overwrite pointer to audio frame in framework decode control
1117     for (z=DECODE1; z < DECODEN; z++) 
1118     {
1119         //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
1120         //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1121         //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1122         pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
1123         pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
1124         pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
1125         pP->fxns->initFrame0(pP, pQ, pAsdtCfg, z);
1126     }
1128     return 0;
1129 }  //PAF_ASDT_initPhaseConfig
1131 // -----------------------------------------------------------------------------
1132 // AST Initialization Function - ACP Algorithm Instantiation
1133 //
1134 //   Name:      PAF_AST_initPhaseAcpAlg
1135 //   Purpose:   Audio Stream Task Function for initialization of ACP by
1136 //              instantiation of the algorithm.
1137 //   From:      audioStream1Task or equivalent
1138 //   Uses:      See code.
1139 //   States:    x
1140 //   Return:    0 on success.
1141 //              Source code line number on ACP Algorithm creation failure.
1142 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1143 //              * State information as per parent.
1144 //              * Memory allocation errors.
1145 //
1146 Int
1147 PAF_ASDT_initPhaseAcpAlg(
1148     const PAF_ASDT_Params *pP, 
1149     const PAF_ASDT_Patchs *pQ, 
1150     PAF_ASDT_Config *pAsdtCfg
1153     PAF_AST_Config *pAstCfg;
1154     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1155     Int z;                     /* input/encode/stream/decode/output counter */
1156     Int betaPrimeOffset;
1157     ACP_Handle acp;
1158     Int zMS;
1159     Int zS; //, zX;
1161     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1162     as = pAstCfg->as;
1163     zMS = pAstCfg->masterStr;    
1165     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1167     ACP_MDS_init();
1169     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1170     {
1171         TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
1172         return __LINE__;
1173     }
1174     pAsdtCfg->acp = acp;
1176     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
1177         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1179     for (z=DECODE1; z < DECODEN; z++) 
1180     {
1181         zS = pP->streamsFromDecodes[z];
1182         acp->fxns->attach(acp, ACP_SERIES_STD,
1183             STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1184             (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
1185         /* Ignore errors, not reported. */
1186     }
1188     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1190     return 0;
1191 } //PAF_AST_initPhaseAcpAlg
1193 // -----------------------------------------------------------------------------
1194 // AST Initialization Function - Common Memory and Algorithms
1195 //
1196 //   Name:      PAF_AST_initPhaseCommon
1197 //   Purpose:   Audio Stream Task Function for initialization of data pointers
1198 //              by allocation for common memory and by instantiation for
1199 //              algorithms.
1200 //   From:      audioStream1Task or equivalent
1201 //   Uses:      See code.
1202 //   States:    x
1203 //   Return:    0 on success.
1204 //              Source code line number on PAF_ALG_alloc failure.
1205 //              Source code line number on PAF_ALG_mallocMemory failure.
1206 //              Source code line number on Decode Chain initialization failure.
1207 //              Source code line number on ASP Chain initialization failure.
1208 //              Source code line number on Encode Chain initialization failure.
1209 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1210 //              * State information as per parent.
1211 //              * Memory allocation errors.
1212 //
1214 #include <pafsio_ialg.h>
1216 Int
1217 PAF_ASDT_initPhaseCommon(
1218     const PAF_ASDT_Params *pP, 
1219     const PAF_ASDT_Patchs *pQ, 
1220     PAF_ASDT_Config *pAsdtCfg
1223     PAF_AST_Config *pAstCfg;
1224     Int as;                         /* Audio Stream Number (1, 2, etc.) */
1225     Int z;                          /* stream counter */
1226     //Int g;                        /* gear */
1227     ACP_Handle acp;
1228     PAF_IALG_Config pafAlgConfig;
1229     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1230    
1231     acp = pAsdtCfg->acp; // get acp handle
1232     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1233     as = pAstCfg->as;
1234     
1235     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
1237     //
1238     // Determine memory needs and instantiate algorithms across audio streams
1239     //
1241     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
1242     PAF_ALG_setup(&pafAlgConfig, 
1243         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1244         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1245         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1246         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1247         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1248         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1249         HEAP_CLEAR);
1251     if (pP->fxns->headerPrint)
1252         pP->fxns->headerPrint();
1254     for (z=STREAM1; z < STREAMN; z++) 
1255     {
1256         //Int zD, zE, zX;
1257         Int zD, zX;
1259         TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
1261         //
1262         // Determine common memory needs of Decode Algorithms
1263         //
1264         PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
1266         zD = -1;
1267         for (zX = DECODE1; zX < DECODEN; zX++) 
1268         {
1269             if (pP->streamsFromDecodes[zX] == z) 
1270             {
1271                 zD = zX;
1272                 break;
1273             }
1274         }
1276         if (zD >= 0) 
1277         {
1278             TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
1279             if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z])) 
1280             {
1281                 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1282                 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1284                 SW_BREAKPOINT;
1285                 return __LINE__;
1286             }
1287             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1288             if(pP->fxns->allocPrint)
1289                 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1290         }
1292 #if 0 // FL: master
1293         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1294         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1295         if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z])) 
1296         {
1297             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1298             TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1299             SW_BREAKPOINT;
1300             return __LINE__;
1301         }
1302         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1303         if(pP->fxns->allocPrint)
1304             pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1305 #endif
1306         
1307     }
1308     {
1309         // Changes made to share scratch between zones
1310         // Assume maximum 3 zones and scratch common memory is at offset 0;
1311         int max=0;
1312         for (z=STREAM1; z < STREAMN; z++)
1313         {
1314             if (max<common[z][0].size)
1315                 max=common[z][0].size;
1316         }
1317         common[STREAM1][0].size=max;
1318         for (z=STREAM1+1; z < STREAMN; z++)
1319             common[z][0].size=0;
1320     }
1321     
1322     //
1323     // Provide common memory needs of Decode Algorithms
1324     //
1325     for (z=STREAM1; z < STREAMN; z++) 
1326     {
1327         //Int zD, zE, zX;
1328         Int zD, zX;
1330         zD = -1;        
1331         for (zX = DECODE1; zX < DECODEN; zX++) 
1332         {
1333            if (pP->streamsFromDecodes[zX] == z) 
1334            {
1335                zD = zX;
1336                break;
1337            }
1338         }
1340         TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1341         if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig)) 
1342         {
1343             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1344             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1345             SW_BREAKPOINT;
1346             return __LINE__;
1347         }
1348         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1349         // share zone0 scratch with all zones 
1350         common[z][0].base=common[0][0].base;
1351         if (pP->fxns->commonPrint)
1352                 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1354         //
1355         // Instantiate Decode Algorithms
1356         //
1357         if (zD >= 0) 
1358         {
1359             PAF_ASP_Chain *chain;
1360             TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1361             chain =
1362                 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1363                                    HEAP_INTERNAL, as+z, acp, &trace,
1364                                    decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1365             if (!chain) 
1366             {
1367                 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1368                 return __LINE__;
1369             }
1370         }
1372 #if 0 // FL: master
1373         pC->xStr[z].aspChain[0] = NULL;
1374         for (g=0; g < GEARS; g++) 
1375         {
1376             PAF_ASP_Chain *chain;
1377             TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1378             chain =
1379                 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1380                                    HEAP_INTERNAL, as+z, acp, &trace,
1381                                    aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1382             if (! chain) 
1383             {
1384                 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1385                 return __LINE__;
1386             }
1387             else
1388                 pC->xStr[z].aspChain[g] = chain;
1389         }
1390 #endif
1392     }
1393     TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1395     return 0;
1396 } //PAF_ASDT_initPhaseCommon
1398 // -----------------------------------------------------------------------------
1399 // AST Initialization Function - Algorithm Keys
1400 //
1401 //   Name:      PAF_AST_initPhaseAlgKey
1402 //   Purpose:   Audio Stream Task Function for initialization of data values
1403 //              from parameters for Algorithm Keys.
1404 //   From:      audioStream1Task or equivalent
1405 //   Uses:      See code.
1406 //   States:    x
1407 //   Return:    0.
1408 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1409 //              * State information as per parent.
1410 //
1411 // .............................................................................
1412 Int
1413 PAF_ASDT_initPhaseAlgKey(
1414     const PAF_ASDT_Params *pP, 
1415     const PAF_ASDT_Patchs *pQ, 
1416     PAF_ASDT_Config *pAsdtCfg
1419     PAF_AST_Config *pAstCfg;
1420     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1421     Int z;                      /* decode/encode counter */
1422     Int s;                      /* key number */
1423     PAF_ASP_Link *that;
1425     (void)as;  // clear warning.
1427     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1428     as = pAstCfg->as;
1429     
1430     TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1432     for (z=DECODE1; z < DECODEN; z++) 
1433     {
1434         for (s=0; s < pP->pDecAlgKey->length; s++) 
1435         {
1436             if ((pP->pDecAlgKey->code[s].full != 0)
1437                 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1438             {
1439                 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1440                     /* Cast in interface, for now --Kurt */
1441             }
1442             else
1443                 pAstCfg->xDec[z].decAlg[s] = NULL;
1444         }
1445     }
1447     return 0;
1448 } //PAF_AST_initPhaseAlgKey
1450 //   Purpose:   Audio Stream Decode Task Function for initialization of the Audio
1451 //              Frame(s) by memory allocation and loading of data pointers
1452 //              and values.
1453 Int
1454 PAF_ASDT_initFrame0(
1455     const PAF_ASDT_Params *pP, 
1456     const PAF_ASDT_Patchs *pQ, 
1457     PAF_ASDT_Config *pAsdtCfg, 
1458     Int z
1461     PAF_AST_Config *pAstCfg;
1462     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1463     Int aLen;
1464     Int aSize = sizeof(PAF_AudioData);
1465     Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1466     Int maxFrameLength = pP->maxFramelength;
1467     PAF_AudioData *aBuf=NULL;
1468     XDAS_UInt8 *metadataBuf;
1469     Error_Block    eb;
1470     PAF_AudioFrame *pAudioFrame;
1471     Int i;
1473     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1474     as = pAstCfg->as;
1476     pAudioFrame = &gpDecAudioFrame[z];
1477     if (pAudioFrame == NULL)
1478     {
1479         SW_BREAKPOINT;
1480     }
1481     
1482     // Initialize error block
1483     Error_init(&eb); 
1484     
1485     //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1486     //aLen = numchan[z] * maxFrameLength;
1487     aLen = numchan[z] * maxFrameLength + (maxFrameLength - FRAMELENGTH); /* Qin - need additional memory for starting offset
1488                                                                                   See line 1301 */
1490     //
1491     // Initialize audio frame elements directly
1492     //
1493     pAudioFrame->fxns = pP->pAudioFrameFunctions;
1494     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1495     pAudioFrame->data.nSamples = FRAMELENGTH;
1496     pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1497     pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1498     pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1500     //
1501     // Allocate memory for and initialize pointers to audio data buffers
1502     //
1503     //   The NUMCHANMASK is used to identify the channels for which data
1504     //   buffers can be allocated. Using this mask and switch statement
1505     //   rather than some other construct allows efficient code generation,
1506     //   providing just the code necessary (with significant savings).
1507     //
1508     if (pP->fxns->bufMemPrint)
1509     {
1510         pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1511     }
1513     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1514     
1515     if (aLen != 0)
1516     {
1517         if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1518         {
1519             TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1520             TRACE_TERSE2("  maxFrameLength: %d.  aLen*aSize: %d", maxFrameLength, aLen*aSize);
1521             SW_BREAKPOINT;
1522             return __LINE__;
1523         }
1524     }
1526     TRACE_TERSE3("  maxFrameLength: %d.  aLen*aSize: %d.  aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1528     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1529     if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1530     {
1531         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1532         TRACE_TERSE1("  bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1533         SW_BREAKPOINT;
1534         return __LINE__;
1535     }
1537     for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1538     {
1539         gDecAudioFrameChannelPointers[i] = NULL;
1540     }
1542     if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1)) 
1543     {
1544         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1545         return __LINE__;
1546     }
1547     else 
1548     {
1549         Int j = 0;
1550         TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1551         for (i=0; i<numchan[z]; i++)
1552         {
1553             Int8 chan = AFChanPtrMap[numchan[z]][i];
1554             if (chan != -1)
1555             {
1556                 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1557                 j++;
1558                 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1559                 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1560             }
1561         }
1562     }
1564     // Initialize original audio frame channel pointers
1565     for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++) 
1566     {
1567         if (gDecAudioFrameChannelPointers[i])
1568         {
1569             gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1570         }
1571     }
1573     //
1574     // Initialize meta data elements
1575     //
1576     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1577     pAudioFrame->numPrivateMetadata = 0;
1578     pAudioFrame->bsMetadata_offset = 0;
1579     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1580     pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1581     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1582     {
1583         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1584         pAudioFrame->pafPrivateMetadata[i].size = 0;
1585         pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1586     }
1588     return 0;
1589 } //PAF_ASDT_initFrame0
1591 // -----------------------------------------------------------------------------
1592 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1593 // AST Decoding Function              - Reinitialization of Audio Frame
1594 //
1595 //   Name:      PAF_ASOT_initFrame1
1596 //   Purpose:   Audio Stream Task Function for initialization or reinitiali-
1597 //              zation of the Audio Frame(s) by loading of data values of a
1598 //              time-varying nature.
1599 //   From:      audioStream1Task or equivalent
1600 //              AST Parameter Function -> decodeInfo
1601 //              AST Parameter Function -> decodeDecode
1602 //   Uses:      See code.
1603 //   States:    x
1604 //   Return:    0.
1605 //   Trace:     None.
1606 //
1607 Int
1608 PAF_ASDT_initFrame1(
1609     const PAF_ASDT_Params *pP, 
1610     const PAF_ASDT_Patchs *pQ, 
1611     PAF_ASDT_Config *pAsdtCfg, 
1612     Int z, 
1613     Int apply
1616     PAF_AudioFrame *pAudioFrame;
1618     //
1619     // Reinitialize audio frame elements:
1620     //
1621     //   Channel Configurations during sys init                 = Unknown
1622     //      "          "        during info or decode           = None
1623     //
1624     //   Sample Rate / Count    during sys init, info or decode = Unknown / 0
1625     //
1627     pAudioFrame = &gpDecAudioFrame[z];
1629     if (apply < 0) 
1630     {
1631         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1632         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1633     }
1634     else 
1635     {
1636         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1637         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1638     }
1640     if (apply < 1) 
1641     {
1642         pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1643         pAudioFrame->sampleCount = 0;
1644     }
1646     return 0;
1647 } //PAF_ASDT_initFrame1
1649 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1650 Int resetAf(
1651     const PAF_ASDT_Params *pP, 
1652     Int z, 
1653     Int sourceSelect
1656     PAF_AudioFrame *pAudioFrame;
1657     Int ch;
1658     Int i;
1660     // Get audio frame
1661     pAudioFrame = &gpDecAudioFrame[z];
1662     if (pAudioFrame == NULL)
1663     {
1664         SW_BREAKPOINT;
1665     }
1667     // Reinitialize audio frame elements
1668     pAudioFrame->sampleDecode = PAF_SOURCE_UNKNOWN;
1669     pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1670     pAudioFrame->sampleCount = 0;
1671     pAudioFrame->channelConfigurationRequest.full = PAF_CC_UNKNOWN;
1672     pAudioFrame->channelConfigurationStream.full = PAF_CC_UNKNOWN;
1673     
1674     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1675     switch (sourceSelect)
1676     {
1677         case PAF_SOURCE_PCM:
1678             pAudioFrame->data.nSamples = FRAMELENGTH;
1679             break;
1680         case PAF_SOURCE_AC3:
1681         case PAF_SOURCE_DDP:
1682             pAudioFrame->data.nSamples = 1536;
1683             break;
1684         case PAF_SOURCE_THD:
1685             pAudioFrame->data.nSamples = 5120; //QIN FIX ME
1686             break;
1687         default:  
1688             pAudioFrame->data.nSamples = FRAMELENGTH;
1689             break;
1690     }
1692     // Reset audio frame channel pointers
1693     for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
1694     {
1695         if (gDecAudioFrameChannelPointers[ch])
1696         {
1697             gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1698         }
1699     }
1700     
1701     // Reset audio frame meta data elements
1702     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1703     pAudioFrame->numPrivateMetadata = 0;
1704     pAudioFrame->bsMetadata_offset = 0;
1705     pAudioFrame->bsMetadata_type = PAF_bsMetadata_none;
1706     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1707     {
1708         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1709         pAudioFrame->pafPrivateMetadata[i].size = 0;
1710     }
1711     
1712     return 0;
1715 // Reset AF samsiz, invoked during DECODE
1716 Int resetAfSamsiz(
1717     Int z
1720     PAF_AudioFrame *pAudioFrame;
1721     Int ch;
1722     
1723     // Get audio frame
1724     pAudioFrame = &gpDecAudioFrame[z];
1725     if (pAudioFrame == NULL)
1726     {
1727         SW_BREAKPOINT;
1728     }
1729     
1730     // Clear samsiz for all channels - MID 208.
1731     for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
1732     {
1733         pAudioFrame->data.samsiz[ch] = 0;
1734     }
1736     return 0;
1739 // (***) FL: Check correct behavior for other decs, esp DTSHD & DXP
1740 // Check decoder sync using information in INFO audio frame
1741 static Int8 checkDecSync(
1742     PAF_AudioFrame *pAf
1745     if ((pAf->sampleDecode == PAF_SOURCE_THD) &&
1746         (pAf->sampleRate == PAF_SAMPLERATE_UNKNOWN))
1747     {
1748         return 0;
1749     }
1750     else
1751     {
1752         return 1;
1753     }