Main Page Modules Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# include/FLAC++/decoder.h

Go to the documentation of this file.

    00001 /* libFLAC++ - Free Lossless Audio Codec library
    00002  * Copyright (C) 2002,2003,2004,2005  Josh Coalson
    00003  *
    00004  * Redistribution and use in source and binary forms, with or without
    00005  * modification, are permitted provided that the following conditions
    00006  * are met:
    00007  *
    00008  * - Redistributions of source code must retain the above copyright
    00009  * notice, this list of conditions and the following disclaimer.
    00010  *
    00011  * - Redistributions in binary form must reproduce the above copyright
    00012  * notice, this list of conditions and the following disclaimer in the
    00013  * documentation and/or other materials provided with the distribution.
    00014  *
    00015  * - Neither the name of the Xiph.org Foundation nor the names of its
    00016  * contributors may be used to endorse or promote products derived from
    00017  * this software without specific prior written permission.
    00018  *
    00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    00020  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    00022  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
    00023  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    00024  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    00025  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    00026  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    00027  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    00028  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030  */
    00031
    00032 #ifndef FLACPP__DECODER_H
    00033 #define FLACPP__DECODER_H
    00034
    00035 #include "export.h"
    00036
    00037 #include "FLAC/file_decoder.h"
    00038 #include "FLAC/seekable_stream_decoder.h"
    00039 #include "FLAC/stream_decoder.h"
    00040
    00041
    00069 namespace FLAC {
    00070     namespace Decoder {
    00071
    00072         // ============================================================
    00073         //
    00074         //  Equivalent: FLAC__StreamDecoder
    00075         //
    00076         // ============================================================
    00077
    00091         class FLACPP_API Stream {
    00092         public:
    00093             class FLACPP_API State {
    00094             public:
    00095                 inline State(::FLAC__StreamDecoderState state): state_(state) { }
    00096                 inline operator ::FLAC__StreamDecoderState() const { return state_; }
    00097                 inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
    00098                 inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
    00099             protected:
    00100                 ::FLAC__StreamDecoderState state_;
    00101             };
    00102
    00103             Stream();
    00104             virtual ~Stream();
    00105
    00106             bool is_valid() const;
    00107             inline operator bool() const { return is_valid(); }
    00108
    00109             bool set_metadata_respond(::FLAC__MetadataType type);
    00110             bool set_metadata_respond_application(const FLAC__byte id[4]);
    00111             bool set_metadata_respond_all();
    00112             bool set_metadata_ignore(::FLAC__MetadataType type);
    00113             bool set_metadata_ignore_application(const FLAC__byte id[4]);
    00114             bool set_metadata_ignore_all();
    00115
    00116             State get_state() const;
    00117             unsigned get_channels() const;
    00118             ::FLAC__ChannelAssignment get_channel_assignment() const;
    00119             unsigned get_bits_per_sample() const;
    00120             unsigned get_sample_rate() const;
    00121             unsigned get_blocksize() const;
    00122
    00127             State init();
    00128
    00129             void finish();
    00130
    00131             bool flush();
    00132             bool reset();
    00133
    00134             bool process_single();
    00135             bool process_until_end_of_metadata();
    00136             bool process_until_end_of_stream();
    00137             bool skip_single_frame();
    00138         protected:
    00139             virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
    00140             virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
    00141             virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
    00142             virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
    00143
    00144 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
    00145             // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
    00146             friend State;
    00147 #endif
    00148             ::FLAC__StreamDecoder *decoder_;
    00149         private:
    00150             static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
    00151             static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
    00152             static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
    00153             static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
    00154
    00155             // Private and undefined so you can't use them:
    00156             Stream(const Stream &);
    00157             void operator=(const Stream &);
    00158         };
    00159
    00160         /* \} */
    00161
    00162         // ============================================================
    00163         //
    00164         //  Equivalent: FLAC__SeekableStreamDecoder
    00165         //
    00166         // ============================================================
    00167
    00181         class FLACPP_API SeekableStream {
    00182         public:
    00183             class FLACPP_API State {
    00184             public:
    00185                 inline State(::FLAC__SeekableStreamDecoderState state): state_(state) { }
    00186                 inline operator ::FLAC__SeekableStreamDecoderState() const { return state_; }
    00187                 inline const char *as_cstring() const { return ::FLAC__SeekableStreamDecoderStateString[state_]; }
    00188                 inline const char *resolved_as_cstring(const SeekableStream &decoder) const { return ::FLAC__seekable_stream_decoder_get_resolved_state_string(decoder.decoder_); }
    00189             protected:
    00190                 ::FLAC__SeekableStreamDecoderState state_;
    00191             };
    00192
    00193             SeekableStream();
    00194             virtual ~SeekableStream();
    00195
    00196             bool is_valid() const;
    00197             inline operator bool() const { return is_valid(); }
    00198
    00199             bool set_md5_checking(bool value);
    00200             bool set_metadata_respond(::FLAC__MetadataType type);
    00201             bool set_metadata_respond_application(const FLAC__byte id[4]);
    00202             bool set_metadata_respond_all();
    00203             bool set_metadata_ignore(::FLAC__MetadataType type);
    00204             bool set_metadata_ignore_application(const FLAC__byte id[4]);
    00205             bool set_metadata_ignore_all();
    00206
    00207             State get_state() const;
    00208             Stream::State get_stream_decoder_state() const;
    00209             bool get_md5_checking() const;
    00210             unsigned get_channels() const;
    00211             ::FLAC__ChannelAssignment get_channel_assignment() const;
    00212             unsigned get_bits_per_sample() const;
    00213             unsigned get_sample_rate() const;
    00214             unsigned get_blocksize() const;
    00215
    00216             State init();
    00217
    00218             bool finish();
    00219
    00220             bool flush();
    00221             bool reset();
    00222
    00223             bool process_single();
    00224             bool process_until_end_of_metadata();
    00225             bool process_until_end_of_stream();
    00226             bool skip_single_frame();
    00227
    00228             bool seek_absolute(FLAC__uint64 sample);
    00229         protected:
    00230             virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
    00231             virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
    00232             virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
    00233             virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
    00234             virtual bool eof_callback() = 0;
    00235             virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
    00236             virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
    00237             virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
    00238
    00239 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
    00240             // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
    00241             friend State;
    00242 #endif
    00243             ::FLAC__SeekableStreamDecoder *decoder_;
    00244         private:
    00245             static ::FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
    00246             static ::FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
    00247             static ::FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
    00248             static ::FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
    00249             static FLAC__bool eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data);
    00250             static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
    00251             static void metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
    00252             static void error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
    00253
    00254             // Private and undefined so you can't use them:
    00255             SeekableStream(const SeekableStream &);
    00256             void operator=(const SeekableStream &);
    00257         };
    00258
    00259         /* \} */
    00260
    00261         // ============================================================
    00262         //
    00263         //  Equivalent: FLAC__FileDecoder
    00264         //
    00265         // ============================================================
    00266
    00280         class FLACPP_API File {
    00281         public:
    00282             class FLACPP_API State {
    00283             public:
    00284                 inline State(::FLAC__FileDecoderState state): state_(state) { }
    00285                 inline operator ::FLAC__FileDecoderState() const { return state_; }
    00286                 inline const char *as_cstring() const { return ::FLAC__FileDecoderStateString[state_]; }
    00287                 inline const char *resolved_as_cstring(const File &decoder) const { return ::FLAC__file_decoder_get_resolved_state_string(decoder.decoder_); }
    00288             protected:
    00289                 ::FLAC__FileDecoderState state_;
    00290             };
    00291
    00292             File();
    00293             virtual ~File();
    00294
    00295             bool is_valid() const;
    00296             inline operator bool() const { return is_valid(); }
    00297
    00298             bool set_md5_checking(bool value);
    00299             bool set_filename(const char *value);
    00300             bool set_metadata_respond(::FLAC__MetadataType type);
    00301             bool set_metadata_respond_application(const FLAC__byte id[4]);
    00302             bool set_metadata_respond_all();
    00303             bool set_metadata_ignore(::FLAC__MetadataType type);
    00304             bool set_metadata_ignore_application(const FLAC__byte id[4]);
    00305             bool set_metadata_ignore_all();
    00306
    00307             State get_state() const;
    00308             SeekableStream::State get_seekable_stream_decoder_state() const;
    00309             Stream::State get_stream_decoder_state() const;
    00310             bool get_md5_checking() const;
    00311             unsigned get_channels() const;
    00312             ::FLAC__ChannelAssignment get_channel_assignment() const;
    00313             unsigned get_bits_per_sample() const;
    00314             unsigned get_sample_rate() const;
    00315             unsigned get_blocksize() const;
    00316
    00317             State init();
    00318
    00319             bool finish();
    00320
    00321             bool process_single();
    00322             bool process_until_end_of_metadata();
    00323             bool process_until_end_of_file();
    00324             bool skip_single_frame();
    00325
    00326             bool seek_absolute(FLAC__uint64 sample);
    00327         protected:
    00328             virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
    00329             virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
    00330             virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
    00331
    00332 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
    00333             // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
    00334             friend State;
    00335 #endif
    00336             ::FLAC__FileDecoder *decoder_;
    00337         private:
    00338             static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
    00339             static void metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
    00340             static void error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
    00341
    00342             // Private and undefined so you can't use them:
    00343             File(const File &);
    00344             void operator=(const File &);
    00345         };
    00346
    00347         /* \} */
    00348
    00349     }
    00350 }
    00351
    00352 #endif