1
0
Fork 0
forked from len0rd/rockbox

Correctly detect the end of stream, and correctly re-initialise the FLAC decoder before playing the next track.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6601 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Chapman 2005-06-07 20:09:53 +00:00
parent 3522fc60be
commit b15e546937

View file

@ -36,12 +36,11 @@ FLAC__SeekableStreamDecoderReadStatus flac_read_handler(const FLAC__SeekableStre
*bytes=(unsigned)(ci->read_filebuf(buffer,*bytes)); *bytes=(unsigned)(ci->read_filebuf(buffer,*bytes));
/* QUESTION: How do I detect the end of the stream? */ if (*bytes==0) {
if (ci->curpos >= ci->filesize) {
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
} else {
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
} }
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
} }
static unsigned char pcmbuf[FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS*2] IDATA_ATTR; static unsigned char pcmbuf[FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS*2] IDATA_ATTR;
@ -169,13 +168,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parm)
/* This function sets up the buffers and reads the file into RAM */ /* This function sets up the buffers and reads the file into RAM */
next_track:
if (codec_init(api, ci)) { if (codec_init(api, ci)) {
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
/* Create a decoder instance */ /* Create a decoder instance */
next_track:
flacDecoder=FLAC__seekable_stream_decoder_new(); flacDecoder=FLAC__seekable_stream_decoder_new();
/* Set up the decoder and the callback functions - this must be done before init */ /* Set up the decoder and the callback functions - this must be done before init */
@ -212,6 +212,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parm)
FLAC__seekable_stream_decoder_process_single(flacDecoder); FLAC__seekable_stream_decoder_process_single(flacDecoder);
} }
/* Flush the libFLAC buffers */
FLAC__seekable_stream_decoder_finish(flacDecoder);
if (ci->request_next_track()) if (ci->request_next_track())
goto next_track; goto next_track;