# decoder.h

Go to the documentation of this file.

    00001 /* libFLAC++ - Free Lossless Audio Codec library
    00002  * Copyright (C) 2002,2003,2004,2005,2006,2007  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 <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             /* get_state() is not virtual since we want subclasses to be able to return their own state */
    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             // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
    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             // Private and undefined so you can't use them:
    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             // this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
    00235             virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
    00236         private:
    00237             // Private and undefined so you can't use them:
    00238             File(const File &);
    00239             void operator=(const File &);
    00240         };
    00241
    00242     }
    00243 }
    00244
    00245 #endif

Copyright (c) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson |