]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
* Do not take and release the structure lock for each element of the list while
[vlc] / modules / access / directory.c
index 831179a02578b2e53f46e7986c5b74f242f0747a..b0ea03b04f964257c8b411fd52d846e1eeaf50f7 100644 (file)
  *****************************************************************************/
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
 #include <vlc_playlist.h>
 #include <vlc_input.h>
+#include <vlc_access.h>
+#include <vlc_demux.h>
 
 #include <stdlib.h>
 #include <string.h>
@@ -57,7 +58,7 @@
 #   include <dirent.h>
 #endif
 
-#include "charset.h"
+#include <vlc_charset.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -125,7 +126,7 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args );
 
 
 static int ReadDir( playlist_t *, const char *psz_name, int i_mode,
-                    playlist_item_t *, playlist_item_t * );
+                    playlist_item_t *, playlist_item_t *, input_item_t * );
 
 /*****************************************************************************
  * Open: open the directory
@@ -178,13 +179,25 @@ static int ReadNull( access_t *p_access, uint8_t *p_buffer, int i_len)
  *****************************************************************************/
 static int Read( access_t *p_access, uint8_t *p_buffer, int i_len)
 {
-    char *psz;
-    int  i_mode, i_activity;
-
-    char *psz_name = strdup (p_access->psz_path);
-    if (psz_name == NULL)
+    char               *psz;
+    int                 i_mode, i_activity;
+    playlist_t         *p_playlist = pl_Yield( p_access );
+    playlist_item_t    *p_item_in_category;
+    input_item_t       *p_current_input = input_GetItem(
+                                    (input_thread_t*)p_access->p_parent);
+    playlist_item_t    *p_current = playlist_ItemGetByInput( p_playlist,
+                                                             p_current_input,
+                                                             VLC_FALSE );
+    char               *psz_name = strdup (p_access->psz_path);
+
+    if( psz_name == NULL )
         return VLC_ENOMEM;
 
+    if( p_current == NULL ) {
+        msg_Err( p_access, "unable to find item in playlist" );
+        return VLC_ENOOBJ;
+    }
+
     /* Remove the ending '/' char */
     if (psz_name[0])
     {
@@ -197,9 +210,6 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len)
         }
     }
 
-    playlist_item_t *p_item, *p_root_category;
-    playlist_t *p_playlist = pl_Yield( p_access );
-
     /* Handle mode */
     psz = var_CreateGetString( p_access, "recursive" );
     if( *psz == '\0' || !strncmp( psz, "none" , 4 )  )
@@ -212,33 +222,23 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len)
 
     msg_Dbg( p_access, "opening directory `%s'", p_access->psz_path );
 
-    if( p_playlist->status.p_item && p_playlist->status.p_item->p_input ==
-        ((input_thread_t *)p_access->p_parent)->input.p_item )
-        p_item = p_playlist->status.p_item;
-    else
-    {
-        input_item_t *p_current = ( (input_thread_t*)p_access->p_parent)->
-                                                        input.p_item;
-        p_item = playlist_LockItemGetByInput( p_playlist, p_current );
-        if( !p_item )
-        {
-            msg_Dbg( p_playlist, "unable to find item in playlist");
-            return VLC_ENOOBJ;
-        }
-    }
-    p_item->p_input->i_type = ITEM_TYPE_DIRECTORY;
-
-    p_root_category = playlist_LockItemToNode( p_playlist, p_item );
+    p_current->p_input->i_type = ITEM_TYPE_DIRECTORY;
+    p_item_in_category = playlist_ItemToNode( p_playlist, p_current,
+                                              VLC_FALSE );
 
     i_activity = var_GetInteger( p_playlist, "activity" );
     var_SetInteger( p_playlist, "activity", i_activity +
                     DIRECTORY_ACTIVITY );
 
-    ReadDir( p_playlist, psz_name, i_mode, p_item, p_root_category );
+    ReadDir( p_playlist, psz_name, i_mode, p_current, p_item_in_category,
+             p_current_input );
 
     i_activity = var_GetInteger( p_playlist, "activity" );
     var_SetInteger( p_playlist, "activity", i_activity -
                     DIRECTORY_ACTIVITY );
+
+    playlist_Signal( p_playlist );
+
     if( psz_name ) free( psz_name );
     vlc_object_release( p_playlist );
 
@@ -335,7 +335,8 @@ static int Sort (const char **a, const char **b)
  *****************************************************************************/
 static int ReadDir( playlist_t *p_playlist, const char *psz_name,
                     int i_mode, playlist_item_t *p_parent,
-                    playlist_item_t *p_parent_category )
+                    playlist_item_t *p_parent_category,
+                    input_item_t *p_current_input )
 {
     char **pp_dir_content = NULL;
     int             i_dir_content, i, i_return = VLC_SUCCESS;
@@ -394,7 +395,7 @@ static int ReadDir( playlist_t *p_playlist, const char *psz_name,
     {
         const char *entry = pp_dir_content[i];
         int i_size_entry = strlen( psz_name ) +
-                           strlen( entry ) + 2;
+                           strlen( entry ) + 2 + 7 /* strlen("file://") */;
         char psz_uri[i_size_entry];
 
         sprintf( psz_uri, "%s/%s", psz_name, entry);
@@ -434,13 +435,15 @@ static int ReadDir( playlist_t *p_playlist, const char *psz_name,
                 {
                     msg_Dbg(p_playlist, "creading subdirectory %s", psz_uri );
 
-                    p_node = playlist_NodeCreate (p_playlist, entry,
-                                                  p_parent_category);
+                    p_node = playlist_NodeCreate( p_playlist, entry,
+                                                  p_parent_category,
+                                                  PLAYLIST_NO_REBUILD );
 
                     /* If we had the parent in category, the it is now node.
                      * Else, we still don't have  */
                     if( ReadDir( p_playlist, psz_uri , MODE_EXPAND,
-                                 p_node, p_parent_category ? p_node : NULL )
+                                 p_node, p_parent_category ? p_node : NULL,
+                                 p_current_input )
                           != VLC_SUCCESS )
                     {
                         i_return = VLC_EGENERIC;
@@ -471,13 +474,21 @@ static int ReadDir( playlist_t *p_playlist, const char *psz_name,
                     }
                 }
 
+                memmove (psz_uri + 7, psz_uri, sizeof (psz_uri) - 7);
+                memcpy (psz_uri, "file://", 7);
                 p_input = input_ItemNewWithType( VLC_OBJECT(p_playlist),
                                                  psz_uri, entry, 0, NULL,
                                                  -1, ITEM_TYPE_VFILE );
                 if (p_input != NULL)
-                    playlist_AddWhereverNeeded (p_playlist, p_input, p_parent,
-                                                p_parent_category, VLC_FALSE,
-                                                PLAYLIST_APPEND|PLAYLIST_PREPARSE);
+                {
+                    if( p_current_input )
+                        input_ItemCopyOptions( p_current_input, p_input );
+                    playlist_BothAddInput( p_playlist, p_input,
+                                           p_parent_category,
+                                           PLAYLIST_APPEND|PLAYLIST_PREPARSE|
+                                           PLAYLIST_NO_REBUILD,
+                                           PLAYLIST_END, NULL, NULL );
+                }
             }
         }
     }