[vlc-devel] [PATCHv2 05/13] input/item: add slave entries

Thomas Guillem thomas at gllm.fr
Fri May 13 16:58:19 CEST 2016



On Thu, May 5, 2016, at 12:09, Rémi Denis-Courmont wrote:
> On Tuesday 03 May 2016 19:02:32 Thomas Guillem wrote:
> > From: Benjamin Adolphi <b.adolphi at gmail.com>
> > 
> > An input_item_t can now have a list of slaves. These slaves will be loaded
> > when the input_item_t is loaded by an input_thread_t.
> > 
> > Signed-off-by: Thomas Guillem <thomas at gllm.fr>
> > ---
> >  include/vlc_common.h     |  1 +
> >  include/vlc_input_item.h | 49 +++++++++++++++++++++++++++++
> >  src/input/item.c         | 82
> > ++++++++++++++++++++++++++++++++++++++++++++++++ src/libvlccore.sym       |
> >  4 +++
> >  4 files changed, 136 insertions(+)
> > 
> > diff --git a/include/vlc_common.h b/include/vlc_common.h
> > index f05d9c6..088067e 100644
> > --- a/include/vlc_common.h
> > +++ b/include/vlc_common.h
> > @@ -221,6 +221,7 @@ typedef struct config_category_t config_category_t;
> >  typedef struct input_thread_t input_thread_t;
> >  typedef struct input_item_t input_item_t;
> >  typedef struct input_item_node_t input_item_node_t;
> > +typedef struct input_item_slave input_item_slave;
> >  typedef struct access_t access_t;
> >  typedef struct access_sys_t access_sys_t;
> >  typedef struct stream_t     stream_t;
> 
> This should not be necessary here. We don´t use vlc_symbols anymore.
> 
> > diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
> > index 9144fbb..1f83c95 100644
> > --- a/include/vlc_input_item.h
> > +++ b/include/vlc_input_item.h
> > @@ -51,6 +51,13 @@ struct info_category_t
> >      struct info_t **pp_infos;     /**< Pointer to an array of infos */
> >  };
> > 
> > +struct input_item_slave
> > +{
> > +    char        *psz_uri;   /**< Slave mrl */
> > +    uint8_t     i_type;     /**< Slave type (spu, audio, ... see
> > slave_type_e) */
> > +    uint8_t     i_priority; /**< Slave priority */
> > +};
> 
> Probably simpler with flexible array for psz_uri.
> 
> > +
> >  /**
> >   * Describes an input and is used to spawn input_thread_t objects.
> >   */
> > @@ -83,6 +90,10 @@ struct input_item_t
> >      int         i_epg;               /**< Number of EPG entries */
> >      vlc_epg_t   **pp_epg;            /**< EPG entries */
> > 
> > +    int         i_slaves;            /**< Number of slaves */
> > +    input_item_slave **pp_slaves;    /**< Slave entries that will be loaded
> > by
> > +                                          the input_thread */
> > +
> >      vlc_event_manager_t event_manager;
> > 
> >      vlc_mutex_t lock;                 /**< Lock for the item */
> > @@ -123,6 +134,34 @@ enum input_item_net_type
> >      ITEM_LOCAL
> >  };
> > 
> > +enum slave_type
> > +{
> > +    SLAVE_TYPE_SPU,
> > +    SLAVE_TYPE_AUDIO,
> > +};
> > +
> > +enum slave_priotity
> > +{
> > +    SLAVE_PRIORITY_NONE        = 0,
> > +    SLAVE_PRIORITY_MATCH_NONE  = 1,
> > +    SLAVE_PRIORITY_MATCH_RIGHT = 2,
> > +    SLAVE_PRIORITY_MATCH_LEFT  = 3,
> > +    SLAVE_PRIORITY_MATCH_ALL   = 4,
> > +    SLAVE_PRIORITY_USER        = 5,
> > +};
> > +
> > +#define SLAVE_SPU_EXTENSIONS \
> > +    "idx", "sub",  "srt", \
> > +    "ssa", "ass",  "smi", \
> > +    "utf", "utf8", "utf-8", \
> > +    "rt",   "aqt", "txt", \
> > +    "usf", "jss",  "cdg", \
> > +    "psb", "mpsub","mpl2", \
> > +    "pjs", "dks", "stl", \
> > +    "vtt", "sbv"
> > +#define SLAVE_AUDIO_EXTENSIONS \
> > +    "ac3", "m4a"
> > +
> >  typedef int (*input_item_compar_cb)( input_item_t *, input_item_t * );
> > 
> >  struct input_item_node_t
> > @@ -220,6 +259,16 @@ VLC_API int input_item_AddOpaque(input_item_t *, const
> > char *, void *);
> > 
> >  void input_item_ApplyOptions(vlc_object_t *, input_item_t *);
> > 
> > +VLC_API bool input_item_slave_GetType(const char *, enum slave_type *);
> > +VLC_API input_item_slave *input_item_slave_New(const char *, uint8_t,
> > uint8_t);
> > +VLC_API void input_item_slave_Delete(input_item_slave *);
> > +
> > +/**
> > + * This function allows adding a slave to an existing input item.
> > + * The slave is owned by the input item after this call.
> > + */
> > +VLC_API int input_item_AddSlave(input_item_t *, input_item_slave *);
> > +
> >  /* */
> >  VLC_API bool input_item_HasErrorWhenReading( input_item_t * );
> >  VLC_API void input_item_SetMeta( input_item_t *, vlc_meta_type_t meta_type,
> > const char *psz_val ); diff --git a/src/input/item.c b/src/input/item.c
> > index 0dfb820..5a00a15 100644
> > --- a/src/input/item.c
> > +++ b/src/input/item.c
> > @@ -521,6 +521,10 @@ void input_item_Release( input_item_t *p_item )
> >          info_category_Delete( p_item->pp_categories[i] );
> >      TAB_CLEAN( p_item->i_categories, p_item->pp_categories );
> > 
> > +    for( int i = 0; i < p_item->i_slaves; i++ )
> > +        input_item_slave_Delete( p_item->pp_slaves[i] );
> > +    TAB_CLEAN( p_item->i_slaves, p_item->pp_slaves );
> > +
> >      vlc_mutex_destroy( &p_item->lock );
> >      free( owner );
> >  }
> > @@ -604,6 +608,83 @@ void input_item_ApplyOptions(vlc_object_t *obj,
> > input_item_t *item) vlc_mutex_unlock(&item->lock);
> >  }
> > 
> > +bool input_item_slave_GetType(const char *psz_name, enum slave_type
> > *p_slave_type) +{
> > +    static const char *const ppsz_sub_exts[] = { SLAVE_SPU_EXTENSIONS, NULL
> > };
> > +    static const char *const ppsz_audio_exts[] = {
> > SLAVE_AUDIO_EXTENSIONS, NULL }; +
> > +    static struct {
> > +        enum slave_type i_type;
> > +        const char *const *ppsz_exts;
> > +    } p_slave_list[] = {
> > +        { SLAVE_TYPE_SPU, ppsz_sub_exts },
> > +        { SLAVE_TYPE_AUDIO, ppsz_audio_exts },
> > +    };
> > +
> > +    const char *psz_ext = strrchr(psz_name, '.');
> > +    if (psz_ext == NULL)
> > +        return false;
> > +
> > +    size_t i_extlen = strlen(++psz_ext);
> > +    if (i_extlen == 0)
> > +        return false;
> > +
> > +    for (unsigned int i = 0; i < sizeof(p_slave_list) /
> > sizeof(*p_slave_list); ++i) +    {
> > +        for (const char *const *ppsz_slave_ext = p_slave_list[i].ppsz_exts;
> > +             *ppsz_slave_ext != NULL; ppsz_slave_ext++)
> > +        {
> > +            if (!strncasecmp(psz_ext, *ppsz_slave_ext, i_extlen))
> 
> Seems lose.
> 
> > +            {
> > +                *p_slave_type = p_slave_list[i].i_type;
> > +                return true;
> > +            }
> > +        }
> > +    }
> > +    return false;
> > +}
> > +
> > +input_item_slave *input_item_slave_New(const char *psz_uri, uint8_t i_type,
> > +                                       uint8_t i_priority)
> > +{
> > +    if( !psz_uri )
> > +        return NULL;
> > +
> > +    input_item_slave *p_slave = malloc( sizeof( *p_slave ) );
> > +    if( !p_slave )
> > +        return NULL;
> > +
> > +    p_slave->psz_uri = strdup( psz_uri );
> > +    p_slave->i_type = i_type;
> > +    p_slave->i_priority = i_priority;
> > +
> > +    if( !p_slave->psz_uri )
> > +    {
> > +        free( p_slave );
> > +        return NULL;
> > +    }
> > +    return p_slave;
> > +}
> > +
> > +void input_item_slave_Delete(input_item_slave *p_slave)
> > +{
> > +    free( p_slave->psz_uri );
> > +    free( p_slave );
> > +}
> > +
> > +int input_item_AddSlave(input_item_t *p_input, input_item_slave *p_slave)
> 
> p_input is confusing naming IMHO.

