[vlc-commits] player: add on_device_changed callback

Romain Vimont git at videolan.org
Wed May 22 22:04:27 CEST 2019


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Mon May  6 15:08:54 2019 +0200| [fb5b4934df98701e76003f9c98367e662775181f] | committer: Jean-Baptiste Kempf

player: add on_device_changed callback

Expose the "device" event on the aout via a player callback.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fb5b4934df98701e76003f9c98367e662775181f
---

 include/vlc_player.h |  9 +++++++++
 src/input/player.c   | 11 +++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index d4c49fa89d..054c4abae3 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -944,6 +944,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 e01701ba65..e81c717f36 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -3044,6 +3044,15 @@ vlc_player_AoutCallback(vlc_object_t *this, const char *var,
             vlc_player_vout_OSDVolume(player, true);
         }
     }
+    else if (strcmp(var, "device") == 0)
+    {
+        const char *old = oldval.psz_string;
+        const char *new = newval.psz_string;
+        /* support NULL values for string comparison */
+        if (old != new && (!old || !new || strcmp(old, new)))
+            vlc_player_aout_SendEvent(player, on_device_changed,
+                                      newval.psz_string);
+    }
     else
         vlc_assert_unreachable();
 
@@ -3513,6 +3522,7 @@ vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,
     {
         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);
     }
@@ -3534,6 +3544,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)



More information about the vlc-commits mailing list