1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2001-2009  Josh Coalson
3  * Copyright (C) 2011-2013  Xiph.Org Foundation
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Xiph.org Foundation nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 module deimos.flac.metadata;
34 
35 import deimos.flac.callback;
36 import deimos.flac.export_;
37 import deimos.flac.format;
38 import deimos.flac.ordinals;
39 
40 version(Posix) {}
41 else version(Windows) {}
42 else static assert(0, "Unsupported OS.");
43 
44 extern(C):
45 nothrow:
46 
47 
48 /* --------------------------------------------------------------------
49    (For an example of how all these routines are used, see the source
50    code for the unit tests in src/test_libFLAC/metadata_*.c, or
51    metaflac in src/metaflac/)
52    ------------------------------------------------------------------*/
53 
54 /** \file include/FLAC/metadata.h
55  *
56  *  \brief
57  *  This module provides functions for creating and manipulating FLAC
58  *  metadata blocks in memory, and three progressively more powerful
59  *  interfaces for traversing and editing metadata in FLAC files.
60  *
61  *  See the detailed documentation for each interface in the
62  *  \link flac_metadata metadata \endlink module.
63  */
64 
65 /** \defgroup flac_metadata FLAC/metadata.h: metadata interfaces
66  *  \ingroup flac
67  *
68  *  \brief
69  *  This module provides functions for creating and manipulating FLAC
70  *  metadata blocks in memory, and three progressively more powerful
71  *  interfaces for traversing and editing metadata in native FLAC files.
72  *  Note that currently only the Chain interface (level 2) supports Ogg
73  *  FLAC files, and it is read-only i.e. no writing back changed
74  *  metadata to file.
75  *
76  *  There are three metadata interfaces of increasing complexity:
77  *
78  *  Level 0:
79  *  Read-only access to the STREAMINFO, VORBIS_COMMENT, CUESHEET, and
80  *  PICTURE blocks.
81  *
82  *  Level 1:
83  *  Read-write access to all metadata blocks.  This level is write-
84  *  efficient in most cases (more on this below), and uses less memory
85  *  than level 2.
86  *
87  *  Level 2:
88  *  Read-write access to all metadata blocks.  This level is write-
89  *  efficient in all cases, but uses more memory since all metadata for
90  *  the whole file is read into memory and manipulated before writing
91  *  out again.
92  *
93  *  What do we mean by efficient?  Since FLAC metadata appears at the
94  *  beginning of the file, when writing metadata back to a FLAC file
95  *  it is possible to grow or shrink the metadata such that the entire
96  *  file must be rewritten.  However, if the size remains the same during
97  *  changes or PADDING blocks are utilized, only the metadata needs to be
98  *  overwritten, which is much faster.
99  *
100  *  Efficient means the whole file is rewritten at most one time, and only
101  *  when necessary.  Level 1 is not efficient only in the case that you
102  *  cause more than one metadata block to grow or shrink beyond what can
103  *  be accomodated by padding.  In this case you should probably use level
104  *  2, which allows you to edit all the metadata for a file in memory and
105  *  write it out all at once.
106  *
107  *  All levels know how to skip over and not disturb an ID3v2 tag at the
108  *  front of the file.
109  *
110  *  All levels access files via their filenames.  In addition, level 2
111  *  has additional alternative read and write functions that take an I/O
112  *  handle and callbacks, for situations where access by filename is not
113  *  possible.
114  *
115  *  In addition to the three interfaces, this module defines functions for
116  *  creating and manipulating various metadata objects in memory.  As we see
117  *  from the Format module, FLAC metadata blocks in memory are very primitive
118  *  structures for storing information in an efficient way.  Reading
119  *  information from the structures is easy but creating or modifying them
120  *  directly is more complex.  The metadata object routines here facilitate
121  *  this by taking care of the consistency and memory management drudgery.
122  *
123  *  Unless you will be using the level 1 or 2 interfaces to modify existing
124  *  metadata however, you will not probably not need these.
125  *
126  *  From a dependency standpoint, none of the encoders or decoders require
127  *  the metadata module.  This is so that embedded users can strip out the
128  *  metadata module from libFLAC to reduce the size and complexity.
129  */
130 
131 
132 /** \defgroup flac_metadata_level0 FLAC/metadata.h: metadata level 0 interface
133  *  \ingroup flac_metadata
134  *
135  *  \brief
136  *  The level 0 interface consists of individual routines to read the
137  *  STREAMINFO, VORBIS_COMMENT, CUESHEET, and PICTURE blocks, requiring
138  *  only a filename.
139  *
140  *  They try to skip any ID3v2 tag at the head of the file.
141  *
142  * \{
143  */
144 
145 /** Read the STREAMINFO metadata block of the given FLAC file.  This function
146  *  will try to skip any ID3v2 tag at the head of the file.
147  *
148  * \param filename    The path to the FLAC file to read.
149  * \param streaminfo  A pointer to space for the STREAMINFO block.  Since
150  *                    FLAC__StreamMetadata is a simple structure with no
151  *                    memory allocation involved, you pass the address of
152  *                    an existing structure.  It need not be initialized.
153  * \assert
154  *    \code filename != NULL \endcode
155  *    \code streaminfo != NULL \endcode
156  * \retval FLAC__bool
157  *    \c true if a valid STREAMINFO block was read from \a filename.  Returns
158  *    \c false if there was a memory allocation error, a file decoder error,
159  *    or the file contained no STREAMINFO block.  (A memory allocation error
160  *    is possible because this function must set up a file decoder.)
161  */
162 FLAC__bool FLAC__metadata_get_streaminfo(const char* filename, FLAC__StreamMetadata* streaminfo);
163 
164 /** Read the VORBIS_COMMENT metadata block of the given FLAC file.  This
165  *  function will try to skip any ID3v2 tag at the head of the file.
166  *
167  * \param filename    The path to the FLAC file to read.
168  * \param tags        The address where the returned pointer will be
169  *                    stored.  The \a tags object must be deleted by
170  *                    the caller using FLAC__metadata_object_delete().
171  * \assert
172  *    \code filename != NULL \endcode
173  *    \code tags != NULL \endcode
174  * \retval FLAC__bool
175  *    \c true if a valid VORBIS_COMMENT block was read from \a filename,
176  *    and \a *tags will be set to the address of the metadata structure.
177  *    Returns \c false if there was a memory allocation error, a file
178  *    decoder error, or the file contained no VORBIS_COMMENT block, and
179  *    \a *tags will be set to \c NULL.
180  */
181 FLAC__bool FLAC__metadata_get_tags(const char* filename, FLAC__StreamMetadata** tags);
182 
183 /** Read the CUESHEET metadata block of the given FLAC file.  This
184  *  function will try to skip any ID3v2 tag at the head of the file.
185  *
186  * \param filename    The path to the FLAC file to read.
187  * \param cuesheet    The address where the returned pointer will be
188  *                    stored.  The \a cuesheet object must be deleted by
189  *                    the caller using FLAC__metadata_object_delete().
190  * \assert
191  *    \code filename != NULL \endcode
192  *    \code cuesheet != NULL \endcode
193  * \retval FLAC__bool
194  *    \c true if a valid CUESHEET block was read from \a filename,
195  *    and \a *cuesheet will be set to the address of the metadata
196  *    structure.  Returns \c false if there was a memory allocation
197  *    error, a file decoder error, or the file contained no CUESHEET
198  *    block, and \a *cuesheet will be set to \c NULL.
199  */
200 FLAC__bool FLAC__metadata_get_cuesheet(const char* filename, FLAC__StreamMetadata** cuesheet);
201 
202 /** Read a PICTURE metadata block of the given FLAC file.  This
203  *  function will try to skip any ID3v2 tag at the head of the file.
204  *  Since there can be more than one PICTURE block in a file, this
205  *  function takes a number of parameters that act as constraints to
206  *  the search.  The PICTURE block with the largest area matching all
207  *  the constraints will be returned, or \a *picture will be set to
208  *  \c NULL if there was no such block.
209  *
210  * \param filename    The path to the FLAC file to read.
211  * \param picture     The address where the returned pointer will be
212  *                    stored.  The \a picture object must be deleted by
213  *                    the caller using FLAC__metadata_object_delete().
214  * \param type        The desired picture type.  Use \c -1 to mean
215  *                    "any type".
216  * \param mime_type   The desired MIME type, e.g. "image/jpeg".  The
217  *                    string will be matched exactly.  Use \c NULL to
218  *                    mean "any MIME type".
219  * \param description The desired description.  The string will be
220  *                    matched exactly.  Use \c NULL to mean "any
221  *                    description".
222  * \param max_width   The maximum width in pixels desired.  Use
223  *                    \c (uint)(-1) to mean "any width".
224  * \param max_height  The maximum height in pixels desired.  Use
225  *                    \c (uint)(-1) to mean "any height".
226  * \param max_depth   The maximum color depth in bits-per-pixel desired.
227  *                    Use \c (uint)(-1) to mean "any depth".
228  * \param max_colors  The maximum number of colors desired.  Use
229  *                    \c (uint)(-1) to mean "any number of colors".
230  * \assert
231  *    \code filename != NULL \endcode
232  *    \code picture != NULL \endcode
233  * \retval FLAC__bool
234  *    \c true if a valid PICTURE block was read from \a filename,
235  *    and \a *picture will be set to the address of the metadata
236  *    structure.  Returns \c false if there was a memory allocation
237  *    error, a file decoder error, or the file contained no PICTURE
238  *    block, and \a *picture will be set to \c NULL.
239  */
240 FLAC__bool FLAC__metadata_get_picture(const char* filename,
241                                                              FLAC__StreamMetadata** picture,
242                                                              FLAC__StreamMetadata_Picture_Type type,
243                                                              const char* mime_type,
244                                                              const FLAC__byte* description,
245                                                              uint max_width,
246                                                                              uint max_height,
247                                                              uint max_depth,
248                                                              uint max_colors);
249 
250 /* \} */
251 
252 
253 /** \defgroup flac_metadata_level1 FLAC/metadata.h: metadata level 1 interface
254  *  \ingroup flac_metadata
255  *
256  * \brief
257  * The level 1 interface provides read-write access to FLAC file metadata and
258  * operates directly on the FLAC file.
259  *
260  * The general usage of this interface is:
261  *
262  * - Create an iterator using FLAC__metadata_simple_iterator_new()
263  * - Attach it to a file using FLAC__metadata_simple_iterator_init() and check
264  *   the exit code.  Call FLAC__metadata_simple_iterator_is_writable() to
265  *   see if the file is writable, or only read access is allowed.
266  * - Use FLAC__metadata_simple_iterator_next() and
267  *   FLAC__metadata_simple_iterator_prev() to traverse the blocks.
268  *   This is does not read the actual blocks themselves.
269  *   FLAC__metadata_simple_iterator_next() is relatively fast.
270  *   FLAC__metadata_simple_iterator_prev() is slower since it needs to search
271  *   forward from the front of the file.
272  * - Use FLAC__metadata_simple_iterator_get_block_type() or
273  *   FLAC__metadata_simple_iterator_get_block() to access the actual data at
274  *   the current iterator position.  The returned object is yours to modify
275  *   and free.
276  * - Use FLAC__metadata_simple_iterator_set_block() to write a modified block
277  *   back.  You must have write permission to the original file.  Make sure to
278  *   read the whole comment to FLAC__metadata_simple_iterator_set_block()
279  *   below.
280  * - Use FLAC__metadata_simple_iterator_insert_block_after() to add new blocks.
281  *   Use the object creation functions from
282  *   \link flac_metadata_object here \endlink to generate new objects.
283  * - Use FLAC__metadata_simple_iterator_delete_block() to remove the block
284  *   currently referred to by the iterator, or replace it with padding.
285  * - Destroy the iterator with FLAC__metadata_simple_iterator_delete() when
286  *   finished.
287  *
288  * \note
289  * The FLAC file remains open the whole time between
290  * FLAC__metadata_simple_iterator_init() and
291  * FLAC__metadata_simple_iterator_delete(), so make sure you are not altering
292  * the file during this time.
293  *
294  * \note
295  * Do not modify the \a is_last, \a length, or \a type fields of returned
296  * FLAC__StreamMetadata objects.  These are managed automatically.
297  *
298  * \note
299  * If any of the modification functions
300  * (FLAC__metadata_simple_iterator_set_block(),
301  * FLAC__metadata_simple_iterator_delete_block(),
302  * FLAC__metadata_simple_iterator_insert_block_after(), etc.) return \c false,
303  * you should delete the iterator as it may no longer be valid.
304  *
305  * \{
306  */
307 
308 extern struct FLAC__Metadata_SimpleIterator;
309 /** The opaque structure definition for the level 1 iterator type.
310  *  See the
311  *  \link flac_metadata_level1 metadata level 1 module \endlink
312  *  for a detailed description.
313  */
314 
315 /** Status type for FLAC__Metadata_SimpleIterator.
316  *
317  *  The iterator's current status can be obtained by calling FLAC__metadata_simple_iterator_status().
318  */
319 enum FLAC__Metadata_SimpleIteratorStatus
320 {
321     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
322     /**< The iterator is in the normal OK state */
323 
324     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
325     /**< The data passed into a function violated the function's usage criteria */
326 
327     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
328     /**< The iterator could not open the target file */
329 
330     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
331     /**< The iterator could not find the FLAC signature at the start of the file */
332 
333     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
334     /**< The iterator tried to write to a file that was not writable */
335 
336     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
337     /**< The iterator encountered input that does not conform to the FLAC metadata specification */
338 
339     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
340     /**< The iterator encountered an error while reading the FLAC file */
341 
342     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
343     /**< The iterator encountered an error while seeking in the FLAC file */
344 
345     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
346     /**< The iterator encountered an error while writing the FLAC file */
347 
348     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
349     /**< The iterator encountered an error renaming the FLAC file */
350 
351     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
352     /**< The iterator encountered an error removing the temporary file */
353 
354     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
355     /**< Memory allocation failed */
356 
357     FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
358     /**< The caller violated an assertion or an unexpected error occurred */
359 }
360 
361 /** Maps a FLAC__Metadata_SimpleIteratorStatus to a C string.
362  *
363  *  Using a FLAC__Metadata_SimpleIteratorStatus as the index to this array
364  *  will give the string equivalent.  The contents should not be modified.
365  */
366 extern export __gshared const char** FLAC__Metadata_SimpleIteratorStatusString;
367 
368 
369 /** Create a new iterator instance.
370  *
371  * \retval FLAC__Metadata_SimpleIterator*
372  *    \c NULL if there was an error allocating memory, else the new instance.
373  */
374 FLAC__Metadata_SimpleIterator* FLAC__metadata_simple_iterator_new();
375 
376 /** Free an iterator instance.  Deletes the object pointed to by \a iterator.
377  *
378  * \param iterator  A pointer to an existing iterator.
379  * \assert
380  *    \code iterator != NULL \endcode
381  */
382 void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator* iterator);
383 
384 /** Get the current status of the iterator.  Call this after a function
385  *  returns \c false to get the reason for the error.  Also resets the status
386  *  to FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK.
387  *
388  * \param iterator  A pointer to an existing iterator.
389  * \assert
390  *    \code iterator != NULL \endcode
391  * \retval FLAC__Metadata_SimpleIteratorStatus
392  *    The current status of the iterator.
393  */
394 FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator* iterator);
395 
396 /** Initialize the iterator to point to the first metadata block in the
397  *  given FLAC file.
398  *
399  * \param iterator             A pointer to an existing iterator.
400  * \param filename             The path to the FLAC file.
401  * \param read_only            If \c true, the FLAC file will be opened
402  *                             in read-only mode; if \c false, the FLAC
403  *                             file will be opened for edit even if no
404  *                             edits are performed.
405  * \param preserve_file_stats  If \c true, the owner and modification
406  *                             time will be preserved even if the FLAC
407  *                             file is written to.
408  * \assert
409  *    \code iterator != NULL \endcode
410  *    \code filename != NULL \endcode
411  * \retval FLAC__bool
412  *    \c false if a memory allocation error occurs, the file can't be
413  *    opened, or another error occurs, else \c true.
414  */
415 FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator* iterator, const char* filename, FLAC__bool read_only, FLAC__bool preserve_file_stats);
416 
417 /** Returns \c true if the FLAC file is writable.  If \c false, calls to
418  *  FLAC__metadata_simple_iterator_set_block() and
419  *  FLAC__metadata_simple_iterator_insert_block_after() will fail.
420  *
421  * \param iterator             A pointer to an existing iterator.
422  * \assert
423  *    \code iterator != NULL \endcode
424  * \retval FLAC__bool
425  *    See above.
426  */
427 FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator* iterator);
428 
429 /** Moves the iterator forward one metadata block, returning \c false if
430  *  already at the end.
431  *
432  * \param iterator  A pointer to an existing initialized iterator.
433  * \assert
434  *    \code iterator != NULL \endcode
435  *    \a iterator has been successfully initialized with
436  *    FLAC__metadata_simple_iterator_init()
437  * \retval FLAC__bool
438  *    \c false if already at the last metadata block of the chain, else
439  *    \c true.
440  */
441 FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator* iterator);
442 
443 /** Moves the iterator backward one metadata block, returning \c false if
444  *  already at the beginning.
445  *
446  * \param iterator  A pointer to an existing initialized iterator.
447  * \assert
448  *    \code iterator != NULL \endcode
449  *    \a iterator has been successfully initialized with
450  *    FLAC__metadata_simple_iterator_init()
451  * \retval FLAC__bool
452  *    \c false if already at the first metadata block of the chain, else
453  *    \c true.
454  */
455 FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator* iterator);
456 
457 /** Returns a flag telling if the current metadata block is the last.
458  *
459  * \param iterator  A pointer to an existing initialized iterator.
460  * \assert
461  *    \code iterator != NULL \endcode
462  *    \a iterator has been successfully initialized with
463  *    FLAC__metadata_simple_iterator_init()
464  * \retval FLAC__bool
465  *    \c true if the current metadata block is the last in the file,
466  *    else \c false.
467  */
468 FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator* iterator);
469 
470 /** Get the offset of the metadata block at the current position.  This
471  *  avoids reading the actual block data which can save time for large
472  *  blocks.
473  *
474  * \param iterator  A pointer to an existing initialized iterator.
475  * \assert
476  *    \code iterator != NULL \endcode
477  *    \a iterator has been successfully initialized with
478  *    FLAC__metadata_simple_iterator_init()
479  * \retval off_t
480  *    The offset of the metadata block at the current iterator position.
481  *    This is the byte offset relative to the beginning of the file of
482  *    the current metadata block's header.
483  */
484 off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator* iterator);
485 
486 /** Get the type of the metadata block at the current position.  This
487  *  avoids reading the actual block data which can save time for large
488  *  blocks.
489  *
490  * \param iterator  A pointer to an existing initialized iterator.
491  * \assert
492  *    \code iterator != NULL \endcode
493  *    \a iterator has been successfully initialized with
494  *    FLAC__metadata_simple_iterator_init()
495  * \retval FLAC__MetadataType
496  *    The type of the metadata block at the current iterator position.
497  */
498 FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator* iterator);
499 
500 /** Get the length of the metadata block at the current position.  This
501  *  avoids reading the actual block data which can save time for large
502  *  blocks.
503  *
504  * \param iterator  A pointer to an existing initialized iterator.
505  * \assert
506  *    \code iterator != NULL \endcode
507  *    \a iterator has been successfully initialized with
508  *    FLAC__metadata_simple_iterator_init()
509  * \retval uint
510  *    The length of the metadata block at the current iterator position.
511  *    The is same length as that in the
512  *    <a href="http://flac.sourceforge.net/format.html#metadata_block_header">metadata block header</a>,
513  *    i.e. the length of the metadata body that follows the header.
514  */
515 uint FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator* iterator);
516 
517 /** Get the application ID of the \c APPLICATION block at the current
518  *  position.  This avoids reading the actual block data which can save
519  *  time for large blocks.
520  *
521  * \param iterator  A pointer to an existing initialized iterator.
522  * \param id        A pointer to a buffer of at least \c 4 bytes where
523  *                  the ID will be stored.
524  * \assert
525  *    \code iterator != NULL \endcode
526  *    \code id != NULL \endcode
527  *    \a iterator has been successfully initialized with
528  *    FLAC__metadata_simple_iterator_init()
529  * \retval FLAC__bool
530  *    \c true if the ID was successfully read, else \c false, in which
531  *    case you should check FLAC__metadata_simple_iterator_status() to
532  *    find out why.  If the status is
533  *    \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT, then the
534  *    current metadata block is not an \c APPLICATION block.  Otherwise
535  *    if the status is
536  *    \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR or
537  *    \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR, an I/O error
538  *    occurred and the iterator can no longer be used.
539  */
540 FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator* iterator, FLAC__byte* id);
541 
542 /** Get the metadata block at the current position.  You can modify the
543  *  block but must use FLAC__metadata_simple_iterator_set_block() to
544  *  write it back to the FLAC file.
545  *
546  *  You must call FLAC__metadata_object_delete() on the returned object
547  *  when you are finished with it.
548  *
549  * \param iterator  A pointer to an existing initialized iterator.
550  * \assert
551  *    \code iterator != NULL \endcode
552  *    \a iterator has been successfully initialized with
553  *    FLAC__metadata_simple_iterator_init()
554  * \retval FLAC__StreamMetadata*
555  *    The current metadata block, or \c NULL if there was a memory
556  *    allocation error.
557  */
558 FLAC__StreamMetadata* FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator* iterator);
559 
560 /** Write a block back to the FLAC file.  This function tries to be
561  *  as efficient as possible; how the block is actually written is
562  *  shown by the following:
563  *
564  *  Existing block is a STREAMINFO block and the new block is a
565  *  STREAMINFO block: the new block is written in place.  Make sure
566  *  you know what you're doing when changing the values of a
567  *  STREAMINFO block.
568  *
569  *  Existing block is a STREAMINFO block and the new block is a
570  *  not a STREAMINFO block: this is an error since the first block
571  *  must be a STREAMINFO block.  Returns \c false without altering the
572  *  file.
573  *
574  *  Existing block is not a STREAMINFO block and the new block is a
575  *  STREAMINFO block: this is an error since there may be only one
576  *  STREAMINFO block.  Returns \c false without altering the file.
577  *
578  *  Existing block and new block are the same length: the existing
579  *  block will be replaced by the new block, written in place.
580  *
581  *  Existing block is longer than new block: if use_padding is \c true,
582  *  the existing block will be overwritten in place with the new
583  *  block followed by a PADDING block, if possible, to make the total
584  *  size the same as the existing block.  Remember that a padding
585  *  block requires at least four bytes so if the difference in size
586  *  between the new block and existing block is less than that, the
587  *  entire file will have to be rewritten, using the new block's
588  *  exact size.  If use_padding is \c false, the entire file will be
589  *  rewritten, replacing the existing block by the new block.
590  *
591  *  Existing block is shorter than new block: if use_padding is \c true,
592  *  the function will try and expand the new block into the following
593  *  PADDING block, if it exists and doing so won't shrink the PADDING
594  *  block to less than 4 bytes.  If there is no following PADDING
595  *  block, or it will shrink to less than 4 bytes, or use_padding is
596  *  \c false, the entire file is rewritten, replacing the existing block
597  *  with the new block.  Note that in this case any following PADDING
598  *  block is preserved as is.
599  *
600  *  After writing the block, the iterator will remain in the same
601  *  place, i.e. pointing to the new block.
602  *
603  * \param iterator     A pointer to an existing initialized iterator.
604  * \param block        The block to set.
605  * \param use_padding  See above.
606  * \assert
607  *    \code iterator != NULL \endcode
608  *    \a iterator has been successfully initialized with
609  *    FLAC__metadata_simple_iterator_init()
610  *    \code block != NULL \endcode
611  * \retval FLAC__bool
612  *    \c true if successful, else \c false.
613  */
614 FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator* iterator, FLAC__StreamMetadata* block, FLAC__bool use_padding);
615 
616 /** This is similar to FLAC__metadata_simple_iterator_set_block()
617  *  except that instead of writing over an existing block, it appends
618  *  a block after the existing block.  \a use_padding is again used to
619  *  tell the function to try an expand into following padding in an
620  *  attempt to avoid rewriting the entire file.
621  *
622  *  This function will fail and return \c false if given a STREAMINFO
623  *  block.
624  *
625  *  After writing the block, the iterator will be pointing to the
626  *  new block.
627  *
628  * \param iterator     A pointer to an existing initialized iterator.
629  * \param block        The block to set.
630  * \param use_padding  See above.
631  * \assert
632  *    \code iterator != NULL \endcode
633  *    \a iterator has been successfully initialized with
634  *    FLAC__metadata_simple_iterator_init()
635  *    \code block != NULL \endcode
636  * \retval FLAC__bool
637  *    \c true if successful, else \c false.
638  */
639 FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator* iterator, FLAC__StreamMetadata* block, FLAC__bool use_padding);
640 
641 /** Deletes the block at the current position.  This will cause the
642  *  entire FLAC file to be rewritten, unless \a use_padding is \c true,
643  *  in which case the block will be replaced by an equal-sized PADDING
644  *  block.  The iterator will be left pointing to the block before the
645  *  one just deleted.
646  *
647  *  You may not delete the STREAMINFO block.
648  *
649  * \param iterator     A pointer to an existing initialized iterator.
650  * \param use_padding  See above.
651  * \assert
652  *    \code iterator != NULL \endcode
653  *    \a iterator has been successfully initialized with
654  *    FLAC__metadata_simple_iterator_init()
655  * \retval FLAC__bool
656  *    \c true if successful, else \c false.
657  */
658 FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator* iterator, FLAC__bool use_padding);
659 
660 /* \} */
661 
662 
663 /** \defgroup flac_metadata_level2 FLAC/metadata.h: metadata level 2 interface
664  *  \ingroup flac_metadata
665  *
666  * \brief
667  * The level 2 interface provides read-write access to FLAC file metadata;
668  * all metadata is read into memory, operated on in memory, and then written
669  * to file, which is more efficient than level 1 when editing multiple blocks.
670  *
671  * Currently Ogg FLAC is supported for read only, via
672  * FLAC__metadata_chain_read_ogg() but a subsequent
673  * FLAC__metadata_chain_write() will fail.
674  *
675  * The general usage of this interface is:
676  *
677  * - Create a new chain using FLAC__metadata_chain_new().  A chain is a
678  *   linked list of FLAC metadata blocks.
679  * - Read all metadata into the the chain from a FLAC file using
680  *   FLAC__metadata_chain_read() or FLAC__metadata_chain_read_ogg() and
681  *   check the status.
682  * - Optionally, consolidate the padding using
683  *   FLAC__metadata_chain_merge_padding() or
684  *   FLAC__metadata_chain_sort_padding().
685  * - Create a new iterator using FLAC__metadata_iterator_new()
686  * - Initialize the iterator to point to the first element in the chain
687  *   using FLAC__metadata_iterator_init()
688  * - Traverse the chain using FLAC__metadata_iterator_next and
689  *   FLAC__metadata_iterator_prev().
690  * - Get a block for reading or modification using
691  *   FLAC__metadata_iterator_get_block().  The pointer to the object
692  *   inside the chain is returned, so the block is yours to modify.
693  *   Changes will be reflected in the FLAC file when you write the
694  *   chain.  You can also add and delete blocks (see functions below).
695  * - When done, write out the chain using FLAC__metadata_chain_write().
696  *   Make sure to read the whole comment to the function below.
697  * - Delete the chain using FLAC__metadata_chain_delete().
698  *
699  * \note
700  * Even though the FLAC file is not open while the chain is being
701  * manipulated, you must not alter the file externally during
702  * this time.  The chain assumes the FLAC file will not change
703  * between the time of FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg()
704  * and FLAC__metadata_chain_write().
705  *
706  * \note
707  * Do not modify the is_last, length, or type fields of returned
708  * FLAC__StreamMetadata objects.  These are managed automatically.
709  *
710  * \note
711  * The metadata objects returned by FLAC__metadata_iterator_get_block()
712  * are owned by the chain; do not FLAC__metadata_object_delete() them.
713  * In the same way, blocks passed to FLAC__metadata_iterator_set_block()
714  * become owned by the chain and they will be deleted when the chain is
715  * deleted.
716  *
717  * \{
718  */
719 
720 extern struct FLAC__Metadata_Chain;
721 /** The opaque structure definition for the level 2 chain type.
722  */
723 
724 extern struct FLAC__Metadata_Iterator;
725 /** The opaque structure definition for the level 2 iterator type.
726  */
727 
728 enum FLAC__Metadata_ChainStatus
729 {
730     FLAC__METADATA_CHAIN_STATUS_OK = 0,
731     /**< The chain is in the normal OK state */
732 
733     FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
734     /**< The data passed into a function violated the function's usage criteria */
735 
736     FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
737     /**< The chain could not open the target file */
738 
739     FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
740     /**< The chain could not find the FLAC signature at the start of the file */
741 
742     FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
743     /**< The chain tried to write to a file that was not writable */
744 
745     FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
746     /**< The chain encountered input that does not conform to the FLAC metadata specification */
747 
748     FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
749     /**< The chain encountered an error while reading the FLAC file */
750 
751     FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
752     /**< The chain encountered an error while seeking in the FLAC file */
753 
754     FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
755     /**< The chain encountered an error while writing the FLAC file */
756 
757     FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
758     /**< The chain encountered an error renaming the FLAC file */
759 
760     FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
761     /**< The chain encountered an error removing the temporary file */
762 
763     FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
764     /**< Memory allocation failed */
765 
766     FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
767     /**< The caller violated an assertion or an unexpected error occurred */
768 
769     FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
770     /**< One or more of the required callbacks was NULL */
771 
772     FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
773     /**< FLAC__metadata_chain_write() was called on a chain read by
774      *   FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
775      *   or
776      *   FLAC__metadata_chain_write_with_callbacks()/FLAC__metadata_chain_write_with_callbacks_and_tempfile()
777      *   was called on a chain read by
778      *   FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
779      *   Matching read/write methods must always be used. */
780 
781     FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
782     /**< FLAC__metadata_chain_write_with_callbacks() was called when the
783      *   chain write requires a tempfile; use
784      *   FLAC__metadata_chain_write_with_callbacks_and_tempfile() instead.
785      *   Or, FLAC__metadata_chain_write_with_callbacks_and_tempfile() was
786      *   called when the chain write does not require a tempfile; use
787      *   FLAC__metadata_chain_write_with_callbacks() instead.
788      *   Always check FLAC__metadata_chain_check_if_tempfile_needed()
789      *   before writing via callbacks. */
790 }
791 
792 /** Maps a FLAC__Metadata_ChainStatus to a C string.
793  *
794  *  Using a FLAC__Metadata_ChainStatus as the index to this array
795  *  will give the string equivalent.  The contents should not be modified.
796  */
797 extern export const char** FLAC__Metadata_ChainStatusString;
798 
799 /*********** FLAC__Metadata_Chain ***********/
800 
801 /** Create a new chain instance.
802  *
803  * \retval FLAC__Metadata_Chain*
804  *    \c NULL if there was an error allocating memory, else the new instance.
805  */
806 FLAC__Metadata_Chain* FLAC__metadata_chain_new();
807 
808 /** Free a chain instance.  Deletes the object pointed to by \a chain.
809  *
810  * \param chain  A pointer to an existing chain.
811  * \assert
812  *    \code chain != NULL \endcode
813  */
814 void FLAC__metadata_chain_delete(FLAC__Metadata_Chain* chain);
815 
816 /** Get the current status of the chain.  Call this after a function
817  *  returns \c false to get the reason for the error.  Also resets the
818  *  status to FLAC__METADATA_CHAIN_STATUS_OK.
819  *
820  * \param chain    A pointer to an existing chain.
821  * \assert
822  *    \code chain != NULL \endcode
823  * \retval FLAC__Metadata_ChainStatus
824  *    The current status of the chain.
825  */
826 FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain* chain);
827 
828 /** Read all metadata from a FLAC file into the chain.
829  *
830  * \param chain    A pointer to an existing chain.
831  * \param filename The path to the FLAC file to read.
832  * \assert
833  *    \code chain != NULL \endcode
834  *    \code filename != NULL \endcode
835  * \retval FLAC__bool
836  *    \c true if a valid list of metadata blocks was read from
837  *    \a filename, else \c false.  On failure, check the status with
838  *    FLAC__metadata_chain_status().
839  */
840 FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain* chain, const char* filename);
841 
842 /** Read all metadata from an Ogg FLAC file into the chain.
843  *
844  * \note Ogg FLAC metadata data writing is not supported yet and
845  * FLAC__metadata_chain_write() will fail.
846  *
847  * \param chain    A pointer to an existing chain.
848  * \param filename The path to the Ogg FLAC file to read.
849  * \assert
850  *    \code chain != NULL \endcode
851  *    \code filename != NULL \endcode
852  * \retval FLAC__bool
853  *    \c true if a valid list of metadata blocks was read from
854  *    \a filename, else \c false.  On failure, check the status with
855  *    FLAC__metadata_chain_status().
856  */
857 FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain* chain, const char* filename);
858 
859 /** Read all metadata from a FLAC stream into the chain via I/O callbacks.
860  *
861  *  The \a handle need only be open for reading, but must be seekable.
862  *  The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb"
863  *  for Windows).
864  *
865  * \param chain    A pointer to an existing chain.
866  * \param handle   The I/O handle of the FLAC stream to read.  The
867  *                 handle will NOT be closed after the metadata is read;
868  *                 that is the duty of the caller.
869  * \param callbacks
870  *                 A set of callbacks to use for I/O.  The mandatory
871  *                 callbacks are \a read, \a seek, and \a tell.
872  * \assert
873  *    \code chain != NULL \endcode
874  * \retval FLAC__bool
875  *    \c true if a valid list of metadata blocks was read from
876  *    \a handle, else \c false.  On failure, check the status with
877  *    FLAC__metadata_chain_status().
878  */
879 FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain* chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
880 
881 /** Read all metadata from an Ogg FLAC stream into the chain via I/O callbacks.
882  *
883  *  The \a handle need only be open for reading, but must be seekable.
884  *  The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb"
885  *  for Windows).
886  *
887  * \note Ogg FLAC metadata data writing is not supported yet and
888  * FLAC__metadata_chain_write() will fail.
889  *
890  * \param chain    A pointer to an existing chain.
891  * \param handle   The I/O handle of the Ogg FLAC stream to read.  The
892  *                 handle will NOT be closed after the metadata is read;
893  *                 that is the duty of the caller.
894  * \param callbacks
895  *                 A set of callbacks to use for I/O.  The mandatory
896  *                 callbacks are \a read, \a seek, and \a tell.
897  * \assert
898  *    \code chain != NULL \endcode
899  * \retval FLAC__bool
900  *    \c true if a valid list of metadata blocks was read from
901  *    \a handle, else \c false.  On failure, check the status with
902  *    FLAC__metadata_chain_status().
903  */
904 FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain* chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
905 
906 /** Checks if writing the given chain would require the use of a
907  *  temporary file, or if it could be written in place.
908  *
909  *  Under certain conditions, padding can be utilized so that writing
910  *  edited metadata back to the FLAC file does not require rewriting the
911  *  entire file.  If rewriting is required, then a temporary workfile is
912  *  required.  When writing metadata using callbacks, you must check
913  *  this function to know whether to call
914  *  FLAC__metadata_chain_write_with_callbacks() or
915  *  FLAC__metadata_chain_write_with_callbacks_and_tempfile().  When
916  *  writing with FLAC__metadata_chain_write(), the temporary file is
917  *  handled internally.
918  *
919  * \param chain    A pointer to an existing chain.
920  * \param use_padding
921  *                 Whether or not padding will be allowed to be used
922  *                 during the write.  The value of \a use_padding given
923  *                 here must match the value later passed to
924  *                 FLAC__metadata_chain_write_with_callbacks() or
925  *                 FLAC__metadata_chain_write_with_callbacks_with_tempfile().
926  * \assert
927  *    \code chain != NULL \endcode
928  * \retval FLAC__bool
929  *    \c true if writing the current chain would require a tempfile, or
930  *    \c false if metadata can be written in place.
931  */
932 FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain* chain, FLAC__bool use_padding);
933 
934 /** Write all metadata out to the FLAC file.  This function tries to be as
935  *  efficient as possible; how the metadata is actually written is shown by
936  *  the following:
937  *
938  *  If the current chain is the same size as the existing metadata, the new
939  *  data is written in place.
940  *
941  *  If the current chain is longer than the existing metadata, and
942  *  \a use_padding is \c true, and the last block is a PADDING block of
943  *  sufficient length, the function will truncate the final padding block
944  *  so that the overall size of the metadata is the same as the existing
945  *  metadata, and then just rewrite the metadata.  Otherwise, if not all of
946  *  the above conditions are met, the entire FLAC file must be rewritten.
947  *  If you want to use padding this way it is a good idea to call
948  *  FLAC__metadata_chain_sort_padding() first so that you have the maximum
949  *  amount of padding to work with, unless you need to preserve ordering
950  *  of the PADDING blocks for some reason.
951  *
952  *  If the current chain is shorter than the existing metadata, and
953  *  \a use_padding is \c true, and the final block is a PADDING block, the padding
954  *  is extended to make the overall size the same as the existing data.  If
955  *  \a use_padding is \c true and the last block is not a PADDING block, a new
956  *  PADDING block is added to the end of the new data to make it the same
957  *  size as the existing data (if possible, see the note to
958  *  FLAC__metadata_simple_iterator_set_block() about the four byte limit)
959  *  and the new data is written in place.  If none of the above apply or
960  *  \a use_padding is \c false, the entire FLAC file is rewritten.
961  *
962  *  If \a preserve_file_stats is \c true, the owner and modification time will
963  *  be preserved even if the FLAC file is written.
964  *
965  *  For this write function to be used, the chain must have been read with
966  *  FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(), not
967  *  FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks().
968  *
969  * \param chain               A pointer to an existing chain.
970  * \param use_padding         See above.
971  * \param preserve_file_stats See above.
972  * \assert
973  *    \code chain != NULL \endcode
974  * \retval FLAC__bool
975  *    \c true if the write succeeded, else \c false.  On failure,
976  *    check the status with FLAC__metadata_chain_status().
977  */
978 FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain* chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
979 
980 /** Write all metadata out to a FLAC stream via callbacks.
981  *
982  *  (See FLAC__metadata_chain_write() for the details on how padding is
983  *  used to write metadata in place if possible.)
984  *
985  *  The \a handle must be open for updating and be seekable.  The
986  *  equivalent minimum stdio fopen() file mode is \c "r+" (or \c "r+b"
987  *  for Windows).
988  *
989  *  For this write function to be used, the chain must have been read with
990  *  FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
991  *  not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
992  *  Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned
993  *  \c false.
994  *
995  * \param chain        A pointer to an existing chain.
996  * \param use_padding  See FLAC__metadata_chain_write()
997  * \param handle       The I/O handle of the FLAC stream to write.  The
998  *                     handle will NOT be closed after the metadata is
999  *                     written; that is the duty of the caller.
1000  * \param callbacks    A set of callbacks to use for I/O.  The mandatory
1001  *                     callbacks are \a write and \a seek.
1002  * \assert
1003  *    \code chain != NULL \endcode
1004  * \retval FLAC__bool
1005  *    \c true if the write succeeded, else \c false.  On failure,
1006  *    check the status with FLAC__metadata_chain_status().
1007  */
1008 FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain* chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
1009 
1010 /** Write all metadata out to a FLAC stream via callbacks.
1011  *
1012  *  (See FLAC__metadata_chain_write() for the details on how padding is
1013  *  used to write metadata in place if possible.)
1014  *
1015  *  This version of the write-with-callbacks function must be used when
1016  *  FLAC__metadata_chain_check_if_tempfile_needed() returns true.  In
1017  *  this function, you must supply an I/O handle corresponding to the
1018  *  FLAC file to edit, and a temporary handle to which the new FLAC
1019  *  file will be written.  It is the caller's job to move this temporary
1020  *  FLAC file on top of the original FLAC file to complete the metadata
1021  *  edit.
1022  *
1023  *  The \a handle must be open for reading and be seekable.  The
1024  *  equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb"
1025  *  for Windows).
1026  *
1027  *  The \a temp_handle must be open for writing.  The
1028  *  equivalent minimum stdio fopen() file mode is \c "w" (or \c "wb"
1029  *  for Windows).  It should be an empty stream, or at least positioned
1030  *  at the start-of-file (in which case it is the caller's duty to
1031  *  truncate it on return).
1032  *
1033  *  For this write function to be used, the chain must have been read with
1034  *  FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
1035  *  not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
1036  *  Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned
1037  *  \c true.
1038  *
1039  * \param chain        A pointer to an existing chain.
1040  * \param use_padding  See FLAC__metadata_chain_write()
1041  * \param handle       The I/O handle of the original FLAC stream to read.
1042  *                     The handle will NOT be closed after the metadata is
1043  *                     written; that is the duty of the caller.
1044  * \param callbacks    A set of callbacks to use for I/O on \a handle.
1045  *                     The mandatory callbacks are \a read, \a seek, and
1046  *                     \a eof.
1047  * \param temp_handle  The I/O handle of the FLAC stream to write.  The
1048  *                     handle will NOT be closed after the metadata is
1049  *                     written; that is the duty of the caller.
1050  * \param temp_callbacks
1051  *                     A set of callbacks to use for I/O on temp_handle.
1052  *                     The only mandatory callback is \a write.
1053  * \assert
1054  *    \code chain != NULL \endcode
1055  * \retval FLAC__bool
1056  *    \c true if the write succeeded, else \c false.  On failure,
1057  *    check the status with FLAC__metadata_chain_status().
1058  */
1059 FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain* chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks);
1060 
1061 /** Merge adjacent PADDING blocks into a single block.
1062  *
1063  * \note This function does not write to the FLAC file, it only
1064  * modifies the chain.
1065  *
1066  * \warning Any iterator on the current chain will become invalid after this
1067  * call.  You should delete the iterator and get a new one.
1068  *
1069  * \param chain               A pointer to an existing chain.
1070  * \assert
1071  *    \code chain != NULL \endcode
1072  */
1073 void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain* chain);
1074 
1075 /** This function will move all PADDING blocks to the end on the metadata,
1076  *  then merge them into a single block.
1077  *
1078  * \note This function does not write to the FLAC file, it only
1079  * modifies the chain.
1080  *
1081  * \warning Any iterator on the current chain will become invalid after this
1082  * call.  You should delete the iterator and get a new one.
1083  *
1084  * \param chain  A pointer to an existing chain.
1085  * \assert
1086  *    \code chain != NULL \endcode
1087  */
1088 void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain* chain);
1089 
1090 
1091 /*********** FLAC__Metadata_Iterator ***********/
1092 
1093 /** Create a new iterator instance.
1094  *
1095  * \retval FLAC__Metadata_Iterator*
1096  *    \c NULL if there was an error allocating memory, else the new instance.
1097  */
1098 FLAC__Metadata_Iterator* FLAC__metadata_iterator_new();
1099 
1100 /** Free an iterator instance.  Deletes the object pointed to by \a iterator.
1101  *
1102  * \param iterator  A pointer to an existing iterator.
1103  * \assert
1104  *    \code iterator != NULL \endcode
1105  */
1106 void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator* iterator);
1107 
1108 /** Initialize the iterator to point to the first metadata block in the
1109  *  given chain.
1110  *
1111  * \param iterator  A pointer to an existing iterator.
1112  * \param chain     A pointer to an existing and initialized (read) chain.
1113  * \assert
1114  *    \code iterator != NULL \endcode
1115  *    \code chain != NULL \endcode
1116  */
1117 void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator* iterator, FLAC__Metadata_Chain* chain);
1118 
1119 /** Moves the iterator forward one metadata block, returning \c false if
1120  *  already at the end.
1121  *
1122  * \param iterator  A pointer to an existing initialized iterator.
1123  * \assert
1124  *    \code iterator != NULL \endcode
1125  *    \a iterator has been successfully initialized with
1126  *    FLAC__metadata_iterator_init()
1127  * \retval FLAC__bool
1128  *    \c false if already at the last metadata block of the chain, else
1129  *    \c true.
1130  */
1131 FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator* iterator);
1132 
1133 /** Moves the iterator backward one metadata block, returning \c false if
1134  *  already at the beginning.
1135  *
1136  * \param iterator  A pointer to an existing initialized iterator.
1137  * \assert
1138  *    \code iterator != NULL \endcode
1139  *    \a iterator has been successfully initialized with
1140  *    FLAC__metadata_iterator_init()
1141  * \retval FLAC__bool
1142  *    \c false if already at the first metadata block of the chain, else
1143  *    \c true.
1144  */
1145 FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator* iterator);
1146 
1147 /** Get the type of the metadata block at the current position.
1148  *
1149  * \param iterator  A pointer to an existing initialized iterator.
1150  * \assert
1151  *    \code iterator != NULL \endcode
1152  *    \a iterator has been successfully initialized with
1153  *    FLAC__metadata_iterator_init()
1154  * \retval FLAC__MetadataType
1155  *    The type of the metadata block at the current iterator position.
1156  */
1157 FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator* iterator);
1158 
1159 /** Get the metadata block at the current position.  You can modify
1160  *  the block in place but must write the chain before the changes
1161  *  are reflected to the FLAC file.  You do not need to call
1162  *  FLAC__metadata_iterator_set_block() to reflect the changes;
1163  *  the pointer returned by FLAC__metadata_iterator_get_block()
1164  *  points directly into the chain.
1165  *
1166  * \warning
1167  * Do not call FLAC__metadata_object_delete() on the returned object;
1168  * to delete a block use FLAC__metadata_iterator_delete_block().
1169  *
1170  * \param iterator  A pointer to an existing initialized iterator.
1171  * \assert
1172  *    \code iterator != NULL \endcode
1173  *    \a iterator has been successfully initialized with
1174  *    FLAC__metadata_iterator_init()
1175  * \retval FLAC__StreamMetadata*
1176  *    The current metadata block.
1177  */
1178 FLAC__StreamMetadata* FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator* iterator);
1179 
1180 /** Set the metadata block at the current position, replacing the existing
1181  *  block.  The new block passed in becomes owned by the chain and it will be
1182  *  deleted when the chain is deleted.
1183  *
1184  * \param iterator  A pointer to an existing initialized iterator.
1185  * \param block     A pointer to a metadata block.
1186  * \assert
1187  *    \code iterator != NULL \endcode
1188  *    \a iterator has been successfully initialized with
1189  *    FLAC__metadata_iterator_init()
1190  *    \code block != NULL \endcode
1191  * \retval FLAC__bool
1192  *    \c false if the conditions in the above description are not met, or
1193  *    a memory allocation error occurs, otherwise \c true.
1194  */
1195 FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator* iterator, FLAC__StreamMetadata* block);
1196 
1197 /** Removes the current block from the chain.  If \a replace_with_padding is
1198  *  \c true, the block will instead be replaced with a padding block of equal
1199  *  size.  You can not delete the STREAMINFO block.  The iterator will be
1200  *  left pointing to the block before the one just "deleted", even if
1201  *  \a replace_with_padding is \c true.
1202  *
1203  * \param iterator              A pointer to an existing initialized iterator.
1204  * \param replace_with_padding  See above.
1205  * \assert
1206  *    \code iterator != NULL \endcode
1207  *    \a iterator has been successfully initialized with
1208  *    FLAC__metadata_iterator_init()
1209  * \retval FLAC__bool
1210  *    \c false if the conditions in the above description are not met,
1211  *    otherwise \c true.
1212  */
1213 FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator* iterator, FLAC__bool replace_with_padding);
1214 
1215 /** Insert a new block before the current block.  You cannot insert a block
1216  *  before the first STREAMINFO block.  You cannot insert a STREAMINFO block
1217  *  as there can be only one, the one that already exists at the head when you
1218  *  read in a chain.  The chain takes ownership of the new block and it will be
1219  *  deleted when the chain is deleted.  The iterator will be left pointing to
1220  *  the new block.
1221  *
1222  * \param iterator  A pointer to an existing initialized iterator.
1223  * \param block     A pointer to a metadata block to insert.
1224  * \assert
1225  *    \code iterator != NULL \endcode
1226  *    \a iterator has been successfully initialized with
1227  *    FLAC__metadata_iterator_init()
1228  * \retval FLAC__bool
1229  *    \c false if the conditions in the above description are not met, or
1230  *    a memory allocation error occurs, otherwise \c true.
1231  */
1232 FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator* iterator, FLAC__StreamMetadata* block);
1233 
1234 /** Insert a new block after the current block.  You cannot insert a STREAMINFO
1235  *  block as there can be only one, the one that already exists at the head when
1236  *  you read in a chain.  The chain takes ownership of the new block and it will
1237  *  be deleted when the chain is deleted.  The iterator will be left pointing to
1238  *  the new block.
1239  *
1240  * \param iterator  A pointer to an existing initialized iterator.
1241  * \param block     A pointer to a metadata block to insert.
1242  * \assert
1243  *    \code iterator != NULL \endcode
1244  *    \a iterator has been successfully initialized with
1245  *    FLAC__metadata_iterator_init()
1246  * \retval FLAC__bool
1247  *    \c false if the conditions in the above description are not met, or
1248  *    a memory allocation error occurs, otherwise \c true.
1249  */
1250 FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator* iterator, FLAC__StreamMetadata* block);
1251 
1252 /* \} */
1253 
1254 
1255 /** \defgroup flac_metadata_object FLAC/metadata.h: metadata object methods
1256  *  \ingroup flac_metadata
1257  *
1258  * \brief
1259  * This module contains methods for manipulating FLAC metadata objects.
1260  *
1261  * Since many are variable length we have to be careful about the memory
1262  * management.  We decree that all pointers to data in the object are
1263  * owned by the object and memory-managed by the object.
1264  *
1265  * Use the FLAC__metadata_object_new() and FLAC__metadata_object_delete()
1266  * functions to create all instances.  When using the
1267  * FLAC__metadata_object_set_*() functions to set pointers to data, set
1268  * \a copy to \c true to have the function make it's own copy of the data, or
1269  * to \c false to give the object ownership of your data.  In the latter case
1270  * your pointer must be freeable by free() and will be free()d when the object
1271  * is FLAC__metadata_object_delete()d.  It is legal to pass a null pointer as
1272  * the data pointer to a FLAC__metadata_object_set_*() function as long as
1273  * the length argument is 0 and the \a copy argument is \c false.
1274  *
1275  * The FLAC__metadata_object_new() and FLAC__metadata_object_clone() function
1276  * will return \c NULL in the case of a memory allocation error, otherwise a new
1277  * object.  The FLAC__metadata_object_set_*() functions return \c false in the
1278  * case of a memory allocation error.
1279  *
1280  * We don't have the convenience of C++ here, so note that the library relies
1281  * on you to keep the types straight.  In other words, if you pass, for
1282  * example, a FLAC__StreamMetadata* that represents a STREAMINFO block to
1283  * FLAC__metadata_object_application_set_data(), you will get an assertion
1284  * failure.
1285  *
1286  * For convenience the FLAC__metadata_object_vorbiscomment_*() functions
1287  * maintain a trailing NUL on each Vorbis comment entry.  This is not counted
1288  * toward the length or stored in the stream, but it can make working with plain
1289  * comments (those that don't contain embedded-NULs in the value) easier.
1290  * Entries passed into these functions have trailing NULs added if missing, and
1291  * returned entries are guaranteed to have a trailing NUL.
1292  *
1293  * The FLAC__metadata_object_vorbiscomment_*() functions that take a Vorbis
1294  * comment entry/name/value will first validate that it complies with the Vorbis
1295  * comment specification and return false if it does not.
1296  *
1297  * There is no need to recalculate the length field on metadata blocks you
1298  * have modified.  They will be calculated automatically before they  are
1299  * written back to a file.
1300  *
1301  * \{
1302  */
1303 
1304 
1305 /** Create a new metadata object instance of the given type.
1306  *
1307  *  The object will be "empty"; i.e. values and data pointers will be \c 0,
1308  *  with the exception of FLAC__METADATA_TYPE_VORBIS_COMMENT, which will have
1309  *  the vendor string set (but zero comments).
1310  *
1311  *  Do not pass in a value greater than or equal to
1312  *  \a FLAC__METADATA_TYPE_UNDEFINED unless you really know what you're
1313  *  doing.
1314  *
1315  * \param type  Type of object to create
1316  * \retval FLAC__StreamMetadata*
1317  *    \c NULL if there was an error allocating memory or the type code is
1318  *    greater than FLAC__MAX_METADATA_TYPE_CODE, else the new instance.
1319  */
1320 FLAC__StreamMetadata* FLAC__metadata_object_new(FLAC__MetadataType type);
1321 
1322 /** Create a copy of an existing metadata object.
1323  *
1324  *  The copy is a "deep" copy, i.e. dynamically allocated data within the
1325  *  object is also copied.  The caller takes ownership of the new block and
1326  *  is responsible for freeing it with FLAC__metadata_object_delete().
1327  *
1328  * \param object  Pointer to object to copy.
1329  * \assert
1330  *    \code object != NULL \endcode
1331  * \retval FLAC__StreamMetadata*
1332  *    \c NULL if there was an error allocating memory, else the new instance.
1333  */
1334 FLAC__StreamMetadata* FLAC__metadata_object_clone(const FLAC__StreamMetadata* object);
1335 
1336 /** Free a metadata object.  Deletes the object pointed to by \a object.
1337  *
1338  *  The delete is a "deep" delete, i.e. dynamically allocated data within the
1339  *  object is also deleted.
1340  *
1341  * \param object  A pointer to an existing object.
1342  * \assert
1343  *    \code object != NULL \endcode
1344  */
1345 void FLAC__metadata_object_delete(FLAC__StreamMetadata* object);
1346 
1347 /** Compares two metadata objects.
1348  *
1349  *  The compare is "deep", i.e. dynamically allocated data within the
1350  *  object is also compared.
1351  *
1352  * \param block1  A pointer to an existing object.
1353  * \param block2  A pointer to an existing object.
1354  * \assert
1355  *    \code block1 != NULL \endcode
1356  *    \code block2 != NULL \endcode
1357  * \retval FLAC__bool
1358  *    \c true if objects are identical, else \c false.
1359  */
1360 FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata* block1, const FLAC__StreamMetadata* block2);
1361 
1362 /** Sets the application data of an APPLICATION block.
1363  *
1364  *  If \a copy is \c true, a copy of the data is stored; otherwise, the object
1365  *  takes ownership of the pointer.  The existing data will be freed if this
1366  *  function is successful, otherwise the original data will remain if \a copy
1367  *  is \c true and malloc() fails.
1368  *
1369  * \note It is safe to pass a const pointer to \a data if \a copy is \c true.
1370  *
1371  * \param object  A pointer to an existing APPLICATION object.
1372  * \param data    A pointer to the data to set.
1373  * \param length  The length of \a data in bytes.
1374  * \param copy    See above.
1375  * \assert
1376  *    \code object != NULL \endcode
1377  *    \code object->type == FLAC__METADATA_TYPE_APPLICATION \endcode
1378  *    \code (data != NULL && length > 0) ||
1379  * (data == NULL && length == 0 && copy == false) \endcode
1380  * \retval FLAC__bool
1381  *    \c false if \a copy is \c true and malloc() fails, else \c true.
1382  */
1383 FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata* object, FLAC__byte* data, uint length, FLAC__bool copy);
1384 
1385 /** Resize the seekpoint array.
1386  *
1387  *  If the size shrinks, elements will truncated; if it grows, new placeholder
1388  *  points will be added to the end.
1389  *
1390  * \param object          A pointer to an existing SEEKTABLE object.
1391  * \param new_num_points  The desired length of the array; may be \c 0.
1392  * \assert
1393  *    \code object != NULL \endcode
1394  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1395  *    \code (object->data.seek_table.points == NULL && object->data.seek_table.num_points == 0) ||
1396  * (object->data.seek_table.points != NULL && object->data.seek_table.num_points > 0) \endcode
1397  * \retval FLAC__bool
1398  *    \c false if memory allocation error, else \c true.
1399  */
1400 FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata* object, uint new_num_points);
1401 
1402 /** Set a seekpoint in a seektable.
1403  *
1404  * \param object     A pointer to an existing SEEKTABLE object.
1405  * \param point_num  Index into seekpoint array to set.
1406  * \param point      The point to set.
1407  * \assert
1408  *    \code object != NULL \endcode
1409  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1410  *    \code object->data.seek_table.num_points > point_num \endcode
1411  */
1412 void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata* object, uint point_num, FLAC__StreamMetadata_SeekPoint point);
1413 
1414 /** Insert a seekpoint into a seektable.
1415  *
1416  * \param object     A pointer to an existing SEEKTABLE object.
1417  * \param point_num  Index into seekpoint array to set.
1418  * \param point      The point to set.
1419  * \assert
1420  *    \code object != NULL \endcode
1421  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1422  *    \code object->data.seek_table.num_points >= point_num \endcode
1423  * \retval FLAC__bool
1424  *    \c false if memory allocation error, else \c true.
1425  */
1426 FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata* object, uint point_num, FLAC__StreamMetadata_SeekPoint point);
1427 
1428 /** Delete a seekpoint from a seektable.
1429  *
1430  * \param object     A pointer to an existing SEEKTABLE object.
1431  * \param point_num  Index into seekpoint array to set.
1432  * \assert
1433  *    \code object != NULL \endcode
1434  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1435  *    \code object->data.seek_table.num_points > point_num \endcode
1436  * \retval FLAC__bool
1437  *    \c false if memory allocation error, else \c true.
1438  */
1439 FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata* object, uint point_num);
1440 
1441 /** Check a seektable to see if it conforms to the FLAC specification.
1442  *  See the format specification for limits on the contents of the
1443  *  seektable.
1444  *
1445  * \param object  A pointer to an existing SEEKTABLE object.
1446  * \assert
1447  *    \code object != NULL \endcode
1448  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1449  * \retval FLAC__bool
1450  *    \c false if seek table is illegal, else \c true.
1451  */
1452 FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata* object);
1453 
1454 /** Append a number of placeholder points to the end of a seek table.
1455  *
1456  * \note
1457  * As with the other ..._seektable_template_... functions, you should
1458  * call FLAC__metadata_object_seektable_template_sort() when finished
1459  * to make the seek table legal.
1460  *
1461  * \param object  A pointer to an existing SEEKTABLE object.
1462  * \param num     The number of placeholder points to append.
1463  * \assert
1464  *    \code object != NULL \endcode
1465  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1466  * \retval FLAC__bool
1467  *    \c false if memory allocation fails, else \c true.
1468  */
1469 FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata* object, uint num);
1470 
1471 /** Append a specific seek point template to the end of a seek table.
1472  *
1473  * \note
1474  * As with the other ..._seektable_template_... functions, you should
1475  * call FLAC__metadata_object_seektable_template_sort() when finished
1476  * to make the seek table legal.
1477  *
1478  * \param object  A pointer to an existing SEEKTABLE object.
1479  * \param sample_number  The sample number of the seek point template.
1480  * \assert
1481  *    \code object != NULL \endcode
1482  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1483  * \retval FLAC__bool
1484  *    \c false if memory allocation fails, else \c true.
1485  */
1486 FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata* object, FLAC__uint64 sample_number);
1487 
1488 /** Append specific seek point templates to the end of a seek table.
1489  *
1490  * \note
1491  * As with the other ..._seektable_template_... functions, you should
1492  * call FLAC__metadata_object_seektable_template_sort() when finished
1493  * to make the seek table legal.
1494  *
1495  * \param object  A pointer to an existing SEEKTABLE object.
1496  * \param sample_numbers  An array of sample numbers for the seek points.
1497  * \param num     The number of seek point templates to append.
1498  * \assert
1499  *    \code object != NULL \endcode
1500  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1501  * \retval FLAC__bool
1502  *    \c false if memory allocation fails, else \c true.
1503  */
1504 FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata* object, FLAC__uint64* sample_numbers, uint num);
1505 
1506 /** Append a set of evenly-spaced seek point templates to the end of a
1507  *  seek table.
1508  *
1509  * \note
1510  * As with the other ..._seektable_template_... functions, you should
1511  * call FLAC__metadata_object_seektable_template_sort() when finished
1512  * to make the seek table legal.
1513  *
1514  * \param object  A pointer to an existing SEEKTABLE object.
1515  * \param num     The number of placeholder points to append.
1516  * \param total_samples  The total number of samples to be encoded;
1517  *                       the seekpoints will be spaced approximately
1518  *                       \a total_samples / \a num samples apart.
1519  * \assert
1520  *    \code object != NULL \endcode
1521  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1522  *    \code total_samples > 0 \endcode
1523  * \retval FLAC__bool
1524  *    \c false if memory allocation fails, else \c true.
1525  */
1526 FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata* object, uint num, FLAC__uint64 total_samples);
1527 
1528 /** Append a set of evenly-spaced seek point templates to the end of a
1529  *  seek table.
1530  *
1531  * \note
1532  * As with the other ..._seektable_template_... functions, you should
1533  * call FLAC__metadata_object_seektable_template_sort() when finished
1534  * to make the seek table legal.
1535  *
1536  * \param object  A pointer to an existing SEEKTABLE object.
1537  * \param samples The number of samples apart to space the placeholder
1538  *                points.  The first point will be at sample \c 0, the
1539  *                second at sample \a samples, then 2*\a samples, and
1540  *                so on.  As long as \a samples and \a total_samples
1541  *                are greater than \c 0, there will always be at least
1542  *                one seekpoint at sample \c 0.
1543  * \param total_samples  The total number of samples to be encoded;
1544  *                       the seekpoints will be spaced
1545  *                       \a samples samples apart.
1546  * \assert
1547  *    \code object != NULL \endcode
1548  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1549  *    \code samples > 0 \endcode
1550  *    \code total_samples > 0 \endcode
1551  * \retval FLAC__bool
1552  *    \c false if memory allocation fails, else \c true.
1553  */
1554 FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata* object, uint samples, FLAC__uint64 total_samples);
1555 
1556 /** Sort a seek table's seek points according to the format specification,
1557  *  removing duplicates.
1558  *
1559  * \param object   A pointer to a seek table to be sorted.
1560  * \param compact  If \c false, behaves like FLAC__format_seektable_sort().
1561  *                 If \c true, duplicates are deleted and the seek table is
1562  *                 shrunk appropriately; the number of placeholder points
1563  *                 present in the seek table will be the same after the call
1564  *                 as before.
1565  * \assert
1566  *    \code object != NULL \endcode
1567  *    \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1568  * \retval FLAC__bool
1569  *    \c false if realloc() fails, else \c true.
1570  */
1571 FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata* object, FLAC__bool compact);
1572 
1573 /** Sets the vendor string in a VORBIS_COMMENT block.
1574  *
1575  *  For convenience, a trailing NUL is added to the entry if it doesn't have
1576  *  one already.
1577  *
1578  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1579  *  takes ownership of the \c entry.entry pointer.
1580  *
1581  *  \note If this function returns \c false, the caller still owns the
1582  *  pointer.
1583  *
1584  * \param object  A pointer to an existing VORBIS_COMMENT object.
1585  * \param entry   The entry to set the vendor string to.
1586  * \param copy    See above.
1587  * \assert
1588  *    \code object != NULL \endcode
1589  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1590  *    \code (entry.entry != NULL && entry.length > 0) ||
1591  * (entry.entry == NULL && entry.length == 0) \endcode
1592  * \retval FLAC__bool
1593  *    \c false if memory allocation fails or \a entry does not comply with the
1594  *    Vorbis comment specification, else \c true.
1595  */
1596 FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata* object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1597 
1598 /** Resize the comment array.
1599  *
1600  *  If the size shrinks, elements will truncated; if it grows, new empty
1601  *  fields will be added to the end.
1602  *
1603  * \param object            A pointer to an existing VORBIS_COMMENT object.
1604  * \param new_num_comments  The desired length of the array; may be \c 0.
1605  * \assert
1606  *    \code object != NULL \endcode
1607  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1608  *    \code (object->data.vorbis_comment.comments == NULL && object->data.vorbis_comment.num_comments == 0) ||
1609  * (object->data.vorbis_comment.comments != NULL && object->data.vorbis_comment.num_comments > 0) \endcode
1610  * \retval FLAC__bool
1611  *    \c false if memory allocation fails, else \c true.
1612  */
1613 FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata* object, uint new_num_comments);
1614 
1615 /** Sets a comment in a VORBIS_COMMENT block.
1616  *
1617  *  For convenience, a trailing NUL is added to the entry if it doesn't have
1618  *  one already.
1619  *
1620  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1621  *  takes ownership of the \c entry.entry pointer.
1622  *
1623  *  \note If this function returns \c false, the caller still owns the
1624  *  pointer.
1625  *
1626  * \param object       A pointer to an existing VORBIS_COMMENT object.
1627  * \param comment_num  Index into comment array to set.
1628  * \param entry        The entry to set the comment to.
1629  * \param copy         See above.
1630  * \assert
1631  *    \code object != NULL \endcode
1632  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1633  *    \code comment_num < object->data.vorbis_comment.num_comments \endcode
1634  *    \code (entry.entry != NULL && entry.length > 0) ||
1635  * (entry.entry == NULL && entry.length == 0) \endcode
1636  * \retval FLAC__bool
1637  *    \c false if memory allocation fails or \a entry does not comply with the
1638  *    Vorbis comment specification, else \c true.
1639  */
1640 FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata* object, uint comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1641 
1642 /** Insert a comment in a VORBIS_COMMENT block at the given index.
1643  *
1644  *  For convenience, a trailing NUL is added to the entry if it doesn't have
1645  *  one already.
1646  *
1647  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1648  *  takes ownership of the \c entry.entry pointer.
1649  *
1650  *  \note If this function returns \c false, the caller still owns the
1651  *  pointer.
1652  *
1653  * \param object       A pointer to an existing VORBIS_COMMENT object.
1654  * \param comment_num  The index at which to insert the comment.  The comments
1655  *                     at and after \a comment_num move right one position.
1656  *                     To append a comment to the end, set \a comment_num to
1657  *                     \c object->data.vorbis_comment.num_comments .
1658  * \param entry        The comment to insert.
1659  * \param copy         See above.
1660  * \assert
1661  *    \code object != NULL \endcode
1662  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1663  *    \code object->data.vorbis_comment.num_comments >= comment_num \endcode
1664  *    \code (entry.entry != NULL && entry.length > 0) ||
1665  * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode
1666  * \retval FLAC__bool
1667  *    \c false if memory allocation fails or \a entry does not comply with the
1668  *    Vorbis comment specification, else \c true.
1669  */
1670 FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata* object, uint comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1671 
1672 /** Appends a comment to a VORBIS_COMMENT block.
1673  *
1674  *  For convenience, a trailing NUL is added to the entry if it doesn't have
1675  *  one already.
1676  *
1677  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1678  *  takes ownership of the \c entry.entry pointer.
1679  *
1680  *  \note If this function returns \c false, the caller still owns the
1681  *  pointer.
1682  *
1683  * \param object       A pointer to an existing VORBIS_COMMENT object.
1684  * \param entry        The comment to insert.
1685  * \param copy         See above.
1686  * \assert
1687  *    \code object != NULL \endcode
1688  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1689  *    \code (entry.entry != NULL && entry.length > 0) ||
1690  * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode
1691  * \retval FLAC__bool
1692  *    \c false if memory allocation fails or \a entry does not comply with the
1693  *    Vorbis comment specification, else \c true.
1694  */
1695 FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata* object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1696 
1697 /** Replaces comments in a VORBIS_COMMENT block with a new one.
1698  *
1699  *  For convenience, a trailing NUL is added to the entry if it doesn't have
1700  *  one already.
1701  *
1702  *  Depending on the the value of \a all, either all or just the first comment
1703  *  whose field name(s) match the given entry's name will be replaced by the
1704  *  given entry.  If no comments match, \a entry will simply be appended.
1705  *
1706  *  If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1707  *  takes ownership of the \c entry.entry pointer.
1708  *
1709  *  \note If this function returns \c false, the caller still owns the
1710  *  pointer.
1711  *
1712  * \param object       A pointer to an existing VORBIS_COMMENT object.
1713  * \param entry        The comment to insert.
1714  * \param all          If \c true, all comments whose field name matches
1715  *                     \a entry's field name will be removed, and \a entry will
1716  *                     be inserted at the position of the first matching
1717  *                     comment.  If \c false, only the first comment whose
1718  *                     field name matches \a entry's field name will be
1719  *                     replaced with \a entry.
1720  * \param copy         See above.
1721  * \assert
1722  *    \code object != NULL \endcode
1723  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1724  *    \code (entry.entry != NULL && entry.length > 0) ||
1725  * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode
1726  * \retval FLAC__bool
1727  *    \c false if memory allocation fails or \a entry does not comply with the
1728  *    Vorbis comment specification, else \c true.
1729  */
1730 FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata* object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
1731 
1732 /** Delete a comment in a VORBIS_COMMENT block at the given index.
1733  *
1734  * \param object       A pointer to an existing VORBIS_COMMENT object.
1735  * \param comment_num  The index of the comment to delete.
1736  * \assert
1737  *    \code object != NULL \endcode
1738  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1739  *    \code object->data.vorbis_comment.num_comments > comment_num \endcode
1740  * \retval FLAC__bool
1741  *    \c false if realloc() fails, else \c true.
1742  */
1743 FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata* object, uint comment_num);
1744 
1745 /** Creates a Vorbis comment entry from NUL-terminated name and value strings.
1746  *
1747  *  On return, the filled-in \a entry->entry pointer will point to malloc()ed
1748  *  memory and shall be owned by the caller.  For convenience the entry will
1749  *  have a terminating NUL.
1750  *
1751  * \param entry              A pointer to a Vorbis comment entry.  The entry's
1752  *                           \c entry pointer should not point to allocated
1753  *                           memory as it will be overwritten.
1754  * \param field_name         The field name in ASCII, \c NUL terminated.
1755  * \param field_value        The field value in UTF-8, \c NUL terminated.
1756  * \assert
1757  *    \code entry != NULL \endcode
1758  *    \code field_name != NULL \endcode
1759  *    \code field_value != NULL \endcode
1760  * \retval FLAC__bool
1761  *    \c false if malloc() fails, or if \a field_name or \a field_value does
1762  *    not comply with the Vorbis comment specification, else \c true.
1763  */
1764 FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry* entry, const char* field_name, const char* field_value);
1765 
1766 /** Splits a Vorbis comment entry into NUL-terminated name and value strings.
1767  *
1768  *  The returned pointers to name and value will be allocated by malloc()
1769  *  and shall be owned by the caller.
1770  *
1771  * \param entry              An existing Vorbis comment entry.
1772  * \param field_name         The address of where the returned pointer to the
1773  *                           field name will be stored.
1774  * \param field_value        The address of where the returned pointer to the
1775  *                           field value will be stored.
1776  * \assert
1777  *    \code (entry.entry != NULL && entry.length > 0) \endcode
1778  *    \code memchr(entry.entry, '=', entry.length) != NULL \endcode
1779  *    \code field_name != NULL \endcode
1780  *    \code field_value != NULL \endcode
1781  * \retval FLAC__bool
1782  *    \c false if memory allocation fails or \a entry does not comply with the
1783  *    Vorbis comment specification, else \c true.
1784  */
1785 FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char** field_name, char** field_value);
1786 
1787 /** Check if the given Vorbis comment entry's field name matches the given
1788  *  field name.
1789  *
1790  * \param entry              An existing Vorbis comment entry.
1791  * \param field_name         The field name to check.
1792  * \param field_name_length  The length of \a field_name, not including the
1793  *                           terminating \c NUL.
1794  * \assert
1795  *    \code (entry.entry != NULL && entry.length > 0) \endcode
1796  * \retval FLAC__bool
1797  *    \c true if the field names match, else \c false
1798  */
1799 FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char* field_name, uint field_name_length);
1800 
1801 /** Find a Vorbis comment with the given field name.
1802  *
1803  *  The search begins at entry number \a offset; use an offset of 0 to
1804  *  search from the beginning of the comment array.
1805  *
1806  * \param object      A pointer to an existing VORBIS_COMMENT object.
1807  * \param offset      The offset into the comment array from where to start
1808  *                    the search.
1809  * \param field_name  The field name of the comment to find.
1810  * \assert
1811  *    \code object != NULL \endcode
1812  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1813  *    \code field_name != NULL \endcode
1814  * \retval int
1815  *    The offset in the comment array of the first comment whose field
1816  *    name matches \a field_name, or \c -1 if no match was found.
1817  */
1818 int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata* object, uint offset, const char* field_name);
1819 
1820 /** Remove first Vorbis comment matching the given field name.
1821  *
1822  * \param object      A pointer to an existing VORBIS_COMMENT object.
1823  * \param field_name  The field name of comment to delete.
1824  * \assert
1825  *    \code object != NULL \endcode
1826  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1827  * \retval int
1828  *    \c -1 for memory allocation error, \c 0 for no matching entries,
1829  *    \c 1 for one matching entry deleted.
1830  */
1831 int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata* object, const char* field_name);
1832 
1833 /** Remove all Vorbis comments matching the given field name.
1834  *
1835  * \param object      A pointer to an existing VORBIS_COMMENT object.
1836  * \param field_name  The field name of comments to delete.
1837  * \assert
1838  *    \code object != NULL \endcode
1839  *    \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1840  * \retval int
1841  *    \c -1 for memory allocation error, \c 0 for no matching entries,
1842  *    else the number of matching entries deleted.
1843  */
1844 int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata* object, const char* field_name);
1845 
1846 /** Create a new CUESHEET track instance.
1847  *
1848  *  The object will be "empty"; i.e. values and data pointers will be \c 0.
1849  *
1850  * \retval FLAC__StreamMetadata_CueSheet_Track*
1851  *    \c NULL if there was an error allocating memory, else the new instance.
1852  */
1853 FLAC__StreamMetadata_CueSheet_Track* FLAC__metadata_object_cuesheet_track_new();
1854 
1855 /** Create a copy of an existing CUESHEET track object.
1856  *
1857  *  The copy is a "deep" copy, i.e. dynamically allocated data within the
1858  *  object is also copied.  The caller takes ownership of the new object and
1859  *  is responsible for freeing it with
1860  *  FLAC__metadata_object_cuesheet_track_delete().
1861  *
1862  * \param object  Pointer to object to copy.
1863  * \assert
1864  *    \code object != NULL \endcode
1865  * \retval FLAC__StreamMetadata_CueSheet_Track*
1866  *    \c NULL if there was an error allocating memory, else the new instance.
1867  */
1868 FLAC__StreamMetadata_CueSheet_Track* FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track* object);
1869 
1870 /** Delete a CUESHEET track object
1871  *
1872  * \param object       A pointer to an existing CUESHEET track object.
1873  * \assert
1874  *    \code object != NULL \endcode
1875  */
1876 void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track* object);
1877 
1878 /** Resize a track's index point array.
1879  *
1880  *  If the size shrinks, elements will truncated; if it grows, new blank
1881  *  indices will be added to the end.
1882  *
1883  * \param object           A pointer to an existing CUESHEET object.
1884  * \param track_num        The index of the track to modify.  NOTE: this is not
1885  *                         necessarily the same as the track's \a number field.
1886  * \param new_num_indices  The desired length of the array; may be \c 0.
1887  * \assert
1888  *    \code object != NULL \endcode
1889  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1890  *    \code object->data.cue_sheet.num_tracks > track_num \endcode
1891  *    \code (object->data.cue_sheet.tracks[track_num].indices == NULL && object->data.cue_sheet.tracks[track_num].num_indices == 0) ||
1892  * (object->data.cue_sheet.tracks[track_num].indices != NULL && object->data.cue_sheet.tracks[track_num].num_indices > 0) \endcode
1893  * \retval FLAC__bool
1894  *    \c false if memory allocation error, else \c true.
1895  */
1896 FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata* object, uint track_num, uint new_num_indices);
1897 
1898 /** Insert an index point in a CUESHEET track at the given index.
1899  *
1900  * \param object       A pointer to an existing CUESHEET object.
1901  * \param track_num    The index of the track to modify.  NOTE: this is not
1902  *                     necessarily the same as the track's \a number field.
1903  * \param index_num    The index into the track's index array at which to
1904  *                     insert the index point.  NOTE: this is not necessarily
1905  *                     the same as the index point's \a number field.  The
1906  *                     indices at and after \a index_num move right one
1907  *                     position.  To append an index point to the end, set
1908  *                     \a index_num to
1909  *                     \c object->data.cue_sheet.tracks[track_num].num_indices .
1910  * \param index        The index point to insert.
1911  * \assert
1912  *    \code object != NULL \endcode
1913  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1914  *    \code object->data.cue_sheet.num_tracks > track_num \endcode
1915  *    \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode
1916  * \retval FLAC__bool
1917  *    \c false if realloc() fails, else \c true.
1918  */
1919 FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata* object, uint track_num, uint index_num, FLAC__StreamMetadata_CueSheet_Index index);
1920 
1921 /** Insert a blank index point in a CUESHEET track at the given index.
1922  *
1923  *  A blank index point is one in which all field values are zero.
1924  *
1925  * \param object       A pointer to an existing CUESHEET object.
1926  * \param track_num    The index of the track to modify.  NOTE: this is not
1927  *                     necessarily the same as the track's \a number field.
1928  * \param index_num    The index into the track's index array at which to
1929  *                     insert the index point.  NOTE: this is not necessarily
1930  *                     the same as the index point's \a number field.  The
1931  *                     indices at and after \a index_num move right one
1932  *                     position.  To append an index point to the end, set
1933  *                     \a index_num to
1934  *                     \c object->data.cue_sheet.tracks[track_num].num_indices .
1935  * \assert
1936  *    \code object != NULL \endcode
1937  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1938  *    \code object->data.cue_sheet.num_tracks > track_num \endcode
1939  *    \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode
1940  * \retval FLAC__bool
1941  *    \c false if realloc() fails, else \c true.
1942  */
1943 FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata* object, uint track_num, uint index_num);
1944 
1945 /** Delete an index point in a CUESHEET track at the given index.
1946  *
1947  * \param object       A pointer to an existing CUESHEET object.
1948  * \param track_num    The index into the track array of the track to
1949  *                     modify.  NOTE: this is not necessarily the same
1950  *                     as the track's \a number field.
1951  * \param index_num    The index into the track's index array of the index
1952  *                     to delete.  NOTE: this is not necessarily the same
1953  *                     as the index's \a number field.
1954  * \assert
1955  *    \code object != NULL \endcode
1956  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1957  *    \code object->data.cue_sheet.num_tracks > track_num \endcode
1958  *    \code object->data.cue_sheet.tracks[track_num].num_indices > index_num \endcode
1959  * \retval FLAC__bool
1960  *    \c false if realloc() fails, else \c true.
1961  */
1962 FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata* object, uint track_num, uint index_num);
1963 
1964 /** Resize the track array.
1965  *
1966  *  If the size shrinks, elements will truncated; if it grows, new blank
1967  *  tracks will be added to the end.
1968  *
1969  * \param object            A pointer to an existing CUESHEET object.
1970  * \param new_num_tracks    The desired length of the array; may be \c 0.
1971  * \assert
1972  *    \code object != NULL \endcode
1973  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1974  *    \code (object->data.cue_sheet.tracks == NULL && object->data.cue_sheet.num_tracks == 0) ||
1975  * (object->data.cue_sheet.tracks != NULL && object->data.cue_sheet.num_tracks > 0) \endcode
1976  * \retval FLAC__bool
1977  *    \c false if memory allocation error, else \c true.
1978  */
1979 FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata* object, uint new_num_tracks);
1980 
1981 /** Sets a track in a CUESHEET block.
1982  *
1983  *  If \a copy is \c true, a copy of the track is stored; otherwise, the object
1984  *  takes ownership of the \a track pointer.
1985  *
1986  * \param object       A pointer to an existing CUESHEET object.
1987  * \param track_num    Index into track array to set.  NOTE: this is not
1988  *                     necessarily the same as the track's \a number field.
1989  * \param track        The track to set the track to.  You may safely pass in
1990  *                     a const pointer if \a copy is \c true.
1991  * \param copy         See above.
1992  * \assert
1993  *    \code object != NULL \endcode
1994  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1995  *    \code track_num < object->data.cue_sheet.num_tracks \endcode
1996  *    \code (track->indices != NULL && track->num_indices > 0) ||
1997  * (track->indices == NULL && track->num_indices == 0) \endcode
1998  * \retval FLAC__bool
1999  *    \c false if \a copy is \c true and malloc() fails, else \c true.
2000  */
2001 FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata* object, uint track_num, FLAC__StreamMetadata_CueSheet_Track* track, FLAC__bool copy);
2002 
2003 /** Insert a track in a CUESHEET block at the given index.
2004  *
2005  *  If \a copy is \c true, a copy of the track is stored; otherwise, the object
2006  *  takes ownership of the \a track pointer.
2007  *
2008  * \param object       A pointer to an existing CUESHEET object.
2009  * \param track_num    The index at which to insert the track.  NOTE: this
2010  *                     is not necessarily the same as the track's \a number
2011  *                     field.  The tracks at and after \a track_num move right
2012  *                     one position.  To append a track to the end, set
2013  *                     \a track_num to \c object->data.cue_sheet.num_tracks .
2014  * \param track        The track to insert.  You may safely pass in a const
2015  *                     pointer if \a copy is \c true.
2016  * \param copy         See above.
2017  * \assert
2018  *    \code object != NULL \endcode
2019  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
2020  *    \code object->data.cue_sheet.num_tracks >= track_num \endcode
2021  * \retval FLAC__bool
2022  *    \c false if \a copy is \c true and malloc() fails, else \c true.
2023  */
2024 FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata* object, uint track_num, FLAC__StreamMetadata_CueSheet_Track* track, FLAC__bool copy);
2025 
2026 /** Insert a blank track in a CUESHEET block at the given index.
2027  *
2028  *  A blank track is one in which all field values are zero.
2029  *
2030  * \param object       A pointer to an existing CUESHEET object.
2031  * \param track_num    The index at which to insert the track.  NOTE: this
2032  *                     is not necessarily the same as the track's \a number
2033  *                     field.  The tracks at and after \a track_num move right
2034  *                     one position.  To append a track to the end, set
2035  *                     \a track_num to \c object->data.cue_sheet.num_tracks .
2036  * \assert
2037  *    \code object != NULL \endcode
2038  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
2039  *    \code object->data.cue_sheet.num_tracks >= track_num \endcode
2040  * \retval FLAC__bool
2041  *    \c false if \a copy is \c true and malloc() fails, else \c true.
2042  */
2043 FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata* object, uint track_num);
2044 
2045 /** Delete a track in a CUESHEET block at the given index.
2046  *
2047  * \param object       A pointer to an existing CUESHEET object.
2048  * \param track_num    The index into the track array of the track to
2049  *                     delete.  NOTE: this is not necessarily the same
2050  *                     as the track's \a number field.
2051  * \assert
2052  *    \code object != NULL \endcode
2053  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
2054  *    \code object->data.cue_sheet.num_tracks > track_num \endcode
2055  * \retval FLAC__bool
2056  *    \c false if realloc() fails, else \c true.
2057  */
2058 FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata* object, uint track_num);
2059 
2060 /** Check a cue sheet to see if it conforms to the FLAC specification.
2061  *  See the format specification for limits on the contents of the
2062  *  cue sheet.
2063  *
2064  * \param object     A pointer to an existing CUESHEET object.
2065  * \param check_cd_da_subset  If \c true, check CUESHEET against more
2066  *                   stringent requirements for a CD-DA (audio) disc.
2067  * \param violation  Address of a pointer to a string.  If there is a
2068  *                   violation, a pointer to a string explanation of the
2069  *                   violation will be returned here. \a violation may be
2070  *                   \c NULL if you don't need the returned string.  Do not
2071  *                   free the returned string; it will always point to static
2072  *                   data.
2073  * \assert
2074  *    \code object != NULL \endcode
2075  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
2076  * \retval FLAC__bool
2077  *    \c false if cue sheet is illegal, else \c true.
2078  */
2079 FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata* object, FLAC__bool check_cd_da_subset, const char** violation);
2080 
2081 /** Calculate and return the CDDB/freedb ID for a cue sheet.  The function
2082  *  assumes the cue sheet corresponds to a CD; the result is undefined
2083  *  if the cuesheet's is_cd bit is not set.
2084  *
2085  * \param object     A pointer to an existing CUESHEET object.
2086  * \assert
2087  *    \code object != NULL \endcode
2088  *    \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
2089  * \retval FLAC__uint32
2090  *    The uint integer representation of the CDDB/freedb ID
2091  */
2092 FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata* object);
2093 
2094 /** Sets the MIME type of a PICTURE block.
2095  *
2096  *  If \a copy is \c true, a copy of the string is stored; otherwise, the object
2097  *  takes ownership of the pointer.  The existing string will be freed if this
2098  *  function is successful, otherwise the original string will remain if \a copy
2099  *  is \c true and malloc() fails.
2100  *
2101  * \note It is safe to pass a const pointer to \a mime_type if \a copy is \c true.
2102  *
2103  * \param object      A pointer to an existing PICTURE object.
2104  * \param mime_type   A pointer to the MIME type string.  The string must be
2105  *                    ASCII characters 0x20-0x7e, NUL-terminated.  No validation
2106  *                    is done.
2107  * \param copy        See above.
2108  * \assert
2109  *    \code object != NULL \endcode
2110  *    \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode
2111  *    \code (mime_type != NULL) \endcode
2112  * \retval FLAC__bool
2113  *    \c false if \a copy is \c true and malloc() fails, else \c true.
2114  */
2115 FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata* object, char* mime_type, FLAC__bool copy);
2116 
2117 /** Sets the description of a PICTURE block.
2118  *
2119  *  If \a copy is \c true, a copy of the string is stored; otherwise, the object
2120  *  takes ownership of the pointer.  The existing string will be freed if this
2121  *  function is successful, otherwise the original string will remain if \a copy
2122  *  is \c true and malloc() fails.
2123  *
2124  * \note It is safe to pass a const pointer to \a description if \a copy is \c true.
2125  *
2126  * \param object      A pointer to an existing PICTURE object.
2127  * \param description A pointer to the description string.  The string must be
2128  *                    valid UTF-8, NUL-terminated.  No validation is done.
2129  * \param copy        See above.
2130  * \assert
2131  *    \code object != NULL \endcode
2132  *    \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode
2133  *    \code (description != NULL) \endcode
2134  * \retval FLAC__bool
2135  *    \c false if \a copy is \c true and malloc() fails, else \c true.
2136  */
2137 FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata* object, FLAC__byte* description, FLAC__bool copy);
2138 
2139 /** Sets the picture data of a PICTURE block.
2140  *
2141  *  If \a copy is \c true, a copy of the data is stored; otherwise, the object
2142  *  takes ownership of the pointer.  Also sets the \a data_length field of the
2143  *  metadata object to what is passed in as the \a length parameter.  The
2144  *  existing data will be freed if this function is successful, otherwise the
2145  *  original data and data_length will remain if \a copy is \c true and
2146  *  malloc() fails.
2147  *
2148  * \note It is safe to pass a const pointer to \a data if \a copy is \c true.
2149  *
2150  * \param object  A pointer to an existing PICTURE object.
2151  * \param data    A pointer to the data to set.
2152  * \param length  The length of \a data in bytes.
2153  * \param copy    See above.
2154  * \assert
2155  *    \code object != NULL \endcode
2156  *    \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode
2157  *    \code (data != NULL && length > 0) ||
2158  * (data == NULL && length == 0 && copy == false) \endcode
2159  * \retval FLAC__bool
2160  *    \c false if \a copy is \c true and malloc() fails, else \c true.
2161  */
2162 FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata* object, FLAC__byte* data, FLAC__uint32 length, FLAC__bool copy);
2163 
2164 /** Check a PICTURE block to see if it conforms to the FLAC specification.
2165  *  See the format specification for limits on the contents of the
2166  *  PICTURE block.
2167  *
2168  * \param object     A pointer to existing PICTURE block to be checked.
2169  * \param violation  Address of a pointer to a string.  If there is a
2170  *                   violation, a pointer to a string explanation of the
2171  *                   violation will be returned here. \a violation may be
2172  *                   \c NULL if you don't need the returned string.  Do not
2173  *                   free the returned string; it will always point to static
2174  *                   data.
2175  * \assert
2176  *    \code object != NULL \endcode
2177  *    \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode
2178  * \retval FLAC__bool
2179  *    \c false if PICTURE block is illegal, else \c true.
2180  */
2181 FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata* object, const char** violation);