annotate osx/include/FLAC++/decoder.h @ 129:90a976269628

Updated MSVC
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 18 Oct 2016 15:58:42 +0100
parents dde06ec3df43
children
rev   line source
cannam@87 1 /* libFLAC++ - Free Lossless Audio Codec library
cannam@87 2 * Copyright (C) 2002,2003,2004,2005,2006,2007 Josh Coalson
cannam@87 3 *
cannam@87 4 * Redistribution and use in source and binary forms, with or without
cannam@87 5 * modification, are permitted provided that the following conditions
cannam@87 6 * are met:
cannam@87 7 *
cannam@87 8 * - Redistributions of source code must retain the above copyright
cannam@87 9 * notice, this list of conditions and the following disclaimer.
cannam@87 10 *
cannam@87 11 * - Redistributions in binary form must reproduce the above copyright
cannam@87 12 * notice, this list of conditions and the following disclaimer in the
cannam@87 13 * documentation and/or other materials provided with the distribution.
cannam@87 14 *
cannam@87 15 * - Neither the name of the Xiph.org Foundation nor the names of its
cannam@87 16 * contributors may be used to endorse or promote products derived from
cannam@87 17 * this software without specific prior written permission.
cannam@87 18 *
cannam@87 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
cannam@87 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
cannam@87 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
cannam@87 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
cannam@87 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
cannam@87 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
cannam@87 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
cannam@87 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
cannam@87 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
cannam@87 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
cannam@87 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cannam@87 30 */
cannam@87 31
cannam@87 32 #ifndef FLACPP__DECODER_H
cannam@87 33 #define FLACPP__DECODER_H
cannam@87 34
cannam@87 35 #include "export.h"
cannam@87 36
cannam@87 37 #include <string>
cannam@87 38 #include "FLAC/stream_decoder.h"
cannam@87 39
cannam@87 40
cannam@87 41 /** \file include/FLAC++/decoder.h
cannam@87 42 *
cannam@87 43 * \brief
cannam@87 44 * This module contains the classes which implement the various
cannam@87 45 * decoders.
cannam@87 46 *
cannam@87 47 * See the detailed documentation in the
cannam@87 48 * \link flacpp_decoder decoder \endlink module.
cannam@87 49 */
cannam@87 50
cannam@87 51 /** \defgroup flacpp_decoder FLAC++/decoder.h: decoder classes
cannam@87 52 * \ingroup flacpp
cannam@87 53 *
cannam@87 54 * \brief
cannam@87 55 * This module describes the decoder layers provided by libFLAC++.
cannam@87 56 *
cannam@87 57 * The libFLAC++ decoder classes are object wrappers around their
cannam@87 58 * counterparts in libFLAC. All decoding layers available in
cannam@87 59 * libFLAC are also provided here. The interface is very similar;
cannam@87 60 * make sure to read the \link flac_decoder libFLAC decoder module \endlink.
cannam@87 61 *
cannam@87 62 * There are only two significant differences here. First, instead of
cannam@87 63 * passing in C function pointers for callbacks, you inherit from the
cannam@87 64 * decoder class and provide implementations for the callbacks in your
cannam@87 65 * derived class; because of this there is no need for a 'client_data'
cannam@87 66 * property.
cannam@87 67 *
cannam@87 68 * Second, there are two stream decoder classes. FLAC::Decoder::Stream
cannam@87 69 * is used for the same cases that FLAC__stream_decoder_init_stream() /
cannam@87 70 * FLAC__stream_decoder_init_ogg_stream() are used, and FLAC::Decoder::File
cannam@87 71 * is used for the same cases that
cannam@87 72 * FLAC__stream_decoder_init_FILE() and FLAC__stream_decoder_init_file() /
cannam@87 73 * FLAC__stream_decoder_init_ogg_FILE() and FLAC__stream_decoder_init_ogg_file()
cannam@87 74 * are used.
cannam@87 75 */
cannam@87 76
cannam@87 77 namespace FLAC {
cannam@87 78 namespace Decoder {
cannam@87 79
cannam@87 80 /** \ingroup flacpp_decoder
cannam@87 81 * \brief
cannam@87 82 * This class wraps the ::FLAC__StreamDecoder. If you are
cannam@87 83 * decoding from a file, FLAC::Decoder::File may be more
cannam@87 84 * convenient.
cannam@87 85 *
cannam@87 86 * The usage of this class is similar to FLAC__StreamDecoder,
cannam@87 87 * except instead of providing callbacks to
cannam@87 88 * FLAC__stream_decoder_init*_stream(), you will inherit from this
cannam@87 89 * class and override the virtual callback functions with your
cannam@87 90 * own implementations, then call init() or init_ogg(). The rest
cannam@87 91 * of the calls work the same as in the C layer.
cannam@87 92 *
cannam@87 93 * Only the read, write, and error callbacks are mandatory. The
cannam@87 94 * others are optional; this class provides default
cannam@87 95 * implementations that do nothing. In order for seeking to work
cannam@87 96 * you must overide seek_callback(), tell_callback(),
cannam@87 97 * length_callback(), and eof_callback().
cannam@87 98 */
cannam@87 99 class FLACPP_API Stream {
cannam@87 100 public:
cannam@87 101 /** This class is a wrapper around FLAC__StreamDecoderState.
cannam@87 102 */
cannam@87 103 class FLACPP_API State {
cannam@87 104 public:
cannam@87 105 inline State(::FLAC__StreamDecoderState state): state_(state) { }
cannam@87 106 inline operator ::FLAC__StreamDecoderState() const { return state_; }
cannam@87 107 inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
cannam@87 108 inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
cannam@87 109 protected:
cannam@87 110 ::FLAC__StreamDecoderState state_;
cannam@87 111 };
cannam@87 112
cannam@87 113 Stream();
cannam@87 114 virtual ~Stream();
cannam@87 115
cannam@87 116 //@{
cannam@87 117 /** Call after construction to check the that the object was created
cannam@87 118 * successfully. If not, use get_state() to find out why not.
cannam@87 119 */
cannam@87 120 virtual bool is_valid() const;
cannam@87 121 inline operator bool() const { return is_valid(); } ///< See is_valid()
cannam@87 122 //@}
cannam@87 123
cannam@87 124 virtual bool set_ogg_serial_number(long value); ///< See FLAC__stream_decoder_set_ogg_serial_number()
cannam@87 125 virtual bool set_md5_checking(bool value); ///< See FLAC__stream_decoder_set_md5_checking()
cannam@87 126 virtual bool set_metadata_respond(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_respond()
cannam@87 127 virtual bool set_metadata_respond_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_respond_application()
cannam@87 128 virtual bool set_metadata_respond_all(); ///< See FLAC__stream_decoder_set_metadata_respond_all()
cannam@87 129 virtual bool set_metadata_ignore(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_ignore()
cannam@87 130 virtual bool set_metadata_ignore_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_ignore_application()
cannam@87 131 virtual bool set_metadata_ignore_all(); ///< See FLAC__stream_decoder_set_metadata_ignore_all()
cannam@87 132
cannam@87 133 /* get_state() is not virtual since we want subclasses to be able to return their own state */
cannam@87 134 State get_state() const; ///< See FLAC__stream_decoder_get_state()
cannam@87 135 virtual bool get_md5_checking() const; ///< See FLAC__stream_decoder_get_md5_checking()
cannam@87 136 virtual FLAC__uint64 get_total_samples() const; ///< See FLAC__stream_decoder_get_total_samples()
cannam@87 137 virtual unsigned get_channels() const; ///< See FLAC__stream_decoder_get_channels()
cannam@87 138 virtual ::FLAC__ChannelAssignment get_channel_assignment() const; ///< See FLAC__stream_decoder_get_channel_assignment()
cannam@87 139 virtual unsigned get_bits_per_sample() const; ///< See FLAC__stream_decoder_get_bits_per_sample()
cannam@87 140 virtual unsigned get_sample_rate() const; ///< See FLAC__stream_decoder_get_sample_rate()
cannam@87 141 virtual unsigned get_blocksize() const; ///< See FLAC__stream_decoder_get_blocksize()
cannam@87 142 virtual bool get_decode_position(FLAC__uint64 *position) const; ///< See FLAC__stream_decoder_get_decode_position()
cannam@87 143
cannam@87 144 virtual ::FLAC__StreamDecoderInitStatus init(); ///< Seek FLAC__stream_decoder_init_stream()
cannam@87 145 virtual ::FLAC__StreamDecoderInitStatus init_ogg(); ///< Seek FLAC__stream_decoder_init_ogg_stream()
cannam@87 146
cannam@87 147 virtual bool finish(); ///< See FLAC__stream_decoder_finish()
cannam@87 148
cannam@87 149 virtual bool flush(); ///< See FLAC__stream_decoder_flush()
cannam@87 150 virtual bool reset(); ///< See FLAC__stream_decoder_reset()
cannam@87 151
cannam@87 152 virtual bool process_single(); ///< See FLAC__stream_decoder_process_single()
cannam@87 153 virtual bool process_until_end_of_metadata(); ///< See FLAC__stream_decoder_process_until_end_of_metadata()
cannam@87 154 virtual bool process_until_end_of_stream(); ///< See FLAC__stream_decoder_process_until_end_of_stream()
cannam@87 155 virtual bool skip_single_frame(); ///< See FLAC__stream_decoder_skip_single_frame()
cannam@87 156
cannam@87 157 virtual bool seek_absolute(FLAC__uint64 sample); ///< See FLAC__stream_decoder_seek_absolute()
cannam@87 158 protected:
cannam@87 159 /// see FLAC__StreamDecoderReadCallback
cannam@87 160 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0;
cannam@87 161
cannam@87 162 /// see FLAC__StreamDecoderSeekCallback
cannam@87 163 virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
cannam@87 164
cannam@87 165 /// see FLAC__StreamDecoderTellCallback
cannam@87 166 virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
cannam@87 167
cannam@87 168 /// see FLAC__StreamDecoderLengthCallback
cannam@87 169 virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
cannam@87 170
cannam@87 171 /// see FLAC__StreamDecoderEofCallback
cannam@87 172 virtual bool eof_callback();
cannam@87 173
cannam@87 174 /// see FLAC__StreamDecoderWriteCallback
cannam@87 175 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
cannam@87 176
cannam@87 177 /// see FLAC__StreamDecoderMetadataCallback
cannam@87 178 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
cannam@87 179
cannam@87 180 /// see FLAC__StreamDecoderErrorCallback
cannam@87 181 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
cannam@87 182
cannam@87 183 #if (defined _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
cannam@87 184 // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
cannam@87 185 friend State;
cannam@87 186 #endif
cannam@87 187 ::FLAC__StreamDecoder *decoder_;
cannam@87 188
cannam@87 189 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
cannam@87 190 static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
cannam@87 191 static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
cannam@87 192 static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
cannam@87 193 static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data);
cannam@87 194 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
cannam@87 195 static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
cannam@87 196 static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
cannam@87 197 private:
cannam@87 198 // Private and undefined so you can't use them:
cannam@87 199 Stream(const Stream &);
cannam@87 200 void operator=(const Stream &);
cannam@87 201 };
cannam@87 202
cannam@87 203 /** \ingroup flacpp_decoder
cannam@87 204 * \brief
cannam@87 205 * This class wraps the ::FLAC__StreamDecoder. If you are
cannam@87 206 * not decoding from a file, you may need to use
cannam@87 207 * FLAC::Decoder::Stream.
cannam@87 208 *
cannam@87 209 * The usage of this class is similar to FLAC__StreamDecoder,
cannam@87 210 * except instead of providing callbacks to
cannam@87 211 * FLAC__stream_decoder_init*_FILE() or
cannam@87 212 * FLAC__stream_decoder_init*_file(), you will inherit from this
cannam@87 213 * class and override the virtual callback functions with your
cannam@87 214 * own implementations, then call init() or init_off(). The rest
cannam@87 215 * of the calls work the same as in the C layer.
cannam@87 216 *
cannam@87 217 * Only the write, and error callbacks from FLAC::Decoder::Stream
cannam@87 218 * are mandatory. The others are optional; this class provides
cannam@87 219 * full working implementations for all other callbacks and
cannam@87 220 * supports seeking.
cannam@87 221 */
cannam@87 222 class FLACPP_API File: public Stream {
cannam@87 223 public:
cannam@87 224 File();
cannam@87 225 virtual ~File();
cannam@87 226
cannam@87 227 virtual ::FLAC__StreamDecoderInitStatus init(FILE *file); ///< See FLAC__stream_decoder_init_FILE()
cannam@87 228 virtual ::FLAC__StreamDecoderInitStatus init(const char *filename); ///< See FLAC__stream_decoder_init_file()
cannam@87 229 virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename); ///< See FLAC__stream_decoder_init_file()
cannam@87 230 virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file); ///< See FLAC__stream_decoder_init_ogg_FILE()
cannam@87 231 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename); ///< See FLAC__stream_decoder_init_ogg_file()
cannam@87 232 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_decoder_init_ogg_file()
cannam@87 233 protected:
cannam@87 234 // this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
cannam@87 235 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
cannam@87 236 private:
cannam@87 237 // Private and undefined so you can't use them:
cannam@87 238 File(const File &);
cannam@87 239 void operator=(const File &);
cannam@87 240 };
cannam@87 241
cannam@87 242 }
cannam@87 243 }
cannam@87 244
cannam@87 245 #endif