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