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