0c639377494fa3141de6ac5ee87e2e81a11d5db6
[platform/upstream/flac.git] / include / OggFLAC++ / encoder.h
1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2  * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * - Neither the name of the Xiph.org Foundation nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef OggFLACPP__ENCODER_H
33 #define OggFLACPP__ENCODER_H
34
35 #include "export.h"
36
37 #include "OggFLAC/file_encoder.h"
38 #include "OggFLAC/seekable_stream_encoder.h"
39 #include "OggFLAC/stream_encoder.h"
40 #include "decoder.h"
41 // we only need these for the state abstractions really...
42 #include "FLAC++/decoder.h"
43 #include "FLAC++/encoder.h"
44
45
46 /** \file include/OggFLAC++/encoder.h
47  *
48  *  \brief
49  *  This module contains the classes which implement the various
50  *  encoders.
51  *
52  *  See the detailed documentation in the
53  *  \link oggflacpp_encoder encoder \endlink module.
54  */
55
56 /** \defgroup oggflacpp_encoder OggFLAC++/encoder.h: encoder classes
57  *  \ingroup oggflacpp
58  *
59  *  \brief
60  *  This module describes the three encoder layers provided by libOggFLAC++.
61  *
62  * The libOggFLAC++ encoder classes are object wrappers around their
63  * counterparts in libOggFLAC.  All three encoding layers available in
64  * libOggFLAC are also provided here.  The interface is very similar;
65  * make sure to read the \link oggflac_encoder libOggFLAC encoder module \endlink.
66  *
67  * The only real difference here is that instead of passing in C function
68  * pointers for callbacks, you inherit from the encoder class and provide
69  * implementations for the callbacks in the derived class; because of this
70  * there is no need for a 'client_data' property.
71  */
72
73 namespace OggFLAC {
74         namespace Encoder {
75
76                 // ============================================================
77                 //
78                 //  Equivalent: OggFLAC__StreamEncoder
79                 //
80                 // ============================================================
81
82                 /** \defgroup oggflacpp_stream_encoder OggFLAC++/encoder.h: stream encoder class
83                  *  \ingroup oggflacpp_encoder
84                  *
85                  *  \brief
86                  *  This class wraps the ::OggFLAC__StreamEncoder.
87                  *
88                  * See the \link oggflac_stream_encoder libOggFLAC stream encoder module \endlink.
89                  *
90                  * \{
91                  */
92
93                 /** This class wraps the ::OggFLAC__StreamEncoder.
94                  */
95                 class OggFLACPP_API Stream {
96                 public:
97                         class OggFLACPP_API State {
98                         public:
99                                 inline State(::OggFLAC__StreamEncoderState state): state_(state) { }
100                                 inline operator ::OggFLAC__StreamEncoderState() const { return state_; }
101                                 inline const char *as_cstring() const { return ::OggFLAC__StreamEncoderStateString[state_]; }
102                                 inline const char *resolved_as_cstring(const Stream &encoder) const { return ::OggFLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); }
103                         protected:
104                                 ::OggFLAC__StreamEncoderState state_;
105                         };
106
107                         Stream();
108                         virtual ~Stream();
109
110                         bool is_valid() const;
111                         inline operator bool() const { return is_valid(); }
112
113                         bool set_serial_number(long value);
114                         bool set_verify(bool value);
115                         bool set_streamable_subset(bool value);
116                         bool set_do_mid_side_stereo(bool value);
117                         bool set_loose_mid_side_stereo(bool value);
118                         bool set_channels(unsigned value);
119                         bool set_bits_per_sample(unsigned value);
120                         bool set_sample_rate(unsigned value);
121                         bool set_blocksize(unsigned value);
122                         bool set_apodization(const char *specification);
123                         bool set_max_lpc_order(unsigned value);
124                         bool set_qlp_coeff_precision(unsigned value);
125                         bool set_do_qlp_coeff_prec_search(bool value);
126                         bool set_do_escape_coding(bool value);
127                         bool set_do_exhaustive_model_search(bool value);
128                         bool set_min_residual_partition_order(unsigned value);
129                         bool set_max_residual_partition_order(unsigned value);
130                         bool set_rice_parameter_search_dist(unsigned value);
131                         bool set_total_samples_estimate(FLAC__uint64 value);
132                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
133
134                         State    get_state() const;
135                         FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
136                         FLAC::Decoder::Stream::State get_verify_decoder_state() const;
137                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
138                         bool     get_verify() const;
139                         bool     get_streamable_subset() const;
140                         bool     get_do_mid_side_stereo() const;
141                         bool     get_loose_mid_side_stereo() const;
142                         unsigned get_channels() const;
143                         unsigned get_bits_per_sample() const;
144                         unsigned get_sample_rate() const;
145                         unsigned get_blocksize() const;
146                         unsigned get_max_lpc_order() const;
147                         unsigned get_qlp_coeff_precision() const;
148                         bool     get_do_qlp_coeff_prec_search() const;
149                         bool     get_do_escape_coding() const;
150                         bool     get_do_exhaustive_model_search() const;
151                         unsigned get_min_residual_partition_order() const;
152                         unsigned get_max_residual_partition_order() const;
153                         unsigned get_rice_parameter_search_dist() const;
154                         FLAC__uint64 get_total_samples_estimate() const;
155
156                         State init();
157
158                         void finish();
159
160                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
161                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
162                 protected:
163                         virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
164                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
165
166 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
167                         // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
168                         friend State;
169 #endif
170                         ::OggFLAC__StreamEncoder *encoder_;
171                 private:
172                         static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
173                         static void metadata_callback_(const ::OggFLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
174
175                         // Private and undefined so you can't use them:
176                         Stream(const Stream &);
177                         void operator=(const Stream &);
178                 };
179
180                 /* \} */
181
182                 /** \defgroup oggflacpp_seekable_stream_encoder OggFLAC++/encoder.h: seekable stream encoder class
183                  *  \ingroup oggflacpp_encoder
184                  *
185                  *  \brief
186                  *  This class wraps the ::OggFLAC__SeekableStreamEncoder.
187                  *
188                  * See the \link oggflac_seekable_stream_encoder libOggFLAC seekable stream encoder module \endlink.
189                  *
190                  * \{
191                  */
192
193                 /** This class wraps the ::OggFLAC__SeekableStreamEncoder.
194                  */
195                 class OggFLACPP_API SeekableStream {
196                 public:
197                         class OggFLACPP_API State {
198                         public:
199                                 inline State(::OggFLAC__SeekableStreamEncoderState state): state_(state) { }
200                                 inline operator ::OggFLAC__SeekableStreamEncoderState() const { return state_; }
201                                 inline const char *as_cstring() const { return ::OggFLAC__SeekableStreamEncoderStateString[state_]; }
202                                 inline const char *resolved_as_cstring(const SeekableStream &encoder) const { return ::OggFLAC__seekable_stream_encoder_get_resolved_state_string(encoder.encoder_); }
203                         protected:
204                                 ::OggFLAC__SeekableStreamEncoderState state_;
205                         };
206
207                         SeekableStream();
208                         virtual ~SeekableStream();
209
210                         bool is_valid() const;
211                         inline operator bool() const { return is_valid(); }
212
213                         bool set_serial_number(long value);
214                         bool set_verify(bool value);
215                         bool set_streamable_subset(bool value);
216                         bool set_do_mid_side_stereo(bool value);
217                         bool set_loose_mid_side_stereo(bool value);
218                         bool set_channels(unsigned value);
219                         bool set_bits_per_sample(unsigned value);
220                         bool set_sample_rate(unsigned value);
221                         bool set_blocksize(unsigned value);
222                         bool set_apodization(const char *specification);
223                         bool set_max_lpc_order(unsigned value);
224                         bool set_qlp_coeff_precision(unsigned value);
225                         bool set_do_qlp_coeff_prec_search(bool value);
226                         bool set_do_escape_coding(bool value);
227                         bool set_do_exhaustive_model_search(bool value);
228                         bool set_min_residual_partition_order(unsigned value);
229                         bool set_max_residual_partition_order(unsigned value);
230                         bool set_rice_parameter_search_dist(unsigned value);
231                         bool set_total_samples_estimate(FLAC__uint64 value);
232                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
233
234                         State    get_state() const;
235                         FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
236                         FLAC::Decoder::Stream::State get_verify_decoder_state() const;
237                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
238                         bool     get_verify() const;
239                         bool     get_streamable_subset() const;
240                         bool     get_do_mid_side_stereo() const;
241                         bool     get_loose_mid_side_stereo() const;
242                         unsigned get_channels() const;
243                         unsigned get_bits_per_sample() const;
244                         unsigned get_sample_rate() const;
245                         unsigned get_blocksize() const;
246                         unsigned get_max_lpc_order() const;
247                         unsigned get_qlp_coeff_precision() const;
248                         bool     get_do_qlp_coeff_prec_search() const;
249                         bool     get_do_escape_coding() const;
250                         bool     get_do_exhaustive_model_search() const;
251                         unsigned get_min_residual_partition_order() const;
252                         unsigned get_max_residual_partition_order() const;
253                         unsigned get_rice_parameter_search_dist() const;
254                         FLAC__uint64 get_total_samples_estimate() const;
255
256                         State init();
257
258                         void finish();
259
260                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
261                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
262                 protected:
263                         virtual ::OggFLAC__SeekableStreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
264                         virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
265                         virtual ::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
266                         virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
267
268 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
269                         // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
270                         friend State;
271 #endif
272                         ::OggFLAC__SeekableStreamEncoder *encoder_;
273                 private:
274                         static ::OggFLAC__SeekableStreamEncoderReadStatus read_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
275                         static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
276                         static ::FLAC__SeekableStreamEncoderTellStatus tell_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
277                         static ::FLAC__StreamEncoderWriteStatus write_callback_(const OggFLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
278
279                         // Private and undefined so you can't use them:
280                         SeekableStream(const SeekableStream &);
281                         void operator=(const SeekableStream &);
282                 };
283
284                 /* \} */
285
286                 /** \defgroup oggflacpp_file_encoder OggFLAC++/encoder.h: file encoder class
287                  *  \ingroup oggflacpp_encoder
288                  *
289                  *  \brief
290                  *  This class wraps the ::OggFLAC__FileEncoder.
291                  *
292                  * See the \link oggflac_file_encoder libOggFLAC file encoder module \endlink.
293                  *
294                  * \{
295                  */
296
297                 /** This class wraps the ::OggFLAC__FileEncoder.
298                  */
299                 class OggFLACPP_API File {
300                 public:
301                         class OggFLACPP_API State {
302                         public:
303                                 inline State(::OggFLAC__FileEncoderState state): state_(state) { }
304                                 inline operator ::OggFLAC__FileEncoderState() const { return state_; }
305                                 inline const char *as_cstring() const { return ::OggFLAC__FileEncoderStateString[state_]; }
306                                 inline const char *resolved_as_cstring(const File &encoder) const { return ::OggFLAC__file_encoder_get_resolved_state_string(encoder.encoder_); }
307                         protected:
308                                 ::OggFLAC__FileEncoderState state_;
309                         };
310
311                         File();
312                         virtual ~File();
313
314                         bool is_valid() const;
315                         inline operator bool() const { return is_valid(); }
316
317                         bool set_serial_number(long value);
318                         bool set_verify(bool value);
319                         bool set_streamable_subset(bool value);
320                         bool set_do_mid_side_stereo(bool value);
321                         bool set_loose_mid_side_stereo(bool value);
322                         bool set_channels(unsigned value);
323                         bool set_bits_per_sample(unsigned value);
324                         bool set_sample_rate(unsigned value);
325                         bool set_blocksize(unsigned value);
326                         bool set_apodization(const char *specification);
327                         bool set_max_lpc_order(unsigned value);
328                         bool set_qlp_coeff_precision(unsigned value);
329                         bool set_do_qlp_coeff_prec_search(bool value);
330                         bool set_do_escape_coding(bool value);
331                         bool set_do_exhaustive_model_search(bool value);
332                         bool set_min_residual_partition_order(unsigned value);
333                         bool set_max_residual_partition_order(unsigned value);
334                         bool set_rice_parameter_search_dist(unsigned value);
335                         bool set_total_samples_estimate(FLAC__uint64 value);
336                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
337                         bool set_filename(const char *value);
338
339                         State    get_state() const;
340                         SeekableStream::State get_seekable_stream_encoder_state() const;
341                         FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
342                         FLAC::Decoder::Stream::State get_verify_decoder_state() const;
343                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
344                         bool     get_verify() const;
345                         bool     get_streamable_subset() const;
346                         bool     get_do_mid_side_stereo() const;
347                         bool     get_loose_mid_side_stereo() const;
348                         unsigned get_channels() const;
349                         unsigned get_bits_per_sample() const;
350                         unsigned get_sample_rate() const;
351                         unsigned get_blocksize() const;
352                         unsigned get_max_lpc_order() const;
353                         unsigned get_qlp_coeff_precision() const;
354                         bool     get_do_qlp_coeff_prec_search() const;
355                         bool     get_do_escape_coding() const;
356                         bool     get_do_exhaustive_model_search() const;
357                         unsigned get_min_residual_partition_order() const;
358                         unsigned get_max_residual_partition_order() const;
359                         unsigned get_rice_parameter_search_dist() const;
360                         FLAC__uint64 get_total_samples_estimate() const;
361
362                         State init();
363
364                         void finish();
365
366                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
367                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
368                 protected:
369                         virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
370
371 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
372                         // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
373                         friend State;
374 #endif
375                         ::OggFLAC__FileEncoder *encoder_;
376                 private:
377                         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);
378
379                         // Private and undefined so you can't use them:
380                         File(const Stream &);
381                         void operator=(const Stream &);
382                 };
383
384                 /* \} */
385
386         }
387 }
388
389 #endif