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 * ======== audioStreamInpProc.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Diags.h>
43 #include <xdc/runtime/Error.h>
44 #include <xdc/runtime/Log.h>
45 #include <xdc/runtime/Memory.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/hal/Hwi.h>
49 #include <ti/sysbios/hal/Cache.h>
50 #include <ti/sysbios/knl/Clock.h>
51 #include <ti/sysbios/knl/Task.h>
52 #include <ti/ipc/Ipc.h>
53 #include <ti/ipc/MessageQ.h>
54 #include <ti/ipc/MultiProc.h>
56 #include <sio.h>
57 #include <pafsio_ialg.h>
59 #include "common.h"
60 #include "paf_heapMgr.h"
61 #include "aspMsg_common.h"
62 #include "aspMsg_master.h"
63 #include "aspDecOpCircBuf_master.h"
64 #include "audioStreamProc_common.h"
65 #include "audioStreamProc_master.h"
66 #include "audioStreamInpProc.h"
67 #include "statusOp_common.h"
69 #include "pfp/pfp.h"
70 #include "pfp_app.h" /* contains all PFP ID's */
71 Int32 gNumPfpAsit0=0; // debug
72 Int32 gNumPfpAsit1=0;
76 // FL: debug
77 #include "dbgCapAf.h"
80 // -----------------------------------------------------------------------------
81 // Debugging Trace Control, local to this file.
82 //
83 #include "logp.h"
85 #define TRACE_ARC(a)
87 // allows you to set a different trace module in pa.cfg
88 #define TR_MOD trace
90 // Allow a developer to selectively enable tracing.
91 #define CURRENT_TRACE_MASK 0x21
93 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
94 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
95 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
96 #define TRACE_MASK_DATA 0x08 // Show data
97 #define TRACE_MASK_TIME 0x10 // Timing related traces
98 #define TRACE_MASK_MSG 0x20 // Message related traces
100 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
101 #undef TRACE_TERSE0
102 #undef TRACE_TERSE1
103 #undef TRACE_TERSE2
104 #undef TRACE_TERSE3
105 #undef TRACE_TERSE4
106 #define TRACE_TERSE0(a)
107 #define TRACE_TERSE1(a,b)
108 #define TRACE_TERSE2(a,b,c)
109 #define TRACE_TERSE3(a,b,c,d)
110 #define TRACE_TERSE4(a,b,c,d,e)
111 #endif
113 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
114 #undef TRACE_GEN0
115 #undef TRACE_GEN1
116 #undef TRACE_GEN2
117 #undef TRACE_GEN3
118 #undef TRACE_GEN4
119 #define TRACE_GEN0(a)
120 #define TRACE_GEN1(a,b)
121 #define TRACE_GEN2(a,b,c)
122 #define TRACE_GEN3(a,b,c,d)
123 #define TRACE_GEN4(a,b,c,d,e)
124 #endif
126 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
127 // consolidate list of processing strings, indexed by PAF_SOURCE
128 static char *procName[] =
129 {
130 "", //PAF_SOURCE_UNKNOWN
131 "", //PAF_SOURCE_NONE
132 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
133 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
134 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
135 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
136 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
137 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
138 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
139 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
140 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
142 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
143 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
144 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
145 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
146 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
147 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
148 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
149 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
150 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
151 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
152 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
153 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
154 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
155 "AS%d: THD processing ...", //PAF_SOURCE_THD
156 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
157 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
158 };
160 #else
161 #undef TRACE_VERBOSE0
162 #undef TRACE_VERBOSE1
163 #undef TRACE_VERBOSE2
164 #undef TRACE_VERBOSE3
165 #undef TRACE_VERBOSE4
166 #define TRACE_VERBOSE0(a)
167 #define TRACE_VERBOSE1(a,b)
168 #define TRACE_VERBOSE2(a,b,c)
169 #define TRACE_VERBOSE3(a,b,c,d)
170 #define TRACE_VERBOSE4(a,b,c,d,e)
171 #endif
173 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
174 #define TRACE_DATA(a) LOG_printf a
175 #else
176 #define TRACE_DATA(a)
177 #endif
179 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
180 #define TRACE_TIME(a) LOG_printf a
181 #define TIME_MOD trace // this could be different
182 static Int dtime()
183 {
184 static Int old_time = 0;
185 Int time = TSK_time();
186 Int delta_time = time - old_time;
187 old_time = time;
188 return( delta_time);
189 }
191 static char *stateName[11] =
192 {
193 "INIT",
194 "INFO1",
195 "AGAIN",
196 "INFO2",
197 "CONT",
198 "TIME",
199 "DECODE",
200 "STREAM",
201 "ENCODE",
202 "FINAL",
203 "QUIT"
204 };
206 #else
207 #define TRACE_TIME(a)
208 #endif
210 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
211 #undef TRACE_MSG0
212 #undef TRACE_MSG1
213 #undef TRACE_MSG2
214 #undef TRACE_MSG3
215 #undef TRACE_MSG4
216 #define TRACE_MSG0(a)
217 #define TRACE_MSG1(a,b)
218 #define TRACE_MSG2(a,b,c)
219 #define TRACE_MSG3(a,b,c,d)
220 #define TRACE_MSG4(a,b,c,d,e)
221 #endif
224 // .............................................................................
226 #include <pafsio.h>
227 #include "paferr.h"
229 #include <acp_mds.h>
231 #include <pcm.h>
233 #include <pce.h>
235 #include <doberr.h>
237 #include <diberr.h>
239 #include <stdasp.h>
241 #include "as0.h"
242 #include "asperr.h"
244 #include "audioStreamProc_params.h"
245 #include "audioStreamProc_patchs.h"
246 #include "audioStreamProc_config.h"
247 #include "audioStreamInpProc.h"
250 #include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
251 #ifdef _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
252 //
253 // Performing PCM high-sampling rate + SRC + CAR benchmarking
254 //
256 #define PROFILER
257 #endif
259 #ifdef PROFILER
260 extern UInt32 start_profiling;
261 #endif
263 extern UInt32 gAspProfileEnable;
265 //
266 // Audio Stream Definitions
267 //
269 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
270 #define MINFRAMELENGTH 24
271 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
274 //
275 // Decoder Definitions
276 //
277 //#define decLinkInit pQ->i_decLinkInit
279 //
280 // Audio Stream Processing Definitions
281 //
282 //#define aspLinkInit pQ->i_aspLinkInit
284 //
285 // Encoder Definitions
286 //
287 #define encLinkInit pQ->i_encLinkInit
289 //
290 // Input, Output Definitions
291 //
292 #define inpLinkInit pP->i_inpLinkInit
293 //#define outLinkInit pP->i_outLinkInit
295 /* ---------------------------------------------------------------- */
296 /* Parameter macro definitions end here. */
297 /* ---------------------------------------------------------------- */
299 //
300 // Standardized Definitions
301 //
303 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
304 //#define ENC_Handle PCE_Handle /* works for all: PCE */
306 #define __TASK_NAME__ "TaskAsip"
308 LINNO_DEFN(TaskAsip); /* Line number macros */
309 ERRNO_DEFN(TaskAsip); /* Error number macros */
311 // ASIT configuration
312 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
313 PAF_ASIT_Config gPAF_ASIT_config = {
314 NULL, // taskHandle
315 NULL, // acp
316 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
317 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
318 };
320 // Global debug counters */
321 UInt32 gTaskAsipCnt =0;
322 UInt32 gAsipInitCnt =0;
323 UInt32 gAsipInfo1Cnt =0;
324 UInt32 gAsipInfo2Cnt =0;
325 UInt32 gAsipDecodeCnt =0;
326 UInt32 gAsipDecodeErrCnt =0;
327 UInt32 gAsipFinalCnt =0;
328 UInt32 gAsipQuitCnt =0;
329 UInt32 gAsipInfo1_PrimaryErrCnt =0;
330 UInt32 gAsipInfo1_ErrCnt =0;
331 UInt32 gAsipInfo2_PrimaryErrCnt =0;
332 UInt32 gAsipInfo2_ErrCnt =0;
333 UInt32 gCapIbReset_cnt =0;
334 UInt32 gCapIb_cnt =0;
335 // debug
336 UInt32 gCbWrtAfErrCnt =0; // decoder output circular buffer write error count (returned from ARM to DSP)
339 #include "dbgDib.h" // debug
341 extern struct {
342 Int size;
343 IALG_Status *pStatus[512];
344 } IACP_STD_BETA_TABLE;
346 // FL: debug
347 #include "evmc66x_gpio_dbg.h"
349 /*
350 * ======== taskAsipFxn ========
351 * Audio Stream Input Processing task function
352 */
353 Void taskAsipFxn(
354 // Int betaPrimeValue, // FL: revisit
355 const PAF_ASIT_Params *pP,
356 const PAF_ASIT_Patchs *pQ
357 )
358 {
359 PAF_ASIT_Config *pC; /* Local configuration pointer */
360 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
361 Int as; /* Audio Stream Number (1, 2, etc.) */
362 Int z; /* input/encode/stream/decode/output counter */
363 Int i; /* phase */
364 Int errno; /* error number */
365 Int zMD, zMI, zMS, zX;
366 Int loopCount = 0; // used to stop trace to see startup behavior.
367 UInt32 curTime;
368 Int size;
369 // Messaging
370 ASP_Msg *pAspMsg;
371 Int status;
372 #ifdef NON_CACHE_STATUS
373 Int8 tempVar8;
374 #endif
376 Log_info0("Enter taskAsipFxn()");
378 //
379 // Audio Framework Parameters & Patch (*pP, *pQ)
380 //
381 if (!pP)
382 {
383 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
384 LINNO_RPRT(TaskAsip, -1);
385 return;
386 }
388 if (!pQ)
389 {
390 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
391 LINNO_RPRT(TaskAsip, -1);
392 return;
393 }
395 //
396 // Audio Framework Configuration (*pC):
397 //
398 pC = &gPAF_ASIT_config; // initialize pointer to task configuration
399 pC->taskHandle = Task_self(); // set task handle
400 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
402 /* Set Audio Stream Number (1, 2, etc.) */
403 as = gBetaPrimeValue + 1;
404 pAstCfg->as = as;
405 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
407 //
408 // Initialize message log trace and line number reporting
409 //
410 for (z=STREAM1; z < STREAMN; z++)
411 {
412 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
413 }
414 LINNO_RPRT(TaskAsip, -1);
416 //
417 // Determine decoder and stream indices associated with the master input
418 //
419 zMI = pP->zone.master;
420 pAstCfg->masterDec = zMI;
421 pAstCfg->masterStr = zMI;
422 for (zX = DECODE1; zX < DECODEN; zX++)
423 {
424 if (pP->inputsFromDecodes[zX] == zMI)
425 {
426 pAstCfg->masterDec = zX;
427 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
428 break;
429 }
430 }
431 zMD = pAstCfg->masterDec;
432 zMS = pAstCfg->masterStr;
434 // Initialize as per parametrized phases:
435 //
436 // In standard form these are:
437 // - Malloc: Memory Allocation
438 // - Config: Configuration Initialization
439 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
440 // - Common: Common Memory Initialization
441 // - AlgKey: Dec/Enc chain to Array Initialization
442 // - Device: I/O Device Initialization
443 // - DecOpCircBuf: Decoder Output Circular Buffer
444 // - Unused: (available)
445 //
446 LINNO_RPRT(TaskAsip, -2);
447 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
448 {
449 Int linno;
450 if (pP->fxns->initPhase[i])
451 {
452 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
453 {
454 LINNO_RPRT(TaskAsip, linno);
455 return;
456 }
457 }
458 else
459 {
460 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
461 }
462 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
463 LINNO_RPRT(TaskAsip, -i-3);
464 }
466 //
467 // End of Initialization -- display memory usage report.
468 //
469 if (pP->fxns->memStatusPrint)
470 {
471 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
472 }
474 // (***) FL: revisit
475 // write back AST shared configuration
476 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
477 // FL: no need to share this pointer, can be local
478 //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
479 Cache_wait();
481 // (***) FL: revisit
482 // write back Dec configuration
483 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
484 Cache_wait();
486 // (***) FL: revisit
487 // write back entire beta table
488 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
489 Cache_wait();
491 // FL: send start initialization message to slave
492 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
493 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
494 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
495 pAspMsg->procId = hAspMsgMaster->masterProcId;
496 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
497 pAspMsg->expectResp = TRUE;
498 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
499 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
500 if (status != MessageQ_S_SUCCESS)
501 {
502 SW_BREAKPOINT;
503 }
504 // wait for initialization complete message from slave
505 do {
506 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
507 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
508 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
509 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
510 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
511 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
512 {
513 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
514 SW_BREAKPOINT;
515 }
516 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
517 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
518 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
519 if (status != MessageQ_S_SUCCESS)
520 {
521 SW_BREAKPOINT;
522 }
524 // (***) FL: revisit
525 // invalidate Status structure addresses for Beta Units initialized on Slave
526 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
527 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
528 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
529 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
530 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
531 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
532 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
533 Cache_wait();
534 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
535 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
536 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
537 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
538 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
539 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
540 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
542 // (***) FL: revisit
543 // invalidate Status structures for Beta Units initialized on Slave
544 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
545 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
546 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
547 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
548 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
549 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
550 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
551 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
552 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
553 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
554 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
555 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
556 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
557 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
558 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
559 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
560 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
561 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
562 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
563 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
564 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
565 Cache_wait();
567 #ifdef NON_CACHE_STATUS
568 // Get the shared status structure GateMP handles. Initialized at slave.
569 if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
570 {
571 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
572 }
573 if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
574 {
575 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
576 }
577 if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
578 {
579 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
580 }
581 if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
582 {
583 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
584 }
585 #endif
587 // (***) FL: revisit
588 // invalidate Dec configuration
589 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
590 Cache_wait();
592 //
593 // Main processing loop
594 //
595 for (z=STREAM1; z < STREAMN; z++)
596 {
597 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
598 }
600 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
602 errno = 0;
603 for (;;)
604 {
605 Int sourceSelect;
606 XDAS_Int8 sourceProgram;
608 loopCount++;
610 #if 0 // enable and tune to see startup behavior.
611 // this is an alternative to fixed/circular setting in pa.cfg.
612 // If you are searching for a memory allocation failure, disable on first round.
613 // All allocation has already happened.
614 // This is the outer loop. This loop count goes up when the stream resets.
615 // If the stream is running without problems, this does not increment.
616 // If the stream is repeatedly resetting, this loop count will go up rapidly.
617 if (loopCount > 10) // see traces for a few of the passes through the main loop.
618 {
619 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
620 LOG_disable(&TR_MOD); // stop tracing
621 }
622 #endif
624 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
625 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
627 // since not decoding indicate such
628 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
630 // any error forces idling of input
631 if (errno)
632 {
633 for (z=INPUT1; z < INPUTN; z++)
634 {
635 if (pAstCfg->xInp[z].hRxSio)
636 {
637 SIO_idle(pAstCfg->xInp[z].hRxSio);
638 }
639 }
641 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
642 ERRNO_RPRT(TaskAsip, errno);
643 }
645 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
646 // up to allow lower priority tasks to run. This may seem odd to be at the top
647 // of the state machine but provides for a cleaner flow even though the very
648 // first time we enter we do a sleep which is non-intuitive.
649 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
650 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
651 Task_sleep(1);
653 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
654 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
655 {
656 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
657 continue;
658 }
660 // if no master input selected then we don't know what may be at the input
661 // so set to unknown and skip any remaining processing
662 if (!pAstCfg->xInp[zMI].hRxSio)
663 {
664 #ifdef NON_CACHE_STATUS
665 tempVar8 = PAF_SOURCE_UNKNOWN;
666 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
667 &tempVar8,
668 sizeof(tempVar8),
669 GATEMP_INDEX_DEC);
670 #else
671 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
672 #endif
673 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
674 continue;
675 }
677 // if here then we have a valid input so query its status
678 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
679 {
680 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
681 continue;
682 }
684 #ifdef NON_CACHE_STATUS
685 statusOp_read(&tempVar8,
686 &(pAstCfg->xDec[zMD].decodeStatus.mode),
687 sizeof(tempVar8),
688 GATEMP_INDEX_DEC);
689 // If master decoder is not enabled, or the input is unlocked, then do nothing
690 if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
691 {
692 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
693 continue;
694 }
695 #else
696 // If master decoder is not enabled, or the input is unlocked, then do nothing
697 if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
698 {
699 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
700 continue;
701 }
702 #endif
704 #ifdef NON_CACHE_STATUS
705 statusOp_read(&tempVar8,
706 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
707 sizeof(tempVar8),
708 GATEMP_INDEX_DEC);
709 // If no source selected then do nothing
710 if (tempVar8 == PAF_SOURCE_NONE)
711 {
712 tempVar8 = PAF_SOURCE_NONE;
713 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
714 &tempVar8,
715 sizeof(tempVar8),
716 GATEMP_INDEX_DEC);
717 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
718 continue;
719 }
720 #else
721 // If no source selected then do nothing
722 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
723 {
724 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
725 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
726 continue;
727 }
728 #endif
730 #ifdef NON_CACHE_STATUS
731 statusOp_read(&tempVar8,
732 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
733 sizeof(tempVar8),
734 GATEMP_INDEX_DEC);
735 // If we want pass processing then proceed directly
736 if (tempVar8 == PAF_SOURCE_PASS)
737 {
738 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
740 tempVar8 = PAF_SOURCE_PASS;
741 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
742 &tempVar8,
743 sizeof(tempVar8),
744 GATEMP_INDEX_DEC);
745 #else
746 // If we want pass processing then proceed directly
747 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
748 {
749 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
750 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
751 #endif
752 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
753 if (pP->fxns->passProcessing)
754 {
755 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
756 }
757 else
758 {
759 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
760 errno = ASPERR_PASS;
761 }
762 TRACE_VERBOSE0("TaskAsip: continue");
763 continue;
764 }
766 #ifdef NON_CACHE_STATUS
767 // Measure cycles in autodet processing loop.
768 // Only measures cycles spent in loop.
769 pfpEnd(PFP_ID_ASIT_0, PFP_FINISH_MEAS); // PFP end
770 gNumPfpAsit0--;
771 pfpBegin(PFP_ID_ASIT_0, pC->taskHandle); // PFP begin
772 gNumPfpAsit0++;
774 statusOp_read(&tempVar8,
775 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
776 sizeof(tempVar8),
777 GATEMP_INDEX_DEC);
778 // .....................................................................
779 // At this point we have an enabled input and want to decode something.
780 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
781 // when no decoder is selected there are no calls to IB
782 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
783 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, tempVar8, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
784 {
785 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
786 continue;
787 }
788 #else
789 // .....................................................................
790 // At this point we have an enabled input and want to decode something.
791 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
792 // when no decoder is selected there are no calls to IB
793 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
794 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pAstCfg->xDec[zMD].decodeStatus.sourceSelect, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
795 {
796 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
797 continue;
798 }
799 #endif
801 // PFP end -- outside of PFP for autodetection complete
802 pfpEnd(PFP_ID_ASIT_0, PFP_FINISH_MEAS);
803 gNumPfpAsit0--;
805 // query for input type
806 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
807 {
808 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
809 errno = ASPERR_AUTO_PROGRAM;
810 continue;
811 }
812 #ifdef NON_CACHE_STATUS
813 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
814 &(sourceProgram),
815 sizeof(sourceProgram),
816 GATEMP_INDEX_DEC);
817 #else
818 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
819 #endif
821 // if input is unclassifiable then do nothing
822 if (sourceProgram == PAF_SOURCE_UNKNOWN)
823 {
824 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
825 continue;
826 }
828 // now that we have some input classification, and possibly an outstanding
829 // input frame, we determine whether or not to call decodeProcessing and with
830 // what decAlg.
831 sourceSelect = PAF_SOURCE_NONE;
832 #ifdef NON_CACHE_STATUS
833 statusOp_read(&tempVar8,
834 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
835 sizeof(tempVar8),
836 GATEMP_INDEX_DEC);
837 switch (tempVar8)
838 {
839 #else
840 switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect)
841 {
842 #endif
843 // If autodetecting, decoding everything, and input is something
844 // (i.e. bitstream or PCM) then decode.
845 case PAF_SOURCE_AUTO:
846 if (sourceProgram >= PAF_SOURCE_PCM)
847 {
848 sourceSelect = sourceProgram;
849 }
850 break;
852 // If autodetecting, decoding only PCM, and input is PCM then decode.
853 case PAF_SOURCE_PCMAUTO:
854 if (sourceProgram == PAF_SOURCE_PCM)
855 {
856 sourceSelect = sourceProgram;
857 }
858 break;
860 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
861 case PAF_SOURCE_BITSTREAM:
862 if (sourceProgram >= PAF_SOURCE_AC3)
863 {
864 sourceSelect = sourceProgram;
865 }
866 break;
868 // If autodetecting, decoding only DTS, and input is DTS then decode.
869 case PAF_SOURCE_DTSALL:
870 switch (sourceProgram)
871 {
872 case PAF_SOURCE_DTS11:
873 case PAF_SOURCE_DTS12:
874 case PAF_SOURCE_DTS13:
875 case PAF_SOURCE_DTS14:
876 case PAF_SOURCE_DTS16:
877 case PAF_SOURCE_DTSHD:
878 sourceSelect = sourceProgram;
879 break;
880 }
881 break;
883 // All others, e.g., force modes, fall through to here.
884 // If user made specific selection then program must match select.
885 // (NB: this compare relies on ordering of PAF_SOURCE)
886 default:
887 #ifdef NON_CACHE_STATUS
888 sourceSelect = 0; // due to size difference
889 statusOp_read(&sourceSelect,
890 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
891 sizeof(Int8),
892 GATEMP_INDEX_DEC);
893 #else
894 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
895 #endif
896 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
897 {
898 if (sourceProgram != sourceSelect)
899 {
900 sourceSelect = PAF_SOURCE_NONE;
901 }
902 }
903 break;
904 }
906 // if we didn't find any matches then skip
907 if (sourceSelect == PAF_SOURCE_NONE)
908 {
909 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
910 continue;
911 }
913 // FL: debug, reset IB capture buffer
914 capIbReset();
915 gCapIbReset_cnt++;
916 Log_info0("capIbReset()");
918 // FL: send source select message to slave
919 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
920 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
921 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
922 pAspMsg->procId = hAspMsgMaster->masterProcId;
923 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
924 pAspMsg->expectResp = TRUE;
925 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
926 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
927 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
928 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
929 if (status != MessageQ_S_SUCCESS)
930 {
931 SW_BREAKPOINT;
932 }
933 // wait for source select complete message from slave
934 //do {
935 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
936 //} while (status != MessageQ_S_SUCCESS);
937 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
938 if (status != MessageQ_S_SUCCESS)
939 {
940 TRACE_TERSE0("MessageQ_get() failure.");
941 SW_BREAKPOINT; // temporary
942 }
943 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
944 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
945 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
946 {
947 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
948 SW_BREAKPOINT;
949 }
950 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
951 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
952 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
953 if (status != MessageQ_S_SUCCESS)
954 {
955 SW_BREAKPOINT;
956 }
958 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
959 // iff we are in this top level state machine and specifically not in decodeProcessing
960 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
962 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
964 // Reduce priority level since autodetection complete
965 Task_setPri(pC->taskHandle, Task_getPri(pC->taskHandle)-1);
967 gAspProfileEnable=1; // enable ASP profiling
969 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
970 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
971 if (errno)
972 {
973 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
974 }
975 else
976 {
977 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
978 }
980 gAspProfileEnable=0; // disable ASP profiling
982 // Increase priority level since decoding complete
983 Task_setPri(pC->taskHandle, Task_getPri(pC->taskHandle)+1);
985 // FL: send dec exit message to slave
986 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
987 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
988 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
989 pAspMsg->procId = hAspMsgMaster->masterProcId;
990 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
991 pAspMsg->expectResp = TRUE;
992 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
993 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
994 if (status != MessageQ_S_SUCCESS)
995 {
996 SW_BREAKPOINT;
997 }
998 // wait for dec exit complete message from slave
999 //do {
1000 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
1001 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
1002 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
1003 if (status != MessageQ_S_SUCCESS)
1004 {
1005 TRACE_TERSE0("MessageQ_get() failure.");
1006 SW_BREAKPOINT; // temporary
1007 }
1008 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
1009 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
1010 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
1011 {
1012 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1013 SW_BREAKPOINT;
1014 }
1015 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
1016 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1017 // free the message
1018 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
1019 if (status != MessageQ_S_SUCCESS)
1020 {
1021 SW_BREAKPOINT;
1022 }
1023 } // End of main processing loop for (;;)
1025 Log_info0("Exit taskAsipFxn()");
1026 }
1028 // -----------------------------------------------------------------------------
1029 // ASIT Initialization Function - Memory Allocation
1030 //
1031 // Name: PAF_ASIT_initPhaseMalloc
1032 // Purpose: Audio Stream Input Task Function for initialization of data pointers
1033 // by allocation of memory.
1034 // From: audioStream1Task or equivalent
1035 // Uses: See code.
1036 // States: x
1037 // Return: 0 on success.
1038 // Source code line number on MEM_calloc failure.
1039 // Trace: Message Log "trace" in Debug Project Configuration reports:
1040 // * State information as per parent.
1041 // * Memory allocation errors.
1042 //
1043 Int
1044 PAF_ASIT_initPhaseMalloc(
1045 const PAF_ASIT_Params *pP,
1046 const PAF_ASIT_Patchs *pQ,
1047 PAF_ASIT_Config *pC
1048 )
1049 {
1050 PAF_AST_Config *pAstCfg;
1051 Int as; /* Audio Stream Number (1, 2, etc.) */
1052 Int zMS;
1053 Error_Block eb;
1055 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1056 as = pAstCfg->as;
1057 zMS = pAstCfg->masterStr;
1059 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1061 // Initialize error block
1062 Error_init(&eb);
1064 /* Input memory */
1065 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1066 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
1067 {
1068 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1069 SW_BREAKPOINT;
1070 return __LINE__;
1071 }
1072 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
1073 INPUTN * sizeof (*pAstCfg->xInp),
1074 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
1076 #ifdef NON_CACHE_STATUS
1077 /* Decode memory */
1078 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM,
1079 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1080 {
1081 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1082 SW_BREAKPOINT;
1083 return __LINE__;
1084 }
1085 #else
1086 /* Decode memory */
1087 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1088 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1089 {
1090 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1091 SW_BREAKPOINT;
1092 return __LINE__;
1093 }
1094 #endif
1095 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
1096 DECODEN * sizeof (*pAstCfg->xDec),
1097 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
1099 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1100 return 0;
1101 } //PAF_ASIT_initPhaseMalloc
1103 // -----------------------------------------------------------------------------
1104 // ASIT Initialization Function - Memory Initialization from Configuration
1105 //
1106 // Name: PAF_ASIT_initPhaseConfig
1107 // Purpose: Audio Stream Task Function for initialization of data values
1108 // from parameters.
1109 // From: audioStream1Task or equivalent
1110 // Uses: See code.
1111 // States: x
1112 // Return: 0 on success.
1113 // Other as per initFrame0 and initFrame1.
1114 // Trace: Message Log "trace" in Debug Project Configuration reports:
1115 // * State information as per parent.
1116 //
1117 Int
1118 PAF_ASIT_initPhaseConfig(
1119 const PAF_ASIT_Params *pP,
1120 const PAF_ASIT_Patchs *pQ,
1121 PAF_ASIT_Config *pC
1122 )
1123 {
1124 PAF_AST_Config *pAstCfg;
1125 Int as; /* Audio Stream Number (1, 2, etc.) */
1126 Int z; /* input/encode/stream/decode/output counter */
1127 Int zMS;
1129 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1130 as = pAstCfg->as;
1131 zMS = pAstCfg->masterStr;
1133 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1135 //
1136 // Unspecified elements have been initialized to zero during alloc
1137 //
1139 for (z=INPUT1; z < INPUTN; z++)
1140 {
1141 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
1142 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
1143 }
1145 for (z=DECODE1; z < DECODEN; z++)
1146 {
1147 Int zI = pP->inputsFromDecodes[z];
1148 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1149 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1150 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1151 }
1153 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1154 return 0;
1155 } //PAF_ASIT_initPhaseConfig
1157 // -----------------------------------------------------------------------------
1158 // ASIT Initialization Function - ACP Algorithm Instantiation
1159 //
1160 // Name: PAF_ASIT_initPhaseAcpAlg
1161 // Purpose: Audio Stream Input Task Function for initialization of ACP by
1162 // instantiation of the algorithm.
1163 // From: audioStream1Task or equivalent
1164 // Uses: See code.
1165 // States: x
1166 // Return: 0 on success.
1167 // Source code line number on ACP Algorithm creation failure.
1168 // Trace: Message Log "trace" in Debug Project Configuration reports:
1169 // * State information as per parent.
1170 // * Memory allocation errors.
1171 //
1172 Int
1173 PAF_ASIT_initPhaseAcpAlg(
1174 const PAF_ASIT_Params *pP,
1175 const PAF_ASIT_Patchs *pQ,
1176 PAF_ASIT_Config *pC
1177 )
1178 {
1179 PAF_AST_Config *pAstCfg;
1180 Int as; /* Audio Stream Number (1, 2, etc.) */
1181 Int z; /* input/encode/stream/decode/output counter */
1182 Int betaPrimeOffset;
1183 ACP_Handle acp;
1184 Int zMS;
1185 Int zS, zX;
1187 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1188 as = pAstCfg->as;
1189 zMS = pAstCfg->masterStr;
1191 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1193 ACP_MDS_init();
1195 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1196 {
1197 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1198 return __LINE__;
1199 }
1200 pC->acp = acp;
1202 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1203 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1205 for (z=INPUT1; z < INPUTN; z++)
1206 {
1207 zS = z;
1208 for (zX = DECODE1; zX < DECODEN; zX++)
1209 {
1210 if (pP->inputsFromDecodes[zX] == z)
1211 {
1212 zS = pP->streamsFromDecodes[zX];
1213 break;
1214 }
1215 }
1216 acp->fxns->attach(acp, ACP_SERIES_STD,
1217 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1218 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1219 /* Ignore errors, not reported. */
1220 }
1222 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1224 return 0;
1225 } //PAF_ASIT_initPhaseAcpAlg
1227 // -----------------------------------------------------------------------------
1228 // ASIT Initialization Function - Common Memory
1229 //
1230 // Name: PAF_ASIT_initPhaseCommon
1231 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1232 // From: audioStream1Task or equivalent
1233 // Uses: See code.
1234 // States: x
1235 // Return: 0 on success.
1236 // Source code line number on PAF_ALG_alloc failure.
1237 // Source code line number on PAF_ALG_mallocMemory failure.
1238 // Source code line number on Decode Chain initialization failure.
1239 // Source code line number on ASP Chain initialization failure.
1240 // Source code line number on Encode Chain initialization failure.
1241 // Trace: Message Log "trace" in Debug Project Configuration reports:
1242 // * State information as per parent.
1243 // * Memory allocation errors.
1244 //
1245 Int
1246 PAF_ASIT_initPhaseCommon(
1247 const PAF_ASIT_Params *pP,
1248 const PAF_ASIT_Patchs *pQ,
1249 PAF_ASIT_Config *pC
1250 )
1251 {
1252 PAF_AST_Config *pAstCfg;
1253 Int as; /* Audio Stream Number (1, 2, etc.) */
1254 Int z; /* stream counter */
1255 ACP_Handle acp;
1256 PAF_IALG_Config pafAlgConfig;
1257 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1259 acp = pC->acp;
1260 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1261 as = pAstCfg->as;
1263 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1265 //
1266 // Determine memory needs and instantiate algorithms across audio streams
1267 //
1268 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1269 PAF_ALG_setup(&pafAlgConfig,
1270 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1271 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1272 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1273 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1274 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1275 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1276 HEAP_CLEAR);
1278 if (pP->fxns->headerPrint)
1279 {
1280 pP->fxns->headerPrint();
1281 }
1283 for (z = STREAM1; z < STREAMN; z++)
1284 {
1285 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1287 //
1288 // Determine common memory for:
1289 // (1) Logical Input drivers
1290 //
1291 // Decode Algorithms common memory determined in ASP Slave.
1292 //
1293 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1295 //
1296 // Determine common memory needs of Logical Input driver
1297 //
1299 // really need to loop over all inputs for this stream using the tables
1300 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1301 // patch, and not needed for FS11, since there is only one input.
1302 if (INPUT1 <= z && z < INPUTN)
1303 {
1304 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1305 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1306 {
1307 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1308 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1309 SW_BREAKPOINT;
1310 return __LINE__;
1311 }
1312 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1313 if (pP->fxns->allocPrint)
1314 {
1315 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1316 }
1317 }
1318 }
1319 {
1320 // Changes made to share scratch between zones
1321 // Assume maximum 3 zones and scratch common memory is at offset 0;
1322 int max=0;
1323 for (z=STREAM1; z<STREAMN; z++)
1324 {
1325 if (max < common[z][0].size)
1326 {
1327 max = common[z][0].size;
1328 }
1329 }
1330 common[STREAM1][0].size=max;
1331 for (z=STREAM1+1; z<STREAMN; z++)
1332 {
1333 common[z][0].size = 0;
1334 }
1335 }
1337 //
1338 // Allocate common memory for:
1339 // (1) Logical Input drivers
1340 //
1341 for (z = STREAM1; z < STREAMN; z++)
1342 {
1343 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1344 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1345 {
1346 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1347 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1348 SW_BREAKPOINT;
1349 return __LINE__;
1350 }
1351 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1352 // share zone0 scratch with all zones
1353 common[z][0].base = common[0][0].base;
1354 if (pP->fxns->commonPrint)
1355 {
1356 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1357 }
1359 //
1360 // Allocate non-common memories for Logical IO drivers
1361 // Since these structures are used at run-time we allocate from external memory
1362 if (INPUT1 <= z && z < INPUTN)
1363 {
1364 PAF_ASP_Chain *chain;
1365 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1366 as+z, z);
1367 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1368 HEAP_EXTERNAL, as+z, acp, &trace,
1369 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1370 if (!chain)
1371 {
1372 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1373 return __LINE__;
1374 }
1375 }
1376 }
1377 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1379 return 0;
1380 } //PAF_ASIT_initPhaseCommon
1382 // (***) FL: candidate for removal
1383 // -----------------------------------------------------------------------------
1384 // ASIT Initialization Function - Algorithm Keys
1385 //
1386 // Name: PAF_ASIT_initPhaseAlgKey
1387 // Purpose: Audio Stream Input Task Function for initialization of data values
1388 // from parameters for Algorithm Keys.
1389 // From: audioStream1Task or equivalent
1390 // Uses: See code.
1391 // States: x
1392 // Return: 0.
1393 // Trace: Message Log "trace" in Debug Project Configuration reports:
1394 // * State information as per parent.
1395 //
1396 // .............................................................................
1397 Int
1398 PAF_ASIT_initPhaseAlgKey(
1399 const PAF_ASIT_Params *pP,
1400 const PAF_ASIT_Patchs *pQ,
1401 PAF_ASIT_Config *pC
1402 )
1403 {
1404 PAF_AST_Config *pAstCfg;
1405 Int as; /* Audio Stream Number (1, 2, etc.) */
1408 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1409 as = pAstCfg->as;
1410 (void)as; // clear compiler warning in case not used with tracing disabled
1412 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1414 #if 0 // FL: slave
1415 for (z=DECODE1; z < DECODEN; z++)
1416 {
1417 for (s=0; s < pP->pDecAlgKey->length; s++)
1418 {
1419 if ((pP->pDecAlgKey->code[s].full != 0) &&
1420 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1421 {
1422 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1423 /* Cast in interface, for now --Kurt */
1424 }
1425 else
1426 {
1427 pC->xDec[z].decAlg[s] = NULL;
1428 }
1429 }
1430 }
1431 #endif
1433 return 0;
1434 } //PAF_ASIT_initPhaseAlgKey
1436 // -----------------------------------------------------------------------------
1437 // ASIT Initialization Function - I/O Devices
1438 //
1439 // Name: PAF_ASIT_initPhaseDevice
1440 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1441 // From: audioStream1Task or equivalent
1442 // Uses: See code.
1443 // States: x
1444 // Return: 0 on success.
1445 // Source code line number on device allocation failure.
1446 // Trace: Message Log "trace" in Debug Project Configuration reports:
1447 // * State information as per parent.
1448 // * Memory allocation errors.
1449 //
1450 Int
1451 PAF_ASIT_initPhaseDevice(
1452 const PAF_ASIT_Params *pP,
1453 const PAF_ASIT_Patchs *pQ,
1454 PAF_ASIT_Config *pC
1455 )
1456 {
1457 PAF_AST_Config *pAstCfg;
1458 Int as; /* Audio Stream Number (1, 2, etc.) */
1459 Int z; /* input/output counter */
1460 PAF_SIO_IALG_Obj *pObj;
1461 PAF_SIO_IALG_Config *pAlgConfig;
1462 PAF_IALG_Config pafAlgConfig;
1465 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1466 as = pAstCfg->as;
1467 (void)as; // clear compiler warning in case not used with tracing disabled
1469 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1471 if (pP->fxns->bufMemPrint)
1472 {
1473 PAF_ALG_setup (&pafAlgConfig,
1474 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1475 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1476 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1477 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1478 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1479 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1480 HEAP_CLEAR);
1481 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1482 }
1484 for (z=INPUT1; z < INPUTN; z++)
1485 {
1486 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1488 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1489 pAlgConfig = &pObj->config;
1491 pAstCfg->xInp[z].hRxSio = NULL;
1493 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1494 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1495 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1496 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1497 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1498 pConfig->sizeofElement = 2;
1499 pConfig->precision = 16;
1501 if (pP->fxns->bufMemPrint)
1502 {
1503 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1504 }
1505 }
1507 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1509 return 0;
1510 } //PAF_ASIT_initPhaseDevice
1512 // -----------------------------------------------------------------------------
1513 // ASIT Initialization Function - Decoder Output Circular Buffer
1514 //
1515 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1516 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1517 // From: audioStream1Task or equivalent
1518 // Uses: See code.
1519 // States: x
1520 // Return: 0 on success.
1521 // Source code line number on device allocation failure.
1522 // Trace: Message Log "trace" in Debug Project Configuration reports:
1523 // * State information as per parent.
1524 // * Memory allocation errors.
1525 //
1526 Int
1527 PAF_ASIT_initPhaseDecOpCircBuf(
1528 const PAF_ASIT_Params *pP,
1529 const PAF_ASIT_Patchs *pQ,
1530 PAF_ASIT_Config *pC
1531 )
1532 {
1533 PAF_AST_Config *pAstCfg;
1534 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1535 Int as; /* Audio Stream Number (1, 2, etc.) */
1536 Int zMS;
1537 Int z; /* decode counter */
1538 Int errno; /* error number */
1539 Error_Block eb;
1540 Int i;
1542 // FL: (***)revisit
1543 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1544 as = pAstCfg->as;
1545 zMS = pAstCfg->masterStr;
1547 /* Decode output circular buffer memory */
1548 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1549 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1550 {
1551 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1552 SW_BREAKPOINT;
1553 return __LINE__;
1554 }
1556 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1557 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1558 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1560 for (z=DECODE1; z < DECODEN; z++)
1561 {
1562 pCb = &pAstCfg->xDecOpCb[z];
1564 // allocate audio frame circular buffer
1565 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1566 {
1567 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1568 SW_BREAKPOINT;
1569 }
1570 // allocate audio frame PCM sample pointer array
1571 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1572 {
1573 if (!(pCb->afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioData *), 4, &eb)))
1574 {
1575 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1576 SW_BREAKPOINT;
1577 }
1578 if (!(pCb->afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioSize), 4, &eb)))
1579 {
1580 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1581 SW_BREAKPOINT;
1582 }
1583 }
1584 // allocate PCM sample buffer
1585 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1586 {
1587 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1588 SW_BREAKPOINT;
1589 }
1590 pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1591 // allocate Metadata buffers //QIN
1592 if (!(pCb->metaBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
1593 {
1594 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1595 SW_BREAKPOINT;
1596 }
1597 pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1598 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1599 // Initialize decoder output circular buffer for PCM
1600 errno = cbInit(pCb);
1601 if (errno)
1602 {
1603 SW_BREAKPOINT; // FL: debug
1604 return errno;
1605 }
1606 }
1608 return 0;
1609 } //PAF_ASIT_initPhaseDecOpCircBuf
1612 #if 0
1613 // -----------------------------------------------------------------------------
1614 // AST Processing Function - Pass-Through Processing
1615 //
1616 // Name: PAF_AST_passProcessing
1617 // Purpose: Audio Stream Task Function for processing audio data as a
1618 // pass-through from the input driver to the output driver
1619 // for development and testing.
1620 // From: audioStream1Task or equivalent
1621 // Uses: See code.
1622 // States: x
1623 // Return: Error number in standard form (0 on success).
1624 // Trace: Message Log "trace" in Debug Project Configuration reports:
1625 // * State information on initialization.
1626 // * State information on processing.
1627 //
1629 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1630 /* Pass Processing is often omitted from builds to save memory, */
1631 /* and CODE_SECTION/clink constructs facilitate this omission. */
1633 Int
1634 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1635 {
1636 Int z; /* input/output counter */
1637 Int errno = 0; /* error number */
1638 Int getVal;
1639 Int rxNumChan, txNumChan;
1640 Int first;
1641 Int zMD = pC->masterDec;
1642 Int zMI = pP->zone.master;
1645 #ifndef __TI_EABI__
1646 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1647 #endif
1649 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1651 //
1652 // Determine that receive/transmit channels are compatible
1653 //
1655 // Can handle handle only master input
1656 for (z=INPUT1; z < INPUTN; z++) {
1657 if (z != zMI && pC->xInp[z].hRxSio)
1658 return (ASPERR_PASS + 0x01);
1659 }
1661 /* Number of receive/transmit channels */
1663 if (! pC->xInp[zMI].hRxSio)
1664 return (ASPERR_PASS + 0x11);
1665 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1666 return (ASPERR_PASS + 0x12);
1667 if (rxNumChan > NUM_TX_CHAN(zMI))
1668 return (ASPERR_PASS + 0x13);
1670 for (z=OUTPUT1; z < OUTPUTN; z++) {
1671 if (! pC->xOut[zMI].hTxSio)
1672 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1673 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1674 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1675 if (txNumChan > NUM_TX_CHAN(zMI))
1676 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1677 }
1679 //
1680 // Set up receive/transmit
1681 //
1683 SIO_idle (pC->xInp[zMI].hRxSio);
1684 for (z=OUTPUT1; z < OUTPUTN; z++) {
1685 if(SIO_idle (pC->xOut[z].hTxSio))
1686 return ASPERR_IDLE;
1687 }
1689 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1690 return (ASPERR_PASS + 0x14);
1692 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1693 return (ASPERR_PASS + 0x15);
1695 for (z=OUTPUT1; z < OUTPUTN; z++)
1696 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1698 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1699 return ASPERR_PASS + 0x16;
1701 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1702 return ASPERR_PASS + 0x17;
1704 //
1705 // Receive and transmit the data in single-frame buffers
1706 //
1708 first = 1;
1709 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1710 PAF_OutBufConfig *pOutBuf;
1711 PAF_InpBufConfig *pInpBuf;
1713 if (first) {
1714 first = 0;
1716 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1718 for (z=OUTPUT1; z < OUTPUTN; z++) {
1719 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1720 if (getVal > 0) {
1721 errno = ASPERR_ISSUE;
1722 break;
1723 }
1724 else if (getVal < 0) {
1725 errno = -getVal;
1726 break;
1727 }
1729 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1730 return (getVal & 0xff) | ASPERR_MUTE;
1731 }
1732 if (errno)
1733 break;
1735 }
1737 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1738 if (getVal > 0) {
1739 errno = ASPERR_ISSUE;
1740 break;
1741 }
1743 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1745 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1746 if (getVal < 0) {
1747 errno = -getVal;
1748 break;
1749 }
1751 for (z=OUTPUT1; z < OUTPUTN; z++) {
1752 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1753 if (getVal < 0) {
1754 errno = -getVal;
1755 break;
1756 }
1757 }
1758 if( errno )
1759 break;
1761 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1763 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1764 break;
1766 for (z=OUTPUT1; z < OUTPUTN; z++) {
1767 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1768 if (getVal > 0) {
1769 errno = ASPERR_ISSUE;
1770 break;
1771 }
1772 else if (getVal < 0) {
1773 errno = -getVal;
1774 break;
1775 }
1776 }
1777 if( errno )
1778 break;
1779 }
1781 //
1782 // Close down receive/transmit
1783 //
1785 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1787 for (z=OUTPUT1; z < OUTPUTN; z++) {
1788 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1789 if (! errno)
1790 errno = (getVal & 0xff) | ASPERR_MUTE;
1791 /* convert to sensical errno */
1792 }
1793 }
1795 SIO_idle (pC->xInp[zMI].hRxSio);
1796 for (z=OUTPUT1; z < OUTPUTN; z++)
1797 SIO_idle (pC->xOut[z].hTxSio);
1799 return errno;
1801 } //PAF_AST_passProcessing
1802 #endif // #if 0
1804 #if 0
1805 // -----------------------------------------------------------------------------
1806 // AST Processing Function Helper - Pass-Through Processing Patch Point
1807 //
1808 // Name: PAF_AST_passProcessingCopy
1809 // Purpose: Pass-Through Processing Function for copying audio data
1810 // from the input buffer to the output buffer.
1811 // From: AST Parameter Function -> passProcessing
1812 // Uses: See code.
1813 // States: x
1814 // Return: Error number in standard form (0 on success).
1815 // Trace: Message Log "trace" in Debug Project Configuration reports:
1816 // x
1817 //
1819 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1820 /* Pass Processing is often omitted from builds to save memory, */
1821 /* and CODE_SECTION/clink constructs facilitate this omission. */
1823 Int
1824 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1825 {
1826 Int z; /* output counter */
1827 Int errno; /* error number */
1828 Int i;
1829 Int rxNumChan, txNumChan;
1830 Int zMI = pP->zone.master;
1833 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1835 // Copy data from input channels to output channels one of two ways:
1837 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1838 return (ASPERR_PASS + 0x12);
1840 for (z=OUTPUT1; z < OUTPUTN; z++) {
1841 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1842 return (ASPERR_PASS + 0x22);
1844 if( txNumChan <= rxNumChan ) {
1846 // Copy one to one, ignoring later rx channels as needed.
1848 for( i=0; i < txNumChan; i++ ) {
1849 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1850 if( errno )
1851 return errno;
1852 }
1853 }
1854 else {
1856 // Copy one to many, repeating earlier rx channels as needed.
1858 Int from, to;
1860 from = 0;
1861 to = 0;
1862 while( to < txNumChan ) {
1863 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1864 if( errno )
1865 return errno;
1867 from++;
1868 to++;
1869 if( from == rxNumChan )
1870 from = 0;
1871 }
1872 }
1873 }
1875 return 0;
1876 } //PAF_AST_passProcessingCopy
1877 #endif // #if 0
1879 // -----------------------------------------------------------------------------
1880 // ASIT Processing Function - Auto Processing
1881 //
1882 // Name: PAF_ASIT_autoProcessing
1883 // Purpose: Audio Stream Input Task Function for processing audio data to
1884 // determine the input type without output.
1885 // From: audioStream1Task or equivalent
1886 // Uses: See code.
1887 // States: x
1888 // Return: Error number in standard or SIO form (0 on success).
1889 // Trace: Message Log "trace" in Debug Project Configuration reports:
1890 // * State information on initialization.
1891 //
1893 #define DECSIOMAP(X) \
1894 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1896 Int
1897 PAF_ASIT_autoProcessing(
1898 const PAF_ASIT_Params *pP,
1899 const PAF_ASIT_Patchs *pQ,
1900 PAF_ASIT_Config *pC,
1901 Int inputTypeSelect,
1902 ALG_Handle pcmAlgMaster
1903 )
1904 {
1905 PAF_AST_Config *pAstCfg;
1906 Int as; /* Audio Stream Number (1, 2, etc.) */
1907 Int errno = 0; /* error number */
1908 Int nbytes;
1909 Int frameLength;
1910 Int zMD;
1911 Int zMI;
1912 Int zMS;
1914 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1915 as = pAstCfg->as;
1916 zMD = pAstCfg->masterDec;
1917 zMS = pAstCfg->masterStr;
1918 zMI = pP->zone.master;
1920 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1922 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1923 PAF_SIO_CONTROL_SET_SOURCESELECT,
1924 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1925 {
1926 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1927 return errno;
1928 }
1929 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1930 // pC->xDec[zMD].decodeStatus.bufferRatio);
1931 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1933 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1934 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1935 {
1936 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1937 errno, ASPERR_AUTO_LENGTH);
1938 return ASPERR_AUTO_LENGTH;
1939 }
1941 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1942 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1943 PAF_SIO_REQUEST_SYNC))
1944 {
1945 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1946 errno, ASPERR_ISSUE);
1947 return ASPERR_ISSUE;
1948 }
1950 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1952 // all of the sync scan work is done in this call. If the error returned
1953 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1954 // error so we mask it off.
1955 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1956 if (nbytes == -DIBERR_SYNC)
1957 {
1958 #if 1 // (***) FL: shows timing of autosync restart
1959 // (***) debug // B5
1960 {
1961 static Uint8 toggleState = 0;
1962 if (toggleState == 0)
1963 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
1964 else
1965 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
1966 toggleState = ~(toggleState);
1967 }
1968 #endif
1969 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1970 return nbytes;
1971 }
1972 if (nbytes != sizeof(PAF_InpBufConfig))
1973 {
1974 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1975 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1976 return ASPERR_RECLAIM;
1977 }
1978 if (errno)
1979 {
1980 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1981 }
1982 return errno;
1983 } //PAF_ASIT_autoProcessing
1985 UInt32 gProbe1Err=0;
1986 UInt32 gProbe2Err=0;
1987 UInt32 gMajorAuMissed=0;
1989 // -----------------------------------------------------------------------------
1990 // ASIT Processing Function - Decode Processing
1991 //
1992 // Name: PAF_ASIT_decodeProcessing
1993 // Purpose: Audio Stream Input Task Function for processing audio data.
1994 // From: audioStream1Task or equivalent
1995 // Uses: See code.
1996 // States: x
1997 // Return: Error number in standard form (0 on success).
1998 // Trace: Message Log "trace" in Debug Project Configuration reports:
1999 // * State information on initialization (via children).
2000 // * State information on processing (via children).
2001 // * Decode warnings.
2002 //
2003 // When "writeDECModeContinuous" is used for zMI input/decode:
2004 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
2005 // (a) if "writeDECCommandRestart" is used
2006 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
2007 // (b) if "writeDECSourceSelectNone" is used
2008 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
2009 // (c) if an error occurs in
2010 // INIT
2011 // CONT ("subsequent block state", which "Establish[es] secondary timing")
2012 // -> PAF_AST_decodeCont(): "Await slave inputs"
2013 // STREAM (errno |= PAF_COMPONENT_ASP)
2014 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
2015 // [ the latter errors lead to "switch_break:"
2016 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
2017 //
2018 // [ Notably, in FINAL ("frame-finalization state")
2019 // -> PAF_AST_decodeFinalTest() is *not* called,
2020 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
2021 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
2022 //
2023 // States in which error can't occur:
2024 // AGAIN ("subsequent initial state")
2025 //
2026 // States in which (some) errors must be handled:
2027 // INFO1 ("first frame state")
2028 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
2029 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
2030 // ?*? but what about ASPERR_RESYNC from same call ?*?
2031 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
2032 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
2033 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
2034 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
2035 // - enc->fxns->info()
2036 // - pP->fxns->setCheckRateX()
2037 // - pP->fxns->startOutput()
2038 // - "Start slave inputs if necessary"
2039 // INFO2 ("subsequent frame state")
2040 // -> PAF_AST_decodeInfo(): (see above)
2041 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
2042 // - pP->fxns->setCheckRateX()
2043 // TIME ("timing state")
2044 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
2045 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
2046 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
2047 // (*OK* don't try to recover from this*)
2048 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
2049 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
2050 // possibly in PAF_AST_decodeProcessing() itself **
2051 // DECODE ("decode state")
2052 // -> PAF_AST_decodeDecode(): pass on error from
2053 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
2054 // - dec->fxns->reset()
2055 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
2056 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
2057 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
2058 Int
2059 PAF_ASIT_decodeProcessing(
2060 const PAF_ASIT_Params *pP,
2061 const PAF_ASIT_Patchs *pQ,
2062 PAF_ASIT_Config *pC,
2063 Int sourceSelect
2064 )
2065 {
2066 PAF_AST_Config *pAstCfg;
2067 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2068 Int z; /* decode counter */
2069 Int errno; /* error number */
2070 Int getVal;
2071 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
2072 ALG_Handle alg[DECODEN_MAX];
2073 Int zMD;
2074 Int zMS;
2075 Int size;
2076 //PAF_InpBufConfig *pIpBufConfig;
2077 Int frame; // decoder input frame count
2078 Int block; // (***) FL: formerly -- decoder output block count / input frame
2079 #ifdef NON_CACHE_STATUS
2080 Int8 tempVar8, temp2Var8;
2081 #endif
2083 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2084 zMD = pAstCfg->masterDec;
2085 zMS = pAstCfg->masterStr;
2087 for (z=DECODE1; z < DECODEN; z++)
2088 {
2089 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
2090 }
2091 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
2093 //
2094 // Receive and process the data in single-frame buffers
2095 //
2097 state = INIT;
2098 errno = 0; /* error number */
2100 #ifdef NON_CACHE_STATUS
2101 statusOp_read(&tempVar8,
2102 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2103 sizeof(tempVar8),
2104 GATEMP_INDEX_DEC);
2105 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
2107 for (;;)
2108 {
2109 statusOp_read(&tempVar8,
2110 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2111 sizeof(tempVar8),
2112 GATEMP_INDEX_DEC);
2113 if (tempVar8 == PAF_SOURCE_NONE)
2114 {
2115 #else
2116 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
2118 for (;;)
2119 {
2120 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
2121 {
2122 #endif
2123 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
2124 state = QUIT;
2125 }
2127 // Process commands (decode)
2128 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
2129 {
2130 if (state != INIT) // no need to restart/abort if not yet started
2131 {
2132 if (getVal == ASPERR_QUIT)
2133 {
2134 state = QUIT;
2135 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
2136 }
2137 else if (getVal == ASPERR_ABORT)
2138 {
2139 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
2141 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2142 pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS);
2143 gNumPfpAsit1--;
2145 return getVal;
2146 }
2147 else
2148 {
2149 /* ignore */;
2150 }
2151 }
2152 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
2153 }
2155 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
2156 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
2158 // Process state (decode)
2159 switch (state)
2160 {
2161 case INIT: // initial state
2162 gAsipInitCnt++;
2163 Log_info0("TaskAsip: state=INIT");
2165 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
2166 {
2167 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
2168 break;
2169 }
2171 frame = 0;
2172 block = 0;
2174 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2175 state = INFO1;
2176 continue;
2178 case INFO1: // first frame state
2179 gAsipInfo1Cnt++;
2180 Log_info0("TaskAsip: state=INFO1");
2182 // Establish primary timing
2183 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2184 {
2185 gAsipInfo1_PrimaryErrCnt++;
2186 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2187 break;
2188 }
2190 #ifdef NON_CACHE_STATUS
2191 statusOp_read(&tempVar8,
2192 &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2193 sizeof(tempVar8),
2194 GATEMP_INDEX_DEC);
2195 statusOp_read(&temp2Var8,
2196 &(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
2197 sizeof(tempVar8),
2198 GATEMP_INDEX_DEC);
2199 // Don't start decode until major access unit is found.
2200 if (((tempVar8 == PAF_SOURCE_THD) ||
2201 (tempVar8 == PAF_SOURCE_DXP) ||
2202 (tempVar8 == PAF_SOURCE_DTSHD)) &&
2203 (temp2Var8 == PAF_SAMPLERATE_UNKNOWN))
2204 #else
2205 // Don't start decode until major access unit is found.
2206 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
2207 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
2208 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2209 (pAstCfg->xDec[zMD].decodeStatus.sampleRate == PAF_SAMPLERATE_UNKNOWN))
2210 #endif
2211 {
2212 Int z;
2213 for (z=DECODE1; z < DECODEN; z++)
2214 {
2215 Int zI = pP->inputsFromDecodes[z];
2216 #ifdef NON_CACHE_STATUS
2217 statusOp_read(&tempVar8,
2218 &(pAstCfg->xDec[z].decodeStatus.mode),
2219 sizeof(tempVar8),
2220 GATEMP_INDEX_DEC);
2221 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2222 {
2223 #else
2224 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2225 {
2226 #endif
2227 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2228 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2229 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2230 {
2231 gProbe2Err++;
2232 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2234 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2235 pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS);
2236 gNumPfpAsit1--;
2238 return (ASPERR_ISSUE);
2239 }
2240 }
2241 }
2242 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2243 gMajorAuMissed++; // debug
2244 frame++;
2245 state = INFO1;
2246 continue;
2247 }
2248 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2250 // Establish secondary timing
2251 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2252 {
2253 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2254 gAsipInfo1_ErrCnt++;
2255 break;
2256 }
2258 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2259 state = DECODE;
2260 continue;
2262 case INFO2: // subsequent frame state
2263 gAsipInfo2Cnt++;
2264 Log_info0("TaskAsip: state=INFO2");
2266 // Establish primary timing
2267 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2268 {
2269 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2270 gAsipInfo2_PrimaryErrCnt++;
2271 break;
2272 }
2274 // Measure cycles in decode processing loop.
2275 // Only measures cycles spent in loop.
2276 pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS); // PFP end
2277 gNumPfpAsit1--;
2278 pfpBegin(PFP_ID_ASIT_1, pC->taskHandle); // PFP begin
2279 gNumPfpAsit1++;
2281 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2282 {
2283 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2284 gAsipInfo2_ErrCnt++;
2285 break;
2286 }
2288 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2289 state = DECODE;
2290 continue;
2292 case DECODE: // decode state
2293 gAsipDecodeCnt++;
2294 Log_info0("TaskAsip: state=DECODE");
2296 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2297 {
2298 gAsipDecodeErrCnt++;
2299 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2300 break;
2301 }
2303 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2304 state = FINAL;
2305 continue;
2307 case FINAL: // frame-finalization state
2308 gAsipFinalCnt++;
2309 Log_info0("TaskAsip: state=FINAL");
2311 // Check for final frame, and if indicated:
2312 // - Exit state machine to "complete" processing.
2313 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2314 {
2315 break;
2316 }
2318 frame++;
2319 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2320 state = INFO2;
2321 continue;
2323 case QUIT: // exit state
2324 gAsipQuitCnt++;
2325 Log_info0("TaskAsip: state=QUIT");
2327 // Quit:
2328 // - Set error number registers.
2329 // - Exit state machine to "decode complete" processing.
2330 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2331 errno = ASPERR_QUIT;
2332 break;
2334 default: // unknown state
2336 // Unknown:
2337 // - Set error number registers.
2338 // - Exit state machine to "decode complete" processing.
2340 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2341 errno = ASPERR_UNKNOWNSTATE;
2342 break;
2344 } // End of switch (state).
2346 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2347 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2348 {
2349 /* ignored? */;
2350 }
2352 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2354 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2355 //pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS);
2356 //gNumPfpAsit1--;
2358 //return errno;
2359 break;
2360 } // End of for (;;) to Receive, process, and transmit the data.
2362 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2363 pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS);
2364 gNumPfpAsit1--;
2366 return errno;
2367 } //PAF_ASIT_decodeProcessing
2369 // -----------------------------------------------------------------------------
2370 // ASIT Decoding Function - Decode Command Processing
2371 //
2372 // Name: PAF_ASIT_decodeCommand
2373 // Purpose: Decoding Function for processing Decode Commands.
2374 // From: AST Parameter Function -> decodeProcessing
2375 // Uses: See code.
2376 // States: x
2377 // Return: Error number in standard form (0 on success).
2378 // Trace: Message Log "trace" in Debug Project Configuration reports:
2379 // * Command execution.
2380 //
2382 Int
2383 PAF_ASIT_decodeCommand(
2384 const PAF_ASIT_Params *pP,
2385 const PAF_ASIT_Patchs *pQ,
2386 PAF_ASIT_Config *pC
2387 )
2388 {
2389 PAF_AST_Config *pAstCfg;
2390 Int as; /* Audio Stream Number (1, 2, etc.) */
2391 Int z; /* decode counter */
2392 Int zS;
2393 #ifdef NON_CACHE_STATUS
2394 Int8 tempVar8;
2395 #endif
2397 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2398 as = pAstCfg->as;
2400 for (z=DECODE1; z < DECODEN; z++)
2401 {
2402 zS = pP->streamsFromDecodes[z];
2403 #ifdef NON_CACHE_STATUS
2404 statusOp_read(&tempVar8,
2405 &(pAstCfg->xDec[z].decodeStatus.command2),
2406 sizeof(tempVar8),
2407 GATEMP_INDEX_DEC);
2408 if (!(tempVar8 & 0x80))
2409 {
2410 switch (tempVar8)
2411 {
2412 case 0: // command none - process
2413 tempVar8 |= 0x80;
2414 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2415 &tempVar8,
2416 sizeof(tempVar8),
2417 GATEMP_INDEX_DEC);
2418 break;
2419 case 1: // command abort - leave now
2420 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2421 tempVar8 |= 0x80;
2422 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2423 &tempVar8,
2424 sizeof(tempVar8),
2425 GATEMP_INDEX_DEC);
2426 return (ASPERR_ABORT);
2427 case 2: // command restart - leave later
2428 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2429 tempVar8 |= 0x80;
2430 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2431 &tempVar8,
2432 sizeof(tempVar8),
2433 GATEMP_INDEX_DEC);
2434 return (ASPERR_QUIT);
2435 default: // command unknown - ignore
2436 break;
2437 }
2438 }
2439 #else
2440 if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2441 {
2442 switch (pAstCfg->xDec[z].decodeStatus.command2)
2443 {
2444 case 0: // command none - process
2445 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2446 break;
2447 case 1: // command abort - leave now
2448 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2449 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2450 return (ASPERR_ABORT);
2451 case 2: // command restart - leave later
2452 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2453 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2454 return (ASPERR_QUIT);
2455 default: // command unknown - ignore
2456 break;
2457 }
2458 }
2459 #endif
2460 }
2462 return 0;
2463 } //PAF_ASIT_decodeCommand
2465 // -----------------------------------------------------------------------------
2466 // ASIT Decoding Function - Reinitialization of Decode
2467 //
2468 // Name: PAF_ASIT_decodeInit
2469 // Purpose: Decoding Function for reinitializing the decoding process.
2470 // From: AST Parameter Function -> decodeProcessing
2471 // Uses: See code.
2472 // States: x
2473 // Return: Error number in standard or SIO form (0 on success).
2474 // Trace: Message Log "trace" in Debug Project Configuration reports:
2475 // * State information as per parent.
2476 //
2477 Int
2478 PAF_ASIT_decodeInit(
2479 const PAF_ASIT_Params *pP,
2480 const PAF_ASIT_Patchs *pQ,
2481 PAF_ASIT_Config *pC,
2482 Int sourceSelect
2483 )
2484 {
2485 PAF_AST_Config *pAstCfg;
2486 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2487 Int as; /* Audio Stream Number (1, 2, etc.) */
2488 Int z; /* decode/encode counter */
2489 Int errno; /* error number */
2490 Int zI, zS;
2491 Int zMD;
2492 Int zMI;
2493 ASP_Msg* pAspMsg; /* Messaging */
2494 Int argIdx;
2495 Int status;
2496 #ifdef NON_CACHE_STATUS
2497 Int8 tempVar8;
2498 #endif
2500 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2501 as = pAstCfg->as;
2502 zMD = pAstCfg->masterDec;
2503 zMI = pP->zone.master;
2504 (void)as; // clear compiler warning in case not used with tracing disabled
2506 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2508 #ifdef NON_CACHE_STATUS
2509 // reset frameCount
2510 for (z=DECODE1; z < DECODEN; z++)
2511 {
2512 statusOp_read(&tempVar8,
2513 &(pAstCfg->xDec[z].decodeStatus.mode),
2514 sizeof(tempVar8),
2515 GATEMP_INDEX_DEC);
2516 if (tempVar8)
2517 {
2518 tempVar8 = 0;
2519 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2520 &tempVar8,
2521 sizeof(tempVar8),
2522 GATEMP_INDEX_DEC);
2523 }
2524 }
2526 for (z=DECODE1; z < DECODEN; z++)
2527 {
2528 zI = pP->inputsFromDecodes[z];
2529 zS = pP->streamsFromDecodes[z];
2530 (void)zS; // clear compiler warning in case not used with tracing disabled
2531 statusOp_read(&tempVar8,
2532 &(pAstCfg->xDec[z].decodeStatus.mode),
2533 sizeof(tempVar8),
2534 GATEMP_INDEX_DEC);
2535 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2536 {
2537 #else
2538 // reset frameCount
2539 for (z=DECODE1; z < DECODEN; z++)
2540 {
2541 if (pAstCfg->xDec[z].decodeStatus.mode)
2542 {
2543 pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2544 }
2545 }
2547 for (z=DECODE1; z < DECODEN; z++)
2548 {
2549 zI = pP->inputsFromDecodes[z];
2550 zS = pP->streamsFromDecodes[z];
2551 (void)zS; // clear compiler warning in case not used with tracing disabled
2552 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2553 {
2554 #endif
2555 Uns gear;
2556 Int frameLength;
2557 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2559 // write back Dec configuration
2560 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2561 Cache_wait();
2563 // FL: send dec activate message to slave
2564 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2565 if (pAspMsg == NULL)
2566 {
2567 TRACE_TERSE0("MessageQ_alloc() failure.");
2568 SW_BREAKPOINT; // temporary
2569 return -1; // temporary
2570 }
2571 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2572 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2573 pAspMsg->procId = hAspMsgMaster->masterProcId;
2574 pAspMsg->expectResp = TRUE;
2575 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2576 argIdx = 0; // set decIdx (zone index)
2577 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2578 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2579 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2580 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2581 if (status != MessageQ_S_SUCCESS)
2582 {
2583 SW_BREAKPOINT;
2584 }
2585 // wait for dec activate complete message from slave
2586 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2587 if (status != MessageQ_S_SUCCESS)
2588 {
2589 TRACE_TERSE0("MessageQ_get() failure.");
2590 SW_BREAKPOINT; // temporary
2591 return -1; // temporary
2592 }
2593 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2594 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2595 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2596 {
2597 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2598 SW_BREAKPOINT; // temporary
2599 return -1; // temporary
2600 }
2601 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2602 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2603 // free the message
2604 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2605 if (status != MessageQ_S_SUCCESS)
2606 {
2607 SW_BREAKPOINT;
2608 }
2610 #if 0 // FL: decoder activate call, slave
2611 if (decAlg[z]->fxns->algActivate)
2612 decAlg[z]->fxns->algActivate (decAlg[z]);
2613 #endif
2615 // FL: send dec reset message to slave
2616 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2617 if (pAspMsg == NULL)
2618 {
2619 TRACE_TERSE0("MessageQ_alloc() failure.");
2620 SW_BREAKPOINT; // temporary
2621 return -1; // temporary
2622 }
2623 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2624 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2625 pAspMsg->procId = hAspMsgMaster->masterProcId;
2626 pAspMsg->expectResp = TRUE;
2627 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2628 argIdx = 0; // set decIdx
2629 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2630 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2631 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2632 // wait for dec reset complete message from slave
2633 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2634 if (status != MessageQ_S_SUCCESS)
2635 {
2636 SW_BREAKPOINT;
2637 }
2638 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2639 if (status != MessageQ_S_SUCCESS)
2640 {
2641 TRACE_TERSE0("MessageQ_get() failure.");
2642 SW_BREAKPOINT; // temporary
2643 return -1; // temporary
2644 }
2645 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2646 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2647 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2648 {
2649 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2650 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2651 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2653 argIdx = 0; // get decErrno
2654 errno = *(Int32 *)&pAspMsg->buf[argIdx];
2655 }
2656 else
2657 {
2658 //
2659 // Invalid message received
2660 //
2661 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2662 SW_BREAKPOINT; // temporary
2663 return -1; // temporary
2664 }
2665 // free the message
2666 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2667 if (status != MessageQ_S_SUCCESS)
2668 {
2669 SW_BREAKPOINT;
2670 }
2672 // (***) FL: revisit
2673 // invalidate Dec configuration
2674 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2675 Cache_wait();
2677 #if 0 // FL: decoder reset call, slave
2678 if (dec->fxns->reset
2679 && (errno = dec->fxns->reset (dec, NULL,
2680 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2681 return errno;
2682 #endif
2683 if (errno != 0)
2684 {
2685 return errno;
2686 }
2688 #ifdef NON_CACHE_STATUS
2689 gear = 0; // due to size difference
2690 statusOp_read(&gear,
2691 &(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2692 sizeof(Int8),
2693 GATEMP_INDEX_DEC);
2694 tempVar8 = gear < GEARS ? gear : 0;
2695 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2696 &tempVar8,
2697 sizeof(tempVar8),
2698 GATEMP_INDEX_DEC);
2699 #else
2700 gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2701 pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2702 #endif
2704 #if 0 // FL: change handle to decIdx (zone index)
2705 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2706 FRAMELENGTH,
2707 pC->xDec[z].decodeStatus.bufferRatio);
2708 #endif
2709 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2710 frameLength = pP->fxns->computeFrameLength(z,
2711 FRAMELENGTH,
2712 pC->xDec[z].decodeStatus.bufferRatio);
2713 #else
2714 if (sourceSelect == PAF_SOURCE_PCM)
2715 {
2716 frameLength = PAF_SYS_FRAMELENGTH;
2717 }
2718 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2719 {
2720 frameLength = 1536;
2721 }
2722 else if (sourceSelect == PAF_SOURCE_THD)
2723 {
2724 frameLength = 1536; //QIN FIX ME
2725 }
2726 else
2727 {
2728 frameLength = 256;
2729 }
2730 #endif
2732 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2733 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2734 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2736 // (***) FL: revisit. Count samples for DDP.
2737 // Add framework frame length and running sample count to decoder control.
2738 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2739 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2741 // Initialize decoder output circular buffer for selected source
2742 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2743 if (errno)
2744 {
2745 SW_BREAKPOINT; // FL: debug
2746 return errno;
2747 }
2748 // FL: debug
2749 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2751 if (z != zMD)
2752 {
2753 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2754 {
2755 return errno;
2756 }
2757 }
2759 #ifdef NON_CACHE_STATUS
2760 statusOp_read(&tempVar8,
2761 &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2762 sizeof(Int8),
2763 GATEMP_INDEX_DEC);
2764 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2765 DECSIOMAP(tempVar8)))
2766 {
2767 return errno;
2768 }
2769 #else
2770 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2771 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2772 {
2773 return errno;
2774 }
2775 #endif
2776 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2777 frameLength))
2778 {
2779 return errno;
2780 }
2781 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2782 &pAstCfg->xInp[zI].inpBufConfig))
2783 {
2784 return errno;
2785 }
2786 }
2787 }
2789 if (pAstCfg->xInp[zMI].hRxSio)
2790 {
2791 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2792 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2793 if (errno)
2794 {
2795 return errno;
2796 }
2797 }
2799 return 0;
2800 } //PAF_AST_decodeInit
2802 // -----------------------------------------------------------------------------
2803 // ASIT Decoding Function - Info Processing, Common
2804 //
2805 // Name: PAF_ASIT_decodeInfo
2806 // Purpose: Decoding Function for processing information in a manner that
2807 // is common for both initial and subsequent frames of input data.
2808 // From: AST Parameter Function -> decodeProcessing
2809 // Uses: See code.
2810 // States: x
2811 // Return: Error number in standard form (0 on success).
2812 // Trace: Message Log "trace" in Debug Project Configuration reports:
2813 // * State information as per parent.
2814 //
2815 Int
2816 PAF_ASIT_decodeInfo(
2817 const PAF_ASIT_Params *pP,
2818 const PAF_ASIT_Patchs *pQ,
2819 PAF_ASIT_Config *pC,
2820 Int frame,
2821 Int block
2822 )
2823 {
2824 PAF_AST_Config *pAstCfg;
2825 Int as; /* Audio Stream Number (1, 2, etc.) */
2826 Int z; /* input/decode/stream counter */
2827 Int errno; /* error number */
2828 Int sioErr; /* error number, SIO */
2829 Int zD, zI, zS, zX;
2830 Int zMD;
2831 Int zMI;
2832 Int zMS;
2833 UInt32 curTime;
2834 ASP_Msg *pAspMsg; /* Messaging */
2835 Int argIdx;
2836 Int status;
2837 #ifdef NON_CACHE_STATUS
2838 Int8 tempVar8;
2839 Int tempVar;
2840 #endif
2841 // FL: revisit
2842 //Int size;
2843 //PAF_InpBufConfig *pIpBufConfig;
2845 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2846 as = pAstCfg->as;
2847 zMD = pAstCfg->masterDec;
2848 zMS = pAstCfg->masterStr;
2849 zMI = pP->zone.master;
2850 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2852 // Set decode control: sample rate, emphasis
2853 for (z=INPUT1; z < INPUTN; z++)
2854 {
2855 zD = z;
2856 for (zX = DECODE1; zX < DECODEN; zX++)
2857 {
2858 if (pP->inputsFromDecodes[zX] == z)
2859 {
2860 zD = zX;
2861 break;
2862 }
2863 }
2864 #ifdef PROFILER
2865 // modify for different sampling rate
2866 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus == PAF_SAMPLERATE_96000HZ)
2867 {
2868 start_profiling = 1;
2869 }
2870 else
2871 {
2872 start_profiling = 0;
2873 }
2874 #endif
2875 if (pAstCfg->xInp[z].hRxSio)
2876 {
2877 //determine associated decoder
2878 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2879 pAstCfg->xDec[zD].decodeControl.sampleRate)
2880 {
2881 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2882 {
2883 pAstCfg->xDec[zD].decodeControl.sampleRate =
2884 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2885 }
2886 else
2887 {
2888 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2889 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2890 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2891 pAstCfg->xDec[zD].decodeControl.sampleRate);
2892 // return (ASPERR_INFO_RATECHANGE);
2893 }
2894 }
2895 #ifdef NON_CACHE_STATUS
2896 statusOp_read(&tempVar8,
2897 &(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2898 sizeof(Int8),
2899 GATEMP_INDEX_DEC);
2900 pAstCfg->xDec[zD].decodeControl.emphasis =
2901 tempVar8 != PAF_SOURCE_PCM
2902 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2903 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2904 #else
2905 pAstCfg->xDec[zD].decodeControl.emphasis =
2906 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2907 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2908 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2909 #endif
2910 }
2911 else
2912 {
2913 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2914 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2915 }
2916 }
2918 // Wait for info input
2919 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2920 if (pAstCfg->xInp[zMI].hRxSio)
2921 {
2922 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2923 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2924 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2925 {
2926 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2927 return ASPERR_RECLAIM;
2928 }
2930 // FL: debug, capture input buffer
2931 capIb(pAstCfg->xInp[zMI].pInpBuf);
2932 gCapIb_cnt++;
2934 #if 1 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
2935 // (***) debug // B5
2936 {
2937 static Uint8 toggleState = 0;
2938 if (toggleState == 0)
2939 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
2940 else
2941 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
2942 toggleState = ~(toggleState);
2943 }
2944 #endif
2946 //
2947 // Simulate Rx SIO_reclaim() pend
2948 //
2949 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2950 gTaskAsipCnt++;
2951 curTime = Clock_getTicks();
2952 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2953 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2954 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2955 } //pC->xInp[zMI].hRxSio
2957 // Decode info
2958 for (z=DECODE1; z < DECODEN; z++)
2959 {
2960 zI = pP->inputsFromDecodes[z];
2961 zS = pP->streamsFromDecodes[z];
2962 (void)zS; // clear compiler warning in case not used with tracing disabled
2963 #ifdef NON_CACHE_STATUS
2964 statusOp_read(&tempVar8,
2965 &(pAstCfg->xDec[z].decodeStatus.mode),
2966 sizeof(Int8),
2967 GATEMP_INDEX_DEC);
2968 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2969 {
2970 #else
2971 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2972 {
2973 #endif
2974 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2976 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2977 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2978 {
2979 TRACE_TERSE1("return error errno 0x%x.", errno);
2980 return errno;
2981 }
2983 #if 1
2984 // (***) FL: revisit
2985 // write back Inp configuration
2986 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2987 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2988 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2989 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2990 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2991 // write back Dec configuration
2992 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2993 Cache_wait();
2994 #endif
2996 // FL: send info message to slave
2997 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2998 if (pAspMsg == NULL)
2999 {
3000 TRACE_TERSE0("MessageQ_alloc() failure.");
3001 SW_BREAKPOINT; // temporary
3002 return -1; // temporary
3003 }
3004 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3005 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
3006 pAspMsg->procId = hAspMsgMaster->masterProcId;
3007 pAspMsg->expectResp = TRUE;
3008 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3009 argIdx = 0; // set decIdx
3010 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3011 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3012 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3013 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
3014 if (status != MessageQ_S_SUCCESS)
3015 {
3016 SW_BREAKPOINT;
3017 }
3018 // wait for dec info complete message from slave -- temporary
3019 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3020 if (status != MessageQ_S_SUCCESS)
3021 {
3022 TRACE_TERSE0("MessageQ_get() failure.");
3023 SW_BREAKPOINT;
3024 return -1; // temporary
3025 }
3026 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
3027 (pAspMsg->cmd == ASP_MASTER_DEC_INFO_DONE) &&
3028 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3029 {
3030 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3031 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3032 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
3034 argIdx = 0; // get decErrno
3035 errno = *(Int32 *)&pAspMsg->buf[argIdx];
3036 }
3037 else
3038 {
3039 //
3040 // Invalid message received
3041 //
3042 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3043 SW_BREAKPOINT; // temporary
3044 return -1; // temporary
3045 }
3046 // free the message
3047 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3048 if (status != MessageQ_S_SUCCESS)
3049 {
3050 SW_BREAKPOINT;
3051 }
3053 #if 1
3054 // (***) FL: revisit
3055 // invalidate Dec configuration
3056 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3057 Cache_wait();
3058 #endif
3060 #if 0 // FL: decoder info call, slave
3061 if (dec->fxns->info
3062 && (errno = dec->fxns->info (dec, NULL,
3063 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3064 #endif
3065 if (errno)
3066 {
3067 TRACE_TERSE1("return error errno 0x%x.", errno);
3068 return errno;
3069 }
3071 #ifdef NON_CACHE_STATUS
3072 statusOp_read(&tempVar,
3073 &(pAstCfg->xDec[z].decodeStatus.frameCount),
3074 sizeof(Int),
3075 GATEMP_INDEX_DEC);
3076 // increment decoded frame count
3077 tempVar += 1;
3078 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
3079 &tempVar,
3080 sizeof(Int),
3081 GATEMP_INDEX_DEC);
3082 #else
3083 // increment decoded frame count
3084 pAstCfg->xDec[z].decodeStatus.frameCount += 1;
3085 #endif
3086 }
3087 } // z=DECODE1 to DECODEN
3089 #ifdef NON_CACHE_STATUS
3090 statusOp_read(&tempVar8,
3091 &(pAstCfg->xDec[zMD].decodeStatus.mode),
3092 sizeof(Int8),
3093 GATEMP_INDEX_DEC);
3094 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
3095 if (tempVar8)
3096 {
3097 XDAS_Int8 sourceProgram;
3098 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
3099 (Arg)&sourceProgram))
3100 {
3101 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
3102 return ASPERR_AUTO_PROGRAM;
3103 }
3104 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3105 &(sourceProgram),
3106 sizeof(Int8),
3107 GATEMP_INDEX_DEC);
3108 }
3110 // since now decoding update decode status for all enabled decoders
3111 for (z=DECODE1; z < DECODEN; z++)
3112 {
3113 statusOp_read(&tempVar8,
3114 &(pAstCfg->xDec[z].decodeStatus.mode),
3115 sizeof(Int8),
3116 GATEMP_INDEX_DEC);
3117 if (tempVar8)
3118 {
3119 statusOp_read(&tempVar8,
3120 &(pAstCfg->xDec[z].decodeStatus.sourceProgram),
3121 sizeof(Int8),
3122 GATEMP_INDEX_DEC);
3123 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3124 &tempVar8,
3125 sizeof(Int8),
3126 GATEMP_INDEX_DEC);
3127 statusOp_read(&tempVar8,
3128 &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
3129 sizeof(Int8),
3130 GATEMP_INDEX_DEC);
3131 if (tempVar8 == PAF_SOURCE_SNG)
3132 {
3133 tempVar8 = PAF_SOURCE_SNG;
3134 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3135 &tempVar8,
3136 sizeof(Int8),
3137 GATEMP_INDEX_DEC);
3138 }
3139 }
3140 }
3141 #else
3142 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
3143 if (pAstCfg->xDec[zMD].decodeStatus.mode)
3144 {
3145 XDAS_Int8 sourceProgram;
3146 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
3147 (Arg)&sourceProgram))
3148 {
3149 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
3150 return ASPERR_AUTO_PROGRAM;
3151 }
3152 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
3153 }
3155 // since now decoding update decode status for all enabled decoders
3156 for (z=DECODE1; z < DECODEN; z++)
3157 {
3158 if (pAstCfg->xDec[z].decodeStatus.mode)
3159 {
3160 pAstCfg->xDec[z].decodeStatus.sourceDecode = pAstCfg->xDec[z].decodeStatus.sourceProgram;
3161 if (pAstCfg->xDec[z].decodeStatus.sourceSelect == PAF_SOURCE_SNG)
3162 {
3163 pAstCfg->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_SNG;
3164 }
3165 }
3166 }
3167 #endif
3169 #if 0 // FL: ASDT (slave)
3170 // TODO: move this to start of this function so that it doesn't affect IO timing
3171 // Initialize audio frame(s)
3172 // Re-initialize audio frame if there is an associated decode and
3173 // that decode doesn't have a valid input or is turned off
3174 for (z=STREAM1; z < STREAMN; z++)
3175 {
3176 Int reset = 0;
3177 for (zX = DECODE1; zX < DECODEN; zX++)
3178 {
3179 if (pP->streamsFromDecodes[zX] == z)
3180 {
3181 zI = pP->inputsFromDecodes[zX];
3182 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3183 {
3184 reset = 1;
3185 }
3186 }
3187 }
3188 if (reset)
3189 {
3190 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
3191 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3192 }
3193 else
3194 {
3195 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
3196 }
3197 }
3198 #endif
3200 return 0;
3201 } //PAF_ASIT_decodeInfo
3203 // -----------------------------------------------------------------------------
3204 // ASIT Decoding Function - Info Processing, Initial
3205 //
3206 // Name: PAF_ASIT_decodeInfo1
3207 // Purpose: Decoding Function for processing information in a manner that
3208 // is unique to initial frames of input data.
3209 // From: AST Parameter Function -> decodeProcessing
3210 // Uses: See code.
3211 // States: x
3212 // Return: Error number in standard or SIO form (0 on success).
3213 // Trace: Message Log "trace" in Debug Project Configuration reports:
3214 // * State information as per parent.
3215 //
3216 Int
3217 PAF_ASIT_decodeInfo1(
3218 const PAF_ASIT_Params *pP,
3219 const PAF_ASIT_Patchs *pQ,
3220 PAF_ASIT_Config *pC,
3221 Int frame,
3222 Int block
3223 )
3224 {
3225 return 0;
3226 } //PAF_ASIT_decodeInfo1
3228 // -----------------------------------------------------------------------------
3229 // AST Decoding Function - Info Processing, Subsequent
3230 //
3231 // Name: PAF_AST_decodeInfo2
3232 // Purpose: Decoding Function for processing information in a manner that
3233 // is unique to frames of input data other than the initial one.
3234 // From: AST Parameter Function -> decodeProcessing
3235 // Uses: See code.
3236 // States: x
3237 // Return: Error number in standard form (0 on success).
3238 // Trace: None.
3239 //
3240 Int
3241 PAF_ASIT_decodeInfo2(
3242 const PAF_ASIT_Params *pP,
3243 const PAF_ASIT_Patchs *pQ,
3244 PAF_ASIT_Config *pC,
3245 Int frame,
3246 Int block
3247 )
3248 {
3249 return 0;
3250 } //PAF_ASIT_decodeInfo2
3252 // -----------------------------------------------------------------------------
3253 // AST Decoding Function - Continuation Processing
3254 //
3255 // Name: PAF_AST_decodeCont
3256 // Purpose: Decoding Function for processing that occurs subsequent to
3257 // information processing but antecedent to timing processing
3258 // for frames of input data other than the initial one.
3259 // From: AST Parameter Function -> decodeProcessing
3260 // Uses: See code.
3261 // States: x
3262 // Return: Error number in standard form (0 on success).
3263 // Trace: Message Log "trace" in Debug Project Configuration reports:
3264 // * State information as per parent.
3265 //
3267 Int
3268 PAF_AST_decodeCont(
3269 const PAF_ASIT_Params *pP,
3270 const PAF_ASIT_Patchs *pQ,
3271 PAF_ASIT_Config *pC,
3272 ALG_Handle decAlg[],
3273 Int frame,
3274 Int block
3275 )
3276 {
3277 PAF_AST_Config *pAstCfg;
3278 Int as; /* Audio Stream Number (1, 2, etc.) */
3279 Int z; /* decode counter */
3280 Int zI, zS;
3281 Int zMD;
3282 #ifdef NON_CACHE_STATUS
3283 Int8 tempVar8;
3284 #endif
3287 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3288 as = pAstCfg->as;
3289 zMD = pAstCfg->masterDec;
3290 (void)as; // clear compiler warning in case not used with tracing disabled
3292 // Await slave inputs
3293 for (z=DECODE1; z < DECODEN; z++)
3294 {
3295 zI = pP->inputsFromDecodes[z];
3296 zS = pP->streamsFromDecodes[z];
3297 (void)zS;
3298 #ifdef NON_CACHE_STATUS
3299 statusOp_read(&tempVar8,
3300 &(pAstCfg->xDec[z].decodeStatus.mode),
3301 sizeof(Int8),
3302 GATEMP_INDEX_DEC);
3303 if (z == zMD
3304 || ! pAstCfg->xInp[zI].hRxSio
3305 || ! tempVar8)
3306 continue;
3307 #else
3308 if (z == zMD
3309 || ! pAstCfg->xInp[zI].hRxSio
3310 || ! pAstCfg->xDec[z].decodeStatus.mode)
3311 continue;
3312 #endif
3313 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
3314 if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
3315 != sizeof (pAstCfg->xInp[zI].inpBufConfig))
3316 return (ASPERR_RECLAIM);
3317 }
3319 return 0;
3320 } //PAF_AST_decodeCont
3322 // -----------------------------------------------------------------------------
3323 // ASIT Decoding Function - Decode Processing
3324 //
3325 // Name: PAF_ASIT_decodeDecode
3326 // Purpose: Decoding Function for processing of input data by the
3327 // Decode Algorithm.
3328 // From: AST Parameter Function -> decodeProcessing
3329 // Uses: See code.
3330 // States: x
3331 // Return: Error number in standard form (0 on success).
3332 // Trace: Message Log "trace" in Debug Project Configuration reports:
3333 // * State information as per parent.
3334 //
3335 Int
3336 PAF_ASIT_decodeDecode(
3337 const PAF_ASIT_Params *pP,
3338 const PAF_ASIT_Patchs *pQ,
3339 PAF_ASIT_Config *pC,
3340 Int sourceSelect,
3341 Int frame,
3342 Int block
3343 )
3344 {
3345 PAF_AST_Config *pAstCfg;
3346 Int as; /* Audio Stream Number (1, 2, etc.) */
3347 Int z; /* decode/stream counter */
3348 Int errno; /* error number */
3349 //Int ch;
3350 ASP_Msg *pAspMsg; /* Messaging */
3351 Int argIdx;
3352 Int status;
3353 Int cbErrno;
3354 Int frameLength;
3356 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3357 as = pAstCfg->as;
3358 (void)as; // clear compiler warning in case not used with tracing disabled
3360 #if 0 // FL: slave
3361 // Clear samsiz for all channels - MID 208.
3362 for (z=STREAM1; z < STREAMN; z++)
3363 {
3364 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
3365 {
3366 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
3367 }
3368 }
3369 #endif
3371 // Decode data
3372 for (z=DECODE1; z < DECODEN; z++)
3373 {
3374 Int zI = pP->inputsFromDecodes[z];
3375 Int zS = pP->streamsFromDecodes[z];
3376 (void)zS; // clear compiler warning in case not used with tracing disabled
3377 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3378 {
3379 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
3381 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
3382 as+zS,
3383 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
3384 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
3386 // FL: debug, capture input buffer
3387 //capIbPcm(pAstCfg->xInp[z].pInpBuf);
3389 // (***) FL: revisit
3390 // write back Dec configuration
3391 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3392 Cache_wait();
3394 // FL: send decode message to slave
3395 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3396 if (pAspMsg == NULL)
3397 {
3398 TRACE_TERSE0("MessageQ_alloc() failure.");
3399 SW_BREAKPOINT; // temporary
3400 return -1; // temporary
3401 }
3402 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3403 pAspMsg->cmd = ASP_SLAVE_DEC_DECODE; /* fill in message payload */
3404 pAspMsg->procId = hAspMsgMaster->masterProcId;
3405 pAspMsg->expectResp = TRUE;
3406 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3407 argIdx = 0; // set decIdx
3408 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3409 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3410 TRACE_MSG1("decIdx=%d", pAspMsg->buf[argIdx]);
3411 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3412 if (status != MessageQ_S_SUCCESS)
3413 {
3414 SW_BREAKPOINT;
3415 }
3416 // wait for decode complete message from slave -- temporary
3417 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3418 if (status != MessageQ_S_SUCCESS)
3419 {
3420 TRACE_TERSE0("MessageQ_get() failure.");
3421 SW_BREAKPOINT; // temporary
3422 return -1; // temporary
3423 }
3424 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
3425 (pAspMsg->cmd == ASP_MASTER_DEC_DECODE_DONE) &&
3426 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3427 {
3428 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3429 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3431 argIdx = 0; // get decErrno
3432 errno = *(Int32 *)&pAspMsg->buf[argIdx];
3433 argIdx += sizeof(Int32); // get cbErrno
3434 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
3435 if (cbErrno != 0)
3436 {
3437 gCbWrtAfErrCnt++;
3438 TRACE_TERSE1("CB write error=%d", cbErrno);
3439 //SW_BREAKPOINT; // temporary
3440 }
3441 }
3442 else
3443 {
3444 //
3445 // Invalid message received
3446 //
3447 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3448 SW_BREAKPOINT; // temporary
3449 }
3450 // free the message
3451 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3452 if (status != MessageQ_S_SUCCESS)
3453 {
3454 SW_BREAKPOINT;
3455 }
3457 // (***) FL: revisit
3458 // invalidate Dec configuration
3459 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3460 Cache_wait();
3462 #if 0 // FL: decoder decode call, slave
3463 if (dec->fxns->decode
3464 && (errno = dec->fxns->decode (dec, NULL,
3465 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
3466 #endif
3467 if (errno)
3468 {
3469 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
3470 return errno;
3471 }
3473 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3474 as_traceChannels(pC, z);
3475 #endif
3477 #if 0 // FL: change handle to decIdx (zone index)
3478 frameLength = pP->fxns->computeFrameLength(decAlg[z],
3479 FRAMELENGTH,
3480 pC->xDec[z].decodeStatus.bufferRatio);
3481 #endif
3482 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
3483 frameLength = pP->fxns->computeFrameLength(z,
3484 FRAMELENGTH,
3485 pC->xDec[z].decodeStatus.bufferRatio);
3486 #else
3487 if (sourceSelect == PAF_SOURCE_PCM)
3488 {
3489 frameLength = PAF_SYS_FRAMELENGTH;
3490 }
3491 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
3492 {
3493 frameLength = 1536;
3494 }
3495 else if (sourceSelect == PAF_SOURCE_THD)
3496 {
3497 frameLength = 1536; //QIN FIX ME
3498 }
3499 else
3500 {
3501 frameLength = 256;
3502 }
3503 #endif
3506 //#ifdef PROFILER
3507 // // modify for different decoders
3508 // if (sourceSelect == PAF_SOURCE_THD)
3509 // {
3510 // start_profiling = 1;
3511 // }
3512 // else
3513 // {
3514 // start_profiling = 0;
3515 // }
3516 //#endif
3519 // ............................................................................
3521 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3522 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3523 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3524 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3525 {
3526 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3527 return errno;
3528 }
3530 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3531 if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3532 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3533 PAF_SIO_REQUEST_NEWFRAME))
3534 {
3535 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3536 return (ASPERR_ISSUE);
3537 }
3538 } // hRxSio && decodeStatus.mode
3539 else
3540 {
3541 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3542 }
3543 } // z=DECODE1 to DECODEN
3545 #if 0 // FL: ASDT (slave)
3546 // Set up audio frames not decoded into
3547 // Re-initialize audio frame if there is an assocatiated decode and
3548 // that decode doesn't have a valid input or is turned off
3549 for (z=STREAM1; z < STREAMN; z++)
3550 {
3551 Int zX;
3552 Int reset = 0;
3553 for (zX = DECODE1; zX < DECODEN; zX++)
3554 {
3555 if (pP->streamsFromDecodes[zX] == z)
3556 {
3557 Int zI = pP->inputsFromDecodes[zX];
3558 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3559 reset = 1;
3560 }
3561 }
3562 if (reset)
3563 {
3564 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3565 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3566 }
3567 else
3568 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3569 }
3570 #endif
3572 return 0;
3573 } //PAF_ASIT_decodeDecode
3575 // -----------------------------------------------------------------------------
3576 // ASIT Decoding Function - Frame-Final Processing
3577 //
3578 // Name: PAF_ASIT_decodeFinalTest
3579 // Purpose: Decoding Function for determining whether processing of the
3580 // current frame is complete.
3581 // From: AST Parameter Function -> decodeProcessing
3582 // Uses: See code.
3583 // States: x
3584 // Return: 0 if incomplete, and 1 if complete.
3585 // Trace: None.
3586 //
3588 Int
3589 PAF_ASIT_decodeFinalTest(
3590 const PAF_ASIT_Params *pP,
3591 const PAF_ASIT_Patchs *pQ,
3592 PAF_ASIT_Config *pC,
3593 Int frame,
3594 Int block
3595 )
3596 {
3597 PAF_AST_Config *pAstCfg;
3598 Int zMD;
3599 Int sourceSelect;
3600 Int sourceProgram;
3601 #ifdef NON_CACHE_STATUS
3602 Int8 tempVar8, temp2Var8;
3603 #endif
3605 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3606 zMD = pAstCfg->masterDec;
3608 #ifdef NON_CACHE_STATUS
3609 statusOp_read(&tempVar8,
3610 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3611 sizeof(Int8),
3612 GATEMP_INDEX_DEC);
3613 sourceSelect = tempVar8;
3614 statusOp_read(&tempVar8,
3615 &(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3616 sizeof(Int8),
3617 GATEMP_INDEX_DEC);
3618 sourceProgram = tempVar8;
3619 #else
3620 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
3621 sourceProgram = pAstCfg->xDec[zMD].decodeStatus.sourceProgram;
3622 #endif
3624 if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3625 {
3626 return 1;
3627 }
3629 // The following allows for Force modes to switch without command deferral. This might
3630 // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3631 if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
3632 {
3633 if (sourceSelect == PAF_SOURCE_DTSALL)
3634 {
3635 if (sourceProgram != PAF_SOURCE_DTS11 &&
3636 sourceProgram != PAF_SOURCE_DTS12 &&
3637 sourceProgram != PAF_SOURCE_DTS13 &&
3638 sourceProgram != PAF_SOURCE_DTS14 &&
3639 sourceProgram != PAF_SOURCE_DTS16 &&
3640 sourceProgram != PAF_SOURCE_DTSHD)
3641 {
3642 return 1;
3643 }
3644 }
3645 else if (sourceSelect == PAF_SOURCE_PCMAUTO)
3646 {
3647 if (sourceProgram != PAF_SOURCE_PCM)
3648 {
3649 return 1;
3650 }
3651 }
3652 else
3653 {
3654 #ifdef NON_CACHE_STATUS
3655 statusOp_read(&tempVar8,
3656 &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
3657 sizeof(Int8),
3658 GATEMP_INDEX_DEC);
3659 statusOp_read(&temp2Var8,
3660 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3661 sizeof(Int8),
3662 GATEMP_INDEX_DEC);
3663 if (temp2Var8 != tempVar8)
3664 {
3665 return 1;
3666 }
3667 #else
3668 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect != pAstCfg->xDec[zMD].decodeStatus.sourceDecode)
3669 {
3670 return 1;
3671 }
3672 #endif
3673 }
3674 }
3676 return 0;
3677 } //PAF_ASIT_decodeFinalTest
3679 // -----------------------------------------------------------------------------
3680 // ASIT Decoding Function - Stream-Final Processing
3681 //
3682 // Name: PAF_ASIT_decodeComplete
3683 // Purpose: Decoding Function for terminating the decoding process.
3684 // From: AST Parameter Function -> decodeProcessing
3685 // Uses: See code.
3686 // States: x
3687 // Return: 0.
3688 // Trace: Message Log "trace" in Debug Project Configuration reports:
3689 // * State information as per parent.
3690 //
3691 Int
3692 PAF_ASIT_decodeComplete(
3693 const PAF_ASIT_Params *pP,
3694 const PAF_ASIT_Patchs *pQ,
3695 PAF_ASIT_Config *pC,
3696 ALG_Handle decAlg[],
3697 Int frame,
3698 Int block
3699 )
3700 {
3701 PAF_AST_Config *pAstCfg;
3702 Int as; /* Audio Stream Number (1, 2, etc.) */
3703 Int z; /* decode/encode counter */
3704 ASP_Msg* pAspMsg;
3705 Int argIdx;
3706 Int errno; /* error number */
3707 Int status;
3708 #ifdef NON_CACHE_STATUS
3709 Int8 tempVar8;
3710 #endif
3713 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3714 as = pAstCfg->as;
3715 (void)as; // clear compiler warning in case not used with tracing disabled
3717 #ifdef PAF_ASP_FINAL
3718 /* This material is currently not utilized */
3719 #endif /* PAF_ASP_FINAL */
3720 for (z=DECODE1; z < DECODEN; z++)
3721 {
3722 #ifdef PAF_ASP_FINAL
3723 DEC_Handle dec = (DEC_Handle )decAlg[z];
3724 #endif /* PAF_ASP_FINAL */
3725 Int zI = pP->inputsFromDecodes[z];
3726 #ifdef NON_CACHE_STATUS
3727 statusOp_read(&tempVar8,
3728 &(pAstCfg->xDec[z].decodeStatus.mode),
3729 sizeof(Int8),
3730 GATEMP_INDEX_DEC);
3731 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
3732 {
3733 #else
3734 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3735 {
3736 #endif
3737 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3738 #ifdef PAF_ASP_FINAL
3739 if (dec->fxns->final)
3740 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3741 &pAstCfg->xDec[z].decodeStatus);
3742 #endif /* PAF_ASP_FINAL */
3743 // FL: send dec deactivate message to slave
3744 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3745 if (pAspMsg == NULL)
3746 {
3747 TRACE_TERSE0("MessageQ_alloc() failure.");
3748 errno = -1; // temporary
3749 return errno;
3750 }
3751 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3752 pAspMsg->cmd = ASP_SLAVE_DEC_DEACTIVATE; /* fill in message payload */
3753 pAspMsg->procId = hAspMsgMaster->masterProcId;
3754 pAspMsg->expectResp = TRUE;
3755 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3756 argIdx = 0; // set decIdx
3757 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3758 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3759 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3760 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3761 if (status != MessageQ_S_SUCCESS)
3762 {
3763 SW_BREAKPOINT;
3764 }
3765 // wait for dec deactivate complete message from slave
3766 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3767 if (status != MessageQ_S_SUCCESS)
3768 {
3769 TRACE_TERSE0("MessageQ_get() failure.");
3770 return errno;
3771 }
3772 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
3773 (pAspMsg->cmd != ASP_MASTER_DEC_DEACTIVATE_DONE) ||
3774 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3775 {
3776 TRACE_MSG3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3777 SW_BREAKPOINT; // temporary
3778 }
3779 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3780 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3781 // free the message
3782 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3783 if (status != MessageQ_S_SUCCESS)
3784 {
3785 SW_BREAKPOINT;
3786 }
3788 #if 0 // FL: decoder deactivate call, slave
3789 if (decAlg[z]->fxns->algDeactivate)
3790 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3791 #endif
3792 }
3793 else
3794 {
3795 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3796 }
3797 }
3798 return 0;
3799 } //PAF_ASIT_decodeComplete
3801 // -----------------------------------------------------------------------------
3802 // ASIT Selection Function - Input Device Selection
3803 //
3804 // Name: PAF_ASIT_selectDevices
3805 // Purpose: Audio Stream Input Task Function for selecting the devices used
3806 // for input.
3807 // From: audioStream1Task or equivalent
3808 // Uses: See code.
3809 // States: x
3810 // Return: Error number in standard form (0 on success).
3811 // Trace: Message Log "trace" in Debug Project Configuration reports:
3812 // * State information as per parent.
3813 //
3814 Int
3815 PAF_ASIT_selectDevices(
3816 const PAF_ASIT_Params *pP,
3817 const PAF_ASIT_Patchs *pQ,
3818 PAF_ASIT_Config *pC
3819 )
3820 {
3821 PAF_AST_Config *pAstCfg;
3822 Int as; /* Audio Stream Number (1, 2, etc.) */
3823 Int z; /* input/output counter */
3824 Int errno = 0; /* error number */
3825 Int errme; /* error number, local */
3826 Int device;
3827 Int zMD;
3829 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3830 as = pAstCfg->as;
3831 zMD = pAstCfg->masterDec;
3832 (void)as; // clear compiler warning in case not used with tracing disabled
3834 // Select input devices
3835 for (z=INPUT1; z < INPUTN; z++)
3836 {
3837 if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0)
3838 {
3839 TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3841 // check for valid index into device array
3842 if (device >= pQ->devinp->n)
3843 {
3844 device = 0; /* treat as device None */
3845 }
3847 errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3848 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3850 if (errme)
3851 {
3852 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3853 if (!errno)
3854 {
3855 errno = ASPERR_DEVINP + errme;
3856 }
3857 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3858 }
3859 else
3860 {
3861 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3862 // register decodeStatus pointer with input devices
3863 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3864 // Use zMIs decodeStatus for all inputs
3865 if (pAstCfg->xInp[z].hRxSio)
3866 {
3867 // register PAF_SIO_IALG object address
3868 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR,
3869 (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3870 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR,
3871 (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3872 }
3873 }
3874 }
3875 }
3877 return errno;
3878 } //PAF_ASIT_selectDevices
3880 // -----------------------------------------------------------------------------
3881 // ASIT Selection Function - Source Selection
3882 //
3883 // Name: PAF_ASIT_sourceDecode
3884 // Purpose: Audio Input Stream Task Function for selecting the sources used
3885 // for decoding of input to output.
3886 // From: audioStream1Task or equivalent
3887 // Uses: See code.
3888 // States: x
3889 // Return: 0.
3890 // Trace: None.
3891 //
3892 Int
3893 PAF_ASIT_sourceDecode(
3894 const PAF_ASIT_Params *pP,
3895 const PAF_ASIT_Patchs *pQ,
3896 PAF_ASIT_Config *pC,
3897 Int x
3898 )
3899 {
3900 PAF_AST_Config *pAstCfg;
3901 Int z; /* decode counter */
3902 #ifdef NON_CACHE_STATUS
3903 Int8 tempVar8;
3904 #endif
3906 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3908 for (z=DECODE1; z < DECODEN; z++)
3909 {
3910 #ifdef NON_CACHE_STATUS
3911 statusOp_read(&tempVar8,
3912 &(pAstCfg->xDec[z].decodeStatus.mode),
3913 sizeof(Int8),
3914 GATEMP_INDEX_DEC);
3915 if (tempVar8)
3916 {
3917 tempVar8 = x;
3918 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3919 &tempVar8,
3920 sizeof(Int8),
3921 GATEMP_INDEX_DEC);
3922 }
3923 #else
3924 if (pAstCfg->xDec[z].decodeStatus.mode)
3925 {
3926 pAstCfg->xDec[z].decodeStatus.sourceDecode = x;
3927 }
3928 #endif
3929 }
3931 return 0;
3932 } //PAF_ASIT_sourceDecode
3934 // -----------------------------------------------------------------------------
3936 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3937 Int
3938 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3939 {
3940 Int errno = 0;
3941 Int zMD = pC->masterDec;
3942 Int zI = pP->inputsFromDecodes[z];
3944 // only handle real errors, on primary input, for writeDECModeContinuous
3945 if ( !( error &&
3946 z == zMD ))
3947 return error;
3949 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3950 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3952 if (pC->xInp[zI].hRxSio) {
3953 DEC_Handle dec;
3955 if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3956 return errno;
3958 // indicates (primary) input not running
3959 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3961 pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3963 // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3964 pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3966 if (decAlg[z]->fxns->algDeactivate)
3967 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3969 decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3970 dec = (DEC_Handle )decAlg[z];
3972 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3973 pC->as+z));
3975 if (decAlg[z]->fxns->algActivate)
3976 decAlg[z]->fxns->algActivate (decAlg[z]);
3978 if (dec->fxns->reset
3979 && (errno = dec->fxns->reset (dec, NULL,
3980 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3981 return errno;
3982 }
3984 return errno;
3985 } //PAF_AST_decodeHandleErrorInput
3986 #endif
3988 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3990 //------------------------------------------------------------------------------
3991 static int sSkipCount = 0;
3992 int gReportBuffers = 0;
3993 void as_traceChannels(PAF_AST_Config *pC, int z)
3994 {
3995 PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3996 int i;
3998 // #ifdef THIS_IS_DSPA
3999 sSkipCount++;
4000 if (sSkipCount<1)
4001 return;
4002 sSkipCount = 0;
4003 // #endif
4005 #ifdef THIS_IS_DSPB
4006 if (!gReportBuffers)
4007 return;
4008 gReportBuffers = 0;
4009 #endif
4011 dp(NULL, "\n");
4012 for (i=0; i<PAF_MAXNUMCHAN; i++)
4013 {
4014 if (pAudioFrame->data.sample[i] != 0)
4015 {
4016 float *wp = (float*)pAudioFrame->data.sample[i];
4017 dp(NULL, "i: %d. p: 0x%x. %f, %f, %f, %f\n",
4018 i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
4019 }
4020 }
4021 }
4022 #endif