[vlc-devel] [PATCH 06/20] player: add vlc_player_SelectEsIdList

Thomas Guillem thomas at gllm.fr
Thu Jun 20 18:10:26 CEST 2019


On Thu, Jun 20, 2019, at 17:51, Rémi Denis-Courmont wrote:
> Hi,
> 
> You could use memstream_puts directly here.

Indeed.

> 
> Le 20 juin 2019 18:23:49 GMT+03:00, Thomas Guillem <thomas at gllm.fr> a écrit :
>> From: Roland Bewick <roland.bewick at gmail.com>
>> 
>> Signed-off-by: Thomas Guillem <thomas at gllm.fr> include/vlc_player.h | 26 +++++++++++++++++
>>  src/input/player.c   | 68 ++++++++++++++++++++++++++++++++++++++++++++
>>  src/libvlccore.sym   |  1 +
>>  3 files changed, 95 insertions(+)
>> 
>> diff --git a/include/vlc_player.h b/include/vlc_player.h
>> index 225051447a..4fcf4f0bb7 100644
>> --- a/include/vlc_player.h
>> +++ b/include/vlc_player.h
>> @@ -1749,6 +1749,32 @@ vlc_player_SelectTrack(vlc_player_t *player,
>>      vlc_player_SelectEsId(player, track->es_id);
>>  }
>>  
>> +/**
>> + * Select multiple tracks from a list of ES identifiers.
>> + *
>> + * Any tracks of the category, not referenced in the list will be unselected.
>> + *
>> + * @warning there is no guarantee all requested tracks will be selected.
>> + * Only one audio track can be selected at a time. Two subtitle tracks
>> + * can be selected simultaneously.
>> + *
>> + * @warning behaviour is undefined if the list is not null-terminated.
>> + *
>> + * @note A successful call will trigger the
>> + * vlc_player_cbs.on_track_selection_changed event for each track that has
>> + * its selection state changed.
>> + *
>> + * @param player locked player instance
>> + * @param cat VIDEO_ES, AUDIO_ES or SPU_ES
>> + * @param es_id_list a null-terminated list of ES identifiers.
>> + * (ES IDs can be retrieved from vlc_player_cbs.on_track_list_changed or
>> + * vlc_player_GetTrackAt())
>> + */
>> +VLC_API void
>> +vlc_player_SelectEsIdList(vlc_player_t *player,
>> +                          enum es_format_category_e cat,
>> +                          vlc_es_id_t *const es_id_list[]);
>> +
>>  /**
>>   * Select the next track
>>   *
>> diff --git a/src/input/player.c b/src/input/player.c
>> index fd0ef7f8ea..358502d21b 100644
>> --- a/src/input/player.c
>> +++ b/src/input/player.c
>> @@ -32,6 +32,7 @@
>>  #include <vlc_atomic.h>
>>  #include <vlc_tick.h>
>>  #include <vlc_decoder.h>
>> +#include <vlc_memstream.h>
>>  
>>  #include "libvlc.h"
>>  #include "input_internal.h"
>> @@ -1394,6 +1395,73 @@ vlc_player_SelectEsId(vlc_player_t *player, vlc_es_id_t *id)
>>      vlc_player_vout_OSDTrack(player, id, true);
>>  }
>>  
>> +void
>> +vlc_player_SelectEsIdList(vlc_player_t *player,
>> +                          enum es_format_category_e cat,
>> +                          vlc_es_id_t *const es_id_list[])
>> +{
>> +    struct vlc_player_input *input = vlc_player_get_input_locked(player);
>> +    if (!input)
>> +        return;
>> +
>> +    /* First, count and hold all the ES Ids.
>> +       Ids will be released in input.c:ControlRelease */
>> +    size_t id_count;
>> +    for (id_count = 0; es_id_list[id_count] != NULL; id_count++);
>> +
>> +    /* Copy es_id_list into an allocated list so that it remains in memory until
>> +       selection completes. The list will be freed in input.c:ControlRelease */
>> +    struct vlc_es_id_t **allocated_ids =
>> +        vlc_alloc(id_count + 1, sizeof(vlc_es_id_t *));
>> +
>> +    if (allocated_ids == NULL)
>> +        return;
>> +
>> +    for (size_t i = 0; i < id_count; i++)
>> +    {
>> +        vlc_es_id_t *es_id = es_id_list[i];
>> +
>> +        vlc_es_id_Hold(es_id);
>> +        allocated_ids[i] = es_id;
>> +    }
>> +    allocated_ids[id_count] = NULL;
>> +
>> +    /* Attempt to select all the requested tracks */
>> +    input_ControlPush(input->thread, INPUT_CONTROL_SET_ES_LIST,
>> +        &(input_control_param_t) {
>> +            .list.cat = cat,
>> +            .list.ids = allocated_ids,
>> +        });
>> +
>> +    /* Display track selection message */
>> +    const char *cat_name = es_format_category_to_string(cat);
>> +    if (id_count == 0)
>> +        vlc_player_vout_OSDMessage(player, _("%s track: %s"), cat_name,
>> +                                   _("N/A"));
>> +    else if (id_count == 1)
>> +        vlc_player_vout_OSDTrack(player, es_id_list[0], true);
>> +    else
>> +    {
>> +        struct vlc_memstream stream;
>> +        vlc_memstream_open(&stream);
>> +        for (size_t i = 0; i < id_count; i++)
>> +        {
>> +            const struct vlc_player_track *track =
>> +                vlc_player_GetTrack(player, es_id_list[i]);
>> +
>> +            if (track)
>> +                vlc_memstream_printf(&stream, "%s%s",
>> +                                     i == 0 ? "" : ", ", track->name);
>> +        }
>> +        if (vlc_memstream_close(&stream) == 0)
>> +        {
>> +            vlc_player_vout_OSDMessage(player, _("%s tracks: %s"), cat_name,
>> +                                       stream.ptr);
>> +            free(stream.ptr);
>> +        }
>> +    }
>> +}
>> +
>>  static void
>>  vlc_player_CycleTrack(vlc_player_t *player, enum es_format_category_e cat,
>>                        bool next)
>> diff --git a/src/libvlccore.sym b/src/libvlccore.sym
>> index 7432848866..3c11a9fefd 100644
>> --- a/src/libvlccore.sym
>> +++ b/src/libvlccore.sym
>> @@ -834,6 +834,7 @@ vlc_player_SelectCategoryLanguage
>>  vlc_player_SelectChapter
>>  vlc_player_SelectChapterIdx
>>  vlc_player_SelectEsId
>> +vlc_player_SelectEsIdList
>>  vlc_player_SelectNextChapter
>>  vlc_player_SelectNextTitle
>>  vlc_player_SelectNextTrack
> 
> -- 
> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté. 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20190620/c11089b3/attachment.html>


More information about the vlc-devel mailing list