Skip to content
Snippets Groups Projects
Commit f3bf7483 authored by Gregory Nutt's avatar Gregory Nutt
Browse files

NxPlayer: Fix an error I introduced: Need to pass through final buffer even...

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
parent f725bdd9
No related branches found
No related tags found
No related merge requests found
...@@ -516,16 +516,18 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, ...@@ -516,16 +516,18 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer,
if (apb->nbytes < apb->nmaxbytes) if (apb->nbytes < apb->nmaxbytes)
{ {
#ifdef CONFIG_DEBUG
int errcode = errno; int errcode = errno;
int readerror = ferror(pPlayer->fileFd); 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 /* End of file or read error.. We are finished with this file in any
* event. * event.
*/ */
audvdbg("Closing audio file, nbytes=%d readerr=%d\n",
apb->nbytes, readerror);
fclose(pPlayer->fileFd); fclose(pPlayer->fileFd);
pPlayer->fileFd = NULL; pPlayer->fileFd = NULL;
...@@ -533,55 +535,59 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer, ...@@ -533,55 +535,59 @@ static int nxplayer_enqueuebuffer(FAR struct nxplayer_s *pPlayer,
apb->flags |= AUDIO_APB_FINAL; apb->flags |= AUDIO_APB_FINAL;
#ifdef CONFIG_DEBUG
/* Was this a file read error */ /* Was this a file read error */
if (apb->nbytes == 0 && readerror) if (apb->nbytes == 0 && readerror)
{ {
DEBUGASSERT(errcode > 0); DEBUGASSERT(errcode > 0);
auddbg("ERROR: fread failed: %d\n", errcode); 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
/* Now enqueue the buffer with the audio device. If the number of * buffer size, then we will receive the last buffer size = 0. We
* bytes in the file happens to be an exact multiple of the audio * encode this buffer also so the audio system knows its the end of
* buffer size, then we will receive the last buffer size = 0. We * the file and can do proper clean-up.
* 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 #ifdef CONFIG_AUDIO_MULTI_SESSION
bufdesc.session = pPlayer->session; bufdesc.session = pPlayer->session;
#endif #endif
bufdesc.numbytes = apb->nbytes; bufdesc.numbytes = apb->nbytes;
bufdesc.u.pBuffer = apb; bufdesc.u.pBuffer = apb;
ret = ioctl(pPlayer->devFd, AUDIOIOC_ENQUEUEBUFFER, ret = ioctl(pPlayer->devFd, AUDIOIOC_ENQUEUEBUFFER,
(unsigned long)&bufdesc); (unsigned long)&bufdesc);
if (ret < 0) if (ret < 0)
{ {
int errcode = errno; int errcode = errno;
DEBUGASSERT(errcode > 0); 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)
*/
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;
} }
/**************************************************************************** /****************************************************************************
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment