[vlc-commits] libvlc: expose event for audio volume change (fixes #14568)
Rémi Denis-Courmont
git at videolan.org
Mon Jul 27 15:33:55 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jul 27 14:05:37 2015 +0300| [5f1b7491084e73b6ed732d6d6746a60cbf6dc65e] | committer: Rémi Denis-Courmont
libvlc: expose event for audio volume change (fixes #14568)
Cc: Harald Sitter <sitter at kde.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5f1b7491084e73b6ed732d6d6746a60cbf6dc65e
---
include/vlc/libvlc_events.h | 11 +++++++++++
lib/event.c | 2 ++
lib/media_player.c | 35 +++++++++++++++++++++++++++++++++++
src/audio_output/output.c | 11 +++++++++++
src/playlist/engine.c | 1 +
5 files changed, 60 insertions(+)
diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index a997d22..b0e6bc2 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -81,6 +81,8 @@ enum libvlc_event_e {
libvlc_MediaPlayerUncorked,
libvlc_MediaPlayerMuted,
libvlc_MediaPlayerUnmuted,
+ libvlc_MediaPlayerAudioVolume,
+ libvlc_MediaPlayerAudioDevice,
libvlc_MediaListItemAdded=0x200,
libvlc_MediaListWillAddItem,
@@ -244,6 +246,15 @@ typedef struct libvlc_event_t
libvlc_track_type_t i_type;
int i_id;
} media_player_es_changed;
+
+ struct
+ {
+ float volume;
+ } media_player_audio_volume;
+
+ struct
+ {
+
} u; /**< Type-dependent event description */
} libvlc_event_t;
diff --git a/lib/event.c b/lib/event.c
index f26af5c..7b42c53 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -287,6 +287,8 @@ static const event_name_t event_list[] = {
DEF(MediaPlayerUncorked)
DEF(MediaPlayerMuted)
DEF(MediaPlayerUnmuted)
+ DEF(MediaPlayerAudioVolume)
+ DEF(MediaPlayerAudioDevice)
DEF(MediaListItemAdded)
DEF(MediaListWillAddItem)
diff --git a/lib/media_player.c b/lib/media_player.c
index 5cf5bf1..778ef80 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -75,6 +75,10 @@ static int
mute_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
vlc_value_t cur, void *opaque);
+static int
+volume_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
+ vlc_value_t cur, void *opaque);
+
static void
add_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi );
@@ -487,6 +491,19 @@ static int corks_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
return VLC_SUCCESS;
}
+static int audio_device_changed(vlc_object_t *obj, const char *name,
+ vlc_value_t old, vlc_value_t cur, void *opaque)
+{
+ libvlc_media_player_t *mp = (libvlc_media_player_t *)obj;
+ libvlc_event_t event;
+
+ event.type = libvlc_MediaPlayerAudioDevice;
+ event.u.media_player_audio_device.device = cur.psz_string;
+ libvlc_event_send(mp->p_event_manager, &event);
+ VLC_UNUSED(name); VLC_UNUSED(old); VLC_UNUSED(opaque);
+ return VLC_SUCCESS;
+}
+
static int mute_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
vlc_value_t cur, void *opaque)
{
@@ -504,6 +521,19 @@ static int mute_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
return VLC_SUCCESS;
}
+static int volume_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
+ vlc_value_t cur, void *opaque)
+{
+ libvlc_media_player_t *mp = (libvlc_media_player_t *)obj;
+ libvlc_event_t event;
+
+ event.type = libvlc_MediaPlayerAudioVolume;
+ event.u.media_player_audio_volume.volume = cur.f_float;
+ libvlc_event_send(mp->p_event_manager, &event);
+ VLC_UNUSED(name); VLC_UNUSED(old); VLC_UNUSED(opaque);
+ return VLC_SUCCESS;
+}
+
/**************************************************************************
* Create a Media Instance object.
*
@@ -604,6 +634,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
/* Audio */
var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+ var_Create (mp, "audio-device", VLC_VAR_STRING);
var_Create (mp, "mute", VLC_VAR_BOOL);
var_Create (mp, "volume", VLC_VAR_FLOAT);
var_Create (mp, "corks", VLC_VAR_INTEGER);
@@ -683,7 +714,9 @@ libvlc_media_player_new( libvlc_instance_t *instance )
register_event(mp, Uncorked);
var_AddCallback(mp, "corks", corks_changed, NULL);
+ var_AddCallback(mp, "audio-device", audio_device_changed, NULL);
var_AddCallback(mp, "mute", mute_changed, NULL);
+ var_AddCallback(mp, "volume", volume_changed, NULL);
/* Snapshot initialization */
register_event(mp, SnapshotTaken);
@@ -735,7 +768,9 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
"snapshot-file", snapshot_was_taken, p_mi );
/* Detach callback from the media player / input manager object */
+ var_DelCallback( p_mi, "volume", volume_changed, NULL );
var_DelCallback( p_mi, "mute", mute_changed, NULL );
+ var_DelCallback( p_mi, "audio-device", audio_device_changed, NULL );
var_DelCallback( p_mi, "corks", corks_changed, NULL );
/* No need for lock_input() because no other threads knows us anymore */
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 2be34e7..d3c1bb9 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -64,6 +64,15 @@ static int var_Copy (vlc_object_t *src, const char *name, vlc_value_t prev,
return var_Set (dst, name, value);
}
+static int var_CopyDevice (vlc_object_t *src, const char *name,
+ vlc_value_t prev, vlc_value_t value, void *data)
+{
+ vlc_object_t *dst = data;
+
+ (void) src; (void) name; (void) prev;
+ return var_Set (dst, "audio-device", value);
+}
+
/**
* Supply or update the current custom ("hardware") volume.
* @note This only makes sense after calling aout_VolumeHardInit().
@@ -192,6 +201,7 @@ audio_output_t *aout_New (vlc_object_t *parent)
var_Create (aout, "mute", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
var_AddCallback (aout, "mute", var_Copy, parent);
var_Create (aout, "device", VLC_VAR_STRING);
+ var_AddCallback (aout, "device", var_CopyDevice, parent);
aout->event.volume_report = aout_VolumeNotify;
aout->event.mute_report = aout_MuteNotify;
@@ -324,6 +334,7 @@ void aout_Destroy (audio_output_t *aout)
aout_OutputUnlock (aout);
var_DelCallback (aout, "audio-filter", FilterCallback, NULL);
+ var_DelCallback (aout, "device", var_CopyDevice, aout->p_parent);
var_DelCallback (aout, "mute", var_Copy, aout->p_parent);
var_SetFloat (aout, "volume", -1.f);
var_DelCallback (aout, "volume", var_Copy, aout->p_parent);
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index c34be2d..6000a37 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -480,6 +480,7 @@ static void VariablesInit( playlist_t *p_playlist )
var_Create( p_playlist, "video-wallpaper", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
/* Audio output parameters */
+ var_Create( p_playlist, "audio-device", VLC_VAR_STRING );
var_Create( p_playlist, "mute", VLC_VAR_BOOL );
var_Create( p_playlist, "volume", VLC_VAR_FLOAT );
var_SetFloat( p_playlist, "volume", -1.f );
More information about the vlc-commits
mailing list