tweaks to build libs as DLLs under windows
[platform/upstream/flac.git] / include / FLAC / metadata.h
1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2001,2002  Josh Coalson
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA  02111-1307, USA.
18  */
19
20 #ifndef FLAC__METADATA_H
21 #define FLAC__METADATA_H
22
23 #include "export.h"
24 #include "format.h"
25
26 /******************************************************************************
27         (For an example of how all these routines are used, see the source
28         code for the unit tests in src/test_libFLAC/metadata_*.c, or metaflac
29         in src/metaflac/)
30 ******************************************************************************/
31
32 /** \file include/FLAC/metadata.h
33  *
34  *  \brief
35  *  This module provides functions for creating and manipulating FLAC
36  *  metadata blocks in memory, and three progressively more powerful
37  *  interfaces for traversing and editing metadata in FLAC files.
38  *
39  *  See the detailed documentation for each interface in the
40  *  \link flac_metadata metadata \endlink module.
41  */
42
43 /** \defgroup flac_metadata FLAC/metadata.h: metadata interfaces
44  *  \ingroup flac
45  *
46  *  \brief
47  *  This module provides functions for creating and manipulating FLAC
48  *  metadata blocks in memory, and three progressively more powerful
49  *  interfaces for traversing and editing metadata in FLAC files.
50  *
51  *  There are three metadata interfaces of increasing complexity:
52  *
53  *  Level 0:
54  *  Read-only access to the STREAMINFO block.
55  *
56  *  Level 1:
57  *  Read-write access to all metadata blocks.  This level is write-
58  *  efficient in most cases (more on this below), and uses less memory
59  *  than level 2.
60  *
61  *  Level 2:
62  *  Read-write access to all metadata blocks.  This level is write-
63  *  efficient in all cases, but uses more memory since all metadata for
64  *  the whole file is read into memory and manipulated before writing
65  *  out again.
66  *
67  *  What do we mean by efficient?  When writing metadata back to a FLAC
68  *  file it is possible to grow or shrink the metadata such that the entire
69  *  file must be rewritten.  However, if the size remains the same during
70  *  changes or PADDING blocks are utilized, only the metadata needs to be
71  *  overwritten, which is much faster.
72  *
73  *  Efficient means the whole file is rewritten at most one time, and only
74  *  when necessary.  Level 1 is not efficient only in the case that you
75  *  cause more than one metadata block to grow or shrink beyond what can
76  *  be accomodated by padding.  In this case you should probably use level
77  *  2, which allows you to edit all the metadata for a file in memory and
78  *  write it out all at once.
79  *
80  *  All levels know how to skip over and not disturb an ID3v2 tag at the
81  *  front of the file.
82  *
83  *  In addition to the three interfaces, this module defines functions for
84  *  creating and manipulating various metadata objects in memory.  As we see
85  *  from the Format module, FLAC metadata blocks in memory are very primitive
86  *  structures for storing information in an efficient way.  Reading
87  *  information from the structures is easy but creating or modifying them
88  *  directly is more complex.  The metadata object routines here facilitate
89  *  this by taking care of the consistency and memory management drudgery.
90  *
91  *  Unless you will be using the level 1 or 2 interfaces to modify existing
92  *  metadata however, you will not probably not need these.
93  *
94  *  From a dependency standpoint, none of the encoders or decoders require
95  *  the metadata module.  This is so that embedded users can strip out the
96  *  metadata module from libFLAC to reduce the size and complexity.
97  */
98
99 #ifdef __cplusplus
100 extern "C" {
101 #endif
102
103
104 /** \defgroup flac_metadata_level0 FLAC/metadata.h: metadata level 0 interface
105  *  \ingroup flac_metadata
106  *
107  *  \brief
108  *  The level 0 interface consists of a single routine to read the
109  *  STREAMINFO block.
110  *
111  *  It skips any ID3v2 tag at the head of the file.
112  *
113  * \{
114  */
115
116 /** Read the STREAMINFO metadata block of the given FLAC file.  This function
117  *  will skip any ID3v2 tag at the head of the file.
118  *
119  * \param filename    The path to the FLAC file to read.
120  * \param streaminfo  A pointer to space for the STREAMINFO block.
121  * \assert
122  *    \code filename != NULL \endcode
123  *    \code streaminfo != NULL \endcode
124  * \retval FLAC__bool
125  *    \c true if a valid STREAMINFO block was read from \a filename.  Returns
126  *    \c false if there was a memory allocation error, a file decoder error,
127  *    or the file contained no STREAMINFO block.
128  */
129 FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
130
131 /* \} */
132
133
134 /** \defgroup flac_metadata_level1 FLAC/metadata.h: metadata level 1 interface
135  *  \ingroup flac_metadata
136  *
137  * \brief
138  * The level 1 interface provides read-write access to FLAC file metadata and
139  * operates directly on the FLAC file.
140  *
141  * The general usage of this interface is:
142  *
143  * - Create an iterator using FLAC__metadata_simple_iterator_new()
144  * - Attach it to a file using FLAC__metadata_simple_iterator_init() and check
145  *   the exit code.  Call FLAC__metadata_simple_iterator_is_writable() to
146  *   see if the file is writable, or read-only access is allowed.
147  * - Use FLAC__metadata_simple_iterator_next() and
148  *   FLAC__metadata_simple_iterator_prev() to move around the blocks.
149  *   This is does not read the actual blocks themselves.
150  *   FLAC__metadata_simple_iterator_next() is relatively fast.
151  *   FLAC__metadata_simple_iterator_prev() is slower since it needs to search
152  *   forward from the front of the file.
153  * - Use FLAC__metadata_simple_iterator_get_block_type() or
154  *   FLAC__metadata_simple_iterator_get_block() to access the actual data at
155  *   the current iterator position.  The returned object is yours to modify
156  *   and free.
157  * - Use FLAC__metadata_simple_iterator_set_block() to write a modified block
158  *   back.  You must have write permission to the original file.  Make sure to
159  *   read the whole comment to FLAC__metadata_simple_iterator_set_block()
160  *   below.
161  * - Use FLAC__metadata_simple_iterator_insert_block_after() to add new blocks.
162  *   Use the object creation functions from
163  *   \link flac_metadata_object here \endlink to generate new objects.
164  * - Use FLAC__metadata_simple_iterator_delete_block() to remove the block
165  *   currently referred to by the iterator, or replace it with padding.
166  * - Destroy the iterator with FLAC__metadata_simple_iterator_delete() when
167  *   finished.
168  *
169  * \note
170  * The FLAC file remains open the whole time between
171  * FLAC__metadata_simple_iterator_init() and
172  * FLAC__metadata_simple_iterator_delete(), so make sure you are not altering
173  * the file during this time.
174  *
175  * \note
176  * Do not modify the \a is_last, \a length, or \a type fields of returned
177  * FLAC__MetadataType objects.  These are managed automatically.
178  *
179  * \note
180  * If any of the modification functions
181  * (FLAC__metadata_simple_iterator_set_block(),
182  * FLAC__metadata_simple_iterator_delete_block(),
183  * FLAC__metadata_simple_iterator_insert_block_after(), etc.) return \c false,
184  * you should delete the iterator as it may no longer be valid.
185  *
186  * \{
187  */
188
189 struct FLAC__Metadata_SimpleIterator;
190 /** The opaque structure definition for the level 1 iterator type.
191  *  See the
192  *  \link flac_metadata_level1 metadata level 1 module \endlink
193  *  for a detailed description.
194  */
195 typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
196
197 /** Status type for FLAC__Metadata_SimpleIterator.
198  *
199  *  The iterator's current status can be obtained by calling FLAC__metadata_simple_iterator_status().
200  */
201 typedef enum {
202
203         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
204         /**< The iterator is in the normal OK state */
205
206         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
207         /**< The data passed into a function violated the function's usage criteria */
208
209         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
210         /**< The iterator could not open the target file */
211
212         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
213         /**< The iterator could not find the FLAC signature at the start of the file */
214
215         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
216         /**< The iterator tried to write to a file that was not writable */
217
218         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
219         /**< The iterator encountered input that does not conform to the FLAC metadata specification */
220
221         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
222         /**< The iterator encountered an error while reading the FLAC file */
223
224         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
225         /**< The iterator encountered an error while seeking in the FLAC file */
226
227         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
228         /**< The iterator encountered an error while writing the FLAC file */
229
230         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
231         /**< The iterator encountered an error renaming the FLAC file */
232
233         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
234         /**< The iterator encountered an error removing the temporary file */
235
236         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
237         /**< Memory allocation failed */
238
239         FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
240         /**< The caller violated an assertion or an unexpected error occurred */
241
242 } FLAC__Metadata_SimpleIteratorStatus;
243
244 /** Maps a FLAC__Metadata_SimpleIteratorStatus to a C string.
245  *
246  *  Using a FLAC__Metadata_SimpleIteratorStatus as the index to this array
247  *  will give the string equivalent.  The contents should not be modified.
248  */
249 extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
250
251
252 /** Create a new iterator instance.
253  *
254  * \retval FLAC__Metadata_SimpleIterator*
255  *    \c NULL if there was an error allocating memory, else the new instance.
256  */
257 FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new();
258
259 /** Free an iterator instance.  Deletes the object pointed to by \a iterator.
260  *
261  * \param iterator  A pointer to an existing iterator.
262  * \assert
263  *    \code iterator != NULL \endcode
264  */
265 FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
266
267 /** Get the current status of the iterator.  Call this after a function
268  *  returns \c false to get the reason for the error.  Also resets the status
269  *  to FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK.
270  *
271  * \param iterator  A pointer to an existing iterator.
272  * \assert
273  *    \code iterator != NULL \endcode
274  * \retval FLAC__Metadata_SimpleIteratorStatus
275  *    The current status of the iterator.
276  */
277 FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
278
279 /** Initialize the iterator to point to the first metadata block in the
280  *  given FLAC file.
281  *
282  * \param iterator             A pointer to an existing iterator.
283  * \param filename             The path to the FLAC file.
284  * \param read_only            If \c true, the FLAC file will be opened
285  *                             in read-only mode; if \c false, the FLAC
286  *                             file will be opened for edit even if no
287  *                             edits are performed.
288  * \param preserve_file_stats  If \c true, the owner and modification
289  *                             time will be preserved even if the FLAC
290  *                             file is written to.
291  * \assert
292  *    \code iterator != NULL \endcode
293  *    \code filename != NULL \endcode
294  * \retval FLAC__bool
295  *    \c false if a memory allocation error occurs, the file can't be
296  *    opened, or another error occurs, else \c true.
297  */
298 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats);
299
300 /** Returns \c true if the FLAC file is writable.  If \c false, calls to
301  *  FLAC__metadata_simple_iterator_set_block() and
302  *  FLAC__metadata_simple_iterator_insert_block_after() will fail.
303  *
304  * \param iterator             A pointer to an existing iterator.
305  * \assert
306  *    \code iterator != NULL \endcode
307  * \retval FLAC__bool
308  *    See above.
309  */
310 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
311
312 /** Moves the iterator forward one metadata block, returning \c false if
313  *  already at the end.
314  *
315  * \param iterator  A pointer to an existing initialized iterator.
316  * \assert
317  *    \code iterator != NULL \endcode
318  *    \a iterator has been successfully initialized with
319  *    FLAC__metadata_simple_iterator_init()
320  * \retval FLAC__bool
321  *    \c false if already at the last metadata block of the chain, else
322  *    \c true.
323  */
324 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
325
326 /** Moves the iterator backward one metadata block, returning \c false if
327  *  already at the beginning.
328  *
329  * \param iterator  A pointer to an existing initialized iterator.
330  * \assert
331  *    \code iterator != NULL \endcode
332  *    \a iterator has been successfully initialized with
333  *    FLAC__metadata_simple_iterator_init()
334  * \retval FLAC__bool
335  *    \c false if already at the first metadata block of the chain, else
336  *    \c true.
337  */
338 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
339
340 /** Get the type of the metadata block at the current position.  This
341  *  avoids reading the actual block data which can save time for large
342  *  blocks.
343  *
344  * \param iterator  A pointer to an existing initialized iterator.
345  * \assert
346  *    \code iterator != NULL \endcode
347  *    \a iterator has been successfully initialized with
348  *    FLAC__metadata_simple_iterator_init()
349  * \retval FLAC__MetadataType
350  *    The type of the metadata block at the current iterator position.
351  */
352
353 FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
354
355 /** Get the metadata block at the current position.  You can modify the
356  *  block but must use FLAC__metadata_simple_iterator_set_block() to
357  *  write it back to the FLAC file.
358  *
359  *  You must call FLAC__metadata_object_delete() on the returned object
360  *  when you are finished with it.
361  *
362  * \param iterator  A pointer to an existing initialized iterator.
363  * \assert
364  *    \code iterator != NULL \endcode
365  *    \a iterator has been successfully initialized with
366  *    FLAC__metadata_simple_iterator_init()
367  * \retval FLAC__StreamMetadata*
368  *    The current metadata block.
369  */
370 FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
371
372 /** Write a block back to the FLAC file.  This function tries to be
373  *  as efficient as possible; how the block is actually written is
374  *  shown by the following:
375  *
376  *  Existing block is a STREAMINFO block and the new block is a
377  *  STREAMINFO block: the new block is written in place.  Make sure
378  *  you know what you're doing when changing the values of a
379  *  STREAMINFO block.
380  *
381  *  Existing block is a STREAMINFO block and the new block is a
382  *  not a STREAMINFO block: this is an error since the first block
383  *  must be a STREAMINFO block.  Returns \c false without altering the
384  *  file.
385  *
386  *  Existing block is not a STREAMINFO block and the new block is a
387  *  STREAMINFO block: this is an error since there may be only one
388  *  STREAMINFO block.  Returns \c false without altering the file.
389  *
390  *  Existing block and new block are the same length: the existing
391  *  block will be replaced by the new block, written in place.
392  *
393  *  Existing block is longer than new block: if use_padding is \c true,
394  *  the existing block will be overwritten in place with the new
395  *  block followed by a PADDING block, if possible, to make the total
396  *  size the same as the existing block.  Remember that a padding
397  *  block requires at least four bytes so if the difference in size
398  *  between the new block and existing block is less than that, the
399  *  entire file will have to be rewritten, using the new block's
400  *  exact size.  If use_padding is \c false, the entire file will be
401  *  rewritten, replacing the existing block by the new block.
402  *
403  *  Existing block is shorter than new block: if use_padding is \c true,
404  *  the function will try and expand the new block into the following
405  *  PADDING block, if it exists and doing so won't shrink the PADDING
406  *  block to less than 4 bytes.  If there is no following PADDING
407  *  block, or it will shrink to less than 4 bytes, or use_padding is
408  *  \c false, the entire file is rewritten, replacing the existing block
409  *  with the new block.  Note that in this case any following PADDING
410  *  block is preserved as is.
411  *
412  *  After writing the block, the iterator will remain in the same
413  *  place, i.e. pointing to the new block.
414  *
415  * \param iterator     A pointer to an existing initialized iterator.
416  * \param block        The block to set.
417  * \param use_padding  See above.
418  * \assert
419  *    \code iterator != NULL \endcode
420  *    \a iterator has been successfully initialized with
421  *    FLAC__metadata_simple_iterator_init()
422  *    \code block != NULL \endcode
423  * \retval FLAC__bool
424  *    \c true if successful, else \c false.
425  */
426 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
427
428 /** This is similar to FLAC__metadata_simple_iterator_set_block()
429  *  except that instead of writing over an existing block, it appends
430  *  a block after the existing block.  \a use_padding is again used to
431  *  tell the function to try an expand into following padding in an
432  *  attempt to avoid rewriting the entire file.
433  *
434  *  This function will fail and return \c false if given a STREAMINFO
435  *  block.
436  *
437  *  After writing the block, the iterator will be pointing to the
438  *  new block.
439  *
440  * \param iterator     A pointer to an existing initialized iterator.
441  * \param block        The block to set.
442  * \param use_padding  See above.
443  * \assert
444  *    \code iterator != NULL \endcode
445  *    \a iterator has been successfully initialized with
446  *    FLAC__metadata_simple_iterator_init()
447  *    \code block != NULL \endcode
448  * \retval FLAC__bool
449  *    \c true if successful, else \c false.
450  */
451 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
452
453 /** Deletes the block at the current position.  This will cause the
454  *  entire FLAC file to be rewritten, unless \a use_padding is \c true,
455  *  in which case the block will be replaced by an equal-sized PADDING
456  *  block.  The iterator will be left pointing to the block before the
457  *  one just deleted.
458  *
459  *  You may not delete the STREAMINFO block.
460  *
461  * \param iterator     A pointer to an existing initialized iterator.
462  * \param use_padding  See above.
463  * \assert
464  *    \code iterator != NULL \endcode
465  *    \a iterator has been successfully initialized with
466  *    FLAC__metadata_simple_iterator_init()
467  * \retval FLAC__bool
468  *    \c true if successful, else \c false.
469  */
470 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
471
472 /* \} */
473
474
475 /** \defgroup flac_metadata_level2 FLAC/metadata.h: metadata level 2 interface
476  *  \ingroup flac_metadata
477  *
478  * \brief
479  * The level 2 interface provides read-write access to FLAC file metadata;
480  * all metadata is read into memory, operated on in memory, and then written
481  * to file, which is more efficient than level 1 when editing multiple blocks.
482  *
483  * The general usage of this interface is:
484  *
485  * - Create a new chain using FLAC__metadata_chain_new().  A chain is a
486  *   linked list of FLAC metadata blocks.
487  * - Read all metadata into the the chain from a FLAC file using
488  *   FLAC__metadata_chain_read() and check the status.
489  * - Optionally, consolidate the padding using
490  *   FLAC__metadata_chain_merge_padding() or
491  *   FLAC__metadata_chain_sort_padding().
492  * - Create a new iterator using FLAC__metadata_iterator_new()
493  * - Initialize the iterator to point to the first element in the chain
494  *   using FLAC__metadata_iterator_init()
495  * - Traverse the chain using FLAC__metadata_iterator_next and
496  *   FLAC__metadata_iterator_prev().
497  * - Get a block for reading or modification using
498  *   FLAC__metadata_iterator_get_block().  The pointer to the object
499  *   inside the chain is returned, so the block is yours to modify.
500  *   Changes will be reflected in the FLAC file when you write the
501  *   chain.  You can also add and delete blocks (see functions below).
502  * - When done, write out the chain using FLAC__metadata_chain_write().
503  *   Make sure to read the whole comment to the function below.
504  * - Delete the chain using FLAC__metadata_chain_delete().
505  *
506  * \note
507  * Even though the FLAC file is not open while the chain is being
508  * manipulated, you must not alter the file externally during
509  * this time.  The chain assumes the FLAC file will not change
510  * between the time of FLAC__metadata_chain_read() and
511  * FLAC__metadata_chain_write().
512  *
513  * \note
514  * Do not modify the is_last, length, or type fields of returned
515  * FLAC__MetadataType objects.  These are managed automatically.
516  *
517  * \note
518  * The metadata objects returned by FLAC__metadata_iterator_get_block()
519  * are owned by the chain; do not FLAC__metadata_object_delete() them.
520  * In the same way, blocks passed to FLAC__metadata_iterator_set_block()
521  * become owned by the chain and they will be deleted when the chain is
522  * deleted.
523  *
524  * \{
525  */
526
527 struct FLAC__Metadata_Chain;
528 /** The opaque structure definition for the level 2 chain type.
529  */
530 typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
531
532 struct FLAC__Metadata_Iterator;
533 /** The opaque structure definition for the level 2 iterator type.
534  */
535 typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
536
537 typedef enum {
538         FLAC__METADATA_CHAIN_STATUS_OK = 0,
539         /**< The chain is in the normal OK state */
540
541         FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
542         /**< The data passed into a function violated the function's usage criteria */
543
544         FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
545         /**< The chain could not open the target file */
546
547         FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
548         /**< The chain could not find the FLAC signature at the start of the file */
549
550         FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
551         /**< The chain tried to write to a file that was not writable */
552
553         FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
554         /**< The chain encountered input that does not conform to the FLAC metadata specification */
555
556         FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
557         /**< The chain encountered an error while reading the FLAC file */
558
559         FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
560         /**< The chain encountered an error while seeking in the FLAC file */
561
562         FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
563         /**< The chain encountered an error while writing the FLAC file */
564
565         FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
566         /**< The chain encountered an error renaming the FLAC file */
567
568         FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
569         /**< The chain encountered an error removing the temporary file */
570
571         FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
572         /**< Memory allocation failed */
573
574         FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR
575         /**< The caller violated an assertion or an unexpected error occurred */
576
577 } FLAC__Metadata_ChainStatus;
578
579 /** Maps a FLAC__Metadata_ChainStatus to a C string.
580  *
581  *  Using a FLAC__Metadata_ChainStatus as the index to this array
582  *  will give the string equivalent.  The contents should not be modified.
583  */
584 extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
585
586 /*********** FLAC__Metadata_Chain ***********/
587
588 /** Create a new chain instance.
589  *
590  * \retval FLAC__Metadata_Chain*
591  *    \c NULL if there was an error allocating memory, else the new instance.
592  */
593 FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new();
594
595 /** Free a chain instance.  Deletes the object pointed to by \a chain.
596  *
597  * \param chain  A pointer to an existing chain.
598  * \assert
599  *    \code chain != NULL \endcode
600  */
601 FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
602
603 /** Get the current status of the chain.  Call this after a function
604  *  returns \c false to get the reason for the error.  Also resets the
605  *  status to FLAC__METADATA_CHAIN_STATUS_OK.
606  *
607  * \param chain    A pointer to an existing chain.
608  * \assert
609  *    \code chain != NULL \endcode
610  * \retval FLAC__Metadata_ChainStatus
611  *    The current status of the chain.
612  */
613 FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
614
615 /** Read all metadata from a FLAC file into the chain.
616  *
617  * \param chain    A pointer to an existing chain.
618  * \param filename The path to the FLAC file to read.
619  * \assert
620  *    \code chain != NULL \endcode
621  *    \code filename != NULL \endcode
622  * \retval FLAC__bool
623  *    \c true if a valid list of metadata blocks was read from
624  *    \a filename, else \c false.  On failure, check the status with
625  *    FLAC__metadata_chain_status().
626  */
627 FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
628
629 /** Write all metadata out to the FLAC file.  This function tries to be as
630  *  efficient as possible; how the metadata is actually written is shown by
631  *  the following:
632  *
633  *  If the current chain is the same size as the existing metadata, the new
634  *  data is written in place.
635  *
636  *  If the current chain is longer than the existing metadata, and
637  *  \a use_padding is \c true, and the last block is a PADDING block of
638  *  sufficient length, the function will truncate the final padding block
639  *  so that the overall size of the metadata is the same as the existing
640  *  metadata, and then just rewrite the metadata.  Otherwise, if not all of
641  *  the above conditions are met, the entire FLAC file must be rewritten.
642  *  If you want to use padding this way it is a good idea to call
643  *  FLAC__metadata_chain_sort_padding() first so that you have the maximum
644  *  amount of padding to work with, unless you need to preserve ordering
645  *  of the PADDING blocks for some reason.
646  *
647  *  If the current chain is shorter than the existing metadata, and
648  *  \a use_padding is \c true, and the final block is a PADDING block, the padding
649  *  is extended to make the overall size the same as the existing data.  If
650  *  \a use_padding is \c true and the last block is not a PADDING block, a new
651  *  PADDING block is added to the end of the new data to make it the same
652  *  size as the existing data (if possible, see the note to
653  *  FLAC__metadata_simple_iterator_set_block() about the four byte limit)
654  *  and the new data is written in place.  If none of the above apply or
655  *  \a use_padding is \c false, the entire FLAC file is rewritten.
656  *
657  *  If \a preserve_file_stats is \c true, the owner and modification time will
658  *  be preserved even if the FLAC file is written.
659  *
660  * \param chain               A pointer to an existing chain.
661  * \param use_padding         See above.
662  * \param preserve_file_stats See above.
663  * \assert
664  *    \code chain != NULL \endcode
665  * \retval FLAC__bool
666  *    \c true if the write succeeded, else \c false.  On failure,
667  *    check the status with FLAC__metadata_chain_status().
668  */
669 FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
670
671 /** Merge adjacent PADDING blocks into a single block.
672  *
673  * \note This function does not write to the FLAC file, it only
674  * modifies the chain.
675  *
676  * \warning Any iterator on the current chain will become invalid after this
677  * call.  You should delete the iterator and get a new one.
678  *
679  * \param chain               A pointer to an existing chain.
680  * \assert
681  *    \code chain != NULL \endcode
682  */
683 FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
684
685 /** This function will move all PADDING blocks to the end on the metadata,
686  *  then merge them into a single block.
687  *
688  * \note This function does not write to the FLAC file, it only
689  * modifies the chain.
690  *
691  * \warning Any iterator on the current chain will become invalid after this
692  * call.  You should delete the iterator and get a new one.
693  *
694  * \param chain  A pointer to an existing chain.
695  * \assert
696  *    \code chain != NULL \endcode
697  */
698 FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
699
700
701 /*********** FLAC__Metadata_Iterator ***********/
702
703 /** Create a new iterator instance.
704  *
705  * \retval FLAC__Metadata_Iterator*
706  *    \c NULL if there was an error allocating memory, else the new instance.
707  */
708 FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new();
709
710 /** Free an iterator instance.  Deletes the object pointed to by \a iterator.
711  *
712  * \param iterator  A pointer to an existing iterator.
713  * \assert
714  *    \code iterator != NULL \endcode
715  */
716 FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
717
718 /** Initialize the iterator to point to the first metadata block in the
719  *  given chain.
720  *
721  * \param iterator  A pointer to an existing iterator.
722  * \param chain     A pointer to an existing and initialized (read) chain.
723  * \assert
724  *    \code iterator != NULL \endcode
725  *    \code chain != NULL \endcode
726  */
727 FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
728
729 /** Moves the iterator forward one metadata block, returning \c false if
730  *  already at the end.
731  *
732  * \param iterator  A pointer to an existing initialized iterator.
733  * \assert
734  *    \code iterator != NULL \endcode
735  *    \a iterator has been successfully initialized with
736  *    FLAC__metadata_iterator_init()
737  * \retval FLAC__bool
738  *    \c false if already at the last metadata block of the chain, else
739  *    \c true.
740  */
741 FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
742
743 /** Moves the iterator backward one metadata block, returning \c false if
744  *  already at the beginning.
745  *
746  * \param iterator  A pointer to an existing initialized iterator.
747  * \assert
748  *    \code iterator != NULL \endcode
749  *    \a iterator has been successfully initialized with
750  *    FLAC__metadata_iterator_init()
751  * \retval FLAC__bool
752  *    \c false if already at the first metadata block of the chain, else
753  *    \c true.
754  */
755 FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
756
757 /** Get the type of the metadata block at the current position.
758  *
759  * \param iterator  A pointer to an existing initialized iterator.
760  * \assert
761  *    \code iterator != NULL \endcode
762  *    \a iterator has been successfully initialized with
763  *    FLAC__metadata_iterator_init()
764  * \retval FLAC__MetadataType
765  *    The type of the metadata block at the current iterator position.
766  */
767 FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
768
769 /** Get the metadata block at the current position.  You can modify
770  *  the block in place but must write the chain before the changes
771  *  are reflected to the FLAC file.  You do not need to call
772  *  FLAC__metadata_iterator_set_block() to reflect the changes;
773  *  the pointer returned by FLAC__metadata_iterator_get_block()
774  *  points directly into the chain.
775  *
776  * \warning
777  * Do not call FLAC__metadata_object_delete() on the returned object;
778  * to delete a block use FLAC__metadata_iterator_delete_block().
779  *
780  * \param iterator  A pointer to an existing initialized iterator.
781  * \assert
782  *    \code iterator != NULL \endcode
783  *    \a iterator has been successfully initialized with
784  *    FLAC__metadata_iterator_init()
785  * \retval FLAC__StreamMetadata*
786  *    The current metadata block.
787  */
788 FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
789
790 /** Set the metadata block at the current position, replacing the existing
791  *  block.  The new block passed in becomes owned by the chain and it will be
792  *  deleted when the chain is deleted.
793  *
794  * \param iterator  A pointer to an existing initialized iterator.
795  * \param block     A pointer to a metadata block.
796  * \assert
797  *    \code iterator != NULL \endcode
798  *    \a iterator has been successfully initialized with
799  *    FLAC__metadata_iterator_init()
800  *    \code block != NULL \endcode
801  * \retval FLAC__bool
802  *    \c false if the conditions in the above description are not met, or
803  *    a memory allocation error occurs, otherwise \c true.
804  */
805 FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
806
807 /** Removes the current block from the chain.  If \a replace_with_padding is
808  *  \c true, the block will instead be replaced with a padding block of equal
809  *  size.  You can not delete the STREAMINFO block.  The iterator will be
810  *  left pointing to the block before the one just "deleted", even if
811  *  \a replace_with_padding is \c true.
812  *
813  * \param iterator              A pointer to an existing initialized iterator.
814  * \param replace_with_padding  See above.
815  * \assert
816  *    \code iterator != NULL \endcode
817  *    \a iterator has been successfully initialized with
818  *    FLAC__metadata_iterator_init()
819  * \retval FLAC__bool
820  *    \c false if the conditions in the above description are not met,
821  *    otherwise \c true.
822  */
823 FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
824
825 /** Insert a new block before the current block.  You cannot insert a block
826  *  before the first STREAMINFO block.  You cannot insert a STREAMINFO block
827  *  as there can be only one, the one that already exists at the head when you
828  *  read in a chain.  The chain takes ownership of the new block and it will be
829  *  deleted when the chain is deleted.  The iterator will be left pointing to
830  *  the new block.
831  *
832  * \param iterator  A pointer to an existing initialized iterator.
833  * \param block     A pointer to a metadata block to insert.
834  * \assert
835  *    \code iterator != NULL \endcode
836  *    \a iterator has been successfully initialized with
837  *    FLAC__metadata_iterator_init()
838  * \retval FLAC__bool
839  *    \c false if the conditions in the above description are not met, or
840  *    a memory allocation error occurs, otherwise \c true.
841  */
842 FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
843
844 /** Insert a new block after the current block.  You cannot insert a STREAMINFO
845  *  block as there can be only one, the one that already exists at the head when
846  *  you read in a chain.  The chain takes ownership of the new block and it will
847  *  be deleted when the chain is deleted.  The iterator will be left pointing to
848  *  the new block.
849  *
850  * \param iterator  A pointer to an existing initialized iterator.
851  * \param block     A pointer to a metadata block to insert.
852  * \assert
853  *    \code iterator != NULL \endcode
854  *    \a iterator has been successfully initialized with
855  *    FLAC__metadata_iterator_init()
856  * \retval FLAC__bool
857  *    \c false if the conditions in the above description are not met, or
858  *    a memory allocation error occurs, otherwise \c true.
859  */
860 FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
861
862 /* \} */
863
864
865 /** \defgroup flac_metadata_object FLAC/metadata.h: metadata object methods
866  *  \ingroup flac_metadata
867  *
868  * \brief
869  * This module contains methods for manipulating FLAC metadata objects.
870  *
871  * Since many are variable length we have to be careful about the memory
872  * management.  We decree that all pointers to data in the object are
873  * owned by the object and memory-managed by the object.
874  *
875  * Use the FLAC__metadata_object_new() and FLAC__metadata_object_delete()
876  * functions to create all instances.  When using the
877  * FLAC__metadata_object_set_*() functions to set pointers to data, set
878  * \a copy to \c true to have the function make it's own copy of the data, or
879  * to \c false to give the object ownership of your data.  In the latter case
880  * your pointer must be freeable by free() and will be free()d when the object
881  * is FLAC__metadata_object_delete()d.  It is legal to pass a null pointer as
882  * the data pointer to a FLAC__metadata_object_set_*() function as long as
883  * the length argument is 0 and the \a copy argument is \c false.
884  *
885  * The FLAC__metadata_object_new() and FLAC__metadata_object_clone() function
886  * will return \c NULL in the case of a memory allocation error, otherwise a new
887  * object.  The FLAC__metadata_object_set_*() functions return \c false in the
888  * case of a memory allocation error.
889  *
890  * We don't have the convenience of C++ here, so note that the library relies
891  * on you to keep the types straight.  In other words, if you pass, for
892  * example, a FLAC__StreamMetadata* that represents a STREAMINFO block to
893  * FLAC__metadata_object_application_set_data(), you will get an assertion
894  * failure.
895  *
896  * There is no need to recalculate the length field on metadata blocks you
897  * have modified.  They will be calculated automatically before they  are
898  * written back to a file.
899  *
900  * \{
901  */
902
903
904 /** Create a new metadata object instance of the given type.
905  *
906  *  The object will be "empty"; i.e. values and data pointers will be \c 0.
907  *
908  * \param type  Type of object to create
909  * \retval FLAC__StreamMetadata*
910  *    \c NULL if there was an error allocating memory, else the new instance.
911  */
912 FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
913
914 /** Create a copy of an existing metadata object.
915  *
916  *  The copy is a "deep" copy, i.e. dynamically allocated data within the
917  *  object is also copied.  The caller takes ownership of the new block and
918  *  is responsible for freeing it with FLAC__metadata_object_delete().
919  *
920  * \param object  Pointer to object to copy.
921  * \assert
922  *    \code object != NULL \endcode
923  * \retval FLAC__StreamMetadata*
924  *    \c NULL if there was an error allocating memory, else the new instance.
925  */
926 FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
927
928 /** Free a metadata object.  Deletes the object pointed to by \a object.
929  *
930  *  The delete is a "deep" delete, i.e. dynamically allocated data within the
931  *  object is also deleted.
932  *
933  * \param object  A pointer to an existing object.
934  * \assert
935  *    \code object != NULL \endcode
936  */
937 FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
938
939 /** Compares two metadata objects.
940  *
941  *  The compare is "deep", i.e. dynamically allocated data within the
942  *  object is also compared.
943  *
944  * \param block1  A pointer to an existing object.
945  * \param block2  A pointer to an existing object.
946  * \assert
947  *    \code block1 != NULL \endcode
948  *    \code block2 != NULL \endcode
949  * \retval FLAC__bool
950  *    \c true if objects are identical, else \c false.
951  */
952 FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
953
954 /** Sets the application data of an APPLICATION block.
955  *
956  *  If \a copy is \c true, a copy of the data is stored; otherwise, the object
957  *  takes ownership of the pointer.  Returns \c false if \a copy == \c true
958  *  and malloc fails.
959  *
960  * \param object  A pointer to an existing APPLICATION object.
961  * \param data    A pointer to the data to set.
962  * \param length  The length of \a data in bytes.
963  * \param copy    See above.
964  * \assert
965  *    \code object != NULL \endcode
966  *    \code object->type == FLAC__METADATA_TYPE_APPLICATION \endcode
967  *    \code (data != NULL && length > 0) ||
968  * (data == NULL && length == 0 && copy == false) \endcode
969  * \retval FLAC__bool
970  *    \c false if \a copy is \c true and malloc fails, else \c true.
971  */
972 FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
973
974 /** Resize the seekpoint array.
975  *
976  *  If the size shrinks, elements will truncated; if it grows, new placeholder
977  *  points will be added to the end.
978  *
979  * \param object          A pointer to an existing SEEKTABLE object.
980  * \param new_num_points  The desired length of the array; may be \c 0.
981  * \assert
982  *    \code object != NULL \endcode
983  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
984  *    \code (object->data.seek_table.points == NULL && object->data.seek_table.num_points == 0) ||
985  * (object->data.seek_table.points != NULL && object->data.seek_table.num_points > 0) \endcode
986  * \retval FLAC__bool
987  *    \c false if memory allocation error, else \c true.
988  */
989 FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
990
991 /** Set a seekpoint in a seektable.
992  *
993  * \param object     A pointer to an existing SEEKTABLE object.
994  * \param point_num  Index into seekpoint array to set.
995  * \param point      The point to set.
996  * \assert
997  *    \code object != NULL \endcode
998  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
999  *    \code object->data.seek_table.num_points > point_num \endcode
1000  */
1001 FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
1002
1003 /** Insert a seekpoint into a seektable.
1004  *
1005  * \param object     A pointer to an existing SEEKTABLE object.
1006  * \param point_num  Index into seekpoint array to set.
1007  * \param point      The point to set.
1008  * \assert
1009  *    \code object != NULL \endcode
1010  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1011  *    \code object->data.seek_table.num_points >= point_num \endcode
1012  * \retval FLAC__bool
1013  *    \c false if memory allocation error, else \c true.
1014  */
1015 FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
1016
1017 /** Delete a seekpoint from a seektable.
1018  *
1019  * \param object     A pointer to an existing SEEKTABLE object.
1020  * \param point_num  Index into seekpoint array to set.
1021  * \assert
1022  *    \code object != NULL \endcode
1023  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1024  *    \code object->data.seek_table.num_points > point_num \endcode
1025  * \retval FLAC__bool
1026  *    \c false if memory allocation error, else \c true.
1027  */
1028 FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
1029
1030 /** Check a seektable to see if it conforms to the FLAC specification.
1031  *  See the format specification for limits on the contents of the
1032  *  seektable.
1033  *
1034  * \param object  A pointer to an existing SEEKTABLE object.
1035  * \assert
1036  *    \code object != NULL \endcode
1037  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1038  * \retval FLAC__bool
1039  *    \c false if seek table is illegal, else \c true.
1040  */
1041 FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
1042
1043 /** Append a number of placeholder points to the end of a seek table.
1044  *
1045  * \note
1046  * As with the other ..._seektable_template_... functions, you should
1047  * call FLAC__metadata_object_seektable_template_sort() when finished
1048  * to make the seek table legal.
1049  *
1050  * \param object  A pointer to an existing SEEKTABLE object.
1051  * \param num     The number of placeholder points to append.
1052  * \assert
1053  *    \code object != NULL \endcode
1054  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1055  * \retval FLAC__bool
1056  *    \c false if memory allocation fails, else \c true.
1057  */
1058 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
1059
1060 /** Append a specific seek point template to the end of a seek table.
1061  *
1062  * \note
1063  * As with the other ..._seektable_template_... functions, you should
1064  * call FLAC__metadata_object_seektable_template_sort() when finished
1065  * to make the seek table legal.
1066  *
1067  * \param object  A pointer to an existing SEEKTABLE object.
1068  * \param sample_number  The sample number of the seek point template.
1069  * \assert
1070  *    \code object != NULL \endcode
1071  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1072  * \retval FLAC__bool
1073  *    \c false if memory allocation fails, else \c true.
1074  */
1075 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
1076
1077 /** Append specific seek point templates to the end of a seek table.
1078  *
1079  * \note
1080  * As with the other ..._seektable_template_... functions, you should
1081  * call FLAC__metadata_object_seektable_template_sort() when finished
1082  * to make the seek table legal.
1083  *
1084  * \param object  A pointer to an existing SEEKTABLE object.
1085  * \param sample_numbers  An array of sample numbers for the seek points.
1086  * \param num     The number of seek point templates to append.
1087  * \assert
1088  *    \code object != NULL \endcode
1089  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1090  * \retval FLAC__bool
1091  *    \c false if memory allocation fails, else \c true.
1092  */
1093 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
1094
1095 /** Append a set of evenly-spaced seek point templates to the end of a
1096  *  seek table.
1097  *
1098  * \note
1099  * As with the other ..._seektable_template_... functions, you should
1100  * call FLAC__metadata_object_seektable_template_sort() when finished
1101  * to make the seek table legal.
1102  *
1103  * \param object  A pointer to an existing SEEKTABLE object.
1104  * \param num     The number of placeholder points to append.
1105  * \param total_samples  The total number of samples to be encoded;
1106  *                       the seekpoints will be spaced approximately
1107  *                       \a total_samples / \a num samples apart.
1108  * \assert
1109  *    \code object != NULL \endcode
1110  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1111  * \retval FLAC__bool
1112  *    \c false if memory allocation fails, else \c true.
1113  */
1114 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
1115
1116 /** Sort a seek table's seek points according to the format specification,
1117  *  removing duplicates.
1118  *
1119  * \param object   A pointer to a seek table to be sorted.
1120  * \param compact  If \c false, behaves like FLAC__format_seektable_sort().
1121  *                 If \c true, duplicates are deleted and the seek table is
1122  *                 shrunk appropriately; the number of placeholder points
1123  *                 present in the seek table will be the same after the call
1124  *                 as before.
1125  * \assert
1126  *    \code object != NULL \endcode
1127  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1128  * \retval FLAC__bool
1129  *    \c false if realloc fails, else \c true.
1130  */
1131 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
1132
1133 /** Sets the vendor string in a VORBIS_COMMENT block.
1134  *
1135  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1136  *  takes ownership of the \c entry->entry pointer.  Returns \c false if
1137  *  \a copy == \c true and malloc fails.
1138  *
1139  * \param object  A pointer to an existing VORBIS_COMMENT object.
1140  * \param entry   The entry to set the vendor string to.
1141  * \param copy    See above.
1142  * \assert
1143  *    \code object != NULL \endcode
1144  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1145  *    \code (entry->entry != NULL && entry->length > 0) ||
1146  * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1147  * \retval FLAC__bool
1148  *    \c false if \a copy is \c true and malloc fails, else \c true.
1149  */
1150 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1151
1152 /** Resize the comment array.
1153  *
1154  *  If the size shrinks, elements will truncated; if it grows, new empty
1155  *  fields will be added to the end.
1156  *
1157  * \param object            A pointer to an existing VORBIS_COMMENT object.
1158  * \param new_num_comments  The desired length of the array; may be \c 0.
1159  * \assert
1160  *    \code object != NULL \endcode
1161  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1162  *    \code (object->data.vorbis_comment.comments == NULL && object->data.vorbis_comment.num_comments == 0) ||
1163  * (object->data.vorbis_comment.comments != NULL && object->data.vorbis_comment.num_comments > 0) \endcode
1164  * \retval FLAC__bool
1165  *    \c false if memory allocation error, else \c true.
1166  */
1167 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
1168
1169 /** Sets a comment in a VORBIS_COMMENT block.
1170  *
1171  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1172  *  takes ownership of the \c entry->entry pointer.  Returns \c false if
1173  *  \a copy == \c true and malloc fails.
1174  *
1175  * \param object       A pointer to an existing VORBIS_COMMENT object.
1176  * \param comment_num  Index into comment array to set.
1177  * \param entry        The entry to set the comment to.
1178  * \param copy         See above.
1179  * \assert
1180  *    \code object != NULL \endcode
1181  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1182  *    \code (entry->entry != NULL && entry->length > 0) ||
1183  * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1184  * \retval FLAC__bool
1185  *    \c false if \a copy is \c true and malloc fails, else \c true.
1186  */
1187 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1188
1189 /** Insert a comment in a VORBIS_COMMENT block at the given index.
1190  *
1191  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1192  *  takes ownership of the \c entry->entry pointer.  Returns \c false if
1193  *  \a copy == \c true and malloc fails.
1194  *
1195  * \param object       A pointer to an existing VORBIS_COMMENT object.
1196  * \param comment_num  The index at which to insert the comment.  The comments
1197  *                     at and after \a comment_num move right one position.
1198  *                     To append a comment to the end, set \a comment_num to
1199  *                     \c object->data.vorbis_comment.num_comments .
1200  * \param entry        The comment to insert.
1201  * \param copy         See above.
1202  * \assert
1203  *    \code object != NULL \endcode
1204  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1205  *    \code object->data.vorbis_comment.num_comments >= comment_num \endcode
1206  *    \code (entry->entry != NULL && entry->length > 0) ||
1207  * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1208  * \retval FLAC__bool
1209  *    \c false if \a copy is \c true and malloc fails, else \c true.
1210  */
1211 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1212
1213 /** Delete a comment in a VORBIS_COMMENT block at the given index.
1214  *
1215  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1216  *  takes ownership of the \c entry->entry pointer.  Returns \c false if
1217  *  \a copy == \c true and malloc fails.
1218  *
1219  * \param object       A pointer to an existing VORBIS_COMMENT object.
1220  * \param comment_num  The index of the comment to delete.
1221  * \assert
1222  *    \code object != NULL \endcode
1223  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1224  *    \code object->data.vorbis_comment.num_comments > comment_num \endcode
1225  *    \code (entry->entry != NULL && entry->length > 0) ||
1226  * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1227  * \retval FLAC__bool
1228  *    \c false if realloc fails, else \c true.
1229  */
1230 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
1231
1232 /* \} */
1233
1234 #ifdef __cplusplus
1235 }
1236 #endif
1237
1238 #endif