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