From: Frank Livingston Date: Fri, 23 Jun 2017 00:18:52 +0000 (-0500) Subject: PASDK-218:Add CB statistics X-Git-Url: https://git.ti.com/gitweb?p=processor-sdk%2Fperformance-audio-sr.git;a=commitdiff_plain;h=e24e00ec4d34d856436bc4013ffc7b1c4302329f PASDK-218:Add CB statistics - readAfWriterInactiveCnt - wrtAfReaderInactiveCnt - wrtAfZeroSampsCnt --- diff --git a/pasdk/common/aspDecOpCircBuf_common.c b/pasdk/common/aspDecOpCircBuf_common.c index 8b69e794..39dc3128 100644 --- a/pasdk/common/aspDecOpCircBuf_common.c +++ b/pasdk/common/aspDecOpCircBuf_common.c @@ -105,7 +105,10 @@ Int cbReset( pAfCb->numPrivateMetadata = 0; } - // reset error counts + // reset stats + pCb->readAfWriterInactiveCnt = 0; + pCb->wrtAfReaderInactiveCnt = 0; + pCb->wrtAfZeroSampsCnt = 0; pCb->errUndCnt = 0; pCb->errOvrCnt = 0; diff --git a/pasdk/common/aspDecOpCircBuf_common.h b/pasdk/common/aspDecOpCircBuf_common.h index dd872ec4..cc4a7fc4 100644 --- a/pasdk/common/aspDecOpCircBuf_common.h +++ b/pasdk/common/aspDecOpCircBuf_common.h @@ -103,40 +103,43 @@ All rights reserved. // Decoder output circular buffer typedef struct PAF_AST_DecOpCircBuf { - PAF_AudioFrame *afCb; // audio frame CB - PAF_AudioData *pcmBuf; // PCM buffer, contains PCM data associated with audio frames - UInt8 *metaBuf; // metadata buffer, contains metadata associated with audio frames - Int8 sourceSel; // selected source - Int8 primedFlag; // flag indicated whether CB is primed: FALSE - CB not primed, TRUE - CB primed - Int16 targetNDSamps; // target CB Nominal Delay number of samples - Int16 deltaSamps; // number of 256 (N) sample output frames to block reader - Int8 afRdIdx; // audio frame CB read index - Int8 afWrtIdx; // audio frame CB write index - //Int8 afLagIdx; // audio frame CB Lag idx, - //Int8 afInitialLag; // Initial delay/lag between CB write and read - Int16 pcmRdIdx; // pcm buffer read index - Int8 numAfCb; // current number frames in CB - Int8 maxNumAfCb; // maximum number of audio frames in CB - Int16 decOpFrameLen; // selected decoder output frame length (input transaction size) - Int16 strFrameLen; // stream frame length (output transaction size) - Int8 writerActiveFlag; // flag indicates whether CB writer is active: FALSE - writer not active, TRUE - writer active - Int8 readerActiveFlag; // flag indicates whether CB reader is active: FALSE - reader not active, TRUE - reader active - Int8 drainFlag; // flag indicates whether reader should drain (empty) remaining frames in CB: FALSE - reader should not drain, TRUE - reader should drain - Int8 errUndCnt; // underflow count - Int8 errOvrCnt; // overflow count - PAF_AudioData *pcmBufEnd; // PCM buffer, contains PCM data associated with audio frames end - UInt8 *metaBufEnd; // metadata buffer, contains metadata associated with audio frames end - Int8 maxAFChanNum; // maximum number of audio data channels in audio frame - Int16 maxAFSampCount; // maximum number of sample counts in audio frame - PAF_AudioFrame lastAf; // used to store the last valid read out audio frame info to generate mute frame - #ifdef CB_RW_OP_CAP_PP // debug - UInt32 *cb_samples_op; // should be in shared memory, preferred NON cache - UInt8 *cb_op_owner; // should be in shared memory, preferred NON cache - UInt8 *cb_afRdIdx; // should be in shared memory, preferred NON cache - UInt8 *cb_afWrtIdx; // should be in shared memory, preferred NON cache - UInt8 *cb_numAfCb; // should be in shared memory, preferred NON cache - UInt32 cb_opCnt; // range (0 - CB_OP_COUNT_MAX) - #endif + PAF_AudioFrame *afCb; // audio frame CB + PAF_AudioData *pcmBuf; // PCM buffer, contains PCM data associated with audio frames + UInt8 *metaBuf; // metadata buffer, contains metadata associated with audio frames + Int8 sourceSel; // selected source + Int8 primedFlag; // flag indicated whether CB is primed: FALSE - CB not primed, TRUE - CB primed + Int16 targetNDSamps; // target CB Nominal Delay number of samples + Int16 deltaSamps; // number of 256 (N) sample output frames to block reader + Int8 afRdIdx; // audio frame CB read index + Int8 afWrtIdx; // audio frame CB write index + //Int8 afLagIdx; // audio frame CB Lag idx, + //Int8 afInitialLag; // Initial delay/lag between CB write and read + Int16 pcmRdIdx; // pcm buffer read index + Int8 numAfCb; // current number frames in CB + Int8 maxNumAfCb; // maximum number of audio frames in CB + Int16 decOpFrameLen; // selected decoder output frame length (input transaction size) + Int16 strFrameLen; // stream frame length (output transaction size) + Int8 writerActiveFlag; // flag indicates whether CB writer is active: FALSE - writer not active, TRUE - writer active + Int8 readerActiveFlag; // flag indicates whether CB reader is active: FALSE - reader not active, TRUE - reader active + Int8 drainFlag; // flag indicates whether reader should drain (empty) remaining frames in CB: FALSE - reader should not drain, TRUE - reader should drain + Int32 readAfWriterInactiveCnt; // count of read audio frames with inactive writer & not draining + Int32 wrtAfReaderInactiveCnt; // count of write audio frames with inactive reader + Int32 wrtAfZeroSampsCnt; // count of write audio frames with zero samples + Int32 errUndCnt; // read error underflow count + Int32 errOvrCnt; // write error overflow count + PAF_AudioData *pcmBufEnd; // PCM buffer, contains PCM data associated with audio frames end + UInt8 *metaBufEnd; // metadata buffer, contains metadata associated with audio frames end + Int8 maxAFChanNum; // maximum number of audio data channels in audio frame + Int16 maxAFSampCount; // maximum number of sample counts in audio frame + PAF_AudioFrame lastAf; // used to store the last valid read out audio frame info to generate mute frame +#ifdef CB_RW_OP_CAP_PP // debug + UInt32 *cb_samples_op; // should be in shared memory, preferred NON cache + UInt8 *cb_op_owner; // should be in shared memory, preferred NON cache + UInt8 *cb_afRdIdx; // should be in shared memory, preferred NON cache + UInt8 *cb_afWrtIdx; // should be in shared memory, preferred NON cache + UInt8 *cb_numAfCb; // should be in shared memory, preferred NON cache + UInt32 cb_opCnt; // range (0 - CB_OP_COUNT_MAX) +#endif } PAF_AST_DecOpCircBuf; // Decoder output circular buffer control diff --git a/pasdk/test_arm/framework/aspDecOpCircBuf_slave.c b/pasdk/test_arm/framework/aspDecOpCircBuf_slave.c index 1ed6f66f..d2f34413 100644 --- a/pasdk/test_arm/framework/aspDecOpCircBuf_slave.c +++ b/pasdk/test_arm/framework/aspDecOpCircBuf_slave.c @@ -210,242 +210,260 @@ Int cbWriteAf( //Log_info1("cbWriteAf:afCb=0x%04x", (IArg)pCb->afCb); // debug //Log_info2("cbWriteAf:pCb->readerActiveFlag=%d, pCb->writerActiveFlag=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->writerActiveFlag); // debug - if ((pCb->readerActiveFlag == 1) && (pAfWrt->sampleCount)) //QIN ? + if (pCb->readerActiveFlag == 1) { // // Normal case, reader active. - // If reader not active, don't write to circular buffer or check OVRflow. - -#if 0 - if (pCb->cbWriteAfInit == 0) + // + + if (pAfWrt->sampleCount != 0) { - // Invalidate AF circular buffer - Cache_inv(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0); - for (n=0; nmaxNumAfCb; n++) + //Log_info2("cbWriteAf:pCb->numAfCb=%d, pCb->maxNumAfCb=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->maxNumAfCb); // debug + + // check overflow + //while (pCb->numAfCb >= pCb->maxNumAfCb); // debug + if (pCb->numAfCb >= pCb->maxNumAfCb) { - pAfCb = &pCb->afCb[n]; - Cache_inv(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0); - } - Cache_wait(); + pCb->errOvrCnt++; - pCb->cbWriteAfInit = 1; - } -#endif + //SW_BREAKPOINT; + Log_info1("cbWriteAf: ERROR: overflow, numAfCb=%d", pCb->numAfCb); - //Log_info2("cbWriteAf:pCb->numAfCb=%d, pCb->maxNumAfCb=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->maxNumAfCb); // debug + // Write back circular buffer configuration + Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); - // check overflow - //while (pCb->numAfCb >= pCb->maxNumAfCb); // debug - if (pCb->numAfCb >= pCb->maxNumAfCb) - { - pCb->errOvrCnt++; + // Leave the gate + GateMP_leave(gateHandle, key); - //SW_BREAKPOINT; - Log_info1("cbWriteAf: ERROR: overflow, numAfCb=%d", pCb->numAfCb); + //Log_info2("cbWriteAf:gate leave, gateHandle=0x%04x, key=%d", (IArg)gateHandle, (IArg)key); // debug - // Write back circular buffer configuration - Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); + return ASP_DECOP_CB_WRITE_OVERFLOW; + } - // Leave the gate - GateMP_leave(gateHandle, key); + pAfCb = &pCb->afCb[pCb->afWrtIdx]; + pPcmBuf = pAfCb->data.sample[0]; + pMetaBuf = pAfCb->pafPrivateMetadata[0].pMdBuf; + if((pPcmBuf + (pAfWrt->sampleCount * pCb->maxAFChanNum )) > (pCb->pcmBufEnd)) + { + pPcmBuf = pCb->pcmBuf; + } - //Log_info2("cbWriteAf:gate leave, gateHandle=0x%04x, key=%d", (IArg)gateHandle, (IArg)key); // debug + for (i=0; imaxAFChanNum; i++) + { + pAfCb->data.sample[i] = pPcmBuf; + pPcmBuf += pAfWrt->sampleCount; + pAfCb->data.samsiz[i] = 0; + } + Cache_inv(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0); // FL: this is write back and invalidate?? + Cache_wait(); - return ASP_DECOP_CB_WRITE_OVERFLOW; - } + //for (i=0; imaxAFChanNum; i++){ + //} + for (i=0; ipafPrivateMetadata[i].offset = 0; + pAfCb->pafPrivateMetadata[i].size = 0; + pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf; + pMetaBuf += PAF_MAX_PRIVATE_MD_SZ; + } - pAfCb = &pCb->afCb[pCb->afWrtIdx]; - pPcmBuf = pAfCb->data.sample[0]; - pMetaBuf = pAfCb->pafPrivateMetadata[0].pMdBuf; - if((pPcmBuf + (pAfWrt->sampleCount * pCb->maxAFChanNum )) > (pCb->pcmBufEnd)) - { - pPcmBuf = pCb->pcmBuf; - } + nextWrtIdx = 0; + if ((pCb->afWrtIdx +1) >= pCb->maxNumAfCb) + { + //Log_info0("cbWriteAf: AF Wrap around **** "); + // next audio frame will be audio frame 0 + nextWrtIdx = 0; + } + else + { + // next audio frame will be current audio frame + 1 + nextWrtIdx = pCb->afWrtIdx + 1; + } - for (i=0; imaxAFChanNum; i++) - { - pAfCb->data.sample[i] = pPcmBuf; - pPcmBuf += pAfWrt->sampleCount; - pAfCb->data.samsiz[i] = 0; - } - Cache_inv(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0); // FL: this is write back and invalidate?? - Cache_wait(); + pAfCbNextAf = &pCb->afCb[nextWrtIdx]; // +1 or last AF if overflow + pAfCbNextAf->data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount];// pAfCb->data.sample[15] + (pAfCb->sampleCount * sizeof(PAF_AudioData)); + + // write audio frame information updated by decoder + pAfCb->sampleDecode = pAfWrt->sampleDecode; + PAF_PROCESS_COPY(pAfCb->sampleProcess, pAfWrt->sampleProcess); + pAfCb->sampleRate = pAfWrt->sampleRate; + pAfCb->sampleCount = pAfWrt->sampleCount; + pAfCb->channelConfigurationRequest = pAfWrt->channelConfigurationRequest; + pAfCb->channelConfigurationStream = pAfWrt->channelConfigurationStream; + // write metadata information updated by decoder + pAfCb->bsMetadata_type = pAfWrt->bsMetadata_type; /* non zero if metadata is attached. */ + pAfCb->pafBsMetadataUpdate = pAfWrt->pafBsMetadataUpdate; /* indicates whether bit-stream metadata update */ + pAfCb->numPrivateMetadata = pAfWrt->numPrivateMetadata; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */ + pAfCb->bsMetadata_offset = pAfWrt->bsMetadata_offset; /* offset into audio frame for change in bsMetadata_type field */ + // write PCM samples + streamMask = pAfWrt->fxns->channelMask(pAfWrt, pAfCb->channelConfigurationStream); + for (i = 0; i < pCb->maxAFChanNum; i++) + { + if ((streamMask >> i) & 0x1) + { + for (j = 0; j < pAfWrt->sampleCount; j++) + { + pAfCb->data.sample[i][j] = pAfWrt->data.sample[i][j]; + } - for (i=0; imaxAFChanNum; i++){ - } - for (i=0; ipafPrivateMetadata[i].offset = 0; - pAfCb->pafPrivateMetadata[i].size = 0; - pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf; - pMetaBuf += PAF_MAX_PRIVATE_MD_SZ; - } + pAfCb->data.samsiz[i] = pAfWrt->data.samsiz[i]; + } + } - nextWrtIdx = 0; - if ((pCb->afWrtIdx +1) >= pCb->maxNumAfCb) - { - //Log_info0("cbWriteAf: AF Wrap around **** "); - // next audio frame will be audio frame 0 - nextWrtIdx = 0; - }else{ - // next audio frame will be current audio frame + 1 - nextWrtIdx = pCb->afWrtIdx + 1; - } + #ifdef CB_RW_OP_CAP_PP // debug + if (pCb->cb_opCnt < CB_OP_COUNT_MAX) + { + if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL)) + { + // log sample count + pCb->cb_samples_op[pCb->cb_opCnt] = pAfWrt->sampleCount; + pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_W; + // log idxs + pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx; + pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx; + pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance + pCb->cb_opCnt++; + } + } + #endif - pAfCbNextAf = &pCb->afCb[nextWrtIdx]; // +1 or last AF if overflow - pAfCbNextAf->data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount];// pAfCb->data.sample[15] + (pAfCb->sampleCount * sizeof(PAF_AudioData)); - - // write audio frame information updated by decoder - pAfCb->sampleDecode = pAfWrt->sampleDecode; - PAF_PROCESS_COPY(pAfCb->sampleProcess, pAfWrt->sampleProcess); - pAfCb->sampleRate = pAfWrt->sampleRate; - pAfCb->sampleCount = pAfWrt->sampleCount; - pAfCb->channelConfigurationRequest = pAfWrt->channelConfigurationRequest; - pAfCb->channelConfigurationStream = pAfWrt->channelConfigurationStream; - // write metadata information updated by decoder - pAfCb->bsMetadata_type = pAfWrt->bsMetadata_type; /* non zero if metadata is attached. */ - pAfCb->pafBsMetadataUpdate = pAfWrt->pafBsMetadataUpdate; /* indicates whether bit-stream metadata update */ - pAfCb->numPrivateMetadata = pAfWrt->numPrivateMetadata; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */ - pAfCb->bsMetadata_offset = pAfWrt->bsMetadata_offset; /* offset into audio frame for change in bsMetadata_type field */ - // write PCM samples - streamMask = pAfWrt->fxns->channelMask(pAfWrt, pAfCb->channelConfigurationStream); - for (i = 0; i < pCb->maxAFChanNum; i++) - { - if ((streamMask >> i) & 0x1) + // prepare metadata buffer pointers according to the metadata and buffer sizes + for (i=0; i < pAfWrt->numPrivateMetadata; i++) { - for (j = 0; j < pAfWrt->sampleCount; j++) + UInt8 *nextMdBuf; + if(i == 0) + nextMdBuf = (pAfCb->pafPrivateMetadata[0].pMdBuf + pAfWrt->pafPrivateMetadata[0].size); + else + nextMdBuf = (pAfCb->pafPrivateMetadata[i-1].pMdBuf + pAfWrt->pafPrivateMetadata[i-1].size); + if(nextMdBuf >= pCb->metaBufEnd) // metadata buffer overflow { - pAfCb->data.sample[i][j] = pAfWrt->data.sample[i][j]; + pAfCb->pafPrivateMetadata[i].pMdBuf = pCb->metaBuf; } + else if(i != 0) + { + pAfCb->pafPrivateMetadata[i].pMdBuf = nextMdBuf; + } + Cache_inv(pAfCb->pafPrivateMetadata[i].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0); + } - pAfCb->data.samsiz[i] = pAfWrt->data.samsiz[i]; + // Write metadata to circular buffer + for (i = 0; i < pAfWrt->numPrivateMetadata; i++) // only copy numPrivateMetadata + { + pAfCb->pafPrivateMetadata[i].offset = pAfWrt->pafPrivateMetadata[i].offset; + pAfCb->pafPrivateMetadata[i].size = pAfWrt->pafPrivateMetadata[i].size; + memcpy(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].size); } - } - #ifdef CB_RW_OP_CAP_PP // debug - if (pCb->cb_opCnt < CB_OP_COUNT_MAX) - { - if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL)) + Cache_inv(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0); // FL: this is write back and invalidate?? + Cache_wait(); + for (i=0; inumPrivateMetadata; i++) // only write back numPrivateMetadata { - // log sample count - pCb->cb_samples_op[pCb->cb_opCnt] = pAfWrt->sampleCount; - pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_W; - // log idxs - pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx; - pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx; - pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance - pCb->cb_opCnt++; + //Log_info4("cbWriteAf: AF: %d nummd: %d offset: %d size: %d ", pCb->afWrtIdx, pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[i].offset, pAfCb->pafPrivateMetadata[i].size); + Cache_wb(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size, Cache_Type_ALLD, 0); + } + // update audio frame write index + pCb->afWrtIdx++; + if (pCb->afWrtIdx >= pCb->maxNumAfCb) + { + pCb->afWrtIdx = 0; } - } - #endif - // prepare metadata buffer pointers according to the metadata and buffer sizes - for (i=0; i < pAfWrt->numPrivateMetadata; i++) - { - UInt8 *nextMdBuf; - if(i == 0) - nextMdBuf = (pAfCb->pafPrivateMetadata[0].pMdBuf + pAfWrt->pafPrivateMetadata[0].size); + pCb->afCb[pCb->afWrtIdx].data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount]; + if(pAfWrt->numPrivateMetadata > 0) + { + pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].pMdBuf + pAfWrt->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].size; + } else - nextMdBuf = (pAfCb->pafPrivateMetadata[i-1].pMdBuf + pAfWrt->pafPrivateMetadata[i-1].size); - if(nextMdBuf >= pCb->metaBufEnd) // metadata buffer overflow { - pAfCb->pafPrivateMetadata[i].pMdBuf = pCb->metaBuf; + pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[0].pMdBuf; + Cache_wb(pCb->afCb , ASP_DECOP_CB_MAX_NUM_PCM_FRAMES*sizeof(PAF_AudioFrame *), Cache_Type_ALLD, 0); + Cache_wait(); } - else if(i != 0) + Cache_inv(pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0); + Cache_wait(); + // update number of audio frames in circular buffer + pCb->numAfCb++; + + // Update CB Lag index + //if (pCb->afLagIdx < pCb->afInitialLag) + //{ + // pCb->afLagIdx += 1; + //} + + // Update CB primed flag + // calculate number of delta samples before + if (pCb->primedFlag == 0) { - pAfCb->pafPrivateMetadata[i].pMdBuf = nextMdBuf; + pCb->primedFlag = 1; + + // Calculate number of output frames to block reader. + // This is sample count reader waits before allowed to actually read samples from the CB. + pCb->deltaSamps = (pCb->targetNDSamps - pAfWrt->sampleCount + (pCb->strFrameLen-1)) / pCb->strFrameLen * pCb->strFrameLen; + + // debug + //gSampleCountBuf[gPrimedFlagCnt] = pAfWrt->sampleCount; + //gCalcDeltaSampsBuf[gPrimedFlagCnt] = pCb->deltaSamps; + //if (gPrimedFlagCnt < 10) + // gPrimedFlagCnt++; } - Cache_inv(pAfCb->pafPrivateMetadata[i].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0); - } - - // Write metadata to circular buffer - for (i = 0; i < pAfWrt->numPrivateMetadata; i++) // only copy numPrivateMetadata - { - pAfCb->pafPrivateMetadata[i].offset = pAfWrt->pafPrivateMetadata[i].offset; - pAfCb->pafPrivateMetadata[i].size = pAfWrt->pafPrivateMetadata[i].size; - memcpy(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].size); - } - Cache_inv(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0); // FL: this is write back and invalidate?? - Cache_wait(); - for (i=0; inumPrivateMetadata; i++) // only write back numPrivateMetadata - { - //Log_info4("cbWriteAf: AF: %d nummd: %d offset: %d size: %d ", pCb->afWrtIdx, pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[i].offset, pAfCb->pafPrivateMetadata[i].size); - Cache_wb(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size, Cache_Type_ALLD, 0); - } - // update audio frame write index - pCb->afWrtIdx++; - if (pCb->afWrtIdx >= pCb->maxNumAfCb) - { - pCb->afWrtIdx = 0; - } + // Write back circular buffer configuration + Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); + // write back audio frame + Cache_wb(pAfCb, sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0); + Cache_wb(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0); + Cache_wb(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0); + Cache_wait(); + // write back PCM data + for (i = 0; i < pCb->maxAFChanNum; i++) + { + if ((streamMask >> i) & 0x1) + { + Cache_wb(pAfCb->data.sample[i], pAfWrt->sampleCount * sizeof(PAF_AudioData), Cache_Type_ALLD, 0); + } + } + Cache_wait(); - pCb->afCb[pCb->afWrtIdx].data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount]; - if(pAfWrt->numPrivateMetadata > 0) - { - pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].pMdBuf + pAfWrt->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].size; + { + static Uint8 toggleState = 0; + if (toggleState == 0) + GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99); + else + GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99); + toggleState = ~(toggleState); + } + Log_info3("wrote %d samples into AF %d sourceSel: %d", pAfCb->sampleCount, pCb->afWrtIdx, pCb->sourceSel); + Log_info4("CBWMETA num=%d size=%d offset=%d chrequest=0x%04x", pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[0].size, pAfCb->pafPrivateMetadata[0].offset, pAfCb->channelConfigurationRequest.full); } else { - pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[0].pMdBuf; - Cache_wb(pCb->afCb , ASP_DECOP_CB_MAX_NUM_PCM_FRAMES*sizeof(PAF_AudioFrame *), Cache_Type_ALLD, 0); + // + // Skip write in case of 0 sample count + // + + // writing audio frame w/ zero samples + // update stat + pCb->wrtAfZeroSampsCnt++; + + // Write back circular buffer configuration + Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); Cache_wait(); } - Cache_inv(pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0); - Cache_wait(); - // update number of audio frames in circular buffer - pCb->numAfCb++; - - // Update CB Lag index - //if (pCb->afLagIdx < pCb->afInitialLag) - //{ - // pCb->afLagIdx += 1; - //} + } + else if (pCb->readerActiveFlag == 0) + { + // + // Reader inactive, don't write to circular buffer or check OVRflow. + // - // Update CB primed flag - // calculate number of delta samples before - if (pCb->primedFlag == 0) - { - pCb->primedFlag = 1; - - // Calculate number of output frames to block reader. - // This is sample count reader waits before allowed to actually read samples from the CB. - pCb->deltaSamps = (pCb->targetNDSamps - pAfWrt->sampleCount + (pCb->strFrameLen-1)) / pCb->strFrameLen * pCb->strFrameLen; - - // debug - //gSampleCountBuf[gPrimedFlagCnt] = pAfWrt->sampleCount; - //gCalcDeltaSampsBuf[gPrimedFlagCnt] = pCb->deltaSamps; - //if (gPrimedFlagCnt < 10) - // gPrimedFlagCnt++; - } + // writing AF w/ inactive reader + // update stat + pCb->wrtAfReaderInactiveCnt++; // Write back circular buffer configuration Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); - // write back audio frame - Cache_wb(pAfCb, sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0); - Cache_wb(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0); - Cache_wb(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0); - Cache_wait(); - // write back PCM data - for (i = 0; i < pCb->maxAFChanNum; i++) - { - if ((streamMask >> i) & 0x1) - { - Cache_wb(pAfCb->data.sample[i], pAfWrt->sampleCount * sizeof(PAF_AudioData), Cache_Type_ALLD, 0); - } - } Cache_wait(); - - { - static Uint8 toggleState = 0; - if (toggleState == 0) - GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99); - else - GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99); - toggleState = ~(toggleState); - } - Log_info3("wrote %d samples into AF %d sourceSel: %d", pAfCb->sampleCount, pCb->afWrtIdx, pCb->sourceSel); - Log_info4("CBWMETA num=%d size=%d offset=%d chrequest=0x%04x", pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[0].size, pAfCb->pafPrivateMetadata[0].offset, pAfCb->channelConfigurationRequest.full); } // Leave the gate @@ -456,6 +474,7 @@ Int cbWriteAf( return ASP_DECOP_CB_SOK; } +#if 0 // Get next audio frame to write in circular buffer Int cbGetNextWriteAf( PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control @@ -490,3 +509,4 @@ Int cbGetNextWriteAf( return ASP_DECOP_CB_SOK; } +#endif diff --git a/pasdk/test_arm/framework/aspDecOpCircBuf_slave.h b/pasdk/test_arm/framework/aspDecOpCircBuf_slave.h index 4e4dbf14..766c3f54 100644 --- a/pasdk/test_arm/framework/aspDecOpCircBuf_slave.h +++ b/pasdk/test_arm/framework/aspDecOpCircBuf_slave.h @@ -61,11 +61,13 @@ Int cbWriteAf( PAF_AudioFrame *pAfWrt // audio frame from which to write ); +#if 0 // Get next audio frame to write in circular buffer Int cbGetNextWriteAf( PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control Int8 cbIdx, // decoder output circular buffer index PAF_AudioFrame **ppAfWrt // audio frame next to be written ); +#endif #endif /* _ASP_DECOP_CB_SLAVE_H_ */ diff --git a/pasdk/test_dsp/framework/aspDecOpCircBuf_master.c b/pasdk/test_dsp/framework/aspDecOpCircBuf_master.c index c00f5e3e..38b90f14 100644 --- a/pasdk/test_dsp/framework/aspDecOpCircBuf_master.c +++ b/pasdk/test_dsp/framework/aspDecOpCircBuf_master.c @@ -204,7 +204,10 @@ Int cbInit( pCb->readerActiveFlag = 0; pCb->drainFlag = 0; - // reset error counts + // reset stats + pCb->readAfWriterInactiveCnt = 0; + pCb->wrtAfReaderInactiveCnt = 0; + pCb->wrtAfZeroSampsCnt = 0; pCb->errUndCnt = 0; pCb->errOvrCnt = 0; @@ -251,7 +254,7 @@ Int cbInitSourceSel( Int8 sourceSelect, // source select (PCM, DDP, etc.) Int16 decOpFrameLen, // decoder output frame length (PCM samples) Int16 strFrameLen, // stream frame length (PCM samples) - Int8 resetRwFlags // whether to reset reader, writer, and empty flags + Int8 resetRwFlags // whether to reset reader, writer, and drain flags ) { IArg key; @@ -457,7 +460,10 @@ Int cbInitSourceSel( pCb->drainFlag = 0; } - // reset error counts + // reset stats + pCb->readAfWriterInactiveCnt = 0; + pCb->wrtAfReaderInactiveCnt = 0; + pCb->wrtAfZeroSampsCnt = 0; pCb->errUndCnt = 0; pCb->errOvrCnt = 0; @@ -592,10 +598,14 @@ Int cbReadAf( //Log_info1("cbReadAf:afCb=0x%04x", (IArg)pCb->afCb); // debug + // Check (writerActiveFlag,drainFlag)=(1,1) if ((pCb->writerActiveFlag == 1) && (pCb->drainFlag == 1)) { + // // This shouldn't occur: - // writer is active AND draining circular buffer + // writer is active AND draining circular buffer + // + //Log_info2("cbReadAf: ERROR: writerActiveFlag=%d, drainFlag=%d", pCb->writerActiveFlag, pCb->drainFlag); // FL: debug SW_BREAKPOINT; // FL: debug @@ -605,16 +615,24 @@ Int cbReadAf( return ASP_DECOP_CB_READ_INVSTATE; } + // Check (writerActiveFlag,drainFlag)=(0,0) //if (((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0)) || (pCb->afLagIdx < pCb->afInitialLag)) if ((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0)) { // - // No active writer, not draining circular buffer. + // Writer inactive, not draining circular buffer. // Skip UNDerflow check, mute output. // + + pCb->readAfWriterInactiveCnt++; + //cbReadAfMute(pAfRd, pCb->strFrameLen); cbReadMuteWithLastAfInfo(pCb, pAfRd); + // Write back circular buffer configuration. + Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); + // Leave the gate GateMP_leave(gateHandle, key); @@ -646,9 +664,9 @@ Int cbReadAf( return ASP_DECOP_CB_SOK; } - + // (writerActiveFlag,drainFlag)= (0,0) and (1,1) checked above // (writerActiveFlag,drainFlag)=(1,0) and (0,1) are left - // Here we are checking (1,0) state here + // Checking (writerActiveFlag,drainFlag)=(1,0) state here if (pCb->writerActiveFlag == 1) { // check underflow @@ -701,6 +719,8 @@ Int cbReadAf( } } + // Checking (writerActiveFlag,drainFlag)=(1,0) state above and here + // Checking (writerActiveFlag,drainFlag)=(0,1) state here if ((pCb->writerActiveFlag == 1) || (pCb->drainFlag == 1)) { // @@ -846,7 +866,7 @@ Int cbReadAf( { // // Writer inactive, but remaining frames in circular buffer. - // Update empty flag. + // Update drain flag. // if (pCb->numAfCb <= 0) { diff --git a/pasdk/test_dsp/framework/aspDecOpCircBuf_master.h b/pasdk/test_dsp/framework/aspDecOpCircBuf_master.h index fb224485..e06c5ff3 100644 --- a/pasdk/test_dsp/framework/aspDecOpCircBuf_master.h +++ b/pasdk/test_dsp/framework/aspDecOpCircBuf_master.h @@ -57,7 +57,7 @@ Int cbInitSourceSel( Int8 sourceSelect, // source select (PCM, DDP, etc.) Int16 decOpFrameLen, // decoder output frame length (PCM samples) Int16 strFrameLen, // stream frame length (PCM samples) - Int8 resetRwFlags // whether to reset reader, writer, and empty flags + Int8 resetRwFlags // whether to reset reader, writer, and drain flags ); // Start reads from circular buffer