volume: fix definition of PA_VOLUME_MAX and introduce PA_VOLUME_INVALID and use it wherever applicable

This commit is contained in:
Lennart Poettering 2009-09-07 19:53:39 +02:00
parent 5cf0c1e544
commit 3bbc5e6a4d
5 changed files with 17 additions and 14 deletions

View file

@ -187,7 +187,7 @@ pa_operation *pa_context_play_sample(pa_context *c, const char *name, const char
pa_tagstruct_putu32(t, PA_INVALID_INDEX); pa_tagstruct_putu32(t, PA_INVALID_INDEX);
pa_tagstruct_puts(t, dev); pa_tagstruct_puts(t, dev);
if (volume == (pa_volume_t) -1 && c->version < 15) if (volume == PA_VOLUME_INVALID && c->version < 15)
volume = PA_VOLUME_NORM; volume = PA_VOLUME_NORM;
pa_tagstruct_putu32(t, volume); pa_tagstruct_putu32(t, volume);
@ -228,7 +228,7 @@ pa_operation *pa_context_play_sample_with_proplist(pa_context *c, const char *na
pa_tagstruct_putu32(t, PA_INVALID_INDEX); pa_tagstruct_putu32(t, PA_INVALID_INDEX);
pa_tagstruct_puts(t, dev); pa_tagstruct_puts(t, dev);
if (volume == (pa_volume_t) -1 && c->version < 15) if (volume == PA_VOLUME_INVALID && c->version < 15)
volume = PA_VOLUME_NORM; volume = PA_VOLUME_NORM;
pa_tagstruct_putu32(t, volume); pa_tagstruct_putu32(t, volume);

View file

@ -101,7 +101,7 @@ pa_operation* pa_context_play_sample(
pa_context *c /**< Context */, pa_context *c /**< Context */,
const char *name /**< Name of the sample to play */, const char *name /**< Name of the sample to play */,
const char *dev /**< Sink to play this sample on */, const char *dev /**< Sink to play this sample on */,
pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here (pa_volume_t) -1 which will leave the decision about the volume to the server side which is a good idea. */ , pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here PA_VOLUME_INVALID which will leave the decision about the volume to the server side which is a good idea. */ ,
pa_context_success_cb_t cb /**< Call this function after successfully starting playback, or NULL */, pa_context_success_cb_t cb /**< Call this function after successfully starting playback, or NULL */,
void *userdata /**< Userdata to pass to the callback */); void *userdata /**< Userdata to pass to the callback */);
@ -113,7 +113,7 @@ pa_operation* pa_context_play_sample_with_proplist(
pa_context *c /**< Context */, pa_context *c /**< Context */,
const char *name /**< Name of the sample to play */, const char *name /**< Name of the sample to play */,
const char *dev /**< Sink to play this sample on */, const char *dev /**< Sink to play this sample on */,
pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here (pa_volume_t) -1 which will leave the decision about the volume to the server side which is a good idea. */ , pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here PA_VOLUME_INVALID which will leave the decision about the volume to the server side which is a good idea. */ ,
pa_proplist *proplist /**< Property list for this sound. The property list of the cached entry will be merged into this property list */, pa_proplist *proplist /**< Property list for this sound. The property list of the cached entry will be merged into this property list */,
pa_context_play_sample_cb_t cb /**< Call this function after successfully starting playback, or NULL */, pa_context_play_sample_cb_t cb /**< Call this function after successfully starting playback, or NULL */,
void *userdata /**< Userdata to pass to the callback */); void *userdata /**< Userdata to pass to the callback */);

View file

