Files
flac/include/FLAC++/decoder.h

339 lines
13 KiB
C
Raw Normal View History

2002-05-29 05:49:50 +00:00
/* libFLAC++ - Free Lossless Audio Codec library
2003-01-02 07:03:16 +00:00
* Copyright (C) 2002,2003 Josh Coalson
2002-05-29 05:49:50 +00:00
*
2003-01-31 23:34:56 +00:00
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
2002-05-29 05:49:50 +00:00
*
2003-01-31 23:34:56 +00:00
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
2002-05-29 05:49:50 +00:00
*
2003-01-31 23:34:56 +00:00
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2002-05-29 05:49:50 +00:00
*/
#ifndef FLACPP__DECODER_H
#define FLACPP__DECODER_H
#include "export.h"
2002-05-29 05:49:50 +00:00
#include "FLAC/file_decoder.h"
#include "FLAC/seekable_stream_decoder.h"
#include "FLAC/stream_decoder.h"
2002-07-27 04:59:54 +00:00
/** \file include/FLAC++/decoder.h
*
* \brief
2002-08-21 03:40:11 +00:00
* This module contains the classes which implement the various
2002-07-27 04:59:54 +00:00
* decoders.
*
* See the detailed documentation in the
* \link flacpp_decoder decoder \endlink module.
*/
/** \defgroup flacpp_decoder FLAC++/decoder.h: decoder classes
* \ingroup flacpp
*
* \brief
2002-08-21 03:40:11 +00:00
* This module describes the three decoder layers provided by libFLAC++.
*
* The libFLAC++ decoder classes are object wrappers around their
* counterparts in libFLAC. All three decoding layers available in
* libFLAC are also provided here. The interface is very similar;
* make sure to read the \link flac_decoder libFLAC decoder module \endlink.
2002-07-27 04:59:54 +00:00
*
2002-08-21 03:40:11 +00:00
* The only real difference here is that instead of passing in C function
* pointers for callbacks, you inherit from the decoder class and provide
* implementations for the callbacks in the derived class; because of this
* there is no need for a 'client_data' property.
2002-07-27 04:59:54 +00:00
*/
2002-05-29 05:49:50 +00:00
namespace FLAC {
namespace Decoder {
// ============================================================
//
// Equivalent: FLAC__StreamDecoder
//
// ============================================================
2002-07-27 04:59:54 +00:00
/** \defgroup flacpp_stream_decoder FLAC++/decoder.h: stream decoder class
* \ingroup flacpp_decoder
*
* \brief
2002-08-21 03:40:11 +00:00
* This class wraps the ::FLAC__StreamDecoder.
2002-07-27 04:59:54 +00:00
*
2002-08-21 03:40:11 +00:00
* See the \link flac_stream_decoder libFLAC stream decoder module \endlink.
2002-08-15 19:19:46 +00:00
*
2002-07-27 04:59:54 +00:00
* \{
*/
2002-08-21 03:40:11 +00:00
/** This class wraps the ::FLAC__StreamDecoder.
2002-07-27 04:59:54 +00:00
*/
class FLACPP_API Stream {
2002-05-29 05:49:50 +00:00
public:
class FLACPP_API State {
2002-05-29 05:49:50 +00:00
public:
inline State(::FLAC__StreamDecoderState state): state_(state) { }
inline operator ::FLAC__StreamDecoderState() const { return state_; }
inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
protected:
::FLAC__StreamDecoderState state_;
};
Stream();
virtual ~Stream();
bool is_valid() const;
inline operator bool() const { return is_valid(); }
2002-06-08 04:53:42 +00:00
bool set_metadata_respond(::FLAC__MetadataType type);
2002-05-29 05:49:50 +00:00
bool set_metadata_respond_application(const FLAC__byte id[4]);
bool set_metadata_respond_all();
2002-06-08 04:53:42 +00:00
bool set_metadata_ignore(::FLAC__MetadataType type);
2002-05-29 05:49:50 +00:00
bool set_metadata_ignore_application(const FLAC__byte id[4]);
bool set_metadata_ignore_all();
State get_state() const;
unsigned get_channels() const;
::FLAC__ChannelAssignment get_channel_assignment() const;
unsigned get_bits_per_sample() const;
unsigned get_sample_rate() const;
unsigned get_blocksize() const;
2002-08-21 03:40:11 +00:00
/** Initialize the instance; as with the C interface,
* init() should be called after construction and 'set'
* calls but before any of the 'process' calls.
*/
2002-05-29 05:49:50 +00:00
State init();
void finish();
bool flush();
bool reset();
2002-08-02 06:26:12 +00:00
bool process_single();
bool process_until_end_of_metadata();
bool process_until_end_of_stream();
2002-05-29 05:49:50 +00:00
protected:
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
2002-06-08 04:53:42 +00:00
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
2002-05-29 05:49:50 +00:00
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
::FLAC__StreamDecoder *decoder_;
private:
static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
2002-06-08 04:53:42 +00:00
static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
2002-05-29 05:49:50 +00:00
static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
// Private and undefined so you can't use them:
Stream(const Stream &);
void operator=(const Stream &);
};
2002-07-27 04:59:54 +00:00
/* \} */
2002-05-29 05:49:50 +00:00
// ============================================================
//
// Equivalent: FLAC__SeekableStreamDecoder
//
// ============================================================
2002-07-27 04:59:54 +00:00
/** \defgroup flacpp_seekable_stream_decoder FLAC++/decoder.h: seekable stream decoder class
* \ingroup flacpp_decoder
*
* \brief
2002-08-21 03:40:11 +00:00
* This class wraps the ::FLAC__SeekableStreamDecoder.
2002-07-27 04:59:54 +00:00
*
2002-08-21 03:40:11 +00:00
* See the \link flac_seekable_stream_decoder libFLAC seekable stream decoder module \endlink.
2002-08-15 19:19:46 +00:00
*
2002-07-27 04:59:54 +00:00
* \{
*/
2002-08-21 03:40:11 +00:00
/** This class wraps the ::FLAC__SeekableStreamDecoder.
2002-07-27 04:59:54 +00:00
*/
class FLACPP_API SeekableStream {
2002-05-29 05:49:50 +00:00
public:
class FLACPP_API State {
2002-05-29 05:49:50 +00:00
public:
inline State(::FLAC__SeekableStreamDecoderState state): state_(state) { }
inline operator ::FLAC__SeekableStreamDecoderState() const { return state_; }
inline const char *as_cstring() const { return ::FLAC__SeekableStreamDecoderStateString[state_]; }
2003-09-24 04:17:26 +00:00
inline const char *resolved_as_cstring(const SeekableStream &decoder) const { return ::FLAC__seekable_stream_decoder_get_resolved_state_string(decoder.decoder_); }
2002-05-29 05:49:50 +00:00
protected:
::FLAC__SeekableStreamDecoderState state_;
};
SeekableStream();
virtual ~SeekableStream();
bool is_valid() const;
inline operator bool() const { return is_valid(); }
bool set_md5_checking(bool value);
2002-06-08 04:53:42 +00:00
bool set_metadata_respond(::FLAC__MetadataType type);
2002-05-29 05:49:50 +00:00
bool set_metadata_respond_application(const FLAC__byte id[4]);
bool set_metadata_respond_all();
2002-06-08 04:53:42 +00:00
bool set_metadata_ignore(::FLAC__MetadataType type);
2002-05-29 05:49:50 +00:00
bool set_metadata_ignore_application(const FLAC__byte id[4]);
bool set_metadata_ignore_all();
State get_state() const;
2002-08-02 06:26:12 +00:00
Stream::State get_stream_decoder_state() const;
2002-05-29 05:49:50 +00:00
bool get_md5_checking() const;
unsigned get_channels() const;
::FLAC__ChannelAssignment get_channel_assignment() const;
unsigned get_bits_per_sample() const;
unsigned get_sample_rate() const;
unsigned get_blocksize() const;
2002-05-29 05:49:50 +00:00
State init();
bool finish();
bool flush();
bool reset();
2002-08-02 06:26:12 +00:00
bool process_single();
bool process_until_end_of_metadata();
bool process_until_end_of_stream();
2002-05-29 05:49:50 +00:00
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 bool eof_callback() = 0;
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
2002-06-08 04:53:42 +00:00
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
2002-05-29 05:49:50 +00:00
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
::FLAC__SeekableStreamDecoder *decoder_;
private:
2002-09-19 01:00:32 +00:00
static ::FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static ::FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static ::FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static ::FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
2002-05-29 05:49:50 +00:00
static FLAC__bool eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data);
2002-09-19 01:00:32 +00:00
static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
2002-06-08 04:53:42 +00:00
static void metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
2002-05-29 05:49:50 +00:00
static void error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
// Private and undefined so you can't use them:
SeekableStream(const SeekableStream &);
void operator=(const SeekableStream &);
};
2002-07-27 04:59:54 +00:00
/* \} */
2002-05-29 05:49:50 +00:00
// ============================================================
//
// Equivalent: FLAC__FileDecoder
//
// ============================================================
2002-07-27 04:59:54 +00:00
/** \defgroup flacpp_file_decoder FLAC++/decoder.h: file decoder class
* \ingroup flacpp_decoder
*
* \brief
2002-08-21 03:40:11 +00:00
* This class wraps the ::FLAC__FileDecoder.
2002-07-27 04:59:54 +00:00
*
2002-08-21 03:40:11 +00:00
* See the \link flac_file_decoder libFLAC file decoder module \endlink.
2002-08-15 19:19:46 +00:00
*
2002-07-27 04:59:54 +00:00
* \{
*/
2002-08-21 03:40:11 +00:00
/** This class wraps the ::FLAC__FileDecoder.
2002-07-27 04:59:54 +00:00
*/
class FLACPP_API File {
2002-05-29 05:49:50 +00:00
public:
class FLACPP_API State {
2002-05-29 05:49:50 +00:00
public:
inline State(::FLAC__FileDecoderState state): state_(state) { }
inline operator ::FLAC__FileDecoderState() const { return state_; }
inline const char *as_cstring() const { return ::FLAC__FileDecoderStateString[state_]; }
2003-09-24 04:17:26 +00:00
inline const char *resolved_as_cstring(const File &decoder) const { return ::FLAC__file_decoder_get_resolved_state_string(decoder.decoder_); }
2002-05-29 05:49:50 +00:00
protected:
::FLAC__FileDecoderState state_;
};
File();
virtual ~File();
bool is_valid() const;
inline operator bool() const { return is_valid(); }
bool set_md5_checking(bool value);
2002-08-21 03:40:11 +00:00
bool set_filename(const char *value); //!< 'value' may not be \c NULL; use "-" for stdin
2002-06-08 04:53:42 +00:00
bool set_metadata_respond(::FLAC__MetadataType type);
2002-05-29 05:49:50 +00:00
bool set_metadata_respond_application(const FLAC__byte id[4]);
bool set_metadata_respond_all();
2002-06-08 04:53:42 +00:00
bool set_metadata_ignore(::FLAC__MetadataType type);
2002-05-29 05:49:50 +00:00
bool set_metadata_ignore_application(const FLAC__byte id[4]);
bool set_metadata_ignore_all();
State get_state() const;
2002-08-02 06:26:12 +00:00
SeekableStream::State get_seekable_stream_decoder_state() const;
Stream::State get_stream_decoder_state() const;
2002-05-29 05:49:50 +00:00
bool get_md5_checking() const;
unsigned get_channels() const;
::FLAC__ChannelAssignment get_channel_assignment() const;
unsigned get_bits_per_sample() const;
unsigned get_sample_rate() const;
unsigned get_blocksize() const;
2002-05-29 05:49:50 +00:00
State init();
bool finish();
2002-08-02 06:26:12 +00:00
bool process_single();
bool process_until_end_of_metadata();
bool process_until_end_of_file();
2002-05-29 05:49:50 +00:00
bool seek_absolute(FLAC__uint64 sample);
protected:
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
2002-06-08 04:53:42 +00:00
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
2002-05-29 05:49:50 +00:00
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
::FLAC__FileDecoder *decoder_;
private:
static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
2002-06-08 04:53:42 +00:00
static void metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
2002-05-29 05:49:50 +00:00
static void error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
// Private and undefined so you can't use them:
File(const File &);
void operator=(const File &);
};
2002-07-27 04:59:54 +00:00
/* \} */
2002-05-29 05:49:50 +00:00
};
};
#endif