7123b0d764f5eca30051e678c10b5dce43161a43
[platform/upstream/flac.git] / include / OggFLAC++ / encoder.h
1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2  * Copyright (C) 2002,2003  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_max_lpc_order(unsigned value);
123                         bool set_qlp_coeff_precision(unsigned value);
124                         bool set_do_qlp_coeff_prec_search(bool value);
125                         bool set_do_escape_coding(bool value);
126                         bool set_do_exhaustive_model_search(bool value);
127                         bool set_min_residual_partition_order(unsigned value);
128                         bool set_max_residual_partition_order(unsigned value);
129                         bool set_rice_parameter_search_dist(unsigned value);
130                         bool set_total_samples_estimate(FLAC__uint64 value);
131                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
132
133                         State    get_state() const;
134                         FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
135                         FLAC::Decoder::Stream::State get_verify_decoder_state() const;
136                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
137                         bool     get_verify() const;
138                         bool     get_streamable_subset() const;
139                         bool     get_do_mid_side_stereo() const;
140                         bool     get_loose_mid_side_stereo() const;
141                         unsigned get_channels() const;
142                         unsigned get_bits_per_sample() const;
143                         unsigned get_sample_rate() const;
144                         unsigned get_blocksize() const;
145                         unsigned get_max_lpc_order() const;
146                         unsigned get_qlp_coeff_precision() const;
147                         bool     get_do_qlp_coeff_prec_search() const;
148                         bool     get_do_escape_coding() const;
149                         bool     get_do_exhaustive_model_search() const;
150                         unsigned get_min_residual_partition_order() const;
151                         unsigned get_max_residual_partition_order() const;
152                         unsigned get_rice_parameter_search_dist() const;
153                         FLAC__uint64 get_total_samples_estimate() const;
154
155                         State init();
156
157                         void finish();
158
159                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
160                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
161                 protected:
162                         virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
163                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
164
165 #ifdef _MSC_VER
166                 //@@@@@@ lame hack: some MSVC versions can't see a protected encoder_ from nested State::resolved_as_cstring(); fix properly later
167                 public:
168 #endif
169                         ::OggFLAC__StreamEncoder *encoder_;
170                 private:
171                         static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
172                         static void metadata_callback_(const ::OggFLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
173
174                         // Private and undefined so you can't use them:
175                         Stream(const Stream &);
176                         void operator=(const Stream &);
177                 };
178
179                 /* \} */
180
181                 /** \defgroup oggflacpp_seekable_stream_encoder OggFLAC++/encoder.h: seekable stream encoder class
182                  *  \ingroup oggflacpp_encoder
183                  *
184                  *  \brief
185                  *  This class wraps the ::OggFLAC__SeekableStreamEncoder.
186                  *
187                  * See the \link oggflac_seekable_stream_encoder libOggFLAC seekable stream encoder module \endlink.
188                  *
189                  * \{
190                  */
191
192                 /** This class wraps the ::OggFLAC__SeekableStreamEncoder.
193                  */
194                 class OggFLACPP_API SeekableStream {
195                 public:
196                         class OggFLACPP_API State {
197                         public:
198                                 inline State(::OggFLAC__SeekableStreamEncoderState state): state_(state) { }
199                                 inline operator ::OggFLAC__SeekableStreamEncoderState() const { return state_; }
200                                 inline const char *as_cstring() const { return ::OggFLAC__SeekableStreamEncoderStateString[state_]; }
201                                 inline const char *resolved_as_cstring(const SeekableStream &encoder) const { return ::OggFLAC__seekable_stream_encoder_get_resolved_state_string(encoder.encoder_); }
202                         protected:
203                                 ::OggFLAC__SeekableStreamEncoderState state_;
204                         };
205
206                         SeekableStream();
207                         virtual ~SeekableStream();
208
209                         bool is_valid() const;
210                         inline operator bool() const { return is_valid(); }
211
212                         bool set_serial_number(long value);
213                         bool set_verify(bool value);
214                         bool set_streamable_subset(bool value);
215                         bool set_do_mid_side_stereo(bool value);
216                         bool set_loose_mid_side_stereo(bool value);
217                         bool set_channels(unsigned value);
218                         bool set_bits_per_sample(unsigned value);
219                         bool set_sample_rate(unsigned value);
220                         bool set_blocksize(unsigned value);
221                         bool set_max_lpc_order(unsigned value);
222                         bool set_qlp_coeff_precision(unsigned value);
223                         bool set_do_qlp_coeff_prec_search(bool value);
224                         bool set_do_escape_coding(bool value);
225                         bool set_do_exhaustive_model_search(bool value);
226                         bool set_min_residual_partition_order(unsigned value);
227                         bool set_max_residual_partition_order(unsigned value);
228                         bool set_rice_parameter_search_dist(unsigned value);
229                         bool set_total_samples_estimate(FLAC__uint64 value);
230                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
231
232                         State    get_state() const;
233                         FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
234                         FLAC::Decoder::Stream::State get_verify_decoder_state() const;
235                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
236                         bool     get_verify() const;
237                         bool     get_streamable_subset() const;
238                         bool     get_do_mid_side_stereo() const;
239                         bool     get_loose_mid_side_stereo() const;
240                         unsigned get_channels() const;
241                         unsigned get_bits_per_sample() const;
242                         unsigned get_sample_rate() const;
243                         unsigned get_blocksize() const;
244                         unsigned get_max_lpc_order() const;
245                         unsigned get_qlp_coeff_precision() const;
246                         bool     get_do_qlp_coeff_prec_search() const;
247                         bool     get_do_escape_coding() const;
248                         bool     get_do_exhaustive_model_search() const;
249                         unsigned get_min_residual_partition_order() const;
250                         unsigned get_max_residual_partition_order() const;
251                         unsigned get_rice_parameter_search_dist() const;
252                         FLAC__uint64 get_total_samples_estimate() const;
253
254                         State init();
255
256                         void finish();
257
258                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
259                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
260                 protected:
261                         virtual ::OggFLAC__SeekableStreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
262                         virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
263                         virtual ::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
264                         virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
265
266 #ifdef _MSC_VER
267                 //@@@@@@ lame hack: some MSVC versions can't see a protected encoder_ from nested State::resolved_as_cstring(); fix properly later
268                 public:
269 #endif
270                         ::OggFLAC__SeekableStreamEncoder *encoder_;
271                 private:
272                         static ::OggFLAC__SeekableStreamEncoderReadStatus read_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
273                         static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
274                         static ::FLAC__SeekableStreamEncoderTellStatus tell_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
275                         static ::FLAC__StreamEncoderWriteStatus write_callback_(const OggFLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
276
277                         // Private and undefined so you can't use them:
278                         SeekableStream(const SeekableStream &);
279                         void operator=(const SeekableStream &);
280                 };
281
282                 /* \} */
283
284                 /** \defgroup oggflacpp_file_encoder OggFLAC++/encoder.h: file encoder class
285                  *  \ingroup oggflacpp_encoder
286                  *
287                  *  \brief
288                  *  This class wraps the ::OggFLAC__FileEncoder.
289                  *
290                  * See the \link oggflac_file_encoder libOggFLAC file encoder module \endlink.
291                  *
292                  * \{
293                  */
294
295                 /** This class wraps the ::OggFLAC__FileEncoder.
296                  */
297                 class OggFLACPP_API File {
298                 public:
299                         class OggFLACPP_API State {
300                         public:
301                                 inline State(::OggFLAC__FileEncoderState state): state_(state) { }
302                                 inline operator ::OggFLAC__FileEncoderState() const { return state_; }
303                                 inline const char *as_cstring() const { return ::OggFLAC__FileEncoderStateString[state_]; }
304                                 inline const char *resolved_as_cstring(const File &encoder) const { return ::OggFLAC__file_encoder_get_resolved_state_string(encoder.encoder_); }
305                         protected:
306                                 ::OggFLAC__FileEncoderState state_;
307                         };
308
309                         File();
310                         virtual ~File();
311
312                         bool is_valid() const;
313                         inline operator bool() const { return is_valid(); }
314
315                         bool set_serial_number(long value);
316                         bool set_verify(bool value);
317                         bool set_streamable_subset(bool value);
318                         bool set_do_mid_side_stereo(bool value);
319                         bool set_loose_mid_side_stereo(bool value);
320                         bool set_channels(unsigned value);
321                         bool set_bits_per_sample(unsigned value);
322                         bool set_sample_rate(unsigned value);
323                         bool set_blocksize(unsigned value);
324                         bool set_max_lpc_order(unsigned value);
325                         bool set_qlp_coeff_precision(unsigned value);
326                         bool set_do_qlp_coeff_prec_search(bool value);
327                         bool set_do_escape_coding(bool value);
328                         bool set_do_exhaustive_model_search(bool value);
329                         bool set_min_residual_partition_order(unsigned value);
330                         bool set_max_residual_partition_order(unsigned value);
331                         bool set_rice_parameter_search_dist(unsigned value);
332                         bool set_total_samples_estimate(FLAC__uint64 value);
333                         bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
334                         bool set_filename(const char *value);
335
336                         State    get_state() const;
337                         SeekableStream::State get_seekable_stream_encoder_state() const;
338                         FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const;
339                         FLAC::Decoder::Stream::State get_verify_decoder_state() const;
340                         void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
341                         bool     get_verify() const;
342                         bool     get_streamable_subset() const;
343                         bool     get_do_mid_side_stereo() const;
344                         bool     get_loose_mid_side_stereo() const;
345                         unsigned get_channels() const;
346                         unsigned get_bits_per_sample() const;
347                         unsigned get_sample_rate() const;
348                         unsigned get_blocksize() const;
349                         unsigned get_max_lpc_order() const;
350                         unsigned get_qlp_coeff_precision() const;
351                         bool     get_do_qlp_coeff_prec_search() const;
352                         bool     get_do_escape_coding() const;
353                         bool     get_do_exhaustive_model_search() const;
354                         unsigned get_min_residual_partition_order() const;
355                         unsigned get_max_residual_partition_order() const;
356                         unsigned get_rice_parameter_search_dist() const;
357                         FLAC__uint64 get_total_samples_estimate() const;
358
359                         State init();
360
361                         void finish();
362
363                         bool process(const FLAC__int32 * const buffer[], unsigned samples);
364                         bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
365                 protected:
366                         virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
367
368 #ifdef _MSC_VER
369                 //@@@@@@ lame hack: some MSVC versions can't see a protected encoder_ from nested State::resolved_as_cstring(); fix properly later
370                 public:
371 #endif
372                         ::OggFLAC__FileEncoder *encoder_;
373                 private:
374                         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);
375
376                         // Private and undefined so you can't use them:
377                         File(const Stream &);
378                         void operator=(const Stream &);
379                 };
380
381                 /* \} */
382
383         };
384 };
385
386 #endif