Commit 24ddff58 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

libvlc: Move input_item array from playlist to libvlc.

This avoids the circular dependency there is from playlist and input item, which creates a dead lock at exit.
parent 5f84c2fc
......@@ -26,6 +26,8 @@
#error You are not libvlc or one of its plugins. You cannot include this file
#endif
TYPEDEF_ARRAY(input_item_t*, input_item_array_t);
/*****************************************************************************
* libvlc_internal_instance_t
*****************************************************************************
......@@ -47,6 +49,11 @@ struct libvlc_int_t
vlc_object_t *p_interaction; ///< interface interaction object
/* There is no real reason to keep a list of items, but not to break
* everything, let's keep it */
input_item_array_t input_items; ///< Array of all created input items
int i_last_input_id ; ///< Last id of input item
/* Messages */
msg_bank_t msg_bank; ///< The message bank
int i_verbose; ///< info messages
......
......@@ -382,7 +382,8 @@ VLC_EXPORT(int, input_ItemAddInfo, ( input_item_t *p_i, const char *psz_cat, con
VLC_EXPORT( input_item_t *, __input_ItemNewExt, (vlc_object_t *, const char *, const char*, int, const char *const *, mtime_t i_duration ) );
VLC_EXPORT( input_item_t *, input_ItemNewWithType, ( vlc_object_t *, const char *, const char *e, int, const char *const *, mtime_t i_duration, int ) );
VLC_EXPORT( input_item_t *, input_ItemGetById, (playlist_t *, int ) );
#define input_ItemGetById(a,b) __input_ItemGetById( VLC_OBJECT(a),b )
VLC_EXPORT( input_item_t *, __input_ItemGetById, (vlc_object_t *, int ) );
/*****************************************************************************
* Meta data helpers
......
......@@ -39,7 +39,6 @@ extern "C" {
#include <stdlib.h>
TYPEDEF_ARRAY(playlist_item_t*, playlist_item_array_t);
TYPEDEF_ARRAY(input_item_t*, input_item_array_t);
/**
* \file
......@@ -176,8 +175,6 @@ struct playlist_t
playlist_item_array_t items; /**< Arrays of items */
playlist_item_array_t all_items; /**< Array of items and nodes */
input_item_array_t input_items; /**< Array of input items */
playlist_item_array_t current; /**< Items currently being played */
int i_current_index; /**< Index in current array */
/** Reset current item array */
......@@ -185,7 +182,6 @@ struct playlist_t
mtime_t last_rebuild_date;
int i_last_playlist_id; /**< Last id to an item */
int i_last_input_id ; /**< Last id on an input */
/* Predefined items */
playlist_item_t * p_root_category; /**< Root of category tree */
......
......@@ -104,14 +104,16 @@ static void input_ItemDestroy ( gc_object_t *p_this )
input_item_t *p_input = (input_item_t *) p_this;
int i;
playlist_t *p_playlist = pl_Yield( p_obj );
input_ItemClean( p_input );
ARRAY_BSEARCH( p_playlist->input_items,->i_id, int, p_input->i_id, i);
vlc_mutex_lock( &p_obj->p_libvlc->object_lock );
ARRAY_BSEARCH( p_obj->p_libvlc->input_items,->i_id, int, p_input->i_id, i);
if( i != -1 )
ARRAY_REMOVE( p_playlist->input_items, i);
ARRAY_REMOVE( p_obj->p_libvlc->input_items, i);
vlc_mutex_unlock( &p_obj->p_libvlc->object_lock );
pl_Release( p_obj );
free( p_input );
}
......@@ -215,13 +217,20 @@ int input_ItemAddInfo( input_item_t *p_i,
return p_info->psz_value ? VLC_SUCCESS : VLC_ENOMEM;
}
input_item_t *input_ItemGetById( playlist_t *p_playlist, int i_id )
input_item_t *__input_ItemGetById( vlc_object_t *p_obj, int i_id )
{
input_item_t * p_ret = NULL;
int i;
ARRAY_BSEARCH( p_playlist->input_items, ->i_id, int, i_id, i);
vlc_mutex_lock( &p_obj->p_libvlc->object_lock );
ARRAY_BSEARCH( p_obj->p_libvlc->input_items, ->i_id, int, i_id, i);
if( i != -1 )
return ARRAY_VAL( p_playlist->input_items, i);
return NULL;
p_ret = ARRAY_VAL( p_obj->p_libvlc->input_items, i);
vlc_mutex_unlock( &p_obj->p_libvlc->object_lock );
return p_ret;
}
input_item_t *__input_ItemNewExt( vlc_object_t *p_obj, const char *psz_uri,
......@@ -243,17 +252,15 @@ input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri,
mtime_t i_duration,
int i_type )
{
playlist_t *p_playlist = pl_Yield( p_obj );
DECMALLOC_NULL( p_input, input_item_t );
input_ItemInit( p_obj, p_input );
vlc_gc_init( p_input, input_ItemDestroy, (void *)p_obj );
PL_LOCK;
p_input->i_id = ++p_playlist->i_last_input_id;
ARRAY_APPEND( p_playlist->input_items, p_input );
PL_UNLOCK;
pl_Release( p_obj );
vlc_mutex_lock( &p_obj->p_libvlc->object_lock );
p_input->i_id = ++p_obj->p_libvlc->i_last_input_id;
ARRAY_APPEND( p_obj->p_libvlc->input_items, p_input );
vlc_mutex_unlock( &p_obj->p_libvlc->object_lock );
p_input->b_fixed_name = VLC_FALSE;
......
......@@ -726,6 +726,10 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
p_libvlc->i_timers = 0;
p_libvlc->pp_timers = NULL;
/* Init the array that holds every input item */
ARRAY_INIT( p_libvlc->input_items );
p_libvlc->i_last_input_id = 0;
/*
* Initialize hotkey handling
*/
......@@ -966,6 +970,15 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
vlc_object_release( p_announce );
announce_HandlerDestroy( p_announce );
}
msg_Dbg( p_libvlc, "removing remaining input items" );
FOREACH_ARRAY( input_item_t *p_del, p_libvlc->input_items )
msg_Dbg( p_libvlc, "WARNING: %p input item has not been deleted properly", p_del );
input_ItemClean( p_del );
free( p_del );
FOREACH_END();
ARRAY_RESET( p_libvlc->input_items );
return VLC_SUCCESS;
}
......
......@@ -130,7 +130,7 @@ input_DecoderNew
input_GetItem
input_ItemAddInfo
input_ItemAddOpt
input_ItemGetById
__input_ItemGetById
input_ItemGetInfo
__input_ItemNewExt
input_ItemNewWithType
......
......@@ -80,7 +80,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
/* Initialise data structures */
vlc_mutex_init( p_playlist, &p_playlist->gc_lock );
p_playlist->i_last_playlist_id = 0;
p_playlist->i_last_input_id = 0;
p_playlist->p_input = NULL;
p_playlist->gc_date = 0;
......@@ -88,7 +87,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
ARRAY_INIT( p_playlist->items );
ARRAY_INIT( p_playlist->all_items );
ARRAY_INIT( p_playlist->input_items );
ARRAY_INIT( p_playlist->current );
p_playlist->i_current_index = 0;
......@@ -492,12 +490,6 @@ void playlist_LastLoop( playlist_t *p_playlist )
FOREACH_END();
ARRAY_RESET( p_playlist->all_items );
FOREACH_ARRAY( input_item_t *p_del, p_playlist->input_items )
input_ItemClean( p_del );
free( p_del );
FOREACH_END();
ARRAY_RESET( p_playlist->input_items );
ARRAY_RESET( p_playlist->items );
ARRAY_RESET( p_playlist->current );
......
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