aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio_format.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-02-11 18:00:48 +0100
committerMax Kellermann <max@duempel.org>2009-02-11 18:00:48 +0100
commit3bc4224bfda5ebf9cd6969ea0f6647b1af3e9da6 (patch)
tree8c52ad4a6fc9a95033d40536a96291161130f556 /src/audio_format.h
parent5090cf6484f5e7464aeba54d19500cc334a80fad (diff)
downloadmpd-3bc4224bfda5ebf9cd6969ea0f6647b1af3e9da6.tar.gz
mpd-3bc4224bfda5ebf9cd6969ea0f6647b1af3e9da6.tar.xz
mpd-3bc4224bfda5ebf9cd6969ea0f6647b1af3e9da6.zip
audio_format: added validation functions
In addition to audio_format_valid(), provide functions which validate only one attribute of an audio_format. These functions are reused by audio_format_parse().
Diffstat (limited to 'src/audio_format.h')
-rw-r--r--src/audio_format.h37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/audio_format.h b/src/audio_format.h
index 739fe6c1f..a7ff30830 100644
--- a/src/audio_format.h
+++ b/src/audio_format.h
@@ -41,14 +41,45 @@ static inline bool audio_format_defined(const struct audio_format *af)
}
/**
+ * Checks whether the sample rate is valid.
+ *
+ * @param sample_rate the sample rate in Hz
+ */
+static inline bool
+audio_valid_sample_rate(unsigned sample_rate)
+{
+ return sample_rate > 0 && sample_rate < (1 << 30);
+}
+
+/**
+ * Checks whether the sample format is valid.
+ *
+ * @param bits the number of significant bits per sample
+ */
+static inline bool
+audio_valid_sample_format(unsigned bits)
+{
+ return bits == 16 || bits == 24 || bits == 8;
+}
+
+/**
+ * Checks whether the number of channels is valid.
+ */
+static inline bool
+audio_valid_channel_count(unsigned channels)
+{
+ return channels == 1 || channels == 2;
+}
+
+/**
* Returns false if the format is not valid for playback with MPD.
* This function performs some basic validity checks.
*/
static inline bool audio_format_valid(const struct audio_format *af)
{
- return af->sample_rate > 0 &&
- (af->bits == 8 || af->bits == 16 || af->bits == 24) &&
- af->channels >= 1;
+ return audio_valid_sample_rate(af->sample_rate) &&
+ audio_valid_sample_format(af->bits) &&
+ audio_valid_channel_count(af->channels);
}
static inline bool audio_format_equals(const struct audio_format *a,