metadata.h 97 KB

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