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
00143 virtual ::FLAC__StreamDecoderInitStatus init();
00144 virtual ::FLAC__StreamDecoderInitStatus init_ogg();
00145
00146 virtual bool finish();
00147
00148 virtual bool flush();
00149 virtual bool reset();
00150
00151 virtual bool process_single();
00152 virtual bool process_until_end_of_metadata();
00153 virtual bool process_until_end_of_stream();
00154 virtual bool skip_single_frame();
00155
00156 virtual bool seek_absolute(FLAC__uint64 sample);
00157 protected:
00159 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0;
00160
00162 virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
00163
00165 virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
00166
00168 virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
00169
00171 virtual bool eof_callback();
00172
00174 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
00175
00177 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
00178
00180 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
00181
00182 #if (defined _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
00183
00184 friend State;
00185 #endif
00186 ::FLAC__StreamDecoder *decoder_;
00187
00188 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
00189 static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
00190 static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
00191 static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
00192 static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data);
00193 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
00194 static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
00195 static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
00196 private:
00197
00198 Stream(const Stream &);
00199 void operator=(const Stream &);
00200 };
00201
00221 class FLACPP_API File: public Stream {
00222 public:
00223 File();
00224 virtual ~File();
00225
00226 virtual ::FLAC__StreamDecoderInitStatus init(FILE *file);
00227 virtual ::FLAC__StreamDecoderInitStatus init(const char *filename);
00228 virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename);
00229 virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file);
00230 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename);
00231 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename);
00232 protected:
00233
00234 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
00235 private:
00236
00237 File(const File &);
00238 void operator=(const File &);
00239 };
00240
00241 }
00242 }
00243
00244 #endif