4b869a2ff5e1a967ff04f53749364c497652e44c
[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_CLEAR);
967 if (pP->fxns->headerPrint)
968 pP->fxns->headerPrint();
970 for (z=STREAM1; z < STREAMN; z++)
971 {
972 //Int zD, zE, zX;
973 Int zD, zX;
975 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
977 //
978 // Determine common memory needs of Decode Algorithms
979 //
980 PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
982 zD = -1;
983 for (zX = DECODE1; zX < DECODEN; zX++)
984 {
985 if (pP->streamsFromDecodes[zX] == z)
986 {
987 zD = zX;
988 break;
989 }
990 }
992 if (zD >= 0)
993 {
994 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
995 if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z]))
996 {
997 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
998 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1000 SW_BREAKPOINT;
1001 return __LINE__;
1002 }
1003 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1004 if(pP->fxns->allocPrint)
1005 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1006 }
1008 #if 0 // FL: master
1009 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1010 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1011 if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z]))
1012 {
1013 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1014 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1015 SW_BREAKPOINT;
1016 return __LINE__;
1017 }
1018 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1019 if(pP->fxns->allocPrint)
1020 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1021 #endif
1023 }
1024 {
1025 // Changes made to share scratch between zones
1026 // Assume maximum 3 zones and scratch common memory is at offset 0;
1027 int max=0;
1028 for (z=STREAM1; z < STREAMN; z++)
1029 {
1030 if (max<common[z][0].size)
1031 max=common[z][0].size;
1032 }
1033 common[STREAM1][0].size=max;
1034 for (z=STREAM1+1; z < STREAMN; z++)
1035 common[z][0].size=0;
1036 }
1038 //
1039 // Provide common memory needs of Decode Algorithms
1040 //
1041 for (z=STREAM1; z < STREAMN; z++)
1042 {
1043 //Int zD, zE, zX;
1044 Int zD, zX;
1046 zD = -1;
1047 for (zX = DECODE1; zX < DECODEN; zX++)
1048 {
1049 if (pP->streamsFromDecodes[zX] == z)
1050 {
1051 zD = zX;
1052 break;
1053 }
1054 }
1056 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1057 if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig))
1058 {
1059 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1060 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1061 SW_BREAKPOINT;
1062 return __LINE__;
1063 }
1064 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1065 // share zone0 scratch with all zones
1066 common[z][0].base=common[0][0].base;
1067 if (pP->fxns->commonPrint)
1068 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1070 //
1071 // Instantiate Decode Algorithms
1072 //
1073 if (zD >= 0)
1074 {
1075 PAF_ASP_Chain *chain;
1076 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1077 chain =
1078 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1079 HEAP_INTERNAL, as+z, acp, &trace,
1080 decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1081 if (!chain)
1082 {
1083 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1084 return __LINE__;
1085 }
1086 }
1088 #if 0 // FL: master
1089 pC->xStr[z].aspChain[0] = NULL;
1090 for (g=0; g < GEARS; g++)
1091 {
1092 PAF_ASP_Chain *chain;
1093 TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1094 chain =
1095 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1096 HEAP_INTERNAL, as+z, acp, &trace,
1097 aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1098 if (! chain)
1099 {
1100 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1101 return __LINE__;
1102 }
1103 else
1104 pC->xStr[z].aspChain[g] = chain;
1105 }
1106 #endif
1108 }
1109 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1111 return 0;
1112 } //PAF_ASDT_initPhaseCommon
1114 // -----------------------------------------------------------------------------
1115 // AST Initialization Function - Algorithm Keys
1116 //
1117 // Name: PAF_AST_initPhaseAlgKey
1118 // Purpose: Audio Stream Task Function for initialization of data values
1119 // from parameters for Algorithm Keys.
1120 // From: audioStream1Task or equivalent
1121 // Uses: See code.
1122 // States: x
1123 // Return: 0.
1124 // Trace: Message Log "trace" in Debug Project Configuration reports:
1125 // * State information as per parent.
1126 //
1127 // .............................................................................
1128 Int
1129 PAF_ASDT_initPhaseAlgKey(
1130 const PAF_ASDT_Params *pP,
1131 const PAF_ASDT_Patchs *pQ,
1132 PAF_ASDT_Config *pC
1133 )
1134 {
1135 PAF_AST_Config *pAstCfg;
1136 Int as; /* Audio Stream Number (1, 2, etc.) */
1137 Int z; /* decode/encode counter */
1138 Int s; /* key number */
1139 PAF_ASP_Link *that;
1141 (void)as; // clear warning.
1143 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1144 as = pAstCfg->as;
1146 TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1148 for (z=DECODE1; z < DECODEN; z++)
1149 {
1150 for (s=0; s < pP->pDecAlgKey->length; s++)
1151 {
1152 if ((pP->pDecAlgKey->code[s].full != 0)
1153 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1154 {
1155 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1156 /* Cast in interface, for now --Kurt */
1157 }
1158 else
1159 pAstCfg->xDec[z].decAlg[s] = NULL;
1160 }
1161 }
1163 return 0;
1164 } //PAF_AST_initPhaseAlgKey
1166 // Purpose: Audio Stream Decode Task Function for initialization of the Audio
1167 // Frame(s) by memory allocation and loading of data pointers
1168 // and values.
1169 Int
1170 PAF_ASDT_initFrame0(
1171 const PAF_ASDT_Params *pP,
1172 const PAF_ASDT_Patchs *pQ,
1173 PAF_ASDT_Config *pC,
1174 Int z
1175 )
1176 {
1177 PAF_AST_Config *pAstCfg;
1178 Int as; /* Audio Stream Number (1, 2, etc.) */
1179 Int aLen;
1180 Int aSize = sizeof(PAF_AudioData);
1181 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1182 Int maxFrameLength = pP->maxFramelength;
1183 PAF_AudioData *aBuf=NULL;
1184 XDAS_UInt8 *metadataBuf;
1185 Error_Block eb;
1186 PAF_AudioFrame *pAudioFrame;
1187 Int i;
1189 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1190 as = pAstCfg->as;
1192 pAudioFrame = &gpDecAudioFrame[z];
1193 if (pAudioFrame == NULL)
1194 {
1195 SW_BREAKPOINT;
1196 }
1198 // Initialize error block
1199 Error_init(&eb);
1201 //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1202 aLen = numchan[z] * maxFrameLength;
1204 //
1205 // Initialize audio frame elements directly
1206 //
1207 pAudioFrame->fxns = pP->pAudioFrameFunctions;
1208 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1209 pAudioFrame->data.nSamples = FRAMELENGTH;
1210 pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1211 pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1212 pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1214 //
1215 // Allocate memory for and initialize pointers to audio data buffers
1216 //
1217 // The NUMCHANMASK is used to identify the channels for which data
1218 // buffers can be allocated. Using this mask and switch statement
1219 // rather than some other construct allows efficient code generation,
1220 // providing just the code necessary (with significant savings).
1221 //
1222 if (pP->fxns->bufMemPrint)
1223 {
1224 pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1225 }
1227 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1229 if (aLen != 0)
1230 {
1231 if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1232 {
1233 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1234 TRACE_TERSE2(" maxFrameLength: %d. aLen*aSize: %d", maxFrameLength, aLen*aSize);
1235 SW_BREAKPOINT;
1236 return __LINE__;
1237 }
1238 }
1240 TRACE_TERSE3(" maxFrameLength: %d. aLen*aSize: %d. aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1242 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1243 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1244 {
1245 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1246 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1247 SW_BREAKPOINT;
1248 return __LINE__;
1249 }
1251 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1252 {
1253 gDecAudioFrameChannelPointers[i] = NULL;
1254 }
1256 if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1257 {
1258 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1259 return __LINE__;
1260 }
1261 else
1262 {
1263 Int j = 0;
1264 TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1265 for (i=0; i<numchan[z]; i++)
1266 {
1267 Int8 chan = AFChanPtrMap[numchan[z]][i];
1268 if (chan != -1)
1269 {
1270 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1271 j++;
1272 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1273 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1274 }
1275 }
1276 }
1278 // Initialize original audio frame channel pointers
1279 for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++)
1280 {
1281 if (gDecAudioFrameChannelPointers[i])
1282 {
1283 gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1284 }
1285 }
1287 //
1288 // Initialize meta data elements
1289 //
1290 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1291 pAudioFrame->numPrivateMetadata = 0;
1292 pAudioFrame->bsMetadata_offset = 0;
1293 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1294 pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1295 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1296 {
1297 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1298 pAudioFrame->pafPrivateMetadata[i].size = 0;
1299 pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1300 }
1302 return 0;
1303 } //PAF_ASDT_initFrame0
1305 // -----------------------------------------------------------------------------
1306 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1307 // AST Decoding Function - Reinitialization of Audio Frame
1308 //
1309 // Name: PAF_ASOT_initFrame1
1310 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1311 // zation of the Audio Frame(s) by loading of data values of a
1312 // time-varying nature.
1313 // From: audioStream1Task or equivalent
1314 // AST Parameter Function -> decodeInfo
1315 // AST Parameter Function -> decodeDecode
1316 // Uses: See code.
1317 // States: x
1318 // Return: 0.
1319 // Trace: None.
1320 //
1321 Int
1322 PAF_ASDT_initFrame1(
1323 const PAF_ASDT_Params *pP,
1324 const PAF_ASDT_Patchs *pQ,
1325 PAF_ASDT_Config *pC,
1326 Int z,
1327 Int apply
1328 )
1329 {
1330 PAF_AudioFrame *pAudioFrame;
1332 //
1333 // Reinitialize audio frame elements:
1334 //
1335 // Channel Configurations during sys init = Unknown
1336 // " " during info or decode = None
1337 //
1338 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1339 //
1341 pAudioFrame = &gpDecAudioFrame[z];
1343 if (apply < 0)
1344 {
1345 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1346 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1347 }
1348 else
1349 {
1350 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1351 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1352 }
1354 if (apply < 1)
1355 {
1356 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1357 pAudioFrame->sampleCount = 0;
1358 }
1360 return 0;
1361 } //PAF_ASDT_initFrame1
1363 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1364 Int resetAf(
1365 const PAF_ASDT_Params *pP,
1366 Int z,
1367 Int sourceSelect
1368 )
1369 {
1370 PAF_AudioFrame *pAudioFrame;
1371 Int ch;
1372 Int i;
1374 // Get audio frame
1375 pAudioFrame = &gpDecAudioFrame[z];
1376 if (pAudioFrame == NULL)
1377 {
1378 SW_BREAKPOINT;
1379 }
1381 // Reinitialize audio frame elements
1382 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1383 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1384 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1385 pAudioFrame->sampleCount = 0;
1386 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1388 switch (sourceSelect)
1389 {
1390 case PAF_SOURCE_PCM:
1391 pAudioFrame->data.nSamples = FRAMELENGTH;
1392 break;
1393 case PAF_SOURCE_AC3:
1394 case PAF_SOURCE_DDP:
1395 pAudioFrame->data.nSamples = 1536;
1396 break;
1397 default:
1398 pAudioFrame->data.nSamples = FRAMELENGTH;
1399 break;
1400 }
1402 // Reset audio frame channel pointers
1403 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1404 {
1405 if (gDecAudioFrameChannelPointers[ch])
1406 {
1407 gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1408 }
1409 }
1411 // Reset audio frame meta data elements
1412 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1413 pAudioFrame->numPrivateMetadata = 0;
1414 pAudioFrame->bsMetadata_offset = 0;
1415 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1416 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1417 {
1418 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1419 pAudioFrame->pafPrivateMetadata[i].size = 0;
1420 }
1422 return 0;
1423 }
1425 // Reset AF samsiz, invoked during DECODE
1426 Int resetAfSamsiz(
1427 Int z
1428 )
1429 {
1430 PAF_AudioFrame *pAudioFrame;
1431 Int ch;
1433 // Get audio frame
1434 pAudioFrame = &gpDecAudioFrame[z];
1435 if (pAudioFrame == NULL)
1436 {
1437 SW_BREAKPOINT;
1438 }
1440 // Clear samsiz for all channels - MID 208.
1441 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
1442 {
1443 pAudioFrame->data.samsiz[ch] = 0;
1444 }
1446 return 0;
1447 }