2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamOutProc.c ========
38 */
40 #include <string.h> // for memset
41 #include <xdc/runtime/Log.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/Memory.h>
44 #include <ti/sysbios/knl/Clock.h>
45 #include <ti/sysbios/knl/Task.h>
47 #include "paferr.h"
48 #include <acp_mds.h>
49 #include <pcm.h>
50 #include <pce.h>
51 #include <pafsio_ialg.h>
52 #include <stdasp.h>
53 #include <doberr.h>
54 #include "asperr.h"
56 #include "common.h"
57 #include "aspMsg_common.h"
58 #include "aspMsg_master.h"
59 #include "aspDecOpCircBuf_master.h"
60 #include "aspOutInitSync_master.h"
61 #include "audioStreamProc_common.h"
62 #include "audioStreamOutProc.h"
64 #include "pfp/pfp.h"
65 #include "pfp_app.h" /* contains all PFP ID's */
66 Int32 gNumPfpAsot1=0; // debug
68 // FL: debug
69 #include "evmc66x_gpio_dbg.h"
70 #include "dbgCapAf.h"
73 // -----------------------------------------------------------------------------
74 // Debugging Trace Control, local to this file.
75 //
76 #include "logp.h"
78 #define TRACE_TIME(a)
80 // Allow a developer to selectively enable tracing.
81 #define CURRENT_TRACE_MASK 0x07
83 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
84 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
85 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
87 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
88 #undef TRACE_TERSE0
89 #undef TRACE_TERSE1
90 #undef TRACE_TERSE2
91 #undef TRACE_TERSE3
92 #undef TRACE_TERSE4
93 #define TRACE_TERSE0(a)
94 #define TRACE_TERSE1(a,b)
95 #define TRACE_TERSE2(a,b,c)
96 #define TRACE_TERSE3(a,b,c,d)
97 #define TRACE_TERSE4(a,b,c,d,e)
98 #endif
100 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
101 #undef TRACE_GEN0
102 #undef TRACE_GEN1
103 #undef TRACE_GEN2
104 #undef TRACE_GEN3
105 #undef TRACE_GEN4
106 #define TRACE_GEN0(a)
107 #define TRACE_GEN1(a,b)
108 #define TRACE_GEN2(a,b,c)
109 #define TRACE_GEN3(a,b,c,d)
110 #define TRACE_GEN4(a,b,c,d,e)
111 #endif
113 #if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
114 #undef TRACE_VERBOSE0
115 #undef TRACE_VERBOSE1
116 #undef TRACE_VERBOSE2
117 #undef TRACE_VERBOSE3
118 #undef TRACE_VERBOSE4
119 #define TRACE_VERBOSE0(a)
120 #define TRACE_VERBOSE1(a,b)
121 #define TRACE_VERBOSE2(a,b,c)
122 #define TRACE_VERBOSE3(a,b,c,d)
123 #define TRACE_VERBOSE4(a,b,c,d,e)
124 #endif
126 // .............................................................................
128 //
129 // Audio Stream Definitions
130 //
132 //
133 // Audio Stream Processing Definitions
134 //
135 #define aspLinkInit pQ->i_aspLinkInit
137 //
138 // Encoder Definitions
139 //
140 #define encLinkInit pQ->i_encLinkInit
142 //
143 // Output Definitions
144 //
145 #define outLinkInit pP->i_outLinkInit
147 /* ---------------------------------------------------------------- */
148 /* Parameter macro definitions end here. */
149 /* ---------------------------------------------------------------- */
151 //
152 // Standardized Definitions
153 //
155 #define ENC_Handle PCE_Handle /* works for all: PCE */
157 #define __TASK_NAME__ "TaskAsop"
160 //
161 // Audio Stream Output Task definitions
162 //
164 // status codes
165 // Output FSM
166 #define ASOP_INITSYNC_NOTREADY ( 1 ) // ok, init-sync not ready
167 #define ASOP_SOK ( 0 ) // ok
168 #define ASOP_FORWARD_ERR ( -1 ) // forward (ASIT) error
169 #define ASOP_ENCRESET_ERR ( -2 ) // enc reset error
170 #define ASOP_DECINFO1_ERR ( -3 ) // dec info1 error
171 // Decode Processing
172 #define ASOP_DP_OUT_SIO_UPDATE ( 3 ) // new output selected
173 #define ASOP_DP_CB_DRAINED ( 2 ) // circular buffer drained
174 #define ASOP_DP_SOK ( 0 ) // ok
175 #define ASOP_DP_FORWARD_ERR ( -1 ) // forward (ASIT) error
176 #define ASOP_DP_DECINIT_ERR ( -2 ) // decode init error
177 #define ASOP_DP_DECSTREAM_ERR ( -3 ) // decode stream error
178 #define ASOP_DP_DECENC_ERR ( -4 ) // decode encode error
179 #define ASOP_DP_DECINFO2_ERR ( -5 ) // decode encode error
180 #define ASOP_DP_DECFINALTEST_ERR ( -6 ) // decode final error
184 /* Check if at least one output selected */
185 static Int checkOutSel(
186 const PAF_ASOT_Params *pP,
187 PAF_ASOT_Config *pAsotCfg,
188 Int *pOutSel
189 );
191 /* Check if at least one output sio changed */
192 static Int checkOutSio(
193 const PAF_ASOT_Params *pP,
194 PAF_ASOT_Config *pAsotCfg,
195 Int *pOutSioUpdate
196 );
198 // Initialize Output Processing state function
199 static Int PAF_ASOT_initOutProc(
200 const PAF_ASOT_Params *pP,
201 PAF_AST_Stream *xStr
202 );
204 // Initialize Output Processing state function
205 static Int PAF_ASOT_initSyncDecReset(
206 const PAF_ASOT_Params *pP,
207 const PAF_ASOT_Patchs *pQ,
208 PAF_ASOT_Config *pAsotCfg,
209 PAF_AudioFrame *pDecResetAf
210 );
212 // Purpose: ASOT Function for Output reset
213 static Int PAF_ASOT_outputReset(
214 const PAF_ASOT_Params *pP,
215 const PAF_ASOT_Patchs *pQ,
216 PAF_ASOT_Config *pAsotCfg
217 );
219 // Purpose: Init-Sync Dec Info1 state function.
220 // Performes Dec Info1 Init-Sync.
221 static Int PAF_ASOT_initSyncDecInfo1(
222 const PAF_ASOT_Params *pP,
223 const PAF_ASOT_Patchs *pQ,
224 PAF_ASOT_Config *pAsotCfg,
225 PAF_AudioFrame *pDecInfo1Af
226 );
228 // Purpose: ASOT function for ASP chain reset and ENC info
229 static Int PAF_ASOT_outputInfo1(
230 const PAF_ASOT_Params *pP,
231 const PAF_ASOT_Patchs *pQ,
232 PAF_ASOT_Config *pAsotCfg
233 );
235 // Purpose: Init-Sync Dec Decode1 state function.
236 // Performes Dec Decode1 Init-Sync.
237 static Int PAF_ASOT_initSyncDecDecode1(
238 const PAF_ASOT_Params *pP,
239 const PAF_ASOT_Patchs *pQ,
240 PAF_ASOT_Config *pAsotCfg
241 );
243 // Purpose: Init-Sync Re-Sync state function.
244 // Peformed Init-Sync using stored Dec Reset/Info1 AFs.
245 static Int PAF_ASOT_initSyncResync(
246 const PAF_ASOT_Params *pP,
247 const PAF_ASOT_Patchs *pQ,
248 PAF_ASOT_Config *pAsotCfg,
249 PAF_AudioFrame *pDecResetAf,
250 PAF_AudioFrame *pDecInfo1Af
251 );
253 #if 0
254 // Init-Sync update audio frame
255 static Int initSyncUpdateAf(
256 PAF_AudioFrame *dstAf,
257 PAF_AudioFrame *srcAf
258 );
259 #endif
261 // Reset audio frames
262 static Void resetAfs(
263 const PAF_ASOT_Params *pP,
264 PAF_AST_Stream *xStr
265 );
267 // Reset audio frame pointers to original values
268 static Void resetAfPointers(
269 const PAF_ASOT_Params *pP,
270 PAF_AST_Stream *xStr
271 );
273 // Reset audio frame meta data elements
274 static Void resetAfMetadata(
275 const PAF_ASOT_Params *pP,
276 PAF_AST_Stream *xStr
277 );
280 LINNO_DEFN(TaskAsop); /* Line number macros */
281 ERRNO_DEFN(TaskAsop); /* Error number macros */
283 // ASOT configuration
284 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
285 PAF_ASOT_Config gPAF_ASOT_config = {
286 NULL, // taskHandle
287 NULL, // acp
288 0,0,0, // CB drained flags (size DECODE_MAXN)
289 &gPAF_ASPM_config, // pAspmCfg
290 &gPAF_AST_config // pAstCfg
291 };
293 // Underflow threshold before circular buffer reset and return error to Top-Level FSM
294 #define DEC_OP_CB_RDAF_UND_THR ( 80 ) // FL: arbitrary setting
295 UInt32 gCbReadAfErr =0; // read circular buffer error count, not including underflows
296 UInt32 gDecOpCbRdAfUnd =0; // decoder output circular buffer underflow count
297 UInt32 gMaxDecOpCbRdAfUnd =0; // max (consecutive) decoder output circular buffer underflow count
298 UInt32 gMasterCbResetCnt =0; // master circular buffer reset count
300 // For writeDECCommandRestart
301 extern volatile UInt32 gCommandOutputTask_SYNC;
302 extern volatile UInt32 gCommandOutputTask_ACK;
304 // Global debug counters */
305 UInt32 gAsopTxSioReclaimCnt =0;
306 UInt32 gAsopInitOutProcCnt =0;
307 UInt32 gAsopInitSyncDecResetCnt =0;
308 UInt32 gAsopInitSyncDecInfo1Cnt =0;
309 UInt32 gAsopInitSyncDecDecode1Cnt =0;
310 UInt32 gAsopInitSyncResyncCnt =0;
311 UInt32 gAsopOutProcCnt =0;
312 UInt32 gAsopInitCnt =0;
313 UInt32 gAsopStreamCnt =0;
314 UInt32 gAsopEncodeCnt =0;
315 UInt32 gAsopFinalCnt =0;
316 UInt32 gAsopOutSioUpdateCnt =0;
317 UInt32 gAsopQuitCnt =0;
319 /*
320 * ======== taskAsopFxnInit ========
321 * Audio Stream Output Processing initialization function
322 */
323 Void taskAsopFxnInit(
324 const PAF_ASOT_Params *pP,
325 const PAF_ASOT_Patchs *pQ
326 )
327 {
328 PAF_ASOT_Config *pAsotCfg; /* ASOT configuration pointer */
329 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
330 Int as; /* Audio Stream Number (1, 2, etc.) */
331 Int z; /* input/encode/stream/decode/output counter */
332 Int i; /* phase */
333 Int zMS;
335 Log_info0("Enter taskAsopFxnInit()");
337 //
338 // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
339 //
340 if (!pP)
341 {
342 TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
343 LINNO_RPRT(TaskAsop, -1);
344 return;
345 }
347 if (!pQ)
348 {
349 TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
350 LINNO_RPRT(TaskAsop, -1);
351 return;
352 }
354 //
355 // Audio Stream Output Task Configuration (*pAsotCfg):
356 //
357 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
358 pAsotCfg->taskHandle = Task_self(); // set task handle
359 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
361 /* Obtain Audio Stream Number (1, 2, etc.) */
362 as = pAstCfg->as;
363 TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
365 //
366 // Initialize message log trace and line number reporting
367 //
368 for (z=STREAM1; z < STREAMN; z++)
369 {
370 TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
371 }
372 LINNO_RPRT(TaskAsop, -1);
374 //
375 // Determine stream index
376 //
377 zMS = pAstCfg->masterStr;
379 // Initialize as per parametrized phases:
380 //
381 // In standard form these are:
382 // - Malloc: Memory Allocation
383 // - Config: Configuration Initialization
384 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
385 // - Common: Common Memory Initialization
386 // - AlgKey: Dec/Enc chain to Array Initialization
387 // - Device: I/O Device Initialization
388 // - Unused: (available)
389 // - Unused: (available)
390 //
391 LINNO_RPRT(TaskAsop, -2);
392 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
393 {
394 Int linno;
395 if (pP->fxns->initPhase[i])
396 {
397 linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
398 if (linno)
399 {
400 LINNO_RPRT(TaskAsop, linno);
401 return;
402 }
403 }
404 else
405 {
406 TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
407 }
408 TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
409 LINNO_RPRT(TaskAsop, -i-3);
410 }
412 //
413 // End of Initialization -- display memory usage report.
414 //
415 if (pP->fxns->memStatusPrint)
416 {
417 pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
418 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
419 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
420 }
421 } /* taskAsopFxnInit */
424 /*
425 * ======== taskAsopFxn ========
426 * Audio Stream Output Processing task function
427 */
428 Void taskAsopFxn(
429 // Int betaPrimeValue, // FL: revisit
430 const PAF_ASOT_Params *pP,
431 const PAF_ASOT_Patchs *pQ
432 )
433 {
434 PAF_ASOT_Config *pAsotCfg; /* ASOT configuration pointer */
435 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
436 Int as; /* Audio Stream Number (1, 2, etc.) */
437 Int z; /* input/encode/stream/decode/output counter */
438 Int zMS;
439 Int errno; // error number
440 Int8 procSleep; // whether to sleep: 0: No, 1: Yes
441 Int8 procOutDevSel; // whether to perform output device selection: 0: No, 1:Yes
442 Int outSel; // whether output device selected
443 enum { INIT_OUT_PROC_STATE,
444 INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE,
445 INITSYNC_RESYNC_STATE,
446 OUT_PROC_STATE } state;
447 PAF_AudioFrame decResetAf;
448 PAF_AudioFrame decInfo1Af;
449 Int loopCount = 0; // used to stop trace to see startup behavior.
451 Log_info0("Enter taskAsopFxn()");
453 taskAsopFxnInit(pP, pQ); // initialization of output task
455 //
456 // Audio Stream Output Task Configuration (*pAsotCfg):
457 //
458 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
459 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
461 /* Obtain Audio Stream Number (1, 2, etc.) */
462 as = pAstCfg->as;
464 zMS = pAstCfg->masterStr;
466 //
467 // Main processing loop
468 //
469 for (z=STREAM1; z < STREAMN; z++)
470 {
471 TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
472 }
474 errno = 0; // init error indicator -- no error
475 procSleep = 1; // init sleep flag -- sleep
476 procOutDevSel = 1; // init device output selection flag -- perform output device selection
477 state = INIT_OUT_PROC_STATE; // init state
478 for (;;)
479 {
480 loopCount++;
481 TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", loopCount, errno);
483 //
484 // Check forward (ASIT) error here, TBD
485 //
487 // Even if we are not in error state, we check if writeDECCommandRestar issued or not
488 if (gCommandOutputTask_SYNC) {
489 TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Wait for the command deasserted");
490 gCommandOutputTask_ACK = 1;
491 while (gCommandOutputTask_SYNC) {
492 Task_sleep(1);
493 }
494 TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Startover the process");
495 procSleep = 1; // init sleep flag -- sleep
496 procOutDevSel = 1; // init device output selection flag -- perform output device selection
497 state = INIT_OUT_PROC_STATE; // init state -- starover
498 errno = ASOP_DP_FORWARD_ERR; // Override the error -- for flushing SIO output device
499 }
501 // any error forces idling of output
502 if (errno)
503 {
504 for (z=OUTPUT1; z < OUTPUTN; z++)
505 {
506 if (pAstCfg->xOut[z].hTxSio)
507 {
508 SIO_idle(pAstCfg->xOut[z].hTxSio);
509 }
510 }
512 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
513 ERRNO_RPRT(TaskAsop, errno);
514 }
516 if (procSleep == 1)
517 {
518 TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
519 Task_sleep(1);
520 }
522 if (procOutDevSel == 1)
523 {
524 // select output devices
525 TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
526 errno = pP->fxns->selectDevices(pP, pQ, pAsotCfg);
527 if (errno)
528 {
529 TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
531 procSleep = 1;
532 procOutDevSel = 1;
534 continue;
535 }
537 // if no output selected skip remaining processing
538 errno = checkOutSel(pP, pAsotCfg, &outSel);
539 if (errno < 0)
540 {
541 TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
543 procSleep = 1;
544 procOutDevSel = 1;
546 continue;
547 }
548 else if (!outSel)
549 {
550 TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);
552 procSleep = 1;
553 procOutDevSel = 1;
555 continue;
556 }
557 }
559 switch (state)
560 {
561 case INIT_OUT_PROC_STATE:
562 gAsopInitOutProcCnt++;
563 Log_info0("TaskAsop: state=INIT_OUT_PROC_STATE");
565 //
566 // Output Processing initialization.
567 //
568 errno = PAF_ASOT_initOutProc(pP, pAstCfg->xStr);
569 if (errno < 0)
570 {
571 state = INIT_OUT_PROC_STATE;
572 procSleep = 1;
573 procOutDevSel = 1;
574 }
575 else
576 {
577 state = INITSYNC_DEC_RESET_STATE;
578 procSleep = 0;
579 procOutDevSel = 0;
580 }
582 break;
584 case INITSYNC_DEC_RESET_STATE:
585 gAsopInitSyncDecResetCnt++;
586 Log_info0("TaskAsop: state=INITSYNC_DEC_RESET_STATE");
588 //
589 // Dec Reset Init-Sync.
590 //
592 // Perform Dec Reset init-sync.
593 // Latch Dec Reset AF.
594 errno = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, &decResetAf);
595 if (errno < 0)
596 {
597 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE errno=%d", errno);
599 // sync error -- start over
600 state = INIT_OUT_PROC_STATE;
601 procSleep = 1;
602 procOutDevSel = 1;
603 }
604 else if (errno == ASOP_INITSYNC_NOTREADY)
605 {
606 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE not sync'd errno=%d", errno);
608 // sync not ready -- try again
609 state = INITSYNC_DEC_RESET_STATE;
610 errno=0; // FL: temp hack
611 procSleep = 1;
612 procOutDevSel = 1;
613 }
614 else // errno==0
615 {
616 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE sync'd, errno=%d", errno);
618 // sync'd -- move on
619 state = INITSYNC_DEC_INFO1_STATE;
620 procSleep = 0;
621 procOutDevSel = 0;
622 }
624 break;
626 case INITSYNC_DEC_INFO1_STATE:
627 gAsopInitSyncDecInfo1Cnt++;
628 Log_info0("TaskAsop: state=INITSYNC_DEC_INFO1_STATE");
630 //
631 // Dec Info1 Init-Sync.
632 //
634 // Perform Dec Info1 init-sync.
635 // Latch Dec Info1 AF.
636 errno = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af);
637 if (errno < 0)
638 {
639 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE errno=%d", errno);
641 // sync error -- start over
642 state = INIT_OUT_PROC_STATE;
643 procSleep = 1;
644 procOutDevSel = 1;
645 }
646 else if (errno == ASOP_INITSYNC_NOTREADY)
647 {
648 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE not sync'd errno=%d", errno);
650 // sync not ready -- try again
651 state = INITSYNC_DEC_INFO1_STATE;
652 errno=0; // FL: temp hack
653 procSleep = 1;
654 procOutDevSel = 0;
655 }
656 else // errno = 0
657 {
658 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE sync'd errno=%d", errno);
660 // sync'd -- move on
661 state = INITSYNC_DEC_DECODE1_STATE;
662 procSleep = 0;
663 procOutDevSel = 0;
664 }
666 break;
668 case INITSYNC_DEC_DECODE1_STATE:
669 gAsopInitSyncDecDecode1Cnt++;
670 Log_info0("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE");
672 //
673 // Dec Info1 Init-Sync.
674 //
676 // Perform Dec Info1 init-sync.
677 // Latch Dec Info1 AF.
678 errno = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg);
679 if (errno < 0)
680 {
681 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE errno=%d", errno);
683 // sync error -- start over
684 state = INIT_OUT_PROC_STATE;
685 procSleep = 1;
686 procOutDevSel = 1;
687 }
688 else if (errno == ASOP_INITSYNC_NOTREADY)
689 {
690 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE not sync'd errno=%d", errno);
692 // sync not ready -- try again
693 state = INITSYNC_DEC_DECODE1_STATE;
694 errno=0; // FL: temp hack
695 procSleep = 1;
696 procOutDevSel = 0;
697 }
698 else // errno = 0
699 {
700 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE sync'd errno=%d", errno);
702 // sync'd -- move on
703 state = OUT_PROC_STATE;
704 procSleep = 0;
705 procOutDevSel = 0;
706 }
708 break;
710 case INITSYNC_RESYNC_STATE:
711 gAsopInitSyncResyncCnt++;
712 Log_info0("TaskAsop: state=INITSYNC_RESYNC_STATE");
714 //
715 // Re-Sync.
716 // Use stored AF info from init-sync.
717 // This is done in case of local error.
718 //
720 // Perform Dec Info1 init-sync.
721 errno = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf,
722 &decInfo1Af);
723 if (errno < 0)
724 {
725 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE errno=%d", errno);
727 // sync error -- start over
728 state = INIT_OUT_PROC_STATE;
729 procSleep = 1;
730 procOutDevSel = 1;
731 }
732 else
733 {
734 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE sync'd errno=%d", errno);
736 // re-sync'd -- move on
737 state = OUT_PROC_STATE;
738 procSleep = 0;
739 procOutDevSel = 0;
740 }
742 break;
744 case OUT_PROC_STATE:
745 gAsopOutProcCnt++;
746 Log_info0("TaskAsop: state=OUT_PROC_STATE");
748 //
749 // Output Processing.
750 //
752 TRACE_VERBOSE0("TaskAsop: calling decodeProcessing.");
753 errno = pP->fxns->decodeProcessing(pP, pQ, pAsotCfg);
754 if (errno < 0)
755 {
756 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
758 //
759 // Output Processing exit, due to error
760 //
762 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
763 if (errno == ASOP_DP_FORWARD_ERR)
764 {
765 // forward (ASIT) error -- start over
766 state = INIT_OUT_PROC_STATE;
767 procSleep = 1;
768 procOutDevSel = 1;
769 }
770 else
771 {
772 // local (ASOT) error
773 state = INITSYNC_RESYNC_STATE;
774 procSleep = 1;
775 procOutDevSel = 0; // disallow device re-select if local error during output processing
776 }
777 }
778 else if (errno > 0)
779 {
780 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
782 //
783 // Output Processing exit, not due to error
784 //
786 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
787 if (errno == ASOP_DP_OUT_SIO_UPDATE)
788 {
789 // skip re-sync
790 // resume output processing after new output selected
791 state = OUT_PROC_STATE;
792 procSleep = 1;
793 procOutDevSel = 1;
794 }
795 }
796 else
797 {
798 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
800 //
801 // Output Processing exit, normal
802 //
804 TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
806 // no error returned if CB drained
807 // (i.e. CB drained is normal behavior)
808 state = INIT_OUT_PROC_STATE;
809 procSleep = 1;
810 procOutDevSel = 1;
811 }
813 break;
815 default: // unknown state
816 TRACE_TERSE2("TaskAsop: AS%d: state: unknown, 0x%x", as+zMS, state);
817 break;
818 }
819 } // End of main processing loop for (;;)
821 //Log_info0("Exit taskAsopFxn()");
822 }
824 // -----------------------------------------------------------------------------
825 // AST Initialization Function - Memory Allocation
826 //
827 // Name: PAF_ASOT_initPhaseMalloc
828 // Purpose: Audio Stream Output Task Function for initialization of data pointers
829 // by allocation of memory.
830 // From: audioStream1Task or equivalent
831 // Uses: See code.
832 // States: x
833 // Return: 0 on success.
834 // Source code line number on MEM_calloc failure.
835 // Trace: Message Log "trace" in Debug Project Configuration reports:
836 // * State information as per parent.
837 // * Memory allocation errors.
838 //
840 Int
841 PAF_ASOT_initPhaseMalloc (
842 const PAF_ASOT_Params *pP,
843 const PAF_ASOT_Patchs *pQ,
844 PAF_ASOT_Config *pAsotCfg
845 )
846 {
847 PAF_AST_Config *pAstCfg;
848 Int as; /* Audio Stream Number (1, 2, etc.) */
849 Int zMS;
850 Error_Block eb;
851 //Int i;
853 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
854 as = pAstCfg->as;
855 zMS = pAstCfg->masterStr;
857 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
859 // Initialize error block
860 Error_init(&eb);
862 /* Stream memory */
863 if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
864 {
865 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
866 SW_BREAKPOINT;
867 return __LINE__;
868 }
869 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
870 STREAMN * sizeof (*pAstCfg->xStr),
871 HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
873 {
874 Int z; /* stream counter */
876 PAF_AudioFrame *fBuf;
878 if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
879 {
880 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
881 SW_BREAKPOINT;
882 return __LINE__;
883 }
884 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
885 STREAMS * sizeof (*fBuf),
886 HEAP_ID_INTERNAL, (IArg)fBuf);
888 for (z=STREAM1; z < STREAMN; z++)
889 {
890 pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
891 TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
892 }
893 }
895 /* Encode memory */
896 if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
897 {
898 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
899 SW_BREAKPOINT;
900 return __LINE__;
901 }
902 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
903 ENCODEN * sizeof (*pAstCfg->xEnc),
904 HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
906 /* Output memory */
907 if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
908 {
909 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
910 SW_BREAKPOINT;
911 return __LINE__;
912 }
913 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
914 OUTPUTN * sizeof (*pAstCfg->xOut),
915 HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
917 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
918 return 0;
919 } //PAF_ASOT_initPhaseMalloc
921 // -----------------------------------------------------------------------------
922 // ASOT Initialization Function - Memory Initialization from Configuration
923 //
924 // Name: PAF_ASOT_initPhaseConfig
925 // Purpose: Audio Stream Output Task Function for initialization of data values
926 // from parameters.
927 // From: audioStream1Task or equivalent
928 // Uses: See code.
929 // States: x
930 // Return: 0 on success.
931 // Other as per initFrame0 and initFrame1.
932 // Trace: Message Log "trace" in Debug Project Configuration reports:
933 // * State information as per parent.
934 //
935 Int
936 PAF_ASOT_initPhaseConfig(
937 const PAF_ASOT_Params *pP,
938 const PAF_ASOT_Patchs *pQ,
939 PAF_ASOT_Config *pAsotCfg
940 )
941 {
942 PAF_AST_Config *pAstCfg;
943 Int as; /* Audio Stream Number (1, 2, etc.) */
944 Int z; /* input/encode/stream/decode/output counter */
945 Int zMS;
947 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
948 as = pAstCfg->as;
949 zMS = pAstCfg->masterStr;
951 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
953 //
954 // Unspecified elements have been initialized to zero during alloc
955 //
957 for (z=STREAM1; z < STREAMN; z++)
958 {
959 Int linno;
960 if (linno = pP->fxns->initFrame0(pP, pQ, pAsotCfg, z))
961 {
962 return linno;
963 }
964 if (linno = pP->fxns->initFrame1(pP, pQ, pAsotCfg, z, -1))
965 {
966 return linno;
967 }
968 }
970 for (z=ENCODE1; z < ENCODEN; z++)
971 {
972 Int zO = pP->outputsFromEncodes[z];
973 Int zS = pP->streamsFromEncodes[z];
974 pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
975 pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
976 pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
977 pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
978 pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
979 pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
980 pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
981 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
982 }
984 for (z=OUTPUT1; z < OUTPUTN; z++)
985 {
986 pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
987 }
989 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
990 return 0;
991 } //PAF_ASOT_initPhaseConfig
993 // -----------------------------------------------------------------------------
994 // ASOT Initialization Function - ACP Algorithm Instantiation
995 //
996 // Name: PAF_ASOT_initPhaseAcpAlg
997 // Purpose: Audio Stream Input Task Function for initialization of ACP by
998 // instantiation of the algorithm.
999 // From: audioStream1Task or equivalent
1000 // Uses: See code.
1001 // States: x
1002 // Return: 0 on success.
1003 // Source code line number on ACP Algorithm creation failure.
1004 // Trace: Message Log "trace" in Debug Project Configuration reports:
1005 // * State information as per parent.
1006 // * Memory allocation errors.
1007 //
1008 Int
1009 PAF_ASOT_initPhaseAcpAlg(
1010 const PAF_ASOT_Params *pP,
1011 const PAF_ASOT_Patchs *pQ,
1012 PAF_ASOT_Config *pAsotCfg
1013 )
1014 {
1015 PAF_AST_Config *pAstCfg;
1016 Int as; /* Audio Stream Number (1, 2, etc.) */
1017 Int z; /* input/encode/stream/decode/output counter */
1018 Int betaPrimeOffset;
1019 ACP_Handle acp;
1020 Int zMS;
1021 Int zS, zX;
1023 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1024 as = pAstCfg->as;
1025 zMS = pAstCfg->masterStr;
1027 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1029 ACP_MDS_init();
1031 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
1032 {
1033 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1034 return __LINE__;
1035 }
1036 pAsotCfg->acp = acp;
1038 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1039 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1041 for (z=ENCODE1; z < ENCODEN; z++)
1042 {
1043 zS = pP->streamsFromEncodes[z];
1044 acp->fxns->attach(acp, ACP_SERIES_STD,
1045 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
1046 (IALG_Status *)&pAstCfg->xEnc[z].encodeStatus);
1047 acp->fxns->attach(acp, ACP_SERIES_STD,
1048 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
1049 (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
1050 /* Ignore errors, not reported. */
1051 }
1053 for (z=OUTPUT1; z < OUTPUTN; z++)
1054 {
1055 zS = z;
1056 for (zX = ENCODE1; zX < ENCODEN; zX++)
1057 {
1058 if (pP->outputsFromEncodes[zX] == z)
1059 {
1060 zS = pP->streamsFromEncodes[zX];
1061 break;
1062 }
1063 }
1064 acp->fxns->attach(acp, ACP_SERIES_STD,
1065 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
1066 (IALG_Status *)&pAstCfg->xOut[z].outBufStatus);
1067 /* Ignore errors, not reported. */
1068 }
1070 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1072 return 0;
1073 } //PAF_ASOT_initPhaseAcpAlg
1075 // -----------------------------------------------------------------------------
1076 // ASOT Initialization Function - Common Memory
1077 //
1078 // Name: PAF_ASOT_initPhaseCommon
1079 // Purpose: Audio Stream Output Task Function for allocation of common memory.
1080 // From: audioStream1Task or equivalent
1081 // Uses: See code.
1082 // States: x
1083 // Return: 0 on success.
1084 // Source code line number on PAF_ALG_alloc failure.
1085 // Source code line number on PAF_ALG_mallocMemory failure.
1086 // Source code line number on Decode Chain initialization failure.
1087 // Source code line number on ASP Chain initialization failure.
1088 // Source code line number on Encode Chain initialization failure.
1089 // Trace: Message Log "trace" in Debug Project Configuration reports:
1090 // * State information as per parent.
1091 // * Memory allocation errors.
1092 //
1093 Int
1094 PAF_ASOT_initPhaseCommon(
1095 const PAF_ASOT_Params *pP,
1096 const PAF_ASOT_Patchs *pQ,
1097 PAF_ASOT_Config *pAsotCfg
1098 )
1099 {
1100 PAF_AST_Config *pAstCfg;
1101 Int as; /* Audio Stream Number (1, 2, etc.) */
1102 Int z; /* stream counter */
1103 Int g; /* gear */
1104 ACP_Handle acp;
1105 PAF_IALG_Config pafAlgConfig;
1106 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1108 acp = pAsotCfg->acp;
1109 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1110 as = pAstCfg->as;
1112 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
1114 //
1115 // Determine memory needs and instantiate algorithms across audio streams
1116 //
1117 TRACE_TERSE0("PAF_ASOT_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_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1124 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1125 HEAP_CLEAR);
1127 if (pP->fxns->headerPrint)
1128 {
1129 pP->fxns->headerPrint();
1130 }
1132 for (z = STREAM1; z < STREAMN; z++)
1133 {
1134 //Int zD, zE, zX;
1135 Int zE, zX;
1137 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1139 //
1140 // Determine common memory needs for:
1141 // (1) ASP Algorithms
1142 // (2) Encode Algorithms
1143 // (3) Logical Output drivers
1144 //
1145 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1147 zE = -1;
1148 for (zX = ENCODE1; zX < ENCODEN; zX++)
1149 {
1150 if (pP->streamsFromEncodes[zX] == z)
1151 {
1152 zE = zX;
1153 break;
1154 }
1155 }
1157 TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
1158 if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z]))
1159 {
1160 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1161 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1162 SW_BREAKPOINT;
1163 return __LINE__;
1164 }
1165 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1166 if (pP->fxns->allocPrint)
1167 {
1168 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1169 }
1171 if (zE >= 0)
1172 {
1173 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
1174 if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z]))
1175 {
1176 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1177 SW_BREAKPOINT;
1178 return __LINE__;
1179 }
1180 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1181 if (pP->fxns->allocPrint)
1182 {
1183 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
1184 }
1185 }
1187 //
1188 // Determine common memory needs of Logical IO drivers
1189 //
1191 if (OUTPUT1 <= z && z < OUTPUTN)
1192 {
1193 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
1194 if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
1195 {
1196 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
1197 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1198 SW_BREAKPOINT;
1199 return __LINE__;
1200 }
1201 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1202 if (pP->fxns->allocPrint)
1203 {
1204 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
1205 }
1206 }
1207 }
1208 {
1209 // Changes made to share scratch between zones
1210 // Assume maximum 3 zones and scratch common memory is at offset 0;
1211 int max=0;
1212 for (z=STREAM1; z<STREAMN; z++)
1213 {
1214 if (max < common[z][0].size)
1215 {
1216 max = common[z][0].size;
1217 }
1218 }
1219 common[STREAM1][0].size=max;
1220 for (z=STREAM1+1; z<STREAMN; z++)
1221 {
1222 common[z][0].size = 0;
1223 }
1224 }
1226 //
1227 // Allocate common memory for:
1228 // (1) ASP Algorithms
1229 // (2) Encode Algorithms
1230 // (3) Logical Output drivers
1231 //
1232 for (z = STREAM1; z < STREAMN; z++)
1233 {
1234 //Int zD, zE, zX;
1235 Int zE, zX;
1237 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1238 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1239 {
1240 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
1241 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1242 SW_BREAKPOINT;
1243 return __LINE__;
1244 }
1245 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1246 // share zone0 scratch with all zones
1247 common[z][0].base = common[0][0].base;
1248 if (pP->fxns->commonPrint)
1249 {
1250 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1251 }
1253 zE = -1;
1254 for (zX = ENCODE1; zX < ENCODEN; zX++)
1255 {
1256 if (pP->streamsFromEncodes[zX] == z)
1257 {
1258 zE = zX;
1259 break;
1260 }
1261 }
1263 pAstCfg->xStr[z].aspChain[0] = NULL;
1264 for (g=0; g < GEARS; g++)
1265 {
1266 PAF_ASP_Chain *chain;
1267 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
1268 chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
1269 HEAP_INTERNAL, as+z, acp, &trace,
1270 aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1271 if (!chain)
1272 {
1273 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1274 return __LINE__;
1275 }
1276 else
1277 {
1278 pAstCfg->xStr[z].aspChain[g] = chain;
1279 }
1280 }
1282 if (zE >= 0)
1283 {
1284 PAF_ASP_Chain *chain;
1285 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
1286 chain = PAF_ASP_chainInit(&pAstCfg->xEnc[zE].encChainData, pP->pChainFxns,
1287 HEAP_INTERNAL, as+z, acp, &trace,
1288 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
1289 if (!chain)
1290 {
1291 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
1292 return __LINE__;
1293 }
1294 }
1296 //
1297 // Allocate non-common memories for Logical IO drivers
1298 // Since these structures are used at run-time we allocate from external memory
1299 if (OUTPUT1 <= z && z < OUTPUTN)
1300 {
1301 PAF_ASP_Chain *chain;
1302 TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
1303 as+z, z);
1304 chain = PAF_ASP_chainInit (&pAstCfg->xOut[z].outChainData, pP->pChainFxns,
1305 HEAP_EXTERNAL, as+z, acp, &trace,
1306 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
1307 if (!chain)
1308 {
1309 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
1310 return __LINE__;
1311 }
1312 }
1313 }
1314 TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
1316 return 0;
1317 } //PAF_ASOT_initPhaseCommon
1319 // -----------------------------------------------------------------------------
1320 // ASOT Initialization Function - Algorithm Keys
1321 //
1322 // Name: PAF_ASOT_initPhaseAlgKey
1323 // Purpose: Audio Stream Output Task Function for initialization of data values
1324 // from parameters for Algorithm Keys.
1325 // From: audioStream1Task or equivalent
1326 // Uses: See code.
1327 // States: x
1328 // Return: 0.
1329 // Trace: Message Log "trace" in Debug Project Configuration reports:
1330 // * State information as per parent.
1331 //
1332 // .............................................................................
1333 Int
1334 PAF_ASOT_initPhaseAlgKey(
1335 const PAF_ASOT_Params *pP,
1336 const PAF_ASOT_Patchs *pQ,
1337 PAF_ASOT_Config *pAsotCfg
1338 )
1339 {
1340 PAF_AST_Config *pAstCfg;
1341 Int as; /* Audio Stream Number (1, 2, etc.) */
1342 Int z; /* decode/encode counter */
1343 Int s; /* key number */
1344 PAF_ASP_Link *that;
1346 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1347 as = pAstCfg->as;
1348 (void)as; // clear compiler warning in case not used with tracing disabled
1350 TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1352 for (z=ENCODE1; z < ENCODEN; z++)
1353 {
1354 for (s=0; s < pP->pEncAlgKey->length; s++)
1355 {
1356 if ((pP->pEncAlgKey->code[s].full != 0) &&
1357 (that = PAF_ASP_chainFind(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
1358 {
1359 pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
1360 }
1361 /* Cast in interface, for now --Kurt */
1362 else
1363 {
1364 pAstCfg->xEnc[z].encAlg[s] = NULL;
1365 }
1366 }
1367 }
1369 return 0;
1370 } //PAF_ASOT_initPhaseAlgKey
1372 // -----------------------------------------------------------------------------
1373 // ASOT Initialization Function - I/O Devices
1374 //
1375 // Name: PAF_ASOT_initPhaseDevice
1376 // Purpose: Audio Stream Output Task Function for initialization of I/O Devices.
1377 // From: audioStream1Task or equivalent
1378 // Uses: See code.
1379 // States: x
1380 // Return: 0 on success.
1381 // Source code line number on device allocation failure.
1382 // Trace: Message Log "trace" in Debug Project Configuration reports:
1383 // * State information as per parent.
1384 // * Memory allocation errors.
1385 //
1386 Int
1387 PAF_ASOT_initPhaseDevice(
1388 const PAF_ASOT_Params *pP,
1389 const PAF_ASOT_Patchs *pQ,
1390 PAF_ASOT_Config *pAsotCfg
1391 )
1392 {
1393 PAF_AST_Config *pAstCfg;
1394 Int as; /* Audio Stream Number (1, 2, etc.) */
1395 Int z; /* input/output counter */
1396 PAF_SIO_IALG_Obj *pObj;
1397 PAF_SIO_IALG_Config *pAlgConfig;
1398 PAF_IALG_Config pafAlgConfig;
1400 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1401 as = pAstCfg->as;
1402 (void)as; // clear compiler warning in case not used with tracing disabled
1404 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1406 if(pP->fxns->bufMemPrint)
1407 {
1408 PAF_ALG_setup (&pafAlgConfig,
1409 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1410 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1411 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1412 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1413 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1414 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1415 HEAP_CLEAR);
1416 TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1417 }
1419 for (z=OUTPUT1; z < OUTPUTN; z++)
1420 {
1421 PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
1423 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
1424 pAlgConfig = &pObj->config;
1426 pAstCfg->xOut[z].hTxSio = NULL;
1427 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1428 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1429 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1430 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1431 pConfig->sizeofElement = 3;
1432 pConfig->precision = 24;
1433 if(pP->fxns->bufMemPrint)
1434 {
1435 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
1436 }
1437 }
1438 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1440 return 0;
1441 } //PAF_ASOT_initPhaseDevice
1443 // -----------------------------------------------------------------------------
1444 // ASOT Initialization Function Helper - Initialization of Audio Frame
1445 //
1446 // Name: PAF_ASOT_initFrame0
1447 // Purpose: Audio Stream Output Task Function for initialization of the Audio
1448 // Frame(s) by memory allocation and loading of data pointers
1449 // and values.
1450 // From: AST Parameter Function -> decodeInfo
1451 // Uses: See code.
1452 // States: x
1453 // Return: 0 on success.
1454 // Source code line number on MEM_calloc failure.
1455 // Source code line number on unsupported option.
1456 // Trace: Message Log "trace" in Debug Project Configuration reports:
1457 // * Memory allocation errors.
1458 // * Unsupported option errors.
1459 //
1461 // MID 314
1462 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
1463 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
1465 Int
1466 PAF_ASOT_initFrame0(
1467 const PAF_ASOT_Params *pP,
1468 const PAF_ASOT_Patchs *pQ,
1469 PAF_ASOT_Config *pAsotCfg,
1470 Int z
1471 )
1472 {
1473 PAF_AST_Config *pAstCfg;
1474 Int as; /* Audio Stream Number (1, 2, etc.) */
1475 Int ch;
1476 //Int aLen;
1477 Int aLen_int=0,aLen_ext=0;
1478 Int aSize = sizeof(PAF_AudioData);
1479 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1480 Int maxFrameLength = pP->maxFramelength;
1481 Int zX;
1482 PAF_AudioData *aBuf_int=NULL;
1483 PAF_AudioData *aBuf_ext=NULL;
1484 XDAS_UInt8 *metadataBuf;
1485 char i;
1486 Error_Block eb;
1488 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1489 as = pAstCfg->as;
1491 // Initialize error block
1492 Error_init(&eb);
1494 // Compute maximum framelength (needed for ARC support)
1495 maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
1496 //aLen = numchan[z] * maxFrameLength;
1497 for (i=0; i < numchan[z]; i++)
1498 {
1499 if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1500 {
1501 aLen_int += maxFrameLength;
1502 }
1503 else
1504 {
1505 aLen_ext += maxFrameLength;
1506 }
1507 }
1509 //
1510 // Initialize audio frame elements directly
1511 //
1512 pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
1513 pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
1514 /// pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
1515 pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
1516 pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
1517 pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
1518 pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1520 //
1521 // Allocate memory for and initialize pointers to audio data buffers
1522 //
1523 // The NUMCHANMASK is used to identify the channels for which data
1524 // buffers can be allocated. Using this mask and switch statement
1525 // rather than some other construct allows efficient code generation,
1526 // providing just the code necessary (with significant savings).
1527 //
1528 if (pP->fxns->bufMemPrint)
1529 {
1530 pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
1531 pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
1532 }
1534 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1536 if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
1537 {
1538 if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb))) //Qin: Add start offset
1539 {
1540 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1541 TRACE_TERSE2(" maxFrameLength: %d. aLen_int*aSize: %d", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize);
1542 SW_BREAKPOINT;
1543 return __LINE__;
1544 }
1545 }
1547 if (aLen_ext*aSize!=0)
1548 {
1549 if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb)))//Qin: Add start offset
1550 {
1551 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1552 TRACE_TERSE2(" maxFrameLength: %d. aLen_ext*aSize: %d", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize);
1553 SW_BREAKPOINT;
1554 return __LINE__;
1555 }
1556 }
1558 TRACE_TERSE3(" maxFrameLength: %d. aLen_int*aSize: %d. aBuf_int: 0x%x", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_int);
1559 TRACE_TERSE3(" maxFrameLength: %d. aLen_ext*aSize: %d. aBuf_ext: 0x%x", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_ext);
1561 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1562 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1563 {
1564 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1565 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1566 SW_BREAKPOINT;
1567 return __LINE__;
1568 }
1570 {
1571 Int i;
1573 #pragma UNROLL(1)
1574 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1575 {
1576 pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
1577 }
1578 }
1580 // MID 314
1581 if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1582 {
1583 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
1584 return __LINE__;
1585 }
1586 else
1587 {
1588 Int j = 0;
1589 Int k = 0;
1590 TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1591 for(i=0;i<numchan[z];i++)
1592 {
1593 char chan = AFChanPtrMap[numchan[z]][i];
1594 if(chan != -1)
1595 {
1596 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1597 {
1598 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
1599 j++;
1600 }
1601 else
1602 {
1603 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1604 k++;
1605 }
1606 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1607 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
1608 }
1609 }
1610 }
1612 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1613 {
1614 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1615 {
1616 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
1617 }
1618 }
1620 //
1621 // Initialize meta data elements
1622 //
1623 pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1624 pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1625 pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1626 pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1627 pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1628 for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1629 {
1630 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1631 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1632 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1633 }
1635 //
1636 // Initialize decoder elements directly
1637 //
1639 for (zX = DECODE1; zX < DECODEN; zX++)
1640 {
1641 if (pP->streamsFromDecodes[zX] == z)
1642 {
1643 #ifdef NOAUDIOSHARE
1644 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1645 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1646 #else /* NOAUDIOSHARE */
1647 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1648 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1649 #endif /* NOAUDIOSHARE */
1650 }
1651 }
1653 return 0;
1654 } //PAF_ASOT_initFrame0
1656 // -----------------------------------------------------------------------------
1657 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1658 // AST Decoding Function - Reinitialization of Audio Frame
1659 //
1660 // Name: PAF_ASOT_initFrame1
1661 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1662 // zation of the Audio Frame(s) by loading of data values of a
1663 // time-varying nature.
1664 // From: audioStream1Task or equivalent
1665 // AST Parameter Function -> decodeInfo
1666 // AST Parameter Function -> decodeDecode
1667 // Uses: See code.
1668 // States: x
1669 // Return: 0.
1670 // Trace: None.
1671 //
1672 Int
1673 PAF_ASOT_initFrame1(
1674 const PAF_ASOT_Params *pP,
1675 const PAF_ASOT_Patchs *pQ,
1676 PAF_ASOT_Config *pAsotCfg,
1677 Int z,
1678 Int apply
1679 )
1680 {
1681 PAF_AST_Config *pAstCfg;
1683 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1685 //
1686 // Reinitialize audio frame elements:
1687 //
1688 // Channel Configurations during sys init = Unknown
1689 // " " during info or decode = None
1690 //
1691 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1692 //
1694 if (apply < 0)
1695 {
1696 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1697 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1698 }
1699 else
1700 {
1701 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1702 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1703 }
1705 if (apply < 1)
1706 {
1707 pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1708 pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
1709 }
1711 return 0;
1712 } //PAF_ASOT_initFrame1
1714 // -----------------------------------------------------------------------------
1715 // ASOT Selection Function - Output Device Selection
1716 //
1717 // Name: PAF_ASOT_selectDevices
1718 // Purpose: Audio Stream Output Task Function for selecting the devices used
1719 // for output.
1720 // From: audioStream1Task or equivalent
1721 // Uses: See code.
1722 // States: x
1723 // Return: Error number in standard form (0 on success).
1724 // Trace: Message Log "trace" in Debug Project Configuration reports:
1725 // * State information as per parent.
1726 //
1727 Int
1728 PAF_ASOT_selectDevices(
1729 const PAF_ASOT_Params *pP,
1730 const PAF_ASOT_Patchs *pQ,
1731 PAF_ASOT_Config *pAsotCfg
1732 )
1733 {
1734 PAF_AST_Config *pAstCfg;
1735 Int as; /* Audio Stream Number (1, 2, etc.) */
1736 Int z; /* input/output counter */
1737 Int errno = 0; /* error number */
1738 Int errme; /* error number, local */
1739 Int device;
1741 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1742 as = pAstCfg->as;
1743 (void)as; // clear compiler warning in case not used with tracing disabled
1745 // Select output devices
1746 for (z=OUTPUT1; z < OUTPUTN; z++)
1747 {
1748 if ((device = pAstCfg->xOut[z].outBufStatus.sioSelect) >= 0)
1749 {
1750 TRACE_VERBOSE2("PAF_ASOT_selectDevices: AS%d: output device %d selecting ...", as+z, device);
1752 /* check for valid index into device array */
1753 if (device >= pQ->devout->n)
1754 {
1755 device = 0; /* treat as device None */
1756 }
1758 errme = pP->fxns->deviceSelect(&pAstCfg->xOut[z].hTxSio, SIO_OUTPUT,
1759 HEAP_ID_OUTBUF, (Ptr)pQ->devout->x[device]);
1760 if (errme)
1761 {
1762 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1763 if (!errno)
1764 {
1765 errno = ASPERR_DEVOUT + errme;
1766 }
1767 pAstCfg->xOut[z].outBufStatus.sioSelect = 0x80;
1768 }
1769 else
1770 {
1771 Int zE;
1773 pAstCfg->xOut[z].outBufStatus.sioSelect = device | 0x80;
1774 // register outBufStatus and encodeStatus pointers with output devices
1775 // This enables proper IEC encapsulation.
1776 if (pAstCfg->xOut[z].hTxSio)
1777 {
1778 // set max # of output buffers (use override if necessary)
1779 if (pAstCfg->xOut[z].outBufStatus.maxNumBufOverride == 0)
1780 {
1781 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1782 (Arg)pP->poutNumBufMap[z]->maxNumBuf);
1783 }
1784 else
1785 {
1786 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1787 (Arg)pAstCfg->xOut[z].outBufStatus.maxNumBufOverride);
1788 }
1790 // register PAF_SIO_IALG object address
1791 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_IALGADDR,
1792 (Arg)pAstCfg->xOut[z].outChainData.head->alg);
1793 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_BUFSTATUSADDR,
1794 (Arg)&pAstCfg->xOut[z].outBufStatus);
1795 for (zE=ENCODE1; zE < ENCODEN; zE++)
1796 {
1797 if (pP->outputsFromEncodes[zE] == z)
1798 {
1799 SIO_ctrl(pAstCfg->xOut[z].hTxSio,
1800 PAF_SIO_CONTROL_SET_ENCSTATUSADDR,
1801 (Arg)&pAstCfg->xEnc[zE].encodeStatus);
1802 break;
1803 }
1804 }
1805 }
1806 }
1807 }
1809 /* No need to start-clocks here, since only selecting the device. */
1810 #if 0
1811 // if device selected and valid then enable stat tracking if
1812 // required and start clocking
1813 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
1814 {
1815 TRACE_VERBOSE0("PAF_ASOT_selectDevices: start SIO clocks");
1816 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
1817 if (errme)
1818 {
1819 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1820 SIO_idle(pAstCfg->xOut[z].hTxSio);
1821 if (!errno)
1822 {
1823 errno = ASPERR_DEVOUT + errme;
1824 }
1825 }
1826 }
1827 #endif
1828 }
1830 return errno;
1831 } //PAF_ASOT_selectDevices
1834 // -----------------------------------------------------------------------------
1835 // ASOT Processing Function - Decode Processing
1836 //
1837 // Name: PAF_ASOT_decodeProcessing
1838 // Purpose: Audio Stream Output Task Function for processing audio data.
1839 //
1840 Int
1841 PAF_ASOT_decodeProcessing(
1842 const PAF_ASOT_Params *pP,
1843 const PAF_ASOT_Patchs *pQ,
1844 PAF_ASOT_Config *pAsotCfg
1845 )
1846 {
1847 PAF_AST_Config *pAstCfg;
1848 Int errno; /* error number */
1849 Int getVal;
1850 enum { INIT, STREAM, ENCODE, FINAL, QUIT, OUT_SIO_UPDATE } state;
1851 state = INIT;
1852 errno = 0; /* error number */
1853 Int frame; // (***) FL: formerly -- decoder input frame count
1854 Int block; // decoder output block count / input frame
1855 Int outSioUpdate;
1857 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1859 for (;;)
1860 {
1861 //
1862 // Check forward (ASIT) error here, TBD
1863 //
1865 // If writeDECCommandRestart issued, force exit the statemachine
1866 if (gCommandOutputTask_SYNC) {
1867 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: writeDECCommandRestart issued in state=0x%x ... exiting core loop", state);
1868 errno = ASOP_DP_FORWARD_ERR;
1869 break;
1870 }
1872 // Check if any change in output SIO, e.g. from Output shortcut.
1873 // Changes will break FSM and allow Output reconfiguration.
1874 errno = checkOutSio(pP, pAsotCfg, &outSioUpdate);
1875 if (errno < 0)
1876 {
1877 TRACE_TERSE1("PAF_ASOT_decodeProcessing: checkOutSio returned errno = 0x%04x", errno);
1878 break;
1879 }
1880 else if (outSioUpdate)
1881 {
1882 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Change in Output SIO selection");
1883 state = OUT_SIO_UPDATE;
1884 }
1886 // Process commands (encode)
1887 getVal = pP->fxns->encodeCommand(pP, pQ, pAsotCfg);
1888 if (getVal)
1889 {
1890 /* ignore */;
1891 }
1893 // Process state (decode)
1894 switch (state)
1895 {
1896 case INIT: // initial state
1897 gAsopInitCnt++;
1898 Log_info0("TaskAsop: state=INIT");
1900 frame = 0;
1901 block = 0;
1903 #if 0 // FL: moved to PAF_ASOT_initOutProc()
1904 // Reset audio frame pointers to original values
1905 // (may be needed if error occurred).
1906 resetAfPointers(pP, pAstCfg->xStr);
1907 // Reset audio frame meta data elements
1908 resetAfMetadata(pP, pAstCfg->xStr);
1909 #endif
1911 errno = pP->fxns->decodeInit(pP, pQ, pAsotCfg);
1912 if (errno)
1913 {
1914 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1915 errno = ASOP_DP_DECINIT_ERR;
1916 break;
1917 }
1919 //
1920 // Setup output: setCheckRateX, start output
1921 //
1922 // Establish secondary timing
1923 errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, frame, block);
1924 if (errno)
1925 {
1926 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInfo1", errno);
1927 break;
1928 }
1930 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: INIT->STREAM");
1931 state = STREAM;
1932 continue;
1934 case STREAM: // stream state
1935 gAsopStreamCnt++;
1936 Log_info0("TaskAsop: state=STREAM");
1938 errno = pP->fxns->decodeStream(pP, pQ, pAsotCfg, frame, block);
1939 if (errno)
1940 {
1941 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: STREAM. decodeStream err 0x%x", errno);
1942 errno = ASOP_DP_DECSTREAM_ERR;
1943 break;
1944 }
1946 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: STREAM->ENCODE");
1947 state = ENCODE;
1948 continue;
1950 case ENCODE: // encode state
1951 gAsopEncodeCnt++;
1952 Log_info0("TaskAsop: state=ENCODE");
1954 errno = pP->fxns->decodeEncode(pP, pQ, pAsotCfg, frame, block);
1955 if (errno)
1956 {
1957 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: ENCODE. decodeEncode err 0x%x", errno);
1958 errno = ASOP_DP_DECENC_ERR;
1959 break;
1960 }
1962 // Measure cycles in output processing loop.
1963 // Only measures cycles spent in loop.
1964 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS);
1965 gNumPfpAsot1--;
1966 pfpBegin(PFP_ID_ASOT_1, pAsotCfg->taskHandle);
1967 gNumPfpAsot1++;
1969 // (***) FL: do we need this?
1970 // AF pointers come from CB read, any resets occur in Decoder AF.
1971 //
1972 // Reset audio frame pointers to original values
1973 // (may have been adjusted by ARC or the like).
1974 resetAfPointers(pP, pAstCfg->xStr);
1976 // (***) FL: update output (setCheckRateX)
1977 // Contained in INFO2 in combined FSM.
1978 errno = pP->fxns->decodeInfo2(pP, pQ, pAsotCfg, frame, block);
1979 if (errno)
1980 {
1981 TRACE_TERSE1("PAF_ASOT_decodeProcessing: ENCODE break on decodeInfo2. errno 0x%x", errno);
1982 errno = ASOP_DP_DECINFO2_ERR;
1983 break;
1984 }
1986 block++;
1987 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: ENCODE->FINAL");
1988 state = FINAL;
1989 continue;
1991 case FINAL:
1992 gAsopFinalCnt++;
1993 Log_info0("TaskAsop: state=FINAL");
1995 //
1996 // (***) FL: this needs to be fixed.
1997 // (1) Only require selected Output to be in this FSM
1998 // => Dec Status checks aren't valid,
1999 // will probably always exit FSM if only Output running
2000 // (2) Checking Dec Status info asych to input events (maybe ok)
2001 //
2002 // Check for final frame, and if indicated:
2003 // - Update audio flag to cause output buffer flush rather than
2004 // the default truncate in "complete" processing.
2005 // - Exit state machine to "complete" processing.
2006 #if 0
2007 if (pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block))
2008 {
2009 for (z=OUTPUT1; z < OUTPUTN; z++)
2010 {
2011 if ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND)
2012 {
2013 TRACE_VERBOSE0("PAF_ASOT_outputProcessing: state: FINAL: SOUND -> QUIET");
2014 pAstCfg->xOut[z].outBufStatus.audio++; // SOUND -> QUIET
2015 }
2016 }
2017 break;
2018 }
2019 #endif
2020 errno = pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block);
2021 if (errno < 0)
2022 {
2023 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL break. errno 0x%x", errno);
2024 errno = ASOP_DP_DECFINALTEST_ERR;
2025 break;
2026 }
2027 else if (errno == ASOP_DP_CB_DRAINED)
2028 {
2029 // EOS, exit normally
2030 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL normal exit. errno 0x%x", errno);
2031 errno = ASOP_DP_SOK;
2032 break;
2033 }
2035 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: FINAL->STREAM");
2036 state = STREAM;
2037 continue;
2039 case OUT_SIO_UPDATE:
2040 gAsopOutSioUpdateCnt++;
2041 Log_info0("TaskAsop: state=OUT_SIO_UPDATE");
2043 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: OUT_SIO_UPDATE");
2044 errno = ASOP_DP_OUT_SIO_UPDATE;
2045 break;
2047 case QUIT:
2048 gAsopQuitCnt++;
2049 Log_info0("TaskAsop: state=QUIT");
2051 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: QUIT");
2052 errno = ASPERR_QUIT;
2053 break;
2055 default: // unknown state
2056 // Unknown:
2057 // - Set error number registers.
2058 // - Exit state machine to "complete" processing.
2060 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: unknown, 0x%x", state);
2061 errno = ASPERR_UNKNOWNSTATE;
2062 break;
2064 } // End of switch (state).
2066 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Calling decode complete");
2067 if (pP->fxns->decodeComplete(pP, pQ, pAsotCfg, NULL, frame, block))
2068 {
2069 /* ignored? */;
2070 }
2072 //pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
2073 //gNumPfpAsot1--;
2075 //return errno;
2076 break;
2077 } // End of for (;;)
2079 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
2080 gNumPfpAsot1--;
2082 return errno;
2083 }
2085 // -----------------------------------------------------------------------------
2086 // ASOT Decoding Function - Encode Command Processing
2087 //
2088 // Name: PAF_ASOT_encodeCommand
2089 // Purpose: Decoding Function for processing Encode Commands.
2090 // From: AST Parameter Function -> decodeProcessing
2091 // Uses: See code.
2092 // States: x
2093 // Return: 0.
2094 // Trace: Message Log "trace" in Debug Project Configuration reports:
2095 // * Command execution.
2096 // * SIO control errors.
2097 // * Error number macros.
2098 //
2099 Int
2100 PAF_ASOT_encodeCommand(
2101 const PAF_ASOT_Params *pP,
2102 const PAF_ASOT_Patchs *pQ,
2103 PAF_ASOT_Config *pAsotCfg
2104 )
2105 {
2106 PAF_AST_Config *pAstCfg;
2107 Int as; /* Audio Stream Number (1, 2, etc.) */
2108 Int z; /* encode counter */
2109 Int errno = 0; /* error number */
2110 Int zO, zS;
2113 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2114 as = pAstCfg->as;
2116 for (z=ENCODE1; z < ENCODEN; z++)
2117 {
2118 zO = pP->outputsFromEncodes[z];
2119 zS = pP->streamsFromEncodes[z];
2120 if (! (pAstCfg->xEnc[z].encodeStatus.command2 & 0x80))
2121 {
2122 switch (pAstCfg->xEnc[z].encodeStatus.command2)
2123 {
2124 case 0: // command none - process
2125 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2126 break;
2127 case 1: // mute command
2128 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command mute (0x%02x)", as+zS, 1);
2129 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2130 && pAstCfg->xOut[zO].hTxSio
2131 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2132 {
2133 errno = (errno & 0xff) | ASPERR_MUTE;
2134 /* convert to sensical errno */
2135 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (mute)", as+zS);
2136 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2137 }
2138 else
2139 {
2140 pAstCfg->xOut[zO].outBufStatus.audio |= PAF_OB_AUDIO_MUTED;
2141 }
2142 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2143 break;
2144 case 2: // unmute command
2145 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command unmute (0x%02x)", as+zS, 2);
2146 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2147 && pAstCfg->xOut[zO].hTxSio
2148 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2149 {
2150 errno = (errno & 0xff) | ASPERR_MUTE;
2151 /* convert to sensical errno */
2152 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (unmute)", as+zS);
2153 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2154 }
2155 else
2156 {
2157 pAstCfg->xOut[zO].outBufStatus.audio &= ~PAF_OB_AUDIO_MUTED;
2158 }
2159 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2160 break;
2161 default: // command unknown - ignore
2162 break;
2163 }
2164 }
2165 }
2167 ERRNO_RPRT (TaskAsop, errno);
2169 return 0;
2170 } //PAF_ASOT_encodeCommand
2172 //debug -- allow dynamic config
2173 //Int16 gStrFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
2175 // Purpose: Decoding Function for reinitializing the decoding process.
2176 Int
2177 PAF_ASOT_decodeInit(
2178 const PAF_ASOT_Params *pP,
2179 const PAF_ASOT_Patchs *pQ,
2180 PAF_ASOT_Config *pAsotCfg
2181 )
2182 {
2183 //PAF_AST_Config *pAstCfg;
2184 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2185 //Int as; /* Audio Stream Number (1, 2, etc.) */
2186 Int z; /* decode/encode counter */
2187 Int errno; /* error number */
2188 //Int zO, zS;
2190 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2191 //as = pAstCfg->as;
2193 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2195 for (z=DECODE1; z < DECODEN; z++)
2196 {
2197 // Initialize decoder output circular buffer for stream reads
2198 //errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
2199 errno = cbInitStreamRead(pCbCtl, z);
2200 if (errno)
2201 {
2202 TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
2203 SW_BREAKPOINT; // debug
2204 return errno;
2205 }
2207 // Start decoder output circular buffer reads
2208 errno = cbReadStart(pCbCtl, z);
2209 if (errno)
2210 {
2211 TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
2212 SW_BREAKPOINT; // debug
2213 return errno;
2214 }
2216 gCbReadAfErr=0; // reset read circular buffer error count
2217 gDecOpCbRdAfUnd=0; // reset decoder output circular buffer underflow count
2218 gMaxDecOpCbRdAfUnd=0; // reset max decoder output circular buffer underflow count
2219 gMasterCbResetCnt=0; // reset master circular buffer reset count
2221 // FL: debug, log circular buffer control variables
2222 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
2223 }
2225 #if 0 // moved to PAF_ASOT_outputReset()
2226 // TODO: move this to start of this function so that it doesn't affect IO timing
2227 for (z=ENCODE1; z < ENCODEN; z++)
2228 {
2229 zO = pP->outputsFromEncodes[z];
2230 zS = pP->streamsFromEncodes[z];
2231 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2232 {
2233 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2234 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2235 ENC_Handle enc = (ENC_Handle )encAlg;
2236 TRACE_VERBOSE1("AS%d: PAF_ASOT_decodeInit: initializing encode", as+zS);
2237 if (encAlg->fxns->algActivate)
2238 {
2239 encAlg->fxns->algActivate (encAlg);
2240 }
2241 if (enc->fxns->reset)
2242 {
2243 errno = enc->fxns->reset(enc, NULL,
2244 &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus);
2245 if (errno)
2246 {
2247 return errno;
2248 }
2249 }
2250 }
2251 }
2252 #endif
2254 return 0;
2255 }
2257 // -----------------------------------------------------------------------------
2258 // ASOT Decoding Function - Info Processing, Initial
2259 //
2260 // Name: PAF_ASOT_decodeInfo1
2261 // Purpose: Decoding Function for processing information in a manner that
2262 // is unique to initial frames of input data.
2263 // From: AST Parameter Function -> decodeProcessing
2264 // Uses: See code.
2265 // States: x
2266 // Return: Error number in standard or SIO form (0 on success).
2267 // Trace: Message Log "trace" in Debug Project Configuration reports:
2268 // * State information as per parent.
2269 //
2270 Int
2271 PAF_ASOT_decodeInfo1(
2272 const PAF_ASOT_Params *pP,
2273 const PAF_ASOT_Patchs *pQ,
2274 PAF_ASOT_Config *pAsotCfg,
2275 Int frame,
2276 Int block
2277 )
2278 {
2279 //PAF_AST_Config *pAstCfg;
2280 //Int z; /* decode/encode counter */
2281 Int errno; /* error number */
2283 #if 0 // moved to PAF_ASOT_outputInfo1()
2284 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2286 // run the chain of ASP's on the stream.
2287 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
2288 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2289 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame);
2290 if (errno)
2291 {
2292 TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
2293 return errno;
2294 }
2296 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
2297 for (z=ENCODE1; z < ENCODEN; z++)
2298 {
2299 Int zO = pP->outputsFromEncodes[z];
2300 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2301 {
2302 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2303 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2304 ENC_Handle enc = (ENC_Handle )encAlg;
2306 if (enc->fxns->info)
2307 {
2308 errno = enc->fxns->info(enc, NULL,
2309 &pAstCfg->xEnc[z].encodeControl,
2310 &pAstCfg->xEnc[z].encodeStatus);
2311 if (errno)
2312 {
2313 TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
2314 return errno;
2315 }
2316 }
2317 }
2318 }
2319 #endif
2321 errno = pP->fxns->setCheckRateX(pP, pQ, pAsotCfg, 0);
2322 if (errno)
2323 {
2324 // ignore if rateX has changed since we haven't, but are about to,
2325 // start the output. If we didn't ignore this case then the state machine
2326 // would restart unnecessarily, e.g. in the case of SRC, resulting in
2327 // added latency.
2328 if (errno != ASPERR_INFO_RATECHANGE)
2329 {
2330 TRACE_TERSE1("PAF_ASOT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
2331 return errno;
2332 }
2333 else
2334 {
2335 TRACE_TERSE0("PAF_ASOT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
2336 }
2337 }
2339 errno = pP->fxns->startOutput(pP, pQ, pAsotCfg);
2340 if (errno)
2341 {
2342 if (errno == 0x105)
2343 {
2344 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
2345 }
2346 else
2347 {
2348 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
2349 }
2350 return errno;
2351 }
2353 return 0;
2354 }
2356 // -----------------------------------------------------------------------------
2357 // ASOT Decoding Function - Info Processing, Subsequent
2358 //
2359 // Name: PAF_ASOT_decodeInfo2
2360 // Purpose: Decoding Function for processing information in a manner that
2361 // is unique to frames of input data other than the initial one.
2362 // From: AST Parameter Function -> decodeProcessing
2363 // Uses: See code.
2364 // States: x
2365 // Return: Error number in standard form (0 on success).
2366 // Trace: None.
2367 //
2368 Int
2369 PAF_ASOT_decodeInfo2(
2370 const PAF_ASOT_Params *pP,
2371 const PAF_ASOT_Patchs *pQ,
2372 PAF_ASOT_Config *pAsotCfg,
2373 Int frame,
2374 Int block
2375 )
2376 {
2377 //PAF_AST_Config *pAstCfg;
2378 Int errno;
2381 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2383 errno = pP->fxns->setCheckRateX (pP, pQ, pAsotCfg, 1);
2384 TRACE_VERBOSE1("PAF_ASOT_decodeInfo2: return 0x%x", errno);
2385 return errno;
2386 } //PAF_ASOT_decodeInfo2
2389 PAF_AST_DecOpCircBufStats gCbStats; // FL: debug
2390 // -----------------------------------------------------------------------------
2391 // ASOT Decoding Function - Stream Processing
2392 //
2393 // Name: PAF_ASOT_decodeStream
2394 // Purpose: Decoding Function for processing of audio frame data by the
2395 // ASP Algorithms.
2396 // From: AST Parameter Function -> decodeProcessing
2397 // Uses: See code.
2398 // States: x
2399 // Return: Error number in standard form (0 on success).
2400 // Trace: Message Log "trace" in Debug Project Configuration reports:
2401 // * State information as per parent/child.
2402 //
2403 Int
2404 PAF_ASOT_decodeStream(
2405 const PAF_ASOT_Params *pP,
2406 const PAF_ASOT_Patchs *pQ,
2407 PAF_ASOT_Config *pAsotCfg,
2408 Int frame,
2409 Int block
2410 )
2411 {
2412 PAF_AST_Config *pAstCfg;
2413 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2414 Int z; /* decode/stream counter */
2415 PAF_AudioFrame *pAfRd;
2416 Int cbErrno;
2417 //PAF_AST_DecOpCircBufStats cbStats; /* circular buffer statistics */
2418 Int errno;
2421 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2423 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2425 for (z=DECODE1; z < DECODEN; z++)
2426 {
2427 Int zS = pP->streamsFromDecodes[z];
2429 //
2430 // Read decoder output circular buffer
2431 //
2432 pAfRd = pAstCfg->xStr[zS].pAudioFrame;
2433 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2434 cbErrno = cbReadAf(pCbCtl, z, pAfRd);
2435 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2436 if ((cbErrno < 0) &&
2437 (cbErrno != ASP_DECOP_CB_AF_READ_UNDERFLOW) &&
2438 (cbErrno != ASP_DECOP_CB_PCM_READ_UNDERFLOW))
2439 {
2440 gCbReadAfErr++;
2441 TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
2442 //SW_BREAKPOINT; // debug
2443 return cbErrno;
2444 }
2446 // Handle underflows
2447 if ((cbErrno == ASP_DECOP_CB_AF_READ_UNDERFLOW) ||
2448 (cbErrno == ASP_DECOP_CB_PCM_READ_UNDERFLOW))
2449 {
2450 // (***) FL: Need to check behavior of cbReset().
2451 // Need to check behavior on exit/re-entry into Output processing.
2452 gDecOpCbRdAfUnd++; // increment circular buffer underflow count
2453 if (gDecOpCbRdAfUnd >= DEC_OP_CB_RDAF_UND_THR)
2454 {
2455 // Underflow count above threshold.
2456 // (1) set max underflow count to threshold
2457 // (2) reset underflow count
2458 // (3) reset circular buffer
2460 gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
2461 gDecOpCbRdAfUnd = 0; // reset underflow count
2463 // Reset circular buffer
2464 cbReset(pCbCtl, z);
2465 gMasterCbResetCnt++; // increment master circular buffer reset count
2466 Log_info0("ASOT:cbReset");
2468 return cbErrno;
2469 }
2470 }
2471 else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbRdAfUnd > 0))
2472 {
2473 // No underflow detected.
2474 // update max underflow count,
2475 // reset underflow count
2477 // update max underflow count
2478 if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
2479 {
2480 gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
2481 }
2482 gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
2483 }
2484 //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2485 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2486 Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2488 #if 0 // (***) FL: shows timing of CB read
2489 // (***) debug // B8
2490 {
2491 static Uint8 toggleState = 0;
2492 if (toggleState == 0)
2493 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2494 else
2495 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2496 toggleState = ~(toggleState);
2497 }
2498 #endif
2500 // debug, get circular buffer statistics
2501 //cbGetStats(pCbCtl, z, &cbStats);
2502 cbGetStats(pCbCtl, z, &gCbStats);
2504 // debug
2505 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
2507 #if 0 // debug, capture audio frame
2508 if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
2509 {
2510 Log_info0("capAfWrite() error");
2511 }
2512 #endif
2513 }
2515 TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
2516 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2517 PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
2518 if (errno)
2519 {
2520 TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
2521 return errno;
2522 }
2524 return 0;
2526 } //PAF_ASOT_decodeStream
2528 // -----------------------------------------------------------------------------
2529 // ASOT Decoding Function - Encode Processing
2530 //
2531 // Name: PAF_ASOT_decodeEncode
2532 // Purpose: Decoding Function for processing of audio frame data by the
2533 // Encode Algorithm.
2534 // From: AST Parameter Function -> decodeProcessing
2535 // Uses: See code.
2536 // States: x
2537 // Return: Error number in standard or SIO form (0 on success).
2538 // Trace: Message Log "trace" in Debug Project Configuration reports:
2539 // * State information as per parent.
2540 //
2541 Int
2542 PAF_ASOT_decodeEncode(
2543 const PAF_ASOT_Params *pP,
2544 const PAF_ASOT_Patchs *pQ,
2545 PAF_ASOT_Config *pAsotCfg,
2546 Int frame,
2547 Int block
2548 )
2549 {
2550 PAF_AST_Config *pAstCfg;
2551 Int as; /* Audio Stream Number (1, 2, etc.) */
2552 Int z; /* encode/output counter */
2553 Int errno; /* error number */
2554 Int zX, zE, zS;
2555 // debug
2556 //UInt32 curTime;
2558 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2559 as = pAstCfg->as;
2561 // Await output buffers (but not first time)
2562 for (z=OUTPUT1; z < OUTPUTN; z++)
2563 {
2564 // determine encoder associated with this output
2565 zE = z;
2566 for (zX = ENCODE1; zX < ENCODEN; zX++)
2567 {
2568 if (pP->outputsFromEncodes[zX] == z)
2569 {
2570 zE = zX;
2571 break;
2572 }
2573 }
2574 zS = pP->streamsFromEncodes[zE];
2576 if (pAstCfg->xOut[z].hTxSio)
2577 {
2578 // update length (e.g. ARC may have changed)
2579 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
2580 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2581 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- idle", as+zS, block);
2582 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2583 errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
2584 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2585 if (errno < 0)
2586 {
2587 SIO_idle(pAstCfg->xOut[z].hTxSio);
2588 TRACE_TERSE2("PAF_ASOT_decodeEncode: AS%d: SIO_reclaim returns error %d", as+zS, -errno);
2589 return -errno; // SIO negates error codes
2590 }
2591 // TODO: use pC->xOut[z].pOutBuf in following ->encode call
2593 #if 0 // (***) FL: shows timing of Output Tx SIO reclaim
2594 // (***) debug // B8
2595 {
2596 static Uint8 toggleState = 0;
2597 if (toggleState == 0)
2598 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2599 else
2600 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2601 toggleState = ~(toggleState);
2602 }
2603 #endif
2605 //
2606 // Simulate Tx SIO_reclaim() pend
2607 //
2608 //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
2609 //curTime = Clock_getTicks();
2610 //System_printf("System time in TaskAsopFxn Tx audio = %lu\n", (ULong)curTime);
2611 //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
2613 gAsopTxSioReclaimCnt++;
2614 }
2615 else
2616 {
2617 TRACE_VERBOSE2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- idle <ignored>", as+zS, block);
2618 }
2619 }
2621 // Encode data
2622 for (z=ENCODE1; z < ENCODEN; z++)
2623 {
2624 Int zO = pP->outputsFromEncodes[z];
2625 Int zS = pP->streamsFromEncodes[z];
2626 (void)zS; // clear compiler warning in case not used with tracing disabled
2627 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2628 {
2629 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2630 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2631 ENC_Handle enc = (ENC_Handle )encAlg;
2632 if (select != pAstCfg->xEnc[z].encodeControl.encActive)
2633 {
2634 pAstCfg->xEnc[z].encodeControl.encActive = select;
2635 TRACE_TERSE0("PAF_ASOT_decodeEncode: return error");
2636 return (-1);
2637 }
2638 TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- encode", as+zS, block);
2640 // (MID 1933) temp. workaround for PCE2
2641 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
2643 /*
2644 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2645 {
2646 PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
2647 int *wp;
2648 wp = (int*)pAudioFrame->data.sample[0];
2649 TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
2650 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
2651 wp = (int*)pAudioFrame->data.sample[1];
2652 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
2653 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
2654 wp = (int*)pAudioFrame->data.sample[2];
2655 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
2656 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
2657 }
2658 #endif
2659 */
2661 if (enc->fxns->encode)
2662 {
2663 pAstCfg->xEnc[z].encodeOutStruct.bypassFlag =
2664 pP->z_pEncodeStatus[z]->encBypass;
2665 errno = enc->fxns->encode(enc, NULL,
2666 &pAstCfg->xEnc[z].encodeInStruct,
2667 &pAstCfg->xEnc[z].encodeOutStruct);
2668 if (errno)
2669 {
2670 if (errno != PCEERR_OUTPUT_POINTERNULL)
2671 {
2672 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error %d line %d", errno);
2673 return errno;
2674 }
2675 }
2676 /* #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2677 else
2678 {
2679 int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
2680 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
2681 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
2682 }
2683 #endif
2684 */
2685 }
2686 }
2687 else
2688 {
2689 TRACE_VERBOSE2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- encode <ignored>",
2690 as+pP->streamsFromEncodes[z], block);
2691 }
2692 }
2694 // Transmit data
2695 for (z=OUTPUT1; z < OUTPUTN; z++)
2696 {
2697 // determine encoder associated with this output
2698 zE = z;
2699 for (zX = ENCODE1; zX < ENCODEN; zX++)
2700 {
2701 if (pP->outputsFromEncodes[zX] == z)
2702 {
2703 zE = zX;
2704 break;
2705 }
2706 }
2707 zS = pP->streamsFromEncodes[zE];
2709 if (pAstCfg->xOut[z].hTxSio)
2710 {
2711 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
2712 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2713 errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2714 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
2715 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2716 if (errno)
2717 {
2718 SIO_idle(pAstCfg->xOut[z].hTxSio);
2719 if (errno == 0x105) // 0x105 == RINGIO_EBUFFULL
2720 {
2721 // statStruct_LogFullRing(STATSTRUCT_AS1_F2);
2722 TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
2723 }
2724 if (errno > 0)
2725 {
2726 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error 0x%x line %d", errno);
2727 return (ASPERR_ISSUE + (z << 4));
2728 }
2729 else if (errno < 0)
2730 {
2731 TRACE_TERSE1("PAF_ASOT_decodeEncode: return neg error 0x%x line %d", -errno);
2732 return -errno; // SIO negates error codes
2733 }
2734 }
2735 if (errno > 0)
2736 {
2737 return (ASPERR_ISSUE + (z << 4));
2738 }
2739 else if (errno < 0)
2740 {
2741 return -errno; // SIO negates error codes
2742 }
2743 }
2744 else
2745 {
2746 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output <ignored>", as+zS, block);
2747 }
2748 }
2750 return 0;
2751 } //PAF_ASOT_decodeEncode
2753 // -----------------------------------------------------------------------------
2754 // ASOT Decoding Function - Stream-Final Processing
2755 //
2756 // Name: PAF_ASOT_decodeComplete
2757 // Purpose: Decoding Function for terminating the decoding process.
2758 // From: AST Parameter Function -> decodeProcessing
2759 // Uses: See code.
2760 // States: x
2761 // Return: 0.
2762 // Trace: Message Log "trace" in Debug Project Configuration reports:
2763 // * State information as per parent.
2764 //
2765 Int
2766 PAF_ASOT_decodeComplete(
2767 const PAF_ASOT_Params *pP,
2768 const PAF_ASOT_Patchs *pQ,
2769 PAF_ASOT_Config *pAsotCfg,
2770 ALG_Handle decAlg[],
2771 Int frame,
2772 Int block
2773 )
2774 {
2775 PAF_AST_Config *pAstCfg;
2776 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2777 Int as; /* Audio Stream Number (1, 2, etc.) */
2778 Int z; /* decode/encode counter */
2779 Int errno; /* error number */
2782 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2783 as = pAstCfg->as;
2784 (void)as; // clear compiler warning in case not used with tracing disabled
2786 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2788 for (z=DECODE1; z < DECODEN; z++)
2789 {
2790 // Stop decoder output circular buffer reads
2791 errno = cbReadStop(pCbCtl, z);
2792 if (errno)
2793 {
2794 TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
2795 SW_BREAKPOINT; // FL: debug
2796 return errno;
2797 }
2798 // FL: debug
2799 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeComplete:cbReadStop");
2800 }
2802 pP->fxns->streamChainFunction(pP, pQ, pAsotCfg, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
2804 for (z=ENCODE1; z < ENCODEN; z++)
2805 {
2806 Int zO = pP->outputsFromEncodes[z];
2807 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2808 {
2809 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2810 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2811 #ifdef PAF_ASP_FINAL
2812 ENC_Handle enc = (ENC_Handle)encAlg;
2813 #endif /* PAF_ASP_FINAL */
2814 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode", as+z);
2815 #ifdef PAF_ASP_FINAL
2816 if (enc->fxns->final)
2817 enc->fxns->final(enc, NULL, &pAstCfg->xEnc[z].encodeControl,
2818 &pAstCfg->xEnc[z].encodeStatus);
2819 #endif /* PAF_ASP_FINAL */
2820 if (encAlg->fxns->algDeactivate)
2821 {
2822 encAlg->fxns->algDeactivate(encAlg);
2823 }
2824 }
2825 else
2826 {
2827 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
2828 }
2829 }
2831 // wait for remaining data to be output
2832 pP->fxns->stopOutput(pP, pQ, pAsotCfg);
2834 return 0;
2835 } //PAF_ASOT_decodeComplete
2837 // -----------------------------------------------------------------------------
2838 // ASOT Decoding Function Helper - SIO Driver Start
2839 //
2840 // Name: PAF_ASOT_startOutput
2841 // Purpose: Decoding Function for initiating output.
2842 // From: AST Parameter Function -> decodeInfo1
2843 // Uses: See code.
2844 // States: x
2845 // Return: Error number in standard or SIO form (0 on success).
2846 // Trace: Message Log "trace" in Debug Project Configuration reports:
2847 // * State information as per parent.
2848 // * SIO control errors.
2849 //
2850 #define DEC_OUTNUMBUF_MAP(X) \
2851 pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
2853 Int
2854 PAF_ASOT_startOutput(
2855 const PAF_ASOT_Params *pP,
2856 const PAF_ASOT_Patchs *pQ,
2857 PAF_ASOT_Config *pAsotCfg
2858 )
2859 {
2860 PAF_AST_Config *pAstCfg;
2861 Int as; /* Audio Stream Number (1, 2, etc.) */
2862 Int z; /* output counter */
2863 Int errno,nbufs, errme; /* error number */
2864 Int zE, zS, zX;
2865 Int zMD;
2866 PAF_SIO_IALG_Obj *pObj;
2867 PAF_SIO_IALG_Config *pAlgConfig;
2870 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2871 as = pAstCfg->as;
2872 zMD = pAstCfg->masterDec;
2874 for (z=OUTPUT1; z < OUTPUTN; z++)
2875 {
2876 if (pAstCfg->xOut[z].hTxSio)
2877 {
2878 // determine associated encoder and stream
2879 zE = z;
2880 zS = z;
2881 for (zX = ENCODE1; zX < ENCODEN; zX++)
2882 {
2883 if (pP->outputsFromEncodes[zX] == z)
2884 {
2885 zE = zX;
2886 zS = pP->streamsFromEncodes[zE];
2887 break;
2888 }
2889 }
2891 // Need to Revisit: Starting Clocks here seems logical & also manages the McASP without spurious underruns .
2893 #if 1
2894 // if device selected and valid then enable stat tracking if
2895 // required and start clocking
2896 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
2897 {
2898 TRACE_VERBOSE0("PAF_ASOT_startOutput: start SIO clocks");
2899 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
2900 if (errno)
2901 {
2902 TRACE_VERBOSE2("PAF_ASOT_startOutput: errme 0x%x, errno 0x%x", errme, errno);
2903 SIO_idle(pAstCfg->xOut[z].hTxSio);
2904 if (!errno)
2905 {
2906 errno = ASPERR_DEVOUT + errme;
2907 }
2908 }
2909 }
2910 #endif