diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-07-31 16:36:09 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-07-31 16:36:09 -0600 |
commit | 753c87342ecb63da03961944f13bd80d897a45d8 (patch) | |
tree | e22d11b966d50315aae625bd499c049a83d15309 /apps | |
parent | 46d2d7391d973f805d633c1a112ad37cc4ec1f78 (diff) | |
download | px4-nuttx-753c87342ecb63da03961944f13bd80d897a45d8.tar.gz px4-nuttx-753c87342ecb63da03961944f13bd80d897a45d8.tar.bz2 px4-nuttx-753c87342ecb63da03961944f13bd80d897a45d8.zip |
Audio: Change how the end of the audio stream is detected by the leaf audio component. This used by be done by looking for the first partial buffer. That does not work with the in-place sub-sampling performed by the PCM decoder: That always reduces the size of the buffer so that all buffers only partially filled by the time they get to the leaf. Now, a flag is set in the audio buffer flags set to indicate the final buffer in the stream.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/system/nxplayer/nxplayer.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/apps/system/nxplayer/nxplayer.c b/apps/system/nxplayer/nxplayer.c index d3c2366a3..49d015de6 100644 --- a/apps/system/nxplayer/nxplayer.c +++ b/apps/system/nxplayer/nxplayer.c @@ -489,7 +489,7 @@ static int nxplayer_mediasearch(FAR struct nxplayer_s *pPlayer, ****************************************************************************/ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, - FAR struct ap_buffer_s* pBuf) + FAR struct ap_buffer_s* apb) { struct audio_buf_desc_s bufdesc; int ret; @@ -510,10 +510,11 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, /* Read data into the buffer. */ - pBuf->nbytes = fread(&pBuf->samp, 1, pBuf->nmaxbytes, pPlayer->fileFd); - pBuf->curbyte = 0; + apb->nbytes = fread(&apb->samp, 1, apb->nmaxbytes, pPlayer->fileFd); + apb->curbyte = 0; + apb->flags = 0; - if (pBuf->nbytes < pBuf->nmaxbytes) + if (apb->nbytes < apb->nmaxbytes) { int errcode = errno; int readerror = ferror(pPlayer->fileFd); @@ -523,14 +524,18 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, */ audvdbg("Closing audio file, nbytes=%d readerr=%d\n", - pBuf->nbytes, readerror); + apb->nbytes, readerror); fclose(pPlayer->fileFd); pPlayer->fileFd = NULL; + /* Set a flag to indicate that this is the final buffer in the stream */ + + apb->flags |= AUDIO_APB_FINAL; + /* Was this a file read error */ - if (pBuf->nbytes == 0 && readerror) + if (apb->nbytes == 0 && readerror) { DEBUGASSERT(errcode > 0); @@ -541,7 +546,7 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, /* Do nothing more if this was the end-of-file with nothing read */ - if (pBuf->nbytes > 0) + if (apb->nbytes > 0) { /* Now enqueue the buffer with the audio device. If the number of * bytes in the file happens to be an exact multiple of the audio @@ -553,8 +558,8 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, #ifdef CONFIG_AUDIO_MULTI_SESSION bufdesc.session = pPlayer->session; #endif - bufdesc.numbytes = pBuf->nbytes; - bufdesc.u.pBuffer = pBuf; + bufdesc.numbytes = apb->nbytes; + bufdesc.u.pBuffer = apb; ret = ioctl(pPlayer->devFd, AUDIOIOC_ENQUEUEBUFFER, (unsigned long)&bufdesc); |