d9503c0af43e5c959e1ed31a2bcae4db04db61ff
2 /*
3 Copyright (c) 2018, 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 <xdc/runtime/Log.h>
41 #include <ti/sysbios/BIOS.h>
43 #include "aspOutInitSync_master.h"
44 #include "aspDecOpCircBuf_master.h"
45 #include "audioStreamProc_common.h"
46 #include "audioStreamOutProc.h"
47 #include "audioStreamOutInit.h"
48 #include "audioStreamOutDec.h"
49 #include "audioStreamOutIo.h"
50 #include "common.h"
52 //#include "pfp/pfp.h"
53 //#include "pfp_app.h" /* contains all PFP ID's */
54 //Int32 gNumPfpAsot1=0; // debug
56 // debug
57 #include "evmc66x_gpio_dbg.h"
59 //#include "ioConfig.h"
61 // -----------------------------------------------------------------------------
62 // Debugging Trace Control, local to this file.
63 //
64 #include "logp.h"
66 // Allow a developer to selectively enable tracing.
67 #define CURRENT_TRACE_MASK 0x07
69 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
70 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
71 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
73 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
74 #undef TRACE_TERSE0
75 #undef TRACE_TERSE1
76 #undef TRACE_TERSE2
77 #undef TRACE_TERSE3
78 #undef TRACE_TERSE4
79 #define TRACE_TERSE0(a)
80 #define TRACE_TERSE1(a,b)
81 #define TRACE_TERSE2(a,b,c)
82 #define TRACE_TERSE3(a,b,c,d)
83 #define TRACE_TERSE4(a,b,c,d,e)
84 #endif
86 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
87 #undef TRACE_GEN0
88 #undef TRACE_GEN1
89 #undef TRACE_GEN2
90 #undef TRACE_GEN3
91 #undef TRACE_GEN4
92 #define TRACE_GEN0(a)
93 #define TRACE_GEN1(a,b)
94 #define TRACE_GEN2(a,b,c)
95 #define TRACE_GEN3(a,b,c,d)
96 #define TRACE_GEN4(a,b,c,d,e)
97 #endif
99 #if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
100 #undef TRACE_VERBOSE0
101 #undef TRACE_VERBOSE1
102 #undef TRACE_VERBOSE2
103 #undef TRACE_VERBOSE3
104 #undef TRACE_VERBOSE4
105 #define TRACE_VERBOSE0(a)
106 #define TRACE_VERBOSE1(a,b)
107 #define TRACE_VERBOSE2(a,b,c)
108 #define TRACE_VERBOSE3(a,b,c,d)
109 #define TRACE_VERBOSE4(a,b,c,d,e)
110 #endif
112 // -----------------------------------------------------------------------------
113 //
114 // Audio Stream Output Task definitions
115 //
117 #define __TASK_NAME__ "TaskAsop"
119 // status codes
120 // ASOT FSM
121 #define ASOP_SOK_INITSYNC_NOTREADY ( 1 ) // ok, init-sync not ready
122 #define ASOP_SOK ( 0 ) // ok
123 #define ASOP_ERR_FORWARD_ERR ( -1 ) // error, forward (ASIT) error
124 #define ASOP_ERR_RESETOUTPROC_NOOUTDEVSEL ( -2 ) // error, reset dec out proc, no output device selected
125 #define ASOP_ERR_PROCDECOUT_OUTDEVSELUPD ( -3 ) // error, proc dec out, output device select updated
126 #define ASOP_ERR_PROCDECOUT_IOPHYXFERCOMPLETE ( -4 ) // error, proc dec out, io phy transfer complete
127 #define ASOP_ERR_PROCDECOUT_CHKOUTDEVSELUPD ( -5 ) // error, proc dec out, check output device select update
129 // -----------------------------------------------------------------------------
131 // ASOT FSM states
132 enum
133 {
134 ASOT_STATE_SEL_OUT_DEV,
135 ASOT_STATE_RESET_OUT_PROC,
136 ASOT_STATE_INITSYNC_DEC_INFO1,
137 ASOT_STATE_INITSYNC_DEC_DECODE1,
138 ASOT_STATE_PROC_DEC_OUT,
139 ASOT_STATE_RESEL_OUT_DEV,
140 ASOT_STATE_INITSYNC_RESYNC
141 };
143 // Check if Output device selected
144 static Int checkOutDevSel(
145 PAF_AST_IoOut *pOut,
146 Bool *pOutDevSel);
148 // Check if any Output device selected
149 static Int checkAnyOutDevSel(
150 const PAF_ASOT_Params *pP,
151 PAF_AST_IoOut *pOut,
152 Bool *pOutDevSel);
154 // ASOT SM function
155 // Purpose: Audio Stream Output Task Function for selecting the devices used
156 // for output.
157 static Int PAF_ASOT_selectDevices(
158 const PAF_ASOT_Params *pP,
159 const PAF_ASOT_Patchs *pQ,
160 PAF_ASOT_Config *pAsotCfg,
161 Bool *pOutDevSel
162 );
164 // Reset audio frame pointers to original values
165 static Void resetAfPointers(
166 const PAF_ASOT_Params *pP,
167 PAF_AST_Stream *xStr
168 );
170 // Reset audio frame meta data elements
171 static Void resetAfMetadata(
172 const PAF_ASOT_Params *pP,
173 PAF_AST_Stream *xStr
174 );
176 // Reset audio frames
177 static Void resetAfs(
178 const PAF_ASOT_Params *pP,
179 PAF_AST_Stream *xStr
180 );
182 // used by new OutProc.c, will be changed back to static once refactoring is done
183 // Purpose: Init-Sync Dec Reset state function.
184 // Performs Dec Reset Init-Sync.
185 static Int PAF_ASOT_initSyncDecReset(
186 const PAF_ASOT_Params *pP,
187 const PAF_ASOT_Patchs *pQ,
188 PAF_ASOT_Config *pAsotCfg,
189 PAF_AudioFrame *pDecResetAf,
190 Int frame
191 );
193 // ASOT SM function
194 // Reset Decoder Output processing
195 static Int PAF_ASOT_resetDecOutProc(
196 const PAF_ASOT_Params *pP,
197 const PAF_ASOT_Patchs *pQ,
198 PAF_ASOT_Config *pAsotCfg,
199 PAF_AudioFrame *pDecResetAf,
200 Bool outDevSel,
201 Int frame
202 );
204 // ASOT SM function
205 // Purpose: Init-Sync Dec Info1 state function.
206 // Performs Dec Info1 Init-Sync.
207 static Int PAF_ASOT_initSyncDecInfo1(
208 const PAF_ASOT_Params *pP,
209 const PAF_ASOT_Patchs *pQ,
210 PAF_ASOT_Config *pAsotCfg,
211 PAF_AudioFrame *pDecInfo1Af,
212 Int frame
213 );
215 // ASOT SM function
216 // Purpose: Init-Sync Dec Decode1 state function.
217 // Performs Dec Decode1 Init-Sync.
218 static Int PAF_ASOT_initSyncDecDecode1(
219 const PAF_ASOT_Params *pP,
220 const PAF_ASOT_Patchs *pQ,
221 PAF_ASOT_Config *pAsotCfg,
222 PAF_AudioFrame *pDecDecode1Af,
223 Int frame
224 );
226 // ASOT SM function
227 // Process Decoder output audio data
228 static Int PAF_ASOT_procDecOut(
229 const PAF_ASOT_Params *pP,
230 const PAF_ASOT_Patchs *pQ,
231 PAF_ASOT_Config *pAsotCfg,
232 Bool *pFirstTime,
233 Int frame
234 );
236 // ASOT SM function
237 // Purpose: Init-Sync Re-Sync state function.
238 // Performs Init-Sync using stored Init-Sync AFs.
239 static Int PAF_ASOT_initSyncResync(
240 const PAF_ASOT_Params *pP,
241 const PAF_ASOT_Patchs *pQ,
242 PAF_ASOT_Config *pAsotCfg,
243 PAF_AudioFrame *pDecResetAf,
244 PAF_AudioFrame *pDecInfo1Af,
245 PAF_AudioFrame *pDecDecode1Af,
246 Int frame
247 );
249 static Int asopDecOutProcEncodeWrap(
250 const PAF_ASOT_Params *pP,
251 const PAF_ASOT_Patchs *pQ,
252 PAF_ASOT_Config *pAsotCfg,
253 Int frame,
254 Int zO
255 );
257 // ASOT SM function
258 // Purpose: Re-select devices used for Output.
259 // Performs Init-Sync using stored Init-Sync AFs.
260 static Int PAF_ASOT_reselectDevices(
261 const PAF_ASOT_Params *pP,
262 const PAF_ASOT_Patchs *pQ,
263 PAF_ASOT_Config *pAsotCfg,
264 PAF_AudioFrame *pDecResetAf,
265 PAF_AudioFrame *pDecInfo1Af,
266 PAF_AudioFrame *pDecDecode1Af,
267 Int frame,
268 Bool *pOutDevSel
269 );
272 // FL: debug, allow modification of Output frame length via JTAG.
273 Int16 gOutFrameLen=PAF_ASOT_FRAMELENGTH; // output frame length (PCM samples)
275 // ASOT configuration
276 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
277 PAF_ASOT_Config gPAF_ASOT_config = {
278 NULL, // taskHandle
279 0, // asotState
280 NULL, // acp
281 0,0,0, // cbDrainedFlag (size DECODE_MAXN)
282 &gPAF_ASPM_config, // pAspmCfg
283 &gPAF_AST_config // pAstCfg
284 };
286 // ASOT event handle - to put in structure
287 Event_Handle gAsotEvtHandle;
289 extern Int d10Initialized;
291 // For writeDECCommandRestart
292 extern volatile UInt32 gCommandOutputTask_SYNC;
293 extern volatile UInt32 gCommandOutputTask_ACK;
295 LINNO_DEFN(TaskAsop); // Line number macros
296 ERRNO_DEFN(TaskAsop); // Error number macros
298 #define ASOP_DEBUG
299 #ifdef ASOP_DEBUG
300 Int asopLoopCount;
301 #endif
303 // Debug event-in-state counters
304 UInt32 gSelOutDevState_EvtWakeTimer_cnt = 0; // Select Output state, Wake Timer event count
305 UInt32 gSelOutDevState_EvtTxMcaspEdma_invCnt = 0; // Select Output state, invalid Tx McASP EDMA event count
306 UInt32 gSelOutDevState_Evt_invCnt = 0; // Select Output state, invalid other event count
307 UInt32 gResetOutProcState_EvtWakeTimer_cnt = 0; // Select Output state, Wake Timer event count
308 UInt32 gResetOutProcState_EvtTxMcaspEdma_invCnt = 0; // Reset Output Processing state, invalid Tx McASP EDMA event count
309 UInt32 gResetOutProcState_Evt_invCnt = 0; // Reset Output Processing state, invalid other event count
310 UInt32 gInitSyncDecInfo1State_EvtWakeTimer_cnt = 0; // Init-Sync Dec Info1 state, Wake Timer event count
311 UInt32 gInitSyncDecInfo1State_EvtTxMcaspEdma_invCnt = 0; // Init-Sync Dec Info1 state, invalid Tx McASP EDMA event count
312 UInt32 gInitSyncDecInfo1State_Evt_invCnt = 0; // Init-Sync Dec Info1 state, invalid other event count
313 UInt32 gInitSyncDecDecode1State_EvtWakeTimer_cnt = 0; // Init-Sync Dec Decode1 state, Wake Timer event count
314 UInt32 gInitSyncDecDecode1State_EvtTxMcaspEdma_invCnt = 0; // Init-Sync Dec Decode1 state, invalid Tx McASP EDMA event count
315 UInt32 gInitSyncDecDecode1State_Evt_invCnt = 0; // Init-Sync Dec Decode1 state, invalid other event count
316 UInt32 gProcDecOutState_EvtWakeTimer_cnt = 0; // Process Output state, Wake Timer event count
317 UInt32 gProcDecOutState_EvtTxMcaspEdma_cnt = 0; // Process Output state, Tx McASP EDMA event count
318 UInt32 gProcDecOutState_Evt_invCnt = 0; // Process Output state, invalid other event count
319 UInt32 gReselOutDevState_EvtWakeTimer_cnt = 0; // Process Output state, Wake Timer event count
320 UInt32 gReselOutDevState_EvtTxMcaspEdma_invCnt = 0; // Re-select Output state, invalid other event count
321 UInt32 gReselOutDevState_Evt_invCnt = 0; // Re-select Output state, invalid other event count
322 // Debug state counters
323 UInt32 gAsotInitSyncResyncState_Cnt = 0; // Init-Sync Re-sync (Local error) state execution count
324 UInt32 gAsotInvState_Cnt = 0; // invalid state count
327 /*
328 * ======== taskAsopFxn ========
329 * Audio Stream Output Processing task function
330 */
331 Void taskAsopFxn(
332 const PAF_ASOT_Params *pP,
333 const PAF_ASOT_Patchs *pQ
334 )
335 {
336 PAF_ASOT_Config *pAsotCfg; // ASOT configuration pointer
337 PAF_AST_Config *pAstCfg; // Common (shared) configuration pointer
338 Int as; // Audio Stream Number (1, 2, etc.)
339 Int z; // input/encode/stream/decode/output counter
340 Bool outDevSel; // whether output device selected
341 PAF_AudioFrame decResetAf;
342 PAF_AudioFrame decInfo1Af;
343 PAF_AudioFrame decDecode1Af;
344 UInt events; // latched event flags
345 Bool procEvents; // process events flags
346 Bool procOutFirstTime; // first time process output flag
347 Int asopFrameCount; // frame counter
348 Int status; // status code
349 #ifndef ASOP_DEBUG
350 Int asopLoopCount; // debug, ASOT loop counter
351 #endif
353 Log_info0("Enter taskAsopFxn()");
355 taskAsopFxnInit(pP, pQ); // initialization of output task
357 //
358 // Audio Stream Output Task Configuration (*pAsotCfg):
359 //
360 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
361 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
362 as = pAstCfg->as; // obtain Audio Stream Number (1, 2, etc.)
364 //
365 // Main processing loop
366 //
367 for (z=STREAM1; z < STREAMN; z++)
368 {
369 TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
370 }
372 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // init state
373 procEvents = TRUE; // init proc events flag
374 procOutFirstTime = TRUE; // init first time process output flag
375 asopFrameCount = 0; // init frame counter TBD
376 asopLoopCount = 0; // loop counter
377 for (;;)
378 {
379 // Pend for next event
380 // Evt_Id_AsotWakeTimer : Wakeup timer (poll for Output device selection)
381 // Evt_Id_AsotTxMcaspEdma : Tx McASP EDMA completion
382 if (procEvents == TRUE)
383 {
384 events = Event_pend(gAsotEvtHandle, Event_Id_NONE, (Evt_Id_AsotWakeTimer + Evt_Id_AsotTxMcaspEdma), BIOS_WAIT_FOREVER);
385 }
387 asopLoopCount++;
388 //TRACE_GEN1("TaskAsop (begin Main loop %d)", asopLoopCount);
390 switch (pAsotCfg->state)
391 {
392 //
393 // Select Output Device state
394 //
395 case ASOT_STATE_SEL_OUT_DEV:
396 if (events & Evt_Id_AsotWakeTimer)
397 {
398 gSelOutDevState_EvtWakeTimer_cnt++;
399 events &= ~Evt_Id_AsotWakeTimer; // clear event
401 // Select Output devices
402 // outDevSel==TRUE if Output device selection successful
403 status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
404 if (status < 0)
405 {
406 // FL, New IO:
407 //Tx status==error message to ASIT; // ASOT initiated message to ASIT, "backward" error
409 // No explicit handling of Select Output Device error, so stay in state and try again
410 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
411 break;
412 }
413 else if (outDevSel == TRUE)
414 {
415 // Select successful
416 pAsotCfg->state = ASOT_STATE_RESET_OUT_PROC;
417 }
418 else
419 {
420 // No output device selected (outDevSel == FALSE).
421 // Remain in current state.
422 ;
423 }
424 }
426 // Check for unexpected Tx McASP EDMA event
427 if (events & Evt_Id_AsotTxMcaspEdma)
428 {
429 gSelOutDevState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
430 TRACE_TERSE2("TaskAsop: invalid Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
431 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
432 }
434 // Check for any other unexpected events
435 if (events != 0)
436 {
437 gSelOutDevState_Evt_invCnt++; // log invalid event count in state
438 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
439 events &= ~events; // clear events
440 }
442 break;
444 // FL, New IO: currently using timer event
445 //
446 // Reset Output Processing state
447 //
448 case ASOT_STATE_RESET_OUT_PROC:
449 if (events & Evt_Id_AsotWakeTimer)
450 {
451 gResetOutProcState_EvtWakeTimer_cnt++;
452 events &= ~Evt_Id_AsotWakeTimer; // clear event
454 //
455 // Allow Output device re-selection prior to Output processing.
456 // Output device selection has already been performed in state==ASOT_STATE_SEL_OUT_DEV.
457 // Output device can be re-selected via alpha commands before streaming is initiated.
458 // Here check whether this has occurred.
459 //
461 // Select Output devices
462 // outDevSel==TRUE if Output device selection successful
463 status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
464 if (status < 0)
465 {
466 // FL, New IO:
467 //Tx status==error message to ASIT; // ASOT initiated message to ASIT, "backward" error
469 // Starting over with Output device selection in case of error
470 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
471 break;
472 }
473 else if (outDevSel == FALSE)
474 {
475 // No device selected
476 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
477 break;
478 }
480 // Reset Output processing
481 status = PAF_ASOT_resetDecOutProc(pP, pQ, pAsotCfg, &decResetAf, outDevSel, asopFrameCount);
482 if (status < 0)
483 {
484 // FL, New IO:
485 //Tx status==error message to ASDT; // feedback message ASOT -> ASDT
487 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
488 break;
489 }
490 else if (status == ASOP_SOK_INITSYNC_NOTREADY)
491 {
492 // FL, New IO: this is only necessary for Wake Timer, POLLING Init-Sync
493 // FL, New IO: can be removed once Rx ASDT messages are implemented for Init-Sync
495 // Dec Reset Init-Sync not ready.
496 // Remain in current state.
497 ;
498 }
499 else
500 {
501 // FL, New IO:
502 //Tx status==ok message to ASDT; // feedback message ASOT -> ASDT
504 pAsotCfg->state = ASOT_STATE_INITSYNC_DEC_INFO1;
505 }
506 }
508 // Check for unexpected Tx McASP EDMA event
509 if (events & Evt_Id_AsotTxMcaspEdma)
510 {
511 gResetOutProcState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
512 TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
513 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
514 }
516 // Check for any other unexpected events
517 if (events != 0)
518 {
519 gResetOutProcState_Evt_invCnt++; // log invalid event count in state
520 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
521 events &= ~events; // clear events
522 }
524 break;
526 // FL, New IO: currently using timer event
527 //
528 // Init-Sync Info1 state
529 //
530 case ASOT_STATE_INITSYNC_DEC_INFO1:
531 if (events & Evt_Id_AsotWakeTimer)
532 {
533 gInitSyncDecInfo1State_EvtWakeTimer_cnt++;
534 events &= ~Evt_Id_AsotWakeTimer; // clear event
536 status = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af, asopFrameCount);
537 if (status < 0)
538 {
539 // FL, New IO:
540 //Tx status==error message to ASDT; // feedback message ASOT -> ASDT
542 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
543 break;
544 }
545 else if (status == ASOP_SOK_INITSYNC_NOTREADY)
546 {
547 // FL, New IO: this is only necessary for Wake Timer, POLLING Init-Sync
548 // FL, New IO: can be removed once Rx ASDT messages are implemented for Init-Sync
550 // Dec Reset Init-Sync not ready.
551 // Remain in current state.
552 ;
553 }
554 else
555 {
556 // FL, New IO:
557 //Tx status==ok message to ASDT; // feedback message ASOT -> ASDT
559 pAsotCfg->state = ASOT_STATE_INITSYNC_DEC_DECODE1;
560 }
561 }
563 // Check for unexpected Tx McASP EDMA event
564 if (events & Evt_Id_AsotTxMcaspEdma)
565 {
566 gInitSyncDecInfo1State_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
567 TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
568 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
569 }
571 // Check for any other unexpected events
572 if (events != 0)
573 {
574 gInitSyncDecInfo1State_Evt_invCnt++; // log invalid event count in state
575 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
576 events &= ~events; // clear events
577 }
579 break;
581 // FL, New IO: currently using timer event
582 //
583 // Init-Sync Decode1 state
584 //
585 case ASOT_STATE_INITSYNC_DEC_DECODE1:
586 if (events & Evt_Id_AsotWakeTimer)
587 {
588 gInitSyncDecDecode1State_EvtWakeTimer_cnt++;
589 events &= ~Evt_Id_AsotWakeTimer; // clear event
591 status = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg, &decDecode1Af, asopFrameCount);
592 if (status < 0)
593 {
594 // FL, New IO:
595 //Tx status==error message to ASDT; // feedback message ASOT -> ASDT
597 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
598 break;
599 }
600 else if (status == ASOP_SOK_INITSYNC_NOTREADY)
601 {
602 // FL, New IO: this is only necessary for Wake Timer, POLLING Init-Sync
603 // FL, New IO: can be removed once Rx ASDT messages are implemented for Init-Sync
605 // Dec Reset Init-Sync not ready.
606 // Remain in current state.
607 ;
608 }
609 else
610 {
611 // FL, New IO:
612 //Tx status==ok message to ASDT; // feedback message ASOT -> ASDT
614 pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
615 procOutFirstTime = TRUE;
616 }
617 }
619 // Check for unexpected Tx McASP EDMA event
620 if (events & Evt_Id_AsotTxMcaspEdma)
621 {
622 gInitSyncDecDecode1State_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
623 TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
624 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
625 }
627 // Check for any other unexpected events
628 if (events != 0)
629 {
630 gInitSyncDecDecode1State_Evt_invCnt++; // log invalid event count in state
631 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
632 events &= ~events; // clear events
633 }
635 break;
637 //
638 // Process Decoder Output state
639 //
640 case ASOT_STATE_PROC_DEC_OUT:
641 if (events & Evt_Id_AsotTxMcaspEdma)
642 {
643 gProcDecOutState_EvtTxMcaspEdma_cnt++;
644 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
646 #if 1 // (***) FL: shows timing of Output (Tx McASP EDMA)
647 // (***) debug // B8
648 {
649 static Uint8 toggleState = 0;
650 if (toggleState == 0)
651 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
652 else
653 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
654 toggleState = ~(toggleState);
655 }
656 #endif
658 // Process Output
659 status = PAF_ASOT_procDecOut(pP, pQ, pAsotCfg, &procOutFirstTime, asopFrameCount);
660 if (status < 0)
661 {
662 if (status == ASOP_DOP_ERR_FINALTEST_CBDRAINED)
663 {
664 // normal completion, CB drained @ EOS
665 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
666 break;
668 }
669 else if (status == ASOP_ERR_PROCDECOUT_OUTDEVSELUPD)
670 {
671 // Output re-select
672 pAsotCfg->state = ASOT_STATE_RESEL_OUT_DEV;
673 break;
674 }
675 // FL, New IO: "backward" error handling.
676 // Currently all errors handled locally.
677 else
678 {
679 // Handle ASOT "local" errors
680 pAsotCfg->state = ASOT_STATE_INITSYNC_RESYNC;
681 procEvents = FALSE;
682 break;
683 }
684 }
685 }
687 // Check for Wakeup Timer event.
688 // Wakeup Timer events are allowed to occur, but no processing is
689 // performed in response to such an event.
690 if (events & Evt_Id_AsotWakeTimer)
691 {
692 events &= ~Evt_Id_AsotWakeTimer; // clear event
693 gProcDecOutState_EvtWakeTimer_cnt++; // log event count in state
694 }
696 // Check for any other unexpected events
697 if (events != 0)
698 {
699 gProcDecOutState_Evt_invCnt++; // log invalid event count in state
700 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
701 events &= ~events; // clear events
702 }
704 break;
706 //
707 // Re-Select Output Device state
708 //
709 case ASOT_STATE_RESEL_OUT_DEV:
710 if (events & Evt_Id_AsotWakeTimer)
711 {
712 gReselOutDevState_EvtWakeTimer_cnt++;
713 events &= ~Evt_Id_AsotWakeTimer; // clear event
715 status = PAF_ASOT_reselectDevices(pP, pQ, pAsotCfg, &decResetAf, &decInfo1Af, &decDecode1Af, asopFrameCount, &outDevSel);
716 if (status < 0)
717 {
718 // FL, New IO:
719 //Tx status==error message to ASIT; // ASOT initiated message to ASIT, "backward" error
721 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
722 break;
723 }
724 else if (outDevSel == TRUE)
725 {
726 // Re-select successful
727 pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
728 procOutFirstTime = TRUE;
729 }
730 else
731 {
732 // No output device selected (outDevSel == FALSE).
733 // Remain in current state.
734 ;
735 }
736 }
738 // Check for unexpected Tx McASP EDMA event
739 if (events & Evt_Id_AsotTxMcaspEdma)
740 {
741 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
742 gReselOutDevState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
743 }
745 // Check for any other unexpected events
746 if (events != 0)
747 {
748 gReselOutDevState_Evt_invCnt++; // log invalid event count in state
749 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
750 events &= ~events; // clear events
751 }
753 break;
755 //
756 // Init-Sync Re-sync (Process Output Local Error) state
757 //
758 case ASOT_STATE_INITSYNC_RESYNC: // not event driven state
759 gAsotInitSyncResyncState_Cnt++;
761 status = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf, &decInfo1Af, &decDecode1Af, asopFrameCount);
762 if (status < 0)
763 {
764 // FL, New IO:
765 //Tx status==error message to ASIT; // ASIT initiated message to ASOT, "backward" error
767 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
768 procEvents = TRUE;
769 break;
770 }
771 else
772 {
773 pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
774 procEvents = TRUE;
775 procOutFirstTime = TRUE;
776 }
778 break;
780 default:
781 gAsotInvState_Cnt++;
782 TRACE_TERSE1("TaskAsop: invalid state, state=%u", pAsotCfg->state);
784 break;
785 }
787 // FL, New IO: handle ASIT messages separately in each state
788 // FL, New IO: proper SM clean up can be skipped if forward error / DEC restart is handled in this way
790 //
791 // Check forward (ASIT) error, TBD
792 //
794 // Check writeDECCommandRestart, TBD
795 if (gCommandOutputTask_SYNC)
796 {
797 TRACE_TERSE0("TaskAsop: ack writeDECCommandRestart ... Wait for command de-assert");
798 gCommandOutputTask_ACK = 1;
799 while (gCommandOutputTask_SYNC)
800 {
801 Event_pend(gAsotEvtHandle, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
802 }
803 TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Re-start the process");
804 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // init state -- start over
805 status = ASOP_ERR_FORWARD_ERR; // set status -- force flushing of output device
806 }
808 // any error forces idling of output
809 if (status < 0)
810 {
811 for (z=OUTPUT1; z < OUTPUTN; z++)
812 {
813 //if (pAstCfg->xOut[z].hTxSio)
814 if (pAsotCfg->pIoOut[z].hIoPhy)
815 {
816 //SIO_idle(pAstCfg->xOut[z].hTxSio); JX TO DO: implement proper error handling
817 }
818 }
820 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", asopLoopCount);
821 //ERRNO_RPRT(TaskAsop, errno);
822 }
823 } // End of main processing loop for (;;)
824 } /* taskAsopFxn */
826 // ASOT wake timer (clock) function
827 Void clkAsotFxn(Void)
828 {
829 Event_post(gAsotEvtHandle, Evt_Id_AsotWakeTimer);
830 }
832 void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
833 {
834 /* post semaphore */
835 if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
836 //Semaphore_post(asopSemTx);
837 Event_post(gAsotEvtHandle, Evt_Id_AsotTxMcaspEdma);
838 } else {
839 ; // intermediate packet due to buffer wrapping around
840 }
841 }
843 // Reset audio frame pointers to original values
844 static Void resetAfPointers(
845 const PAF_ASOT_Params *pP,
846 PAF_AST_Stream *xStr
847 )
848 {
849 Int z;
850 Int ch;
852 // Reset audio frame pointers to original values
853 for (z = STREAM1; z < STREAMN; z++)
854 {
855 for (ch = PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
856 {
857 if (xStr[z].audioFrameChannelPointers[ch])
858 {
859 xStr[z].audioFrameChannelPointers[ch] =
860 xStr[z].origAudioFrameChannelPointers[ch];
861 }
862 }
863 }
864 }
866 // Check if Output device selected
867 static Int checkOutDevSel(
868 PAF_AST_IoOut *pOut,
869 Bool *pOutDevSel
870 )
871 {
872 *pOutDevSel = (Bool)(pOut->hMcaspChan != NULL);
874 return ASOP_SOK;
875 }
877 // Check if any Output device selected
878 static Int checkAnyOutDevSel(
879 const PAF_ASOT_Params *pP,
880 PAF_AST_IoOut *pOut,
881 Bool *pOutDevSel
882 )
883 {
884 Bool outDevSel;
885 Int z;
887 outDevSel = FALSE;
888 for (z=OUTPUT1; z < OUTPUTN; z++)
889 {
890 if (pOut[z].hMcaspChan)
891 {
892 outDevSel = TRUE;
893 break;
894 }
895 }
897 *pOutDevSel = outDevSel;
899 return ASOP_SOK;
900 }
902 // ASOT SM function
903 // -----------------------------------------------------------------------------
904 // ASOT Selection Function - Output Device Selection
905 //
906 // Name: PAF_ASOT_selectDevices
907 // Purpose: Audio Stream Output Task Function for selecting the devices used
908 // for output.
909 //
910 static Int PAF_ASOT_selectDevices(
911 const PAF_ASOT_Params *pP,
912 const PAF_ASOT_Patchs *pQ,
913 PAF_ASOT_Config *pAsotCfg,
914 Bool *pOutDevSel
915 )
916 {
917 PAF_AST_Config *pAstCfg; // Common (shared) configuration pointer
918 Int z;
919 Int zS, zO;
920 Int device;
921 Int status;
922 Bool ioPhyInit;
924 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
926 // Find first Output associated with Master Stream
927 zO = OUTPUT1;
928 for (z=ENCODE1; z < ENCODEN; z++)
929 {
930 zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
931 if (zS == pAstCfg->masterStr)
932 {
933 // This Encoder is associated with Master Stream.
934 // Note other Encoder can also be associated with Master Stream.
935 zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
936 }
937 }
939 ioPhyInit = asopIoPhyCheckInit(); // check if IO Phy is initialized
940 device = pAstCfg->xOut[zO].outBufStatus.sioSelect; // obtain SIO select for Output
941 if ((ioPhyInit == TRUE) && (device >= 0))
942 {
943 // check for valid index into device array
944 if (device >= pQ->devout->n) // DEVOUT_N
945 {
946 device = 0; // treat as device None
947 }
949 // Select Output Devices
950 // FL, New IO: API for single Output
951 status = asopSelectDevices(pQ->devout->x[device], &pAsotCfg->pIoOut[zO]);
952 if (status < 0)
953 {
954 pAstCfg->xOut[zO].outBufStatus.sioSelect = 0x80;
955 *pOutDevSel = FALSE;
956 return status;
957 }
959 // Reset IO Buff & IO Phy
960 // FL, New IO: API for single Output
961 status = asopIoCompsInit(&pAstCfg->xOut[zO], &pAsotCfg->pIoOut[zO]);
962 if (status < 0)
963 {
964 pAstCfg->xOut[zO].outBufStatus.sioSelect = 0x80;
965 *pOutDevSel = FALSE;
966 return status;
967 }
969 pAstCfg->xOut[zO].outBufStatus.sioSelect = device | 0x80;
970 }
972 // Check if Output device selected
973 // FL, New IO: API for single Output
974 status = checkOutDevSel(&pAsotCfg->pIoOut[zO], pOutDevSel);
975 if (status < 0)
976 {
977 *pOutDevSel = FALSE;
978 return status;
979 }
981 return ASOP_SOK;
982 }
984 // ASOT SM function
985 // Wake Timer + *POLLING* version.
986 // No explicit Rx ASDT message event from ASDT.
987 // ASOT wakes on Wake Timer event and polls for flag set.
988 // Reset Decoder Output processing
989 static Int PAF_ASOT_resetDecOutProc(
990 const PAF_ASOT_Params *pP,
991 const PAF_ASOT_Patchs *pQ,
992 PAF_ASOT_Config *pAsotCfg,
993 PAF_AudioFrame *pDecResetAf,
994 Bool outDevSel,
995 Int frame
996 )
997 {
998 Int status;
1000 if (outDevSel == FALSE)
1001 {
1002 //
1003 // Rx Dec Out-IS message before Output selected.
1004 // Decoder is producing output, but no Output selected.
1005 //
1006 return ASOP_ERR_RESETOUTPROC_NOOUTDEVSEL;
1007 }
1009 // Perform Dec Reset Init-Sync
1010 status = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, pDecResetAf, frame);
1012 return status;
1013 }
1016 // Reset audio frame meta data elements
1017 static Void resetAfMetadata(
1018 const PAF_ASOT_Params *pP,
1019 PAF_AST_Stream *xStr
1020 )
1021 {
1022 Int z;
1023 Int i;
1025 for (z = STREAM1; z < STREAMN; z++)
1026 {
1027 xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1028 xStr[z].pAudioFrame->numPrivateMetadata = 0;
1029 xStr[z].pAudioFrame->bsMetadata_offset = 0;
1030 xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1032 for (i = 0; i < pP->pMetadataBufStatus->NumBuf; i++)
1033 {
1034 xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1035 xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1036 }
1037 }
1038 }
1040 // Reset audio frames
1041 static Void resetAfs(
1042 const PAF_ASOT_Params *pP,
1043 PAF_AST_Stream *xStr
1044 )
1045 {
1046 // Reset audio frame pointers to original values
1047 // (may be needed if error occurred).
1048 resetAfPointers(pP, xStr);
1049 // Reset audio frame meta data elements
1050 resetAfMetadata(pP, xStr);
1051 }
1053 // Purpose: Performs Dec Reset Init-Sync.
1054 //static Int PAF_ASOT_initSyncDecReset(
1055 // used by new OutProc.c, will be changed back to static once refactoring is done
1056 static Int PAF_ASOT_initSyncDecReset(
1057 const PAF_ASOT_Params *pP,
1058 const PAF_ASOT_Patchs *pQ,
1059 PAF_ASOT_Config *pAsotCfg,
1060 PAF_AudioFrame *pDecResetAf,
1061 Int frame
1062 )
1063 {
1064 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1065 Int zMD; // Dec Master index
1066 Int zMS; // Stream Master index
1067 PAF_AudioFrame *pStrAf; // stream audio frame
1068 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
1069 Int8 decFlag; // dec stage flag
1070 Int status; // status code
1072 pAstCfg = pAsotCfg->pAstCfg;
1073 zMD = pAstCfg->masterDec;
1074 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
1076 // check for Dec Reset
1077 // store dec reset AF
1078 status = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
1079 ASP_OUTIS_DEC_STAGE_RESET_IDX, &decFlag, pDecResetAf);
1080 if (status < 0)
1081 {
1082 return status;
1083 }
1085 if (decFlag == 0)
1086 {
1087 return ASOP_SOK_INITSYNC_NOTREADY;
1088 }
1089 else
1090 {
1091 zMS = pAstCfg->masterStr;
1092 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1094 // Reset audio frames
1095 // FL, New IO: API for multiple streams.
1096 resetAfs(pP, pAstCfg->xStr);
1098 // Update Stream Audio Frame.
1099 // Copy Dec Reset AF to Stream AF.
1100 // FL, New IO: Only Master zone (single) stream handled.
1101 outIsCpyAf(pDecResetAf, pStrAf);
1103 // Enc activate
1104 // Enc reset
1105 status = asopDecOutProcReset(pP, pQ, pAsotCfg, frame);
1106 if (status < 0)
1107 {
1108 return status;
1109 }
1111 return ASOP_SOK;
1112 }
1113 }
1115 // ASOT SM function
1116 // Purpose: Init-Sync Dec Info1 state function.
1117 // Wake Timer + *POLLING* version.
1118 // No explicit Rx ASDT message event from ASDT.
1119 // ASOT wakes on Wake Timer event and polls for flag set.
1120 static Int PAF_ASOT_initSyncDecInfo1(
1121 const PAF_ASOT_Params *pP,
1122 const PAF_ASOT_Patchs *pQ,
1123 PAF_ASOT_Config *pAsotCfg,
1124 PAF_AudioFrame *pDecInfo1Af,
1125 Int frame
1126 )
1127 {
1128 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1129 Int zMD; // Dec Master index
1130 //Int zMS; // Stream Master index
1131 //PAF_AudioFrame *pStrAf; // stream audio frame
1132 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
1133 Int8 decFlag; // dec stage flag
1134 Int status; // status code
1135 //PAF_AST_DecOpCircBufCtl *pCbCtl; // Decoder output circular buffer control
1137 pAstCfg = pAsotCfg->pAstCfg;
1138 zMD = pAstCfg->masterDec;
1139 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
1141 // Check for Dec Info1,
1142 // Store Dec Info1 AF
1143 status = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
1144 ASP_OUTIS_DEC_STAGE_INFO1_IDX, &decFlag, pDecInfo1Af);
1145 if (status < 0)
1146 {
1147 return status;
1148 }
1150 if (decFlag == 0)
1151 {
1152 return ASOP_SOK_INITSYNC_NOTREADY;
1153 }
1154 else
1155 {
1156 // FL: moved to PAF_ASOT_initSyncDecDecode1()
1157 // Decode parameters necessary for CB stream FL auto config are known at that time.
1158 // CB stream FL used to configure Stream AF sample count.
1159 // ASP chain reset can adjust Stream AF sample count, depending on whether SRC enabled & decimation factor.
1160 #if 0
1161 // Get pointer to circular buffer control
1162 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl;
1164 // Initialize decoder output circular buffer for stream reads
1165 cbInitStreamRead(pCbCtl, zMD);
1167 // Get pointer to stream audio frame
1168 zMS = pAstCfg->masterStr;
1169 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1171 // Set ASOT output frame length
1172 //pDecInfo1Af->sampleCount = gOutFrameLen; // !!!! GJ: Revisit !!!!
1173 cbReadStrFrameLen(pCbCtl, zMD, &pDecInfo1Af->sampleCount);
1175 // Update Stream Audio Frame.
1176 // Copy Dec Info1 AF to Stream AF.
1177 outIsCpyAf(pDecInfo1Af, pStrAf);
1179 // outputInfo1():
1180 // - ASP chain reset,
1181 // - Enc Info,
1182 // - Start Output
1183 status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1185 if (status < 0)
1186 {
1187 return status;
1188 }
1189 #endif
1191 return ASOP_SOK;
1192 }
1193 }
1195 // ASOT SM function
1196 // Purpose: Init-Sync Dec Decode1 state function.
1197 // Wake Timer + *POLLING* version.
1198 // No explicit Rx ASDT message event from ASDT.
1199 // ASOT wakes on Wake Timer event and polls for flag set.
1200 //static Int PAF_ASOT_initSyncDecDecode1(
1201 static Int PAF_ASOT_initSyncDecDecode1(
1202 const PAF_ASOT_Params *pP,
1203 const PAF_ASOT_Patchs *pQ,
1204 PAF_ASOT_Config *pAsotCfg,
1205 PAF_AudioFrame *pDecDecode1Af,
1206 Int frame
1207 )
1208 {
1209 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1210 Int zMD; // Dec Master index
1211 Int zMS; // Stream Master index
1212 PAF_AudioFrame *pStrAf; // stream audio frame
1213 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
1214 Int8 decFlag; // dec stage flag
1215 Int z;
1216 Int zS, zO;
1217 Int status; // status code
1218 PAF_AST_DecOpCircBufCtl *pCbCtl; // Decoder output circular buffer control
1220 pAstCfg = pAsotCfg->pAstCfg;
1221 zMD = pAstCfg->masterDec;
1222 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl; // get pointer to output init-sync control
1225 // Check for Dec Decode1,
1226 // Store Dec Decode1 AF
1227 status = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
1228 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, &decFlag, pDecDecode1Af);
1229 if (status < 0)
1230 {
1231 return status;
1232 }
1234 if (decFlag == 0)
1235 {
1236 return ASOP_SOK_INITSYNC_NOTREADY;
1237 }
1238 else
1239 {
1240 #if 1
1241 // Get pointer to circular buffer control
1242 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl;
1244 // Initialize decoder output circular buffer for stream reads
1245 cbInitStreamRead(pCbCtl, zMD);
1247 // Get pointer to stream audio frame
1248 zMS = pAstCfg->masterStr;
1249 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1251 // Set ASOT output frame length.
1252 // Frame length is initialized to CB stream (read) frame length.
1253 // CB stream frame length modified via SRC reset in ASP chain reset if SRC enabled.
1254 //pDecDecode1Af->sampleCount = 256; // 48/96/192 kHz pass through
1255 //pDecDecode1Af->sampleCount = 512; // 96 kHz, SRC DF=2
1256 //pDecDecode1Af->sampleCount = 1024; // 192 kHz, SRC DF=4
1257 //pDecDecode1Af->sampleCount = gOutFrameLen; // !!!! GJ: Revisit !!!!
1258 cbReadStrFrameLen(pCbCtl, zMD, &pDecDecode1Af->sampleCount);
1260 // Update Stream Audio Frame.
1261 // Copy Dec Reset AF to Stream AF.
1262 outIsCpyAf(pDecDecode1Af, pStrAf);
1264 // outputInfo1():
1265 // - ASP chain reset,
1266 // - Enc Info,
1267 // - Start Output
1268 status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1269 if (status < 0)
1270 {
1271 return status;
1272 }
1273 #endif
1275 // Find first Output associated with Master Stream
1276 zO = OUTPUT1;
1277 for (z=ENCODE1; z < ENCODEN; z++)
1278 {
1279 zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
1280 if (zS == pAstCfg->masterStr)
1281 {
1282 // This Encoder is associated with Master Stream.
1283 // Note other Encoder can also be associated with Master Stream.
1284 zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
1285 }
1286 }
1288 // FL, New IO: assumption here is Tx McASP clock dividers &
1289 // Output frame size are set correctly before IO prime,
1290 // i.e. IO prime is not using defaults
1292 // FL, New IO: API for single Output
1294 // I/O physical layer prime operation required by McASP LLD
1295 asopIoPhyPrime(&pAsotCfg->pIoOut[zO]);
1296 TRACE_VERBOSE0("PAF_ASOT_initSyncDecDecode1: ASOP McASP LLD primed.");
1298 return ASOP_SOK;
1299 }
1300 }
1302 // ASOT SM function
1303 // Process Decoder output audio data
1304 static Int PAF_ASOT_procDecOut(
1305 const PAF_ASOT_Params *pP,
1306 const PAF_ASOT_Patchs *pQ,
1307 PAF_ASOT_Config *pAsotCfg,
1308 Bool *pFirstTime,
1309 Int frame
1310 )
1311 {
1312 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1313 Bool outDevSioSelUpdate; // indicates whether Output SIO selection has changed
1314 Int zO, zS;
1315 Int z; // decode/encode counter
1316 Int errno; // error number
1317 Int status; // status code
1319 status = ASOP_SOK;
1320 pAstCfg = pAsotCfg->pAstCfg;
1322 if (*pFirstTime == TRUE)
1323 {
1324 // Initialize Decoder output processing
1325 errno = asopDecOutProcInit(pP, pQ, pAsotCfg, frame);
1326 if (errno < 0)
1327 {
1328 status = errno;
1329 }
1330 else
1331 {
1332 *pFirstTime = FALSE;
1333 }
1334 }
1336 if (status == ASOP_SOK)
1337 {
1338 // Find first Output associated with Master Stream
1339 zO = OUTPUT1;
1340 for (z=ENCODE1; z < ENCODEN; z++)
1341 {
1342 zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
1343 if (zS == pAstCfg->masterStr)
1344 {
1345 // This Encoder is associated with Master Stream.
1346 // Note other Encoder can also be associated with Master Stream.
1347 zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
1348 }
1349 }
1351 // Mark Output transfer complete
1352 errno = ioPhyXferComplete(pAsotCfg->pIoOut[zO].hIoPhy, FALSE);
1353 if (errno)
1354 {
1355 status = ASOP_ERR_PROCDECOUT_IOPHYXFERCOMPLETE;
1356 }
1357 }
1359 if (status == ASOP_SOK)
1360 {
1361 // Check if Output device SIO selection changed
1362 errno = checkOutDevSioSelUpdate(pP, pAsotCfg, zO, &outDevSioSelUpdate);
1363 if (errno)
1364 {
1365 status = ASOP_ERR_PROCDECOUT_CHKOUTDEVSELUPD;
1366 }
1367 else if (outDevSioSelUpdate == TRUE)
1368 {
1369 status = ASOP_ERR_PROCDECOUT_OUTDEVSELUPD;
1370 }
1371 }
1373 if (status == ASOP_SOK)
1374 {
1375 // Process encoder command
1376 errno = asopDecOutProcEncodeCommand(pP, pQ, pAsotCfg);
1377 if (errno < 0)
1378 {
1379 status = errno;
1380 }
1381 }
1383 if (status == ASOP_SOK)
1384 {
1385 // Read CB, execute ASP chain
1386 errno = asopDecOutProcStream(pP, pQ, pAsotCfg, frame);
1387 if (errno < 0)
1388 {
1389 status = errno;
1390 }
1391 }
1393 if (status == ASOP_SOK)
1394 {
1395 size_t totalOutputSize;
1397 // Calculate the total size that encoder will write to output buffer
1398 totalOutputSize = pAstCfg->xEnc[zO].encodeInStruct.pAudioFrame->sampleCount
1399 * pAstCfg->xOut[zO].outBufConfig.stride
1400 * pAstCfg->xOut[zO].outBufConfig.sizeofElement;
1402 // Get output buffer pointers for encoder to write. Pointers are stored in pAsotCfg->pIoOut[zO]
1403 asopGetOutBufPtrs(&pAsotCfg->pIoOut[zO], totalOutputSize);
1405 // Invoke the encoder
1406 errno = asopDecOutProcEncodeWrap(pP, pQ, pAsotCfg, frame, zO);
1407 if (errno < 0)
1408 {
1409 status = errno;
1410 }
1412 // Mark Output buffers write complete
1413 asopMarkOutBuffsWriteComplete(&pAstCfg->xOut[zO], &pAsotCfg->pIoOut[zO]);
1414 }
1416 if (status == ASOP_SOK)
1417 {
1418 // Execute Info2
1419 errno = asopDecOutProcInfo2(pP, pQ, pAsotCfg, frame);
1420 if (errno < 0)
1421 {
1422 status = errno;
1423 }
1424 }
1426 if (status == ASOP_SOK)
1427 {
1428 errno = asopDecOutProcFinalTest(pP, pQ, pAsotCfg, frame);
1429 if (errno < 0)
1430 {
1431 status = errno;
1432 }
1433 }
1435 if (status != ASOP_SOK)
1436 {
1437 // Complete Output Processing
1438 errno = asopDecOutProcComplete(pP, pQ, pAsotCfg, frame);
1439 if (errno < 0)
1440 {
1441 status = errno;
1442 }
1443 }
1445 return status;
1446 }
1448 static Int asopDecOutProcEncodeWrap(
1449 const PAF_ASOT_Params *pP,
1450 const PAF_ASOT_Patchs *pQ,
1451 PAF_ASOT_Config *pAsotCfg,
1452 Int frame,
1453 Int zO
1454 )
1455 {
1456 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1457 Int errno; // error number
1458 Int status; // status code
1459 PAF_OutBufConfig *pOutBufCfg;
1460 PAF_AudioFrame * pAf;
1462 status = ASOP_SOK;
1463 pAstCfg = pAsotCfg->pAstCfg;
1464 pOutBufCfg = &(pAstCfg->xOut[zO].outBufConfig);
1465 pAf = pAstCfg->xEnc[zO].encodeInStruct.pAudioFrame;
1467 if(pAsotCfg->pIoOut[zO].buff2 == NULL)
1468 {
1469 // Output buffer won't wrap around - to invoke the encoder once
1470 pOutBufCfg->lengthofFrame = pAf->sampleCount;
1471 pOutBufCfg->pntr.pLgInt = pAsotCfg->pIoOut[zO].buff1;
1473 // Execute encode
1474 errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
1475 if (errno < 0)
1476 {
1477 status = errno;
1478 }
1479 }
1480 else
1481 {
1482 // Output buffer will wrap around - to invoke the encoder twice
1483 XDAS_Int16 sampleCountSave;
1484 PAF_AudioData *afDataAddrSave[16];
1485 PAF_AudioData **afDataAddr;
1486 int i, ch;
1488 sampleCountSave = pAf->sampleCount; // save sample count for restoring later
1490 // Invoke the encoder to write data to the end of output buffer
1491 pOutBufCfg->lengthofFrame = pAsotCfg->pIoOut[zO].size1 / (pOutBufCfg->stride * pOutBufCfg->sizeofElement);
1492 pAf->sampleCount = pOutBufCfg->lengthofFrame;
1493 pOutBufCfg->pntr.pLgInt = pAsotCfg->pIoOut[zO].buff1;
1495 // Execute encode
1496 errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
1497 if (errno < 0)
1498 {
1499 status = errno;
1500 }
1502 // Adjust audio frame buffer addresses for second invoking of the encoder
1503 afDataAddr = pAf->data.sample;
1504 for(i=0; i<pOutBufCfg->stride; i++)
1505 {
1506 ch = pAstCfg->xEnc[zO].encodeStatus.channelMap.from[i];
1507 afDataAddrSave[i] = afDataAddr[ch]; // save audio frame buffer addresses
1508 afDataAddr[ch] = &afDataAddr[ch][pOutBufCfg->lengthofFrame];
1509 }
1511 // Invoke the encoder to write data to the beginning of output buffer (wrapping around)
1512 pOutBufCfg->lengthofFrame = pAsotCfg->pIoOut[zO].size2 / (pOutBufCfg->stride * pOutBufCfg->sizeofElement);
1513 pAf->sampleCount = pOutBufCfg->lengthofFrame;
1514 pOutBufCfg->pntr.pLgInt = pAsotCfg->pIoOut[zO].buff2;
1516 // Execute encode
1517 errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
1518 if (errno < 0)
1519 {
1520 status = errno;
1521 }
1523 // Restore sample count and audio frame buffer addresses
1524 pAf->sampleCount = sampleCountSave;
1525 for(i=0; i<pOutBufCfg->stride; i++)
1526 {
1527 ch = pAstCfg->xEnc[zO].encodeStatus.channelMap.from[i];
1528 afDataAddr[ch] = afDataAddrSave[i];
1529 }
1531 pAsotCfg->pIoOut[zO].ioBuffBuf2AllocCnt++; // debug
1532 }
1534 return status;
1535 }
1537 // ASOT SM function
1538 // Purpose: Init-Sync Re-Sync state function.
1539 // Performs Init-Sync using stored Init-Sync AFs.
1540 static Int PAF_ASOT_initSyncResync(
1541 const PAF_ASOT_Params *pP,
1542 const PAF_ASOT_Patchs *pQ,
1543 PAF_ASOT_Config *pAsotCfg,
1544 PAF_AudioFrame *pDecResetAf,
1545 PAF_AudioFrame *pDecInfo1Af,
1546 PAF_AudioFrame *pDecDecode1Af,
1547 Int frame
1548 )
1549 {
1550 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1551 Int zMD; // Dec Master index
1552 Int zMS; // Stream Master index
1553 PAF_AudioFrame *pStrAf; // stream audio frame
1554 Int status; // status code
1555 PAF_AST_DecOpCircBufCtl *pCbCtl; // Decoder output circular buffer control
1557 pAstCfg = pAsotCfg->pAstCfg;
1558 zMD = pAstCfg->masterDec;
1559 zMS = pAstCfg->masterStr;
1560 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1562 // Reset audio frames
1563 resetAfs(pP, pAstCfg->xStr);
1565 //
1566 // Dec Reset re-sync using stored Dec Reset AF
1567 //
1569 // Update Stream Audio Frame.
1570 // Copy Dec Reset AF to Stream AF.
1571 outIsCpyAf(pDecResetAf, pStrAf);
1573 // Enc activate,
1574 // Enc reset
1575 status = asopDecOutProcReset(pP, pQ, pAsotCfg, frame);
1576 if (status < 0)
1577 {
1578 return status;
1579 }
1581 //
1582 // Dec Info1 re-sync using stored Dec Info1 AF
1583 //
1585 #if 0
1586 // Update Stream Audio Frame.
1587 // Copy Dec Info1 AF to Stream AF.
1588 outIsCpyAf(pDecInfo1Af, pStrAf);
1590 // outputInfo1():
1591 // - ASP chain reset,
1592 // - Enc Info,
1593 // - Start Output
1594 status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1595 if (status < 0)
1596 {
1597 return status;
1598 }
1599 #endif
1601 //
1602 // Dec Decode1 re-sync using stored Dec Decode1 AF
1603 //
1605 // Get pointer to circular buffer control
1606 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl;
1608 // Initialize decoder output circular buffer for stream reads
1609 cbInitStreamRead(pCbCtl, zMD);
1611 // Set ASOT output frame length.
1612 // Frame length is initialized to CB stream (read) frame length.
1613 // CB stream frame length modified via SRC reset in ASP chain reset if SRC enabled.
1614 cbReadStrFrameLen(pCbCtl, zMD, &pDecDecode1Af->sampleCount);
1616 // Update Stream Audio Frame.
1617 // Copy Dec Info1 AF to Stream AF.
1618 outIsCpyAf(pDecInfo1Af, pStrAf);
1620 // outputInfo1():
1621 // - ASP chain reset,
1622 // - Enc Info,
1623 // - Start Output
1624 status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1625 if (status < 0)
1626 {
1627 return status;
1628 }
1630 return ASOP_SOK;
1631 }
1633 // ASOT SM function
1634 // Purpose: Re-select devices used for Output.
1635 // Performs Init-Sync using stored Init-Sync AFs.
1636 static Int PAF_ASOT_reselectDevices(
1637 const PAF_ASOT_Params *pP,
1638 const PAF_ASOT_Patchs *pQ,
1639 PAF_ASOT_Config *pAsotCfg,
1640 PAF_AudioFrame *pDecResetAf,
1641 PAF_AudioFrame *pDecInfo1Af,
1642 PAF_AudioFrame *pDecDecode1Af,
1643 Int frame,
1644 Bool *pOutDevSel
1645 )
1646 {
1647 Bool outDevSel;
1648 Int status;
1650 // Re-select Output devices
1651 status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
1652 if (status < 0)
1653 {
1654 *pOutDevSel = outDevSel;
1655 return status;
1656 }
1657 else if (outDevSel == FALSE)
1658 {
1659 *pOutDevSel = outDevSel;
1660 return status;
1661 }
1662 else
1663 {
1664 // Init-Sync Resync
1665 status = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, pDecResetAf, pDecInfo1Af, pDecDecode1Af, frame);
1666 if (status < 0)
1667 {
1668 outDevSel = FALSE;
1669 *pOutDevSel = outDevSel;
1670 return status;
1671 }
1672 }
1674 *pOutDevSel = outDevSel;
1675 return status;
1676 }