[vlc-devel] [PATCH] aout intf: implement functions to change volume and also show the appropriate osd text

David Fuhrmann david.fuhrmann at googlemail.com
Wed Feb 1 14:45:42 CET 2012


---
 include/vlc_aout_intf.h |    7 +++
 src/audio_output/intf.c |  114 +++++++++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym      |    2 +
 3 files changed, 123 insertions(+), 0 deletions(-)

diff --git a/include/vlc_aout_intf.h b/include/vlc_aout_intf.h
index e81f747..b08778a 100644
--- a/include/vlc_aout_intf.h
+++ b/include/vlc_aout_intf.h
@@ -36,8 +36,15 @@ VLC_API int aout_VolumeSet( vlc_object_t *, audio_volume_t );
 VLC_API int aout_VolumeUp( vlc_object_t *, int, audio_volume_t * );
 #define aout_VolumeUp(a, b, c) aout_VolumeUp(VLC_OBJECT(a), b, c)
 #define aout_VolumeDown(a, b, c) aout_VolumeUp(a, -(b), c)
+VLC_API int aout_VolumeUpWithOSD( vlc_object_t *, int, audio_volume_t * );
+#define aout_VolumeUpWithOSD(a, b, c) aout_VolumeUpWithOSD(VLC_OBJECT(a), b, c)
+#define aout_VolumeDownWithOSD(a, b, c) aout_VolumeUpWithOSD(a, -(b), c)
+
 VLC_API int aout_ToggleMute( vlc_object_t *, audio_volume_t * );
 #define aout_ToggleMute(a, b) aout_ToggleMute(VLC_OBJECT(a), b)
+VLC_API int aout_ToggleMuteWithOSD( vlc_object_t *, audio_volume_t * );
+#define aout_ToggleMuteWithOSD(a, b) aout_ToggleMuteWithOSD(VLC_OBJECT(a), b)
+
 VLC_API int aout_SetMute( vlc_object_t *, audio_volume_t *, bool );
 VLC_API bool aout_IsMuted( vlc_object_t * );
 
diff --git a/src/audio_output/intf.c b/src/audio_output/intf.c
index e8fff11..25c8215 100644
--- a/src/audio_output/intf.c
+++ b/src/audio_output/intf.c
@@ -41,6 +41,20 @@
 
 #include <vlc_playlist.h>
 
+#include <vlc_vout.h>
+#include <vlc_osd.h>
+
+#define CHANNELS_NUMBER 2
+#define VOLUME_TEXT_CHAN     p_channels[ 0 ]
+#define VOLUME_WIDGET_CHAN   p_channels[ 1 ]
+
+/*****************************************************************************
+ * some local variables
+ *****************************************************************************/
+vout_thread_t   *p_last_vout = NULL;
+int              p_channels[ CHANNELS_NUMBER ]; /* contains registered channel IDs */
+
+
 static audio_output_t *findAout (vlc_object_t *obj)
 {
     input_thread_t *(*pf_find_input) (vlc_object_t *);
@@ -59,6 +73,72 @@ static audio_output_t *findAout (vlc_object_t *obj)
 }
 #define findAout(o) findAout(VLC_OBJECT(o))
 
