metadata.h 99 KB

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