e0fd6ff1d2e6a6964e991e4dabc3ede2aa90ca8e
[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                                 const char *resolved_as_cstring(const Stream &) const;
86                         protected:
87                                 ::FLAC__StreamEncoderState state_;
88                         };
89
90                         Stream();
91                         virtual ~Stream();
92
93                         bool is_valid() const;
94                         inline operator bool() const { return is_valid(); }
95
96                         bool set_verify(bool value);
97                         bool set_streamable_subset(bool value);
98                         bool set_do_mid_side_stereo(bool value);
99                         bool set_loose_mid_side_stereo(bool value);
100                         bool set_channels(unsigned value);
101                         bool set_bits_per_sample(unsigned value);
102                         bool set_sample_rate(unsigned value);
103                         bool set_blocksize(unsigned value);
104                         bool set_max_lpc_order(unsigned value);
105                         bool set_qlp_coeff_precision(unsigned value);
106                         bool set_do_qlp_coeff_prec_search(bool value);
107                         bool set_do_escape_coding(bool value);
108                         bool set_do_exhaustive_model_search(bool value);
109                         bool set_min_residual_partition_order(unsigned value);
110                         bool set_max_residual_partition_order(unsigned value);
111                         bool set_rice_parameter_search_dist(unsigned value);
112                         bool set_total_samples_estimate(FLAC__uint64 value);
113                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
114
115                         State    get_state() const;
116                         Decoder::Stream::State get_verify_decoder_state() const;
117                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
118                         bool     get_verify() const;
119                         bool     get_streamable_subset() const;
120                         bool     get_do_mid_side_stereo() const;
121                         bool     get_loose_mid_side_stereo() const;
122                         unsigned get_channels() const;
123                         unsigned get_bits_per_sample() const;
124                         unsigned get_sample_rate() const;
125                         unsigned get_blocksize() const;
126                         unsigned get_max_lpc_order() const;
127                         unsigned get_qlp_coeff_precision() const;
128                         bool     get_do_qlp_coeff_prec_search() const;
129                         bool     get_do_escape_coding() const;
130                         bool     get_do_exhaustive_model_search() const;
131                         unsigned get_min_residual_partition_order() const;
132                         unsigned get_max_residual_partition_order() const;
133                         unsigned get_rice_parameter_search_dist() const;
134                         FLAC__uint64 get_total_samples_estimate() const;
135
136                         State init();
137
138                         void finish();
139
140                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
141                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
142                 protected:
143                         virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
144                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
145
146                         ::FLAC__StreamEncoder *encoder_;
147                 private:
148                         static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
149                         static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
150
151                         // Private and undefined so you can't use them:
152                         Stream(const Stream &);
153                         void operator=(const Stream &);
154                 };
155
156                 /* \} */
157
158                 /** \defgroup flacpp_seekable_stream_encoder FLAC++/encoder.h: seekable stream encoder class
159                  *  \ingroup flacpp_encoder
160                  *
161                  *  \brief
162                  *  This class wraps the ::FLAC__SeekableStreamEncoder.
163                  *
164                  * See the \link flac_seekable_stream_encoder libFLAC seekable stream encoder module \endlink.
165                  *
166                  * \{
167                  */
168
169                 /** This class wraps the ::FLAC__SeekableStreamEncoder.
170                  */
171                 class SeekableStream {
172                 public:
173                         class State {
174                         public:
175                                 inline State(::FLAC__SeekableStreamEncoderState state): state_(state) { }
176                                 inline operator ::FLAC__SeekableStreamEncoderState() const { return state_; }
177                                 inline const char *as_cstring() const { return ::FLAC__SeekableStreamEncoderStateString[state_]; }
178                                 const char *resolved_as_cstring(const SeekableStream &) const;
179                         protected:
180                                 ::FLAC__SeekableStreamEncoderState state_;
181                         };
182
183                         SeekableStream();
184                         virtual ~SeekableStream();
185
186                         bool is_valid() const;
187                         inline operator bool() const { return is_valid(); }
188
189                         bool set_verify(bool value);
190                         bool set_streamable_subset(bool value);
191                         bool set_do_mid_side_stereo(bool value);
192                         bool set_loose_mid_side_stereo(bool value);
193                         bool set_channels(unsigned value);
194                         bool set_bits_per_sample(unsigned value);
195                         bool set_sample_rate(unsigned value);
196                         bool set_blocksize(unsigned value);
197                         bool set_max_lpc_order(unsigned value);
198                         bool set_qlp_coeff_precision(unsigned value);
199                         bool set_do_qlp_coeff_prec_search(bool value);
200                         bool set_do_escape_coding(bool value);
201                         bool set_do_exhaustive_model_search(bool value);
202                         bool set_min_residual_partition_order(unsigned value);
203                         bool set_max_residual_partition_order(unsigned value);
204                         bool set_rice_parameter_search_dist(unsigned value);
205                         bool set_total_samples_estimate(FLAC__uint64 value);
206                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
207
208                         State    get_state() const;
209                         Stream::State get_stream_encoder_state() const;
210                         Decoder::Stream::State get_verify_decoder_state() const;
211                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
212                         bool     get_verify() const;
213                         bool     get_streamable_subset() const;
214                         bool     get_do_mid_side_stereo() const;
215                         bool     get_loose_mid_side_stereo() const;
216                         unsigned get_channels() const;
217                         unsigned get_bits_per_sample() const;
218                         unsigned get_sample_rate() const;
219                         unsigned get_blocksize() const;
220                         unsigned get_max_lpc_order() const;
221                         unsigned get_qlp_coeff_precision() const;
222                         bool     get_do_qlp_coeff_prec_search() const;
223                         bool     get_do_escape_coding() const;
224                         bool     get_do_exhaustive_model_search() const;
225                         unsigned get_min_residual_partition_order() const;
226                         unsigned get_max_residual_partition_order() const;
227                         unsigned get_rice_parameter_search_dist() const;
228                         FLAC__uint64 get_total_samples_estimate() const;
229
230                         State init();
231
232                         void finish();
233
234                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
235                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
236                 protected:
237                         virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
238                         virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
239
240                         ::FLAC__SeekableStreamEncoder *encoder_;
241                 private:
242                         static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
243                         static ::FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
244
245                         // Private and undefined so you can't use them:
246                         SeekableStream(const SeekableStream &);
247                         void operator=(const SeekableStream &);
248                 };
249
250                 /* \} */
251
252                 /** \defgroup flacpp_file_encoder FLAC++/encoder.h: file encoder class
253                  *  \ingroup flacpp_encoder
254                  *
255                  *  \brief
256                  *  This class wraps the ::FLAC__FileEncoder.
257                  *
258                  * See the \link flac_file_encoder libFLAC file encoder module \endlink.
259                  *
260                  * \{
261                  */
262
263                 /** This class wraps the ::FLAC__FileEncoder.
264                  */
265                 class File {
266                 public:
267                         class State {
268                         public:
269                                 inline State(::FLAC__FileEncoderState state): state_(state) { }
270                                 inline operator ::FLAC__FileEncoderState() const { return state_; }
271                                 inline const char *as_cstring() const { return ::FLAC__FileEncoderStateString[state_]; }
272                                 const char *resolved_as_cstring(const File &) const;
273                         protected:
274                                 ::FLAC__FileEncoderState state_;
275                         };
276
277                         File();
278                         virtual ~File();
279
280                         bool is_valid() const;
281                         inline operator bool() const { return is_valid(); }
282
283                         bool set_verify(bool value);
284                         bool set_streamable_subset(bool value);
285                         bool set_do_mid_side_stereo(bool value);
286                         bool set_loose_mid_side_stereo(bool value);
287                         bool set_channels(unsigned value);
288                         bool set_bits_per_sample(unsigned value);
289                         bool set_sample_rate(unsigned value);
290                         bool set_blocksize(unsigned value);
291                         bool set_max_lpc_order(unsigned value);
292                         bool set_qlp_coeff_precision(unsigned value);
293                         bool set_do_qlp_coeff_prec_search(bool value);
294                         bool set_do_escape_coding(bool value);
295                         bool set_do_exhaustive_model_search(bool value);
296                         bool set_min_residual_partition_order(unsigned value);
297                         bool set_max_residual_partition_order(unsigned value);
298                         bool set_rice_parameter_search_dist(unsigned value);
299                         bool set_total_samples_estimate(FLAC__uint64 value);
300                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
301                         bool set_filename(const char *value);
302
303                         State    get_state() const;
304                         SeekableStream::State get_seekable_stream_encoder_state() const;
305                         Stream::State get_stream_encoder_state() const;
306                         Decoder::Stream::State get_verify_decoder_state() const;
307                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
308                         bool     get_verify() const;
309                         bool     get_streamable_subset() const;
310                         bool     get_do_mid_side_stereo() const;
311                         bool     get_loose_mid_side_stereo() const;
312                         unsigned get_channels() const;
313                         unsigned get_bits_per_sample() const;
314                         unsigned get_sample_rate() const;
315                         unsigned get_blocksize() const;
316                         unsigned get_max_lpc_order() const;
317                         unsigned get_qlp_coeff_precision() const;
318                         bool     get_do_qlp_coeff_prec_search() const;
319                         bool     get_do_escape_coding() const;
320                         bool     get_do_exhaustive_model_search() const;
321                         unsigned get_min_residual_partition_order() const;
322                         unsigned get_max_residual_partition_order() const;
323                         unsigned get_rice_parameter_search_dist() const;
324                         FLAC__uint64 get_total_samples_estimate() const;
325
326                         State init();
327
328                         void finish();
329
330                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
331                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
332                 protected:
333                         virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
334
335                         ::FLAC__FileEncoder *encoder_;
336                 private:
337                         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);
338
339                         // Private and undefined so you can't use them:
340                         File(const Stream &);
341                         void operator=(const Stream &);
342                 };
343
344                 /* \} */
345
346         };
347 };
348
349 #endif