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

Thomas Guillem thomas at gllm.fr
Mon Oct 26 13:46:01 CET 2020



On Mon, Oct 26, 2020, at 13:33, Prince Gupta wrote:
> ---
>  src/player/osd.c    | 41 +++++++++++++++++++++++++++++++++++++++++
>  src/player/player.c | 11 +++++++++--
>  src/player/player.h |  3 +++
>  3 files changed, 53 insertions(+), 2 deletions(-)
> 
> diff --git a/src/player/osd.c b/src/player/osd.c
> index ca163da215..b3469b5b03 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,46 @@ 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 **selected, 
> vlc_es_id_t *unselect)
> +{
> +    if ( !selected )
> +        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..b8d7b38de2 100644
> --- a/src/player/player.c
> +++ b/src/player/player.c
> @@ -701,8 +701,15 @@ 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 );

You leak selected_es. Maybe it should be fetched from the vlc_player_osd_Tracks() function.

This function could take a selected_id and a unselected_id.
It fetches the list internally, and compare with selected_id, unselected_id accordingly.

Because, here you are using it from vlc_player_UnselectEsId(), but why not using it from vlc_player_SelectEsId() ?

>  }
>  
>  void
> diff --git a/src/player/player.h b/src/player/player.h
> index fde4b1dbf3..2f168741e3 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 **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