[vlc-devel] [PATCH 10/12] playlist: don't play directories that can loop into themselves

Thomas Guillem thomas at gllm.fr
Tue May 19 10:27:50 CEST 2015


---
 include/vlc_input_item.h           |  1 +
 modules/demux/playlist/directory.c |  6 +++++-
 src/input/item.c                   |  1 +
 src/playlist/item.c                | 16 ++++++++++++++++
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 4a07984..c2db4e3 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -119,6 +119,7 @@ struct input_item_node_t
     int                    i_children;
     input_item_node_t      **pp_children;
     input_item_node_t      *p_parent;
+    bool                   b_can_loop;
 };
 
 typedef int (*input_item_compar_cb)( input_item_t *, input_item_t * );
diff --git a/modules/demux/playlist/directory.c b/modules/demux/playlist/directory.c
index 887c762..73027e0 100644
--- a/modules/demux/playlist/directory.c
+++ b/modules/demux/playlist/directory.c
@@ -36,6 +36,7 @@
 struct demux_sys_t
 {
     bool b_dir_sorted;
+    bool b_dir_can_loop;
 };
 
 /*****************************************************************************
@@ -50,14 +51,16 @@ int Import_Dir ( vlc_object_t *p_this)
 
     bool b_is_dir = false;
     bool b_dir_sorted = false;
+    bool b_dir_can_loop = false;
     int i_err = stream_Control( p_demux->s, STREAM_IS_DIRECTORY, &b_is_dir,
-                                &b_dir_sorted, NULL );
+                                &b_dir_sorted, &b_dir_can_loop );
 
     if ( !( i_err == VLC_SUCCESS && b_is_dir ) )
         return VLC_EGENERIC;
 
     STANDARD_DEMUX_INIT_MSG( "reading directory content" );
     p_demux->p_sys->b_dir_sorted = b_dir_sorted;
+    p_demux->p_sys->b_dir_can_loop = b_dir_can_loop;
 
     return VLC_SUCCESS;
 }
@@ -154,6 +157,7 @@ static int Demux( demux_t *p_demux )
 
     p_input = GetCurrentItem( p_demux );
     p_node = input_item_node_Create( p_input );
+    p_node->b_can_loop = p_demux->p_sys->b_dir_can_loop;
     input_item_Release(p_input);
 
     b_show_hiddenfiles = var_InheritBool( p_demux, "show-hiddenfiles" );
diff --git a/src/input/item.c b/src/input/item.c
index 5912768..55a54df 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -1102,6 +1102,7 @@ input_item_node_t *input_item_node_Create( input_item_t *p_input )
     p_node->p_parent = NULL;
     p_node->i_children = 0;
     p_node->pp_children = NULL;
+    p_node->b_can_loop = false;
 
     return p_node;
 }
diff --git a/src/playlist/item.c b/src/playlist/item.c
index 5ce59f3..8d54e86 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -150,6 +150,22 @@ static void input_item_add_subitem_tree ( const vlc_event_t * p_event,
             }
             else
             {
+                /* Don't Play a directory if it can loop into a parent */
+                if( p_new_root->b_can_loop )
+                {
+                    /* Play the first regular file */
+                    for( ; pos < last_pos; pos++ )
+                    {
+                        if( p_item->pp_children[pos]->p_input->i_type != ITEM_TYPE_DIRECTORY )
+                            break;
+                    }
+                    if( last_pos == pos )
+                    {
+                        PL_UNLOCK;
+                        playlist_Stop( p_playlist );
+                        return;
+                    }
+                }
                 p_play_item = p_item->pp_children[pos];
                 /* NOTE: this is a work around the general bug:
                 if node-to-be-played contains sub-nodes, then second instead
-- 
2.1.4




More information about the vlc-devel mailing list