volume: fix definition of PA_VOLUME_MAX and introduce PA_VOLUME_INVALID and use it...
authorLennart Poettering <lennart@poettering.net>
Mon, 7 Sep 2009 17:53:39 +0000 (19:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 7 Sep 2009 17:53:39 +0000 (19:53 +0200)
src/pulse/scache.c
src/pulse/scache.h
src/pulse/volume.c
src/pulse/volume.h
src/pulsecore/core-scache.c

index 77f60d7..43dc529 100644 (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_puts(t, dev);
 
-    if (volume == (pa_volume_t) -1 && c->version < 15)
+    if (volume == PA_VOLUME_INVALID && c->version < 15)
         volume = PA_VOLUME_NORM;
 
     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_puts(t, dev);
 
-    if (volume == (pa_volume_t) -1 && c->version < 15)
+    if (volume == PA_VOLUME_INVALID && c->version < 15)
         volume = PA_VOLUME_NORM;
 
     pa_tagstruct_putu32(t, volume);
index cd579d2..31cf7b0 100644 (file)
@@ -101,7 +101,7 @@ pa_operation* pa_context_play_sample(
         pa_context *c               /**< Context */,
         const char *name            /**< Name of the sample to play */,
         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 */,
         void *userdata              /**< Userdata to pass to the callback */);
 
@@ -113,7 +113,7 @@ pa_operation* pa_context_play_sample_with_proplist(
         pa_context *c                   /**< Context */,
         const char *name                /**< Name of the sample to play */,
         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_context_play_sample_cb_t cb  /**< Call this function after successfully starting playback, or NULL */,
         void *userdata                  /**< Userdata to pass to the callback */);
index 234c3f7..4991e5c 100644 (file)
@@ -64,7 +64,7 @@ pa_cvolume* pa_cvolume_init(pa_cvolume *a) {
     a->channels = 0;
 
     for (c = 0; c < PA_CHANNELS_MAX; c++)
-        a->values[c] = (pa_volume_t) -1;
+        a->values[c] = PA_VOLUME_INVALID;
 
     return a;
 }
@@ -307,7 +307,7 @@ char *pa_volume_snprint(char *s, size_t l, pa_volume_t v) {
 
     pa_init_i18n();
 
-    if (v == (pa_volume_t) -1) {
+    if (v == PA_VOLUME_INVALID) {
         pa_snprintf(s, l, _("(invalid)"));
         return s;
     }
@@ -357,7 +357,7 @@ char *pa_sw_volume_snprint_dB(char *s, size_t l, pa_volume_t v) {
 
     pa_init_i18n();
 
-    if (v == (pa_volume_t) -1) {
+    if (v == PA_VOLUME_INVALID) {
         pa_snprintf(s, l, _("(invalid)"));
         return s;
     }
@@ -459,7 +459,7 @@ int pa_cvolume_valid(const pa_cvolume *v) {
         return 0;
 
     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 1;
@@ -679,7 +679,7 @@ pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max) {
     pa_assert(v);
 
     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);
 
index 543b0af..c964020 100644 (file)
@@ -106,11 +106,14 @@ typedef uint32_t pa_volume_t;
 /** Normal volume (100%, 0 dB) */
 #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)
 
-/** Maximum volume we can store. \since 0.9.15 */
-#define PA_VOLUME_MAX ((pa_volume_t) UINT32_MAX)
+/** Maximum valid volume we can store. \since 0.9.15 */
+#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 */
 typedef struct pa_cvolume {
index fde12ec..1fb81d0 100644 (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;
 
-    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_sw_cvolume_multiply(&r, &r, &e->volume);
     } else if (e->volume_is_set)
         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);
     else
         pass_volume = FALSE;