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