input/item: add slave entries
authorBenjamin Adolphi <b.adolphi@gmail.com>
Thu, 24 Mar 2016 08:48:10 +0000 (09:48 +0100)
committerThomas Guillem <thomas@gllm.fr>
Thu, 19 May 2016 13:55:27 +0000 (15:55 +0200)
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@gllm.fr>
include/vlc_input_item.h
src/input/item.c
src/libvlccore.sym

index 9144fbb..cc2a19f 100644 (file)
@@ -37,6 +37,7 @@
 #include <string.h>
 
 typedef struct input_item_opaque input_item_opaque_t;
 #include <string.h>
 
 typedef struct input_item_opaque input_item_opaque_t;
+typedef struct input_item_slave input_item_slave_t;
 
 struct info_t
 {
 
 struct info_t
 {
@@ -83,6 +84,10 @@ struct input_item_t
     int         i_epg;               /**< Number of EPG entries */
     vlc_epg_t   **pp_epg;            /**< EPG entries */
 
     int         i_epg;               /**< Number of EPG entries */
     vlc_epg_t   **pp_epg;            /**< EPG entries */
 
+    int         i_slaves;            /**< Number of slaves */
+    input_item_slave_t **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 */
     vlc_event_manager_t event_manager;
 
     vlc_mutex_t lock;                 /**< Lock for the item */
@@ -123,6 +128,40 @@ enum input_item_net_type
     ITEM_LOCAL
 };
 
     ITEM_LOCAL
 };
 
+enum slave_type
+{
+    SLAVE_TYPE_SPU,
+    SLAVE_TYPE_AUDIO,
+};
+
+enum slave_priority
+{
+    SLAVE_PRIORITY_MATCH_NONE = 1,
+    SLAVE_PRIORITY_MATCH_RIGHT,
+    SLAVE_PRIORITY_MATCH_LEFT,
+    SLAVE_PRIORITY_MATCH_ALL,
+    SLAVE_PRIORITY_USER
+};
+
+#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"
+
+struct input_item_slave
+{
+    enum slave_type     i_type;     /**< Slave type (spu, audio) */
+    enum slave_priority i_priority; /**< Slave priority */
+    char                psz_uri[];  /**< Slave mrl */
+};
+
 typedef int (*input_item_compar_cb)( input_item_t *, input_item_t * );
 
 struct input_item_node_t
 typedef int (*input_item_compar_cb)( input_item_t *, input_item_t * );
 
 struct input_item_node_t
@@ -220,6 +259,18 @@ VLC_API int input_item_AddOpaque(input_item_t *, const char *, void *);
 
 void input_item_ApplyOptions(vlc_object_t *, input_item_t *);
 
 
 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_t *input_item_slave_New(const char *, enum slave_type,
+                                               enum slave_priority);
+#define input_item_slave_Delete(p_slave) free(p_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_t *);
+
 /* */
 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 );
 /* */
 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 );
index c0f627f..bce22e9 100644 (file)
@@ -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 );
 
         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 );
 }
     vlc_mutex_destroy( &p_item->lock );
     free( owner );
 }
@@ -604,6 +608,69 @@ void input_item_ApplyOptions(vlc_object_t *obj, input_item_t *item)
     vlc_mutex_unlock(&item->lock);
 }
 
     vlc_mutex_unlock(&item->lock);
 }
 
+bool input_item_slave_GetType(const char *psz_filename,
+                              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_filename, '.');
+    if (psz_ext == NULL || *(++psz_ext) == '\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 (!strcasecmp(psz_ext, *ppsz_slave_ext))
+            {
+                *p_slave_type = p_slave_list[i].i_type;
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
+input_item_slave_t *input_item_slave_New(const char *psz_uri, enum slave_type i_type,
+                                       enum slave_priority i_priority)
+{
+    if( !psz_uri )
+        return NULL;
+
+    input_item_slave_t *p_slave = malloc( sizeof( *p_slave ) + strlen( psz_uri ) + 1 );
+    if( !p_slave )
+        return NULL;
+
+    p_slave->i_type = i_type;
+    p_slave->i_priority = i_priority;
+    strcpy( p_slave->psz_uri, psz_uri );
+
+    return p_slave;
+}
+
+int input_item_AddSlave(input_item_t *p_item, input_item_slave_t *p_slave)
+{
+    if( p_item == NULL || p_slave == NULL )
+        return VLC_EGENERIC;
+
+    vlc_mutex_lock( &p_item->lock );
+
+    INSERT_ELEM( p_item->pp_slaves, p_item->i_slaves, p_item->i_slaves, p_slave );
+
+    vlc_mutex_unlock( &p_item->lock );
+    return VLC_SUCCESS;
+}
+
 static info_category_t *InputItemFindCat( input_item_t *p_item,
                                           int *pi_index, const char *psz_cat )
 {
 static info_category_t *InputItemFindCat( input_item_t *p_item,
                                           int *pi_index, const char *psz_cat )
 {
@@ -956,6 +1023,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 );
     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 );
 
     vlc_event_manager_init( p_em, p_input );
     vlc_event_manager_register_event_type( p_em, vlc_InputItemMetaChanged );
index 4f5283d..1e19c48 100644 (file)
@@ -209,6 +209,9 @@ input_item_SetMeta
 input_item_SetName
 input_item_SetURI
 input_item_WriteMeta
 input_item_SetName
 input_item_SetURI
 input_item_WriteMeta
+input_item_slave_GetType
+input_item_slave_New
+input_item_AddSlave
 input_Read
 input_resource_New
 input_resource_Release
 input_Read
 input_resource_New
 input_resource_Release