Chris@34: /* libFLAC - Free Lossless Audio Codec library Chris@34: * Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Josh Coalson Chris@34: * Chris@34: * Redistribution and use in source and binary forms, with or without Chris@34: * modification, are permitted provided that the following conditions Chris@34: * are met: Chris@34: * Chris@34: * - Redistributions of source code must retain the above copyright Chris@34: * notice, this list of conditions and the following disclaimer. Chris@34: * Chris@34: * - Redistributions in binary form must reproduce the above copyright Chris@34: * notice, this list of conditions and the following disclaimer in the Chris@34: * documentation and/or other materials provided with the distribution. Chris@34: * Chris@34: * - Neither the name of the Xiph.org Foundation nor the names of its Chris@34: * contributors may be used to endorse or promote products derived from Chris@34: * this software without specific prior written permission. Chris@34: * Chris@34: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@34: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@34: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@34: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR Chris@34: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@34: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@34: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@34: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@34: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@34: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@34: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@34: */ Chris@34: Chris@34: #ifndef FLAC__METADATA_H Chris@34: #define FLAC__METADATA_H Chris@34: Chris@34: #include /* for off_t */ Chris@34: #include "export.h" Chris@34: #include "callback.h" Chris@34: #include "format.h" Chris@34: Chris@34: /* -------------------------------------------------------------------- Chris@34: (For an example of how all these routines are used, see the source Chris@34: code for the unit tests in src/test_libFLAC/metadata_*.c, or Chris@34: metaflac in src/metaflac/) Chris@34: ------------------------------------------------------------------*/ Chris@34: Chris@34: /** \file include/FLAC/metadata.h Chris@34: * Chris@34: * \brief Chris@34: * This module provides functions for creating and manipulating FLAC Chris@34: * metadata blocks in memory, and three progressively more powerful Chris@34: * interfaces for traversing and editing metadata in FLAC files. Chris@34: * Chris@34: * See the detailed documentation for each interface in the Chris@34: * \link flac_metadata metadata \endlink module. Chris@34: */ Chris@34: Chris@34: /** \defgroup flac_metadata FLAC/metadata.h: metadata interfaces Chris@34: * \ingroup flac Chris@34: * Chris@34: * \brief Chris@34: * This module provides functions for creating and manipulating FLAC Chris@34: * metadata blocks in memory, and three progressively more powerful Chris@34: * interfaces for traversing and editing metadata in native FLAC files. Chris@34: * Note that currently only the Chain interface (level 2) supports Ogg Chris@34: * FLAC files, and it is read-only i.e. no writing back changed Chris@34: * metadata to file. Chris@34: * Chris@34: * There are three metadata interfaces of increasing complexity: Chris@34: * Chris@34: * Level 0: Chris@34: * Read-only access to the STREAMINFO, VORBIS_COMMENT, CUESHEET, and Chris@34: * PICTURE blocks. Chris@34: * Chris@34: * Level 1: Chris@34: * Read-write access to all metadata blocks. This level is write- Chris@34: * efficient in most cases (more on this below), and uses less memory Chris@34: * than level 2. Chris@34: * Chris@34: * Level 2: Chris@34: * Read-write access to all metadata blocks. This level is write- Chris@34: * efficient in all cases, but uses more memory since all metadata for Chris@34: * the whole file is read into memory and manipulated before writing Chris@34: * out again. Chris@34: * Chris@34: * What do we mean by efficient? Since FLAC metadata appears at the Chris@34: * beginning of the file, when writing metadata back to a FLAC file Chris@34: * it is possible to grow or shrink the metadata such that the entire Chris@34: * file must be rewritten. However, if the size remains the same during Chris@34: * changes or PADDING blocks are utilized, only the metadata needs to be Chris@34: * overwritten, which is much faster. Chris@34: * Chris@34: * Efficient means the whole file is rewritten at most one time, and only Chris@34: * when necessary. Level 1 is not efficient only in the case that you Chris@34: * cause more than one metadata block to grow or shrink beyond what can Chris@34: * be accomodated by padding. In this case you should probably use level Chris@34: * 2, which allows you to edit all the metadata for a file in memory and Chris@34: * write it out all at once. Chris@34: * Chris@34: * All levels know how to skip over and not disturb an ID3v2 tag at the Chris@34: * front of the file. Chris@34: * Chris@34: * All levels access files via their filenames. In addition, level 2 Chris@34: * has additional alternative read and write functions that take an I/O Chris@34: * handle and callbacks, for situations where access by filename is not Chris@34: * possible. Chris@34: * Chris@34: * In addition to the three interfaces, this module defines functions for Chris@34: * creating and manipulating various metadata objects in memory. As we see Chris@34: * from the Format module, FLAC metadata blocks in memory are very primitive Chris@34: * structures for storing information in an efficient way. Reading Chris@34: * information from the structures is easy but creating or modifying them Chris@34: * directly is more complex. The metadata object routines here facilitate Chris@34: * this by taking care of the consistency and memory management drudgery. Chris@34: * Chris@34: * Unless you will be using the level 1 or 2 interfaces to modify existing Chris@34: * metadata however, you will not probably not need these. Chris@34: * Chris@34: * From a dependency standpoint, none of the encoders or decoders require Chris@34: * the metadata module. This is so that embedded users can strip out the Chris@34: * metadata module from libFLAC to reduce the size and complexity. Chris@34: */ Chris@34: Chris@34: #ifdef __cplusplus Chris@34: extern "C" { Chris@34: #endif Chris@34: Chris@34: Chris@34: /** \defgroup flac_metadata_level0 FLAC/metadata.h: metadata level 0 interface Chris@34: * \ingroup flac_metadata Chris@34: * Chris@34: * \brief Chris@34: * The level 0 interface consists of individual routines to read the Chris@34: * STREAMINFO, VORBIS_COMMENT, CUESHEET, and PICTURE blocks, requiring Chris@34: * only a filename. Chris@34: * Chris@34: * They try to skip any ID3v2 tag at the head of the file. Chris@34: * Chris@34: * \{ Chris@34: */ Chris@34: Chris@34: /** Read the STREAMINFO metadata block of the given FLAC file. This function Chris@34: * will try to skip any ID3v2 tag at the head of the file. Chris@34: * Chris@34: * \param filename The path to the FLAC file to read. Chris@34: * \param streaminfo A pointer to space for the STREAMINFO block. Since Chris@34: * FLAC__StreamMetadata is a simple structure with no Chris@34: * memory allocation involved, you pass the address of Chris@34: * an existing structure. It need not be initialized. Chris@34: * \assert Chris@34: * \code filename != NULL \endcode Chris@34: * \code streaminfo != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid STREAMINFO block was read from \a filename. Returns Chris@34: * \c false if there was a memory allocation error, a file decoder error, Chris@34: * or the file contained no STREAMINFO block. (A memory allocation error Chris@34: * is possible because this function must set up a file decoder.) Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo); Chris@34: Chris@34: /** Read the VORBIS_COMMENT metadata block of the given FLAC file. This Chris@34: * function will try to skip any ID3v2 tag at the head of the file. Chris@34: * Chris@34: * \param filename The path to the FLAC file to read. Chris@34: * \param tags The address where the returned pointer will be Chris@34: * stored. The \a tags object must be deleted by Chris@34: * the caller using FLAC__metadata_object_delete(). Chris@34: * \assert Chris@34: * \code filename != NULL \endcode Chris@34: * \code tags != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid VORBIS_COMMENT block was read from \a filename, Chris@34: * and \a *tags will be set to the address of the metadata structure. Chris@34: * Returns \c false if there was a memory allocation error, a file Chris@34: * decoder error, or the file contained no VORBIS_COMMENT block, and Chris@34: * \a *tags will be set to \c NULL. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags); Chris@34: Chris@34: /** Read the CUESHEET metadata block of the given FLAC file. This Chris@34: * function will try to skip any ID3v2 tag at the head of the file. Chris@34: * Chris@34: * \param filename The path to the FLAC file to read. Chris@34: * \param cuesheet The address where the returned pointer will be Chris@34: * stored. The \a cuesheet object must be deleted by Chris@34: * the caller using FLAC__metadata_object_delete(). Chris@34: * \assert Chris@34: * \code filename != NULL \endcode Chris@34: * \code cuesheet != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid CUESHEET block was read from \a filename, Chris@34: * and \a *cuesheet will be set to the address of the metadata Chris@34: * structure. Returns \c false if there was a memory allocation Chris@34: * error, a file decoder error, or the file contained no CUESHEET Chris@34: * block, and \a *cuesheet will be set to \c NULL. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet); Chris@34: Chris@34: /** Read a PICTURE metadata block of the given FLAC file. This Chris@34: * function will try to skip any ID3v2 tag at the head of the file. Chris@34: * Since there can be more than one PICTURE block in a file, this Chris@34: * function takes a number of parameters that act as constraints to Chris@34: * the search. The PICTURE block with the largest area matching all Chris@34: * the constraints will be returned, or \a *picture will be set to Chris@34: * \c NULL if there was no such block. Chris@34: * Chris@34: * \param filename The path to the FLAC file to read. Chris@34: * \param picture The address where the returned pointer will be Chris@34: * stored. The \a picture object must be deleted by Chris@34: * the caller using FLAC__metadata_object_delete(). Chris@34: * \param type The desired picture type. Use \c -1 to mean Chris@34: * "any type". Chris@34: * \param mime_type The desired MIME type, e.g. "image/jpeg". The Chris@34: * string will be matched exactly. Use \c NULL to Chris@34: * mean "any MIME type". Chris@34: * \param description The desired description. The string will be Chris@34: * matched exactly. Use \c NULL to mean "any Chris@34: * description". Chris@34: * \param max_width The maximum width in pixels desired. Use Chris@34: * \c (unsigned)(-1) to mean "any width". Chris@34: * \param max_height The maximum height in pixels desired. Use Chris@34: * \c (unsigned)(-1) to mean "any height". Chris@34: * \param max_depth The maximum color depth in bits-per-pixel desired. Chris@34: * Use \c (unsigned)(-1) to mean "any depth". Chris@34: * \param max_colors The maximum number of colors desired. Use Chris@34: * \c (unsigned)(-1) to mean "any number of colors". Chris@34: * \assert Chris@34: * \code filename != NULL \endcode Chris@34: * \code picture != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid PICTURE block was read from \a filename, Chris@34: * and \a *picture will be set to the address of the metadata Chris@34: * structure. Returns \c false if there was a memory allocation Chris@34: * error, a file decoder error, or the file contained no PICTURE Chris@34: * block, and \a *picture will be set to \c NULL. Chris@34: */ Chris@34: 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@34: Chris@34: /* \} */ Chris@34: Chris@34: Chris@34: /** \defgroup flac_metadata_level1 FLAC/metadata.h: metadata level 1 interface Chris@34: * \ingroup flac_metadata Chris@34: * Chris@34: * \brief Chris@34: * The level 1 interface provides read-write access to FLAC file metadata and Chris@34: * operates directly on the FLAC file. Chris@34: * Chris@34: * The general usage of this interface is: Chris@34: * Chris@34: * - Create an iterator using FLAC__metadata_simple_iterator_new() Chris@34: * - Attach it to a file using FLAC__metadata_simple_iterator_init() and check Chris@34: * the exit code. Call FLAC__metadata_simple_iterator_is_writable() to Chris@34: * see if the file is writable, or only read access is allowed. Chris@34: * - Use FLAC__metadata_simple_iterator_next() and Chris@34: * FLAC__metadata_simple_iterator_prev() to traverse the blocks. Chris@34: * This is does not read the actual blocks themselves. Chris@34: * FLAC__metadata_simple_iterator_next() is relatively fast. Chris@34: * FLAC__metadata_simple_iterator_prev() is slower since it needs to search Chris@34: * forward from the front of the file. Chris@34: * - Use FLAC__metadata_simple_iterator_get_block_type() or Chris@34: * FLAC__metadata_simple_iterator_get_block() to access the actual data at Chris@34: * the current iterator position. The returned object is yours to modify Chris@34: * and free. Chris@34: * - Use FLAC__metadata_simple_iterator_set_block() to write a modified block Chris@34: * back. You must have write permission to the original file. Make sure to Chris@34: * read the whole comment to FLAC__metadata_simple_iterator_set_block() Chris@34: * below. Chris@34: * - Use FLAC__metadata_simple_iterator_insert_block_after() to add new blocks. Chris@34: * Use the object creation functions from Chris@34: * \link flac_metadata_object here \endlink to generate new objects. Chris@34: * - Use FLAC__metadata_simple_iterator_delete_block() to remove the block Chris@34: * currently referred to by the iterator, or replace it with padding. Chris@34: * - Destroy the iterator with FLAC__metadata_simple_iterator_delete() when Chris@34: * finished. Chris@34: * Chris@34: * \note Chris@34: * The FLAC file remains open the whole time between Chris@34: * FLAC__metadata_simple_iterator_init() and Chris@34: * FLAC__metadata_simple_iterator_delete(), so make sure you are not altering Chris@34: * the file during this time. Chris@34: * Chris@34: * \note Chris@34: * Do not modify the \a is_last, \a length, or \a type fields of returned Chris@34: * FLAC__StreamMetadata objects. These are managed automatically. Chris@34: * Chris@34: * \note Chris@34: * If any of the modification functions Chris@34: * (FLAC__metadata_simple_iterator_set_block(), Chris@34: * FLAC__metadata_simple_iterator_delete_block(), Chris@34: * FLAC__metadata_simple_iterator_insert_block_after(), etc.) return \c false, Chris@34: * you should delete the iterator as it may no longer be valid. Chris@34: * Chris@34: * \{ Chris@34: */ Chris@34: Chris@34: struct FLAC__Metadata_SimpleIterator; Chris@34: /** The opaque structure definition for the level 1 iterator type. Chris@34: * See the Chris@34: * \link flac_metadata_level1 metadata level 1 module \endlink Chris@34: * for a detailed description. Chris@34: */ Chris@34: typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator; Chris@34: Chris@34: /** Status type for FLAC__Metadata_SimpleIterator. Chris@34: * Chris@34: * The iterator's current status can be obtained by calling FLAC__metadata_simple_iterator_status(). Chris@34: */ Chris@34: typedef enum { Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0, Chris@34: /**< The iterator is in the normal OK state */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT, Chris@34: /**< The data passed into a function violated the function's usage criteria */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE, Chris@34: /**< The iterator could not open the target file */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE, Chris@34: /**< The iterator could not find the FLAC signature at the start of the file */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE, Chris@34: /**< The iterator tried to write to a file that was not writable */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA, Chris@34: /**< The iterator encountered input that does not conform to the FLAC metadata specification */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR, Chris@34: /**< The iterator encountered an error while reading the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR, Chris@34: /**< The iterator encountered an error while seeking in the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR, Chris@34: /**< The iterator encountered an error while writing the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR, Chris@34: /**< The iterator encountered an error renaming the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR, Chris@34: /**< The iterator encountered an error removing the temporary file */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR, Chris@34: /**< Memory allocation failed */ Chris@34: Chris@34: FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR Chris@34: /**< The caller violated an assertion or an unexpected error occurred */ Chris@34: Chris@34: } FLAC__Metadata_SimpleIteratorStatus; Chris@34: Chris@34: /** Maps a FLAC__Metadata_SimpleIteratorStatus to a C string. Chris@34: * Chris@34: * Using a FLAC__Metadata_SimpleIteratorStatus as the index to this array Chris@34: * will give the string equivalent. The contents should not be modified. Chris@34: */ Chris@34: extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[]; Chris@34: Chris@34: Chris@34: /** Create a new iterator instance. Chris@34: * Chris@34: * \retval FLAC__Metadata_SimpleIterator* Chris@34: * \c NULL if there was an error allocating memory, else the new instance. Chris@34: */ Chris@34: FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void); Chris@34: Chris@34: /** Free an iterator instance. Deletes the object pointed to by \a iterator. Chris@34: * Chris@34: * \param iterator A pointer to an existing iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Get the current status of the iterator. Call this after a function Chris@34: * returns \c false to get the reason for the error. Also resets the status Chris@34: * to FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK. Chris@34: * Chris@34: * \param iterator A pointer to an existing iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \retval FLAC__Metadata_SimpleIteratorStatus Chris@34: * The current status of the iterator. Chris@34: */ Chris@34: FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Initialize the iterator to point to the first metadata block in the Chris@34: * given FLAC file. Chris@34: * Chris@34: * \param iterator A pointer to an existing iterator. Chris@34: * \param filename The path to the FLAC file. Chris@34: * \param read_only If \c true, the FLAC file will be opened Chris@34: * in read-only mode; if \c false, the FLAC Chris@34: * file will be opened for edit even if no Chris@34: * edits are performed. Chris@34: * \param preserve_file_stats If \c true, the owner and modification Chris@34: * time will be preserved even if the FLAC Chris@34: * file is written to. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \code filename != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if a memory allocation error occurs, the file can't be Chris@34: * opened, or another error occurs, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Returns \c true if the FLAC file is writable. If \c false, calls to Chris@34: * FLAC__metadata_simple_iterator_set_block() and Chris@34: * FLAC__metadata_simple_iterator_insert_block_after() will fail. Chris@34: * Chris@34: * \param iterator A pointer to an existing iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * See above. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Moves the iterator forward one metadata block, returning \c false if Chris@34: * already at the end. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c false if already at the last metadata block of the chain, else Chris@34: * \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Moves the iterator backward one metadata block, returning \c false if Chris@34: * already at the beginning. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c false if already at the first metadata block of the chain, else Chris@34: * \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Returns a flag telling if the current metadata block is the last. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c true if the current metadata block is the last in the file, Chris@34: * else \c false. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Get the offset of the metadata block at the current position. This Chris@34: * avoids reading the actual block data which can save time for large Chris@34: * blocks. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval off_t Chris@34: * The offset of the metadata block at the current iterator position. Chris@34: * This is the byte offset relative to the beginning of the file of Chris@34: * the current metadata block's header. Chris@34: */ Chris@34: FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Get the type of the metadata block at the current position. This Chris@34: * avoids reading the actual block data which can save time for large Chris@34: * blocks. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval FLAC__MetadataType Chris@34: * The type of the metadata block at the current iterator position. Chris@34: */ Chris@34: FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Get the length of the metadata block at the current position. This Chris@34: * avoids reading the actual block data which can save time for large Chris@34: * blocks. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval unsigned Chris@34: * The length of the metadata block at the current iterator position. Chris@34: * The is same length as that in the Chris@34: * metadata block header, Chris@34: * i.e. the length of the metadata body that follows the header. Chris@34: */ Chris@34: FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Get the application ID of the \c APPLICATION block at the current Chris@34: * position. This avoids reading the actual block data which can save Chris@34: * time for large blocks. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param id A pointer to a buffer of at least \c 4 bytes where Chris@34: * the ID will be stored. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \code id != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c true if the ID was successfully read, else \c false, in which Chris@34: * case you should check FLAC__metadata_simple_iterator_status() to Chris@34: * find out why. If the status is Chris@34: * \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT, then the Chris@34: * current metadata block is not an \c APPLICATION block. Otherwise Chris@34: * if the status is Chris@34: * \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR or Chris@34: * \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR, an I/O error Chris@34: * occurred and the iterator can no longer be used. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id); Chris@34: Chris@34: /** Get the metadata block at the current position. You can modify the Chris@34: * block but must use FLAC__metadata_simple_iterator_set_block() to Chris@34: * write it back to the FLAC file. Chris@34: * Chris@34: * You must call FLAC__metadata_object_delete() on the returned object Chris@34: * when you are finished with it. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval FLAC__StreamMetadata* Chris@34: * The current metadata block, or \c NULL if there was a memory Chris@34: * allocation error. Chris@34: */ Chris@34: FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator); Chris@34: Chris@34: /** Write a block back to the FLAC file. This function tries to be Chris@34: * as efficient as possible; how the block is actually written is Chris@34: * shown by the following: Chris@34: * Chris@34: * Existing block is a STREAMINFO block and the new block is a Chris@34: * STREAMINFO block: the new block is written in place. Make sure Chris@34: * you know what you're doing when changing the values of a Chris@34: * STREAMINFO block. Chris@34: * Chris@34: * Existing block is a STREAMINFO block and the new block is a Chris@34: * not a STREAMINFO block: this is an error since the first block Chris@34: * must be a STREAMINFO block. Returns \c false without altering the Chris@34: * file. Chris@34: * Chris@34: * Existing block is not a STREAMINFO block and the new block is a Chris@34: * STREAMINFO block: this is an error since there may be only one Chris@34: * STREAMINFO block. Returns \c false without altering the file. Chris@34: * Chris@34: * Existing block and new block are the same length: the existing Chris@34: * block will be replaced by the new block, written in place. Chris@34: * Chris@34: * Existing block is longer than new block: if use_padding is \c true, Chris@34: * the existing block will be overwritten in place with the new Chris@34: * block followed by a PADDING block, if possible, to make the total Chris@34: * size the same as the existing block. Remember that a padding Chris@34: * block requires at least four bytes so if the difference in size Chris@34: * between the new block and existing block is less than that, the Chris@34: * entire file will have to be rewritten, using the new block's Chris@34: * exact size. If use_padding is \c false, the entire file will be Chris@34: * rewritten, replacing the existing block by the new block. Chris@34: * Chris@34: * Existing block is shorter than new block: if use_padding is \c true, Chris@34: * the function will try and expand the new block into the following Chris@34: * PADDING block, if it exists and doing so won't shrink the PADDING Chris@34: * block to less than 4 bytes. If there is no following PADDING Chris@34: * block, or it will shrink to less than 4 bytes, or use_padding is Chris@34: * \c false, the entire file is rewritten, replacing the existing block Chris@34: * with the new block. Note that in this case any following PADDING Chris@34: * block is preserved as is. Chris@34: * Chris@34: * After writing the block, the iterator will remain in the same Chris@34: * place, i.e. pointing to the new block. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param block The block to set. Chris@34: * \param use_padding See above. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \code block != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if successful, else \c false. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding); Chris@34: Chris@34: /** This is similar to FLAC__metadata_simple_iterator_set_block() Chris@34: * except that instead of writing over an existing block, it appends Chris@34: * a block after the existing block. \a use_padding is again used to Chris@34: * tell the function to try an expand into following padding in an Chris@34: * attempt to avoid rewriting the entire file. Chris@34: * Chris@34: * This function will fail and return \c false if given a STREAMINFO Chris@34: * block. Chris@34: * Chris@34: * After writing the block, the iterator will be pointing to the Chris@34: * new block. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param block The block to set. Chris@34: * \param use_padding See above. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \code block != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if successful, else \c false. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding); Chris@34: Chris@34: /** Deletes the block at the current position. This will cause the Chris@34: * entire FLAC file to be rewritten, unless \a use_padding is \c true, Chris@34: * in which case the block will be replaced by an equal-sized PADDING Chris@34: * block. The iterator will be left pointing to the block before the Chris@34: * one just deleted. Chris@34: * Chris@34: * You may not delete the STREAMINFO block. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param use_padding See above. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_simple_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c true if successful, else \c false. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding); Chris@34: Chris@34: /* \} */ Chris@34: Chris@34: Chris@34: /** \defgroup flac_metadata_level2 FLAC/metadata.h: metadata level 2 interface Chris@34: * \ingroup flac_metadata Chris@34: * Chris@34: * \brief Chris@34: * The level 2 interface provides read-write access to FLAC file metadata; Chris@34: * all metadata is read into memory, operated on in memory, and then written Chris@34: * to file, which is more efficient than level 1 when editing multiple blocks. Chris@34: * Chris@34: * Currently Ogg FLAC is supported for read only, via Chris@34: * FLAC__metadata_chain_read_ogg() but a subsequent Chris@34: * FLAC__metadata_chain_write() will fail. Chris@34: * Chris@34: * The general usage of this interface is: Chris@34: * Chris@34: * - Create a new chain using FLAC__metadata_chain_new(). A chain is a Chris@34: * linked list of FLAC metadata blocks. Chris@34: * - Read all metadata into the the chain from a FLAC file using Chris@34: * FLAC__metadata_chain_read() or FLAC__metadata_chain_read_ogg() and Chris@34: * check the status. Chris@34: * - Optionally, consolidate the padding using Chris@34: * FLAC__metadata_chain_merge_padding() or Chris@34: * FLAC__metadata_chain_sort_padding(). Chris@34: * - Create a new iterator using FLAC__metadata_iterator_new() Chris@34: * - Initialize the iterator to point to the first element in the chain Chris@34: * using FLAC__metadata_iterator_init() Chris@34: * - Traverse the chain using FLAC__metadata_iterator_next and Chris@34: * FLAC__metadata_iterator_prev(). Chris@34: * - Get a block for reading or modification using Chris@34: * FLAC__metadata_iterator_get_block(). The pointer to the object Chris@34: * inside the chain is returned, so the block is yours to modify. Chris@34: * Changes will be reflected in the FLAC file when you write the Chris@34: * chain. You can also add and delete blocks (see functions below). Chris@34: * - When done, write out the chain using FLAC__metadata_chain_write(). Chris@34: * Make sure to read the whole comment to the function below. Chris@34: * - Delete the chain using FLAC__metadata_chain_delete(). Chris@34: * Chris@34: * \note Chris@34: * Even though the FLAC file is not open while the chain is being Chris@34: * manipulated, you must not alter the file externally during Chris@34: * this time. The chain assumes the FLAC file will not change Chris@34: * between the time of FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg() Chris@34: * and FLAC__metadata_chain_write(). Chris@34: * Chris@34: * \note Chris@34: * Do not modify the is_last, length, or type fields of returned Chris@34: * FLAC__StreamMetadata objects. These are managed automatically. Chris@34: * Chris@34: * \note Chris@34: * The metadata objects returned by FLAC__metadata_iterator_get_block() Chris@34: * are owned by the chain; do not FLAC__metadata_object_delete() them. Chris@34: * In the same way, blocks passed to FLAC__metadata_iterator_set_block() Chris@34: * become owned by the chain and they will be deleted when the chain is Chris@34: * deleted. Chris@34: * Chris@34: * \{ Chris@34: */ Chris@34: Chris@34: struct FLAC__Metadata_Chain; Chris@34: /** The opaque structure definition for the level 2 chain type. Chris@34: */ Chris@34: typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain; Chris@34: Chris@34: struct FLAC__Metadata_Iterator; Chris@34: /** The opaque structure definition for the level 2 iterator type. Chris@34: */ Chris@34: typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator; Chris@34: Chris@34: typedef enum { Chris@34: FLAC__METADATA_CHAIN_STATUS_OK = 0, Chris@34: /**< The chain is in the normal OK state */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT, Chris@34: /**< The data passed into a function violated the function's usage criteria */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE, Chris@34: /**< The chain could not open the target file */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE, Chris@34: /**< The chain could not find the FLAC signature at the start of the file */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE, Chris@34: /**< The chain tried to write to a file that was not writable */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_BAD_METADATA, Chris@34: /**< The chain encountered input that does not conform to the FLAC metadata specification */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_READ_ERROR, Chris@34: /**< The chain encountered an error while reading the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR, Chris@34: /**< The chain encountered an error while seeking in the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR, Chris@34: /**< The chain encountered an error while writing the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR, Chris@34: /**< The chain encountered an error renaming the FLAC file */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR, Chris@34: /**< The chain encountered an error removing the temporary file */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR, Chris@34: /**< Memory allocation failed */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR, Chris@34: /**< The caller violated an assertion or an unexpected error occurred */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS, Chris@34: /**< One or more of the required callbacks was NULL */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH, Chris@34: /**< FLAC__metadata_chain_write() was called on a chain read by Chris@34: * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), Chris@34: * or Chris@34: * FLAC__metadata_chain_write_with_callbacks()/FLAC__metadata_chain_write_with_callbacks_and_tempfile() Chris@34: * was called on a chain read by Chris@34: * FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). Chris@34: * Matching read/write methods must always be used. */ Chris@34: Chris@34: FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL Chris@34: /**< FLAC__metadata_chain_write_with_callbacks() was called when the Chris@34: * chain write requires a tempfile; use Chris@34: * FLAC__metadata_chain_write_with_callbacks_and_tempfile() instead. Chris@34: * Or, FLAC__metadata_chain_write_with_callbacks_and_tempfile() was Chris@34: * called when the chain write does not require a tempfile; use Chris@34: * FLAC__metadata_chain_write_with_callbacks() instead. Chris@34: * Always check FLAC__metadata_chain_check_if_tempfile_needed() Chris@34: * before writing via callbacks. */ Chris@34: Chris@34: } FLAC__Metadata_ChainStatus; Chris@34: Chris@34: /** Maps a FLAC__Metadata_ChainStatus to a C string. Chris@34: * Chris@34: * Using a FLAC__Metadata_ChainStatus as the index to this array Chris@34: * will give the string equivalent. The contents should not be modified. Chris@34: */ Chris@34: extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[]; Chris@34: Chris@34: /*********** FLAC__Metadata_Chain ***********/ Chris@34: Chris@34: /** Create a new chain instance. Chris@34: * Chris@34: * \retval FLAC__Metadata_Chain* Chris@34: * \c NULL if there was an error allocating memory, else the new instance. Chris@34: */ Chris@34: FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void); Chris@34: Chris@34: /** Free a chain instance. Deletes the object pointed to by \a chain. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain); Chris@34: Chris@34: /** Get the current status of the chain. Call this after a function Chris@34: * returns \c false to get the reason for the error. Also resets the Chris@34: * status to FLAC__METADATA_CHAIN_STATUS_OK. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \retval FLAC__Metadata_ChainStatus Chris@34: * The current status of the chain. Chris@34: */ Chris@34: FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain); Chris@34: Chris@34: /** Read all metadata from a FLAC file into the chain. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param filename The path to the FLAC file to read. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \code filename != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid list of metadata blocks was read from Chris@34: * \a filename, else \c false. On failure, check the status with Chris@34: * FLAC__metadata_chain_status(). Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename); Chris@34: Chris@34: /** Read all metadata from an Ogg FLAC file into the chain. Chris@34: * Chris@34: * \note Ogg FLAC metadata data writing is not supported yet and Chris@34: * FLAC__metadata_chain_write() will fail. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param filename The path to the Ogg FLAC file to read. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \code filename != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid list of metadata blocks was read from Chris@34: * \a filename, else \c false. On failure, check the status with Chris@34: * FLAC__metadata_chain_status(). Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename); Chris@34: Chris@34: /** Read all metadata from a FLAC stream into the chain via I/O callbacks. Chris@34: * Chris@34: * The \a handle need only be open for reading, but must be seekable. Chris@34: * The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb" Chris@34: * for Windows). Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param handle The I/O handle of the FLAC stream to read. The Chris@34: * handle will NOT be closed after the metadata is read; Chris@34: * that is the duty of the caller. Chris@34: * \param callbacks Chris@34: * A set of callbacks to use for I/O. The mandatory Chris@34: * callbacks are \a read, \a seek, and \a tell. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid list of metadata blocks was read from Chris@34: * \a handle, else \c false. On failure, check the status with Chris@34: * FLAC__metadata_chain_status(). Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks); Chris@34: Chris@34: /** Read all metadata from an Ogg FLAC stream into the chain via I/O callbacks. Chris@34: * Chris@34: * The \a handle need only be open for reading, but must be seekable. Chris@34: * The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb" Chris@34: * for Windows). Chris@34: * Chris@34: * \note Ogg FLAC metadata data writing is not supported yet and Chris@34: * FLAC__metadata_chain_write() will fail. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param handle The I/O handle of the Ogg FLAC stream to read. The Chris@34: * handle will NOT be closed after the metadata is read; Chris@34: * that is the duty of the caller. Chris@34: * \param callbacks Chris@34: * A set of callbacks to use for I/O. The mandatory Chris@34: * callbacks are \a read, \a seek, and \a tell. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if a valid list of metadata blocks was read from Chris@34: * \a handle, else \c false. On failure, check the status with Chris@34: * FLAC__metadata_chain_status(). Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks); Chris@34: Chris@34: /** Checks if writing the given chain would require the use of a Chris@34: * temporary file, or if it could be written in place. Chris@34: * Chris@34: * Under certain conditions, padding can be utilized so that writing Chris@34: * edited metadata back to the FLAC file does not require rewriting the Chris@34: * entire file. If rewriting is required, then a temporary workfile is Chris@34: * required. When writing metadata using callbacks, you must check Chris@34: * this function to know whether to call Chris@34: * FLAC__metadata_chain_write_with_callbacks() or Chris@34: * FLAC__metadata_chain_write_with_callbacks_and_tempfile(). When Chris@34: * writing with FLAC__metadata_chain_write(), the temporary file is Chris@34: * handled internally. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param use_padding Chris@34: * Whether or not padding will be allowed to be used Chris@34: * during the write. The value of \a use_padding given Chris@34: * here must match the value later passed to Chris@34: * FLAC__metadata_chain_write_with_callbacks() or Chris@34: * FLAC__metadata_chain_write_with_callbacks_with_tempfile(). Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if writing the current chain would require a tempfile, or Chris@34: * \c false if metadata can be written in place. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding); Chris@34: Chris@34: /** Write all metadata out to the FLAC file. This function tries to be as Chris@34: * efficient as possible; how the metadata is actually written is shown by Chris@34: * the following: Chris@34: * Chris@34: * If the current chain is the same size as the existing metadata, the new Chris@34: * data is written in place. Chris@34: * Chris@34: * If the current chain is longer than the existing metadata, and Chris@34: * \a use_padding is \c true, and the last block is a PADDING block of Chris@34: * sufficient length, the function will truncate the final padding block Chris@34: * so that the overall size of the metadata is the same as the existing Chris@34: * metadata, and then just rewrite the metadata. Otherwise, if not all of Chris@34: * the above conditions are met, the entire FLAC file must be rewritten. Chris@34: * If you want to use padding this way it is a good idea to call Chris@34: * FLAC__metadata_chain_sort_padding() first so that you have the maximum Chris@34: * amount of padding to work with, unless you need to preserve ordering Chris@34: * of the PADDING blocks for some reason. Chris@34: * Chris@34: * If the current chain is shorter than the existing metadata, and Chris@34: * \a use_padding is \c true, and the final block is a PADDING block, the padding Chris@34: * is extended to make the overall size the same as the existing data. If Chris@34: * \a use_padding is \c true and the last block is not a PADDING block, a new Chris@34: * PADDING block is added to the end of the new data to make it the same Chris@34: * size as the existing data (if possible, see the note to Chris@34: * FLAC__metadata_simple_iterator_set_block() about the four byte limit) Chris@34: * and the new data is written in place. If none of the above apply or Chris@34: * \a use_padding is \c false, the entire FLAC file is rewritten. Chris@34: * Chris@34: * If \a preserve_file_stats is \c true, the owner and modification time will Chris@34: * be preserved even if the FLAC file is written. Chris@34: * Chris@34: * For this write function to be used, the chain must have been read with Chris@34: * FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(), not Chris@34: * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(). Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param use_padding See above. Chris@34: * \param preserve_file_stats See above. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if the write succeeded, else \c false. On failure, Chris@34: * check the status with FLAC__metadata_chain_status(). Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats); Chris@34: Chris@34: /** Write all metadata out to a FLAC stream via callbacks. Chris@34: * Chris@34: * (See FLAC__metadata_chain_write() for the details on how padding is Chris@34: * used to write metadata in place if possible.) Chris@34: * Chris@34: * The \a handle must be open for updating and be seekable. The Chris@34: * equivalent minimum stdio fopen() file mode is \c "r+" (or \c "r+b" Chris@34: * for Windows). Chris@34: * Chris@34: * For this write function to be used, the chain must have been read with Chris@34: * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), Chris@34: * not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). Chris@34: * Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned Chris@34: * \c false. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param use_padding See FLAC__metadata_chain_write() Chris@34: * \param handle The I/O handle of the FLAC stream to write. The Chris@34: * handle will NOT be closed after the metadata is Chris@34: * written; that is the duty of the caller. Chris@34: * \param callbacks A set of callbacks to use for I/O. The mandatory Chris@34: * callbacks are \a write and \a seek. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if the write succeeded, else \c false. On failure, Chris@34: * check the status with FLAC__metadata_chain_status(). Chris@34: */ Chris@34: 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@34: Chris@34: /** Write all metadata out to a FLAC stream via callbacks. Chris@34: * Chris@34: * (See FLAC__metadata_chain_write() for the details on how padding is Chris@34: * used to write metadata in place if possible.) Chris@34: * Chris@34: * This version of the write-with-callbacks function must be used when Chris@34: * FLAC__metadata_chain_check_if_tempfile_needed() returns true. In Chris@34: * this function, you must supply an I/O handle corresponding to the Chris@34: * FLAC file to edit, and a temporary handle to which the new FLAC Chris@34: * file will be written. It is the caller's job to move this temporary Chris@34: * FLAC file on top of the original FLAC file to complete the metadata Chris@34: * edit. Chris@34: * Chris@34: * The \a handle must be open for reading and be seekable. The Chris@34: * equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb" Chris@34: * for Windows). Chris@34: * Chris@34: * The \a temp_handle must be open for writing. The Chris@34: * equivalent minimum stdio fopen() file mode is \c "w" (or \c "wb" Chris@34: * for Windows). It should be an empty stream, or at least positioned Chris@34: * at the start-of-file (in which case it is the caller's duty to Chris@34: * truncate it on return). Chris@34: * Chris@34: * For this write function to be used, the chain must have been read with Chris@34: * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), Chris@34: * not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). Chris@34: * Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned Chris@34: * \c true. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \param use_padding See FLAC__metadata_chain_write() Chris@34: * \param handle The I/O handle of the original FLAC stream to read. Chris@34: * The handle will NOT be closed after the metadata is Chris@34: * written; that is the duty of the caller. Chris@34: * \param callbacks A set of callbacks to use for I/O on \a handle. Chris@34: * The mandatory callbacks are \a read, \a seek, and Chris@34: * \a eof. Chris@34: * \param temp_handle The I/O handle of the FLAC stream to write. The Chris@34: * handle will NOT be closed after the metadata is Chris@34: * written; that is the duty of the caller. Chris@34: * \param temp_callbacks Chris@34: * A set of callbacks to use for I/O on temp_handle. Chris@34: * The only mandatory callback is \a write. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if the write succeeded, else \c false. On failure, Chris@34: * check the status with FLAC__metadata_chain_status(). Chris@34: */ Chris@34: 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@34: Chris@34: /** Merge adjacent PADDING blocks into a single block. Chris@34: * Chris@34: * \note This function does not write to the FLAC file, it only Chris@34: * modifies the chain. Chris@34: * Chris@34: * \warning Any iterator on the current chain will become invalid after this Chris@34: * call. You should delete the iterator and get a new one. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain); Chris@34: Chris@34: /** This function will move all PADDING blocks to the end on the metadata, Chris@34: * then merge them into a single block. Chris@34: * Chris@34: * \note This function does not write to the FLAC file, it only Chris@34: * modifies the chain. Chris@34: * Chris@34: * \warning Any iterator on the current chain will become invalid after this Chris@34: * call. You should delete the iterator and get a new one. Chris@34: * Chris@34: * \param chain A pointer to an existing chain. Chris@34: * \assert Chris@34: * \code chain != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain); Chris@34: Chris@34: Chris@34: /*********** FLAC__Metadata_Iterator ***********/ Chris@34: Chris@34: /** Create a new iterator instance. Chris@34: * Chris@34: * \retval FLAC__Metadata_Iterator* Chris@34: * \c NULL if there was an error allocating memory, else the new instance. Chris@34: */ Chris@34: FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void); Chris@34: Chris@34: /** Free an iterator instance. Deletes the object pointed to by \a iterator. Chris@34: * Chris@34: * \param iterator A pointer to an existing iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator); Chris@34: Chris@34: /** Initialize the iterator to point to the first metadata block in the Chris@34: * given chain. Chris@34: * Chris@34: * \param iterator A pointer to an existing iterator. Chris@34: * \param chain A pointer to an existing and initialized (read) chain. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \code chain != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain); Chris@34: Chris@34: /** Moves the iterator forward one metadata block, returning \c false if Chris@34: * already at the end. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c false if already at the last metadata block of the chain, else Chris@34: * \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator); Chris@34: Chris@34: /** Moves the iterator backward one metadata block, returning \c false if Chris@34: * already at the beginning. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c false if already at the first metadata block of the chain, else Chris@34: * \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator); Chris@34: Chris@34: /** Get the type of the metadata block at the current position. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \retval FLAC__MetadataType Chris@34: * The type of the metadata block at the current iterator position. Chris@34: */ Chris@34: FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator); Chris@34: Chris@34: /** Get the metadata block at the current position. You can modify Chris@34: * the block in place but must write the chain before the changes Chris@34: * are reflected to the FLAC file. You do not need to call Chris@34: * FLAC__metadata_iterator_set_block() to reflect the changes; Chris@34: * the pointer returned by FLAC__metadata_iterator_get_block() Chris@34: * points directly into the chain. Chris@34: * Chris@34: * \warning Chris@34: * Do not call FLAC__metadata_object_delete() on the returned object; Chris@34: * to delete a block use FLAC__metadata_iterator_delete_block(). Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \retval FLAC__StreamMetadata* Chris@34: * The current metadata block. Chris@34: */ Chris@34: FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator); Chris@34: Chris@34: /** Set the metadata block at the current position, replacing the existing Chris@34: * block. The new block passed in becomes owned by the chain and it will be Chris@34: * deleted when the chain is deleted. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param block A pointer to a metadata block. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \code block != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if the conditions in the above description are not met, or Chris@34: * a memory allocation error occurs, otherwise \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block); Chris@34: Chris@34: /** Removes the current block from the chain. If \a replace_with_padding is Chris@34: * \c true, the block will instead be replaced with a padding block of equal Chris@34: * size. You can not delete the STREAMINFO block. The iterator will be Chris@34: * left pointing to the block before the one just "deleted", even if Chris@34: * \a replace_with_padding is \c true. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param replace_with_padding See above. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c false if the conditions in the above description are not met, Chris@34: * otherwise \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding); Chris@34: Chris@34: /** Insert a new block before the current block. You cannot insert a block Chris@34: * before the first STREAMINFO block. You cannot insert a STREAMINFO block Chris@34: * as there can be only one, the one that already exists at the head when you Chris@34: * read in a chain. The chain takes ownership of the new block and it will be Chris@34: * deleted when the chain is deleted. The iterator will be left pointing to Chris@34: * the new block. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param block A pointer to a metadata block to insert. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c false if the conditions in the above description are not met, or Chris@34: * a memory allocation error occurs, otherwise \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block); Chris@34: Chris@34: /** Insert a new block after the current block. You cannot insert a STREAMINFO Chris@34: * block as there can be only one, the one that already exists at the head when Chris@34: * you read in a chain. The chain takes ownership of the new block and it will Chris@34: * be deleted when the chain is deleted. The iterator will be left pointing to Chris@34: * the new block. Chris@34: * Chris@34: * \param iterator A pointer to an existing initialized iterator. Chris@34: * \param block A pointer to a metadata block to insert. Chris@34: * \assert Chris@34: * \code iterator != NULL \endcode Chris@34: * \a iterator has been successfully initialized with Chris@34: * FLAC__metadata_iterator_init() Chris@34: * \retval FLAC__bool Chris@34: * \c false if the conditions in the above description are not met, or Chris@34: * a memory allocation error occurs, otherwise \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block); Chris@34: Chris@34: /* \} */ Chris@34: Chris@34: Chris@34: /** \defgroup flac_metadata_object FLAC/metadata.h: metadata object methods Chris@34: * \ingroup flac_metadata Chris@34: * Chris@34: * \brief Chris@34: * This module contains methods for manipulating FLAC metadata objects. Chris@34: * Chris@34: * Since many are variable length we have to be careful about the memory Chris@34: * management. We decree that all pointers to data in the object are Chris@34: * owned by the object and memory-managed by the object. Chris@34: * Chris@34: * Use the FLAC__metadata_object_new() and FLAC__metadata_object_delete() Chris@34: * functions to create all instances. When using the Chris@34: * FLAC__metadata_object_set_*() functions to set pointers to data, set Chris@34: * \a copy to \c true to have the function make it's own copy of the data, or Chris@34: * to \c false to give the object ownership of your data. In the latter case Chris@34: * your pointer must be freeable by free() and will be free()d when the object Chris@34: * is FLAC__metadata_object_delete()d. It is legal to pass a null pointer as Chris@34: * the data pointer to a FLAC__metadata_object_set_*() function as long as Chris@34: * the length argument is 0 and the \a copy argument is \c false. Chris@34: * Chris@34: * The FLAC__metadata_object_new() and FLAC__metadata_object_clone() function Chris@34: * will return \c NULL in the case of a memory allocation error, otherwise a new Chris@34: * object. The FLAC__metadata_object_set_*() functions return \c false in the Chris@34: * case of a memory allocation error. Chris@34: * Chris@34: * We don't have the convenience of C++ here, so note that the library relies Chris@34: * on you to keep the types straight. In other words, if you pass, for Chris@34: * example, a FLAC__StreamMetadata* that represents a STREAMINFO block to Chris@34: * FLAC__metadata_object_application_set_data(), you will get an assertion Chris@34: * failure. Chris@34: * Chris@34: * For convenience the FLAC__metadata_object_vorbiscomment_*() functions Chris@34: * maintain a trailing NUL on each Vorbis comment entry. This is not counted Chris@34: * toward the length or stored in the stream, but it can make working with plain Chris@34: * comments (those that don't contain embedded-NULs in the value) easier. Chris@34: * Entries passed into these functions have trailing NULs added if missing, and Chris@34: * returned entries are guaranteed to have a trailing NUL. Chris@34: * Chris@34: * The FLAC__metadata_object_vorbiscomment_*() functions that take a Vorbis Chris@34: * comment entry/name/value will first validate that it complies with the Vorbis Chris@34: * comment specification and return false if it does not. Chris@34: * Chris@34: * There is no need to recalculate the length field on metadata blocks you Chris@34: * have modified. They will be calculated automatically before they are Chris@34: * written back to a file. Chris@34: * Chris@34: * \{ Chris@34: */ Chris@34: Chris@34: Chris@34: /** Create a new metadata object instance of the given type. Chris@34: * Chris@34: * The object will be "empty"; i.e. values and data pointers will be \c 0, Chris@34: * with the exception of FLAC__METADATA_TYPE_VORBIS_COMMENT, which will have Chris@34: * the vendor string set (but zero comments). Chris@34: * Chris@34: * Do not pass in a value greater than or equal to Chris@34: * \a FLAC__METADATA_TYPE_UNDEFINED unless you really know what you're Chris@34: * doing. Chris@34: * Chris@34: * \param type Type of object to create Chris@34: * \retval FLAC__StreamMetadata* Chris@34: * \c NULL if there was an error allocating memory or the type code is Chris@34: * greater than FLAC__MAX_METADATA_TYPE_CODE, else the new instance. Chris@34: */ Chris@34: FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type); Chris@34: Chris@34: /** Create a copy of an existing metadata object. Chris@34: * Chris@34: * The copy is a "deep" copy, i.e. dynamically allocated data within the Chris@34: * object is also copied. The caller takes ownership of the new block and Chris@34: * is responsible for freeing it with FLAC__metadata_object_delete(). Chris@34: * Chris@34: * \param object Pointer to object to copy. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \retval FLAC__StreamMetadata* Chris@34: * \c NULL if there was an error allocating memory, else the new instance. Chris@34: */ Chris@34: FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object); Chris@34: Chris@34: /** Free a metadata object. Deletes the object pointed to by \a object. Chris@34: * Chris@34: * The delete is a "deep" delete, i.e. dynamically allocated data within the Chris@34: * object is also deleted. Chris@34: * Chris@34: * \param object A pointer to an existing object. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object); Chris@34: Chris@34: /** Compares two metadata objects. Chris@34: * Chris@34: * The compare is "deep", i.e. dynamically allocated data within the Chris@34: * object is also compared. Chris@34: * Chris@34: * \param block1 A pointer to an existing object. Chris@34: * \param block2 A pointer to an existing object. Chris@34: * \assert Chris@34: * \code block1 != NULL \endcode Chris@34: * \code block2 != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if objects are identical, else \c false. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2); Chris@34: Chris@34: /** Sets the application data of an APPLICATION block. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the data is stored; otherwise, the object Chris@34: * takes ownership of the pointer. The existing data will be freed if this Chris@34: * function is successful, otherwise the original data will remain if \a copy Chris@34: * is \c true and malloc() fails. Chris@34: * Chris@34: * \note It is safe to pass a const pointer to \a data if \a copy is \c true. Chris@34: * Chris@34: * \param object A pointer to an existing APPLICATION object. Chris@34: * \param data A pointer to the data to set. Chris@34: * \param length The length of \a data in bytes. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_APPLICATION \endcode Chris@34: * \code (data != NULL && length > 0) || Chris@34: * (data == NULL && length == 0 && copy == false) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if \a copy is \c true and malloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy); Chris@34: Chris@34: /** Resize the seekpoint array. Chris@34: * Chris@34: * If the size shrinks, elements will truncated; if it grows, new placeholder Chris@34: * points will be added to the end. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param new_num_points The desired length of the array; may be \c 0. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \code (object->data.seek_table.points == NULL && object->data.seek_table.num_points == 0) || Chris@34: * (object->data.seek_table.points != NULL && object->data.seek_table.num_points > 0) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation error, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points); Chris@34: Chris@34: /** Set a seekpoint in a seektable. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param point_num Index into seekpoint array to set. Chris@34: * \param point The point to set. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \code object->data.seek_table.num_points > point_num \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point); Chris@34: Chris@34: /** Insert a seekpoint into a seektable. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param point_num Index into seekpoint array to set. Chris@34: * \param point The point to set. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \code object->data.seek_table.num_points >= point_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation error, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point); Chris@34: Chris@34: /** Delete a seekpoint from a seektable. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param point_num Index into seekpoint array to set. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \code object->data.seek_table.num_points > point_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation error, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num); Chris@34: Chris@34: /** Check a seektable to see if it conforms to the FLAC specification. Chris@34: * See the format specification for limits on the contents of the Chris@34: * seektable. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if seek table is illegal, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object); Chris@34: Chris@34: /** Append a number of placeholder points to the end of a seek table. Chris@34: * Chris@34: * \note Chris@34: * As with the other ..._seektable_template_... functions, you should Chris@34: * call FLAC__metadata_object_seektable_template_sort() when finished Chris@34: * to make the seek table legal. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param num The number of placeholder points to append. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num); Chris@34: Chris@34: /** Append a specific seek point template to the end of a seek table. Chris@34: * Chris@34: * \note Chris@34: * As with the other ..._seektable_template_... functions, you should Chris@34: * call FLAC__metadata_object_seektable_template_sort() when finished Chris@34: * to make the seek table legal. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param sample_number The sample number of the seek point template. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number); Chris@34: Chris@34: /** Append specific seek point templates to the end of a seek table. Chris@34: * Chris@34: * \note Chris@34: * As with the other ..._seektable_template_... functions, you should Chris@34: * call FLAC__metadata_object_seektable_template_sort() when finished Chris@34: * to make the seek table legal. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param sample_numbers An array of sample numbers for the seek points. Chris@34: * \param num The number of seek point templates to append. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num); Chris@34: Chris@34: /** Append a set of evenly-spaced seek point templates to the end of a Chris@34: * seek table. Chris@34: * Chris@34: * \note Chris@34: * As with the other ..._seektable_template_... functions, you should Chris@34: * call FLAC__metadata_object_seektable_template_sort() when finished Chris@34: * to make the seek table legal. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param num The number of placeholder points to append. Chris@34: * \param total_samples The total number of samples to be encoded; Chris@34: * the seekpoints will be spaced approximately Chris@34: * \a total_samples / \a num samples apart. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \code total_samples > 0 \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples); Chris@34: Chris@34: /** Append a set of evenly-spaced seek point templates to the end of a Chris@34: * seek table. Chris@34: * Chris@34: * \note Chris@34: * As with the other ..._seektable_template_... functions, you should Chris@34: * call FLAC__metadata_object_seektable_template_sort() when finished Chris@34: * to make the seek table legal. Chris@34: * Chris@34: * \param object A pointer to an existing SEEKTABLE object. Chris@34: * \param samples The number of samples apart to space the placeholder Chris@34: * points. The first point will be at sample \c 0, the Chris@34: * second at sample \a samples, then 2*\a samples, and Chris@34: * so on. As long as \a samples and \a total_samples Chris@34: * are greater than \c 0, there will always be at least Chris@34: * one seekpoint at sample \c 0. Chris@34: * \param total_samples The total number of samples to be encoded; Chris@34: * the seekpoints will be spaced Chris@34: * \a samples samples apart. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \code samples > 0 \endcode Chris@34: * \code total_samples > 0 \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples); Chris@34: Chris@34: /** Sort a seek table's seek points according to the format specification, Chris@34: * removing duplicates. Chris@34: * Chris@34: * \param object A pointer to a seek table to be sorted. Chris@34: * \param compact If \c false, behaves like FLAC__format_seektable_sort(). Chris@34: * If \c true, duplicates are deleted and the seek table is Chris@34: * shrunk appropriately; the number of placeholder points Chris@34: * present in the seek table will be the same after the call Chris@34: * as before. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if realloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact); Chris@34: Chris@34: /** Sets the vendor string in a VORBIS_COMMENT block. Chris@34: * Chris@34: * For convenience, a trailing NUL is added to the entry if it doesn't have Chris@34: * one already. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the entry is stored; otherwise, the object Chris@34: * takes ownership of the \c entry.entry pointer. Chris@34: * Chris@34: * \note If this function returns \c false, the caller still owns the Chris@34: * pointer. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param entry The entry to set the vendor string to. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code (entry.entry != NULL && entry.length > 0) || Chris@34: * (entry.entry == NULL && entry.length == 0) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails or \a entry does not comply with the Chris@34: * Vorbis comment specification, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy); Chris@34: Chris@34: /** Resize the comment array. Chris@34: * Chris@34: * If the size shrinks, elements will truncated; if it grows, new empty Chris@34: * fields will be added to the end. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param new_num_comments The desired length of the array; may be \c 0. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code (object->data.vorbis_comment.comments == NULL && object->data.vorbis_comment.num_comments == 0) || Chris@34: * (object->data.vorbis_comment.comments != NULL && object->data.vorbis_comment.num_comments > 0) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments); Chris@34: Chris@34: /** Sets a comment in a VORBIS_COMMENT block. Chris@34: * Chris@34: * For convenience, a trailing NUL is added to the entry if it doesn't have Chris@34: * one already. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the entry is stored; otherwise, the object Chris@34: * takes ownership of the \c entry.entry pointer. Chris@34: * Chris@34: * \note If this function returns \c false, the caller still owns the Chris@34: * pointer. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param comment_num Index into comment array to set. Chris@34: * \param entry The entry to set the comment to. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code comment_num < object->data.vorbis_comment.num_comments \endcode Chris@34: * \code (entry.entry != NULL && entry.length > 0) || Chris@34: * (entry.entry == NULL && entry.length == 0) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails or \a entry does not comply with the Chris@34: * Vorbis comment specification, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Insert a comment in a VORBIS_COMMENT block at the given index. Chris@34: * Chris@34: * For convenience, a trailing NUL is added to the entry if it doesn't have Chris@34: * one already. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the entry is stored; otherwise, the object Chris@34: * takes ownership of the \c entry.entry pointer. Chris@34: * Chris@34: * \note If this function returns \c false, the caller still owns the Chris@34: * pointer. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param comment_num The index at which to insert the comment. The comments Chris@34: * at and after \a comment_num move right one position. Chris@34: * To append a comment to the end, set \a comment_num to Chris@34: * \c object->data.vorbis_comment.num_comments . Chris@34: * \param entry The comment to insert. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code object->data.vorbis_comment.num_comments >= comment_num \endcode Chris@34: * \code (entry.entry != NULL && entry.length > 0) || Chris@34: * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails or \a entry does not comply with the Chris@34: * Vorbis comment specification, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Appends a comment to a VORBIS_COMMENT block. Chris@34: * Chris@34: * For convenience, a trailing NUL is added to the entry if it doesn't have Chris@34: * one already. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the entry is stored; otherwise, the object Chris@34: * takes ownership of the \c entry.entry pointer. Chris@34: * Chris@34: * \note If this function returns \c false, the caller still owns the Chris@34: * pointer. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param entry The comment to insert. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code (entry.entry != NULL && entry.length > 0) || Chris@34: * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails or \a entry does not comply with the Chris@34: * Vorbis comment specification, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy); Chris@34: Chris@34: /** Replaces comments in a VORBIS_COMMENT block with a new one. Chris@34: * Chris@34: * For convenience, a trailing NUL is added to the entry if it doesn't have Chris@34: * one already. Chris@34: * Chris@34: * Depending on the the value of \a all, either all or just the first comment Chris@34: * whose field name(s) match the given entry's name will be replaced by the Chris@34: * given entry. If no comments match, \a entry will simply be appended. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the entry is stored; otherwise, the object Chris@34: * takes ownership of the \c entry.entry pointer. Chris@34: * Chris@34: * \note If this function returns \c false, the caller still owns the Chris@34: * pointer. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param entry The comment to insert. Chris@34: * \param all If \c true, all comments whose field name matches Chris@34: * \a entry's field name will be removed, and \a entry will Chris@34: * be inserted at the position of the first matching Chris@34: * comment. If \c false, only the first comment whose Chris@34: * field name matches \a entry's field name will be Chris@34: * replaced with \a entry. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code (entry.entry != NULL && entry.length > 0) || Chris@34: * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails or \a entry does not comply with the Chris@34: * Vorbis comment specification, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Delete a comment in a VORBIS_COMMENT block at the given index. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param comment_num The index of the comment to delete. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code object->data.vorbis_comment.num_comments > comment_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if realloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num); Chris@34: Chris@34: /** Creates a Vorbis comment entry from NUL-terminated name and value strings. Chris@34: * Chris@34: * On return, the filled-in \a entry->entry pointer will point to malloc()ed Chris@34: * memory and shall be owned by the caller. For convenience the entry will Chris@34: * have a terminating NUL. Chris@34: * Chris@34: * \param entry A pointer to a Vorbis comment entry. The entry's Chris@34: * \c entry pointer should not point to allocated Chris@34: * memory as it will be overwritten. Chris@34: * \param field_name The field name in ASCII, \c NUL terminated. Chris@34: * \param field_value The field value in UTF-8, \c NUL terminated. Chris@34: * \assert Chris@34: * \code entry != NULL \endcode Chris@34: * \code field_name != NULL \endcode Chris@34: * \code field_value != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if malloc() fails, or if \a field_name or \a field_value does Chris@34: * not comply with the Vorbis comment specification, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Splits a Vorbis comment entry into NUL-terminated name and value strings. Chris@34: * Chris@34: * The returned pointers to name and value will be allocated by malloc() Chris@34: * and shall be owned by the caller. Chris@34: * Chris@34: * \param entry An existing Vorbis comment entry. Chris@34: * \param field_name The address of where the returned pointer to the Chris@34: * field name will be stored. Chris@34: * \param field_value The address of where the returned pointer to the Chris@34: * field value will be stored. Chris@34: * \assert Chris@34: * \code (entry.entry != NULL && entry.length > 0) \endcode Chris@34: * \code memchr(entry.entry, '=', entry.length) != NULL \endcode Chris@34: * \code field_name != NULL \endcode Chris@34: * \code field_value != NULL \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation fails or \a entry does not comply with the Chris@34: * Vorbis comment specification, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Check if the given Vorbis comment entry's field name matches the given Chris@34: * field name. Chris@34: * Chris@34: * \param entry An existing Vorbis comment entry. Chris@34: * \param field_name The field name to check. Chris@34: * \param field_name_length The length of \a field_name, not including the Chris@34: * terminating \c NUL. Chris@34: * \assert Chris@34: * \code (entry.entry != NULL && entry.length > 0) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c true if the field names match, else \c false Chris@34: */ Chris@34: 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@34: Chris@34: /** Find a Vorbis comment with the given field name. Chris@34: * Chris@34: * The search begins at entry number \a offset; use an offset of 0 to Chris@34: * search from the beginning of the comment array. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param offset The offset into the comment array from where to start Chris@34: * the search. Chris@34: * \param field_name The field name of the comment to find. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \code field_name != NULL \endcode Chris@34: * \retval int Chris@34: * The offset in the comment array of the first comment whose field Chris@34: * name matches \a field_name, or \c -1 if no match was found. Chris@34: */ Chris@34: FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name); Chris@34: Chris@34: /** Remove first Vorbis comment matching the given field name. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param field_name The field name of comment to delete. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \retval int Chris@34: * \c -1 for memory allocation error, \c 0 for no matching entries, Chris@34: * \c 1 for one matching entry deleted. Chris@34: */ Chris@34: FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name); Chris@34: Chris@34: /** Remove all Vorbis comments matching the given field name. Chris@34: * Chris@34: * \param object A pointer to an existing VORBIS_COMMENT object. Chris@34: * \param field_name The field name of comments to delete. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode Chris@34: * \retval int Chris@34: * \c -1 for memory allocation error, \c 0 for no matching entries, Chris@34: * else the number of matching entries deleted. Chris@34: */ Chris@34: FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name); Chris@34: Chris@34: /** Create a new CUESHEET track instance. Chris@34: * Chris@34: * The object will be "empty"; i.e. values and data pointers will be \c 0. Chris@34: * Chris@34: * \retval FLAC__StreamMetadata_CueSheet_Track* Chris@34: * \c NULL if there was an error allocating memory, else the new instance. Chris@34: */ Chris@34: FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void); Chris@34: Chris@34: /** Create a copy of an existing CUESHEET track object. Chris@34: * Chris@34: * The copy is a "deep" copy, i.e. dynamically allocated data within the Chris@34: * object is also copied. The caller takes ownership of the new object and Chris@34: * is responsible for freeing it with Chris@34: * FLAC__metadata_object_cuesheet_track_delete(). Chris@34: * Chris@34: * \param object Pointer to object to copy. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \retval FLAC__StreamMetadata_CueSheet_Track* Chris@34: * \c NULL if there was an error allocating memory, else the new instance. Chris@34: */ Chris@34: FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object); Chris@34: Chris@34: /** Delete a CUESHEET track object Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET track object. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: */ Chris@34: FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object); Chris@34: Chris@34: /** Resize a track's index point array. Chris@34: * Chris@34: * If the size shrinks, elements will truncated; if it grows, new blank Chris@34: * indices will be added to the end. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num The index of the track to modify. NOTE: this is not Chris@34: * necessarily the same as the track's \a number field. Chris@34: * \param new_num_indices The desired length of the array; may be \c 0. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code object->data.cue_sheet.num_tracks > track_num \endcode Chris@34: * \code (object->data.cue_sheet.tracks[track_num].indices == NULL && object->data.cue_sheet.tracks[track_num].num_indices == 0) || Chris@34: * (object->data.cue_sheet.tracks[track_num].indices != NULL && object->data.cue_sheet.tracks[track_num].num_indices > 0) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation error, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices); Chris@34: Chris@34: /** Insert an index point in a CUESHEET track at the given index. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num The index of the track to modify. NOTE: this is not Chris@34: * necessarily the same as the track's \a number field. Chris@34: * \param index_num The index into the track's index array at which to Chris@34: * insert the index point. NOTE: this is not necessarily Chris@34: * the same as the index point's \a number field. The Chris@34: * indices at and after \a index_num move right one Chris@34: * position. To append an index point to the end, set Chris@34: * \a index_num to Chris@34: * \c object->data.cue_sheet.tracks[track_num].num_indices . Chris@34: * \param index The index point to insert. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code object->data.cue_sheet.num_tracks > track_num \endcode Chris@34: * \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if realloc() fails, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Insert a blank index point in a CUESHEET track at the given index. Chris@34: * Chris@34: * A blank index point is one in which all field values are zero. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num The index of the track to modify. NOTE: this is not Chris@34: * necessarily the same as the track's \a number field. Chris@34: * \param index_num The index into the track's index array at which to Chris@34: * insert the index point. NOTE: this is not necessarily Chris@34: * the same as the index point's \a number field. The Chris@34: * indices at and after \a index_num move right one Chris@34: * position. To append an index point to the end, set Chris@34: * \a index_num to Chris@34: * \c object->data.cue_sheet.tracks[track_num].num_indices . Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code object->data.cue_sheet.num_tracks > track_num \endcode Chris@34: * \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if realloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num); Chris@34: Chris@34: /** Delete an index point in a CUESHEET track at the given index. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num The index into the track array of the track to Chris@34: * modify. NOTE: this is not necessarily the same Chris@34: * as the track's \a number field. Chris@34: * \param index_num The index into the track's index array of the index Chris@34: * to delete. NOTE: this is not necessarily the same Chris@34: * as the index's \a number field. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code object->data.cue_sheet.num_tracks > track_num \endcode Chris@34: * \code object->data.cue_sheet.tracks[track_num].num_indices > index_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if realloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num); Chris@34: Chris@34: /** Resize the track array. Chris@34: * Chris@34: * If the size shrinks, elements will truncated; if it grows, new blank Chris@34: * tracks will be added to the end. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param new_num_tracks The desired length of the array; may be \c 0. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code (object->data.cue_sheet.tracks == NULL && object->data.cue_sheet.num_tracks == 0) || Chris@34: * (object->data.cue_sheet.tracks != NULL && object->data.cue_sheet.num_tracks > 0) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if memory allocation error, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks); Chris@34: Chris@34: /** Sets a track in a CUESHEET block. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the track is stored; otherwise, the object Chris@34: * takes ownership of the \a track pointer. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num Index into track array to set. NOTE: this is not Chris@34: * necessarily the same as the track's \a number field. Chris@34: * \param track The track to set the track to. You may safely pass in Chris@34: * a const pointer if \a copy is \c true. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code track_num < object->data.cue_sheet.num_tracks \endcode Chris@34: * \code (track->indices != NULL && track->num_indices > 0) || Chris@34: * (track->indices == NULL && track->num_indices == 0) Chris@34: * \retval FLAC__bool Chris@34: * \c false if \a copy is \c true and malloc() fails, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Insert a track in a CUESHEET block at the given index. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the track is stored; otherwise, the object Chris@34: * takes ownership of the \a track pointer. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num The index at which to insert the track. NOTE: this Chris@34: * is not necessarily the same as the track's \a number Chris@34: * field. The tracks at and after \a track_num move right Chris@34: * one position. To append a track to the end, set Chris@34: * \a track_num to \c object->data.cue_sheet.num_tracks . Chris@34: * \param track The track to insert. You may safely pass in a const Chris@34: * pointer if \a copy is \c true. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code object->data.cue_sheet.num_tracks >= track_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if \a copy is \c true and malloc() fails, else \c true. Chris@34: */ Chris@34: 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@34: Chris@34: /** Insert a blank track in a CUESHEET block at the given index. Chris@34: * Chris@34: * A blank track is one in which all field values are zero. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num The index at which to insert the track. NOTE: this Chris@34: * is not necessarily the same as the track's \a number Chris@34: * field. The tracks at and after \a track_num move right Chris@34: * one position. To append a track to the end, set Chris@34: * \a track_num to \c object->data.cue_sheet.num_tracks . Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code object->data.cue_sheet.num_tracks >= track_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if \a copy is \c true and malloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num); Chris@34: Chris@34: /** Delete a track in a CUESHEET block at the given index. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param track_num The index into the track array of the track to Chris@34: * delete. NOTE: this is not necessarily the same Chris@34: * as the track's \a number field. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \code object->data.cue_sheet.num_tracks > track_num \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if realloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num); Chris@34: Chris@34: /** Check a cue sheet to see if it conforms to the FLAC specification. Chris@34: * See the format specification for limits on the contents of the Chris@34: * cue sheet. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \param check_cd_da_subset If \c true, check CUESHEET against more Chris@34: * stringent requirements for a CD-DA (audio) disc. Chris@34: * \param violation Address of a pointer to a string. If there is a Chris@34: * violation, a pointer to a string explanation of the Chris@34: * violation will be returned here. \a violation may be Chris@34: * \c NULL if you don't need the returned string. Do not Chris@34: * free the returned string; it will always point to static Chris@34: * data. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if cue sheet is illegal, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation); Chris@34: Chris@34: /** Calculate and return the CDDB/freedb ID for a cue sheet. The function Chris@34: * assumes the cue sheet corresponds to a CD; the result is undefined Chris@34: * if the cuesheet's is_cd bit is not set. Chris@34: * Chris@34: * \param object A pointer to an existing CUESHEET object. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode Chris@34: * \retval FLAC__uint32 Chris@34: * The unsigned integer representation of the CDDB/freedb ID Chris@34: */ Chris@34: FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object); Chris@34: Chris@34: /** Sets the MIME type of a PICTURE block. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the string is stored; otherwise, the object Chris@34: * takes ownership of the pointer. The existing string will be freed if this Chris@34: * function is successful, otherwise the original string will remain if \a copy Chris@34: * is \c true and malloc() fails. Chris@34: * Chris@34: * \note It is safe to pass a const pointer to \a mime_type if \a copy is \c true. Chris@34: * Chris@34: * \param object A pointer to an existing PICTURE object. Chris@34: * \param mime_type A pointer to the MIME type string. The string must be Chris@34: * ASCII characters 0x20-0x7e, NUL-terminated. No validation Chris@34: * is done. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode Chris@34: * \code (mime_type != NULL) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if \a copy is \c true and malloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy); Chris@34: Chris@34: /** Sets the description of a PICTURE block. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the string is stored; otherwise, the object Chris@34: * takes ownership of the pointer. The existing string will be freed if this Chris@34: * function is successful, otherwise the original string will remain if \a copy Chris@34: * is \c true and malloc() fails. Chris@34: * Chris@34: * \note It is safe to pass a const pointer to \a description if \a copy is \c true. Chris@34: * Chris@34: * \param object A pointer to an existing PICTURE object. Chris@34: * \param description A pointer to the description string. The string must be Chris@34: * valid UTF-8, NUL-terminated. No validation is done. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode Chris@34: * \code (description != NULL) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if \a copy is \c true and malloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy); Chris@34: Chris@34: /** Sets the picture data of a PICTURE block. Chris@34: * Chris@34: * If \a copy is \c true, a copy of the data is stored; otherwise, the object Chris@34: * takes ownership of the pointer. Also sets the \a data_length field of the Chris@34: * metadata object to what is passed in as the \a length parameter. The Chris@34: * existing data will be freed if this function is successful, otherwise the Chris@34: * original data and data_length will remain if \a copy is \c true and Chris@34: * malloc() fails. Chris@34: * Chris@34: * \note It is safe to pass a const pointer to \a data if \a copy is \c true. Chris@34: * Chris@34: * \param object A pointer to an existing PICTURE object. Chris@34: * \param data A pointer to the data to set. Chris@34: * \param length The length of \a data in bytes. Chris@34: * \param copy See above. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode Chris@34: * \code (data != NULL && length > 0) || Chris@34: * (data == NULL && length == 0 && copy == false) \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if \a copy is \c true and malloc() fails, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy); Chris@34: Chris@34: /** Check a PICTURE block to see if it conforms to the FLAC specification. Chris@34: * See the format specification for limits on the contents of the Chris@34: * PICTURE block. Chris@34: * Chris@34: * \param object A pointer to existing PICTURE block to be checked. Chris@34: * \param violation Address of a pointer to a string. If there is a Chris@34: * violation, a pointer to a string explanation of the Chris@34: * violation will be returned here. \a violation may be Chris@34: * \c NULL if you don't need the returned string. Do not Chris@34: * free the returned string; it will always point to static Chris@34: * data. Chris@34: * \assert Chris@34: * \code object != NULL \endcode Chris@34: * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode Chris@34: * \retval FLAC__bool Chris@34: * \c false if PICTURE block is illegal, else \c true. Chris@34: */ Chris@34: FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation); Chris@34: Chris@34: /* \} */ Chris@34: Chris@34: #ifdef __cplusplus Chris@34: } Chris@34: #endif Chris@34: Chris@34: #endif