📄 metadata.h
字号:
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001,2002,2003,2004,2005 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FLAC__METADATA_H
#define FLAC__METADATA_H
#include "export.h"
#include "callback.h"
#include "format.h"
/******************************************************************************
(For an example of how all these routines are used, see the source
code for the unit tests in src/test_libFLAC/metadata_*.c, or metaflac
in src/metaflac/)
******************************************************************************/
/** \file include/FLAC/metadata.h
*
* \brief
* This module provides functions for creating and manipulating FLAC
* metadata blocks in memory, and three progressively more powerful
* interfaces for traversing and editing metadata in FLAC files.
*
* See the detailed documentation for each interface in the
* \link flac_metadata metadata \endlink module.
*/
/** \defgroup flac_metadata FLAC/metadata.h: metadata interfaces
* \ingroup flac
*
* \brief
* This module provides functions for creating and manipulating FLAC
* metadata blocks in memory, and three progressively more powerful
* interfaces for traversing and editing metadata in FLAC files.
*
* There are three metadata interfaces of increasing complexity:
*
* Level 0:
* Read-only access to the STREAMINFO and VORBIS_COMMENT blocks.
*
* Level 1:
* Read-write access to all metadata blocks. This level is write-
* efficient in most cases (more on this below), and uses less memory
* than level 2.
*
* Level 2:
* Read-write access to all metadata blocks. This level is write-
* efficient in all cases, but uses more memory since all metadata for
* the whole file is read into memory and manipulated before writing
* out again.
*
* What do we mean by efficient? Since FLAC metadata appears at the
* beginning of the file, when writing metadata back to a FLAC file
* it is possible to grow or shrink the metadata such that the entire
* file must be rewritten. However, if the size remains the same during
* changes or PADDING blocks are utilized, only the metadata needs to be
* overwritten, which is much faster.
*
* Efficient means the whole file is rewritten at most one time, and only
* when necessary. Level 1 is not efficient only in the case that you
* cause more than one metadata block to grow or shrink beyond what can
* be accomodated by padding. In this case you should probably use level
* 2, which allows you to edit all the metadata for a file in memory and
* write it out all at once.
*
* All levels know how to skip over and not disturb an ID3v2 tag at the
* front of the file.
*
* All levels access files via their filenames. In addition, level 2
* has additional alternative read and write functions that take an I/O
* handle and callbacks, for times when access by filename is not possible.
*
* In addition to the three interfaces, this module defines functions for
* creating and manipulating various metadata objects in memory. As we see
* from the Format module, FLAC metadata blocks in memory are very primitive
* structures for storing information in an efficient way. Reading
* information from the structures is easy but creating or modifying them
* directly is more complex. The metadata object routines here facilitate
* this by taking care of the consistency and memory management drudgery.
*
* Unless you will be using the level 1 or 2 interfaces to modify existing
* metadata however, you will not probably not need these.
*
* From a dependency standpoint, none of the encoders or decoders require
* the metadata module. This is so that embedded users can strip out the
* metadata module from libFLAC to reduce the size and complexity.
*/
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup flac_metadata_level0 FLAC/metadata.h: metadata level 0 interface
* \ingroup flac_metadata
*
* \brief
* The level 0 interface consists of individual routines to read the
* STREAMINFO and VORBIS_COMMENT blocks, requiring only a filename.
*
* It skips any ID3v2 tag at the head of the file.
*
* \{
*/
/** Read the STREAMINFO metadata block of the given FLAC file. This function
* will skip any ID3v2 tag at the head of the file.
*
* \param filename The path to the FLAC file to read.
* \param streaminfo A pointer to space for the STREAMINFO block. Since
* FLAC__StreamMetadata is a simple structure with no
* memory allocation involved, you pass the address of
* an existing structure. It need not be initialized.
* \assert
* \code filename != NULL \endcode
* \code streaminfo != NULL \endcode
* \retval FLAC__bool
* \c true if a valid STREAMINFO block was read from \a filename. Returns
* \c false if there was a memory allocation error, a file decoder error,
* or the file contained no STREAMINFO block. (A memory allocation error
* is possible because this function must set up a file decoder.)
*/
FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
/** Read the VORBIS_COMMENT metadata block of the given FLAC file. This
* function will skip any ID3v2 tag at the head of the file.
*
* \param filename The path to the FLAC file to read.
* \param tags The address where the returned pointer will be
* stored. The \a tags object must be deleted by
* the caller using FLAC__metadata_object_delete().
* \assert
* \code filename != NULL \endcode
* \code streaminfo != NULL \endcode
* \retval FLAC__bool
* \c true if a valid VORBIS_COMMENT block was read from \a filename,
* and \a *tags will be set to the address of the tag structure.
* Returns \c false if there was a memory allocation error, a file
* decoder error, or the file contained no VORBIS_COMMENT block, and
* \a *tags will be set to \c NULL.
*/
FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
/* \} */
/** \defgroup flac_metadata_level1 FLAC/metadata.h: metadata level 1 interface
* \ingroup flac_metadata
*
* \brief
* The level 1 interface provides read-write access to FLAC file metadata and
* operates directly on the FLAC file.
*
* The general usage of this interface is:
*
* - Create an iterator using FLAC__metadata_simple_iterator_new()
* - Attach it to a file using FLAC__metadata_simple_iterator_init() and check
* the exit code. Call FLAC__metadata_simple_iterator_is_writable() to
* see if the file is writable, or read-only access is allowed.
* - Use FLAC__metadata_simple_iterator_next() and
* FLAC__metadata_simple_iterator_prev() to move around the blocks.
* This is does not read the actual blocks themselves.
* FLAC__metadata_simple_iterator_next() is relatively fast.
* FLAC__metadata_simple_iterator_prev() is slower since it needs to search
* forward from the front of the file.
* - Use FLAC__metadata_simple_iterator_get_block_type() or
* FLAC__metadata_simple_iterator_get_block() to access the actual data at
* the current iterator position. The returned object is yours to modify
* and free.
* - Use FLAC__metadata_simple_iterator_set_block() to write a modified block
* back. You must have write permission to the original file. Make sure to
* read the whole comment to FLAC__metadata_simple_iterator_set_block()
* below.
* - Use FLAC__metadata_simple_iterator_insert_block_after() to add new blocks.
* Use the object creation functions from
* \link flac_metadata_object here \endlink to generate new objects.
* - Use FLAC__metadata_simple_iterator_delete_block() to remove the block
* currently referred to by the iterator, or replace it with padding.
* - Destroy the iterator with FLAC__metadata_simple_iterator_delete() when
* finished.
*
* \note
* The FLAC file remains open the whole time between
* FLAC__metadata_simple_iterator_init() and
* FLAC__metadata_simple_iterator_delete(), so make sure you are not altering
* the file during this time.
*
* \note
* Do not modify the \a is_last, \a length, or \a type fields of returned
* FLAC__StreamMetadata objects. These are managed automatically.
*
* \note
* If any of the modification functions
* (FLAC__metadata_simple_iterator_set_block(),
* FLAC__metadata_simple_iterator_delete_block(),
* FLAC__metadata_simple_iterator_insert_block_after(), etc.) return \c false,
* you should delete the iterator as it may no longer be valid.
*
* \{
*/
struct FLAC__Metadata_SimpleIterator;
/** The opaque structure definition for the level 1 iterator type.
* See the
* \link flac_metadata_level1 metadata level 1 module \endlink
* for a detailed description.
*/
typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
/** Status type for FLAC__Metadata_SimpleIterator.
*
* The iterator's current status can be obtained by calling FLAC__metadata_simple_iterator_status().
*/
typedef enum {
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
/**< The iterator is in the normal OK state */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
/**< The data passed into a function violated the function's usage criteria */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
/**< The iterator could not open the target file */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
/**< The iterator could not find the FLAC signature at the start of the file */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
/**< The iterator tried to write to a file that was not writable */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
/**< The iterator encountered input that does not conform to the FLAC metadata specification */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
/**< The iterator encountered an error while reading the FLAC file */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
/**< The iterator encountered an error while seeking in the FLAC file */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
/**< The iterator encountered an error while writing the FLAC file */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
/**< The iterator encountered an error renaming the FLAC file */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
/**< The iterator encountered an error removing the temporary file */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
/**< Memory allocation failed */
FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
/**< The caller violated an assertion or an unexpected error occurred */
} FLAC__Metadata_SimpleIteratorStatus;
/** Maps a FLAC__Metadata_SimpleIteratorStatus to a C string.
*
* Using a FLAC__Metadata_SimpleIteratorStatus as the index to this array
* will give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
/** Create a new iterator instance.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -