annotate win32-mingw/include/FLAC/metadata.h @ 5:e582a1ccd5fe

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