Commit 63f8edc6 authored by Josh Coalson's avatar Josh Coalson
Browse files

revamp OggFLAC__SeekableStreamDecoder to derive from OggFLAC__StreamDecoder...

revamp OggFLAC__SeekableStreamDecoder to derive from OggFLAC__StreamDecoder instead of FLAC__SeekableStreamDecoder; rewrite seek routine to do a binary search through Ogg pages, instead of the seektable-based search of FLAC__SeekableStreamDecoder
parent 6ebbabfd
......@@ -209,7 +209,7 @@ namespace OggFLAC {
bool set_metadata_ignore_all();
State get_state() const;
FLAC::Decoder::SeekableStream::State get_FLAC_seekable_stream_decoder_state() const;
OggFLAC::Decoder::Stream::State get_stream_decoder_state() const;
FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
bool get_md5_checking() const;
unsigned get_channels() const;
......@@ -231,10 +231,10 @@ namespace OggFLAC {
bool seek_absolute(FLAC__uint64 sample);
protected:
virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
virtual ::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
virtual ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
virtual ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
virtual ::OggFLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
virtual bool eof_callback() = 0;
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
......@@ -246,10 +246,10 @@ namespace OggFLAC {
#endif
::OggFLAC__SeekableStreamDecoder *decoder_;
private:
static ::FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static ::FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static ::FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static ::FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
static ::OggFLAC__SeekableStreamDecoderReadStatus read_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static ::OggFLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
static FLAC__bool eof_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, void *client_data);
static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
static void metadata_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
......@@ -311,7 +311,7 @@ namespace OggFLAC {
State get_state() const;
OggFLAC::Decoder::SeekableStream::State get_seekable_stream_decoder_state() const;
FLAC::Decoder::SeekableStream::State get_FLAC_seekable_stream_decoder_state() const;
OggFLAC::Decoder::Stream::State get_stream_decoder_state() const;
FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
bool get_md5_checking() const;
unsigned get_channels() const;
......
......@@ -118,7 +118,7 @@ extern OggFLAC_API const char * const OggFLAC__FileDecoderStateString[];
/***********************************************************************
*
* class OggFLAC__FileDecoder : public FLAC__FileDecoder
* class OggFLAC__FileDecoder : public OggFLAC__SeekableStreamDecoder
*
***********************************************************************/
......@@ -421,27 +421,27 @@ OggFLAC_API OggFLAC__FileDecoderState OggFLAC__file_decoder_get_state(const OggF
*/
OggFLAC_API OggFLAC__SeekableStreamDecoderState OggFLAC__file_decoder_get_seekable_stream_decoder_state(const OggFLAC__FileDecoder *decoder);
/** Get the state of the underlying FLAC seekable stream decoder.
/** Get the state of the underlying stream decoder.
* Useful when the file decoder state is
* \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.
* \c OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR.
*
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
* \retval FLAC__SeekableStreamDecoderState
* The FLAC seekable stream decoder state.
* \retval OggFLAC__StreamDecoderState
* The stream decoder state.
*/
OggFLAC_API FLAC__SeekableStreamDecoderState OggFLAC__file_decoder_get_FLAC_seekable_stream_decoder_state(const OggFLAC__FileDecoder *decoder);
OggFLAC_API OggFLAC__StreamDecoderState OggFLAC__file_decoder_get_stream_decoder_state(const OggFLAC__FileDecoder *decoder);
/** Get the state of the underlying FLAC stream decoder.
* Useful when the file decoder state is
* \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.
* \c OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR
* and the stream decoder state is
* \c OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR.
*
* \param decoder A decoder instance to query.
* \assert
......@@ -530,6 +530,8 @@ OggFLAC_API unsigned OggFLAC__file_decoder_get_sample_rate(const OggFLAC__FileDe
*/
OggFLAC_API unsigned OggFLAC__file_decoder_get_blocksize(const OggFLAC__FileDecoder *decoder);
#if 0
@@@@@@ this can never be made to work without writing a custom Ogg decoder; remove for release
/** This is inherited from FLAC__FileDecoder; see
* FLAC__file_decoder_get_decode_position().
*
......@@ -543,6 +545,7 @@ OggFLAC_API unsigned OggFLAC__file_decoder_get_blocksize(const OggFLAC__FileDeco
* the 'tell' callback.
*/
OggFLAC_API FLAC__bool OggFLAC__file_decoder_get_decode_position(const OggFLAC__FileDecoder *decoder, FLAC__uint64 *position);
#endif
/** Initialize the decoder instance.
* Should be called after OggFLAC__file_decoder_new() and
......@@ -614,8 +617,8 @@ OggFLAC_API FLAC__bool OggFLAC__file_decoder_process_until_end_of_metadata(OggFL
*/
OggFLAC_API FLAC__bool OggFLAC__file_decoder_process_until_end_of_file(OggFLAC__FileDecoder *decoder);
/** This is inherited from FLAC__FileDecoder; see
* FLAC__file_decoder_seek_absolute().
/** This is inherited from OggFLAC__SeekableStreamDecoder; see
* OggFLAC__seekable_stream_decoder_seek_absolute().
*
* \param decoder A decoder instance.
* \param sample The target sample number to seek to.
......
......@@ -33,8 +33,7 @@
#define OggFLAC__SEEKABLE_STREAM_DECODER_H
#include "export.h"
#include "FLAC/seekable_stream_decoder.h"
#include "stream_decoder.h"
#ifdef __cplusplus
extern "C" {
......@@ -77,22 +76,27 @@ typedef enum {
OggFLAC__SEEKABLE_STREAM_DECODER_OK = 0,
/**< The decoder is in the normal OK state. */
OggFLAC__SEEKABLE_STREAM_DECODER_SEEKING,
/**< The decoder is in the process of seeking. */
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. */
OggFLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
/**< Memory allocation failed. */
OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR,
/**< An error occurred in the underlying FLAC seekable stream decoder;
* check OggFLAC__seekable_stream_decoder_get_FLAC_seekable_stream_decoder_state().
OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR,
/**< An error occurred in the underlying stream decoder;
* check OggFLAC__seekable_stream_decoder_get_stream_decoder_state().
*/
OggFLAC__SEEKABLE_STREAM_DECODER_READ_ERROR,
/**< The read callback returned an error. */
OggFLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
/**< Memory allocation failed. */
OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_ERROR,
/**< An error occurred while seeking or the seek or tell
* callback returned an error.
*/
OggFLAC__SEEKABLE_STREAM_DECODER_ALREADY_INITIALIZED,
/**< OggFLAC__seekable_stream_decoder_init() was called when the decoder was
......@@ -116,6 +120,86 @@ typedef enum {
extern OggFLAC_API const char * const OggFLAC__SeekableStreamDecoderStateString[];
/** Return values for the OggFLAC__SeekableStreamDecoder read callback.
*/
typedef enum {
OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK,
/**< The read was OK and decoding can continue. */
OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR
/**< An unrecoverable error occurred. The decoder will return from the process call. */
} OggFLAC__SeekableStreamDecoderReadStatus;
/** Maps a OggFLAC__SeekableStreamDecoderReadStatus to a C string.
*
* Using a OggFLAC__SeekableStreamDecoderReadStatus as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern OggFLAC_API const char * const OggFLAC__SeekableStreamDecoderReadStatusString[];
/** Return values for the OggFLAC__SeekableStreamDecoder seek callback.
*/
typedef enum {
OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK,
/**< The seek was OK and decoding can continue. */
OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR
/**< An unrecoverable error occurred. The decoder will return from the process call. */
} OggFLAC__SeekableStreamDecoderSeekStatus;
/** Maps a OggFLAC__SeekableStreamDecoderSeekStatus to a C string.
*
* Using a OggFLAC__SeekableStreamDecoderSeekStatus as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern OggFLAC_API const char * const OggFLAC__SeekableStreamDecoderSeekStatusString[];
/** Return values for the OggFLAC__SeekableStreamDecoder tell callback.
*/
typedef enum {
OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK,
/**< The tell was OK and decoding can continue. */
OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR
/**< An unrecoverable error occurred. The decoder will return from the process call. */
} OggFLAC__SeekableStreamDecoderTellStatus;
/** Maps a OggFLAC__SeekableStreamDecoderTellStatus to a C string.
*
* Using a OggFLAC__SeekableStreamDecoderTellStatus as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern OggFLAC_API const char * const OggFLAC__SeekableStreamDecoderTellStatusString[];
/** Return values for the OggFLAC__SeekableStreamDecoder length callback.
*/
typedef enum {
OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK,
/**< The length call was OK and decoding can continue. */
OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR
/**< An unrecoverable error occurred. The decoder will return from the process call. */
} OggFLAC__SeekableStreamDecoderLengthStatus;
/** Maps a OggFLAC__SeekableStreamDecoderLengthStatus to a C string.
*
* Using a OggFLAC__SeekableStreamDecoderLengthStatus as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern OggFLAC_API const char * const OggFLAC__SeekableStreamDecoderLengthStatusString[];
/***********************************************************************
*
* class OggFLAC__SeekableStreamDecoder : public FLAC__StreamDecoder
......@@ -147,7 +231,7 @@ typedef struct {
* \retval FLAC__SeekableStreamDecoderReadStatus
* The callee's return status.
*/
typedef FLAC__SeekableStreamDecoderReadStatus (*OggFLAC__SeekableStreamDecoderReadCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
typedef OggFLAC__SeekableStreamDecoderReadStatus (*OggFLAC__SeekableStreamDecoderReadCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
/** Signature for the seek callback.
* See OggFLAC__seekable_stream_decoder_set_seek_callback() for more info.
......@@ -160,7 +244,7 @@ typedef FLAC__SeekableStreamDecoderReadStatus (*OggFLAC__SeekableStreamDecoderRe
* \retval FLAC__SeekableStreamDecoderSeekStatus
* The callee's return status.
*/
typedef FLAC__SeekableStreamDecoderSeekStatus (*OggFLAC__SeekableStreamDecoderSeekCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
typedef OggFLAC__SeekableStreamDecoderSeekStatus (*OggFLAC__SeekableStreamDecoderSeekCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
/** Signature for the tell callback.
* See OggFLAC__seekable_stream_decoder_set_tell_callback() for more info.
......@@ -173,7 +257,7 @@ typedef FLAC__SeekableStreamDecoderSeekStatus (*OggFLAC__SeekableStreamDecoderSe
* \retval FLAC__SeekableStreamDecoderTellStatus
* The callee's return status.
*/
typedef FLAC__SeekableStreamDecoderTellStatus (*OggFLAC__SeekableStreamDecoderTellCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
typedef OggFLAC__SeekableStreamDecoderTellStatus (*OggFLAC__SeekableStreamDecoderTellCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
/** Signature for the length callback.
* See OggFLAC__seekable_stream_decoder_set_length_callback() for more info.
......@@ -186,7 +270,7 @@ typedef FLAC__SeekableStreamDecoderTellStatus (*OggFLAC__SeekableStreamDecoderTe
* \retval FLAC__SeekableStreamDecoderLengthStatus
* The callee's return status.
*/
typedef FLAC__SeekableStreamDecoderLengthStatus (*OggFLAC__SeekableStreamDecoderLengthCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
typedef OggFLAC__SeekableStreamDecoderLengthStatus (*OggFLAC__SeekableStreamDecoderLengthCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
/** Signature for the EOF callback.
* See OggFLAC__seekable_stream_decoder_set_eof_callback() for more info.
......@@ -550,22 +634,22 @@ OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(
*/
OggFLAC_API OggFLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder_get_state(const OggFLAC__SeekableStreamDecoder *decoder);
/** Get the state of the underlying FLAC seekable stream decoder.
/** Get the state of the underlying stream decoder.
* Useful when the seekable stream decoder state is
* \c OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR.
* \c OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR.
*
* \param decoder A decoder instance to query.
* \assert
* \code decoder != NULL \endcode
* \retval FLAC__SeekableStreamDecoderState
* The FLAC seekable stream decoder state.
* \retval OggFLAC__StreamDecoderState
* The stream decoder state.
*/
OggFLAC_API FLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder_get_FLAC_seekable_stream_decoder_state(const OggFLAC__SeekableStreamDecoder *decoder);
OggFLAC_API OggFLAC__StreamDecoderState OggFLAC__seekable_stream_decoder_get_stream_decoder_state(const OggFLAC__SeekableStreamDecoder *decoder);
/** Get the state of the underlying FLAC seekable stream decoder's stream decoder.
/** Get the state of the underlying stream decoder's FLAC stream decoder.
* Useful when 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
* \c OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR and the
* stream decoder state is \c OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR
*
* \param decoder A decoder instance to query.
* \assert
......@@ -577,8 +661,8 @@ OggFLAC_API FLAC__StreamDecoderState OggFLAC__seekable_stream_decoder_get_FLAC_s
/** Get the current decoder state as a C string.
* This version automatically resolves
* \c OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR
* by getting the FLAC seekable stream decoder's state.
* \c OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR
* by getting the stream decoder's state.
*
* \param decoder A decoder instance to query.
* \assert
......@@ -654,6 +738,8 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_decoder_get_sample_rate(const OggF
*/
OggFLAC_API unsigned OggFLAC__seekable_stream_decoder_get_blocksize(const OggFLAC__SeekableStreamDecoder *decoder);
#if 0
@@@@@@ this can never be made to work without writing a custom Ogg decoder; remove for release
/** Returns the decoder's current read position within the stream.
* This is inherited from FLAC__SeekableStreamDecoder; see
* FLAC__seekable_stream_decoder_get_decode_position().
......@@ -667,7 +753,9 @@ OggFLAC_API unsigned OggFLAC__seekable_stream_decoder_get_blocksize(const OggFLA
* \c true if successful, \c false if there was an error from
* the 'tell' callback.
*/
/*@@@@@@ probably does not work... is it used? */
OggFLAC_API FLAC__bool OggFLAC__seekable_stream_decoder_get_decode_position(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *position);
#endif
/** Initialize the decoder instance.
* Should be called after OggFLAC__seekable_stream_decoder_new() and
......
......@@ -123,10 +123,10 @@ namespace OggFLAC {
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
OggFLAC::Decoder::Stream::State File::get_stream_decoder_state() const
{
FLAC__ASSERT(is_valid());
return FLAC::Decoder::SeekableStream::State(::OggFLAC__file_decoder_get_FLAC_seekable_stream_decoder_state(decoder_));
return OggFLAC::Decoder::Stream::State(::OggFLAC__file_decoder_get_stream_decoder_state(decoder_));
}
FLAC::Decoder::Stream::State File::get_FLAC_stream_decoder_state() const
......
......@@ -111,10 +111,10 @@ namespace OggFLAC {
return State(::OggFLAC__seekable_stream_decoder_get_state(decoder_));
}
FLAC::Decoder::SeekableStream::State SeekableStream::get_FLAC_seekable_stream_decoder_state() const
OggFLAC::Decoder::Stream::State SeekableStream::get_stream_decoder_state() const
{
FLAC__ASSERT(is_valid());
return FLAC::Decoder::SeekableStream::State(::OggFLAC__seekable_stream_decoder_get_FLAC_seekable_stream_decoder_state(decoder_));
return OggFLAC::Decoder::Stream::State(::OggFLAC__seekable_stream_decoder_get_stream_decoder_state(decoder_));
}
FLAC::Decoder::Stream::State SeekableStream::get_FLAC_stream_decoder_state() const
......@@ -216,7 +216,7 @@ namespace OggFLAC {
return (bool)::OggFLAC__seekable_stream_decoder_seek_absolute(decoder_, sample);
}
::FLAC__SeekableStreamDecoderReadStatus SeekableStream::read_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
::OggFLAC__SeekableStreamDecoderReadStatus SeekableStream::read_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void) decoder;
FLAC__ASSERT(0 != client_data);
......@@ -225,7 +225,7 @@ namespace OggFLAC {
return instance->read_callback(buffer, bytes);
}
::FLAC__SeekableStreamDecoderSeekStatus SeekableStream::seek_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
::OggFLAC__SeekableStreamDecoderSeekStatus SeekableStream::seek_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
(void) decoder;
FLAC__ASSERT(0 != client_data);
......@@ -234,7 +234,7 @@ namespace OggFLAC {
return instance->seek_callback(absolute_byte_offset);
}
::FLAC__SeekableStreamDecoderTellStatus SeekableStream::tell_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
::OggFLAC__SeekableStreamDecoderTellStatus SeekableStream::tell_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
(void) decoder;
FLAC__ASSERT(0 != client_data);
......@@ -243,7 +243,7 @@ namespace OggFLAC {
return instance->tell_callback(absolute_byte_offset);
}
::FLAC__SeekableStreamDecoderLengthStatus SeekableStream::length_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
::OggFLAC__SeekableStreamDecoderLengthStatus SeekableStream::length_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
{
(void) decoder;
FLAC__ASSERT(0 != client_data);
......
......@@ -52,10 +52,10 @@
static void set_defaults_(OggFLAC__FileDecoder *decoder);
static FILE *get_binary_stdin_();
static FLAC__SeekableStreamDecoderReadStatus read_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static FLAC__SeekableStreamDecoderTellStatus tell_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static FLAC__SeekableStreamDecoderLengthStatus length_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
static OggFLAC__SeekableStreamDecoderReadStatus read_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static OggFLAC__SeekableStreamDecoderSeekStatus seek_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static OggFLAC__SeekableStreamDecoderTellStatus tell_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static OggFLAC__SeekableStreamDecoderLengthStatus length_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
static FLAC__bool eof_callback_(const OggFLAC__SeekableStreamDecoder *decoder, void *client_data);
static FLAC__StreamDecoderWriteStatus write_callback_(const OggFLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
static void metadata_callback_(const OggFLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
......@@ -392,11 +392,11 @@ OggFLAC_API OggFLAC__SeekableStreamDecoderState OggFLAC__file_decoder_get_seekab
return OggFLAC__seekable_stream_decoder_get_state(decoder->private_->seekable_stream_decoder);
}
OggFLAC_API FLAC__SeekableStreamDecoderState OggFLAC__file_decoder_get_FLAC_seekable_stream_decoder_state(const OggFLAC__FileDecoder *decoder)
OggFLAC_API OggFLAC__StreamDecoderState OggFLAC__file_decoder_get_stream_decoder_state(const OggFLAC__FileDecoder *decoder)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return OggFLAC__seekable_stream_decoder_get_FLAC_seekable_stream_decoder_state(decoder->private_->seekable_stream_decoder);
return OggFLAC__seekable_stream_decoder_get_stream_decoder_state(decoder->private_->seekable_stream_decoder);
}
OggFLAC_API FLAC__StreamDecoderState OggFLAC__file_decoder_get_FLAC_stream_decoder_state(const OggFLAC__FileDecoder *decoder)
......@@ -456,12 +456,15 @@ OggFLAC_API unsigned OggFLAC__file_decoder_get_blocksize(const OggFLAC__FileDeco
return OggFLAC__seekable_stream_decoder_get_blocksize(decoder->private_->seekable_stream_decoder);
}
#if 0
@@@@@@ this can never be made to work without writing a custom Ogg decoder; remove for release
OggFLAC_API FLAC__bool OggFLAC__file_decoder_get_decode_position(const OggFLAC__FileDecoder *decoder, FLAC__uint64 *position)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
return OggFLAC__seekable_stream_decoder_get_decode_position(decoder->private_->seekable_stream_decoder, position);
}
#endif
OggFLAC_API FLAC__bool OggFLAC__file_decoder_process_single(OggFLAC__FileDecoder *decoder)
{
......@@ -581,7 +584,7 @@ FILE *get_binary_stdin_()
return stdin;
}
FLAC__SeekableStreamDecoderReadStatus read_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
OggFLAC__SeekableStreamDecoderReadStatus read_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
OggFLAC__FileDecoder *file_decoder = (OggFLAC__FileDecoder *)client_data;
(void)decoder;
......@@ -589,52 +592,52 @@ FLAC__SeekableStreamDecoderReadStatus read_callback_(const OggFLAC__SeekableStre
if(*bytes > 0) {
*bytes = (unsigned)fread(buffer, sizeof(FLAC__byte), *bytes, file_decoder->private_->file);
if(ferror(file_decoder->private_->file)) {
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
}
else {
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
}
}
else
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; /* abort to avoid a deadlock */
return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; /* abort to avoid a deadlock */
}
FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
OggFLAC__SeekableStreamDecoderSeekStatus seek_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
OggFLAC__FileDecoder *file_decoder = (OggFLAC__FileDecoder *)client_data;
(void)decoder;
if(fseek(file_decoder->private_->file, (long)absolute_byte_offset, SEEK_SET) < 0)
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
else
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
}
FLAC__SeekableStreamDecoderTellStatus tell_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
OggFLAC__SeekableStreamDecoderTellStatus tell_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
OggFLAC__FileDecoder *file_decoder = (OggFLAC__FileDecoder *)client_data;
long pos;
(void)decoder;
if((pos = ftell(file_decoder->private_->file)) < 0)
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
else {
*absolute_byte_offset = (FLAC__uint64)pos;
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
}
}
FLAC__SeekableStreamDecoderLengthStatus length_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
OggFLAC__SeekableStreamDecoderLengthStatus length_callback_(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
{
OggFLAC__FileDecoder *file_decoder = (OggFLAC__FileDecoder *)client_data;
struct stat filestats;
(void)decoder;
if(0 == file_decoder->private_->filename || stat(file_decoder->private_->filename, &filestats) != 0)
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
else {
*stream_length = (FLAC__uint64)filestats.st_size;
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
}
}
......
......@@ -36,6 +36,7 @@
#include "private/ogg_decoder_aspect.h"
typedef struct OggFLAC__SeekableStreamDecoderProtected {
FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
OggFLAC__SeekableStreamDecoderState state;
OggFLAC__OggDecoderAspect ogg_decoder_aspect;
} OggFLAC__SeekableStreamDecoderProtected;
......
This diff is collapsed.
......@@ -802,10 +802,10 @@ public:
~SeekableStreamDecoder() { }
// from OggFLAC::Decoder::SeekableStream
::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
::OggFLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
bool eof_callback();
::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
......@@ -816,56 +816,56 @@ public:
bool test_respond();
};
::FLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
::OggFLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
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;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:
return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
default:
FLAC__ASSERT(0);
return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
}
}
::FLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
::OggFLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
{
if(error_occurred_)
return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) {
error_occurred_ = true;
return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
}
return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
}
::FLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
::OggFLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
{
if(error_occurred_)
return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
long offset = ::ftell(file_);
*absolute_byte_offset = (FLAC__uint64)offset;
if(offset < 0) {
error_occurred_ = true;
return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
}
return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;