+static vout_thread_t *findVout (vlc_object_t *obj)
+{
+    input_thread_t *(*pf_find_input) (vlc_object_t *);
+
+    pf_find_input = var_GetAddress (obj, "find-input-callback");
+    if (unlikely(pf_find_input == NULL))
+        return NULL;
+
+    input_thread_t *p_input = pf_find_input (obj);
+    if (p_input == NULL)
+        return NULL;
+
+    vout_thread_t *p_vout = input_GetVout (p_input);
+    vlc_object_release (p_input);
+    return p_vout;
+}
+#define findVout(o) findVout(VLC_OBJECT(o))
+
+static void ClearChannels( vout_thread_t *p_vout )
+{
+    if( p_vout )
+    {
+        vout_FlushSubpictureChannel( p_vout, SPU_DEFAULT_CHANNEL );
+        for( int i = 0; i < CHANNELS_NUMBER; i++ )
+            vout_FlushSubpictureChannel( p_vout, p_channels[i] );
+    }
+}
+
+static void DisplayVolume( vlc_object_t *obj, audio_volume_t i_vol, bool b_isMuted )
+{
+    vout_thread_t *p_vout = findVout( obj );
+
+    if( p_vout == NULL )
+    {
+        return;
+    }
+
+    /* Register OSD channels */
+    /* FIXME: this check can fail if the new vout is reallocated at the same
+     * address as the old one... We should rather listen to vout events.
+     * Alternatively, we should keep a reference to the vout thread. */
+    if( p_vout && p_vout != p_last_vout )
+        for( unsigned i = 0; i < CHANNELS_NUMBER; i++ )
+            p_channels[i] = vout_RegisterSubpictureChannel( p_vout );
+    p_last_vout = p_vout;
+
+    ClearChannels( p_vout );
+
+    if( i_vol == 0 && b_isMuted )
+    {
+        vout_OSDIcon( p_vout, SPU_DEFAULT_CHANNEL, OSD_MUTE_ICON );
+    }
+    else
+    {
+        if( var_GetBool( p_vout, "fullscreen" ))
+        {
+            vout_OSDSlider( p_vout, VOLUME_WIDGET_CHAN,
+                           i_vol * 100 / AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
+        }
+        vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %d%%" ),
+                        i_vol * 100 / AOUT_VOLUME_DEFAULT );
+    }
+
+    vlc_object_release( p_vout );
+}
+
 /** Start a volume change transaction. */
 static void prepareVolume (vlc_object_t *obj, audio_output_t **aoutp,
                            audio_volume_t *volp, bool *mutep)
@@ -150,6 +230,23 @@ int aout_VolumeSet (vlc_object_t *obj, audio_volume_t volume)
     return commitVolume (obj, aout, volume, mute);
 }
 
+#undef aout_VolumeUpWithOSD
+/**
+ * Raises the volume and shows the appropriate osd text.
+ * \param value how much to increase (> 0) or decrease (< 0) the volume
+ * \param volp if non-NULL, will contain contain the resulting volume
+ */
+int aout_VolumeUpWithOSD (vlc_object_t *obj, int value, audio_volume_t *volp)
+{
+    audio_volume_t i_newvol;
+    int ret = aout_VolumeUp (obj, value, &i_newvol);
+    DisplayVolume (obj, i_newvol, false);
+
+    if (volp != NULL)
+        *volp = i_newvol;
+    return ret;
+}
+
 #undef aout_VolumeUp
 /**
  * Raises the volume.
@@ -180,9 +277,26 @@ int aout_VolumeUp (vlc_object_t *obj, int value, audio_volume_t *volp)
     return ret;
 }
 
+#undef aout_ToggleMuteWithOSD
+/**
+ * Toggles the mute state and shows the appropriate osd text.
+ * \param volp if non-NULL, will contain contain the resulting volume
+ */
+int aout_ToggleMuteWithOSD (vlc_object_t *obj, audio_volume_t *volp)
+{
+    audio_volume_t i_newvol;
+    int ret = aout_ToggleMute (obj, &i_newvol);
+    DisplayVolume (obj, i_newvol, true);
+
+    if (volp != NULL)
+        *volp = i_newvol;
+    return ret;
+}
+
 #undef aout_ToggleMute
 /**
  * Toggles the mute state.
+ * \param volp if non-NULL, will contain contain the resulting volume
  */
 int aout_ToggleMute (vlc_object_t *obj, audio_volume_t *volp)
 {
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 779d643..06880a7 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -26,7 +26,9 @@ aout_PacketNext
 aout_VolumeGet
 aout_VolumeSet
 aout_VolumeUp
+aout_VolumeUpWithOSD
 aout_ToggleMute
+aout_ToggleMuteWithOSD
 aout_IsMuted
 aout_SetMute
 aout_TimeReport
-- 
1.7.5.4




More information about the vlc-devel mailing list