decoder.h
Go to the documentation of this file.
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
* Copyright (C) 2011-2025 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - 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.
*/
#ifndef FLACPP__DECODER_H
#define FLACPP__DECODER_H
#include "export.h"
#include <string>
#include "FLAC/stream_decoder.h"
namespace FLAC {
namespace Decoder {
class FLACPP_API Stream {
public:
class FLACPP_API State {
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_]; }
inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
protected:
::FLAC__StreamDecoderState state_;
};
Stream();
virtual ~Stream();
virtual bool is_valid() const;
inline operator bool() const { return is_valid(); }
virtual bool set_ogg_serial_number(long value);
virtual bool set_decode_chained_stream(bool value);
virtual bool set_md5_checking(bool value);
virtual bool set_metadata_respond(::FLAC__MetadataType type);
virtual bool set_metadata_respond_application(const FLAC__byte id[4]);
virtual bool set_metadata_respond_all();
virtual bool set_metadata_ignore(::FLAC__MetadataType type);
virtual bool set_metadata_ignore_application(const FLAC__byte id[4]);
virtual bool set_metadata_ignore_all();
/* get_state() is not virtual since we want subclasses to be able to return their own state */
State get_state() const;
virtual bool get_decode_chained_stream() const;
virtual bool get_md5_checking() const;
virtual FLAC__uint64 get_total_samples() const;
virtual FLAC__uint64 find_total_samples();
virtual uint32_t get_channels() const;
virtual ::FLAC__ChannelAssignment get_channel_assignment() const;
virtual uint32_t get_bits_per_sample() const;
virtual uint32_t get_sample_rate() const;
virtual uint32_t get_blocksize() const;
virtual bool get_decode_position(FLAC__uint64 *position) const;
virtual int32_t get_link_lengths(FLAC__uint64 **link_lengths);
virtual ::FLAC__StreamDecoderInitStatus init();
virtual ::FLAC__StreamDecoderInitStatus init_ogg();
virtual bool finish();
virtual bool finish_link();
virtual bool flush();
virtual bool reset();
virtual bool process_single();
virtual bool process_until_end_of_metadata();
virtual bool process_until_end_of_link();
virtual bool process_until_end_of_stream();
virtual bool skip_single_frame();
virtual bool skip_single_link();
virtual bool seek_absolute(FLAC__uint64 sample);
protected:
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0;
virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
virtual bool eof_callback();
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
#if (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
// lame hack: some compilers can't see a protected decoder_ from nested State::resolved_as_cstring()
friend State;
#endif
::FLAC__StreamDecoder *decoder_;
static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data);
static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
private:
// Private and undefined so you can't use them:
Stream(const Stream &);
void operator=(const Stream &);
};
class FLACPP_API File: public Stream {
public:
File();
virtual ~File();
using Stream::init;
virtual ::FLAC__StreamDecoderInitStatus init(FILE *file);
virtual ::FLAC__StreamDecoderInitStatus init(const char *filename);
virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename);
using Stream::init_ogg;
virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file);
virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename);
virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename);
protected:
// this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
private:
// Private and undefined so you can't use them:
File(const File &);
void operator=(const File &);
};
}
}
#endif
export.h
This module contains #defines and symbols for exporting function calls, and providing version informa...
FLAC::Decoder::File
This class wraps the FLAC__StreamDecoder. If you are not decoding from a file, you may need to use FL...
Definition decoder.h:230
FLAC::Decoder::File::init
virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename)
See FLAC__stream_decoder_init_file()
FLAC::Decoder::File::init_ogg
virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename)
See FLAC__stream_decoder_init_ogg_file()
FLAC::Decoder::File::init
virtual ::FLAC__StreamDecoderInitStatus init(const char *filename)
See FLAC__stream_decoder_init_file()
FLAC::Decoder::File::read_callback
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes)
see FLAC__StreamDecoderReadCallback
FLAC::Decoder::File::init
virtual ::FLAC__StreamDecoderInitStatus init(FILE *file)
See FLAC__stream_decoder_init_FILE()
FLAC::Decoder::File::init_ogg
virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file)
See FLAC__stream_decoder_init_ogg_FILE()
FLAC::Decoder::File::init_ogg
virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename)
See FLAC__stream_decoder_init_ogg_file()
FLAC::Decoder::Stream::State
Definition decoder.h:104
FLAC::Decoder::Stream
This class wraps the FLAC__StreamDecoder. If you are decoding from a file, FLAC::Decoder::File may be...
Definition decoder.h:100
FLAC::Decoder::Stream::tell_callback
virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset)
see FLAC__StreamDecoderTellCallback
FLAC::Decoder::Stream::finish
virtual bool finish()
See FLAC__stream_decoder_finish()
FLAC::Decoder::Stream::is_valid
virtual bool is_valid() const
FLAC::Decoder::Stream::skip_single_link
virtual bool skip_single_link()
See FLAC__stream_decoder_skip_single_link()
FLAC::Decoder::Stream::error_callback
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status)=0
see FLAC__StreamDecoderErrorCallback
FLAC::Decoder::Stream::get_sample_rate
virtual uint32_t get_sample_rate() const
See FLAC__stream_decoder_get_sample_rate()
FLAC::Decoder::Stream::metadata_callback
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata)
see FLAC__StreamDecoderMetadataCallback
FLAC::Decoder::Stream::set_metadata_respond_all
virtual bool set_metadata_respond_all()
See FLAC__stream_decoder_set_metadata_respond_all()
FLAC::Decoder::Stream::skip_single_frame
virtual bool skip_single_frame()
See FLAC__stream_decoder_skip_single_frame()
FLAC::Decoder::Stream::init
virtual ::FLAC__StreamDecoderInitStatus init()
Seek FLAC__stream_decoder_init_stream()
FLAC::Decoder::Stream::get_decode_position
virtual bool get_decode_position(FLAC__uint64 *position) const
See FLAC__stream_decoder_get_decode_position()
FLAC::Decoder::Stream::set_decode_chained_stream
virtual bool set_decode_chained_stream(bool value)
See FLAC__stream_decoder_set_decode_chained_stream()
FLAC::Decoder::Stream::get_md5_checking
virtual bool get_md5_checking() const
See FLAC__stream_decoder_get_md5_checking()
FLAC::Decoder::Stream::get_bits_per_sample
virtual uint32_t get_bits_per_sample() const
See FLAC__stream_decoder_get_bits_per_sample()
FLAC::Decoder::Stream::get_channels
virtual uint32_t get_channels() const
See FLAC__stream_decoder_get_channels()
FLAC::Decoder::Stream::get_link_lengths
virtual int32_t get_link_lengths(FLAC__uint64 **link_lengths)
See FLAC__stream_decoder_get_link_lengths()
FLAC::Decoder::Stream::length_callback
virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length)
see FLAC__StreamDecoderLengthCallback
FLAC::Decoder::Stream::process_until_end_of_link
virtual bool process_until_end_of_link()
See FLAC__stream_decoder_process_until_end_of_link()
FLAC::Decoder::Stream::get_blocksize
virtual uint32_t get_blocksize() const
See FLAC__stream_decoder_get_blocksize()
FLAC::Decoder::Stream::get_channel_assignment
virtual ::FLAC__ChannelAssignment get_channel_assignment() const
See FLAC__stream_decoder_get_channel_assignment()
FLAC::Decoder::Stream::reset
virtual bool reset()
See FLAC__stream_decoder_reset()
FLAC::Decoder::Stream::set_md5_checking
virtual bool set_md5_checking(bool value)
See FLAC__stream_decoder_set_md5_checking()
FLAC::Decoder::Stream::set_metadata_ignore_all
virtual bool set_metadata_ignore_all()
See FLAC__stream_decoder_set_metadata_ignore_all()
FLAC::Decoder::Stream::find_total_samples
virtual FLAC__uint64 find_total_samples()
See FLAC__stream_decoder_find_total_samples()
FLAC::Decoder::Stream::set_metadata_respond
virtual bool set_metadata_respond(::FLAC__MetadataType type)
See FLAC__stream_decoder_set_metadata_respond()
FLAC::Decoder::Stream::set_metadata_respond_application
virtual bool set_metadata_respond_application(const FLAC__byte id[4])
See FLAC__stream_decoder_set_metadata_respond_application()
FLAC::Decoder::Stream::flush
virtual bool flush()
See FLAC__stream_decoder_flush()
FLAC::Decoder::Stream::finish_link
virtual bool finish_link()
See FLAC__stream_decoder_finish_link()
FLAC::Decoder::Stream::set_ogg_serial_number
virtual bool set_ogg_serial_number(long value)
See FLAC__stream_decoder_set_ogg_serial_number()
FLAC::Decoder::Stream::process_until_end_of_metadata
virtual bool process_until_end_of_metadata()
See FLAC__stream_decoder_process_until_end_of_metadata()
FLAC::Decoder::Stream::process_single
virtual bool process_single()
See FLAC__stream_decoder_process_single()
FLAC::Decoder::Stream::get_decode_chained_stream
virtual bool get_decode_chained_stream() const
See FLAC__stream_decoder_get_decode_chained_stream()
FLAC::Decoder::Stream::get_state
State get_state() const
See FLAC__stream_decoder_get_state()
FLAC::Decoder::Stream::eof_callback
virtual bool eof_callback()
see FLAC__StreamDecoderEofCallback
FLAC::Decoder::Stream::seek_absolute
virtual bool seek_absolute(FLAC__uint64 sample)
See FLAC__stream_decoder_seek_absolute()
FLAC::Decoder::Stream::get_total_samples
virtual FLAC__uint64 get_total_samples() const
See FLAC__stream_decoder_get_total_samples()
FLAC::Decoder::Stream::set_metadata_ignore_application
virtual bool set_metadata_ignore_application(const FLAC__byte id[4])
See FLAC__stream_decoder_set_metadata_ignore_application()
FLAC::Decoder::Stream::init_ogg
virtual ::FLAC__StreamDecoderInitStatus init_ogg()
Seek FLAC__stream_decoder_init_ogg_stream()
FLAC::Decoder::Stream::set_metadata_ignore
virtual bool set_metadata_ignore(::FLAC__MetadataType type)
See FLAC__stream_decoder_set_metadata_ignore()
FLAC::Decoder::Stream::write_callback
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[])=0
see FLAC__StreamDecoderWriteCallback
FLAC::Decoder::Stream::seek_callback
virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset)
see FLAC__StreamDecoderSeekCallback
FLAC::Decoder::Stream::read_callback
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes)=0
see FLAC__StreamDecoderReadCallback
FLAC::Decoder::Stream::process_until_end_of_stream
virtual bool process_until_end_of_stream()
See FLAC__stream_decoder_process_until_end_of_stream()
FLAC__MetadataType
FLAC__MetadataType
Definition format.h:496
FLAC__StreamDecoderErrorStatus
FLAC__StreamDecoderErrorStatus
Definition stream_decoder.h:444
FLAC__StreamDecoderState
FLAC__StreamDecoderState
Definition stream_decoder.h:202
FLACPP_API
#define FLACPP_API
Definition export.h:88
stream_decoder.h
This module contains the functions which implement the stream decoder.
FLAC__StreamDecoder
Definition stream_decoder.h:495

Copyright (c) 2000-2009 Josh Coalson Copyright (c) 2011-2025 Xiph.Org Foundation