2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamOutProc.c ========
38 */
40 #include <string.h> // for memset
41 #include <xdc/runtime/Log.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/Memory.h>
44 #include <ti/sysbios/knl/Clock.h>
45 #include <ti/sysbios/knl/Task.h>
47 #include "paferr.h"
48 #include <acp_mds.h>
49 #include <pcm.h>
50 #include <pce.h>
51 #include <pafsio_ialg.h>
52 #include <stdasp.h>
53 #include <doberr.h>
54 #include "asperr.h"
56 #include "common.h"
57 #include "aspMsg_common.h"
58 #include "aspMsg_master.h"
59 #include "aspDecOpCircBuf_master.h"
60 #include "aspOutInitSync_master.h"
61 #include "audioStreamProc_common.h"
62 #include "audioStreamOutProc.h"
64 #include "pfp/pfp.h"
65 #include "pfp_app.h" /* contains all PFP ID's */
66 Int32 gNumPfpAsot1=0; // debug
68 // FL: debug
69 #include "evmc66x_gpio_dbg.h"
70 #include "dbgCapAf.h"
72 #include "ioConfig.h"
74 // -----------------------------------------------------------------------------
75 // Debugging Trace Control, local to this file.
76 //
77 #include "logp.h"
79 #define TRACE_TIME(a)
81 // Allow a developer to selectively enable tracing.
82 #define CURRENT_TRACE_MASK 0x07
84 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
85 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
86 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
88 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
89 #undef TRACE_TERSE0
90 #undef TRACE_TERSE1
91 #undef TRACE_TERSE2
92 #undef TRACE_TERSE3
93 #undef TRACE_TERSE4
94 #define TRACE_TERSE0(a)
95 #define TRACE_TERSE1(a,b)
96 #define TRACE_TERSE2(a,b,c)
97 #define TRACE_TERSE3(a,b,c,d)
98 #define TRACE_TERSE4(a,b,c,d,e)
99 #endif
101 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
102 #undef TRACE_GEN0
103 #undef TRACE_GEN1
104 #undef TRACE_GEN2
105 #undef TRACE_GEN3
106 #undef TRACE_GEN4
107 #define TRACE_GEN0(a)
108 #define TRACE_GEN1(a,b)
109 #define TRACE_GEN2(a,b,c)
110 #define TRACE_GEN3(a,b,c,d)
111 #define TRACE_GEN4(a,b,c,d,e)
112 #endif
114 #if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
115 #undef TRACE_VERBOSE0
116 #undef TRACE_VERBOSE1
117 #undef TRACE_VERBOSE2
118 #undef TRACE_VERBOSE3
119 #undef TRACE_VERBOSE4
120 #define TRACE_VERBOSE0(a)
121 #define TRACE_VERBOSE1(a,b)
122 #define TRACE_VERBOSE2(a,b,c)
123 #define TRACE_VERBOSE3(a,b,c,d)
124 #define TRACE_VERBOSE4(a,b,c,d,e)
125 #endif
127 // .............................................................................
129 //
130 // Audio Stream Definitions
131 //
133 //
134 // Audio Stream Processing Definitions
135 //
136 #define aspLinkInit pQ->i_aspLinkInit
138 //
139 // Encoder Definitions
140 //
141 #define encLinkInit pQ->i_encLinkInit
143 //
144 // Output Definitions
145 //
146 #define outLinkInit pP->i_outLinkInit
148 /* ---------------------------------------------------------------- */
149 /* Parameter macro definitions end here. */
150 /* ---------------------------------------------------------------- */
152 //
153 // Standardized Definitions
154 //
156 #define ENC_Handle PCE_Handle /* works for all: PCE */
158 #define __TASK_NAME__ "TaskAsop"
161 //
162 // Audio Stream Output Task definitions
163 //
165 // status codes
166 // Output FSM
167 #define ASOP_INITSYNC_NOTREADY ( 1 ) // ok, init-sync not ready
168 #define ASOP_SOK ( 0 ) // ok
169 #define ASOP_FORWARD_ERR ( -1 ) // forward (ASIT) error
170 #define ASOP_ENCRESET_ERR ( -2 ) // enc reset error
171 #define ASOP_DECINFO1_ERR ( -3 ) // dec info1 error
172 // Decode Processing
173 #define ASOP_DP_OUT_SIO_UPDATE ( 3 ) // new output selected
174 #define ASOP_DP_CB_DRAINED ( 2 ) // circular buffer drained
175 #define ASOP_DP_SOK ( 0 ) // ok
176 #define ASOP_DP_FORWARD_ERR ( -1 ) // forward (ASIT) error
177 #define ASOP_DP_DECINIT_ERR ( -2 ) // decode init error
178 #define ASOP_DP_DECSTREAM_ERR ( -3 ) // decode stream error
179 #define ASOP_DP_DECENC_ERR ( -4 ) // decode encode error
180 #define ASOP_DP_DECINFO2_ERR ( -5 ) // decode encode error
181 #define ASOP_DP_DECFINALTEST_ERR ( -6 ) // decode final error
184 /* Check if at least one output selected */
185 static Int checkOutSel(
186 const PAF_ASOT_Params *pP,
187 PAF_ASOT_Config *pAsotCfg,
188 Int *pOutSel
189 );
191 /* Check if at least one output sio changed */
192 static Int checkOutSio(
193 const PAF_ASOT_Params *pP,
194 PAF_ASOT_Config *pAsotCfg,
195 Int *pOutSioUpdate
196 );
198 // Initialize Output Processing state function
199 //static Int PAF_ASOT_initOutProc(
200 // used by new OutProc.c, will be changed back to static once refactoring is done
201 Int PAF_ASOT_initOutProc(
202 const PAF_ASOT_Params *pP,
203 PAF_AST_Stream *xStr
204 );
206 // Initialize Output Processing state function
207 // used by new OutProc.c, will be changed back to static once refactoring is done
208 Int PAF_ASOT_initSyncDecReset(
209 const PAF_ASOT_Params *pP,
210 const PAF_ASOT_Patchs *pQ,
211 PAF_ASOT_Config *pAsotCfg,
212 PAF_AudioFrame *pDecResetAf
213 );
215 // Purpose: ASOT Function for Output reset
216 static Int PAF_ASOT_outputReset(
217 const PAF_ASOT_Params *pP,
218 const PAF_ASOT_Patchs *pQ,
219 PAF_ASOT_Config *pAsotCfg
220 );
222 // Purpose: Init-Sync Dec Info1 state function.
223 // Performs Dec Info1 Init-Sync.
224 Int PAF_ASOT_initSyncDecInfo1(
225 const PAF_ASOT_Params *pP,
226 const PAF_ASOT_Patchs *pQ,
227 PAF_ASOT_Config *pAsotCfg,
228 PAF_AudioFrame *pDecInfo1Af
229 );
231 // Purpose: ASOT function for ASP chain reset and ENC info
232 static Int PAF_ASOT_outputInfo1(
233 const PAF_ASOT_Params *pP,
234 const PAF_ASOT_Patchs *pQ,
235 PAF_ASOT_Config *pAsotCfg
236 );
238 // Purpose: Init-Sync Dec Decode1 state function.
239 // Performs Dec Decode1 Init-Sync.
240 Int PAF_ASOT_initSyncDecDecode1(
241 const PAF_ASOT_Params *pP,
242 const PAF_ASOT_Patchs *pQ,
243 PAF_ASOT_Config *pAsotCfg
244 );
246 // Purpose: Init-Sync Re-Sync state function.
247 // Performs Init-Sync using stored Dec Reset/Info1 AFs.
248 Int PAF_ASOT_initSyncResync(
249 const PAF_ASOT_Params *pP,
250 const PAF_ASOT_Patchs *pQ,
251 PAF_ASOT_Config *pAsotCfg,
252 PAF_AudioFrame *pDecResetAf,
253 PAF_AudioFrame *pDecInfo1Af
254 );
256 // Reset audio frames
257 static Void resetAfs(
258 const PAF_ASOT_Params *pP,
259 PAF_AST_Stream *xStr
260 );
262 // Reset audio frame pointers to original values
263 static Void resetAfPointers(
264 const PAF_ASOT_Params *pP,
265 PAF_AST_Stream *xStr
266 );
268 // Reset audio frame meta data elements
269 static Void resetAfMetadata(
270 const PAF_ASOT_Params *pP,
271 PAF_AST_Stream *xStr
272 );
274 // Create ASOT event
275 static Int asotCreateEvent(void);
278 LINNO_DEFN(TaskAsop); /* Line number macros */
279 ERRNO_DEFN(TaskAsop); /* Error number macros */
281 // ASOT configuration
282 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
283 PAF_ASOT_Config gPAF_ASOT_config = {
284 NULL, // taskHandle
285 0, // asotState
286 NULL, // acp
287 0,0,0, // cbDrainedFlag (size DECODE_MAXN)
288 &gPAF_ASPM_config, // pAspmCfg
289 &gPAF_AST_config // pAstCfg
290 };
292 /* ASOT event handle - to put in structure */
293 Event_Handle asotEvt;
295 // Underflow threshold before circular buffer reset and return error to Top-Level FSM
296 #define DEC_OP_CB_RDAF_UND_THR ( 80 ) // FL: arbitrary setting
297 UInt32 gCbReadAfErr =0; // read circular buffer error count, not including underflows
298 UInt32 gDecOpCbRdAfUnd =0; // decoder output circular buffer underflow count
299 UInt32 gMaxDecOpCbRdAfUnd =0; // max (consecutive) decoder output circular buffer underflow count
300 UInt32 gMasterCbResetCnt =0; // master circular buffer reset count
302 // For writeDECCommandRestart
303 extern volatile UInt32 gCommandOutputTask_SYNC;
304 extern volatile UInt32 gCommandOutputTask_ACK;
306 // Global debug counters */
307 UInt32 gAsopTxSioReclaimCnt =0;
308 UInt32 gAsopInitOutProcCnt =0;
309 UInt32 gAsopInitSyncDecResetCnt =0;
310 UInt32 gAsopInitSyncDecInfo1Cnt =0;
311 UInt32 gAsopInitSyncDecDecode1Cnt =0;
312 UInt32 gAsopInitSyncResyncCnt =0;
313 UInt32 gAsopOutProcCnt =0;
314 UInt32 gAsopInitCnt =0;
315 UInt32 gAsopStreamCnt =0;
316 UInt32 gAsopEncodeCnt =0;
317 UInt32 gAsopFinalCnt =0;
318 UInt32 gAsopOutSioUpdateCnt =0;
319 UInt32 gAsopQuitCnt =0;
321 /*
322 * ======== taskAsopFxnInit ========
323 * Audio Stream Output Processing initialization function
324 */
325 Void taskAsopFxnInit(
326 const PAF_ASOT_Params *pP,
327 const PAF_ASOT_Patchs *pQ
328 )
329 {
330 PAF_ASOT_Config *pAsotCfg; /* ASOT configuration pointer */
331 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
332 Int as; /* Audio Stream Number (1, 2, etc.) */
333 Int z; /* input/encode/stream/decode/output counter */
334 Int i; /* phase */
335 Int zMS;
336 Int status;
338 Log_info0("Enter taskAsopFxnInit()");
340 //
341 // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
342 //
343 if (!pP)
344 {
345 TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
346 LINNO_RPRT(TaskAsop, -1);
347 return;
348 }
350 if (!pQ)
351 {
352 TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
353 LINNO_RPRT(TaskAsop, -1);
354 return;
355 }
357 //
358 // Audio Stream Output Task Configuration (*pAsotCfg):
359 //
360 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
361 pAsotCfg->taskHandle = Task_self(); // set task handle
362 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
364 // Create ASIT event
365 status = asotCreateEvent();
366 if (status < 0)
367 {
368 TRACE_TERSE0("TaskAsop: unable to initialize event. Exiting.");
369 return;
370 }
372 /* Obtain Audio Stream Number (1, 2, etc.) */
373 as = pAstCfg->as;
374 TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
376 //
377 // Initialize message log trace and line number reporting
378 //
379 for (z=STREAM1; z < STREAMN; z++)
380 {
381 TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
382 }
383 LINNO_RPRT(TaskAsop, -1);
385 //
386 // Determine stream index
387 //
388 zMS = pAstCfg->masterStr;
390 // Initialize as per parametrized phases:
391 //
392 // In standard form these are:
393 // - Malloc: Memory Allocation
394 // - Config: Configuration Initialization
395 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
396 // - Common: Common Memory Initialization
397 // - AlgKey: Dec/Enc chain to Array Initialization
398 // - Device: I/O Device Initialization
399 // - Unused: (available)
400 // - Unused: (available)
401 //
402 LINNO_RPRT(TaskAsop, -2);
403 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
404 {
405 Int linno;
406 if (pP->fxns->initPhase[i])
407 {
408 linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
409 if (linno)
410 {
411 LINNO_RPRT(TaskAsop, linno);
412 return;
413 }
414 }
415 else
416 {
417 TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
418 }
419 TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
420 LINNO_RPRT(TaskAsop, -i-3);
421 }
423 //
424 // End of Initialization -- display memory usage report.
425 //
426 if (pP->fxns->memStatusPrint)
427 {
428 pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
429 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
430 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
431 }
432 } /* taskAsopFxnInit */
434 /*
435 * ========asotCreateEvent ========
436 * Create ASOT event
437 */
438 static Int asotCreateEvent(void)
439 {
440 Error_Block eb;
442 Error_init(&eb);
444 // Default instance configuration params
445 asotEvt = Event_create(NULL, &eb);
446 if (asotEvt == NULL)
447 {
448 return -1; // error code
449 }
451 return 0;
452 } /* asotCreateEvent */
454 /*
455 * ======== taskAsopFxn ========
456 * Audio Stream Output Processing task function
457 */
458 #ifdef PASDK_SIO_DEV
459 Void taskAsopFxn(
460 #else
461 #ifndef IO_LOOPBACK_TEST
462 Void taskAsopFxn_NOt_Used(
463 #else
464 Void taskAsopFxn_Not_Used(
465 #endif
466 #endif
467 const PAF_ASOT_Params *pP,
468 const PAF_ASOT_Patchs *pQ
469 )
470 {
471 PAF_ASOT_Config *pAsotCfg; /* ASOT configuration pointer */
472 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
473 Int as; /* Audio Stream Number (1, 2, etc.) */
474 Int z; /* input/encode/stream/decode/output counter */
475 Int zMS;
476 Int errno; // error number
477 Int8 procSleep; // whether to sleep: 0: No, 1: Yes
478 Int8 procOutDevSel; // whether to perform output device selection: 0: No, 1:Yes
479 Int outSel; // whether output device selected
480 enum { INIT_OUT_PROC_STATE,
481 INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE,
482 INITSYNC_RESYNC_STATE,
483 OUT_PROC_STATE } state;
484 PAF_AudioFrame decResetAf;
485 PAF_AudioFrame decInfo1Af;
486 Int loopCount = 0; // used to stop trace to see startup behavior.
488 Log_info0("Enter taskAsopFxn()");
490 taskAsopFxnInit(pP, pQ); // initialization of output task
492 //
493 // Audio Stream Output Task Configuration (*pAsotCfg):
494 //
495 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
496 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
498 /* Obtain Audio Stream Number (1, 2, etc.) */
499 as = pAstCfg->as;
501 zMS = pAstCfg->masterStr;
503 //
504 // Main processing loop
505 //
506 for (z=STREAM1; z < STREAMN; z++)
507 {
508 TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
509 }
511 errno = 0; // init error indicator -- no error
512 procSleep = 1; // init sleep flag -- sleep
513 procOutDevSel = 1; // init device output selection flag -- perform output device selection
514 state = INIT_OUT_PROC_STATE; // init state
515 for (;;)
516 {
517 loopCount++;
518 TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", loopCount, errno);
520 //
521 // Check forward (ASIT) error here, TBD
522 //
524 // Even if we are not in error state, we check if writeDECCommandRestar issued or not
525 if (gCommandOutputTask_SYNC) {
526 TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Wait for the command deasserted");
527 gCommandOutputTask_ACK = 1;
528 while (gCommandOutputTask_SYNC) {
529 Task_sleep(1);
530 }
531 TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Startover the process");
532 procSleep = 1; // init sleep flag -- sleep
533 procOutDevSel = 1; // init device output selection flag -- perform output device selection
534 state = INIT_OUT_PROC_STATE; // init state -- starover
535 errno = ASOP_DP_FORWARD_ERR; // Override the error -- for flushing SIO output device
536 }
538 // any error forces idling of output
539 if (errno)
540 {
541 for (z=OUTPUT1; z < OUTPUTN; z++)
542 {
543 if (pAstCfg->xOut[z].hTxSio)
544 {
545 SIO_idle(pAstCfg->xOut[z].hTxSio);
546 }
547 }
549 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
550 ERRNO_RPRT(TaskAsop, errno);
551 }
553 if (procSleep == 1)
554 {
555 TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
556 Task_sleep(1);
557 }
559 if (procOutDevSel == 1)
560 {
561 // select output devices
562 TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
563 errno = pP->fxns->selectDevices(pP, pQ, pAsotCfg);
564 if (errno)
565 {
566 TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
568 procSleep = 1;
569 procOutDevSel = 1;
571 continue;
572 }
574 // if no output selected skip remaining processing
575 errno = checkOutSel(pP, pAsotCfg, &outSel);
576 if (errno < 0)
577 {
578 TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
580 procSleep = 1;
581 procOutDevSel = 1;
583 continue;
584 }
585 else if (!outSel)
586 {
587 TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);
589 procSleep = 1;
590 procOutDevSel = 1;
592 continue;
593 }
594 }
596 switch (state)
597 {
598 case INIT_OUT_PROC_STATE:
599 gAsopInitOutProcCnt++;
600 Log_info0("TaskAsop: state=INIT_OUT_PROC_STATE");
602 //
603 // Output Processing initialization.
604 //
605 errno = PAF_ASOT_initOutProc(pP, pAstCfg->xStr);
606 if (errno < 0)
607 {
608 state = INIT_OUT_PROC_STATE;
609 procSleep = 1;
610 procOutDevSel = 1;
611 }
612 else
613 {
614 state = INITSYNC_DEC_RESET_STATE;
615 procSleep = 0;
616 procOutDevSel = 0;
617 }
619 break;
621 case INITSYNC_DEC_RESET_STATE:
622 gAsopInitSyncDecResetCnt++;
623 Log_info0("TaskAsop: state=INITSYNC_DEC_RESET_STATE");
625 //
626 // Dec Reset Init-Sync.
627 //
629 // Perform Dec Reset init-sync.
630 // Latch Dec Reset AF.
631 errno = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, &decResetAf);
632 if (errno < 0)
633 {
634 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE errno=%d", errno);
636 // sync error -- start over
637 state = INIT_OUT_PROC_STATE;
638 procSleep = 1;
639 procOutDevSel = 1;
640 }
641 else if (errno == ASOP_INITSYNC_NOTREADY)
642 {
643 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE not sync'd errno=%d", errno);
645 // sync not ready -- try again
646 state = INITSYNC_DEC_RESET_STATE;
647 errno=0; // FL: temp hack
648 procSleep = 1;
649 procOutDevSel = 1;
650 }
651 else // errno==0
652 {
653 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE sync'd, errno=%d", errno);
655 // sync'd -- move on
656 state = INITSYNC_DEC_INFO1_STATE;
657 procSleep = 0;
658 procOutDevSel = 0;
659 }
661 break;
663 case INITSYNC_DEC_INFO1_STATE:
664 gAsopInitSyncDecInfo1Cnt++;
665 Log_info0("TaskAsop: state=INITSYNC_DEC_INFO1_STATE");
667 //
668 // Dec Info1 Init-Sync.
669 //
671 // Perform Dec Info1 init-sync.
672 // Latch Dec Info1 AF.
673 errno = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af);
674 if (errno < 0)
675 {
676 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE errno=%d", errno);
678 // sync error -- start over
679 state = INIT_OUT_PROC_STATE;
680 procSleep = 1;
681 procOutDevSel = 1;
682 }
683 else if (errno == ASOP_INITSYNC_NOTREADY)
684 {
685 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE not sync'd errno=%d", errno);
687 // sync not ready -- try again
688 state = INITSYNC_DEC_INFO1_STATE;
689 errno=0; // FL: temp hack
690 procSleep = 1;
691 procOutDevSel = 0;
692 }
693 else // errno = 0
694 {
695 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE sync'd errno=%d", errno);
697 // sync'd -- move on
698 state = INITSYNC_DEC_DECODE1_STATE;
699 procSleep = 0;
700 procOutDevSel = 0;
701 }
703 break;
705 case INITSYNC_DEC_DECODE1_STATE:
706 gAsopInitSyncDecDecode1Cnt++;
707 Log_info0("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE");
709 //
710 // Dec Info1 Init-Sync.
711 //
713 // Perform Dec Info1 init-sync.
714 // Latch Dec Info1 AF.
715 errno = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg);
716 if (errno < 0)
717 {
718 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE errno=%d", errno);
720 // sync error -- start over
721 state = INIT_OUT_PROC_STATE;
722 procSleep = 1;
723 procOutDevSel = 1;
724 }
725 else if (errno == ASOP_INITSYNC_NOTREADY)
726 {
727 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE not sync'd errno=%d", errno);
729 // sync not ready -- try again
730 state = INITSYNC_DEC_DECODE1_STATE;
731 errno=0; // FL: temp hack
732 procSleep = 1;
733 procOutDevSel = 0;
734 }
735 else // errno = 0
736 {
737 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE sync'd errno=%d", errno);
739 // sync'd -- move on
740 state = OUT_PROC_STATE;
741 procSleep = 0;
742 procOutDevSel = 0;
743 }
745 break;
747 case INITSYNC_RESYNC_STATE:
748 gAsopInitSyncResyncCnt++;
749 Log_info0("TaskAsop: state=INITSYNC_RESYNC_STATE");
751 //
752 // Re-Sync.
753 // Use stored AF info from init-sync.
754 // This is done in case of local error.
755 //
757 // Perform Dec Info1 init-sync.
758 errno = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf,
759 &decInfo1Af);
760 if (errno < 0)
761 {
762 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE errno=%d", errno);
764 // sync error -- start over
765 state = INIT_OUT_PROC_STATE;
766 procSleep = 1;
767 procOutDevSel = 1;
768 }
769 else
770 {
771 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE sync'd errno=%d", errno);
773 // re-sync'd -- move on
774 state = OUT_PROC_STATE;
775 procSleep = 0;
776 procOutDevSel = 0;
777 }
779 break;
781 case OUT_PROC_STATE:
782 gAsopOutProcCnt++;
783 Log_info0("TaskAsop: state=OUT_PROC_STATE");
785 //
786 // Output Processing.
787 //
789 TRACE_VERBOSE0("TaskAsop: calling decodeProcessing.");
790 errno = pP->fxns->decodeProcessing(pP, pQ, pAsotCfg);
791 if (errno < 0)
792 {
793 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
795 //
796 // Output Processing exit, due to error
797 //
799 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
800 if (errno == ASOP_DP_FORWARD_ERR)
801 {
802 // forward (ASIT) error -- start over
803 state = INIT_OUT_PROC_STATE;
804 procSleep = 1;
805 procOutDevSel = 1;
806 }
807 else
808 {
809 // local (ASOT) error
810 state = INITSYNC_RESYNC_STATE;
811 procSleep = 1;
812 procOutDevSel = 0; // disallow device re-select if local error during output processing
813 }
814 }
815 else if (errno > 0)
816 {
817 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
819 //
820 // Output Processing exit, not due to error
821 //
823 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
824 if (errno == ASOP_DP_OUT_SIO_UPDATE)
825 {
826 // skip re-sync
827 // resume output processing after new output selected
828 state = OUT_PROC_STATE;
829 procSleep = 1;
830 procOutDevSel = 1;
831 }
832 }
833 else
834 {
835 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
837 //
838 // Output Processing exit, normal
839 //
841 TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
843 // no error returned if CB drained
844 // (i.e. CB drained is normal behavior)
845 state = INIT_OUT_PROC_STATE;
846 procSleep = 1;
847 procOutDevSel = 1;
848 }
850 break;
852 default: // unknown state
853 TRACE_TERSE2("TaskAsop: AS%d: state: unknown, 0x%x", as+zMS, state);
854 break;
855 }
856 } // End of main processing loop for (;;)
858 //Log_info0("Exit taskAsopFxn()");
859 }
861 Int PAF_ASOT_ioCompCreate(PAF_AST_IoOut *pIoOut, int numOut, IHeap_Handle iHeapHandle)
862 {
863 int i, j, num_alloc;
864 lib_mem_rec_t *mem_rec;
865 ioBuffHandle_t ioBufHandle;
866 ioPhyHandle_t ioPhyHandle;
867 Error_Block eb;
869 for(i=0; i<numOut; i++)
870 {
871 // Create an I/O BUFF instance
872 // Obtain number of memory blocks required by I/O BUFF
873 num_alloc = ioBuffNumAlloc();
875 // Obtain requirements of each memory block
876 mem_rec = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
877 if(ioBuffAlloc(mem_rec) != IOBUFF_NOERR) {
878 return __LINE__;
879 }
881 /* Allocate memory and create I/O BUFF instance */
882 for(j=0; j<num_alloc; j++) {
883 mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
884 (1<<mem_rec[j].alignment), &eb);
885 }
887 if(ioBuffCreate(&ioBufHandle, mem_rec) != IOBUFF_NOERR) {
888 return __LINE__;
889 }
891 pIoOut[i].hIoBuff = ioBufHandle;
893 free(mem_rec);
895 // Create an I/O PHY instance
896 // Obtain number of memory blocks required by I/O PHY
897 num_alloc = ioPhyNumAlloc();
899 // Obtain requirements of each memory block
900 mem_rec = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
901 if(ioPhyAlloc(mem_rec) != IOBUFF_NOERR) {
902 return __LINE__;
903 }
905 /* Allocate memory and create I/O PHY instance */
906 for(j=0; j<num_alloc; j++) {
907 mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
908 (1<<mem_rec[j].alignment), &eb);
909 }
911 if(ioPhyCreate(&ioPhyHandle, mem_rec) != IOBUFF_NOERR) {
912 return __LINE__;
913 }
915 pIoOut[i].hIoPhy = ioPhyHandle;
917 free(mem_rec);
919 } // end of for loop
921 return 0;
922 } // PAF_ASOT_ioCompCreate
924 // -----------------------------------------------------------------------------
925 // AST Initialization Function - Memory Allocation
926 //
927 // Name: PAF_ASOT_initPhaseMalloc
928 // Purpose: Audio Stream Output Task Function for initialization of data pointers
929 // by allocation of memory.
930 // From: audioStream1Task or equivalent
931 // Uses: See code.
932 // States: x
933 // Return: 0 on success.
934 // Source code line number on MEM_calloc failure.
935 // Trace: Message Log "trace" in Debug Project Configuration reports:
936 // * State information as per parent.
937 // * Memory allocation errors.
938 //
940 Int
941 PAF_ASOT_initPhaseMalloc (
942 const PAF_ASOT_Params *pP,
943 const PAF_ASOT_Patchs *pQ,
944 PAF_ASOT_Config *pAsotCfg
945 )
946 {
947 PAF_AST_Config *pAstCfg;
948 Int as; /* Audio Stream Number (1, 2, etc.) */
949 Int zMS, errLineNum;
950 Error_Block eb;
951 //Int i;
953 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
954 as = pAstCfg->as;
955 zMS = pAstCfg->masterStr;
957 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
959 // Initialize error block
960 Error_init(&eb);
962 /* Stream memory */
963 if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
964 {
965 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
966 SW_BREAKPOINT;
967 return __LINE__;
968 }
969 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
970 STREAMN * sizeof (*pAstCfg->xStr),
971 HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
973 {
974 Int z; /* stream counter */
976 PAF_AudioFrame *fBuf;
978 if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
979 {
980 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
981 SW_BREAKPOINT;
982 return __LINE__;
983 }
984 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
985 STREAMS * sizeof (*fBuf),
986 HEAP_ID_INTERNAL, (IArg)fBuf);
988 for (z=STREAM1; z < STREAMN; z++)
989 {
990 pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
991 TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
992 }
993 }
995 /* Encode memory */
996 if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
997 {
998 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
999 SW_BREAKPOINT;
1000 return __LINE__;
1001 }
1002 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
1003 ENCODEN * sizeof (*pAstCfg->xEnc),
1004 HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
1006 /* Output memory */
1007 if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
1008 {
1009 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1010 SW_BREAKPOINT;
1011 return __LINE__;
1012 }
1013 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
1014 OUTPUTN * sizeof (*pAstCfg->xOut),
1015 HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
1017 /* Output I/O data structure memory */
1018 if (!(pAsotCfg->pIoOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAsotCfg->pIoOut), 4, &eb)))
1019 {
1020 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1021 SW_BREAKPOINT;
1022 return __LINE__;
1023 }
1024 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAsotCfg->pIoOut) %d bytes from space %d at 0x%x.",
1025 OUTPUTN * sizeof (*pAsotCfg->pIoOut),
1026 HEAP_ID_INTERNAL, (IArg)pAsotCfg->pIoOut);
1028 /* I/O components memory for output */
1029 errLineNum = PAF_ASOT_ioCompCreate(pAsotCfg->pIoOut, OUTPUTN, (IHeap_Handle)HEAP_INTERNAL);
1030 if(errLineNum)
1031 {
1032 SW_BREAKPOINT;
1033 return errLineNum;
1034 }
1035 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1036 return 0;
1037 } //PAF_ASOT_initPhaseMalloc
1039 // -----------------------------------------------------------------------------
1040 // ASOT Initialization Function - Memory Initialization from Configuration
1041 //
1042 // Name: PAF_ASOT_initPhaseConfig
1043 // Purpose: Audio Stream Output Task Function for initialization of data values
1044 // from parameters.
1045 // From: audioStream1Task or equivalent
1046 // Uses: See code.
1047 // States: x
1048 // Return: 0 on success.
1049 // Other as per initFrame0 and initFrame1.
1050 // Trace: Message Log "trace" in Debug Project Configuration reports:
1051 // * State information as per parent.
1052 //
1053 Int
1054 PAF_ASOT_initPhaseConfig(
1055 const PAF_ASOT_Params *pP,
1056 const PAF_ASOT_Patchs *pQ,
1057 PAF_ASOT_Config *pAsotCfg
1058 )
1059 {
1060 PAF_AST_Config *pAstCfg;
1061 Int as; /* Audio Stream Number (1, 2, etc.) */
1062 Int z; /* input/encode/stream/decode/output counter */
1063 Int zMS;
1065 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1066 as = pAstCfg->as;
1067 zMS = pAstCfg->masterStr;
1069 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1071 //
1072 // Unspecified elements have been initialized to zero during alloc
1073 //
1075 for (z=STREAM1; z < STREAMN; z++)
1076 {
1077 Int linno;
1078 if (linno = pP->fxns->initFrame0(pP, pQ, pAsotCfg, z))
1079 {
1080 return linno;
1081 }
1082 if (linno = pP->fxns->initFrame1(pP, pQ, pAsotCfg, z, -1))
1083 {
1084 return linno;
1085 }
1086 }
1088 for (z=ENCODE1; z < ENCODEN; z++)
1089 {
1090 Int zO = pP->outputsFromEncodes[z];
1091 Int zS = pP->streamsFromEncodes[z];
1092 pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
1093 pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
1094 pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
1095 pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
1096 pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
1097 pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
1098 pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
1099 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
1100 }
1102 for (z=OUTPUT1; z < OUTPUTN; z++)
1103 {
1104 pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
1105 }
1107 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1108 return 0;
1109 } //PAF_ASOT_initPhaseConfig
1111 // -----------------------------------------------------------------------------
1112 // ASOT Initialization Function - ACP Algorithm Instantiation
1113 //
1114 // Name: PAF_ASOT_initPhaseAcpAlg
1115 // Purpose: Audio Stream Input Task Function for initialization of ACP by
1116 // instantiation of the algorithm.
1117 // From: audioStream1Task or equivalent
1118 // Uses: See code.
1119 // States: x
1120 // Return: 0 on success.
1121 // Source code line number on ACP Algorithm creation failure.
1122 // Trace: Message Log "trace" in Debug Project Configuration reports:
1123 // * State information as per parent.
1124 // * Memory allocation errors.
1125 //
1126 Int
1127 PAF_ASOT_initPhaseAcpAlg(
1128 const PAF_ASOT_Params *pP,
1129 const PAF_ASOT_Patchs *pQ,
1130 PAF_ASOT_Config *pAsotCfg
1131 )
1132 {
1133 PAF_AST_Config *pAstCfg;
1134 Int as; /* Audio Stream Number (1, 2, etc.) */
1135 Int z; /* input/encode/stream/decode/output counter */
1136 Int betaPrimeOffset;
1137 ACP_Handle acp;
1138 Int zMS;
1139 Int zS, zX;
1141 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1142 as = pAstCfg->as;
1143 zMS = pAstCfg->masterStr;
1145 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1147 ACP_MDS_init();
1149 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
1150 {
1151 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1152 return __LINE__;
1153 }
1154 pAsotCfg->acp = acp;
1156 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1157 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1159 for (z=ENCODE1; z < ENCODEN; z++)
1160 {
1161 zS = pP->streamsFromEncodes[z];
1162 acp->fxns->attach(acp, ACP_SERIES_STD,
1163 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
1164 (IALG_Status *)&pAstCfg->xEnc[z].encodeStatus);
1165 acp->fxns->attach(acp, ACP_SERIES_STD,
1166 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
1167 (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
1168 /* Ignore errors, not reported. */
1169 }
1171 for (z=OUTPUT1; z < OUTPUTN; z++)
1172 {
1173 zS = z;
1174 for (zX = ENCODE1; zX < ENCODEN; zX++)
1175 {
1176 if (pP->outputsFromEncodes[zX] == z)
1177 {
1178 zS = pP->streamsFromEncodes[zX];
1179 break;
1180 }
1181 }
1182 acp->fxns->attach(acp, ACP_SERIES_STD,
1183 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
1184 (IALG_Status *)&pAstCfg->xOut[z].outBufStatus);
1185 /* Ignore errors, not reported. */
1186 }
1188 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1190 return 0;
1191 } //PAF_ASOT_initPhaseAcpAlg
1193 // -----------------------------------------------------------------------------
1194 // ASOT Initialization Function - Common Memory
1195 //
1196 // Name: PAF_ASOT_initPhaseCommon
1197 // Purpose: Audio Stream Output Task Function for allocation of common memory.
1198 // From: audioStream1Task or equivalent
1199 // Uses: See code.
1200 // States: x
1201 // Return: 0 on success.
1202 // Source code line number on PAF_ALG_alloc failure.
1203 // Source code line number on PAF_ALG_mallocMemory failure.
1204 // Source code line number on Decode Chain initialization failure.
1205 // Source code line number on ASP Chain initialization failure.
1206 // Source code line number on Encode Chain initialization failure.
1207 // Trace: Message Log "trace" in Debug Project Configuration reports:
1208 // * State information as per parent.
1209 // * Memory allocation errors.
1210 //
1211 Int
1212 PAF_ASOT_initPhaseCommon(
1213 const PAF_ASOT_Params *pP,
1214 const PAF_ASOT_Patchs *pQ,
1215 PAF_ASOT_Config *pAsotCfg
1216 )
1217 {
1218 PAF_AST_Config *pAstCfg;
1219 Int as; /* Audio Stream Number (1, 2, etc.) */
1220 Int z; /* stream counter */
1221 Int g; /* gear */
1222 ACP_Handle acp;
1223 PAF_IALG_Config pafAlgConfig;
1224 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1226 acp = pAsotCfg->acp;
1227 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1228 as = pAstCfg->as;
1230 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
1232 //
1233 // Determine memory needs and instantiate algorithms across audio streams
1234 //
1235 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
1236 PAF_ALG_setup(&pafAlgConfig,
1237 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1238 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1239 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1240 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1241 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1242 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1243 HEAP_CLEAR);
1245 if (pP->fxns->headerPrint)
1246 {
1247 pP->fxns->headerPrint();
1248 }
1250 for (z = STREAM1; z < STREAMN; z++)
1251 {
1252 //Int zD, zE, zX;
1253 Int zE, zX;
1255 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1257 //
1258 // Determine common memory needs for:
1259 // (1) ASP Algorithms
1260 // (2) Encode Algorithms
1261 // (3) Logical Output drivers
1262 //
1263 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1265 zE = -1;
1266 for (zX = ENCODE1; zX < ENCODEN; zX++)
1267 {
1268 if (pP->streamsFromEncodes[zX] == z)
1269 {
1270 zE = zX;
1271 break;
1272 }
1273 }
1275 TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
1276 if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z]))
1277 {
1278 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1279 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1280 SW_BREAKPOINT;
1281 return __LINE__;
1282 }
1283 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1284 if (pP->fxns->allocPrint)
1285 {
1286 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1287 }
1289 if (zE >= 0)
1290 {
1291 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
1292 if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z]))
1293 {
1294 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1295 SW_BREAKPOINT;
1296 return __LINE__;
1297 }
1298 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1299 if (pP->fxns->allocPrint)
1300 {
1301 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
1302 }
1303 }
1305 //
1306 // Determine common memory needs of Logical IO drivers
1307 //
1309 if (OUTPUT1 <= z && z < OUTPUTN)
1310 {
1311 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
1312 if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
1313 {
1314 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
1315 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1316 SW_BREAKPOINT;
1317 return __LINE__;
1318 }
1319 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1320 if (pP->fxns->allocPrint)
1321 {
1322 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
1323 }
1324 }
1325 }
1326 {
1327 // Changes made to share scratch between zones
1328 // Assume maximum 3 zones and scratch common memory is at offset 0;
1329 int max=0;
1330 for (z=STREAM1; z<STREAMN; z++)
1331 {
1332 if (max < common[z][0].size)
1333 {
1334 max = common[z][0].size;
1335 }
1336 }
1337 common[STREAM1][0].size=max;
1338 for (z=STREAM1+1; z<STREAMN; z++)
1339 {
1340 common[z][0].size = 0;
1341 }
1342 }
1344 //
1345 // Allocate common memory for:
1346 // (1) ASP Algorithms
1347 // (2) Encode Algorithms
1348 // (3) Logical Output drivers
1349 //
1350 for (z = STREAM1; z < STREAMN; z++)
1351 {
1352 //Int zD, zE, zX;
1353 Int zE, zX;
1355 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1356 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1357 {
1358 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
1359 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1360 SW_BREAKPOINT;
1361 return __LINE__;
1362 }
1363 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1364 // share zone0 scratch with all zones
1365 common[z][0].base = common[0][0].base;
1366 if (pP->fxns->commonPrint)
1367 {
1368 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1369 }
1371 zE = -1;
1372 for (zX = ENCODE1; zX < ENCODEN; zX++)
1373 {
1374 if (pP->streamsFromEncodes[zX] == z)
1375 {
1376 zE = zX;
1377 break;
1378 }
1379 }
1381 pAstCfg->xStr[z].aspChain[0] = NULL;
1382 for (g=0; g < GEARS; g++)
1383 {
1384 PAF_ASP_Chain *chain;
1385 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
1386 chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
1387 HEAP_INTERNAL, as+z, acp, &trace,
1388 aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1389 if (!chain)
1390 {
1391 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1392 return __LINE__;
1393 }
1394 else
1395 {
1396 pAstCfg->xStr[z].aspChain[g] = chain;
1397 }
1398 }
1400 if (zE >= 0)
1401 {
1402 PAF_ASP_Chain *chain;
1403 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
1404 chain = PAF_ASP_chainInit(&pAstCfg->xEnc[zE].encChainData, pP->pChainFxns,
1405 HEAP_INTERNAL, as+z, acp, &trace,
1406 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
1407 if (!chain)
1408 {
1409 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
1410 return __LINE__;
1411 }
1412 }
1414 //
1415 // Allocate non-common memories for Logical IO drivers
1416 // Since these structures are used at run-time we allocate from external memory
1417 if (OUTPUT1 <= z && z < OUTPUTN)
1418 {
1419 PAF_ASP_Chain *chain;
1420 TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
1421 as+z, z);
1422 chain = PAF_ASP_chainInit (&pAstCfg->xOut[z].outChainData, pP->pChainFxns,
1423 HEAP_EXTERNAL, as+z, acp, &trace,
1424 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
1425 if (!chain)
1426 {
1427 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
1428 return __LINE__;
1429 }
1430 }
1431 }
1432 TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
1434 return 0;
1435 } //PAF_ASOT_initPhaseCommon
1437 // -----------------------------------------------------------------------------
1438 // ASOT Initialization Function - Algorithm Keys
1439 //
1440 // Name: PAF_ASOT_initPhaseAlgKey
1441 // Purpose: Audio Stream Output Task Function for initialization of data values
1442 // from parameters for Algorithm Keys.
1443 // From: audioStream1Task or equivalent
1444 // Uses: See code.
1445 // States: x
1446 // Return: 0.
1447 // Trace: Message Log "trace" in Debug Project Configuration reports:
1448 // * State information as per parent.
1449 //
1450 // .............................................................................
1451 Int
1452 PAF_ASOT_initPhaseAlgKey(
1453 const PAF_ASOT_Params *pP,
1454 const PAF_ASOT_Patchs *pQ,
1455 PAF_ASOT_Config *pAsotCfg
1456 )
1457 {
1458 PAF_AST_Config *pAstCfg;
1459 Int as; /* Audio Stream Number (1, 2, etc.) */
1460 Int z; /* decode/encode counter */
1461 Int s; /* key number */
1462 PAF_ASP_Link *that;
1464 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1465 as = pAstCfg->as;
1466 (void)as; // clear compiler warning in case not used with tracing disabled
1468 TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1470 for (z=ENCODE1; z < ENCODEN; z++)
1471 {
1472 for (s=0; s < pP->pEncAlgKey->length; s++)
1473 {
1474 if ((pP->pEncAlgKey->code[s].full != 0) &&
1475 (that = PAF_ASP_chainFind(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
1476 {
1477 pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
1478 }
1479 /* Cast in interface, for now --Kurt */
1480 else
1481 {
1482 pAstCfg->xEnc[z].encAlg[s] = NULL;
1483 }
1484 }
1485 }
1487 return 0;
1488 } //PAF_ASOT_initPhaseAlgKey
1490 // -----------------------------------------------------------------------------
1491 // ASOT Initialization Function - I/O Devices
1492 //
1493 // Name: PAF_ASOT_initPhaseDevice
1494 // Purpose: Audio Stream Output Task Function for initialization of I/O Devices.
1495 // From: audioStream1Task or equivalent
1496 // Uses: See code.
1497 // States: x
1498 // Return: 0 on success.
1499 // Source code line number on device allocation failure.
1500 // Trace: Message Log "trace" in Debug Project Configuration reports:
1501 // * State information as per parent.
1502 // * Memory allocation errors.
1503 //
1504 Int
1505 PAF_ASOT_initPhaseDevice(
1506 const PAF_ASOT_Params *pP,
1507 const PAF_ASOT_Patchs *pQ,
1508 PAF_ASOT_Config *pAsotCfg
1509 )
1510 {
1511 PAF_AST_Config *pAstCfg;
1512 Int as; /* Audio Stream Number (1, 2, etc.) */
1513 Int z; /* input/output counter */
1514 PAF_SIO_IALG_Obj *pObj;
1515 PAF_SIO_IALG_Config *pAlgConfig;
1516 PAF_IALG_Config pafAlgConfig;
1518 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1519 as = pAstCfg->as;
1520 (void)as; // clear compiler warning in case not used with tracing disabled
1522 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1524 if(pP->fxns->bufMemPrint)
1525 {
1526 PAF_ALG_setup (&pafAlgConfig,
1527 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1528 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1529 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1530 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1531 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1532 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1533 HEAP_CLEAR);
1534 TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1535 }
1537 for (z=OUTPUT1; z < OUTPUTN; z++)
1538 {
1539 PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
1541 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
1542 pAlgConfig = &pObj->config;
1544 pAstCfg->xOut[z].hTxSio = NULL;
1545 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1546 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1547 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1548 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1549 pConfig->sizeofElement = 3;
1550 pConfig->precision = 24;
1551 if(pP->fxns->bufMemPrint)
1552 {
1553 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
1554 }
1555 }
1556 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1558 return 0;
1559 } //PAF_ASOT_initPhaseDevice
1561 // -----------------------------------------------------------------------------
1562 // ASOT Initialization Function Helper - Initialization of Audio Frame
1563 //
1564 // Name: PAF_ASOT_initFrame0
1565 // Purpose: Audio Stream Output Task Function for initialization of the Audio
1566 // Frame(s) by memory allocation and loading of data pointers
1567 // and values.
1568 // From: AST Parameter Function -> decodeInfo
1569 // Uses: See code.
1570 // States: x
1571 // Return: 0 on success.
1572 // Source code line number on MEM_calloc failure.
1573 // Source code line number on unsupported option.
1574 // Trace: Message Log "trace" in Debug Project Configuration reports:
1575 // * Memory allocation errors.
1576 // * Unsupported option errors.
1577 //
1579 // MID 314
1580 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
1581 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
1583 Int
1584 PAF_ASOT_initFrame0(
1585 const PAF_ASOT_Params *pP,
1586 const PAF_ASOT_Patchs *pQ,
1587 PAF_ASOT_Config *pAsotCfg,
1588 Int z
1589 )
1590 {
1591 PAF_AST_Config *pAstCfg;
1592 Int as; /* Audio Stream Number (1, 2, etc.) */
1593 Int ch;
1594 //Int aLen;
1595 Int aLen_int=0,aLen_ext=0;
1596 Int aSize = sizeof(PAF_AudioData);
1597 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1598 Int maxFrameLength = pP->maxFramelength;
1599 Int zX;
1600 PAF_AudioData *aBuf_int=NULL;
1601 PAF_AudioData *aBuf_ext=NULL;
1602 XDAS_UInt8 *metadataBuf;
1603 char i;
1604 Error_Block eb;
1606 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1607 as = pAstCfg->as;
1609 // Initialize error block
1610 Error_init(&eb);
1612 // Compute maximum framelength (needed for ARC support)
1613 maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
1614 //aLen = numchan[z] * maxFrameLength;
1615 for (i=0; i < numchan[z]; i++)
1616 {
1617 if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1618 {
1619 aLen_int += maxFrameLength;
1620 }
1621 else
1622 {
1623 aLen_ext += maxFrameLength;
1624 }
1625 }
1627 //
1628 // Initialize audio frame elements directly
1629 //
1630 pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
1631 pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
1632 /// pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
1633 pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
1634 pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
1635 pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
1636 pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1638 //
1639 // Allocate memory for and initialize pointers to audio data buffers
1640 //
1641 // The NUMCHANMASK is used to identify the channels for which data
1642 // buffers can be allocated. Using this mask and switch statement
1643 // rather than some other construct allows efficient code generation,
1644 // providing just the code necessary (with significant savings).
1645 //
1646 if (pP->fxns->bufMemPrint)
1647 {
1648 pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
1649 pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
1650 }
1652 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1654 if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
1655 {
1656 if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb))) //Qin: Add start offset
1657 {
1658 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1659 TRACE_TERSE2(" maxFrameLength: %d. aLen_int*aSize: %d", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize);
1660 SW_BREAKPOINT;
1661 return __LINE__;
1662 }
1663 }
1665 if (aLen_ext*aSize!=0)
1666 {
1667 if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb)))//Qin: Add start offset
1668 {
1669 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1670 TRACE_TERSE2(" maxFrameLength: %d. aLen_ext*aSize: %d", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize);
1671 SW_BREAKPOINT;
1672 return __LINE__;
1673 }
1674 }
1676 TRACE_TERSE3(" maxFrameLength: %d. aLen_int*aSize: %d. aBuf_int: 0x%x", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_int);
1677 TRACE_TERSE3(" maxFrameLength: %d. aLen_ext*aSize: %d. aBuf_ext: 0x%x", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_ext);
1679 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1680 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1681 {
1682 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1683 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1684 SW_BREAKPOINT;
1685 return __LINE__;
1686 }
1688 {
1689 Int i;
1691 #pragma UNROLL(1)
1692 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1693 {
1694 pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
1695 }
1696 }
1698 // MID 314
1699 if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1700 {
1701 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
1702 return __LINE__;
1703 }
1704 else
1705 {
1706 Int j = 0;
1707 Int k = 0;
1708 TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1709 for(i=0;i<numchan[z];i++)
1710 {
1711 char chan = AFChanPtrMap[numchan[z]][i];
1712 if(chan != -1)
1713 {
1714 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1715 {
1716 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
1717 j++;
1718 }
1719 else
1720 {
1721 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1722 k++;
1723 }
1724 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1725 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
1726 }
1727 }
1728 }
1730 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1731 {
1732 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1733 {
1734 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
1735 }
1736 }
1738 //
1739 // Initialize meta data elements
1740 //
1741 pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1742 pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1743 pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1744 pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1745 pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1746 for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1747 {
1748 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1749 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1750 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1751 }
1753 //
1754 // Initialize decoder elements directly
1755 //
1757 for (zX = DECODE1; zX < DECODEN; zX++)
1758 {
1759 if (pP->streamsFromDecodes[zX] == z)
1760 {
1761 #ifdef NOAUDIOSHARE
1762 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1763 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1764 #else /* NOAUDIOSHARE */
1765 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1766 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1767 #endif /* NOAUDIOSHARE */
1768 }
1769 }
1771 return 0;
1772 } //PAF_ASOT_initFrame0
1774 // -----------------------------------------------------------------------------
1775 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1776 // AST Decoding Function - Reinitialization of Audio Frame
1777 //
1778 // Name: PAF_ASOT_initFrame1
1779 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1780 // zation of the Audio Frame(s) by loading of data values of a
1781 // time-varying nature.
1782 // From: audioStream1Task or equivalent
1783 // AST Parameter Function -> decodeInfo
1784 // AST Parameter Function -> decodeDecode
1785 // Uses: See code.
1786 // States: x
1787 // Return: 0.
1788 // Trace: None.
1789 //
1790 Int
1791 PAF_ASOT_initFrame1(
1792 const PAF_ASOT_Params *pP,
1793 const PAF_ASOT_Patchs *pQ,
1794 PAF_ASOT_Config *pAsotCfg,
1795 Int z,
1796 Int apply
1797 )
1798 {
1799 PAF_AST_Config *pAstCfg;
1801 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1803 //
1804 // Reinitialize audio frame elements:
1805 //
1806 // Channel Configurations during sys init = Unknown
1807 // " " during info or decode = None
1808 //
1809 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1810 //
1812 if (apply < 0)
1813 {
1814 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1815 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1816 }
1817 else
1818 {
1819 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1820 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1821 }
1823 if (apply < 1)
1824 {
1825 pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1826 pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
1827 }
1829 return 0;
1830 } //PAF_ASOT_initFrame1
1832 // -----------------------------------------------------------------------------
1833 // ASOT Selection Function - Output Device Selection
1834 //
1835 // Name: PAF_ASOT_selectDevices
1836 // Purpose: Audio Stream Output Task Function for selecting the devices used
1837 // for output.
1838 // From: audioStream1Task or equivalent
1839 // Uses: See code.
1840 // States: x
1841 // Return: Error number in standard form (0 on success).
1842 // Trace: Message Log "trace" in Debug Project Configuration reports:
1843 // * State information as per parent.
1844 //
1845 Int
1846 PAF_ASOT_selectDevices(
1847 const PAF_ASOT_Params *pP,
1848 const PAF_ASOT_Patchs *pQ,
1849 PAF_ASOT_Config *pAsotCfg
1850 )
1851 {
1852 PAF_AST_Config *pAstCfg;
1853 Int as; /* Audio Stream Number (1, 2, etc.) */
1854 Int z; /* input/output counter */
1855 Int errno = 0; /* error number */
1856 Int errme; /* error number, local */
1857 Int device;
1859 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1860 as = pAstCfg->as;
1861 (void)as; // clear compiler warning in case not used with tracing disabled
1863 // Select output devices
1864 for (z=OUTPUT1; z < OUTPUTN; z++)
1865 {
1866 if ((device = pAstCfg->xOut[z].outBufStatus.sioSelect) >= 0)
1867 {
1868 TRACE_VERBOSE2("PAF_ASOT_selectDevices: AS%d: output device %d selecting ...", as+z, device);
1870 /* check for valid index into device array */
1871 if (device >= pQ->devout->n)
1872 {
1873 device = 0; /* treat as device None */
1874 }
1876 errme = pP->fxns->deviceSelect(&pAstCfg->xOut[z].hTxSio, SIO_OUTPUT,
1877 HEAP_ID_OUTBUF, (Ptr)pQ->devout->x[device]);
1878 if (errme)
1879 {
1880 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1881 if (!errno)
1882 {
1883 errno = ASPERR_DEVOUT + errme;
1884 }
1885 pAstCfg->xOut[z].outBufStatus.sioSelect = 0x80;
1886 }
1887 else
1888 {
1889 Int zE;
1891 pAstCfg->xOut[z].outBufStatus.sioSelect = device | 0x80;
1892 // register outBufStatus and encodeStatus pointers with output devices
1893 // This enables proper IEC encapsulation.
1894 if (pAstCfg->xOut[z].hTxSio)
1895 {
1896 // set max # of output buffers (use override if necessary)
1897 if (pAstCfg->xOut[z].outBufStatus.maxNumBufOverride == 0)
1898 {
1899 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1900 (Arg)pP->poutNumBufMap[z]->maxNumBuf);
1901 }
1902 else
1903 {
1904 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1905 (Arg)pAstCfg->xOut[z].outBufStatus.maxNumBufOverride);
1906 }
1908 // register PAF_SIO_IALG object address
1909 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_IALGADDR,
1910 (Arg)pAstCfg->xOut[z].outChainData.head->alg);
1911 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_BUFSTATUSADDR,
1912 (Arg)&pAstCfg->xOut[z].outBufStatus);
1913 for (zE=ENCODE1; zE < ENCODEN; zE++)
1914 {
1915 if (pP->outputsFromEncodes[zE] == z)
1916 {
1917 SIO_ctrl(pAstCfg->xOut[z].hTxSio,
1918 PAF_SIO_CONTROL_SET_ENCSTATUSADDR,
1919 (Arg)&pAstCfg->xEnc[zE].encodeStatus);
1920 break;
1921 }
1922 }
1923 }
1924 }
1925 }
1927 /* No need to start-clocks here, since only selecting the device. */
1928 #if 0
1929 // if device selected and valid then enable stat tracking if
1930 // required and start clocking
1931 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
1932 {
1933 TRACE_VERBOSE0("PAF_ASOT_selectDevices: start SIO clocks");
1934 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
1935 if (errme)
1936 {
1937 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1938 SIO_idle(pAstCfg->xOut[z].hTxSio);
1939 if (!errno)
1940 {
1941 errno = ASPERR_DEVOUT + errme;
1942 }
1943 }
1944 }
1945 #endif
1946 }
1948 return errno;
1949 } //PAF_ASOT_selectDevices
1952 // -----------------------------------------------------------------------------
1953 // ASOT Processing Function - Decode Processing
1954 //
1955 // Name: PAF_ASOT_decodeProcessing
1956 // Purpose: Audio Stream Output Task Function for processing audio data.
1957 //
1958 Int
1959 PAF_ASOT_decodeProcessing(
1960 const PAF_ASOT_Params *pP,
1961 const PAF_ASOT_Patchs *pQ,
1962 PAF_ASOT_Config *pAsotCfg
1963 )
1964 {
1965 PAF_AST_Config *pAstCfg;
1966 Int errno; /* error number */
1967 Int getVal;
1968 enum { INIT, STREAM, ENCODE, FINAL, QUIT, OUT_SIO_UPDATE } state;
1969 state = INIT;
1970 errno = 0; /* error number */
1971 Int frame; // (***) FL: formerly -- decoder input frame count
1972 Int block; // decoder output block count / input frame
1973 Int outSioUpdate;
1975 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1977 for (;;)
1978 {
1979 //
1980 // Check forward (ASIT) error here, TBD
1981 //
1983 // If writeDECCommandRestart issued, force exit the statemachine
1984 if (gCommandOutputTask_SYNC) {
1985 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: writeDECCommandRestart issued in state=0x%x ... exiting core loop", state);
1986 errno = ASOP_DP_FORWARD_ERR;
1987 break;
1988 }
1990 // Check if any change in output SIO, e.g. from Output shortcut.
1991 // Changes will break FSM and allow Output reconfiguration.
1992 errno = checkOutSio(pP, pAsotCfg, &outSioUpdate);
1993 if (errno < 0)
1994 {
1995 TRACE_TERSE1("PAF_ASOT_decodeProcessing: checkOutSio returned errno = 0x%04x", errno);
1996 break;
1997 }
1998 else if (outSioUpdate)
1999 {
2000 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Change in Output SIO selection");
2001 state = OUT_SIO_UPDATE;
2002 }
2004 // Process commands (encode)
2005 getVal = pP->fxns->encodeCommand(pP, pQ, pAsotCfg);
2006 if (getVal)
2007 {
2008 /* ignore */;
2009 }
2011 // Process state (decode)
2012 switch (state)
2013 {
2014 case INIT: // initial state
2015 gAsopInitCnt++;
2016 Log_info0("TaskAsop: state=INIT");
2018 frame = 0;
2019 block = 0;
2021 #if 0 // FL: moved to PAF_ASOT_initOutProc()
2022 // Reset audio frame pointers to original values
2023 // (may be needed if error occurred).
2024 resetAfPointers(pP, pAstCfg->xStr);
2025 // Reset audio frame meta data elements
2026 resetAfMetadata(pP, pAstCfg->xStr);
2027 #endif
2029 errno = pP->fxns->decodeInit(pP, pQ, pAsotCfg);
2030 if (errno)
2031 {
2032 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
2033 errno = ASOP_DP_DECINIT_ERR;
2034 break;
2035 }
2037 //
2038 // Setup output: setCheckRateX, start output
2039 //
2040 // Establish secondary timing
2041 errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, frame, block);
2042 if (errno)
2043 {
2044 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInfo1", errno);
2045 break;
2046 }
2048 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: INIT->STREAM");
2049 state = STREAM;
2050 continue;
2052 case STREAM: // stream state
2053 gAsopStreamCnt++;
2054 Log_info0("TaskAsop: state=STREAM");
2056 errno = pP->fxns->decodeStream(pP, pQ, pAsotCfg, frame, block);
2057 if (errno)
2058 {
2059 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: STREAM. decodeStream err 0x%x", errno);
2060 errno = ASOP_DP_DECSTREAM_ERR;
2061 break;
2062 }
2064 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: STREAM->ENCODE");
2065 state = ENCODE;
2066 continue;
2068 case ENCODE: // encode state
2069 gAsopEncodeCnt++;
2070 Log_info0("TaskAsop: state=ENCODE");
2072 errno = pP->fxns->decodeEncode(pP, pQ, pAsotCfg, frame, block);
2073 if (errno)
2074 {
2075 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: ENCODE. decodeEncode err 0x%x", errno);
2076 errno = ASOP_DP_DECENC_ERR;
2077 break;
2078 }
2080 // Measure cycles in output processing loop.
2081 // Only measures cycles spent in loop.
2082 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS);
2083 gNumPfpAsot1--;
2084 pfpBegin(PFP_ID_ASOT_1, pAsotCfg->taskHandle);
2085 gNumPfpAsot1++;
2087 // (***) FL: do we need this?
2088 // AF pointers come from CB read, any resets occur in Decoder AF.
2089 //
2090 // Reset audio frame pointers to original values
2091 // (may have been adjusted by ARC or the like).
2092 resetAfPointers(pP, pAstCfg->xStr);
2094 // (***) FL: update output (setCheckRateX)
2095 // Contained in INFO2 in combined FSM.
2096 errno = pP->fxns->decodeInfo2(pP, pQ, pAsotCfg, frame, block);
2097 if (errno)
2098 {
2099 TRACE_TERSE1("PAF_ASOT_decodeProcessing: ENCODE break on decodeInfo2. errno 0x%x", errno);
2100 errno = ASOP_DP_DECINFO2_ERR;
2101 break;
2102 }
2104 block++;
2105 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: ENCODE->FINAL");
2106 state = FINAL;
2107 continue;
2109 case FINAL:
2110 gAsopFinalCnt++;
2111 Log_info0("TaskAsop: state=FINAL");
2113 //
2114 // (***) FL: this needs to be fixed.
2115 // (1) Only require selected Output to be in this FSM
2116 // => Dec Status checks aren't valid,
2117 // will probably always exit FSM if only Output running
2118 // (2) Checking Dec Status info asych to input events (maybe ok)
2119 //
2120 // Check for final frame, and if indicated:
2121 // - Update audio flag to cause output buffer flush rather than
2122 // the default truncate in "complete" processing.
2123 // - Exit state machine to "complete" processing.
2124 #if 0
2125 if (pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block))
2126 {
2127 for (z=OUTPUT1; z < OUTPUTN; z++)
2128 {
2129 if ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND)
2130 {
2131 TRACE_VERBOSE0("PAF_ASOT_outputProcessing: state: FINAL: SOUND -> QUIET");
2132 pAstCfg->xOut[z].outBufStatus.audio++; // SOUND -> QUIET
2133 }
2134 }
2135 break;
2136 }
2137 #endif
2138 errno = pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block);
2139 if (errno < 0)
2140 {
2141 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL break. errno 0x%x", errno);
2142 errno = ASOP_DP_DECFINALTEST_ERR;
2143 break;
2144 }
2145 else if (errno == ASOP_DP_CB_DRAINED)
2146 {
2147 // EOS, exit normally
2148 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL normal exit. errno 0x%x", errno);
2149 errno = ASOP_DP_SOK;
2150 break;
2151 }
2153 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: FINAL->STREAM");
2154 state = STREAM;
2155 continue;
2157 case OUT_SIO_UPDATE:
2158 gAsopOutSioUpdateCnt++;
2159 Log_info0("TaskAsop: state=OUT_SIO_UPDATE");
2161 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: OUT_SIO_UPDATE");
2162 errno = ASOP_DP_OUT_SIO_UPDATE;
2163 break;
2165 case QUIT:
2166 gAsopQuitCnt++;
2167 Log_info0("TaskAsop: state=QUIT");
2169 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: QUIT");
2170 errno = ASPERR_QUIT;
2171 break;
2173 default: // unknown state
2174 // Unknown:
2175 // - Set error number registers.
2176 // - Exit state machine to "complete" processing.
2178 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: unknown, 0x%x", state);
2179 errno = ASPERR_UNKNOWNSTATE;
2180 break;
2182 } // End of switch (state).
2184 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Calling decode complete");
2185 if (pP->fxns->decodeComplete(pP, pQ, pAsotCfg, NULL, frame, block))
2186 {
2187 /* ignored? */;
2188 }
2190 //pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
2191 //gNumPfpAsot1--;
2193 //return errno;
2194 break;
2195 } // End of for (;;)
2197 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
2198 gNumPfpAsot1--;
2200 return errno;
2201 }
2203 // -----------------------------------------------------------------------------
2204 // ASOT Decoding Function - Encode Command Processing
2205 //
2206 // Name: PAF_ASOT_encodeCommand
2207 // Purpose: Decoding Function for processing Encode Commands.
2208 // From: AST Parameter Function -> decodeProcessing
2209 // Uses: See code.
2210 // States: x
2211 // Return: 0.
2212 // Trace: Message Log "trace" in Debug Project Configuration reports:
2213 // * Command execution.
2214 // * SIO control errors.
2215 // * Error number macros.
2216 //
2217 Int
2218 PAF_ASOT_encodeCommand(
2219 const PAF_ASOT_Params *pP,
2220 const PAF_ASOT_Patchs *pQ,
2221 PAF_ASOT_Config *pAsotCfg
2222 )
2223 {
2224 PAF_AST_Config *pAstCfg;
2225 Int as; /* Audio Stream Number (1, 2, etc.) */
2226 Int z; /* encode counter */
2227 Int errno = 0; /* error number */
2228 Int zO, zS;
2231 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2232 as = pAstCfg->as;
2234 for (z=ENCODE1; z < ENCODEN; z++)
2235 {
2236 zO = pP->outputsFromEncodes[z];
2237 zS = pP->streamsFromEncodes[z];
2238 if (! (pAstCfg->xEnc[z].encodeStatus.command2 & 0x80))
2239 {
2240 switch (pAstCfg->xEnc[z].encodeStatus.command2)
2241 {
2242 case 0: // command none - process
2243 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2244 break;
2245 case 1: // mute command
2246 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command mute (0x%02x)", as+zS, 1);
2247 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2248 && pAstCfg->xOut[zO].hTxSio
2249 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2250 {
2251 errno = (errno & 0xff) | ASPERR_MUTE;
2252 /* convert to sensical errno */
2253 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (mute)", as+zS);
2254 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2255 }
2256 else
2257 {
2258 pAstCfg->xOut[zO].outBufStatus.audio |= PAF_OB_AUDIO_MUTED;
2259 }
2260 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2261 break;
2262 case 2: // unmute command
2263 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command unmute (0x%02x)", as+zS, 2);
2264 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2265 && pAstCfg->xOut[zO].hTxSio
2266 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2267 {
2268 errno = (errno & 0xff) | ASPERR_MUTE;
2269 /* convert to sensical errno */
2270 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (unmute)", as+zS);
2271 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2272 }
2273 else
2274 {
2275 pAstCfg->xOut[zO].outBufStatus.audio &= ~PAF_OB_AUDIO_MUTED;
2276 }
2277 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2278 break;
2279 default: // command unknown - ignore
2280 break;
2281 }
2282 }
2283 }
2285 ERRNO_RPRT (TaskAsop, errno);
2287 return 0;
2288 } //PAF_ASOT_encodeCommand
2290 //debug -- allow dynamic config
2291 //Int16 gStrFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
2293 // Purpose: Decoding Function for reinitializing the decoding process.
2294 Int
2295 PAF_ASOT_decodeInit(
2296 const PAF_ASOT_Params *pP,
2297 const PAF_ASOT_Patchs *pQ,
2298 PAF_ASOT_Config *pAsotCfg
2299 )
2300 {
2301 //PAF_AST_Config *pAstCfg;
2302 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2303 //Int as; /* Audio Stream Number (1, 2, etc.) */
2304 Int z; /* decode/encode counter */
2305 Int errno; /* error number */
2306 //Int zO, zS;
2308 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2309 //as = pAstCfg->as;
2311 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2313 for (z=DECODE1; z < DECODEN; z++)
2314 {
2315 // Initialize decoder output circular buffer for stream reads
2316 //errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
2317 errno = cbInitStreamRead(pCbCtl, z);
2318 if (errno)
2319 {
2320 TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
2321 SW_BREAKPOINT; // debug
2322 return errno;
2323 }
2325 // Start decoder output circular buffer reads
2326 errno = cbReadStart(pCbCtl, z);
2327 if (errno)
2328 {
2329 TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
2330 SW_BREAKPOINT; // debug
2331 return errno;
2332 }
2334 gCbReadAfErr=0; // reset read circular buffer error count
2335 gDecOpCbRdAfUnd=0; // reset decoder output circular buffer underflow count
2336 gMaxDecOpCbRdAfUnd=0; // reset max decoder output circular buffer underflow count
2337 gMasterCbResetCnt=0; // reset master circular buffer reset count
2339 // FL: debug, log circular buffer control variables
2340 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
2341 }
2343 #if 0 // moved to PAF_ASOT_outputReset()
2344 // TODO: move this to start of this function so that it doesn't affect IO timing
2345 for (z=ENCODE1; z < ENCODEN; z++)
2346 {
2347 zO = pP->outputsFromEncodes[z];
2348 zS = pP->streamsFromEncodes[z];
2349 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2350 {
2351 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2352 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2353 ENC_Handle enc = (ENC_Handle )encAlg;
2354 TRACE_VERBOSE1("AS%d: PAF_ASOT_decodeInit: initializing encode", as+zS);
2355 if (encAlg->fxns->algActivate)
2356 {
2357 encAlg->fxns->algActivate (encAlg);
2358 }
2359 if (enc->fxns->reset)
2360 {
2361 errno = enc->fxns->reset(enc, NULL,
2362 &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus);
2363 if (errno)
2364 {
2365 return errno;
2366 }
2367 }
2368 }
2369 }
2370 #endif
2372 return 0;
2373 }
2375 // -----------------------------------------------------------------------------
2376 // ASOT Decoding Function - Info Processing, Initial
2377 //
2378 // Name: PAF_ASOT_decodeInfo1
2379 // Purpose: Decoding Function for processing information in a manner that
2380 // is unique to initial frames of input data.
2381 // From: AST Parameter Function -> decodeProcessing
2382 // Uses: See code.
2383 // States: x
2384 // Return: Error number in standard or SIO form (0 on success).
2385 // Trace: Message Log "trace" in Debug Project Configuration reports:
2386 // * State information as per parent.
2387 //
2388 Int
2389 PAF_ASOT_decodeInfo1(
2390 const PAF_ASOT_Params *pP,
2391 const PAF_ASOT_Patchs *pQ,
2392 PAF_ASOT_Config *pAsotCfg,
2393 Int frame,
2394 Int block
2395 )
2396 {
2397 //PAF_AST_Config *pAstCfg;
2398 //Int z; /* decode/encode counter */
2399 Int errno; /* error number */
2401 #if 0 // moved to PAF_ASOT_outputInfo1()
2402 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2404 // run the chain of ASP's on the stream.
2405 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
2406 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2407 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame);
2408 if (errno)
2409 {
2410 TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
2411 return errno;
2412 }
2414 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
2415 for (z=ENCODE1; z < ENCODEN; z++)
2416 {
2417 Int zO = pP->outputsFromEncodes[z];
2418 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2419 {
2420 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2421 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2422 ENC_Handle enc = (ENC_Handle )encAlg;
2424 if (enc->fxns->info)
2425 {
2426 errno = enc->fxns->info(enc, NULL,
2427 &pAstCfg->xEnc[z].encodeControl,
2428 &pAstCfg->xEnc[z].encodeStatus);
2429 if (errno)
2430 {
2431 TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
2432 return errno;
2433 }
2434 }
2435 }
2436 }
2437 #endif
2439 errno = pP->fxns->setCheckRateX(pP, pQ, pAsotCfg, 0);
2440 if (errno)
2441 {
2442 // ignore if rateX has changed since we haven't, but are about to,
2443 // start the output. If we didn't ignore this case then the state machine
2444 // would restart unnecessarily, e.g. in the case of SRC, resulting in
2445 // added latency.
2446 if (errno != ASPERR_INFO_RATECHANGE)
2447 {
2448 TRACE_TERSE1("PAF_ASOT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
2449 return errno;
2450 }
2451 else
2452 {
2453 TRACE_TERSE0("PAF_ASOT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
2454 }
2455 }
2457 errno = pP->fxns->startOutput(pP, pQ, pAsotCfg);
2458 if (errno)
2459 {
2460 if (errno == 0x105)
2461 {
2462 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
2463 }
2464 else
2465 {
2466 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
2467 }
2468 return errno;
2469 }
2471 return 0;
2472 }
2474 // -----------------------------------------------------------------------------
2475 // ASOT Decoding Function - Info Processing, Subsequent
2476 //
2477 // Name: PAF_ASOT_decodeInfo2
2478 // Purpose: Decoding Function for processing information in a manner that
2479 // is unique to frames of input data other than the initial one.
2480 // From: AST Parameter Function -> decodeProcessing
2481 // Uses: See code.
2482 // States: x
2483 // Return: Error number in standard form (0 on success).
2484 // Trace: None.
2485 //
2486 Int
2487 PAF_ASOT_decodeInfo2(
2488 const PAF_ASOT_Params *pP,
2489 const PAF_ASOT_Patchs *pQ,
2490 PAF_ASOT_Config *pAsotCfg,
2491 Int frame,
2492 Int block
2493 )
2494 {
2495 //PAF_AST_Config *pAstCfg;
2496 Int errno;
2499 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2501 errno = pP->fxns->setCheckRateX (pP, pQ, pAsotCfg, 1);
2502 TRACE_VERBOSE1("PAF_ASOT_decodeInfo2: return 0x%x", errno);
2503 return errno;
2504 } //PAF_ASOT_decodeInfo2
2507 PAF_AST_DecOpCircBufStats gCbStats; // FL: debug
2508 // -----------------------------------------------------------------------------
2509 // ASOT Decoding Function - Stream Processing
2510 //
2511 // Name: PAF_ASOT_decodeStream
2512 // Purpose: Decoding Function for processing of audio frame data by the
2513 // ASP Algorithms.
2514 // From: AST Parameter Function -> decodeProcessing
2515 // Uses: See code.
2516 // States: x
2517 // Return: Error number in standard form (0 on success).
2518 // Trace: Message Log "trace" in Debug Project Configuration reports:
2519 // * State information as per parent/child.
2520 //
2521 Int
2522 PAF_ASOT_decodeStream(
2523 const PAF_ASOT_Params *pP,
2524 const PAF_ASOT_Patchs *pQ,
2525 PAF_ASOT_Config *pAsotCfg,
2526 Int frame,
2527 Int block
2528 )
2529 {
2530 PAF_AST_Config *pAstCfg;
2531 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2532 Int z; /* decode/stream counter */
2533 PAF_AudioFrame *pAfRd;
2534 Int cbErrno;
2535 //PAF_AST_DecOpCircBufStats cbStats; /* circular buffer statistics */
2536 Int errno;
2539 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2541 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2543 for (z=DECODE1; z < DECODEN; z++)
2544 {
2545 Int zS = pP->streamsFromDecodes[z];
2547 //
2548 // Read decoder output circular buffer
2549 //
2550 pAfRd = pAstCfg->xStr[zS].pAudioFrame;
2551 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2552 cbErrno = cbReadAf(pCbCtl, z, pAfRd);
2553 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2554 if ((cbErrno < 0) &&
2555 (cbErrno != ASP_DECOP_CB_AF_READ_UNDERFLOW) &&
2556 (cbErrno != ASP_DECOP_CB_PCM_READ_UNDERFLOW))
2557 {
2558 gCbReadAfErr++;
2559 TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
2560 //SW_BREAKPOINT; // debug
2561 return cbErrno;
2562 }
2564 // Handle underflows
2565 if ((cbErrno == ASP_DECOP_CB_AF_READ_UNDERFLOW) ||
2566 (cbErrno == ASP_DECOP_CB_PCM_READ_UNDERFLOW))
2567 {
2568 // (***) FL: Need to check behavior of cbReset().
2569 // Need to check behavior on exit/re-entry into Output processing.
2570 gDecOpCbRdAfUnd++; // increment circular buffer underflow count
2571 if (gDecOpCbRdAfUnd >= DEC_OP_CB_RDAF_UND_THR)
2572 {
2573 // Underflow count above threshold.
2574 // (1) set max underflow count to threshold
2575 // (2) reset underflow count
2576 // (3) reset circular buffer
2578 gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
2579 gDecOpCbRdAfUnd = 0; // reset underflow count
2581 // Reset circular buffer
2582 cbReset(pCbCtl, z);
2583 gMasterCbResetCnt++; // increment master circular buffer reset count
2584 Log_info0("ASOT:cbReset");
2586 return cbErrno;
2587 }
2588 }
2589 else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbRdAfUnd > 0))
2590 {
2591 // No underflow detected.
2592 // update max underflow count,
2593 // reset underflow count
2595 // update max underflow count
2596 if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
2597 {
2598 gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
2599 }
2600 gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
2601 }
2602 //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2603 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2604 Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2606 #if 0 // (***) FL: shows timing of CB read
2607 // (***) debug // B8
2608 {
2609 static Uint8 toggleState = 0;
2610 if (toggleState == 0)
2611 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2612 else
2613 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2614 toggleState = ~(toggleState);
2615 }
2616 #endif
2618 // debug, get circular buffer statistics
2619 //cbGetStats(pCbCtl, z, &cbStats);
2620 cbGetStats(pCbCtl, z, &gCbStats);
2622 // debug
2623 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
2625 #if 0 // debug, capture audio frame
2626 if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
2627 {
2628 Log_info0("capAfWrite() error");
2629 }
2630 #endif
2631 }
2633 TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
2634 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2635 PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
2636 if (errno)
2637 {
2638 TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
2639 return errno;
2640 }
2642 return 0;
2644 } //PAF_ASOT_decodeStream
2646 // -----------------------------------------------------------------------------
2647 // ASOT Decoding Function - Encode Processing
2648 //
2649 // Name: PAF_ASOT_decodeEncode
2650 // Purpose: Decoding Function for processing of audio frame data by the
2651 // Encode Algorithm.
2652 // From: AST Parameter Function -> decodeProcessing
2653 // Uses: See code.
2654 // States: x
2655 // Return: Error number in standard or SIO form (0 on success).
2656 // Trace: Message Log "trace" in Debug Project Configuration reports:
2657 // * State information as per parent.
2658 //
2659 Int
2660 PAF_ASOT_decodeEncode(
2661 const PAF_ASOT_Params *pP,
2662 const PAF_ASOT_Patchs *pQ,
2663 PAF_ASOT_Config *pAsotCfg,
2664 Int frame,
2665 Int block
2666 )
2667 {
2668 PAF_AST_Config *pAstCfg;
2669 Int as; /* Audio Stream Number (1, 2, etc.) */
2670 Int z; /* encode/output counter */
2671 Int errno; /* error number */
2672 Int zX, zE, zS;
2673 // debug
2674 //UInt32 curTime;
2676 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2677 as = pAstCfg->as;
2679 // Await output buffers (but not first time)
2680 for (z=OUTPUT1; z < OUTPUTN; z++)
2681 {
2682 // determine encoder associated with this output
2683 zE = z;
2684 for (zX = ENCODE1; zX < ENCODEN; zX++)
2685 {
2686 if (pP->outputsFromEncodes[zX] == z)
2687 {
2688 zE = zX;
2689 break;
2690 }
2691 }
2692 zS = pP->streamsFromEncodes[zE];
2694 if (pAstCfg->xOut[z].hTxSio)
2695 {
2696 // update length (e.g. ARC may have changed)
2697 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
2698 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2699 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- idle", as+zS, block);
2700 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2701 errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
2702 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2703 if (errno < 0)
2704 {
2705 SIO_idle(pAstCfg->xOut[z].hTxSio);
2706 TRACE_TERSE2("PAF_ASOT_decodeEncode: AS%d: SIO_reclaim returns error %d", as+zS, -errno);
2707 return -errno; // SIO negates error codes
2708 }
2709 // TODO: use pC->xOut[z].pOutBuf in following ->encode call
2711 #if 0 // (***) FL: shows timing of Output Tx SIO reclaim
2712 // (***) debug // B8
2713 {
2714 static Uint8 toggleState = 0;
2715 if (toggleState == 0)
2716 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2717 else
2718 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2719 toggleState = ~(toggleState);
2720 }
2721 #endif
2723 //
2724 // Simulate Tx SIO_reclaim() pend
2725 //
2726 //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
2727 //curTime = Clock_getTicks();
2728 //System_printf("System time in TaskAsopFxn Tx audio = %lu\n", (ULong)curTime);
2729 //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
2731 gAsopTxSioReclaimCnt++;
2732 }
2733 else
2734 {
2735 TRACE_VERBOSE2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- idle <ignored>", as+zS, block);
2736 }
2737 }
2739 // Encode data
2740 for (z=ENCODE1; z < ENCODEN; z++)
2741 {
2742 Int zO = pP->outputsFromEncodes[z];
2743 Int zS = pP->streamsFromEncodes[z];
2744 (void)zS; // clear compiler warning in case not used with tracing disabled
2745 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2746 {
2747 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2748 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2749 ENC_Handle enc = (ENC_Handle )encAlg;
2750 if (select != pAstCfg->xEnc[z].encodeControl.encActive)
2751 {
2752 pAstCfg->xEnc[z].encodeControl.encActive = select;
2753 TRACE_TERSE0("PAF_ASOT_decodeEncode: return error");
2754 return (-1);
2755 }
2756 TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- encode", as+zS, block);
2758 // (MID 1933) temp. workaround for PCE2
2759 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
2761 /*
2762 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2763 {
2764 PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
2765 int *wp;
2766 wp = (int*)pAudioFrame->data.sample[0];
2767 TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
2768 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
2769 wp = (int*)pAudioFrame->data.sample[1];
2770 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
2771 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
2772 wp = (int*)pAudioFrame->data.sample[2];
2773 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
2774 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
2775 }
2776 #endif
2777 */
2779 if (enc->fxns->encode)
2780 {
2781 pAstCfg->xEnc[z].encodeOutStruct.bypassFlag =
2782 pP->z_pEncodeStatus[z]->encBypass;
2783 errno = enc->fxns->encode(enc, NULL,
2784 &pAstCfg->xEnc[z].encodeInStruct,
2785 &pAstCfg->xEnc[z].encodeOutStruct);
2786 if (errno)
2787 {
2788 if (errno != PCEERR_OUTPUT_POINTERNULL)
2789 {
2790 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error %d line %d", errno);
2791 return errno;
2792 }
2793 }
2794 /* #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2795 else
2796 {
2797 int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
2798 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
2799 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
2800 }
2801 #endif
2802 */
2803 }
2804 }
2805 else
2806 {
2807 TRACE_VERBOSE2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- encode <ignored>",
2808 as+pP->streamsFromEncodes[z], block);
2809 }
2810 }
2812 // Transmit data
2813 for (z=OUTPUT1; z < OUTPUTN; z++)
2814 {
2815 // determine encoder associated with this output
2816 zE = z;
2817 for (zX = ENCODE1; zX < ENCODEN; zX++)
2818 {
2819 if (pP->outputsFromEncodes[zX] == z)
2820 {
2821 zE = zX;
2822 break;
2823 }
2824 }
2825 zS = pP->streamsFromEncodes[zE];
2827 if (pAstCfg->xOut[z].hTxSio)
2828 {
2829 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
2830 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2831 errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2832 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
2833 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2834 if (errno)
2835 {
2836 SIO_idle(pAstCfg->xOut[z].hTxSio);
2837 if (errno == 0x105) // 0x105 == RINGIO_EBUFFULL
2838 {
2839 // statStruct_LogFullRing(STATSTRUCT_AS1_F2);
2840 TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
2841 }
2842 if (errno > 0)
2843 {
2844 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error 0x%x line %d", errno);
2845 return (ASPERR_ISSUE + (z << 4));
2846 }
2847 else if (errno < 0)
2848 {
2849 TRACE_TERSE1("PAF_ASOT_decodeEncode: return neg error 0x%x line %d", -errno);
2850 return -errno; // SIO negates error codes
2851 }
2852 }
2853 if (errno > 0)
2854 {
2855 return (ASPERR_ISSUE + (z << 4));
2856 }
2857 else if (errno < 0)
2858 {
2859 return -errno; // SIO negates error codes
2860 }
2861 }
2862 else
2863 {
2864 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output <ignored>", as+zS, block);
2865 }
2866 }
2868 return 0;
2869 } //PAF_ASOT_decodeEncode
2871 // -----------------------------------------------------------------------------
2872 // ASOT Decoding Function - Stream-Final Processing
2873 //
2874 // Name: PAF_ASOT_decodeComplete
2875 // Purpose: Decoding Function for terminating the decoding process.
2876 // From: AST Parameter Function -> decodeProcessing
2877 // Uses: See code.
2878 // States: x
2879 // Return: 0.
2880 // Trace: Message Log "trace" in Debug Project Configuration reports:
2881 // * State information as per parent.
2882 //
2883 Int
2884 PAF_ASOT_decodeComplete(
2885 const PAF_ASOT_Params *pP,
2886 const PAF_ASOT_Patchs *pQ,
2887 PAF_ASOT_Config *pAsotCfg,
2888 ALG_Handle decAlg[],
2889 Int frame,
2890 Int block
2891 )
2892 {
2893 PAF_AST_Config *pAstCfg;
2894 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2895 Int as; /* Audio Stream Number (1, 2, etc.) */
2896 Int z; /* decode/encode counter */
2897 Int errno; /* error number */
2900 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2901 as = pAstCfg->as;
2902 (void)as; // clear compiler warning in case not used with tracing disabled
2904 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2906 for (z=DECODE1; z < DECODEN; z++)
2907 {
2908 // Stop decoder output circular buffer reads
2909 errno = cbReadStop(pCbCtl, z);
2910 if (errno)
2911 {
2912 TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
2913 SW_BREAKPOINT; // FL: debug
2914 return errno;
2915 }
2916 // FL: debug
2917 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeComplete:cbReadStop");
2918 }
2920 pP->fxns->streamChainFunction(pP, pQ, pAsotCfg, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
2922 for (z=ENCODE1; z < ENCODEN; z++)
2923 {
2924 Int zO = pP->outputsFromEncodes[z];
2925 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2926 {
2927 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2928 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2929 #ifdef PAF_ASP_FINAL
2930 ENC_Handle enc = (ENC_Handle)encAlg;
2931 #endif /* PAF_ASP_FINAL */
2932 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode", as+z);
2933 #ifdef PAF_ASP_FINAL
2934 if (enc->fxns->final)
2935 enc->fxns->final(enc, NULL, &pAstCfg->xEnc[z].encodeControl,
2936 &pAstCfg->xEnc[z].encodeStatus);
2937 #endif /* PAF_ASP_FINAL */
2938 if (encAlg->fxns->algDeactivate)
2939 {
2940 encAlg->fxns->algDeactivate(encAlg);
2941 }
2942 }
2943 else
2944 {
2945 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
2946 }
2947 }
2949 // wait for remaining data to be output
2950 pP->fxns->stopOutput(pP, pQ, pAsotCfg);
2952 return 0;
2953 } //PAF_ASOT_decodeComplete
2955 // -----------------------------------------------------------------------------
2956 // ASOT Decoding Function Helper - SIO Driver Start
2957 //
2958 // Name: PAF_ASOT_startOutput
2959 // Purpose: Decoding Function for initiating output.
2960 // From: AST Parameter Function -> decodeInfo1
2961 // Uses: See code.
2962 // States: x
2963 // Return: Error number in standard or SIO form (0 on success).
2964 // Trace: Message Log "trace" in Debug Project Configuration reports:
2965 // * State information as per parent.
2966 // * SIO control errors.
2967 //
2968 #define DEC_OUTNUMBUF_MAP(X) \
2969 pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
2971 Int
2972 PAF_ASOT_startOutput(
2973 const PAF_ASOT_Params *pP,
2974 const PAF_ASOT_Patchs *pQ,
2975 PAF_ASOT_Config *pAsotCfg
2976 )
2977 {
2978 PAF_AST_Config *pAstCfg;
2979 Int as; /* Audio Stream Number (1, 2, etc.) */
2980 Int z; /* output counter */
2981 Int errno,nbufs, errme; /* error number */
2982 Int zE, zS, zX;
2983 Int zMD;
2984 PAF_SIO_IALG_Obj *pObj;
2985 PAF_SIO_IALG_Config *pAlgConfig;
2988 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2989 as = pAstCfg->as;
2990 zMD = pAstCfg->masterDec;
2992 for (z=OUTPUT1; z < OUTPUTN; z++)
2993 {
2994 if (pAstCfg->xOut[z].hTxSio)
2995 {
2996 // determine associated encoder and stream
2997 zE = z;
2998 zS = z;
2999 for (zX = ENCODE1; zX < ENCODEN; zX++)
3000 {
3001 if (pP->outputsFromEncodes[zX] == z)
3002 {
3003 zE = zX;
3004 zS = pP->streamsFromEncodes[zE];
3005 break;
3006 }
3007 }
3009 // Need to Revisit: Starting Clocks here seems logical & also manages the McASP without spurious underruns .
3011 #if 1
3012 // if device selected and valid then enable stat tracking if
3013 // required and start clocking
3014 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
3015 {
3016 TRACE_VERBOSE0("PAF_ASOT_startOutput: start SIO clocks");
3017 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
3018 if (errno)
3019 {
3020 TRACE_VERBOSE2("PAF_ASOT_startOutput: errme 0x%x, errno 0x%x", errme, errno);
3021 SIO_idle(pAstCfg->xOut[z].hTxSio);
3022 if (!errno)
3023 {
3024 errno = ASPERR_DEVOUT + errme;
3025 }
3026 }
3027 }
3028 #endif
3029 // Set sample count so that DOB knows how much data to send
3030 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
3031 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
3033 if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
3034 {
3035 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
3036 pAlgConfig = &pObj->config;
3037 memset(pAstCfg->xOut[z].outBufConfig.base.pVoid, 0xAA,
3038 pAlgConfig->pMemRec[0].size);
3039 }
3041 // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
3042 // decoder. How should we handle the sourceProgram for multiple decoders?
3043 // Override as needed
3044 nbufs = DEC_OUTNUMBUF_MAP(pAstCfg->xDec[zMD].decodeStatus.sourceProgram);
3045 if (pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram] > 0)
3046 {
3047 nbufs = pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram];
3048 }
3049 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
3051 if (errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
3052 &pAstCfg->xOut[z].outBufConfig, sizeof(pAstCfg->xOut[z].outBufConfig), 0))
3053 {
3054 SIO_idle(pAstCfg->xOut[z].hTxSio);
3055 TRACE_TERSE2("PAF_ASOT_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
3056 return errno;
3057 }
3059 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
3060 (errno = SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
3061 {
3062 errno = (errno & 0xff) | ASPERR_MUTE;
3063 /* convert to sensical errno */
3064 TRACE_TERSE2("as1-f2: PAF_ASOT_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
3065 return (errno);
3066 }
3067 else
3068 {
3069 pAstCfg->xOut[z].outBufStatus.audio
3070 = (pAstCfg->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
3071 }
3073 TRACE_VERBOSE1("PAF_ASOT_startOutput: AS%d: output started", as+zS);
3074 }
3075 }
3077 return 0;
3078 } //PAF_ASOT_startOutput
3080 // -----------------------------------------------------------------------------
3081 // ASOT Decoding Function Helper - SIO Driver Stop
3082 //
3083 // Name: PAF_ASOT_stopOutput
3084 // Purpose: Decoding Function for terminating output.
3085 // From: AST Parameter Function -> decodeProcessing
3086 // AST Parameter Function -> decodeComplete
3087 // Uses: See code.
3088 // States: x
3089 // Return: Error number in standard or SIO form (0 on success).
3090 // Trace: Message Log "trace" in Debug Project Configuration reports:
3091 // * SIO control errors.
3092 //
3093 Int
3094 PAF_ASOT_stopOutput(
3095 const PAF_ASOT_Params *pP,
3096 const PAF_ASOT_Patchs *pQ,
3097 PAF_ASOT_Config *pAsotCfg
3098 )
3099 {
3100 PAF_AST_Config *pAstCfg;
3101 Int as; /* Audio Stream Number (1, 2, etc.) */
3102 Int z; /* output counter */
3103 Int errno = 0, getVal;
3104 Int zS, zX;
3105 PAF_SIO_IALG_Obj *pObj;
3106 PAF_SIO_IALG_Config *pAlgConfig;
3108 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3109 as = pAstCfg->as;
3110 (void)as; // clear compiler warning in case not used with tracing disabled
3112 for (z=OUTPUT1; z < OUTPUTN; z++)
3113 {
3114 if (pAstCfg->xOut[z].hTxSio)
3115 {
3116 // determine associated encoder and stream
3117 zS = z;
3118 (void)zS;
3119 for (zX = ENCODE1; zX < ENCODEN; zX++)
3120 {
3121 if (pP->outputsFromEncodes[zX] == z)
3122 {
3123 zS = pP->streamsFromEncodes[zX];
3124 break;
3125 }
3126 }
3128 // Mute output before audio data termination in the usual case,
3129 // where such termination is due to decode error or user command.
3130 // Identification of this as the usual case is provided by the
3131 // "decode processing" state machine.
3132 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
3133 ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND) &&
3134 (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
3135 {
3136 if (!errno)
3137 {
3138 errno = (getVal & 0xff) | ASPERR_MUTE;
3139 /* convert to sensical errno */
3140 }
3141 TRACE_VERBOSE1("PAF_ASOT_stopOutput: AS%d: SIO control failed (mute)", as+zS);
3142 }
3144 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- begin PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
3146 // Terminate audio data output, truncating (ignore) or flushing
3147 // (play out) final samples as per (1) control register set by
3148 // the user and (2) the type of audio data termination:
3150 #if 0
3151 // This form is not used because driver support for truncating
3152 // data is not supported for internal clocks, although it is
3153 // for external clocks.
3154 getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
3155 pC->xOut[z].outBufStatus.flush
3156 & (pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
3157 ? 1 : 0);
3158 /* UNTESTED */
3159 #else
3160 // This form should be used when driver support for truncating
3161 // data is supported for both internal and external clocks.
3162 getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
3163 pAstCfg->xOut[z].outBufStatus.flush ? 1 :
3164 (pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
3165 ? 1 : 0);
3166 /* TESTED */
3167 #endif
3169 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- after PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
3171 if (!errno)
3172 {
3173 errno = getVal;
3174 }
3176 // Mute output after audio data termination in a special case,
3177 // where such termination is due to processing of a final frame
3178 // or user command. Identification of this as a special case is
3179 // provided by the "decode processing" state machine.
3180 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
3181 ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH) &&
3182 (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
3183 {
3184 if (!errno)
3185 {
3186 errno = (getVal & 0xff) | ASPERR_MUTE;
3187 /* convert to sensical errno */
3188 }
3189 TRACE_VERBOSE1("as1-f2: PAF_ASOT_stopOutput: AS%d: SIO control failed (mute)", as+zS);
3190 }
3192 pAstCfg->xOut[z].outBufStatus.audio &= ~0x0f;
3194 // zero output buffers
3195 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
3196 pAlgConfig = &pObj->config;
3197 memset (pAstCfg->xOut[z].outBufConfig.base.pVoid, 0, pAlgConfig->pMemRec[0].size);
3198 } //pAstCfg->xOut[z].hTxSio
3199 }//OUTPUT
3201 return errno;
3202 } //PAF_ASOT_stopOutput
3205 // -----------------------------------------------------------------------------
3206 // ASOT Decoding Function Helper - SIO Driver Change
3207 //
3208 // Name: PAF_ASOT_setCheckRateX
3209 // Purpose: Decoding Function for reinitiating output.
3210 // From: AST Parameter Function -> decodeInfo1
3211 // AST Parameter Function -> decodeInfo2
3212 // Uses: See code.
3213 // States: x
3214 // Return: Error number in standard form (0 on success).
3215 // Trace: None.
3216 //
3218 /* 0: set, 1: check, unused for now. --Kurt */
3219 Int
3220 PAF_ASOT_setCheckRateX(
3221 const PAF_ASOT_Params *pP,
3222 const PAF_ASOT_Patchs *pQ,
3223 PAF_ASOT_Config *pAsotCfg,
3224 Int check
3225 )
3226 {
3227 PAF_AST_Config *pAstCfg;
3228 float rateX;
3229 PAF_SampleRateHz rateO /* std */, rateI /* inv */;
3230 Int z; /* output counter */
3231 Int zx; /* output re-counter */
3232 Int getVal;
3233 int inputRate, inputCount, outputRate, outputCount;
3234 Int zMD;
3235 Int zMI;
3236 Int zMS;
3237 Int zE, zX;
3239 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3240 zMD = pAstCfg->masterDec;
3241 zMS = pAstCfg->masterStr;
3242 zMI = pP->zone.master;
3244 inputRate = pAstCfg->xInp[zMI].inpBufStatus.sampleRateStatus;
3245 inputCount = pAstCfg->xDec[zMD].decodeStatus.frameLength;
3246 rateI = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz
3247 (pAstCfg->xStr[zMS].pAudioFrame, inputRate, PAF_SAMPLERATEHZ_INV);
3249 for (z=OUTPUT1; z < OUTPUTN; z++)
3250 {
3251 if (pAstCfg->xOut[z].hTxSio && (pAstCfg->xOut[z].outBufStatus.clock & 0x01))
3252 {
3253 // determine associated encoder
3254 zE = z;
3255 for (zX = ENCODE1; zX < ENCODEN; zX++)
3256 {
3257 if (pP->outputsFromEncodes[zX] == z)
3258 {
3259 zE = zX;
3260 break;
3261 }
3262 }
3264 outputRate = pAstCfg->xEnc[zE].encodeStatus.sampleRate;
3265 outputCount = pAstCfg->xEnc[zE].encodeStatus.frameLength;
3266 rateO = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz
3267 (pAstCfg->xStr[zMS].pAudioFrame, outputRate, PAF_SAMPLERATEHZ_STD);
3268 if ((rateI > 0) && (rateO > 0))
3269 {
3270 rateX = rateO /* std */ * rateI /* inv */;
3271 }
3272 else if (inputCount != 0)
3273 {
3274 rateX = (float )outputCount / inputCount;
3275 }
3276 else
3277 {
3278 return ASPERR_INFO_RATERATIO;
3279 }
3281 getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_RATEX, (Arg)&rateX);
3282 if (getVal == DOBERR_RATECHANGE)
3283 {
3284 for (zx=OUTPUT1; zx < OUTPUTN; zx++)
3285 {
3286 if (pAstCfg->xOut[zx].hTxSio)
3287 {
3288 SIO_idle (pAstCfg->xOut[zx].hTxSio);
3289 }
3290 }
3292 // this forces an exit from the calling state machine which will
3293 // eventually call startOutput which calls setCheckRateX for all outputs
3294 // and so it is ok, in the presence of a rate change on any output, to
3295 // exit this loop /function early.
3296 return ASPERR_INFO_RATECHANGE;
3297 }
3298 else if (getVal != SYS_OK)
3299 {
3300 return ((getVal & 0xff) | ASPERR_RATE_CHECK);
3301 }
3302 }
3303 }
3305 return 0;
3306 } //PAF_ASOT_setCheckRateX
3308 // -----------------------------------------------------------------------------
3309 // ASOT Decoding Function Helper - Chain Processing
3310 //
3311 // Name: PAF_ASOT_streamChainFunction
3312 // Purpose: Common Function for processing algorithm chains.
3313 // From: AST Parameter Function -> decodeInfo1
3314 // AST Parameter Function -> decodeStream
3315 // AST Parameter Function -> decodeComplete
3316 // Uses: See code.
3317 // States: x
3318 // Return: Error number in standard form (0 on success).
3319 // Trace: Message Log "trace" in Debug Project Configuration reports:
3320 // * State information as per parent.
3321 //
3322 Int
3323 PAF_ASOT_streamChainFunction(
3324 const PAF_ASOT_Params *pP,
3325 const PAF_ASOT_Patchs *pQ,
3326 PAF_ASOT_Config *pAsotCfg,
3327 Int iChainFrameFxns,
3328 Int abortOnError,
3329 Int logArg
3330 )
3331 {
3332 PAF_AST_Config *pAstCfg;
3333 Int as; /* Audio Stream Number (1, 2, etc.) */
3334 Int z; /* stream counter */
3335 Int errno; /* error number */
3336 Int dFlag, eFlag, gear;
3337 Int zX;
3338 Int zS;
3340 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3341 as = pAstCfg->as;
3342 (void)as; // clear compiler warning in case not used with tracing disabled
3344 for (zS = STREAM1; zS < STREAMN; zS++)
3345 {
3346 z = pP->streamOrder[zS]; // Select stream order from streamOrder parameter - MID 788
3348 // apply stream
3349 // unless the stream is associated with a decoder and it is not running
3350 // or
3351 // unless the stream is associated with an encoder and it is not running
3352 // Also gear control only works for streams with an associated decoder
3353 // if no such association exists then gear 0 (All) is used
3354 dFlag = 1;
3355 gear = 0;
3356 for (zX = DECODE1; zX < DECODEN; zX++) {
3357 if (pP->streamsFromDecodes[zX] == z) {
3358 dFlag = pAstCfg->xDec[zX].decodeStatus.mode;
3359 gear = pAstCfg->xDec[zX].decodeStatus.aspGearStatus;
3360 break;
3361 }
3362 }
3363 eFlag = 1;
3364 for (zX = ENCODE1; zX < ENCODEN; zX++) {
3365 if (pP->streamsFromEncodes[zX] == z) {
3366 eFlag = pAstCfg->xEnc[zX].encodeStatus.mode;
3367 break;
3368 }
3369 }
3371 if (dFlag && eFlag) {
3372 PAF_ASP_Chain *chain = pAstCfg->xStr[z].aspChain[gear];
3373 PAF_AudioFrame *frame = pAstCfg->xStr[z].pAudioFrame;
3374 Int (*func) (PAF_ASP_Chain *, PAF_AudioFrame *) =
3375 chain->fxns->chainFrameFunction[iChainFrameFxns];
3377 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
3378 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (reset)"
3379 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
3380 ? "PAF_ASOT_streamChainFunction: AS%d: processing block %d -- audio stream (apply)"
3381 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
3382 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (final)"
3383 : "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (?????)",
3384 as+z, logArg);
3385 errno = (*func) (chain, frame);
3386 TRACE_VERBOSE2("PAF_ASOT_streamChainFunction: AS%d: errno 0x%x.",
3387 as+z, errno);
3389 if (errno && abortOnError)
3390 return errno;
3391 }
3392 else {
3393 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
3394 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (reset) <ignored>"
3395 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
3396 ? "PAF_ASOT_streamChainFunction: AS%d: processing block %d -- audio stream (apply) <ignored>"
3397 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
3398 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (final) <ignored>"
3399 : "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (?????) <ignored>",
3400 as+z, logArg);
3401 }
3403 /*
3404 {
3405 void dp_tracePAF_Data(float *lBuf, float *rBuf, int count);
3406 PAF_AudioFrameData *afd;
3407 float ** afPtr;
3409 afd = &(pC->xStr->pAudioFrame->data);
3410 afPtr = (float**)afd->sample;
3411 dp_tracePAF_Data(afPtr[4], afPtr[5], 256);
3413 }
3414 */
3416 }
3418 return 0;
3419 } //PAF_ASOT_streamChainFunction
3421 /* Check if at least one output selected */
3422 static Int checkOutSel(
3423 const PAF_ASOT_Params *pP,
3424 PAF_ASOT_Config *pAsotCfg,
3425 Int *pOutSel
3426 )
3427 {
3428 PAF_AST_Config *pAstCfg;
3429 Int outSel;
3430 Int z;
3432 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3434 outSel = 0;
3435 for (z=OUTPUT1; z < OUTPUTN; z++)
3436 {
3437 if (pAstCfg->xOut[z].hTxSio)
3438 {
3439 outSel = 1;
3440 break;
3441 }
3442 }
3444 *pOutSel = outSel;
3446 return ASOP_SOK;
3447 }
3449 /* Check if at least one output sio changed */
3450 static Int checkOutSio(
3451 const PAF_ASOT_Params *pP,
3452 PAF_ASOT_Config *pAsotCfg,
3453 Int *pOutSioUpdate
3454 )
3455 {
3456 PAF_AST_Config *pAstCfg;
3457 Int outSioUpdate;
3458 Int z;
3460 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3462 outSioUpdate = 0;
3463 for (z=OUTPUT1; z < OUTPUTN; z++)
3464 {
3465 if (pAstCfg->xOut[z].outBufStatus.sioSelect >= 0)
3466 {
3467 outSioUpdate = 1;
3468 break;
3469 }
3470 }
3472 *pOutSioUpdate = outSioUpdate;
3474 return ASOP_SOK;
3475 }
3477 // Reset audio frames
3478 static Void resetAfs(
3479 const PAF_ASOT_Params *pP,
3480 PAF_AST_Stream *xStr
3481 )
3482 {
3483 // Reset audio frame pointers to original values
3484 // (may be needed if error occurred).
3485 resetAfPointers(pP, xStr);
3486 // Reset audio frame meta data elements
3487 resetAfMetadata(pP, xStr);
3488 }
3490 // Reset audio frame pointers to original values
3491 static Void resetAfPointers(
3492 const PAF_ASOT_Params *pP,
3493 PAF_AST_Stream *xStr
3494 )
3495 {
3496 Int z;
3497 Int ch;
3499 // Reset audio frame pointers to original values
3500 for (z = STREAM1; z < STREAMN; z++)
3501 {
3502 for (ch = PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
3503 {
3504 if (xStr[z].audioFrameChannelPointers[ch])
3505 {
3506 xStr[z].audioFrameChannelPointers[ch] =
3507 xStr[z].origAudioFrameChannelPointers[ch];
3508 }
3509 }
3510 }
3511 }
3513 // Reset audio frame meta data elements
3514 static Void resetAfMetadata(
3515 const PAF_ASOT_Params *pP,
3516 PAF_AST_Stream *xStr
3517 )
3518 {
3519 Int z;
3520 Int i;
3522 for (z = STREAM1; z < STREAMN; z++)
3523 {
3524 xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
3525 xStr[z].pAudioFrame->numPrivateMetadata = 0;
3526 xStr[z].pAudioFrame->bsMetadata_offset = 0;
3527 xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
3529 for (i = 0; i < pP->pMetadataBufStatus->NumBuf; i++)
3530 {
3531 xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
3532 xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
3533 }
3534 }
3535 }
3537 // Initialize Output Processing state function
3538 //static Int PAF_ASOT_initOutProc(
3539 Int PAF_ASOT_initOutProc(
3540 const PAF_ASOT_Params *pP,
3541 PAF_AST_Stream *xStr
3542 )
3543 {
3544 // Reset audio frames
3545 resetAfs(pP, xStr);
3547 return ASOP_SOK;
3548 }
3550 // Purpose: Init-Sync Dec Reset state function.
3551 // Performes Dec Reset Init-Sync.
3552 //static Int PAF_ASOT_initSyncDecReset(
3553 // used by new OutProc.c, will be changed back to static once refactoring is done
3554 Int PAF_ASOT_initSyncDecReset(
3555 const PAF_ASOT_Params *pP,
3556 const PAF_ASOT_Patchs *pQ,
3557 PAF_ASOT_Config *pAsotCfg,
3558 PAF_AudioFrame *pDecResetAf
3559 )
3560 {
3561 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3562 Int zMD, zMS; // Dec and Stream Master indices
3563 PAF_AudioFrame *pStrAf; // stream audio frame
3564 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
3565 Int8 decFlag; // dec stage flag
3566 Int errno; // error number
3569 pAstCfg = pAsotCfg->pAstCfg;
3570 zMD = pAstCfg->masterDec;
3571 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
3573 // check for Dec Reset
3574 // store dec reset AF
3575 errno = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
3576 ASP_OUTIS_DEC_STAGE_RESET_IDX, &decFlag, pDecResetAf);
3577 if (errno < 0)
3578 {
3579 return errno;
3580 }
3582 if (decFlag == 0)
3583 {
3584 return ASOP_INITSYNC_NOTREADY;
3585 }
3586 else
3587 {
3588 zMS = pAstCfg->masterStr;
3589 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
3591 // Update Stream Audio Frame.
3592 // Copy Dec Reset AF to Stream AF.
3593 outIsCpyAf(pDecResetAf, pStrAf);
3595 // Enc activate
3596 // Enc reset
3597 errno = PAF_ASOT_outputReset(pP, pQ, pAsotCfg);
3598 if (errno < 0)
3599 {
3600 return errno;
3601 }
3603 return ASOP_SOK;
3604 }
3605 }
3607 // Purpose: ASOT Function for Output reset
3608 static Int PAF_ASOT_outputReset(
3609 const PAF_ASOT_Params *pP,
3610 const PAF_ASOT_Patchs *pQ,
3611 PAF_ASOT_Config *pAsotCfg
3612 )
3613 {
3614 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3615 Int as; // Audio Stream Number (1, 2, etc.) */
3616 Int z; // encode counter
3617 Int errno; // error number
3618 Int zO, zS;
3621 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3622 as = pAstCfg->as;
3624 for (z=ENCODE1; z < ENCODEN; z++)
3625 {
3626 zO = pP->outputsFromEncodes[z];
3627 zS = pP->streamsFromEncodes[z];
3628 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
3629 {
3630 Int select = pAstCfg->xEnc[z].encodeStatus.select;
3631 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
3632 ENC_Handle enc = (ENC_Handle )encAlg;
3634 TRACE_VERBOSE1("AS%d: PAF_ASOT_outputReset: initializing encode", as+zS);
3636 if (encAlg->fxns->algActivate)
3637 {
3638 encAlg->fxns->algActivate(encAlg);
3639 }
3641 if (enc->fxns->reset)
3642 {
3643 errno = enc->fxns->reset(enc, NULL,
3644 &pAstCfg->xEnc[z].encodeControl,
3645 &pAstCfg->xEnc[z].encodeStatus);
3646 if (errno)
3647 {
3648 return ASOP_ENCRESET_ERR;
3649 }
3650 }
3651 }
3652 }
3654 return ASOP_SOK;
3655 }
3657 // FL: debug, allow modification of output frame length via JTAG
3658 Int16 gOutFrameLen=PAF_ASOT_FRAMELENGTH; // output frame length (PCM samples)
3660 // Purpose: Init-Sync Dec Info1 state function.
3661 // Performs Dec Info1 Init-Sync.
3662 Int PAF_ASOT_initSyncDecInfo1(
3663 const PAF_ASOT_Params *pP,
3664 const PAF_ASOT_Patchs *pQ,
3665 PAF_ASOT_Config *pAsotCfg,
3666 PAF_AudioFrame *pDecInfo1Af
3667 )
3668 {
3669 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3670 Int zMD, zMS; // Dec and Stream Master indices
3671 PAF_AudioFrame *pStrAf; // stream audio frame
3672 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
3673 Int8 decFlag; // dec stage flag
3674 Int errno; // error number
3677 pAstCfg = pAsotCfg->pAstCfg;
3678 zMD = pAstCfg->masterDec;
3679 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
3681 // Check for Dec Reset,
3682 // Store dec reset AF
3683 errno = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
3684 ASP_OUTIS_DEC_STAGE_INFO1_IDX, &decFlag, pDecInfo1Af);
3685 if (errno < 0)
3686 {
3687 return errno;
3688 }
3690 if (decFlag == 0)
3691 {
3692 return ASOP_INITSYNC_NOTREADY;
3693 }
3694 else
3695 {
3696 zMS = pAstCfg->masterStr;
3697 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
3699 // Set ASOT output frame length.
3700 // THD sets this to 256 (hard-coded in Dec Info)
3701 // DDP sets this to 0 (audio frame pass through, 0 from ASDT AF frame length)
3702 // PCM sets this to 256 (decodeControl.frameLength)
3703 pDecInfo1Af->sampleCount = gOutFrameLen; // !!!! GJ: Revisit !!!!
3705 // Update Stream Audio Frame.
3706 // Copy Dec Reset AF to Stream AF.
3707 outIsCpyAf(pDecInfo1Af, pStrAf);
3709 // outputInfo1():
3710 // - ASP chain reset,
3711 // - Enc Info
3712 PAF_ASOT_outputInfo1(pP, pQ, pAsotCfg);
3713 if (errno)
3714 {
3715 return ASOP_DECINFO1_ERR;
3716 }
3718 return ASOP_SOK;
3719 }
3720 }
3722 // Purpose: ASOT function for ASP chain reset and ENC info
3723 static Int PAF_ASOT_outputInfo1(
3724 const PAF_ASOT_Params *pP,
3725 const PAF_ASOT_Patchs *pQ,
3726 PAF_ASOT_Config *pAsotCfg
3727 )
3728 {
3729 PAF_AST_Config *pAstCfg;
3730 Int z; /* decode/encode counter */
3731 Int errno; /* error number */
3734 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
3736 // FL: frame parameter hard-coded to 0
3737 // run the chain of ASP's on the stream.
3738 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
3739 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
3740 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, 0);
3741 if (errno)
3742 {
3743 TRACE_TERSE1("PAF_ASOT_outputInfo1: streamChainFunction returns errno 0x%x ", errno);
3744 return errno;
3745 }
3747 TRACE_VERBOSE0("PAF_ASOT_outputInfo1: calling enc->info.");
3748 for (z=ENCODE1; z < ENCODEN; z++)
3749 {
3750 Int zO = pP->outputsFromEncodes[z];
3751 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
3752 {
3753 Int select = pAstCfg->xEnc[z].encodeStatus.select;
3754 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
3755 ENC_Handle enc = (ENC_Handle )encAlg;
3757 if (enc->fxns->info)
3758 {
3759 errno = enc->fxns->info(enc, NULL,
3760 &pAstCfg->xEnc[z].encodeControl,
3761 &pAstCfg->xEnc[z].encodeStatus);
3762 if (errno)
3763 {
3764 TRACE_TERSE1("PAF_ASOT_outputInfo1: info returns errno 0x%x ", errno);
3765 return errno;
3766 }
3767 }
3768 }
3769 }
3771 return 0;
3772 }
3774 // Purpose: Init-Sync Dec Decode1 state function.
3775 // Performs Dec Decode1 Init-Sync.
3776 //static Int PAF_ASOT_initSyncDecDecode1(
3777 Int PAF_ASOT_initSyncDecDecode1(
3778 const PAF_ASOT_Params *pP,
3779 const PAF_ASOT_Patchs *pQ,
3780 PAF_ASOT_Config *pAsotCfg
3781 )
3782 {
3783 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3784 Int zMD; // Dec Master index
3785 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
3786 Int8 decFlag; // dec stage flag
3787 Int errno; // error number
3790 pAstCfg = pAsotCfg->pAstCfg;
3791 zMD = pAstCfg->masterDec;
3792 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
3794 // Check for Dec Reset,
3795 // Store dec reset AF
3796 errno = outIsReadDecStageFlag(pOutIsCtl, zMD,
3797 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, &decFlag);
3798 if (errno < 0)
3799 {
3800 return errno;
3801 }
3803 if (decFlag == 0)
3804 {
3805 return ASOP_INITSYNC_NOTREADY;
3806 }
3807 else
3808 {
3809 return ASOP_SOK;
3810 }
3811 }
3813 // Purpose: Init-Sync Re-Sync state function.
3814 // Peforms Init-Sync using stored Dec Reset/Info1 AFs.
3815 Int PAF_ASOT_initSyncResync(
3816 const PAF_ASOT_Params *pP,
3817 const PAF_ASOT_Patchs *pQ,
3818 PAF_ASOT_Config *pAsotCfg,
3819 PAF_AudioFrame *pDecResetAf,
3820 PAF_AudioFrame *pDecInfo1Af
3821 )
3822 {
3823 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
3824 Int zMS; // Stream Master index
3825 PAF_AudioFrame *pStrAf; // stream audio frame
3826 Int errno; // error number
3829 pAstCfg = pAsotCfg->pAstCfg;
3830 zMS = pAstCfg->masterStr;
3831 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
3833 // Reset audio frames
3834 resetAfs(pP, pAstCfg->xStr);
3836 //
3837 // Dec Reset re-sync using stored Dec Reset AF
3838 //
3840 // Update Stream Audio Frame.
3841 // Copy Dec Reset AF to Stream AF.
3842 outIsCpyAf(pDecResetAf, pStrAf);
3844 // Enc activate,
3845 // Enc reset
3846 errno = PAF_ASOT_outputReset(pP, pQ, pAsotCfg);
3847 if (errno)
3848 {
3849 return errno;
3850 }
3852 //
3853 // Dec Info1 re-sync using stored Dec Info1 AF
3854 //
3856 // Update Stream Audio Frame.
3857 // Copy Dec Info1 AF to Stream AF.
3858 outIsCpyAf(pDecInfo1Af, pStrAf);
3860 // decodeInfo1():
3861 // - ASP chain reset,
3862 // - Enc Info
3863 errno = PAF_ASOT_outputInfo1(pP, pQ, pAsotCfg);
3864 if (errno)
3865 {
3866 return errno;
3867 }
3869 return ASOP_SOK;
3870 }
3872 // Purpose: Decoding Function for determining whether processing of the
3873 // current stream is complete.
3874 Int
3875 PAF_ASOT_decodeFinalTest(
3876 const struct PAF_ASOT_Params *pP,
3877 const struct PAF_ASOT_Patchs *pQ,
3878 struct PAF_ASOT_Config *pAsotCfg,
3879 Int frame,
3880 Int block
3881 )
3882 {
3883 PAF_AST_DecOpCircBufCtl *pCbCtl; // decoder output circular buffer control
3884 Int8 drainedFlag; // CB drained indicator flag
3885 Int zMD; // master Dec index
3886 Int errno; // error number
3889 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
3890 zMD = pAsotCfg->pAstCfg->masterDec; // get master Dec index
3892 // Check circular buffer drain state
3893 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107); // debug
3894 errno = cbCheckDrainState(pCbCtl, zMD, &drainedFlag);
3895 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107); // debug
3896 if (errno < 0)
3897 {
3898 return errno;
3899 }
3901 if (drainedFlag == 1)
3902 {
3903 return ASOP_DP_CB_DRAINED;
3904 }
3906 return ASOP_DP_SOK;
3907 }