@ -64,7 +64,7 @@ pa_cvolume* pa_cvolume_init(pa_cvolume *a) {
a->channels = 0; a->channels = 0;
for (c = 0; c < PA_CHANNELS_MAX; c++) for (c = 0; c < PA_CHANNELS_MAX; c++)
a->values[c] = (pa_volume_t) -1; a->values[c] = PA_VOLUME_INVALID;
return a; return a;
} }
@ -307,7 +307,7 @@ char *pa_volume_snprint(char *s, size_t l, pa_volume_t v) {
pa_init_i18n(); pa_init_i18n();
if (v == (pa_volume_t) -1) { if (v == PA_VOLUME_INVALID) {
pa_snprintf(s, l, _("(invalid)")); pa_snprintf(s, l, _("(invalid)"));
return s; return s;
} }
@ -357,7 +357,7 @@ char *pa_sw_volume_snprint_dB(char *s, size_t l, pa_volume_t v) {
pa_init_i18n(); pa_init_i18n();
if (v == (pa_volume_t) -1) { if (v == PA_VOLUME_INVALID) {
pa_snprintf(s, l, _("(invalid)")); pa_snprintf(s, l, _("(invalid)"));
return s; return s;
} }
@ -459,7 +459,7 @@ int pa_cvolume_valid(const pa_cvolume *v) {
return 0; return 0;
for (c = 0; c < v->channels; c++) for (c = 0; c < v->channels; c++)
if (v->values[c] == (pa_volume_t) -1) if (v->values[c] == PA_VOLUME_INVALID)
return 0; return 0;
return 1; return 1;
@ -679,7 +679,7 @@ pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max) {
pa_assert(v); pa_assert(v);
pa_return_val_if_fail(pa_cvolume_valid(v), NULL); pa_return_val_if_fail(pa_cvolume_valid(v), NULL);
pa_return_val_if_fail(max != (pa_volume_t) -1, NULL); pa_return_val_if_fail(max != PA_VOLUME_INVALID, NULL);
t = pa_cvolume_max(v); t = pa_cvolume_max(v);

View file

@ -106,11 +106,14 @@ typedef uint32_t pa_volume_t;
/** Normal volume (100%, 0 dB) */ /** Normal volume (100%, 0 dB) */
#define PA_VOLUME_NORM ((pa_volume_t) 0x10000U) #define PA_VOLUME_NORM ((pa_volume_t) 0x10000U)
/** Muted volume (0%, -inf dB) */ /** Muted (minimal valid) volume (0%, -inf dB) */
#define PA_VOLUME_MUTED ((pa_volume_t) 0U) #define PA_VOLUME_MUTED ((pa_volume_t) 0U)
/** Maximum volume we can store. \since 0.9.15 */ /** Maximum valid volume we can store. \since 0.9.15 */
#define PA_VOLUME_MAX ((pa_volume_t) UINT32_MAX) #define PA_VOLUME_MAX ((pa_volume_t) UINT32_MAX-1)
/** Special 'invalid' volume. \since 0.9.16 */
#define PA_VOLUME_INVALID ((pa_volume_t) UINT32_MAX)
/** A structure encapsulating a per-channel volume */ /** A structure encapsulating a per-channel volume */
typedef struct pa_cvolume { typedef struct pa_cvolume {

View file

@ -335,12 +335,12 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t
pass_volume = TRUE; pass_volume = TRUE;
if (e->volume_is_set && volume != (pa_volume_t) -1) { if (e->volume_is_set && volume != PA_VOLUME_INVALID) {
pa_cvolume_set(&r, e->sample_spec.channels, volume); pa_cvolume_set(&r, e->sample_spec.channels, volume);
pa_sw_cvolume_multiply(&r, &r, &e->volume); pa_sw_cvolume_multiply(&r, &r, &e->volume);
} else if (e->volume_is_set) } else if (e->volume_is_set)
r = e->volume; r = e->volume;
else if (volume != (pa_volume_t) -1) else if (volume != PA_VOLUME_INVALID)
pa_cvolume_set(&r, e->sample_spec.channels, volume); pa_cvolume_set(&r, e->sample_spec.channels, volume);
else else
pass_volume = FALSE; pass_volume = FALSE;