diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-08-01 07:00:02 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-08-01 07:00:02 -0600 |
commit | de8d31cf44d8586d60ad8e80f36f22c7462a601d (patch) | |
tree | bf82eeb3bedf523528f7651c72ce350b57a6f51a /apps/system/nxplayer | |
parent | 294044693ef84a65daae44ab35c3b12657e91cb2 (diff) | |
download | px4-nuttx-de8d31cf44d8586d60ad8e80f36f22c7462a601d.tar.gz px4-nuttx-de8d31cf44d8586d60ad8e80f36f22c7462a601d.tar.bz2 px4-nuttx-de8d31cf44d8586d60ad8e80f36f22c7462a601d.zip |
NxPlayer: Fix an error I introduced: Need to pass through final buffer even if is it zero length because it contains the end of audio stream flag
Diffstat (limited to 'apps/system/nxplayer')
-rw-r--r-- | apps/system/nxplayer/nxplayer.c | 74 |
1 files changed, 40 insertions, 34 deletions
diff --git a/apps/system/nxplayer/nxplayer.c b/apps/system/nxplayer/nxplayer.c index 49d015de6..53860f00d 100644 --- a/apps/system/nxplayer/nxplayer.c +++ b/apps/system/nxplayer/nxplayer.c @@ -516,16 +516,18 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, if (apb->nbytes < apb->nmaxbytes) { +#ifdef CONFIG_DEBUG int errcode = errno; int readerror = ferror(pPlayer->fileFd); + audvdbg("Closing audio file, nbytes=%d readerr=%d\n", + apb->nbytes, readerror); +#endif + /* End of file or read error.. We are finished with this file in any * event. */ - audvdbg("Closing audio file, nbytes=%d readerr=%d\n", - apb->nbytes, readerror); - fclose(pPlayer->fileFd); pPlayer->fileFd = NULL; @@ -533,55 +535,59 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, apb->flags |= AUDIO_APB_FINAL; +#ifdef CONFIG_DEBUG /* Was this a file read error */ if (apb->nbytes == 0 && readerror) { DEBUGASSERT(errcode > 0); - auddbg("ERROR: fread failed: %d\n", errcode); - return -errcode; + UNUSED(errcode); } +#endif } - /* Do nothing more if this was the end-of-file with nothing read */ + /* We get here either on a successful read or a read error. + * + * We will have a zero length buffer (with the AUDIO_APB_FINAL set) if a + * read error occurs or in the event that the file was an exact multiple + * of the nmaxbytes size of the audio buffer. In that latter case, we + * have an end of file with no bytes read. + * + * These infrequency zero length buffers have to be passed through because + * the include the AUDIO_APB_FINAL flag that is needed to terminate the + * audio stream. + */ - 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 - * buffer size, then we will receive the last buffer size = 0. We - * encode this buffer also so the audio system knows its the end of - * the file and can do proper clean-up. - */ + /* 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 + * buffer size, then we will receive the last buffer size = 0. We + * encode this buffer also so the audio system knows its the end of + * the file and can do proper clean-up. + */ #ifdef CONFIG_AUDIO_MULTI_SESSION - bufdesc.session = pPlayer->session; + bufdesc.session = pPlayer->session; #endif - bufdesc.numbytes = apb->nbytes; - bufdesc.u.pBuffer = apb; + bufdesc.numbytes = apb->nbytes; + bufdesc.u.pBuffer = apb; - ret = ioctl(pPlayer->devFd, AUDIOIOC_ENQUEUEBUFFER, - (unsigned long)&bufdesc); - if (ret < 0) - { - int errcode = errno; - DEBUGASSERT(errcode > 0); - - auddbg("ERROR: AUDIOIOC_ENQUEUEBUFFER ioctl failed: %d\n", errcode); - return -errcode; - } - - /* Return OK to indicate that we successfully read data from the file - * (and we are not yet at the end of file) - */ + ret = ioctl(pPlayer->devFd, AUDIOIOC_ENQUEUEBUFFER, + (unsigned long)&bufdesc); + if (ret < 0) + { + int errcode = errno; + DEBUGASSERT(errcode > 0); - return OK; + auddbg("ERROR: AUDIOIOC_ENQUEUEBUFFER ioctl failed: %d\n", errcode); + return -errcode; } - /* Return -ENODATA if we are at the end of file */ + /* Return OK to indicate that we successfully read data from the file + * (and we are not yet at the end of file) + */ - return -ENODATA; + return OK; } /**************************************************************************** |