[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 "paf_decOpCircBuf.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 LINNO_DEFN(TaskAsdp); /* Line number macros */
78 ERRNO_DEFN(TaskAsdp); /* Error number macros */
80 extern struct {
81 Int size;
82 IALG_Status *pStatus[512];
83 } IACP_STD_BETA_TABLE;
85 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
86 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
88 // Global debug counters */
89 extern Uint32 gTaskAsdpCnt; // debug counter for ASDP task
91 PAF_AudioFrame *gpDecAudioFrame=NULL;
92 PAF_AudioData *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
93 PAF_AudioSize gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
94 PAF_AudioData *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
96 // Debug counters
97 UInt32 gSlaveStartErrCnt =0;
98 UInt32 gSlaveStartCnt =0;
99 UInt32 gSlaveSourceSelectCnt =0;
100 UInt32 gSlaveExitCnt =0;
101 UInt32 gSlaveDecExitCnt =0;
102 UInt32 gSlaveDecControlCnt =0;
103 UInt32 gSlaveDecActivateCnt =0;
104 UInt32 gSlaveDecResetCnt =0;
105 UInt32 gSlaveDecInfoCnt =0;
106 UInt32 gSlaveDecDecodeCnt =0;
107 UInt32 gSlaveDecDeactivateCnt =0;
110 /*
111 * ======== taskAsdpFxn ========
112 * Audio Stream Decode Processing task function
113 */
114 Void taskAsdpFxn(
115 // Int betaPrimeValue, // FL: revisit
116 const PAF_AST_Params *pP,
117 const PAF_AST_Patchs *pQ
118 )
119 {
120 PAF_AST_Config *pC; /* Local configuration pointer */
121 Int as; /* Audio Stream Number (1, 2, etc.) */
122 Int z; /* input/encode/stream/decode/output counter */
123 Int i; /* phase */
124 Int zMD, zMS;
125 Bool done;
126 Bool decDone;
127 ALG_Handle alg[DECODEN_MAX];
128 ASP_Slave_Cmd slaveCmd;
129 Int sourceSelect;
130 DEC_Handle dec;
131 IALG_Cmd decCtrlCmd; // decoder control command
132 Int decCtrlRet; // decoder control return
133 Int errno; /* error number */
134 Int size;
135 Int argIdx;
136 // Decoder output circular buffer
137 PAF_AST_DecOpCircBuf *pCb;
138 PAF_AudioFrame *pAfWrt;
139 Int cbErrno;
140 // Messaging
141 PAF_InpBufConfig *pIpBufConfig;
142 ASP_Msg *pAspMsg;
143 MessageQ_QueueId queId;
144 Int status;
145 Int zI;
148 Log_info0("Enter taskAsdpFxn()");
150 //
151 // Audio Framework Parameters & Patch (*pP, *pQ):
152 //
153 if (!pP)
154 {
155 TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
156 LINNO_RPRT(TaskAsdp, -1);
157 return;
158 }
160 if (!pQ)
161 {
162 TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
163 LINNO_RPRT(TaskAsdp, -1);
164 return;
165 }
167 // wait for initialization message from master
168 do {
169 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
170 //TRACE_TERSE1("Rx ASP message: status=%d", status);
171 //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
172 } while (status != MessageQ_S_SUCCESS);
173 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
174 (pAspMsg->cmd != ASP_SLAVE_START))
175 {
176 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
177 SW_BREAKPOINT;
178 }
179 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
180 gSlaveStartCnt++;
181 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
183 Cache_inv(&gPAF_AST_config, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
184 // FL: no need to share this pointer, can be local
185 //Cache_inv(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
186 Cache_wait();
188 // (***) FL: revisit
189 // invalidate Dec configuration
190 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
191 Cache_wait();
193 // (***) FL: revisit
194 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
195 Cache_wait();
197 //
198 // Audio Framework Configuration (*pC):
199 //
200 pC = &gPAF_AST_config;
201 as = pC->as; // obtain audio stream number
202 TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
204 //
205 // Initialize message log trace and line number reporting
206 //
207 for (z=STREAM1; z < STREAMN; z++)
208 {
209 TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
210 }
211 LINNO_RPRT(TaskAsdp, -1);
213 // Get decoder and stream index associated with the master input
214 zMD = pC->masterDec;
215 zMS = pC->masterStr;
217 //
218 // Initialize per parameterized phases.
219 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
220 // - Common: Common Algorithm Initialization
221 // - AlgKey: Dec/Enc chain to Array Initialization
222 // - Unused: (available)
223 //
224 LINNO_RPRT(TaskAsdp, -2);
225 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
226 {
227 Int linno;
228 if (pP->fxns->initPhase[i])
229 {
230 if ((linno = pP->fxns->initPhase[i](pP, pQ, pC)))
231 {
232 LINNO_RPRT(TaskAsdp, linno);
233 return;
234 }
235 }
236 else
237 {
238 TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
239 }
240 TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
241 LINNO_RPRT(TaskAsdp, -i-3);
242 }
244 //
245 // End of Initialization -- final memory usage report.
246 //
247 if (pP->fxns->memStatusPrint)
248 {
249 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
250 }
252 // (***) FL: revisit
253 // write back Status structure addresses for Beta Units initialized on Slave
254 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
255 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
256 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
257 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
258 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
259 Cache_wait();
261 // (***) FL: revisit
262 // write back Status structures for Beta Units initialized on Slave
263 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
264 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
265 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
266 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
267 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
268 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
269 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
270 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
271 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
272 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
273 Cache_wait();
275 // (***) FL: revisit
276 // write back Dec configuration
277 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
278 Cache_wait();
280 // Send initialization complete message to master
281 queId = MessageQ_getReplyQueue(pAspMsg);
282 pAspMsg->procId = hAspMsgSlave->slaveProcId;
283 pAspMsg->cmd = ASP_MASTER_START_DONE;
284 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
285 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
286 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
287 if (status != MessageQ_S_SUCCESS)
288 {
289 SW_BREAKPOINT;
290 }
292 done = FALSE;
293 while (done==FALSE)
294 {
295 // wait for source select message from master
296 do {
297 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
298 } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
299 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
300 (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
301 {
302 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
303 SW_BREAKPOINT;
304 }
305 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
306 sourceSelect = *(Int32 *)&pAspMsg->buf[0];
307 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
308 TRACE_MSG1("sourceSelect=%d.", sourceSelect);
309 // send source select complete message to master
310 queId = MessageQ_getReplyQueue(pAspMsg);
311 pAspMsg->procId = hAspMsgSlave->slaveProcId;
312 pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
313 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
314 gSlaveSourceSelectCnt++;
315 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
316 MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
318 for (z=DECODE1; z < DECODEN; z++)
319 {
320 alg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
321 }
322 alg[zMD] = pC->xDec[zMD].decAlg[sourceSelect];
324 // FL: debug, reset IB capture buffer
325 //capIbReset();
326 //Log_info0("capIbReset()");
327 // FL: debug, reset audio frame capture buffer
328 //capAfReset();
330 decDone = FALSE;
331 while (decDone==FALSE)
332 {
333 // wait for received message from master
334 do {
335 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
336 } while (status < 0);
337 if (pAspMsg->procId != hAspMsgSlave->masterProcId)
338 {
339 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
340 SW_BREAKPOINT;
341 }
342 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
343 slaveCmd = pAspMsg->cmd;
344 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
346 switch (slaveCmd)
347 {
348 case ASP_SLAVE_NULL:
349 case ASP_SLAVE_START:
350 gSlaveStartErrCnt++;
351 TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
353 break;
355 case ASP_SLAVE_EXIT:
356 gSlaveExitCnt++;
357 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
359 decDone = TRUE;
360 done = TRUE;
361 break;
363 case ASP_SLAVE_DEC_EXIT:
364 gSlaveDecExitCnt++;
365 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
367 // send dec exit complete message to master
368 queId = MessageQ_getReplyQueue(pAspMsg);
369 pAspMsg->procId = hAspMsgSlave->slaveProcId;
370 pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
371 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
372 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
373 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
374 if (status != MessageQ_S_SUCCESS)
375 {
376 SW_BREAKPOINT;
377 }
379 decDone=TRUE;
380 break;
382 case ASP_SLAVE_DEC_CONTROL:
383 gSlaveDecControlCnt++;
384 // simulate dec control load
385 //simLoad(DEC_CONTROL_LOAD);
387 argIdx = 0; // get decIdx
388 z = *(Int32 *)&pAspMsg->buf[argIdx];
389 argIdx += sizeof(Int32);
390 decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
391 TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
393 decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
395 // send dec control complete message to master
396 queId = MessageQ_getReplyQueue(pAspMsg);
397 pAspMsg->procId = hAspMsgSlave->slaveProcId;
398 pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
399 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
400 argIdx = 0; // set decCtrlRet
401 *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
402 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
403 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
404 if (status != MessageQ_S_SUCCESS)
405 {
406 SW_BREAKPOINT;
407 }
409 break;
411 case ASP_SLAVE_DEC_ACTIVATE:
412 gSlaveDecActivateCnt++;
413 // simulate dec activate load
414 //simLoad(DEC_ACTIVATE_LOAD);
416 // (***) FL: revisit
417 // invalidate Status structures for shared Beta Units
418 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
419 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
420 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
421 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
422 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
423 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
424 Cache_wait();
426 argIdx = 0; // get decIdx
427 z = *(Int32 *)&pAspMsg->buf[argIdx];
428 TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
430 // invalidate Dec configuration
431 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
432 Cache_wait();
434 if (alg[z]->fxns->algActivate)
435 {
436 alg[z]->fxns->algActivate(alg[z]);
437 }
439 // Start writes to circular buffer
440 pCb = &pC->xDecOpCb[z];
441 cbErrno = cbWriteStart(pCb);
442 if (cbErrno < 0)
443 {
444 SW_BREAKPOINT;
445 }
446 // FL: debug, log circular buffer control variables
447 cbLog(pCb, 1, "cbWriteStart");
448 // Reset audio frame
449 resetAf(pP, z, sourceSelect);
451 // send dec activate complete message to master
452 queId = MessageQ_getReplyQueue(pAspMsg);
453 pAspMsg->procId = hAspMsgSlave->slaveProcId;
454 pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
455 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
456 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
457 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
458 if (status != MessageQ_S_SUCCESS)
459 {
460 SW_BREAKPOINT;
461 }
463 break;
465 case ASP_SLAVE_DEC_RESET:
466 gSlaveDecResetCnt++;
467 // simulate dec reset load
468 //simLoad(DEC_RESET_LOAD);
470 argIdx = 0; // get decIdx
471 z = *(Int32 *)&pAspMsg->buf[argIdx];
472 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
474 dec = (DEC_Handle)alg[z];
475 errno = 0;
476 if (dec->fxns->reset)
477 {
478 errno = dec->fxns->reset(dec, NULL, &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus);
479 }
481 // write back Dec configuration
482 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
483 Cache_wait();
485 // (***) FL: revisit
486 // write back Status structures for shared Beta Units
487 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
488 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
489 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
490 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
491 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
492 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
493 Cache_wait();
495 // send dec reset complete message to master
496 queId = MessageQ_getReplyQueue(pAspMsg);
497 pAspMsg->procId = hAspMsgSlave->slaveProcId;
498 pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
499 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
500 argIdx = 0; // set decErrno
501 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
502 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
503 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
504 if (status != MessageQ_S_SUCCESS)
505 {
506 SW_BREAKPOINT;
507 }
509 break;
511 case ASP_SLAVE_DEC_INFO:
512 gSlaveDecInfoCnt++;
513 // simulate dec info load
514 //simLoad(DEC_INFO_LOAD);
516 argIdx = 0; // get decIdx
517 z = *(Int32 *)&pAspMsg->buf[argIdx];
518 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
519 // Get input associated w/ decoder
520 zI = pP->inputsFromDecodes[z];
522 // (***) FL: revisit
523 // invalidate Inp configuration
524 Cache_inv(&gPAF_AST_config.xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
525 // invalidate input data
526 pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
527 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
528 if (sourceSelect == PAF_SOURCE_PCM)
529 {
530 size *= pIpBufConfig->stride;
531 }
532 Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
533 // invalidate Dec configuration
534 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
535 // status for selected decoder should be invalidated
536 Cache_wait();
538 dec = (DEC_Handle)alg[z];
539 errno = 0;
540 if (dec->fxns->info)
541 {
542 errno = dec->fxns->info(dec, NULL, &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus);
543 }
545 // write back Dec configuration
546 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
547 Cache_wait();
549 // Re-initialize audio frame if decoder is disabled or
550 // doesn't have a valid input
551 if (!pC->xDec[z].decodeStatus.mode || !pC->xInp[zI].hRxSio)
552 {
553 pP->fxns->initFrame1(pP, pQ, pC, z, 0);
554 }
556 // send dec info complete message to master
557 queId = MessageQ_getReplyQueue(pAspMsg);
558 pAspMsg->procId = hAspMsgSlave->slaveProcId;
559 pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
560 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
561 argIdx = 0; // set decErrno
562 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
563 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
564 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
565 if (status != MessageQ_S_SUCCESS)
566 {
567 SW_BREAKPOINT;
568 }
570 break;
572 case ASP_SLAVE_DEC_DECODE:
573 gSlaveDecDecodeCnt++;
574 // simulate dec info load
575 //simLoad(DEC_DECODE_LOAD);
577 argIdx = 0; // get decIdx
578 z = *(Int32 *)&pAspMsg->buf[argIdx];
579 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
580 // Get input associated w/ decoder
581 zI = pP->inputsFromDecodes[z];
583 // Reset AF samsiz
584 resetAfSamsiz(z);
586 // invalidate Dec configuration
587 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
588 Cache_wait();
589 //TRACE_TERSE0("Dec:cache wb done");
591 dec = (DEC_Handle)alg[z];
592 //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
594 errno = 0;
595 cbErrno = 0;
596 if (dec->fxns->decode)
597 {
598 // FL: debug, capture input buffer
599 //capIb(pC->xInp[z].pInpBuf);
601 errno = dec->fxns->decode(dec, NULL, &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct);
602 if (errno < 0)
603 {
604 SW_BREAKPOINT;
605 }
606 //TRACE_TERSE0("Dec:decode done");
608 // copy decoder output to decoder output circular buffers
609 pCb = &pC->xDecOpCb[z];
610 //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
612 pAfWrt = pC->xDec[z].decodeOutStruct.pAudioFrame;
613 //TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
614 //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
616 // FL: debug, capture audio frame
617 //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
618 //{
619 // Log_info0("capAfWrite() error");
620 //}
622 cbErrno = cbWriteAf(pCb, pAfWrt);
623 if (cbErrno < 0)
624 {
625 SW_BREAKPOINT;
626 }
627 //TRACE_TERSE0("Dec:cbWriteAf() complete");
629 // FL: debug, log circular buffer control variables
630 cbLog(pCb, 1, "cbWriteAf");
631 }
633 // write back Dec configuration
634 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
635 Cache_wait();
637 // Re-initialize audio frame if decoder is disabled or
638 // doesn't have a valid input
639 if (!pC->xDec[z].decodeStatus.mode || !pC->xInp[zI].hRxSio)
640 {
641 pP->fxns->initFrame1(pP, pQ, pC, z, 0);
642 }
644 // send dec info complete message to master
645 queId = MessageQ_getReplyQueue(pAspMsg);
646 pAspMsg->procId = hAspMsgSlave->slaveProcId;
647 pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
648 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
649 argIdx = 0; // set decErrno
650 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
651 argIdx += sizeof(Int32); // set cbErrno
652 *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;
653 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
654 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
655 if (status != MessageQ_S_SUCCESS)
656 {
657 SW_BREAKPOINT;
658 }
660 break;
662 case ASP_SLAVE_DEC_DEACTIVATE:
663 gSlaveDecDeactivateCnt++;
664 // simulate dec info load
665 //simLoad(DEC_DEACTIVATE_LOAD);
667 argIdx = 0; // get decIdx
668 z = *(Int32 *)&pAspMsg->buf[argIdx];
669 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
671 if (alg[z]->fxns->algDeactivate)
672 {
673 alg[z]->fxns->algDeactivate(alg[z]);
674 }
676 // Stop writes to circular buffer
677 pCb = &pC->xDecOpCb[z];
678 cbErrno = cbWriteStop(pCb);
679 if (cbErrno < 0)
680 {
681 SW_BREAKPOINT;
682 }
683 // FL: debug, log circular buffer control variables
684 cbLog(pCb, 1, "cbWriteStop");
686 // send dec deactivate complete message to master
687 queId = MessageQ_getReplyQueue(pAspMsg);
688 pAspMsg->procId = hAspMsgSlave->slaveProcId;
689 pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
690 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
691 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
692 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
693 if (status != MessageQ_S_SUCCESS)
694 {
695 SW_BREAKPOINT;
696 }
698 break;
700 default:
701 TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
702 break;
703 }
704 }
705 }
707 Log_info0("exit taskAsdpFxn()");
708 }
711 // -----------------------------------------------------------------------------
712 // AST Initialization Function - Memory Allocation
713 //
714 // Name: PAF_AST_initPhaseMalloc
715 // Purpose: Audio Stream Task Function for initialization of data pointers
716 // by allocation of memory.
717 // From: audioStream1Task or equivalent
718 // Uses: See code.
719 // States: x
720 // Return: 0 on success.
721 // Source code line number on MEM_calloc failure.
722 // Trace: Message Log "trace" in Debug Project Configuration reports:
723 // * State information as per parent.
724 // * Memory allocation errors.
725 //
726 Int
727 PAF_ASDT_initPhaseMalloc(
728 const PAF_AST_Params *pP,
729 const PAF_AST_Patchs *pQ,
730 PAF_AST_Config *pC
731 )
732 {
733 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
734 Int zMS = pC->masterStr;
735 Error_Block eb;
737 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
739 // Initialize error block
740 Error_init(&eb);
742 if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL1,
743 DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
744 {
745 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
746 SW_BREAKPOINT;
747 return __LINE__;
748 }
749 TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
750 DECODEN * sizeof (PAF_AudioFrame),
751 HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
753 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
754 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
755 return 0;
756 } //PAF_ASDT_initPhaseMalloc
758 // -----------------------------------------------------------------------------
759 // AST Initialization Function - Memory Initialization from Configuration
760 //
761 // Name: PAF_AST_initPhaseConfig
762 // Purpose: Audio Stream Task Function for initialization of data values
763 // from parameters.
764 // From: audioStream1Task or equivalent
765 // Uses: See code.
766 // States: x
767 // Return: 0 on success.
768 // Other as per initFrame0 and initFrame1.
769 // Trace: Message Log "trace" in Debug Project Configuration reports:
770 // * State information as per parent.
771 //
773 Int
774 PAF_ASDT_initPhaseConfig(
775 const PAF_AST_Params *pP,
776 const PAF_AST_Patchs *pQ,
777 PAF_AST_Config *pC
778 )
779 {
780 Int z;
782 // overwrite pointer to audio frame in framework decode control
783 for (z=DECODE1; z < DECODEN; z++)
784 {
785 //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
786 //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
787 //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
788 pC->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
789 pC->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
790 pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
791 pP->fxns->initFrame0(pP, pQ, pC, z);
792 }
794 return 0;
795 } //PAF_ASDT_initPhaseConfig
797 // -----------------------------------------------------------------------------
798 // AST Initialization Function - ACP Algorithm Instantiation
799 //
800 // Name: PAF_AST_initPhaseAcpAlg
801 // Purpose: Audio Stream Task Function for initialization of ACP by
802 // instantiation of the algorithm.
803 // From: audioStream1Task or equivalent
804 // Uses: See code.
805 // States: x
806 // Return: 0 on success.
807 // Source code line number on ACP Algorithm creation failure.
808 // Trace: Message Log "trace" in Debug Project Configuration reports:
809 // * State information as per parent.
810 // * Memory allocation errors.
811 //
812 Int
813 PAF_ASDT_initPhaseAcpAlg(
814 const PAF_AST_Params *pP,
815 const PAF_AST_Patchs *pQ,
816 PAF_AST_Config *pC
817 )
818 {
819 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
820 Int z; /* input/encode/stream/decode/output */
821 /* counter */
822 Int betaPrimeOffset;
823 ACP_Handle acp;
824 Int zMS = pC->masterStr;
825 Int zS; //, zX;
827 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
829 ACP_MDS_init();
831 if (!(acp = (ACP_Handle )ACP_MDS_create (NULL)))
832 {
833 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
834 return __LINE__;
835 }
836 pC->acpSlave = acp;
838 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
839 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
841 #if 0 // FL: master
842 for (z=INPUT1; z < INPUTN; z++)
843 {
844 zS = z;
845 for (zX = DECODE1; zX < DECODEN; zX++)
846 {
847 if (pP->inputsFromDecodes[zX] == z)
848 {
849 zS = pP->streamsFromDecodes[zX];
850 break;
851 }
852 }
853 acp->fxns->attach(acp, ACP_SERIES_STD,
854 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
855 (IALG_Status *)&pC->xInp[z].inpBufStatus);
856 /* Ignore errors, not reported. */
857 }
858 #endif
860 for (z=DECODE1; z < DECODEN; z++)
861 {
862 zS = pP->streamsFromDecodes[z];
863 acp->fxns->attach(acp, ACP_SERIES_STD,
864 STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
865 (IALG_Status *)&pC->xDec[z].decodeStatus);
866 /* Ignore errors, not reported. */
867 }
869 #if 0 // FL: master
870 for (z=ENCODE1; z < ENCODEN; z++)
871 {
872 zS = pP->streamsFromEncodes[z];
873 acp->fxns->attach(acp, ACP_SERIES_STD,
874 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
875 (IALG_Status *)&pC->xEnc[z].encodeStatus);
876 acp->fxns->attach(acp, ACP_SERIES_STD,
877 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
878 (IALG_Status *)&pC->xEnc[z].volumeStatus);
879 /* Ignore errors, not reported. */
880 }
881 #endif
883 #if 0 // FL: master
884 for (z=OUTPUT1; z < OUTPUTN; z++)
885 {
886 zS = z;
887 for (zX = ENCODE1; zX < ENCODEN; zX++)
888 {
889 if (pP->outputsFromEncodes[zX] == z)
890 {
891 zS = pP->streamsFromEncodes[zX];
892 break;
893 }
894 }
895 acp->fxns->attach(acp, ACP_SERIES_STD,
896 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
897 (IALG_Status *)&pC->xOut[z].outBufStatus);
898 /* Ignore errors, not reported. */
899 }
900 #endif
902 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
904 return 0;
905 } //PAF_AST_initPhaseAcpAlg
907 // -----------------------------------------------------------------------------
908 // AST Initialization Function - Common Memory and Algorithms
909 //
910 // Name: PAF_AST_initPhaseCommon
911 // Purpose: Audio Stream Task Function for initialization of data pointers
912 // by allocation for common memory and by instantiation for
913 // algorithms.
914 // From: audioStream1Task or equivalent
915 // Uses: See code.
916 // States: x
917 // Return: 0 on success.
918 // Source code line number on PAF_ALG_alloc failure.
919 // Source code line number on PAF_ALG_mallocMemory failure.
920 // Source code line number on Decode Chain initialization failure.
921 // Source code line number on ASP Chain initialization failure.
922 // Source code line number on Encode Chain initialization failure.
923 // Trace: Message Log "trace" in Debug Project Configuration reports:
924 // * State information as per parent.
925 // * Memory allocation errors.
926 //
928 #include <pafsio_ialg.h>
930 Int
931 PAF_ASDT_initPhaseCommon(
932 const PAF_AST_Params *pP,
933 const PAF_AST_Patchs *pQ,
934 PAF_AST_Config *pC
935 )
936 {
937 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
938 Int z; /* stream counter */
939 //Int g; /* gear */
940 ACP_Handle acp = pC->acpSlave;
941 PAF_IALG_Config pafAlgConfig;
942 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
944 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Algorithms");
946 //
947 // Determine memory needs and instantiate algorithms across audio streams
948 //
950 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
951 PAF_ALG_setup(&pafAlgConfig,
952 HEAP_ID_INTERNAL, HEAP_INTERNAL,
953 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
954 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
955 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
956 HEAP_CLEAR);
958 if (pP->fxns->headerPrint)
959 pP->fxns->headerPrint();
961 for (z=STREAM1; z < STREAMN; z++)
962 {
963 //Int zD, zE, zX;
964 Int zD, zX;
966 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
968 //
969 // Determine common memory needs of Decode Algorithms
970 //
971 PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
973 zD = -1;
974 for (zX = DECODE1; zX < DECODEN; zX++)
975 {
976 if (pP->streamsFromDecodes[zX] == z)
977 {
978 zD = zX;
979 break;
980 }
981 }
983 #if 0 // FL: master
984 zE = -1;
985 for (zX = ENCODE1; zX < ENCODEN; zX++)
986 {
987 if (pP->streamsFromEncodes[zX] == z)
988 {
989 zE = zX;
990 break;
991 }
992 }
993 #endif
995 if (zD >= 0)
996 {
997 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
998 if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z]))
999 {
1000 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1001 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1003 SW_BREAKPOINT;
1004 return __LINE__;
1005 }
1006 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1007 if(pP->fxns->allocPrint)
1008 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1009 }
1011 #if 0 // FL: master
1012 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1013 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1014 if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z]))
1015 {
1016 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1017 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1018 SW_BREAKPOINT;
1019 return __LINE__;
1020 }
1021 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1022 if(pP->fxns->allocPrint)
1023 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1024 #endif
1026 #if 0 // FL: master
1027 if (zE >= 0)
1028 {
1029 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC/ for encoder common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1030 if (PAF_ALG_ALLOC (encLinkInit[zE-ENCODE1], common[z]))
1031 {
1032 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed",
1033 as+z, (IArg)__FUNCTION__, __LINE__);
1034 SW_BREAKPOINT;
1035 return __LINE__;
1036 }
1037 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1038 if(pP->fxns->allocPrint)
1039 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
1040 }
1041 #endif
1043 //
1044 // Determine common memory needs of Logical IO drivers
1045 //
1047 #if 0 // FL: master
1048 // really need to loop over all inputs for this stream using the tables
1049 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1050 // patch, and not needed for FS11, since there is only one input.
1051 if (INPUT1 <= z && z < INPUTN)
1052 {
1053 TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: alloc inpLinkInit common[%d]", as+z, __LINE__, z);
1054 if (PAF_ALG_ALLOC (inpLinkInit[z-INPUT1], common[z]))
1055 {
1056 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1057 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1058 SW_BREAKPOINT;
1059 return __LINE__;
1060 }
1061 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1062 if(pP->fxns->allocPrint)
1063 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1064 }
1065 #endif
1067 #if 0 // FL: master
1068 if (OUTPUT1 <= z && z < OUTPUTN)
1069 {
1070 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC outLinkInit common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1071 if (PAF_ALG_ALLOC (outLinkInit[z-OUTPUT1], common[z]))
1072 {
1073 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1074 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1075 SW_BREAKPOINT;
1076 return __LINE__;
1077 }
1078 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1079 if(pP->fxns->allocPrint)
1080 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
1081 }
1082 #endif
1083 }
1084 {
1085 // Changes made to share scratch between zones
1086 // Assume maximum 3 zones and scratch common memory is at offset 0;
1087 int max=0;
1088 for (z=STREAM1; z < STREAMN; z++)
1089 {
1090 if (max<common[z][0].size)
1091 max=common[z][0].size;
1092 }
1093 common[STREAM1][0].size=max;
1094 for (z=STREAM1+1; z < STREAMN; z++)
1095 common[z][0].size=0;
1096 }
1098 //
1099 // Provide common memory needs of Decode Algorithms
1100 //
1101 for (z=STREAM1; z < STREAMN; z++)
1102 {
1103 //Int zD, zE, zX;
1104 Int zD, zX;
1106 zD = -1;
1107 for (zX = DECODE1; zX < DECODEN; zX++)
1108 {
1109 if (pP->streamsFromDecodes[zX] == z)
1110 {
1111 zD = zX;
1112 break;
1113 }
1114 }
1116 #if 0 // FL: master
1117 zE = -1;
1118 for (zX = ENCODE1; zX < ENCODEN; zX++)
1119 {
1120 if (pP->streamsFromEncodes[zX] == z)
1121 {
1122 zE = zX;
1123 break;
1124 }
1125 }
1126 #endif
1128 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1129 if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig))
1130 {
1131 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1132 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1133 SW_BREAKPOINT;
1134 return __LINE__;
1135 }
1136 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1137 // share zone0 scratch with all zones
1138 common[z][0].base=common[0][0].base;
1139 if (pP->fxns->commonPrint)
1140 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1142 //
1143 // Instantiate Decode Algorithms
1144 //
1145 if (zD >= 0)
1146 {
1147 PAF_ASP_Chain *chain;
1148 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1149 chain =
1150 PAF_ASP_chainInit (&pC->xDec[zD].decChainData, pP->pChainFxns,
1151 HEAP_INTERNAL, as+z, acp, &trace,
1152 decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1153 if (!chain)
1154 {
1155 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1156 return __LINE__;
1157 }
1158 }
1160 #if 0 // FL: master
1161 pC->xStr[z].aspChain[0] = NULL;
1162 for (g=0; g < GEARS; g++)
1163 {
1164 PAF_ASP_Chain *chain;
1165 TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1166 chain =
1167 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1168 HEAP_INTERNAL, as+z, acp, &trace,
1169 aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1170 if (! chain)
1171 {
1172 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1173 return __LINE__;
1174 }
1175 else
1176 pC->xStr[z].aspChain[g] = chain;
1177 }
1178 #endif
1180 #if 0 // FL: master
1181 if (zE >= 0)
1182 {
1183 PAF_ASP_Chain *chain;
1184 TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for encode.", (IArg)__FUNCTION__, __LINE__);
1185 chain =
1186 PAF_ASP_chainInit (&pC->xEnc[zE].encChainData, pP->pChainFxns,
1187 HEAP_INTERNAL, as+z, acp, &trace,
1188 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
1189 if (!chain)
1190 {
1191 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
1192 return __LINE__;
1193 }
1194 }
1195 #endif
1197 #if 0 // FL: master
1198 //
1199 // Allocate non-common memories for Logical IO drivers
1200 // Since these structures are used at run-time we allocate from external memory
1201 if (INPUT1 <= z && z < INPUTN)
1202 {
1203 PAF_ASP_Chain *chain;
1204 TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: non-common input chain init for %d",
1205 as+z, __LINE__, z);
1206 chain = PAF_ASP_chainInit (&pC->xInp[z].inpChainData, pP->pChainFxns,
1207 HEAP_EXTERNAL, as+z, acp, &trace,
1208 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1209 if (!chain)
1210 {
1211 TRACE_TERSE1("AS%d: Input chain initialization failed", as+z);
1212 return __LINE__;
1213 }
1214 }
1215 #endif
1217 #if 0 // FL: master
1218 if (OUTPUT1 <= z && z < OUTPUTN)
1219 {
1220 PAF_ASP_Chain *chain;
1221 TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: non-common output chain init for %d",
1222 as+z, __LINE__, z);
1223 chain = PAF_ASP_chainInit (&pC->xOut[z].outChainData, pP->pChainFxns,
1224 HEAP_EXTERNAL, as+z, acp, &trace,
1225 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
1226 if (!chain)
1227 {
1228 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
1229 return __LINE__;
1230 }
1231 }
1232 #endif
1233 }
1234 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1236 return 0;
1237 } //PAF_ASDT_initPhaseCommon
1239 // -----------------------------------------------------------------------------
1240 // AST Initialization Function - Algorithm Keys
1241 //
1242 // Name: PAF_AST_initPhaseAlgKey
1243 // Purpose: Audio Stream Task Function for initialization of data values
1244 // from parameters for Algorithm Keys.
1245 // From: audioStream1Task or equivalent
1246 // Uses: See code.
1247 // States: x
1248 // Return: 0.
1249 // Trace: Message Log "trace" in Debug Project Configuration reports:
1250 // * State information as per parent.
1251 //
1252 // .............................................................................
1253 Int
1254 PAF_ASDT_initPhaseAlgKey(
1255 const PAF_AST_Params *pP,
1256 const PAF_AST_Patchs *pQ,
1257 PAF_AST_Config *pC
1258 )
1259 {
1260 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1261 Int z; /* decode/encode counter */
1262 Int s; /* key number */
1263 PAF_ASP_Link *that;
1265 (void)as; // clear warning.
1267 TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1269 for (z=DECODE1; z < DECODEN; z++)
1270 {
1271 for (s=0; s < pP->pDecAlgKey->length; s++)
1272 {
1273 if ((pP->pDecAlgKey->code[s].full != 0)
1274 && (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1275 {
1276 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1277 /* Cast in interface, for now --Kurt */
1278 }
1279 else
1280 pC->xDec[z].decAlg[s] = NULL;
1281 }
1282 }
1284 #if 0 // FL: master
1285 for (z=ENCODE1; z < ENCODEN; z++)
1286 {
1287 for (s=0; s < pP->pEncAlgKey->length; s++)
1288 {
1289 if (pP->pEncAlgKey->code[s].full != 0
1290 && (that = PAF_ASP_chainFind (&pC->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
1291 pC->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
1292 /* Cast in interface, for now --Kurt */
1293 else
1294 pC->xEnc[z].encAlg[s] = NULL;
1295 }
1296 }
1297 #endif
1299 return 0;
1300 } //PAF_AST_initPhaseAlgKey
1302 Int
1303 PAF_ASDT_initFrame0(
1304 const PAF_AST_Params *pP,
1305 const PAF_AST_Patchs *pQ,
1306 PAF_AST_Config *pC,
1307 Int z
1308 )
1309 {
1310 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1311 Int aLen;
1312 Int aSize = sizeof(PAF_AudioData);
1313 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1314 Int maxFrameLength = pP->maxFramelength;
1315 PAF_AudioData *aBuf=NULL;
1316 XDAS_UInt8 *metadataBuf;
1317 Error_Block eb;
1318 PAF_AudioFrame *pAudioFrame;
1319 Int i;
1321 pAudioFrame = &gpDecAudioFrame[z];
1322 if (pAudioFrame == NULL)
1323 {
1324 SW_BREAKPOINT;
1325 }
1327 // Initialize error block
1328 Error_init(&eb);
1330 //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1331 aLen = numchan[z] * maxFrameLength;
1333 //
1334 // Initialize audio frame elements directly
1335 //
1336 pAudioFrame->fxns = pP->pAudioFrameFunctions;
1337 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1338 pAudioFrame->data.nSamples = FRAMELENGTH;
1339 pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1340 pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1341 pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1343 //
1344 // Allocate memory for and initialize pointers to audio data buffers
1345 //
1346 // The NUMCHANMASK is used to identify the channels for which data
1347 // buffers can be allocated. Using this mask and switch statement
1348 // rather than some other construct allows efficient code generation,
1349 // providing just the code necessary (with significant savings).
1350 //
1351 if (pP->fxns->bufMemPrint)
1352 {
1353 pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1354 }
1356 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1358 if (aLen != 0)
1359 {
1360 if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1361 {
1362 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1363 TRACE_TERSE2(" maxFrameLength: %d. aLen*aSize: %d", maxFrameLength, aLen*aSize);
1364 SW_BREAKPOINT;
1365 return __LINE__;
1366 }
1367 }
1369 TRACE_TERSE3(" maxFrameLength: %d. aLen*aSize: %d. aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1371 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1372 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1373 {
1374 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1375 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1376 SW_BREAKPOINT;
1377 return __LINE__;
1378 }
1380 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1381 {
1382 gDecAudioFrameChannelPointers[i] = NULL;
1383 }
1385 if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1386 {
1387 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1388 return __LINE__;
1389 }
1390 else
1391 {
1392 Int j = 0;
1393 TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1394 for (i=0; i<numchan[z]; i++)
1395 {
1396 Int8 chan = AFChanPtrMap[numchan[z]][i];
1397 if (chan != -1)
1398 {
1399 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1400 j++;
1401 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1402 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1403 }
1404 }
1405 }
1407 // Initialize original audio frame channel pointers
1408 for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++)
1409 {
1410 if (gDecAudioFrameChannelPointers[i])
1411 {
1412 gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1413 }
1414 }
1416 //
1417 // Initialize meta data elements
1418 //
1419 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1420 pAudioFrame->numPrivateMetadata = 0;
1421 pAudioFrame->bsMetadata_offset = 0;
1422 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1423 pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1424 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1425 {
1426 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1427 pAudioFrame->pafPrivateMetadata[i].size = 0;
1428 pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1429 }
1431 return 0;
1432 } //PAF_ASDT_initFrame0
1434 // -----------------------------------------------------------------------------
1435 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1436 // AST Decoding Function - Reinitialization of Audio Frame
1437 //
1438 // Name: PAF_ASOT_initFrame1
1439 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1440 // zation of the Audio Frame(s) by loading of data values of a
1441 // time-varying nature.
1442 // From: audioStream1Task or equivalent
1443 // AST Parameter Function -> decodeInfo
1444 // AST Parameter Function -> decodeDecode
1445 // Uses: See code.
1446 // States: x
1447 // Return: 0.
1448 // Trace: None.
1449 //
1450 Int
1451 PAF_ASDT_initFrame1(
1452 const PAF_AST_Params *pP,
1453 const PAF_AST_Patchs *pQ,
1454 PAF_AST_Config *pC,
1455 Int z,
1456 Int apply
1457 )
1458 {
1459 PAF_AudioFrame *pAudioFrame;
1461 //
1462 // Reinitialize audio frame elements:
1463 //
1464 // Channel Configurations during sys init = Unknown
1465 // " " during info or decode = None
1466 //
1467 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1468 //
1470 pAudioFrame = &gpDecAudioFrame[z];
1472 if (apply < 0)
1473 {
1474 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1475 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1476 }
1477 else
1478 {
1479 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1480 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1481 }
1483 if (apply < 1)
1484 {
1485 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1486 pAudioFrame->sampleCount = 0;
1487 }
1489 return 0;
1490 } //PAF_ASDT_initFrame1
1492 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1493 Int resetAf(
1494 const PAF_AST_Params *pP,
1495 Int z,
1496 Int sourceSelect
1497 )
1498 {
1499 PAF_AudioFrame *pAudioFrame;
1500 Int ch;
1501 Int i;
1503 // Get audio frame
1504 pAudioFrame = &gpDecAudioFrame[z];
1505 if (pAudioFrame == NULL)
1506 {
1507 SW_BREAKPOINT;
1508 }
1510 // Reinitialize audio frame elements
1511 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1512 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1513 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1514 pAudioFrame->sampleCount = 0;
1515 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1517 if (sourceSelect == PAF_SOURCE_PCM)
1518 {
1519 pAudioFrame->data.nSamples = FRAMELENGTH;
1520 }
1521 else if (sourceSelect == PAF_SOURCE_DDP)
1522 {
1523 pAudioFrame->data.nSamples = 1536;
1524 }
1525 else
1526 {
1527 pAudioFrame->data.nSamples = FRAMELENGTH;
1528 }
1530 // Reset audio frame channel pointers
1531 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1532 {
1533 if (gDecAudioFrameChannelPointers[ch])
1534 {
1535 gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1536 }
1537 }
1539 // Reset audio frame meta data elements
1540 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1541 pAudioFrame->numPrivateMetadata = 0;
1542 pAudioFrame->bsMetadata_offset = 0;
1543 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1544 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1545 {
1546 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1547 pAudioFrame->pafPrivateMetadata[i].size = 0;
1548 }
1550 return 0;
1551 }
1553 // Reset AF samsiz, invoked during DECODE
1554 Int resetAfSamsiz(
1555 Int z
1556 )
1557 {
1558 PAF_AudioFrame *pAudioFrame;
1559 Int ch;
1561 // Get audio frame
1562 pAudioFrame = &gpDecAudioFrame[z];
1563 if (pAudioFrame == NULL)
1564 {
1565 SW_BREAKPOINT;
1566 }
1568 // Clear samsiz for all channels - MID 208.
1569 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
1570 {
1571 pAudioFrame->data.samsiz[ch] = 0;
1572 }
1574 return 0;
1575 }