From 43166130b51e995ada4130f6400efbb5d38eeb47 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 29 Jul 2013 07:50:08 +0200 Subject: audio_check: convert to C++ --- src/AudioParser.cxx | 2 +- src/CheckAudioFormat.cxx | 74 +++++++++++++++++++++++++++++++++ src/CheckAudioFormat.hxx | 54 ++++++++++++++++++++++++ src/audio_check.c | 74 --------------------------------- src/audio_check.h | 63 ---------------------------- src/decoder/AdPlugDecoderPlugin.cxx | 5 +-- src/decoder/AudiofileDecoderPlugin.cxx | 2 +- src/decoder/DsdiffDecoderPlugin.cxx | 2 +- src/decoder/DsfDecoderPlugin.cxx | 2 +- src/decoder/FaadDecoderPlugin.cxx | 2 +- src/decoder/FfmpegDecoderPlugin.cxx | 5 +-- src/decoder/FlacCommon.cxx | 5 +-- src/decoder/FluidsynthDecoderPlugin.cxx | 2 +- src/decoder/GmeDecoderPlugin.cxx | 2 +- src/decoder/MadDecoderPlugin.cxx | 2 +- src/decoder/MpcdecDecoderPlugin.cxx | 2 +- src/decoder/Mpg123DecoderPlugin.cxx | 2 +- src/decoder/OpusDecoderPlugin.cxx | 2 +- src/decoder/SndfileDecoderPlugin.cxx | 2 +- src/decoder/VorbisDecoderPlugin.cxx | 6 +-- src/decoder/WavpackDecoderPlugin.cxx | 6 +-- src/filter/RouteFilterPlugin.cxx | 2 +- 22 files changed, 146 insertions(+), 172 deletions(-) create mode 100644 src/CheckAudioFormat.cxx create mode 100644 src/CheckAudioFormat.hxx delete mode 100644 src/audio_check.c delete mode 100644 src/audio_check.h (limited to 'src') diff --git a/src/AudioParser.cxx b/src/AudioParser.cxx index 9178c3e1a..297d99f12 100644 --- a/src/AudioParser.cxx +++ b/src/AudioParser.cxx @@ -25,7 +25,7 @@ #include "config.h" #include "AudioParser.hxx" #include "audio_format.h" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "gcc.h" #include diff --git a/src/CheckAudioFormat.cxx b/src/CheckAudioFormat.cxx new file mode 100644 index 000000000..6d484be19 --- /dev/null +++ b/src/CheckAudioFormat.cxx @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * 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 + * (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. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "CheckAudioFormat.hxx" +#include "audio_format.h" + +#include + +bool +audio_check_sample_rate(unsigned long sample_rate, GError **error_r) +{ + if (!audio_valid_sample_rate(sample_rate)) { + g_set_error(error_r, audio_format_quark(), 0, + "Invalid sample rate: %lu", sample_rate); + return false; + } + + return true; +} + +bool +audio_check_sample_format(enum sample_format sample_format, GError **error_r) +{ + if (!audio_valid_sample_format(sample_format)) { + g_set_error(error_r, audio_format_quark(), 0, + "Invalid sample format: %u", sample_format); + return false; + } + + return true; +} + +bool +audio_check_channel_count(unsigned channels, GError **error_r) +{ + if (!audio_valid_channel_count(channels)) { + g_set_error(error_r, audio_format_quark(), 0, + "Invalid channel count: %u", channels); + return false; + } + + return true; +} + +bool +audio_format_init_checked(struct audio_format *af, unsigned long sample_rate, + enum sample_format sample_format, unsigned channels, + GError **error_r) +{ + if (audio_check_sample_rate(sample_rate, error_r) && + audio_check_sample_format(sample_format, error_r) && + audio_check_channel_count(channels, error_r)) { + audio_format_init(af, sample_rate, sample_format, channels); + assert(audio_format_valid(af)); + return true; + } else + return false; +} diff --git a/src/CheckAudioFormat.hxx b/src/CheckAudioFormat.hxx new file mode 100644 index 000000000..cb3e43c22 --- /dev/null +++ b/src/CheckAudioFormat.hxx @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * 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 + * (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. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_CHECK_AUDIO_FORMAT_HXX +#define MPD_CHECK_AUDIO_FORMAT_HXX + +#include "audio_format.h" + +#include + +/** + * The GLib quark used for errors reported by this library. + */ +gcc_const +static inline GQuark +audio_format_quark(void) +{ + return g_quark_from_static_string("audio_format"); +} + +bool +audio_check_sample_rate(unsigned long sample_rate, GError **error_r); + +bool +audio_check_sample_format(enum sample_format, GError **error_r); + +bool +audio_check_channel_count(unsigned sample_format, GError **error_r); + +/** + * Wrapper for audio_format_init(), which checks all attributes. + */ +bool +audio_format_init_checked(struct audio_format *af, unsigned long sample_rate, + enum sample_format sample_format, unsigned channels, + GError **error_r); + +#endif diff --git a/src/audio_check.c b/src/audio_check.c deleted file mode 100644 index a9aa2dd82..000000000 --- a/src/audio_check.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * 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 - * (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. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "audio_check.h" -#include "audio_format.h" - -#include - -bool -audio_check_sample_rate(unsigned long sample_rate, GError **error_r) -{ - if (!audio_valid_sample_rate(sample_rate)) { - g_set_error(error_r, audio_format_quark(), 0, - "Invalid sample rate: %lu", sample_rate); - return false; - } - - return true; -} - -bool -audio_check_sample_format(enum sample_format sample_format, GError **error_r) -{ - if (!audio_valid_sample_format(sample_format)) { - g_set_error(error_r, audio_format_quark(), 0, - "Invalid sample format: %u", sample_format); - return false; - } - - return true; -} - -bool -audio_check_channel_count(unsigned channels, GError **error_r) -{ - if (!audio_valid_channel_count(channels)) { - g_set_error(error_r, audio_format_quark(), 0, - "Invalid channel count: %u", channels); - return false; - } - - return true; -} - -bool -audio_format_init_checked(struct audio_format *af, unsigned long sample_rate, - enum sample_format sample_format, unsigned channels, - GError **error_r) -{ - if (audio_check_sample_rate(sample_rate, error_r) && - audio_check_sample_format(sample_format, error_r) && - audio_check_channel_count(channels, error_r)) { - audio_format_init(af, sample_rate, sample_format, channels); - assert(audio_format_valid(af)); - return true; - } else - return false; -} diff --git a/src/audio_check.h b/src/audio_check.h deleted file mode 100644 index d4d3f13fd..000000000 --- a/src/audio_check.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * 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 - * (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. - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_AUDIO_CHECK_H -#define MPD_AUDIO_CHECK_H - -#include "audio_format.h" - -#include -#include - -/** - * The GLib quark used for errors reported by this library. - */ -gcc_const -static inline GQuark -audio_format_quark(void) -{ - return g_quark_from_static_string("audio_format"); -} - -#ifdef __cplusplus -extern "C" { -#endif - -bool -audio_check_sample_rate(unsigned long sample_rate, GError **error_r); - -bool -audio_check_sample_format(enum sample_format, GError **error_r); - -bool -audio_check_channel_count(unsigned sample_format, GError **error_r); - -/** - * Wrapper for audio_format_init(), which checks all attributes. - */ -bool -audio_format_init_checked(struct audio_format *af, unsigned long sample_rate, - enum sample_format sample_format, unsigned channels, - GError **error_r); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/decoder/AdPlugDecoderPlugin.cxx b/src/decoder/AdPlugDecoderPlugin.cxx index d1ed07891..a9a90c283 100644 --- a/src/decoder/AdPlugDecoderPlugin.cxx +++ b/src/decoder/AdPlugDecoderPlugin.cxx @@ -21,10 +21,7 @@ #include "AdPlugDecoderPlugin.h" #include "TagHandler.hxx" #include "DecoderAPI.hxx" - -extern "C" { -#include "audio_check.h" -} +#include "CheckAudioFormat.hxx" #include #include diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx index ee7d0da14..b77c41d02 100644 --- a/src/decoder/AudiofileDecoderPlugin.cxx +++ b/src/decoder/AudiofileDecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "AudiofileDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #include diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx index fb542c3b7..4b9a59a7a 100644 --- a/src/decoder/DsdiffDecoderPlugin.cxx +++ b/src/decoder/DsdiffDecoderPlugin.cxx @@ -29,7 +29,7 @@ #include "config.h" #include "DsdiffDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "util/bit_reverse.h" #include "TagHandler.hxx" #include "DsdLib.hxx" diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx index c19669dd6..9661d70e6 100644 --- a/src/decoder/DsfDecoderPlugin.cxx +++ b/src/decoder/DsfDecoderPlugin.cxx @@ -30,7 +30,7 @@ #include "config.h" #include "DsfDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "util/bit_reverse.h" #include "DsdLib.hxx" #include "TagHandler.hxx" diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx index 4c21ae7c9..d87c48628 100644 --- a/src/decoder/FaadDecoderPlugin.cxx +++ b/src/decoder/FaadDecoderPlugin.cxx @@ -21,7 +21,7 @@ #include "FaadDecoderPlugin.hxx" #include "DecoderAPI.hxx" #include "DecoderBuffer.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #include diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index 5930f7fa7..ae95dec09 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -26,10 +26,7 @@ #include "FfmpegMetaData.hxx" #include "TagHandler.hxx" #include "InputStream.hxx" - -extern "C" { -#include "audio_check.h" -} +#include "CheckAudioFormat.hxx" #include diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx index 425ab55df..07a377055 100644 --- a/src/decoder/FlacCommon.cxx +++ b/src/decoder/FlacCommon.cxx @@ -25,10 +25,7 @@ #include "FlacCommon.hxx" #include "FlacMetadata.hxx" #include "FlacPcm.hxx" - -extern "C" { -#include "audio_check.h" -} +#include "CheckAudioFormat.hxx" #include diff --git a/src/decoder/FluidsynthDecoderPlugin.cxx b/src/decoder/FluidsynthDecoderPlugin.cxx index 5fbc83bdf..15d2f5e6b 100644 --- a/src/decoder/FluidsynthDecoderPlugin.cxx +++ b/src/decoder/FluidsynthDecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "FluidsynthDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "conf.h" #include diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx index 14367e311..8158ab553 100644 --- a/src/decoder/GmeDecoderPlugin.cxx +++ b/src/decoder/GmeDecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "GmeDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #include "util/UriUtil.hxx" diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index 0d74caf91..c9b2f0a6c 100644 --- a/src/decoder/MadDecoderPlugin.cxx +++ b/src/decoder/MadDecoderPlugin.cxx @@ -24,7 +24,7 @@ #include "TagId3.hxx" #include "TagRva2.hxx" #include "TagHandler.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include #include diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx index 482610e2d..d4333a527 100644 --- a/src/decoder/MpcdecDecoderPlugin.cxx +++ b/src/decoder/MpcdecDecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "MpcdecDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #ifdef MPC_IS_OLD_API diff --git a/src/decoder/Mpg123DecoderPlugin.cxx b/src/decoder/Mpg123DecoderPlugin.cxx index a22f926f5..73f94ea44 100644 --- a/src/decoder/Mpg123DecoderPlugin.cxx +++ b/src/decoder/Mpg123DecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" /* must be first for large file support */ #include "Mpg123DecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #include diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index 063d13d79..84467371c 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -26,7 +26,7 @@ #include "OggSyncState.hxx" #include "DecoderAPI.hxx" #include "OggCodec.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #include "InputStream.hxx" diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx index 186f357ff..b1bb97538 100644 --- a/src/decoder/SndfileDecoderPlugin.cxx +++ b/src/decoder/SndfileDecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "SndfileDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #include diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx index 438ba5949..7e039ab1e 100644 --- a/src/decoder/VorbisDecoderPlugin.cxx +++ b/src/decoder/VorbisDecoderPlugin.cxx @@ -24,11 +24,7 @@ #include "InputStream.hxx" #include "OggCodec.hxx" #include "util/UriUtil.hxx" - -extern "C" { -#include "audio_check.h" -} - +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #ifndef HAVE_TREMOR diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx index dbec7e82c..1a31b7aac 100644 --- a/src/decoder/WavpackDecoderPlugin.cxx +++ b/src/decoder/WavpackDecoderPlugin.cxx @@ -21,11 +21,7 @@ #include "WavpackDecoderPlugin.hxx" #include "DecoderAPI.hxx" #include "InputStream.hxx" - -extern "C" { -#include "audio_check.h" -} - +#include "CheckAudioFormat.hxx" #include "TagHandler.hxx" #include "ApeTag.hxx" diff --git a/src/filter/RouteFilterPlugin.cxx b/src/filter/RouteFilterPlugin.cxx index c6cf302b2..85db7e9ea 100644 --- a/src/filter/RouteFilterPlugin.cxx +++ b/src/filter/RouteFilterPlugin.cxx @@ -43,7 +43,7 @@ #include "conf.h" #include "ConfigQuark.hxx" #include "audio_format.h" -#include "audio_check.h" +#include "CheckAudioFormat.hxx" #include "FilterPlugin.hxx" #include "FilterInternal.hxx" #include "FilterRegistry.hxx" -- cgit v1.2.3