metabrainz/libdiscid — pull request #11 by phw (2013-03-10 12:54:05+00:00)
Title: Add discid_read_sparse() (LIB-29)

This patch adds a new public method discid_read_sparse() to fix http://tickets.musicbrainz.org/browse/LIB-29. It is similar to discid_read() but allows to specify the features to use and thus skip unneeded features. E.g. you can skip reading the MCN and ISRCs which will result in faster reads.

This implementation will always read the TOC since I don't see any use case in skipping it. Its quite fast and required to get even the basic information anyway (e.g. you can't return the list of ISRCs without knowing the number of tracks).

Samples:

/* Read only the TOC */
discid_read_sparse(disc, device, 0);

/* Read only the TOC and MCN */
discid_read_sparse(disc, device, DISCID_FEATURE_MCN);

/* Read only the TOC and ISRCs */
discid_read_sparse(disc, device, DISCID_FEATURE_ISRC);

/* Read the TOC, MCN and ISRCs */
discid_read_sparse(disc, device, DISCID_FEATURE_MCN | DISCID_FEATURE_ISRC);

/* Passing DISCID_FEATURE_READ is not an error, but not necessary */
discid_read_sparse(disc, device, DISCID_FEATURE_READ | DISCID_FEATURE_MCN | DISCID_FEATURE_ISRC);

Passing a feature does not guarantee that it will be used. You still have to check for features supported on the platform using the feature detection API. Passing an unsupported feature to discid_read_sparse() must not result in an error but should be ignored by the platform specific implementation.