2774d61ac62f902a9e309f37b9a5da0a1f81feb5
[platform/upstream/flac.git] / include / OggFLAC / stream_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 OggFLAC__STREAM_ENCODER_H
33 #define OggFLAC__STREAM_ENCODER_H
34
35 #include "export.h"
36
37 #include "FLAC/stream_encoder.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43
44 /** \file include/OggFLAC/stream_encoder.h
45  *
46  *  \brief
47  *  This module contains the functions which implement the stream
48  *  encoder.
49  *
50  *  See the detailed documentation in the
51  *  \link oggflac_stream_encoder stream encoder \endlink module.
52  */
53
54 /** \defgroup oggflac_encoder OggFLAC/ *_encoder.h: encoder interfaces
55  *  \ingroup oggflac
56  *
57  *  \brief
58  *  This module describes the three encoder layers provided by libOggFLAC.
59  *
60  * libOggFLAC currently provides the same three layers of access as libFLAC;
61  * the interfaces are nearly identical, with the addition of a method for
62  * specifying the Ogg serial number.  See the \link flac_encoder FLAC
63  * encoder module \endlink for full documentation.
64  */
65
66 /** \defgroup oggflac_stream_encoder OggFLAC/stream_encoder.h: stream encoder interface
67  *  \ingroup oggflac_encoder
68  *
69  *  \brief
70  *  This module contains the functions which implement the stream
71  *  encoder.  The Ogg stream encoder is derived
72  *  from the FLAC stream encoder.
73  *
74  * The interface here is nearly identical to FLAC's stream encoder,
75  * including the callbacks, with the addition of
76  * OggFLAC__stream_encoder_set_serial_number().  See the
77  * \link flac_stream_encoder FLAC stream encoder module \endlink
78  * for full documentation.
79  *
80  * \{
81  */
82
83
84 /** State values for an OggFLAC__StreamEncoder
85  *
86  *  The encoder's state can be obtained by calling OggFLAC__stream_encoder_get_state().
87  */
88 typedef enum {
89
90         OggFLAC__STREAM_ENCODER_OK = 0,
91         /**< The encoder is in the normal OK state and samples can be processed. */
92
93         OggFLAC__STREAM_ENCODER_UNINITIALIZED,
94         /**< The encoder is in the uninitialized state; one of the
95          * OggFLAC__stream_encoder_init_*() functions must be called before samples
96          * can be processed.
97          */
98
99         OggFLAC__STREAM_ENCODER_OGG_ERROR,
100         /**< An error occurred in the underlying Ogg layer.  */
101
102         OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR,
103         /**< An error occurred in the underlying FLAC stream encoder;
104          * check OggFLAC__stream_encoder_get_FLAC_stream_encoder_state().
105          */
106
107         OggFLAC__STREAM_ENCODER_CLIENT_ERROR,
108         /**< One of the callbacks returned a fatal error. */
109
110         OggFLAC__STREAM_ENCODER_IO_ERROR,
111         /**< An I/O error occurred while opening/reading/writing a file.
112          * Check \c errno.
113          */
114
115         OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
116         /**< Memory allocation failed. */
117
118 } OggFLAC__StreamEncoderState;
119
120 /** Maps an OggFLAC__StreamEncoderState to a C string.
121  *
122  *  Using an OggFLAC__StreamEncoderState as the index to this array
123  *  will give the string equivalent.  The contents should not be modified.
124  */
125 extern OggFLAC_API const char * const OggFLAC__StreamEncoderStateString[];
126
127
128 /** Return values for the OggFLAC__StreamEncoder read callback.
129  */
130 typedef enum {
131
132         OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
133         /**< The read was OK and decoding can continue. */
134
135         OggFLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
136         /**< The read was attempted at the end of the stream. */
137
138         OggFLAC__STREAM_ENCODER_READ_STATUS_ABORT,
139         /**< An unrecoverable error occurred. */
140
141         OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
142         /**< Client does not support reading back from the output. */
143
144 } OggFLAC__StreamEncoderReadStatus;
145
146 /** Maps a OggFLAC__StreamEncoderReadStatus to a C string.
147  *
148  *  Using a OggFLAC__StreamEncoderReadStatus as the index to this array
149  *  will give the string equivalent.  The contents should not be modified.
150  */
151 extern OggFLAC_API const char * const OggFLAC__StreamEncoderReadStatusString[];
152
153
154 /***********************************************************************
155  *
156  * class OggFLAC__StreamEncoder
157  *
158  ***********************************************************************/
159
160 struct OggFLAC__StreamEncoderProtected;
161 struct OggFLAC__StreamEncoderPrivate;
162 /** The opaque structure definition for the stream encoder type.
163  *  See the \link oggflac_stream_encoder stream encoder module \endlink
164  *  for a detailed description.
165  */
166 typedef struct {
167         FLAC__StreamEncoder super_; /* parentclass@@@@@@ */
168         struct OggFLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
169         struct OggFLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
170 } OggFLAC__StreamEncoder;
171
172 /** Signature for the read callback.
173  *
174  *  A function pointer matching this signature must be passed to
175  *  OggFLAC__stream_encoder_init_stream() if seeking is supported.
176  *  The supplied function will be called when the encoder needs to read back
177  *  encoded data.  This happens during the metadata callback, when the encoder
178  *  has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered
179  *  while encoding.  The address of the buffer to be filled is supplied, along
180  *  with the number of bytes the buffer can hold.  The callback may choose to
181  *  supply less data and modify the byte count but must be careful not to
182  *  overflow the buffer.  The callback then returns a status code chosen from
183  *  OggFLAC__StreamEncoderReadStatus.
184  *
185  * \note In general, FLAC__StreamEncoder functions which change the
186  * state should not be called on the \a encoder while in the callback.
187  *
188  * \param  encoder  The encoder instance calling the callback.
189  * \param  buffer   A pointer to a location for the callee to store
190  *                  data to be encoded.
191  * \param  bytes    A pointer to the size of the buffer.  On entry
192  *                  to the callback, it contains the maximum number
193  *                  of bytes that may be stored in \a buffer.  The
194  *                  callee must set it to the actual number of bytes
195  *                  stored (0 in case of error or end-of-stream) before
196  *                  returning.
197  * \param  client_data  The callee's client data set through
198  *                      OggFLAC__stream_encoder_set_client_data().
199  * \retval OggFLAC__StreamEncoderReadStatus
200  *    The callee's return status.
201  */
202 typedef OggFLAC__StreamEncoderReadStatus (*OggFLAC__StreamEncoderReadCallback)(const OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
203
204
205 /***********************************************************************
206  *
207  * Class constructor/destructor
208  *
209  ***********************************************************************/
210
211 /** Create a new stream encoder instance.  The instance is created with
212  *  default settings; see the individual OggFLAC__stream_encoder_set_*()
213  *  functions for each setting's default.
214  *
215  * \retval OggFLAC__StreamEncoder*
216  *    \c NULL if there was an error allocating memory, else the new instance.
217  */
218 OggFLAC_API OggFLAC__StreamEncoder *OggFLAC__stream_encoder_new();
219
220 /** Free an encoder instance.  Deletes the object pointed to by \a encoder.
221  *
222  * \param encoder  A pointer to an existing encoder.
223  * \assert
224  *    \code encoder != NULL \endcode
225  */
226 OggFLAC_API void OggFLAC__stream_encoder_delete(OggFLAC__StreamEncoder *encoder);
227
228
229 /***********************************************************************
230  *
231  * Public class method prototypes
232  *
233  ***********************************************************************/
234
235 /** Set the serial number for the FLAC stream.
236  *
237  * \note
238  * It is recommended to set a serial number explicitly as the default of '0'
239  * may collide with other streams.
240  *
241  * \default \c 0
242  * \param  encoder        An encoder instance to set.
243  * \param  serial_number  See above.
244  * \assert
245  *    \code encoder != NULL \endcode
246  * \retval FLAC__bool
247  *    \c false if the encoder is already initialized, else \c true.
248  */
249 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_serial_number(OggFLAC__StreamEncoder *encoder, long serial_number);
250
251 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_verify()
252  *
253  * \default \c false
254  * \param  encoder  An encoder instance to set.
255  * \param  value    Flag value (see above).
256  * \assert
257  *    \code encoder != NULL \endcode
258  * \retval FLAC__bool
259  *    \c false if the encoder is already initialized, else \c true.
260  */
261 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_verify(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
262
263 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_streamable_subset()
264  *
265  * \default \c true
266  * \param  encoder  An encoder instance to set.
267  * \param  value    Flag value (see above).
268  * \assert
269  *    \code encoder != NULL \endcode
270  * \retval FLAC__bool
271  *    \c false if the encoder is already initialized, else \c true.
272  */
273 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_streamable_subset(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
274
275 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_mid_side_stereo()
276  *
277  * \default \c false
278  * \param  encoder  An encoder instance to set.
279  * \param  value    Flag value (see above).
280  * \assert
281  *    \code encoder != NULL \endcode
282  * \retval FLAC__bool
283  *    \c false if the encoder is already initialized, else \c true.
284  */
285 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
286
287 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_loose_mid_side_stereo()
288  *
289  * \default \c false
290  * \param  encoder  An encoder instance to set.
291  * \param  value    Flag value (see above).
292  * \assert
293  *    \code encoder != NULL \endcode
294  * \retval FLAC__bool
295  *    \c false if the encoder is already initialized, else \c true.
296  */
297 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_loose_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
298
299 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_channels()
300  *
301  * \default \c 2
302  * \param  encoder  An encoder instance to set.
303  * \param  value    See above.
304  * \assert
305  *    \code encoder != NULL \endcode
306  * \retval FLAC__bool
307  *    \c false if the encoder is already initialized, else \c true.
308  */
309 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_channels(OggFLAC__StreamEncoder *encoder, unsigned value);
310
311 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_bits_per_sample()
312  *
313  * \default \c 16
314  * \param  encoder  An encoder instance to set.
315  * \param  value    See above.
316  * \assert
317  *    \code encoder != NULL \endcode
318  * \retval FLAC__bool
319  *    \c false if the encoder is already initialized, else \c true.
320  */
321 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_bits_per_sample(OggFLAC__StreamEncoder *encoder, unsigned value);
322
323 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_sample_rate()
324  *
325  * \default \c 44100
326  * \param  encoder  An encoder instance to set.
327  * \param  value    See above.
328  * \assert
329  *    \code encoder != NULL \endcode
330  * \retval FLAC__bool
331  *    \c false if the encoder is already initialized, else \c true.
332  */
333 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_sample_rate(OggFLAC__StreamEncoder *encoder, unsigned value);
334
335 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_blocksize()
336  *
337  * \default \c 1152
338  * \param  encoder  An encoder instance to set.
339  * \param  value    See above.
340  * \assert
341  *    \code encoder != NULL \endcode
342  * \retval FLAC__bool
343  *    \c false if the encoder is already initialized, else \c true.
344  */
345 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_blocksize(OggFLAC__StreamEncoder *encoder, unsigned value);
346
347 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_apodization()
348  *
349  * \default \c 0
350  * \param  encoder        An encoder instance to set.
351  * \param  specification  See above.
352  * \assert
353  *    \code encoder != NULL \endcode
354  *    \code specification != NULL \endcode
355  * \retval FLAC__bool
356  *    \c false if the encoder is already initialized, else \c true.
357  */
358 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_apodization(OggFLAC__StreamEncoder *encoder, const char *specification);
359
360 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_lpc_order()
361  *
362  * \default \c 0
363  * \param  encoder  An encoder instance to set.
364  * \param  value    See above.
365  * \assert
366  *    \code encoder != NULL \endcode
367  * \retval FLAC__bool
368  *    \c false if the encoder is already initialized, else \c true.
369  */
370 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_lpc_order(OggFLAC__StreamEncoder *encoder, unsigned value);
371
372 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_precision()
373  *
374  * \default \c 0
375  * \param  encoder  An encoder instance to set.
376  * \param  value    See above.
377  * \assert
378  *    \code encoder != NULL \endcode
379  * \retval FLAC__bool
380  *    \c false if the encoder is already initialized, else \c true.
381  */
382 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_qlp_coeff_precision(OggFLAC__StreamEncoder *encoder, unsigned value);
383
384 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_prec_search()
385  *
386  * \default \c false
387  * \param  encoder  An encoder instance to set.
388  * \param  value    See above.
389  * \assert
390  *    \code encoder != NULL \endcode
391  * \retval FLAC__bool
392  *    \c false if the encoder is already initialized, else \c true.
393  */
394 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
395
396 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_escape_coding()
397  *
398  * \default \c false
399  * \param  encoder  An encoder instance to set.
400  * \param  value    See above.
401  * \assert
402  *    \code encoder != NULL \endcode
403  * \retval FLAC__bool
404  *    \c false if the encoder is already initialized, else \c true.
405  */
406 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_escape_coding(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
407
408 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_exhaustive_model_search()
409  *
410  * \default \c false
411  * \param  encoder  An encoder instance to set.
412  * \param  value    See above.
413  * \assert
414  *    \code encoder != NULL \endcode
415  * \retval FLAC__bool
416  *    \c false if the encoder is already initialized, else \c true.
417  */
418 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_exhaustive_model_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
419
420 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_min_residual_partition_order()
421  *
422  * \default \c 0
423  * \param  encoder  An encoder instance to set.
424  * \param  value    See above.
425  * \assert
426  *    \code encoder != NULL \endcode
427  * \retval FLAC__bool
428  *    \c false if the encoder is already initialized, else \c true.
429  */
430 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_min_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value);
431
432 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_residual_partition_order()
433  *
434  * \default \c 0
435  * \param  encoder  An encoder instance to set.
436  * \param  value    See above.
437  * \assert
438  *    \code encoder != NULL \endcode
439  * \retval FLAC__bool
440  *    \c false if the encoder is already initialized, else \c true.
441  */
442 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value);
443
444 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_rice_parameter_search_dist()
445  *
446  * \default \c 0
447  * \param  encoder  An encoder instance to set.
448  * \param  value    See above.
449  * \assert
450  *    \code encoder != NULL \endcode
451  * \retval FLAC__bool
452  *    \c false if the encoder is already initialized, else \c true.
453  */
454 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_rice_parameter_search_dist(OggFLAC__StreamEncoder *encoder, unsigned value);
455
456 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_total_samples_estimate()
457  *
458  * \default \c 0
459  * \param  encoder  An encoder instance to set.
460  * \param  value    See above.
461  * \assert
462  *    \code encoder != NULL \endcode
463  * \retval FLAC__bool
464  *    \c false if the encoder is already initialized, else \c true.
465  */
466 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_total_samples_estimate(OggFLAC__StreamEncoder *encoder, FLAC__uint64 value);
467
468 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_metadata()
469  *
470  * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be
471  * the second metadata block of the stream.  The encoder already supplies
472  * the STREAMINFO block automatically.  If \a metadata does not contain a
473  * VORBIS_COMMENT block, the encoder will supply that too.  Otherwise, if
474  * \a metadata does contain a VORBIS_COMMENT block and it is not the
475  * first, this function will reorder \a metadata by moving the
476  * VORBIS_COMMENT block to the front; the relative ordering of the other
477  * blocks will remain as they were.
478  *
479  * \note The Ogg FLAC mapping limits the number of metadata blocks per
480  * stream to \c 65535.  If \a num_blocks exceeds this the function will
481  * return \c false.
482  *
483  * \default \c NULL, 0
484  * \param  encoder     An encoder instance to set.
485  * \param  metadata    See above.
486  * \param  num_blocks  See above.
487  * \assert
488  *    \code encoder != NULL \endcode
489  * \retval FLAC__bool
490  *    \c false if the encoder is already initialized, or if
491  *    \a num_blocks > 65535, else \c true.
492  */
493 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_metadata(OggFLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
494
495 /** Get the current encoder state.
496  *
497  * \param  encoder  An encoder instance to query.
498  * \assert
499  *    \code encoder != NULL \endcode
500  * \retval OggFLAC__StreamEncoderState
501  *    The current encoder state.
502  */
503 OggFLAC_API OggFLAC__StreamEncoderState OggFLAC__stream_encoder_get_state(const OggFLAC__StreamEncoder *encoder);
504
505 /** Get the state of the underlying FLAC stream encoder.
506  *  Useful when the stream encoder state is
507  *  \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR.
508  *
509  * \param  encoder  An encoder instance to query.
510  * \assert
511  *    \code encoder != NULL \endcode
512  * \retval FLAC__StreamEncoderState
513  *    The FLAC stream encoder state.
514  */
515 OggFLAC_API FLAC__StreamEncoderState OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(const OggFLAC__StreamEncoder *encoder);
516
517 /** Get the state of the underlying FLAC stream encoder's verify decoder.
518  *  Useful when the stream encoder state is
519  *  \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR and the
520  *  FLAC encoder state is \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
521  *
522  * \param  encoder  An encoder instance to query.
523  * \assert
524  *    \code encoder != NULL \endcode
525  * \retval FLAC__StreamDecoderState
526  *    The FLAC verify decoder state.
527  */
528 OggFLAC_API FLAC__StreamDecoderState OggFLAC__stream_encoder_get_verify_decoder_state(const OggFLAC__StreamEncoder *encoder);
529
530 /** Get the current encoder state as a C string.
531  *  This version automatically resolves
532  *  \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR by getting the
533  *  FLAC stream encoder's state.
534  *
535  * \param  encoder  A encoder instance to query.
536  * \assert
537  *    \code encoder != NULL \endcode
538  * \retval const char *
539  *    The encoder state as a C string.  Do not modify the contents.
540  */
541 OggFLAC_API const char *OggFLAC__stream_encoder_get_resolved_state_string(const OggFLAC__StreamEncoder *encoder);
542
543 /** Get relevant values about the nature of a verify decoder error.
544  *  Inherited from FLAC__stream_encoder_get_verify_decoder_error_stats().
545  *  Useful when the stream encoder state is
546  *  \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR and the
547  *  FLAC stream encoder state is
548  *  \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
549  *
550  * \param  encoder  An encoder instance to query.
551  * \param  absolute_sample  The absolute sample number of the mismatch.
552  * \param  frame_number  The number of the frame in which the mismatch occurred.
553  * \param  channel       The channel in which the mismatch occurred.
554  * \param  sample        The number of the sample (relative to the frame) in
555  *                       which the mismatch occurred.
556  * \param  expected      The expected value for the sample in question.
557  * \param  got           The actual value returned by the decoder.
558  * \assert
559  *    \code encoder != NULL \endcode
560  *    \code absolute_sample != NULL \endcode
561  *    \code frame_number != NULL \endcode
562  *    \code channel != NULL \endcode
563  *    \code sample != NULL \endcode
564  *    \code expected != NULL \endcode
565  */
566 OggFLAC_API void OggFLAC__stream_encoder_get_verify_decoder_error_stats(const OggFLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
567
568 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_verify()
569  *
570  * \param  encoder  An encoder instance to query.
571  * \assert
572  *    \code encoder != NULL \endcode
573  * \retval FLAC__bool
574  *    See OggFLAC__stream_encoder_set_verify().
575  */
576 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_verify(const OggFLAC__StreamEncoder *encoder);
577
578 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_streamable_subset()
579  *
580  * \param  encoder  An encoder instance to query.
581  * \assert
582  *    \code encoder != NULL \endcode
583  * \retval FLAC__bool
584  *    See OggFLAC__stream_encoder_set_streamable_subset().
585  */
586 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_streamable_subset(const OggFLAC__StreamEncoder *encoder);
587
588 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_mid_side_stereo()
589  *
590  * \param  encoder  An encoder instance to query.
591  * \assert
592  *    \code encoder != NULL \endcode
593  * \retval FLAC__bool
594  *    See OggFLAC__stream_encoder_get_do_mid_side_stereo().
595  */
596 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_mid_side_stereo(const OggFLAC__StreamEncoder *encoder);
597
598 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_loose_mid_side_stereo()
599  *
600  * \param  encoder  An encoder instance to query.
601  * \assert
602  *    \code encoder != NULL \endcode
603  * \retval FLAC__bool
604  *    See OggFLAC__stream_encoder_set_loose_mid_side_stereo().
605  */
606 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_loose_mid_side_stereo(const OggFLAC__StreamEncoder *encoder);
607
608 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_channels()
609  *
610  * \param  encoder  An encoder instance to query.
611  * \assert
612  *    \code encoder != NULL \endcode
613  * \retval unsigned
614  *    See OggFLAC__stream_encoder_set_channels().
615  */
616 OggFLAC_API unsigned OggFLAC__stream_encoder_get_channels(const OggFLAC__StreamEncoder *encoder);
617
618 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_bits_per_sample()
619  *
620  * \param  encoder  An encoder instance to query.
621  * \assert
622  *    \code encoder != NULL \endcode
623  * \retval unsigned
624  *    See OggFLAC__stream_encoder_set_bits_per_sample().
625  */
626 OggFLAC_API unsigned OggFLAC__stream_encoder_get_bits_per_sample(const OggFLAC__StreamEncoder *encoder);
627
628 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_sample_rate()
629  *
630  * \param  encoder  An encoder instance to query.
631  * \assert
632  *    \code encoder != NULL \endcode
633  * \retval unsigned
634  *    See OggFLAC__stream_encoder_set_sample_rate().
635  */
636 OggFLAC_API unsigned OggFLAC__stream_encoder_get_sample_rate(const OggFLAC__StreamEncoder *encoder);
637
638 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_blocksize()
639  *
640  * \param  encoder  An encoder instance to query.
641  * \assert
642  *    \code encoder != NULL \endcode
643  * \retval unsigned
644  *    See OggFLAC__stream_encoder_set_blocksize().
645  */
646 OggFLAC_API unsigned OggFLAC__stream_encoder_get_blocksize(const OggFLAC__StreamEncoder *encoder);
647
648 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_max_lpc_order()
649  *
650  * \param  encoder  An encoder instance to query.
651  * \assert
652  *    \code encoder != NULL \endcode
653  * \retval unsigned
654  *    See OggFLAC__stream_encoder_set_max_lpc_order().
655  */
656 OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_lpc_order(const OggFLAC__StreamEncoder *encoder);
657
658 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_qlp_coeff_precision()
659  *
660  * \param  encoder  An encoder instance to query.
661  * \assert
662  *    \code encoder != NULL \endcode
663  * \retval unsigned
664  *    See OggFLAC__stream_encoder_set_qlp_coeff_precision().
665  */
666 OggFLAC_API unsigned OggFLAC__stream_encoder_get_qlp_coeff_precision(const OggFLAC__StreamEncoder *encoder);
667
668 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
669  *
670  * \param  encoder  An encoder instance to query.
671  * \assert
672  *    \code encoder != NULL \endcode
673  * \retval FLAC__bool
674  *    See OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search().
675  */
676 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__StreamEncoder *encoder);
677
678 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_escape_coding()
679  *
680  * \param  encoder  An encoder instance to query.
681  * \assert
682  *    \code encoder != NULL \endcode
683  * \retval FLAC__bool
684  *    See OggFLAC__stream_encoder_set_do_escape_coding().
685  */
686 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_escape_coding(const OggFLAC__StreamEncoder *encoder);
687
688 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_exhaustive_model_search()
689  *
690  * \param  encoder  An encoder instance to query.
691  * \assert
692  *    \code encoder != NULL \endcode
693  * \retval FLAC__bool
694  *    See OggFLAC__stream_encoder_set_do_exhaustive_model_search().
695  */
696 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_exhaustive_model_search(const OggFLAC__StreamEncoder *encoder);
697
698 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_min_residual_partition_order()
699  *
700  * \param  encoder  An encoder instance to query.
701  * \assert
702  *    \code encoder != NULL \endcode
703  * \retval unsigned
704  *    See OggFLAC__stream_encoder_set_min_residual_partition_order().
705  */
706 OggFLAC_API unsigned OggFLAC__stream_encoder_get_min_residual_partition_order(const OggFLAC__StreamEncoder *encoder);
707
708 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_man_residual_partition_order()
709  *
710  * \param  encoder  An encoder instance to query.
711  * \assert
712  *    \code encoder != NULL \endcode
713  * \retval unsigned
714  *    See OggFLAC__stream_encoder_set_max_residual_partition_order().
715  */
716 OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_residual_partition_order(const OggFLAC__StreamEncoder *encoder);
717
718 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_rice_parameter_search_dist()
719  *
720  * \param  encoder  An encoder instance to query.
721  * \assert
722  *    \code encoder != NULL \endcode
723  * \retval unsigned
724  *    See OggFLAC__stream_encoder_set_rice_parameter_search_dist().
725  */
726 OggFLAC_API unsigned OggFLAC__stream_encoder_get_rice_parameter_search_dist(const OggFLAC__StreamEncoder *encoder);
727
728 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_total_samples_estimate()
729  *
730  * \param  encoder  An encoder instance to set.
731  * \assert
732  *    \code encoder != NULL \endcode
733  * \retval FLAC__uint64
734  *    See OggFLAC__stream_encoder_get_total_samples_estimate().
735  */
736 OggFLAC_API FLAC__uint64 OggFLAC__stream_encoder_get_total_samples_estimate(const OggFLAC__StreamEncoder *encoder);
737
738 /** Initialize the encoder instance.
739  *  Should be called after OggFLAC__stream_encoder_new() and
740  *  OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
741  *  or OggFLAC__stream_encoder_process_interleaved().  Will set and return
742  *  the encoder state, which will be OggFLAC__STREAM_ENCODER_OK if
743  *  initialization succeeded.
744  *
745  *  The call to OggFLAC__stream_encoder_init() currently will also immediately
746  *  call the write callback several times, once with the \c fLaC signature,
747  *  and once for each encoded metadata block.
748  *
749  * \param  encoder  An uninitialized encoder instance.
750  * \assert
751  *    \code encoder != NULL \endcode
752  * \retval OggFLAC__StreamEncoderState
753  *    \c OggFLAC__STREAM_ENCODER_OK if initialization was successful; see
754  *    OggFLAC__StreamEncoderState for the meanings of other return values.
755  */
756 OggFLAC_API OggFLAC__StreamEncoderState OggFLAC__stream_encoder_init(OggFLAC__StreamEncoder *encoder);
757
758 /** Initialize the encoder instance.
759  *
760  *  This flavor of initialization sets up the encoder to encode to a stream.
761  *  I/O is performed via callbacks to the client.  For encoding to a plain file
762  *  via filename or open \c FILE*, OggFLAC__stream_encoder_init_file() and
763  *  OggFLAC__stream_encoder_init_FILE() provide a simpler interface.
764  *
765  *  This function should be called after OggFLAC__stream_encoder_new() and
766  *  OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
767  *  or OggFLAC__stream_encoder_process_interleaved().
768  *  initialization succeeded.
769  *
770  *  The call to OggFLAC__stream_encoder_init_stream() currently will also immediately
771  *  call the write callback several times, once with the \c fLaC signature,
772  *  and once for each encoded metadata block.
773  *
774  * \note
775  * Unlike the FLAC stream encoder write callback, the Ogg stream
776  * encoder write callback will be called twice when writing each audio
777  * frame; once for the page header, and once for the page body.
778  * When writing the page header, the \a samples argument to the
779  * write callback will be \c 0.
780  *
781  * \param  encoder            An uninitialized encoder instance.
782  * \param  read_callback      See OggFLAC__StreamEncoderReadCallback.  This
783  *                            pointer must not be \c NULL if \a seek_callback
784  *                            is non-NULL since they are both needed to be
785  *                            able to write data back to the Ogg FLAC stream
786  *                            in the post-encode phase.
787  * \param  write_callback     See FLAC__StreamEncoderWriteCallback.  This
788  *                            pointer must not be \c NULL.
789  * \param  seek_callback      See FLAC__StreamEncoderSeekCallback.  This
790  *                            pointer may be \c NULL if seeking is not
791  *                            supported.  The encoder uses seeking to go back
792  *                            and write some some stream statistics to the
793  *                            STREAMINFO block; this is recommended but not
794  *                            necessary to create a valid FLAC stream.  If
795  *                            \a seek_callback is not \c NULL then a
796  *                            \a tell_callback must also be supplied.
797  *                            Alternatively, a dummy seek callback that just
798  *                            returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
799  *                            may also be supplied, all though this is slightly
800  *                            less efficient for the decoder.
801  * \param  tell_callback      See FLAC__StreamEncoderTellCallback.  This
802  *                            pointer may be \c NULL if seeking is not
803  *                            supported.  If \a seek_callback is \c NULL then
804  *                            this argument will be ignored.  If
805  *                            \a seek_callback is not \c NULL then a
806  *                            \a tell_callback must also be supplied.
807  *                            Alternatively, a dummy tell callback that just
808  *                            returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
809  *                            may also be supplied, all though this is slightly
810  *                            less efficient for the decoder.
811  * \param  metadata_callback  See FLAC__StreamEncoderMetadataCallback.  This
812  *                            pointer may be \c NULL if the callback is not
813  *                            desired.  If the client provides a seek callback,
814  *                            this function is not necessary as the encoder
815  *                            will automatically seek back and update the
816  *                            STREAMINFO block.  It may also be \c NULL if the
817  *                            client does not support seeking, since it will
818  *                            have no way of going back to update the
819  *                            STREAMINFO.  However the client can still supply
820  *                            a callback if it would like to know the details
821  *                            from the STREAMINFO.
822  * \param  client_data        This value will be supplied to callbacks in their
823  *                            \a client_data argument.
824  * \assert
825  *    \code encoder != NULL \endcode
826  * \retval FLAC__StreamEncoderInitStatus
827  *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
828  *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
829  */
830 OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_stream(OggFLAC__StreamEncoder *encoder, OggFLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
831
832 /** Initialize the encoder instance.
833  *
834  *  This flavor of initialization sets up the encoder to encode to a plain
835  *  file.  For non-stdio streams, you must use
836  *  OggFLAC__stream_encoder_init_stream() and provide callbacks for the I/O.
837  *
838  *  This function should be called after OggFLAC__stream_encoder_new() and
839  *  OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
840  *  or OggFLAC__stream_encoder_process_interleaved().
841  *  initialization succeeded.
842  *
843  *  The call to OggFLAC__stream_encoder_init_stream() currently will also immediately
844  *  call the write callback several times, once with the \c fLaC signature,
845  *  and once for each encoded metadata block.
846  *
847  * \note
848  * Unlike the FLAC stream encoder write callback, the Ogg stream
849  * encoder write callback will be called twice when writing each audio
850  * frame; once for the page header, and once for the page body.
851  * When writing the page header, the \a samples argument to the
852  * write callback will be \c 0.
853  *
854  * \param  encoder            An uninitialized encoder instance.
855  * \param  file               An open file.  The file should have been opened
856  *                            with mode \c "w+b" and rewound.  The file
857  *                            becomes owned by the encoder and should not be
858  *                            manipulated by the client while encoding.
859  *                            Unless \a file is \c stdout, it will be closed
860  *                            when OggFLAC__stream_encoder_finish() is called.
861  *                            Note however that a proper SEEKTABLE cannot be
862  *                            created when encoding to \c stdout since it is
863  *                            not seekable.
864  * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
865  *                            pointer may be \c NULL if the callback is not
866  *                            desired.
867  * \param  client_data        This value will be supplied to callbacks in their
868  *                            \a client_data argument.
869  * \assert
870  *    \code encoder != NULL \endcode
871  *    \code file != NULL \endcode
872  * \retval FLAC__StreamEncoderInitStatus
873  *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
874  *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
875  */
876 OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_FILE(OggFLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
877
878 /** Initialize the encoder instance.
879  *
880  *  This flavor of initialization sets up the encoder to encode to a plain
881  *  file.  If POSIX fopen() semantics are not sufficient (for example,
882  *  with Unicode filenames on Windows), you must use
883  *  OggFLAC__stream_encodeR_init_FILE(), or OggFLAC__stream_encoder_init_stream()
884  *  and provide callbacks for the I/O.
885  *
886  *  This function should be called after OggFLAC__stream_encoder_new() and
887  *  OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
888  *  or OggFLAC__stream_encoder_process_interleaved().
889  *  initialization succeeded.
890  *
891  *  The call to OggFLAC__stream_encoder_init_stream() currently will also immediately
892  *  call the write callback several times, once with the \c fLaC signature,
893  *  and once for each encoded metadata block.
894  *
895  * \note
896  * Unlike the FLAC stream encoder write callback, the Ogg stream
897  * encoder write callback will be called twice when writing each audio
898  * frame; once for the page header, and once for the page body.
899  * When writing the page header, the \a samples argument to the
900  * write callback will be \c 0.
901  *
902  * \param  encoder            An uninitialized encoder instance.
903  * \param  filename           The name of the file to encode to.  The file will
904  *                            be opened with fopen().  Use \c NULL to encode to
905  *                            \c stdout.  Note however that a proper SEEKTABLE
906  *                            cannot be created when encoding to \c stdout since
907  *                            it is not seekable.
908  * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
909  *                            pointer may be \c NULL if the callback is not
910  *                            desired.
911  * \param  client_data        This value will be supplied to callbacks in their
912  *                            \a client_data argument.
913  * \assert
914  *    \code encoder != NULL \endcode
915  * \retval FLAC__StreamEncoderInitStatus
916  *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
917  *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
918  */
919 OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_file(OggFLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
920
921 /** Finish the encoding process.
922  *  Flushes the encoding buffer, releases resources, resets the encoder
923  *  settings to their defaults, and returns the encoder state to
924  *  OggFLAC__STREAM_ENCODER_UNINITIALIZED.  Note that this can generate
925  *  one or more write callbacks before returning.
926  *
927  *  In the event of a prematurely-terminated encode, it is not strictly
928  *  necessary to call this immediately before OggFLAC__stream_encoder_delete()
929  *  but it is good practice to match every OggFLAC__stream_encoder_init()
930  *  with an OggFLAC__stream_encoder_finish().
931  *
932  * \param  encoder  An uninitialized encoder instance.
933  * \assert
934  *    \code encoder != NULL \endcode
935  */
936 OggFLAC_API void OggFLAC__stream_encoder_finish(OggFLAC__StreamEncoder *encoder);
937
938 /** Submit data for encoding.
939  * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process().
940  *
941  * \param  encoder  An initialized encoder instance in the OK state.
942  * \param  buffer   An array of pointers to each channel's signal.
943  * \param  samples  The number of samples in one channel.
944  * \assert
945  *    \code encoder != NULL \endcode
946  *    \code OggFLAC__stream_encoder_get_state(encoder) == OggFLAC__STREAM_ENCODER_OK \endcode
947  * \retval FLAC__bool
948  *    \c true if successful, else \c false; in this case, check the
949  *    encoder state with OggFLAC__stream_encoder_get_state() to see what
950  *    went wrong.
951  */
952 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process(OggFLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
953
954 /** Submit data for encoding.
955  * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process_interleaved().
956  *
957  * \param  encoder  An initialized encoder instance in the OK state.
958  * \param  buffer   An array of channel-interleaved data (see above).
959  * \param  samples  The number of samples in one channel, the same as for
960  *                  OggFLAC__stream_encoder_process().  For example, if
961  *                  encoding two channels, \c 1000 \a samples corresponds
962  *                  to a \a buffer of 2000 values.
963  * \assert
964  *    \code encoder != NULL \endcode
965  *    \code OggFLAC__stream_encoder_get_state(encoder) == OggFLAC__STREAM_ENCODER_OK \endcode
966  * \retval FLAC__bool
967  *    \c true if successful, else \c false; in this case, check the
968  *    encoder state with OggFLAC__stream_encoder_get_state() to see what
969  *    went wrong.
970  */
971 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process_interleaved(OggFLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
972
973 /* \} */
974
975 #ifdef __cplusplus
976 }
977 #endif
978
979 #endif