[vlc-devel] [PATCH 01/11] input/item: add slave entries

Thomas Guillem thomas at gllm.fr
Fri Apr 1 10:31:00 CEST 2016


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.
---
 include/vlc_input_item.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/input/item.c         | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym       |  3 +++
 3 files changed, 97 insertions(+)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 8d20efa..6f39d78 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 */
 };
 
+typedef struct
+{
+    char        *psz_uri;   /**< Slave mrl */
+    uint8_t     i_type;     /**< Slave type (spu, audio, ... see slave_type_e) */
+    uint8_t     i_priority; /**< Slave priority */
+} input_item_slave;
+
 /**
  * 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 */
@@ -116,6 +127,34 @@ enum input_item_type_e
     ITEM_TYPE_NUMBER
 };
 
+enum slave_type_e
+{
+    SLAVE_TYPE_SPU,
+    SLAVE_TYPE_AUDIO,
+};
+
+enum slave_priotity_e
+{
+    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
@@ -207,6 +246,15 @@ VLC_API int input_item_AddOpaque(input_item_t *, const char *, void *);
 
 void input_item_ApplyOptions(vlc_object_t *, input_item_t *);
 
+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 b27beee..81d36c0 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -495,6 +495,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 );
 }
@@ -568,6 +572,47 @@ void input_item_ApplyOptions(vlc_object_t *obj, input_item_t *item)
     vlc_mutex_unlock(&item->lock);
 }
 
+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)
+{
+    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 )
 {
@@ -934,6 +979,7 @@ input_item_NewWithTypeExt( 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 0d69d14..37cb6bb 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -207,6 +207,9 @@ input_item_SetMeta
 input_item_SetName
 input_item_SetURI
 input_item_WriteMeta
+input_item_slave_New
+input_item_slave_Delete
+input_item_AddSlave
 input_Read
 input_resource_New
 input_resource_Release
-- 
2.8.0.rc3



More information about the vlc-devel mailing list