[vlc-commits] player: include other selected tracks(if any) in osd_message when unselecting an es
Prince Gupta
git at videolan.org
Thu Oct 29 16:46:06 CET 2020
vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Thu Oct 29 21:04:33 2020 +0530| [0fd17069d5d4ba3fff32409f9433cbde60dd9685] | committer: Thomas Guillem
player: include other selected tracks(if any) in osd_message when unselecting an es
Signed-off-by: Thomas Guillem <thomas at gllm.fr>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0fd17069d5d4ba3fff32409f9433cbde60dd9685
---
src/player/osd.c | 42 ++++++++++++++++++++++++++++++++++++++++++
src/player/player.c | 50 ++++++++++++++++++++------------------------------
src/player/player.h | 3 +++
3 files changed, 65 insertions(+), 30 deletions(-)
diff --git a/src/player/osd.c b/src/player/osd.c
index ca163da215..99ce63967c 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 != NULL
+ && !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..f4b82a4bd2 100644
--- a/src/player/player.c
+++ b/src/player/player.c
@@ -477,8 +477,10 @@ 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)
+ if (allocated_ids == NULL || osd_ids == NULL)
return 0;
track_count = 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 */
@@ -500,37 +504,15 @@ vlc_player_SelectEsIdList(vlc_player_t *player,
.list.ids = allocated_ids,
});
if (ret != VLC_SUCCESS)
+ {
+ free(osd_ids);
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 +683,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 == NULL)
+ 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);
More information about the vlc-commits
mailing list