annotate src/flac-1.2.1/include/FLAC++/encoder.h @ 93:5fcdb63f4cc6

Add sord, serd
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:23:43 +0000
parents 98c1576536ae
children
rev   line source
cannam@86 1 /* libFLAC++ - Free Lossless Audio Codec library
cannam@86 2 * Copyright (C) 2002,2003,2004,2005,2006,2007 Josh Coalson
cannam@86 3 *
cannam@86 4 * Redistribution and use in source and binary forms, with or without
cannam@86 5 * modification, are permitted provided that the following conditions
cannam@86 6 * are met:
cannam@86 7 *
cannam@86 8 * - Redistributions of source code must retain the above copyright
cannam@86 9 * notice, this list of conditions and the following disclaimer.
cannam@86 10 *
cannam@86 11 * - Redistributions in binary form must reproduce the above copyright
cannam@86 12 * notice, this list of conditions and the following disclaimer in the
cannam@86 13 * documentation and/or other materials provided with the distribution.
cannam@86 14 *
cannam@86 15 * - Neither the name of the Xiph.org Foundation nor the names of its
cannam@86 16 * contributors may be used to endorse or promote products derived from
cannam@86 17 * this software without specific prior written permission.
cannam@86 18 *
cannam@86 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
cannam@86 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
cannam@86 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
cannam@86 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
cannam@86 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
cannam@86 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
cannam@86 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
cannam@86 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
cannam@86 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
cannam@86 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
cannam@86 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cannam@86 30 */
cannam@86 31
cannam@86 32 #ifndef FLACPP__ENCODER_H
cannam@86 33 #define FLACPP__ENCODER_H
cannam@86 34
cannam@86 35 #include "export.h"
cannam@86 36
cannam@86 37 #include "FLAC/stream_encoder.h"
cannam@86 38 #include "decoder.h"
cannam@86 39 #include "metadata.h"
cannam@86 40
cannam@86 41
cannam@86 42 /** \file include/FLAC++/encoder.h
cannam@86 43 *
cannam@86 44 * \brief
cannam@86 45 * This module contains the classes which implement the various
cannam@86 46 * encoders.
cannam@86 47 *
cannam@86 48 * See the detailed documentation in the
cannam@86 49 * \link flacpp_encoder encoder \endlink module.
cannam@86 50 */
cannam@86 51
cannam@86 52 /** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes
cannam@86 53 * \ingroup flacpp
cannam@86 54 *
cannam@86 55 * \brief
cannam@86 56 * This module describes the encoder layers provided by libFLAC++.
cannam@86 57 *
cannam@86 58 * The libFLAC++ encoder classes are object wrappers around their
cannam@86 59 * counterparts in libFLAC. All encoding layers available in
cannam@86 60 * libFLAC are also provided here. The interface is very similar;
cannam@86 61 * make sure to read the \link flac_encoder libFLAC encoder module \endlink.
cannam@86 62 *
cannam@86 63 * There are only two significant differences here. First, instead of
cannam@86 64 * passing in C function pointers for callbacks, you inherit from the
cannam@86 65 * encoder class and provide implementations for the callbacks in your
cannam@86 66 * derived class; because of this there is no need for a 'client_data'
cannam@86 67 * property.
cannam@86 68 *
cannam@86 69 * Second, there are two stream encoder classes. FLAC::Encoder::Stream
cannam@86 70 * is used for the same cases that FLAC__stream_encoder_init_stream() /
cannam@86 71 * FLAC__stream_encoder_init_ogg_stream() are used, and FLAC::Encoder::File
cannam@86 72 * is used for the same cases that
cannam@86 73 * FLAC__stream_encoder_init_FILE() and FLAC__stream_encoder_init_file() /
cannam@86 74 * FLAC__stream_encoder_init_ogg_FILE() and FLAC__stream_encoder_init_ogg_file()
cannam@86 75 * are used.
cannam@86 76 */
cannam@86 77
cannam@86 78 namespace FLAC {
cannam@86 79 namespace Encoder {
cannam@86 80
cannam@86 81 /** \ingroup flacpp_encoder
cannam@86 82 * \brief
cannam@86 83 * This class wraps the ::FLAC__StreamEncoder. If you are
cannam@86 84 * encoding to a file, FLAC::Encoder::File may be more
cannam@86 85 * convenient.
cannam@86 86 *
cannam@86 87 * The usage of this class is similar to FLAC__StreamEncoder,
cannam@86 88 * except instead of providing callbacks to
cannam@86 89 * FLAC__stream_encoder_init*_stream(), you will inherit from this
cannam@86 90 * class and override the virtual callback functions with your
cannam@86 91 * own implementations, then call init() or init_ogg(). The rest of
cannam@86 92 * the calls work the same as in the C layer.
cannam@86 93 *
cannam@86 94 * Only the write callback is mandatory. The others are
cannam@86 95 * optional; this class provides default implementations that do
cannam@86 96 * nothing. In order for some STREAMINFO and SEEKTABLE data to
cannam@86 97 * be written properly, you must overide seek_callback() and
cannam@86 98 * tell_callback(); see FLAC__stream_encoder_init_stream() as to
cannam@86 99 * why.
cannam@86 100 */
cannam@86 101 class FLACPP_API Stream {
cannam@86 102 public:
cannam@86 103 /** This class is a wrapper around FLAC__StreamEncoderState.
cannam@86 104 */
cannam@86 105 class FLACPP_API State {
cannam@86 106 public:
cannam@86 107 inline State(::FLAC__StreamEncoderState state): state_(state) { }
cannam@86 108 inline operator ::FLAC__StreamEncoderState() const { return state_; }
cannam@86 109 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
cannam@86 110 inline const char *resolved_as_cstring(const Stream &encoder) const { return ::FLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); }
cannam@86 111 protected:
cannam@86 112 ::FLAC__StreamEncoderState state_;
cannam@86 113 };
cannam@86 114
cannam@86 115 Stream();
cannam@86 116 virtual ~Stream();
cannam@86 117
cannam@86 118 //@{
cannam@86 119 /** Call after construction to check the that the object was created
cannam@86 120 * successfully. If not, use get_state() to find out why not.
cannam@86 121 *
cannam@86 122 */
cannam@86 123 virtual bool is_valid() const;
cannam@86 124 inline operator bool() const { return is_valid(); } ///< See is_valid()
cannam@86 125 //@}
cannam@86 126
cannam@86 127 virtual bool set_ogg_serial_number(long value); ///< See FLAC__stream_encoder_set_ogg_serial_number()
cannam@86 128 virtual bool set_verify(bool value); ///< See FLAC__stream_encoder_set_verify()
cannam@86 129 virtual bool set_streamable_subset(bool value); ///< See FLAC__stream_encoder_set_streamable_subset()
cannam@86 130 virtual bool set_channels(unsigned value); ///< See FLAC__stream_encoder_set_channels()
cannam@86 131 virtual bool set_bits_per_sample(unsigned value); ///< See FLAC__stream_encoder_set_bits_per_sample()
cannam@86 132 virtual bool set_sample_rate(unsigned value); ///< See FLAC__stream_encoder_set_sample_rate()
cannam@86 133 virtual bool set_compression_level(unsigned value); ///< See FLAC__stream_encoder_set_compression_level()
cannam@86 134 virtual bool set_blocksize(unsigned value); ///< See FLAC__stream_encoder_set_blocksize()
cannam@86 135 virtual bool set_do_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_do_mid_side_stereo()
cannam@86 136 virtual bool set_loose_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_loose_mid_side_stereo()
cannam@86 137 virtual bool set_apodization(const char *specification); ///< See FLAC__stream_encoder_set_apodization()
cannam@86 138 virtual bool set_max_lpc_order(unsigned value); ///< See FLAC__stream_encoder_set_max_lpc_order()
cannam@86 139 virtual bool set_qlp_coeff_precision(unsigned value); ///< See FLAC__stream_encoder_set_qlp_coeff_precision()
cannam@86 140 virtual bool set_do_qlp_coeff_prec_search(bool value); ///< See FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
cannam@86 141 virtual bool set_do_escape_coding(bool value); ///< See FLAC__stream_encoder_set_do_escape_coding()
cannam@86 142 virtual bool set_do_exhaustive_model_search(bool value); ///< See FLAC__stream_encoder_set_do_exhaustive_model_search()
cannam@86 143 virtual bool set_min_residual_partition_order(unsigned value); ///< See FLAC__stream_encoder_set_min_residual_partition_order()
cannam@86 144 virtual bool set_max_residual_partition_order(unsigned value); ///< See FLAC__stream_encoder_set_max_residual_partition_order()
cannam@86 145 virtual bool set_rice_parameter_search_dist(unsigned value); ///< See FLAC__stream_encoder_set_rice_parameter_search_dist()
cannam@86 146 virtual bool set_total_samples_estimate(FLAC__uint64 value); ///< See FLAC__stream_encoder_set_total_samples_estimate()
cannam@86 147 virtual bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks); ///< See FLAC__stream_encoder_set_metadata()
cannam@86 148 virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks); ///< See FLAC__stream_encoder_set_metadata()
cannam@86 149
cannam@86 150 /* get_state() is not virtual since we want subclasses to be able to return their own state */
cannam@86 151 State get_state() const; ///< See FLAC__stream_encoder_get_state()
cannam@86 152 virtual Decoder::Stream::State get_verify_decoder_state() const; ///< See FLAC__stream_encoder_get_verify_decoder_state()
cannam@86 153 virtual void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got); ///< See FLAC__stream_encoder_get_verify_decoder_error_stats()
cannam@86 154 virtual bool get_verify() const; ///< See FLAC__stream_encoder_get_verify()
cannam@86 155 virtual bool get_streamable_subset() const; ///< See FLAC__stream_encoder_get_streamable_subset()
cannam@86 156 virtual bool get_do_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_do_mid_side_stereo()
cannam@86 157 virtual bool get_loose_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_loose_mid_side_stereo()
cannam@86 158 virtual unsigned get_channels() const; ///< See FLAC__stream_encoder_get_channels()
cannam@86 159 virtual unsigned get_bits_per_sample() const; ///< See FLAC__stream_encoder_get_bits_per_sample()
cannam@86 160 virtual unsigned get_sample_rate() const; ///< See FLAC__stream_encoder_get_sample_rate()
cannam@86 161 virtual unsigned get_blocksize() const; ///< See FLAC__stream_encoder_get_blocksize()
cannam@86 162 virtual unsigned get_max_lpc_order() const; ///< See FLAC__stream_encoder_get_max_lpc_order()
cannam@86 163 virtual unsigned get_qlp_coeff_precision() const; ///< See FLAC__stream_encoder_get_qlp_coeff_precision()
cannam@86 164 virtual bool get_do_qlp_coeff_prec_search() const; ///< See FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
cannam@86 165 virtual bool get_do_escape_coding() const; ///< See FLAC__stream_encoder_get_do_escape_coding()
cannam@86 166 virtual bool get_do_exhaustive_model_search() const; ///< See FLAC__stream_encoder_get_do_exhaustive_model_search()
cannam@86 167 virtual unsigned get_min_residual_partition_order() const; ///< See FLAC__stream_encoder_get_min_residual_partition_order()
cannam@86 168 virtual unsigned get_max_residual_partition_order() const; ///< See FLAC__stream_encoder_get_max_residual_partition_order()
cannam@86 169 virtual unsigned get_rice_parameter_search_dist() const; ///< See FLAC__stream_encoder_get_rice_parameter_search_dist()
cannam@86 170 virtual FLAC__uint64 get_total_samples_estimate() const; ///< See FLAC__stream_encoder_get_total_samples_estimate()
cannam@86 171
cannam@86 172 virtual ::FLAC__StreamEncoderInitStatus init(); ///< See FLAC__stream_encoder_init_stream()
cannam@86 173 virtual ::FLAC__StreamEncoderInitStatus init_ogg(); ///< See FLAC__stream_encoder_init_ogg_stream()
cannam@86 174
cannam@86 175 virtual bool finish(); ///< See FLAC__stream_encoder_finish()
cannam@86 176
cannam@86 177 virtual bool process(const FLAC__int32 * const buffer[], unsigned samples); ///< See FLAC__stream_encoder_process()
cannam@86 178 virtual bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); ///< See FLAC__stream_encoder_process_interleaved()
cannam@86 179 protected:
cannam@86 180 /// See FLAC__StreamEncoderReadCallback
cannam@86 181 virtual ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
cannam@86 182
cannam@86 183 /// See FLAC__StreamEncoderWriteCallback
cannam@86 184 virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame) = 0;
cannam@86 185
cannam@86 186 /// See FLAC__StreamEncoderSeekCallback
cannam@86 187 virtual ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
cannam@86 188
cannam@86 189 /// See FLAC__StreamEncoderTellCallback
cannam@86 190 virtual ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
cannam@86 191
cannam@86 192 /// See FLAC__StreamEncoderMetadataCallback
cannam@86 193 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
cannam@86 194
cannam@86 195 #if (defined _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
cannam@86 196 // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
cannam@86 197 friend State;
cannam@86 198 #endif
cannam@86 199 ::FLAC__StreamEncoder *encoder_;
cannam@86 200
cannam@86 201 static ::FLAC__StreamEncoderReadStatus read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
cannam@86 202 static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
cannam@86 203 static ::FLAC__StreamEncoderSeekStatus seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
cannam@86 204 static ::FLAC__StreamEncoderTellStatus tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
cannam@86 205 static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
cannam@86 206 private:
cannam@86 207 // Private and undefined so you can't use them:
cannam@86 208 Stream(const Stream &);
cannam@86 209 void operator=(const Stream &);
cannam@86 210 };
cannam@86 211
cannam@86 212 /** \ingroup flacpp_encoder
cannam@86 213 * \brief
cannam@86 214 * This class wraps the ::FLAC__StreamEncoder. If you are
cannam@86 215 * not encoding to a file, you may need to use
cannam@86 216 * FLAC::Encoder::Stream.
cannam@86 217 *
cannam@86 218 * The usage of this class is similar to FLAC__StreamEncoder,
cannam@86 219 * except instead of providing callbacks to
cannam@86 220 * FLAC__stream_encoder_init*_FILE() or
cannam@86 221 * FLAC__stream_encoder_init*_file(), you will inherit from this
cannam@86 222 * class and override the virtual callback functions with your
cannam@86 223 * own implementations, then call init() or init_ogg(). The rest
cannam@86 224 * of the calls work the same as in the C layer.
cannam@86 225 *
cannam@86 226 * There are no mandatory callbacks; all the callbacks from
cannam@86 227 * FLAC::Encoder::Stream are implemented here fully and support
cannam@86 228 * full post-encode STREAMINFO and SEEKTABLE updating. There is
cannam@86 229 * only an optional progress callback which you may override to
cannam@86 230 * get periodic reports on the progress of the encode.
cannam@86 231 */
cannam@86 232 class FLACPP_API File: public Stream {
cannam@86 233 public:
cannam@86 234 File();
cannam@86 235 virtual ~File();
cannam@86 236
cannam@86 237 virtual ::FLAC__StreamEncoderInitStatus init(FILE *file); ///< See FLAC__stream_encoder_init_FILE()
cannam@86 238 virtual ::FLAC__StreamEncoderInitStatus init(const char *filename); ///< See FLAC__stream_encoder_init_file()
cannam@86 239 virtual ::FLAC__StreamEncoderInitStatus init(const std::string &filename); ///< See FLAC__stream_encoder_init_file()
cannam@86 240 virtual ::FLAC__StreamEncoderInitStatus init_ogg(FILE *file); ///< See FLAC__stream_encoder_init_ogg_FILE()
cannam@86 241 virtual ::FLAC__StreamEncoderInitStatus init_ogg(const char *filename); ///< See FLAC__stream_encoder_init_ogg_file()
cannam@86 242 virtual ::FLAC__StreamEncoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_encoder_init_ogg_file()
cannam@86 243 protected:
cannam@86 244 /// See FLAC__StreamEncoderProgressCallback
cannam@86 245 virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
cannam@86 246
cannam@86 247 /// This is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
cannam@86 248 virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame);
cannam@86 249 private:
cannam@86 250 static void progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
cannam@86 251
cannam@86 252 // Private and undefined so you can't use them:
cannam@86 253 File(const Stream &);
cannam@86 254 void operator=(const Stream &);
cannam@86 255 };
cannam@86 256
cannam@86 257 }
cannam@86 258 }
cannam@86 259
cannam@86 260 #endif