[vlc-devel] [PATCH 1/5] player: add on_device_changed callback

Romain Vimont rom1v at videolabs.io
Thu May 9 17:56:54 CEST 2019


Expose the "device" event on the aout via a player callback.
---
 include/vlc_player.h | 9 +++++++++
 src/input/player.c   | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index 17e927c948..fdd2709ac3 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -923,6 +923,15 @@ struct vlc_player_aout_cbs
      */
     void (*on_mute_changed)(vlc_player_t *player,
         bool new_muted, void *data);
+
+    /**
+     * Called when the audio device has changed
+     *
+     * @param player unlocked player instance
+     * @param device the device name
+     */
+    void (*on_device_changed)(vlc_player_t *player, const char *device,
+                              void *data);
 };
 
 /**
diff --git a/src/input/player.c b/src/input/player.c
index f43f9f71a5..2045028aab 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -3043,6 +3043,12 @@ vlc_player_AoutCallback(vlc_object_t *this, const char *var,
             vlc_player_vout_OSDVolume(player, true);
         }
     }
+    else if (strcmp(var, "device") == 0)
+    {
+        if (strcmp(oldval.psz_string, newval.psz_string) != 0)
+            vlc_player_aout_SendEvent(player, on_device_changed,
+                                      newval.psz_string);
+    }
     else
         vlc_assert_unreachable();
 
@@ -3569,6 +3575,7 @@ vlc_player_New(vlc_object_t *parent,
     {
         var_AddCallback(aout, "volume", vlc_player_AoutCallback, player);
         var_AddCallback(aout, "mute", vlc_player_AoutCallback, player);
+        var_AddCallback(aout, "device", vlc_player_AoutCallback, player);
         var_AddCallback(player, "corks", vlc_player_CorkCallback, NULL);
         input_resource_PutAout(player->resource, aout);
     }
@@ -3590,6 +3597,7 @@ error:
     {
         var_DelCallback(aout, "volume", vlc_player_AoutCallback, player);
         var_DelCallback(aout, "mute", vlc_player_AoutCallback, player);
+        var_DelCallback(aout, "device", vlc_player_AoutCallback, player);
         var_DelCallback(player, "corks", vlc_player_AoutCallback, NULL);
     }
     if (player->resource)
-- 
2.20.1



More information about the vlc-devel mailing list