[vlc-commits] input: add support for pointer options to input item

Rémi Denis-Courmont git at videolan.org
Mon Mar 30 22:05:07 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Mar 30 21:13:17 2015 +0300| [2822a77846f88fcbaa3482ca9754060c192119fe] | committer: Rémi Denis-Courmont

input: add support for pointer options to input item

Pointers cannot be inherited as normal configuration item for somewhat
obvious reasons. For output parameters, this is not much of an issue as
LibVLC sets the pointer values directly on its media player object. But
for input-related parameters, LibVLC would need to store pointer values
in the media item. Thus this change to input items.

Note that pointers are considered intrinsically unsafe, so there are no
flags for the time being.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2822a77846f88fcbaa3482ca9754060c192119fe
---

 include/vlc_input_item.h |   10 +++++++---
 src/input/item.c         |   40 ++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym       |    1 +
 3 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 4bb84c5..48dcd32 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -36,9 +36,8 @@
 
 #include <string.h>
 
-/*****************************************************************************
- * input_item_t: Describes an input and is used to spawn input_thread_t objects
- *****************************************************************************/
+typedef struct input_item_opaque input_item_opaque_t;
+
 struct info_t
 {
     char *psz_name;            /**< Name of this info */
@@ -52,6 +51,9 @@ struct info_category_t
     struct info_t **pp_infos;     /**< Pointer to an array of infos */
 };
 
+/**
+ * Describes an input and is used to spawn input_thread_t objects.
+ */
 struct input_item_t
 {
     int        i_id;                 /**< Identifier of the item */
@@ -63,6 +65,7 @@ struct input_item_t
     char       **ppsz_options;       /**< Array of input options */
     uint8_t    *optflagv;            /**< Some flags of input options */
     unsigned   optflagc;
+    input_item_opaque_t *opaques;    /**< List of opaque pointer values */
 
     mtime_t    i_duration;           /**< Duration in microseconds */
 
@@ -187,6 +190,7 @@ enum input_item_option_e
  * This function allows to add an option to an existing input_item_t.
  */
 VLC_API int input_item_AddOption(input_item_t *, const char *, unsigned i_flags );
+VLC_API int input_item_AddOpaque(input_item_t *, const char *, void *);
 
 void input_item_ApplyOptions(vlc_object_t *, input_item_t *);
 
diff --git a/src/input/item.c b/src/input/item.c
index a4c1d74..d357c25 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -35,6 +35,13 @@
 #include "item.h"
 #include "info.h"
 
+struct input_item_opaque
+{
+    struct input_item_opaque *next;
+    void *value;
+    char name[1];
+};
+
 static int GuessType( const input_item_t *p_item, bool *p_net );
 
 void input_item_SetErrorWhenReading( input_item_t *p_i, bool b_error )
@@ -462,6 +469,12 @@ void input_item_Release( input_item_t *p_item )
     if( p_item->p_meta != NULL )
         vlc_meta_Delete( p_item->p_meta );
 
+    for( input_item_opaque_t *o = p_item->opaques, *next; o != NULL; o = next )
+    {
+        next = o->next;
+        free( o );
+    }
+
     for( int i = 0; i < p_item->i_options; i++ )
         free( p_item->ppsz_options[i] );
     TAB_CLEAN( p_item->i_options, p_item->ppsz_options );
@@ -518,6 +531,25 @@ out:
     return err;
 }
 
+int input_item_AddOpaque(input_item_t *item, const char *name, void *value)
+{
+    assert(name != NULL);
+
+    size_t namelen = strlen(name);
+    input_item_opaque_t *entry = malloc(sizeof (*entry) + namelen);
+    if (unlikely(entry == NULL))
+        return VLC_ENOMEM;
+
+    memcpy(entry->name, name, namelen + 1);
+    entry->value = value;
+
+    vlc_mutex_lock(&item->lock);
+    entry->next = item->opaques;
+    item->opaques = entry;
+    vlc_mutex_unlock(&item->lock);
+    return VLC_SUCCESS;
+}
+
 void input_item_ApplyOptions(vlc_object_t *obj, input_item_t *item)
 {
     vlc_mutex_lock(&item->lock);
@@ -526,6 +558,13 @@ void input_item_ApplyOptions(vlc_object_t *obj, input_item_t *item)
     for (unsigned i = 0; i < (unsigned)item->i_options; i++)
         var_OptionParse(obj, item->ppsz_options[i],
                         !!(item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED));
+
+    for (const input_item_opaque_t *o = item->opaques; o != NULL; o = o->next)
+    {
+        var_Create(obj, o->name, VLC_VAR_ADDRESS);
+        var_SetAddress(obj, o->name, o->value);
+    }
+
     vlc_mutex_unlock(&item->lock);
 }
 
@@ -887,6 +926,7 @@ input_item_NewWithTypeExt( const char *psz_uri, const char *psz_name,
     p_input->optflagv = NULL;
     for( int i = 0; i < i_options; i++ )
         input_item_AddOption( p_input, ppsz_options[i], flags );
+    p_input->opaques = NULL;
 
     p_input->i_duration = duration;
     TAB_INIT( p_input->i_categories, p_input->pp_categories );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 2d88c8d..e89cf4e 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -182,6 +182,7 @@ input_DecoderFlush
 input_GetItem
 input_item_AddInfo
 input_item_AddOption
+input_item_AddOpaque
 input_item_Copy
 input_item_CopyOptions
 input_item_DelInfo



More information about the vlc-commits mailing list