f317800efda5ca6e8fe8c565e5e6be7081e31400
[platform/upstream/flac.git] / include / OggFLAC / seekable_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__SEEKABLE_STREAM_ENCODER_H
33 #define OggFLAC__SEEKABLE_STREAM_ENCODER_H
34
35 #include "export.h"
36
37 #include "FLAC/stream_encoder.h"
38 #include "FLAC/seekable_stream_encoder.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44
45 /** \file include/OggFLAC/seekable_stream_encoder.h
46  *
47  *  \brief
48  *  This module contains the functions which implement the seekable
49  *  stream encoder.
50  *
51  *  See the detailed documentation in the
52  *  \link oggflac_seekable_stream_encoder seekable stream encoder \endlink module.
53  */
54
55 /** \defgroup oggflac_seekable_stream_encoder OggFLAC/seekable_stream_encoder.h: seekable stream encoder interface
56  *  \ingroup oggflac_encoder
57  *
58  *  \brief
59  *  This module contains the functions which implement the seekable
60  *  stream encoder.  The Ogg seekable stream encoder is derived
61  *  from the FLAC seekable stream encoder.
62  *
63  * The interface here is nearly identical to FLAC's seekable stream
64  * encoder, including the callbacks, with the addition of a new required
65  * read callback (needed when writing back STREAMINFO after encoding) and
66  * OggFLAC__seekable_stream_encoder_set_serial_number().  See the
67  * \link flac_seekable_stream_encoder FLAC seekable stream encoder module \endlink
68  * for full documentation.
69  *
70  * \{
71  */
72
73
74 /** State values for an OggFLAC__SeekableStreamEncoder
75  *
76  *  The encoder's state can be obtained by calling OggFLAC__stream_encoder_get_state().
77  */
78 typedef enum {
79
80         OggFLAC__SEEKABLE_STREAM_ENCODER_OK = 0,
81         /**< The encoder is in the normal OK state. */
82
83         OggFLAC__SEEKABLE_STREAM_ENCODER_OGG_ERROR,
84         /**< An error occurred in the underlying Ogg layer.  */
85
86         OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR,
87         /**< An error occurred in the underlying FLAC stream encoder;
88          * check OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state().
89          */
90
91         OggFLAC__SEEKABLE_STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
92         /**< Memory allocation failed. */
93
94         OggFLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR,
95         /**< The write callback returned an error. */
96
97         OggFLAC__SEEKABLE_STREAM_ENCODER_READ_ERROR,
98         /**< The read callback returned an error. */
99
100         OggFLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR,
101         /**< The seek callback returned an error. */
102
103         OggFLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR,
104         /**< The tell callback returned an error. */
105
106         OggFLAC__SEEKABLE_STREAM_ENCODER_ALREADY_INITIALIZED,
107         /**< OggFLAC__seekable_stream_encoder_init() was called when the encoder was
108          * already initialized, usually because
109          * OggFLAC__seekable_stream_encoder_finish() was not called.
110          */
111
112         OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_CALLBACK,
113         /**< OggFLAC__seekable_stream_encoder_init() was called without all
114          * callbacks being set.
115          */
116
117         OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_SEEKTABLE,
118         /**< An invalid seek table was passed is the metadata to
119          * OggFLAC__seekable_stream_encoder_set_metadata().
120          */
121
122         OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED
123         /**< The encoder is in the uninitialized state. */
124
125 } OggFLAC__SeekableStreamEncoderState;
126
127 /** Maps an OggFLAC__StreamEncoderState to a C string.
128  *
129  *  Using an OggFLAC__StreamEncoderState as the index to this array
130  *  will give the string equivalent.  The contents should not be modified.
131  */
132 extern OggFLAC_API const char * const OggFLAC__SeekableStreamEncoderStateString[];
133
134
135 /** Return values for the OggFLAC__SeekableStreamEncoder read callback.
136  */
137 typedef enum {
138
139         OggFLAC__SEEKABLE_STREAM_ENCODER_READ_STATUS_CONTINUE,
140         /**< The read was OK and decoding can continue. */
141
142         OggFLAC__SEEKABLE_STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
143         /**< The read was attempted at the end of the stream. */
144
145         OggFLAC__SEEKABLE_STREAM_ENCODER_READ_STATUS_ABORT
146         /**< An unrecoverable error occurred. */
147
148 } OggFLAC__SeekableStreamEncoderReadStatus;
149
150 /** Maps a OggFLAC__SeekableStreamEncoderReadStatus to a C string.
151  *
152  *  Using a OggFLAC__SeekableStreamEncoderReadStatus as the index to this array
153  *  will give the string equivalent.  The contents should not be modified.
154  */
155 extern OggFLAC_API const char * const OggFLAC__SeekableStreamEncoderReadStatusString[];
156
157
158 /***********************************************************************
159  *
160  * class OggFLAC__StreamEncoder
161  *
162  ***********************************************************************/
163
164 struct OggFLAC__SeekableStreamEncoderProtected;
165 struct OggFLAC__SeekableStreamEncoderPrivate;
166 /** The opaque structure definition for the seekable stream encoder type.
167  *  See the \link oggflac_seekable_stream_encoder seekable stream encoder module \endlink
168  *  for a detailed description.
169  */
170 typedef struct {
171         struct OggFLAC__SeekableStreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
172         struct OggFLAC__SeekableStreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
173 } OggFLAC__SeekableStreamEncoder;
174
175 /** Signature for the read callback.
176  *  See OggFLAC__seekable_stream_encoder_set_read_callback() for more info.
177  *
178  * \param  encoder  The encoder instance calling the callback.
179  * \param  buffer   A pointer to a location for the callee to store
180  *                  data to be encoded.
181  * \param  bytes    A pointer to the size of the buffer.  On entry
182  *                  to the callback, it contains the maximum number
183  *                  of bytes that may be stored in \a buffer.  The
184  *                  callee must set it to the actual number of bytes
185  *                  stored (0 in case of error or end-of-stream) before
186  *                  returning.
187  * \param  client_data  The callee's client data set through
188  *                      OggFLAC__seekable_stream_encoder_set_client_data().
189  * \retval OggFLAC__SeekableStreamEncoderReadStatus
190  *    The callee's return status.
191  */
192 typedef OggFLAC__SeekableStreamEncoderReadStatus (*OggFLAC__SeekableStreamEncoderReadCallback)(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
193
194 /** Signature for the seek callback.
195  *  See OggFLAC__seekable_stream_encoder_set_seek_callback()
196  *  and FLAC__SeekableStreamEncoderSeekCallback for more info.
197  *
198  * \param  encoder  The encoder instance calling the callback.
199  * \param  absolute_byte_offset  The offset from the beginning of the stream
200  *                               to seek to.
201  * \param  client_data  The callee's client data set through
202  *                      OggFLAC__seekable_stream_encoder_set_client_data().
203  * \retval FLAC__SeekableStreamEncoderSeekStatus
204  *    The callee's return status.
205  */
206 typedef FLAC__SeekableStreamEncoderSeekStatus (*OggFLAC__SeekableStreamEncoderSeekCallback)(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
207
208 /** Signature for the tell callback.
209  *  See OggFLAC__seekable_stream_encoder_set_tell_callback()
210  *  and FLAC__SeekableStreamEncoderTellCallback for more info.
211  *
212  * \param  encoder  The encoder instance calling the callback.
213  * \param  absolute_byte_offset  The address at which to store the current
214  *                               position of the output.
215  * \param  client_data  The callee's client data set through
216  *                      OggFLAC__seekable_stream_encoder_set_client_data().
217  * \retval FLAC__SeekableStreamEncoderTellStatus
218  *    The callee's return status.
219  */
220 typedef FLAC__SeekableStreamEncoderTellStatus (*OggFLAC__SeekableStreamEncoderTellCallback)(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
221
222 /** Signature for the write callback.
223  *  See OggFLAC__seekable_stream_encoder_set_write_callback()
224  *  and FLAC__SeekableStreamEncoderWriteCallback for more info.
225  *
226  * \param  encoder  The encoder instance calling the callback.
227  * \param  buffer   An array of encoded data of length \a bytes.
228  * \param  bytes    The byte length of \a buffer.
229  * \param  samples  The number of samples encoded by \a buffer.
230  *                  \c 0 has a special meaning; see
231  *                  OggFLAC__seekable_stream_encoder_set_write_callback().
232  * \param  current_frame  The number of current frame being encoded.
233  * \param  client_data  The callee's client data set through
234  *                      OggFLAC__seekable_stream_encoder_set_client_data().
235  * \retval FLAC__StreamEncoderWriteStatus
236  *    The callee's return status.
237  */
238 typedef FLAC__StreamEncoderWriteStatus (*OggFLAC__SeekableStreamEncoderWriteCallback)(const OggFLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
239
240
241 /***********************************************************************
242  *
243  * Class constructor/destructor
244  *
245  ***********************************************************************/
246
247 /** Create a new seekable stream encoder instance.  The instance is created with
248  *  default settings; see the individual OggFLAC__seekable_stream_encoder_set_*()
249  *  functions for each setting's default.
250  *
251  * \retval OggFLAC__SeekableStreamEncoder*
252  *    \c NULL if there was an error allocating memory, else the new instance.
253  */
254 OggFLAC_API OggFLAC__SeekableStreamEncoder *OggFLAC__seekable_stream_encoder_new();
255
256 /** Free an encoder instance.  Deletes the object pointed to by \a encoder.
257  *
258  * \param encoder  A pointer to an existing encoder.
259  * \assert
260  *    \code encoder != NULL \endcode
261  */
262 OggFLAC_API void OggFLAC__seekable_stream_encoder_delete(OggFLAC__SeekableStreamEncoder *encoder);
263
264
265 /***********************************************************************
266  *
267  * Public class method prototypes
268  *
269  ***********************************************************************/
270
271 /** Set the serial number for the FLAC stream.
272  *
273  * \default \c 0
274  * \param  encoder        An encoder instance to set.
275  * \param  serial_number  See above.
276  * \assert
277  *    \code encoder != NULL \endcode
278  * \retval FLAC__bool
279  *    \c false if the encoder is already initialized, else \c true.
280  */
281 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_serial_number(OggFLAC__SeekableStreamEncoder *encoder, long serial_number);
282
283 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_verify()
284  *
285  * \default \c false
286  * \param  encoder  An encoder instance to set.
287  * \param  value    Flag value (see above).
288  * \assert
289  *    \code encoder != NULL \endcode
290  * \retval FLAC__bool
291  *    \c false if the encoder is already initialized, else \c true.
292  */
293 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_verify(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
294
295 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_streamable_subset()
296  *
297  * \default \c true
298  * \param  encoder  An encoder instance to set.
299  * \param  value    Flag value (see above).
300  * \assert
301  *    \code encoder != NULL \endcode
302  * \retval FLAC__bool
303  *    \c false if the encoder is already initialized, else \c true.
304  */
305 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_streamable_subset(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
306
307 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_mid_side_stereo()
308  *
309  * \default \c false
310  * \param  encoder  An encoder instance to set.
311  * \param  value    Flag value (see above).
312  * \assert
313  *    \code encoder != NULL \endcode
314  * \retval FLAC__bool
315  *    \c false if the encoder is already initialized, else \c true.
316  */
317 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
318
319 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_loose_mid_side_stereo()
320  *
321  * \default \c false
322  * \param  encoder  An encoder instance to set.
323  * \param  value    Flag value (see above).
324  * \assert
325  *    \code encoder != NULL \endcode
326  * \retval FLAC__bool
327  *    \c false if the encoder is already initialized, else \c true.
328  */
329 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
330
331 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_channels()
332  *
333  * \default \c 2
334  * \param  encoder  An encoder instance to set.
335  * \param  value    See above.
336  * \assert
337  *    \code encoder != NULL \endcode
338  * \retval FLAC__bool
339  *    \c false if the encoder is already initialized, else \c true.
340  */
341 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_channels(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
342
343 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_bits_per_sample()
344  *
345  * \default \c 16
346  * \param  encoder  An encoder instance to set.
347  * \param  value    See above.
348  * \assert
349  *    \code encoder != NULL \endcode
350  * \retval FLAC__bool
351  *    \c false if the encoder is already initialized, else \c true.
352  */
353 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_bits_per_sample(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
354
355 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_sample_rate()
356  *
357  * \default \c 44100
358  * \param  encoder  An encoder instance to set.
359  * \param  value    See above.
360  * \assert
361  *    \code encoder != NULL \endcode
362  * \retval FLAC__bool
363  *    \c false if the encoder is already initialized, else \c true.
364  */
365 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_sample_rate(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
366
367 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_blocksize()
368  *
369  * \default \c 1152
370  * \param  encoder  An encoder instance to set.
371  * \param  value    See above.
372  * \assert
373  *    \code encoder != NULL \endcode
374  * \retval FLAC__bool
375  *    \c false if the encoder is already initialized, else \c true.
376  */
377 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_blocksize(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
378
379 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_apodization()
380  *
381  * \default \c 0
382  * \param  encoder        An encoder instance to set.
383  * \param  specification  See above.
384  * \assert
385  *    \code encoder != NULL \endcode
386  *    \code specification != NULL \endcode
387  * \retval FLAC__bool
388  *    \c false if the encoder is already initialized, else \c true.
389  */
390 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_apodization(OggFLAC__SeekableStreamEncoder *encoder, const char *specification);
391
392 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_lpc_order()
393  *
394  * \default \c 0
395  * \param  encoder  An encoder instance to set.
396  * \param  value    See above.
397  * \assert
398  *    \code encoder != NULL \endcode
399  * \retval FLAC__bool
400  *    \c false if the encoder is already initialized, else \c true.
401  */
402 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_lpc_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
403
404 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_precision()
405  *
406  * \default \c 0
407  * \param  encoder  An encoder instance to set.
408  * \param  value    See above.
409  * \assert
410  *    \code encoder != NULL \endcode
411  * \retval FLAC__bool
412  *    \c false if the encoder is already initialized, else \c true.
413  */
414 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
415
416 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_prec_search()
417  *
418  * \default \c false
419  * \param  encoder  An encoder instance to set.
420  * \param  value    See above.
421  * \assert
422  *    \code encoder != NULL \endcode
423  * \retval FLAC__bool
424  *    \c false if the encoder is already initialized, else \c true.
425  */
426 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
427
428 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_escape_coding()
429  *
430  * \default \c false
431  * \param  encoder  An encoder instance to set.
432  * \param  value    See above.
433  * \assert
434  *    \code encoder != NULL \endcode
435  * \retval FLAC__bool
436  *    \c false if the encoder is already initialized, else \c true.
437  */
438 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_escape_coding(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
439
440 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_exhaustive_model_search()
441  *
442  * \default \c false
443  * \param  encoder  An encoder instance to set.
444  * \param  value    See above.
445  * \assert
446  *    \code encoder != NULL \endcode
447  * \retval FLAC__bool
448  *    \c false if the encoder is already initialized, else \c true.
449  */
450 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value);
451
452 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_min_residual_partition_order()
453  *
454  * \default \c 0
455  * \param  encoder  An encoder instance to set.
456  * \param  value    See above.
457  * \assert
458  *    \code encoder != NULL \endcode
459  * \retval FLAC__bool
460  *    \c false if the encoder is already initialized, else \c true.
461  */
462 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_min_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
463
464 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_residual_partition_order()
465  *
466  * \default \c 0
467  * \param  encoder  An encoder instance to set.
468  * \param  value    See above.
469  * \assert
470  *    \code encoder != NULL \endcode
471  * \retval FLAC__bool
472  *    \c false if the encoder is already initialized, else \c true.
473  */
474 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_max_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
475
476 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_rice_parameter_search_dist()
477  *
478  * \default \c 0
479  * \param  encoder  An encoder instance to set.
480  * \param  value    See above.
481  * \assert
482  *    \code encoder != NULL \endcode
483  * \retval FLAC__bool
484  *    \c false if the encoder is already initialized, else \c true.
485  */
486 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist(OggFLAC__SeekableStreamEncoder *encoder, unsigned value);
487
488 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_total_samples_estimate()
489  *
490  * \default \c 0
491  * \param  encoder  An encoder instance to set.
492  * \param  value    See above.
493  * \assert
494  *    \code encoder != NULL \endcode
495  * \retval FLAC__bool
496  *    \c false if the encoder is already initialized, else \c true.
497  */
498 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_total_samples_estimate(OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 value);
499
500 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_metadata()
501  *
502  * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be
503  * the second metadata block of the stream.  The encoder already supplies
504  * the STREAMINFO block automatically.  If \a metadata does not contain a
505  * VORBIS_COMMENT block, the encoder will supply that too.  Otherwise, if
506  * \a metadata does contain a VORBIS_COMMENT block and it is not the
507  * first, this function will reorder \a metadata by moving the
508  * VORBIS_COMMENT block to the front; the relative ordering of the other
509  * blocks will remain as they were.
510  *
511  * \note The Ogg FLAC mapping limits the number of metadata blocks per
512  * stream to \c 65535.  If \a num_blocks exceeds this the function will
513  * return \c false.
514  *
515  * \default \c NULL, 0
516  * \param  encoder     An encoder instance to set.
517  * \param  metadata    See above.
518  * \param  num_blocks  See above.
519  * \assert
520  *    \code encoder != NULL \endcode
521  * \retval FLAC__bool
522  *    \c false if the encoder is already initialized, or if
523  *    \a num_blocks > 65535, else \c true.
524  */
525 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_metadata(OggFLAC__SeekableStreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
526
527 /** Set the read callback.
528  *  The supplied function will be called when the encoder needs to read back
529  *  encoded data.  This happens during the metadata callback, when the encoder
530  *  has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered
531  *  while encoding.  The address of the buffer to be filled is supplied, along
532  *  with the number of bytes the buffer can hold.  The callback may choose to
533  *  supply less data and modify the byte count but must be careful not to
534  *  overflow the buffer.  The callback then returns a status code chosen from
535  *  OggFLAC__SeekableStreamEncoderReadStatus.
536  *
537  * \note
538  * The callback is mandatory and must be set before initialization.
539  *
540  * \default \c NULL
541  * \param  encoder  A encoder instance to set.
542  * \param  value    See above.
543  * \assert
544  *    \code encoder != NULL \endcode
545  *    \code value != NULL \endcode
546  * \retval FLAC__bool
547  *    \c false if the encoder is already initialized, else \c true.
548  */
549 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_read_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderReadCallback value);
550
551 /** Set the seek callback.
552  *  The supplied function will be called when the encoder needs to seek
553  *  the output stream.  The encoder will pass the absolute byte offset
554  *  to seek to, 0 meaning the beginning of the stream.
555  *
556  * \note
557  * The callback is mandatory and must be set before initialization.
558  *
559  * \default \c NULL
560  * \param  encoder  An encoder instance to set.
561  * \param  value    See above.
562  * \assert
563  *    \code encoder != NULL \endcode
564  *    \code value != NULL \endcode
565  * \retval FLAC__bool
566  *    \c false if the encoder is already initialized, else \c true.
567  */
568 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_seek_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderSeekCallback value);
569
570 /** Set the tell callback.
571  *  The supplied function will be called when the encoder needs to know
572  *  the current position of the output stream.
573  *
574  * \note
575  * The callback is mandatory and must be set before initialization.
576  *
577  * \default \c NULL
578  * \param  encoder  An encoder instance to set.
579  * \param  value    See above.
580  * \assert
581  *    \code encoder != NULL \endcode
582  *    \code value != NULL \endcode
583  * \retval FLAC__bool
584  *    \c false if the encoder is already initialized, else \c true.
585  */
586 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_tell_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderTellCallback value);
587
588 /** Set the write callback.
589  *  This is inherited from FLAC__StreamEncoder; see
590  *  FLAC__stream_encoder_set_write_callback().
591  *
592  * \note
593  * Unlike the FLAC seekable stream encoder write callback, the Ogg
594  * seekable stream encoder write callback will be called twice when
595  * writing audio frames; once for the page header, and once for the page
596  * body.  When writing the page header, the \a samples argument to the
597  * write callback will be \c 0.
598  *
599  * \note
600  * The callback is mandatory and must be set before initialization.
601  *
602  * \default \c NULL
603  * \param  encoder  An encoder instance to set.
604  * \param  value    See above.
605  * \assert
606  *    \code encoder != NULL \endcode
607  *    \code value != NULL \endcode
608  * \retval FLAC__bool
609  *    \c false if the encoder is already initialized, else \c true.
610  */
611 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_write_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderWriteCallback value);
612
613 /** Set the client data to be passed back to callbacks.
614  *  This value will be supplied to callbacks in their \a client_data
615  *  argument.
616  *
617  * \default \c NULL
618  * \param  encoder  An encoder instance to set.
619  * \param  value    See above.
620  * \assert
621  *    \code encoder != NULL \endcode
622  * \retval FLAC__bool
623  *    \c false if the encoder is already initialized, else \c true.
624  */
625 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_set_client_data(OggFLAC__SeekableStreamEncoder *encoder, void *value);
626
627 /** Get the current encoder state.
628  *
629  * \param  encoder  An encoder instance to query.
630  * \assert
631  *    \code encoder != NULL \endcode
632  * \retval OggFLAC__SeekableStreamEncoderState
633  *    The current encoder state.
634  */
635 OggFLAC_API OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_get_state(const OggFLAC__SeekableStreamEncoder *encoder);
636
637 /** Get the state of the underlying FLAC stream encoder.
638  *  Useful when the seekable stream encoder state is
639  *  \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR.
640  *
641  * \param  encoder  An encoder instance to query.
642  * \assert
643  *    \code encoder != NULL \endcode
644  * \retval FLAC__StreamEncoderState
645  *    The FLAC stream encoder state.
646  */
647 OggFLAC_API FLAC__StreamEncoderState OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state(const OggFLAC__SeekableStreamEncoder *encoder);
648
649 /** Get the state of the underlying FLAC encoder's verify decoder.
650  *  Useful when the seekable stream encoder state is
651  *  \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR
652  *  and the FLAC stream encoder state is
653  *  \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
654  *
655  * \param  encoder  An encoder instance to query.
656  * \assert
657  *    \code encoder != NULL \endcode
658  * \retval FLAC__StreamDecoderState
659  *    The FLAC verify decoder state.
660  */
661 OggFLAC_API FLAC__StreamDecoderState OggFLAC__seekable_stream_encoder_get_verify_decoder_state(const OggFLAC__SeekableStreamEncoder *encoder);
662
663 /** Get the current encoder state as a C string.
664  *  This version automatically resolves
665  *  \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR
666  *  by getting the FLAC stream encoder's resolved state.
667  *
668  * \param  encoder  A encoder instance to query.
669  * \assert
670  *    \code encoder != NULL \endcode
671  * \retval const char *
672  *    The encoder state as a C string.  Do not modify the contents.
673  */
674 OggFLAC_API const char *OggFLAC__seekable_stream_encoder_get_resolved_state_string(const OggFLAC__SeekableStreamEncoder *encoder);
675
676 /** Get relevant values about the nature of a verify decoder error.
677  *  Inherited from FLAC__stream_encoder_get_verify_decoder_error_stats().
678  *  Useful when the seekable stream encoder state is
679  *  \c OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR
680  *  and the FLAC stream encoder state is
681  *  \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
682  *
683  * \param  encoder  An encoder instance to query.
684  * \param  absolute_sample  The absolute sample number of the mismatch.
685  * \param  frame_number  The number of the frame in which the mismatch occurred.
686  * \param  channel       The channel in which the mismatch occurred.
687  * \param  sample        The number of the sample (relative to the frame) in
688  *                       which the mismatch occurred.
689  * \param  expected      The expected value for the sample in question.
690  * \param  got           The actual value returned by the decoder.
691  * \assert
692  *    \code encoder != NULL \endcode
693  *    \code absolute_sample != NULL \endcode
694  *    \code frame_number != NULL \endcode
695  *    \code channel != NULL \endcode
696  *    \code sample != NULL \endcode
697  *    \code expected != NULL \endcode
698  */
699 OggFLAC_API void OggFLAC__seekable_stream_encoder_get_verify_decoder_error_stats(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
700
701 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_verify()
702  *
703  * \param  encoder  An encoder instance to query.
704  * \assert
705  *    \code encoder != NULL \endcode
706  * \retval FLAC__bool
707  *    See OggFLAC__seekable_stream_encoder_set_verify().
708  */
709 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_verify(const OggFLAC__SeekableStreamEncoder *encoder);
710
711 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_streamable_subset()
712  *
713  * \param  encoder  An encoder instance to query.
714  * \assert
715  *    \code encoder != NULL \endcode
716  * \retval FLAC__bool
717  *    See OggFLAC__seekable_stream_encoder_set_streamable_subset().
718  */
719 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_streamable_subset(const OggFLAC__SeekableStreamEncoder *encoder);
720
721 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_mid_side_stereo()
722  *
723  * \param  encoder  An encoder instance to query.
724  * \assert
725  *    \code encoder != NULL \endcode
726  * \retval FLAC__bool
727  *    See OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo().
728  */
729 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder);
730
731 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_loose_mid_side_stereo()
732  *
733  * \param  encoder  An encoder instance to query.
734  * \assert
735  *    \code encoder != NULL \endcode
736  * \retval FLAC__bool
737  *    See OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo().
738  */
739 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_loose_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder);
740
741 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_channels()
742  *
743  * \param  encoder  An encoder instance to query.
744  * \assert
745  *    \code encoder != NULL \endcode
746  * \retval unsigned
747  *    See OggFLAC__seekable_stream_encoder_set_channels().
748  */
749 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_channels(const OggFLAC__SeekableStreamEncoder *encoder);
750
751 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_bits_per_sample()
752  *
753  * \param  encoder  An encoder instance to query.
754  * \assert
755  *    \code encoder != NULL \endcode
756  * \retval unsigned
757  *    See OggFLAC__seekable_stream_encoder_set_bits_per_sample().
758  */
759 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_bits_per_sample(const OggFLAC__SeekableStreamEncoder *encoder);
760
761 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_sample_rate()
762  *
763  * \param  encoder  An encoder instance to query.
764  * \assert
765  *    \code encoder != NULL \endcode
766  * \retval unsigned
767  *    See OggFLAC__seekable_stream_encoder_set_sample_rate().
768  */
769 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_sample_rate(const OggFLAC__SeekableStreamEncoder *encoder);
770
771 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_blocksize()
772  *
773  * \param  encoder  An encoder instance to query.
774  * \assert
775  *    \code encoder != NULL \endcode
776  * \retval unsigned
777  *    See OggFLAC__seekable_stream_encoder_set_blocksize().
778  */
779 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_blocksize(const OggFLAC__SeekableStreamEncoder *encoder);
780
781 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_max_lpc_order()
782  *
783  * \param  encoder  An encoder instance to query.
784  * \assert
785  *    \code encoder != NULL \endcode
786  * \retval unsigned
787  *    See OggFLAC__seekable_stream_encoder_set_max_lpc_order().
788  */
789 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_lpc_order(const OggFLAC__SeekableStreamEncoder *encoder);
790
791 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_qlp_coeff_precision()
792  *
793  * \param  encoder  An encoder instance to query.
794  * \assert
795  *    \code encoder != NULL \endcode
796  * \retval unsigned
797  *    See OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision().
798  */
799 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(const OggFLAC__SeekableStreamEncoder *encoder);
800
801 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
802  *
803  * \param  encoder  An encoder instance to query.
804  * \assert
805  *    \code encoder != NULL \endcode
806  * \retval FLAC__bool
807  *    See OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search().
808  */
809 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__SeekableStreamEncoder *encoder);
810
811 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_escape_coding()
812  *
813  * \param  encoder  An encoder instance to query.
814  * \assert
815  *    \code encoder != NULL \endcode
816  * \retval FLAC__bool
817  *    See OggFLAC__seekable_stream_encoder_set_do_escape_coding().
818  */
819 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_escape_coding(const OggFLAC__SeekableStreamEncoder *encoder);
820
821 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_exhaustive_model_search()
822  *
823  * \param  encoder  An encoder instance to query.
824  * \assert
825  *    \code encoder != NULL \endcode
826  * \retval FLAC__bool
827  *    See OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search().
828  */
829 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_search(const OggFLAC__SeekableStreamEncoder *encoder);
830
831 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_min_residual_partition_order()
832  *
833  * \param  encoder  An encoder instance to query.
834  * \assert
835  *    \code encoder != NULL \endcode
836  * \retval unsigned
837  *    See OggFLAC__seekable_stream_encoder_set_min_residual_partition_order().
838  */
839 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_min_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder);
840
841 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_man_residual_partition_order()
842  *
843  * \param  encoder  An encoder instance to query.
844  * \assert
845  *    \code encoder != NULL \endcode
846  * \retval unsigned
847  *    See OggFLAC__seekable_stream_encoder_set_max_residual_partition_order().
848  */
849 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_max_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder);
850
851 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_rice_parameter_search_dist()
852  *
853  * \param  encoder  An encoder instance to query.
854  * \assert
855  *    \code encoder != NULL \endcode
856  * \retval unsigned
857  *    See OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist().
858  */
859 OggFLAC_API unsigned OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist(const OggFLAC__SeekableStreamEncoder *encoder);
860
861 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_total_samples_estimate()
862  *
863  * \param  encoder  An encoder instance to set.
864  * \assert
865  *    \code encoder != NULL \endcode
866  * \retval FLAC__uint64
867  *    See OggFLAC__seekable_stream_encoder_get_total_samples_estimate().
868  */
869 OggFLAC_API FLAC__uint64 OggFLAC__seekable_stream_encoder_get_total_samples_estimate(const OggFLAC__SeekableStreamEncoder *encoder);
870
871 /** Initialize the encoder instance.
872  *  Should be called after OggFLAC__seekable_stream_encoder_new() and
873  *  OggFLAC__seekable_stream_encoder_set_*() but before OggFLAC__seekable_stream_encoder_process()
874  *  or OggFLAC__seekable_stream_encoder_process_interleaved().  Will set and return
875  *  the encoder state, which will be OggFLAC__SEEKABLE_STREAM_ENCODER_OK if
876  *  initialization succeeded.
877  *
878  *  The call to OggFLAC__seekable_stream_encoder_init() currently will also immediately
879  *  call the write callback several times, once with the \c fLaC signature,
880  *  and once for each encoded metadata block.
881  *
882  * \param  encoder  An uninitialized encoder instance.
883  * \assert
884  *    \code encoder != NULL \endcode
885  * \retval OggFLAC__SeekableStreamEncoderState
886  *    \c OggFLAC__SEEKABLE_STREAM_ENCODER_OK if initialization was successful; see
887  *    OggFLAC__SeekableStreamEncoderState for the meanings of other return values.
888  */
889 OggFLAC_API OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_init(OggFLAC__SeekableStreamEncoder *encoder);
890
891 /** Finish the encoding process.
892  *  Flushes the encoding buffer, releases resources, resets the encoder
893  *  settings to their defaults, and returns the encoder state to
894  *  OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED.  Note that this can generate
895  *  one or more write callbacks before returning.
896  *
897  *  In the event of a prematurely-terminated encode, it is not strictly
898  *  necessary to call this immediately before OggFLAC__seekable_stream_encoder_delete()
899  *  but it is good practice to match every OggFLAC__seekable_stream_encoder_init()
900  *  with an OggFLAC__seekable_stream_encoder_finish().
901  *
902  * \param  encoder  An uninitialized encoder instance.
903  * \assert
904  *    \code encoder != NULL \endcode
905  */
906 OggFLAC_API void OggFLAC__seekable_stream_encoder_finish(OggFLAC__SeekableStreamEncoder *encoder);
907
908 /** Submit data for encoding.
909  * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process().
910  *
911  * \param  encoder  An initialized encoder instance in the OK state.
912  * \param  buffer   An array of pointers to each channel's signal.
913  * \param  samples  The number of samples in one channel.
914  * \assert
915  *    \code encoder != NULL \endcode
916  *    \code OggFLAC__seekable_stream_encoder_get_state(encoder) == OggFLAC__SEEKABLE_STREAM_ENCODER_OK \endcode
917  * \retval FLAC__bool
918  *    \c true if successful, else \c false; in this case, check the
919  *    encoder state with OggFLAC__seekable_stream_encoder_get_state() to see what
920  *    went wrong.
921  */
922 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process(OggFLAC__SeekableStreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
923
924 /** Submit data for encoding.
925  * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process_interleaved().
926  *
927  * \param  encoder  An initialized encoder instance in the OK state.
928  * \param  buffer   An array of channel-interleaved data (see above).
929  * \param  samples  The number of samples in one channel, the same as for
930  *                  OggFLAC__seekable_stream_encoder_process().  For example, if
931  *                  encoding two channels, \c 1000 \a samples corresponds
932  *                  to a \a buffer of 2000 values.
933  * \assert
934  *    \code encoder != NULL \endcode
935  *    \code OggFLAC__seekable_stream_encoder_get_state(encoder) == OggFLAC__SEEKABLE_STREAM_ENCODER_OK \endcode
936  * \retval FLAC__bool
937  *    \c true if successful, else \c false; in this case, check the
938  *    encoder state with OggFLAC__seekable_stream_encoder_get_state() to see what
939  *    went wrong.
940  */
941 OggFLAC_API FLAC__bool OggFLAC__seekable_stream_encoder_process_interleaved(OggFLAC__SeekableStreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
942
943 /* \} */
944
945 #ifdef __cplusplus
946 }
947 #endif
948
949 #endif