OK I'll fix these remarks, thanks for the review.

> 
> > +{
> > +    if( p_input == NULL || p_slave == NULL )
> > +        return VLC_EGENERIC;
> > +
> > +    vlc_mutex_lock( &p_input->lock );
> > +
> > +    INSERT_ELEM( p_input->pp_slaves, p_input->i_slaves, p_input->i_slaves,
> > p_slave ); +
> > +    vlc_mutex_unlock( &p_input->lock );
> > +    return VLC_SUCCESS;
> > +}
> > +
> >  static info_category_t *InputItemFindCat( input_item_t *p_item,
> >                                            int *pi_index, const char
> > *psz_cat ) {
> > @@ -956,6 +1037,7 @@ input_item_NewExt( const char *psz_uri, const char
> > *psz_name, p_input->p_stats = NULL;
> >      p_input->p_meta = NULL;
> >      TAB_INIT( p_input->i_epg, p_input->pp_epg );
> > +    TAB_INIT( p_input->i_slaves, p_input->pp_slaves );
> > 
> >      vlc_event_manager_init( p_em, p_input );
> >      vlc_event_manager_register_event_type( p_em, vlc_InputItemMetaChanged
> > ); diff --git a/src/libvlccore.sym b/src/libvlccore.sym
> > index bb108d5..49fb0b5 100644
> > --- a/src/libvlccore.sym
> > +++ b/src/libvlccore.sym
> > @@ -209,6 +209,10 @@ input_item_SetMeta
> >  input_item_SetName
> >  input_item_SetURI
> >  input_item_WriteMeta
> > +input_item_slave_GetType
> > +input_item_slave_New
> > +input_item_slave_Delete
> > +input_item_AddSlave
> >  input_Read
> >  input_resource_New
> >  input_resource_Release
> 
> -- 
> Rémi Denis-Courmont
> http://www.remlab.net/
> 
> _______________________________________________
> 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