Commit 073bd9e4 authored by Josh Coalson's avatar Josh Coalson
Browse files

revamp ogg flac file decoder; it needed to be derived from the ogg flac stream...

revamp ogg flac file decoder; it needed to be derived from the ogg flac stream encoder instead of the flac file encoder
parent 4d373f84
......@@ -310,7 +310,7 @@ namespace OggFLAC {
bool set_metadata_ignore_all();
State get_state() const;
FLAC::Decoder::File::State get_FLAC_file_decoder_state() const;
OggFLAC::Decoder::SeekableStream::State get_seekable_stream_decoder_state() const;
FLAC::Decoder::SeekableStream::State get_FLAC_seekable_stream_decoder_state() const;
FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
bool get_md5_checking() const;
......
......@@ -34,7 +34,7 @@
#include "export.h"
#include "FLAC/file_decoder.h"
#include "seekable_stream_decoder.h"
#ifdef __cplusplus
extern "C" {
......@@ -80,12 +80,15 @@ typedef enum {
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. */
OggFLAC__FILE_DECODER_ERROR_OPENING_FILE,
/**< An error occurred opening the input file. */
OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR,
/**< An error occurred in the underlying FLAC file decoder;
* check OggFLAC__file_decoder_get_FLAC_file_decoder_state().
OggFLAC__FILE_DECODER_SEEK_ERROR,
/**< An error occurred while seeking. */
OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR,
/**< An error occurred in the underlying seekable stream decoder;
* check OggFLAC__file_decoder_get_seekable_stream_decoder_state().
*/
OggFLAC__FILE_DECODER_INVALID_CALLBACK,
......@@ -406,22 +409,23 @@ OggFLAC_API FLAC__bool OggFLAC__file_decoder_set_metadata_ignore_all(OggFLAC__Fi
*/
OggFLAC_API OggFLAC__FileDecoderState OggFLAC__file_decoder_get_state(const OggFLAC__FileDecoder *decoder);
/** Get the state of the underlying FLAC file decoder.
/** Get the state of the underlying seekable stream decoder.
* Useful when the file decoder state is
* \c OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR.
* \c OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR.
*
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
* \retval FLAC__FileDecoderState
* The FLAC file decoder state.
* The seekable stream decoder state.
*/
OggFLAC_API FLAC__FileDecoderState OggFLAC__file_decoder_get_FLAC_file_decoder_state(const OggFLAC__FileDecoder *decoder);
OggFLAC_API OggFLAC__SeekableStreamDecoderState OggFLAC__file_decoder_get_seekable_stream_decoder_state(const OggFLAC__FileDecoder *decoder);
/** Get the state of the underlying FLAC file decoder's seekable stream decoder.
/** Get the state of the underlying FLAC seekable stream decoder.
* Useful when the file decoder state is
* \c OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR and the FLAC file decoder state is
* \c FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR.
* \c OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR
* and the seekable stream decoder state is
* \c OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR.
*
* \param decoder A decoder instance to query.
* \assert
......@@ -431,11 +435,13 @@ OggFLAC_API FLAC__FileDecoderState OggFLAC__file_decoder_get_FLAC_file_decoder_s
*/
OggFLAC_API FLAC__SeekableStreamDecoderState OggFLAC__file_decoder_get_FLAC_seekable_stream_decoder_state(const OggFLAC__FileDecoder *decoder);
/** Get the state of the underlying FLAC file decoder's stream decoder.
/** Get the state of the underlying FLAC stream decoder.
* Useful when the file decoder state is
* \c OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR and the FLAC file decoder state is
* \c FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR and the
* FLAC seekable stream decoder state is \c FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR.
* \c OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR
* and the seekable stream decoder state is
* \c OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR
* and the * FLAC seekable stream decoder state is
* \c FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR.
*
* \param decoder A decoder instance to query.
* \assert
......@@ -447,8 +453,8 @@ OggFLAC_API FLAC__StreamDecoderState OggFLAC__file_decoder_get_FLAC_stream_decod
/** Get the current decoder state as a C string.
* This version automatically resolves
* \c OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR
* by getting the FLAC file decoder's state.
* \c OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR
* by getting the seekable stream decoder's state.
*
* \param decoder A decoder instance to query.
* \assert
......
......@@ -117,10 +117,10 @@ namespace OggFLAC {
return State(::OggFLAC__file_decoder_get_state(decoder_));
}
FLAC::Decoder::File::State File::get_FLAC_file_decoder_state() const
OggFLAC::Decoder::SeekableStream::State File::get_seekable_stream_decoder_state() const
{
FLAC__ASSERT(is_valid());
return FLAC::Decoder::File::State(::OggFLAC__file_decoder_get_FLAC_file_decoder_state(decoder_));
return OggFLAC::Decoder::SeekableStream::State(::OggFLAC__file_decoder_get_seekable_stream_decoder_state(decoder_));
}
FLAC::Decoder::SeekableStream::State File::get_FLAC_seekable_stream_decoder_state() const
......
This diff is collapsed.
......@@ -91,18 +91,19 @@ public:
if(error_occurred_)
return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
if(feof(file_))
if(feof(file_)) {
*bytes = 0;
return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
else if(*bytes > 0) {
unsigned bytes_read = ::fread(buffer, 1, *bytes, file_);
if(bytes_read == 0) {
*bytes = ::fread(buffer, 1, *bytes, file_);
if(*bytes == 0) {
if(feof(file_))
return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else
return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
else {
*bytes = bytes_read;
return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
}
......@@ -819,9 +820,9 @@ public:
{
switch(common_read_callback_(buffer, bytes)) {
case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
default:
FLAC__ASSERT(0);
......@@ -1571,9 +1572,9 @@ bool FileDecoder::die(const char *msg) const
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
if(state == ::OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR) {
FLAC::Decoder::File::State state_ = get_FLAC_file_decoder_state();
printf(" FLAC file decoder state = %u (%s)\n", (unsigned)((::FLAC__FileDecoderState)state_), state_.as_cstring());
if(state == ::OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
OggFLAC::Decoder::SeekableStream::State state_ = get_seekable_stream_decoder_state();
printf(" seekable stream decoder state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
if(state_ == ::OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR) {
FLAC::Decoder::SeekableStream::State state__ = get_FLAC_seekable_stream_decoder_state();
printf(" FLAC seekable stream decoder state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state__), state__.as_cstring());
......@@ -1725,9 +1726,9 @@ static bool test_file_decoder()
OggFLAC::Decoder::File::State state = decoder->get_state();
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__FileDecoderState)state), state.as_cstring());
printf("testing get_FLAC_file_decoder_state()... ");
FLAC::Decoder::File::State state_ = decoder->get_FLAC_file_decoder_state();
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__FileDecoderState)state_), state_.as_cstring());
printf("testing get_seekable_stream_decoder_state()... ");
OggFLAC::Decoder::SeekableStream::State state_ = decoder->get_seekable_stream_decoder_state();
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamDecoderState)state_), state_.as_cstring());
printf("testing get_FLAC_seekable_stream_decoder_state()... ");
FLAC::Decoder::SeekableStream::State state__ = decoder->get_FLAC_seekable_stream_decoder_state();
......
......@@ -101,10 +101,10 @@ static FLAC__bool die_f_(const char *msg, const OggFLAC__FileDecoder *decoder)
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__SeekableStreamDecoderStateString[state]);
if(state == OggFLAC__FILE_DECODER_FLAC_FILE_DECODER_ERROR) {
FLAC__FileDecoderState state_ = OggFLAC__file_decoder_get_FLAC_file_decoder_state(decoder);
printf(" FLAC file decoder state = %u (%s)\n", (unsigned)state_, FLAC__FileDecoderStateString[state_]);
if(state_ == FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
if(state == OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
OggFLAC__SeekableStreamDecoderState state_ = OggFLAC__file_decoder_get_seekable_stream_decoder_state(decoder);
printf(" seekable stream decoder state = %u (%s)\n", (unsigned)state_, OggFLAC__SeekableStreamDecoderStateString[state_]);
if(state_ == OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR) {
FLAC__SeekableStreamDecoderState state__ = OggFLAC__file_decoder_get_FLAC_seekable_stream_decoder_state(decoder);
printf(" FLAC seekable stream decoder state = %u (%s)\n", (unsigned)state__, FLAC__SeekableStreamDecoderStateString[state__]);
if(state__ == FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
......@@ -149,7 +149,6 @@ static FLAC__bool generate_file_()
static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
const unsigned requested_bytes = *bytes;
(void)decoder;
......@@ -165,8 +164,8 @@ static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const OggFLAC
*bytes = 0;
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
else if(requested_bytes > 0) {
*bytes = fread(buffer, 1, requested_bytes, dcd->file);
else if(*bytes > 0) {
*bytes = fread(buffer, 1, *bytes, dcd->file);
if(*bytes == 0) {
if(feof(dcd->file))
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
......@@ -1582,7 +1581,7 @@ static FLAC__bool test_file_decoder()
{
OggFLAC__FileDecoder *decoder;
OggFLAC__FileDecoderState state;
FLAC__FileDecoderState ffstate;
OggFLAC__SeekableStreamDecoderState sstate;
FLAC__SeekableStreamDecoderState fsstate;
FLAC__StreamDecoderState fstate;
seekable_stream_decoder_client_data_struct decoder_client_data;
......@@ -1673,9 +1672,9 @@ static FLAC__bool test_file_decoder()
state = OggFLAC__file_decoder_get_state(decoder);
printf("returned state = %u (%s)... OK\n", state, OggFLAC__FileDecoderStateString[state]);
printf("testing OggFLAC__file_decoder_get_FLAC_file_decoder_state()... ");
ffstate = OggFLAC__file_decoder_get_FLAC_file_decoder_state(decoder);
printf("returned state = %u (%s)... OK\n", ffstate, FLAC__FileDecoderStateString[ffstate]);
printf("testing OggFLAC__file_decoder_get_seekable_stream_decoder_state()... ");
sstate = OggFLAC__file_decoder_get_seekable_stream_decoder_state(decoder);
printf("returned state = %u (%s)... OK\n", sstate, OggFLAC__SeekableStreamDecoderStateString[sstate]);
printf("testing OggFLAC__file_decoder_get_FLAC_seekable_stream_decoder_state()... ");
fsstate = OggFLAC__file_decoder_get_FLAC_seekable_stream_decoder_state(decoder);
......
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