~ubuntu-branches/ubuntu/karmic/flac/karmic

« back to all changes in this revision

Viewing changes to include/FLAC++/encoder.h

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libFLAC++ - Free Lossless Audio Codec library
2
 
 * Copyright (C) 2002,2003,2004,2005  Josh Coalson
 
2
 * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
3
3
 *
4
4
 * Redistribution and use in source and binary forms, with or without
5
5
 * modification, are permitted provided that the following conditions
34
34
 
35
35
#include "export.h"
36
36
 
37
 
#include "FLAC/file_encoder.h"
38
 
#include "FLAC/seekable_stream_encoder.h"
39
37
#include "FLAC/stream_encoder.h"
40
38
#include "decoder.h"
41
39
#include "metadata.h"
55
53
 *  \ingroup flacpp
56
54
 *
57
55
 *  \brief
58
 
 *  This module describes the three encoder layers provided by libFLAC++.
 
56
 *  This module describes the encoder layers provided by libFLAC++.
59
57
 *
60
58
 * The libFLAC++ encoder classes are object wrappers around their
61
 
 * counterparts in libFLAC.  All three encoding layers available in
 
59
 * counterparts in libFLAC.  All encoding layers available in
62
60
 * libFLAC are also provided here.  The interface is very similar;
63
61
 * make sure to read the \link flac_encoder libFLAC encoder module \endlink.
64
62
 *
65
 
 * The only real difference here is that instead of passing in C function
66
 
 * pointers for callbacks, you inherit from the encoder class and provide
67
 
 * implementations for the callbacks in the derived class; because of this
68
 
 * there is no need for a 'client_data' property.
 
63
 * There are only two significant differences here.  First, instead of
 
64
 * passing in C function pointers for callbacks, you inherit from the
 
65
 * encoder class and provide implementations for the callbacks in your
 
66
 * derived class; because of this there is no need for a 'client_data'
 
67
 * property.
 
68
 *
 
69
 * Second, there are two stream encoder classes.  FLAC::Encoder::Stream
 
70
 * is used for the same cases that FLAC__stream_encoder_init_stream() /
 
71
 * FLAC__stream_encoder_init_ogg_stream() are used, and FLAC::Encoder::File
 
72
 * is used for the same cases that
 
73
 * FLAC__stream_encoder_init_FILE() and FLAC__stream_encoder_init_file() /
 
74
 * FLAC__stream_encoder_init_ogg_FILE() and FLAC__stream_encoder_init_ogg_file()
 
75
 * are used.
69
76
 */
70
77
 
71
78
namespace FLAC {
72
79
        namespace Encoder {
73
80
 
74
 
                // ============================================================
75
 
                //
76
 
                //  Equivalent: FLAC__StreamEncoder
77
 
                //
78
 
                // ============================================================
79
 
 
80
 
                /** \defgroup flacpp_stream_encoder FLAC++/encoder.h: stream encoder class
81
 
                 *  \ingroup flacpp_encoder
82
 
                 *
 
81
                /** \ingroup flacpp_encoder
83
82
                 *  \brief
84
 
                 *  This class wraps the ::FLAC__StreamEncoder.
85
 
                 *
86
 
                 * See the \link flac_stream_encoder libFLAC stream encoder module \endlink.
87
 
                 *
88
 
                 * \{
89
 
                 */
90
 
 
91
 
