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