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