                /** This class wraps the ::FLAC__StreamEncoder.
 
83
                 *  This class wraps the ::FLAC__StreamEncoder.  If you are
 
84
                 *  encoding to a file, FLAC::Encoder::File may be more
 
85
                 *  convenient.
 
86
                 *
 
87
                 * The usage of this class is similar to FLAC__StreamEncoder,
 
88
                 * except instead of providing callbacks to
 
89
                 * FLAC__stream_encoder_init*_stream(), you will inherit from this
 
90
                 * class and override the virtual callback functions with your
 
91
                 * own implementations, then call init() or init_ogg().  The rest of
 
92
                 * the calls work the same as in the C layer.
 
93
                 *
 
94
                 * Only the write callback is mandatory.  The others are
 
95
                 * optional; this class provides default implementations that do
 
96
                 * nothing.  In order for some STREAMINFO and SEEKTABLE data to
 
97
                 * be written properly, you must overide seek_callback() and
 
98
                 * tell_callback(); see FLAC__stream_encoder_init_stream() as to
 
99
                 * why.
92
100
                 */
93
101
                class FLACPP_API Stream {
94
102
                public:
 
103
                        /** This class is a wrapper around FLAC__StreamEncoderState.
 
104
                         */
95
105
                        class FLACPP_API State {
96
106
                        public:
97
107
                                inline State(::FLAC__StreamEncoderState state): state_(state) { }
105
115
                        Stream();
106
116
                        virtual ~Stream();
107
117
 
108
 
                        bool is_valid() const;
109
 
                        inline operator bool() const { return is_valid(); }
110
 
 
111
 
                        bool set_verify(bool value);
112
 
                        bool set_streamable_subset(bool value);
113
 
                        bool set_do_mid_side_stereo(bool value);
114
 
                        bool set_loose_mid_side_stereo(bool value);
115
 
                        bool set_channels(unsigned value);
116
 
                        bool set_bits_per_sample(unsigned value);
117
 
                        bool set_sample_rate(unsigned value);
118
 
                        bool set_blocksize(unsigned value);
119
 
                        bool set_max_lpc_order(unsigned value);
120
 
                        bool set_qlp_coeff_precision(unsigned value);
121
 
                        bool set_do_qlp_coeff_prec_search(bool value);
122
 
                        bool set_do_escape_coding(bool value);
123
 
                        bool set_do_exhaustive_model_search(bool value);
124
 
                        bool set_min_residual_partition_order(unsigned value);
125
 
                        bool set_max_residual_partition_order(unsigned value);
126
 
                        bool set_rice_parameter_search_dist(unsigned value);
127
 
                        bool set_total_samples_estimate(FLAC__uint64 value);
128
 
                        bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
129
 
                        bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
130
 
 
131
 
                        State    get_state() const;
132
 
                        Decoder::Stream::State get_verify_decoder_state() const;
133
 
                        void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
134
 
                        bool     get_verify() const;
135
 
                        bool     get_streamable_subset() const;
136
 
                        bool     get_do_mid_side_stereo() const;
137
 
                        bool     get_loose_mid_side_stereo() const;
138
 
                        unsigned get_channels() const;
139
 
                        unsigned get_bits_per_sample() const;
140
 
                        unsigned get_sample_rate() const;
141
 
                        unsigned get_blocksize() const;
142
 
                        unsigned get_max_lpc_order() const;
143
 
                        unsigned get_qlp_coeff_precision() const;
144
 
                        bool     get_do_qlp_coeff_prec_search() const;
145
 
                        bool     get_do_escape_coding() const;
146
 
                        bool     get_do_exhaustive_model_search() const;
147
 
                        unsigned get_min_residual_partition_order() const;
148
 
                        unsigned get_max_residual_partition_order() const;
149
 
                        unsigned get_rice_parameter_search_dist() const;
150
 
                        FLAC__uint64 get_total_samples_estimate() const;
151
 
 
152
 
                        State init();
153
 
 
154
 
                        void finish();
155
 
 
156
 
                        bool process(const FLAC__int32 * const buffer[], unsigned samples);
157
 
