[vlc-devel] [PATCH 02/22] player: include other selected tracks(if any) in osd_message when unselecting an es

Prince Gupta guptaprince8832 at gmail.com
Mon Oct 26 14:51:52 CET 2020


---
 src/player/osd.c    | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/player/player.c | 45 ++++++++++++++++-----------------------------
 src/player/player.h |  3 +++
 3 files changed, 61 insertions(+), 29 deletions(-)

diff --git a/src/player/osd.c b/src/player/osd.c
index ca163da215..11db06a813 100644
--- a/src/player/osd.c
+++ b/src/player/osd.c
@@ -25,6 +25,7 @@
 #include <limits.h>
 
 #include <vlc_common.h>
+#include <vlc_memstream.h>
 #include "player.h"
 #include "input/resource.h"
 
@@ -199,6 +200,47 @@ vlc_player_osd_Track(vlc_player_t *player, vlc_es_id_t *id, bool select)
     vlc_player_osd_Message(player, _("%s track: %s"), cat_name, track_name);
 }
 
+void
+vlc_player_osd_Tracks(vlc_player_t *player, vlc_es_id_t * const *selected, vlc_es_id_t *unselect)
+{
+    if ( !selected || !selected[0] )
+        return;
+
+    const enum es_format_category_e cat = vlc_es_id_GetCat( selected[0] );
+    const char *cat_name = es_format_category_to_string(cat);
+    int tracks_count = 0;
+    struct vlc_memstream stream;
+    vlc_memstream_open(&stream);
+
+    for (size_t i = 0; selected[i] != NULL; i++)
+    {
+        if ( unselect && !strcmp( vlc_es_id_GetStrId( selected[i] ), vlc_es_id_GetStrId( unselect )) )
+            continue;
+
+        const struct vlc_player_track *track =
+            vlc_player_GetTrack(player, selected[i]);
+        if ( track )
+        {
+            if ( tracks_count != 0 )
+                vlc_memstream_puts(&stream, ", ");
+            vlc_memstream_puts(&stream, track->name);
+            tracks_count++;
+        }
+    }
+    if (vlc_memstream_close(&stream) == 0 && tracks_count != 0)
+    {
+        if ( tracks_count == 1 )
+            vlc_player_osd_Message(player, _("%s track: %s"), cat_name,
+                                   stream.ptr);
+        else
+            vlc_player_osd_Message(player, _("%s tracks: %s"), cat_name,
+                                   stream.ptr);
+        free(stream.ptr);
+    } else if (tracks_count == 0) {
+        vlc_player_osd_Message(player, _("%s track: %s"), cat_name, _("N/A"));
+    }
+}
+
 void
 vlc_player_osd_Program(vlc_player_t *player, const char *name)
 {
diff --git a/src/player/player.c b/src/player/player.c
index 669df87649..796c62e1c0 100644
--- a/src/player/player.c
+++ b/src/player/player.c
@@ -477,6 +477,8 @@ vlc_player_SelectEsIdList(vlc_player_t *player,
        selection completes. The list will be freed in input.c:ControlRelease */
     struct vlc_es_id_t **allocated_ids =
         vlc_alloc(track_count + 1, sizeof(vlc_es_id_t *));
+    struct vlc_es_id_t **osd_ids = // create two copies, one for osd message,
+        vlc_alloc(track_count + 1, sizeof(vlc_es_id_t *));
 
     if (allocated_ids == NULL)
         return 0;
@@ -488,9 +490,11 @@ vlc_player_SelectEsIdList(vlc_player_t *player,
         if (vlc_es_id_GetCat(es_id_list[i]) == cat)
         {
             vlc_es_id_Hold(es_id);
+            osd_ids[track_count] = es_id;
             allocated_ids[track_count++] = es_id;
         }
     }
+    osd_ids[track_count] = NULL;
     allocated_ids[track_count] = NULL;
 
     /* Attempt to select all the requested tracks */
@@ -503,34 +507,9 @@ vlc_player_SelectEsIdList(vlc_player_t *player,
         return 0;
 
     /* Display track selection message */
-    const char *cat_name = es_format_category_to_string(cat);
-    if (track_count == 0)
-        vlc_player_osd_Message(player, _("%s track: %s"), cat_name, _("N/A"));
-    else if (track_count == 1)
-        vlc_player_osd_Track(player, es_id_list[0], true);
-    else
-    {
-        struct vlc_memstream stream;
-        vlc_memstream_open(&stream);
-        for (size_t i = 0; i < track_count; i++)
-        {
-            const struct vlc_player_track *track =
-                vlc_player_GetTrack(player, es_id_list[i]);
+    vlc_player_osd_Tracks( player, osd_ids, NULL );
+    free( osd_ids );
 
-            if (track)
-            {
-                if (i != 0)
-                    vlc_memstream_puts(&stream, ", ");
-                vlc_memstream_puts(&stream, track->name);
-            }
-        }
-        if (vlc_memstream_close(&stream) == 0)
-        {
-            vlc_player_osd_Message(player, _("%s tracks: %s"), cat_name,
-                                   stream.ptr);
-            free(stream.ptr);
-        }
-    }
     return track_count;
 }
 
@@ -701,8 +680,16 @@ vlc_player_UnselectEsId(vlc_player_t *player, vlc_es_id_t *id)
 
     int ret = input_ControlPushEsHelper(input->thread, INPUT_CONTROL_UNSET_ES,
                                         id);
-    if (ret == VLC_SUCCESS)
-        vlc_player_osd_Track(player, id, false);
+    if ( ret != VLC_SUCCESS )
+        return;
+
+    const enum es_format_category_e cat = vlc_es_id_GetCat( id );
+    vlc_es_id_t ** selected_es = vlc_player_GetEsIdList( player, cat, NULL );
+    if ( !selected_es )
+        return;
+
+    vlc_player_osd_Tracks( player, selected_es, id );
+    free( selected_es );
 }
 
 void
diff --git a/src/player/player.h b/src/player/player.h
index fde4b1dbf3..ae5a2770d6 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -518,6 +518,9 @@ vlc_player_vout_OSDCallback(vlc_object_t *this, const char *var,
 void
 vlc_player_osd_Track(vlc_player_t *player, vlc_es_id_t *id, bool select);
 
+void
+vlc_player_osd_Tracks(vlc_player_t *player, vlc_es_id_t * const*selected, vlc_es_id_t *unselect);
+
 void
 vlc_player_osd_Program(vlc_player_t *player, const char *name);
 
-- 
2.25.1



More information about the vlc-devel mailing list