annotate osx/include/FLAC++/encoder.h @ 83:ae30d91d2ffe

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