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