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

Thomas Guillem thomas at gllm.fr
Thu Oct 29 16:46:27 CET 2020


pushed, thanks !

On Thu, Oct 29, 2020, at 16:16, Prince Gupta wrote:
> ---
>  src/player/osd.c    | 42 +++++++++++++++++++++++++++++++++++++
>  src/player/player.c | 51 ++++++++++++++++++---------------------------
>  src/player/player.h |  3 +++
>  3 files changed, 65 insertions(+), 31 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..25ee6dd389 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 */
> @@ -499,38 +503,15 @@ vlc_player_SelectEsIdList(vlc_player_t *player,
>              .list.cat = cat,
>              .list.ids = allocated_ids,
>          });
> -    if (ret != VLC_SUCCESS)
> +    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 +682,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
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list