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.
This commit is contained in:
Max Kellermann
2009-10-21 23:01:04 +02:00
parent a5c4566fa1
commit 9526fdbe73
14 changed files with 118 additions and 30 deletions

View File

@@ -90,6 +90,27 @@ static inline bool audio_format_defined(const struct audio_format *af)
return af->sample_rate != 0;
}
/**
* 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.
*
@@ -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.
*/