e59942cf1909949c8943a324613b562b32040228
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / audioStreamInpProc.c
2 /*
3 Copyright (c) 2016, 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 "paf_decOpCircBuf.h"
64 #include "audioStreamProc_common.h"
65 #include "audioStreamInpProc.h"
67 // FL: porting
68 #include "fwkSim.h"
69 //#include "fwkPort.h"
70 // FL: debug
71 #include "dbgCapAf.h"
74 // -----------------------------------------------------------------------------
75 // Debugging Trace Control, local to this file.
76 //
77 #include "logp.h"
79 #define TRACE_ARC(a)
81 // allows you to set a different trace module in pa.cfg
82 #define TR_MOD trace
84 // Allow a developer to selectively enable tracing.
85 #define CURRENT_TRACE_MASK 0x21
87 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
88 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
89 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
90 #define TRACE_MASK_DATA 0x08 // Show data
91 #define TRACE_MASK_TIME 0x10 // Timing related traces
92 #define TRACE_MASK_MSG 0x20 // Message related traces
94 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
95 #undef TRACE_TERSE0
96 #undef TRACE_TERSE1
97 #undef TRACE_TERSE2
98 #undef TRACE_TERSE3
99 #undef TRACE_TERSE4
100 #define TRACE_TERSE0(a)
101 #define TRACE_TERSE1(a,b)
102 #define TRACE_TERSE2(a,b,c)
103 #define TRACE_TERSE3(a,b,c,d)
104 #define TRACE_TERSE4(a,b,c,d,e)
105 #endif
107 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
108 #undef TRACE_GEN0
109 #undef TRACE_GEN1
110 #undef TRACE_GEN2
111 #undef TRACE_GEN3
112 #undef TRACE_GEN4
113 #define TRACE_GEN0(a)
114 #define TRACE_GEN1(a,b)
115 #define TRACE_GEN2(a,b,c)
116 #define TRACE_GEN3(a,b,c,d)
117 #define TRACE_GEN4(a,b,c,d,e)
118 #endif
120 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
121 // consolidate list of processing strings, indexed by PAF_SOURCE
122 static char *procName[] =
123 {
124 "", //PAF_SOURCE_UNKNOWN
125 "", //PAF_SOURCE_NONE
126 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
127 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
128 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
129 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
130 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
131 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
132 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
133 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
134 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
135 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
136 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
137 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
138 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
139 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
140 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
142 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
143 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
144 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
145 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
146 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
147 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
148 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
149 "AS%d: THD processing ...", //PAF_SOURCE_THD
150 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
151 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
152 };
154 #else
155 #undef TRACE_VERBOSE0
156 #undef TRACE_VERBOSE1
157 #undef TRACE_VERBOSE2
158 #undef TRACE_VERBOSE3
159 #undef TRACE_VERBOSE4
160 #define TRACE_VERBOSE0(a)
161 #define TRACE_VERBOSE1(a,b)
162 #define TRACE_VERBOSE2(a,b,c)
163 #define TRACE_VERBOSE3(a,b,c,d)
164 #define TRACE_VERBOSE4(a,b,c,d,e)
165 #endif
167 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
168 #define TRACE_DATA(a) LOG_printf a
169 #else
170 #define TRACE_DATA(a)
171 #endif
173 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
174 #define TRACE_TIME(a) LOG_printf a
175 #define TIME_MOD trace // this could be different
176 static Int dtime()
177 {
178 static Int old_time = 0;
179 Int time = TSK_time();
180 Int delta_time = time - old_time;
181 old_time = time;
182 return( delta_time);
183 }
185 static char *stateName[11] =
186 {
187 "INIT",
188 "INFO1",
189 "AGAIN",
190 "INFO2",
191 "CONT",
192 "TIME",
193 "DECODE",
194 "STREAM",
195 "ENCODE",
196 "FINAL",
197 "QUIT"
198 };
200 #else
201 #define TRACE_TIME(a)
202 #endif
204 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
205 #undef TRACE_MSG0
206 #undef TRACE_MSG1
207 #undef TRACE_MSG2
208 #undef TRACE_MSG3
209 #undef TRACE_MSG4
210 #define TRACE_MSG0(a)
211 #define TRACE_MSG1(a,b)
212 #define TRACE_MSG2(a,b,c)
213 #define TRACE_MSG3(a,b,c,d)
214 #define TRACE_MSG4(a,b,c,d,e)
215 #endif
218 // .............................................................................
220 #include <pafsio.h>
221 #include "paferr.h"
223 #include <acp_mds.h>
225 #include <pcm.h>
227 #include <pce.h>
229 #include <doberr.h>
231 #include <diberr.h>
233 #include <stdasp.h>
235 #include "as0.h"
236 #include "asperr.h"
238 #include "audioStreamProc_params.h"
239 #include "audioStreamProc_patchs.h"
240 #include "audioStreamProc_config.h"
242 //
243 // Audio Stream Definitions
244 //
246 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
247 #define MINFRAMELENGTH 24
248 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
250 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
251 Int PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error);
252 #endif
255 //
256 // Decoder Definitions
257 //
258 //#define decLinkInit pQ->i_decLinkInit
260 //
261 // Audio Stream Processing Definitions
262 //
263 //#define aspLinkInit pQ->i_aspLinkInit
265 //
266 // Encoder Definitions
267 //
268 #define encLinkInit pQ->i_encLinkInit
270 //
271 // Input, Output Definitions
272 //
273 #define inpLinkInit pP->i_inpLinkInit
274 //#define outLinkInit pP->i_outLinkInit
276 /* ---------------------------------------------------------------- */
277 /* Parameter macro definitions end here. */
278 /* ---------------------------------------------------------------- */
280 //
281 // Standardized Definitions
282 //
284 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
285 //#define ENC_Handle PCE_Handle /* works for all: PCE */
287 #define __TASK_NAME__ "TaskAsip"
289 LINNO_DEFN(TaskAsip); /* Line number macros */
290 ERRNO_DEFN(TaskAsip); /* Error number macros */
292 // Global debug counters */
293 UInt32 gTaskAsipCnt=0; // debug
294 UInt32 gAsipInitCnt =0;
295 UInt32 gAsipInfo1Cnt =0;
296 UInt32 gAsipInfo2Cnt =0;
297 UInt32 gAsipDecodeCnt =0;
298 UInt32 gAsipFinalCnt =0;
299 UInt32 gAsipQuitCnt =0;
300 #include "dbgDib.h"
302 extern struct {
303 Int size;
304 IALG_Status *pStatus[512];
305 } IACP_STD_BETA_TABLE;
308 /*
309 * ======== taskAsipFxn ========
310 * Audio Stream Input Processing task function
311 */
312 Void taskAsipFxn(
313 // Int betaPrimeValue, // FL: revisit
314 const PAF_AST_Params *pP,
315 const PAF_AST_Patchs *pQ
316 )
317 {
318 // Task data
319 //PAF_AST_Config PAF_AST_config; /* Local configuration */
320 //PAF_AST_Config *pC; /* Local configuration pointer */
321 // Local data
322 Int as; /* Audio Stream Number (1, 2, etc.) */
323 Int z; /* input/encode/stream/decode/output counter */
324 Int i; /* phase */
325 Int errno; /* error number */
326 Int zMD, zMI, zMS, zX;
327 Int loopCount = 0; // used to stop trace to see startup behavior.
328 UInt32 curTime;
329 Int size;
330 // Messaging
331 ASP_Msg *pAspMsg;
332 Int status;
334 Log_info0("Enter taskAsipFxn()");
336 #ifdef SIMULATE_SIO
337 /* Start simulation */
338 simStart();
339 #endif // SIMULATE_SIO
341 //
342 // Audio Framework Configuration (*pC):
343 //
344 pC = &gPAF_AST_config;
346 TRACE_TERSE1("TaskAsip: Started with betaPrimeValue=%d.", gBetaPrimeValue);
347 as = gBetaPrimeValue + 1; /* Audio Stream Number (1, 2, etc.) */
348 pC->as = as;
350 //
351 // Audio Framework Parameters & Patch (*pP, *pQ)
352 //
353 if (!pP)
354 {
355 TRACE_TERSE1("TaskAsip: AS%d: No Parameters defined. Exiting.", as);
356 LINNO_RPRT(TaskAsip, -1);
357 return;
358 }
360 if (!pQ)
361 {
362 TRACE_TERSE1("TaskAsip: AS%d: No Patchs defined. Exiting.", as);
363 LINNO_RPRT(TaskAsip, -1);
364 return;
365 }
367 //
368 // Initialize message log trace and line number reporting
369 //
370 for (z=STREAM1; z < STREAMN; z++)
371 {
372 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
373 }
374 LINNO_RPRT(TaskAsip, -1);
376 //
377 // Determine decoder and stream indices associated with the master input
378 //
379 zMI = pP->zone.master;
380 pC->masterDec = zMI;
381 pC->masterStr = zMI;
382 for (zX = DECODE1; zX < DECODEN; zX++)
383 {
384 if (pP->inputsFromDecodes[zX] == zMI)
385 {
386 pC->masterDec = zX;
387 pC->masterStr = pP->streamsFromDecodes[zX];
388 break;
389 }
390 }
391 zMD = pC->masterDec;
392 zMS = pC->masterStr;
394 // Initialize as per parametrized phases:
395 //
396 // In standard form these are:
397 // - Malloc: Memory Allocation
398 // - Config: Configuration Initialization
399 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
400 // - Common: Common Memory Initialization
401 // - AlgKey: Dec/Enc chain to Array Initialization
402 // - Device: I/O Device Initialization
403 // - Unused: (available)
404 // - Unused: (available)
405 //
406 LINNO_RPRT(TaskAsip, -2);
407 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
408 {
409 Int linno;
410 if (pP->fxns->initPhase[i])
411 {
412 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
413 {
414 LINNO_RPRT(TaskAsip, linno);
415 return;
416 }
417 }
418 else
419 {
420 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
421 }
422 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
423 LINNO_RPRT(TaskAsip, -i-3);
424 }
426 //
427 // End of Initialization -- display memory usage report.
428 //
429 if (pP->fxns->memStatusPrint)
430 {
431 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
432 }
434 // (***) FL: revisit
435 // write back configuration
436 Cache_wb(&gPAF_AST_config, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
437 Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
438 Cache_wait();
440 // (***) FL: revisit
441 // write Dec configuration
442 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
443 Cache_wait();
445 // (***) FL: revisit
446 // write back entire beta table
447 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
448 Cache_wait();
450 // FL: send start initialization message to slave
451 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
452 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
453 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
454 pAspMsg->procId = hAspMsgMaster->masterProcId;
455 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
456 pAspMsg->expectResp = TRUE;
457 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
458 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
459 if (status != MessageQ_S_SUCCESS)
460 {
461 SW_BREAKPOINT;
462 }
463 // wait for initialization complete message from slave
464 do {
465 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
466 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
467 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
468 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
469 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
470 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
471 {
472 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
473 SW_BREAKPOINT;
474 }
475 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
476 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
477 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
478 if (status != MessageQ_S_SUCCESS)
479 {
480 SW_BREAKPOINT;
481 }
483 // (***) FL: revisit
484 // invalidate Status structure addresses for Beta Units initialized on Slave
485 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
486 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
487 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
488 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
489 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
490 Cache_wait();
491 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
492 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
493 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
494 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
495 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
497 // (***) FL: revisit
498 // invalidate Status structures for Beta Units initialized on Slave
499 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
500 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
501 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
502 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
503 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
504 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
505 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
506 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
507 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
508 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
509 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
510 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
511 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
512 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
513 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
514 Cache_wait();
516 // (***) FL: revisit
517 // invalidate Dec configuration
518 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
519 Cache_wait();
521 //
522 // Main processing loop
523 //
524 for (z=STREAM1; z < STREAMN; z++)
525 {
526 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
527 }
529 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
531 errno = 0;
532 for (;;)
533 {
534 Int sourceSelect;
535 XDAS_Int8 sourceProgram;
537 loopCount++;
539 #if 0 // enable and tune to see startup behavior.
540 // this is an alternative to fixed/circular setting in pa.cfg.
541 // If you are searching for a memory allocation failure, disable on first round.
542 // All allocation has already happened.
543 // This is the outer loop. This loop count goes up when the stream resets.
544 // If the stream is running without problems, this does not increment.
545 // If the stream is repeatedly resetting, this loop count will go up rapidly.
546 if (loopCount > 10) // see traces for a few of the passes through the main loop.
547 {
548 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
549 LOG_disable(&TR_MOD); // stop tracing
550 }
551 #endif
553 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
554 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
556 // since not decoding indicate such
557 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
559 // any error forces idling of input
560 if (errno)
561 {
562 for (z=INPUT1; z < INPUTN; z++)
563 {
564 if (pC->xInp[z].hRxSio)
565 {
566 SIO_idle(pC->xInp[z].hRxSio);
567 }
568 }
570 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
571 ERRNO_RPRT(TaskAsip, errno);
572 }
574 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
575 // up to allow lower priority tasks to run. This may seem odd to be at the top
576 // of the state machine but provides for a cleaner flow even though the very
577 // first time we enter we do a sleep which is non-intuitive.
578 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
579 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
580 Task_sleep(1);
582 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
583 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
584 {
585 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
586 continue;
587 }
589 // if no master input selected then we don't know what may be at the input
590 // so set to unknown and skip any remaining processing
591 if (!pC->xInp[zMI].hRxSio)
592 {
593 pC->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
594 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
595 continue;
596 }
598 // if here then we have a valid input so query its status
599 if (errno = pP->fxns->updateInputStatus(pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufStatus, &pC->xInp[zMI].inpBufConfig))
600 {
601 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
602 continue;
603 }
605 // If master decoder is not enabled, or the input is unlocked, then do nothing
606 if (!pC->xDec[zMD].decodeStatus.mode || !pC->xInp[zMI].inpBufStatus.lock)
607 {
608 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
609 continue;
610 }
612 // If no source selected then do nothing
613 if (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
614 {
615 pC->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
616 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
617 continue;
618 }
620 // If we want pass processing then proceed directly
621 if (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
622 {
623 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
624 pC->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
625 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
626 if (pP->fxns->passProcessing)
627 {
628 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
629 }
630 else
631 {
632 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
633 errno = ASPERR_PASS;
634 }
635 TRACE_VERBOSE0("TaskAsip: continue");
636 continue;
637 }
639 // .....................................................................
640 // At this point we have an enabled input and want to decode something.
641 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
642 // when no decoder is selected there are no calls to IB
643 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
644 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, NULL)) // (***) FL: hard-coded to use PCM framelength inside function
645 {
646 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
647 continue;
648 }
650 // query for input type
651 if (errno = SIO_ctrl(pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
652 {
653 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
654 errno = ASPERR_AUTO_PROGRAM;
655 continue;
656 }
657 pC->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
659 // if input is unclassifiable then do nothing
660 if (sourceProgram == PAF_SOURCE_UNKNOWN)
661 {
662 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
663 continue;
664 }
666 // now that we have some input classification, and possibly an outstanding
667 // input frame, we determine whether or not to call decodeProcessing and with
668 // what decAlg.
669 sourceSelect = PAF_SOURCE_NONE;
670 switch (pC->xDec[zMD].decodeStatus.sourceSelect)
671 {
672 // If autodetecting, decoding everything, and input is something
673 // (i.e. bitstream or PCM) then decode.
674 case PAF_SOURCE_AUTO:
675 if (sourceProgram >= PAF_SOURCE_PCM)
676 {
677 sourceSelect = sourceProgram;
678 }
679 break;
681 // If autodetecting, decoding only PCM, and input is PCM then decode.
682 case PAF_SOURCE_PCMAUTO:
683 if (sourceProgram == PAF_SOURCE_PCM)
684 {
685 sourceSelect = sourceProgram;
686 }
687 break;
689 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
690 case PAF_SOURCE_BITSTREAM:
691 if (sourceProgram >= PAF_SOURCE_AC3)
692 {
693 sourceSelect = sourceProgram;
694 }
695 break;
697 // If autodetecting, decoding only DTS, and input is DTS then decode.
698 case PAF_SOURCE_DTSALL:
699 switch (sourceProgram)
700 {
701 case PAF_SOURCE_DTS11:
702 case PAF_SOURCE_DTS12:
703 case PAF_SOURCE_DTS13:
704 case PAF_SOURCE_DTS14:
705 case PAF_SOURCE_DTS16:
706 case PAF_SOURCE_DTSHD:
707 sourceSelect = sourceProgram;
708 break;
709 }
710 break;
712 // All others, e.g., force modes, fall through to here.
713 // If user made specific selection then program must match select.
714 // (NB: this compare relies on ordering of PAF_SOURCE)
715 default:
716 sourceSelect = pC->xDec[zMD].decodeStatus.sourceSelect;
717 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
718 {
719 if (sourceProgram != sourceSelect)
720 {
721 sourceSelect = PAF_SOURCE_NONE;
722 }
723 }
724 break;
725 }
727 // if we didn't find any matches then skip
728 if (sourceSelect == PAF_SOURCE_NONE)
729 {
730 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
731 continue;
732 }
734 // FL: debug, reset IB capture buffer
735 //capIbReset();
736 //Log_info0("capIbReset()");
738 // FL: send source select message to slave
739 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
740 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
741 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
742 pAspMsg->procId = hAspMsgMaster->masterProcId;
743 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
744 pAspMsg->expectResp = TRUE;
745 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
746 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
747 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
748 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
749 if (status != MessageQ_S_SUCCESS)
750 {
751 SW_BREAKPOINT;
752 }
753 // wait for source select complete message from slave
754 //do {
755 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
756 //} while (status != MessageQ_S_SUCCESS);
757 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
758 if (status != MessageQ_S_SUCCESS)
759 {
760 TRACE_TERSE0("MessageQ_get() failure.");
761 SW_BREAKPOINT; // temporary
762 }
763 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
764 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
765 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
766 {
767 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
768 SW_BREAKPOINT;
769 }
770 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
771 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
772 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
773 if (status != MessageQ_S_SUCCESS)
774 {
775 SW_BREAKPOINT;
776 }
778 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
779 // iff we are in this top level state machine and specifically not in decodeProcessing
780 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
782 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
784 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
785 //errno = pP->fxns->decodeProcessing(pP, pQ, pC, pC->xDec[zMD].decAlg[sourceSelect]);
786 //errno = pP->fxns->decodeProcessing(pP, pQ, pC, NULL); // (***) FL: dec handle doesn't exist on Master (DSP)
787 //errno = pP->fxns->decodeProcessing(pP, pQ, pC, NULL, sourceSelect);
788 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
789 if (errno)
790 {
791 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
792 }
793 else
794 {
795 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
796 }
798 // FL: send dec exit message to slave
799 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
800 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
801 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
802 pAspMsg->procId = hAspMsgMaster->masterProcId;
803 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
804 pAspMsg->expectResp = TRUE;
805 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
806 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
807 if (status != MessageQ_S_SUCCESS)
808 {
809 SW_BREAKPOINT;
810 }
811 // wait for dec exit complete message from slave
812 //do {
813 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
814 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
815 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
816 if (status != MessageQ_S_SUCCESS)
817 {
818 TRACE_TERSE0("MessageQ_get() failure.");
819 SW_BREAKPOINT; // temporary
820 }
821 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
822 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
823 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
824 {
825 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
826 SW_BREAKPOINT;
827 }
828 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
829 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
830 // free the message
831 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
832 if (status != MessageQ_S_SUCCESS)
833 {
834 SW_BREAKPOINT;
835 }
836 } // End of main processing loop for (;;)
838 Log_info0("Exit taskAsipFxn()");
839 }
841 // -----------------------------------------------------------------------------
842 // ASIT Initialization Function - Memory Allocation
843 //
844 // Name: PAF_ASIT_initPhaseMalloc
845 // Purpose: Audio Stream Input Task Function for initialization of data pointers
846 // by allocation of memory.
847 // From: audioStream1Task or equivalent
848 // Uses: See code.
849 // States: x
850 // Return: 0 on success.
851 // Source code line number on MEM_calloc failure.
852 // Trace: Message Log "trace" in Debug Project Configuration reports:
853 // * State information as per parent.
854 // * Memory allocation errors.
855 //
856 Int
857 PAF_ASIT_initPhaseMalloc(
858 const PAF_AST_Params *pP,
859 const PAF_AST_Patchs *pQ,
860 PAF_AST_Config *pC
861 )
862 {
863 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
864 Int zMS = pC->masterStr;
865 Error_Block eb;
866 Int i;
868 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
870 // Initialize error block
871 Error_init(&eb);
873 /* Input memory */
874 if (!(pC->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, INPUTN * sizeof (*pC->xInp), 4, &eb)))
875 {
876 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
877 SW_BREAKPOINT;
878 return __LINE__;
879 }
880 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
881 INPUTN * sizeof (*pC->xInp),
882 HEAP_ID_INTERNAL1_SHM, (IArg)pC->xInp);
884 /* Decode memory */
885 if (!(pC->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, DECODEN * sizeof (*pC->xDec), 4, &eb)))
886 {
887 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
888 SW_BREAKPOINT;
889 return __LINE__;
890 }
891 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
892 DECODEN * sizeof (*pC->xDec),
893 HEAP_ID_INTERNAL1_SHM, (IArg)pC->xDec);
895 {
896 // FL: added for decode output circular buffer
897 // FL: (***)revisit
898 Int z; /* decode counter */
900 for (z=DECODE1; z < DECODEN; z++)
901 {
902 // allocate audio frame circular buffer
903 if (!(pC->xDec[z].decOpCb.afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
904 {
905 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
906 SW_BREAKPOINT;
907 }
908 // allocate audio frame PCM sample pointer array
909 for (i = 0; i<PAF_DECOP_CB_MAX_NUM_AF; i++)
910 {
911 if (!(pC->xDec[z].decOpCb.afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioData *), 4, &eb)))
912 {
913 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
914 SW_BREAKPOINT;
915 }
916 if (!(pC->xDec[z].decOpCb.afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioSize), 4, &eb)))
917 {
918 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
919 SW_BREAKPOINT;
920 }
921 }
922 // allocate PCM sample buffer
923 if (!(pC->xDec[z].decOpCb.pcmBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
924 {
925 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
926 SW_BREAKPOINT;
927 }
928 // allocate Metadata buffers //QIN
929 if (!(pC->xDec[z].decOpCb.metaBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, PAF_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
930 {
931 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
932 SW_BREAKPOINT;
933 }
934 }
935 }
937 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
938 return 0;
939 } //PAF_ASIT_initPhaseMalloc
941 // -----------------------------------------------------------------------------
942 // ASIT Initialization Function - Memory Initialization from Configuration
943 //
944 // Name: PAF_ASIT_initPhaseConfig
945 // Purpose: Audio Stream Task Function for initialization of data values
946 // from parameters.
947 // From: audioStream1Task or equivalent
948 // Uses: See code.
949 // States: x
950 // Return: 0 on success.
951 // Other as per initFrame0 and initFrame1.
952 // Trace: Message Log "trace" in Debug Project Configuration reports:
953 // * State information as per parent.
954 //
955 Int
956 PAF_ASIT_initPhaseConfig(
957 const PAF_AST_Params *pP,
958 const PAF_AST_Patchs *pQ,
959 PAF_AST_Config *pC
960 )
961 {
962 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
963 Int z; /* input/encode/stream/decode/output counter */
964 Int zMS = pC->masterStr;
965 Int errno; /* error number */
966 PAF_DecodeOpCircBuf *pCb; /* Decoder output circular buffer */
968 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
970 //
971 // Unspecified elements have been initialized to zero during alloc
972 //
974 for (z=INPUT1; z < INPUTN; z++)
975 {
976 pC->xInp[z].inpBufStatus = *pP->pInpBufStatus;
977 pC->xInp[z].inpBufConfig.pBufStatus = &pC->xInp[z].inpBufStatus;
978 }
980 for (z=DECODE1; z < DECODEN; z++)
981 {
982 Int zI = pP->inputsFromDecodes[z];
983 pC->xDec[z].decodeControl.size = sizeof(pC->xDec[z].decodeControl);
984 pC->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pC->xInp[zI].inpBufConfig;
985 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
987 // Initialize decoder output circular buffer for PCM
988 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
989 pCb = &pC->xDec[z].decOpCb;
990 errno = cbInit(PAF_SOURCE_PCM, 256, FRAMELENGTH, pCb, 1);
991 if (errno)
992 {
993 SW_BREAKPOINT; // FL: debug
994 return errno;
995 }
996 // FL: debug
997 cbLog(pCb, 1, "PAF_ASIT_initPhaseConfig:cbInit");
998 }
1000 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1001 return 0;
1002 } //PAF_ASIT_initPhaseConfig
1004 // -----------------------------------------------------------------------------
1005 // ASIT Initialization Function - ACP Algorithm Instantiation
1006 //
1007 // Name: PAF_ASIT_initPhaseAcpAlg
1008 // Purpose: Audio Stream Input Task Function for initialization of ACP by
1009 // instantiation of the algorithm.
1010 // From: audioStream1Task or equivalent
1011 // Uses: See code.
1012 // States: x
1013 // Return: 0 on success.
1014 // Source code line number on ACP Algorithm creation failure.
1015 // Trace: Message Log "trace" in Debug Project Configuration reports:
1016 // * State information as per parent.
1017 // * Memory allocation errors.
1018 //
1019 Int
1020 PAF_ASIT_initPhaseAcpAlg(
1021 const PAF_AST_Params *pP,
1022 const PAF_AST_Patchs *pQ,
1023 PAF_AST_Config *pC
1024 )
1025 {
1026 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1027 Int z; /* input/encode/stream/decode/output counter */
1028 Int betaPrimeOffset;
1029 ACP_Handle acp;
1030 Int zMS = pC->masterStr;
1031 Int zS, zX;
1033 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1035 ACP_MDS_init();
1037 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
1038 {
1039 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1040 return __LINE__;
1041 }
1042 pC->acp = acp;
1044 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1045 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1047 for (z=INPUT1; z < INPUTN; z++)
1048 {
1049 zS = z;
1050 for (zX = DECODE1; zX < DECODEN; zX++)
1051 {
1052 if (pP->inputsFromDecodes[zX] == z)
1053 {
1054 zS = pP->streamsFromDecodes[zX];
1055 break;
1056 }
1057 }
1058 acp->fxns->attach(acp, ACP_SERIES_STD,
1059 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1060 (IALG_Status *)&pC->xInp[z].inpBufStatus);
1061 /* Ignore errors, not reported. */
1062 }
1064 #if 0 // FL: slave
1065 for (z=DECODE1; z < DECODEN; z++)
1066 {
1067 zS = pP->streamsFromDecodes[z];
1068 acp->fxns->attach(acp, ACP_SERIES_STD,
1069 STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1070 (IALG_Status *)&pC->xDec[z].decodeStatus);
1071 /* Ignore errors, not reported. */
1072 }
1073 #endif
1075 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1077 return 0;
1078 } //PAF_ASIT_initPhaseAcpAlg
1080 // -----------------------------------------------------------------------------
1081 // ASIT Initialization Function - Common Memory
1082 //
1083 // Name: PAF_ASIT_initPhaseCommon
1084 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1085 // From: audioStream1Task or equivalent
1086 // Uses: See code.
1087 // States: x
1088 // Return: 0 on success.
1089 // Source code line number on PAF_ALG_alloc failure.
1090 // Source code line number on PAF_ALG_mallocMemory failure.
1091 // Source code line number on Decode Chain initialization failure.
1092 // Source code line number on ASP Chain initialization failure.
1093 // Source code line number on Encode Chain initialization failure.
1094 // Trace: Message Log "trace" in Debug Project Configuration reports:
1095 // * State information as per parent.
1096 // * Memory allocation errors.
1097 //
1098 Int
1099 PAF_ASIT_initPhaseCommon(
1100 const PAF_AST_Params *pP,
1101 const PAF_AST_Patchs *pQ,
1102 PAF_AST_Config *pC
1103 )
1104 {
1105 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1106 Int z; /* stream counter */
1107 //Int g; /* gear */
1108 ACP_Handle acp = pC->acp;
1109 PAF_IALG_Config pafAlgConfig;
1110 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1112 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1114 //
1115 // Determine memory needs and instantiate algorithms across audio streams
1116 //
1117 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1118 PAF_ALG_setup(&pafAlgConfig,
1119 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1120 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1121 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1122 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1123 HEAP_CLEAR);
1125 if (pP->fxns->headerPrint)
1126 {
1127 pP->fxns->headerPrint();
1128 }
1130 for (z = STREAM1; z < STREAMN; z++)
1131 {
1132 //Int zD, zE, zX;
1134 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1136 //
1137 // Determine common memory for:
1138 // (1) Logical Input drivers
1139 //
1140 // Decode Algorithms common memory determined in ASP Slave.
1141 //
1142 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1144 #if 0 // FL: slave
1145 zD = -1;
1146 for (zX = DECODE1; zX < DECODEN; zX++)
1147 {
1148 if (pP->streamsFromDecodes[zX] == z)
1149 {
1150 zD = zX;
1151 break;
1152 }
1153 }
1154 #endif
1156 #if 0 // FL: slave
1157 if (zD >= 0)
1158 {
1159 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for decoder common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1160 if (PAF_ALG_ALLOC(decLinkInit[zD-DECODE1], common[z]))
1161 {
1162 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1163 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1165 SW_BREAKPOINT;
1166 return __LINE__;
1167 }
1168 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1169 if (pP->fxns->allocPrint)
1170 {
1171 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1172 }
1173 }
1174 #endif
1176 //
1177 // Determine common memory needs of Logical Input driver
1178 //
1180 // really need to loop over all inputs for this stream using the tables
1181 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1182 // patch, and not needed for FS11, since there is only one input.
1183 if (INPUT1 <= z && z < INPUTN)
1184 {
1185 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1186 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1187 {
1188 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1189 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1190 SW_BREAKPOINT;
1191 return __LINE__;
1192 }
1193 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1194 if (pP->fxns->allocPrint)
1195 {
1196 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1197 }
1198 }
1199 }
1200 {
1201 // Changes made to share scratch between zones
1202 // Assume maximum 3 zones and scratch common memory is at offset 0;
1203 int max=0;
1204 for (z=STREAM1; z<STREAMN; z++)
1205 {
1206 if (max < common[z][0].size)
1207 {
1208 max = common[z][0].size;
1209 }
1210 }
1211 common[STREAM1][0].size=max;
1212 for (z=STREAM1+1; z<STREAMN; z++)
1213 {
1214 common[z][0].size = 0;
1215 }
1216 }
1218 //
1219 // Allocate common memory for:
1220 // (1) Logical Input drivers
1221 //
1222 for (z = STREAM1; z < STREAMN; z++)
1223 {
1224 //Int zD, zE, zX;
1226 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1227 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1228 {
1229 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1230 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1231 SW_BREAKPOINT;
1232 return __LINE__;
1233 }
1234 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1235 // share zone0 scratch with all zones
1236 common[z][0].base = common[0][0].base;
1237 if (pP->fxns->commonPrint)
1238 {
1239 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1240 }
1242 #if 0 // FL: slave
1243 zD = -1;
1244 for (zX = DECODE1; zX < DECODEN; zX++)
1245 {
1246 if (pP->streamsFromDecodes[zX] == z)
1247 {
1248 zD = zX;
1249 break;
1250 }
1251 }
1252 #endif
1254 #if 0 // FL: slave
1255 if (zD >= 0)
1256 {
1257 PAF_ASP_Chain *chain;
1258 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1259 chain = PAF_ASP_chainInit(&pC->xDec[zD].decChainData, pP->pChainFxns,
1260 HEAP_INTERNAL, as+z, acp, &trace,
1261 decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1262 if (!chain)
1263 {
1264 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1265 return __LINE__;
1266 }
1267 }
1268 #endif
1270 //
1271 // Allocate non-common memories for Logical IO drivers
1272 // Since these structures are used at run-time we allocate from external memory
1273 if (INPUT1 <= z && z < INPUTN)
1274 {
1275 PAF_ASP_Chain *chain;
1276 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1277 as+z, z);
1278 chain = PAF_ASP_chainInit(&pC->xInp[z].inpChainData, pP->pChainFxns,
1279 HEAP_EXTERNAL, as+z, acp, &trace,
1280 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1281 if (!chain)
1282 {
1283 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1284 return __LINE__;
1285 }
1286 }
1287 }
1288 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1290 return 0;
1291 } //PAF_ASIT_initPhaseCommon
1293 // -----------------------------------------------------------------------------
1294 // ASIT Initialization Function - Algorithm Keys
1295 //
1296 // Name: PAF_ASIT_initPhaseAlgKey
1297 // Purpose: Audio Stream Input Task Function for initialization of data values
1298 // from parameters for Algorithm Keys.
1299 // From: audioStream1Task or equivalent
1300 // Uses: See code.
1301 // States: x
1302 // Return: 0.
1303 // Trace: Message Log "trace" in Debug Project Configuration reports:
1304 // * State information as per parent.
1305 //
1306 // .............................................................................
1307 Int
1308 PAF_ASIT_initPhaseAlgKey(
1309 const PAF_AST_Params *pP,
1310 const PAF_AST_Patchs *pQ,
1311 PAF_AST_Config *pC
1312 )
1313 {
1314 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1315 #if 0
1316 Int z; /* decode/encode counter */
1317 Int s; /* key number */
1318 PAF_ASP_Link *that;
1319 #endif
1321 (void)as; // clear compiler warning in case not used with tracing disabled
1323 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1325 #if 0 // FL: slave
1326 for (z=DECODE1; z < DECODEN; z++)
1327 {
1328 for (s=0; s < pP->pDecAlgKey->length; s++)
1329 {
1330 if ((pP->pDecAlgKey->code[s].full != 0) &&
1331 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1332 {
1333 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1334 /* Cast in interface, for now --Kurt */
1335 }
1336 else
1337 {
1338 pC->xDec[z].decAlg[s] = NULL;
1339 }
1340 }
1341 }
1342 #endif
1344 return 0;
1345 } //PAF_ASIT_initPhaseAlgKey
1347 // -----------------------------------------------------------------------------
1348 // ASIT Initialization Function - I/O Devices
1349 //
1350 // Name: PAF_ASIT_initPhaseDevice
1351 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1352 // From: audioStream1Task or equivalent
1353 // Uses: See code.
1354 // States: x
1355 // Return: 0 on success.
1356 // Source code line number on device allocation failure.
1357 // Trace: Message Log "trace" in Debug Project Configuration reports:
1358 // * State information as per parent.
1359 // * Memory allocation errors.
1360 //
1361 Int
1362 PAF_ASIT_initPhaseDevice(
1363 const PAF_AST_Params *pP,
1364 const PAF_AST_Patchs *pQ,
1365 PAF_AST_Config *pC
1366 )
1367 {
1368 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1369 Int z; /* input/output counter */
1370 PAF_SIO_IALG_Obj *pObj;
1371 PAF_SIO_IALG_Config *pAlgConfig;
1372 PAF_IALG_Config pafAlgConfig;
1374 (void)as; // clear compiler warning in case not used with tracing disabled
1376 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1378 if(pP->fxns->bufMemPrint)
1379 {
1380 PAF_ALG_setup (&pafAlgConfig,
1381 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1382 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1383 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1384 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1385 HEAP_CLEAR);
1386 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1387 }
1389 for (z=INPUT1; z < INPUTN; z++)
1390 {
1391 PAF_InpBufConfig *pConfig = &pC->xInp[z].inpBufConfig;
1393 pObj = (PAF_SIO_IALG_Obj *)pC->xInp[z].inpChainData.head->alg;
1394 pAlgConfig = &pObj->config;
1396 pC->xInp[z].hRxSio = NULL;
1398 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1399 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1400 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1401 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1402 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1403 pConfig->sizeofElement = 2;
1404 pConfig->precision = 16;
1406 if(pP->fxns->bufMemPrint)
1407 {
1408 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),0);
1409 }
1410 }
1411 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1413 return 0;
1414 } //PAF_ASIT_initPhaseDevice
1416 #if 0
1417 // -----------------------------------------------------------------------------
1418 // AST Processing Function - Pass-Through Processing
1419 //
1420 // Name: PAF_AST_passProcessing
1421 // Purpose: Audio Stream Task Function for processing audio data as a
1422 // pass-through from the input driver to the output driver
1423 // for development and testing.
1424 // From: audioStream1Task or equivalent
1425 // Uses: See code.
1426 // States: x
1427 // Return: Error number in standard form (0 on success).
1428 // Trace: Message Log "trace" in Debug Project Configuration reports:
1429 // * State information on initialization.
1430 // * State information on processing.
1431 //
1433 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1434 /* Pass Processing is often omitted from builds to save memory, */
1435 /* and CODE_SECTION/clink constructs facilitate this omission. */
1437 Int
1438 PAF_AST_passProcessing (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1439 {
1440 Int z; /* input/output counter */
1441 Int errno = 0; /* error number */
1442 Int getVal;
1443 Int rxNumChan, txNumChan;
1444 Int first;
1445 Int zMD = pC->masterDec;
1446 Int zMI = pP->zone.master;
1449 #ifndef __TI_EABI__
1450 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1451 #endif
1453 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1455 //
1456 // Determine that receive/transmit channels are compatible
1457 //
1459 // Can handle handle only master input
1460 for (z=INPUT1; z < INPUTN; z++) {
1461 if (z != zMI && pC->xInp[z].hRxSio)
1462 return (ASPERR_PASS + 0x01);
1463 }
1465 /* Number of receive/transmit channels */
1467 if (! pC->xInp[zMI].hRxSio)
1468 return (ASPERR_PASS + 0x11);
1469 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1470 return (ASPERR_PASS + 0x12);
1471 if (rxNumChan > NUM_TX_CHAN(zMI))
1472 return (ASPERR_PASS + 0x13);
1474 for (z=OUTPUT1; z < OUTPUTN; z++) {
1475 if (! pC->xOut[zMI].hTxSio)
1476 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1477 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1478 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1479 if (txNumChan > NUM_TX_CHAN(zMI))
1480 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1481 }
1483 //
1484 // Set up receive/transmit
1485 //
1487 SIO_idle (pC->xInp[zMI].hRxSio);
1488 for (z=OUTPUT1; z < OUTPUTN; z++) {
1489 if(SIO_idle (pC->xOut[z].hTxSio))
1490 return ASPERR_IDLE;
1491 }
1493 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1494 return (ASPERR_PASS + 0x14);
1496 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1497 return (ASPERR_PASS + 0x15);
1499 for (z=OUTPUT1; z < OUTPUTN; z++)
1500 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1502 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1503 return ASPERR_PASS + 0x16;
1505 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1506 return ASPERR_PASS + 0x17;
1508 //
1509 // Receive and transmit the data in single-frame buffers
1510 //
1512 first = 1;
1513 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1514 PAF_OutBufConfig *pOutBuf;
1515 PAF_InpBufConfig *pInpBuf;
1517 if (first) {
1518 first = 0;
1520 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1522 for (z=OUTPUT1; z < OUTPUTN; z++) {
1523 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1524 if (getVal > 0) {
1525 errno = ASPERR_ISSUE;
1526 break;
1527 }
1528 else if (getVal < 0) {
1529 errno = -getVal;
1530 break;
1531 }
1533 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1534 return (getVal & 0xff) | ASPERR_MUTE;
1535 }
1536 if (errno)
1537 break;
1539 }
1541 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1542 if (getVal > 0) {
1543 errno = ASPERR_ISSUE;
1544 break;
1545 }
1547 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1549 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1550 if (getVal < 0) {
1551 errno = -getVal;
1552 break;
1553 }
1555 for (z=OUTPUT1; z < OUTPUTN; z++) {
1556 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1557 if (getVal < 0) {
1558 errno = -getVal;
1559 break;
1560 }
1561 }
1562 if( errno )
1563 break;
1565 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1567 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1568 break;
1570 for (z=OUTPUT1; z < OUTPUTN; z++) {
1571 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1572 if (getVal > 0) {
1573 errno = ASPERR_ISSUE;
1574 break;
1575 }
1576 else if (getVal < 0) {
1577 errno = -getVal;
1578 break;
1579 }
1580 }
1581 if( errno )
1582 break;
1583 }
1585 //
1586 // Close down receive/transmit
1587 //
1589 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1591 for (z=OUTPUT1; z < OUTPUTN; z++) {
1592 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1593 if (! errno)
1594 errno = (getVal & 0xff) | ASPERR_MUTE;
1595 /* convert to sensical errno */
1596 }
1597 }
1599 SIO_idle (pC->xInp[zMI].hRxSio);
1600 for (z=OUTPUT1; z < OUTPUTN; z++)
1601 SIO_idle (pC->xOut[z].hTxSio);
1603 return errno;
1605 } //PAF_AST_passProcessing
1606 #endif
1608 #if 0
1609 // -----------------------------------------------------------------------------
1610 // AST Processing Function Helper - Pass-Through Processing Patch Point
1611 //
1612 // Name: PAF_AST_passProcessingCopy
1613 // Purpose: Pass-Through Processing Function for copying audio data
1614 // from the input buffer to the output buffer.
1615 // From: AST Parameter Function -> passProcessing
1616 // Uses: See code.
1617 // States: x
1618 // Return: Error number in standard form (0 on success).
1619 // Trace: Message Log "trace" in Debug Project Configuration reports:
1620 // x
1621 //
1623 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1624 /* Pass Processing is often omitted from builds to save memory, */
1625 /* and CODE_SECTION/clink constructs facilitate this omission. */
1627 Int
1628 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1629 {
1630 Int z; /* output counter */
1631 Int errno; /* error number */
1632 Int i;
1633 Int rxNumChan, txNumChan;
1634 Int zMI = pP->zone.master;
1637 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1639 // Copy data from input channels to output channels one of two ways:
1641 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1642 return (ASPERR_PASS + 0x12);
1644 for (z=OUTPUT1; z < OUTPUTN; z++) {
1645 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1646 return (ASPERR_PASS + 0x22);
1648 if( txNumChan <= rxNumChan ) {
1650 // Copy one to one, ignoring later rx channels as needed.
1652 for( i=0; i < txNumChan; i++ ) {
1653 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1654 if( errno )
1655 return errno;
1656 }
1657 }
1658 else {
1660 // Copy one to many, repeating earlier rx channels as needed.
1662 Int from, to;
1664 from = 0;
1665 to = 0;
1666 while( to < txNumChan ) {
1667 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1668 if( errno )
1669 return errno;
1671 from++;
1672 to++;
1673 if( from == rxNumChan )
1674 from = 0;
1675 }
1676 }
1677 }
1679 return 0;
1680 } //PAF_AST_passProcessingCopy
1681 #endif
1683 // -----------------------------------------------------------------------------
1684 // ASIT Processing Function - Auto Processing
1685 //
1686 // Name: PAF_ASIT_autoProcessing
1687 // Purpose: Audio Stream Input Task Function for processing audio data to
1688 // determine the input type without output.
1689 // From: audioStream1Task or equivalent
1690 // Uses: See code.
1691 // States: x
1692 // Return: Error number in standard or SIO form (0 on success).
1693 // Trace: Message Log "trace" in Debug Project Configuration reports:
1694 // * State information on initialization.
1695 //
1697 #define DECSIOMAP(X) \
1698 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1700 Int
1701 PAF_ASIT_autoProcessing(
1702 const PAF_AST_Params *pP,
1703 const PAF_AST_Patchs *pQ,
1704 PAF_AST_Config *pC,
1705 Int inputTypeSelect,
1706 ALG_Handle pcmAlgMaster
1707 )
1708 {
1709 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1710 Int errno = 0; /* error number */
1711 Int nbytes;
1712 Int frameLength;
1713 Int zMD = pC->masterDec;
1714 Int zMI = pP->zone.master;
1715 Int zMS = pC->masterStr;
1717 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1719 if (errno = SIO_ctrl (pC->xInp[zMI].hRxSio,
1720 PAF_SIO_CONTROL_SET_SOURCESELECT,
1721 DECSIOMAP (pC->xDec[zMD].decodeStatus.sourceSelect)))
1722 {
1723 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1724 return errno;
1725 }
1726 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1727 // pC->xDec[zMD].decodeStatus.bufferRatio);
1728 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1730 if (errno = SIO_ctrl (pC->xInp[zMI].hRxSio,
1731 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1732 {
1733 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1734 errno, ASPERR_AUTO_LENGTH);
1735 return ASPERR_AUTO_LENGTH;
1736 }
1738 if (errno = SIO_issue (pC->xInp[zMI].hRxSio,
1739 &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig),
1740 PAF_SIO_REQUEST_SYNC))
1741 {
1742 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1743 errno, ASPERR_ISSUE);
1744 return ASPERR_ISSUE;
1745 }
1747 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1749 // all of the sync scan work is done in this call. If the error returned
1750 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1751 // error so we mask it off.
1752 nbytes = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL);
1753 if (nbytes == -DIBERR_SYNC)
1754 {
1755 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1756 return 0;
1757 }
1758 if (nbytes != sizeof (PAF_InpBufConfig))
1759 {
1760 TRACE_TERSE3("PAF_AST_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1761 nbytes, sizeof (PAF_InpBufConfig), ASPERR_RECLAIM);
1762 return ASPERR_RECLAIM;
1763 }
1764 if (errno)
1765 {
1766 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1767 }
1768 return errno;
1769 } //PAF_ASIT_autoProcessing
1771 // -----------------------------------------------------------------------------
1772 // ASIT Processing Function - Decode Processing
1773 //
1774 // Name: PAF_ASIT_decodeProcessing
1775 // Purpose: Audio Stream Input Task Function for processing audio data.
1776 // From: audioStream1Task or equivalent
1777 // Uses: See code.
1778 // States: x
1779 // Return: Error number in standard form (0 on success).
1780 // Trace: Message Log "trace" in Debug Project Configuration reports:
1781 // * State information on initialization (via children).
1782 // * State information on processing (via children).
1783 // * Decode warnings.
1784 //
1785 // When "writeDECModeContinuous" is used for zMI input/decode:
1786 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1787 // (a) if "writeDECCommandRestart" is used
1788 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1789 // (b) if "writeDECSourceSelectNone" is used
1790 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1791 // (c) if an error occurs in
1792 // INIT
1793 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1794 // -> PAF_AST_decodeCont(): "Await slave inputs"
1795 // STREAM (errno |= PAF_COMPONENT_ASP)
1796 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1797 // [ the latter errors lead to "switch_break:"
1798 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1799 //
1800 // [ Notably, in FINAL ("frame-finalization state")
1801 // -> PAF_AST_decodeFinalTest() is *not* called,
1802 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1803 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1804 //
1805 // States in which error can't occur:
1806 // AGAIN ("subsequent initial state")
1807 //
1808 // States in which (some) errors must be handled:
1809 // INFO1 ("first frame state")
1810 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1811 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1812 // ?*? but what about ASPERR_RESYNC from same call ?*?
1813 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1814 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1815 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1816 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1817 // - enc->fxns->info()
1818 // - pP->fxns->setCheckRateX()
1819 // - pP->fxns->startOutput()
1820 // - "Start slave inputs if necessary"
1821 // INFO2 ("subsequent frame state")
1822 // -> PAF_AST_decodeInfo(): (see above)
1823 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1824 // - pP->fxns->setCheckRateX()
1825 // TIME ("timing state")
1826 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1827 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1828 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1829 // (*OK* don't try to recover from this*)
1830 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1831 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1832 // possibly in PAF_AST_decodeProcessing() itself **
1833 // DECODE ("decode state")
1834 // -> PAF_AST_decodeDecode(): pass on error from
1835 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1836 // - dec->fxns->reset()
1837 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1838 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
1839 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1840 Int
1841 PAF_ASIT_decodeProcessing(
1842 const PAF_AST_Params *pP,
1843 const PAF_AST_Patchs *pQ,
1844 PAF_AST_Config *pC,
1845 Int sourceSelect
1846 )
1847 {
1848 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1849 Int z; /* decode counter */
1850 Int errno; /* error number */
1851 Int getVal;
1852 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1853 ALG_Handle alg[DECODEN_MAX];
1854 Int zMD = pC->masterDec;
1855 Int zMS = pC->masterStr;
1856 Int size;
1857 //PAF_InpBufConfig *pIpBufConfig;
1858 Int frame; // decoder input frame count
1859 Int block; // (***) FL: formerly -- decoder output block count / input frame
1862 for (z=DECODE1; z < DECODEN; z++)
1863 alg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
1864 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1866 //
1867 // Receive and process the data in single-frame buffers
1868 //
1870 state = INIT;
1871 errno = 0; /* error number */
1873 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pC->xDec[zMD].decodeStatus.sourceSelect);
1875 for (;;)
1876 {
1877 if (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
1878 {
1879 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1880 state = QUIT;
1881 }
1883 // Process commands (decode)
1884 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
1885 {
1886 if (state != INIT) // no need to restart/abort if not yet started
1887 {
1888 if (getVal == ASPERR_QUIT)
1889 {
1890 state = QUIT;
1891 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1892 }
1893 else if (getVal == ASPERR_ABORT)
1894 {
1895 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1896 return getVal;
1897 }
1898 else
1899 {
1900 /* ignore */;
1901 }
1902 }
1903 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
1904 }
1906 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
1907 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
1909 // Process state (decode)
1910 switch (state)
1911 {
1912 case INIT: // initial state
1913 gAsipInitCnt++;
1914 Log_info0("TaskAsip: state=INIT");
1916 // (***) FL: revisit
1917 #if 1 // status for shared beta units can change (e.g. at-boot or alpha)
1918 // write back Status structures for shared Beta Units
1919 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1920 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1921 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1922 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1923 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1924 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1925 Cache_wait();
1926 #endif
1927 #if 0
1928 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1929 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1930 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1931 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1932 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1933 Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1934 Cache_wait();
1935 #endif
1937 //if (errno = pP->fxns->decodeInit (pP, pQ, pC, alg))
1938 //if (errno = pP->fxns->decodeInit(pP, pQ, pC, alg, sourceSelect))
1939 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1940 {
1941 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1942 break;
1943 }
1945 #if 1
1946 // (***) FL: revisit
1947 // invalidate Status structures for shared Beta Units
1948 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1949 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1950 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1951 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1952 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1953 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1954 Cache_wait();
1955 #endif
1957 frame = 0;
1958 block = 0;
1960 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
1961 state = INFO1;
1962 continue;
1964 case INFO1: // first frame state
1965 gAsipInfo1Cnt++;
1966 Log_info0("TaskAsip: state=INFO1");
1968 #if 0
1969 // (***) FL: revisit
1970 // write back Inp configuration
1971 Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
1972 // write back input data
1973 pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
1974 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
1975 Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
1976 // write back Dec configuration
1977 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1978 Cache_wait();
1979 #endif
1981 // Establish primary timing
1982 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
1983 {
1984 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1985 break;
1986 }
1988 #if 0
1989 // (***) FL: revisit
1990 // invalidate Dec configuration
1991 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1992 Cache_wait();
1993 #endif
1995 // Don't start decode until major access unit is found.
1996 if (((pC->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
1997 (pC->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
1998 (pC->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
1999 (pC->xStr[zMS].pAudioFrame->sampleRate == PAF_SAMPLERATE_UNKNOWN))
2000 {
2001 Int z;
2002 for (z=DECODE1; z < DECODEN; z++)
2003 {
2004 Int zI = pP->inputsFromDecodes[z];
2005 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
2006 {
2007 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2008 if (SIO_issue (pC->xInp[zI].hRxSio, &pC->xInp[zI].inpBufConfig,
2009 sizeof (pC->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2010 {
2011 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2012 return (ASPERR_ISSUE);
2013 }
2014 }
2015 }
2016 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2017 frame++;
2018 state = INFO1;
2019 continue;
2020 }
2021 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2023 // Establish secondary timing
2024 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2025 {
2026 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2027 break;
2028 }
2030 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2031 state = DECODE;
2032 continue;
2034 case INFO2: // subsequent frame state
2035 gAsipInfo2Cnt++;
2036 Log_info0("TaskAsip: state=INFO2");
2038 #if 0
2039 // (***) FL: revisit
2040 // write back Inp configuration
2041 Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2042 // write back input data
2043 pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2044 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2045 Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2046 // write back Dec configuration
2047 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2048 Cache_wait();
2049 #endif
2051 // Establish primary timing
2052 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2053 {
2054 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2055 break;
2056 }
2058 #if 0
2059 // (***) FL: revisit
2060 // invalidate Dec configuration
2061 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2062 Cache_wait();
2063 #endif
2065 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2066 {
2067 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2068 break;
2069 }
2071 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2072 state = DECODE;
2073 continue;
2075 case DECODE: // decode state
2076 gAsipDecodeCnt++;
2077 Log_info0("TaskAsip: state=DECODE");
2079 #if 0
2080 // (***) FL: revisit
2081 // write back Dec configuration
2082 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2083 Cache_wait();
2084 #endif
2086 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2087 {
2088 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2089 break;
2090 }
2092 #if 0
2093 // (***) FL: revisit
2094 // invalidate Dec configuration
2095 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2096 Cache_wait();
2097 #endif
2099 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2100 state = FINAL;
2101 continue;
2103 case FINAL: // frame-finalization state
2104 gAsipFinalCnt++;
2105 Log_info0("TaskAsip: state=FINAL");
2107 // Check for final frame, and if indicated:
2108 // - Exit state machine to "complete" processing.
2109 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2110 {
2111 break;
2112 }
2114 frame++;
2115 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2116 state = INFO2;
2117 continue;
2119 case QUIT: // exit state
2120 gAsipQuitCnt++;
2121 Log_info0("TaskAsip: state=QUIT");
2123 // Quit:
2124 // - Set error number registers.
2125 // - Exit state machine to "decode complete" processing.
2126 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2127 errno = ASPERR_QUIT;
2128 break;
2130 default: // unknown state
2132 // Unknown:
2133 // - Set error number registers.
2134 // - Exit state machine to "decode complete" processing.
2136 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2137 errno = ASPERR_UNKNOWNSTATE;
2138 break;
2140 } // End of switch (state).
2142 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2143 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2144 {
2145 /* ignored? */;
2146 }
2148 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2150 return errno;
2151 } // End of for (;;) to Receive, process, and transmit the data.
2152 } //PAF_ASIT_decodeProcessing
2154 // -----------------------------------------------------------------------------
2155 // ASIT Decoding Function - Decode Command Processing
2156 //
2157 // Name: PAF_ASIT_decodeCommand
2158 // Purpose: Decoding Function for processing Decode Commands.
2159 // From: AST Parameter Function -> decodeProcessing
2160 // Uses: See code.
2161 // States: x
2162 // Return: Error number in standard form (0 on success).
2163 // Trace: Message Log "trace" in Debug Project Configuration reports:
2164 // * Command execution.
2165 //
2167 Int
2168 PAF_ASIT_decodeCommand(
2169 const PAF_AST_Params *pP,
2170 const PAF_AST_Patchs *pQ,
2171 PAF_AST_Config *pC
2172 )
2173 {
2174 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2175 Int z; /* decode counter */
2176 Int zS;
2179 for (z=DECODE1; z < DECODEN; z++)
2180 {
2181 zS = pP->streamsFromDecodes[z];
2182 if (!(pC->xDec[z].decodeStatus.command2 & 0x80))
2183 {
2184 switch (pC->xDec[z].decodeStatus.command2)
2185 {
2186 case 0: // command none - process
2187 pC->xDec[z].decodeStatus.command2 |= 0x80;
2188 break;
2189 case 1: // command abort - leave now
2190 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2191 pC->xDec[z].decodeStatus.command2 |= 0x80;
2192 return (ASPERR_ABORT);
2193 case 2: // command restart - leave later
2194 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2195 pC->xDec[z].decodeStatus.command2 |= 0x80;
2196 return (ASPERR_QUIT);
2197 default: // command unknown - ignore
2198 break;
2199 }
2200 }
2201 }
2203 return 0;
2204 } //PAF_ASIT_decodeCommand
2206 // -----------------------------------------------------------------------------
2207 // ASIT Decoding Function - Reinitialization of Decode
2208 //
2209 // Name: PAF_ASIT_decodeInit
2210 // Purpose: Decoding Function for reinitializing the decoding process.
2211 // From: AST Parameter Function -> decodeProcessing
2212 // Uses: See code.
2213 // States: x
2214 // Return: Error number in standard or SIO form (0 on success).
2215 // Trace: Message Log "trace" in Debug Project Configuration reports:
2216 // * State information as per parent.
2217 //
2218 Int
2219 PAF_ASIT_decodeInit(
2220 const PAF_AST_Params *pP,
2221 const PAF_AST_Patchs *pQ,
2222 PAF_AST_Config *pC,
2223 Int sourceSelect
2224 )
2225 {
2226 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2227 Int z; /* decode/encode counter */
2228 Int errno; /* error number */
2229 Int zI, zS;
2230 Int zMD = pC->masterDec;
2231 Int zMI = pP->zone.master;
2232 ASP_Msg* pAspMsg; /* Messaging */
2233 Int argIdx;
2234 Int decErrno;
2235 Int status;
2236 PAF_DecodeOpCircBuf *pCb; /* Decoder output circular buffer */
2238 (void)as; // clear compiler warning in case not used with tracing disabled
2240 // reset frameCount
2241 for (z=DECODE1; z < DECODEN; z++)
2242 {
2243 if (pC->xDec[z].decodeStatus.mode)
2244 {
2245 pC->xDec[z].decodeStatus.frameCount = 0;
2246 }
2247 }
2249 for (z=DECODE1; z < DECODEN; z++)
2250 {
2251 zI = pP->inputsFromDecodes[z];
2252 zS = pP->streamsFromDecodes[z];
2253 (void)zS; // clear compiler warning in case not used with tracing disabled
2254 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
2255 {
2256 Uns gear;
2257 Int frameLength;
2258 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2260 // write back Dec configuration
2261 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2262 Cache_wait();
2264 // FL: send dec activate message to slave
2265 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2266 if (pAspMsg == NULL)
2267 {
2268 TRACE_TERSE0("MessageQ_alloc() failure.");
2269 SW_BREAKPOINT; // temporary
2270 return -1; // temporary
2271 }
2272 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2273 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2274 pAspMsg->procId = hAspMsgMaster->masterProcId;
2275 pAspMsg->expectResp = TRUE;
2276 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2277 argIdx = 0; // set decIdx (zone index)
2278 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2279 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2280 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2281 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2282 if (status != MessageQ_S_SUCCESS)
2283 {
2284 SW_BREAKPOINT;
2285 }
2286 // wait for dec activate complete message from slave
2287 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2288 if (status != MessageQ_S_SUCCESS)
2289 {
2290 TRACE_TERSE0("MessageQ_get() failure.");
2291 SW_BREAKPOINT; // temporary
2292 return -1; // temporary
2293 }
2294 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2295 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2296 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2297 {
2298 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2299 SW_BREAKPOINT; // temporary
2300 return -1; // temporary
2301 }
2302 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2303 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2304 // free the message
2305 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2306 if (status != MessageQ_S_SUCCESS)
2307 {
2308 SW_BREAKPOINT;
2309 }
2311 #if 0 // FL: decoder activate call, slave
2312 if (decAlg[z]->fxns->algActivate)
2313 decAlg[z]->fxns->algActivate (decAlg[z]);
2314 #endif
2316 // FL: send dec reset message to slave
2317 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2318 if (pAspMsg == NULL)
2319 {
2320 TRACE_TERSE0("MessageQ_alloc() failure.");
2321 SW_BREAKPOINT; // temporary
2322 return -1; // temporary
2323 }
2324 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2325 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2326 pAspMsg->procId = hAspMsgMaster->masterProcId;
2327 pAspMsg->expectResp = TRUE;
2328 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2329 argIdx = 0; // set decIdx
2330 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2331 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2332 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2333 // wait for dec reset complete message from slave
2334 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2335 if (status != MessageQ_S_SUCCESS)
2336 {
2337 SW_BREAKPOINT;
2338 }
2339 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2340 if (status != MessageQ_S_SUCCESS)
2341 {
2342 TRACE_TERSE0("MessageQ_get() failure.");
2343 SW_BREAKPOINT; // temporary
2344 return -1; // temporary
2345 }
2346 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2347 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2348 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2349 {
2350 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2351 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2352 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2354 argIdx = 0; // get decErrno
2355 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2356 if (decErrno != 0)
2357 {
2358 return decErrno;
2359 }
2360 }
2361 else
2362 {
2363 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2364 SW_BREAKPOINT; // temporary
2365 return -1; // temporary
2366 }
2367 // free the message
2368 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2369 if (status != MessageQ_S_SUCCESS)
2370 {
2371 SW_BREAKPOINT;
2372 }
2374 // (***) FL: revisit
2375 // invalidate Dec configuration
2376 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2377 Cache_wait();
2379 #if 0 // FL: decoder reset call, slave
2380 if (dec->fxns->reset
2381 && (errno = dec->fxns->reset (dec, NULL,
2382 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2383 return errno;
2384 #endif
2386 gear = pC->xDec[z].decodeStatus.aspGearControl;
2387 pC->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2389 #if 0 // FL: change handle to decIdx (zone index)
2390 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2391 FRAMELENGTH,
2392 pC->xDec[z].decodeStatus.bufferRatio);
2393 #endif
2394 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2395 frameLength = pP->fxns->computeFrameLength(z,
2396 FRAMELENGTH,
2397 pC->xDec[z].decodeStatus.bufferRatio);
2398 #else
2399 if (sourceSelect == PAF_SOURCE_PCM)
2400 {
2401 frameLength = 256;
2402 }
2403 else if (sourceSelect == PAF_SOURCE_DDP)
2404 {
2405 frameLength = 1536;
2406 }
2407 else
2408 {
2409 frameLength = 256;
2410 }
2411 #endif
2413 pC->xDec[z].decodeControl.frameLength = frameLength;
2414 pC->xDec[z].decodeInStruct.sampleCount = frameLength;
2415 pC->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2417 // (***) FL: revisit. Count samples for DDP.
2418 // Add framework frame length and running sample count to decoder control.
2419 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2420 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2422 // Initialize decoder output circular buffer for selected source
2423 pCb = &pC->xDec[z].decOpCb;
2424 errno = cbInit(sourceSelect, frameLength, FRAMELENGTH, pCb, 0);
2425 if (errno)
2426 {
2427 SW_BREAKPOINT; // FL: debug
2428 return errno;
2429 }
2430 // FL: debug
2431 cbLog(pCb, 1, "PAF_ASIT_decodeInit:cbInit");
2433 if (z != zMD)
2434 {
2435 if (errno = SIO_idle(pC->xInp[zI].hRxSio))
2436 {
2437 return errno;
2438 }
2439 }
2441 if (errno = SIO_ctrl(pC->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2442 DECSIOMAP(pC->xDec[z].decodeStatus.sourceSelect)))
2443 {
2444 return errno;
2445 }
2446 if (errno = SIO_ctrl(pC->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2447 frameLength))
2448 {
2449 return errno;
2450 }
2451 if (errno = pP->fxns->updateInputStatus(pC->xInp[zI].hRxSio, &pC->xInp[zI].inpBufStatus,
2452 &pC->xInp[zI].inpBufConfig))
2453 {
2454 return errno;
2455 }
2456 }
2457 }
2459 if (pC->xInp[zMI].hRxSio)
2460 {
2461 errno = SIO_issue(pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig,
2462 sizeof(pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2463 if (errno)
2464 {
2465 return errno;
2466 }
2467 }
2469 return 0;
2470 } //PAF_AST_decodeInit
2472 // -----------------------------------------------------------------------------
2473 // ASIT Decoding Function - Info Processing, Common
2474 //
2475 // Name: PAF_ASIT_decodeInfo
2476 // Purpose: Decoding Function for processing information in a manner that
2477 // is common for both initial and subsequent frames of input data.
2478 // From: AST Parameter Function -> decodeProcessing
2479 // Uses: See code.
2480 // States: x
2481 // Return: Error number in standard form (0 on success).
2482 // Trace: Message Log "trace" in Debug Project Configuration reports:
2483 // * State information as per parent.
2484 //
2485 Int
2486 PAF_ASIT_decodeInfo(
2487 const PAF_AST_Params *pP,
2488 const PAF_AST_Patchs *pQ,
2489 PAF_AST_Config *pC,
2490 Int frame,
2491 Int block
2492 )
2493 {
2494 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2495 Int z; /* input/decode/stream counter */
2496 Int errno; /* error number */
2497 Int sioErr; /* error number, SIO */
2498 Int zD, zI, zS, zX;
2499 Int zMD = pC->masterDec;
2500 Int zMI = pP->zone.master;
2501 Int zMS = pC->masterStr;
2502 UInt32 curTime;
2503 ASP_Msg *pAspMsg; /* Messaging */
2504 Int argIdx;
2505 Int status;
2506 // FL: revisit
2507 //Int size;
2508 //PAF_InpBufConfig *pIpBufConfig;
2510 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2512 // Set decode control: sample rate, emphasis
2513 for (z=INPUT1; z < INPUTN; z++)
2514 {
2515 zD = z;
2516 for (zX = DECODE1; zX < DECODEN; zX++)
2517 {
2518 if (pP->inputsFromDecodes[zX] == z)
2519 {
2520 zD = zX;
2521 break;
2522 }
2523 }
2525 if (pC->xInp[z].hRxSio)
2526 {
2527 //determine associated decoder
2528 if (pC->xInp[z].inpBufStatus.sampleRateStatus !=
2529 pC->xDec[zD].decodeControl.sampleRate)
2530 {
2531 if (pC->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2532 {
2533 pC->xDec[zD].decodeControl.sampleRate =
2534 pC->xInp[z].inpBufStatus.sampleRateStatus;
2535 }
2536 else
2537 {
2538 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pC->masterStr);
2539 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2540 pC->xInp[z].inpBufStatus.sampleRateStatus,
2541 pC->xDec[zD].decodeControl.sampleRate);
2542 // return (ASPERR_INFO_RATECHANGE);
2543 }
2544 }
2545 pC->xDec[zD].decodeControl.emphasis =
2546 pC->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2547 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2548 : pC->xInp[z].inpBufStatus.emphasisStatus;
2549 }
2550 else
2551 {
2552 pC->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2553 pC->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2554 }
2555 }
2557 // Wait for info input
2558 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2559 if (pC->xInp[zMI].hRxSio)
2560 {
2561 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2562 sioErr = SIO_reclaim(pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL);
2563 if (sioErr != sizeof(pC->xInp[zMI].inpBufConfig))
2564 {
2565 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2566 return ASPERR_RECLAIM;
2567 }
2569 // FL: debug, capture input buffer
2570 //capIb(pC->xInp[zMI].pInpBuf);
2572 //
2573 // Simulate Rx SIO_reclaim() pend
2574 //
2575 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2576 gTaskAsipCnt++;
2577 curTime = Clock_getTicks();
2578 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2579 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2580 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2581 } //pC->xInp[zMI].hRxSio
2583 // Decode info
2584 for (z=DECODE1; z < DECODEN; z++)
2585 {
2586 zI = pP->inputsFromDecodes[z];
2587 zS = pP->streamsFromDecodes[z];
2588 (void)zS; // clear compiler warning in case not used with tracing disabled
2589 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
2590 {
2591 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2593 if (errno = pP->fxns->updateInputStatus(pC->xInp[zI].hRxSio,
2594 &pC->xInp[zI].inpBufStatus, &pC->xInp[zI].inpBufConfig))
2595 {
2596 TRACE_TERSE1("return error errno 0x%x.", errno);
2597 return errno;
2598 }
2600 #if 1
2601 // (***) FL: revisit
2602 // write back Inp configuration
2603 Cache_wb(&gPAF_AST_config.xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2604 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2605 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2606 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2607 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2608 // write back Dec configuration
2609 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2610 Cache_wait();
2611 #endif
2613 // FL: send info message to slave
2614 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2615 if (pAspMsg == NULL)
2616 {
2617 TRACE_TERSE0("MessageQ_alloc() failure.");
2618 SW_BREAKPOINT; // temporary
2619 return -1; // temporary
2620 }
2621 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2622 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
2623 pAspMsg->procId = hAspMsgMaster->masterProcId;
2624 pAspMsg->expectResp = TRUE;
2625 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2626 argIdx = 0; // set decIdx
2627 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2628 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2629 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2630 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
2631 if (status != MessageQ_S_SUCCESS)
2632 {
2633 SW_BREAKPOINT;
2634 }
2635 // wait for dec info complete message from slave -- temporary
2636 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2637 if (status != MessageQ_S_SUCCESS)
2638 {
2639 TRACE_TERSE0("MessageQ_get() failure.");
2640 SW_BREAKPOINT;
2641 return -1; // temporary
2642 }
2643 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2644 (pAspMsg->cmd != ASP_MASTER_DEC_INFO_DONE) ||
2645 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2646 {
2647 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2648 SW_BREAKPOINT; // temporary
2649 }
2650 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2651 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2652 // free the message
2653 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2654 if (status != MessageQ_S_SUCCESS)
2655 {
2656 SW_BREAKPOINT;
2657 }
2659 #if 1
2660 // (***) FL: revisit
2661 // invalidate Dec configuration
2662 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2663 Cache_wait();
2664 #endif
2666 #if 0 // FL: decoder info call, slave
2667 if (dec->fxns->info
2668 && (errno = dec->fxns->info (dec, NULL,
2669 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2670 #endif
2671 if (errno)
2672 {
2673 TRACE_TERSE1("return error errno 0x%x.", errno);
2674 return errno;
2675 }
2676 // increment decoded frame count
2677 pC->xDec[z].decodeStatus.frameCount += 1;
2678 }
2679 } // z=DECODE1 to DECODEN
2681 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2682 if (pC->xDec[zMD].decodeStatus.mode)
2683 {
2684 XDAS_Int8 sourceProgram;
2685 if (errno = SIO_ctrl(pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2686 (Arg)&sourceProgram))
2687 {
2688 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2689 return ASPERR_AUTO_PROGRAM;
2690 }
2691 pC->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
2693 #if 0
2694 // (***) FL: revisit
2695 Cache_wb((Ptr)&pC->xDec[zMD].decodeStatus.sourceProgram,
2696 sizeof(pC->xDec[zMD].decodeStatus.sourceProgram), Cache_Type_ALLD, 0);
2697 Cache_wait();
2698 #endif
2699 }
2701 // since now decoding update decode status for all enabled decoders
2702 for (z=DECODE1; z < DECODEN; z++)
2703 {
2704 if (pC->xDec[z].decodeStatus.mode)
2705 {
2706 pC->xDec[z].decodeStatus.sourceDecode = pC->xDec[z].decodeStatus.sourceProgram;
2707 if (pC->xDec[z].decodeStatus.sourceSelect == PAF_SOURCE_SNG)
2708 {
2709 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_SNG;
2710 }
2712 #if 0
2713 // (***) FL: revisit
2714 Cache_wb((Ptr)&pC->xDec[z].decodeStatus.sourceDecode,
2715 sizeof(pC->xDec[z].decodeStatus.sourceDecode), Cache_Type_ALLD, 0);
2716 Cache_wait();
2717 #endif
2718 }
2719 }
2721 #if 0 // FL: ASDT (slave)
2722 // TODO: move this to start of this function so that it doesn't affect IO timing
2723 // Initialize audio frame(s)
2724 // Re-initialize audio frame if there is an associated decode and
2725 // that decode doesn't have a valid input or is turned off
2726 for (z=STREAM1; z < STREAMN; z++)
2727 {
2728 Int reset = 0;
2729 for (zX = DECODE1; zX < DECODEN; zX++)
2730 {
2731 if (pP->streamsFromDecodes[zX] == z)
2732 {
2733 zI = pP->inputsFromDecodes[zX];
2734 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2735 {
2736 reset = 1;
2737 }
2738 }
2739 }
2740 if (reset)
2741 {
2742 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2743 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2744 }
2745 else
2746 {
2747 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2748 }
2749 }
2750 #endif
2752 return 0;
2753 } //PAF_ASIT_decodeInfo
2755 // -----------------------------------------------------------------------------
2756 // ASIT Decoding Function - Info Processing, Initial
2757 //
2758 // Name: PAF_ASIT_decodeInfo1
2759 // Purpose: Decoding Function for processing information in a manner that
2760 // is unique to initial frames of input data.
2761 // From: AST Parameter Function -> decodeProcessing
2762 // Uses: See code.
2763 // States: x
2764 // Return: Error number in standard or SIO form (0 on success).
2765 // Trace: Message Log "trace" in Debug Project Configuration reports:
2766 // * State information as per parent.
2767 //
2768 Int
2769 PAF_ASIT_decodeInfo1(
2770 const PAF_AST_Params *pP,
2771 const PAF_AST_Patchs *pQ,
2772 PAF_AST_Config *pC,
2773 Int frame,
2774 Int block
2775 )
2776 {
2777 return 0;
2778 } //PAF_ASIT_decodeInfo1
2780 // -----------------------------------------------------------------------------
2781 // AST Decoding Function - Info Processing, Subsequent
2782 //
2783 // Name: PAF_AST_decodeInfo2
2784 // Purpose: Decoding Function for processing information in a manner that
2785 // is unique to frames of input data other than the initial one.
2786 // From: AST Parameter Function -> decodeProcessing
2787 // Uses: See code.
2788 // States: x
2789 // Return: Error number in standard form (0 on success).
2790 // Trace: None.
2791 //
2792 Int
2793 PAF_ASIT_decodeInfo2(
2794 const PAF_AST_Params *pP,
2795 const PAF_AST_Patchs *pQ,
2796 PAF_AST_Config *pC,
2797 Int frame,
2798 Int block
2799 )
2800 {
2801 return 0;
2802 } //PAF_ASIT_decodeInfo2
2804 // -----------------------------------------------------------------------------
2805 // AST Decoding Function - Continuation Processing
2806 //
2807 // Name: PAF_AST_decodeCont
2808 // Purpose: Decoding Function for processing that occurs subsequent to
2809 // information processing but antecedent to timing processing
2810 // for frames of input data other than the initial one.
2811 // From: AST Parameter Function -> decodeProcessing
2812 // Uses: See code.
2813 // States: x
2814 // Return: Error number in standard form (0 on success).
2815 // Trace: Message Log "trace" in Debug Project Configuration reports:
2816 // * State information as per parent.
2817 //
2819 Int
2820 PAF_AST_decodeCont (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int frame, Int block)
2821 {
2822 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2823 Int z; /* decode counter */
2824 Int zI, zS;
2825 Int zMD = pC->masterDec;
2827 (void)as; // clear compiler warning in case not used with tracing disabled
2829 // Await slave inputs
2830 for (z=DECODE1; z < DECODEN; z++) {
2831 zI = pP->inputsFromDecodes[z];
2832 zS = pP->streamsFromDecodes[z];
2833 (void)zS;
2834 if (z == zMD
2835 || ! pC->xInp[zI].hRxSio
2836 || ! pC->xDec[z].decodeStatus.mode)
2837 continue;
2838 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2839 if (SIO_reclaim (pC->xInp[zI].hRxSio, (Ptr)&pC->xInp[zI].pInpBuf, NULL)
2840 != sizeof (pC->xInp[zI].inpBufConfig))
2841 return (ASPERR_RECLAIM);
2842 }
2844 return 0;
2845 } //PAF_AST_decodeCont
2847 // -----------------------------------------------------------------------------
2848 // ASIT Decoding Function - Decode Processing
2849 //
2850 // Name: PAF_ASIT_decodeDecode
2851 // Purpose: Decoding Function for processing of input data by the
2852 // Decode Algorithm.
2853 // From: AST Parameter Function -> decodeProcessing
2854 // Uses: See code.
2855 // States: x
2856 // Return: Error number in standard form (0 on success).
2857 // Trace: Message Log "trace" in Debug Project Configuration reports:
2858 // * State information as per parent.
2859 //
2860 Int
2861 PAF_ASIT_decodeDecode(
2862 const PAF_AST_Params *pP,
2863 const PAF_AST_Patchs *pQ,
2864 PAF_AST_Config *pC,
2865 Int sourceSelect,
2866 Int frame,
2867 Int block
2868 )
2869 {
2870 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2871 Int z; /* decode/stream counter */
2872 Int errno; /* error number */
2873 //Int ch;
2874 ASP_Msg *pAspMsg; /* Messaging */
2875 Int argIdx;
2876 Int status;
2877 Int cbErrno;
2878 Int frameLength;
2880 (void)as; // clear compiler warning in case not used with tracing disabled
2882 #if 0 // FL: slave
2883 // Clear samsiz for all channels - MID 208.
2884 for (z=STREAM1; z < STREAMN; z++)
2885 {
2886 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
2887 {
2888 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
2889 }
2890 }
2891 #endif
2893 // Decode data
2894 for (z=DECODE1; z < DECODEN; z++)
2895 {
2896 Int zI = pP->inputsFromDecodes[z];
2897 Int zS = pP->streamsFromDecodes[z];
2898 (void)zS; // clear compiler warning in case not used with tracing disabled
2899 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
2900 {
2901 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
2903 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
2904 as+zS,
2905 (IArg)pC->xInp[z].pInpBuf->base.pVoid,
2906 (IArg)pC->xInp[z].pInpBuf->head.pVoid);
2908 // FL: debug, capture input buffer
2909 //capIbPcm(pC->xInp[z].pInpBuf);
2911 // (***) FL: revisit
2912 // write back Dec configuration
2913 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2914 Cache_wait();
2916 // FL: send decode message to slave
2917 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2918 if (pAspMsg == NULL)
2919 {
2920 TRACE_TERSE0("MessageQ_alloc() failure.");
2921 SW_BREAKPOINT; // temporary
2922 return -1; // temporary
2923 }
2924 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2925 pAspMsg->cmd = ASP_SLAVE_DEC_DECODE; /* fill in message payload */
2926 pAspMsg->procId = hAspMsgMaster->masterProcId;
2927 pAspMsg->expectResp = TRUE;
2928 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2929 argIdx = 0; // set decIdx
2930 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2931 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2932 TRACE_MSG1("decIdx=%d", pAspMsg->buf[argIdx]);
2933 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2934 if (status != MessageQ_S_SUCCESS)
2935 {
2936 SW_BREAKPOINT;
2937 }
2938 // wait for decode complete message from slave -- temporary
2939 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2940 if (status != MessageQ_S_SUCCESS)
2941 {
2942 TRACE_TERSE0("MessageQ_get() failure.");
2943 SW_BREAKPOINT; // temporary
2944 return -1; // temporary
2945 }
2946 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2947 (pAspMsg->cmd == ASP_MASTER_DEC_DECODE_DONE) &&
2948 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2949 {
2950 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2951 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2953 argIdx = 0;
2954 errno = *(Int32 *)&pAspMsg->buf[argIdx];
2955 argIdx += sizeof(Int32);
2956 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2957 if (cbErrno != 0)
2958 {
2959 TRACE_TERSE1("CB write error=%d", cbErrno);
2960 SW_BREAKPOINT; // temporary
2961 }
2962 }
2963 else
2964 {
2965 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2966 SW_BREAKPOINT; // temporary
2967 }
2968 // free the message
2969 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2970 if (status != MessageQ_S_SUCCESS)
2971 {
2972 SW_BREAKPOINT;
2973 }
2975 // (***) FL: revisit
2976 // invalidate Dec configuration
2977 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2978 Cache_wait();
2980 #if 0 // FL: decoder decode call, slave
2981 if (dec->fxns->decode
2982 && (errno = dec->fxns->decode (dec, NULL,
2983 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
2984 #endif
2985 if (errno)
2986 {
2987 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
2988 return errno;
2989 }
2991 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2992 as_traceChannels(pC, z);
2993 #endif
2995 #if 0 // FL: change handle to decIdx (zone index)
2996 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2997 FRAMELENGTH,
2998 pC->xDec[z].decodeStatus.bufferRatio);
2999 #endif
3000 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
3001 frameLength = pP->fxns->computeFrameLength(z,
3002 FRAMELENGTH,
3003 pC->xDec[z].decodeStatus.bufferRatio);
3004 #else
3005 if (sourceSelect == PAF_SOURCE_PCM)
3006 frameLength = 256;
3007 else if (sourceSelect == PAF_SOURCE_DDP)
3008 frameLength = 1536;
3009 else
3010 frameLength = 256;
3011 #endif
3013 // ............................................................................
3015 pC->xDec[z].decodeControl.frameLength = frameLength;
3016 pC->xDec[z].decodeInStruct.sampleCount = frameLength;
3017 if (errno = SIO_ctrl(pC->xInp[zI].hRxSio,
3018 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3019 {
3020 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3021 return errno;
3022 }
3024 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3025 if (errno = SIO_issue(pC->xInp[zI].hRxSio, &pC->xInp[zI].inpBufConfig,
3026 sizeof(pC->xInp[zI].inpBufConfig),
3027 PAF_SIO_REQUEST_NEWFRAME))
3028 {
3029 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3030 return (ASPERR_ISSUE);
3031 }
3032 } // hRxSio && decodeStatus.mode
3033 else
3034 {
3035 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3036 }
3037 } // z=DECODE1 to DECODEN
3039 #if 0 // FL: ASDT (slave)
3040 // Set up audio frames not decoded into
3041 // Re-initialize audio frame if there is an assocatiated decode and
3042 // that decode doesn't have a valid input or is turned off
3043 for (z=STREAM1; z < STREAMN; z++)
3044 {
3045 Int zX;
3046 Int reset = 0;
3047 for (zX = DECODE1; zX < DECODEN; zX++)
3048 {
3049 if (pP->streamsFromDecodes[zX] == z)
3050 {
3051 Int zI = pP->inputsFromDecodes[zX];
3052 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3053 reset = 1;
3054 }
3055 }
3056 if (reset)
3057 {
3058 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3059 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3060 }
3061 else
3062 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3063 }
3064 #endif
3066 return 0;
3067 } //PAF_ASIT_decodeDecode
3069 // -----------------------------------------------------------------------------
3070 // ASIT Decoding Function - Frame-Final Processing
3071 //
3072 // Name: PAF_ASIT_decodeFinalTest
3073 // Purpose: Decoding Function for determining whether processing of the
3074 // current frame is complete.
3075 // From: AST Parameter Function -> decodeProcessing
3076 // Uses: See code.
3077 // States: x
3078 // Return: 0 if incomplete, and 1 if complete.
3079 // Trace: None.
3080 //
3082 Int
3083 PAF_ASIT_decodeFinalTest(
3084 const PAF_AST_Params *pP,
3085 const PAF_AST_Patchs *pQ,
3086 PAF_AST_Config *pC,
3087 Int frame,
3088 Int block
3089 )
3090 {
3091 Int zMD = pC->masterDec;
3092 Int sourceSelect;
3093 Int sourceProgram;
3096 sourceSelect = pC->xDec[zMD].decodeStatus.sourceSelect;
3097 sourceProgram = pC->xDec[zMD].decodeStatus.sourceProgram;
3099 if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3100 {
3101 return 1;
3102 }
3104 // The following allows for Force modes to switch without command deferral. This might
3105 // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3106 if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
3107 {
3108 if (sourceSelect == PAF_SOURCE_DTSALL)
3109 {
3110 if (sourceProgram != PAF_SOURCE_DTS11 &&
3111 sourceProgram != PAF_SOURCE_DTS12 &&
3112 sourceProgram != PAF_SOURCE_DTS13 &&
3113 sourceProgram != PAF_SOURCE_DTS14 &&
3114 sourceProgram != PAF_SOURCE_DTS16 &&
3115 sourceProgram != PAF_SOURCE_DTSHD)
3116 {
3117 return 1;
3118 }
3119 }
3120 else if (sourceSelect == PAF_SOURCE_PCMAUTO)
3121 {
3122 if (sourceProgram != PAF_SOURCE_PCM)
3123 {
3124 return 1;
3125 }
3126 }
3127 else
3128 {
3129 if (pC->xDec[zMD].decodeStatus.sourceSelect != pC->xDec[zMD].decodeStatus.sourceDecode)
3130 {
3131 return 1;
3132 }
3133 }
3134 }
3136 return 0;
3137 } //PAF_ASIT_decodeFinalTest
3139 // -----------------------------------------------------------------------------
3140 // ASIT Decoding Function - Stream-Final Processing
3141 //
3142 // Name: PAF_ASIT_decodeComplete
3143 // Purpose: Decoding Function for terminating the decoding process.
3144 // From: AST Parameter Function -> decodeProcessing
3145 // Uses: See code.
3146 // States: x
3147 // Return: 0.
3148 // Trace: Message Log "trace" in Debug Project Configuration reports:
3149 // * State information as per parent.
3150 //
3151 Int
3152 PAF_ASIT_decodeComplete(
3153 const PAF_AST_Params *pP,
3154 const PAF_AST_Patchs *pQ,
3155 PAF_AST_Config *pC,
3156 ALG_Handle decAlg[],
3157 Int frame,
3158 Int block
3159 )
3160 {
3161 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
3162 Int z; /* decode/encode counter */
3163 ASP_Msg* pAspMsg;
3164 Int argIdx;
3165 Int errno; /* error number */
3166 Int status;
3167 PAF_DecodeOpCircBuf *pCb; // FL: decoder output circular buffer
3169 (void)as; // clear compiler warning in case not used with tracing disabled
3171 #ifdef PAF_ASP_FINAL
3172 /* This material is currently not utilized */
3173 #endif /* PAF_ASP_FINAL */
3174 for (z=DECODE1; z < DECODEN; z++)
3175 {
3176 #ifdef PAF_ASP_FINAL
3177 DEC_Handle dec = (DEC_Handle )decAlg[z];
3178 #endif /* PAF_ASP_FINAL */
3179 Int zI = pP->inputsFromDecodes[z];
3180 if (pC->xInp[zI].hRxSio && pC->xDec[z].decodeStatus.mode)
3181 {
3182 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3183 #ifdef PAF_ASP_FINAL
3184 if (dec->fxns->final)
3185 dec->fxns->final(dec, NULL, &pC->xDec[z].decodeControl,
3186 &pC->xDec[z].decodeStatus);
3187 #endif /* PAF_ASP_FINAL */
3188 // FL: send dec deactivate message to slave
3189 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3190 if (pAspMsg == NULL)
3191 {
3192 TRACE_TERSE0("MessageQ_alloc() failure.");
3193 errno = -1; // temporary
3194 return errno;
3195 }
3196 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3197 pAspMsg->cmd = ASP_SLAVE_DEC_DEACTIVATE; /* fill in message payload */
3198 pAspMsg->procId = hAspMsgMaster->masterProcId;
3199 pAspMsg->expectResp = TRUE;
3200 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3201 argIdx = 0; // set decIdx
3202 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3203 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3204 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3205 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3206 if (status != MessageQ_S_SUCCESS)
3207 {
3208 SW_BREAKPOINT;
3209 }
3210 // wait for dec deactivate complete message from slave
3211 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3212 if (status != MessageQ_S_SUCCESS)
3213 {
3214 TRACE_TERSE0("MessageQ_get() failure.");
3215 return errno;
3216 }
3217 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
3218 (pAspMsg->cmd != ASP_MASTER_DEC_DEACTIVATE_DONE) ||
3219 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3220 {
3221 TRACE_MSG3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3222 SW_BREAKPOINT; // temporary
3223 }
3224 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3225 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3226 // free the message
3227 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3228 if (status != MessageQ_S_SUCCESS)
3229 {
3230 SW_BREAKPOINT;
3231 }
3233 #if 0 // FL: decoder deactivate call, slave
3234 if (decAlg[z]->fxns->algDeactivate)
3235 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3236 #endif
3238 #if 0
3239 // Stop decoder output circular buffer writes
3240 pCb = &pC->xDec[z].decOpCb;
3241 errno = cbWriteStop(pCb);
3242 if (errno)
3243 {
3244 return errno;
3245 }
3246 #endif
3247 }
3248 else
3249 {
3250 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3251 }
3252 }
3253 return 0;
3254 } //PAF_ASIT_decodeComplete
3256 // -----------------------------------------------------------------------------
3257 // ASIT Selection Function - Input Device Selection
3258 //
3259 // Name: PAF_ASIT_selectDevices
3260 // Purpose: Audio Stream Input Task Function for selecting the devices used
3261 // for input.
3262 // From: audioStream1Task or equivalent
3263 // Uses: See code.
3264 // States: x
3265 // Return: Error number in standard form (0 on success).
3266 // Trace: Message Log "trace" in Debug Project Configuration reports:
3267 // * State information as per parent.
3268 //
3269 Int
3270 PAF_ASIT_selectDevices(
3271 const PAF_AST_Params *pP,
3272 const PAF_AST_Patchs *pQ,
3273 PAF_AST_Config *pC
3274 )
3275 {
3276 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
3277 Int z; /* input/output counter */
3278 Int errno = 0; /* error number */
3279 Int errme; /* error number, local */
3280 Int device;
3281 Int zMD = pC->masterDec;
3283 (void)as; // clear compiler warning in case not used with tracing disabled
3285 // Select input devices
3286 for (z=INPUT1; z < INPUTN; z++)
3287 {
3288 if ((device = pC->xInp[z].inpBufStatus.sioSelect) >= 0)
3289 {
3290 TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3292 // check for valid index into device array
3293 if (device >= pQ->devinp->n)
3294 {
3295 device = 0; /* treat as device None */
3296 }
3298 errme = pP->fxns->deviceSelect(&pC->xInp[z].hRxSio, SIO_INPUT,
3299 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3301 if (errme)
3302 {
3303 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3304 if (!errno)
3305 {
3306 errno = ASPERR_DEVINP + errme;
3307 }
3308 pC->xInp[z].inpBufStatus.sioSelect = 0x80;
3309 }
3310 else
3311 {
3312 pC->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3313 // register decodeStatus pointer with input devices
3314 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3315 // Use zMIs decodeStatus for all inputs
3316 if (pC->xInp[z].hRxSio)
3317 {
3318 // register PAF_SIO_IALG object address
3319 SIO_ctrl(pC->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR,
3320 (Arg)pC->xInp[z].inpChainData.head->alg);
3321 SIO_ctrl(pC->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR,
3322 (Arg)&pC->xDec[zMD].decodeStatus);
3323 }
3324 }
3325 }
3326 }
3328 return errno;
3329 } //PAF_ASIT_selectDevices
3331 // -----------------------------------------------------------------------------
3332 // ASIT Selection Function - Source Selection
3333 //
3334 // Name: PAF_ASIT_sourceDecode
3335 // Purpose: Audio Input Stream Task Function for selecting the sources used
3336 // for decoding of input to output.
3337 // From: audioStream1Task or equivalent
3338 // Uses: See code.
3339 // States: x
3340 // Return: 0.
3341 // Trace: None.
3342 //
3343 Int
3344 PAF_ASIT_sourceDecode(
3345 const PAF_AST_Params *pP,
3346 const PAF_AST_Patchs *pQ,
3347 PAF_AST_Config *pC,
3348 Int x
3349 )
3350 {
3351 Int z; /* decode counter */
3353 for (z=DECODE1; z < DECODEN; z++)
3354 {
3355 if (pC->xDec[z].decodeStatus.mode)
3356 {
3357 pC->xDec[z].decodeStatus.sourceDecode = x;
3358 }
3359 }
3361 return 0;
3362 } //PAF_ASIT_sourceDecode
3364 // -----------------------------------------------------------------------------
3366 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3367 Int
3368 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3369 {
3370 Int errno = 0;
3371 Int zMD = pC->masterDec;
3372 Int zI = pP->inputsFromDecodes[z];
3374 // only handle real errors, on primary input, for writeDECModeContinuous
3375 if ( !( error &&
3376 z == zMD ))
3377 return error;
3379 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3380 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3382 if (pC->xInp[zI].hRxSio) {
3383 DEC_Handle dec;
3385 if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3386 return errno;
3388 // indicates (primary) input not running
3389 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3391 pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3393 // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3394 pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3396 if (decAlg[z]->fxns->algDeactivate)
3397 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3399 decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3400 dec = (DEC_Handle )decAlg[z];
3402 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3403 pC->as+z));
3405 if (decAlg[z]->fxns->algActivate)
3406 decAlg[z]->fxns->algActivate (decAlg[z]);
3408 if (dec->fxns->reset
3409 && (errno = dec->fxns->reset (dec, NULL,
3410 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3411 return errno;
3412 }
3414 return errno;
3415 } //PAF_AST_decodeHandleErrorInput
3416 #endif
3418 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3420 //------------------------------------------------------------------------------
3421 static int sSkipCount = 0;
3422 int gReportBuffers = 0;
3423 void as_traceChannels(PAF_AST_Config *pC, int z)
3424 {
3425 PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3426 int i;
3428 // #ifdef THIS_IS_DSPA
3429 sSkipCount++;
3430 if (sSkipCount<1)
3431 return;
3432 sSkipCount = 0;
3433 // #endif
3435 #ifdef THIS_IS_DSPB
3436 if (!gReportBuffers)
3437 return;
3438 gReportBuffers = 0;
3439 #endif
3441 dp(NULL, "\n");
3442 for (i=0; i<PAF_MAXNUMCHAN; i++)
3443 {
3444 if (pAudioFrame->data.sample[i] != 0)
3445 {
3446 float *wp = (float*)pAudioFrame->data.sample[i];
3447 dp(NULL, "i: %d. p: 0x%x. %f, %f, %f, %f\n",
3448 i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
3449 }
3450 }
3451 }
3452 #endif