include/OggFLAC++/encoder.h Source File

Main Page Modules Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# include/OggFLAC++/encoder.h

Go to the documentation of this file.

    00001 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
    00002  * Copyright (C) 2002,2003,2004,2005  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 OggFLACPP__ENCODER_H
    00033 #define OggFLACPP__ENCODER_H
    00034
    00035 #include "export.h"
    00036
    00037 #include "OggFLAC/file_encoder.h"
    00038 #include "OggFLAC/seekable_stream_encoder.h"
    00039 #include "OggFLAC/stream_encoder.h"
    00040 #include "decoder.h"
    00041 // we only need these for the state abstractions really...
    00042 #include "FLAC++/decoder.h"
    00043 #include "FLAC++/encoder.h"
    00044
    00045
    00073 namespace OggFLAC {
    00074     namespace Encoder {
    00075
    00076         // ============================================================
    00077         //
    00078         //  Equivalent: OggFLAC__StreamEncoder
    00079         //
    00080         // ============================================================
    00081
    00095         class OggFLACPP_API Stream {
    00096         public:
    00097             class OggFLACPP_API State {
    00098             public:
    00099                 inline State(::OggFLAC__StreamEncoderState state): state_(state) { }
    00100                 inline operator ::OggFLAC__StreamEncoderState() const { return state_; }
    00101                 inline const char *as_cstring() const { return ::OggFLAC__StreamEncoderStateString[state_]; }
    00102                 inline const char *resolved_as_cstring(const Stream &encoder) const { return ::OggFLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); }
    00103             protected:
    00104                 ::OggFLAC__StreamEncoderState state_;
    00105             };
    00106
    00107             Stream();
    00108             virtual ~Stream();
    00109
    00110             bool is_valid() const;
    00111             inline operator bool() const { return is_valid(); }
    00112
    00113             bool set_serial_number(long value);
    00114             bool set_verify(bool value);
    00115             bool set_streamable_subset(bool value);
    00116             bool set_do_mid_side_stereo(bool value);
    00117             bool set_loose_mid_side_stereo(bool value);
    00118             bool set_channels(unsigned value);
    00119             bool set_bits_per_sample(unsigned value);
    00120             bool set_sample_rate(unsigned value);
    00121             bool set_blocksize(unsigned value);
    00122             bool set_max_lpc_order(unsigned value);
    00123             bool set_qlp_coeff_precision(unsigned value);
    00124             bool set_do_qlp_coeff_prec_search(bool value);
    00125             bool set_do_escape_coding(bool value);
    00126             bool set_do_exhaustive_model_search(bool value);
    00127             bool set_min_residual_partition_order(unsigned value);
    00128             bool set_max_residual_partition_order(unsigned value);
    00129             bool set_rice_parameter_search_dist(unsigned value);
    00130             bool set_total_samples_estimate(FLAC__uint64 value);
    00131             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
    00132
    00133             State    get_state() const;
    00134             FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
    00135             FLAC::Decoder::Stream::State get_verify_decoder_state() const;
    00136             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
    00137             bool     get_verify() const;
    00138             bool     get_streamable_subset() const;
    00139             bool     get_do_mid_side_stereo() const;
    00140             bool     get_loose_mid_side_stereo() const;
    00141             unsigned get_channels() const;
    00142             unsigned get_bits_per_sample() const;
    00143             unsigned get_sample_rate() const;
    00144             unsigned get_blocksize() const;
    00145             unsigned get_max_lpc_order() const;
    00146             unsigned get_qlp_coeff_precision() const;
    00147             bool     get_do_qlp_coeff_prec_search() const;
    00148             bool     get_do_escape_coding() const;
    00149             bool     get_do_exhaustive_model_search() const;
    00150             unsigned get_min_residual_partition_order() const;
    00151             unsigned get_max_residual_partition_order() const;
    00152             unsigned get_rice_parameter_search_dist() const;
    00153             FLAC__uint64 get_total_samples_estimate() const;
    00154
    00155             State init();
    00156
    00157             void finish();
    00158
    00159             bool process(const FLAC__int32 * const buffer[], unsigned samples);
    00160             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
    00161         protected:
    00162             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
    00163             virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
    00164
    00165 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
    00166             // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
    00167             friend State;
    00168 #endif
    00169             ::OggFLAC__StreamEncoder *encoder_;
    00170         private:
    00171             static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
    00172             static void metadata_callback_(const ::OggFLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
    00173
    00174             // Private and undefined so you can't use them:
    00175             Stream(const Stream &);
    00176             void operator=(const Stream &);
    00177         };
    00178
    00179         /* \} */
    00180
    00194         class OggFLACPP_API SeekableStream {
    00195         public:
    00196             class OggFLACPP_API State {
    00197             public:
    00198                 inline State(::OggFLAC__SeekableStreamEncoderState state): state_(state) { }
    00199                 inline operator ::OggFLAC__SeekableStreamEncoderState() const { return state_; }
    00200                 inline const char *as_cstring() const { return ::OggFLAC__SeekableStreamEncoderStateString[state_]; }
    00201                 inline const char *resolved_as_cstring(const SeekableStream &encoder) const { return ::OggFLAC__seekable_stream_encoder_get_resolved_state_string(encoder.encoder_); }
    00202             protected:
    00203                 ::OggFLAC__SeekableStreamEncoderState state_;
    00204             };
    00205
    00206             SeekableStream();
    00207             virtual ~SeekableStream();
    00208
    00209             bool is_valid() const;
    00210             inline operator bool() const { return is_valid(); }
    00211
    00212             bool set_serial_number(long value);
    00213             bool set_verify(bool value);
    00214             bool set_streamable_subset(bool value);
    00215             bool set_do_mid_side_stereo(bool value);
    00216             bool set_loose_mid_side_stereo(bool value);
    00217             bool set_channels(unsigned value);
    00218             bool set_bits_per_sample(unsigned value);
    00219             bool set_sample_rate(unsigned value);
    00220             bool set_blocksize(unsigned value);
    00221             bool set_max_lpc_order(unsigned value);
    00222             bool set_qlp_coeff_precision(unsigned value);
    00223             bool set_do_qlp_coeff_prec_search(bool value);
    00224             bool set_do_escape_coding(bool value);
    00225             bool set_do_exhaustive_model_search(bool value);
    00226             bool set_min_residual_partition_order(unsigned value);
    00227             bool set_max_residual_partition_order(unsigned value);
    00228             bool set_rice_parameter_search_dist(unsigned value);
    00229             bool set_total_samples_estimate(FLAC__uint64 value);
    00230             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
    00231
    00232             State    get_state() const;
    00233             FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
    00234             FLAC::Decoder::Stream::State get_verify_decoder_state() const;
    00235             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
    00236             bool     get_verify() const;
    00237             bool     get_streamable_subset() const;
    00238             bool     get_do_mid_side_stereo() const;
    00239             bool     get_loose_mid_side_stereo() const;
    00240             unsigned get_channels() const;
    00241             unsigned get_bits_per_sample() const;
    00242             unsigned get_sample_rate() const;
    00243             unsigned get_blocksize() const;
    00244             unsigned get_max_lpc_order() const;
    00245             unsigned get_qlp_coeff_precision() const;
    00246             bool     get_do_qlp_coeff_prec_search() const;
    00247             bool     get_do_escape_coding() const;
    00248             bool     get_do_exhaustive_model_search() const;
    00249             unsigned get_min_residual_partition_order() const;
    00250             unsigned get_max_residual_partition_order() const;
    00251             unsigned get_rice_parameter_search_dist() const;
    00252             FLAC__uint64 get_total_samples_estimate() const;
    00253
    00254             State init();
    00255
    00256             void finish();
    00257
    00258             bool process(const FLAC__int32 * const buffer[], unsigned samples);
    00259             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
    00260         protected:
    00261             virtual ::OggFLAC__SeekableStreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
    00262             virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
    00263             virtual ::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
    00264             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
    00265
    00266 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
    00267             // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
    00268             friend State;
    00269 #endif
    00270             ::OggFLAC__SeekableStreamEncoder *encoder_;
    00271         private:
    00272             static ::OggFLAC__SeekableStreamEncoderReadStatus read_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
    00273             static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
    00274             static ::FLAC__SeekableStreamEncoderTellStatus tell_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
    00275             static ::FLAC__StreamEncoderWriteStatus write_callback_(const OggFLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
    00276
    00277             // Private and undefined so you can't use them:
    00278             SeekableStream(const SeekableStream &);
    00279             void operator=(const SeekableStream &);
    00280         };
    00281
    00282         /* \} */
    00283
    00297         class OggFLACPP_API File {
    00298         public:
    00299             class OggFLACPP_API State {
    00300             public:
    00301                 inline State(::OggFLAC__FileEncoderState state): state_(state) { }
    00302                 inline operator ::OggFLAC__FileEncoderState() const { return state_; }
    00303                 inline const char *as_cstring() const { return ::OggFLAC__FileEncoderStateString[state_]; }
    00304                 inline const char *resolved_as_cstring(const File &encoder) const { return ::OggFLAC__file_encoder_get_resolved_state_string(encoder.encoder_); }
    00305             protected:
    00306                 ::OggFLAC__FileEncoderState state_;
    00307             };
    00308
    00309             File();
    00310             virtual ~File();
    00311
    00312             bool is_valid() const;
    00313             inline operator bool() const { return is_valid(); }
    00314
    00315             bool set_serial_number(long value);
    00316             bool set_verify(bool value);
    00317             bool set_streamable_subset(bool value);
    00318             bool set_do_mid_side_stereo(bool value);
    00319             bool set_loose_mid_side_stereo(bool value);
    00320             bool set_channels(unsigned value);
    00321             bool set_bits_per_sample(unsigned value);
    00322             bool set_sample_rate(unsigned value);
    00323             bool set_blocksize(unsigned value);
    00324             bool set_max_lpc_order(unsigned value);
    00325             bool set_qlp_coeff_precision(unsigned value);
    00326             bool set_do_qlp_coeff_prec_search(bool value);
    00327             bool set_do_escape_coding(bool value);
    00328             bool set_do_exhaustive_model_search(bool value);
    00329             bool set_min_residual_partition_order(unsigned value);
    00330             bool set_max_residual_partition_order(unsigned value);
    00331             bool set_rice_parameter_search_dist(unsigned value);
    00332             bool set_total_samples_estimate(FLAC__uint64 value);
    00333             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
    00334             bool set_filename(const char *value);
    00335
    00336             State    get_state() const;
    00337             SeekableStream::State get_seekable_stream_encoder_state() const;
    00338             FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
    00339             FLAC::Decoder::Stream::State get_verify_decoder_state() const;
    00340             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
    00341             bool     get_verify() const;
    00342             bool     get_streamable_subset() const;
    00343             bool     get_do_mid_side_stereo() const;
    00344             bool     get_loose_mid_side_stereo() const;
    00345             unsigned get_channels() const;
    00346             unsigned get_bits_per_sample() const;
    00347             unsigned get_sample_rate() const;
    00348             unsigned get_blocksize() const;
    00349             unsigned get_max_lpc_order() const;
    00350             unsigned get_qlp_coeff_precision() const;
    00351             bool     get_do_qlp_coeff_prec_search() const;
    00352             bool     get_do_escape_coding() const;
    00353             bool     get_do_exhaustive_model_search() const;
    00354             unsigned get_min_residual_partition_order() const;
    00355             unsigned get_max_residual_partition_order() const;
    00356             unsigned get_rice_parameter_search_dist() const;
    00357             FLAC__uint64 get_total_samples_estimate() const;
    00358
    00359             State init();
    00360
    00361             void finish();
    00362
    00363             bool process(const FLAC__int32 * const buffer[], unsigned samples);
    00364             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
    00365         protected:
    00366             virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
    00367
    00368 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
    00369             // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
    00370             friend State;
    00371 #endif
    00372             ::OggFLAC__FileEncoder *encoder_;
    00373         private:
    00374             static void progress_callback_(const ::OggFLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
    00375
    00376             // Private and undefined so you can't use them:
    00377             File(const Stream &);
    00378             void operator=(const Stream &);
    00379         };
    00380
    00381         /* \} */
    00382
    00383     }
    00384 }
    00385
    00386 #endif