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