more doxygen docs
[platform/upstream/flac.git] / include / FLAC++ / encoder.h
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002  Josh Coalson
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA  02111-1307, USA.
18  */
19
20 #ifndef FLACPP__ENCODER_H
21 #define FLACPP__ENCODER_H
22
23 #include "FLAC/file_encoder.h"
24 #include "FLAC/seekable_stream_encoder.h"
25 #include "FLAC/stream_encoder.h"
26 #include "decoder.h"
27
28
29 /** \file include/FLAC++/encoder.h
30  *
31  *  \brief
32  *  This module contains the classes which implement the various
33  *  encoders.
34  *
35  *  See the detailed documentation in the
36  *  \link flacpp_encoder encoder \endlink module.
37  */
38
39 /** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes
40  *  \ingroup flacpp
41  *
42  *  \brief
43  *  This module describes the three encoder layers provided by libFLAC++.
44  *
45  * The libFLAC++ encoder classes are object wrappers around their
46  * counterparts in libFLAC.  All three encoding layers available in
47  * libFLAC are also provided here.  The interface is very similar;
48  * make sure to read the \link flac_encoder libFLAC encoder module \endlink.
49  *
50  * The only real difference here is that instead of passing in C function
51  * pointers for callbacks, you inherit from the encoder class and provide
52  * implementations for the callbacks in the derived class; because of this
53  * there is no need for a 'client_data' property.
54  */
55
56 namespace FLAC {
57         namespace Encoder {
58
59                 // ============================================================
60                 //
61                 //  Equivalent: FLAC__StreamEncoder
62                 //
63                 // ============================================================
64
65                 /** \defgroup flacpp_stream_encoder FLAC++/encoder.h: stream encoder class
66                  *  \ingroup flacpp_encoder
67                  *
68                  *  \brief
69                  *  This class wraps the ::FLAC__StreamEncoder.
70                  *
71                  * See the \link flac_stream_encoder libFLAC stream encoder module \endlink.
72                  *
73                  * \{
74                  */
75
76                 /** This class wraps the ::FLAC__StreamEncoder.
77                  */
78                 class Stream {
79                 public:
80                         class State {
81                         public:
82                                 inline State(::FLAC__StreamEncoderState state): state_(state) { }
83                                 inline operator ::FLAC__StreamEncoderState() const { return state_; }
84                                 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
85                         protected:
86                                 ::FLAC__StreamEncoderState state_;
87                         };
88
89                         Stream();
90                         virtual ~Stream();
91
92                         bool is_valid() const;
93                         inline operator bool() const { return is_valid(); }
94
95                         bool set_verify(bool value);
96                         bool set_streamable_subset(bool value);
97                         bool set_do_mid_side_stereo(bool value);
98                         bool set_loose_mid_side_stereo(bool value);
99                         bool set_channels(unsigned value);
100                         bool set_bits_per_sample(unsigned value);
101                         bool set_sample_rate(unsigned value);
102                         bool set_blocksize(unsigned value);
103                         bool set_max_lpc_order(unsigned value);
104                         bool set_qlp_coeff_precision(unsigned value);
105                         bool set_do_qlp_coeff_prec_search(bool value);
106                         bool set_do_escape_coding(bool value);
107                         bool set_do_exhaustive_model_search(bool value);
108                         bool set_min_residual_partition_order(unsigned value);
109                         bool set_max_residual_partition_order(unsigned value);
110                         bool set_rice_parameter_search_dist(unsigned value);
111                         bool set_total_samples_estimate(FLAC__uint64 value);
112                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
113
114                         State    get_state() const;
115                         Decoder::Stream::State get_verify_decoder_state() const;
116                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
117                         bool     get_verify() const;
118                         bool     get_streamable_subset() const;
119                         bool     get_do_mid_side_stereo() const;
120                         bool     get_loose_mid_side_stereo() const;
121                         unsigned get_channels() const;
122                         unsigned get_bits_per_sample() const;
123                         unsigned get_sample_rate() const;
124                         unsigned get_blocksize() const;
125                         unsigned get_max_lpc_order() const;
126                         unsigned get_qlp_coeff_precision() const;
127                         bool     get_do_qlp_coeff_prec_search() const;
128                         bool     get_do_escape_coding() const;
129                         bool     get_do_exhaustive_model_search() const;
130                         unsigned get_min_residual_partition_order() const;
131                         unsigned get_max_residual_partition_order() const;
132                         unsigned get_rice_parameter_search_dist() const;
133                         FLAC__uint64 get_total_samples_estimate() const;
134
135                         State init();
136
137                         void finish();
138
139                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
140                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
141                 protected:
142                         virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
143                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
144
145                         ::FLAC__StreamEncoder *encoder_;
146                 private:
147                         static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
148                         static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
149
150                         // Private and undefined so you can't use them:
151                         Stream(const Stream &);
152                         void operator=(const Stream &);
153                 };
154
155                 /* \} */
156
157                 /** \defgroup flacpp_seekable_stream_encoder FLAC++/encoder.h: seekable stream encoder class
158                  *  \ingroup flacpp_encoder
159                  *
160                  *  \brief
161                  *  This class wraps the ::FLAC__SeekableStreamEncoder.
162                  *
163                  * See the \link flac_seekable_stream_encoder libFLAC seekable stream encoder module \endlink.
164                  *
165                  * \{
166                  */
167
168                 /** This class wraps the ::FLAC__SeekableStreamEncoder.
169                  */
170                 class SeekableStream {
171                 public:
172                         class State {
173                         public:
174                                 inline State(::FLAC__SeekableStreamEncoderState state): state_(state) { }
175                                 inline operator ::FLAC__SeekableStreamEncoderState() const { return state_; }
176                                 inline const char *as_cstring() const { return ::FLAC__SeekableStreamEncoderStateString[state_]; }
177                         protected:
178                                 ::FLAC__SeekableStreamEncoderState state_;
179                         };
180
181                         SeekableStream();
182                         virtual ~SeekableStream();
183
184                         bool is_valid() const;
185                         inline operator bool() const { return is_valid(); }
186
187                         bool set_verify(bool value);
188                         bool set_streamable_subset(bool value);
189                         bool set_do_mid_side_stereo(bool value);
190                         bool set_loose_mid_side_stereo(bool value);
191                         bool set_channels(unsigned value);
192                         bool set_bits_per_sample(unsigned value);
193                         bool set_sample_rate(unsigned value);
194                         bool set_blocksize(unsigned value);
195                         bool set_max_lpc_order(unsigned value);
196                         bool set_qlp_coeff_precision(unsigned value);
197                         bool set_do_qlp_coeff_prec_search(bool value);
198                         bool set_do_escape_coding(bool value);
199                         bool set_do_exhaustive_model_search(bool value);
200                         bool set_min_residual_partition_order(unsigned value);
201                         bool set_max_residual_partition_order(unsigned value);
202                         bool set_rice_parameter_search_dist(unsigned value);
203                         bool set_total_samples_estimate(FLAC__uint64 value);
204                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
205
206                         State    get_state() const;
207                         Stream::State get_stream_encoder_state() const;
208                         Decoder::Stream::State get_verify_decoder_state() const;
209                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
210                         bool     get_verify() const;
211                         bool     get_streamable_subset() const;
212                         bool     get_do_mid_side_stereo() const;
213                         bool     get_loose_mid_side_stereo() const;
214                         unsigned get_channels() const;
215                         unsigned get_bits_per_sample() const;
216                         unsigned get_sample_rate() const;
217                         unsigned get_blocksize() const;
218                         unsigned get_max_lpc_order() const;
219                         unsigned get_qlp_coeff_precision() const;
220                         bool     get_do_qlp_coeff_prec_search() const;
221                         bool     get_do_escape_coding() const;
222                         bool     get_do_exhaustive_model_search() const;
223                         unsigned get_min_residual_partition_order() const;
224                         unsigned get_max_residual_partition_order() const;
225                         unsigned get_rice_parameter_search_dist() const;
226                         FLAC__uint64 get_total_samples_estimate() const;
227
228                         State init();
229
230                         void finish();
231
232                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
233                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
234                 protected:
235                         virtual FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
236                         virtual FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
237
238                         ::FLAC__SeekableStreamEncoder *encoder_;
239                 private:
240                         static FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
241                         static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
242
243                         // Private and undefined so you can't use them:
244                         SeekableStream(const SeekableStream &);
245                         void operator=(const SeekableStream &);
246                 };
247
248                 /* \} */
249
250                 /** \defgroup flacpp_file_encoder FLAC++/encoder.h: file encoder class
251                  *  \ingroup flacpp_encoder
252                  *
253                  *  \brief
254                  *  This class wraps the ::FLAC__FileEncoder.
255                  *
256                  * See the \link flac_file_encoder libFLAC file encoder module \endlink.
257                  *
258                  * \{
259                  */
260
261                 /** This class wraps the ::FLAC__FileEncoder.
262                  */
263                 class File {
264                 public:
265                         class State {
266                         public:
267                                 inline State(::FLAC__FileEncoderState state): state_(state) { }
268                                 inline operator ::FLAC__FileEncoderState() const { return state_; }
269                                 inline const char *as_cstring() const { return ::FLAC__FileEncoderStateString[state_]; }
270                         protected:
271                                 ::FLAC__FileEncoderState state_;
272                         };
273
274                         File();
275                         virtual ~File();
276
277                         bool is_valid() const;
278                         inline operator bool() const { return is_valid(); }
279
280                         bool set_verify(bool value);
281                         bool set_streamable_subset(bool value);
282                         bool set_do_mid_side_stereo(bool value);
283                         bool set_loose_mid_side_stereo(bool value);
284                         bool set_channels(unsigned value);
285                         bool set_bits_per_sample(unsigned value);
286                         bool set_sample_rate(unsigned value);
287                         bool set_blocksize(unsigned value);
288                         bool set_max_lpc_order(unsigned value);
289                         bool set_qlp_coeff_precision(unsigned value);
290                         bool set_do_qlp_coeff_prec_search(bool value);
291                         bool set_do_escape_coding(bool value);
292                         bool set_do_exhaustive_model_search(bool value);
293                         bool set_min_residual_partition_order(unsigned value);
294                         bool set_max_residual_partition_order(unsigned value);
295                         bool set_rice_parameter_search_dist(unsigned value);
296                         bool set_total_samples_estimate(FLAC__uint64 value);
297                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
298                         bool set_filename(const char *value);
299
300                         State    get_state() const;
301                         SeekableStream::State get_seekable_stream_encoder_state() const;
302                         Stream::State get_stream_encoder_state() const;
303                         Decoder::Stream::State get_verify_decoder_state() const;
304                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
305                         bool     get_verify() const;
306                         bool     get_streamable_subset() const;
307                         bool     get_do_mid_side_stereo() const;
308                         bool     get_loose_mid_side_stereo() const;
309                         unsigned get_channels() const;
310                         unsigned get_bits_per_sample() const;
311                         unsigned get_sample_rate() const;
312                         unsigned get_blocksize() const;
313                         unsigned get_max_lpc_order() const;
314                         unsigned get_qlp_coeff_precision() const;
315                         bool     get_do_qlp_coeff_prec_search() const;
316                         bool     get_do_escape_coding() const;
317                         bool     get_do_exhaustive_model_search() const;
318                         unsigned get_min_residual_partition_order() const;
319                         unsigned get_max_residual_partition_order() const;
320                         unsigned get_rice_parameter_search_dist() const;
321                         FLAC__uint64 get_total_samples_estimate() const;
322
323                         State init();
324
325                         void finish();
326
327                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
328                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
329                 protected:
330                         virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
331
332                         ::FLAC__FileEncoder *encoder_;
333                 private:
334                         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);
335
336                         // Private and undefined so you can't use them:
337                         File(const Stream &);
338                         void operator=(const Stream &);
339                 };
340
341                 /* \} */
342
343         };
344 };
345
346 #endif