d10e34e20d731fd218647cc772e2a2d45403f362
[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
142 /*
143  *  ======== taskAsdpFxn ========
144  *  Audio Stream Decode Processing task function
145  */
146 Void taskAsdpFxn(
147 //    Int betaPrimeValue, // FL: revisit
148     const PAF_ASDT_Params *pP,
149     const PAF_ASDT_Patchs *pQ
152     PAF_ASDT_Config *pAsdtCfg;          // ASDT configuration pointer
153     PAF_AST_Config *pAstCfg;            // Common (shared) configuration pointer
154     Int as;                             // Audio Stream Number (1, 2, etc.)
155     Int z;                              // input/encode/stream/decode/output counter
156     Int i;                              // phase
157     Int zMD, zMS;
158     Bool done;
159     Bool decDone;
160     ALG_Handle alg[DECODEN_MAX];
161     ASP_Slave_Cmd slaveCmd;
162     Int sourceSelect;
163     DEC_Handle dec;
164     IALG_Cmd decCtrlCmd;                // decoder control command
165     Int decCtrlRet;                     // decoder control return
166     Int errno;                          // error number
167     Int size;
168     Int argIdx;
169     // Decoder output circular buffer
170     PAF_AST_DecOpCircBufCtl *pCbCtl;    // Decoder output Circular Buffer control
171     PAF_AudioFrame *pAfWrt;             // pointer to audio frame written to CB
172     Int cbErrno;                        // CB error number
173     // Output Init-Sync
174     PAF_AudioFrame *pDecCtrlAf;         // pointer to Dec Control audio frame
175     PAF_AST_OutInitSyncCtl *pOutIsCtl;  // OutIS control
176     Int8 outIsDecInfo1Flag;             // indicates whether Dec Info Init-Sync has executed
177     Int8 outIsDecDecode1Flag;           // indicates whether Dec Decode1 Init-Sync has executed
178     Int outIsErrno;                     // OutIS error number
179     // Messaging
180     PAF_InpBufConfig *pIpBufConfig;     // IB buffer configuration
181     ASP_Msg *pAspMsg;                   // Rx/Tx MessageQ message
182     MessageQ_QueueId queId;             // MessageQ ID
183     Int status;
184     Int zI;
185     Int bufEnd, wrapSize, currentBufSize, chunkSize;
186     Int8 temp8;
188     Log_info0("Enter taskAsdpFxn()");
189     
190     
191     //
192     // Audio Framework Parameters & Patch (*pP, *pQ):
193     //
194     if (!pP) 
195     {
196         TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
197         LINNO_RPRT(TaskAsdp, -1);
198         return;
199     }
201     if (!pQ) 
202     {
203         TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
204         LINNO_RPRT(TaskAsdp, -1);
205         return;
206     }    
208     //
209     // Audio Stream Decode Task Configuration (*pAsdtCfg):
210     //
211     pAsdtCfg = &gPAF_ASDT_config;           // initialize pointer to task configuration
212     pAsdtCfg->taskHandle = Task_self();     // set task handle
213     pAstCfg = pAsdtCfg->pAstCfg;            // get pointer to AST common (shared) configuration 
214     pCbCtl = &pAsdtCfg->decOpCircBufCtl;    // get pointer to circular buffer control
215     pOutIsCtl = &pAsdtCfg->outIsCtl;        // get pointer to output init-sync control
216     
217     // wait for initialization message from master
218     do {
219         status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
220         //TRACE_TERSE1("Rx ASP message: status=%d", status);
221     //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
222     } while (status != MessageQ_S_SUCCESS);
223     if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
224         (pAspMsg->cmd != ASP_SLAVE_START))
225     {
226         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
227         SW_BREAKPOINT;
228     }
229     hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
230     gSlaveStartCnt++;
231     TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
233     // invalidate AST shared configuration
234     Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
235     Cache_wait();
236     
237     // (***) FL: revisit
238     // invalidate Dec configuration for all Decoder zones
239     Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
240     Cache_wait();
242     // (***) FL: revisit
243     // invalidate Beta Table status pointers
244     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
245     Cache_wait();
247     /* Obtain Audio Stream Number (1, 2, etc.) */
248     as = pAstCfg->as;
249     TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
250     
251     //
252     // Initialize message log trace and line number reporting
253     //
254     for (z=STREAM1; z < STREAMN; z++)
255     {
256         TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
257     }
258     LINNO_RPRT(TaskAsdp, -1);
260     // Get decoder and stream index associated with the master input
261     zMD = pAstCfg->masterDec;
262     zMS = pAstCfg->masterStr;
264     // 
265     // Initialize per parameterized phases.
266     //   - Malloc: Memory Allocation
267     //   - Config: Configuration Initialization
268     //   - AcpAlg: ACP Algorithm Initialization and Local Attachment
269     //   - Common: Common Algorithm Initialization
270     //   - AlgKey: Dec/Enc chain to Array Initialization
271     //   - Unused: (available)
272     //   - Unused: (available)
273     //   - Unused: (available)
274     //
275     LINNO_RPRT(TaskAsdp, -2);
276     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
277     {
278         Int linno;
279         if (pP->fxns->initPhase[i])
280         {
281             if ((linno = pP->fxns->initPhase[i](pP, pQ, pAsdtCfg)))
282             {
283                 LINNO_RPRT(TaskAsdp, linno);
284                 return;
285             }
286         }
287         else 
288         {
289             TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
290         }
291         TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
292         LINNO_RPRT(TaskAsdp, -i-3);
293     }
294     
295 #ifdef NON_CACHE_STATUS
296     //
297     // init Status structure Gate
298     //
299     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
300     {
301         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DEC);
302     }
303     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
304     {
305         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DDP);
306     }
307     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
308     {
309         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_PCM);
310     }
311     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
312     {
313         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_THD);
314     }
315     if (statusOp_Init(GATEMP_INDEX_DTS) == STATUSOP_INIT_FAIL)
316     {
317         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DTS);
318     }
319 #endif
320     //
321     // End of Initialization -- final memory usage report.
322     //
323     if (pP->fxns->memStatusPrint)
324     {
325         pP->fxns->memStatusPrint("ASDT MEMSTAT REPORT",
326             HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, 
327             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
328     }
329     
330     // (***) FL: revisit
331     // write back Status structure addresses for Beta Units initialized on Slave
332     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
333     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
334     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
335     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
336     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
337     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
338     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
339     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DTSUHDA]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
340     Cache_wait();
341     
342     // (***) FL: revisit
343     // write back Status structures for Beta Units initialized on Slave
344    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
345     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
346     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
347     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
348     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
349     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
350     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
351     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
352     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
353     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
354     Cache_wait();
356     // (***) FL: revisit
357     // write back Dec configuration
358     Cache_wbInv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
359     Cache_wait();*/
360     
361     // Send initialization complete message to master
362     queId = MessageQ_getReplyQueue(pAspMsg);
363     pAspMsg->procId = hAspMsgSlave->slaveProcId;
364     pAspMsg->cmd = ASP_MASTER_START_DONE;
365     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
366     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
367     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
368     if (status != MessageQ_S_SUCCESS)
369     {
370         SW_BREAKPOINT;
371     }
373     done = FALSE;
374     while (done==FALSE)
375     {
376         // wait for source select message from master
377         do {
378             status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
379         } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
380         if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
381             (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
382         {
383             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
384             SW_BREAKPOINT;
385         }            
386         hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
387         sourceSelect = *(Int32 *)&pAspMsg->buf[0];
388         TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
389         TRACE_MSG1("sourceSelect=%d.", sourceSelect);
390         // send source select complete message to master
391         queId = MessageQ_getReplyQueue(pAspMsg);
392         pAspMsg->procId = hAspMsgSlave->slaveProcId;
393         pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
394         pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
395         gSlaveSourceSelectCnt++;
396         TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
397         MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
398         
399         for (z=DECODE1; z < DECODEN; z++)
400         {
401             alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
402         }
403         alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
405 #if 0 // debug, reset IB capture buffer
406         capIbReset();
407         Log_info0("capIbReset()");
408 #endif
409         
410 #if 0 // debug, reset audio frame capture buffer
411         capAfReset();
412         Log_info0("capAfReset()");
413 #endif
414         
415         decDone = FALSE;
416         while (decDone==FALSE)
417         {
418             // wait for received message from master
419             do {
420                 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
421             } while (status < 0);
422             if (pAspMsg->procId != hAspMsgSlave->masterProcId)
423             {
424                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
425                 SW_BREAKPOINT;
426             }
427             hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
428             slaveCmd = pAspMsg->cmd;
429             TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
431             switch (slaveCmd)
432             {
433                 case ASP_SLAVE_NULL:
434                 case ASP_SLAVE_START:
435                     gSlaveStartErrCnt++;
436                     TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
437                     
438                     break;
439                     
440                 case ASP_SLAVE_EXIT:
441                     gSlaveExitCnt++;
442                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
443                     
444                     decDone = TRUE;
445                     done = TRUE;
446                     break;
447                     
448                 case ASP_SLAVE_DEC_EXIT:
449                     gSlaveDecExitCnt++;
450                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
451                     
452                     // send dec exit complete message to master
453                     queId = MessageQ_getReplyQueue(pAspMsg);
454                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
455                     pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
456                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
457                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
458                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
459                     if (status != MessageQ_S_SUCCESS)
460                     {
461                         SW_BREAKPOINT;
462                     }
463                     
464                     decDone=TRUE;
465                     break;
466                     
467                 case ASP_SLAVE_DEC_CONTROL:
468                     gSlaveDecControlCnt++;
469                     
470                     argIdx = 0; // get decIdx
471                     z = *(Int32 *)&pAspMsg->buf[argIdx];
472                     argIdx += sizeof(Int32);
473                     decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
474                     TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
475                     
476                     decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
478                     // send dec control complete message to master
479                     queId = MessageQ_getReplyQueue(pAspMsg);
480                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
481                     pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
482                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
483                     argIdx = 0; // set decCtrlRet
484                     *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
485                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
486                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
487                     if (status != MessageQ_S_SUCCESS)
488                     {
489                         SW_BREAKPOINT;
490                     }
492                     break;
493                     
494                 case ASP_SLAVE_DEC_ACTIVATE:
495                     gSlaveDecActivateCnt++;
496                     
497                     // (***) FL: revisit
498                     // invalidate Status structures for shared Beta Units
499                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
500                     //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
501                     /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
502                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
503                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
504                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
505                     Cache_wait();*/
506                     
507                     argIdx = 0; // get decIdx
508                     z = *(Int32 *)&pAspMsg->buf[argIdx];
509                     TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
510                     
511                     // invalidate Dec configuration
512                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
513                     Cache_wait();
514                     
515                     if (alg[z]->fxns->algActivate)
516                     {
517                         alg[z]->fxns->algActivate(alg[z]);
518                     }
520                     // Start writes to circular buffer
521                     cbErrno = cbWriteStart(pCbCtl, z);
522                     if (cbErrno < 0)
523                     {
524                         SW_BREAKPOINT;
525                     }
526                     gCbWrtAfErrCnt=0;       // reset write circular buffer error count
527                     gDecOpCbWrtAfOvr=0;     // reset decoder output circular buffer overflow count
528                     gMaxDecOpCbWrtAfOvr=0;  // reset max decoder output circular buffer overflow count
529                     gSlaveCbResetCnt=0;     // reset slave circular buffer reset count
530                     // Log circular buffer control variables (debug)
531                     cbLog(pCbCtl, z, 1, "cbWriteStart");
532                     
533                     // Reset audio frame
534                     resetAf(pP, z, sourceSelect);
535                     
536                     // Initialize OutIS Dec flags
537                     outIsDecInfo1Flag = 0;      // OutIS Dec Info1 hasn't executed
538                     outIsDecDecode1Flag = 0;    // OutIS Dec Decode1 hasn't executed
539                     
540                     // send dec activate complete message to master
541                     queId = MessageQ_getReplyQueue(pAspMsg);
542                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
543                     pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
544                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
545                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
546                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
547                     if (status != MessageQ_S_SUCCESS)
548                     {
549                         SW_BREAKPOINT;
550                     }
551                    
552                     break;
553                     
554                 case ASP_SLAVE_DEC_RESET:
555                     gSlaveDecResetCnt++;
556                     
557                     argIdx = 0; // get decIdx
558                     z = *(Int32 *)&pAspMsg->buf[argIdx];
559                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
560                     
561                     dec = (DEC_Handle)alg[z];
562                     errno = 0;
563                     if (dec->fxns->reset)
564                     {
565                         //
566                         // Execute decode reset
567                         //
568                         errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
570                         // Get pointer to Dec Reset output audio frame
571                         pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
573                         // Perform Dec Reset Init-Sync
574                         //  - Write Dec Reset output audio frame
575                         //  - Set Dec Reset decoder stage flag
576                         outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
577                             ASP_OUTIS_DEC_STAGE_RESET_IDX, 1, pDecCtrlAf);
578                         if (outIsErrno < 0)
579                         {
580                             SW_BREAKPOINT; // debug
581                         }
582                     }
584                     // write back Dec configuration
585                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
586                     Cache_wait();            
588                     // (***) FL: revisit
589                     // write back Status structures for shared Beta Units
590                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
591                     //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
592                    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
593                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
594                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
595                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
596                     Cache_wait();*/
598                     // send dec reset complete message to master
599                     queId = MessageQ_getReplyQueue(pAspMsg);
600                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
601                     pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
602                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
603                     argIdx = 0; // set decErrno
604                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
605                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
606                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
607                     if (status != MessageQ_S_SUCCESS)
608                     {
609                         SW_BREAKPOINT;
610                     }
612                     break;
613                     
614                 case ASP_SLAVE_DEC_INFO:
615                     gSlaveDecInfoCnt++;
616                     
617                     argIdx = 0; // get decIdx
618                     z = *(Int32 *)&pAspMsg->buf[argIdx];
619                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
620                     // Get input associated w/ decoder
621                     zI = pP->inputsFromDecodes[z];
623                     // (***) FL: revisit
624                     // invalidate Inp configuration
625                     Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
626                     Cache_wait();
627                     // invalidate input data
628                     pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
629                     size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
630                     if (sourceSelect == PAF_SOURCE_PCM)
631                     {
632                         size *= pIpBufConfig->stride;
633                     }
635                     bufEnd = (Int) pIpBufConfig->base.pVoid + pIpBufConfig->sizeofBuffer;
636                     currentBufSize = (bufEnd - (Int)pIpBufConfig->pntr.pSmInt);
637                     if (currentBufSize >= size)
638                     {
639                         chunkSize = size;
640                     }
641                     else
642                     {
643                         chunkSize = currentBufSize;
644                     }
645                     wrapSize = size - chunkSize;
646                     // invalidate input data
647                     Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
648                     // invalidate Dec configuration
649                     TRACE_MSG2("IBUF : pIpBufConfig->pntr.pSmInt: 0x%x and chunkSize: %d", (IArg)pIpBufConfig->pntr.pSmInt, chunkSize);
650                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
651                     // status for selected decoder should be invalidated
652                     Cache_wait();
654                     /* Circular buffer wrap condition*/
655                     //if(((Int) pIpBufConfig->head.pVoid + size)  > bufEnd)
656                     if(wrapSize > 0)
657                     {
658                         // invalidate input data
659                         Cache_inv((Ptr)pIpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
660                         TRACE_MSG2("IBUF : pIpBufConfig->base.pSmInt: 0x%x and wrapSize: %d", (IArg)pIpBufConfig->base.pSmInt, wrapSize);
661                         // status for selected decoder should be invalidated
662                         Cache_wait();
663                     }
664                     /* Circular buffer wrap condition */
666                     dec = (DEC_Handle)alg[z];
667                     errno = 0;
668                     if (dec->fxns->info)
669                     {
670                         //
671                         // Execute decode info
672                         //
673                         pfpBegin(PFP_ID_ASDT_1, pAsdtCfg->taskHandle);
674                         errno = dec->fxns->info(dec, NULL, 
675                             &pAstCfg->xDec[z].decodeControl, 
676                             &pAstCfg->xDec[z].decodeStatus);
677                         pfpEnd(PFP_ID_ASDT_1, PFP_FINISH_MEAS);
679                         //
680                         // Execute Dec Info1 Init-Sync if required
681                         //
682                         if (outIsDecInfo1Flag == 0)
683                         {
684                             // Get pointer to Dec Info1 output audio frame
685                             pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
687                             if (checkDecSync(pDecCtrlAf) == 1)
688                             {
689                                 // Perform Dec Info1 Init-Sync
690                                 //  - Write Dec Info1 output audio frame
691                                 //  - Set Dec Info1 decoder stage flag
692                                 outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z, 
693                                     ASP_OUTIS_DEC_STAGE_INFO1_IDX, 1, pDecCtrlAf);
694                                 if (outIsErrno < 0)
695                                 {
696                                     SW_BREAKPOINT; // debug
697                                 }
699                                 outIsDecInfo1Flag = 1;  // OutIS Dec Info1 has executed
700                             }
701                         }
702                     }
703                     
704                     // write back Dec configuration
705                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
706                     Cache_wait();            
707                     
708 #ifdef NON_CACHE_STATUS
709                     statusOp_read(&(temp8),
710                                   &(pAstCfg->xDec[z].decodeStatus.mode),
711                                   sizeof(Int8),
712                                   GATEMP_INDEX_DEC);
713                     // Re-initialize audio frame if decoder is disabled or
714                     // doesn't have a valid input
715                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
716                     {
717                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
718                     }
719 #else
720                     // Re-initialize audio frame if decoder is disabled or
721                     // doesn't have a valid input
722                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
723                     {
724                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
725                     }
726 #endif
728                     // send dec info complete message to master
729                     queId = MessageQ_getReplyQueue(pAspMsg);
730                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
731                     pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
732                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
733                     argIdx = 0; // set decErrno
734                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
735                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
736                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
737                     if (status != MessageQ_S_SUCCESS)
738                     {
739                         SW_BREAKPOINT;
740                     }
741                     
742                     break;
743                     
744                 case ASP_SLAVE_DEC_DECODE:
745                     gSlaveDecDecodeCnt++;
746                     
747                     argIdx = 0; // get decIdx
748                     z = *(Int32 *)&pAspMsg->buf[argIdx];
749                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
750                     // Get input associated w/ decoder
751                     zI = pP->inputsFromDecodes[z];
752                     
753                     // Reset AF samsiz
754                     resetAfSamsiz(z);
755                     
756                     // Invalidate Dec configuration
757                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
758                     Cache_wait();
759                     //TRACE_TERSE0("Dec:cache wb done");
760             
761                     dec = (DEC_Handle)alg[z];
762                     //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
764                     errno = 0;
765                     cbErrno = 0;
766                     if (dec->fxns->decode)
767                     {
768 #if 0 // debug, capture input buffer
769                         capIb(pAstCfg->xInp[z].pInpBuf);
770 #endif
771                         
772                         //
773                         // Execute decode
774                         //
775                         pfpBegin(PFP_ID_ASDT_2, pAsdtCfg->taskHandle);
776                         errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
777                         pfpEnd(PFP_ID_ASDT_2, PFP_FINISH_MEAS);
778                         if (errno < 0)
779                         {
780                             //SW_BREAKPOINT;
781                         }
782                         TRACE_TERSE0("Dec:decode done");
784                         // Get pointer to Dec Decode output audio frame
785                         pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;                           
786                         TRACE_TERSE2("Dec:pAfWrt=0x%04x, nSamples=%d", (IArg)pAfWrt, pAfWrt->data.nSamples);
787                         
788 #if 0 // debug, capture audio frame
789                         if (capAfWrite(pAfWrt, PAF_LEFT) != CAP_AF_SOK)
790                         {
791                             Log_info0("capAfWrite() error");
792                         }
793 #endif
795                         #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
796                         if (tempCap_frameCnt < CAP_FRAME_MAX)
797                         {
798                             tempCap_decSampleOut[tempCap_frameCnt] = pAfWrt->sampleCount;
799                             tempCap_frameCnt++;
800                         }
801                         #endif
803                         //
804                         // Execute Dec Decode1 Init-Sync if required
805                         //
806                         if (outIsDecDecode1Flag == 0)
807                         {
808                             //
809                             // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
810                             //  frameLength: changed to decodeControl.frameLength.
811                             //    Written by ASIT:decodeInit:getFrameLengthSourceSel().
812                             
813                             // Initialize decoder output circular buffer
814                             errno = cbInitDecWrite(pCbCtl, z, sourceSelect,
815                                 pAstCfg->xDec[z].decodeControl.frameLength, 
816                                 0, pAfWrt);
817                             if (errno)
818                             {
819                                 SW_BREAKPOINT; // debug
820                             }
821                             // debug
822                             cbLog(pCbCtl, z, 1, "cbInitSourceSel");
823                             
824                             // Perform Dec Decode1 Init-Sync
825                             //  - Set Dec Decode1 decoder stage flag
826                             outIsErrno = outIsWriteDecStageFlag(pOutIsCtl, z, 
827                                 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, 1);
828                             if (outIsErrno < 0)
829                             {
830                                 SW_BREAKPOINT; // debug
831                             }
833                             outIsDecDecode1Flag = 1;    // OutIS Dec Decode1 has executed
834                         }
836                         //
837                         // Write decoder output audio frame to circular buffer
838                         //
840                         // debug
841                         //pCb = &pAstCfg->xDecOpCb[z];
842                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);                                                
844                         //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);      // debug
845                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
846                         //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);    // debug
847                         if ((cbErrno < 0) && 
848                             (cbErrno != ASP_DECOP_CB_AF_WRITE_OVERFLOW) && 
849                             (cbErrno != ASP_DECOP_CB_PCM_WRITE_OVERFLOW))
850                         {
851                             gCbWrtAfErrCnt++;
852                             //SW_BREAKPOINT; // debug
853                         }
854                         
855                         // Handle circular buffer overflows
856                         if ((cbErrno == ASP_DECOP_CB_AF_WRITE_OVERFLOW) ||
857                             (cbErrno == ASP_DECOP_CB_PCM_WRITE_OVERFLOW))
858                         {
859                             gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
860                             if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
861                             {
862                                 gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
863                                 gDecOpCbWrtAfOvr = 0; // reset overflow count
864                                 
865                                 // Reset circular buffer
866                                 cbReset(pCbCtl, z);
867                                 gSlaveCbResetCnt++; // increment slave circular buffer reset count
868                                 Log_info0("ASDT:cbReset");
869                             }
870                         }
871                         else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
872                         {
873                             // No overflow detected.
874                             // update max overflow count,
875                             // reset overflow count
876                             
877                             if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
878                             {
879                                 gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
880                             }
881                             gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
882                             
883                             cbErrno = 0; // don't return error condition
884                         }
885                         //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);   // debug
886                         TRACE_TERSE0("Dec:cbWriteAf() complete");
887                         
888 #if 0 // (***) FL: shows timing of CB write
889                         // (***) debug // B9
890                         {
891                             static Uint8 toggleState = 0;
892                             if (toggleState == 0)
893                                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
894                             else
895                                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
896                             toggleState = ~(toggleState);
897                         }
898 #endif        
899                         
900                         // Log circular buffer control variables (debug)
901                         cbLog(pCbCtl, z, 1, "cbWriteAf");
902                     }
903                     
904                     // write back Dec configuration
905                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
906                     Cache_wait();
907                     
908 #ifdef NON_CACHE_STATUS
909                     statusOp_read(&(temp8),
910                                   &(pAstCfg->xDec[z].decodeStatus.mode),
911                                   sizeof(Int8),
912                                   GATEMP_INDEX_DEC);
913                     // Re-initialize audio frame if decoder is disabled or 
914                     // doesn't have a valid input 
915                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
916                     {
917                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
918                     }
919 #else
920                     // Re-initialize audio frame if decoder is disabled or
921                     // doesn't have a valid input
922                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
923                     {
924                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
925                     }
926 #endif
927                     // send dec info complete message to master
928                     queId = MessageQ_getReplyQueue(pAspMsg);
929                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
930                     pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
931                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
932                     argIdx = 0; // set decErrno
933                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
934                     argIdx += sizeof(Int32); // set cbErrno
935                     *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;                    
936                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
937                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
938                     if (status != MessageQ_S_SUCCESS)
939                     {
940                         SW_BREAKPOINT;
941                     }
942                     
943                     break;
944                     
945                 case ASP_SLAVE_DEC_DEACTIVATE:
946                     gSlaveDecDeactivateCnt++;
947                     
948                     argIdx = 0; // get decIdx
949                     z = *(Int32 *)&pAspMsg->buf[argIdx];
950                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
951                     
952                     if (alg[z]->fxns->algDeactivate)
953                     {
954                         alg[z]->fxns->algDeactivate(alg[z]);
955                     }
956                     
957                     // Stop writes to circular buffer
958                     cbErrno = cbWriteStop(pCbCtl, z);
959                     if (cbErrno < 0)
960                     {
961                         SW_BREAKPOINT; // debug
962                     }
963                     // Log circular buffer control variables (debug)
964                     cbLog(pCbCtl, z, 1, "cbWriteStop");
965                     
966                     // Reset Output Init-Sync decoder stage flags
967                     outIsErrno = outIsResetDecStageFlags(pOutIsCtl, z);
968                     if (outIsErrno < 0)
969                     {
970                         SW_BREAKPOINT; // debug
971                     }
972                     
973                     // send dec deactivate complete message to master
974                     queId = MessageQ_getReplyQueue(pAspMsg);
975                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
976                     pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
977                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
978                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
979                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
980                     if (status != MessageQ_S_SUCCESS)
981                     {
982                         SW_BREAKPOINT;
983                     }
984                     
985                     break;
986                     
987                 default:
988                     TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
989                     break;
990             }
991         }
992     }
993     
994     Log_info0("exit taskAsdpFxn()");   
998 // -----------------------------------------------------------------------------
999 // AST Initialization Function - Memory Allocation
1000 //
1001 //   Name:      PAF_AST_initPhaseMalloc
1002 //   Purpose:   Audio Stream Task Function for initialization of data pointers
1003 //              by allocation of memory.
1004 //   From:      audioStream1Task or equivalent
1005 //   Uses:      See code.
1006 //   States:    x
1007 //   Return:    0 on success.
1008 //              Source code line number on MEM_calloc failure.
1009 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1010 //              * State information as per parent.
1011 //              * Memory allocation errors.
1012 //
1013 Int
1014 PAF_ASDT_initPhaseMalloc(
1015     const PAF_ASDT_Params *pP, 
1016     const PAF_ASDT_Patchs *pQ, 
1017     PAF_ASDT_Config *pAsdtCfg
1020     PAF_AST_Config *pAstCfg;
1021     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1022     Int zMS;
1023     Error_Block eb;
1025     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1026     as = pAstCfg->as;
1027     zMS = pAstCfg->masterStr;
1028     
1029     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1031     // Initialize error block
1032     Error_init(&eb); 
1034     if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL,
1035         DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
1036     {
1037         TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1038         SW_BREAKPOINT;
1039         return __LINE__;
1040     }
1041     TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
1042             DECODEN * sizeof (PAF_AudioFrame),
1043             HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
1045     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1046     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1047     return 0;
1048 } //PAF_ASDT_initPhaseMalloc
1050 // -----------------------------------------------------------------------------
1051 // AST Initialization Function - Memory Initialization from Configuration
1052 //
1053 //   Name:      PAF_AST_initPhaseConfig
1054 //   Purpose:   Audio Stream Task Function for initialization of data values
1055 //              from parameters.
1056 //   From:      audioStream1Task or equivalent
1057 //   Uses:      See code.
1058 //   States:    x
1059 //   Return:    0 on success.
1060 //              Other as per initFrame0 and initFrame1.
1061 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1062 //              * State information as per parent.
1063 //
1065 Int
1066 PAF_ASDT_initPhaseConfig(
1067     const PAF_ASDT_Params *pP, 
1068     const PAF_ASDT_Patchs *pQ, 
1069     PAF_ASDT_Config *pAsdtCfg
1072     PAF_AST_Config *pAstCfg;
1073     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1074     Int zMS;
1075     Int z;
1077     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1078     as = pAstCfg->as;
1079     zMS = pAstCfg->masterStr;
1080     
1081     TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1083     // overwrite pointer to audio frame in framework decode control
1084     for (z=DECODE1; z < DECODEN; z++) 
1085     {
1086         //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
1087         //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1088         //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1089         pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
1090         pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
1091         pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
1092         pP->fxns->initFrame0(pP, pQ, pAsdtCfg, z);
1093     }
1095     return 0;
1096 }  //PAF_ASDT_initPhaseConfig
1098 // -----------------------------------------------------------------------------
1099 // AST Initialization Function - ACP Algorithm Instantiation
1100 //
1101 //   Name:      PAF_AST_initPhaseAcpAlg
1102 //   Purpose:   Audio Stream Task Function for initialization of ACP by
1103 //              instantiation of the algorithm.
1104 //   From:      audioStream1Task or equivalent
1105 //   Uses:      See code.
1106 //   States:    x
1107 //   Return:    0 on success.
1108 //              Source code line number on ACP Algorithm creation failure.
1109 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1110 //              * State information as per parent.
1111 //              * Memory allocation errors.
1112 //
1113 Int
1114 PAF_ASDT_initPhaseAcpAlg(
1115     const PAF_ASDT_Params *pP, 
1116     const PAF_ASDT_Patchs *pQ, 
1117     PAF_ASDT_Config *pAsdtCfg
1120     PAF_AST_Config *pAstCfg;
1121     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1122     Int z;                     /* input/encode/stream/decode/output counter */
1123     Int betaPrimeOffset;
1124     ACP_Handle acp;
1125     Int zMS;
1126     Int zS; //, zX;
1128     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1129     as = pAstCfg->as;
1130     zMS = pAstCfg->masterStr;    
1132     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1134     ACP_MDS_init();
1136     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1137     {
1138         TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
1139         return __LINE__;
1140     }
1141     pAsdtCfg->acp = acp;
1143     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
1144         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1146     for (z=DECODE1; z < DECODEN; z++) 
1147     {
1148         zS = pP->streamsFromDecodes[z];
1149         acp->fxns->attach(acp, ACP_SERIES_STD,
1150             STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1151             (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
1152         /* Ignore errors, not reported. */
1153     }
1155     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1157     return 0;
1158 } //PAF_AST_initPhaseAcpAlg
1160 // -----------------------------------------------------------------------------
1161 // AST Initialization Function - Common Memory and Algorithms
1162 //
1163 //   Name:      PAF_AST_initPhaseCommon
1164 //   Purpose:   Audio Stream Task Function for initialization of data pointers
1165 //              by allocation for common memory and by instantiation for
1166 //              algorithms.
1167 //   From:      audioStream1Task or equivalent
1168 //   Uses:      See code.
1169 //   States:    x
1170 //   Return:    0 on success.
1171 //              Source code line number on PAF_ALG_alloc failure.
1172 //              Source code line number on PAF_ALG_mallocMemory failure.
1173 //              Source code line number on Decode Chain initialization failure.
1174 //              Source code line number on ASP Chain initialization failure.
1175 //              Source code line number on Encode Chain initialization failure.
1176 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1177 //              * State information as per parent.
1178 //              * Memory allocation errors.
1179 //
1181 #include <pafsio_ialg.h>
1183 Int
1184 PAF_ASDT_initPhaseCommon(
1185     const PAF_ASDT_Params *pP, 
1186     const PAF_ASDT_Patchs *pQ, 
1187     PAF_ASDT_Config *pAsdtCfg
1190     PAF_AST_Config *pAstCfg;
1191     Int as;                         /* Audio Stream Number (1, 2, etc.) */
1192     Int z;                          /* stream counter */
1193     //Int g;                        /* gear */
1194     ACP_Handle acp;
1195     PAF_IALG_Config pafAlgConfig;
1196     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1197    
1198     acp = pAsdtCfg->acp; // get acp handle
1199     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1200     as = pAstCfg->as;
1201     
1202     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
1204     //
1205     // Determine memory needs and instantiate algorithms across audio streams
1206     //
1208     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
1209     PAF_ALG_setup(&pafAlgConfig, 
1210         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1211         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1212         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1213         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1214         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1215         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1216         HEAP_CLEAR);
1218     if (pP->fxns->headerPrint)
1219         pP->fxns->headerPrint();
1221     for (z=STREAM1; z < STREAMN; z++) 
1222     {
1223         //Int zD, zE, zX;
1224         Int zD, zX;
1226         TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
1228         //
1229         // Determine common memory needs of Decode Algorithms
1230         //
1231         PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
1233         zD = -1;
1234         for (zX = DECODE1; zX < DECODEN; zX++) 
1235         {
1236             if (pP->streamsFromDecodes[zX] == z) 
1237             {
1238                 zD = zX;
1239                 break;
1240             }
1241         }
1243         if (zD >= 0) 
1244         {
1245             TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
1246             if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z])) 
1247             {
1248                 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1249                 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1251                 SW_BREAKPOINT;
1252                 return __LINE__;
1253             }
1254             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1255             if(pP->fxns->allocPrint)
1256                 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1257         }
1259 #if 0 // FL: master
1260         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1261         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1262         if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z])) 
1263         {
1264             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1265             TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1266             SW_BREAKPOINT;
1267             return __LINE__;
1268         }
1269         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1270         if(pP->fxns->allocPrint)
1271             pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1272 #endif
1273         
1274     }
1275     {
1276         // Changes made to share scratch between zones
1277         // Assume maximum 3 zones and scratch common memory is at offset 0;
1278         int max=0;
1279         for (z=STREAM1; z < STREAMN; z++)
1280         {
1281             if (max<common[z][0].size)
1282                 max=common[z][0].size;
1283         }
1284         common[STREAM1][0].size=max;
1285         for (z=STREAM1+1; z < STREAMN; z++)
1286             common[z][0].size=0;
1287     }
1288     
1289     //
1290     // Provide common memory needs of Decode Algorithms
1291     //
1292     for (z=STREAM1; z < STREAMN; z++) 
1293     {
1294         //Int zD, zE, zX;
1295         Int zD, zX;
1297         zD = -1;        
1298         for (zX = DECODE1; zX < DECODEN; zX++) 
1299         {
1300            if (pP->streamsFromDecodes[zX] == z) 
1301            {
1302                zD = zX;
1303                break;
1304            }
1305         }
1307         TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1308         if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig)) 
1309         {
1310             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1311             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1312             SW_BREAKPOINT;
1313             return __LINE__;
1314         }
1315         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1316         // share zone0 scratch with all zones 
1317         common[z][0].base=common[0][0].base;
1318         if (pP->fxns->commonPrint)
1319                 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1321         //
1322         // Instantiate Decode Algorithms
1323         //
1324         if (zD >= 0) 
1325         {
1326             PAF_ASP_Chain *chain;
1327             TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1328             chain =
1329                 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1330                                    HEAP_INTERNAL, as+z, acp, &trace,
1331                                    decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1332             if (!chain) 
1333             {
1334                 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1335                 return __LINE__;
1336             }
1337         }
1339 #if 0 // FL: master
1340         pC->xStr[z].aspChain[0] = NULL;
1341         for (g=0; g < GEARS; g++) 
1342         {
1343             PAF_ASP_Chain *chain;
1344             TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1345             chain =
1346                 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1347                                    HEAP_INTERNAL, as+z, acp, &trace,
1348                                    aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1349             if (! chain) 
1350             {
1351                 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1352                 return __LINE__;
1353             }
1354             else
1355                 pC->xStr[z].aspChain[g] = chain;
1356         }
1357 #endif
1359     }
1360     TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1362     return 0;
1363 } //PAF_ASDT_initPhaseCommon
1365 // -----------------------------------------------------------------------------
1366 // AST Initialization Function - Algorithm Keys
1367 //
1368 //   Name:      PAF_AST_initPhaseAlgKey
1369 //   Purpose:   Audio Stream Task Function for initialization of data values
1370 //              from parameters for Algorithm Keys.
1371 //   From:      audioStream1Task or equivalent
1372 //   Uses:      See code.
1373 //   States:    x
1374 //   Return:    0.
1375 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1376 //              * State information as per parent.
1377 //
1378 // .............................................................................
1379 Int
1380 PAF_ASDT_initPhaseAlgKey(
1381     const PAF_ASDT_Params *pP, 
1382     const PAF_ASDT_Patchs *pQ, 
1383     PAF_ASDT_Config *pAsdtCfg
1386     PAF_AST_Config *pAstCfg;
1387     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1388     Int z;                      /* decode/encode counter */
1389     Int s;                      /* key number */
1390     PAF_ASP_Link *that;
1392     (void)as;  // clear warning.
1394     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1395     as = pAstCfg->as;
1396     
1397     TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1399     for (z=DECODE1; z < DECODEN; z++) 
1400     {
1401         for (s=0; s < pP->pDecAlgKey->length; s++) 
1402         {
1403             if ((pP->pDecAlgKey->code[s].full != 0)
1404                 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1405             {
1406                 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1407                     /* Cast in interface, for now --Kurt */
1408             }
1409             else
1410                 pAstCfg->xDec[z].decAlg[s] = NULL;
1411         }
1412     }
1414     return 0;
1415 } //PAF_AST_initPhaseAlgKey
1417 //   Purpose:   Audio Stream Decode Task Function for initialization of the Audio
1418 //              Frame(s) by memory allocation and loading of data pointers
1419 //              and values.
1420 Int
1421 PAF_ASDT_initFrame0(
1422     const PAF_ASDT_Params *pP, 
1423     const PAF_ASDT_Patchs *pQ, 
1424     PAF_ASDT_Config *pAsdtCfg, 
1425     Int z
1428     PAF_AST_Config *pAstCfg;
1429     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1430     Int aLen;
1431     Int aSize = sizeof(PAF_AudioData);
1432     Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1433     Int maxFrameLength = pP->maxFramelength;
1434     PAF_AudioData *aBuf=NULL;
1435     XDAS_UInt8 *metadataBuf;
1436     Error_Block    eb;
1437     PAF_AudioFrame *pAudioFrame;
1438     Int i;
1440     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1441     as = pAstCfg->as;
1443     pAudioFrame = &gpDecAudioFrame[z];
1444     if (pAudioFrame == NULL)
1445     {
1446         SW_BREAKPOINT;
1447     }
1448     
1449     // Initialize error block
1450     Error_init(&eb); 
1451     
1452     //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1453     //aLen = numchan[z] * maxFrameLength;
1454     aLen = numchan[z] * maxFrameLength + (maxFrameLength - FRAMELENGTH); /* Qin - need additional memory for starting offset
1455                                                                                   See line 1301 */
1457     //
1458     // Initialize audio frame elements directly
1459     //
1460     pAudioFrame->fxns = pP->pAudioFrameFunctions;
1461     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1462     pAudioFrame->data.nSamples = FRAMELENGTH;
1463     pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1464     pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1465     pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1467     //
1468     // Allocate memory for and initialize pointers to audio data buffers
1469     //
1470     //   The NUMCHANMASK is used to identify the channels for which data
1471     //   buffers can be allocated. Using this mask and switch statement
1472     //   rather than some other construct allows efficient code generation,
1473     //   providing just the code necessary (with significant savings).
1474     //
1475     if (pP->fxns->bufMemPrint)
1476     {
1477         pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1478     }
1480     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1481     
1482     if (aLen != 0)
1483     {
1484         if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1485         {
1486             TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1487             TRACE_TERSE2("  maxFrameLength: %d.  aLen*aSize: %d", maxFrameLength, aLen*aSize);
1488             SW_BREAKPOINT;
1489             return __LINE__;
1490         }
1491     }
1493     TRACE_TERSE3("  maxFrameLength: %d.  aLen*aSize: %d.  aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1495     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1496     if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1497     {
1498         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1499         TRACE_TERSE1("  bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1500         SW_BREAKPOINT;
1501         return __LINE__;
1502     }
1504     for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1505     {
1506         gDecAudioFrameChannelPointers[i] = NULL;
1507     }
1509     if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1)) 
1510     {
1511         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1512         return __LINE__;
1513     }
1514     else 
1515     {
1516         Int j = 0;
1517         TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1518         for (i=0; i<numchan[z]; i++)
1519         {
1520             Int8 chan = AFChanPtrMap[numchan[z]][i];
1521             if (chan != -1)
1522             {
1523                 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1524                 j++;
1525                 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1526                 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1527             }
1528         }
1529     }
1531     // Initialize original audio frame channel pointers
1532     for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++) 
1533     {
1534         if (gDecAudioFrameChannelPointers[i])
1535         {
1536             gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1537         }
1538     }
1540     //
1541     // Initialize meta data elements
1542     //
1543     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1544     pAudioFrame->numPrivateMetadata = 0;
1545     pAudioFrame->bsMetadata_offset = 0;
1546     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1547     pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1548     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1549     {
1550         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1551         pAudioFrame->pafPrivateMetadata[i].size = 0;
1552         pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1553     }
1555     return 0;
1556 } //PAF_ASDT_initFrame0
1558 // -----------------------------------------------------------------------------
1559 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1560 // AST Decoding Function              - Reinitialization of Audio Frame
1561 //
1562 //   Name:      PAF_ASOT_initFrame1
1563 //   Purpose:   Audio Stream Task Function for initialization or reinitiali-
1564 //              zation of the Audio Frame(s) by loading of data values of a
1565 //              time-varying nature.
1566 //   From:      audioStream1Task or equivalent
1567 //              AST Parameter Function -> decodeInfo
1568 //              AST Parameter Function -> decodeDecode
1569 //   Uses:      See code.
1570 //   States:    x
1571 //   Return:    0.
1572 //   Trace:     None.
1573 //
1574 Int
1575 PAF_ASDT_initFrame1(
1576     const PAF_ASDT_Params *pP, 
1577     const PAF_ASDT_Patchs *pQ, 
1578     PAF_ASDT_Config *pAsdtCfg, 
1579     Int z, 
1580     Int apply
1583     PAF_AudioFrame *pAudioFrame;
1585     //
1586     // Reinitialize audio frame elements:
1587     //
1588     //   Channel Configurations during sys init                 = Unknown
1589     //      "          "        during info or decode           = None
1590     //
1591     //   Sample Rate / Count    during sys init, info or decode = Unknown / 0
1592     //
1594     pAudioFrame = &gpDecAudioFrame[z];
1596     if (apply < 0) 
1597     {
1598         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1599         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1600     }
1601     else 
1602     {
1603         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1604         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1605     }
1607     if (apply < 1) 
1608     {
1609         pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1610         pAudioFrame->sampleCount = 0;
1611     }
1613     return 0;
1614 } //PAF_ASDT_initFrame1
1616 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1617 Int resetAf(
1618     const PAF_ASDT_Params *pP, 
1619     Int z, 
1620     Int sourceSelect
1623     PAF_AudioFrame *pAudioFrame;
1624     Int ch;
1625     Int i;
1627     // Get audio frame
1628     pAudioFrame = &gpDecAudioFrame[z];
1629     if (pAudioFrame == NULL)
1630     {
1631         SW_BREAKPOINT;
1632     }
1634     // Reinitialize audio frame elements
1635     pAudioFrame->sampleDecode = PAF_SOURCE_UNKNOWN;
1636     pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1637     pAudioFrame->sampleCount = 0;
1638     pAudioFrame->channelConfigurationRequest.full = PAF_CC_UNKNOWN;
1639     pAudioFrame->channelConfigurationStream.full = PAF_CC_UNKNOWN;
1640     
1641     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1642     switch (sourceSelect)
1643     {
1644         case PAF_SOURCE_PCM:
1645             pAudioFrame->data.nSamples = FRAMELENGTH;
1646             break;
1647         case PAF_SOURCE_AC3:
1648         case PAF_SOURCE_DDP:
1649             pAudioFrame->data.nSamples = 1536;
1650             break;
1651         case PAF_SOURCE_THD:
1652             pAudioFrame->data.nSamples = 5120; //QIN FIX ME
1653             break;
1654         case PAF_SOURCE_DTS:
1655         case PAF_SOURCE_DTSHD:
1656         case PAF_SOURCE_DTS12:
1657         case PAF_SOURCE_DTS13:
1658         case PAF_SOURCE_DTS14:
1659         case PAF_SOURCE_DTS16:
1660         case PAF_SOURCE_DTSALL:
1661             pAudioFrame->data.nSamples = 8192; // TODO: Need to set correct value, max Sample output
1662             break;
1663         default:  
1664             pAudioFrame->data.nSamples = FRAMELENGTH;
1665             break;
1666     }
1668     // Reset audio frame channel pointers
1669     for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
1670     {
1671         if (gDecAudioFrameChannelPointers[ch])
1672         {
1673             gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1674         }
1675     }
1676     
1677     // Reset audio frame meta data elements
1678     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1679     pAudioFrame->numPrivateMetadata = 0;
1680     pAudioFrame->bsMetadata_offset = 0;
1681     pAudioFrame->bsMetadata_type = PAF_bsMetadata_none;
1682     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1683     {
1684         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1685         pAudioFrame->pafPrivateMetadata[i].size = 0;
1686     }
1687     
1688     return 0;
1691 // Reset AF samsiz, invoked during DECODE
1692 Int resetAfSamsiz(
1693     Int z
1696     PAF_AudioFrame *pAudioFrame;
1697     Int ch;
1698     
1699     // Get audio frame
1700     pAudioFrame = &gpDecAudioFrame[z];
1701     if (pAudioFrame == NULL)
1702     {
1703         SW_BREAKPOINT;
1704     }
1705     
1706     // Clear samsiz for all channels - MID 208.
1707     for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
1708     {
1709         pAudioFrame->data.samsiz[ch] = 0;
1710     }
1712     return 0;
1715 // (***) FL: Check correct behavior for other decs, esp DTSHD & DXP
1716 // Check decoder sync using information in INFO audio frame
1717 static Int8 checkDecSync(
1718     PAF_AudioFrame *pAf
1721     if ((pAf->sampleDecode == PAF_SOURCE_THD) &&
1722         (pAf->sampleRate == PAF_SAMPLERATE_UNKNOWN))
1723     {
1724         return 0;
1725     }
1726     else
1727     {
1728         return 1;
1729     }