FLAC
1.4.3
Free Lossless Audio Codec
|
Modules | |
FLAC/metadata.h: metadata object methods | |
Typedefs | |
typedef struct FLAC__Metadata_Chain | FLAC__Metadata_Chain |
typedef struct FLAC__Metadata_Iterator | FLAC__Metadata_Iterator |
Variables | |
const char *const | FLAC__Metadata_ChainStatusString [] |
The level 2 interface provides read-write access to FLAC file metadata; all metadata is read into memory, operated on in memory, and then written to file, which is more efficient than level 1 when editing multiple blocks.
Currently Ogg FLAC is supported for read only, via FLAC__metadata_chain_read_ogg() but a subsequent FLAC__metadata_chain_write() will fail.
The general usage of this interface is:
typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain |
The opaque structure definition for the level 2 chain type.
typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator |
The opaque structure definition for the level 2 iterator type.
Enumerator | |
---|---|
FLAC__METADATA_CHAIN_STATUS_OK | The chain is in the normal OK state |
FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT | The data passed into a function violated the function's usage criteria |
FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE | The chain could not open the target file |
FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE | The chain could not find the FLAC signature at the start of the file |
FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE | The chain tried to write to a file that was not writable |
FLAC__METADATA_CHAIN_STATUS_BAD_METADATA | The chain encountered input that does not conform to the FLAC metadata specification |
FLAC__METADATA_CHAIN_STATUS_READ_ERROR | The chain encountered an error while reading the FLAC file |
FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR | The chain encountered an error while seeking in the FLAC file |
FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR | The chain encountered an error while writing the FLAC file |
FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR | The chain encountered an error renaming the FLAC file |
FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR | The chain encountered an error removing the temporary file |
FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR | Memory allocation failed |
FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR | The caller violated an assertion or an unexpected error occurred |
FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS | One or more of the required callbacks was NULL |
FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH | FLAC__metadata_chain_write() was called on a chain read by FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), or FLAC__metadata_chain_write_with_callbacks()/FLAC__metadata_chain_write_with_callbacks_and_tempfile() was called on a chain read by FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). Matching read/write methods must always be used. |
FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL | FLAC__metadata_chain_write_with_callbacks() was called when the chain write requires a tempfile; use FLAC__metadata_chain_write_with_callbacks_and_tempfile() instead. Or, FLAC__metadata_chain_write_with_callbacks_and_tempfile() was called when the chain write does not require a tempfile; use FLAC__metadata_chain_write_with_callbacks() instead. Always check FLAC__metadata_chain_check_if_tempfile_needed() before writing via callbacks. |
FLAC__Metadata_Chain* FLAC__metadata_chain_new | ( | void | ) |
Create a new chain instance.
FLAC__Metadata_Chain* | NULL if there was an error allocating memory, else the new instance. |
void FLAC__metadata_chain_delete | ( | FLAC__Metadata_Chain * | chain | ) |
Free a chain instance. Deletes the object pointed to by chain.
chain | A pointer to an existing chain. |
FLAC__Metadata_ChainStatus FLAC__metadata_chain_status | ( | FLAC__Metadata_Chain * | chain | ) |
Get the current status of the chain. Call this after a function returns false
to get the reason for the error. Also resets the status to FLAC__METADATA_CHAIN_STATUS_OK.
chain | A pointer to an existing chain. |
FLAC__Metadata_ChainStatus | The current status of the chain. |
FLAC__bool FLAC__metadata_chain_read | ( | FLAC__Metadata_Chain * | chain, |
const char * | filename | ||
) |
Read all metadata from a FLAC file into the chain.
On Windows, filename must be a UTF-8 encoded filename, which libFLAC internally translates to an appropriate representation to use with _wfopen. On all other systems, filename is passed to fopen without any translation.
chain | A pointer to an existing chain. |
filename | The path to the FLAC file to read. |
FLAC__bool | true if a valid list of metadata blocks was read from filename, else false . On failure, check the status with FLAC__metadata_chain_status(). |
FLAC__bool FLAC__metadata_chain_read_ogg | ( | FLAC__Metadata_Chain * | chain, |
const char * | filename | ||
) |
Read all metadata from an Ogg FLAC file into the chain.
On Windows, filename must be a UTF-8 encoded filename, which libFLAC internally translates to an appropriate representation to use with _wfopen. On all other systems, filename is passed to fopen without any translation.
chain | A pointer to an existing chain. |
filename | The path to the Ogg FLAC file to read. |
FLAC__bool | true if a valid list of metadata blocks was read from filename, else false . On failure, check the status with FLAC__metadata_chain_status(). |
FLAC__bool FLAC__metadata_chain_read_with_callbacks | ( | FLAC__Metadata_Chain * | chain, |
FLAC__IOHandle | handle, | ||
FLAC__IOCallbacks | callbacks | ||
) |
Read all metadata from a FLAC stream into the chain via I/O callbacks.
The handle need only be open for reading, but must be seekable. The equivalent minimum stdio fopen() file mode is "r"
(or "rb"
for Windows).
chain | A pointer to an existing chain. |
handle | The I/O handle of the FLAC stream to read. The handle will NOT be closed after the metadata is read; that is the duty of the caller. |
callbacks | A set of callbacks to use for I/O. The mandatory callbacks are read, seek, and tell. |
FLAC__bool | true if a valid list of metadata blocks was read from handle, else false . On failure, check the status with FLAC__metadata_chain_status(). |
FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks | ( | FLAC__Metadata_Chain * | chain, |
FLAC__IOHandle | handle, | ||
FLAC__IOCallbacks | callbacks | ||
) |
Read all metadata from an Ogg FLAC stream into the chain via I/O callbacks.
The handle need only be open for reading, but must be seekable. The equivalent minimum stdio fopen() file mode is "r"
(or "rb"
for Windows).
chain | A pointer to an existing chain. |
handle | The I/O handle of the Ogg FLAC stream to read. The handle will NOT be closed after the metadata is read; that is the duty of the caller. |
callbacks | A set of callbacks to use for I/O. The mandatory callbacks are read, seek, and tell. |
FLAC__bool | true if a valid list of metadata blocks was read from handle, else false . On failure, check the status with FLAC__metadata_chain_status(). |
FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed | ( | FLAC__Metadata_Chain * | chain, |
FLAC__bool | use_padding | ||
) |
Checks if writing the given chain would require the use of a temporary file, or if it could be written in place.
Under certain conditions, padding can be utilized so that writing edited metadata back to the FLAC file does not require rewriting the entire file. If rewriting is required, then a temporary workfile is required. When writing metadata using callbacks, you must check this function to know whether to call FLAC__metadata_chain_write_with_callbacks() or FLAC__metadata_chain_write_with_callbacks_and_tempfile(). When writing with FLAC__metadata_chain_write(), the temporary file is handled internally.
chain | A pointer to an existing chain. |
use_padding | Whether or not padding will be allowed to be used during the write. The value of use_padding given here must match the value later passed to FLAC__metadata_chain_write_with_callbacks() or FLAC__metadata_chain_write_with_callbacks_with_tempfile(). |
FLAC__bool | true if writing the current chain would require a tempfile, or false if metadata can be written in place. |
FLAC__bool FLAC__metadata_chain_write | ( | FLAC__Metadata_Chain * | chain, |
FLAC__bool | use_padding, | ||
FLAC__bool | preserve_file_stats | ||
) |
Write all metadata out to the FLAC file. This function tries to be as efficient as possible; how the metadata is actually written is shown by the following:
If the current chain is the same size as the existing metadata, the new data is written in place.
If the current chain is longer than the existing metadata, and use_padding is true
, and the last block is a PADDING block of sufficient length, the function will truncate the final padding block so that the overall size of the metadata is the same as the existing metadata, and then just rewrite the metadata. Otherwise, if not all of the above conditions are met, the entire FLAC file must be rewritten. If you want to use padding this way it is a good idea to call FLAC__metadata_chain_sort_padding() first so that you have the maximum amount of padding to work with, unless you need to preserve ordering of the PADDING blocks for some reason.
If the current chain is shorter than the existing metadata, and use_padding is true
, and the final block is a PADDING block, the padding is extended to make the overall size the same as the existing data. If use_padding is true
and the last block is not a PADDING block, a new PADDING block is added to the end of the new data to make it the same size as the existing data (if possible, see the note to FLAC__metadata_simple_iterator_set_block() about the four byte limit) and the new data is written in place. If none of the above apply or use_padding is false
, the entire FLAC file is rewritten.
If preserve_file_stats is true
, the owner and modification time will be preserved even if the FLAC file is written.
For this write function to be used, the chain must have been read with FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(), not FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks().
chain | A pointer to an existing chain. |
use_padding | See above. |
preserve_file_stats | See above. |
FLAC__bool | true if the write succeeded, else false . On failure, check the status with FLAC__metadata_chain_status(). |
FLAC__bool FLAC__metadata_chain_write_with_callbacks | ( | FLAC__Metadata_Chain * | chain, |
FLAC__bool | use_padding, | ||
FLAC__IOHandle | handle, | ||
FLAC__IOCallbacks | callbacks | ||
) |
Write all metadata out to a FLAC stream via callbacks.
(See FLAC__metadata_chain_write() for the details on how padding is used to write metadata in place if possible.)
The handle must be open for updating and be seekable. The equivalent minimum stdio fopen() file mode is "r+"
(or "r+b"
for Windows).
For this write function to be used, the chain must have been read with FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned false
.
chain | A pointer to an existing chain. |
use_padding | See FLAC__metadata_chain_write() |
handle | The I/O handle of the FLAC stream to write. The handle will NOT be closed after the metadata is written; that is the duty of the caller. |
callbacks | A set of callbacks to use for I/O. The mandatory callbacks are write and seek. |
FLAC__bool | true if the write succeeded, else false . On failure, check the status with FLAC__metadata_chain_status(). |
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 | ||
) |
Write all metadata out to a FLAC stream via callbacks.
(See FLAC__metadata_chain_write() for the details on how padding is used to write metadata in place if possible.)
This version of the write-with-callbacks function must be used when FLAC__metadata_chain_check_if_tempfile_needed() returns true. In this function, you must supply an I/O handle corresponding to the FLAC file to edit, and a temporary handle to which the new FLAC file will be written. It is the caller's job to move this temporary FLAC file on top of the original FLAC file to complete the metadata edit.
The handle must be open for reading and be seekable. The equivalent minimum stdio fopen() file mode is "r"
(or "rb"
for Windows).
The temp_handle must be open for writing. The equivalent minimum stdio fopen() file mode is "w"
(or "wb"
for Windows). It should be an empty stream, or at least positioned at the start-of-file (in which case it is the caller's duty to truncate it on return).
For this write function to be used, the chain must have been read with FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned true
.
chain | A pointer to an existing chain. |
use_padding | See FLAC__metadata_chain_write() |
handle | The I/O handle of the original FLAC stream to read. The handle will NOT be closed after the metadata is written; that is the duty of the caller. |
callbacks | A set of callbacks to use for I/O on handle. The mandatory callbacks are read, seek, and eof. |
temp_handle | The I/O handle of the FLAC stream to write. The handle will NOT be closed after the metadata is written; that is the duty of the caller. |
temp_callbacks | A set of callbacks to use for I/O on temp_handle. The only mandatory callback is write. |
FLAC__bool | true if the write succeeded, else false . On failure, check the status with FLAC__metadata_chain_status(). |
void FLAC__metadata_chain_merge_padding | ( | FLAC__Metadata_Chain * | chain | ) |
Merge adjacent PADDING blocks into a single block.
chain | A pointer to an existing chain. |
void FLAC__metadata_chain_sort_padding | ( | FLAC__Metadata_Chain * | chain | ) |
This function will move all PADDING blocks to the end on the metadata, then merge them into a single block.
chain | A pointer to an existing chain. |
FLAC__Metadata_Iterator* FLAC__metadata_iterator_new | ( | void | ) |
Create a new iterator instance.
FLAC__Metadata_Iterator* | NULL if there was an error allocating memory, else the new instance. |
void FLAC__metadata_iterator_delete | ( | FLAC__Metadata_Iterator * | iterator | ) |
Free an iterator instance. Deletes the object pointed to by iterator.
iterator | A pointer to an existing iterator. |
void FLAC__metadata_iterator_init | ( | FLAC__Metadata_Iterator * | iterator, |
FLAC__Metadata_Chain * | chain | ||
) |
Initialize the iterator to point to the first metadata block in the given chain.
iterator | A pointer to an existing iterator. |
chain | A pointer to an existing and initialized (read) chain. |
FLAC__bool FLAC__metadata_iterator_next | ( | FLAC__Metadata_Iterator * | iterator | ) |
Moves the iterator forward one metadata block, returning false
if already at the end.
iterator | A pointer to an existing initialized iterator. |
FLAC__bool | false if already at the last metadata block of the chain, else true . |
FLAC__bool FLAC__metadata_iterator_prev | ( | FLAC__Metadata_Iterator * | iterator | ) |
Moves the iterator backward one metadata block, returning false
if already at the beginning.
iterator | A pointer to an existing initialized iterator. |
FLAC__bool | false if already at the first metadata block of the chain, else true . |
FLAC__MetadataType FLAC__metadata_iterator_get_block_type | ( | const FLAC__Metadata_Iterator * | iterator | ) |
Get the type of the metadata block at the current position.
iterator | A pointer to an existing initialized iterator. |
FLAC__MetadataType | The type of the metadata block at the current iterator position. |
FLAC__StreamMetadata* FLAC__metadata_iterator_get_block | ( | FLAC__Metadata_Iterator * | iterator | ) |
Get the metadata block at the current position. You can modify the block in place but must write the chain before the changes are reflected to the FLAC file. You do not need to call FLAC__metadata_iterator_set_block() to reflect the changes; the pointer returned by FLAC__metadata_iterator_get_block() points directly into the chain.
iterator | A pointer to an existing initialized iterator. |
FLAC__StreamMetadata* | The current metadata block. |
FLAC__bool FLAC__metadata_iterator_set_block | ( | FLAC__Metadata_Iterator * | iterator, |
FLAC__StreamMetadata * | block | ||
) |
Set the metadata block at the current position, replacing the existing block. The new block passed in becomes owned by the chain and it will be deleted when the chain is deleted.
iterator | A pointer to an existing initialized iterator. |
block | A pointer to a metadata block. |
FLAC__bool | false if the conditions in the above description are not met, or a memory allocation error occurs, otherwise true . |
FLAC__bool FLAC__metadata_iterator_delete_block | ( | FLAC__Metadata_Iterator * | iterator, |
FLAC__bool | replace_with_padding | ||
) |
Removes the current block from the chain. If replace_with_padding is true
, the block will instead be replaced with a padding block of equal size. You can not delete the STREAMINFO block. The iterator will be left pointing to the block before the one just "deleted", even if replace_with_padding is true
.
iterator | A pointer to an existing initialized iterator. |
replace_with_padding | See above. |
FLAC__bool | false if the conditions in the above description are not met, otherwise true . |
FLAC__bool FLAC__metadata_iterator_insert_block_before | ( | FLAC__Metadata_Iterator * | iterator, |
FLAC__StreamMetadata * | block | ||
) |
Insert a new block before the current block. You cannot insert a block before the first STREAMINFO block. You cannot insert a STREAMINFO block as there can be only one, the one that already exists at the head when you read in a chain. The chain takes ownership of the new block and it will be deleted when the chain is deleted. The iterator will be left pointing to the new block.
iterator | A pointer to an existing initialized iterator. |
block | A pointer to a metadata block to insert. |
FLAC__bool | false if the conditions in the above description are not met, or a memory allocation error occurs, otherwise true . |
FLAC__bool FLAC__metadata_iterator_insert_block_after | ( | FLAC__Metadata_Iterator * | iterator, |
FLAC__StreamMetadata * | block | ||
) |
Insert a new block after the current block. You cannot insert a STREAMINFO block as there can be only one, the one that already exists at the head when you read in a chain. The chain takes ownership of the new block and it will be deleted when the chain is deleted. The iterator will be left pointing to the new block.
iterator | A pointer to an existing initialized iterator. |
block | A pointer to a metadata block to insert. |
FLAC__bool | false if the conditions in the above description are not met, or a memory allocation error occurs, otherwise true . |
|
extern |
Maps a FLAC__Metadata_ChainStatus to a C string.
Using a FLAC__Metadata_ChainStatus as the index to this array will give the string equivalent. The contents should not be modified.