Build #38: remove GPIO debug
[processor-sdk/performance-audio-sr.git] / pasdk / test_arm / framework / audioStreamDecodeProc.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37  *  ======== 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 "audioStreamProc_common.h"
62 #include "audioStreamDecodeProc.h"
64 #include "statusOp_common.h"
67 // FL: debug
68 //#include "fwkSim.h"
69 #include "dbgCapAf.h"
70 #include "dbgDib.h"
73 //
74 // Decoder Definitions
75 //
76 #define decLinkInit pQ->i_decLinkInit
78 #define __TASK_NAME__  "TaskAsdp"
80 extern struct {
81     Int size;
82     IALG_Status *pStatus[512];
83 } IACP_STD_BETA_TABLE;
85 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
86 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
88 LINNO_DEFN(TaskAsdp); /* Line number macros */
89 ERRNO_DEFN(TaskAsdp); /* Error number macros */
91 // ASDT configuration
92 PAF_ASDT_Config gPAF_ASDT_config 
93 __attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
94     NULL,               // acp
95     {NULL, NULL},       // decOpCircBufCtl
96     &gPAF_AST_config    // ASIT/ASOT/ASDT shared configuration
97 };
99 PAF_AudioFrame *gpDecAudioFrame=NULL;
100 PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
101 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
102 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
104 // Overflow threshold before circular buffer reset and return error to Top-Level FSM
105 #define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
106 UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count, not including overflows
107 UInt32 gDecOpCbWrtAfOvr         =0; // decoder output circular buffer overflow count
108 UInt32 gMaxDecOpCbWrtAfOvr      =0; // max (consecutive) decoder output circular buffer overflow count
110 // Global debug counters */
111 UInt32 gSlaveStartErrCnt        =0;
112 UInt32 gSlaveStartCnt           =0;
113 UInt32 gSlaveSourceSelectCnt    =0;
114 UInt32 gSlaveExitCnt            =0;
115 UInt32 gSlaveDecExitCnt         =0;
116 UInt32 gSlaveDecControlCnt      =0;
117 UInt32 gSlaveDecActivateCnt     =0;
118 UInt32 gSlaveDecResetCnt        =0;
119 UInt32 gSlaveDecInfoCnt         =0;
120 UInt32 gSlaveDecDecodeCnt       =0;
121 UInt32 gSlaveDecDeactivateCnt   =0;
124 // FL: (***) debug
125 #include "evmc66x_gpio_dbg.h"
128 /*
129  *  ======== taskAsdpFxn ========
130  *  Audio Stream Decode Processing task function
131  */
132 Void taskAsdpFxn(
133 //    Int betaPrimeValue, // FL: revisit
134     const PAF_ASDT_Params *pP,
135     const PAF_ASDT_Patchs *pQ
138     PAF_ASDT_Config *pC;            /* Local configuration pointer */
139     PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
140     Int as;                         /* Audio Stream Number (1, 2, etc.) */
141     Int z;                          /* input/encode/stream/decode/output counter */
142     Int i;                          /* phase */
143     Int zMD, zMS;
144     Bool done;
145     Bool decDone;
146     ALG_Handle alg[DECODEN_MAX];
147     ASP_Slave_Cmd slaveCmd;
148     Int sourceSelect;
149     DEC_Handle dec;
150     IALG_Cmd decCtrlCmd;            // decoder control command
151     Int decCtrlRet;                 // decoder control return
152     Int errno;                      /* error number */
153     Int size;
154     Int argIdx;
155     // Decoder output circular buffer
156     PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
157     //PAF_AST_DecOpCircBuf *pCb;
158     PAF_AudioFrame *pAfWrt;
159     Int cbErrno;    
160     // Messaging
161     PAF_InpBufConfig *pIpBufConfig;
162     ASP_Msg *pAspMsg;
163     MessageQ_QueueId queId;
164     Int status;
165     Int zI;
166     Int bufEnd, wrapSize, currentBufSize, chunkSize;
167     Int8 temp8;
169     
170     Log_info0("Enter taskAsdpFxn()");
171     
172     //
173     // Audio Framework Parameters & Patch (*pP, *pQ):
174     //
175     if (!pP) 
176     {
177         TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
178         LINNO_RPRT(TaskAsdp, -1);
179         return;
180     }
182     if (!pQ) 
183     {
184         TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
185         LINNO_RPRT(TaskAsdp, -1);
186         return;
187     }    
189     //
190     // Audio Framework Configuration (*pC):
191     //
192     pC = &gPAF_ASDT_config;
193     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration 
194     pCbCtl = &pC->decOpCircBufCtl; // get pointer to circular buffer control
196     // wait for initialization message from master
197     do {
198         status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
199         //TRACE_TERSE1("Rx ASP message: status=%d", status);
200     //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
201     } while (status != MessageQ_S_SUCCESS);
202     if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
203         (pAspMsg->cmd != ASP_SLAVE_START))
204     {
205         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
206         SW_BREAKPOINT;
207     }
208     hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
209     gSlaveStartCnt++;
210     TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
212     // invalidate AST shared configuration
213     Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
214     // FL: no need to share this pointer, can be local
215     //Cache_inv(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
216     Cache_wait();
217     
218     // (***) FL: revisit
219     // invalidate Dec configuration for all Decoder zones
220     Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
221     Cache_wait();
223     // (***) FL: revisit
224     // invalidate Beta Table status pointers
225     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
226     Cache_wait();
228     /* Obtain Audio Stream Number (1, 2, etc.) */
229     as = pAstCfg->as;
230     TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
231     
232     //
233     // Initialize message log trace and line number reporting
234     //
235     for (z=STREAM1; z < STREAMN; z++)
236     {
237         TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
238     }
239     LINNO_RPRT(TaskAsdp, -1);
241     // Get decoder and stream index associated with the master input
242     zMD = pAstCfg->masterDec;
243     zMS = pAstCfg->masterStr;
245     // 
246     // Initialize per parameterized phases.
247     //   - Malloc: Memory Allocation
248     //   - Config: Configuration Initialization
249     //   - AcpAlg: ACP Algorithm Initialization and Local Attachment
250     //   - Common: Common Algorithm Initialization
251     //   - AlgKey: Dec/Enc chain to Array Initialization
252     //   - Unused: (available)
253     //   - Unused: (available)
254     //   - Unused: (available)
255     //
256     LINNO_RPRT(TaskAsdp, -2);
257     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
258     {
259         Int linno;
260         if (pP->fxns->initPhase[i])
261         {
262             if ((linno = pP->fxns->initPhase[i](pP, pQ, pC)))
263             {
264                 LINNO_RPRT(TaskAsdp, linno);
265                 return;
266             }
267         }
268         else 
269         {
270             TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
271         }
272         TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
273         LINNO_RPRT(TaskAsdp, -i-3);
274     }
275     
276     //
277     // End of Initialization -- final memory usage report.
278     //
279     if (pP->fxns->memStatusPrint)
280     {
281         pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
282     }
283     
284 #ifdef NON_CACHE_STATUS
285     //
286     // init Status structure Gate
287     //
288     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
289     {
290         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DEC);
291     }
292     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
293     {
294         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DDP);
295     }
296     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
297     {
298         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_PCM);
299     }
300     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
301     {
302         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_THD);
303     }
304 #endif
306     // (***) FL: revisit
307     // write back Status structure addresses for Beta Units initialized on Slave
308     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
309     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
310     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
311     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
312     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
313     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
314     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
315     Cache_wait();
316     
317     // (***) FL: revisit
318     // write back Status structures for Beta Units initialized on Slave
319    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
320     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
321     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
322     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
323     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
324     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
325     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
326     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
327     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
328     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
329     Cache_wait();
331     // (***) FL: revisit
332     // write back Dec configuration
333     Cache_wbInv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
334     Cache_wait();*/
335     
336     // Send initialization complete message to master
337     queId = MessageQ_getReplyQueue(pAspMsg);
338     pAspMsg->procId = hAspMsgSlave->slaveProcId;
339     pAspMsg->cmd = ASP_MASTER_START_DONE;
340     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
341     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
342     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
343     if (status != MessageQ_S_SUCCESS)
344     {
345         SW_BREAKPOINT;
346     }
348     done = FALSE;
349     while (done==FALSE)
350     {
351         // wait for source select message from master
352         do {
353             status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
354         } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
355         if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
356             (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
357         {
358             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
359             SW_BREAKPOINT;
360         }            
361         hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
362         sourceSelect = *(Int32 *)&pAspMsg->buf[0];
363         TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
364         TRACE_MSG1("sourceSelect=%d.", sourceSelect);
365         // send source select complete message to master
366         queId = MessageQ_getReplyQueue(pAspMsg);
367         pAspMsg->procId = hAspMsgSlave->slaveProcId;
368         pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
369         pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
370         gSlaveSourceSelectCnt++;
371         TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
372         MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
373         
374         for (z=DECODE1; z < DECODEN; z++)
375         {
376             alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
377         }
378         alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
380         // FL: debug, reset IB capture buffer
381         //capIbReset();
382         //Log_info0("capIbReset()");
383         // FL: debug, reset audio frame capture buffer
384         //capAfReset();
385         
386         decDone = FALSE;
387         while (decDone==FALSE)
388         {
389             // wait for received message from master
390             do {
391                 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
392             } while (status < 0);
393             if (pAspMsg->procId != hAspMsgSlave->masterProcId)
394             {
395                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
396                 SW_BREAKPOINT;
397             }
398             hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
399             slaveCmd = pAspMsg->cmd;
400             TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
402             switch (slaveCmd)
403             {
404                 case ASP_SLAVE_NULL:
405                 case ASP_SLAVE_START:
406                     gSlaveStartErrCnt++;
407                     TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
408                     
409                     break;
410                     
411                 case ASP_SLAVE_EXIT:
412                     gSlaveExitCnt++;
413                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
414                     
415                     decDone = TRUE;
416                     done = TRUE;
417                     break;
418                     
419                 case ASP_SLAVE_DEC_EXIT:
420                     gSlaveDecExitCnt++;
421                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
422                     
423                     // send dec exit complete message to master
424                     queId = MessageQ_getReplyQueue(pAspMsg);
425                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
426                     pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
427                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
428                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
429                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
430                     if (status != MessageQ_S_SUCCESS)
431                     {
432                         SW_BREAKPOINT;
433                     }
434                     
435                     decDone=TRUE;
436                     break;
437                     
438                 case ASP_SLAVE_DEC_CONTROL:
439                     gSlaveDecControlCnt++;
440                     // simulate dec control load
441                     //simLoad(DEC_CONTROL_LOAD);
442                     
443                     argIdx = 0; // get decIdx
444                     z = *(Int32 *)&pAspMsg->buf[argIdx];
445                     argIdx += sizeof(Int32);
446                     decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
447                     TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
448                     
449                     decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
451                     // send dec control complete message to master
452                     queId = MessageQ_getReplyQueue(pAspMsg);
453                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
454                     pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
455                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
456                     argIdx = 0; // set decCtrlRet
457                     *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
458                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
459                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
460                     if (status != MessageQ_S_SUCCESS)
461                     {
462                         SW_BREAKPOINT;
463                     }
465                     break;
466                     
467                 case ASP_SLAVE_DEC_ACTIVATE:
468                     gSlaveDecActivateCnt++;
469                     // simulate dec activate load
470                     //simLoad(DEC_ACTIVATE_LOAD);
471                     
472                     // (***) FL: revisit
473                     // invalidate Status structures for shared Beta Units
474                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
475                     //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
476                     /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
477                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
478                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
479                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
480                     Cache_wait();*/
481                     
482                     argIdx = 0; // get decIdx
483                     z = *(Int32 *)&pAspMsg->buf[argIdx];
484                     TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
485                     
486                     // invalidate Dec configuration
487                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
488                     Cache_wait();
489                     
490                     if (alg[z]->fxns->algActivate)
491                     {
492                         alg[z]->fxns->algActivate(alg[z]);
493                     }
495                     // Start writes to circular buffer
496                     //pCb = &pAstCfg->xDecOpCb[z];
497                     cbErrno = cbWriteStart(pCbCtl, z);
498                     if (cbErrno < 0)
499                     {
500                         SW_BREAKPOINT;
501                     }
502                     gCbWrtAfErrCnt=0;       // reset write circular buffer error count
503                     gDecOpCbWrtAfOvr=0;     // reset decoder output circular buffer overflow count
504                     gMaxDecOpCbWrtAfOvr=0;  // reset max decoder output circular buffer overflow count
505                     // FL: debug, log circular buffer control variables
506                     cbLog(pCbCtl, z, 1, "cbWriteStart");
507                     // Reset audio frame
508                     resetAf(pP, z, sourceSelect);
509                     
510                     // send dec activate complete message to master
511                     queId = MessageQ_getReplyQueue(pAspMsg);
512                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
513                     pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
514                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
515                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
516                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
517                     if (status != MessageQ_S_SUCCESS)
518                     {
519                         SW_BREAKPOINT;
520                     }
521                    
522                     break;
523                     
524                 case ASP_SLAVE_DEC_RESET:
525                     gSlaveDecResetCnt++;
526                     // simulate dec reset load
527                     //simLoad(DEC_RESET_LOAD);
528                     
529                     argIdx = 0; // get decIdx
530                     z = *(Int32 *)&pAspMsg->buf[argIdx];
531                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
532                     
533                     dec = (DEC_Handle)alg[z];
534                     errno = 0;
535                     if (dec->fxns->reset)
536                     {
537                         errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
538                     }
540                     // write back Dec configuration
541                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
542                     Cache_wait();            
544                     // (***) FL: revisit
545                     // write back Status structures for shared Beta Units
546                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
547                     //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
548                    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
549                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
550                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
551                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
552                     Cache_wait();*/
553                     
554                     // send dec reset complete message to master
555                     queId = MessageQ_getReplyQueue(pAspMsg);
556                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
557                     pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
558                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
559                     argIdx = 0; // set decErrno
560                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
561                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
562                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
563                     if (status != MessageQ_S_SUCCESS)
564                     {
565                         SW_BREAKPOINT;
566                     }
568                     break;
569                     
570                 case ASP_SLAVE_DEC_INFO:
571                     gSlaveDecInfoCnt++;
572                     // simulate dec info load
573                     //simLoad(DEC_INFO_LOAD);
574                     
575                     argIdx = 0; // get decIdx
576                     z = *(Int32 *)&pAspMsg->buf[argIdx];
577                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
578                     // Get input associated w/ decoder
579                     zI = pP->inputsFromDecodes[z];
581                     // (***) FL: revisit
582                     // invalidate Inp configuration
583                     Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
584                     Cache_wait();
585                     // invalidate input data
586                     pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
587                     size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
588                     if (sourceSelect == PAF_SOURCE_PCM)
589                     {
590                         size *= pIpBufConfig->stride;
591                     }
593                     bufEnd = (Int) pIpBufConfig->base.pVoid + pIpBufConfig->sizeofBuffer;
594                     currentBufSize = (bufEnd - (Int)pIpBufConfig->pntr.pSmInt);
595                     if (currentBufSize >= size)
596                     {
597                         chunkSize = size;
598                     }
599                     else
600                     {
601                         chunkSize = currentBufSize;
602                     }
603                     wrapSize = size - chunkSize;
604                     // invalidate input data
605                     Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
606                     // invalidate Dec configuration
607                     TRACE_MSG2("IBUF : pIpBufConfig->pntr.pSmInt: 0x%x and chunkSize: %d", (IArg)pIpBufConfig->pntr.pSmInt, chunkSize);
608                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
609                     // status for selected decoder should be invalidated
610                     Cache_wait();
612                     /* Circular buffer wrap condition*/
613                     //if(((Int) pIpBufConfig->head.pVoid + size)  > bufEnd)
614                     if(wrapSize > 0)
615                     {
616                         // invalidate input data
617                         Cache_inv((Ptr)pIpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
618                         TRACE_MSG2("IBUF : pIpBufConfig->base.pSmInt: 0x%x and wrapSize: %d", (IArg)pIpBufConfig->base.pSmInt, wrapSize);
619                         // status for selected decoder should be invalidated
620                         Cache_wait();
621                     }
622                     /* Circular buffer wrap condition */
624                     dec = (DEC_Handle)alg[z];
625                     errno = 0;
626                     if (dec->fxns->info)
627                     {
628                         errno = dec->fxns->info(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
629                     }
630                     
631                     // write back Dec configuration
632                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
633                     Cache_wait();            
634                     
635 #ifdef NON_CACHE_STATUS
636                     statusOp_read(&(temp8),
637                                   &(pAstCfg->xDec[z].decodeStatus.mode),
638                                   sizeof(Int8),
639                                   GATEMP_INDEX_DEC);
640                     // Re-initialize audio frame if decoder is disabled or
641                     // doesn't have a valid input
642                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
643                     {
644                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
645                     }
646 #else
647                     // Re-initialize audio frame if decoder is disabled or
648                     // doesn't have a valid input
649                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
650                     {
651                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
652                     }
653 #endif
655                     // send dec info complete message to master
656                     queId = MessageQ_getReplyQueue(pAspMsg);
657                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
658                     pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
659                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
660                     argIdx = 0; // set decErrno
661                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
662                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
663                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
664                     if (status != MessageQ_S_SUCCESS)
665                     {
666                         SW_BREAKPOINT;
667                     }
668                     
669                     break;
670                     
671                 case ASP_SLAVE_DEC_DECODE:
672                     gSlaveDecDecodeCnt++;
673                     // simulate dec info load
674                     //simLoad(DEC_DECODE_LOAD);
675                     
676                     argIdx = 0; // get decIdx
677                     z = *(Int32 *)&pAspMsg->buf[argIdx];
678                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
679                     // Get input associated w/ decoder
680                     zI = pP->inputsFromDecodes[z];
681                     
682                     // Reset AF samsiz
683                     resetAfSamsiz(z);
684                     
685                     // invalidate Dec configuration
686                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
687                     Cache_wait();
688                     //TRACE_TERSE0("Dec:cache wb done");
689             
690                     dec = (DEC_Handle)alg[z];
691                     //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
693                     errno = 0;
694                     cbErrno = 0;
695                     if (dec->fxns->decode)
696                     {
697                         // FL: debug, capture input buffer
698                         //capIb(pAstCfg->xInp[z].pInpBuf);
699                     
700                         errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
701                         if (errno < 0)
702                         {
703                             //SW_BREAKPOINT;
704                         }
705                         TRACE_TERSE0("Dec:decode done");
706                         
707                         // copy decoder output to decoder output circular buffers
708                         //pCb = &pAstCfg->xDecOpCb[z];
709                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
710                         
711                         pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
712                         TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
713                         //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
714                         
715                         // FL: debug, capture audio frame
716                         //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
717                         //{
718                         //    Log_info0("capAfWrite() error");
719                         //}                        
721                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
722                         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
723                         {
724                             gCbWrtAfErrCnt++;
725                             //SW_BREAKPOINT; // FL: debug
726                         }
727                         
728                         // Handle overflows
729                         if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
730                         {
731                             gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
732                             if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
733                             {
734                                 gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
735                                 gDecOpCbWrtAfOvr = 0; // reset overflow count
736                                 
737                                 // Reset circular buffer
738                                 cbReset(pCbCtl, z);
739                             }
740                         }
741                         else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
742                         {
743                             // No overflow detected.
744                             // update max overflow count,
745                             // reset overflow count
746                             
747                             if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
748                             {
749                                 gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
750                             }
751                             gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
752                             
753                             cbErrno = 0; // don't return error condition
754                         }
755                         TRACE_TERSE0("Dec:cbWriteAf() complete");
756                         
757 #if 0 // (***) FL: shows timing of CB write
758                         // (***) debug // B9
759                         {
760                             static Uint8 toggleState = 0;
761                             if (toggleState == 0)
762                                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
763                             else
764                                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
765                             toggleState = ~(toggleState);
766                         }
767 #endif        
768                         
769                         // FL: debug, log circular buffer control variables
770                         cbLog(pCbCtl, z, 1, "cbWriteAf");
771                     }
772                     
773                     // write back Dec configuration
774                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
775                     Cache_wait();
776                     
777 #ifdef NON_CACHE_STATUS
778                     statusOp_read(&(temp8),
779                                   &(pAstCfg->xDec[z].decodeStatus.mode),
780                                   sizeof(Int8),
781                                   GATEMP_INDEX_DEC);
782                     // Re-initialize audio frame if decoder is disabled or 
783                     // doesn't have a valid input 
784                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
785                     {
786                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
787                     }
788 #else
789                     // Re-initialize audio frame if decoder is disabled or
790                     // doesn't have a valid input
791                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
792                     {
793                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
794                     }
795 #endif
796                     // send dec info complete message to master
797                     queId = MessageQ_getReplyQueue(pAspMsg);
798                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
799                     pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
800                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
801                     argIdx = 0; // set decErrno
802                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
803                     argIdx += sizeof(Int32); // set cbErrno
804                     *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;                    
805                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
806                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
807                     if (status != MessageQ_S_SUCCESS)
808                     {
809                         SW_BREAKPOINT;
810                     }
811                     
812                     break;
813                     
814                 case ASP_SLAVE_DEC_DEACTIVATE:
815                     gSlaveDecDeactivateCnt++;
816                     // simulate dec info load
817                     //simLoad(DEC_DEACTIVATE_LOAD);
818                     
819                     argIdx = 0; // get decIdx
820                     z = *(Int32 *)&pAspMsg->buf[argIdx];
821                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
822                     
823                     if (alg[z]->fxns->algDeactivate)
824                     {
825                         alg[z]->fxns->algDeactivate(alg[z]);
826                     }
827                     
828                     // Stop writes to circular buffer
829                     //pCb = &pAstCfg->xDecOpCb[z];
830                     cbErrno = cbWriteStop(pCbCtl, z);
831                     if (cbErrno < 0)
832                     {
833                         SW_BREAKPOINT;
834                     }
835                     // FL: debug, log circular buffer control variables
836                     cbLog(pCbCtl, z, 1, "cbWriteStop");
837                     
838                     // send dec deactivate complete message to master
839                     queId = MessageQ_getReplyQueue(pAspMsg);
840                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
841                     pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
842                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
843                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
844                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
845                     if (status != MessageQ_S_SUCCESS)
846                     {
847                         SW_BREAKPOINT;
848                     }
849                     
850                     break;
851                     
852                 default:
853                     TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
854                     break;
855             }
856         }
857     }
858     
859     Log_info0("exit taskAsdpFxn()");   
863 // -----------------------------------------------------------------------------
864 // AST Initialization Function - Memory Allocation
865 //
866 //   Name:      PAF_AST_initPhaseMalloc
867 //   Purpose:   Audio Stream Task Function for initialization of data pointers
868 //              by allocation of memory.
869 //   From:      audioStream1Task or equivalent
870 //   Uses:      See code.
871 //   States:    x
872 //   Return:    0 on success.
873 //              Source code line number on MEM_calloc failure.
874 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
875 //              * State information as per parent.
876 //              * Memory allocation errors.
877 //
878 Int
879 PAF_ASDT_initPhaseMalloc(
880     const PAF_ASDT_Params *pP, 
881     const PAF_ASDT_Patchs *pQ, 
882     PAF_ASDT_Config *pC
885     PAF_AST_Config *pAstCfg;
886     Int as;                     /* Audio Stream Number (1, 2, etc.) */
887     Int zMS;
888     Error_Block eb;
890     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
891     as = pAstCfg->as;
892     zMS = pAstCfg->masterStr;
893     
894     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
896     // Initialize error block
897     Error_init(&eb); 
899 //    if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL1,
900     if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, //Qin - moved to external memory
901         DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
902     {
903         TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
904         SW_BREAKPOINT;
905         return __LINE__;
906     }
907     TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
908             DECODEN * sizeof (PAF_AudioFrame),
909             HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
911     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
912     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
913     return 0;
914 } //PAF_ASDT_initPhaseMalloc
916 // -----------------------------------------------------------------------------
917 // AST Initialization Function - Memory Initialization from Configuration
918 //
919 //   Name:      PAF_AST_initPhaseConfig
920 //   Purpose:   Audio Stream Task Function for initialization of data values
921 //              from parameters.
922 //   From:      audioStream1Task or equivalent
923 //   Uses:      See code.
924 //   States:    x
925 //   Return:    0 on success.
926 //              Other as per initFrame0 and initFrame1.
927 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
928 //              * State information as per parent.
929 //
931 Int
932 PAF_ASDT_initPhaseConfig(
933     const PAF_ASDT_Params *pP, 
934     const PAF_ASDT_Patchs *pQ, 
935     PAF_ASDT_Config *pC
938     PAF_AST_Config *pAstCfg;
939     Int as;                    /* Audio Stream Number (1, 2, etc.) */
940     Int zMS;
941     Int z;
943     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
944     as = pAstCfg->as;
945     zMS = pAstCfg->masterStr;
946     
947     TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
949     // overwrite pointer to audio frame in framework decode control
950     for (z=DECODE1; z < DECODEN; z++) 
951     {
952         //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
953         //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
954         //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
955         pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
956         pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
957         pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
958         pP->fxns->initFrame0(pP, pQ, pC, z);
959     }
961     return 0;
962 }  //PAF_ASDT_initPhaseConfig
964 // -----------------------------------------------------------------------------
965 // AST Initialization Function - ACP Algorithm Instantiation
966 //
967 //   Name:      PAF_AST_initPhaseAcpAlg
968 //   Purpose:   Audio Stream Task Function for initialization of ACP by
969 //              instantiation of the algorithm.
970 //   From:      audioStream1Task or equivalent
971 //   Uses:      See code.
972 //   States:    x
973 //   Return:    0 on success.
974 //              Source code line number on ACP Algorithm creation failure.
975 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
976 //              * State information as per parent.
977 //              * Memory allocation errors.
978 //
979 Int
980 PAF_ASDT_initPhaseAcpAlg(
981     const PAF_ASDT_Params *pP, 
982     const PAF_ASDT_Patchs *pQ, 
983     PAF_ASDT_Config *pC
986     PAF_AST_Config *pAstCfg;
987     Int as;                    /* Audio Stream Number (1, 2, etc.) */
988     Int z;                     /* input/encode/stream/decode/output counter */
989     Int betaPrimeOffset;
990     ACP_Handle acp;
991     Int zMS;
992     Int zS; //, zX;
994     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
995     as = pAstCfg->as;
996     zMS = pAstCfg->masterStr;    
998     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1000     ACP_MDS_init();
1002     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1003     {
1004         TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
1005         return __LINE__;
1006     }
1007     pC->acp = acp;
1009     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
1010         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1012     for (z=DECODE1; z < DECODEN; z++) 
1013     {
1014         zS = pP->streamsFromDecodes[z];
1015         acp->fxns->attach(acp, ACP_SERIES_STD,
1016             STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1017             (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
1018         /* Ignore errors, not reported. */
1019     }
1021     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1023     return 0;
1024 } //PAF_AST_initPhaseAcpAlg
1026 // -----------------------------------------------------------------------------
1027 // AST Initialization Function - Common Memory and Algorithms
1028 //
1029 //   Name:      PAF_AST_initPhaseCommon
1030 //   Purpose:   Audio Stream Task Function for initialization of data pointers
1031 //              by allocation for common memory and by instantiation for
1032 //              algorithms.
1033 //   From:      audioStream1Task or equivalent
1034 //   Uses:      See code.
1035 //   States:    x
1036 //   Return:    0 on success.
1037 //              Source code line number on PAF_ALG_alloc failure.
1038 //              Source code line number on PAF_ALG_mallocMemory failure.
1039 //              Source code line number on Decode Chain initialization failure.
1040 //              Source code line number on ASP Chain initialization failure.
1041 //              Source code line number on Encode Chain initialization failure.
1042 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1043 //              * State information as per parent.
1044 //              * Memory allocation errors.
1045 //
1047 #include <pafsio_ialg.h>
1049 Int
1050 PAF_ASDT_initPhaseCommon(
1051     const PAF_ASDT_Params *pP, 
1052     const PAF_ASDT_Patchs *pQ, 
1053     PAF_ASDT_Config *pC
1056     PAF_AST_Config *pAstCfg;
1057     Int as;                         /* Audio Stream Number (1, 2, etc.) */
1058     Int z;                          /* stream counter */
1059     //Int g;                        /* gear */
1060     ACP_Handle acp;
1061     PAF_IALG_Config pafAlgConfig;
1062     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1063    
1064     acp = pC->acp; // get acp handle
1065     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1066     as = pAstCfg->as;
1067     
1068     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
1070     //
1071     // Determine memory needs and instantiate algorithms across audio streams
1072     //
1074     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
1075     PAF_ALG_setup(&pafAlgConfig, 
1076         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1077         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1078         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1079         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1080         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1081         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1082         HEAP_CLEAR);
1084     if (pP->fxns->headerPrint)
1085         pP->fxns->headerPrint();
1087     for (z=STREAM1; z < STREAMN; z++) 
1088     {
1089         //Int zD, zE, zX;
1090         Int zD, zX;
1092         TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
1094         //
1095         // Determine common memory needs of Decode Algorithms
1096         //
1097         PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
1099         zD = -1;
1100         for (zX = DECODE1; zX < DECODEN; zX++) 
1101         {
1102             if (pP->streamsFromDecodes[zX] == z) 
1103             {
1104                 zD = zX;
1105                 break;
1106             }
1107         }
1109         if (zD >= 0) 
1110         {
1111             TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
1112             if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z])) 
1113             {
1114                 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1115                 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1117                 SW_BREAKPOINT;
1118                 return __LINE__;
1119             }
1120             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1121             if(pP->fxns->allocPrint)
1122                 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1123         }
1125 #if 0 // FL: master
1126         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1127         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1128         if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z])) 
1129         {
1130             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1131             TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1132             SW_BREAKPOINT;
1133             return __LINE__;
1134         }
1135         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1136         if(pP->fxns->allocPrint)
1137             pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1138 #endif
1139         
1140     }
1141     {
1142         // Changes made to share scratch between zones
1143         // Assume maximum 3 zones and scratch common memory is at offset 0;
1144         int max=0;
1145         for (z=STREAM1; z < STREAMN; z++)
1146         {
1147             if (max<common[z][0].size)
1148                 max=common[z][0].size;
1149         }
1150         common[STREAM1][0].size=max;
1151         for (z=STREAM1+1; z < STREAMN; z++)
1152             common[z][0].size=0;
1153     }
1154     
1155     //
1156     // Provide common memory needs of Decode Algorithms
1157     //
1158     for (z=STREAM1; z < STREAMN; z++) 
1159     {
1160         //Int zD, zE, zX;
1161         Int zD, zX;
1163         zD = -1;        
1164         for (zX = DECODE1; zX < DECODEN; zX++) 
1165         {
1166            if (pP->streamsFromDecodes[zX] == z) 
1167            {
1168                zD = zX;
1169                break;
1170            }
1171         }
1173         TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1174         if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig)) 
1175         {
1176             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1177             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1178             SW_BREAKPOINT;
1179             return __LINE__;
1180         }
1181         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1182         // share zone0 scratch with all zones 
1183         common[z][0].base=common[0][0].base;
1184         if (pP->fxns->commonPrint)
1185                 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1187         //
1188         // Instantiate Decode Algorithms
1189         //
1190         if (zD >= 0) 
1191         {
1192             PAF_ASP_Chain *chain;
1193             TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1194             chain =
1195                 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1196                                    HEAP_INTERNAL, as+z, acp, &trace,
1197                                    decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1198             if (!chain) 
1199             {
1200                 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1201                 return __LINE__;
1202             }
1203         }
1205 #if 0 // FL: master
1206         pC->xStr[z].aspChain[0] = NULL;
1207         for (g=0; g < GEARS; g++) 
1208         {
1209             PAF_ASP_Chain *chain;
1210             TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1211             chain =
1212                 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1213                                    HEAP_INTERNAL, as+z, acp, &trace,
1214                                    aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1215             if (! chain) 
1216             {
1217                 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1218                 return __LINE__;
1219             }
1220             else
1221                 pC->xStr[z].aspChain[g] = chain;
1222         }
1223 #endif
1225     }
1226     TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1228     return 0;
1229 } //PAF_ASDT_initPhaseCommon
1231 // -----------------------------------------------------------------------------
1232 // AST Initialization Function - Algorithm Keys
1233 //
1234 //   Name:      PAF_AST_initPhaseAlgKey
1235 //   Purpose:   Audio Stream Task Function for initialization of data values
1236 //              from parameters for Algorithm Keys.
1237 //   From:      audioStream1Task or equivalent
1238 //   Uses:      See code.
1239 //   States:    x
1240 //   Return:    0.
1241 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1242 //              * State information as per parent.
1243 //
1244 // .............................................................................
1245 Int
1246 PAF_ASDT_initPhaseAlgKey(
1247     const PAF_ASDT_Params *pP, 
1248     const PAF_ASDT_Patchs *pQ, 
1249     PAF_ASDT_Config *pC
1252     PAF_AST_Config *pAstCfg;
1253     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1254     Int z;                      /* decode/encode counter */
1255     Int s;                      /* key number */
1256     PAF_ASP_Link *that;
1258     (void)as;  // clear warning.
1260     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1261     as = pAstCfg->as;
1262     
1263     TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1265     for (z=DECODE1; z < DECODEN; z++) 
1266     {
1267         for (s=0; s < pP->pDecAlgKey->length; s++) 
1268         {
1269             if ((pP->pDecAlgKey->code[s].full != 0)
1270                 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1271             {
1272                 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1273                     /* Cast in interface, for now --Kurt */
1274             }
1275             else
1276                 pAstCfg->xDec[z].decAlg[s] = NULL;
1277         }
1278     }
1280     return 0;
1281 } //PAF_AST_initPhaseAlgKey
1283 //   Purpose:   Audio Stream Decode Task Function for initialization of the Audio
1284 //              Frame(s) by memory allocation and loading of data pointers
1285 //              and values.
1286 Int
1287 PAF_ASDT_initFrame0(
1288     const PAF_ASDT_Params *pP, 
1289     const PAF_ASDT_Patchs *pQ, 
1290     PAF_ASDT_Config *pC, 
1291     Int z
1294     PAF_AST_Config *pAstCfg;
1295     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1296     Int aLen;
1297     Int aSize = sizeof(PAF_AudioData);
1298     Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1299     Int maxFrameLength = pP->maxFramelength;
1300     PAF_AudioData *aBuf=NULL;
1301     XDAS_UInt8 *metadataBuf;
1302     Error_Block    eb;
1303     PAF_AudioFrame *pAudioFrame;
1304     Int i;
1306     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1307     as = pAstCfg->as;
1309     pAudioFrame = &gpDecAudioFrame[z];
1310     if (pAudioFrame == NULL)
1311     {
1312         SW_BREAKPOINT;
1313     }
1314     
1315     // Initialize error block
1316     Error_init(&eb); 
1317     
1318     //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1319     //aLen = numchan[z] * maxFrameLength;
1320     aLen = numchan[z] * maxFrameLength + (maxFrameLength - FRAMELENGTH); /* Qin - need additional memory for starting offset
1321                                                                                       See line 1301 */
1323     //
1324     // Initialize audio frame elements directly
1325     //
1326     pAudioFrame->fxns = pP->pAudioFrameFunctions;
1327     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1328     pAudioFrame->data.nSamples = FRAMELENGTH;
1329     pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1330     pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1331     pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1333     //
1334     // Allocate memory for and initialize pointers to audio data buffers
1335     //
1336     //   The NUMCHANMASK is used to identify the channels for which data
1337     //   buffers can be allocated. Using this mask and switch statement
1338     //   rather than some other construct allows efficient code generation,
1339     //   providing just the code necessary (with significant savings).
1340     //
1341     if (pP->fxns->bufMemPrint)
1342     {
1343         pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1344     }
1346     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1347     
1348     if (aLen != 0)
1349     {
1350         if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1351         {
1352             TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1353             TRACE_TERSE2("  maxFrameLength: %d.  aLen*aSize: %d", maxFrameLength, aLen*aSize);
1354             SW_BREAKPOINT;
1355             return __LINE__;
1356         }
1357     }
1359     TRACE_TERSE3("  maxFrameLength: %d.  aLen*aSize: %d.  aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1361     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1362     if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1363     {
1364         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1365         TRACE_TERSE1("  bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1366         SW_BREAKPOINT;
1367         return __LINE__;
1368     }
1370     for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1371     {
1372         gDecAudioFrameChannelPointers[i] = NULL;
1373     }
1375     if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1)) 
1376     {
1377         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1378         return __LINE__;
1379     }
1380     else 
1381     {
1382         Int j = 0;
1383         TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1384         for (i=0; i<numchan[z]; i++)
1385         {
1386             Int8 chan = AFChanPtrMap[numchan[z]][i];
1387             if (chan != -1)
1388             {
1389                 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1390                 j++;
1391                 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1392                 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1393             }
1394         }
1395     }
1397     // Initialize original audio frame channel pointers
1398     for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++) 
1399     {
1400         if (gDecAudioFrameChannelPointers[i])
1401         {
1402             gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1403         }
1404     }
1406     //
1407     // Initialize meta data elements
1408     //
1409     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1410     pAudioFrame->numPrivateMetadata = 0;
1411     pAudioFrame->bsMetadata_offset = 0;
1412     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1413     pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1414     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1415     {
1416         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1417         pAudioFrame->pafPrivateMetadata[i].size = 0;
1418         pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1419     }
1421     return 0;
1422 } //PAF_ASDT_initFrame0
1424 // -----------------------------------------------------------------------------
1425 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1426 // AST Decoding Function              - Reinitialization of Audio Frame
1427 //
1428 //   Name:      PAF_ASOT_initFrame1
1429 //   Purpose:   Audio Stream Task Function for initialization or reinitiali-
1430 //              zation of the Audio Frame(s) by loading of data values of a
1431 //              time-varying nature.
1432 //   From:      audioStream1Task or equivalent
1433 //              AST Parameter Function -> decodeInfo
1434 //              AST Parameter Function -> decodeDecode
1435 //   Uses:      See code.
1436 //   States:    x
1437 //   Return:    0.
1438 //   Trace:     None.
1439 //
1440 Int
1441 PAF_ASDT_initFrame1(
1442     const PAF_ASDT_Params *pP, 
1443     const PAF_ASDT_Patchs *pQ, 
1444     PAF_ASDT_Config *pC, 
1445     Int z, 
1446     Int apply
1449     PAF_AudioFrame *pAudioFrame;
1451     //
1452     // Reinitialize audio frame elements:
1453     //
1454     //   Channel Configurations during sys init                 = Unknown
1455     //      "          "        during info or decode           = None
1456     //
1457     //   Sample Rate / Count    during sys init, info or decode = Unknown / 0
1458     //
1460     pAudioFrame = &gpDecAudioFrame[z];
1462     if (apply < 0) 
1463     {
1464         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1465         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1466     }
1467     else 
1468     {
1469         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1470         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1471     }
1473     if (apply < 1) 
1474     {
1475         pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1476         pAudioFrame->sampleCount = 0;
1477     }
1479     return 0;
1480 } //PAF_ASDT_initFrame1
1482 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1483 Int resetAf(
1484     const PAF_ASDT_Params *pP, 
1485     Int z, 
1486     Int sourceSelect
1489     PAF_AudioFrame *pAudioFrame;
1490     Int ch;
1491     Int i;
1493     // Get audio frame
1494     pAudioFrame = &gpDecAudioFrame[z];
1495     if (pAudioFrame == NULL)
1496     {
1497         SW_BREAKPOINT;
1498     }
1500     // Reinitialize audio frame elements
1501     pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1502     pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1503     pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1504     pAudioFrame->sampleCount = 0;
1505     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1506     
1507     switch (sourceSelect)
1508     {
1509         case PAF_SOURCE_PCM:
1510             pAudioFrame->data.nSamples = FRAMELENGTH;
1511             break;
1512         case PAF_SOURCE_AC3:
1513         case PAF_SOURCE_DDP:
1514             pAudioFrame->data.nSamples = 1536;
1515             break;
1516         case PAF_SOURCE_THD:
1517             pAudioFrame->data.nSamples = 5120; //QIN FIX ME
1518             break;
1519         default:  
1520             pAudioFrame->data.nSamples = FRAMELENGTH;
1521             break;
1522     }
1524     // Reset audio frame channel pointers
1525     for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
1526     {
1527         if (gDecAudioFrameChannelPointers[ch])
1528         {
1529             gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1530         }
1531     }
1532     
1533     // Reset audio frame meta data elements
1534     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1535     pAudioFrame->numPrivateMetadata = 0;
1536     pAudioFrame->bsMetadata_offset = 0;
1537     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1538     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1539     {
1540         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1541         pAudioFrame->pafPrivateMetadata[i].size = 0;
1542     }
1543     
1544     return 0;
1547 // Reset AF samsiz, invoked during DECODE
1548 Int resetAfSamsiz(
1549     Int z
1552     PAF_AudioFrame *pAudioFrame;
1553     Int ch;
1554     
1555     // Get audio frame
1556     pAudioFrame = &gpDecAudioFrame[z];
1557     if (pAudioFrame == NULL)
1558     {
1559         SW_BREAKPOINT;
1560     }
1561     
1562     // Clear samsiz for all channels - MID 208.
1563     for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
1564     {
1565         pAudioFrame->data.samsiz[ch] = 0;
1566     }
1568     return 0;