                        bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
 
118
                        //@{
 
119
                        /** Call after construction to check the that the object was created
 
120
                         *  successfully.  If not, use get_state() to find out why not.
 
121
                         *
 
122
                         */
 
123
                        virtual bool is_valid() const;
 
124
                        inline operator bool() const { return is_valid(); } ///< See is_valid()
 
125
                        //@}
 
126
 
 
127
                        virtual bool set_ogg_serial_number(long value);                 ///< See FLAC__stream_encoder_set_ogg_serial_number()
 
128
                        virtual bool set_verify(bool value);                            ///< See FLAC__stream_encoder_set_verify()
 
129
                        virtual bool set_streamable_subset(bool value);                 ///< See FLAC__stream_encoder_set_streamable_subset()
 
130
                        virtual bool set_channels(unsigned value);                      ///< See FLAC__stream_encoder_set_channels()
 
131
                        virtual bool set_bits_per_sample(unsigned value);               ///< See FLAC__stream_encoder_set_bits_per_sample()
 
132
                        virtual bool set_sample_rate(unsigned value);                   ///< See FLAC__stream_encoder_set_sample_rate()
 
133
                        virtual bool set_compression_level(unsigned value);             ///< See FLAC__stream_encoder_set_compression_level()
 
134
                        virtual bool set_blocksize(unsigned value);                     ///< See FLAC__stream_encoder_set_blocksize()
 
135
                        virtual bool set_do_mid_side_stereo(bool value);                ///< See FLAC__stream_encoder_set_do_mid_side_stereo()
 
136
                        virtual bool set_loose_mid_side_stereo(bool value);             ///< See FLAC__stream_encoder_set_loose_mid_side_stereo()
 
137
                        virtual bool set_apodization(const char *specification);        ///< See FLAC__stream_encoder_set_apodization()
 
138
                        virtual bool set_max_lpc_order(unsigned value);                 ///< See FLAC__stream_encoder_set_max_lpc_order()
 
139
                        virtual bool set_qlp_coeff_precision(unsigned value);           ///< See FLAC__stream_encoder_set_qlp_coeff_precision()
 
140
                        virtual bool set_do_qlp_coeff_prec_search(bool value);          ///< See FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
 
141
                        virtual bool set_do_escape_coding(bool value);                  ///< See FLAC__stream_encoder_set_do_escape_coding()
 
142
                        virtual bool set_do_exhaustive_model_search(bool value);        ///< See FLAC__stream_encoder_set_do_exhaustive_model_search()
 
143
                        virtual bool set_min_residual_partition_order(unsigned value);  ///< See FLAC__stream_encoder_set_min_residual_partition_order()
 
144
                        virtual bool set_max_residual_partition_order(unsigned value);  ///< See FLAC__stream_encoder_set_max_residual_partition_order()
 
145
                        virtual bool set_rice_parameter_search_dist(unsigned value);    ///< See FLAC__stream_encoder_set_rice_parameter_search_dist()
 
146
                        virtual bool set_total_samples_estimate(FLAC__uint64 value);    ///< See FLAC__stream_encoder_set_total_samples_estimate()
 
147
                        virtual bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);    ///< See FLAC__stream_encoder_set_metadata()
 
148
                        virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks); ///< See FLAC__stream_encoder_set_metadata()
 
149
 
 
150
                        /* get_state() is not virtual since we want subclasses to be able to return their own state */
 
151
                        State get_state() const;                                   ///< See FLAC__stream_encoder_get_state()
 
152
                        virtual Decoder::Stream::State get_verify_decoder_state() const; ///< See FLAC__stream_encoder_get_verify_decoder_state()
 
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()
 
154
                        virtual bool     get_verify() const;                       ///< See FLAC__stream_encoder_get_verify()
 
155
                        virtual bool     get_streamable_subset() const;            ///< See FLAC__stream_encoder_get_streamable_subset()
 
156
                        virtual bool     get_do_mid_side_stereo() const;           ///< See FLAC__stream_encoder_get_do_mid_side_stereo()
 
157
                        virtual bool     get_loose_mid_side_stereo() const;        ///< See FLAC__stream_encoder_get_loose_mid_side_stereo()
 
158
                        virtual unsigned get_channels() const;                     ///< See FLAC__stream_encoder_get_channels()
 
159
                        virtual unsigned get_bits_per_sample() const;              ///< See FLAC__stream_encoder_get_bits_per_sample()
 
160
                        virtual unsigned get_sample_rate() const;                  ///< See FLAC__stream_encoder_get_sample_rate()
 
161
                        virtual unsigned get_blocksize() const;                    ///< See FLAC__stream_encoder_get_blocksize()
 
162
                        virtual unsigned get_max_lpc_order() const;                ///< See FLAC__stream_encoder_get_max_lpc_order()
 
163
                        virtual unsigned get_qlp_coeff_precision() const;          ///< See FLAC__stream_encoder_get_qlp_coeff_precision()
 
164
                        virtual bool     get_do_qlp_coeff_prec_search() const;     ///< See FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
 
165
                        virtual bool     get_do_escape_coding() const;             ///< See FLAC__stream_encoder_get_do_escape_coding()
 
166
                        virtual bool     get_do_exhaustive_model_search() const;   ///< See FLAC__stream_encoder_get_do_exhaustive_model_search()
 
167
                        virtual unsigned get_min_residual_partition_order() const; ///< See FLAC__stream_encoder_get_min_residual_partition_order()
 
168
                        virtual unsigned get_max_residual_partition_order() const; ///< See FLAC__stream_encoder_get_max_residual_partition_order()
 
169
                        virtual unsigned get_rice_parameter_search_dist() const;   ///< See FLAC__stream_encoder_get_rice_parameter_search_dist()
 
170
                        virtual FLAC__uint64 get_total_samples_estimate() const;   ///< See FLAC__stream_encoder_get_total_samples_estimate()
 
171
 
 
172
                        virtual ::FLAC__StreamEncoderInitStatus init();            ///< See FLAC__stream_encoder_init_stream()
 
173
                        virtual ::FLAC__StreamEncoderInitStatus init_ogg();        ///< See FLAC__stream_encoder_init_ogg_stream()
 
174
 
 
175
                        virtual bool finish(); ///< See FLAC__stream_encoder_finish()
 
176
 
 
177
                        virtual bool process(const FLAC__int32 * const buffer[], unsigned samples);     ///< See FLAC__stream_encoder_process()
 
178
                        virtual bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); ///< See FLAC__stream_encoder_process_interleaved()
158
179
                protected:
159
 
