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