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