X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/c57f1201efce928c25c7899cc0baab09845c9ba7..812b526d127c6657e571db8b33a58137af6709cd:/plugins/tracklength.c diff --git a/plugins/tracklength.c b/plugins/tracklength.c index c1b9cb9..86a1fc8 100644 --- a/plugins/tracklength.c +++ b/plugins/tracklength.c @@ -2,20 +2,23 @@ * This file is part of DisOrder. * Copyright (C) 2004, 2005, 2007 Richard Kettlewell * - * This program is free software; you can redistribute it and/or modify + * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA + * along with this program. If not, see . + */ +/** @file plugins/tracklength.c + * @brief Plugin to compute track lengths + * + * Currently implements MP3, OGG, FLAC and WAV. */ #include @@ -32,7 +35,15 @@ #include #include -#include +/* libFLAC has had an API change and stupidly taken away the old API */ +#if HAVE_FLAC_FILE_DECODER_H +# include +#else +# include +#define FLAC__FileDecoder FLAC__StreamDecoder +#define FLAC__FileDecoderState FLAC__StreamDecoderState +#endif + #include @@ -159,33 +170,58 @@ static FLAC__StreamDecoderWriteStatus flac_write } static long tl_flac(const char *path) { - FLAC__FileDecoder *fd = 0; - FLAC__FileDecoderState fs; struct flac_state state[1]; state->duration = -1; /* error */ state->path = path; - if(!(fd = FLAC__file_decoder_new())) { - disorder_error(0, "FLAC__file_decoder_new failed"); - goto fail; - } - if(!(FLAC__file_decoder_set_filename(fd, path))) { - disorder_error(0, "FLAC__file_set_filename failed"); - goto fail; - } - FLAC__file_decoder_set_metadata_callback(fd, flac_metadata); - FLAC__file_decoder_set_error_callback(fd, flac_error); - FLAC__file_decoder_set_write_callback(fd, flac_write); - FLAC__file_decoder_set_client_data(fd, state); - if((fs = FLAC__file_decoder_init(fd))) { - disorder_error(0, "FLAC__file_decoder_init: %s", - FLAC__FileDecoderStateString[fs]); - goto fail; +#if HAVE_FLAC_FILE_DECODER_H + { + FLAC__FileDecoder *fd = 0; + FLAC__FileDecoderState fs; + + if(!(fd = FLAC__file_decoder_new())) { + disorder_error(0, "FLAC__file_decoder_new failed"); + goto fail; + } + if(!(FLAC__file_decoder_set_filename(fd, path))) { + disorder_error(0, "FLAC__file_set_filename failed"); + goto fail; + } + FLAC__file_decoder_set_metadata_callback(fd, flac_metadata); + FLAC__file_decoder_set_error_callback(fd, flac_error); + FLAC__file_decoder_set_write_callback(fd, flac_write); + FLAC__file_decoder_set_client_data(fd, state); + if((fs = FLAC__file_decoder_init(fd))) { + disorder_error(0, "FLAC__file_decoder_init: %s", + FLAC__FileDecoderStateString[fs]); + goto fail; + } + FLAC__file_decoder_process_until_end_of_metadata(fd); +fail: + if(fd) + FLAC__file_decoder_delete(fd); } - FLAC__file_decoder_process_until_end_of_metadata(fd); +#else + { + FLAC__StreamDecoder *sd = 0; + FLAC__StreamDecoderInitStatus is; + + if(!(sd = FLAC__stream_decoder_new())) { + disorder_error(0, "FLAC__stream_decoder_new failed"); + goto fail; + } + if((is = FLAC__stream_decoder_init_file(sd, path, flac_write, flac_metadata, + flac_error, state))) { + disorder_error(0, "FLAC__stream_decoder_init_file %s: %s", + path, FLAC__StreamDecoderInitStatusString[is]); + goto fail; + } + FLAC__stream_decoder_process_until_end_of_metadata(sd); fail: - if(fd) - FLAC__file_decoder_delete(fd); + if(sd) + FLAC__stream_decoder_delete(sd); + } +#endif return state->duration; }