2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamDecodeProc.c ========
38 */
40 #include <xdc/cfg/global.h>
41 #include <xdc/runtime/Error.h>
42 #include <xdc/runtime/Log.h>
43 #include <xdc/runtime/Memory.h>
44 #include <ti/sysbios/BIOS.h>
45 #include <ti/sysbios/hal/Cache.h>
46 #include <ti/sysbios/knl/Task.h>
47 #include <ti/ipc/Ipc.h>
48 #include <ti/ipc/MessageQ.h>
49 #include <ti/ipc/MultiProc.h>
51 #include <acp_mds.h>
52 #include <pcm.h>
53 #include "audioStreamProc_params.h"
54 #include "audioStreamProc_patchs.h"
55 #include "audioStreamProc_config.h"
57 #include "common.h"
58 #include "aspMsg_common.h"
59 #include "aspMsg_slave.h"
60 #include "aspDecOpCircBuf_slave.h"
61 #include "aspOutInitSync_slave.h"
62 #include "audioStreamProc_common.h"
63 #include "audioStreamDecodeProc.h"
64 #include "statusOp_common.h"
66 #include "pfp/pfp.h"
67 #include "pfp_app.h" /* contains all PFP ID's */
69 // FL: debug
70 #include "dbgCapAf.h"
71 #include "dbgDib.h"
72 #include "evmc66x_gpio_dbg.h"
74 //
75 // Decoder Definitions
76 //
77 #define decLinkInit pQ->i_decLinkInit
79 #define __TASK_NAME__ "TaskAsdp"
81 // Check decoder sync using information in INFO audio frame
82 static Int8 checkDecSync(
83 PAF_AudioFrame *pAf
84 );
86 extern struct {
87 Int size;
88 IALG_Status *pStatus[512];
89 } IACP_STD_BETA_TABLE;
91 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
92 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
94 LINNO_DEFN(TaskAsdp); /* Line number macros */
95 ERRNO_DEFN(TaskAsdp); /* Error number macros */
97 // ASDT configuration
98 PAF_ASDT_Config gPAF_ASDT_config
99 __attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
100 NULL, // taskHandle
101 NULL, // acp
102 {NULL, 0, NULL}, // decOpCircBufCtl
103 {NULL, NULL}, // outIsCtl
104 &gPAF_AST_config // ASIT/ASOT/ASDT shared configuration
105 };
107 PAF_AudioFrame *gpDecAudioFrame=NULL;
108 PAF_AudioData *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
109 PAF_AudioSize gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
110 PAF_AudioData *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
112 // Overflow threshold before circular buffer reset and return error to Top-Level FSM
113 #define DEC_OP_CB_WRTAF_OVR_THR ( 20 ) // FL: arbitrary setting
114 UInt32 gCbWrtAfErrCnt =0; // decoder output circular buffer write error count, not including overflows
115 UInt32 gDecOpCbWrtAfOvr =0; // decoder output circular buffer overflow count
116 UInt32 gMaxDecOpCbWrtAfOvr =0; // max (consecutive) decoder output circular buffer overflow count
117 UInt32 gSlaveCbResetCnt =0; // slave circular buffer reset count
119 // Global debug counters */
120 UInt32 gSlaveStartErrCnt =0;
121 UInt32 gSlaveStartCnt =0;
122 UInt32 gSlaveSourceSelectCnt =0;
123 UInt32 gSlaveExitCnt =0;
124 UInt32 gSlaveDecExitCnt =0;
125 UInt32 gSlaveDecControlCnt =0;
126 UInt32 gSlaveDecActivateCnt =0;
127 UInt32 gSlaveDecResetCnt =0;
128 UInt32 gSlaveDecInfoCnt =0;
129 UInt32 gSlaveDecDecodeCnt =0;
130 UInt32 gSlaveDecDeactivateCnt =0;
133 //#define CAPTURE_DECODER_OUTSAMPLES_PP
134 #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
136 #define CAP_FRAME_MAX 2000
137 Uint32 tempCap_frameCnt = 0;
138 int tempCap_decSampleOut[CAP_FRAME_MAX] = {0};
139 #endif
141 // debug
142 PAF_AudioFrame gDecInfoAfCap1[20];
143 UInt8 gDecInfoAfCap1Idx=0;
144 PAF_AudioFrame gDecInfoAfCap2[20];
145 UInt8 gDecInfoAfCap2Idx=0;
147 PAF_AudioFrame gDecDecodeAfCap1[20];
148 UInt8 gDecDecodeAfCap1Idx=0;
149 PAF_AudioFrame gDecDecodeAfCap2[20];
150 UInt8 gDecDecodeAfCap2Idx=0;
153 /*
154 * ======== taskAsdpFxn ========
155 * Audio Stream Decode Processing task function
156 */
157 Void taskAsdpFxn(
158 // Int betaPrimeValue, // FL: revisit
159 const PAF_ASDT_Params *pP,
160 const PAF_ASDT_Patchs *pQ
161 )
162 {
163 PAF_ASDT_Config *pAsdtCfg; // ASDT configuration pointer
164 PAF_AST_Config *pAstCfg; // Common (shared) configuration pointer
165 Int as; // Audio Stream Number (1, 2, etc.)
166 Int z; // input/encode/stream/decode/output counter
167 Int i; // phase
168 Int zMD, zMS;
169 Bool done;
170 Bool decDone;
171 ALG_Handle alg[DECODEN_MAX];
172 ASP_Slave_Cmd slaveCmd;
173 Int sourceSelect;
174 DEC_Handle dec;
175 IALG_Cmd decCtrlCmd; // decoder control command
176 Int decCtrlRet; // decoder control return
177 Int errno; // error number
178 Int size;
179 Int argIdx;
180 // Decoder output circular buffer
181 PAF_AST_DecOpCircBufCtl *pCbCtl; // Decoder output Circular Buffer control
182 PAF_AudioFrame *pAfWrt; // pointer to audio frame written to CB
183 Int cbErrno; // CB error number
184 // Output Init-Sync
185 PAF_AudioFrame *pDecCtrlAf; // pointer to Dec Control audio frame
186 PAF_AST_OutInitSyncCtl *pOutIsCtl; // OutIS control
187 Int8 outIsDecInfo1Flag; // indicates whether Dec Info Init-Sync has executed
188 Int8 outIsDecDecode1Flag; // indicates whether Dec Decode1 Init-Sync has executed
189 Int outIsErrno; // OutIS error number
190 // Messaging
191 PAF_InpBufConfig *pIpBufConfig; // IB buffer configuration
192 ASP_Msg *pAspMsg; // Rx/Tx MessageQ message
193 MessageQ_QueueId queId; // MessageQ ID
194 Int status;
195 Int zI;
196 Int bufEnd, wrapSize, currentBufSize, chunkSize;
197 Int8 temp8;
199 Log_info0("Enter taskAsdpFxn()");
202 //
203 // Audio Framework Parameters & Patch (*pP, *pQ):
204 //
205 if (!pP)
206 {
207 TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
208 LINNO_RPRT(TaskAsdp, -1);
209 return;
210 }
212 if (!pQ)
213 {
214 TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
215 LINNO_RPRT(TaskAsdp, -1);
216 return;
217 }
219 //
220 // Audio Stream Decode Task Configuration (*pAsdtCfg):
221 //
222 pAsdtCfg = &gPAF_ASDT_config; // initialize pointer to task configuration
223 pAsdtCfg->taskHandle = Task_self(); // set task handle
224 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
225 pCbCtl = &pAsdtCfg->decOpCircBufCtl; // get pointer to circular buffer control
226 pOutIsCtl = &pAsdtCfg->outIsCtl; // get pointer to output init-sync control
228 // wait for initialization message from master
229 do {
230 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
231 //TRACE_TERSE1("Rx ASP message: status=%d", status);
232 //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
233 } while (status != MessageQ_S_SUCCESS);
234 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
235 (pAspMsg->cmd != ASP_SLAVE_START))
236 {
237 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
238 SW_BREAKPOINT;
239 }
240 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
241 gSlaveStartCnt++;
242 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
244 // invalidate AST shared configuration
245 Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
246 Cache_wait();
248 // (***) FL: revisit
249 // invalidate Dec configuration for all Decoder zones
250 Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
251 Cache_wait();
253 // (***) FL: revisit
254 // invalidate Beta Table status pointers
255 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
256 Cache_wait();
258 /* Obtain Audio Stream Number (1, 2, etc.) */
259 as = pAstCfg->as;
260 TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
262 //
263 // Initialize message log trace and line number reporting
264 //
265 for (z=STREAM1; z < STREAMN; z++)
266 {
267 TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
268 }
269 LINNO_RPRT(TaskAsdp, -1);
271 // Get decoder and stream index associated with the master input
272 zMD = pAstCfg->masterDec;
273 zMS = pAstCfg->masterStr;
275 //
276 // Initialize per parameterized phases.
277 // - Malloc: Memory Allocation
278 // - Config: Configuration Initialization
279 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
280 // - Common: Common Algorithm Initialization
281 // - AlgKey: Dec/Enc chain to Array Initialization
282 // - Unused: (available)
283 // - Unused: (available)
284 // - Unused: (available)
285 //
286 LINNO_RPRT(TaskAsdp, -2);
287 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
288 {
289 Int linno;
290 if (pP->fxns->initPhase[i])
291 {
292 if ((linno = pP->fxns->initPhase[i](pP, pQ, pAsdtCfg)))
293 {
294 LINNO_RPRT(TaskAsdp, linno);
295 return;
296 }
297 }
298 else
299 {
300 TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
301 }
302 TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
303 LINNO_RPRT(TaskAsdp, -i-3);
304 }
306 #ifdef NON_CACHE_STATUS
307 //
308 // init Status structure Gate
309 //
310 if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
311 {
312 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DEC);
313 }
314 if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
315 {
316 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DDP);
317 }
318 if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
319 {
320 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_PCM);
321 }
322 if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
323 {
324 TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_THD);
325 }
326 #endif
328 //
329 // End of Initialization -- final memory usage report.
330 //
331 if (pP->fxns->memStatusPrint)
332 {
333 pP->fxns->memStatusPrint("ASDT MEMSTAT REPORT",
334 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
335 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
336 }
338 // (***) FL: revisit
339 // write back Status structure addresses for Beta Units initialized on Slave
340 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
341 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
342 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
343 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
344 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
345 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
346 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
347 Cache_wait();
349 // (***) FL: revisit
350 // write back Status structures for Beta Units initialized on Slave
351 /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
352 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
353 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
354 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
355 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
356 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
357 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
358 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
359 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
360 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
361 Cache_wait();
363 // (***) FL: revisit
364 // write back Dec configuration
365 Cache_wbInv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
366 Cache_wait();*/
368 // Send initialization complete message to master
369 queId = MessageQ_getReplyQueue(pAspMsg);
370 pAspMsg->procId = hAspMsgSlave->slaveProcId;
371 pAspMsg->cmd = ASP_MASTER_START_DONE;
372 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
373 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
374 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
375 if (status != MessageQ_S_SUCCESS)
376 {
377 SW_BREAKPOINT;
378 }
380 done = FALSE;
381 while (done==FALSE)
382 {
383 // wait for source select message from master
384 do {
385 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
386 } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
387 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
388 (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
389 {
390 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
391 SW_BREAKPOINT;
392 }
393 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
394 sourceSelect = *(Int32 *)&pAspMsg->buf[0];
395 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
396 TRACE_MSG1("sourceSelect=%d.", sourceSelect);
397 // send source select complete message to master
398 queId = MessageQ_getReplyQueue(pAspMsg);
399 pAspMsg->procId = hAspMsgSlave->slaveProcId;
400 pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
401 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
402 gSlaveSourceSelectCnt++;
403 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
404 MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
406 for (z=DECODE1; z < DECODEN; z++)
407 {
408 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
409 }
410 alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
412 // Reset IB capture buffer (debug)
413 //capIbReset();
414 //Log_info0("capIbReset()");
415 // Reset audio frame capture buffer (debug)
416 //capAfReset();
418 decDone = FALSE;
419 while (decDone==FALSE)
420 {
421 // wait for received message from master
422 do {
423 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
424 } while (status < 0);
425 if (pAspMsg->procId != hAspMsgSlave->masterProcId)
426 {
427 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
428 SW_BREAKPOINT;
429 }
430 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
431 slaveCmd = pAspMsg->cmd;
432 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
434 switch (slaveCmd)
435 {
436 case ASP_SLAVE_NULL:
437 case ASP_SLAVE_START:
438 gSlaveStartErrCnt++;
439 TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
441 break;
443 case ASP_SLAVE_EXIT:
444 gSlaveExitCnt++;
445 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
447 decDone = TRUE;
448 done = TRUE;
449 break;
451 case ASP_SLAVE_DEC_EXIT:
452 gSlaveDecExitCnt++;
453 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
455 // send dec exit complete message to master
456 queId = MessageQ_getReplyQueue(pAspMsg);
457 pAspMsg->procId = hAspMsgSlave->slaveProcId;
458 pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
459 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
460 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
461 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
462 if (status != MessageQ_S_SUCCESS)
463 {
464 SW_BREAKPOINT;
465 }
467 decDone=TRUE;
468 break;
470 case ASP_SLAVE_DEC_CONTROL:
471 gSlaveDecControlCnt++;
473 argIdx = 0; // get decIdx
474 z = *(Int32 *)&pAspMsg->buf[argIdx];
475 argIdx += sizeof(Int32);
476 decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
477 TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
479 decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
481 // send dec control complete message to master
482 queId = MessageQ_getReplyQueue(pAspMsg);
483 pAspMsg->procId = hAspMsgSlave->slaveProcId;
484 pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
485 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
486 argIdx = 0; // set decCtrlRet
487 *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
488 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
489 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
490 if (status != MessageQ_S_SUCCESS)
491 {
492 SW_BREAKPOINT;
493 }
495 break;
497 case ASP_SLAVE_DEC_ACTIVATE:
498 gSlaveDecActivateCnt++;
500 // (***) FL: revisit
501 // invalidate Status structures for shared Beta Units
502 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
503 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
504 /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
505 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
506 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
507 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
508 Cache_wait();*/
510 argIdx = 0; // get decIdx
511 z = *(Int32 *)&pAspMsg->buf[argIdx];
512 TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
514 // invalidate Dec configuration
515 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
516 Cache_wait();
518 if (alg[z]->fxns->algActivate)
519 {
520 alg[z]->fxns->algActivate(alg[z]);
521 }
523 // Start writes to circular buffer
524 cbErrno = cbWriteStart(pCbCtl, z);
525 if (cbErrno < 0)
526 {
527 SW_BREAKPOINT;
528 }
529 gCbWrtAfErrCnt=0; // reset write circular buffer error count
530 gDecOpCbWrtAfOvr=0; // reset decoder output circular buffer overflow count
531 gMaxDecOpCbWrtAfOvr=0; // reset max decoder output circular buffer overflow count
532 gSlaveCbResetCnt=0; // reset slave circular buffer reset count
533 // Log circular buffer control variables (debug)
534 cbLog(pCbCtl, z, 1, "cbWriteStart");
536 // Reset audio frame
537 resetAf(pP, z, sourceSelect);
539 // Initialize OutIS Dec flags
540 outIsDecInfo1Flag = 0; // OutIS Dec Info1 hasn't executed
541 outIsDecDecode1Flag = 0; // OutIS Dec Decode1 hasn't executed
543 // send dec activate complete message to master
544 queId = MessageQ_getReplyQueue(pAspMsg);
545 pAspMsg->procId = hAspMsgSlave->slaveProcId;
546 pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
547 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
548 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
549 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
550 if (status != MessageQ_S_SUCCESS)
551 {
552 SW_BREAKPOINT;
553 }
555 break;
557 case ASP_SLAVE_DEC_RESET:
558 gSlaveDecResetCnt++;
560 argIdx = 0; // get decIdx
561 z = *(Int32 *)&pAspMsg->buf[argIdx];
562 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
564 dec = (DEC_Handle)alg[z];
565 errno = 0;
566 if (dec->fxns->reset)
567 {
568 //
569 // Execute decode reset
570 //
571 errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
573 // Get pointer to Dec Reset output audio frame
574 pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
576 // Perform Dec Reset Init-Sync
577 // - Write Dec Reset output audio frame
578 // - Set Dec Reset decoder stage flag
579 outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z,
580 ASP_OUTIS_DEC_STAGE_RESET_IDX, 1, pDecCtrlAf);
581 if (outIsErrno < 0)
582 {
583 SW_BREAKPOINT; // debug
584 }
585 }
587 // write back Dec configuration
588 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
589 Cache_wait();
591 // (***) FL: revisit
592 // write back Status structures for shared Beta Units
593 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
594 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
595 /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
596 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
597 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
598 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
599 Cache_wait();*/
601 // send dec reset complete message to master
602 queId = MessageQ_getReplyQueue(pAspMsg);
603 pAspMsg->procId = hAspMsgSlave->slaveProcId;
604 pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
605 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
606 argIdx = 0; // set decErrno
607 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
608 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
609 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
610 if (status != MessageQ_S_SUCCESS)
611 {
612 SW_BREAKPOINT;
613 }
615 break;
617 case ASP_SLAVE_DEC_INFO:
618 gSlaveDecInfoCnt++;
620 argIdx = 0; // get decIdx
621 z = *(Int32 *)&pAspMsg->buf[argIdx];
622 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
623 // Get input associated w/ decoder
624 zI = pP->inputsFromDecodes[z];
626 // (***) FL: revisit
627 // invalidate Inp configuration
628 Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
629 Cache_wait();
630 // invalidate input data
631 pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
632 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
633 if (sourceSelect == PAF_SOURCE_PCM)
634 {
635 size *= pIpBufConfig->stride;
636 }
638 bufEnd = (Int) pIpBufConfig->base.pVoid + pIpBufConfig->sizeofBuffer;
639 currentBufSize = (bufEnd - (Int)pIpBufConfig->pntr.pSmInt);
640 if (currentBufSize >= size)
641 {
642 chunkSize = size;
643 }
644 else
645 {
646 chunkSize = currentBufSize;
647 }
648 wrapSize = size - chunkSize;
649 // invalidate input data
650 Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
651 // invalidate Dec configuration
652 TRACE_MSG2("IBUF : pIpBufConfig->pntr.pSmInt: 0x%x and chunkSize: %d", (IArg)pIpBufConfig->pntr.pSmInt, chunkSize);
653 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
654 // status for selected decoder should be invalidated
655 Cache_wait();
657 /* Circular buffer wrap condition*/
658 //if(((Int) pIpBufConfig->head.pVoid + size) > bufEnd)
659 if(wrapSize > 0)
660 {
661 // invalidate input data
662 Cache_inv((Ptr)pIpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
663 TRACE_MSG2("IBUF : pIpBufConfig->base.pSmInt: 0x%x and wrapSize: %d", (IArg)pIpBufConfig->base.pSmInt, wrapSize);
664 // status for selected decoder should be invalidated
665 Cache_wait();
666 }
667 /* Circular buffer wrap condition */
669 dec = (DEC_Handle)alg[z];
670 errno = 0;
671 if (dec->fxns->info)
672 {
673 // debug
674 if (gDecInfoAfCap1Idx < 20)
675 {
676 gDecInfoAfCap1[gDecInfoAfCap1Idx] = *pAstCfg->xDec[z].decodeControl.pAudioFrame;
677 gDecInfoAfCap1Idx++;
678 }
680 //
681 // Execute decode info
682 //
683 pfpBegin(PFP_ID_ASDT_1, pAsdtCfg->taskHandle);
684 errno = dec->fxns->info(dec, NULL,
685 &pAstCfg->xDec[z].decodeControl,
686 &pAstCfg->xDec[z].decodeStatus);
687 pfpEnd(PFP_ID_ASDT_1, PFP_FINISH_MEAS);
689 // debug
690 if (gDecInfoAfCap2Idx < 20)
691 {
692 gDecInfoAfCap2[gDecInfoAfCap2Idx] = *pAstCfg->xDec[z].decodeControl.pAudioFrame;
693 gDecInfoAfCap2Idx++;
694 }
696 // debug
697 //if (outIsDecInfo1Flag < 10)
698 // outIsDecInfo1Flag++;
699 //if (outIsDecInfo1Flag == 10)
701 //
702 // Execute Dec Info1 Init-Sync if required
703 //
704 if (outIsDecInfo1Flag == 0)
705 {
706 // Get pointer to Dec Info1 output audio frame
707 pDecCtrlAf = pAstCfg->xDec[z].decodeControl.pAudioFrame;
709 if (checkDecSync(pDecCtrlAf) == 1)
710 {
711 // Perform Dec Info1 Init-Sync
712 // - Write Dec Info1 output audio frame
713 // - Set Dec Info1 decoder stage flag
714 outIsErrno = outIsWriteDecStageFlagAndAf(pOutIsCtl, z,
715 ASP_OUTIS_DEC_STAGE_INFO1_IDX, 1, pDecCtrlAf);
716 if (outIsErrno < 0)
717 {
718 SW_BREAKPOINT; // debug
719 }
721 outIsDecInfo1Flag = 1; // OutIS Dec Info1 has executed
722 }
723 }
724 }
726 // write back Dec configuration
727 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
728 Cache_wait();
730 #ifdef NON_CACHE_STATUS
731 statusOp_read(&(temp8),
732 &(pAstCfg->xDec[z].decodeStatus.mode),
733 sizeof(Int8),
734 GATEMP_INDEX_DEC);
735 // Re-initialize audio frame if decoder is disabled or
736 // doesn't have a valid input
737 if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
738 {
739 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
740 }
741 #else
742 // Re-initialize audio frame if decoder is disabled or
743 // doesn't have a valid input
744 if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
745 {
746 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
747 }
748 #endif
750 // send dec info complete message to master
751 queId = MessageQ_getReplyQueue(pAspMsg);
752 pAspMsg->procId = hAspMsgSlave->slaveProcId;
753 pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
754 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
755 argIdx = 0; // set decErrno
756 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
757 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
758 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
759 if (status != MessageQ_S_SUCCESS)
760 {
761 SW_BREAKPOINT;
762 }
764 break;
766 case ASP_SLAVE_DEC_DECODE:
767 gSlaveDecDecodeCnt++;
769 argIdx = 0; // get decIdx
770 z = *(Int32 *)&pAspMsg->buf[argIdx];
771 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
772 // Get input associated w/ decoder
773 zI = pP->inputsFromDecodes[z];
775 // Reset AF samsiz
776 resetAfSamsiz(z);
778 // Invalidate Dec configuration
779 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
780 Cache_wait();
781 //TRACE_TERSE0("Dec:cache wb done");
783 dec = (DEC_Handle)alg[z];
784 //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
786 errno = 0;
787 cbErrno = 0;
788 if (dec->fxns->decode)
789 {
790 // Capture input buffer (debug)
791 //capIb(pAstCfg->xInp[z].pInpBuf);
793 // debug
794 if (gDecDecodeAfCap1Idx < 20)
795 {
796 gDecDecodeAfCap1[gDecDecodeAfCap1Idx] = *pAstCfg->xDec[z].decodeInStruct.pAudioFrame;
797 gDecDecodeAfCap1Idx++;
798 }
800 //
801 // Execute decode
802 //
803 pfpBegin(PFP_ID_ASDT_2, pAsdtCfg->taskHandle);
804 errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
805 pfpEnd(PFP_ID_ASDT_2, PFP_FINISH_MEAS);
806 if (errno < 0)
807 {
808 //SW_BREAKPOINT;
809 }
810 TRACE_TERSE0("Dec:decode done");
812 // debug
813 if (gDecDecodeAfCap2Idx < 20)
814 {
815 gDecDecodeAfCap2[gDecDecodeAfCap2Idx] = *pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
816 gDecDecodeAfCap2Idx++;
817 }
819 // Get pointer to Dec Decode output audio frame
820 pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
821 TRACE_TERSE2("Dec:pAfWrt=0x%04x, nSamples=%d", (IArg)pAfWrt, pAfWrt->data.nSamples);
823 // Capture audio frame (debug)
824 //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
825 //{
826 // Log_info0("capAfWrite() error");
827 //}
829 #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
830 if (tempCap_frameCnt < CAP_FRAME_MAX)
831 {
832 tempCap_decSampleOut[tempCap_frameCnt] = pAfWrt->sampleCount;
833 tempCap_frameCnt++;
834 }
835 #endif
837 //
838 // Execute Dec Decode1 Init-Sync if required
839 //
840 if (outIsDecDecode1Flag == 0)
841 {
842 //
843 // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
844 // frameLength: changed to decodeControl.frameLength.
845 // Written by ASIT:decodeInit:getFrameLengthSourceSel().
847 // Initialize decoder output circular buffer
848 errno = cbInitDecWrite(pCbCtl, z, sourceSelect,
849 pAstCfg->xDec[z].decodeControl.frameLength,
850 0, pAfWrt);
851 if (errno)
852 {
853 SW_BREAKPOINT; // debug
854 }
855 // debug
856 cbLog(pCbCtl, z, 1, "cbInitSourceSel");
858 // Perform Dec Decode1 Init-Sync
859 // - Set Dec Decode1 decoder stage flag
860 outIsErrno = outIsWriteDecStageFlag(pOutIsCtl, z,
861 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, 1);
862 if (outIsErrno < 0)
863 {
864 SW_BREAKPOINT; // debug
865 }
867 outIsDecDecode1Flag = 1; // OutIS Dec Decode1 has executed
868 }
870 //
871 // Write decoder output audio frame to circular buffer
872 //
874 // debug
875 //pCb = &pAstCfg->xDecOpCb[z];
876 //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
878 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99); // debug
879 cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
880 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
881 if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
882 {
883 gCbWrtAfErrCnt++;
884 //SW_BREAKPOINT; // debug
885 }
887 // Handle circular buffer overflows
888 if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
889 {
890 gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
891 if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
892 {
893 gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
894 gDecOpCbWrtAfOvr = 0; // reset overflow count
896 // Reset circular buffer
897 cbReset(pCbCtl, z);
898 gSlaveCbResetCnt++; // increment slave circular buffer reset count
899 Log_info0("ASDT:cbReset");
900 }
901 }
902 else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
903 {
904 // No overflow detected.
905 // update max overflow count,
906 // reset overflow count
908 if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
909 {
910 gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
911 }
912 gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
914 cbErrno = 0; // don't return error condition
915 }
916 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
917 TRACE_TERSE0("Dec:cbWriteAf() complete");
919 #if 0 // (***) FL: shows timing of CB write
920 // (***) debug // B9
921 {
922 static Uint8 toggleState = 0;
923 if (toggleState == 0)
924 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
925 else
926 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
927 toggleState = ~(toggleState);
928 }
929 #endif
931 // Log circular buffer control variables (debug)
932 cbLog(pCbCtl, z, 1, "cbWriteAf");
933 }
935 // write back Dec configuration
936 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
937 Cache_wait();
939 #ifdef NON_CACHE_STATUS
940 statusOp_read(&(temp8),
941 &(pAstCfg->xDec[z].decodeStatus.mode),
942 sizeof(Int8),
943 GATEMP_INDEX_DEC);
944 // Re-initialize audio frame if decoder is disabled or
945 // doesn't have a valid input
946 if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
947 {
948 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
949 }
950 #else
951 // Re-initialize audio frame if decoder is disabled or
952 // doesn't have a valid input
953 if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
954 {
955 pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
956 }
957 #endif
958 // send dec info complete message to master
959 queId = MessageQ_getReplyQueue(pAspMsg);
960 pAspMsg->procId = hAspMsgSlave->slaveProcId;
961 pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
962 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
963 argIdx = 0; // set decErrno
964 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
965 argIdx += sizeof(Int32); // set cbErrno
966 *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;
967 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
968 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
969 if (status != MessageQ_S_SUCCESS)
970 {
971 SW_BREAKPOINT;
972 }
974 break;
976 case ASP_SLAVE_DEC_DEACTIVATE:
977 gSlaveDecDeactivateCnt++;
979 argIdx = 0; // get decIdx
980 z = *(Int32 *)&pAspMsg->buf[argIdx];
981 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
983 if (alg[z]->fxns->algDeactivate)
984 {
985 alg[z]->fxns->algDeactivate(alg[z]);
986 }
988 // Stop writes to circular buffer
989 cbErrno = cbWriteStop(pCbCtl, z);
990 if (cbErrno < 0)
991 {
992 SW_BREAKPOINT; // debug
993 }
994 // Log circular buffer control variables (debug)
995 cbLog(pCbCtl, z, 1, "cbWriteStop");
997 // Reset Output Init-Sync decoder stage flags
998 outIsErrno = outIsResetDecStageFlags(pOutIsCtl, z);
999 if (outIsErrno < 0)
1000 {
1001 SW_BREAKPOINT; // debug
1002 }
1004 // send dec deactivate complete message to master
1005 queId = MessageQ_getReplyQueue(pAspMsg);
1006 pAspMsg->procId = hAspMsgSlave->slaveProcId;
1007 pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
1008 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
1009 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1010 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
1011 if (status != MessageQ_S_SUCCESS)
1012 {
1013 SW_BREAKPOINT;
1014 }
1016 break;
1018 default:
1019 TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
1020 break;
1021 }
1022 }
1023 }
1025 Log_info0("exit taskAsdpFxn()");
1026 }
1029 // -----------------------------------------------------------------------------
1030 // AST Initialization Function - Memory Allocation
1031 //
1032 // Name: PAF_AST_initPhaseMalloc
1033 // Purpose: Audio Stream Task Function for initialization of data pointers
1034 // by allocation of memory.
1035 // From: audioStream1Task or equivalent
1036 // Uses: See code.
1037 // States: x
1038 // Return: 0 on success.
1039 // Source code line number on MEM_calloc failure.
1040 // Trace: Message Log "trace" in Debug Project Configuration reports:
1041 // * State information as per parent.
1042 // * Memory allocation errors.
1043 //
1044 Int
1045 PAF_ASDT_initPhaseMalloc(
1046 const PAF_ASDT_Params *pP,
1047 const PAF_ASDT_Patchs *pQ,
1048 PAF_ASDT_Config *pAsdtCfg
1049 )
1050 {
1051 PAF_AST_Config *pAstCfg;
1052 Int as; /* Audio Stream Number (1, 2, etc.) */
1053 Int zMS;
1054 Error_Block eb;
1056 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1057 as = pAstCfg->as;
1058 zMS = pAstCfg->masterStr;
1060 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1062 // Initialize error block
1063 Error_init(&eb);
1065 if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL,
1066 DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
1067 {
1068 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1069 SW_BREAKPOINT;
1070 return __LINE__;
1071 }
1072 TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
1073 DECODEN * sizeof (PAF_AudioFrame),
1074 HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
1076 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1077 TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1078 return 0;
1079 } //PAF_ASDT_initPhaseMalloc
1081 // -----------------------------------------------------------------------------
1082 // AST Initialization Function - Memory Initialization from Configuration
1083 //
1084 // Name: PAF_AST_initPhaseConfig
1085 // Purpose: Audio Stream Task Function for initialization of data values
1086 // from parameters.
1087 // From: audioStream1Task or equivalent
1088 // Uses: See code.
1089 // States: x
1090 // Return: 0 on success.
1091 // Other as per initFrame0 and initFrame1.
1092 // Trace: Message Log "trace" in Debug Project Configuration reports:
1093 // * State information as per parent.
1094 //
1096 Int
1097 PAF_ASDT_initPhaseConfig(
1098 const PAF_ASDT_Params *pP,
1099 const PAF_ASDT_Patchs *pQ,
1100 PAF_ASDT_Config *pAsdtCfg
1101 )
1102 {
1103 PAF_AST_Config *pAstCfg;
1104 Int as; /* Audio Stream Number (1, 2, etc.) */
1105 Int zMS;
1106 Int z;
1108 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1109 as = pAstCfg->as;
1110 zMS = pAstCfg->masterStr;
1112 TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1114 // overwrite pointer to audio frame in framework decode control
1115 for (z=DECODE1; z < DECODEN; z++)
1116 {
1117 //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
1118 //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1119 //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
1120 pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
1121 pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
1122 pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
1123 pP->fxns->initFrame0(pP, pQ, pAsdtCfg, z);
1124 }
1126 return 0;
1127 } //PAF_ASDT_initPhaseConfig
1129 // -----------------------------------------------------------------------------
1130 // AST Initialization Function - ACP Algorithm Instantiation
1131 //
1132 // Name: PAF_AST_initPhaseAcpAlg
1133 // Purpose: Audio Stream Task Function for initialization of ACP by
1134 // instantiation of the algorithm.
1135 // From: audioStream1Task or equivalent
1136 // Uses: See code.
1137 // States: x
1138 // Return: 0 on success.
1139 // Source code line number on ACP Algorithm creation failure.
1140 // Trace: Message Log "trace" in Debug Project Configuration reports:
1141 // * State information as per parent.
1142 // * Memory allocation errors.
1143 //
1144 Int
1145 PAF_ASDT_initPhaseAcpAlg(
1146 const PAF_ASDT_Params *pP,
1147 const PAF_ASDT_Patchs *pQ,
1148 PAF_ASDT_Config *pAsdtCfg
1149 )
1150 {
1151 PAF_AST_Config *pAstCfg;
1152 Int as; /* Audio Stream Number (1, 2, etc.) */
1153 Int z; /* input/encode/stream/decode/output counter */
1154 Int betaPrimeOffset;
1155 ACP_Handle acp;
1156 Int zMS;
1157 Int zS; //, zX;
1159 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1160 as = pAstCfg->as;
1161 zMS = pAstCfg->masterStr;
1163 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1165 ACP_MDS_init();
1167 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1168 {
1169 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1170 return __LINE__;
1171 }
1172 pAsdtCfg->acp = acp;
1174 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
1175 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1177 for (z=DECODE1; z < DECODEN; z++)
1178 {
1179 zS = pP->streamsFromDecodes[z];
1180 acp->fxns->attach(acp, ACP_SERIES_STD,
1181 STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1182 (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
1183 /* Ignore errors, not reported. */
1184 }
1186 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1188 return 0;
1189 } //PAF_AST_initPhaseAcpAlg
1191 // -----------------------------------------------------------------------------
1192 // AST Initialization Function - Common Memory and Algorithms
1193 //
1194 // Name: PAF_AST_initPhaseCommon
1195 // Purpose: Audio Stream Task Function for initialization of data pointers
1196 // by allocation for common memory and by instantiation for
1197 // algorithms.
1198 // From: audioStream1Task or equivalent
1199 // Uses: See code.
1200 // States: x
1201 // Return: 0 on success.
1202 // Source code line number on PAF_ALG_alloc failure.
1203 // Source code line number on PAF_ALG_mallocMemory failure.
1204 // Source code line number on Decode Chain initialization failure.
1205 // Source code line number on ASP Chain initialization failure.
1206 // Source code line number on Encode Chain initialization failure.
1207 // Trace: Message Log "trace" in Debug Project Configuration reports:
1208 // * State information as per parent.
1209 // * Memory allocation errors.
1210 //
1212 #include <pafsio_ialg.h>
1214 Int
1215 PAF_ASDT_initPhaseCommon(
1216 const PAF_ASDT_Params *pP,
1217 const PAF_ASDT_Patchs *pQ,
1218 PAF_ASDT_Config *pAsdtCfg
1219 )
1220 {
1221 PAF_AST_Config *pAstCfg;
1222 Int as; /* Audio Stream Number (1, 2, etc.) */
1223 Int z; /* stream counter */
1224 //Int g; /* gear */
1225 ACP_Handle acp;
1226 PAF_IALG_Config pafAlgConfig;
1227 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1229 acp = pAsdtCfg->acp; // get acp handle
1230 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1231 as = pAstCfg->as;
1233 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
1235 //
1236 // Determine memory needs and instantiate algorithms across audio streams
1237 //
1239 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
1240 PAF_ALG_setup(&pafAlgConfig,
1241 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1242 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1243 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1244 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1245 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1246 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1247 HEAP_CLEAR);
1249 if (pP->fxns->headerPrint)
1250 pP->fxns->headerPrint();
1252 for (z=STREAM1; z < STREAMN; z++)
1253 {
1254 //Int zD, zE, zX;
1255 Int zD, zX;
1257 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
1259 //
1260 // Determine common memory needs of Decode Algorithms
1261 //
1262 PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
1264 zD = -1;
1265 for (zX = DECODE1; zX < DECODEN; zX++)
1266 {
1267 if (pP->streamsFromDecodes[zX] == z)
1268 {
1269 zD = zX;
1270 break;
1271 }
1272 }
1274 if (zD >= 0)
1275 {
1276 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
1277 if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z]))
1278 {
1279 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1280 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1282 SW_BREAKPOINT;
1283 return __LINE__;
1284 }
1285 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1286 if(pP->fxns->allocPrint)
1287 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1288 }
1290 #if 0 // FL: master
1291 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1292 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1293 if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z]))
1294 {
1295 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1296 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1297 SW_BREAKPOINT;
1298 return __LINE__;
1299 }
1300 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1301 if(pP->fxns->allocPrint)
1302 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1303 #endif
1305 }
1306 {
1307 // Changes made to share scratch between zones
1308 // Assume maximum 3 zones and scratch common memory is at offset 0;
1309 int max=0;
1310 for (z=STREAM1; z < STREAMN; z++)
1311 {
1312 if (max<common[z][0].size)
1313 max=common[z][0].size;
1314 }
1315 common[STREAM1][0].size=max;
1316 for (z=STREAM1+1; z < STREAMN; z++)
1317 common[z][0].size=0;
1318 }
1320 //
1321 // Provide common memory needs of Decode Algorithms
1322 //
1323 for (z=STREAM1; z < STREAMN; z++)
1324 {
1325 //Int zD, zE, zX;
1326 Int zD, zX;
1328 zD = -1;
1329 for (zX = DECODE1; zX < DECODEN; zX++)
1330 {
1331 if (pP->streamsFromDecodes[zX] == z)
1332 {
1333 zD = zX;
1334 break;
1335 }
1336 }
1338 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1339 if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig))
1340 {
1341 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1342 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1343 SW_BREAKPOINT;
1344 return __LINE__;
1345 }
1346 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1347 // share zone0 scratch with all zones
1348 common[z][0].base=common[0][0].base;
1349 if (pP->fxns->commonPrint)
1350 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1352 //
1353 // Instantiate Decode Algorithms
1354 //
1355 if (zD >= 0)
1356 {
1357 PAF_ASP_Chain *chain;
1358 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1359 chain =
1360 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1361 HEAP_INTERNAL, as+z, acp, &trace,
1362 decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1363 if (!chain)
1364 {
1365 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1366 return __LINE__;
1367 }
1368 }
1370 #if 0 // FL: master
1371 pC->xStr[z].aspChain[0] = NULL;
1372 for (g=0; g < GEARS; g++)
1373 {
1374 PAF_ASP_Chain *chain;
1375 TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1376 chain =
1377 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1378 HEAP_INTERNAL, as+z, acp, &trace,
1379 aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1380 if (! chain)
1381 {
1382 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1383 return __LINE__;
1384 }
1385 else
1386 pC->xStr[z].aspChain[g] = chain;
1387 }
1388 #endif
1390 }
1391 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1393 return 0;
1394 } //PAF_ASDT_initPhaseCommon
1396 // -----------------------------------------------------------------------------
1397 // AST Initialization Function - Algorithm Keys
1398 //
1399 // Name: PAF_AST_initPhaseAlgKey
1400 // Purpose: Audio Stream Task Function for initialization of data values
1401 // from parameters for Algorithm Keys.
1402 // From: audioStream1Task or equivalent
1403 // Uses: See code.
1404 // States: x
1405 // Return: 0.
1406 // Trace: Message Log "trace" in Debug Project Configuration reports:
1407 // * State information as per parent.
1408 //
1409 // .............................................................................
1410 Int
1411 PAF_ASDT_initPhaseAlgKey(
1412 const PAF_ASDT_Params *pP,
1413 const PAF_ASDT_Patchs *pQ,
1414 PAF_ASDT_Config *pAsdtCfg
1415 )
1416 {
1417 PAF_AST_Config *pAstCfg;
1418 Int as; /* Audio Stream Number (1, 2, etc.) */
1419 Int z; /* decode/encode counter */
1420 Int s; /* key number */
1421 PAF_ASP_Link *that;
1423 (void)as; // clear warning.
1425 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1426 as = pAstCfg->as;
1428 TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1430 for (z=DECODE1; z < DECODEN; z++)
1431 {
1432 for (s=0; s < pP->pDecAlgKey->length; s++)
1433 {
1434 if ((pP->pDecAlgKey->code[s].full != 0)
1435 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1436 {
1437 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1438 /* Cast in interface, for now --Kurt */
1439 }
1440 else
1441 pAstCfg->xDec[z].decAlg[s] = NULL;
1442 }
1443 }
1445 return 0;
1446 } //PAF_AST_initPhaseAlgKey
1448 // Purpose: Audio Stream Decode Task Function for initialization of the Audio
1449 // Frame(s) by memory allocation and loading of data pointers
1450 // and values.
1451 Int
1452 PAF_ASDT_initFrame0(
1453 const PAF_ASDT_Params *pP,
1454 const PAF_ASDT_Patchs *pQ,
1455 PAF_ASDT_Config *pAsdtCfg,
1456 Int z
1457 )
1458 {
1459 PAF_AST_Config *pAstCfg;
1460 Int as; /* Audio Stream Number (1, 2, etc.) */
1461 Int aLen;
1462 Int aSize = sizeof(PAF_AudioData);
1463 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1464 Int maxFrameLength = pP->maxFramelength;
1465 PAF_AudioData *aBuf=NULL;
1466 XDAS_UInt8 *metadataBuf;
1467 Error_Block eb;
1468 PAF_AudioFrame *pAudioFrame;
1469 Int i;
1471 pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1472 as = pAstCfg->as;
1474 pAudioFrame = &gpDecAudioFrame[z];
1475 if (pAudioFrame == NULL)
1476 {
1477 SW_BREAKPOINT;
1478 }
1480 // Initialize error block
1481 Error_init(&eb);
1483 //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1484 //aLen = numchan[z] * maxFrameLength;
1485 aLen = numchan[z] * maxFrameLength + (maxFrameLength - FRAMELENGTH); /* Qin - need additional memory for starting offset
1486 See line 1301 */
1488 //
1489 // Initialize audio frame elements directly
1490 //
1491 pAudioFrame->fxns = pP->pAudioFrameFunctions;
1492 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1493 pAudioFrame->data.nSamples = FRAMELENGTH;
1494 pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1495 pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1496 pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1498 //
1499 // Allocate memory for and initialize pointers to audio data buffers
1500 //
1501 // The NUMCHANMASK is used to identify the channels for which data
1502 // buffers can be allocated. Using this mask and switch statement
1503 // rather than some other construct allows efficient code generation,
1504 // providing just the code necessary (with significant savings).
1505 //
1506 if (pP->fxns->bufMemPrint)
1507 {
1508 pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1509 }
1511 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1513 if (aLen != 0)
1514 {
1515 if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1516 {
1517 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1518 TRACE_TERSE2(" maxFrameLength: %d. aLen*aSize: %d", maxFrameLength, aLen*aSize);
1519 SW_BREAKPOINT;
1520 return __LINE__;
1521 }
1522 }
1524 TRACE_TERSE3(" maxFrameLength: %d. aLen*aSize: %d. aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1526 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1527 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1528 {
1529 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1530 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1531 SW_BREAKPOINT;
1532 return __LINE__;
1533 }
1535 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1536 {
1537 gDecAudioFrameChannelPointers[i] = NULL;
1538 }
1540 if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1541 {
1542 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1543 return __LINE__;
1544 }
1545 else
1546 {
1547 Int j = 0;
1548 TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1549 for (i=0; i<numchan[z]; i++)
1550 {
1551 Int8 chan = AFChanPtrMap[numchan[z]][i];
1552 if (chan != -1)
1553 {
1554 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1555 j++;
1556 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1557 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1558 }
1559 }
1560 }
1562 // Initialize original audio frame channel pointers
1563 for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++)
1564 {
1565 if (gDecAudioFrameChannelPointers[i])
1566 {
1567 gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1568 }
1569 }
1571 //
1572 // Initialize meta data elements
1573 //
1574 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1575 pAudioFrame->numPrivateMetadata = 0;
1576 pAudioFrame->bsMetadata_offset = 0;
1577 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1578 pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1579 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1580 {
1581 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1582 pAudioFrame->pafPrivateMetadata[i].size = 0;
1583 pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1584 }
1586 return 0;
1587 } //PAF_ASDT_initFrame0
1589 // -----------------------------------------------------------------------------
1590 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1591 // AST Decoding Function - Reinitialization of Audio Frame
1592 //
1593 // Name: PAF_ASOT_initFrame1
1594 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1595 // zation of the Audio Frame(s) by loading of data values of a
1596 // time-varying nature.
1597 // From: audioStream1Task or equivalent
1598 // AST Parameter Function -> decodeInfo
1599 // AST Parameter Function -> decodeDecode
1600 // Uses: See code.
1601 // States: x
1602 // Return: 0.
1603 // Trace: None.
1604 //
1605 Int
1606 PAF_ASDT_initFrame1(
1607 const PAF_ASDT_Params *pP,
1608 const PAF_ASDT_Patchs *pQ,
1609 PAF_ASDT_Config *pAsdtCfg,
1610 Int z,
1611 Int apply
1612 )
1613 {
1614 PAF_AudioFrame *pAudioFrame;
1616 //
1617 // Reinitialize audio frame elements:
1618 //
1619 // Channel Configurations during sys init = Unknown
1620 // " " during info or decode = None
1621 //
1622 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1623 //
1625 pAudioFrame = &gpDecAudioFrame[z];
1627 if (apply < 0)
1628 {
1629 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1630 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1631 }
1632 else
1633 {
1634 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1635 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1636 }
1638 if (apply < 1)
1639 {
1640 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1641 pAudioFrame->sampleCount = 0;
1642 }
1644 return 0;
1645 } //PAF_ASDT_initFrame1
1647 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1648 Int resetAf(
1649 const PAF_ASDT_Params *pP,
1650 Int z,
1651 Int sourceSelect
1652 )
1653 {
1654 PAF_AudioFrame *pAudioFrame;
1655 Int ch;
1656 Int i;
1658 // Get audio frame
1659 pAudioFrame = &gpDecAudioFrame[z];
1660 if (pAudioFrame == NULL)
1661 {
1662 SW_BREAKPOINT;
1663 }
1665 // Reinitialize audio frame elements
1666 pAudioFrame->sampleDecode = PAF_SOURCE_UNKNOWN;
1667 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1668 pAudioFrame->sampleCount = 0;
1669 pAudioFrame->channelConfigurationRequest.full = PAF_CC_UNKNOWN;
1670 pAudioFrame->channelConfigurationStream.full = PAF_CC_UNKNOWN;
1672 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1673 switch (sourceSelect)
1674 {
1675 case PAF_SOURCE_PCM:
1676 pAudioFrame->data.nSamples = FRAMELENGTH;
1677 break;
1678 case PAF_SOURCE_AC3:
1679 case PAF_SOURCE_DDP:
1680 pAudioFrame->data.nSamples = 1536;
1681 break;
1682 case PAF_SOURCE_THD:
1683 pAudioFrame->data.nSamples = 5120; //QIN FIX ME
1684 break;
1685 default:
1686 pAudioFrame->data.nSamples = FRAMELENGTH;
1687 break;
1688 }
1690 // Reset audio frame channel pointers
1691 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1692 {
1693 if (gDecAudioFrameChannelPointers[ch])
1694 {
1695 gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1696 }
1697 }
1699 // Reset audio frame meta data elements
1700 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1701 pAudioFrame->numPrivateMetadata = 0;
1702 pAudioFrame->bsMetadata_offset = 0;
1703 pAudioFrame->bsMetadata_type = PAF_bsMetadata_none;
1704 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1705 {
1706 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1707 pAudioFrame->pafPrivateMetadata[i].size = 0;
1708 }
1710 return 0;
1711 }
1713 // Reset AF samsiz, invoked during DECODE
1714 Int resetAfSamsiz(
1715 Int z
1716 )
1717 {
1718 PAF_AudioFrame *pAudioFrame;
1719 Int ch;
1721 // Get audio frame
1722 pAudioFrame = &gpDecAudioFrame[z];
1723 if (pAudioFrame == NULL)
1724 {
1725 SW_BREAKPOINT;
1726 }
1728 // Clear samsiz for all channels - MID 208.
1729 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
1730 {
1731 pAudioFrame->data.samsiz[ch] = 0;
1732 }
1734 return 0;
1735 }
1737 // (***) FL: Check correct behavior for other decs, esp DTSHD & DXP
1738 // Check decoder sync using information in INFO audio frame
1739 static Int8 checkDecSync(
1740 PAF_AudioFrame *pAf
1741 )
1742 {
1743 if ((pAf->sampleDecode == PAF_SOURCE_THD) &&
1744 (pAf->sampleRate == PAF_SAMPLERATE_UNKNOWN))
1745 {
1746 return 0;
1747 }
1748 else
1749 {
1750 return 1;
1751 }
1752 }