2 /*
3 Copyright (c) 2017, 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 "aspOutInitSync_slave.h"
62 #include "audioStreamProc_common.h"
63 #include "audioStreamDecodeProc.h"
64 #include "statusOp_common.h"
66 #include "pfp/pfp.h"
67 #include "pfp_app.h" /* contains all PFP ID's */
69 // FL: debug
70 #include "dbgCapAf.h"
71 #include "dbgDib.h"
72 #include "evmc66x_gpio_dbg.h"
74 //
75 // Decoder Definitions
76 //
77 #define decLinkInit pQ->i_decLinkInit
79 #define __TASK_NAME__ "TaskAsdp"
81 // Check decoder sync using information in INFO audio frame
82 static Int8 checkDecSync(
83 PAF_AudioFrame *pAf
84 );
86 extern struct {
87 Int size;
88 IALG_Status *pStatus[512];
89 } IACP_STD_BETA_TABLE;
91 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
92 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
94 LINNO_DEFN(TaskAsdp); /* Line number macros */
95 ERRNO_DEFN(TaskAsdp); /* Error number macros */
97 // ASDT configuration
98 PAF_ASDT_Config gPAF_ASDT_config
99 __attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
100 NULL, // taskHandle
101 NULL, // acp
102 {NULL, 0, NULL}, // decOpCircBufCtl
103 {NULL, NULL}, // outIsCtl
104 &gPAF_AST_config // ASIT/ASOT/ASDT shared configuration
105 };
107 PAF_AudioFrame *gpDecAudioFrame=NULL;
108 PAF_AudioData *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
109 PAF_AudioSize gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
110 PAF_AudioData *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
112 // Overflow threshold before circular buffer reset and return error to Top-Level FSM
113 #define DEC_OP_CB_WRTAF_OVR_THR ( 20 ) // FL: arbitrary setting
114 UInt32 gCbWrtAfErrCnt =0; // decoder output circular buffer write error count, not including overflows
115 UInt32 gDecOpCbWrtAfOvr =0; // decoder output circular buffer overflow count
116 UInt32 gMaxDecOpCbWrtAfOvr =0; // max (consecutive) decoder output circular buffer overflow count
117 UInt32 gSlaveCbResetCnt =0; // slave circular buffer reset count
119 // Global debug counters */
120 UInt32 gSlaveStartErrCnt =0;
121 UInt32 gSlaveStartCnt =0;
122 UInt32 gSlaveSourceSelectCnt =0;
123 UInt32 gSlaveExitCnt =0;
124 UInt32 gSlaveDecExitCnt =0;
125 UInt32 gSlaveDecControlCnt =0;
126 UInt32 gSlaveDecActivateCnt =0;
127 UInt32 gSlaveDecResetCnt =0;
128 UInt32 gSlaveDecInfoCnt =0;
129 UInt32 gSlaveDecDecodeCnt =0;
130 UInt32 gSlaveDecDeactivateCnt =0;
133 //#define CAPTURE_DECODER_OUTSAMPLES_PP
134 #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
136 #define CAP_FRAME_MAX 2000
137 Uint32 tempCap_frameCnt = 0;
138 int tempCap_decSampleOut[CAP_FRAME_MAX] = {0};
139 #endif
142 /*
143 * ======== taskAsdpFxn ========
144 * Audio Stream Decode Processing task function
145 */
146 Void taskAsdpFxn(
147 // Int betaPrimeValue, // FL: revisit
148 const PAF_ASDT_Params *pP,
149 const PAF_ASDT_Patchs *pQ
150 )
151 {
152 PAF_ASDT_Config *pAsdtCfg; // ASDT configuration pointer
153 PAF_AST_Config *pAstCfg; // Common (shared) configuration pointer
154 Int as; // Audio Stream Number (1, 2, etc.)
155 Int z; // input/encode/stream/decode/output counter
156 Int i; // phase
157 Int zMD, zMS;
158 Bool done;
159 Bool decDone;
160 ALG_Handle alg[DECODEN_MAX];
161 ASP_Slave_Cmd slaveCmd;
162 Int sourceSelect;
163 DEC_Handle dec;
164 IALG_Cmd decCtrlCmd; // decoder control command
165 Int decCtrlRet; // decoder control return
166 Int errno; // error number
167 Int size;
168 Int argIdx;
169 // Decoder output circular buffer
170 PAF_AST_DecOpCircBufCtl *pCbCtl; // Decoder output Circular Buffer control
171 PAF_AudioFrame *pAfWrt; // pointer to audio frame written to CB
172 Int cbErrno; // CB error number
173 // Output Init-Sync
174 PAF_AudioFrame *pDecCtrlAf; // pointer to Dec Control audio frame
175 PAF_AST_OutInitSyncCtl *pOutIsCtl; // OutIS control
176 Int8 outIsDecInfo1Flag; // indicates whether Dec Info Init-Sync has executed
177 Int8 outIsDecDecode1Flag; // indicates whether Dec Decode1 Init-Sync has executed
178 Int outIsErrno; // OutIS error number
179 // Messaging
180 PAF_InpBufConfig *pIpBufConfig; // IB buffer configuration
181 ASP_Msg *pAspMsg; // Rx/Tx MessageQ message
182 MessageQ_QueueId queId; // MessageQ ID
183 Int status;
184 Int zI;
185 Int bufEnd, wrapSize, currentBufSize, chunkSize;
186 Int8 temp8;
188 Log_info0("Enter taskAsdpFxn()");
191 //
192 // Audio Framework Parameters & Patch (*pP, *pQ):
193 //
194 if (!pP)
195 {
196 TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
197 LINNO_RPRT(TaskAsdp, -1);
198 return;
199 }
201 if (!pQ)
202 {
203 TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
204 LINNO_RPRT(TaskAsdp, -1);
205 return;
206 }
208 //
209 // Audio Stream Decode Task Configuration (*pAsdtCfg):
210 //
211 pAsdtCfg = &gPAF_ASDT_config; // initialize pointer to task configuration
212 pAsdtCfg->taskHandle = Task_self(); // set task handle
213 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
214 pCbCtl = &pAsdtCfg->decOpCircBufCtl; // get pointer to circular buffer control
215 pOutIsCtl = &pAsdtCfg->outIsCtl; // get pointer to output init-sync control
217 // wait for initialization message from master
218 do {
219 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
220 //TRACE_TERSE1("Rx ASP message: status=%d", status);
221 //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
222 } while (status != MessageQ_S_SUCCESS);
223 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
224 (pAspMsg->cmd != ASP_SLAVE_START))
225 {
226 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
227 SW_BREAKPOINT;
228 }
229 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
230 gSlaveStartCnt++;
231 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
233 // invalidate AST shared configuration
234 Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
235 Cache_wait();
237 // (***) FL: revisit
238 // invalidate Dec configuration for all Decoder zones
239 Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
240 Cache_wait();
242 // (***) FL: revisit
243 // invalidate Beta Table status pointers
244 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
245 Cache_wait();
247 /* Obtain Audio Stream Number (1, 2, etc.) */
248 as = pAstCfg->as;
249 TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
251 //
252 // Initialize message log trace and line number reporting
253 //
254 for (z=STREAM1; z < STREAMN; z++)
255 {
256 TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
257 }
258 LINNO_RPRT(TaskAsdp, -1);
260 // Get decoder and stream index associated with the master input
261 zMD = pAstCfg->masterDec;
262 zMS = pAstCfg->masterStr;
264 //
265 // Initialize per parameterized phases.
266 // - Malloc: Memory Allocation
267 // - Config: Configuration Initialization
268 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
269 // - Common: Common Algorithm Initialization
270 // - AlgKey: Dec/Enc chain to Array Initialization
271 // - Unused: (available)
272 // - Unused: (available)
273 // - Unused: (available)
274 //
275 LINNO_RPRT(TaskAsdp, -2);
276 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
277 {
278 Int linno;
279 if (pP->fxns->initPhase[i])
280 {
281 if ((linno = pP->fxns->initPhase[i](pP, pQ, pAsdtCfg)))
282 {
283 LINNO_RPRT(TaskAsdp, linno);
284 return;
285 }
286 }
287 else
288 {
289 TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
290 }
291 TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
292 LINNO_RPRT(TaskAsdp, -i-3);
293 }
295 #ifdef NON_CACHE_STATUS
296 //
297 // init Status structure Gate
298 //
299 if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
300 {
301 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DEC);
302 }
303 if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
304 {
305 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DDP);
306 }
307 if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
308 {
309 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_PCM);
310 }
311 if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
312 {
313 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_THD);
314 }
315 #endif
317 //
318 // End of Initialization -- final memory usage report.
319 //
320 if (pP->fxns->memStatusPrint)
321 {
322 pP->fxns->memStatusPrint("ASDT MEMSTAT REPORT",
323 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
324 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
325 }
327 // (***) FL: revisit
328 // write back Status structure addresses for Beta Units initialized on Slave
329 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
330 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
331 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
332 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
333 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
334 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
335 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
336 Cache_wait();
338 // (***) FL: revisit
339 // write back Status structures for Beta Units initialized on Slave
340 /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
341 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
342 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
343 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
344 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
345 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
346 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
347 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
348 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
349 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
350 Cache_wait();
352 // (***) FL: revisit
353 // write back Dec configuration
354 Cache_wbInv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
355 Cache_wait();*/
357 // Send initialization complete message to master
358 queId = MessageQ_getReplyQueue(pAspMsg);
359 pAspMsg->procId = hAspMsgSlave->slaveProcId;
360 pAspMsg->cmd = ASP_MASTER_START_DONE;
361 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
362 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
363 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
364 if (status != MessageQ_S_SUCCESS)
365 {
366 SW_BREAKPOINT;
367 }
369 done = FALSE;
370 while (done==FALSE)
371 {
372 // wait for source select message from master
373 do {
374 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
375 } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
376 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
377 (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
378 {
379 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
380 SW_BREAKPOINT;
381 }
382 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
383 sourceSelect = *(Int32 *)&pAspMsg->buf[0];
384 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
385 TRACE_MSG1("sourceSelect=%d.", sourceSelect);
386 // send source select complete message to master
387 queId = MessageQ_getReplyQueue(pAspMsg);
388 pAspMsg->procId = hAspMsgSlave->slaveProcId;
389 pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
390 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
391 gSlaveSourceSelectCnt++;
392 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
393 MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
395 for (z=DECODE1; z < DECODEN; z++)
396 {
397 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
398 }
399 alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
401 // Reset IB capture buffer (debug)
402 //capIbReset();
403 //Log_info0("capIbReset()");
404 // Reset audio frame capture buffer (debug)
405 //capAfReset();
407 decDone = FALSE;
408 while (decDone==FALSE)
409 {
410 // wait for received message from master
411 do {
412 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
413 } while (status < 0);
414 if (pAspMsg->procId != hAspMsgSlave->masterProcId)
415 {
416 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
417 SW_BREAKPOINT;
418 }
419 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
420 slaveCmd = pAspMsg->cmd;
421 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
423 switch (slaveCmd)
424 {
425 case ASP_SLAVE_NULL:
426 case ASP_SLAVE_START:
427 gSlaveStartErrCnt++;
428 TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
430 break;
432 case ASP_SLAVE_EXIT:
433 gSlaveExitCnt++;
434 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
436 decDone = TRUE;
437 done = TRUE;
438 break;
440 case ASP_SLAVE_DEC_EXIT:
441 gSlaveDecExitCnt++;
442 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
444 // send dec exit complete message to master
445 queId = MessageQ_getReplyQueue(pAspMsg);
446 pAspMsg->procId = hAspMsgSlave->slaveProcId;
447 pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
448 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
449 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
450 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
451 if (status != MessageQ_S_SUCCESS)
452 {
453 SW_BREAKPOINT;
454 }
456 decDone=TRUE;
457 break;
459 case ASP_SLAVE_DEC_CONTROL:
460 gSlaveDecControlCnt++;
462 argIdx = 0; // get decIdx
463 z = *(Int32 *)&pAspMsg->buf[argIdx];
464 argIdx += sizeof(Int32);
465 decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
466 TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
468 decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
470 // send dec control complete message to master
471 queId = MessageQ_getReplyQueue(pAspMsg);
472 pAspMsg->procId = hAspMsgSlave->slaveProcId;
473 pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
474 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
475 argIdx = 0; // set decCtrlRet
476 *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
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_ACTIVATE:
487 gSlaveDecActivateCnt++;
489 // (***) FL: revisit
490 // invalidate Status structures for shared Beta Units
491 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
492 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
493 /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
494 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
495 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
496 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
497 Cache_wait();*/
499 argIdx = 0; // get decIdx
500 z = *(Int32 *)&pAspMsg->buf[argIdx];
501 TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
503 // invalidate Dec configuration
504 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
505 Cache_wait();
507 if (alg[z]->fxns->algActivate)
508 {
509 alg[z]->fxns->algActivate(alg[z]);
510 }
512 // Start writes to circular buffer
513 cbErrno = cbWriteStart(pCbCtl, z);
514 if (cbErrno < 0)
515 {
516 SW_BREAKPOINT;
517 }
518 gCbWrtAfErrCnt=0; // reset write circular buffer error count
519 gDecOpCbWrtAfOvr=0; // reset decoder output circular buffer overflow count
520 gMaxDecOpCbWrtAfOvr=0; // reset max decoder output circular buffer overflow count
521 gSlaveCbResetCnt=0; // reset slave circular buffer reset count
522 // Log circular buffer control variables (debug)
523 cbLog(pCbCtl, z, 1, "cbWriteStart");
525 // Reset audio frame
526 resetAf(pP, z, sourceSelect);
528 // Initialize OutIS Dec flags
529 outIsDecInfo1Flag = 0; // OutIS Dec Info1 hasn't executed
530 outIsDecDecode1Flag = 0; // OutIS Dec Decode1 hasn't executed
532 // send dec activate complete message to master
533 queId = MessageQ_getReplyQueue(pAspMsg);
534 pAspMsg->procId = hAspMsgSlave->slaveProcId;
535 pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
536 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
537 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
538 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
539 if (status != MessageQ_S_SUCCESS)
540 {
541 SW_BREAKPOINT;
542 }
544 break;
546 case ASP_SLAVE_DEC_RESET:
547 gSlaveDecResetCnt++;
549 argIdx = 0; // get decIdx
550 z = *(Int32 *)&pAspMsg->buf[argIdx];
551 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
553 dec = (DEC_Handle)alg[z];
554 errno = 0;
555 if (dec->fxns->reset)
556 {
557 //
558 // Execute decode reset
559 //
560 errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
562 // Get pointer to Dec Reset output audio frame
563 pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
565 // Perform Dec Reset Init-Sync
566 // - Write Dec Reset output audio frame
567 // - Set Dec Reset decoder stage flag
568 outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z,
569 ASP_OUTIS_DEC_STAGE_RESET_IDX, 1, pDecCtrlAf);
570 if (outIsErrno < 0)
571 {
572 SW_BREAKPOINT; // debug
573 }
574 }
576 // write back Dec configuration
577 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
578 Cache_wait();
580 // (***) FL: revisit
581 // write back Status structures for shared Beta Units
582 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
583 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
584 /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
585 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
586 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
587 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
588 Cache_wait();*/
590 // send dec reset complete message to master
591 queId = MessageQ_getReplyQueue(pAspMsg);
592 pAspMsg->procId = hAspMsgSlave->slaveProcId;
593 pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
594 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
595 argIdx = 0; // set decErrno
596 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
597 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
598 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
599 if (status != MessageQ_S_SUCCESS)
600 {
601 SW_BREAKPOINT;
602 }
604 break;
606 case ASP_SLAVE_DEC_INFO:
607 gSlaveDecInfoCnt++;
609 argIdx = 0; // get decIdx
610 z = *(Int32 *)&pAspMsg->buf[argIdx];
611 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
612 // Get input associated w/ decoder
613 zI = pP->inputsFromDecodes[z];
615 // (***) FL: revisit
616 // invalidate Inp configuration
617 Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
618 Cache_wait();
619 // invalidate input data
620 pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
621 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
622 if (sourceSelect == PAF_SOURCE_PCM)
623 {
624 size *= pIpBufConfig->stride;
625 }
627 bufEnd = (Int) pIpBufConfig->base.pVoid + pIpBufConfig->sizeofBuffer;
628 currentBufSize = (bufEnd - (Int)pIpBufConfig->pntr.pSmInt);
629 if (currentBufSize >= size)
630 {
631 chunkSize = size;
632 }
633 else
634 {
635 chunkSize = currentBufSize;
636 }
637 wrapSize = size - chunkSize;
638 // invalidate input data
639 Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
640 // invalidate Dec configuration
641 TRACE_MSG2("IBUF : pIpBufConfig->pntr.pSmInt: 0x%x and chunkSize: %d", (IArg)pIpBufConfig->pntr.pSmInt, chunkSize);
642 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
643 // status for selected decoder should be invalidated
644 Cache_wait();
646 /* Circular buffer wrap condition*/
647 //if(((Int) pIpBufConfig->head.pVoid + size) > bufEnd)
648 if(wrapSize > 0)
649 {
650 // invalidate input data
651 Cache_inv((Ptr)pIpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
652 TRACE_MSG2("IBUF : pIpBufConfig->base.pSmInt: 0x%x and wrapSize: %d", (IArg)pIpBufConfig->base.pSmInt, wrapSize);
653 // status for selected decoder should be invalidated
654 Cache_wait();
655 }
656 /* Circular buffer wrap condition */
658 dec = (DEC_Handle)alg[z];
659 errno = 0;
660 if (dec->fxns->info)
661 {
662 //
663 // Execute decode info
664 //
665 pfpBegin(PFP_ID_ASDT_1, pAsdtCfg->taskHandle);
666 errno = dec->fxns->info(dec, NULL,
667 &pAstCfg->xDec[z].decodeControl,
668 &pAstCfg->xDec[z].decodeStatus);
669 pfpEnd(PFP_ID_ASDT_1, PFP_FINISH_MEAS);
671 //
672 // Execute Dec Info1 Init-Sync if required
673 //
674 if (outIsDecInfo1Flag == 0)
675 {
676 // Get pointer to Dec Info1 output audio frame
677 pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
679 if (checkDecSync(pDecCtrlAf) == 1)
680 {
681 // Perform Dec Info1 Init-Sync
682 // - Write Dec Info1 output audio frame
683 // - Set Dec Info1 decoder stage flag
684 outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z,
685 ASP_OUTIS_DEC_STAGE_INFO1_IDX, 1, pDecCtrlAf);
686 if (outIsErrno < 0)
687 {
688 SW_BREAKPOINT; // debug
689 }
691 outIsDecInfo1Flag = 1; // OutIS Dec Info1 has executed
692 }
693 }
694 }
696 // write back Dec configuration
697 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
698 Cache_wait();
700 #ifdef NON_CACHE_STATUS
701 statusOp_read(&(temp8),
702 &(pAstCfg->xDec[z].decodeStatus.mode),
703 sizeof(Int8),
704 GATEMP_INDEX_DEC);
705 // Re-initialize audio frame if decoder is disabled or
706 // doesn't have a valid input
707 if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
708 {
709 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
710 }
711 #else
712 // Re-initialize audio frame if decoder is disabled or
713 // doesn't have a valid input
714 if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
715 {
716 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
717 }
718 #endif
720 // send dec info complete message to master
721 queId = MessageQ_getReplyQueue(pAspMsg);
722 pAspMsg->procId = hAspMsgSlave->slaveProcId;
723 pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
724 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
725 argIdx = 0; // set decErrno
726 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
727 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
728 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
729 if (status != MessageQ_S_SUCCESS)
730 {
731 SW_BREAKPOINT;
732 }
734 break;
736 case ASP_SLAVE_DEC_DECODE:
737 gSlaveDecDecodeCnt++;
739 argIdx = 0; // get decIdx
740 z = *(Int32 *)&pAspMsg->buf[argIdx];
741 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
742 // Get input associated w/ decoder
743 zI = pP->inputsFromDecodes[z];
745 // Reset AF samsiz
746 resetAfSamsiz(z);
748 // Invalidate Dec configuration
749 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
750 Cache_wait();
751 //TRACE_TERSE0("Dec:cache wb done");
753 dec = (DEC_Handle)alg[z];
754 //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
756 errno = 0;
757 cbErrno = 0;
758 if (dec->fxns->decode)
759 {
760 // Capture input buffer (debug)
761 //capIb(pAstCfg->xInp[z].pInpBuf);
763 //
764 // Execute decode
765 //
766 pfpBegin(PFP_ID_ASDT_2, pAsdtCfg->taskHandle);
767 errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
768 pfpEnd(PFP_ID_ASDT_2, PFP_FINISH_MEAS);
769 if (errno < 0)
770 {
771 //SW_BREAKPOINT;
772 }
773 TRACE_TERSE0("Dec:decode done");
775 // Get pointer to Dec Decode output audio frame
776 pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
777 TRACE_TERSE2("Dec:pAfWrt=0x%04x, nSamples=%d", (IArg)pAfWrt, pAfWrt->data.nSamples);
779 // Capture audio frame (debug)
780 //if (capAfWrite(pAfWrt, PAF_LEFT) != CAP_AF_SOK)
781 //{
782 // Log_info0("capAfWrite() error");
783 //}
785 #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
786 if (tempCap_frameCnt < CAP_FRAME_MAX)
787 {
788 tempCap_decSampleOut[tempCap_frameCnt] = pAfWrt->sampleCount;
789 tempCap_frameCnt++;
790 }
791 #endif
793 //
794 // Execute Dec Decode1 Init-Sync if required
795 //
796 if (outIsDecDecode1Flag == 0)
797 {
798 //
799 // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
800 // frameLength: changed to decodeControl.frameLength.
801 // Written by ASIT:decodeInit:getFrameLengthSourceSel().
803 // Initialize decoder output circular buffer
804 errno = cbInitDecWrite(pCbCtl, z, sourceSelect,
805 pAstCfg->xDec[z].decodeControl.frameLength,
806 0, pAfWrt);
807 if (errno)
808 {
809 SW_BREAKPOINT; // debug
810 }
811 // debug
812 cbLog(pCbCtl, z, 1, "cbInitSourceSel");
814 // Perform Dec Decode1 Init-Sync
815 // - Set Dec Decode1 decoder stage flag
816 outIsErrno = outIsWriteDecStageFlag(pOutIsCtl, z,
817 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, 1);
818 if (outIsErrno < 0)
819 {
820 SW_BREAKPOINT; // debug
821 }
823 outIsDecDecode1Flag = 1; // OutIS Dec Decode1 has executed
824 }
826 //
827 // Write decoder output audio frame to circular buffer
828 //
830 // debug
831 //pCb = &pAstCfg->xDecOpCb[z];
832 //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
834 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99); // debug
835 cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
836 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
837 if ((cbErrno < 0) &&
838 (cbErrno != ASP_DECOP_CB_AF_WRITE_OVERFLOW) &&
839 (cbErrno != ASP_DECOP_CB_PCM_WRITE_OVERFLOW))
840 {
841 gCbWrtAfErrCnt++;
842 //SW_BREAKPOINT; // debug
843 }
845 // Handle circular buffer overflows
846 if ((cbErrno == ASP_DECOP_CB_AF_WRITE_OVERFLOW) ||
847 (cbErrno == ASP_DECOP_CB_PCM_WRITE_OVERFLOW))
848 {
849 gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
850 if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
851 {
852 gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
853 gDecOpCbWrtAfOvr = 0; // reset overflow count
855 // Reset circular buffer
856 cbReset(pCbCtl, z);
857 gSlaveCbResetCnt++; // increment slave circular buffer reset count
858 Log_info0("ASDT:cbReset");
859 }
860 }
861 else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
862 {
863 // No overflow detected.
864 // update max overflow count,
865 // reset overflow count
867 if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
868 {
869 gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
870 }
871 gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
873 cbErrno = 0; // don't return error condition
874 }
875 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
876 TRACE_TERSE0("Dec:cbWriteAf() complete");
878 #if 0 // (***) FL: shows timing of CB write
879 // (***) debug // B9
880 {
881 static Uint8 toggleState = 0;
882 if (toggleState == 0)
883 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
884 else
885 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
886 toggleState = ~(toggleState);
887 }
888 #endif
890 // Log circular buffer control variables (debug)
891 cbLog(pCbCtl, z, 1, "cbWriteAf");
892 }
894 // write back Dec configuration
895 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
896 Cache_wait();
898 #ifdef NON_CACHE_STATUS
899 statusOp_read(&(temp8),
900 &(pAstCfg->xDec[z].decodeStatus.mode),
901 sizeof(Int8),
902 GATEMP_INDEX_DEC);
903 // Re-initialize audio frame if decoder is disabled or
904 // doesn't have a valid input
905 if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
906 {
907 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
908 }
909 #else
910 // Re-initialize audio frame if decoder is disabled or
911 // doesn't have a valid input
912 if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
913 {
914 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
915 }
916 #endif
917 // send dec info complete message to master
918 queId = MessageQ_getReplyQueue(pAspMsg);
919 pAspMsg->procId = hAspMsgSlave->slaveProcId;
920 pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
921 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
922 argIdx = 0; // set decErrno
923 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
924 argIdx += sizeof(Int32); // set cbErrno
925 *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;
926 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
927 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
928 if (status != MessageQ_S_SUCCESS)
929 {
930 SW_BREAKPOINT;
931 }
933 break;
935 case ASP_SLAVE_DEC_DEACTIVATE:
936 gSlaveDecDeactivateCnt++;
938 argIdx = 0; // get decIdx
939 z = *(Int32 *)&pAspMsg->buf[argIdx];
940 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
942 if (alg[z]->fxns->algDeactivate)
943 {
944 alg[z]->fxns->algDeactivate(alg[z]);
945 }
947 // Stop writes to circular buffer
948 cbErrno = cbWriteStop(pCbCtl, z);
949 if (cbErrno < 0)
950 {
951 SW_BREAKPOINT; // debug
952 }
953 // Log circular buffer control variables (debug)
954 cbLog(pCbCtl, z, 1, "cbWriteStop");
956 // Reset Output Init-Sync decoder stage flags
957 outIsErrno = outIsResetDecStageFlags(pOutIsCtl, z);
958 if (outIsErrno < 0)
959 {
960 SW_BREAKPOINT; // debug
961 }
963 // send dec deactivate complete message to master
964 queId = MessageQ_getReplyQueue(pAspMsg);
965 pAspMsg->procId = hAspMsgSlave->slaveProcId;
966 pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
967 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
968 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
969 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
970 if (status != MessageQ_S_SUCCESS)
971 {
972 SW_BREAKPOINT;
973 }
975 break;
977 default:
978 TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
979 break;
980 }
981 }
982 }
984 Log_info0("exit taskAsdpFxn()");
985 }
988 // -----------------------------------------------------------------------------
989 // AST Initialization Function - Memory Allocation
990 //
991 // Name: PAF_AST_initPhaseMalloc
992 // Purpose: Audio Stream Task Function for initialization of data pointers
993 // by allocation of memory.
994 // From: audioStream1Task or equivalent
995 // Uses: See code.
996 // States: x
997 // Return: 0 on success.
998 // Source code line number on MEM_calloc failure.
999 // Trace: Message Log "trace" in Debug Project Configuration reports:
1000 // * State information as per parent.
1001 // * Memory allocation errors.
1002 //
1003 Int
1004 PAF_ASDT_initPhaseMalloc(
1005 const PAF_ASDT_Params *pP,
1006 const PAF_ASDT_Patchs *pQ,
1007 PAF_ASDT_Config *pAsdtCfg
1008 )
1009 {
1010 PAF_AST_Config *pAstCfg;
1011 Int as; /* Audio Stream Number (1, 2, etc.) */
1012 Int zMS;
1013 Error_Block eb;
1015 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1016 as = pAstCfg->as;
1017 zMS = pAstCfg->masterStr;
1019 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1021 // Initialize error block
1022 Error_init(&eb);
1024 if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL,
1025 DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
1026 {
1027 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1028 SW_BREAKPOINT;
1029 return __LINE__;
1030 }
1031 TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
1032 DECODEN * sizeof (PAF_AudioFrame),
1033 HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
1035 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1036 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1037 return 0;
1038 } //PAF_ASDT_initPhaseMalloc
1040 // -----------------------------------------------------------------------------
1041 // AST Initialization Function - Memory Initialization from Configuration
1042 //
1043 // Name: PAF_AST_initPhaseConfig
1044 // Purpose: Audio Stream Task Function for initialization of data values
1045 // from parameters.
1046 // From: audioStream1Task or equivalent
1047 // Uses: See code.
1048 // States: x
1049 // Return: 0 on success.
1050 // Other as per initFrame0 and initFrame1.
1051 // Trace: Message Log "trace" in Debug Project Configuration reports:
1052 // * State information as per parent.
1053 //
1055 Int
1056 PAF_ASDT_initPhaseConfig(
1057 const PAF_ASDT_Params *pP,
1058 const PAF_ASDT_Patchs *pQ,
1059 PAF_ASDT_Config *pAsdtCfg
1060 )
1061 {
1062 PAF_AST_Config *pAstCfg;
1063 Int as; /* Audio Stream Number (1, 2, etc.) */
1064 Int zMS;
1065 Int z;
1067 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1068 as = pAstCfg->as;
1069 zMS = pAstCfg->masterStr;
1071 TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1073 // overwrite pointer to audio frame in framework decode control
1074 for (z=DECODE1; z < DECODEN; z++)
1075 {
1076 //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
1077 //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1078 //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1079 pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
1080 pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
1081 pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
1082 pP->fxns->initFrame0(pP, pQ, pAsdtCfg, z);
1083 }
1085 return 0;
1086 } //PAF_ASDT_initPhaseConfig
1088 // -----------------------------------------------------------------------------
1089 // AST Initialization Function - ACP Algorithm Instantiation
1090 //
1091 // Name: PAF_AST_initPhaseAcpAlg
1092 // Purpose: Audio Stream Task Function for initialization of ACP by
1093 // instantiation of the algorithm.
1094 // From: audioStream1Task or equivalent
1095 // Uses: See code.
1096 // States: x
1097 // Return: 0 on success.
1098 // Source code line number on ACP Algorithm creation failure.
1099 // Trace: Message Log "trace" in Debug Project Configuration reports:
1100 // * State information as per parent.
1101 // * Memory allocation errors.
1102 //
1103 Int
1104 PAF_ASDT_initPhaseAcpAlg(
1105 const PAF_ASDT_Params *pP,
1106 const PAF_ASDT_Patchs *pQ,
1107 PAF_ASDT_Config *pAsdtCfg
1108 )
1109 {
1110 PAF_AST_Config *pAstCfg;
1111 Int as; /* Audio Stream Number (1, 2, etc.) */
1112 Int z; /* input/encode/stream/decode/output counter */
1113 Int betaPrimeOffset;
1114 ACP_Handle acp;
1115 Int zMS;
1116 Int zS; //, zX;
1118 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1119 as = pAstCfg->as;
1120 zMS = pAstCfg->masterStr;
1122 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1124 ACP_MDS_init();
1126 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1127 {
1128 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1129 return __LINE__;
1130 }
1131 pAsdtCfg->acp = acp;
1133 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
1134 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1136 for (z=DECODE1; z < DECODEN; z++)
1137 {
1138 zS = pP->streamsFromDecodes[z];
1139 acp->fxns->attach(acp, ACP_SERIES_STD,
1140 STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1141 (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
1142 /* Ignore errors, not reported. */
1143 }
1145 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1147 return 0;
1148 } //PAF_AST_initPhaseAcpAlg
1150 // -----------------------------------------------------------------------------
1151 // AST Initialization Function - Common Memory and Algorithms
1152 //
1153 // Name: PAF_AST_initPhaseCommon
1154 // Purpose: Audio Stream Task Function for initialization of data pointers
1155 // by allocation for common memory and by instantiation for
1156 // algorithms.
1157 // From: audioStream1Task or equivalent
1158 // Uses: See code.
1159 // States: x
1160 // Return: 0 on success.
1161 // Source code line number on PAF_ALG_alloc failure.
1162 // Source code line number on PAF_ALG_mallocMemory failure.
1163 // Source code line number on Decode Chain initialization failure.
1164 // Source code line number on ASP Chain initialization failure.
1165 // Source code line number on Encode Chain initialization failure.
1166 // Trace: Message Log "trace" in Debug Project Configuration reports:
1167 // * State information as per parent.
1168 // * Memory allocation errors.
1169 //
1171 #include <pafsio_ialg.h>
1173 Int
1174 PAF_ASDT_initPhaseCommon(
1175 const PAF_ASDT_Params *pP,
1176 const PAF_ASDT_Patchs *pQ,
1177 PAF_ASDT_Config *pAsdtCfg
1178 )
1179 {
1180 PAF_AST_Config *pAstCfg;
1181 Int as; /* Audio Stream Number (1, 2, etc.) */
1182 Int z; /* stream counter */
1183 //Int g; /* gear */
1184 ACP_Handle acp;
1185 PAF_IALG_Config pafAlgConfig;
1186 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1188 acp = pAsdtCfg->acp; // get acp handle
1189 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1190 as = pAstCfg->as;
1192 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
1194 //
1195 // Determine memory needs and instantiate algorithms across audio streams
1196 //
1198 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
1199 PAF_ALG_setup(&pafAlgConfig,
1200 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1201 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1202 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1203 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1204 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1205 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1206 HEAP_CLEAR);
1208 if (pP->fxns->headerPrint)
1209 pP->fxns->headerPrint();
1211 for (z=STREAM1; z < STREAMN; z++)
1212 {
1213 //Int zD, zE, zX;
1214 Int zD, zX;
1216 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
1218 //
1219 // Determine common memory needs of Decode Algorithms
1220 //
1221 PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
1223 zD = -1;
1224 for (zX = DECODE1; zX < DECODEN; zX++)
1225 {
1226 if (pP->streamsFromDecodes[zX] == z)
1227 {
1228 zD = zX;
1229 break;
1230 }
1231 }
1233 if (zD >= 0)
1234 {
1235 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
1236 if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z]))
1237 {
1238 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1239 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1241 SW_BREAKPOINT;
1242 return __LINE__;
1243 }
1244 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1245 if(pP->fxns->allocPrint)
1246 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1247 }
1249 #if 0 // FL: master
1250 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1251 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1252 if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z]))
1253 {
1254 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1255 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1256 SW_BREAKPOINT;
1257 return __LINE__;
1258 }
1259 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1260 if(pP->fxns->allocPrint)
1261 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1262 #endif
1264 }
1265 {
1266 // Changes made to share scratch between zones
1267 // Assume maximum 3 zones and scratch common memory is at offset 0;
1268 int max=0;
1269 for (z=STREAM1; z < STREAMN; z++)
1270 {
1271 if (max<common[z][0].size)
1272 max=common[z][0].size;
1273 }
1274 common[STREAM1][0].size=max;
1275 for (z=STREAM1+1; z < STREAMN; z++)
1276 common[z][0].size=0;
1277 }
1279 //
1280 // Provide common memory needs of Decode Algorithms
1281 //
1282 for (z=STREAM1; z < STREAMN; z++)
1283 {
1284 //Int zD, zE, zX;
1285 Int zD, zX;
1287 zD = -1;
1288 for (zX = DECODE1; zX < DECODEN; zX++)
1289 {
1290 if (pP->streamsFromDecodes[zX] == z)
1291 {
1292 zD = zX;
1293 break;
1294 }
1295 }
1297 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1298 if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig))
1299 {
1300 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1301 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1302 SW_BREAKPOINT;
1303 return __LINE__;
1304 }
1305 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1306 // share zone0 scratch with all zones
1307 common[z][0].base=common[0][0].base;
1308 if (pP->fxns->commonPrint)
1309 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1311 //
1312 // Instantiate Decode Algorithms
1313 //
1314 if (zD >= 0)
1315 {
1316 PAF_ASP_Chain *chain;
1317 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1318 chain =
1319 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1320 HEAP_INTERNAL, as+z, acp, &trace,
1321 decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1322 if (!chain)
1323 {
1324 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1325 return __LINE__;
1326 }
1327 }
1329 #if 0 // FL: master
1330 pC->xStr[z].aspChain[0] = NULL;
1331 for (g=0; g < GEARS; g++)
1332 {
1333 PAF_ASP_Chain *chain;
1334 TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1335 chain =
1336 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1337 HEAP_INTERNAL, as+z, acp, &trace,
1338 aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1339 if (! chain)
1340 {
1341 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1342 return __LINE__;
1343 }
1344 else
1345 pC->xStr[z].aspChain[g] = chain;
1346 }
1347 #endif
1349 }
1350 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1352 return 0;
1353 } //PAF_ASDT_initPhaseCommon
1355 // -----------------------------------------------------------------------------
1356 // AST Initialization Function - Algorithm Keys
1357 //
1358 // Name: PAF_AST_initPhaseAlgKey
1359 // Purpose: Audio Stream Task Function for initialization of data values
1360 // from parameters for Algorithm Keys.
1361 // From: audioStream1Task or equivalent
1362 // Uses: See code.
1363 // States: x
1364 // Return: 0.
1365 // Trace: Message Log "trace" in Debug Project Configuration reports:
1366 // * State information as per parent.
1367 //
1368 // .............................................................................
1369 Int
1370 PAF_ASDT_initPhaseAlgKey(
1371 const PAF_ASDT_Params *pP,
1372 const PAF_ASDT_Patchs *pQ,
1373 PAF_ASDT_Config *pAsdtCfg
1374 )
1375 {
1376 PAF_AST_Config *pAstCfg;
1377 Int as; /* Audio Stream Number (1, 2, etc.) */
1378 Int z; /* decode/encode counter */
1379 Int s; /* key number */
1380 PAF_ASP_Link *that;
1382 (void)as; // clear warning.
1384 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1385 as = pAstCfg->as;
1387 TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1389 for (z=DECODE1; z < DECODEN; z++)
1390 {
1391 for (s=0; s < pP->pDecAlgKey->length; s++)
1392 {
1393 if ((pP->pDecAlgKey->code[s].full != 0)
1394 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1395 {
1396 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1397 /* Cast in interface, for now --Kurt */
1398 }
1399 else
1400 pAstCfg->xDec[z].decAlg[s] = NULL;
1401 }
1402 }
1404 return 0;
1405 } //PAF_AST_initPhaseAlgKey
1407 // Purpose: Audio Stream Decode Task Function for initialization of the Audio
1408 // Frame(s) by memory allocation and loading of data pointers
1409 // and values.
1410 Int
1411 PAF_ASDT_initFrame0(
1412 const PAF_ASDT_Params *pP,
1413 const PAF_ASDT_Patchs *pQ,
1414 PAF_ASDT_Config *pAsdtCfg,
1415 Int z
1416 )
1417 {
1418 PAF_AST_Config *pAstCfg;
1419 Int as; /* Audio Stream Number (1, 2, etc.) */
1420 Int aLen;
1421 Int aSize = sizeof(PAF_AudioData);
1422 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1423 Int maxFrameLength = pP->maxFramelength;
1424 PAF_AudioData *aBuf=NULL;
1425 XDAS_UInt8 *metadataBuf;
1426 Error_Block eb;
1427 PAF_AudioFrame *pAudioFrame;
1428 Int i;
1430 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1431 as = pAstCfg->as;
1433 pAudioFrame = &gpDecAudioFrame[z];
1434 if (pAudioFrame == NULL)
1435 {
1436 SW_BREAKPOINT;
1437 }
1439 // Initialize error block
1440 Error_init(&eb);
1442 //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1443 //aLen = numchan[z] * maxFrameLength;
1444 aLen = numchan[z] * maxFrameLength + (maxFrameLength - FRAMELENGTH); /* Qin - need additional memory for starting offset
1445 See line 1301 */
1447 //
1448 // Initialize audio frame elements directly
1449 //
1450 pAudioFrame->fxns = pP->pAudioFrameFunctions;
1451 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1452 pAudioFrame->data.nSamples = FRAMELENGTH;
1453 pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1454 pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1455 pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1457 //
1458 // Allocate memory for and initialize pointers to audio data buffers
1459 //
1460 // The NUMCHANMASK is used to identify the channels for which data
1461 // buffers can be allocated. Using this mask and switch statement
1462 // rather than some other construct allows efficient code generation,
1463 // providing just the code necessary (with significant savings).
1464 //
1465 if (pP->fxns->bufMemPrint)
1466 {
1467 pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1468 }
1470 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1472 if (aLen != 0)
1473 {
1474 if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1475 {
1476 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1477 TRACE_TERSE2(" maxFrameLength: %d. aLen*aSize: %d", maxFrameLength, aLen*aSize);
1478 SW_BREAKPOINT;
1479 return __LINE__;
1480 }
1481 }
1483 TRACE_TERSE3(" maxFrameLength: %d. aLen*aSize: %d. aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1485 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1486 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1487 {
1488 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1489 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1490 SW_BREAKPOINT;
1491 return __LINE__;
1492 }
1494 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1495 {
1496 gDecAudioFrameChannelPointers[i] = NULL;
1497 }
1499 if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1500 {
1501 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1502 return __LINE__;
1503 }
1504 else
1505 {
1506 Int j = 0;
1507 TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1508 for (i=0; i<numchan[z]; i++)
1509 {
1510 Int8 chan = AFChanPtrMap[numchan[z]][i];
1511 if (chan != -1)
1512 {
1513 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1514 j++;
1515 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1516 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1517 }
1518 }
1519 }
1521 // Initialize original audio frame channel pointers
1522 for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++)
1523 {
1524 if (gDecAudioFrameChannelPointers[i])
1525 {
1526 gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1527 }
1528 }
1530 //
1531 // Initialize meta data elements
1532 //
1533 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1534 pAudioFrame->numPrivateMetadata = 0;
1535 pAudioFrame->bsMetadata_offset = 0;
1536 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1537 pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1538 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1539 {
1540 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1541 pAudioFrame->pafPrivateMetadata[i].size = 0;
1542 pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1543 }
1545 return 0;
1546 } //PAF_ASDT_initFrame0
1548 // -----------------------------------------------------------------------------
1549 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1550 // AST Decoding Function - Reinitialization of Audio Frame
1551 //
1552 // Name: PAF_ASOT_initFrame1
1553 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1554 // zation of the Audio Frame(s) by loading of data values of a
1555 // time-varying nature.
1556 // From: audioStream1Task or equivalent
1557 // AST Parameter Function -> decodeInfo
1558 // AST Parameter Function -> decodeDecode
1559 // Uses: See code.
1560 // States: x
1561 // Return: 0.
1562 // Trace: None.
1563 //
1564 Int
1565 PAF_ASDT_initFrame1(
1566 const PAF_ASDT_Params *pP,
1567 const PAF_ASDT_Patchs *pQ,
1568 PAF_ASDT_Config *pAsdtCfg,
1569 Int z,
1570 Int apply
1571 )
1572 {
1573 PAF_AudioFrame *pAudioFrame;
1575 //
1576 // Reinitialize audio frame elements:
1577 //
1578 // Channel Configurations during sys init = Unknown
1579 // " " during info or decode = None
1580 //
1581 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1582 //
1584 pAudioFrame = &gpDecAudioFrame[z];
1586 if (apply < 0)
1587 {
1588 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1589 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1590 }
1591 else
1592 {
1593 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1594 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1595 }
1597 if (apply < 1)
1598 {
1599 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1600 pAudioFrame->sampleCount = 0;
1601 }
1603 return 0;
1604 } //PAF_ASDT_initFrame1
1606 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1607 Int resetAf(
1608 const PAF_ASDT_Params *pP,
1609 Int z,
1610 Int sourceSelect
1611 )
1612 {
1613 PAF_AudioFrame *pAudioFrame;
1614 Int ch;
1615 Int i;
1617 // Get audio frame
1618 pAudioFrame = &gpDecAudioFrame[z];
1619 if (pAudioFrame == NULL)
1620 {
1621 SW_BREAKPOINT;
1622 }
1624 // Reinitialize audio frame elements
1625 pAudioFrame->sampleDecode = PAF_SOURCE_UNKNOWN;
1626 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1627 pAudioFrame->sampleCount = 0;
1628 pAudioFrame->channelConfigurationRequest.full = PAF_CC_UNKNOWN;
1629 pAudioFrame->channelConfigurationStream.full = PAF_CC_UNKNOWN;
1631 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1632 switch (sourceSelect)
1633 {
1634 case PAF_SOURCE_PCM:
1635 pAudioFrame->data.nSamples = FRAMELENGTH;
1636 break;
1637 case PAF_SOURCE_AC3:
1638 case PAF_SOURCE_DDP:
1639 pAudioFrame->data.nSamples = 1536;
1640 break;
1641 case PAF_SOURCE_THD:
1642 pAudioFrame->data.nSamples = 5120; //QIN FIX ME
1643 break;
1644 default:
1645 pAudioFrame->data.nSamples = FRAMELENGTH;
1646 break;
1647 }
1649 // Reset audio frame channel pointers
1650 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1651 {
1652 if (gDecAudioFrameChannelPointers[ch])
1653 {
1654 gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1655 }
1656 }
1658 // Reset audio frame meta data elements
1659 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1660 pAudioFrame->numPrivateMetadata = 0;
1661 pAudioFrame->bsMetadata_offset = 0;
1662 pAudioFrame->bsMetadata_type = PAF_bsMetadata_none;
1663 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1664 {
1665 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1666 pAudioFrame->pafPrivateMetadata[i].size = 0;
1667 }
1669 return 0;
1670 }
1672 // Reset AF samsiz, invoked during DECODE
1673 Int resetAfSamsiz(
1674 Int z
1675 )
1676 {
1677 PAF_AudioFrame *pAudioFrame;
1678 Int ch;
1680 // Get audio frame
1681 pAudioFrame = &gpDecAudioFrame[z];
1682 if (pAudioFrame == NULL)
1683 {
1684 SW_BREAKPOINT;
1685 }
1687 // Clear samsiz for all channels - MID 208.
1688 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
1689 {
1690 pAudioFrame->data.samsiz[ch] = 0;
1691 }
1693 return 0;
1694 }
1696 // (***) FL: Check correct behavior for other decs, esp DTSHD & DXP
1697 // Check decoder sync using information in INFO audio frame
1698 static Int8 checkDecSync(
1699 PAF_AudioFrame *pAf
1700 )
1701 {
1702 if ((pAf->sampleDecode == PAF_SOURCE_THD) &&
1703 (pAf->sampleRate == PAF_SAMPLERATE_UNKNOWN))
1704 {
1705 return 0;
1706 }
1707 else
1708 {
1709 return 1;
1710 }
1711 }