                        virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
160
 
                        virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
161
 
 
162
 
#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
 
180
                        /// See FLAC__StreamEncoderReadCallback
 
181
                        virtual ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
 
182
 
 
183
                        /// See FLAC__StreamEncoderWriteCallback
 
184
                        virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame) = 0;
 
185
 
 
186
                        /// See FLAC__StreamEncoderSeekCallback
 
187
                        virtual ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
 
188
 
 
189
                        /// See FLAC__StreamEncoderTellCallback
 
190
                        virtual ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
 
191
 
 
192
                        /// See FLAC__StreamEncoderTellCallback
 
193
                        virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
 
194
 
 
195
#if (defined _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
163
196
                        // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
164
197
                        friend State;
165
198
#endif
166
199
                        ::FLAC__StreamEncoder *encoder_;
167
 
                private:
168
 
                        static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
 
200
 
 
201
                        static ::FLAC__StreamEncoderReadStatus read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
 
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);
 
203
                        static ::FLAC__StreamEncoderSeekStatus seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
 
204
                        static ::FLAC__StreamEncoderTellStatus tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
169
205
                        static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
170
 
 
 
206
                private:
171
207
                        // Private and undefined so you can't use them:
172
208
                        Stream(const Stream &);
173
209
                        void operator=(const Stream &);
174
210
                };
175
211
 
176
 
                /* \} */
