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.h ========
38 */
40 #ifndef _ASOP_H_
41 #define _ASOP_H_
43 #include <xdc/std.h>
44 #include <ti/sysbios/knl/Task.h>
46 #include "audioStreamProc_params.h"
47 #include "audioStreamProc_patchs.h"
48 #include "audioStreamProc_config.h"
49 #include "audioStreamProc_master.h"
50 #include "ioPhy.h"
51 #include "ioBuff.h"
53 /* !!!!!!!!! Revisit !!!!!!!!!!!!!!
54 * Purpose : Temporary ASOT FL sizes.
55 * Deprecate PAF_SYS_FRAMELENGTH in phases.*/
56 #define PAF_ASOT_FRAMELENGTH 256
57 #define PAF_ASOT_MAX_FRAMELENGTH 1024
59 // Global debug counter */
60 extern Uint32 gTaskAsopCnt; // debug counter for ASOP task
62 struct PAF_ASOT_Params;
63 struct PAF_ASOT_Patchs;
64 struct PAF_ASOT_Config;
66 // Audio Stream Output Task (ASOT) parameters, functions
67 typedef struct PAF_ASOT_Fxns {
68 Int (*initPhase[8]) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
69 Int (*initFrame0) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int);
70 Int (*initFrame1) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
71 //Int (*passProcessing) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int);
72 //Int (*passProcessingCopy) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *);
73 //Int (*autoProcessing) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, ALG_Handle);
75 //Int (*decodeProcessing) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int);
76 Int (*decodeProcessing) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
78 //Int (*decodeCommand) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *);
79 Int (*encodeCommand) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
81 //Int (*decodeInit) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int);
82 Int (*decodeInit) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
84 //Int (*decodeInfo) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int);
85 Int (*decodeInfo1) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
86 Int (*decodeInfo2) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
87 //Int (*decodeCont) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, ALG_Handle *, Int, Int);
88 //Int (*decodeDecode) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int, Int);
89 Int (*decodeStream) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
90 Int (*decodeEncode) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
92 //Int (*decodeFinalTest) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int);
93 Int (*decodeFinalTest) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int);
95 Int (*decodeComplete) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, ALG_Handle *, Int, Int);
96 Int (*selectDevices) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
97 //Int (*sourceDecode) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int);
98 Int (*startOutput) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
99 Int (*stopOutput) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *);
100 Int (*setCheckRateX) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int);
101 Int (*streamChainFunction) (const struct PAF_ASOT_Params *, const struct PAF_ASOT_Patchs *, struct PAF_ASOT_Config *, Int, Int, Int);
102 Int (*deviceAllocate) (SIO_Handle *, int, int, int, Ptr);
103 Int (*deviceSelect) (SIO_Handle *, int, int, Ptr);
104 //Int (*computeFrameLength) (Int, Int, Int);
105 //Int (*updateInputStatus) (SIO_Handle, PAF_InpBufStatus *, PAF_InpBufConfig *);
106 //Int (*copy) (Uns, PAF_InpBufConfig *, Uns, PAF_OutBufConfig *);
108 // For RAM_report
109 Void (*headerPrint)();
110 Int (*allocPrint)(const PAF_ALG_AllocInit *pInit, Int sizeofInit, PAF_IALG_Config *p);
111 Void (*commonPrint)(IALG_MemRec common[], PAF_IALG_Config *p);
112 Void (*bufMemPrint)(Int z, Int size, Int heapId, Int bufType);
113 Void (*memStatusPrint)(
114 CString header,
115 HeapMem_Handle hInternalHeap,
116 HeapMem_Handle hInternal1Heap,
117 HeapMem_Handle hExternalHeap,
118 HeapMem_Handle hInternal1HeapShm,
119 HeapMem_Handle hExternalHeapShm,
120 HeapMem_Handle hExternalNoncachedHeapShm);
121 } PAF_ASOT_Fxns;
123 // Audio Stream Output Task (ASOT) parameters
124 typedef struct PAF_ASOT_Params {
125 const PAF_ASOT_Fxns *fxns;
126 struct {
127 SmInt master;
128 SmInt inputs;
129 SmInt input1;
130 SmInt inputN;
131 SmInt decodes;
132 SmInt decode1;
133 SmInt decodeN;
134 SmInt streams;
135 SmInt stream1; /* unused */
136 SmInt streamN; /* unused */
137 SmInt encodes;
138 SmInt encode1;
139 SmInt encodeN;
140 SmInt outputs;
141 SmInt output1;
142 SmInt outputN;
143 } zone;
144 const SmInt *inputsFromDecodes;
145 const SmInt *outputsFromEncodes;
146 struct {
147 int *pHeapIdIntern; // INT memory heap ID
148 int *pHeapIdExtern; // EXT memory heap ID
149 int *pHeapIdInpbuf; // IB buffer heap ID
150 int *pHeapIdOutbuf; // OB buffer heap ID
151 int *pHeapIdFrmbuf; // Frame buffer heap ID
152 int *pHeapIdIntern1; // INT1 memory heap ID
153 int *pHeapIdInt1Shm; // INT1 SHared Memory heap ID
154 int *pHeapIdExtShm; // EXT SHared Memory heap ID
155 int *pHeapIdExtNonCachedShm; // EXT Non-Cached SHared Memory heap ID
156 int clear;
157 } heap;
158 struct {
159 const IALG_MemSpace *space;
160 } common;
161 const LgInt *z_rx_bufsiz;
162 const LgInt *z_tx_bufsiz;
163 const SmInt *z_numchan;
164 MdInt framelength;
165 const PAF_AudioFunctions *pAudioFrameFunctions;
166 const struct PAF_ASP_ChainFxns *pChainFxns;
167 const PAF_InpBufStatus *pInpBufStatus;
168 const PAF_DecodeStatus * const *z_pDecodeStatus;
169 const PAF_OutBufStatus *pOutBufStatus;
170 const PAF_EncodeStatus * const *z_pEncodeStatus;
171 const PAF_VolumeStatus *pVolumeStatus;
172 const PAF_ASP_AlgKey *pDecAlgKey;
173 const PAF_ASP_AlgKey *pEncAlgKey;
174 const PAF_ASP_SioMap *pDecSioMap;
175 const SmInt *streamsFromDecodes;
176 const SmInt *streamsFromEncodes;
177 const MdInt maxFramelength;
178 const SmInt *streamOrder;
179 const PAF_ASP_LinkInit * const (*i_inpLinkInit);
180 const PAF_ASP_LinkInit * const (*i_outLinkInit);
181 const PAF_ASP_outNumBufMap * const (*poutNumBufMap);
182 const PAF_MetadataBufStatus *pMetadataBufStatus;
183 const PAF_AudioFrameBufStatus *pAudioFrameBufStatus;
184 } PAF_ASOT_Params;
186 // Audio Stream Output Task (ASOT) patchs
187 typedef struct PAF_ASOT_Patchs {
188 //const PAF_SIO_ParamsN * devinp;
189 const PAF_SIO_ParamsN * devout;
190 //const PAF_ASP_LinkInit * const (*i_decLinkInit);
191 const PAF_ASP_LinkInit * const (*i_aspLinkInit)[GEARS];
192 const PAF_ASP_LinkInit * const (*i_encLinkInit);
193 } PAF_ASOT_Patchs;
195 typedef struct PAF_AST_OutIO {
196 ioPhyHandle_t hIoPhy; /* handle to I/O physical layer */
197 ioBuffHandle_t hIoBuff; /* handle to I/O buffer management */
199 void *mcaspTxBuf1;
200 void *mcaspTxBuf2;
201 uint32_t mcaspTxSize1;
202 uint32_t mcaspTxSize2;
203 int mcaspTxtwoXfers;
205 int numPrimeXfers;
207 uint32_t mcaspXferErr;
209 // debugging counters
210 uint32_t num_xfers;
212 } PAF_AST_IoOut;
214 // Audio Stream Input Task (ASOT) configuration
215 typedef struct PAF_ASOT_Config {
216 Task_Handle taskHandle; // ASOT handle
217 ACP_Handle acp; // ASOT local ACP handle
218 Int8 cbDrainedFlag[DECODEN_MAX]; // CB drained flags
219 PAF_ASPM_Config *pAspmCfg; // ASIT/ASOT shared configuration
220 PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
221 PAF_AST_IoOut *pIoOut;
222 } PAF_ASOT_Config;
225 // Purpose: Audio Stream Outpu Task Function for initialization of data pointers
226 // by allocation of memory.
227 Int
228 PAF_ASOT_initPhaseMalloc(
229 const PAF_ASOT_Params *pP,
230 const PAF_ASOT_Patchs *pQ,
231 PAF_ASOT_Config *pAsotCfg
232 );
234 // Purpose: Audio Stream Output Task Function for initialization of data values
235 // from parameters.
236 Int
237 PAF_ASOT_initPhaseConfig(
238 const PAF_ASOT_Params *pP,
239 const PAF_ASOT_Patchs *pQ,
240 PAF_ASOT_Config *pAsotCfg
241 );
243 // Purpose: Audio Stream Output Task Function for initialization of ACP by
244 // instantiation of the algorithm.
245 Int
246 PAF_ASOT_initPhaseAcpAlg(
247 const PAF_ASOT_Params *pP,
248 const PAF_ASOT_Patchs *pQ,
249 PAF_ASOT_Config *pAsotCfg
250 );
252 // (***) FL: ASIT/ASOT currently consider common memory independently.
253 // Should simultaneously consider all algs in ASIT/ASOT.
254 // Purpose: Audio Stream Output Task Function for allocation of common memory.
255 Int
256 PAF_ASOT_initPhaseCommon(
257 const PAF_ASOT_Params *pP,
258 const PAF_ASOT_Patchs *pQ,
259 PAF_ASOT_Config *pAsotCfg
260 );
262 // Purpose: Audio Stream Output Task Function for initialization of ASP algorithms.
263 Int
264 PAF_ASOT_initPhaseAspAlg(
265 const PAF_ASOT_Params *pP,
266 const PAF_ASOT_Patchs *pQ,
267 PAF_ASOT_Config *pAsotCfg
268 );
270 // Purpose: Audio Stream Output Task Function for initialization of data values
271 // from parameters for Algorithm Keys.
272 Int
273 PAF_ASOT_initPhaseAlgKey(
274 const PAF_ASOT_Params *pP,
275 const PAF_ASOT_Patchs *pQ,
276 PAF_ASOT_Config *pAsotCfg
277 );
279 // Purpose: Audio Stream Output Task Function for initialization of Input Devices.
280 Int
281 PAF_ASOT_initPhaseDevice(
282 const PAF_ASOT_Params *pP,
283 const PAF_ASOT_Patchs *pQ,
284 PAF_ASOT_Config *pAsotCfg
285 );
287 // Purpose: Audio Stream Output Task Function for initialization of the Audio
288 // Frame(s) by memory allocation and loading of data pointers
289 // and values.
290 Int
291 PAF_ASOT_initFrame0(
292 const PAF_ASOT_Params *pP,
293 const PAF_ASOT_Patchs *pQ,
294 PAF_ASOT_Config *pAsotCfg,
295 Int z
296 );
298 // Purpose: Audio Stream Task Function for initialization or reinitiali-
299 // zation of the Audio Frame(s) by loading of data values of a
300 // time-varying nature.
301 Int
302 PAF_ASOT_initFrame1(
303 const PAF_ASOT_Params *pP,
304 const PAF_ASOT_Patchs *pQ,
305 PAF_ASOT_Config *pAsotCfg,
306 Int z,
307 Int apply
308 );
310 // Purpose: Audio Stream Output Task Function for selecting the devices used
311 // for output.
312 Int
313 PAF_ASOT_selectDevices(
314 const PAF_ASOT_Params *pP,
315 const PAF_ASOT_Patchs *pQ,
316 PAF_ASOT_Config *pAsotCfg
317 );
319 // Purpose: Audio Stream Output Task Function for processing audio data.
320 //
321 Int
322 PAF_ASOT_decodeProcessing(
323 const PAF_ASOT_Params *pP,
324 const PAF_ASOT_Patchs *pQ,
325 PAF_ASOT_Config *pAsotCfg
326 );
328 // Purpose: Decoding Function for processing Encode Commands.
329 Int
330 PAF_ASOT_encodeCommand(
331 const PAF_ASOT_Params *pP,
332 const PAF_ASOT_Patchs *pQ,
333 PAF_ASOT_Config *pAsotCfg
334 );
336 // Purpose: Decoding Function for reinitializing the decoding process.
337 Int
338 PAF_ASOT_decodeInit(
339 const PAF_ASOT_Params *pP,
340 const PAF_ASOT_Patchs *pQ,
341 PAF_ASOT_Config *pAsotCfg
342 );
344 // Purpose: Decoding Function for processing information in a manner that
345 // is unique to initial frames of input data.
346 Int
347 PAF_ASOT_decodeInfo(
348 const PAF_ASOT_Params *pP,
349 const PAF_ASOT_Patchs *pQ,
350 PAF_ASOT_Config *pAsotCfg,
351 Int frame,
352 Int block
353 );
355 // Purpose: Decoding Function for processing information in a manner that
356 // is unique to initial frames of input data.
357 Int
358 PAF_ASOT_decodeInfo1(
359 const PAF_ASOT_Params *pP,
360 const PAF_ASOT_Patchs *pQ,
361 PAF_ASOT_Config *pAsotCfg,
362 Int frame,
363 Int block
364 );
366 // Purpose: Decoding Function for processing information in a manner that
367 // is unique to frames of input data other than the initial one.
368 Int
369 PAF_ASOT_decodeInfo2(
370 const PAF_ASOT_Params *pP,
371 const PAF_ASOT_Patchs *pQ,
372 PAF_ASOT_Config *pAsotCfg,
373 Int frame,
374 Int block
375 );
377 // Purpose: Decoding Function for processing of audio frame data by the
378 // ASP Algorithms.
379 Int
380 PAF_ASOT_decodeStream(
381 const PAF_ASOT_Params *pP,
382 const PAF_ASOT_Patchs *pQ,
383 PAF_ASOT_Config *pAsotCfg,
384 Int frame,
385 Int block
386 );
388 // Purpose: Decoding Function for processing of audio frame data by the
389 // Encode Algorithm.
390 Int
391 PAF_ASOT_decodeEncode(
392 const PAF_ASOT_Params *pP,
393 const PAF_ASOT_Patchs *pQ,
394 PAF_ASOT_Config *pAsotCfg,
395 Int frame,
396 Int block
397 );
399 // Purpose: Decoding Function for terminating the decoding process.
400 Int
401 PAF_ASOT_decodeComplete(
402 const PAF_ASOT_Params *pP,
403 const PAF_ASOT_Patchs *pQ,
404 PAF_ASOT_Config *pAsotCfg,
405 ALG_Handle decAlg[],
406 Int frame,
407 Int block
408 );
410 // Purpose: Decoding Function for initiating output.
411 Int
412 PAF_ASOT_startOutput(
413 const PAF_ASOT_Params *pP,
414 const PAF_ASOT_Patchs *pQ,
415 PAF_ASOT_Config *pAsotCfg
416 );
418 // Purpose: Decoding Function for terminating output.
419 Int
420 PAF_ASOT_stopOutput(
421 const PAF_ASOT_Params *pP,
422 const PAF_ASOT_Patchs *pQ,
423 PAF_ASOT_Config *pAsotCfg
424 );
426 // Purpose: Decoding Function for re-initiating output.
427 Int
428 PAF_ASOT_setCheckRateX(
429 const PAF_ASOT_Params *pP,
430 const PAF_ASOT_Patchs *pQ,
431 PAF_ASOT_Config *pAsotCfg,
432 Int check
433 );
435 // Purpose: Common Function for processing algorithm chains.
436 Int
437 PAF_ASOT_streamChainFunction(
438 const PAF_ASOT_Params *pP,
439 const PAF_ASOT_Patchs *pQ,
440 PAF_ASOT_Config *pAsotCfg,
441 Int iChainFrameFxns,
442 Int abortOnError,
443 Int logArg
444 );
446 // Purpose: Decoding Function for determining whether processing of the
447 // current stream is complete.
448 Int
449 PAF_ASOT_decodeFinalTest(
450 const struct PAF_ASOT_Params *pP,
451 const struct PAF_ASOT_Patchs *pQ,
452 struct PAF_ASOT_Config *pAsotCfg,
453 Int frame,
454 Int block
455 );
457 #endif /* _ASOP_H_ */