[vlc-devel] [PATCHv3 10/17] lib: update media_player track events

Thomas Guillem thomas at gllm.fr
Wed Jun 10 14:57:49 CEST 2020


Use the string identifier from track events.
---
 include/vlc/libvlc_events.h | 23 ++++++++++++++++++++++-
 lib/media_player.c          | 36 ++++++++++++++++++++++++------------
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 73bddb9de99..6c3ea15e9b4 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -110,8 +110,15 @@ enum libvlc_event_e {
     libvlc_MediaPlayerLengthChanged,
     libvlc_MediaPlayerVout,
     libvlc_MediaPlayerScrambledChanged,
+    /** A track was added, cf. media_player_es_changed in \ref libvlc_event_t.u
+     * to get the id of the new track. */
     libvlc_MediaPlayerESAdded,
+    /** A track was removed, cf. media_player_es_changed in \ref
+     * libvlc_event_t.u to get the id of the removed track. */
     libvlc_MediaPlayerESDeleted,
+    /** Tracks were selected or unselected, cf.
+     * media_player_es_selection_changed in \ref libvlc_event_t.u to get the
+     * unselected and/or the selected track ids. */
     libvlc_MediaPlayerESSelected,
     libvlc_MediaPlayerCorked,
     libvlc_MediaPlayerUncorked,
@@ -119,6 +126,9 @@ enum libvlc_event_e {
     libvlc_MediaPlayerUnmuted,
     libvlc_MediaPlayerAudioVolume,
     libvlc_MediaPlayerAudioDevice,
+    /** A track was updated, cf. media_player_es_changed in \ref
+     * libvlc_event_t.u to get the id of the updated track. */
+    libvlc_MediaPlayerESUpdated,
     /**
      * The title list changed, call
      * libvlc_media_player_get_full_title_descriptions() to get the new list.
@@ -342,12 +352,23 @@ typedef struct libvlc_event_t
             libvlc_media_t * new_media;
         } media_player_media_changed;
 
+        /* ESAdded, ESDeleted, ESUpdated */
         struct
         {
             libvlc_track_type_t i_type;
-            int                 i_id;
+            /** Call libvlc_media_player_get_track_from_id() to get the track
+             * description. */
+            const char *psz_id;
         } media_player_es_changed;
 
+        /* ESSelected */
+        struct
+        {
+            libvlc_track_type_t i_type;
+            const char *psz_unselected_id;
+            const char *psz_selected_id;
+        } media_player_es_selection_changed;
+
         struct
         {
             float volume;
diff --git a/lib/media_player.c b/lib/media_player.c
index 0ac10ba38f0..c512a04f114 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -251,17 +251,19 @@ on_track_list_changed(vlc_player_t *player, enum vlc_player_list_action action,
     libvlc_media_player_t *mp = data;
 
     libvlc_event_t event;
-    if (action == VLC_PLAYER_LIST_ADDED)
-        event.type = libvlc_MediaPlayerESAdded;
-    else if (action == VLC_PLAYER_LIST_REMOVED)
-        event.type = libvlc_MediaPlayerESDeleted;
-    else
-        /* no event to forward */
-        return;
+    switch (action)
+    {
+        case VLC_PLAYER_LIST_ADDED:
+            event.type = libvlc_MediaPlayerESAdded; break;
+        case VLC_PLAYER_LIST_REMOVED:
+            event.type = libvlc_MediaPlayerESDeleted; break;
+        case VLC_PLAYER_LIST_UPDATED:
+            event.type = libvlc_MediaPlayerESUpdated; break;
+    }
 
     event.u.media_player_es_changed.i_type =
         track_type_from_cat(track->fmt.i_cat);
-    event.u.media_player_es_changed.i_id = vlc_es_id_GetInputId(track->es_id);
+    event.u.media_player_es_changed.psz_id = vlc_es_id_GetStrId(track->es_id);
 
     libvlc_event_send(&mp->event_manager, &event);
 }
@@ -278,14 +280,24 @@ on_track_selection_changed(vlc_player_t *player, vlc_es_id_t *unselected_id,
     libvlc_event_t event;
     event.type = libvlc_MediaPlayerESSelected;
 
+    if (unselected_id)
+    {
+        enum es_format_category_e cat = vlc_es_id_GetCat(unselected_id);
+        event.u.media_player_es_selection_changed.i_type = track_type_from_cat(cat);
+    }
     if (selected_id)
     {
         enum es_format_category_e cat = vlc_es_id_GetCat(selected_id);
-        event.u.media_player_es_changed.i_type = track_type_from_cat(cat);
-        event.u.media_player_es_changed.i_id =
-            vlc_es_id_GetInputId(selected_id);
-        libvlc_event_send(&mp->event_manager, &event);
+        event.u.media_player_es_selection_changed.i_type = track_type_from_cat(cat);
     }
+
+    event.u.media_player_es_selection_changed.psz_unselected_id =
+        unselected_id ? vlc_es_id_GetStrId(unselected_id) : NULL;
+
+    event.u.media_player_es_selection_changed.psz_selected_id =
+        selected_id ? vlc_es_id_GetStrId(selected_id) : NULL;
+
+    libvlc_event_send(&mp->event_manager, &event);
 }
 
 static void
-- 
2.20.1



More information about the vlc-devel mailing list