177
 
 
178
 
                /** \defgroup flacpp_seekable_stream_encoder FLAC++/encoder.h: seekable stream encoder class
179
 
                 *  \ingroup flacpp_encoder
180
 
                 *
181
 
                 *  \brief
182
 
                 *  This class wraps the ::FLAC__SeekableStreamEncoder.
183
 
                 *
184
 
                 * See the \link flac_seekable_stream_encoder libFLAC seekable stream encoder module \endlink.
185
 
                 *
186
 
                 * \{
187
 
                 */
188
 
 
189
 
                /** This class wraps the ::FLAC__SeekableStreamEncoder.
190
 
                 */
191
 
                class FLACPP_API SeekableStream {
192
 
                public:
193
 
                        class FLACPP_API State {
194
 
                        public:
195
 
                                inline State(::FLAC__SeekableStreamEncoderState state): state_(state) { }
196
 
                                inline operator ::FLAC__SeekableStreamEncoderState() const { return state_; }
197
 
                                inline const char *as_cstring() const { return ::FLAC__SeekableStreamEncoderStateString[state_]; }
198
 
                                inline const char *resolved_as_cstring(const SeekableStream &encoder) const { return ::FLAC__seekable_stream_encoder_get_resolved_state_string(encoder.encoder_); }
199
 
                        protected:
200
 
                                ::FLAC__SeekableStreamEncoderState state_;
201
 
                        };
202
 
 
203
 
                        SeekableStream();
204
 
                        virtual ~SeekableStream();
205
 
 
206
 
                        bool is_valid() const;
207
 
                        inline operator bool() const { return is_valid(); }
208
 
 
209
 
                        bool set_verify(bool value);
210
 
                        bool set_streamable_subset(bool value);
211
 
                        bool set_do_mid_side_stereo(bool value);
212
 
                        bool set_loose_mid_side_stereo(bool value);
213
 
                        bool set_channels(unsigned value);
214
 
                        bool set_bits_per_sample(unsigned value);
215
 
                        bool set_sample_rate(unsigned value);
216
 
                        bool set_blocksize(unsigned value);
217
 
                        bool set_max_lpc_order(unsigned value);
218
 
                        bool set_qlp_coeff_precision(unsigned value);
219
 
                        bool set_do_qlp_coeff_prec_search(bool value);
220
 
                        bool set_do_escape_coding(bool value);
221
 
                        bool set_do_exhaustive_model_search(bool value);
222
 
                        bool set_min_residual_partition_order(unsigned value);
223
 
                        bool set_max_residual_partition_order(unsigned value);
224
 
                        bool set_rice_parameter_search_dist(unsigned value);
225
 
                        bool set_total_samples_estimate(FLAC__uint64 value);
226
 
                        bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
227
 
                        bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
228
 
 
229
 
                        State    get_state() const;
230
 
                        Stream::State get_stream_encoder_state() const;
231
 
                        Decoder::Stream::State get_verify_decoder_state() const;
232
 
                        void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
233
 
                        bool     get_verify() const;
234
 
                        bool     get_streamable_subset() const;
235
 
                        bool     get_do_mid_side_stereo() const;
236
 
                        bool     get_loose_mid_side_stereo() const;
237
 
                        unsigned get_channels() const;
238
 
                        unsigned get_bits_per_sample() const;
239
 
                        unsigned get_sample_rate() const;
240
 
                        unsigned get_blocksize() const;
241
 
                        unsigned get_max_lpc_order() const;
242
 
                        unsigned get_qlp_coeff_precision() const;
243
 
                        bool     get_do_qlp_coeff_prec_search() const;
244
 
                        bool     get_do_escape_coding() const;
245
 
                        bool     get_do_exhaustive_model_search() const;
246
 
                        unsigned get_min_residual_partition_order() const;
247
 
                        unsigned get_max_residual_partition_order() const;
248
 
                        unsigned get_rice_parameter_search_dist() const;
249
 
                        FLAC__uint64 get_total_samples_estimate() const;
250
 
 
251
 
                        State init();
252
 
 
253
 
                        void finish();
254
 
 
255
 
                        bool process(const FLAC__int32 * const buffer[], unsigned samples);
256
 
                        bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
257
 
                protected:
258
 
                        virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
259
 
                        virtual ::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
260
 
                        virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
261
 
 
262
 
#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
263
 
                        // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
264
 
                        friend State;
265
 
#endif
266
 
                        ::FLAC__SeekableStreamEncoder *encoder_;
267
 
                private:
268
 
                        static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
269
 
                        static ::FLAC__SeekableStreamEncoderTellStatus tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
270
 
                        static ::FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
271
 
 
272
 
                        // Private and undefined so you can't use them:
273
 
                        SeekableStream(const SeekableStream &);
274
 
                        void operator=(const SeekableStream &);
275
 
                };
