aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio_format.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-10-21 23:01:04 +0200
committerMax Kellermann <max@duempel.org>2009-10-21 23:01:04 +0200
commit9526fdbe730edb4b095a1e12aade0e16f1da2292 (patch)
tree4544e77bf35e08a12d2b019e0bf3942754b85b96 /src/audio_format.h
parenta5c4566fa1551953b84882a1fa53400c7bd6551c (diff)
downloadmpd-9526fdbe730edb4b095a1e12aade0e16f1da2292.tar.gz
mpd-9526fdbe730edb4b095a1e12aade0e16f1da2292.tar.xz
mpd-9526fdbe730edb4b095a1e12aade0e16f1da2292.zip
audio_format: wildcards allowed in audio_format configuration
An asterisk means that this attribute should not be enforced, and stays whatever it used to be. This way, some configuration values work like masks.
Diffstat (limited to '')
-rw-r--r--src/audio_format.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/audio_format.h b/src/audio_format.h
index a88fc3a4c..a4f5ba2e0 100644
--- a/src/audio_format.h
+++ b/src/audio_format.h
@@ -91,6 +91,27 @@ static inline bool audio_format_defined(const struct audio_format *af)
}
/**
+ * Checks whether the specified #audio_format object is full, i.e. all
+ * attributes are defined. This is more complete than
+ * audio_format_defined(), but slower.
+ */
+static inline bool
+audio_format_fully_defined(const struct audio_format *af)
+{
+ return af->sample_rate != 0 && af->bits != 0 && af->channels != 0;
+}
+
+/**
+ * Checks whether the specified #audio_format object has at least one
+ * defined value.
+ */
+static inline bool
+audio_format_mask_defined(const struct audio_format *af)
+{
+ return af->sample_rate != 0 || af->bits != 0 || af->channels != 0;
+}
+
+/**
* Checks whether the sample rate is valid.
*
* @param sample_rate the sample rate in Hz
@@ -132,6 +153,18 @@ static inline bool audio_format_valid(const struct audio_format *af)
audio_valid_channel_count(af->channels);
}
+/**
+ * Returns false if the format mask is not valid for playback with
+ * MPD. This function performs some basic validity checks.
+ */
+static inline bool audio_format_mask_valid(const struct audio_format *af)
+{
+ return (af->sample_rate == 0 ||
+ audio_valid_sample_rate(af->sample_rate)) &&
+ (af->bits == 0 || audio_valid_sample_format(af->bits)) &&
+ (af->channels == 0 || audio_valid_channel_count(af->channels));
+}
+
static inline bool audio_format_equals(const struct audio_format *a,
const struct audio_format *b)
{
@@ -141,6 +174,20 @@ static inline bool audio_format_equals(const struct audio_format *a,
a->reverse_endian == b->reverse_endian;
}
+static inline void
+audio_format_mask_apply(struct audio_format *af,
+ const struct audio_format *mask)
+{
+ if (mask->sample_rate != 0)
+ af->sample_rate = mask->sample_rate;
+
+ if (mask->bits != 0)
+ af->bits = mask->bits;
+
+ if (mask->channels != 0)
+ af->channels = mask->channels;
+}
+
/**
* Returns the size of each (mono) sample in bytes.
*/