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"
72 #define TRACE_TIME(a)
74 //
75 // Audio Stream Definitions
76 //
78 //
79 // Audio Stream Processing Definitions
80 //
81 #define aspLinkInit pQ->i_aspLinkInit
83 //
84 // Encoder Definitions
85 //
86 #define encLinkInit pQ->i_encLinkInit
88 //
89 // Output Definitions
90 //
91 #define outLinkInit pP->i_outLinkInit
93 /* ---------------------------------------------------------------- */
94 /* Parameter macro definitions end here. */
95 /* ---------------------------------------------------------------- */
97 //
98 // Standardized Definitions
99 //
101 #define ENC_Handle PCE_Handle /* works for all: PCE */
103 #define __TASK_NAME__ "TaskAsop"
106 //
107 // Audio Stream Output Task definitions
108 //
110 // status codes
111 // Output FSM
112 #define ASOP_INITSYNC_NOTREADY ( 1 ) // ok, init-sync not ready
113 #define ASOP_SOK ( 0 ) // ok
114 #define ASOP_FORWARD_ERR ( -1 ) // forward (ASIT) error
115 #define ASOP_ENCRESET_ERR ( -2 ) // enc reset error
116 #define ASOP_DECINFO1_ERR ( -3 ) // dec info1 error
117 // Decode Processing
118 #define ASOP_DP_OUT_SIO_UPDATE ( 3 ) // new output selected
119 #define ASOP_DP_CB_DRAINED ( 2 ) // circular buffer drained
120 #define ASOP_DP_SOK ( 0 ) // ok
121 #define ASOP_DP_FORWARD_ERR ( -1 ) // forward (ASIT) error
122 #define ASOP_DP_DECINIT_ERR ( -2 ) // decode init error
123 #define ASOP_DP_DECSTREAM_ERR ( -3 ) // decode stream error
124 #define ASOP_DP_DECENC_ERR ( -4 ) // decode encode error
125 #define ASOP_DP_DECINFO2_ERR ( -5 ) // decode encode error
126 #define ASOP_DP_DECFINALTEST_ERR ( -6 ) // decode final error
130 /* Check if at least one output selected */
131 static Int checkOutSel(
132 const PAF_ASOT_Params *pP,
133 PAF_ASOT_Config *pAsotCfg,
134 Int *pOutSel
135 );
137 /* Check if at least one output sio changed */
138 static Int checkOutSio(
139 const PAF_ASOT_Params *pP,
140 PAF_ASOT_Config *pAsotCfg,
141 Int *pOutSioUpdate
142 );
144 // Initialize Output Processing state function
145 static Int PAF_ASOT_initOutProc(
146 const PAF_ASOT_Params *pP,
147 PAF_AST_Stream *xStr
148 );
150 // Initialize Output Processing state function
151 static Int PAF_ASOT_initSyncDecReset(
152 const PAF_ASOT_Params *pP,
153 const PAF_ASOT_Patchs *pQ,
154 PAF_ASOT_Config *pAsotCfg,
155 PAF_AudioFrame *pDecResetAf
156 );
158 // Purpose: ASOT Function for Output reset
159 static Int PAF_ASOT_outputReset(
160 const PAF_ASOT_Params *pP,
161 const PAF_ASOT_Patchs *pQ,
162 PAF_ASOT_Config *pAsotCfg
163 );
165 // Purpose: Init-Sync Dec Info1 state function.
166 // Performes Dec Info1 Init-Sync.
167 static Int PAF_ASOT_initSyncDecInfo1(
168 const PAF_ASOT_Params *pP,
169 const PAF_ASOT_Patchs *pQ,
170 PAF_ASOT_Config *pAsotCfg,
171 PAF_AudioFrame *pDecInfo1Af
172 );
174 // Purpose: ASOT function for ASP chain reset and ENC info
175 static Int PAF_ASOT_outputInfo1(
176 const PAF_ASOT_Params *pP,
177 const PAF_ASOT_Patchs *pQ,
178 PAF_ASOT_Config *pAsotCfg
179 );
181 // Purpose: Init-Sync Dec Decode1 state function.
182 // Performes Dec Decode1 Init-Sync.
183 static Int PAF_ASOT_initSyncDecDecode1(
184 const PAF_ASOT_Params *pP,
185 const PAF_ASOT_Patchs *pQ,
186 PAF_ASOT_Config *pAsotCfg
187 );
189 // Purpose: Init-Sync Re-Sync state function.
190 // Peformed Init-Sync using stored Dec Reset/Info1 AFs.
191 static Int PAF_ASOT_initSyncResync(
192 const PAF_ASOT_Params *pP,
193 const PAF_ASOT_Patchs *pQ,
194 PAF_ASOT_Config *pAsotCfg,
195 PAF_AudioFrame *pDecResetAf,
196 PAF_AudioFrame *pDecInfo1Af
197 );
199 #if 0
200 // Init-Sync update audio frame
201 static Int initSyncUpdateAf(
202 PAF_AudioFrame *dstAf,
203 PAF_AudioFrame *srcAf
204 );
205 #endif
207 // Reset audio frames
208 static Void resetAfs(
209 const PAF_ASOT_Params *pP,
210 PAF_AST_Stream *xStr
211 );
213 // Reset audio frame pointers to original values
214 static Void resetAfPointers(
215 const PAF_ASOT_Params *pP,
216 PAF_AST_Stream *xStr
217 );
219 // Reset audio frame meta data elements
220 static Void resetAfMetadata(
221 const PAF_ASOT_Params *pP,
222 PAF_AST_Stream *xStr
223 );
226 LINNO_DEFN(TaskAsop); /* Line number macros */
227 ERRNO_DEFN(TaskAsop); /* Error number macros */
229 // ASOT configuration
230 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
231 PAF_ASOT_Config gPAF_ASOT_config = {
232 NULL, // taskHandle
233 NULL, // acp
234 0,0,0, // CB drained flags (size DECODE_MAXN)
235 &gPAF_ASPM_config, // pAspmCfg
236 &gPAF_AST_config // pAstCfg
237 };
239 // Underflow threshold before circular buffer reset and return error to Top-Level FSM
240 #define DEC_OP_CB_RDAF_UND_THR ( 80 ) // FL: arbitrary setting
241 UInt32 gCbReadAfErr =0; // read circular buffer error count, not including underflows
242 UInt32 gDecOpCbRdAfUnd =0; // decoder output circular buffer underflow count
243 UInt32 gMaxDecOpCbRdAfUnd =0; // max (consecutive) decoder output circular buffer underflow count
244 UInt32 gMasterCbResetCnt =0; // master circular buffer reset count
246 // Global debug counters */
247 UInt32 gAsopInitOutProcCnt =0;
248 UInt32 gAsopInitSyncDecResetCnt =0;
249 UInt32 gAsopInitSyncDecInfo1Cnt =0;
250 UInt32 gAsopInitSyncDecDecode1Cnt =0;
251 UInt32 gAsopInitSyncResyncCnt =0;
252 UInt32 gAsopOutProcCnt =0;
253 UInt32 gAsopInitCnt =0;
254 UInt32 gAsopStreamCnt =0;
255 UInt32 gAsopEncodeCnt =0;
256 UInt32 gAsopFinalCnt =0;
257 UInt32 gAsopOutSioUpdateCnt =0;
258 UInt32 gAsopQuitCnt =0;
259 UInt32 gAsopTxSioReclaimCnt =0;
261 /*
262 * ======== taskAsopFxn ========
263 * Audio Stream Output Processing task function
264 */
265 Void taskAsopFxn(
266 // Int betaPrimeValue, // FL: revisit
267 const PAF_ASOT_Params *pP,
268 const PAF_ASOT_Patchs *pQ
269 )
270 {
271 PAF_ASOT_Config *pAsotCfg; /* ASOT configuration pointer */
272 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
273 Int as; /* Audio Stream Number (1, 2, etc.) */
274 Int z; /* input/encode/stream/decode/output counter */
275 Int i; /* phase */
276 Int zMS;
277 Int errno; // error number
278 Int8 procSleep; // whether to sleep: 0: No, 1: Yes
279 Int8 procOutDevSel; // whether to perform output device selection: 0: No, 1:Yes
280 Int outSel; // whether output device selected
281 enum { INIT_OUT_PROC_STATE,
282 INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE,
283 INITSYNC_RESYNC_STATE,
284 OUT_PROC_STATE } state;
285 PAF_AudioFrame decResetAf;
286 PAF_AudioFrame decInfo1Af;
287 Int loopCount = 0; // used to stop trace to see startup behavior.
290 Log_info0("Enter taskAsopFxn()");
292 //
293 // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
294 //
295 if (!pP)
296 {
297 TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
298 LINNO_RPRT(TaskAsop, -1);
299 return;
300 }
302 if (!pQ)
303 {
304 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
305 LINNO_RPRT(TaskAsop, -1);
306 return;
307 }
309 //
310 // Audio Stream Output Task Configuration (*pAsotCfg):
311 //
312 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
313 pAsotCfg->taskHandle = Task_self(); // set task handle
314 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
316 /* Obtain Audio Stream Number (1, 2, etc.) */
317 as = pAstCfg->as;
318 TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
320 //
321 // Initialize message log trace and line number reporting
322 //
323 for (z=STREAM1; z < STREAMN; z++)
324 {
325 TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
326 }
327 LINNO_RPRT(TaskAsop, -1);
329 //
330 // Determine stream index
331 //
332 zMS = pAstCfg->masterStr;
334 // Initialize as per parametrized phases:
335 //
336 // In standard form these are:
337 // - Malloc: Memory Allocation
338 // - Config: Configuration Initialization
339 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
340 // - Common: Common Memory Initialization
341 // - AlgKey: Dec/Enc chain to Array Initialization
342 // - Device: I/O Device Initialization
343 // - Unused: (available)
344 // - Unused: (available)
345 //
346 LINNO_RPRT(TaskAsop, -2);
347 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
348 {
349 Int linno;
350 if (pP->fxns->initPhase[i])
351 {
352 linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
353 if (linno)
354 {
355 LINNO_RPRT(TaskAsop, linno);
356 return;
357 }
358 }
359 else
360 {
361 TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
362 }
363 TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
364 LINNO_RPRT(TaskAsop, -i-3);
365 }
367 //
368 // End of Initialization -- display memory usage report.
369 //
370 if (pP->fxns->memStatusPrint)
371 {
372 pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
373 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
374 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
375 }
377 //
378 // Main processing loop
379 //
380 for (z=STREAM1; z < STREAMN; z++)
381 {
382 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
383 }
385 errno = 0; // init error indicator -- no error
386 procSleep = 1; // init sleep flag -- sleep
387 procOutDevSel = 1; // init device output selection flag -- perform output device selection
388 state = INIT_OUT_PROC_STATE; // init state
389 for (;;)
390 {
391 loopCount++;
392 TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", loopCount, errno);
394 //
395 // Check forward (ASIT) error here, TBD
396 //
398 // any error forces idling of output
399 if (errno)
400 {
401 for (z=OUTPUT1; z < OUTPUTN; z++)
402 {
403 if (pAstCfg->xOut[z].hTxSio)
404 {
405 SIO_idle(pAstCfg->xOut[z].hTxSio);
406 }
407 }
409 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
410 ERRNO_RPRT(TaskAsop, errno);
411 }
413 if (procSleep == 1)
414 {
415 TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
416 Task_sleep(1);
417 }
419 if (procOutDevSel == 1)
420 {
421 // select output devices
422 TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
423 errno = pP->fxns->selectDevices(pP, pQ, pAsotCfg);
424 if (errno)
425 {
426 TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
428 procSleep = 1;
429 procOutDevSel = 1;
431 continue;
432 }
434 // if no output selected skip remaining processing
435 errno = checkOutSel(pP, pAsotCfg, &outSel);
436 if (errno < 0)
437 {
438 TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
440 procSleep = 1;
441 procOutDevSel = 1;
443 continue;
444 }
445 else if (!outSel)
446 {
447 TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);
449 procSleep = 1;
450 procOutDevSel = 1;
452 continue;
453 }
454 }
456 switch (state)
457 {
458 case INIT_OUT_PROC_STATE:
459 gAsopInitOutProcCnt++;
460 Log_info0("TaskAsop: state=INIT_OUT_PROC_STATE");
462 //
463 // Output Processing initialization.
464 //
465 errno = PAF_ASOT_initOutProc(pP, pAstCfg->xStr);
466 if (errno < 0)
467 {
468 state = INIT_OUT_PROC_STATE;
469 procSleep = 1;
470 procOutDevSel = 1;
471 }
472 else
473 {
474 state = INITSYNC_DEC_RESET_STATE;
475 procSleep = 0;
476 procOutDevSel = 0;
477 }
479 break;
481 case INITSYNC_DEC_RESET_STATE:
482 gAsopInitSyncDecResetCnt++;
483 Log_info0("TaskAsop: state=INITSYNC_DEC_RESET_STATE");
485 //
486 // Dec Reset Init-Sync.
487 //
489 // Perform Dec Reset init-sync.
490 // Latch Dec Reset AF.
491 errno = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, &decResetAf);
492 if (errno < 0)
493 {
494 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE errno=%d", errno);
496 // sync error -- start over
497 state = INIT_OUT_PROC_STATE;
498 procSleep = 1;
499 procOutDevSel = 1;
500 }
501 else if (errno == ASOP_INITSYNC_NOTREADY)
502 {
503 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE not sync'd errno=%d", errno);
505 // sync not ready -- try again
506 state = INITSYNC_DEC_RESET_STATE;
507 errno=0; // FL: temp hack
508 procSleep = 1;
509 procOutDevSel = 1;
510 }
511 else // errno==0
512 {
513 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE sync'd, errno=%d", errno);
515 // sync'd -- move on
516 state = INITSYNC_DEC_INFO1_STATE;
517 procSleep = 0;
518 procOutDevSel = 0;
519 }
521 break;
523 case INITSYNC_DEC_INFO1_STATE:
524 gAsopInitSyncDecInfo1Cnt++;
525 Log_info0("TaskAsop: state=INITSYNC_DEC_INFO1_STATE");
527 //
528 // Dec Info1 Init-Sync.
529 //
531 // Perform Dec Info1 init-sync.
532 // Latch Dec Info1 AF.
533 errno = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af);
534 if (errno < 0)
535 {
536 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE errno=%d", errno);
538 // sync error -- start over
539 state = INIT_OUT_PROC_STATE;
540 procSleep = 1;
541 procOutDevSel = 1;
542 }
543 else if (errno == ASOP_INITSYNC_NOTREADY)
544 {
545 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE not sync'd errno=%d", errno);
547 // sync not ready -- try again
548 state = INITSYNC_DEC_INFO1_STATE;
549 errno=0; // FL: temp hack
550 procSleep = 1;
551 procOutDevSel = 0;
552 }
553 else // errno = 0
554 {
555 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE sync'd errno=%d", errno);
557 // sync'd -- move on
558 state = INITSYNC_DEC_DECODE1_STATE;
559 procSleep = 0;
560 procOutDevSel = 0;
561 }
563 break;
565 case INITSYNC_DEC_DECODE1_STATE:
566 gAsopInitSyncDecDecode1Cnt++;
567 Log_info0("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE");
569 //
570 // Dec Info1 Init-Sync.
571 //
573 // Perform Dec Info1 init-sync.
574 // Latch Dec Info1 AF.
575 errno = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg);
576 if (errno < 0)
577 {
578 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE errno=%d", errno);
580 // sync error -- start over
581 state = INIT_OUT_PROC_STATE;
582 procSleep = 1;
583 procOutDevSel = 1;
584 }
585 else if (errno == ASOP_INITSYNC_NOTREADY)
586 {
587 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE not sync'd errno=%d", errno);
589 // sync not ready -- try again
590 state = INITSYNC_DEC_DECODE1_STATE;
591 errno=0; // FL: temp hack
592 procSleep = 1;
593 procOutDevSel = 0;
594 }
595 else // errno = 0
596 {
597 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE sync'd errno=%d", errno);
599 // sync'd -- move on
600 state = OUT_PROC_STATE;
601 procSleep = 0;
602 procOutDevSel = 0;
603 }
605 break;
607 case INITSYNC_RESYNC_STATE:
608 gAsopInitSyncResyncCnt++;
609 Log_info0("TaskAsop: state=INITSYNC_RESYNC_STATE");
611 //
612 // Re-Sync.
613 // Use stored AF info from init-sync.
614 // This is done in case of local error.
615 //
617 // Perform Dec Info1 init-sync.
618 errno = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf,
619 &decInfo1Af);
620 if (errno < 0)
621 {
622 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE errno=%d", errno);
624 // sync error -- start over
625 state = INIT_OUT_PROC_STATE;
626 procSleep = 1;
627 procOutDevSel = 1;
628 }
629 else
630 {
631 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE sync'd errno=%d", errno);
633 // re-sync'd -- move on
634 state = OUT_PROC_STATE;
635 procSleep = 0;
636 procOutDevSel = 0;
637 }
639 break;
641 case OUT_PROC_STATE:
642 gAsopOutProcCnt++;
643 Log_info0("TaskAsop: state=OUT_PROC_STATE");
645 //
646 // Output Processing.
647 //
649 TRACE_VERBOSE0("TaskAsop: calling decodeProcessing.");
650 errno = pP->fxns->decodeProcessing(pP, pQ, pAsotCfg);
651 if (errno < 0)
652 {
653 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
655 //
656 // Output Processing exit, due to error
657 //
659 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
660 if (errno == ASOP_DP_FORWARD_ERR)
661 {
662 // forward (ASIT) error -- start over
663 state = INIT_OUT_PROC_STATE;
664 procSleep = 1;
665 procOutDevSel = 1;
666 }
667 else
668 {
669 // local (ASOT) error
670 state = INITSYNC_RESYNC_STATE;
671 procSleep = 1;
672 procOutDevSel = 0; // disallow device re-select if local error during output processing
673 }
674 }
675 else if (errno > 0)
676 {
677 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
679 //
680 // Output Processing exit, not due to error
681 //
683 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
684 if (errno == ASOP_DP_OUT_SIO_UPDATE)
685 {
686 // skip re-sync
687 // resume output processing after new output selected
688 state = OUT_PROC_STATE;
689 procSleep = 1;
690 procOutDevSel = 1;
691 }
692 }
693 else
694 {
695 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
697 //
698 // Output Processing exit, normal
699 //
701 TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
703 // no error returned if CB drained
704 // (i.e. CB drained is normal behavior)
705 state = INIT_OUT_PROC_STATE;
706 procSleep = 1;
707 procOutDevSel = 1;
708 }
710 break;
712 default: // unknown state
713 TRACE_TERSE2("TaskAsop: AS%d: state: unknown, 0x%x", as+zMS, state);
714 break;
715 }
716 } // End of main processing loop for (;;)
718 //Log_info0("Exit taskAsopFxn()");
719 }
721 // -----------------------------------------------------------------------------
722 // AST Initialization Function - Memory Allocation
723 //
724 // Name: PAF_ASOT_initPhaseMalloc
725 // Purpose: Audio Stream Output Task Function for initialization of data pointers
726 // by allocation of memory.
727 // From: audioStream1Task or equivalent
728 // Uses: See code.
729 // States: x
730 // Return: 0 on success.
731 // Source code line number on MEM_calloc failure.
732 // Trace: Message Log "trace" in Debug Project Configuration reports:
733 // * State information as per parent.
734 // * Memory allocation errors.
735 //
737 Int
738 PAF_ASOT_initPhaseMalloc (
739 const PAF_ASOT_Params *pP,
740 const PAF_ASOT_Patchs *pQ,
741 PAF_ASOT_Config *pAsotCfg
742 )
743 {
744 PAF_AST_Config *pAstCfg;
745 Int as; /* Audio Stream Number (1, 2, etc.) */
746 Int zMS;
747 Error_Block eb;
748 //Int i;
750 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
751 as = pAstCfg->as;
752 zMS = pAstCfg->masterStr;
754 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
756 // Initialize error block
757 Error_init(&eb);
759 /* Stream memory */
760 if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
761 {
762 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
763 SW_BREAKPOINT;
764 return __LINE__;
765 }
766 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
767 STREAMN * sizeof (*pAstCfg->xStr),
768 HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
770 {
771 Int z; /* stream counter */
773 PAF_AudioFrame *fBuf;
775 if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
776 {
777 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
778 SW_BREAKPOINT;
779 return __LINE__;
780 }
781 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
782 STREAMS * sizeof (*fBuf),
783 HEAP_ID_INTERNAL, (IArg)fBuf);
785 for (z=STREAM1; z < STREAMN; z++)
786 {
787 pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
788 TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
789 }
790 }
792 /* Encode memory */
793 if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
794 {
795 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
796 SW_BREAKPOINT;
797 return __LINE__;
798 }
799 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
800 ENCODEN * sizeof (*pAstCfg->xEnc),
801 HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
803 /* Output memory */
804 if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
805 {
806 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
807 SW_BREAKPOINT;
808 return __LINE__;
809 }
810 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
811 OUTPUTN * sizeof (*pAstCfg->xOut),
812 HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
814 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
815 return 0;
816 } //PAF_ASOT_initPhaseMalloc
818 // -----------------------------------------------------------------------------
819 // ASOT Initialization Function - Memory Initialization from Configuration
820 //
821 // Name: PAF_ASOT_initPhaseConfig
822 // Purpose: Audio Stream Output Task Function for initialization of data values
823 // from parameters.
824 // From: audioStream1Task or equivalent
825 // Uses: See code.
826 // States: x
827 // Return: 0 on success.
828 // Other as per initFrame0 and initFrame1.
829 // Trace: Message Log "trace" in Debug Project Configuration reports:
830 // * State information as per parent.
831 //
832 Int
833 PAF_ASOT_initPhaseConfig(
834 const PAF_ASOT_Params *pP,
835 const PAF_ASOT_Patchs *pQ,
836 PAF_ASOT_Config *pAsotCfg
837 )
838 {
839 PAF_AST_Config *pAstCfg;
840 Int as; /* Audio Stream Number (1, 2, etc.) */
841 Int z; /* input/encode/stream/decode/output counter */
842 Int zMS;
844 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
845 as = pAstCfg->as;
846 zMS = pAstCfg->masterStr;
848 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
850 //
851 // Unspecified elements have been initialized to zero during alloc
852 //
854 for (z=STREAM1; z < STREAMN; z++)
855 {
856 Int linno;
857 if (linno = pP->fxns->initFrame0(pP, pQ, pAsotCfg, z))
858 {
859 return linno;
860 }
861 if (linno = pP->fxns->initFrame1(pP, pQ, pAsotCfg, z, -1))
862 {
863 return linno;
864 }
865 }
867 for (z=ENCODE1; z < ENCODEN; z++)
868 {
869 Int zO = pP->outputsFromEncodes[z];
870 Int zS = pP->streamsFromEncodes[z];
871 pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
872 pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
873 pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
874 pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
875 pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
876 pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
877 pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
878 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
879 }
881 for (z=OUTPUT1; z < OUTPUTN; z++)
882 {
883 pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
884 }
886 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
887 return 0;
888 } //PAF_ASOT_initPhaseConfig
890 // -----------------------------------------------------------------------------
891 // ASOT Initialization Function - ACP Algorithm Instantiation
892 //
893 // Name: PAF_ASOT_initPhaseAcpAlg
894 // Purpose: Audio Stream Input Task Function for initialization of ACP by
895 // instantiation of the algorithm.
896 // From: audioStream1Task or equivalent
897 // Uses: See code.
898 // States: x
899 // Return: 0 on success.
900 // Source code line number on ACP Algorithm creation failure.
901 // Trace: Message Log "trace" in Debug Project Configuration reports:
902 // * State information as per parent.
903 // * Memory allocation errors.
904 //
905 Int
906 PAF_ASOT_initPhaseAcpAlg(
907 const PAF_ASOT_Params *pP,
908 const PAF_ASOT_Patchs *pQ,
909 PAF_ASOT_Config *pAsotCfg
910 )
911 {
912 PAF_AST_Config *pAstCfg;
913 Int as; /* Audio Stream Number (1, 2, etc.) */
914 Int z; /* input/encode/stream/decode/output counter */
915 Int betaPrimeOffset;
916 ACP_Handle acp;
917 Int zMS;
918 Int zS, zX;
920 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
921 as = pAstCfg->as;
922 zMS = pAstCfg->masterStr;
924 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
926 ACP_MDS_init();
928 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
929 {
930 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
931 return __LINE__;
932 }
933 pAsotCfg->acp = acp;
935 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
936 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
938 for (z=ENCODE1; z < ENCODEN; z++)
939 {
940 zS = pP->streamsFromEncodes[z];
941 acp->fxns->attach(acp, ACP_SERIES_STD,
942 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
943 (IALG_Status *)&pAstCfg->xEnc[z].encodeStatus);
944 acp->fxns->attach(acp, ACP_SERIES_STD,
945 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
946 (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
947 /* Ignore errors, not reported. */
948 }
950 for (z=OUTPUT1; z < OUTPUTN; z++)
951 {
952 zS = z;
953 for (zX = ENCODE1; zX < ENCODEN; zX++)
954 {
955 if (pP->outputsFromEncodes[zX] == z)
956 {
957 zS = pP->streamsFromEncodes[zX];
958 break;
959 }
960 }
961 acp->fxns->attach(acp, ACP_SERIES_STD,
962 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
963 (IALG_Status *)&pAstCfg->xOut[z].outBufStatus);
964 /* Ignore errors, not reported. */
965 }
967 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
969 return 0;
970 } //PAF_ASOT_initPhaseAcpAlg
972 // -----------------------------------------------------------------------------
973 // ASOT Initialization Function - Common Memory
974 //
975 // Name: PAF_ASOT_initPhaseCommon
976 // Purpose: Audio Stream Output Task Function for allocation of common memory.
977 // From: audioStream1Task or equivalent
978 // Uses: See code.
979 // States: x
980 // Return: 0 on success.
981 // Source code line number on PAF_ALG_alloc failure.
982 // Source code line number on PAF_ALG_mallocMemory failure.
983 // Source code line number on Decode Chain initialization failure.
984 // Source code line number on ASP Chain initialization failure.
985 // Source code line number on Encode Chain initialization failure.
986 // Trace: Message Log "trace" in Debug Project Configuration reports:
987 // * State information as per parent.
988 // * Memory allocation errors.
989 //
990 Int
991 PAF_ASOT_initPhaseCommon(
992 const PAF_ASOT_Params *pP,
993 const PAF_ASOT_Patchs *pQ,
994 PAF_ASOT_Config *pAsotCfg
995 )
996 {
997 PAF_AST_Config *pAstCfg;
998 Int as; /* Audio Stream Number (1, 2, etc.) */
999 Int z; /* stream counter */
1000 Int g; /* gear */
1001 ACP_Handle acp;
1002 PAF_IALG_Config pafAlgConfig;
1003 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1005 acp = pAsotCfg->acp;
1006 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1007 as = pAstCfg->as;
1009 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
1011 //
1012 // Determine memory needs and instantiate algorithms across audio streams
1013 //
1014 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
1015 PAF_ALG_setup(&pafAlgConfig,
1016 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1017 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1018 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1019 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1020 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1021 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1022 HEAP_CLEAR);
1024 if (pP->fxns->headerPrint)
1025 {
1026 pP->fxns->headerPrint();
1027 }
1029 for (z = STREAM1; z < STREAMN; z++)
1030 {
1031 //Int zD, zE, zX;
1032 Int zE, zX;
1034 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1036 //
1037 // Determine common memory needs for:
1038 // (1) ASP Algorithms
1039 // (2) Encode Algorithms
1040 // (3) Logical Output drivers
1041 //
1042 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1044 zE = -1;
1045 for (zX = ENCODE1; zX < ENCODEN; zX++)
1046 {
1047 if (pP->streamsFromEncodes[zX] == z)
1048 {
1049 zE = zX;
1050 break;
1051 }
1052 }
1054 TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
1055 if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z]))
1056 {
1057 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1058 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1059 SW_BREAKPOINT;
1060 return __LINE__;
1061 }
1062 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1063 if (pP->fxns->allocPrint)
1064 {
1065 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1066 }
1068 if (zE >= 0)
1069 {
1070 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
1071 if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z]))
1072 {
1073 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1074 SW_BREAKPOINT;
1075 return __LINE__;
1076 }
1077 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1078 if (pP->fxns->allocPrint)
1079 {
1080 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
1081 }
1082 }
1084 //
1085 // Determine common memory needs of Logical IO drivers
1086 //
1088 if (OUTPUT1 <= z && z < OUTPUTN)
1089 {
1090 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
1091 if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
1092 {
1093 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
1094 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1095 SW_BREAKPOINT;
1096 return __LINE__;
1097 }
1098 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1099 if (pP->fxns->allocPrint)
1100 {
1101 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
1102 }
1103 }
1104 }
1105 {
1106 // Changes made to share scratch between zones
1107 // Assume maximum 3 zones and scratch common memory is at offset 0;
1108 int max=0;
1109 for (z=STREAM1; z<STREAMN; z++)
1110 {
1111 if (max < common[z][0].size)
1112 {
1113 max = common[z][0].size;
1114 }
1115 }
1116 common[STREAM1][0].size=max;
1117 for (z=STREAM1+1; z<STREAMN; z++)
1118 {
1119 common[z][0].size = 0;
1120 }
1121 }
1123 //
1124 // Allocate common memory for:
1125 // (1) ASP Algorithms
1126 // (2) Encode Algorithms
1127 // (3) Logical Output drivers
1128 //
1129 for (z = STREAM1; z < STREAMN; z++)
1130 {
1131 //Int zD, zE, zX;
1132 Int zE, zX;
1134 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1135 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1136 {
1137 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
1138 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1139 SW_BREAKPOINT;
1140 return __LINE__;
1141 }
1142 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1143 // share zone0 scratch with all zones
1144 common[z][0].base = common[0][0].base;
1145 if (pP->fxns->commonPrint)
1146 {
1147 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1148 }
1150 zE = -1;
1151 for (zX = ENCODE1; zX < ENCODEN; zX++)
1152 {
1153 if (pP->streamsFromEncodes[zX] == z)
1154 {
1155 zE = zX;
1156 break;
1157 }
1158 }
1160 pAstCfg->xStr[z].aspChain[0] = NULL;
1161 for (g=0; g < GEARS; g++)
1162 {
1163 PAF_ASP_Chain *chain;
1164 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
1165 chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
1166 HEAP_INTERNAL, as+z, acp, &trace,
1167 aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1168 if (!chain)
1169 {
1170 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1171 return __LINE__;
1172 }
1173 else
1174 {
1175 pAstCfg->xStr[z].aspChain[g] = chain;
1176 }
1177 }
1179 if (zE >= 0)
1180 {
1181 PAF_ASP_Chain *chain;
1182 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
1183 chain = PAF_ASP_chainInit(&pAstCfg->xEnc[zE].encChainData, pP->pChainFxns,
1184 HEAP_INTERNAL, as+z, acp, &trace,
1185 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
1186 if (!chain)
1187 {
1188 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
1189 return __LINE__;
1190 }
1191 }
1193 //
1194 // Allocate non-common memories for Logical IO drivers
1195 // Since these structures are used at run-time we allocate from external memory
1196 if (OUTPUT1 <= z && z < OUTPUTN)
1197 {
1198 PAF_ASP_Chain *chain;
1199 TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
1200 as+z, z);
1201 chain = PAF_ASP_chainInit (&pAstCfg->xOut[z].outChainData, pP->pChainFxns,
1202 HEAP_EXTERNAL, as+z, acp, &trace,
1203 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
1204 if (!chain)
1205 {
1206 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
1207 return __LINE__;
1208 }
1209 }
1210 }
1211 TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
1213 return 0;
1214 } //PAF_ASOT_initPhaseCommon
1216 // -----------------------------------------------------------------------------
1217 // ASOT Initialization Function - Algorithm Keys
1218 //
1219 // Name: PAF_ASOT_initPhaseAlgKey
1220 // Purpose: Audio Stream Output Task Function for initialization of data values
1221 // from parameters for Algorithm Keys.
1222 // From: audioStream1Task or equivalent
1223 // Uses: See code.
1224 // States: x
1225 // Return: 0.
1226 // Trace: Message Log "trace" in Debug Project Configuration reports:
1227 // * State information as per parent.
1228 //
1229 // .............................................................................
1230 Int
1231 PAF_ASOT_initPhaseAlgKey(
1232 const PAF_ASOT_Params *pP,
1233 const PAF_ASOT_Patchs *pQ,
1234 PAF_ASOT_Config *pAsotCfg
1235 )
1236 {
1237 PAF_AST_Config *pAstCfg;
1238 Int as; /* Audio Stream Number (1, 2, etc.) */
1239 Int z; /* decode/encode counter */
1240 Int s; /* key number */
1241 PAF_ASP_Link *that;
1243 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1244 as = pAstCfg->as;
1245 (void)as; // clear compiler warning in case not used with tracing disabled
1247 TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1249 for (z=ENCODE1; z < ENCODEN; z++)
1250 {
1251 for (s=0; s < pP->pEncAlgKey->length; s++)
1252 {
1253 if ((pP->pEncAlgKey->code[s].full != 0) &&
1254 (that = PAF_ASP_chainFind(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
1255 {
1256 pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
1257 }
1258 /* Cast in interface, for now --Kurt */
1259 else
1260 {
1261 pAstCfg->xEnc[z].encAlg[s] = NULL;
1262 }
1263 }
1264 }
1266 return 0;
1267 } //PAF_ASOT_initPhaseAlgKey
1269 // -----------------------------------------------------------------------------
1270 // ASOT Initialization Function - I/O Devices
1271 //
1272 // Name: PAF_ASOT_initPhaseDevice
1273 // Purpose: Audio Stream Output Task Function for initialization of I/O Devices.
1274 // From: audioStream1Task or equivalent
1275 // Uses: See code.
1276 // States: x
1277 // Return: 0 on success.
1278 // Source code line number on device allocation failure.
1279 // Trace: Message Log "trace" in Debug Project Configuration reports:
1280 // * State information as per parent.
1281 // * Memory allocation errors.
1282 //
1283 Int
1284 PAF_ASOT_initPhaseDevice(
1285 const PAF_ASOT_Params *pP,
1286 const PAF_ASOT_Patchs *pQ,
1287 PAF_ASOT_Config *pAsotCfg
1288 )
1289 {
1290 PAF_AST_Config *pAstCfg;
1291 Int as; /* Audio Stream Number (1, 2, etc.) */
1292 Int z; /* input/output counter */
1293 PAF_SIO_IALG_Obj *pObj;
1294 PAF_SIO_IALG_Config *pAlgConfig;
1295 PAF_IALG_Config pafAlgConfig;
1297 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1298 as = pAstCfg->as;
1299 (void)as; // clear compiler warning in case not used with tracing disabled
1301 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1303 if(pP->fxns->bufMemPrint)
1304 {
1305 PAF_ALG_setup (&pafAlgConfig,
1306 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1307 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1308 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1309 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1310 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1311 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1312 HEAP_CLEAR);
1313 TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1314 }
1316 for (z=OUTPUT1; z < OUTPUTN; z++)
1317 {
1318 PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
1320 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
1321 pAlgConfig = &pObj->config;
1323 pAstCfg->xOut[z].hTxSio = NULL;
1324 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1325 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1326 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1327 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1328 pConfig->sizeofElement = 3;
1329 pConfig->precision = 24;
1330 if(pP->fxns->bufMemPrint)
1331 {
1332 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
1333 }
1334 }
1335 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1337 return 0;
1338 } //PAF_ASOT_initPhaseDevice
1340 // -----------------------------------------------------------------------------
1341 // ASOT Initialization Function Helper - Initialization of Audio Frame
1342 //
1343 // Name: PAF_ASOT_initFrame0
1344 // Purpose: Audio Stream Output Task Function for initialization of the Audio
1345 // Frame(s) by memory allocation and loading of data pointers
1346 // and values.
1347 // From: AST Parameter Function -> decodeInfo
1348 // Uses: See code.
1349 // States: x
1350 // Return: 0 on success.
1351 // Source code line number on MEM_calloc failure.
1352 // Source code line number on unsupported option.
1353 // Trace: Message Log "trace" in Debug Project Configuration reports:
1354 // * Memory allocation errors.
1355 // * Unsupported option errors.
1356 //
1358 // MID 314
1359 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
1360 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
1362 Int
1363 PAF_ASOT_initFrame0(
1364 const PAF_ASOT_Params *pP,
1365 const PAF_ASOT_Patchs *pQ,
1366 PAF_ASOT_Config *pAsotCfg,
1367 Int z
1368 )
1369 {
1370 PAF_AST_Config *pAstCfg;
1371 Int as; /* Audio Stream Number (1, 2, etc.) */
1372 Int ch;
1373 //Int aLen;
1374 Int aLen_int=0,aLen_ext=0;
1375 Int aSize = sizeof(PAF_AudioData);
1376 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1377 Int maxFrameLength = pP->maxFramelength;
1378 Int zX;
1379 PAF_AudioData *aBuf_int=NULL;
1380 PAF_AudioData *aBuf_ext=NULL;
1381 XDAS_UInt8 *metadataBuf;
1382 char i;
1383 Error_Block eb;
1385 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1386 as = pAstCfg->as;
1388 // Initialize error block
1389 Error_init(&eb);
1391 // Compute maximum framelength (needed for ARC support)
1392 maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
1393 //aLen = numchan[z] * maxFrameLength;
1394 for (i=0; i < numchan[z]; i++)
1395 {
1396 if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1397 {
1398 aLen_int += maxFrameLength;
1399 }
1400 else
1401 {
1402 aLen_ext += maxFrameLength;
1403 }
1404 }
1406 //
1407 // Initialize audio frame elements directly
1408 //
1409 pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
1410 pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
1411 /// pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
1412 pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
1413 pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
1414 pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
1415 pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1417 //
1418 // Allocate memory for and initialize pointers to audio data buffers
1419 //
1420 // The NUMCHANMASK is used to identify the channels for which data
1421 // buffers can be allocated. Using this mask and switch statement
1422 // rather than some other construct allows efficient code generation,
1423 // providing just the code necessary (with significant savings).
1424 //
1425 if (pP->fxns->bufMemPrint)
1426 {
1427 pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
1428 pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
1429 }
1431 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1433 if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
1434 {
1435 if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb))) //Qin: Add start offset
1436 {
1437 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1438 TRACE_TERSE2(" maxFrameLength: %d. aLen_int*aSize: %d", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize);
1439 SW_BREAKPOINT;
1440 return __LINE__;
1441 }
1442 }
1444 if (aLen_ext*aSize!=0)
1445 {
1446 if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb)))//Qin: Add start offset
1447 {
1448 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1449 TRACE_TERSE2(" maxFrameLength: %d. aLen_ext*aSize: %d", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize);
1450 SW_BREAKPOINT;
1451 return __LINE__;
1452 }
1453 }
1455 TRACE_TERSE3(" maxFrameLength: %d. aLen_int*aSize: %d. aBuf_int: 0x%x", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_int);
1456 TRACE_TERSE3(" maxFrameLength: %d. aLen_ext*aSize: %d. aBuf_ext: 0x%x", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_ext);
1458 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1459 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1460 {
1461 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1462 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1463 SW_BREAKPOINT;
1464 return __LINE__;
1465 }
1467 {
1468 Int i;
1470 #pragma UNROLL(1)
1471 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1472 {
1473 pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
1474 }
1475 }
1477 // MID 314
1478 if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1479 {
1480 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
1481 return __LINE__;
1482 }
1483 else
1484 {
1485 Int j = 0;
1486 Int k = 0;
1487 TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1488 for(i=0;i<numchan[z];i++)
1489 {
1490 char chan = AFChanPtrMap[numchan[z]][i];
1491 if(chan != -1)
1492 {
1493 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1494 {
1495 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
1496 j++;
1497 }
1498 else
1499 {
1500 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1501 k++;
1502 }
1503 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1504 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
1505 }
1506 }
1507 }
1509 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1510 {
1511 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1512 {
1513 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
1514 }
1515 }
1517 //
1518 // Initialize meta data elements
1519 //
1520 pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1521 pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1522 pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1523 pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1524 pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1525 for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1526 {
1527 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1528 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1529 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1530 }
1532 //
1533 // Initialize decoder elements directly
1534 //
1536 for (zX = DECODE1; zX < DECODEN; zX++)
1537 {
1538 if (pP->streamsFromDecodes[zX] == z)
1539 {
1540 #ifdef NOAUDIOSHARE
1541 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1542 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1543 #else /* NOAUDIOSHARE */
1544 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1545 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1546 #endif /* NOAUDIOSHARE */
1547 }
1548 }
1550 return 0;
1551 } //PAF_ASOT_initFrame0
1553 // -----------------------------------------------------------------------------
1554 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1555 // AST Decoding Function - Reinitialization of Audio Frame
1556 //
1557 // Name: PAF_ASOT_initFrame1
1558 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1559 // zation of the Audio Frame(s) by loading of data values of a
1560 // time-varying nature.
1561 // From: audioStream1Task or equivalent
1562 // AST Parameter Function -> decodeInfo
1563 // AST Parameter Function -> decodeDecode
1564 // Uses: See code.
1565 // States: x
1566 // Return: 0.
1567 // Trace: None.
1568 //
1569 Int
1570 PAF_ASOT_initFrame1(
1571 const PAF_ASOT_Params *pP,
1572 const PAF_ASOT_Patchs *pQ,
1573 PAF_ASOT_Config *pAsotCfg,
1574 Int z,
1575 Int apply
1576 )
1577 {
1578 PAF_AST_Config *pAstCfg;
1580 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1582 //
1583 // Reinitialize audio frame elements:
1584 //
1585 // Channel Configurations during sys init = Unknown
1586 // " " during info or decode = None
1587 //
1588 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1589 //
1591 if (apply < 0)
1592 {
1593 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1594 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1595 }
1596 else
1597 {
1598 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1599 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1600 }
1602 if (apply < 1)
1603 {
1604 pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1605 pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
1606 }
1608 return 0;
1609 } //PAF_ASOT_initFrame1
1611 // -----------------------------------------------------------------------------
1612 // ASOT Selection Function - Output Device Selection
1613 //
1614 // Name: PAF_ASOT_selectDevices
1615 // Purpose: Audio Stream Output Task Function for selecting the devices used
1616 // for output.
1617 // From: audioStream1Task or equivalent
1618 // Uses: See code.
1619 // States: x
1620 // Return: Error number in standard form (0 on success).
1621 // Trace: Message Log "trace" in Debug Project Configuration reports:
1622 // * State information as per parent.
1623 //
1624 Int
1625 PAF_ASOT_selectDevices(
1626 const PAF_ASOT_Params *pP,
1627 const PAF_ASOT_Patchs *pQ,
1628 PAF_ASOT_Config *pAsotCfg
1629 )
1630 {
1631 PAF_AST_Config *pAstCfg;
1632 Int as; /* Audio Stream Number (1, 2, etc.) */
1633 Int z; /* input/output counter */
1634 Int errno = 0; /* error number */
1635 Int errme; /* error number, local */
1636 Int device;
1638 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1639 as = pAstCfg->as;
1640 (void)as; // clear compiler warning in case not used with tracing disabled
1642 // Select output devices
1643 for (z=OUTPUT1; z < OUTPUTN; z++)
1644 {
1645 if ((device = pAstCfg->xOut[z].outBufStatus.sioSelect) >= 0)
1646 {
1647 TRACE_VERBOSE2("PAF_ASOT_selectDevices: AS%d: output device %d selecting ...", as+z, device);
1649 /* check for valid index into device array */
1650 if (device >= pQ->devout->n)
1651 {
1652 device = 0; /* treat as device None */
1653 }
1655 errme = pP->fxns->deviceSelect(&pAstCfg->xOut[z].hTxSio, SIO_OUTPUT,
1656 HEAP_ID_OUTBUF, (Ptr)pQ->devout->x[device]);
1657 if (errme)
1658 {
1659 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1660 if (!errno)
1661 {
1662 errno = ASPERR_DEVOUT + errme;
1663 }
1664 pAstCfg->xOut[z].outBufStatus.sioSelect = 0x80;
1665 }
1666 else
1667 {
1668 Int zE;
1670 pAstCfg->xOut[z].outBufStatus.sioSelect = device | 0x80;
1671 // register outBufStatus and encodeStatus pointers with output devices
1672 // This enables proper IEC encapsulation.
1673 if (pAstCfg->xOut[z].hTxSio)
1674 {
1675 // set max # of output buffers (use override if necessary)
1676 if (pAstCfg->xOut[z].outBufStatus.maxNumBufOverride == 0)
1677 {
1678 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1679 (Arg)pP->poutNumBufMap[z]->maxNumBuf);
1680 }
1681 else
1682 {
1683 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1684 (Arg)pAstCfg->xOut[z].outBufStatus.maxNumBufOverride);
1685 }
1687 // register PAF_SIO_IALG object address
1688 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_IALGADDR,
1689 (Arg)pAstCfg->xOut[z].outChainData.head->alg);
1690 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_BUFSTATUSADDR,
1691 (Arg)&pAstCfg->xOut[z].outBufStatus);
1692 for (zE=ENCODE1; zE < ENCODEN; zE++)
1693 {
1694 if (pP->outputsFromEncodes[zE] == z)
1695 {
1696 SIO_ctrl(pAstCfg->xOut[z].hTxSio,
1697 PAF_SIO_CONTROL_SET_ENCSTATUSADDR,
1698 (Arg)&pAstCfg->xEnc[zE].encodeStatus);
1699 break;
1700 }
1701 }
1702 }
1703 }
1704 }
1706 // if device selected and valid then enable stat tracking if
1707 // required and start clocking
1708 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
1709 {
1710 TRACE_VERBOSE0("PAF_ASOT_selectDevices: start SIO clocks");
1711 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
1712 if (errme)
1713 {
1714 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1715 SIO_idle(pAstCfg->xOut[z].hTxSio);
1716 if (!errno)
1717 {
1718 errno = ASPERR_DEVOUT + errme;
1719 }
1720 }
1721 }
1722 }
1724 return errno;
1725 } //PAF_ASOT_selectDevices
1728 // -----------------------------------------------------------------------------
1729 // ASOT Processing Function - Decode Processing
1730 //
1731 // Name: PAF_ASOT_decodeProcessing
1732 // Purpose: Audio Stream Output Task Function for processing audio data.
1733 //
1734 Int
1735 PAF_ASOT_decodeProcessing(
1736 const PAF_ASOT_Params *pP,
1737 const PAF_ASOT_Patchs *pQ,
1738 PAF_ASOT_Config *pAsotCfg
1739 )
1740 {
1741 PAF_AST_Config *pAstCfg;
1742 Int errno; /* error number */
1743 Int getVal;
1744 enum { INIT, STREAM, ENCODE, FINAL, QUIT, OUT_SIO_UPDATE } state;
1745 state = INIT;
1746 errno = 0; /* error number */
1747 Int frame; // (***) FL: formerly -- decoder input frame count
1748 Int block; // decoder output block count / input frame
1749 Int outSioUpdate;
1751 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1753 for (;;)
1754 {
1755 //
1756 // Check forward (ASIT) error here, TBD
1757 //
1760 // Check if any change in output SIO, e.g. from Output shortcut.
1761 // Changes will break FSM and allow Output reconfiguration.
1762 errno = checkOutSio(pP, pAsotCfg, &outSioUpdate);
1763 if (errno < 0)
1764 {
1765 TRACE_TERSE1("PAF_ASOT_decodeProcessing: checkOutSio returned errno = 0x%04x", errno);
1766 break;
1767 }
1768 else if (outSioUpdate)
1769 {
1770 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Change in Output SIO selection");
1771 state = OUT_SIO_UPDATE;
1772 }
1774 // Process commands (encode)
1775 getVal = pP->fxns->encodeCommand(pP, pQ, pAsotCfg);
1776 if (getVal)
1777 {
1778 /* ignore */;
1779 }
1781 // Process state (decode)
1782 switch (state)
1783 {
1784 case INIT: // initial state
1785 gAsopInitCnt++;
1786 Log_info0("TaskAsop: state=INIT");
1788 frame = 0;
1789 block = 0;
1791 #if 0 // FL: moved to PAF_ASOT_initOutProc()
1792 // Reset audio frame pointers to original values
1793 // (may be needed if error occurred).
1794 resetAfPointers(pP, pAstCfg->xStr);
1795 // Reset audio frame meta data elements
1796 resetAfMetadata(pP, pAstCfg->xStr);
1797 #endif
1799 errno = pP->fxns->decodeInit(pP, pQ, pAsotCfg);
1800 if (errno)
1801 {
1802 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1803 errno = ASOP_DP_DECINIT_ERR;
1804 break;
1805 }
1807 //
1808 // Setup output: setCheckRateX, start output
1809 //
1810 // Establish secondary timing
1811 errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, frame, block);
1812 if (errno)
1813 {
1814 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInfo1", errno);
1815 break;
1816 }
1818 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: INIT->STREAM");
1819 state = STREAM;
1820 continue;
1822 case STREAM: // stream state
1823 gAsopStreamCnt++;
1824 Log_info0("TaskAsop: state=STREAM");
1826 errno = pP->fxns->decodeStream(pP, pQ, pAsotCfg, frame, block);
1827 if (errno)
1828 {
1829 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: STREAM. decodeStream err 0x%x", errno);
1830 errno = ASOP_DP_DECSTREAM_ERR;
1831 break;
1832 }
1834 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: STREAM->ENCODE");
1835 state = ENCODE;
1836 continue;
1838 case ENCODE: // encode state
1839 gAsopEncodeCnt++;
1840 Log_info0("TaskAsop: state=ENCODE");
1842 errno = pP->fxns->decodeEncode(pP, pQ, pAsotCfg, frame, block);
1843 if (errno)
1844 {
1845 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: ENCODE. decodeEncode err 0x%x", errno);
1846 errno = ASOP_DP_DECENC_ERR;
1847 break;
1848 }
1850 // Measure cycles in output processing loop.
1851 // Only measures cycles spent in loop.
1852 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS);
1853 gNumPfpAsot1--;
1854 pfpBegin(PFP_ID_ASOT_1, pAsotCfg->taskHandle);
1855 gNumPfpAsot1++;
1857 // (***) FL: do we need this?
1858 // AF pointers come from CB read, any resets occur in Decoder AF.
1859 //
1860 // Reset audio frame pointers to original values
1861 // (may have been adjusted by ARC or the like).
1862 resetAfPointers(pP, pAstCfg->xStr);
1864 // (***) FL: update output (setCheckRateX)
1865 // Contained in INFO2 in combined FSM.
1866 errno = pP->fxns->decodeInfo2(pP, pQ, pAsotCfg, frame, block);
1867 if (errno)
1868 {
1869 TRACE_TERSE1("PAF_ASOT_decodeProcessing: ENCODE break on decodeInfo2. errno 0x%x", errno);
1870 errno = ASOP_DP_DECINFO2_ERR;
1871 break;
1872 }
1874 block++;
1875 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: ENCODE->FINAL");
1876 state = FINAL;
1877 continue;
1879 case FINAL:
1880 gAsopFinalCnt++;
1881 Log_info0("TaskAsop: state=FINAL");
1883 //
1884 // (***) FL: this needs to be fixed.
1885 // (1) Only require selected Output to be in this FSM
1886 // => Dec Status checks aren't valid,
1887 // will probably always exit FSM if only Output running
1888 // (2) Checking Dec Status info asych to input events (maybe ok)
1889 //
1890 // Check for final frame, and if indicated:
1891 // - Update audio flag to cause output buffer flush rather than
1892 // the default truncate in "complete" processing.
1893 // - Exit state machine to "complete" processing.
1894 #if 0
1895 if (pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block))
1896 {
1897 for (z=OUTPUT1; z < OUTPUTN; z++)
1898 {
1899 if ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND)
1900 {
1901 TRACE_VERBOSE0("PAF_ASOT_outputProcessing: state: FINAL: SOUND -> QUIET");
1902 pAstCfg->xOut[z].outBufStatus.audio++; // SOUND -> QUIET
1903 }
1904 }
1905 break;
1906 }
1907 #endif
1908 errno = pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block);
1909 if (errno < 0)
1910 {
1911 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL break. errno 0x%x", errno);
1912 errno = ASOP_DP_DECFINALTEST_ERR;
1913 break;
1914 }
1915 else if (errno == ASOP_DP_CB_DRAINED)
1916 {
1917 // EOS, exit normally
1918 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL normal exit. errno 0x%x", errno);
1919 errno = ASOP_DP_SOK;
1920 break;
1921 }
1923 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: FINAL->STREAM");
1924 state = STREAM;
1925 continue;
1927 case OUT_SIO_UPDATE:
1928 gAsopOutSioUpdateCnt++;
1929 Log_info0("TaskAsop: state=OUT_SIO_UPDATE");
1931 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: OUT_SIO_UPDATE");
1932 errno = ASOP_DP_OUT_SIO_UPDATE;
1933 break;
1935 case QUIT:
1936 gAsopQuitCnt++;
1937 Log_info0("TaskAsop: state=QUIT");
1939 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: QUIT");
1940 errno = ASPERR_QUIT;
1941 break;
1943 default: // unknown state
1944 // Unknown:
1945 // - Set error number registers.
1946 // - Exit state machine to "complete" processing.
1948 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: unknown, 0x%x", state);
1949 errno = ASPERR_UNKNOWNSTATE;
1950 break;
1952 } // End of switch (state).
1954 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Calling decode complete");
1955 if (pP->fxns->decodeComplete(pP, pQ, pAsotCfg, NULL, frame, block))
1956 {
1957 /* ignored? */;
1958 }
1960 //pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
1961 //gNumPfpAsot1--;
1963 //return errno;
1964 break;
1965 } // End of for (;;)
1967 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
1968 gNumPfpAsot1--;
1970 return errno;
1971 }
1973 // -----------------------------------------------------------------------------
1974 // ASOT Decoding Function - Encode Command Processing
1975 //
1976 // Name: PAF_ASOT_encodeCommand
1977 // Purpose: Decoding Function for processing Encode Commands.
1978 // From: AST Parameter Function -> decodeProcessing
1979 // Uses: See code.
1980 // States: x
1981 // Return: 0.
1982 // Trace: Message Log "trace" in Debug Project Configuration reports:
1983 // * Command execution.
1984 // * SIO control errors.
1985 // * Error number macros.
1986 //
1987 Int
1988 PAF_ASOT_encodeCommand(
1989 const PAF_ASOT_Params *pP,
1990 const PAF_ASOT_Patchs *pQ,
1991 PAF_ASOT_Config *pAsotCfg
1992 )
1993 {
1994 PAF_AST_Config *pAstCfg;
1995 Int as; /* Audio Stream Number (1, 2, etc.) */
1996 Int z; /* encode counter */
1997 Int errno = 0; /* error number */
1998 Int zO, zS;
2001 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2002 as = pAstCfg->as;
2004 for (z=ENCODE1; z < ENCODEN; z++)
2005 {
2006 zO = pP->outputsFromEncodes[z];
2007 zS = pP->streamsFromEncodes[z];
2008 if (! (pAstCfg->xEnc[z].encodeStatus.command2 & 0x80))
2009 {
2010 switch (pAstCfg->xEnc[z].encodeStatus.command2)
2011 {
2012 case 0: // command none - process
2013 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2014 break;
2015 case 1: // mute command
2016 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command mute (0x%02x)", as+zS, 1);
2017 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2018 && pAstCfg->xOut[zO].hTxSio
2019 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2020 {
2021 errno = (errno & 0xff) | ASPERR_MUTE;
2022 /* convert to sensical errno */
2023 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (mute)", as+zS);
2024 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2025 }
2026 else
2027 {
2028 pAstCfg->xOut[zO].outBufStatus.audio |= PAF_OB_AUDIO_MUTED;
2029 }
2030 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2031 break;
2032 case 2: // unmute command
2033 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command unmute (0x%02x)", as+zS, 2);
2034 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2035 && pAstCfg->xOut[zO].hTxSio
2036 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2037 {
2038 errno = (errno & 0xff) | ASPERR_MUTE;
2039 /* convert to sensical errno */
2040 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (unmute)", as+zS);
2041 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2042 }
2043 else
2044 {
2045 pAstCfg->xOut[zO].outBufStatus.audio &= ~PAF_OB_AUDIO_MUTED;
2046 }
2047 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2048 break;
2049 default: // command unknown - ignore
2050 break;
2051 }
2052 }
2053 }
2055 ERRNO_RPRT (TaskAsop, errno);
2057 return 0;
2058 } //PAF_ASOT_encodeCommand
2060 //debug -- allow dynamic config
2061 Int16 gStrFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
2063 // Purpose: Decoding Function for reinitializing the decoding process.
2064 Int
2065 PAF_ASOT_decodeInit(
2066 const PAF_ASOT_Params *pP,
2067 const PAF_ASOT_Patchs *pQ,
2068 PAF_ASOT_Config *pAsotCfg
2069 )
2070 {
2071 //PAF_AST_Config *pAstCfg;
2072 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2073 //Int as; /* Audio Stream Number (1, 2, etc.) */
2074 Int z; /* decode/encode counter */
2075 Int errno; /* error number */
2076 //Int zO, zS;
2078 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2079 //as = pAstCfg->as;
2081 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2083 for (z=DECODE1; z < DECODEN; z++)
2084 {
2085 // FRAMELENGTH: pP->frameLength.
2086 // Formerly ASIT, now ASOT but same value (PAF_SYS_FRAMELENGTH).
2087 //
2089 // Initialize decoder output circular buffer for stream reads
2090 //errno = cbInitStreamRead(pCbCtl, z, FRAMELENGTH); // use pP->frameLength from ASOT params
2091 errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
2092 if (errno)
2093 {
2094 TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
2095 SW_BREAKPOINT; // debug
2096 return errno;
2097 }
2099 // Start decoder output circular buffer reads
2100 errno = cbReadStart(pCbCtl, z);
2101 if (errno)
2102 {
2103 TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
2104 SW_BREAKPOINT; // debug
2105 return errno;
2106 }
2108 gCbReadAfErr=0; // reset read circular buffer error count
2109 gDecOpCbRdAfUnd=0; // reset decoder output circular buffer underflow count
2110 gMaxDecOpCbRdAfUnd=0; // reset max decoder output circular buffer underflow count
2111 gMasterCbResetCnt=0; // reset master circular buffer reset count
2113 // FL: debug, log circular buffer control variables
2114 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
2115 }
2117 #if 0 // moved to PAF_ASOT_outputReset()
2118 // TODO: move this to start of this function so that it doesn't affect IO timing
2119 for (z=ENCODE1; z < ENCODEN; z++)
2120 {
2121 zO = pP->outputsFromEncodes[z];
2122 zS = pP->streamsFromEncodes[z];
2123 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2124 {
2125 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2126 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2127 ENC_Handle enc = (ENC_Handle )encAlg;
2128 TRACE_VERBOSE1("AS%d: PAF_ASOT_decodeInit: initializing encode", as+zS);
2129 if (encAlg->fxns->algActivate)
2130 {
2131 encAlg->fxns->algActivate (encAlg);
2132 }
2133 if (enc->fxns->reset)
2134 {
2135 errno = enc->fxns->reset(enc, NULL,
2136 &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus);
2137 if (errno)
2138 {
2139 return errno;
2140 }
2141 }
2142 }
2143 }
2144 #endif
2146 return 0;
2147 }
2149 // -----------------------------------------------------------------------------
2150 // ASOT Decoding Function - Info Processing, Initial
2151 //
2152 // Name: PAF_ASOT_decodeInfo1
2153 // Purpose: Decoding Function for processing information in a manner that
2154 // is unique to initial frames of input data.
2155 // From: AST Parameter Function -> decodeProcessing
2156 // Uses: See code.
2157 // States: x
2158 // Return: Error number in standard or SIO form (0 on success).
2159 // Trace: Message Log "trace" in Debug Project Configuration reports:
2160 // * State information as per parent.
2161 //
2162 Int
2163 PAF_ASOT_decodeInfo1(
2164 const PAF_ASOT_Params *pP,
2165 const PAF_ASOT_Patchs *pQ,
2166 PAF_ASOT_Config *pAsotCfg,
2167 Int frame,
2168 Int block
2169 )
2170 {
2171 //PAF_AST_Config *pAstCfg;
2172 //Int z; /* decode/encode counter */
2173 Int errno; /* error number */
2175 #if 0 // moved to PAF_ASOT_outputInfo1()
2176 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2178 // run the chain of ASP's on the stream.
2179 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
2180 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2181 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame);
2182 if (errno)
2183 {
2184 TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
2185 return errno;
2186 }
2188 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
2189 for (z=ENCODE1; z < ENCODEN; z++)
2190 {
2191 Int zO = pP->outputsFromEncodes[z];
2192 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2193 {
2194 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2195 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2196 ENC_Handle enc = (ENC_Handle )encAlg;
2198 if (enc->fxns->info)
2199 {
2200 errno = enc->fxns->info(enc, NULL,
2201 &pAstCfg->xEnc[z].encodeControl,
2202 &pAstCfg->xEnc[z].encodeStatus);
2203 if (errno)
2204 {
2205 TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
2206 return errno;
2207 }
2208 }
2209 }
2210 }
2211 #endif
2213 errno = pP->fxns->setCheckRateX(pP, pQ, pAsotCfg, 0);
2214 if (errno)
2215 {
2216 // ignore if rateX has changed since we haven't, but are about to,
2217 // start the output. If we didn't ignore this case then the state machine
2218 // would restart unnecessarily, e.g. in the case of SRC, resulting in
2219 // added latency.
2220 if (errno != ASPERR_INFO_RATECHANGE)
2221 {
2222 TRACE_TERSE1("PAF_ASOT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
2223 return errno;
2224 }
2225 else
2226 {
2227 TRACE_TERSE0("PAF_ASOT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
2228 }
2229 }
2231 errno = pP->fxns->startOutput(pP, pQ, pAsotCfg);
2232 if (errno)
2233 {
2234 if (errno == 0x105)
2235 {
2236 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
2237 }
2238 else
2239 {
2240 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
2241 }
2242 return errno;
2243 }
2245 return 0;
2246 }
2248 // -----------------------------------------------------------------------------
2249 // ASOT Decoding Function - Info Processing, Subsequent
2250 //
2251 // Name: PAF_ASOT_decodeInfo2
2252 // Purpose: Decoding Function for processing information in a manner that
2253 // is unique to frames of input data other than the initial one.
2254 // From: AST Parameter Function -> decodeProcessing
2255 // Uses: See code.
2256 // States: x
2257 // Return: Error number in standard form (0 on success).
2258 // Trace: None.
2259 //
2260 Int
2261 PAF_ASOT_decodeInfo2(
2262 const PAF_ASOT_Params *pP,
2263 const PAF_ASOT_Patchs *pQ,
2264 PAF_ASOT_Config *pAsotCfg,
2265 Int frame,
2266 Int block
2267 )
2268 {
2269 //PAF_AST_Config *pAstCfg;
2270 Int errno;
2273 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2275 errno = pP->fxns->setCheckRateX (pP, pQ, pAsotCfg, 1);
2276 TRACE_VERBOSE1("PAF_ASOT_decodeInfo2: return 0x%x", errno);
2277 return errno;
2278 } //PAF_ASOT_decodeInfo2
2281 PAF_AST_DecOpCircBufStats gCbStats; // FL: debug
2282 // -----------------------------------------------------------------------------
2283 // ASOT Decoding Function - Stream Processing
2284 //
2285 // Name: PAF_ASOT_decodeStream
2286 // Purpose: Decoding Function for processing of audio frame data by the
2287 // ASP Algorithms.
2288 // From: AST Parameter Function -> decodeProcessing
2289 // Uses: See code.
2290 // States: x
2291 // Return: Error number in standard form (0 on success).
2292 // Trace: Message Log "trace" in Debug Project Configuration reports:
2293 // * State information as per parent/child.
2294 //
2295 Int
2296 PAF_ASOT_decodeStream(
2297 const PAF_ASOT_Params *pP,
2298 const PAF_ASOT_Patchs *pQ,
2299 PAF_ASOT_Config *pAsotCfg,
2300 Int frame,
2301 Int block
2302 )
2303 {
2304 PAF_AST_Config *pAstCfg;
2305 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2306 Int z; /* decode/stream counter */
2307 PAF_AudioFrame *pAfRd;
2308 Int cbErrno;
2309 PAF_AST_DecOpCircBufStats cbStats; /* circular buffer statistics */
2310 Int errno;
2313 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2315 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2317 for (z=DECODE1; z < DECODEN; z++)
2318 {
2319 Int zS = pP->streamsFromDecodes[z];
2321 //
2322 // Read decoder output circular buffer
2323 //
2324 pAfRd = pAstCfg->xStr[zS].pAudioFrame;
2325 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2326 cbErrno = cbReadAf(pCbCtl, z, pAfRd);
2327 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2328 if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_READ_UNDERFLOW))
2329 {
2330 gCbReadAfErr++;
2331 TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
2332 //SW_BREAKPOINT; // FL: debug
2333 return cbErrno;
2334 }
2336 // Handle underflows
2337 if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
2338 {
2339 // FL: some number of underflows alway occur on start of stream when ASOT only depends on configured Output.
2340 // DDP: ~2 underflows
2341 // MAT-THD: ~16 underflows
2342 // Need to check behavior of cbReset().
2343 // Need to check behavior on exit/re-entry into Output processing.
2345 gDecOpCbRdAfUnd++; // increment circular buffer underflow count
2346 if (gDecOpCbRdAfUnd >= DEC_OP_CB_RDAF_UND_THR)
2347 {
2348 // Underflow count above threshold.
2349 // (1) set max underflow count to threshold
2350 // (2) reset underflow count
2351 // (3) reset circular buffer
2353 gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
2354 gDecOpCbRdAfUnd = 0; // reset underflow count
2356 // Reset circular buffer
2357 cbReset(pCbCtl, z);
2358 gMasterCbResetCnt++; // increment master circular buffer reset count
2359 Log_info0("ASOT:cbReset");
2361 return cbErrno;
2362 }
2363 }
2364 else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbRdAfUnd > 0))
2365 {
2366 // No underflow detected.
2367 // update max underflow count,
2368 // reset underflow count
2370 // update max underflow count
2371 if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
2372 {
2373 gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
2374 }
2375 gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
2376 }
2377 //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2378 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2379 Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2381 #if 0 // (***) FL: shows timing of CB read
2382 // (***) debug // B8
2383 {
2384 static Uint8 toggleState = 0;
2385 if (toggleState == 0)
2386 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2387 else
2388 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2389 toggleState = ~(toggleState);
2390 }
2391 #endif
2393 // FL: debug
2394 // Get circular buffer statistics (debug)
2395 //cbGetStats(pCbCtl, z, &cbStats);
2396 cbGetStats(pCbCtl, z, &gCbStats);
2398 // FL: debug
2399 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
2400 //if (capAfWrite(pAfRd, 0) != CAP_AF_SOK)
2401 //{
2402 // Log_info0("capAfWrite() error");
2403 //}
2404 }
2406 TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
2407 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2408 PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
2409 if (errno)
2410 {
2411 TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
2412 return errno;
2413 }
2415 return 0;
2417 } //PAF_ASOT_decodeStream
2419 // -----------------------------------------------------------------------------
2420 // ASOT Decoding Function - Encode Processing
2421 //
2422 // Name: PAF_ASOT_decodeEncode
2423 // Purpose: Decoding Function for processing of audio frame data by the
2424 // Encode Algorithm.
2425 // From: AST Parameter Function -> decodeProcessing
2426 // Uses: See code.
2427 // States: x
2428 // Return: Error number in standard or SIO form (0 on success).
2429 // Trace: Message Log "trace" in Debug Project Configuration reports:
2430 // * State information as per parent.
2431 //
2432 Int
2433 PAF_ASOT_decodeEncode(
2434 const PAF_ASOT_Params *pP,
2435 const PAF_ASOT_Patchs *pQ,
2436 PAF_ASOT_Config *pAsotCfg,
2437 Int frame,
2438 Int block
2439 )
2440 {
2441 PAF_AST_Config *pAstCfg;
2442 Int as; /* Audio Stream Number (1, 2, etc.) */
2443 Int z; /* encode/output counter */
2444 Int errno; /* error number */
2445 Int zX, zE, zS;
2446 UInt32 curTime;
2448 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2449 as = pAstCfg->as;
2451 // Await output buffers (but not first time)
2452 for (z=OUTPUT1; z < OUTPUTN; z++)
2453 {
2454 // determine encoder associated with this output
2455 zE = z;
2456 for (zX = ENCODE1; zX < ENCODEN; zX++)
2457 {
2458 if (pP->outputsFromEncodes[zX] == z)
2459 {
2460 zE = zX;
2461 break;
2462 }
2463 }
2464 zS = pP->streamsFromEncodes[zE];
2466 if (pAstCfg->xOut[z].hTxSio)
2467 {
2468 // update length (e.g. ARC may have changed)
2469 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
2470 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2471 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- idle", as+zS, block);
2472 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2473 errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
2474 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2475 if (errno < 0)
2476 {
2477 SIO_idle(pAstCfg->xOut[z].hTxSio);
2478 TRACE_TERSE2("PAF_ASOT_decodeEncode: AS%d: SIO_reclaim returns error %d", as+zS, -errno);
2479 return -errno; // SIO negates error codes
2480 }
2481 // TODO: use pC->xOut[z].pOutBuf in following ->encode call
2483 #if 0 // (***) FL: shows timing of Output Rx SIO reclaim
2484 // (***) debug // B8
2485 {
2486 static Uint8 toggleState = 0;
2487 if (toggleState == 0)
2488 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2489 else
2490 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2491 toggleState = ~(toggleState);
2492 }
2493 #endif
2495 gAsopTxSioReclaimCnt++;
2497 //
2498 // Simulate Tx SIO_reclaim() pend
2499 //
2500 //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
2501 curTime = Clock_getTicks();
2502 //System_printf("System time in TaskAsipFxn Tx audio = %lu\n", (ULong)curTime);
2503 //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
2504 }
2505 else
2506 {
2507 TRACE_VERBOSE2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- idle <ignored>", as+zS, block);
2508 }
2509 }
2511 // Encode data
2512 for (z=ENCODE1; z < ENCODEN; z++)
2513 {
2514 Int zO = pP->outputsFromEncodes[z];
2515 Int zS = pP->streamsFromEncodes[z];
2516 (void)zS; // clear compiler warning in case not used with tracing disabled
2517 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2518 {
2519 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2520 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2521 ENC_Handle enc = (ENC_Handle )encAlg;
2522 if (select != pAstCfg->xEnc[z].encodeControl.encActive)
2523 {
2524 pAstCfg->xEnc[z].encodeControl.encActive = select;
2525 TRACE_TERSE0("PAF_ASOT_decodeEncode: return error");
2526 return (-1);
2527 }
2528 TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- encode", as+zS, block);
2530 // (MID 1933) temp. workaround for PCE2
2531 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
2533 /*
2534 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2535 {
2536 PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
2537 int *wp;
2538 wp = (int*)pAudioFrame->data.sample[0];
2539 TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
2540 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
2541 wp = (int*)pAudioFrame->data.sample[1];
2542 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
2543 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
2544 wp = (int*)pAudioFrame->data.sample[2];
2545 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
2546 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
2547 }
2548 #endif
2549 */
2551 if (enc->fxns->encode)
2552 {
2553 pAstCfg->xEnc[z].encodeOutStruct.bypassFlag =
2554 pP->z_pEncodeStatus[z]->encBypass;
2555 errno = enc->fxns->encode(enc, NULL,
2556 &pAstCfg->xEnc[z].encodeInStruct,
2557 &pAstCfg->xEnc[z].encodeOutStruct);
2558 if (errno)
2559 {
2560 if (errno != PCEERR_OUTPUT_POINTERNULL)
2561 {
2562 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error %d line %d", errno);
2563 return errno;
2564 }
2565 }
2566 /* #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2567 else
2568 {
2569 int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
2570 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
2571 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
2572 }
2573 #endif
2574 */
2575 }
2576 }
2577 else
2578 {
2579 TRACE_VERBOSE2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- encode <ignored>",
2580 as+pP->streamsFromEncodes[z], block);
2581 }
2582 }
2584 // Transmit data
2585 for (z=OUTPUT1; z < OUTPUTN; z++)
2586 {
2587 // determine encoder associated with this output
2588 zE = z;
2589 for (zX = ENCODE1; zX < ENCODEN; zX++)
2590 {
2591 if (pP->outputsFromEncodes[zX] == z)
2592 {
2593 zE = zX;
2594 break;
2595 }
2596 }
2597 zS = pP->streamsFromEncodes[zE];
2599 if (pAstCfg->xOut[z].hTxSio)
2600 {
2601 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
2602 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2603 errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2604 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
2605 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2606 if (errno)
2607 {
2608 SIO_idle(pAstCfg->xOut[z].hTxSio);
2609 if (errno == 0x105) // 0x105 == RINGIO_EBUFFULL
2610 {
2611 // statStruct_LogFullRing(STATSTRUCT_AS1_F2);
2612 TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
2613 }
2614 if (errno > 0)
2615 {
2616 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error 0x%x line %d", errno);
2617 return (ASPERR_ISSUE + (z << 4));
2618 }
2619 else if (errno < 0)
2620 {
2621 TRACE_TERSE1("PAF_ASOT_decodeEncode: return neg error 0x%x line %d", -errno);
2622 return -errno; // SIO negates error codes
2623 }
2624 }
2625 if (errno > 0)
2626 {
2627 return (ASPERR_ISSUE + (z << 4));
2628 }
2629 else if (errno < 0)
2630 {
2631 return -errno; // SIO negates error codes
2632 }
2633 }
2634 else
2635 {
2636 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output <ignored>", as+zS, block);
2637 }
2638 }
2640 return 0;
2641 } //PAF_ASOT_decodeEncode
2643 // -----------------------------------------------------------------------------
2644 // ASOT Decoding Function - Stream-Final Processing
2645 //
2646 // Name: PAF_ASOT_decodeComplete
2647 // Purpose: Decoding Function for terminating the decoding process.
2648 // From: AST Parameter Function -> decodeProcessing
2649 // Uses: See code.
2650 // States: x
2651 // Return: 0.
2652 // Trace: Message Log "trace" in Debug Project Configuration reports:
2653 // * State information as per parent.
2654 //
2655 Int
2656 PAF_ASOT_decodeComplete(
2657 const PAF_ASOT_Params *pP,
2658 const PAF_ASOT_Patchs *pQ,
2659 PAF_ASOT_Config *pAsotCfg,
2660 ALG_Handle decAlg[],
2661 Int frame,
2662 Int block
2663 )
2664 {
2665 PAF_AST_Config *pAstCfg;
2666 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2667 Int as; /* Audio Stream Number (1, 2, etc.) */
2668 Int z; /* decode/encode counter */
2669 Int errno; /* error number */
2672 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2673 as = pAstCfg->as;
2674 (void)as; // clear compiler warning in case not used with tracing disabled
2676 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2678 for (z=DECODE1; z < DECODEN; z++)
2679 {
2680 // Stop decoder output circular buffer reads
2681 errno = cbReadStop(pCbCtl, z);
2682 if (errno)
2683 {
2684 TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
2685 SW_BREAKPOINT; // FL: debug
2686 return errno;
2687 }
2688 // FL: debug
2689 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeComplete:cbReadStop");
2690 }
2692 pP->fxns->streamChainFunction(pP, pQ, pAsotCfg, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
2694 for (z=ENCODE1; z < ENCODEN; z++)
2695 {
2696 Int zO = pP->outputsFromEncodes[z];
2697 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2698 {
2699 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2700 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2701 #ifdef PAF_ASP_FINAL
2702 ENC_Handle enc = (ENC_Handle)encAlg;
2703 #endif /* PAF_ASP_FINAL */
2704 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode", as+z);
2705 #ifdef PAF_ASP_FINAL
2706 if (enc->fxns->final)
2707 enc->fxns->final(enc, NULL, &pAstCfg->xEnc[z].encodeControl,
2708 &pAstCfg->xEnc[z].encodeStatus);
2709 #endif /* PAF_ASP_FINAL */
2710 if (encAlg->fxns->algDeactivate)
2711 {
2712 encAlg->fxns->algDeactivate(encAlg);
2713 }
2714 }
2715 else
2716 {
2717 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
2718 }
2719 }
2721 // wait for remaining data to be output
2722 pP->fxns->stopOutput(pP, pQ, pAsotCfg);
2724 return 0;
2725 } //PAF_ASOT_decodeComplete
2727 // -----------------------------------------------------------------------------
2728 // ASOT Decoding Function Helper - SIO Driver Start
2729 //
2730 // Name: PAF_ASOT_startOutput
2731 // Purpose: Decoding Function for initiating output.
2732 // From: AST Parameter Function -> decodeInfo1
2733 // Uses: See code.
2734 // States: x
2735 // Return: Error number in standard or SIO form (0 on success).
2736 // Trace: Message Log "trace" in Debug Project Configuration reports:
2737 // * State information as per parent.
2738 // * SIO control errors.
2739 //
2740 #define DEC_OUTNUMBUF_MAP(X) \
2741 pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
2743 Int
2744 PAF_ASOT_startOutput(
2745 const PAF_ASOT_Params *pP,
2746 const PAF_ASOT_Patchs *pQ,
2747 PAF_ASOT_Config *pAsotCfg
2748 )
2749 {
2750 PAF_AST_Config *pAstCfg;
2751 Int as; /* Audio Stream Number (1, 2, etc.) */
2752 Int z; /* output counter */
2753 Int errno,nbufs; /* error number */
2754 Int zE, zS, zX;
2755 Int zMD;
2756 PAF_SIO_IALG_Obj *pObj;
2757 PAF_SIO_IALG_Config *pAlgConfig;
2760 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2761 as = pAstCfg->as;
2762 zMD = pAstCfg->masterDec;
2764 for (z=OUTPUT1; z < OUTPUTN; z++)
2765 {
2766 if (pAstCfg->xOut[z].hTxSio)
2767 {
2768 // determine associated encoder and stream
2769 zE = z;
2770 zS = z;
2771 for (zX = ENCODE1; zX < ENCODEN; zX++)
2772 {
2773 if (pP->outputsFromEncodes[zX] == z)
2774 {
2775 zE = zX;
2776 zS = pP->streamsFromEncodes[zE];
2777 break;
2778 }
2779 }
2781 // Set sample count so that DOB knows how much data to send
2782 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
2783 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2785 if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
2786 {
2787 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
2788 pAlgConfig = &pObj->config;
2789 memset(pAstCfg->xOut[z].outBufConfig.base.pVoid, 0xAA,
2790 pAlgConfig->pMemRec[0].size);
2791 }
2793 // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
2794 // decoder. How should we handle the sourceProgram for multiple decoders?
2795 // Override as needed
2796 nbufs = DEC_OUTNUMBUF_MAP(pAstCfg->xDec[zMD].decodeStatus.sourceProgram);
2797 if (pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram] > 0)
2798 {
2799 nbufs = pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram];
2800 }
2801 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
2803 if (errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2804 &pAstCfg->xOut[z].outBufConfig, sizeof(pAstCfg->xOut[z].outBufConfig), 0))
2805 {
2806 SIO_idle(pAstCfg->xOut[z].hTxSio);
2807 TRACE_TERSE2("PAF_ASOT_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
2808 return errno;
2809 }
2811 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
2812 (errno = SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2813 {
2814 errno = (errno & 0xff) | ASPERR_MUTE;
2815 /* convert to sensical errno */
2816 TRACE_TERSE2("as1-f2: PAF_ASOT_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
2817 return (errno);
2818 }
2819 else
2820 {
2821 pAstCfg->xOut[z].outBufStatus.audio
2822 = (pAstCfg->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
2823 }
2825 TRACE_VERBOSE1("PAF_ASOT_startOutput: AS%d: output started", as+zS);
2826 }
2827 }
2829 return 0;
2830 } //PAF_ASOT_startOutput
2832 // -----------------------------------------------------------------------------
2833 // ASOT Decoding Function Helper - SIO Driver Stop
2834 //
2835 // Name: PAF_ASOT_stopOutput
2836 // Purpose: Decoding Function for terminating output.
2837 // From: AST Parameter Function -> decodeProcessing
2838 // AST Parameter Function -> decodeComplete
2839 // Uses: See code.
2840 // States: x
2841 // Return: Error number in standard or SIO form (0 on success).
2842 // Trace: Message Log "trace" in Debug Project Configuration reports:
2843 // * SIO control errors.
2844 //
2845 Int
2846 PAF_ASOT_stopOutput(
2847 const PAF_ASOT_Params *pP,
2848 const PAF_ASOT_Patchs *pQ,
2849 PAF_ASOT_Config *pAsotCfg
2850 )
2851 {
2852 PAF_AST_Config *pAstCfg;
2853 Int as; /* Audio Stream Number (1, 2, etc.) */
2854 Int z; /* output counter */
2855 Int errno = 0, getVal;
2856 Int zS, zX;
2857 PAF_SIO_IALG_Obj *pObj;
2858 PAF_SIO_IALG_Config *pAlgConfig;
2860 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2861 as = pAstCfg->as;
2862 (void)as; // clear compiler warning in case not used with tracing disabled
2864 for (z=OUTPUT1; z < OUTPUTN; z++)
2865 {
2866 if (pAstCfg->xOut[z].hTxSio)
2867 {
2868 // determine associated encoder and stream
2869 zS = z;
2870 (void)zS;
2871 for (zX = ENCODE1; zX < ENCODEN; zX++)
2872 {
2873 if (pP->outputsFromEncodes[zX] == z)
2874 {
2875 zS = pP->streamsFromEncodes[zX];
2876 break;
2877 }
2878 }
2880 // Mute output before audio data termination in the usual case,
2881 // where such termination is due to decode error or user command.
2882 // Identification of this as the usual case is provided by the
2883 // "decode processing" state machine.
2884 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
2885 ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND) &&
2886 (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2887 {
2888 if (!errno)
2889 {
2890 errno = (getVal & 0xff) | ASPERR_MUTE;
2891 /* convert to sensical errno */
2892 }
2893 TRACE_VERBOSE1("PAF_ASOT_stopOutput: AS%d: SIO control failed (mute)", as+zS);
2894 }
2896 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- begin PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
2898 // Terminate audio data output, truncating (ignore) or flushing
2899 // (play out) final samples as per (1) control register set by
2900 // the user and (2) the type of audio data termination:
2902 #if 0
2903 // This form is not used because driver support for truncating
2904 // data is not supported for internal clocks, although it is
2905 // for external clocks.
2906 getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
2907 pC->xOut[z].outBufStatus.flush
2908 & (pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
2909 ? 1 : 0);
2910 /* UNTESTED */
2911 #else
2912 // This form should be used when driver support for truncating
2913 // data is supported for both internal and external clocks.
2914 getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
2915 pAstCfg->xOut[z].outBufStatus.flush ? 1 :
2916 (pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
2917 ? 1 : 0);
2918 /* TESTED */
2919 #endif
2921 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- after PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
2923 if (!errno)
2924 {
2925 errno = getVal;
2926 }
2928 // Mute output after audio data termination in a special case,
2929 // where such termination is due to processing of a final frame
2930 // or user command. Identification of this as a special case is
2931 // provided by the "decode processing" state machine.
2932 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
2933 ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH) &&
2934 (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2935 {
2936 if (!errno)
2937 {
2938 errno = (getVal & 0xff) | ASPERR_MUTE;
2939 /* convert to sensical errno */
2940 }
2941 TRACE_VERBOSE1("as1-f2: PAF_ASOT_stopOutput: AS%d: SIO control failed (mute)", as+zS);
2942 }
2944 pAstCfg->xOut[z].outBufStatus.audio &= ~0x0f;
2946 // zero output buffers
2947 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
2948 pAlgConfig = &pObj->config;
2949 memset (pAstCfg->xOut[z].outBufConfig.base.pVoid, 0, pAlgConfig->pMemRec[0].size);
2950 } //pAstCfg->xOut[z].hTxSio
2951 }//OUTPUT
2953 return errno;
2954 } //PAF_ASOT_stopOutput
2956 UInt32 gNumRateXCalc1=0;
2957 UInt32 gNumRateXCalc2=0;
2958 UInt32 gNumDobErrRateChange=0;
2959 Int gCheck[100];
2960 float gRateI[100];
2961 float gRateO[100];
2962 float gRateX[100];
2965 // -----------------------------------------------------------------------------
2966 // ASOT Decoding Function Helper - SIO Driver Change
2967 //
2968 // Name: PAF_ASOT_setCheckRateX
2969 // Purpose: Decoding Function for reinitiating output.
2970 // From: AST Parameter Function -> decodeInfo1
2971 // AST Parameter Function -> decodeInfo2
2972 // Uses: See code.
2973 // States: x
2974 // Return: Error number in standard form (0 on success).
2975 // Trace: None.
2976 //
2978 /* 0: set, 1: check, unused for now. --Kurt */
2979 Int
2980 PAF_ASOT_setCheckRateX(
2981 const PAF_ASOT_Params *pP,
2982 const PAF_ASOT_Patchs *pQ,
2983 PAF_ASOT_Config *pAsotCfg,
2984 Int check
2985 )
2986 {
2987 PAF_AST_Config *pAstCfg;
2988 float rateX;
2989 PAF_SampleRateHz rateO /* std */, rateI /* inv */;
2990 Int z; /* output counter */
2991 Int zx; /* output re-counter */
2992 Int getVal;
2993 int inputRate, inputCount, outputRate, outputCount;
2994 Int zMD;
2995 Int zMI;
2996 Int zMS;
2997 Int zE, zX;
2999 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3000 zMD = pAstCfg->masterDec;
3001 zMS = pAstCfg->masterStr;
3002 zMI = pP->zone.master;
3004 inputRate = pAstCfg->xInp[zMI].inpBufStatus.sampleRateStatus;
3005 inputCount = pAstCfg->xDec[zMD].decodeStatus.frameLength;
3006 rateI = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz
3007 (pAstCfg->xStr[zMS].pAudioFrame, inputRate, PAF_SAMPLERATEHZ_INV);
3009 for (z=OUTPUT1; z < OUTPUTN; z++)
3010 {
3011 if (pAstCfg->xOut[z].hTxSio && (pAstCfg->xOut[z].outBufStatus.clock & 0x01))
3012 {
3013 // determine associated encoder
3014 zE = z;
3015 for (zX = ENCODE1; zX < ENCODEN; zX++)
3016 {
3017 if (pP->outputsFromEncodes[zX] == z)
3018 {
3019 zE = zX;
3020 break;
3021 }
3022 }
3024 outputRate = pAstCfg->xEnc[zE].encodeStatus.sampleRate;
3025 outputCount = pAstCfg->xEnc[zE].encodeStatus.frameLength;
3026 rateO = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz
3027 (pAstCfg->xStr[zMS].pAudioFrame, outputRate, PAF_SAMPLERATEHZ_STD);
3028 if ((rateI > 0) && (rateO > 0))
3029 {
3030 rateX = rateO /* std */ * rateI /* inv */;
3031 }
3032 else if (inputCount != 0)
3033 {
3034 rateX = (float )outputCount / inputCount;
3035 }
3036 else
3037 {
3038 return ASPERR_INFO_RATERATIO;
3039 }
3041 getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_RATEX, (Arg)&rateX);
3042 if (getVal == DOBERR_RATECHANGE)
3043 {
3044 for (zx=OUTPUT1; zx < OUTPUTN; zx++)
3045 {
3046 if (pAstCfg->xOut[zx].hTxSio)
3047 {
3048 SIO_idle (pAstCfg->xOut[zx].hTxSio);
3049 }
3050 }
3052 // this forces an exit from the calling state machine which will
3053 // eventually call startOutput which calls setCheckRateX for all outputs
3054 // and so it is ok, in the presence of a rate change on any output, to
3055 // exit this loop /function early.
3056 return ASPERR_INFO_RATECHANGE;
3057 }
3058 else if (getVal != SYS_OK)
3059 {
3060 return ((getVal & 0xff) | ASPERR_RATE_CHECK);
3061 }
3062 }
3063 }
3065 return 0;
3066 } //PAF_ASOT_setCheckRateX
3068 // -----------------------------------------------------------------------------
3069 // ASOT Decoding Function Helper - Chain Processing
3070 //
3071 // Name: PAF_ASOT_streamChainFunction
3072 // Purpose: Common Function for processing algorithm chains.
3073 // From: AST Parameter Function -> decodeInfo1
3074 // AST Parameter Function -> decodeStream
3075 // AST Parameter Function -> decodeComplete
3076 // Uses: See code.
3077 // States: x
3078 // Return: Error number in standard form (0 on success).
3079 // Trace: Message Log "trace" in Debug Project Configuration reports:
3080 // * State information as per parent.
3081 //
3082 Int
3083 PAF_ASOT_streamChainFunction(
3084 const PAF_ASOT_Params *pP,
3085 const PAF_ASOT_Patchs *pQ,
3086 PAF_ASOT_Config *pAsotCfg,
3087 Int iChainFrameFxns,
3088 Int abortOnError,
3089 Int logArg
3090 )
3091 {
3092 PAF_AST_Config *pAstCfg;
3093 Int as; /* Audio Stream Number (1, 2, etc.) */
3094 Int z; /* stream counter */
3095 Int errno; /* error number */
3096 Int dFlag, eFlag, gear;
3097 Int zX;
3098 Int zS;
3100 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3101 as = pAstCfg->as;
3102 (void)as; // clear compiler warning in case not used with tracing disabled
3104 for (zS = STREAM1; zS < STREAMN; zS++)
3105 {
3106 z = pP->streamOrder[zS]; // Select stream order from streamOrder parameter - MID 788
3108 // apply stream
3109 // unless the stream is associated with a decoder and it is not running
3110 // or
3111 // unless the stream is associated with an encoder and it is not running
3112 // Also gear control only works for streams with an associated decoder
3113 // if no such association exists then gear 0 (All) is used
3114 dFlag = 1;
3115 gear = 0;
3116 for (zX = DECODE1; zX < DECODEN; zX++) {
3117 if (pP->streamsFromDecodes[zX] == z) {
3118 dFlag = pAstCfg->xDec[zX].decodeStatus.mode;
3119 gear = pAstCfg->xDec[zX].decodeStatus.aspGearStatus;
3120 break;
3121 }
3122 }
3123 eFlag = 1;
3124 for (zX = ENCODE1; zX < ENCODEN; zX++) {
3125 if (pP->streamsFromEncodes[zX] == z) {
3126 eFlag = pAstCfg->xEnc[zX].encodeStatus.mode;
3127 break;
3128 }
3129 }
3131 if (dFlag && eFlag) {
3132 PAF_ASP_Chain *chain = pAstCfg->xStr[z].aspChain[gear];
3133 PAF_AudioFrame *frame = pAstCfg->xStr[z].pAudioFrame;
3134 Int (*func) (PAF_ASP_Chain *, PAF_AudioFrame *) =
3135 chain->fxns->chainFrameFunction[iChainFrameFxns];
3137 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
3138 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (reset)"
3139 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
3140 ? "PAF_ASOT_streamChainFunction: AS%d: processing block %d -- audio stream (apply)"
3141 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
3142 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (final)"
3143 : "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (?????)",
3144 as+z, logArg);
3145 errno = (*func) (chain, frame);
3146 TRACE_VERBOSE2("PAF_ASOT_streamChainFunction: AS%d: errno 0x%x.",
3147 as+z, errno);
3149 if (errno && abortOnError)
3150 return errno;
3151 }
3152 else {
3153 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
3154 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (reset) <ignored>"
3155 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
3156 ? "PAF_ASOT_streamChainFunction: AS%d: processing block %d -- audio stream (apply) <ignored>"
3157 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
3158 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (final) <ignored>"
3159 : "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (?????) <ignored>",
3160 as+z, logArg);
3161 }
3163 /*
3164 {
3165 void dp_tracePAF_Data(float *lBuf, float *rBuf, int count);
3166 PAF_AudioFrameData *afd;
3167 float ** afPtr;
3169 afd = &(pC->xStr->pAudioFrame->data);
3170 afPtr = (float**)afd->sample;
3171 dp_tracePAF_Data(afPtr[4], afPtr[5], 256);
3173 }
3174 */
3176 }
3178 return 0;
3179 } //PAF_ASOT_streamChainFunction
3181 /* Check if at least one output selected */
3182 static Int checkOutSel(
3183 const PAF_ASOT_Params *pP,
3184 PAF_ASOT_Config *pAsotCfg,
3185 Int *pOutSel
3186 )
3187 {
3188 PAF_AST_Config *pAstCfg;
3189 Int outSel;
3190 Int z;
3192 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3194 outSel = 0;
3195 for (z=OUTPUT1; z < OUTPUTN; z++)
3196 {
3197 if (pAstCfg->xOut[z].hTxSio)
3198 {
3199 outSel = 1;
3200 break;
3201 }
3202 }
3204 *pOutSel = outSel;
3206 return ASOP_SOK;
3207 }
3209 /* Check if at least one output sio changed */
3210 static Int checkOutSio(
3211 const PAF_ASOT_Params *pP,
3212 PAF_ASOT_Config *pAsotCfg,
3213 Int *pOutSioUpdate
3214 )
3215 {
3216 PAF_AST_Config *pAstCfg;
3217 Int outSioUpdate;
3218 Int z;
3220 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3222 outSioUpdate = 0;
3223 for (z=OUTPUT1; z < OUTPUTN; z++)
3224 {
3225 if (pAstCfg->xOut[z].outBufStatus.sioSelect >= 0)
3226 {
3227 outSioUpdate = 1;
3228 break;
3229 }
3230 }
3232 *pOutSioUpdate = outSioUpdate;
3234 return ASOP_SOK;
3235 }
3237 // Reset audio frames
3238 static Void resetAfs(
3239 const PAF_ASOT_Params *pP,
3240 PAF_AST_Stream *xStr
3241 )
3242 {
3243 // Reset audio frame pointers to original values
3244 // (may be needed if error occurred).
3245 resetAfPointers(pP, xStr);
3246 // Reset audio frame meta data elements
3247 resetAfMetadata(pP, xStr);
3248 }
3250 // Reset audio frame pointers to original values
3251 static Void resetAfPointers(
3252 const PAF_ASOT_Params *pP,
3253 PAF_AST_Stream *xStr
3254 )
3255 {
3256 Int z;
3257 Int ch;
3259 // Reset audio frame pointers to original values
3260 for (z = STREAM1; z < STREAMN; z++)
3261 {
3262 for (ch = PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
3263 {
3264 if (xStr[z].audioFrameChannelPointers[ch])
3265 {
3266 xStr[z].audioFrameChannelPointers[ch] =
3267 xStr[z].origAudioFrameChannelPointers[ch];
3268 }
3269 }
3270 }
3271 }
3273 // Reset audio frame meta data elements
3274 static Void resetAfMetadata(
3275 const PAF_ASOT_Params *pP,
3276 PAF_AST_Stream *xStr
3277 )
3278 {
3279 Int z;
3280 Int i;
3282 for (z = STREAM1; z < STREAMN; z++)
3283 {
3284 xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
3285 xStr[z].pAudioFrame->numPrivateMetadata = 0;
3286 xStr[z].pAudioFrame->bsMetadata_offset = 0;
3287 xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
3289 for (i = 0; i < pP->pMetadataBufStatus->NumBuf; i++)
3290 {
3291 xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
3292 xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
3293 }
3294 }
3295 }
3297 // Initialize Output Processing state function
3298 static Int PAF_ASOT_initOutProc(
3299 const PAF_ASOT_Params *pP,
3300 PAF_AST_Stream *xStr
3301 )
3302 {
3303 // Reset audio frames
3304 resetAfs(pP, xStr);
3306 return ASOP_SOK;
3307 }
3309 #if 0
3310 // Init-Sync update audio frame
3311 static Int initSyncUpdateAf(
3312 PAF_AudioFrame *dstAf,
3313 PAF_AudioFrame *srcAf
3314 )
3315 {
3316 memcpy(dstAf, srcAf, sizeof(PAF_AudioFrame));
3318 return ASOP_SOK;
3319 }
3320 #endif
3322 // Purpose: Init-Sync Dec Reset state function.
3323 // Performes Dec Reset Init-Sync.
3324 static Int PAF_ASOT_initSyncDecReset(
3325 const PAF_ASOT_Params *pP,
3326 const PAF_ASOT_Patchs *pQ,
3327 PAF_ASOT_Config *pAsotCfg,
3328 PAF_AudioFrame *pDecResetAf
3329 )
3330 {
3331 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3332 Int zMD, zMS; // Dec and Stream Master indices
3333 PAF_AudioFrame *pStrAf; // stream audio frame
3334 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
3335 Int8 decFlag; // dec stage flag
3336 Int errno; // error number
3339 pAstCfg = pAsotCfg->pAstCfg;
3340 zMD = pAstCfg->masterDec;
3341 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
3343 // check for Dec Reset
3344 // store dec reset AF
3345 errno = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
3346 ASP_OUTIS_DEC_STAGE_RESET_IDX, &decFlag, pDecResetAf);
3347 if (errno < 0)
3348 {
3349 return errno;
3350 }
3352 if (decFlag == 0)
3353 {
3354 return ASOP_INITSYNC_NOTREADY;
3355 }
3356 else
3357 {
3358 zMS = pAstCfg->masterStr;
3359 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
3361 // Update Stream Audio Frame.
3362 // Copy Dec Reset AF to Stream AF.
3363 //errno = initSyncUpdateAf(pStrAf, pDecResetAf);
3364 //if (errno < 0)
3365 //{
3366 // return errno;
3367 //}
3368 outIsCpyAf(pDecResetAf, pStrAf);
3370 // Enc activate
3371 // Enc reset
3372 errno = PAF_ASOT_outputReset(pP, pQ, pAsotCfg);
3373 if (errno < 0)
3374 {
3375 return errno;
3376 }
3378 return ASOP_SOK;
3379 }
3380 }
3382 // Purpose: ASOT Function for Output reset
3383 static Int PAF_ASOT_outputReset(
3384 const PAF_ASOT_Params *pP,
3385 const PAF_ASOT_Patchs *pQ,
3386 PAF_ASOT_Config *pAsotCfg
3387 )
3388 {
3389 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3390 Int as; // Audio Stream Number (1, 2, etc.) */
3391 Int z; // encode counter
3392 Int errno; // error number
3393 Int zO, zS;
3396 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3397 as = pAstCfg->as;
3399 for (z=ENCODE1; z < ENCODEN; z++)
3400 {
3401 zO = pP->outputsFromEncodes[z];
3402 zS = pP->streamsFromEncodes[z];
3403 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
3404 {
3405 Int select = pAstCfg->xEnc[z].encodeStatus.select;
3406 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
3407 ENC_Handle enc = (ENC_Handle )encAlg;
3409 TRACE_VERBOSE1("AS%d: PAF_ASOT_outputReset: initializing encode", as+zS);
3411 if (encAlg->fxns->algActivate)
3412 {
3413 encAlg->fxns->algActivate(encAlg);
3414 }
3416 if (enc->fxns->reset)
3417 {
3418 errno = enc->fxns->reset(enc, NULL,
3419 &pAstCfg->xEnc[z].encodeControl,
3420 &pAstCfg->xEnc[z].encodeStatus);
3421 if (errno)
3422 {
3423 return ASOP_ENCRESET_ERR;
3424 }
3425 }
3426 }
3427 }
3429 return ASOP_SOK;
3430 }
3432 // Purpose: Init-Sync Dec Info1 state function.
3433 // Performes Dec Info1 Init-Sync.
3434 static Int PAF_ASOT_initSyncDecInfo1(
3435 const PAF_ASOT_Params *pP,
3436 const PAF_ASOT_Patchs *pQ,
3437 PAF_ASOT_Config *pAsotCfg,
3438 PAF_AudioFrame *pDecInfo1Af
3439 )
3440 {
3441 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3442 Int zMD, zMS; // Dec and Stream Master indices
3443 PAF_AudioFrame *pStrAf; // stream audio frame
3444 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
3445 Int8 decFlag; // dec stage flag
3446 Int errno; // error number
3449 pAstCfg = pAsotCfg->pAstCfg;
3450 zMD = pAstCfg->masterDec;
3451 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
3453 // Check for Dec Reset,
3454 // Store dec reset AF
3455 errno = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
3456 ASP_OUTIS_DEC_STAGE_INFO1_IDX, &decFlag, pDecInfo1Af);
3457 if (errno < 0)
3458 {
3459 return errno;
3460 }
3462 if (decFlag == 0)
3463 {
3464 return ASOP_INITSYNC_NOTREADY;
3465 }
3466 else
3467 {
3468 zMS = pAstCfg->masterStr;
3469 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
3471 // Update Stream Audio Frame.
3472 // Copy Dec Reset AF to Stream AF.
3473 //errno = initSyncUpdateAf(pStrAf, pDecInfo1Af);
3474 //if (errno < 0)
3475 //{
3476 // return errno;
3477 //}
3479 // Hack to set ASOT output frame length.
3480 // THD sets this to 256 (hard-coded in Dec Info)
3481 // DDP sets this to 0 (audio frame passthrough, 0 from ASDT AF frame length)
3482 // PCM sets this to 256 (decodeControl.frameLength)
3483 pDecInfo1Af->sampleCount = 256; // !!!! GJ: Revisit !!!!
3485 outIsCpyAf(pDecInfo1Af, pStrAf);
3487 // Hack to set ASOT output frame length
3488 // THD sets this to 256 (hard-coded in Dec Info)
3489 // DDP sets this to 0 (audio frame passthrough, 0 from ASDT AF frame length)
3490 // PCM sets this to 256 (decodeControl.frameLength)
3491 //pStrAf->sampleCount = 256; // !!!! GJ: Revisit !!!!
3493 // outputInfo1():
3494 // - ASP chain reset,
3495 // - Enc Info
3496 PAF_ASOT_outputInfo1(pP, pQ, pAsotCfg);
3497 if (errno)
3498 {
3499 return ASOP_DECINFO1_ERR;
3500 }
3502 return ASOP_SOK;
3503 }
3504 }
3506 // Purpose: ASOT function for ASP chain reset and ENC info
3507 static Int PAF_ASOT_outputInfo1(
3508 const PAF_ASOT_Params *pP,
3509 const PAF_ASOT_Patchs *pQ,
3510 PAF_ASOT_Config *pAsotCfg
3511 )
3512 {
3513 PAF_AST_Config *pAstCfg;
3514 Int z; /* decode/encode counter */
3515 Int errno; /* error number */
3518 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3520 // FL: frame parameter hard-coded to 0
3521 // run the chain of ASP's on the stream.
3522 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
3523 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
3524 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, 0);
3525 if (errno)
3526 {
3527 TRACE_TERSE1("PAF_ASOT_outputInfo1: streamChainFunction returns errno 0x%x ", errno);
3528 return errno;
3529 }
3531 TRACE_VERBOSE0("PAF_ASOT_outputInfo1: calling enc->info.");
3532 for (z=ENCODE1; z < ENCODEN; z++)
3533 {
3534 Int zO = pP->outputsFromEncodes[z];
3535 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
3536 {
3537 Int select = pAstCfg->xEnc[z].encodeStatus.select;
3538 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
3539 ENC_Handle enc = (ENC_Handle )encAlg;
3541 if (enc->fxns->info)
3542 {
3543 errno = enc->fxns->info(enc, NULL,
3544 &pAstCfg->xEnc[z].encodeControl,
3545 &pAstCfg->xEnc[z].encodeStatus);
3546 if (errno)
3547 {
3548 TRACE_TERSE1("PAF_ASOT_outputInfo1: info returns errno 0x%x ", errno);
3549 return errno;
3550 }
3551 }
3552 }
3553 }
3555 return 0;
3556 }
3558 // Purpose: Init-Sync Dec Decode1 state function.
3559 // Performes Dec Decode1 Init-Sync.
3560 static Int PAF_ASOT_initSyncDecDecode1(
3561 const PAF_ASOT_Params *pP,
3562 const PAF_ASOT_Patchs *pQ,
3563 PAF_ASOT_Config *pAsotCfg
3564 )
3565 {
3566 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3567 Int zMD; // Dec Master index
3568 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
3569 Int8 decFlag; // dec stage flag
3570 Int errno; // error number
3573 pAstCfg = pAsotCfg->pAstCfg;
3574 zMD = pAstCfg->masterDec;
3575 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
3577 // Check for Dec Reset,
3578 // Store dec reset AF
3579 errno = outIsReadDecStageFlag(pOutIsCtl, zMD,
3580 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, &decFlag);
3581 if (errno < 0)
3582 {
3583 return errno;
3584 }
3586 if (decFlag == 0)
3587 {
3588 return ASOP_INITSYNC_NOTREADY;
3589 }
3590 else
3591 {
3592 return ASOP_SOK;
3593 }
3594 }
3596 // Purpose: Init-Sync Re-Sync state function.
3597 // Peformed Init-Sync using stored Dec Reset/Info1 AFs.
3598 static Int PAF_ASOT_initSyncResync(
3599 const PAF_ASOT_Params *pP,
3600 const PAF_ASOT_Patchs *pQ,
3601 PAF_ASOT_Config *pAsotCfg,
3602 PAF_AudioFrame *pDecResetAf,
3603 PAF_AudioFrame *pDecInfo1Af
3604 )
3605 {
3606 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3607 Int zMS; // Stream Master index
3608 PAF_AudioFrame *pStrAf; // stream audio frame
3609 Int errno; // error number
3612 pAstCfg = pAsotCfg->pAstCfg;
3613 zMS = pAstCfg->masterStr;
3614 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
3616 // Reset audio frames
3617 resetAfs(pP, pAstCfg->xStr);
3619 //
3620 // Dec Reset re-sync using stored Dec Reset AF
3621 //
3623 // Update Stream Audio Frame.
3624 // Copy Dec Reset AF to Stream AF.
3625 //errno = initSyncUpdateAf(pStrAf, pDecResetAf);
3626 //if (errno < 0)
3627 //{
3628 // return errno;
3629 //}
3630 outIsCpyAf(pDecResetAf, pStrAf);
3632 // Enc activate,
3633 // Enc reset
3634 errno = PAF_ASOT_outputReset(pP, pQ, pAsotCfg);
3635 if (errno)
3636 {
3637 return errno;
3638 }
3640 //
3641 // Dec Info1 re-sync using stored Dec Info1 AF
3642 //
3644 // Update Stream Audio Frame.
3645 // Copy Dec Info1 AF to Stream AF.
3646 //errno = initSyncUpdateAf(pStrAf, pDecInfo1Af);
3647 //if (errno < 0)
3648 //{
3649 // return errno;
3650 //}
3651 outIsCpyAf(pDecInfo1Af, pStrAf);
3653 // decodeInfo1():
3654 // - ASP chain reset,
3655 // - Enc Info
3656 errno = PAF_ASOT_outputInfo1(pP, pQ, pAsotCfg);
3657 if (errno)
3658 {
3659 return errno;
3660 }
3662 return ASOP_SOK;
3663 }
3665 // Purpose: Decoding Function for determining whether processing of the
3666 // current stream is complete.
3667 Int
3668 PAF_ASOT_decodeFinalTest(
3669 const struct PAF_ASOT_Params *pP,
3670 const struct PAF_ASOT_Patchs *pQ,
3671 struct PAF_ASOT_Config *pAsotCfg,
3672 Int frame,
3673 Int block
3674 )
3675 {
3676 PAF_AST_DecOpCircBufCtl *pCbCtl; // decoder output circular buffer control
3677 Int8 drainedFlag; // CB drained indicator flag
3678 Int zMD; // master Dec index
3679 Int errno; // error number
3682 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
3683 zMD = pAsotCfg->pAstCfg->masterDec; // get master Dec index
3685 // Check circular buffer drain state
3686 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
3687 errno = cbCheckDrainState(pCbCtl, zMD, &drainedFlag);
3688 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
3689 if (errno < 0)
3690 {
3691 return errno;
3692 }
3694 if (drainedFlag == 1)
3695 {
3696 return ASOP_DP_CB_DRAINED;
3697 }
3699 return ASOP_DP_SOK;
3700 }