Commit 60e47a90 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: use float volume in internals and deal with errors

parent ac564301
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* calloc(), malloc(), free() */ #include <stdlib.h> /* calloc(), malloc(), free() */
#include <string.h> #include <string.h>
#include <math.h>
#include <vlc_aout.h> #include <vlc_aout.h>
#include "aout_internal.h" #include "aout_internal.h"
...@@ -61,7 +62,7 @@ static audio_output_t *findAout (vlc_object_t *obj) ...@@ -61,7 +62,7 @@ static audio_output_t *findAout (vlc_object_t *obj)
/** Start a volume change transaction. */ /** Start a volume change transaction. */
static void prepareVolume (vlc_object_t *obj, audio_output_t **aoutp, static void prepareVolume (vlc_object_t *obj, audio_output_t **aoutp,
audio_volume_t *volp, bool *mutep) float *vol, bool *mute)
{ {
audio_output_t *aout = findAout (obj); audio_output_t *aout = findAout (obj);
...@@ -72,41 +73,43 @@ static void prepareVolume (vlc_object_t *obj, audio_output_t **aoutp, ...@@ -72,41 +73,43 @@ static void prepareVolume (vlc_object_t *obj, audio_output_t **aoutp,
obj = VLC_OBJECT(aout); /* use aout volume if aout exists */ obj = VLC_OBJECT(aout); /* use aout volume if aout exists */
aout_lock_volume (aout); aout_lock_volume (aout);
} }
if (volp != NULL) if (vol != NULL)
*volp = var_InheritInteger (obj, "volume"); *vol = var_InheritInteger (obj, "volume") / (float)AOUT_VOLUME_DEFAULT;
if (mutep != NULL) if (mute != NULL)
*mutep = var_InheritBool (obj, "mute"); *mute = var_InheritBool (obj, "mute");
} }
/** Commit a volume change transaction. */ /** Commit a volume change transaction. */
static int commitVolume (vlc_object_t *obj, audio_output_t *aout, static int commitVolume (vlc_object_t *obj, audio_output_t *aout,
audio_volume_t volume, bool mute) float vol, bool mute)
{ {
long volume = lroundf (vol * AOUT_VOLUME_DEFAULT);
int ret = 0; int ret = 0;
/* update caller (input manager) volume */
var_SetInteger (obj, "volume", volume);
var_SetBool (obj, "mute", mute);
if (var_InheritBool (obj, "volume-save"))
config_PutInt (obj, "volume", volume);
if (aout != NULL) if (aout != NULL)
{ {
float vol = volume / (float)AOUT_VOLUME_DEFAULT;
/* apply volume to the pipeline */ /* apply volume to the pipeline */
aout_lock (aout); aout_lock (aout);
if (aout->pf_volume_set != NULL) if (aout->pf_volume_set != NULL)
ret = aout->pf_volume_set (aout, vol, mute); ret = aout->pf_volume_set (aout, vol, mute);
aout_unlock (aout); aout_unlock (aout);
/* update aout volume if it maintains its own */ if (ret == 0)
{ /* update aout volume if it maintains its own */
var_SetInteger (aout, "volume", volume); var_SetInteger (aout, "volume", volume);
var_SetBool (aout, "mute", mute); var_SetBool (aout, "mute", mute);
}
aout_unlock_volume (aout); aout_unlock_volume (aout);
vlc_object_release (aout); vlc_object_release (aout);
} }
if (ret == 0)
{ /* update caller (input manager) volume */
var_SetInteger (obj, "volume", volume);
var_SetBool (obj, "mute", mute);
if (var_InheritBool (obj, "volume-save"))
config_PutInt (obj, "volume", volume);
}
return ret; return ret;
} }
...@@ -128,11 +131,11 @@ static void cancelVolume (vlc_object_t *obj, audio_output_t *aout) ...@@ -128,11 +131,11 @@ static void cancelVolume (vlc_object_t *obj, audio_output_t *aout)
audio_volume_t aout_VolumeGet (vlc_object_t *obj) audio_volume_t aout_VolumeGet (vlc_object_t *obj)
{ {
audio_output_t *aout; audio_output_t *aout;
audio_volume_t volume; float vol;
prepareVolume (obj, &aout, &volume, NULL); prepareVolume (obj, &aout, &vol, NULL);
cancelVolume (obj, aout); cancelVolume (obj, aout);
return volume; return lroundf (vol * AOUT_VOLUME_DEFAULT);
} }
#undef aout_VolumeSet #undef aout_VolumeSet
...@@ -143,10 +146,11 @@ audio_volume_t aout_VolumeGet (vlc_object_t *obj) ...@@ -143,10 +146,11 @@ audio_volume_t aout_VolumeGet (vlc_object_t *obj)
int aout_VolumeSet (vlc_object_t *obj, audio_volume_t volume) int aout_VolumeSet (vlc_object_t *obj, audio_volume_t volume)
{ {
audio_output_t *aout; audio_output_t *aout;
float vol = volume / (float)AOUT_VOLUME_DEFAULT;
bool mute; bool mute;
prepareVolume (obj, &aout, NULL, &mute); prepareVolume (obj, &aout, NULL, &mute);
return commitVolume (obj, aout, volume, mute); return commitVolume (obj, aout, vol, mute);
} }
#undef aout_VolumeUp #undef aout_VolumeUp
...@@ -159,23 +163,20 @@ int aout_VolumeUp (vlc_object_t *obj, int value, audio_volume_t *volp) ...@@ -159,23 +163,20 @@ int aout_VolumeUp (vlc_object_t *obj, int value, audio_volume_t *volp)
{ {
audio_output_t *aout; audio_output_t *aout;
int ret; int ret;
audio_volume_t volume; float vol;
bool mute; bool mute;
value *= var_InheritInteger (obj, "volume-step"); value *= var_InheritInteger (obj, "volume-step");
prepareVolume (obj, &aout, &volume, &mute); prepareVolume (obj, &aout, &vol, &mute);
value += volume; vol += value / (float)AOUT_VOLUME_DEFAULT;
if (value < 0) if (vol < 0.)
volume = 0; vol = 0.;
else if (vol > (AOUT_VOLUME_MAX / AOUT_VOLUME_DEFAULT))
if (value > AOUT_VOLUME_MAX) vol = AOUT_VOLUME_MAX / AOUT_VOLUME_DEFAULT;
volume = AOUT_VOLUME_MAX; ret = commitVolume (obj, aout, vol, mute);
else
volume = value;
ret = commitVolume (obj, aout, volume, mute);
if (volp != NULL) if (volp != NULL)
*volp = volume; *volp = lroundf (vol * AOUT_VOLUME_DEFAULT);
return ret; return ret;
} }
...@@ -187,14 +188,14 @@ int aout_ToggleMute (vlc_object_t *obj, audio_volume_t *volp) ...@@ -187,14 +188,14 @@ int aout_ToggleMute (vlc_object_t *obj, audio_volume_t *volp)
{ {
audio_output_t *aout; audio_output_t *aout;
int ret; int ret;
audio_volume_t volume; float vol;
bool mute; bool mute;
prepareVolume (obj, &aout, &volume, &mute); prepareVolume (obj, &aout, &vol, &mute);
mute = !mute; mute = !mute;
ret = commitVolume (obj, aout, volume, mute); ret = commitVolume (obj, aout, vol, mute);
if (volp != NULL) if (volp != NULL)
*volp = mute ? 0 : volume; *volp = lroundf (vol * AOUT_VOLUME_DEFAULT);
return ret; return ret;
} }
...@@ -218,12 +219,12 @@ int aout_SetMute (vlc_object_t *obj, audio_volume_t *volp, bool mute) ...@@ -218,12 +219,12 @@ int aout_SetMute (vlc_object_t *obj, audio_volume_t *volp, bool mute)
{ {
audio_output_t *aout; audio_output_t *aout;
int ret; int ret;
audio_volume_t volume; float vol;
prepareVolume (obj, &aout, &volume, NULL); prepareVolume (obj, &aout, &vol, NULL);
ret = commitVolume (obj, aout, volume, mute); ret = commitVolume (obj, aout, vol, mute);
if (volp != NULL) if (volp != NULL)
*volp = mute ? 0 : volume; *volp = mute ? 0 : lroundf (vol * AOUT_VOLUME_DEFAULT);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment