discid.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /* --------------------------------------------------------------------------
  2. MusicBrainz -- The Internet music metadatabase
  3. Copyright (C) 2013 Johannes Dewender
  4. Copyright (C) 2006-2010 Lukas Lalinsky
  5. Copyright (C) 2006 Matthias Friedrich
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. --------------------------------------------------------------------------- */
  18. #ifndef MUSICBRAINZ_DISC_ID_H
  19. #define MUSICBRAINZ_DISC_ID_H
  20. #if (defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__))
  21. # ifdef libdiscid_EXPORTS
  22. # define LIBDISCID_API __declspec(dllexport)
  23. # else
  24. # define LIBDISCID_API __declspec(dllimport)
  25. # endif
  26. # define LIBDISCID_INTERNAL
  27. #elif (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)
  28. # define LIBDISCID_API
  29. # define LIBDISCID_INTERNAL __attribute__((visibility("hidden")))
  30. #elif defined(__SUNPRO_C)
  31. # define LIBDISCID_API __global
  32. # define LIBDISCID_INTERNAL __hidden
  33. #else
  34. # define LIBDISCID_API
  35. # define LIBDISCID_INTERNAL
  36. #endif
  37. #if (defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__))
  38. #define LIBDISCID_DEPRECATED __declspec(deprecated)
  39. #elif (defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) || defined(__clang__)
  40. #define LIBDISCID_DEPRECATED __attribute__((deprecated))
  41. #else
  42. #define LIBDISCID_DEPRECATED
  43. #endif
  44. #define DISCID_VERSION_MAJOR @libdiscid_MAJOR@
  45. #define DISCID_VERSION_MINOR @libdiscid_MINOR@
  46. #define DISCID_VERSION_PATCH @libdiscid_PATCH@
  47. #define DISCID_VERSION_NUM @libdiscid_VERSION_NUM@
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /*!
  52. * \mainpage libdiscid
  53. * \section intro Introduction
  54. *
  55. * Libdiscid is a C library for calculating DiscIDs
  56. * (<a href="http://musicbrainz.org/doc/Disc ID">MusicBrainz</a>
  57. * and <a href="http://freedb.org">freedb</a>)
  58. * for Audio CDs.
  59. * Additionally the library can extract the MCN/UPC/EAN and the
  60. * <a href="http://musicbrainz.org/doc/ISRC">ISRCs</a> from disc.
  61. *
  62. * The idea is to have an easy to use library without any dependencies
  63. * that can be used from scripting languages.
  64. *
  65. * The API is documented in discid.h.
  66. *
  67. * \section examples Examples
  68. *
  69. * This is an example of the most basic usage:
  70. *
  71. * \code
  72. *
  73. * DiscId *disc = discid_new();
  74. *
  75. * if ( discid_read_sparse(disc, "/dev/cdrom", 0) == 0 ) {
  76. * fprintf(stderr, "Error: %s\n", discid_get_error_msg(disc));
  77. * return 1;
  78. * }
  79. *
  80. * printf("DiscID : %s\n", discid_get_id(disc));
  81. * printf("Submit via : %s\n", discid_get_submission_url(disc));
  82. *
  83. * discid_free(disc);
  84. *
  85. * \endcode
  86. *
  87. * \section Building
  88. *
  89. * libdiscid provides a pkg-config script that returns the necessary compiler and linker flags, as well as the
  90. * version number. To build a small sample program one would use:
  91. *
  92. * @par
  93. * <tt>gcc libdiscid-test.c \`pkg-config libdiscid --cflags --libs\` -o libdiscid-test</tt>
  94. *
  95. * \section Contact
  96. *
  97. * - <a href="http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel">MusicBrainz Development Mailing List</a>
  98. * - <a href="http://tickets.musicbrainz.org/browse/LIB">MusicBrainz Bug Tracker</a>
  99. * - <a href="http://musicbrainz.org/doc/libdiscid">MusicBrainz Documentation</a>
  100. * - <a href="https://github.com/metabrainz/libdiscid">Github Repository</a>
  101. *
  102. */
  103. /**
  104. * A transparent handle for an Audio CD.
  105. *
  106. * This is returned by discid_new() and has to be passed as the first
  107. * parameter to all discid_*() functions.
  108. */
  109. typedef void *DiscId;
  110. /**
  111. * Return a handle for a new DiscId object.
  112. *
  113. * If no memory could be allocated, NULL is returned. Don't use the created
  114. * DiscId object before calling discid_read() or discid_put().
  115. *
  116. * @return a DiscId object, or NULL.
  117. */
  118. LIBDISCID_API DiscId *discid_new();
  119. /**
  120. * Release the memory allocated for the DiscId object.
  121. *
  122. * @param d a DiscId object created by discid_new()
  123. */
  124. LIBDISCID_API void discid_free(DiscId *d);
  125. /**
  126. * Read all supported features of the disc in the given CD-ROM/DVD-ROM drive.
  127. *
  128. * This function reads the disc in the drive specified by the given device
  129. * identifier. If the device is NULL, the default drive, as returned by
  130. * discid_get_default_device() is used.
  131. *
  132. * If you do not require all features provided by libdiscid, such as MCN
  133. * or ISRC reading, you should consider using discid_read_sparse() instead
  134. * of discid_read() for performance reasons.
  135. *
  136. * On error, this function returns false and sets the error message which you
  137. * can access using discid_get_error_msg(). In this case, the other functions
  138. * won't return meaningful values and should not be used.
  139. *
  140. * This function may be used multiple times with the same DiscId object.
  141. *
  142. * @param d a DiscId object created by discid_new()
  143. * @param device an operating system dependent device identifier, or NULL
  144. * @return true if successful, or false on error.
  145. */
  146. LIBDISCID_API int discid_read(DiscId *d, const char *device);
  147. /**
  148. * Read the disc in the given CD-ROM/DVD-ROM drive
  149. * extracting only the TOC and additionally specified features.
  150. *
  151. * This function will always read the TOC, but additional features
  152. * like ::DISCID_FEATURE_MCN and ::DISCID_FEATURE_ISRC can be set
  153. * using the features parameter.
  154. * Multiple features can be set using bitwise OR.
  155. *
  156. * If you only want to generate a disc ID, you only need the TOC,
  157. * so set features to 0:
  158. * \code
  159. * discid_read_sparse(disc, device, 0)
  160. * \endcode
  161. * This is a bit more verbose, but equivalent since ::DISCID_FEATURE_READ
  162. * is always implied:
  163. * \code
  164. * discid_read_sparse(disc, device, DISCID_FEATURE_READ)
  165. * \endcode
  166. *
  167. * If you want to read all features available, you can use discid_read().
  168. *
  169. * On error, this function returns false and sets the error message which you
  170. * can access using discid_get_error_msg(). In this case, the other functions
  171. * won't return meaningful values and should not be used.
  172. *
  173. * This function may be used multiple times with the same DiscId object.
  174. *
  175. * \since libdiscid 0.5.0
  176. *
  177. * @param d a DiscId object created by discid_new()
  178. * @param device an operating system dependent device identifier, or NULL
  179. * @param features a list of bit flags from the enum ::discid_feature
  180. * @return true if successful, or false on error.
  181. */
  182. LIBDISCID_API int discid_read_sparse(DiscId *d, const char *device,
  183. unsigned int features);
  184. #define DISCID_HAVE_SPARSE_READ
  185. /**
  186. * Provides the TOC of a known CD.
  187. *
  188. * This function may be used if the TOC has been read earlier and you
  189. * want to calculate the disc ID afterwards, without accessing the disc
  190. * drive. It replaces the discid_read function in this case.
  191. *
  192. * On error, this function returns false and sets the error message which you
  193. * can access using discid_get_error_msg(). In this case, the other functions
  194. * won't return meaningful values and should not be used.
  195. *
  196. * The offsets parameter points to an array which contains the track offsets
  197. * for each track. The first element, offsets[0], is the leadout track. It
  198. * must contain the total number of sectors on the disc.
  199. *
  200. * For discs with additional data tracks, the trailing data tracks
  201. * should be ignored. offset[0] should then be the last sector of the last
  202. * audio track.
  203. * Make sure the length of the last audio track as returned by libdiscid
  204. * after a put is the same as the length of your last audio track.
  205. * Depending on your tools you might need to substract 11400 (2:32 min.).
  206. * See also:
  207. * <a href="http://musicbrainz.org/doc/Disc_ID_Calculation">Disc ID Calculation</a>
  208. *
  209. *
  210. * @param d a DiscID object created by discid_new()
  211. * @param first the number of the first audio track on disc (usually one)
  212. * @param last the number of the last audio track on the disc
  213. * @param offsets a pointer to an array of 100 track offsets
  214. * @return true if the given data was valid, and false on error
  215. */
  216. LIBDISCID_API int discid_put(DiscId *d, int first, int last, int *offsets);
  217. /**
  218. * Return a human-readable error message.
  219. *
  220. * This function may only be used if discid_read() failed. The returned
  221. * error message is only valid as long as the DiscId object exists.
  222. *
  223. * @param d a DiscId object created by discid_new()
  224. * @return a string describing the error that occurred
  225. */
  226. LIBDISCID_API char *discid_get_error_msg(DiscId *d);
  227. /**
  228. * Return a MusicBrainz DiscID.
  229. *
  230. * The returned string is only valid as long as the DiscId object exists.
  231. *
  232. * @param d a DiscId object created by discid_new()
  233. * @return a string containing a MusicBrainz DiscID
  234. */
  235. LIBDISCID_API char *discid_get_id(DiscId *d);
  236. /**
  237. * Return a FreeDB DiscID.
  238. *
  239. * The returned string is only valid as long as the DiscId object exists.
  240. *
  241. * @param d a DiscId object created by discid_new()
  242. * @return a string containing a FreeDB DiscID
  243. */
  244. LIBDISCID_API char *discid_get_freedb_id(DiscId *d);
  245. /**
  246. * Return a string representing CD Table Of Contents (TOC).
  247. *
  248. * The string has following values separated by space:
  249. * first track number
  250. * last track number
  251. * total length in sectors
  252. * offset of 1st track
  253. * offset of 2nd track
  254. * ...
  255. *
  256. * Example:
  257. * 1 7 164900 150 22460 50197 80614 100828 133318 144712
  258. *
  259. * The returned string is only valid as long as the DiscId object exists.
  260. *
  261. * @param d a DiscId object created by discid_new()
  262. * @return a string containing TOC information
  263. */
  264. LIBDISCID_API char *discid_get_toc_string(DiscId *d);
  265. /**
  266. * Return an URL for submitting the DiscID to MusicBrainz.
  267. *
  268. * The URL leads to an interactive disc submission wizard that guides the
  269. * user through the process of associating this disc's DiscID with a
  270. * release in the MusicBrainz database.
  271. *
  272. * The returned string is only valid as long as the DiscId object exists.
  273. *
  274. * @param d a DiscId object created by discid_new()
  275. * @return a string containing an URL
  276. */
  277. LIBDISCID_API char *discid_get_submission_url(DiscId *d);
  278. /**
  279. * Return an URL for retrieving CD information from MusicBrainz' web service
  280. *
  281. * The URL provides the CD information in XML.
  282. * See http://musicbrainz.org/development/mmd for details.
  283. *
  284. * The returned string is only valid as long as the DiscId object exists.
  285. *
  286. * @param d a DiscId object created by discid_new()
  287. * @return a string containing an URL
  288. *
  289. * @deprecated This function is deprecated. Please use libmusicbrainz instead
  290. * since this function returns an URL referring the deprecated webservice.
  291. */
  292. LIBDISCID_API LIBDISCID_DEPRECATED char *discid_get_webservice_url(DiscId *d);
  293. /**
  294. * Return the name of the default disc drive for this machine.
  295. * This isn't constant, but possibly depends on the drives currently
  296. * attached, depending on the platform.
  297. * For this reason you should call this once and save it
  298. * when you want to make sure to use the same drive for
  299. * multiple operations.
  300. *
  301. * The returned string is thread local and owned by libdiscid internally.
  302. *
  303. * @return a string containing an operating system dependent device identifier
  304. */
  305. LIBDISCID_API char *discid_get_default_device(void);
  306. /**
  307. * Return the number of the first track on this disc.
  308. *
  309. * @param d a DiscId object created by discid_new()
  310. * @return the number of the first track
  311. */
  312. LIBDISCID_API int discid_get_first_track_num(DiscId *d);
  313. /**
  314. * Return the number of the last audio track on this disc.
  315. *
  316. * @param d a DiscId object created by discid_new()
  317. * @return the number of the last track
  318. */
  319. LIBDISCID_API int discid_get_last_track_num(DiscId *d);
  320. /**
  321. * Return the length of the disc in sectors.
  322. *
  323. * @param d a DiscId object created by discid_new()
  324. * @return the length of the disc in sectors
  325. */
  326. LIBDISCID_API int discid_get_sectors(DiscId *d);
  327. /**
  328. * Return the sector offset of a track.
  329. *
  330. * Only track numbers between (and including) discid_get_first_track_num()
  331. * and discid_get_last_track_num() may be used.
  332. *
  333. * @param d a DiscId object created by discid_new()
  334. * @param track_num the number of a track
  335. * @return sector offset of the specified track
  336. */
  337. LIBDISCID_API int discid_get_track_offset(DiscId *d, int track_num);
  338. /**
  339. * Return the length of a track in sectors.
  340. *
  341. * Only track numbers between (and including) discid_get_first_track_num()
  342. * and discid_get_last_track_num() may be used.
  343. *
  344. * @param d a DiscId object created by discid_new()
  345. * @param track_num the number of a track
  346. * @return length of the specified track
  347. */
  348. LIBDISCID_API int discid_get_track_length(DiscId *d, int track_num);
  349. /**
  350. * Return the Media Catalogue Number (MCN) for the disc.
  351. *
  352. * This is essentially an EAN (= UPC with 0 prefix).
  353. *
  354. * \since libdiscid 0.3.0
  355. *
  356. * @param d a DiscId object created by discid_new()
  357. * @return a string containing an Media Catalogue Number of the disk
  358. */
  359. LIBDISCID_API char* discid_get_mcn(DiscId *d);
  360. /**
  361. * Return the ISRC for a track.
  362. *
  363. * Only track numbers between (and including) discid_get_first_track_num()
  364. * and discid_get_last_track_num() may be used.
  365. *
  366. * \since libdiscid 0.3.0
  367. *
  368. * @param d a DiscId object created by discid_new()
  369. * @param track_num the number of a track
  370. * @return a string containing an ISRC for the specified track
  371. */
  372. LIBDISCID_API char* discid_get_track_isrc(DiscId *d, int track_num);
  373. /**
  374. * PLATFORM-DEPENDENT FEATURES
  375. *
  376. * The platform dependent features are currently:
  377. * - "read" read TOC from disc
  378. * - "mcn" read MCN from disc
  379. * - "isrc" read ISRC from disc
  380. *
  381. * A table in the
  382. * <a href="http://musicbrainz.org/doc/libdiscid">MusicBrainz Documentation</a>
  383. * specifies which features are available on which platform in what version.
  384. *
  385. * In the code you can use discid_get_feature_list() or discid_has_feature()
  386. * below to get the features for your platform in this version.
  387. */
  388. enum discid_feature {
  389. DISCID_FEATURE_READ = 1 << 0,
  390. DISCID_FEATURE_MCN = 1 << 1,
  391. DISCID_FEATURE_ISRC = 1 << 2,
  392. };
  393. /**
  394. * Check if a certain feature is implemented on the current platform.
  395. *
  396. * This only works for single features, not bit masks with multiple features.
  397. *
  398. * \since libdiscid 0.4.0
  399. *
  400. * @param feature as enum ::discid_feature
  401. * @return 1 if the feature is implemented and 0 if not.
  402. */
  403. LIBDISCID_API int discid_has_feature(enum discid_feature feature);
  404. #define DISCID_FEATURE_STR_READ "read"
  405. #define DISCID_FEATURE_STR_MCN "mcn"
  406. #define DISCID_FEATURE_STR_ISRC "isrc"
  407. #define DISCID_FEATURE_LENGTH 32
  408. /**
  409. * Return a list of features supported by the current platform.
  410. * The array of length ::DISCID_FEATURE_LENGTH should be allocated by the user.
  411. * After the call each element of the array is either NULL
  412. * or a pointer to a static string.
  413. *
  414. * \since libdiscid 0.4.0
  415. *
  416. * @param[out] features a static string array of length ::DISCID_FEATURE_LENGTH
  417. */
  418. LIBDISCID_API void discid_get_feature_list(
  419. char *features[DISCID_FEATURE_LENGTH]);
  420. /**
  421. * Return the full version string of this library, including the name.
  422. * This can be used for debug output.
  423. * Don't use this to test for features, see discid_has_feature().
  424. *
  425. * \since libdiscid 0.4.0
  426. *
  427. * @return a string containing the version of libdiscid.
  428. */
  429. LIBDISCID_API char *discid_get_version_string(void);
  430. #ifdef __cplusplus
  431. }
  432. #endif
  433. #endif /* MUSICBRAINZ_DISC_ID_H */