<html><head></head><body><div class="gmail_quote">Le 27 juin 2017 19:23:38 GMT+03:00, "Hugo Beauzée-Luyssen" <hugo@beauzee.fr> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">---<br /> modules/services_discovery/mediadirs.c | 77 ++++++++++++++++++++++++++++++----<br /> 1 file changed, 70 insertions(+), 7 deletions(-)<br /><br />diff --git a/modules/services_discovery/mediadirs.c b/modules/services_discovery/mediadirs.c<br />index 69ded2d63f..aaf0b2fe07 100644<br />--- a/modules/services_discovery/mediadirs.c<br />+++ b/modules/services_discovery/mediadirs.c<br />@@ -98,19 +98,27 @@ vlc_module_end ()<br /> static void* Run( void* );<br /> <br /> static void input_subnode_added( const vlc_event_t*, void* );<br />+static void input_preparse_ended( const vlc_event_t *p_event, void *user_data );<br /> static int onNewFileAdded( vlc_object_t*, char const *,<br /> vlc_value_t, vlc_value_t, void *);<br /> <br /> static enum type_e fileType( services_discovery_t *p_sd, const char* psz_file );<br /> static void formatSnapshotItem( input_item_t* );<br /> <br />+#define NB_FOLDERS 2<br />+<br /> struct services_discovery_sys_t<br /> {<br /> vlc_thread_t thread;<br /> enum type_e i_type;<br /> <br />- char* psz_dir[2];<br />+ char* psz_dir[NB_FOLDERS];<br />+ input_item_t* p_items[NB_FOLDERS];<br /> const char* psz_var;<br />+<br />+ vlc_mutex_t lock;<br />+ vlc_cond_t cond;<br />+ unsigned int nb_folders_parsed;<br /> };<br /> <br /> /*****************************************************************************<br />@@ -162,8 +170,13 @@ static int Open( vlc_object_t *p_this, enum type_e i_type )<br /> <br /> var_AddCallback( p_sd->obj.libvlc, p_sys->psz_var, onNewFileAdded, p_sd );<br /> <br />+ vlc_mutex_init( &p_sys->lock );<br />+ vlc_cond_init( &p_sys->cond );<br />+ p_sys->nb_folders_parsed = 0;<br /> if( vlc_clone( &p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW ) )<br /> {<br />+ vlc_cond_destroy( &p_sys->cond );<br />+ vlc_mutex_destroy( &p_sys->lock );<br /> var_DelCallback( p_sd->obj.libvlc, p_sys->psz_var, onNewFileAdded, p_sd );<br /> free( p_sys->psz_dir[1] );<br /> free( p_sys->psz_dir[0] );<br />@@ -181,9 +194,9 @@ static void *Run( void *data )<br /> {<br /> services_discovery_t *p_sd = data;<br /> services_discovery_sys_t *p_sys = p_sd->p_sys;<br />+ unsigned int i_to_parse = 0;<br /> <br />- int num_dir = sizeof( p_sys->psz_dir ) / sizeof( p_sys->psz_dir[0] );<br />- for( int i = 0; i < num_dir; i++ )<br />+ for( int i = 0; i < NB_FOLDERS; i++ )<br /> {<br /> char* psz_dir = p_sys->psz_dir[i];<br /> <br />@@ -192,11 +205,14 @@ static void *Run( void *data )<br /> if( psz_dir == NULL ||<br /> vlc_stat( psz_dir, &st ) ||<br /> !S_ISDIR( st.st_mode ) )<br />+ {<br />+ p_sys->p_items[i] = NULL;<br /> continue;<br />+ }<br /> <br /> char* psz_uri = vlc_path2uri( psz_dir, "file" );<br /> <br />- input_item_t* p_root = input_item_New( psz_uri, NULL );<br />+ input_item_t* p_root = p_sys->p_items[i] = input_item_New( psz_uri, NULL );<br /> if( p_sys->i_type == Picture )<br /> input_item_AddOption( p_root, "ignore-filetypes=ini,db,lnk,txt",<br /> VLC_INPUT_OPTION_TRUSTED );<br />@@ -208,15 +224,35 @@ static void *Run( void *data )<br /> vlc_event_manager_t *p_em = &p_root->event_manager;<br /> vlc_event_attach( p_em, vlc_InputItemSubItemTreeAdded,<br /> input_subnode_added, p_sd );<br />+ vlc_event_attach( p_em, vlc_InputItemPreparseEnded,<br />+ input_preparse_ended, p_sd );<br />+<br />+ if ( libvlc_MetadataRequest( p_sd->obj.libvlc, p_root,<br />+ META_REQUEST_OPTION_SCOPE_LOCAL | META_REQUEST_OPTION_DO_INTERACT,<br />+ -1, p_sys->p_items[i] ) == VLC_SUCCESS )<br />+ {<br />+ ++i_to_parse;<br />+ }<br />+<br />+ free( psz_uri );<br />+ }<br /> <br />- input_Read( p_sd, p_root );<br />+ vlc_mutex_lock( &p_sys->lock );<br />+ while ( i_to_parse > 0 && p_sys->nb_folders_parsed < i_to_parse )<br />+ vlc_cond_wait( &p_sys->cond, &p_sys->lock );<br /> <br />+ for( int i = 0; i < NB_FOLDERS; ++i )<br />+ {<br />+ if( p_sys->p_items[i] == NULL )<br />+ continue;<br />+ vlc_event_manager_t *p_em = &p_sys->p_items[i]->event_manager;<br /> vlc_event_detach( p_em, vlc_InputItemSubItemTreeAdded,<br /> input_subnode_added, p_sd );<br /> <br />- input_item_Release( p_root );<br />- free( psz_uri );<br />+ input_item_Release( p_sys->p_items[i] );<br />+ p_sys->p_items[i] = NULL;<br /> }<br />+ vlc_mutex_unlock( &p_sys->lock );<br /> <br /> return NULL;<br /> }<br />@@ -229,7 +265,23 @@ static void Close( vlc_object_t *p_this )<br /> services_discovery_t *p_sd = (services_discovery_t *)p_this;<br /> services_discovery_sys_t *p_sys = p_sd->p_sys;<br /> <br />+ vlc_mutex_lock( &p_sys->lock );<br />+ for ( int i = 0; i < NB_FOLDERS; ++i )<br />+ {<br />+ if( p_sys->p_items[i] != NULL )<br />+ {<br />+ /* This will synchronously cancel the preparse request, but will not<br />+ * invoke the input_preparse_ended callback */<br />+ libvlc_MetadataCancel( p_sd->obj.libvlc, p_sys->p_items[i] );<br />+ p_sys->nb_folders_parsed++;<br />+ }<br />+ }<br />+ vlc_mutex_unlock( &p_sys->lock );<br />+ vlc_cond_signal( &p_sys->cond );<br />+<br /> vlc_join( p_sys->thread, NULL );<br />+ vlc_cond_destroy( &p_sys->cond );<br />+ vlc_mutex_destroy( &p_sys->lock );<br /> <br /> var_DelCallback( p_sd->obj.libvlc, p_sys->psz_var, onNewFileAdded, p_sd );<br /> <br />@@ -260,6 +312,17 @@ static void input_subnode_added( const vlc_event_t *p_event, void *user_data )<br /> }<br /> }<br /> <br />+static void input_preparse_ended( const vlc_event_t *p_event, void *user_data )<br />+{<br />+ VLC_UNUSED( p_event );<br />+ services_discovery_t* p_sd = user_data;<br />+ services_discovery_sys_t *p_sys = p_sd->p_sys;<br />+ vlc_mutex_lock( &p_sys->lock );<br />+ ++p_sys->nb_folders_parsed;<br />+ vlc_mutex_unlock( &p_sys->lock );<br />+ vlc_cond_signal( &p_sys->cond );<br />+}<br />+<br /> static int onNewFileAdded( vlc_object_t *p_this, char const *psz_var,<br /> vlc_value_t oldval, vlc_value_t newval, void *p_data )<br /> {</pre></blockquote></div><br clear="all">There are no reasons why the dir SD cannot look deeper than one level, at least not anymore. So this looks like a hack on top of an existing hack.<br>
-- <br>
Rémi Denis-Courmont<br>
Typed on an inconvenient virtual keyboard</body></html>