Commit 45df1515 authored by Josh Coalson's avatar Josh Coalson
Browse files

better end-of-file/stream checking

parent 7d045bf4
......@@ -77,6 +77,9 @@ typedef enum {
OggFLAC__FILE_DECODER_OK = 0,
/**< The decoder is in the normal OK state. */
OggFLAC__FILE_DECODER_END_OF_FILE,
/**< The decoder has reached the end of the file. */
OggFLAC__FILE_DECODER_OGG_ERROR,
/**< An error occurred in the underlying Ogg layer. */
......
......@@ -77,6 +77,9 @@ typedef enum {
OggFLAC__SEEKABLE_STREAM_DECODER_OK = 0,
/**< The decoder is in the normal OK state. */
OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM,
/**< The decoder has reached the end of the stream. */
OggFLAC__SEEKABLE_STREAM_DECODER_OGG_ERROR,
/**< An error occurred in the underlying Ogg layer. */
......
......@@ -89,6 +89,9 @@ typedef enum {
OggFLAC__STREAM_DECODER_OK = 0,
/**< The decoder is in the normal OK state. */
OggFLAC__STREAM_DECODER_END_OF_STREAM,
/**< The decoder has reached the end of the stream. */
OggFLAC__STREAM_DECODER_OGG_ERROR,
/**< An error occurred in the underlying Ogg layer. */
......
......@@ -67,6 +67,7 @@ typedef struct OggFLAC__FileDecoderPrivate {
OggFLAC_API const char * const OggFLAC__FileDecoderStateString[] = {
"OggFLAC__FILE_DECODER_OK",
"OggFLAC__FILE_DECODER_END_OF_FILE",
"OggFLAC__FILE_DECODER_OGG_ERROR",
"OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR",
"OggFLAC__FILE_DECODER_INVALID_CALLBACK",
......@@ -410,30 +411,77 @@ OggFLAC_API FLAC__bool OggFLAC__file_decoder_get_decode_position(const OggFLAC__
OggFLAC_API FLAC__bool OggFLAC__file_decoder_process_single(OggFLAC__FileDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__file_decoder_process_single(decoder->private_->FLAC_file_decoder);
if(FLAC__file_decoder_get_state(decoder->private_->FLAC_file_decoder) == FLAC__FILE_DECODER_END_OF_FILE)
decoder->protected_->state = OggFLAC__FILE_DECODER_END_OF_FILE;
if(decoder->protected_->state == OggFLAC__FILE_DECODER_END_OF_FILE)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__FILE_DECODER_OK);
ret = FLAC__file_decoder_process_single(decoder->private_->FLAC_file_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__file_decoder_process_until_end_of_metadata(OggFLAC__FileDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__file_decoder_process_until_end_of_metadata(decoder->private_->FLAC_file_decoder);
if(FLAC__file_decoder_get_state(decoder->private_->FLAC_file_decoder) == FLAC__FILE_DECODER_END_OF_FILE)
decoder->protected_->state = OggFLAC__FILE_DECODER_END_OF_FILE;
if(decoder->protected_->state == OggFLAC__FILE_DECODER_END_OF_FILE)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__FILE_DECODER_OK);
ret = FLAC__file_decoder_process_until_end_of_metadata(decoder->private_->FLAC_file_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__file_decoder_process_until_end_of_file(OggFLAC__FileDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__file_decoder_process_until_end_of_file(decoder->private_->FLAC_file_decoder);
if(FLAC__file_decoder_get_state(decoder->private_->FLAC_file_decoder) == FLAC__FILE_DECODER_END_OF_FILE)
decoder->protected_->state = OggFLAC__FILE_DECODER_END_OF_FILE;
if(decoder->protected_->state == OggFLAC__FILE_DECODER_END_OF_FILE)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__FILE_DECODER_OK);
ret = FLAC__file_decoder_process_until_end_of_file(decoder->private_->FLAC_file_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__file_decoder_seek_absolute(OggFLAC__FileDecoder *decoder, FLAC__uint64 sample)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__file_decoder_seek_absolute(decoder->private_->FLAC_file_decoder, sample);
FLAC__ASSERT(decoder->protected_->state == OggFLAC__FILE_DECODER_OK || decoder->protected_->state == OggFLAC__FILE_DECODER_END_OF_FILE);
if(!FLAC__file_decoder_seek_absolute(decoder->private_->FLAC_file_decoder, sample)) {
decoder->protected_->state = OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR;
return false;
}
else {
decoder->protected_->state = OggFLAC__FILE_DECODER_OK;
return true;
}
}
......
......@@ -77,6 +77,7 @@ typedef struct OggFLAC__SeekableStreamDecoderPrivate {
OggFLAC_API const char * const OggFLAC__SeekableStreamDecoderStateString[] = {
"OggFLAC__SEEKABLE_STREAM_DECODER_OK",
"OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM",
"OggFLAC__SEEKABLE_STREAM_DECODER_OGG_ERROR",
"OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR",
"OggFLAC__SEEKABLE_STREAM_DECODER_READ_ERROR",
......@@ -503,30 +504,77 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_reset(OggFLAC__SeekableS
OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_process_single(OggFLAC__SeekableStreamDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__seekable_stream_decoder_process_single(decoder->private_->FLAC_seekable_stream_decoder);
if(FLAC__seekable_stream_decoder_get_state(decoder->private_->FLAC_seekable_stream_decoder) == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM;
if(decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_OK);
ret = FLAC__seekable_stream_decoder_process_single(decoder->private_->FLAC_seekable_stream_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_process_until_end_of_metadata(OggFLAC__SeekableStreamDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder->private_->FLAC_seekable_stream_decoder);
if(FLAC__seekable_stream_decoder_get_state(decoder->private_->FLAC_seekable_stream_decoder) == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM;
if(decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_OK);
ret = FLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder->private_->FLAC_seekable_stream_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_process_until_end_of_stream(OggFLAC__SeekableStreamDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__seekable_stream_decoder_process_until_end_of_stream(decoder->private_->FLAC_seekable_stream_decoder);
if(FLAC__seekable_stream_decoder_get_state(decoder->private_->FLAC_seekable_stream_decoder) == FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM;
if(decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_OK);
ret = FLAC__seekable_stream_decoder_process_until_end_of_stream(decoder->private_->FLAC_seekable_stream_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_seek_absolute(OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 sample)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__seekable_stream_decoder_seek_absolute(decoder->private_->FLAC_seekable_stream_decoder, sample);
FLAC__ASSERT(decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_OK || decoder->protected_->state == OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM);
if(!FLAC__seekable_stream_decoder_seek_absolute(decoder->private_->FLAC_seekable_stream_decoder, sample)) {
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR;
return false;
}
else {
decoder->protected_->state = OggFLAC__SEEKABLE_STREAM_DECODER_OK;
return true;
}
}
......
......@@ -69,6 +69,7 @@ typedef struct OggFLAC__StreamDecoderPrivate {
OggFLAC_API const char * const OggFLAC__StreamDecoderStateString[] = {
"OggFLAC__STREAM_DECODER_OK",
"OggFLAC__STREAM_DECODER_END_OF_STREAM",
"OggFLAC__STREAM_DECODER_OGG_ERROR",
"OggFLAC__STREAM_DECODER_READ_ERROR",
"OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR",
......@@ -412,23 +413,62 @@ OggFLAC_API FLAC__bool OggFLAC__stream_decoder_reset(OggFLAC__StreamDecoder *dec
OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_single(OggFLAC__StreamDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__stream_decoder_process_single(decoder->private_->FLAC_stream_decoder);
if(FLAC__seekable_stream_decoder_get_state(decoder->private_->FLAC_stream_decoder) == FLAC__STREAM_DECODER_END_OF_STREAM)
decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM;
if(decoder->protected_->state == OggFLAC__STREAM_DECODER_END_OF_STREAM)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__STREAM_DECODER_OK);
ret = FLAC__stream_decoder_process_single(decoder->private_->FLAC_stream_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_metadata(OggFLAC__StreamDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__stream_decoder_process_until_end_of_metadata(decoder->private_->FLAC_stream_decoder);
if(FLAC__seekable_stream_decoder_get_state(decoder->private_->FLAC_stream_decoder) == FLAC__STREAM_DECODER_END_OF_STREAM)
decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM;
if(decoder->protected_->state == OggFLAC__STREAM_DECODER_END_OF_STREAM)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__STREAM_DECODER_OK);
ret = FLAC__stream_decoder_process_until_end_of_metadata(decoder->private_->FLAC_stream_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR;
return ret;
}
OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_stream(OggFLAC__StreamDecoder *decoder)
{
FLAC__bool ret;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return FLAC__stream_decoder_process_until_end_of_stream(decoder->private_->FLAC_stream_decoder);
if(FLAC__seekable_stream_decoder_get_state(decoder->private_->FLAC_stream_decoder) == FLAC__STREAM_DECODER_END_OF_STREAM)
decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM;
if(decoder->protected_->state == OggFLAC__STREAM_DECODER_END_OF_STREAM)
return true;
FLAC__ASSERT(decoder->protected_->state == OggFLAC__STREAM_DECODER_OK);
ret = FLAC__stream_decoder_process_until_end_of_stream(decoder->private_->FLAC_stream_decoder);
if(!ret)
decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR;
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment