* Josh Coalson : cynthiune patch for upcoming FLAC 1.1.3 --- Cynthiune-0.9.5/Bundles/FLAC/FLAC.h +++ Cynthiune-0.9.5/Bundles/FLAC/FLAC.h @@ -31,7 +31,11 @@ @interface FLAC : NSObject { +#ifdef LEGACY_FLAC FLAC__FileDecoder *fileDecoder; +#else + FLAC__StreamDecoder *fileDecoder; +#endif unsigned int bitsPerSample; unsigned int duration; --- Cynthiune-0.9.5/Bundles/FLAC/FLAC.m +++ Cynthiune-0.9.5/Bundles/FLAC/FLAC.m @@ -34,13 +34,25 @@ #import #import +/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ +#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 +#define LEGACY_FLAC +#else +#undef LEGACY_FLAC +#endif + #import "FLAC.h" #define LOCALIZED(X) _b ([FLAC class], X) static FLAC__StreamDecoderWriteStatus +#ifdef LEGACY_FLAC writeCallback (const FLAC__FileDecoder *fileDecoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData) +#else +writeCallback (const FLAC__StreamDecoder *fileDecoder, const FLAC__Frame *frame, + const FLAC__int32 * const buffer[], void *clientData) +#endif { CFLAC *cStream; unsigned int sample, channel; @@ -70,9 +82,15 @@ } static void +#ifdef LEGACY_FLAC metadataCallback (const FLAC__FileDecoder *fileDecoder, const FLAC__StreamMetadata *metadata, void *clientData) +#else +metadataCallback (const FLAC__StreamDecoder *fileDecoder, + const FLAC__StreamMetadata *metadata, + void *clientData) +#endif { CFLAC *cStream; @@ -88,9 +106,15 @@ } static void +#ifdef LEGACY_FLAC errorCallback (const FLAC__FileDecoder *fileDecoder, FLAC__StreamDecoderErrorStatus status, void *clientData) +#else +errorCallback (const FLAC__StreamDecoder *fileDecoder, + FLAC__StreamDecoderErrorStatus status, + void *clientData) +#endif { NSLog (@"FLAC: received error with status %d", status); } @@ -161,6 +185,7 @@ - (BOOL) _initializeFileDecoderWithFilename: (NSString *) fileName { +#ifdef LEGACY_FLAC FLAC__file_decoder_set_metadata_ignore_all (fileDecoder); FLAC__file_decoder_set_metadata_respond (fileDecoder, FLAC__METADATA_TYPE_STREAMINFO); @@ -173,13 +198,25 @@ return (FLAC__file_decoder_set_filename (fileDecoder, [fileName cString]) && (FLAC__file_decoder_init (fileDecoder) == FLAC__FILE_DECODER_OK) && FLAC__file_decoder_process_until_end_of_metadata (fileDecoder)); +#else + FLAC__stream_decoder_set_metadata_ignore_all (fileDecoder); + FLAC__stream_decoder_set_metadata_respond (fileDecoder, + FLAC__METADATA_TYPE_STREAMINFO); + return ((FLAC__stream_decoder_init_file (fileDecoder, [fileName cString], + writeCallback, metadataCallback, errorCallback, self) == FLAC__STREAM_DECODER_INIT_STATUS_OK) + && FLAC__stream_decoder_process_until_end_of_metadata (fileDecoder)); +#endif } - (BOOL) streamOpen: (NSString *) fileName { BOOL result; +#ifdef LEGACY_FLAC fileDecoder = FLAC__file_decoder_new(); +#else + fileDecoder = FLAC__stream_decoder_new(); +#endif if (fileDecoder) { @@ -187,7 +224,11 @@ result = YES; else { +#ifdef LEGACY_FLAC FLAC__file_decoder_delete (fileDecoder); +#else + FLAC__stream_decoder_delete (fileDecoder); +#endif fileDecoder = NULL; result = NO; } @@ -200,7 +241,11 @@ - (void) streamClose { +#ifdef LEGACY_FLAC FLAC__file_decoder_delete (fileDecoder); +#else + FLAC__stream_decoder_delete (fileDecoder); +#endif fileDecoder = NULL; } @@ -215,7 +260,11 @@ if (position >= readBufferSize) { position = 0; +#ifdef LEGACY_FLAC success = FLAC__file_decoder_process_single (fileDecoder); +#else + success = FLAC__stream_decoder_process_single (fileDecoder); +#endif } if (success) @@ -251,13 +300,27 @@ withSize: (unsigned int) bufferSize { int readBytes; +#ifdef LEGACY_FLAC FLAC__FileDecoderState state; state = FLAC__file_decoder_get_state (fileDecoder); +#else + FLAC__StreamDecoderState state; + + state = FLAC__stream_decoder_get_state (fileDecoder); +#endif +#ifdef LEGACY_FLAC if (state == FLAC__FILE_DECODER_OK) +#else + if (state < FLAC__STREAM_DECODER_END_OF_STREAM) +#endif readBytes = [self _processNextChunk: buffer withSize: bufferSize]; +#ifdef LEGACY_FLAC else if (state == FLAC__FILE_DECODER_END_OF_FILE) +#else + else if (state == FLAC__STREAM_DECODER_END_OF_STREAM) +#endif readBytes = 0; else readBytes = -1; @@ -272,7 +335,11 @@ - (void) seek: (unsigned int) aPos { +#ifdef LEGACY_FLAC FLAC__file_decoder_seek_absolute (fileDecoder, aPos * rate); +#else + FLAC__stream_decoder_seek_absolute (fileDecoder, aPos * rate); +#endif } - (unsigned int) readChannels @@ -295,7 +362,11 @@ if (readBuffer) free (readBuffer); if (fileDecoder) +#ifdef LEGACY_FLAC FLAC__file_decoder_delete (fileDecoder); +#else + FLAC__stream_decoder_delete (fileDecoder); +#endif [super dealloc]; } --- Cynthiune-0.9.5/Bundles/FLACTags/FLACTags.m +++ Cynthiune-0.9.5/Bundles/FLACTags/FLACTags.m @@ -33,6 +33,13 @@ #import "FLACTags.h" +/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ +#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 +#define LEGACY_FLAC +#else +#undef LEGACY_FLAC +#endif + #define LOCALIZED(X) _b ([FLACTags class], X) static inline int @@ -78,16 +85,27 @@ } static FLAC__StreamDecoderWriteStatus +#ifdef LEGACY_FLAC writeCallback (const FLAC__FileDecoder *fileDecoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData) +#else +writeCallback (const FLAC__StreamDecoder *fileDecoder, const FLAC__Frame *frame, + const FLAC__int32 * const buffer[], void *clientData) +#endif { return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; } static void +#ifdef LEGACY_FLAC metadataCallback (const FLAC__FileDecoder *fileDecoder, const FLAC__StreamMetadata *metadata, void *clientData) +#else +metadataCallback (const FLAC__StreamDecoder *fileDecoder, + const FLAC__StreamMetadata *metadata, + void *clientData) +#endif { unsigned int count; @@ -104,9 +122,15 @@ } static void +#ifdef LEGACY_FLAC errorCallback (const FLAC__FileDecoder *fileDecoder, FLAC__StreamDecoderErrorStatus status, void *clientData) +#else +errorCallback (const FLAC__StreamDecoder *fileDecoder, + FLAC__StreamDecoderErrorStatus status, + void *clientData) +#endif { NSLog (@"FLACTags: received error with status %d", status); } @@ -132,14 +156,23 @@ year: (NSString **) year ofFilename: (NSString *) filename { +#ifdef LEGACY_FLAC FLAC__FileDecoder *fileDecoder; +#else + FLAC__StreamDecoder *fileDecoder; +#endif BOOL result; NSString **arrayOfValues[] = { title, artist, album, trackNumber, genre, year }; +#ifdef LEGACY_FLAC fileDecoder = FLAC__file_decoder_new(); +#else + fileDecoder = FLAC__stream_decoder_new(); +#endif if (fileDecoder) { +#ifdef LEGACY_FLAC FLAC__file_decoder_set_metadata_ignore_all (fileDecoder); FLAC__file_decoder_set_metadata_respond (fileDecoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); @@ -156,6 +189,17 @@ && FLAC__file_decoder_process_until_end_of_metadata (fileDecoder)); FLAC__file_decoder_delete (fileDecoder); +#else + FLAC__stream_decoder_set_metadata_ignore_all (fileDecoder); + FLAC__stream_decoder_set_metadata_respond (fileDecoder, + FLAC__METADATA_TYPE_VORBIS_COMMENT); + result = ((FLAC__stream_decoder_init_file (fileDecoder, [filename cString], + writeCallback, metadataCallback, errorCallback, arrayOfValues) + == FLAC__STREAM_DECODER_INIT_STATUS_OK) + && FLAC__stream_decoder_process_until_end_of_metadata + (fileDecoder)); + FLAC__stream_decoder_delete (fileDecoder); +#endif } else result = NO;