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