[vlc-devel] commit: libvlc: Move input_item array from playlist to libvlc. (Pierre d' Herbemont )
git version control
git at videolan.org
Wed Mar 26 17:36:13 CET 2008
vlc | branch: master | Pierre d'Herbemont <pdherbemont at videolan.org> | Wed Mar 26 17:22:00 2008 +0100| [24ddff58f6fb99cafff56a88d2fb99a5f687ff51]
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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=24ddff58f6fb99cafff56a88d2fb99a5f687ff51
---
include/main.h | 7 +++++++
include/vlc_input.h | 3 ++-
include/vlc_playlist.h | 4 ----
src/input/item.c | 35 +++++++++++++++++++++--------------
src/libvlc-common.c | 13 +++++++++++++
src/libvlc.sym | 2 +-
src/playlist/engine.c | 8 --------
7 files changed, 44 insertions(+), 28 deletions(-)
diff --git a/include/main.h b/include/main.h
index 596de28..b940749 100644
--- a/include/main.h
+++ b/include/main.h
@@ -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
diff --git a/include/vlc_input.h b/include/vlc_input.h
index 75af0c0..e3f3dd4 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -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
diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index 12f96e3..b7f33a9 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -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 */
diff --git a/src/input/item.c b/src/input/item.c
index ac5bb5a..53d2f3a 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -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;
diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index 3f7a9d1..cf2e525 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -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;
}
diff --git a/src/libvlc.sym b/src/libvlc.sym
index a6e28fc..634b311 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -130,7 +130,7 @@ input_DecoderNew
input_GetItem
input_ItemAddInfo
input_ItemAddOpt
-input_ItemGetById
+__input_ItemGetById
input_ItemGetInfo
__input_ItemNewExt
input_ItemNewWithType
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index c1b9b97..0aab56c 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -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 );
More information about the vlc-devel
mailing list