e19652d08f52e03ae5a471177fc5d443bf6d6e0c
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 #include <string.h> // for memset()
37 #include <xdc/std.h>
38 #include <xdc/runtime/Log.h>
39 #include <ti/sysbios/hal/Cache.h>
40 #include <ti/uia/events/UIAEvt.h>
41 #include <ti/ipc/GateMP.h>
43 #include "common.h"
44 #include "paftyp.h"
45 #include "pafdec.h"
46 #include "aspDecOpCircBuf_master.h"
48 #include "evmc66x_gpio_dbg.h" // Debug
50 #ifdef CB_RW_OP_CAP_PP // debug
51 // Global variables
52 Uint32 *gCB_samples_op = NULL;
53 Uint8 *gCB_op_owner = NULL;
54 Uint32 *gCB_opCnt = 0;
55 Uint8 *gCB_afRdIdx = NULL;
56 Uint8 *gCB_afWrtIdx = NULL;
57 Uint8 *gCB_numAfCb = NULL;
58 #endif
60 #if 0
61 // Generate mute AF on circular buffer read
62 static Void cbReadAfMute(
63 PAF_AudioFrame *pAfRd, // audio frame into which to read
64 Int16 strFrameLen // stream frame length (output transaction size)
65 );
66 #endif
68 #if 0
69 // Init last audio frame configuration info
70 static Void cbInitLastAfInfo(
71 PAF_AudioFrame *pAfRd // last audio frame stored in CB instance
72 );
73 #endif
75 // Update last audio frame configuration info
76 static Void cbUpdateLastAfInfo(
77 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
78 PAF_AudioFrame *pAfUpd // audio frame used for update
79 );
81 // Generate mute AF on circular buffer read using the last AF configuration info
82 static Void cbReadMuteWithLastAfInfo(
83 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
84 PAF_AudioFrame *pAfRd // audio frame into which to read
85 );
87 #if 0 // FL: moved to common
88 // Initialize circular buffer control
89 Int cbCtlInit(
90 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
91 Int8 numCb, // number of circular buffers
92 PAF_AST_DecOpCircBuf **pXDecOpCb // address of decoder output circular buffer base pointer
93 )
94 {
95 GateMP_Params gateParams;
96 GateMP_Handle gateHandle;
98 GateMP_Params_init(&gateParams);
99 gateParams.localProtect = GateMP_LocalProtect_THREAD;
100 gateParams.remoteProtect = GateMP_RemoteProtect_SYSTEM;
101 gateParams.name = ASP_DECODE_CB_GATE_NAME;
102 gateParams.regionId = ASP_DECODE_CB_GATE_REGION_ID;
103 gateHandle = GateMP_create(&gateParams);
104 if (gateHandle != NULL)
105 {
106 pCbCtl->gateHandle = gateHandle;
107 }
108 else
109 {
110 pCbCtl->gateHandle = NULL;
111 return ASP_DECOP_CB_CTL_INIT_INV_GATE;
112 }
114 pCbCtl->numCb = numCb; // init number of circular buffers
115 pCbCtl->pXDecOpCb = pXDecOpCb; // init base address of circular buffers
117 return ASP_DECOP_CB_SOK;
118 }
119 #endif
121 // Initialize circular buffer
122 Int cbInit(
123 PAF_AST_DecOpCircBuf *pCb
124 )
125 {
126 #if 0 // FL: unused
127 PAF_AudioFrame *pAfCb;
128 PAF_AudioData *pPcmBuf;
129 UInt8 *pMetaBuf;
130 Int8 n;
131 Int8 i;
133 // set source select
134 pCb->sourceSel = DEF_SOURCE_SEL;
136 // set input frame length
137 pCb->decOpFrameLen = DEF_DEC_OP_FRAME_LEN;
139 // set output frame length
140 pCb->strFrameLen = DEF_STR_FRAME_LEN;
142 // initialize circular buffer maximum number of audio frames
143 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_THD; //ASP_DECOP_CB_MAX_NUM_AF_PCM;
144 pCb->afWrtIdx = ASP_DECOP_CB_INIT_LAG_PCM;
145 pCb->afRdIdx = 0;
146 pCb->pcmRdIdx = 0;
148 // Initialize CB primed flag
149 pCb->primedFlag = 0;
150 // Initialize delta samples
151 pCb->deltaSamps = 0;
153 // set default value to PCM configuration
154 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH;
155 pCb->maxAFSampCount = DEF_DEC_OP_FRAME_LEN;
156 // initialize audio frames
157 for (n=0; n<pCb->maxNumAfCb; n++)
158 {
159 pAfCb = &pCb->afCb[n];
160 pAfCb->sampleDecode = PAF_SOURCE_PCM;
161 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
162 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
163 pAfCb->sampleCount = DEF_DEC_OP_FRAME_LEN;
164 pAfCb->channelConfigurationRequest.full = 0;
165 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
166 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
167 pAfCb->channelConfigurationStream.full = 0;
168 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
169 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
170 }
172 // initialize circular buffer current number of frames
173 pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
175 // initialize audio frame PCM buffers
176 pPcmBuf = pCb->pcmBuf;
177 pMetaBuf = pCb->metaBuf;
178 for (n=0; n<pCb->maxNumAfCb; n++)
179 {
180 pAfCb = &pCb->afCb[n];
181 pAfCb->data.nChannels = ASP_DECOP_CB_MAX_NUM_PCM_CH;
182 pAfCb->data.nSamples = DEF_DEC_OP_FRAME_LEN;
183 for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
184 {
185 pAfCb->data.sample[i] = pPcmBuf;
186 memset(pAfCb->data.sample[i], 0, DEF_DEC_OP_FRAME_LEN);
187 pPcmBuf += DEF_DEC_OP_FRAME_LEN;
189 pAfCb->data.samsiz[i] = 0;
190 }
192 // write metadata information updated by decoder
193 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
194 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
195 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
196 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
198 // Initialize metadata buffers
199 for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
200 {
201 pAfCb->pafPrivateMetadata[i].offset = 0;
202 pAfCb->pafPrivateMetadata[i].size = 0;
203 pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
204 pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
205 }
206 }
208 // reset read/write flags
209 pCb->writerActiveFlag = 0;
210 pCb->readerActiveFlag = 0;
211 pCb->drainFlag = 0;
213 // reset stats
214 pCb->readAfWriterInactiveCnt = 0;
215 pCb->readAfNdCnt = 0;
216 pCb->wrtAfReaderInactiveCnt = 0;
217 pCb->wrtAfZeroSampsCnt = 0;
218 pCb->errUndCnt = 0;
219 pCb->errOvrCnt = 0;
221 #ifdef CB_RW_OP_CAP_PP // debug
222 // Get address in global variables
223 gCB_samples_op = pCb->cb_samples_op;
224 gCB_op_owner = pCb->cb_op_owner;
225 gCB_opCnt = &pCb->cb_opCnt;
226 gCB_afRdIdx = pCb->cb_afRdIdx;
227 gCB_afWrtIdx = pCb->cb_afWrtIdx;
228 gCB_numAfCb = pCb->cb_numAfCb;
229 #endif
231 cbInitLastAfInfo(&pCb->lastAf);
233 // Write back circular buffer configuration
234 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
235 // Write back AF circular buffer
236 Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
237 // Write back PCM data
238 for (n=0; n<pCb->maxNumAfCb; n++)
239 {
240 pAfCb = &pCb->afCb[n];
241 Cache_wb(pAfCb->data.samsiz, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
242 Cache_wb(pAfCb->data.sample, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
243 for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
244 {
245 Cache_wb(pAfCb->data.sample[i], DEF_DEC_OP_FRAME_LEN*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
246 }
247 }
248 Cache_wait();
249 #endif
251 // set source select
252 pCb->sourceSel = PAF_SOURCE_UNKNOWN;
254 #ifdef CB_RW_OP_CAP_PP // debug
255 // Get address in global variables
256 gCB_samples_op = pCb->cb_samples_op;
257 gCB_op_owner = pCb->cb_op_owner;
258 gCB_opCnt = &pCb->cb_opCnt;
259 gCB_afRdIdx = pCb->cb_afRdIdx;
260 gCB_afWrtIdx = pCb->cb_afWrtIdx;
261 gCB_numAfCb = pCb->cb_numAfCb;
262 #endif
264 // Write back circular buffer configuration
265 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
266 Cache_wait();
268 return ASP_DECOP_CB_SOK;
269 }
271 #if 0 // FL: moved to ARM
272 // debug
273 //Int8 gCbInitSourceSelCnt=0;
274 //Int8 gCbInitSourceSelThdCnt=0;
276 // Initialize circular buffer based on selected source
277 Int cbInitSourceSel(
278 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
279 Int8 cbIdx, // decoder output circular buffer index
280 Int8 sourceSelect, // source select (PCM, DDP, etc.)
281 Int16 decOpFrameLen, // decoder output frame length (PCM samples)
282 Int16 strFrameLen, // stream frame length (PCM samples)
283 Int8 resetRwFlags // whether to reset reader, writer, and drain flags
284 )
285 {
286 IArg key;
287 GateMP_Handle gateHandle;
288 PAF_AST_DecOpCircBuf *pCb;
289 PAF_AudioFrame *pAfCb;
290 PAF_AudioData *pPcmBuf;
291 UInt8 *pMetaBuf;
292 Int8 n;
293 Int8 i;
295 //gCbInitSourceSelCnt++; // debug
297 // Get gate handle
298 gateHandle = pCbCtl->gateHandle;
299 // Enter gate
300 key = GateMP_enter(gateHandle);
302 // Get circular buffer base pointer
303 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
305 // Invalidate circular buffer configuration
306 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
307 Cache_wait();
309 //Log_info1("cbInitSourceSel:afCb=0x%04x", (IArg)pCb->afCb); // debug
311 // set source select
312 pCb->sourceSel = sourceSelect;
314 // set input frame length
315 pCb->decOpFrameLen = decOpFrameLen;
317 // set output frame length
318 pCb->strFrameLen = strFrameLen;
320 //pCb->afInitialLag = 0; // default No lag
321 //pCb->afLagIdx = 0;
322 // Initialize CB primed flag
323 pCb->primedFlag = 0;
324 // Initialize delta samples
325 pCb->deltaSamps = 0;
327 // initialize circular buffer maximum number of audio frames
328 if (sourceSelect == PAF_SOURCE_PCM)
329 {
330 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_PCM;
332 //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_PCM;
333 // Initialize target nominal delay
334 pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kPCM;
336 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM;
337 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_PCM;
338 pCb->pcmRdIdx = 0;
340 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH;
341 pCb->maxAFSampCount = DEF_DEC_OP_FRAME_LEN;
343 // initialize audio frames
344 for (n=0; n<pCb->maxNumAfCb; n++)
345 {
346 pAfCb = &pCb->afCb[n];
347 pAfCb->sampleDecode = sourceSelect;
348 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
349 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
350 pAfCb->sampleCount = decOpFrameLen;
351 pAfCb->channelConfigurationRequest.full = 0;
352 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
353 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
354 pAfCb->channelConfigurationStream.full = 0;
355 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
356 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
358 // write metadata information updated by decoder
359 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
360 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
361 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
362 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
363 }
364 }
365 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
366 {
367 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_DDP;
369 //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_DDP;
370 // Initialize target nominal delay
371 pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kDDP;
373 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP;
374 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DDP;
375 pCb->pcmRdIdx = 0;
377 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH_DDP;
378 pCb->maxAFSampCount = ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kDDP;
380 // initialize audio frames
381 for (n=0; n<pCb->maxNumAfCb; n++)
382 {
383 pAfCb = &pCb->afCb[n];
384 pAfCb->sampleDecode = sourceSelect;
385 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
386 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
387 pAfCb->sampleCount = decOpFrameLen;
388 pAfCb->channelConfigurationRequest.full = 0;
389 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
390 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
391 pAfCb->channelConfigurationStream.full = 0;
392 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
393 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
395 // write metadata information updated by decoder
396 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
397 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
398 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
399 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
400 }
401 }
402 else if (sourceSelect == PAF_SOURCE_THD)
403 {
404 //gCbInitSourceSelThdCnt++; //debug
406 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_THD;
408 //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_THD;
409 // Initialize target nominal delay
410 pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD;
412 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_THD;
413 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_THD;
414 pCb->pcmRdIdx = 0;
416 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT;
417 pCb->maxAFSampCount = ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT;
419 // initialize audio frames
420 for (n=0; n<pCb->maxNumAfCb; n++)
421 {
422 pAfCb = &pCb->afCb[n];
423 pAfCb->sampleDecode = sourceSelect;
424 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
425 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
426 pAfCb->sampleCount = decOpFrameLen;
427 pAfCb->channelConfigurationRequest.full = 0;
428 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
429 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
430 pAfCb->channelConfigurationStream.full = 0;
431 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
432 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
434 // write metadata information updated by decoder
435 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
436 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
437 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
438 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
439 }
440 }
441 else
442 {
443 SW_BREAKPOINT;
445 // Leave the gate
446 GateMP_leave(gateHandle, key);
448 return ASP_DECOP_CB_INIT_INV_SOURCE_SEL;
449 }
451 // initialize circular buffer current number of frames
452 pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
454 // initialize audio frame PCM buffers
455 pPcmBuf = pCb->pcmBuf;
456 pMetaBuf = pCb->metaBuf;
457 for (n=0; n<pCb->maxNumAfCb; n++)
458 {
459 pAfCb = &pCb->afCb[n];
460 pAfCb->data.nChannels = pCb->maxAFChanNum;
461 pAfCb->data.nSamples = decOpFrameLen;
462 for (i=0; i<pCb->maxAFChanNum; i++)
463 {
464 pAfCb->data.sample[i] = pPcmBuf;
465 memset(pAfCb->data.sample[i], 0, pCb->maxAFSampCount);
466 pPcmBuf += pCb->maxAFSampCount;
468 pAfCb->data.samsiz[i] = 0;
469 }
471 // Initialize metadata buffers
472 for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
473 {
474 pAfCb->pafPrivateMetadata[i].offset = 0;
475 pAfCb->pafPrivateMetadata[i].size = 0;
476 pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
477 pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
478 }
479 }
481 // reset read/write flags
482 if (resetRwFlags)
483 {
484 pCb->writerActiveFlag = 0;
485 pCb->readerActiveFlag = 0;
486 pCb->drainFlag = 0;
487 }
489 // reset stats
490 pCb->readAfWriterInactiveCnt = 0;
491 pCb->readAfNdCnt = 0;
492 pCb->wrtAfReaderInactiveCnt = 0;
493 pCb->wrtAfZeroSampsCnt = 0;
494 pCb->errUndCnt = 0;
495 pCb->errOvrCnt = 0;
497 // Write back circular buffer configuration
498 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
499 // Write back AF circular buffer
500 Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
501 // Write back PCM data
502 for (n=0; n<pCb->maxNumAfCb; n++)
503 {
504 pAfCb = &pCb->afCb[n];
505 Cache_wb(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
506 Cache_wb(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
507 for (i=0; i<pCb->maxAFChanNum; i++)
508 {
509 Cache_wb(pAfCb->data.sample[i], pCb->maxAFSampCount*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
510 }
511 }
512 Cache_wait();
514 // Leave the gate
515 GateMP_leave(gateHandle, key);
517 return ASP_DECOP_CB_SOK;
518 }
519 #endif
521 // Initialize circular buffer for Stream reads
522 Int cbInitStreamRead(
523 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
524 Int8 cbIdx, // decoder output circular buffer index
525 Int16 strFrameLen // stream frame length (PCM samples)
526 )
527 {
528 IArg key;
529 GateMP_Handle gateHandle;
530 PAF_AST_DecOpCircBuf *pCb;
532 // Get gate handle
533 gateHandle = pCbCtl->gateHandle;
534 // Enter gate
535 key = GateMP_enter(gateHandle);
537 // Get circular buffer base pointer
538 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
540 // Invalidate circular buffer configuration
541 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
542 Cache_wait();
544 // Set output frame length
545 pCb->strFrameLen = strFrameLen;
547 // Write back circular buffer configuration
548 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
549 Cache_wait();
551 // Leave the gate
552 GateMP_leave(gateHandle, key);
554 //return ret;
555 return ASP_DECOP_CB_SOK;
556 }
558 // Start reads from circular buffer
559 Int cbReadStart(
560 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
561 Int8 cbIdx // decoder output circular buffer index
562 )
563 {
564 IArg key;
565 GateMP_Handle gateHandle;
566 PAF_AST_DecOpCircBuf *pCb;
568 // Get gate handle
569 gateHandle = pCbCtl->gateHandle;
570 // Enter gate
571 key = GateMP_enter(gateHandle);
573 // Get circular buffer base pointer
574 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
576 // Invalidate circular buffer configuration
577 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
578 Cache_wait();
580 //Log_info1("cbReadStart:afCb=0x%04x", (IArg)pCb->afCb); // debug
582 // update flags
583 pCb->readerActiveFlag = 1;
585 // Write back circular buffer configuration
586 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
587 Cache_wait();
589 // Leave the gate
590 GateMP_leave(gateHandle, key);
592 return ASP_DECOP_CB_SOK;
593 }
595 // Stop reads from circular buffer
596 Int cbReadStop(
597 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
598 Int8 cbIdx // decoder output circular buffer index
599 )
600 {
601 IArg key;
602 GateMP_Handle gateHandle;
603 PAF_AST_DecOpCircBuf *pCb;
605 // Get gate handle
606 gateHandle = pCbCtl->gateHandle;
607 // Enter gate
608 key = GateMP_enter(gateHandle);
610 // Get circular buffer base pointer
611 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
613 // Invalidate circular buffer configuration
614 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
615 Cache_wait();
617 //Log_info1("cbReadStop:afCb=0x%04x", (IArg)pCb->afCb); // debug
619 // update flags
620 pCb->readerActiveFlag = 0;
622 // Write back circular buffer configuration
623 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
624 Cache_wait();
626 // Leave the gate
627 GateMP_leave(gateHandle, key);
629 return ASP_DECOP_CB_SOK;
630 }
632 // debug
633 //Int16 gDeltaSampsBuf[20];
634 //Int8 gDeltaSampsBufIdx=0;
636 // Read audio frame from circular buffer
637 Int cbReadAf(
638 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
639 Int8 cbIdx, // decoder output circular buffer index
640 PAF_AudioFrame *pAfRd // audio frame into which to read
641 )
642 {
643 IArg key;
644 GateMP_Handle gateHandle;
645 PAF_AST_DecOpCircBuf *pCb;
646 PAF_AudioFrame *pAfCb;
647 PAF_ChannelMask_HD streamMask;
648 Int8 i;
649 Int16 j;
650 Int8 numMetadata = 0;
652 // Get gate handle
653 gateHandle = pCbCtl->gateHandle;
654 // Enter gate
655 key = GateMP_enter(gateHandle);
657 // Get circular buffer base pointer
658 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
660 // Invalidate circular buffer configuration.
661 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
662 Cache_wait();
664 //Log_info1("cbReadAf:afCb=0x%04x", (IArg)pCb->afCb); // debug
666 // Check (writerActiveFlag,drainFlag)=(1,1)
667 if ((pCb->writerActiveFlag == 1) && (pCb->drainFlag == 1))
668 {
669 //
670 // This shouldn't occur:
671 // writer is active AND draining circular buffer
672 //
674 //Log_info2("cbReadAf: ERROR: writerActiveFlag=%d, drainFlag=%d", pCb->writerActiveFlag, pCb->drainFlag); // FL: debug
675 SW_BREAKPOINT; // FL: debug
677 // Leave the gate
678 GateMP_leave(gateHandle, key);
680 return ASP_DECOP_CB_READ_INVSTATE;
681 }
683 // Check (writerActiveFlag,drainFlag)=(0,0)
684 //if (((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0)) || (pCb->afLagIdx < pCb->afInitialLag))
685 if ((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0))
686 {
687 //
688 // Writer inactive, not draining circular buffer.
689 // Skip UNDerflow check, mute output.
690 //
692 pCb->readAfWriterInactiveCnt++;
694 //cbReadAfMute(pAfRd, pCb->strFrameLen);
695 cbReadMuteWithLastAfInfo(pCb, pAfRd);
697 // Write back circular buffer configuration.
698 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
699 Cache_wait();
701 // Leave the gate
702 GateMP_leave(gateHandle, key);
704 return ASP_DECOP_CB_SOK;
705 }
707 //if ((pCb->primedFlag == 0) || ((pCb->primedFlag==1) && (pCb->deltaSamps > 0))
708 if ((pCb->primedFlag == 0) || (pCb->deltaSamps > 0))
709 {
710 pCb->readAfNdCnt++;
712 if (pCb->primedFlag == 1)
713 {
714 pCb->deltaSamps = pCb->deltaSamps - pCb->strFrameLen;
716 // debug
717 //gDeltaSampsBuf[gDeltaSampsBufIdx] = pCb->deltaSamps;
718 //if (gDeltaSampsBufIdx < 20)
719 // gDeltaSampsBufIdx++;
720 }
722 cbReadMuteWithLastAfInfo(pCb, pAfRd);
724 // Write back circular buffer configuration.
725 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
726 Cache_wait();
728 // Leave the gate
729 GateMP_leave(gateHandle, key);
731 return ASP_DECOP_CB_SOK;
732 }
734 // (writerActiveFlag,drainFlag)= (0,0) and (1,1) checked above
735 // (writerActiveFlag,drainFlag)=(1,0) and (0,1) are left
736 // Checking (writerActiveFlag,drainFlag)=(1,0) state here
737 if (pCb->writerActiveFlag == 1)
738 {
739 // check underflow
740 if (pCb->numAfCb <= 0)
741 {
742 //
743 // Increment underflow count.
744 // Mute output on underflow.
745 //
746 pCb->errUndCnt++;
747 //cbReadAfMute(pAfRd, pCb->strFrameLen);
748 cbReadMuteWithLastAfInfo(pCb, pAfRd);
749 //SW_BREAKPOINT; // FL: debug
751 #if 0 // (***) FL: shows timing of CB underflow
752 // debug
753 {
754 static Uint8 toggleState = 0;
755 if (toggleState == 0)
756 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
757 else
758 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
759 toggleState = ~(toggleState);
760 }
761 #endif
763 #ifdef CB_RW_OP_CAP_PP // debug
764 if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
765 {
766 if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL))
767 {
768 // log sample count
769 pCb->cb_samples_op[pCb->cb_opCnt] = 0; // due to underflow
770 pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_R;
771 // log idxs
772 pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx;
773 pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx;
774 pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance
775 pCb->cb_opCnt++;
776 }
777 }
778 #endif
780 // Write back circular buffer configuration.
781 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
782 Cache_wait();
784 // Leave the gate
785 GateMP_leave(gateHandle, key);
787 return ASP_DECOP_CB_READ_UNDERFLOW;
788 }
789 }
791 // Checking (writerActiveFlag,drainFlag)=(1,0) state above and here
792 // Checking (writerActiveFlag,drainFlag)=(0,1) state here
793 if ((pCb->writerActiveFlag == 1) || (pCb->drainFlag == 1))
794 {
795 //
796 // Writer active or draining remaining frames in circular buffer.
797 // Get next output audio frame.
798 //
800 // get pointer to current audio frame in circular buffer
801 pAfCb = &pCb->afCb[pCb->afRdIdx];
803 // Invalidate audio frame
804 Cache_inv(pAfCb, sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
805 Cache_inv(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
806 for (i=0; i<pAfCb->numPrivateMetadata; i++) // only invalidate numPrivateMetadata
807 {
808 Cache_inv(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size, Cache_Type_ALLD, 0); // only update metadata package size
809 }
810 Cache_wait();
812 // compute stream mask
813 streamMask = pAfRd->fxns->channelMask(pAfRd, pAfCb->channelConfigurationStream);
815 // Invalidate channel pointers
816 Cache_inv(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
817 Cache_wait();
819 // Invalidate PCM data
820 for (i = 0; i < pCb->maxAFChanNum; i++)
821 {
822 if ((streamMask >> i) & 0x1)
823 {
824 Cache_inv(&pAfCb->data.sample[i][pCb->pcmRdIdx], pCb->strFrameLen*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
825 }
826 }
827 Cache_wait();
829 // read audio frame information updated by decoder
830 pAfRd->sampleDecode = pAfCb->sampleDecode;
831 PAF_PROCESS_COPY(pAfRd->sampleProcess, pAfCb->sampleProcess);
832 pAfRd->sampleRate = pAfCb->sampleRate;
833 pAfRd->sampleCount = pCb->strFrameLen;
834 pAfRd->channelConfigurationRequest = pAfCb->channelConfigurationRequest;
835 pAfRd->channelConfigurationStream = pAfCb->channelConfigurationStream;
837 // read metadata information updated by decoder
838 pAfRd->bsMetadata_type = pAfCb->bsMetadata_type; /* non zero if metadata is attached. */
839 pAfRd->pafBsMetadataUpdate = pAfCb->pafBsMetadataUpdate; /* indicates whether bit-stream metadata update */
840 pAfRd->numPrivateMetadata = pAfCb->numPrivateMetadata; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
841 pAfRd->bsMetadata_offset = pAfCb->bsMetadata_offset; /* offset into audio frame for change in bsMetadata_type field */
843 #ifdef CB_RW_OP_CAP_PP // debug
844 if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
845 {
846 if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL))
847 {
848 // log sample count
849 pCb->cb_samples_op[pCb->cb_opCnt] = pAfRd->sampleCount;
850 pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_R;
851 // log idxs
852 pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx;
853 pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx;
854 pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance
855 pCb->cb_opCnt++;
856 }
857 }
858 #endif
860 //// update Last Cb info as per actual stream
861 //pCb->lastAf.sampleCount = pCb->strFrameLen; // FL: last AF sample count isn't used (see cbReadMuteWithLastAfInfo())
862 //pCb->lastAf.sampleRate = pAfCb->sampleRate; // FL: moved inside cbUpdateLastAfInfo() along with other params from memcpy below
863 // Update last audio frame configuration info
864 cbUpdateLastAfInfo(pCb, pAfRd);
866 // read PCM samples
867 for (i = 0; i < pCb->maxAFChanNum; i++)
868 {
869 if ((streamMask >> i) & 0x1)
870 {
871 for (j = 0; j < pCb->strFrameLen; j++)
872 {
873 pAfRd->data.sample[i][j] = pAfCb->data.sample[i][pCb->pcmRdIdx+j];
874 }
876 pAfRd->data.samsiz[i] = pAfCb->data.samsiz[i];
877 }
878 }
880 for (i = 0; i < PAF_MAX_NUM_PRIVATE_MD; i++)
881 {
882 pAfRd->pafPrivateMetadata[i].offset = 0;
883 pAfRd->pafPrivateMetadata[i].size = 0;
884 }
886 // read metadata
887 for (i = 0; i < pAfCb->numPrivateMetadata; i++) // only read numPrivateMetadata
888 {
889 if ((pAfCb->pafPrivateMetadata[i].offset >= pCb->pcmRdIdx)
890 &&(pAfCb->pafPrivateMetadata[i].offset < (pCb->pcmRdIdx + pCb->strFrameLen))
891 &&(pAfCb->pafPrivateMetadata[i].size))
892 {
893 // the offset is adjusted for segment [pCb->pcmRdIdx, (pCb->pcmRdIdx + pCb->pafFrameLen)]
894 pAfRd->pafPrivateMetadata[numMetadata].offset = pAfCb->pafPrivateMetadata[i].offset - pCb->pcmRdIdx;
895 pAfRd->pafPrivateMetadata[numMetadata].size = pAfCb->pafPrivateMetadata[i].size;
896 memcpy(pAfRd->pafPrivateMetadata[numMetadata].pMdBuf, pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size);
897 numMetadata++; //number of metadata associated with current 256 segment of audio samples
898 }
899 else //reset un-used buf
900 {
901 pAfRd->pafPrivateMetadata[i].offset = 0;
902 pAfRd->pafPrivateMetadata[i].size = 0;
903 }
905 }
906 pAfRd->numPrivateMetadata = numMetadata; //number of metadata associated with current 256 segment of audio samples
908 pCb->pcmRdIdx += pCb->strFrameLen; // update PCM read index
909 if (pCb->pcmRdIdx >= pAfCb->sampleCount)
910 {
911 // update audio frame read index
912 pCb->afRdIdx++;
913 if (pCb->afRdIdx >= pCb->maxNumAfCb)
914 {
915 pCb->afRdIdx = 0;
916 }
918 // update PCM read index
919 pCb->pcmRdIdx = 0;
921 // update number of audio frames in circular buffer
922 pCb->numAfCb--;
923 }
925 // FL: this update of Last AF is handled above
926 //memcpy (&pCb->lastAf, pAfRd, sizeof(PAF_AudioFrame));
928 #if 0 // (***) FL: shows timing of successful CB read
929 {
930 static Uint8 toggleState = 0;
931 if (toggleState == 0)
932 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
933 else
934 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
935 toggleState = ~(toggleState);
936 }
937 #endif
938 }
940 if (pCb->drainFlag == 1)
941 {
942 //
943 // Writer inactive, but remaining frames in circular buffer.
944 // Update drain flag.
945 //
946 if (pCb->numAfCb <= 0)
947 {
948 pCb->drainFlag = 0;
949 }
950 }
952 // Write back circular buffer configuration.
953 // NOTE: Probably only a subset of this information needs to be updated.
954 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
955 Cache_wait();
957 // Leave the gate
958 GateMP_leave(gateHandle, key);
960 return ASP_DECOP_CB_SOK;
961 }
963 #if 0
964 // Generate mute AF on circular buffer read
965 static Void cbReadAfMute(
966 PAF_AudioFrame *pAfRd, // audio frame into which to read
967 Int16 strFrameLen // stream frame length (output transaction size)
968 )
969 {
970 PAF_ChannelMask_HD streamMask;
971 Int8 i;
973 pAfRd->sampleDecode = PAF_SOURCE_PCM;
974 PAF_PROCESS_ZERO(pAfRd->sampleProcess);
975 pAfRd->sampleRate = PAF_SAMPLERATE_48000HZ;
976 pAfRd->sampleCount = strFrameLen;
977 pAfRd->channelConfigurationRequest.full = 0;
978 pAfRd->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
979 pAfRd->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
980 pAfRd->channelConfigurationStream.full = 0;
981 pAfRd->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
982 pAfRd->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
984 // compute stream mask
985 streamMask = pAfRd->fxns->channelMask(pAfRd, pAfRd->channelConfigurationStream);
986 // Clear PCM data
987 for (i = 0; i < ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
988 {
989 if ((streamMask >> i) & 0x1)
990 {
991 memset(pAfRd->data.sample[i], 0, strFrameLen*sizeof(PAF_AudioData));
992 }
993 pAfRd->data.samsiz[i] = 0;
994 }
995 // write metadata information updated by decoder
996 pAfRd->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
997 pAfRd->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
998 pAfRd->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
999 pAfRd->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
1000 }
1001 #endif
1003 #if 0 // FL: unused
1004 // Init last audio frame configuration info
1005 static Void cbInitLastAfInfo(
1006 PAF_AudioFrame *pAfRd // last audio frame stored in CB instance
1007 )
1008 {
1009 pAfRd->sampleDecode = PAF_SOURCE_PCM;
1010 PAF_PROCESS_ZERO(pAfRd->sampleProcess);
1011 pAfRd->sampleRate = PAF_SAMPLERATE_48000HZ;
1012 pAfRd->sampleCount = DEF_DEC_OP_FRAME_LEN;
1013 pAfRd->channelConfigurationRequest.full = 0;
1014 pAfRd->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
1015 pAfRd->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
1016 pAfRd->channelConfigurationStream.full = 0;
1017 pAfRd->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
1018 pAfRd->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
1020 pAfRd->bsMetadata_type = PAF_bsMetadata_none; /* non zero if metadata is attached. */
1021 pAfRd->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
1022 pAfRd->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
1023 pAfRd->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
1024 }
1025 #endif
1027 // Update last audio frame configuration info
1028 static Void cbUpdateLastAfInfo(
1029 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
1030 PAF_AudioFrame *pAfUpd // audio frame used for update
1031 )
1032 {
1033 // FL: full copy shouldn't be necessary
1034 // Note currently (data.nChannels, data.nSamples)=(32,256) is fixed in ASOT stream AF.
1035 // There parameters aren't copied from CB on CB read.
1036 //memcpy (&pCb->lastAf, pAfUpd, sizeof(PAF_AudioFrame));
1038 // These are parameters used in cbReadMuteWithLastAfInfo()
1039 pCb->lastAf.sampleDecode = pAfUpd->sampleDecode;
1040 pCb->lastAf.sampleRate = pAfUpd->sampleRate;
1041 pCb->lastAf.channelConfigurationRequest.full = pAfUpd->channelConfigurationRequest.full;
1042 pCb->lastAf.channelConfigurationStream.full = pAfUpd->channelConfigurationStream.full;
1043 }
1045 // Generate mute AF on circular buffer read using the last AF configuration info
1046 static Void cbReadMuteWithLastAfInfo(
1047 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
1048 PAF_AudioFrame *pAfRd // audio frame into which to read
1049 )
1050 {
1051 PAF_ChannelMask_HD streamMask;
1052 Int8 i;
1054 pAfRd->sampleDecode = pCb->lastAf.sampleDecode;
1055 PAF_PROCESS_ZERO(pAfRd->sampleProcess);
1056 pAfRd->sampleRate = pCb->lastAf.sampleRate;
1057 pAfRd->sampleCount = pCb->strFrameLen;
1058 pAfRd->channelConfigurationRequest.full = pCb->lastAf.channelConfigurationRequest.full;
1059 //pAfRd->channelConfigurationRequest.part.sat = pCb->lastAf.channelConfigurationRequest.part.sat; // FL: not necessary since full in union already copied
1060 //pAfRd->channelConfigurationRequest.part.sub = pCb->lastAf.channelConfigurationRequest.part.sub;
1061 pAfRd->channelConfigurationStream.full = pCb->lastAf.channelConfigurationStream.full;
1062 //pAfRd->channelConfigurationStream.part.sat = pCb->lastAf.channelConfigurationStream.part.sat;
1063 //pAfRd->channelConfigurationStream.part.sub = pCb->lastAf.channelConfigurationStream.part.sub;
1065 // compute stream mask
1066 streamMask = pAfRd->fxns->channelMask(pAfRd, pAfRd->channelConfigurationStream);
1067 // Clear PCM data
1068 for (i = 0; i < ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
1069 {
1070 if ((streamMask >> i) & 0x1)
1071 {
1072 memset(pAfRd->data.sample[i], 0, pAfRd->sampleCount*sizeof(PAF_AudioData));
1073 }
1074 pAfRd->data.samsiz[i] = 0;
1075 }
1076 pAfRd->bsMetadata_type = PAF_bsMetadata_none; /* non zero if metadata is attached. */
1077 pAfRd->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
1078 pAfRd->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
1079 pAfRd->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
1080 }
1082 // Check circular buffer drain state
1083 Int cbCheckDrainState(
1084 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
1085 Int8 cbIdx, // decoder output circular buffer index, or indicator combined drain state desired
1086 Int8 *pDrainedFlag // output drain state indicator (combined or for selected circular buffer)
1087 )
1088 {
1089 IArg key;
1090 GateMP_Handle gateHandle;
1091 PAF_AST_DecOpCircBuf *pCb;
1092 Int8 drainedFlag;
1093 Int8 i;
1095 // Get gate handle
1096 gateHandle = pCbCtl->gateHandle;
1097 // Enter gate
1098 key = GateMP_enter(gateHandle);
1100 if (cbIdx != ASP_DECOP_CHECK_DRAINSTATE_ALL)
1101 {
1102 //
1103 // Check drain state for selected circular buffer
1104 //
1106 // Get circular buffer base pointer
1107 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
1109 // Invalidate circular buffer configuration
1110 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
1111 Cache_wait();
1113 drainedFlag = !pCb->writerActiveFlag && !pCb->drainFlag;
1114 }
1115 else
1116 {
1117 //
1118 // Check combined drain state for all circular buffers.
1119 // Combined drain state is logical AND of drain state for all circular buffers.
1120 //
1122 drainedFlag = 1; // init combined drained flag to TRUE
1123 for (i = 0; i < pCbCtl->numDecOpCb; i++)
1124 {
1125 // Get circular buffer base pointer
1126 pCb = &((*pCbCtl->pXDecOpCb)[i]);
1128 // Invalidate circular buffer configuration
1129 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
1130 Cache_wait();
1132 // Update combined drain state
1133 drainedFlag = drainedFlag && (!pCb->writerActiveFlag && !pCb->drainFlag);
1134 }
1135 }
1137 *pDrainedFlag = drainedFlag;
1139 // Leave the gate
1140 GateMP_leave(gateHandle, key);
1142 return ASP_DECOP_CB_SOK;
1143 }