1
/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2
* Copyright (C) 2002,2003,2004,2005 Josh Coalson
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* - Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
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.
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.
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.
32
#ifndef OggFLACPP__ENCODER_H
33
#define OggFLACPP__ENCODER_H
37
#include "OggFLAC/file_encoder.h"
38
#include "OggFLAC/seekable_stream_encoder.h"
39
#include "OggFLAC/stream_encoder.h"
41
// we only need these for the state abstractions really...
42
#include "FLAC++/decoder.h"
43
#include "FLAC++/encoder.h"
46
/** \file include/OggFLAC++/encoder.h
49
* This module contains the classes which implement the various
52
* See the detailed documentation in the
53
* \link oggflacpp_encoder encoder \endlink module.
56
/** \defgroup oggflacpp_encoder OggFLAC++/encoder.h: encoder classes
60
* This module describes the three encoder layers provided by libOggFLAC++.
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.
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.
76
// ============================================================
78
// Equivalent: OggFLAC__StreamEncoder
80
// ============================================================
82
/** \defgroup oggflacpp_stream_encoder OggFLAC++/encoder.h: stream encoder class
83
* \ingroup oggflacpp_encoder
86
* This class wraps the ::OggFLAC__StreamEncoder.
88
* See the \link oggflac_stream_encoder libOggFLAC stream encoder module \endlink.
93
/** This class wraps the ::OggFLAC__StreamEncoder.
95
class OggFLACPP_API Stream {
97
class OggFLACPP_API State {
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_); }
104
::OggFLAC__StreamEncoderState state_;
110
bool is_valid() const;
111
inline operator bool() const { return is_valid(); }
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);
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;
159
bool process(const FLAC__int32 * const buffer[], unsigned samples);
160
bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
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;
165
#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
166
// lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
169
::OggFLAC__StreamEncoder *encoder_;
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);
174
// Private and undefined so you can't use them:
175
Stream(const Stream &);
176
void operator=(const Stream &);
181
/** \defgroup oggflacpp_seekable_stream_encoder OggFLAC++/encoder.h: seekable stream encoder class
182
* \ingroup oggflacpp_encoder
185
* This class wraps the ::OggFLAC__SeekableStreamEncoder.
187
* See the \link oggflac_seekable_stream_encoder libOggFLAC seekable stream encoder module \endlink.
192
/** This class wraps the ::OggFLAC__SeekableStreamEncoder.
194
class OggFLACPP_API SeekableStream {
196
class OggFLACPP_API State {
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_); }
203
::OggFLAC__SeekableStreamEncoderState state_;
207
virtual ~SeekableStream();
209
bool is_valid() const;
210
inline operator bool() const { return is_valid(); }
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);
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;
258
bool process(const FLAC__int32 * const buffer[], unsigned samples);
259
bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
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;
266
#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
267
// lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
270
::OggFLAC__SeekableStreamEncoder *encoder_;
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);
277
// Private and undefined so you can't use them:
278
SeekableStream(const SeekableStream &);
279
void operator=(const SeekableStream &);
284
/** \defgroup oggflacpp_file_encoder OggFLAC++/encoder.h: file encoder class
285
* \ingroup oggflacpp_encoder
288
* This class wraps the ::OggFLAC__FileEncoder.
290
* See the \link oggflac_file_encoder libOggFLAC file encoder module \endlink.
295
/** This class wraps the ::OggFLAC__FileEncoder.
297
class OggFLACPP_API File {
299
class OggFLACPP_API State {
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_); }
306
::OggFLAC__FileEncoderState state_;
312
bool is_valid() const;
313
inline operator bool() const { return is_valid(); }
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);
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;
363
bool process(const FLAC__int32 * const buffer[], unsigned samples);
364
bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
366
virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
368
#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
369
// lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
372
::OggFLAC__FileEncoder *encoder_;
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);
376
// Private and undefined so you can't use them:
377
File(const Stream &);
378
void operator=(const Stream &);