00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef FLACPP__DECODER_H
00033 #define FLACPP__DECODER_H
00034
00035 #include "export.h"
00036
00037 #include <string>
00038 #include "FLAC/stream_decoder.h"
00039
00040
00077 namespace FLAC {
00078 namespace Decoder {
00079
00099 class FLACPP_API Stream {
00100 public:
00103 class FLACPP_API State {
00104 public:
00105 inline State(::FLAC__StreamDecoderState state): state_(state) { }
00106 inline operator ::FLAC__StreamDecoderState() const { return state_; }
00107 inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
00108 inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
00109 protected:
00110 ::FLAC__StreamDecoderState state_;
00111 };
00112
00113 Stream();
00114 virtual ~Stream();
00115
00117
00120 virtual bool is_valid() const;
00121 inline operator bool() const { return is_valid(); }
00122
00123
00124 virtual bool set_ogg_serial_number(long value);
00125 virtual bool set_md5_checking(bool value);
00126 virtual bool set_metadata_respond(::FLAC__MetadataType type);
00127 virtual bool set_metadata_respond_application(const FLAC__byte id[4]);
00128 virtual bool set_metadata_respond_all();
00129 virtual bool set_metadata_ignore(::FLAC__MetadataType type);
00130 virtual bool set_metadata_ignore_application(const FLAC__byte id[4]);
00131 virtual bool set_metadata_ignore_all();
00132
00133
00134 State get_state() const;
00135 virtual bool get_md5_checking() const;
00136 virtual FLAC__uint64 get_total_samples() const;
00137 virtual unsigned get_channels() const;
00138 virtual ::FLAC__ChannelAssignment get_channel_assignment() const;
00139 virtual unsigned get_bits_per_sample() const;
00140 virtual unsigned get_sample_rate() const;
00141 virtual unsigned get_blocksize() const;
00142 virtual bool get_decode_position(FLAC__uint64 *position) const;
00143
00144 virtual ::FLAC__StreamDecoderInitStatus init();
00145 virtual ::FLAC__StreamDecoderInitStatus init_ogg();
00146
00147 virtual bool finish();
00148
00149 virtual bool flush();
00150 virtual bool reset();
00151
00152 virtual bool process_single();
00153 virtual bool process_until_end_of_metadata();
00154 virtual bool process_until_end_of_stream();
00155 virtual bool skip_single_frame();
00156
00157 virtual bool seek_absolute(FLAC__uint64 sample);
00158 protected:
00160 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0;
00161
00163 virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
00164
00166 virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
00167
00169 virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
00170
00172 virtual bool eof_callback();
00173
00175 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
00176
00178 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
00179
00181 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
00182
00183 #if (defined _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
00184
00185 friend State;
00186 #endif
00187 ::FLAC__StreamDecoder *decoder_;
00188
00189 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
00190 static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
00191 static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
00192 static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
00193 static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data);
00194 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
00195 static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
00196 static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
00197 private:
00198
00199 Stream(const Stream &);
00200 void operator=(const Stream &);
00201 };
00202
00222 class FLACPP_API File: public Stream {
00223 public:
00224 File();
00225 virtual ~File();
00226
00227 virtual ::FLAC__StreamDecoderInitStatus init(FILE *file);
00228 virtual ::FLAC__StreamDecoderInitStatus init(const char *filename);
00229 virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename);
00230 virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file);
00231 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename);
00232 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename);
00233 protected:
00234
00235 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
00236 private:
00237
00238 File(const File &);
00239 void operator=(const File &);
00240 };
00241
00242 }
00243 }
00244
00245 #endif