Commit 2822a778 authored by Rémi Denis-Courmont's avatar 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.
parent f640890d
...@@ -36,9 +36,8 @@ ...@@ -36,9 +36,8 @@
#include <string.h> #include <string.h>
/***************************************************************************** typedef struct input_item_opaque input_item_opaque_t;
* input_item_t: Describes an input and is used to spawn input_thread_t objects
*****************************************************************************/
struct info_t struct info_t
{ {
char *psz_name; /**< Name of this info */ char *psz_name; /**< Name of this info */
...@@ -52,6 +51,9 @@ struct info_category_t ...@@ -52,6 +51,9 @@ struct info_category_t
struct info_t **pp_infos; /**< Pointer to an array of infos */ 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 struct input_item_t
{ {
int i_id; /**< Identifier of the item */ int i_id; /**< Identifier of the item */
...@@ -63,6 +65,7 @@ struct input_item_t ...@@ -63,6 +65,7 @@ struct input_item_t
char **ppsz_options; /**< Array of input options */ char **ppsz_options; /**< Array of input options */
uint8_t *optflagv; /**< Some flags of input options */ uint8_t *optflagv; /**< Some flags of input options */
unsigned optflagc; unsigned optflagc;
input_item_opaque_t *opaques; /**< List of opaque pointer values */
mtime_t i_duration; /**< Duration in microseconds */ mtime_t i_duration; /**< Duration in microseconds */
...@@ -187,6 +190,7 @@ enum input_item_option_e ...@@ -187,6 +190,7 @@ enum input_item_option_e
* This function allows to add an option to an existing input_item_t. * 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_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 *); void input_item_ApplyOptions(vlc_object_t *, input_item_t *);
......
...@@ -35,6 +35,13 @@ ...@@ -35,6 +35,13 @@
#include "item.h" #include "item.h"
#include "info.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 ); static int GuessType( const input_item_t *p_item, bool *p_net );
void input_item_SetErrorWhenReading( input_item_t *p_i, bool b_error ) 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 ) ...@@ -462,6 +469,12 @@ void input_item_Release( input_item_t *p_item )
if( p_item->p_meta != NULL ) if( p_item->p_meta != NULL )
vlc_meta_Delete( p_item->p_meta ); 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++ ) for( int i = 0; i < p_item->i_options; i++ )
free( p_item->ppsz_options[i] ); free( p_item->ppsz_options[i] );
TAB_CLEAN( p_item->i_options, p_item->ppsz_options ); TAB_CLEAN( p_item->i_options, p_item->ppsz_options );
...@@ -518,6 +531,25 @@ out: ...@@ -518,6 +531,25 @@ out:
return err; 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) void input_item_ApplyOptions(vlc_object_t *obj, input_item_t *item)
{ {
vlc_mutex_lock(&item->lock); vlc_mutex_lock(&item->lock);
...@@ -526,6 +558,13 @@ void input_item_ApplyOptions(vlc_object_t *obj, input_item_t *item) ...@@ -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++) for (unsigned i = 0; i < (unsigned)item->i_options; i++)
var_OptionParse(obj, item->ppsz_options[i], var_OptionParse(obj, item->ppsz_options[i],
!!(item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED)); !!(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); vlc_mutex_unlock(&item->lock);
} }
...@@ -887,6 +926,7 @@ input_item_NewWithTypeExt( const char *psz_uri, const char *psz_name, ...@@ -887,6 +926,7 @@ input_item_NewWithTypeExt( const char *psz_uri, const char *psz_name,
p_input->optflagv = NULL; p_input->optflagv = NULL;
for( int i = 0; i < i_options; i++ ) for( int i = 0; i < i_options; i++ )
input_item_AddOption( p_input, ppsz_options[i], flags ); input_item_AddOption( p_input, ppsz_options[i], flags );
p_input->opaques = NULL;
p_input->i_duration = duration; p_input->i_duration = duration;
TAB_INIT( p_input->i_categories, p_input->pp_categories ); TAB_INIT( p_input->i_categories, p_input->pp_categories );
......
...@@ -182,6 +182,7 @@ input_DecoderFlush ...@@ -182,6 +182,7 @@ input_DecoderFlush
input_GetItem input_GetItem
input_item_AddInfo input_item_AddInfo
input_item_AddOption input_item_AddOption
input_item_AddOpaque
input_item_Copy input_item_Copy
input_item_CopyOptions input_item_CopyOptions
input_item_DelInfo input_item_DelInfo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment