annotate win64-mingw/include/FLAC++/decoder.h @ 36:55ece8862b6d

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