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