Commit 3d227df7 authored by Benjamin Adolphi's avatar Benjamin Adolphi Committed by Thomas Guillem

input/item: add slave entries

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's avatarThomas Guillem <thomas@gllm.fr>
parent 760f2c86
......@@ -37,6 +37,7 @@
#include <string.h>
typedef struct input_item_opaque input_item_opaque_t;
typedef struct input_item_slave input_item_slave_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_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 */
......@@ -123,6 +128,40 @@ enum input_item_net_type
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
......@@ -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 *);
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 );
......
......@@ -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,69 @@ 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_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 )
{
......@@ -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 );
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 );
......
......@@ -209,6 +209,9 @@ input_item_SetMeta
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
......
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