Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2182 lines
99KB

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