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