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