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 "audioStreamProc_common.h"
45 #include "audioStreamOutProc.h"
46 #include "audioStreamOutInit.h"
47 #include "audioStreamOutDec.h"
48 #include "audioStreamOutIo.h"
50 //#include "pfp/pfp.h"
51 //#include "pfp_app.h" /* contains all PFP ID's */
52 //Int32 gNumPfpAsot1=0; // debug
54 // debug
55 //#include "evmc66x_gpio_dbg.h"
56 //#include "dbgCapAf.h"
58 //#include "ioConfig.h"
60 // -----------------------------------------------------------------------------
61 // Debugging Trace Control, local to this file.
62 //
63 #include "logp.h"
65 // Allow a developer to selectively enable tracing.
66 #define CURRENT_TRACE_MASK 0x07
68 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
69 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
70 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
72 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
73 #undef TRACE_TERSE0
74 #undef TRACE_TERSE1
75 #undef TRACE_TERSE2
76 #undef TRACE_TERSE3
77 #undef TRACE_TERSE4
78 #define TRACE_TERSE0(a)
79 #define TRACE_TERSE1(a,b)
80 #define TRACE_TERSE2(a,b,c)
81 #define TRACE_TERSE3(a,b,c,d)
82 #define TRACE_TERSE4(a,b,c,d,e)
83 #endif
85 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
86 #undef TRACE_GEN0
87 #undef TRACE_GEN1
88 #undef TRACE_GEN2
89 #undef TRACE_GEN3
90 #undef TRACE_GEN4
91 #define TRACE_GEN0(a)
92 #define TRACE_GEN1(a,b)
93 #define TRACE_GEN2(a,b,c)
94 #define TRACE_GEN3(a,b,c,d)
95 #define TRACE_GEN4(a,b,c,d,e)
96 #endif
98 #if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
99 #undef TRACE_VERBOSE0
100 #undef TRACE_VERBOSE1
101 #undef TRACE_VERBOSE2
102 #undef TRACE_VERBOSE3
103 #undef TRACE_VERBOSE4
104 #define TRACE_VERBOSE0(a)
105 #define TRACE_VERBOSE1(a,b)
106 #define TRACE_VERBOSE2(a,b,c)
107 #define TRACE_VERBOSE3(a,b,c,d)
108 #define TRACE_VERBOSE4(a,b,c,d,e)
109 #endif
111 // -----------------------------------------------------------------------------
112 //
113 // Audio Stream Output Task definitions
114 //
116 #define __TASK_NAME__ "TaskAsop"
118 // status codes
119 // Output FSM
120 #define ASOP_SOK_INITSYNC_NOTREADY ( 1 ) // ok, init-sync not ready
121 #define ASOP_SOK ( 0 ) // ok
122 #define ASOP_ERR_FORWARD_ERR ( -1 ) // error, forward (ASIT) error
123 #define ASOP_ERR_RESETOUTPROC_NOOUTDEVSEL ( -2 ) // error, reset dec out proc, no output device selected
124 #define ASOP_ERR_PROCDECOUT_OUTDEVSELUPD ( -3 ) // error, proc dec out, output device select updated
125 #define ASOP_ERR_PROCDECOUT_IOPHYXFERCOMPLETE ( -4 ) // error, proc dec out, io phy transfer complete
126 #define ASOP_ERR_PROCDECOUT_CHKOUTDEVSELUPD ( -5 ) // error, proc dec out, check output device select update
128 // -----------------------------------------------------------------------------
130 // ASOT FSM states
131 enum
132 {
133 ASOT_STATE_SEL_OUT_DEV,
134 ASOT_STATE_RESET_OUT_PROC,
135 ASOT_STATE_INITSYNC_DEC_INFO1,
136 ASOT_STATE_INITSYNC_DEC_DECODE1,
137 ASOT_STATE_PROC_DEC_OUT,
138 ASOT_STATE_RESEL_OUT_DEV,
139 ASOT_STATE_INITSYNC_RESYNC
140 };
142 // Check if at least one output selected
143 static Int checkOutDevSel(
144 const PAF_ASOT_Params *pP,
145 PAF_ASOT_Config *pAsotCfg,
146 Bool *pOutSel);
148 // ASOT SM function
149 // Purpose: Audio Stream Output Task Function for selecting the devices used
150 // for output.
151 static Int PAF_ASOT_selectDevices(
152 const PAF_ASOT_Params *pP,
153 const PAF_ASOT_Patchs *pQ,
154 PAF_ASOT_Config *pAsotCfg,
155 Bool *pOutDevSel
156 );
158 // Reset audio frame pointers to original values
159 static Void resetAfPointers(
160 const PAF_ASOT_Params *pP,
161 PAF_AST_Stream *xStr
162 );
164 // Reset audio frame meta data elements
165 static Void resetAfMetadata(
166 const PAF_ASOT_Params *pP,
167 PAF_AST_Stream *xStr
168 );
170 // Reset audio frames
171 static Void resetAfs(
172 const PAF_ASOT_Params *pP,
173 PAF_AST_Stream *xStr
174 );
176 // used by new OutProc.c, will be changed back to static once refactoring is done
177 // Purpose: Init-Sync Dec Reset state function.
178 // Performs Dec Reset Init-Sync.
179 static Int PAF_ASOT_initSyncDecReset(
180 const PAF_ASOT_Params *pP,
181 const PAF_ASOT_Patchs *pQ,
182 PAF_ASOT_Config *pAsotCfg,
183 PAF_AudioFrame *pDecResetAf,
184 Int frame
185 );
187 // ASOT SM function
188 // Reset Decoder Output processing
189 static Int PAF_ASOT_resetDecOutProc(
190 const PAF_ASOT_Params *pP,
191 const PAF_ASOT_Patchs *pQ,
192 PAF_ASOT_Config *pAsotCfg,
193 PAF_AudioFrame *pDecResetAf,
194 Bool outDevSel,
195 Int frame
196 );
198 // ASOT SM function
199 // Purpose: Init-Sync Dec Info1 state function.
200 // Performs Dec Info1 Init-Sync.
201 static Int PAF_ASOT_initSyncDecInfo1(
202 const PAF_ASOT_Params *pP,
203 const PAF_ASOT_Patchs *pQ,
204 PAF_ASOT_Config *pAsotCfg,
205 PAF_AudioFrame *pDecInfo1Af,
206 Int frame
207 );
209 // ASOT SM function
210 // Purpose: Init-Sync Dec Decode1 state function.
211 // Performs Dec Decode1 Init-Sync.
212 static Int PAF_ASOT_initSyncDecDecode1(
213 const PAF_ASOT_Params *pP,
214 const PAF_ASOT_Patchs *pQ,
215 PAF_ASOT_Config *pAsotCfg,
216 Int frame
217 );
219 // ASOT SM function
220 // Process Decoder output audio data
221 static Int PAF_ASOT_procDecOut(
222 const PAF_ASOT_Params *pP,
223 const PAF_ASOT_Patchs *pQ,
224 PAF_ASOT_Config *pAsotCfg,
225 Bool *pFirstTime,
226 Int frame
227 );
229 // ASOT SM function
230 // Purpose: Init-Sync Re-Sync state function.
231 // Performs Init-Sync using stored Dec Reset/Info1 AFs.
232 static Int PAF_ASOT_initSyncResync(
233 const PAF_ASOT_Params *pP,
234 const PAF_ASOT_Patchs *pQ,
235 PAF_ASOT_Config *pAsotCfg,
236 PAF_AudioFrame *pDecResetAf,
237 PAF_AudioFrame *pDecInfo1Af,
238 Int frame
239 );
241 // ASOT SM function
242 // Purpose: Re-select devices used for Output.
243 // Performs Init-Sync using stored Dec Reset/Info1 AFs.
244 static Int PAF_ASOT_reselectDevices(
245 const PAF_ASOT_Params *pP,
246 const PAF_ASOT_Patchs *pQ,
247 PAF_ASOT_Config *pAsotCfg,
248 PAF_AudioFrame *pDecResetAf,
249 PAF_AudioFrame *pDecInfo1Af,
250 Int frame,
251 Bool *pOutDevSel
252 );
255 // FL: debug, allow modification of Output frame length via JTAG.
256 Int16 gOutFrameLen=PAF_ASOT_FRAMELENGTH; // output frame length (PCM samples)
258 // ASOT configuration
259 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
260 PAF_ASOT_Config gPAF_ASOT_config = {
261 NULL, // taskHandle
262 0, // asotState
263 NULL, // acp
264 0,0,0, // cbDrainedFlag (size DECODE_MAXN)
265 &gPAF_ASPM_config, // pAspmCfg
266 &gPAF_AST_config // pAstCfg
267 };
269 /* ASOT event handle - to put in structure */
270 Event_Handle asotEvt;
272 // For writeDECCommandRestart
273 extern volatile UInt32 gCommandOutputTask_SYNC;
274 extern volatile UInt32 gCommandOutputTask_ACK;
276 LINNO_DEFN(TaskAsop); // Line number macros
277 ERRNO_DEFN(TaskAsop); // Error number macros
279 #define ASOP_DEBUG
280 #ifdef ASOP_DEBUG
281 Int asopLoopCount;
282 #endif
284 // Debug event-in-state counters
285 UInt32 gSelOutDevState_EvtWakeTimer_cnt = 0; // Select Output state, Wake Timer event count
286 UInt32 gSelOutDevState_EvtTxMcaspEdma_invCnt = 0; // Select Output state, invalid Tx McASP EDMA event count
287 UInt32 gSelOutDevState_Evt_invCnt = 0; // Select Output state, invalid other event count
288 UInt32 gResetOutProcState_EvtWakeTimer_cnt = 0; // Select Output state, Wake Timer event count
289 UInt32 gResetOutProcState_EvtTxMcaspEdma_cnt = 0; // Reset Output Processing state, Tx McASP EDMA event count
290 UInt32 gResetOutProcState_Evt_invCnt = 0; // Reset Output Processing state, invalid other event count
291 UInt32 gInitSyncDecInfo1State_EvtWakeTimer_cnt = 0; // Init-Sync Dec Info1 state, Wake Timer event count
292 UInt32 gInitSyncDecInfo1State_EvtTxMcaspEdma_cnt = 0; // Init-Sync Dec Info1 state, Tx McASP EDMA event count
293 UInt32 gInitSyncDecInfo1State_Evt_invCnt = 0; // Init-Sync Dec Info1 state, invalid other event count
294 UInt32 gInitSyncDecDecode1State_EvtWakeTimer_cnt = 0; // Init-Sync Dec Decode1 state, Wake Timer event count
295 UInt32 gInitSyncDecDecode1State_EvtTxMcaspEdma_cnt = 0; // Init-Sync Dec Decode1 state, Tx McASP EDMA event count
296 UInt32 gInitSyncDecDecode1State_Evt_invCnt = 0; // Init-Sync Dec Decode1 state, invalid other event count
297 UInt32 gProcDecOutState_EvtWakeTimer_cnt = 0; // Process Output state, Wake Timer event count
298 UInt32 gProcDecOutState_EvtTxMcaspEdma_cnt = 0; // Process Output state, Tx McASP EDMA event count
299 UInt32 gProcDecOutState_Evt_invCnt = 0; // Process Output state, invalid other event count
300 UInt32 gReselOutDevState_EvtWakeTimer_cnt = 0; // Process Output state, Wake Timer event count
301 UInt32 gReselOutDevState_EvtTxMcaspEdma_invCnt = 0; // Re-select Output state, invalid other event count
302 UInt32 gReselOutDevState_Evt_invCnt = 0; // Re-select Output state, invalid other event count
303 // Debug state counters
304 UInt32 gAsotInitSyncResyncState_Cnt = 0; // Init-Sync Re-sync (Local error) state execution count
305 UInt32 gAsotInvState_Cnt = 0; // invalid state count
308 /*
309 * ======== taskAsopFxn ========
310 * Audio Stream Output Processing task function
311 */
312 Void taskAsopFxn(
313 const PAF_ASOT_Params *pP,
314 const PAF_ASOT_Patchs *pQ
315 )
316 {
317 PAF_ASOT_Config *pAsotCfg; // ASOT configuration pointer
318 PAF_AST_Config *pAstCfg; // Common (shared) configuration pointer
319 Int as; // Audio Stream Number (1, 2, etc.)
320 Int z; // input/encode/stream/decode/output counter
321 Bool outDevSel; // whether output device selected
322 PAF_AudioFrame decResetAf;
323 PAF_AudioFrame decInfo1Af;
324 UInt events; // latched event flags
325 Bool procEvents; // process events flags
326 Bool procOutFirstTime; // first time process output flag
327 Int asopFrameCount; // frame counter
328 Int status; // status code
329 #ifndef ASOP_DEBUG
330 Int asopLoopCount; // debug, ASOT loop counter
331 #endif
333 Log_info0("Enter taskAsopFxn()");
335 taskAsopFxnInit(pP, pQ); // initialization of output task
337 //
338 // Audio Stream Output Task Configuration (*pAsotCfg):
339 //
340 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
341 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
342 as = pAstCfg->as; // obtain Audio Stream Number (1, 2, etc.)
344 //
345 // Main processing loop
346 //
347 for (z=STREAM1; z < STREAMN; z++)
348 {
349 TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
350 }
352 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // init state
353 procEvents = TRUE; // init proc events flag
354 procOutFirstTime = TRUE; // init first time process output flag
355 asopFrameCount = 0; // init frame counter TBD
356 asopLoopCount = 0; // loop counter
357 for (;;)
358 {
359 // Pend for next event
360 // Evt_Id_AsotWakeTimer : Wakeup timer (poll for Output device selection)
361 // Evt_Id_AsotTxMcaspEdma : Tx McASP EDMA completion
362 if (procEvents == TRUE)
363 {
364 events = Event_pend(asotEvt, Event_Id_NONE, (Evt_Id_AsotWakeTimer + Evt_Id_AsotTxMcaspEdma), BIOS_WAIT_FOREVER);
365 }
367 asopLoopCount++;
368 TRACE_GEN1("TaskAsop (begin Main loop %d)", asopLoopCount);
370 switch (pAsotCfg->state)
371 {
372 //
373 // Select Output Device state
374 //
375 case ASOT_STATE_SEL_OUT_DEV:
376 if (events & Evt_Id_AsotWakeTimer)
377 {
378 gSelOutDevState_EvtWakeTimer_cnt++;
379 events &= ~Evt_Id_AsotWakeTimer; // clear event
381 // Select Output devices
382 // outDevSel==TRUE if Output device selection successful
383 status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
384 if (status < 0)
385 {
386 // FL, New IO:
387 //Tx status==error message to ASIT; // ASOT initiated message to ASIT, "backward" error
389 // No explicit handling of Select Output Device error, so stay in state and try again
390 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
391 break;
392 }
393 else if (outDevSel == TRUE)
394 {
395 // Select successful
396 pAsotCfg->state = ASOT_STATE_RESET_OUT_PROC;
397 }
398 else
399 {
400 // No output device selected (outDevSel == FALSE)
401 // Staying in same state.
402 ;
403 }
404 }
406 // Check for unexpected Tx McASP EDMA event
407 if (events & Evt_Id_AsotTxMcaspEdma)
408 {
409 gSelOutDevState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
410 TRACE_TERSE2("TaskAsop: invalid Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
411 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
412 }
414 // Check for any other unexpected events
415 if (events != 0)
416 {
417 gSelOutDevState_Evt_invCnt++; // log invalid event count in state
418 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
419 events &= ~events; // clear events
420 }
422 break;
424 // FL, New IO: currently using timer event
425 //
426 // Reset Output Processing state
427 //
428 case ASOT_STATE_RESET_OUT_PROC:
429 if (events & Evt_Id_AsotWakeTimer)
430 {
431 gResetOutProcState_EvtWakeTimer_cnt++;
432 events &= ~Evt_Id_AsotWakeTimer; // clear event
434 //
435 // Allow Output device re-selection prior to Output processing.
436 // Output device selection has already been performed in state==ASOT_STATE_SEL_OUT_DEV.
437 // Output device can be re-selected via alpha commands before streaming is initiated.
438 // Here check whether this has occurred.
439 //
441 // Select Output devices
442 // outDevSel==TRUE if Output device selection successful
443 status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
444 if (status < 0)
445 {
446 // FL, New IO:
447 //Tx status==error message to ASIT; // ASOT initiated message to ASIT, "backward" error
449 // Starting over with Output device selection in case of error
450 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
451 break;
452 }
454 // Reset Output processing
455 status = PAF_ASOT_resetDecOutProc(pP, pQ, pAsotCfg, &decResetAf, outDevSel, asopFrameCount);
456 if (status < 0)
457 {
458 // FL, New IO:
459 //Tx status==error message to ASDT; // feedback message ASOT -> ASDT
461 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
462 break;
463 }
464 else
465 {
466 // FL, New IO:
467 //Tx status==ok message to ASDT; // feedback message ASOT -> ASDT
469 pAsotCfg->state = ASOT_STATE_INITSYNC_DEC_INFO1;
470 }
471 }
473 // Check for unexpected Tx McASP EDMA event
474 if (events & Evt_Id_AsotTxMcaspEdma)
475 {
476 gResetOutProcState_EvtTxMcaspEdma_cnt++; // log event count in state
477 TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
478 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
479 }
481 // Check for any other unexpected events
482 if (events != 0)
483 {
484 gResetOutProcState_Evt_invCnt++; // log invalid event count in state
485 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
486 events &= ~events; // clear events
487 }
489 break;
491 // FL, New IO: currently using timer event
492 //
493 // Init-Sync Info1 state
494 //
495 case ASOT_STATE_INITSYNC_DEC_INFO1:
496 if (events & Evt_Id_AsotWakeTimer)
497 {
498 gInitSyncDecInfo1State_EvtWakeTimer_cnt++;
499 events &= ~Evt_Id_AsotWakeTimer; // clear event
501 status = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af, asopFrameCount);
502 if (status < 0)
503 {
504 // FL, New IO:
505 //Tx status==error message to ASDT; // feedback message ASOT -> ASDT
507 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
508 break;
509 }
510 else
511 {
512 // FL, New IO:
513 //Tx status==ok message to ASDT; // feedback message ASOT -> ASDT
515 pAsotCfg->state = ASOT_STATE_INITSYNC_DEC_DECODE1;
516 }
517 }
519 // Check for unexpected Tx McASP EDMA event
520 if (events & Evt_Id_AsotTxMcaspEdma)
521 {
522 gInitSyncDecInfo1State_EvtTxMcaspEdma_cnt++; // log event count in state
523 TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
524 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
525 }
527 // Check for any other unexpected events
528 if (events != 0)
529 {
530 gInitSyncDecInfo1State_Evt_invCnt++; // log invalid event count in state
531 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
532 events &= ~events; // clear events
533 }
535 break;
537 // FL, New IO: currently using timer event
538 //
539 // Init-Sync Decode1 state
540 //
541 case ASOT_STATE_INITSYNC_DEC_DECODE1:
542 if (events & Evt_Id_AsotWakeTimer)
543 {
544 gInitSyncDecDecode1State_EvtWakeTimer_cnt++;
545 events &= ~Evt_Id_AsotWakeTimer; // clear event
547 status = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg, asopFrameCount);
548 if (status < 0)
549 {
550 // FL, New IO:
551 //Tx status==error message to ASDT; // feedback message ASOT -> ASDT
553 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
554 break;
555 }
556 else
557 {
558 // FL, New IO:
559 //Tx status==ok message to ASDT; // feedback message ASOT -> ASDT
561 pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
562 procOutFirstTime = TRUE;
563 }
564 }
566 // Check for unexpected Tx McASP EDMA event
567 if (events & Evt_Id_AsotTxMcaspEdma)
568 {
569 gInitSyncDecDecode1State_EvtTxMcaspEdma_cnt++; // log event count in state
570 TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
571 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
572 }
574 // Check for any other unexpected events
575 if (events != 0)
576 {
577 gInitSyncDecDecode1State_Evt_invCnt++; // log invalid event count in state
578 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
579 events &= ~events; // clear events
580 }
582 break;
584 //
585 // Process Decoder Output state
586 //
587 case ASOT_STATE_PROC_DEC_OUT:
588 if (events & Evt_Id_AsotTxMcaspEdma)
589 {
590 gProcDecOutState_EvtTxMcaspEdma_cnt++;
591 events &= Evt_Id_AsotTxMcaspEdma; // clear event
593 // Process Output
594 status = PAF_ASOT_procDecOut(pP, pQ, pAsotCfg, &procOutFirstTime, asopFrameCount);
595 if (status < 0)
596 {
597 if (status == ASOP_DOP_ERR_FINALTEST_CBDRAINED)
598 {
599 // normal completion, CB drained @ EOS
600 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
601 break;
603 }
604 else if (status == ASOP_ERR_PROCDECOUT_OUTDEVSELUPD)
605 {
606 // Output re-select
607 pAsotCfg->state = ASOT_STATE_RESEL_OUT_DEV;
608 break;
609 }
610 // FL, New IO: "backward" error handling.
611 // Currently all errors handled locally.
612 else
613 {
614 // Handle ASOT "local" errors
615 pAsotCfg->state = ASOT_STATE_INITSYNC_RESYNC;
616 procEvents = FALSE;
617 break;
618 }
619 }
620 }
622 // Check for Wakeup Timer event.
623 // Wakeup Timer events are allowed to occur, but no processing is
624 // performed in response to such an event.
625 if (events & Evt_Id_AsotWakeTimer)
626 {
627 events &= ~Evt_Id_AsotWakeTimer; // clear event
628 gProcDecOutState_EvtWakeTimer_cnt++; // log event count in state
629 }
631 // Check for any other unexpected events
632 if (events != 0)
633 {
634 gProcDecOutState_Evt_invCnt++; // log invalid event count in state
635 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
636 events &= ~events; // clear events
637 }
639 break;
641 //
642 // Re-Select Output Device state
643 //
644 case ASOT_STATE_RESEL_OUT_DEV:
645 if (events & Evt_Id_AsotWakeTimer)
646 {
647 gReselOutDevState_EvtWakeTimer_cnt++;
648 events &= ~Evt_Id_AsotWakeTimer; // clear event
650 status = PAF_ASOT_reselectDevices(pP, pQ, pAsotCfg, &decResetAf, &decInfo1Af, asopFrameCount, &outDevSel);
651 if (status < 0)
652 {
653 // FL, New IO:
654 //Tx status==error message to ASIT; // ASOT initiated message to ASIT, "backward" error
656 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
657 break;
658 }
659 else if (outDevSel == TRUE)
660 {
661 // Re-select successful
662 pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
663 procOutFirstTime = TRUE;
664 }
665 else
666 {
667 // No output device selected (outDevSel == FALSE).
668 // Staying in same state
669 ;
670 }
671 }
673 // Check for unexpected Tx McASP EDMA event
674 if (events & Evt_Id_AsotTxMcaspEdma)
675 {
676 events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
677 gReselOutDevState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
678 }
680 // Check for any other unexpected events
681 if (events != 0)
682 {
683 gReselOutDevState_Evt_invCnt++; // log invalid event count in state
684 TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
685 events &= ~events; // clear events
686 }
688 break;
690 //
691 // Init-Sync Re-sync (Process Output Local Error) state
692 //
693 case ASOT_STATE_INITSYNC_RESYNC: // not event driven state
694 gAsotInitSyncResyncState_Cnt++;
696 status = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf, &decInfo1Af, asopFrameCount);
697 if (status < 0)
698 {
699 // FL, New IO:
700 //Tx status==error message to ASIT; // ASIT initiated message to ASOT, "backward" error
702 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // starting over with Output device selection in case of error
703 procEvents = TRUE;
704 break;
705 }
706 else
707 {
708 pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
709 procEvents = TRUE;
710 procOutFirstTime = TRUE;
711 }
713 break;
715 default:
716 gAsotInvState_Cnt++;
717 TRACE_TERSE1("TaskAsop: invalid state, state=%u", pAsotCfg->state);
719 break;
720 }
722 // FL, New IO: handle ASIT messages separately in each state
723 // FL, New IO: proper SM clean up can be skipped if forward error / DEC restart is handled in this way
725 //
726 // Check forward (ASIT) error, TBD
727 //
729 // Check writeDECCommandRestart, TBD
730 if (gCommandOutputTask_SYNC)
731 {
732 TRACE_TERSE0("TaskAsop: ack writeDECCommandRestart ... Wait for command de-assert");
733 gCommandOutputTask_ACK = 1;
734 while (gCommandOutputTask_SYNC)
735 {
736 Event_pend(asotEvt, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
737 }
738 TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Re-start the process");
739 pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV; // init state -- start over
740 status = ASOP_ERR_FORWARD_ERR; // set status -- force flushing of output device
741 }
743 // any error forces idling of output
744 if (status < 0)
745 {
746 for (z=OUTPUT1; z < OUTPUTN; z++)
747 {
748 //if (pAstCfg->xOut[z].hTxSio)
749 if (pAsotCfg->pIoOut[z].hIoPhy)
750 {
751 //SIO_idle(pAstCfg->xOut[z].hTxSio); JX TO DO: implement proper error handling
752 }
753 }
755 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", asopLoopCount);
756 //ERRNO_RPRT(TaskAsop, errno);
757 }
758 } // End of main processing loop for (;;)
759 } /* taskAsopFxn */
761 // ASOT wake timer (clock) function
762 Void clkAsotFxn(Void)
763 {
764 Event_post(asotEvt, Evt_Id_AsotWakeTimer);
765 }
767 void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
768 {
769 /* post semaphore */
770 if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
771 //Semaphore_post(asopSemTx);
772 Event_post(asotEvt, Evt_Id_AsotTxMcaspEdma);
773 } else {
774 ; // intermediate packet due to buffer wrapping around
775 }
776 }
778 // Reset audio frame pointers to original values
779 static Void resetAfPointers(
780 const PAF_ASOT_Params *pP,
781 PAF_AST_Stream *xStr
782 )
783 {
784 Int z;
785 Int ch;
787 // Reset audio frame pointers to original values
788 for (z = STREAM1; z < STREAMN; z++)
789 {
790 for (ch = PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
791 {
792 if (xStr[z].audioFrameChannelPointers[ch])
793 {
794 xStr[z].audioFrameChannelPointers[ch] =
795 xStr[z].origAudioFrameChannelPointers[ch];
796 }
797 }
798 }
799 }
801 // Check if at least one output selected
802 Int checkOutDevSel(
803 const PAF_ASOT_Params *pP,
804 PAF_ASOT_Config *pAsotCfg,
805 Bool *pOutSel
806 )
807 {
808 PAF_AST_IoOut *pOut;
809 Int outSel;
810 Int z;
812 pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
814 outSel = 0;
815 for (z=OUTPUT1; z < OUTPUTN; z++)
816 {
817 if (pOut[z].hIoPhy)
818 {
819 outSel = 1;
820 break;
821 }
822 }
824 *pOutSel = outSel;
826 return ASOP_SOK;
827 }
829 // ASOT SM function
830 // -----------------------------------------------------------------------------
831 // ASOT Selection Function - Output Device Selection
832 //
833 // Name: PAF_ASOT_selectDevices
834 // Purpose: Audio Stream Output Task Function for selecting the devices used
835 // for output.
836 //
837 static Int PAF_ASOT_selectDevices(
838 const PAF_ASOT_Params *pP,
839 const PAF_ASOT_Patchs *pQ,
840 PAF_ASOT_Config *pAsotCfg,
841 Bool *pOutDevSel
842 )
843 {
844 PAF_AST_Config *pAstCfg; // Common (shared) configuration pointer
845 Int z;
846 Int zS, zO;
847 Int status;
849 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
851 // Find first Output associated with Master Stream
852 zO = OUTPUT1;
853 for (z=ENCODE1; z < ENCODEN; z++)
854 {
855 zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
856 if (zS == pAstCfg->masterStr)
857 {
858 // This Encoder is associated with Master Stream.
859 // Note other Encoder can also be associated with Master Stream.
860 zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
861 }
862 }
864 // Select Output Devices
865 // FL, New IO: Placeholder function, this will be reorganized moving forward.
866 // FL: New IO: API for single Output.
867 // FL: New IO: Doesn't update Output SIO select.
868 status = asopSelectDevices(&pAsotCfg->pIoOut[zO]);
869 if (status < 0)
870 {
871 *pOutDevSel = FALSE;
872 return status;
873 }
875 // Reset IO Buff & IO Phy
876 // FL, New IO: API for single Output
877 status = asopIoCompsInit(&pAstCfg->xOut[zO], &pAsotCfg->pIoOut[zO]);
878 if (status < 0)
879 {
880 *pOutDevSel = FALSE;
881 return status;
882 }
884 // I/O physical layer prime operation required by McASP LLD
885 // FL, New IO: API for single Output
886 asopIoPhyPrime(&pAsotCfg->pIoOut[zO]);
888 // Check if Output device selected
889 // FL, New IO: API for multiple Outputs
890 status = checkOutDevSel(pP, pAsotCfg, pOutDevSel);
891 if (status < 0)
892 {
893 *pOutDevSel = FALSE;
894 return status;
895 }
897 return ASOP_SOK;
898 }
900 // ASOT SM function
901 // Wake Timer + *POLLING* version.
902 // No explicit Rx ASDT message event from ASDT.
903 // ASOT wakes on Wake Timer event and polls for flag set.
904 // Reset Decoder Output processing
905 static Int PAF_ASOT_resetDecOutProc(
906 const PAF_ASOT_Params *pP,
907 const PAF_ASOT_Patchs *pQ,
908 PAF_ASOT_Config *pAsotCfg,
909 PAF_AudioFrame *pDecResetAf,
910 Bool outDevSel,
911 Int frame
912 )
913 {
914 Int status;
916 if (outDevSel == FALSE)
917 {
918 //
919 // Rx Dec Out-IS message before Output selected.
920 // Decoder is producing output, but no Output selected.
921 //
922 return ASOP_ERR_RESETOUTPROC_NOOUTDEVSEL;
923 }
925 // Perform Dec Reset Init-Sync
926 status = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, pDecResetAf, frame);
928 return status;
929 }
932 // Reset audio frame meta data elements
933 static Void resetAfMetadata(
934 const PAF_ASOT_Params *pP,
935 PAF_AST_Stream *xStr
936 )
937 {
938 Int z;
939 Int i;
941 for (z = STREAM1; z < STREAMN; z++)
942 {
943 xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
944 xStr[z].pAudioFrame->numPrivateMetadata = 0;
945 xStr[z].pAudioFrame->bsMetadata_offset = 0;
946 xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
948 for (i = 0; i < pP->pMetadataBufStatus->NumBuf; i++)
949 {
950 xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
951 xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
952 }
953 }
954 }
956 // Reset audio frames
957 static Void resetAfs(
958 const PAF_ASOT_Params *pP,
959 PAF_AST_Stream *xStr
960 )
961 {
962 // Reset audio frame pointers to original values
963 // (may be needed if error occurred).
964 resetAfPointers(pP, xStr);
965 // Reset audio frame meta data elements
966 resetAfMetadata(pP, xStr);
967 }
969 // Purpose: Performs Dec Reset Init-Sync.
970 //static Int PAF_ASOT_initSyncDecReset(
971 // used by new OutProc.c, will be changed back to static once refactoring is done
972 static Int PAF_ASOT_initSyncDecReset(
973 const PAF_ASOT_Params *pP,
974 const PAF_ASOT_Patchs *pQ,
975 PAF_ASOT_Config *pAsotCfg,
976 PAF_AudioFrame *pDecResetAf,
977 Int frame
978 )
979 {
980 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
981 Int zMD, zMS; // Dec and Stream Master indices
982 PAF_AudioFrame *pStrAf; // stream audio frame
983 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
984 Int8 decFlag; // dec stage flag
985 Int status; // status code
987 pAstCfg = pAsotCfg->pAstCfg;
988 zMD = pAstCfg->masterDec;
989 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
991 // check for Dec Reset
992 // store dec reset AF
993 status = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
994 ASP_OUTIS_DEC_STAGE_RESET_IDX, &decFlag, pDecResetAf);
995 if (status < 0)
996 {
997 return status;
998 }
1000 if (decFlag == 0)
1001 {
1002 return ASOP_SOK_INITSYNC_NOTREADY;
1003 }
1004 else
1005 {
1006 zMS = pAstCfg->masterStr;
1007 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1009 // Reset audio frames
1010 // FL, New IO: API for multiple streams.
1011 resetAfs(pP, pAstCfg->xStr);
1013 // Update Stream Audio Frame.
1014 // Copy Dec Reset AF to Stream AF.
1015 // FL, New IO: Only Master zone (single) stream handled.
1016 outIsCpyAf(pDecResetAf, pStrAf);
1018 // Enc activate
1019 // Enc reset
1020 status = asopDecOutProcReset(pP, pQ, pAsotCfg, frame);
1021 if (status < 0)
1022 {
1023 return status;
1024 }
1026 return ASOP_SOK;
1027 }
1028 }
1030 // ASOT SM function
1031 // Purpose: Init-Sync Dec Info1 state function.
1032 // Wake Timer + *POLLING* version.
1033 // No explicit Rx ASDT message event from ASDT.
1034 // ASOT wakes on Wake Timer event and polls for flag set.
1035 static Int PAF_ASOT_initSyncDecInfo1(
1036 const PAF_ASOT_Params *pP,
1037 const PAF_ASOT_Patchs *pQ,
1038 PAF_ASOT_Config *pAsotCfg,
1039 PAF_AudioFrame *pDecInfo1Af,
1040 Int frame
1041 )
1042 {
1043 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1044 Int zMD, zMS; // Dec and Stream Master indices
1045 PAF_AudioFrame *pStrAf; // stream audio frame
1046 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
1047 Int8 decFlag; // dec stage flag
1048 Int status; // status code
1050 pAstCfg = pAsotCfg->pAstCfg;
1051 zMD = pAstCfg->masterDec;
1052 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
1054 // Check for Dec Reset,
1055 // Store dec reset AF
1056 status = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
1057 ASP_OUTIS_DEC_STAGE_INFO1_IDX, &decFlag, pDecInfo1Af);
1058 if (status < 0)
1059 {
1060 return status;
1061 }
1063 if (decFlag == 0)
1064 {
1065 return ASOP_SOK_INITSYNC_NOTREADY;
1066 }
1067 else
1068 {
1069 zMS = pAstCfg->masterStr;
1070 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1072 // Set ASOT output frame length.
1073 // THD sets this to 256 (hard-coded in Dec Info)
1074 // DDP sets this to 0 (audio frame pass through, 0 from ASDT AF frame length)
1075 // PCM sets this to 256 (decodeControl.frameLength)
1076 pDecInfo1Af->sampleCount = gOutFrameLen; // !!!! GJ: Revisit !!!!
1078 // Update Stream Audio Frame.
1079 // Copy Dec Reset AF to Stream AF.
1080 outIsCpyAf(pDecInfo1Af, pStrAf);
1082 // outputInfo1():
1083 // - ASP chain reset,
1084 // - Enc Info,
1085 // - Start Output
1086 status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1087 if (status < 0)
1088 {
1089 return status;
1090 }
1092 return ASOP_SOK;
1093 }
1094 }
1096 // ASOT SM function
1097 // Purpose: Init-Sync Dec Decode1 state function.
1098 // Wake Timer + *POLLING* version.
1099 // No explicit Rx ASDT message event from ASDT.
1100 // ASOT wakes on Wake Timer event and polls for flag set.
1101 //static Int PAF_ASOT_initSyncDecDecode1(
1102 static Int PAF_ASOT_initSyncDecDecode1(
1103 const PAF_ASOT_Params *pP,
1104 const PAF_ASOT_Patchs *pQ,
1105 PAF_ASOT_Config *pAsotCfg,
1106 Int frame
1107 )
1108 {
1109 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1110 Int zMD; // Dec Master index
1111 PAF_AST_OutInitSyncCtl *pOutIsCtl; // Output Init-Sync control
1112 Int8 decFlag; // dec stage flag
1113 Int status; // status code
1115 pAstCfg = pAsotCfg->pAstCfg;
1116 zMD = pAstCfg->masterDec;
1117 pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
1119 // Check for Dec Reset,
1120 // Store dec reset AF
1121 status = outIsReadDecStageFlag(pOutIsCtl, zMD,
1122 ASP_OUTIS_DEC_STAGE_DECODE1_IDX, &decFlag);
1123 if (status < 0)
1124 {
1125 return status;
1126 }
1128 if (decFlag == 0)
1129 {
1130 return ASOP_SOK_INITSYNC_NOTREADY;
1131 }
1132 else
1133 {
1134 return ASOP_SOK;
1135 }
1136 }
1138 // ASOT SM function
1139 // Process Decoder output audio data
1140 static Int PAF_ASOT_procDecOut(
1141 const PAF_ASOT_Params *pP,
1142 const PAF_ASOT_Patchs *pQ,
1143 PAF_ASOT_Config *pAsotCfg,
1144 Bool *pFirstTime,
1145 Int frame
1146 )
1147 {
1148 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1149 Int outDevSelUpdate; // indicates whether Output SIO selection has changed
1150 Int zO, zS;
1151 Int z; // decode/encode counter
1152 Int errno; // error number
1153 Int status; // status code
1155 status = ASOP_SOK;
1156 pAstCfg = pAsotCfg->pAstCfg;
1158 if (*pFirstTime == TRUE)
1159 {
1160 // Initialize Decoder output processing
1161 errno = asopDecOutProcInit(pP, pQ, pAsotCfg, frame);
1162 if (errno < 0)
1163 {
1164 status = errno;
1165 }
1166 else
1167 {
1168 *pFirstTime = FALSE;
1169 }
1170 }
1172 if (status == ASOP_SOK)
1173 {
1174 // Find first Output associated with Master Stream
1175 zO = OUTPUT1;
1176 for (z=ENCODE1; z < ENCODEN; z++)
1177 {
1178 zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
1179 if (zS == pAstCfg->masterStr)
1180 {
1181 // This Encoder is associated with Master Stream.
1182 // Note other Encoder can also be associated with Master Stream.
1183 zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
1184 }
1185 }
1187 // Mark Output transfer complete
1188 errno = ioPhyXferComplete(pAsotCfg->pIoOut[zO].hIoPhy, FALSE);
1189 if (errno)
1190 {
1191 status = ASOP_ERR_PROCDECOUT_IOPHYXFERCOMPLETE;
1192 }
1193 }
1195 if (status == ASOP_SOK)
1196 {
1197 // Check if at least one Output device SIO selection changed
1198 errno = checkOutDevSelUpdate(pP, pAsotCfg, &outDevSelUpdate);
1199 if (errno)
1200 {
1201 status = ASOP_ERR_PROCDECOUT_CHKOUTDEVSELUPD;
1202 }
1203 else if (outDevSelUpdate == TRUE)
1204 {
1205 status = ASOP_ERR_PROCDECOUT_OUTDEVSELUPD;
1206 }
1207 }
1209 if (status == ASOP_SOK)
1210 {
1211 // Process encoder command
1212 errno = asopDecOutProcEncodeCommand(pP, pQ, pAsotCfg);
1213 if (errno < 0)
1214 {
1215 status = errno;
1216 }
1217 }
1219 if (status == ASOP_SOK)
1220 {
1221 // Read CB, execute ASP chain
1222 errno = asopDecOutProcStream(pP, pQ, pAsotCfg, frame);
1223 if (errno < 0)
1224 {
1225 status = errno;
1226 }
1227 }
1229 if (status == ASOP_SOK)
1230 {
1231 // Execute encode
1232 errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
1233 if (errno < 0)
1234 {
1235 status = errno;
1236 }
1237 }
1239 if (status == ASOP_SOK)
1240 {
1241 // Execute Info2
1242 errno = asopDecOutProcInfo2(pP, pQ, pAsotCfg, frame);
1243 if (errno < 0)
1244 {
1245 status = errno;
1246 }
1247 }
1249 if (status == ASOP_SOK)
1250 {
1251 errno = asopDecOutProcFinalTest(pP, pQ, pAsotCfg, frame);
1252 if (errno < 0)
1253 {
1254 status = errno;
1255 }
1256 }
1258 if (status != ASOP_SOK)
1259 {
1260 // Complete Output Processing
1261 errno = asopDecOutProcComplete(pP, pQ, pAsotCfg, frame);
1262 if (errno < 0)
1263 {
1264 status = errno;
1265 }
1266 }
1268 return status;
1269 }
1271 // ASOT SM function
1272 // Purpose: Init-Sync Re-Sync state function.
1273 // Performs Init-Sync using stored Dec Reset/Info1 AFs.
1274 static Int PAF_ASOT_initSyncResync(
1275 const PAF_ASOT_Params *pP,
1276 const PAF_ASOT_Patchs *pQ,
1277 PAF_ASOT_Config *pAsotCfg,
1278 PAF_AudioFrame *pDecResetAf,
1279 PAF_AudioFrame *pDecInfo1Af,
1280 Int frame
1281 )
1282 {
1283 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
1284 Int zMS; // Stream Master index
1285 PAF_AudioFrame *pStrAf; // stream audio frame
1286 Int status; // status code
1288 pAstCfg = pAsotCfg->pAstCfg;
1289 zMS = pAstCfg->masterStr;
1290 pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1292 // Reset audio frames
1293 resetAfs(pP, pAstCfg->xStr);
1295 //
1296 // Dec Reset re-sync using stored Dec Reset AF
1297 //
1299 // Update Stream Audio Frame.
1300 // Copy Dec Reset AF to Stream AF.
1301 outIsCpyAf(pDecResetAf, pStrAf);
1303 // Enc activate,
1304 // Enc reset
1305 status = asopDecOutProcReset(pP, pQ, pAsotCfg, frame);
1306 if (status < 0)
1307 {
1308 return status;
1309 }
1311 //
1312 // Dec Info1 re-sync using stored Dec Info1 AF
1313 //
1315 // Update Stream Audio Frame.
1316 // Copy Dec Info1 AF to Stream AF.
1317 outIsCpyAf(pDecInfo1Af, pStrAf);
1319 // outputInfo1():
1320 // - ASP chain reset,
1321 // - Enc Info,
1322 // - Start Output
1323 status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1324 if (status < 0)
1325 {
1326 return status;
1327 }
1329 return ASOP_SOK;
1330 }
1332 // ASOT SM function
1333 // Purpose: Re-select devices used for Output.
1334 // Performs Init-Sync using stored Dec Reset/Info1 AFs.
1335 static Int PAF_ASOT_reselectDevices(
1336 const PAF_ASOT_Params *pP,
1337 const PAF_ASOT_Patchs *pQ,
1338 PAF_ASOT_Config *pAsotCfg,
1339 PAF_AudioFrame *pDecResetAf,
1340 PAF_AudioFrame *pDecInfo1Af,
1341 Int frame,
1342 Bool *pOutDevSel
1343 )
1344 {
1345 Bool outDevSel;
1346 Int status;
1348 // Re-select Output devices
1349 status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
1350 if (status < 0)
1351 {
1352 *pOutDevSel = outDevSel;
1353 return status;
1354 }
1355 else if (outDevSel == FALSE)
1356 {
1357 *pOutDevSel = outDevSel;
1358 return status;
1359 }
1360 else
1361 {
1362 // Init-Sync Resync
1363 status = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, pDecResetAf, pDecInfo1Af, frame);
1364 if (status < 0)
1365 {
1366 outDevSel = FALSE;
1367 *pOutDevSel = outDevSel;
1368 return status;
1369 }
1370 }
1372 *pOutDevSel = outDevSel;
1373 return status;
1374 }