276
 
 
277
 
                /* \} */
278
 
 
279
 
                /** \defgroup flacpp_file_encoder FLAC++/encoder.h: file encoder class
280
 
                 *  \ingroup flacpp_encoder
281
 
                 *
282
 
                 *  \brief
283
 
                 *  This class wraps the ::FLAC__FileEncoder.
284
 
                 *
285
 
                 * See the \link flac_file_encoder libFLAC file encoder module \endlink.
286
 
                 *
287
 
                 * \{
288
 
                 */
289
 
 
290
 
                /** This class wraps the ::FLAC__FileEncoder.
291
 
                 */
292
 
                class FLACPP_API File {
293
 
                public:
294
 
                        class FLACPP_API State {
295
 
                        public:
296
 
                                inline State(::FLAC__FileEncoderState state): state_(state) { }
297
 
                                inline operator ::FLAC__FileEncoderState() const { return state_; }
298
 
                                inline const char *as_cstring() const { return ::FLAC__FileEncoderStateString[state_]; }
299
 
                                inline const char *resolved_as_cstring(const File &encoder) const { return ::FLAC__file_encoder_get_resolved_state_string(encoder.encoder_); }
300
 
                        protected:
301
 
                                ::FLAC__FileEncoderState state_;
302
 
                        };
303
 
 
 
212
                /** \ingroup flacpp_encoder
 
213
                 *  \brief
 
214
                 *  This class wraps the ::FLAC__StreamEncoder.  If you are
 
215
                 *  not encoding to a file, you may need to use
 
216
                 *  FLAC::Encoder::Stream.
 
217
                 *
 
218
                 * The usage of this class is similar to FLAC__StreamEncoder,
 
219
                 * except instead of providing callbacks to
 
220
                 * FLAC__stream_encoder_init*_FILE() or
 
221
                 * FLAC__stream_encoder_init*_file(), you will inherit from this
 
222
                 * class and override the virtual callback functions with your
 
223
                 * own implementations, then call init() or init_ogg().  The rest
 
224
                 * of the calls work the same as in the C layer.
 
225
                 *
 
226
                 * There are no mandatory callbacks; all the callbacks from
 
227
                 * FLAC::Encoder::Stream are implemented here fully and support
 
228
                 * full post-encode STREAMINFO and SEEKTABLE updating.  There is
 
229
                 * only an optional progress callback which you may override to
 
230
                 * get periodic reports on the progress of the encode.
 
231
                 */
 
232
                class FLACPP_API File: public Stream {
 
233
                public:
304
234
                        File();
305
235
                        virtual ~File();
306
236
 
307
 
                        bool is_valid() const;
308
 
                        inline operator bool() const { return is_valid(); }
309
 
 
310
 
                        bool set_verify(bool value);
311
 
                        bool set_streamable_subset(bool value);
312
 
                        bool set_do_mid_side_stereo(bool value);
313
 
                        bool set_loose_mid_side_stereo(bool value);
314
 
                        bool set_channels(unsigned value);
315
 
                        bool set_bits_per_sample(unsigned value);
316
 
                        bool set_sample_rate(unsigned value);
317
 
                        bool set_blocksize(unsigned value);
318
 
                        bool set_max_lpc_order(unsigned value);
319
 
                        bool set_qlp_coeff_precision(unsigned value);
320
 
                        bool set_do_qlp_coeff_prec_search(bool value);
321
 
                        bool set_do_escape_coding(bool value);
322
 
                        bool set_do_exhaustive_model_search(bool value);
323
 
                        bool set_min_residual_partition_order(unsigned value);
324
 
                        bool set_max_residual_partition_order(unsigned value);
325
 
                        bool set_rice_parameter_search_dist(unsigned value);
326
 
                        bool set_total_samples_estimate(FLAC__uint64 value);
327
 
                        bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
328
 
                        bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
329
 
                        bool set_filename(const char *value);
330
 
 
331
 
                        State    get_state() const;
332
 
                        SeekableStream::State get_seekable_stream_encoder_state() const;
333
 
                        Stream::State get_stream_encoder_state() const;
334
 
                        Decoder::Stream::State get_verify_decoder_state() const;
335
 
                        void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
336
 
                        bool     get_verify() const;
337
 
                        bool     get_streamable_subset() const;
338
 
                        bool     get_do_mid_side_stereo() const;
339
 
                        bool     get_loose_mid_side_stereo() const;
340
 
                        unsigned get_channels() const;
341
 
                        unsigned get_bits_per_sample() const;
342
 
                        unsigned get_sample_rate() const;
343
 
                        unsigned get_blocksize() const;
344
 
                        unsigned get_max_lpc_order() const;
345
 
                        unsigned get_qlp_coeff_precision() const;
346
 
                        bool     get_do_qlp_coeff_prec_search() const;
347
 
                        bool     get_do_escape_coding() const;
348
 
                        bool     get_do_exhaustive_model_search() const;
349
 
                        unsigned get_min_residual_partition_order() const;
350
 
                        unsigned get_max_residual_partition_order() const;
351
 
                        unsigned get_rice_parameter_search_dist() const;
352
 
                        FLAC__uint64 get_total_samples_estimate() const;
353
 
 
354
 
                        State init();
355
 
 
356
 
                        void finish();
357
 
 
358
 
                        bool process(const FLAC__int32 * const buffer[], unsigned samples);
359
 
                        bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
 
237
                        virtual ::FLAC__StreamEncoderInitStatus init(FILE *file);                      ///< See FLAC__stream_encoder_init_FILE()
 
238
                        virtual ::FLAC__StreamEncoderInitStatus init(const char *filename);            ///< See FLAC__stream_encoder_init_file()
 
239
                        virtual ::FLAC__StreamEncoderInitStatus init(const std::string &filename);     ///< See FLAC__stream_encoder_init_file()
 
240
                        virtual ::FLAC__StreamEncoderInitStatus init_ogg(FILE *file);                  ///< See FLAC__stream_encoder_init_ogg_FILE()
 
241
                        virtual ::FLAC__StreamEncoderInitStatus init_ogg(const char *filename);        ///< See FLAC__stream_encoder_init_ogg_file()
 
242
                        virtual ::FLAC__StreamEncoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_encoder_init_ogg_file()
360
243
                protected:
 
244
                        /// See FLAC__StreamEncoderProgressCallback
361
245
                        virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
362
246
 
363
 
#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
364
 
                        // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
365
 
                        friend State;
366
 
#endif
367
 
                        ::FLAC__FileEncoder *encoder_;
 
247
                        /// This is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
 
248
                        virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame);
368
249
                private:
369
 
                        static void progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
 
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);
370
251
 
371
252
                        // Private and undefined so you can't use them:
372
253
                        File(const Stream &);
373
254
                        void operator=(const Stream &);
374
255
                };
375
256
 
376
 
                /* \} */
377
 
 
378
257
        }
379
258
}
380
259