decoder.h
Go to the documentation of this file.
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
* Copyright (C) 2011-2013 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_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_md5_checking() const;
virtual FLAC__uint64 get_total_samples() const;
virtual unsigned get_channels() const;
virtual ::FLAC__ChannelAssignment get_channel_assignment() const;
virtual unsigned get_bits_per_sample() const;
virtual unsigned get_sample_rate() const;
virtual unsigned get_blocksize() const;
virtual bool get_decode_position(FLAC__uint64 *position) const;
virtual ::FLAC__StreamDecoderInitStatus init();
virtual ::FLAC__StreamDecoderInitStatus init_ogg();
virtual bool finish();
virtual bool flush();
virtual bool reset();
virtual bool process_single();
virtual bool process_until_end_of_metadata();
virtual bool process_until_end_of_stream();
virtual bool skip_single_frame();
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 _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
// lame hack: some MSVC/GCC versions 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();
virtual ::FLAC__StreamDecoderInitStatus init(FILE *file);
virtual ::FLAC__StreamDecoderInitStatus init(const char *filename);
virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename);
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

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