]> git.sesse.net Git - vlc/blob - modules/demux/playlist/directory.c
b4s: memory leak
[vlc] / modules / demux / playlist / directory.c
1 /*****************************************************************************
2  * directory.c : Use access readdir to output folder content to playlist
3  *****************************************************************************
4  * Copyright (C) 2014 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Julien 'Lta' BALLET <contact # lta . io >
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_demux.h>
33
34 #include "playlist.h"
35
36 /*****************************************************************************
37  * Local prototypes
38  *****************************************************************************/
39 static int Demux( demux_t *p_demux );
40
41
42 int Import_Dir ( vlc_object_t *p_this)
43 {
44     demux_t  *p_demux = (demux_t *)p_this;
45
46     bool b_is_dir = false;
47     int i_err = stream_Control( p_demux->s, STREAM_IS_DIRECTORY, &b_is_dir );
48
49     if ( !( i_err == VLC_SUCCESS && b_is_dir ) )
50         return VLC_EGENERIC;
51
52     p_demux->pf_control = Control;
53     p_demux->pf_demux = Demux;
54     msg_Dbg( p_demux, "reading directory content" );
55
56     return VLC_SUCCESS;
57 }
58
59 void Close_Dir ( vlc_object_t *p_this )
60 {
61     VLC_UNUSED(p_this);
62 }
63
64 static int Demux( demux_t *p_demux )
65 {
66     input_item_t *p_input = GetCurrentItem(p_demux);
67     input_item_node_t *p_node = input_item_node_Create( p_input );
68     input_item_Release(p_input);
69
70     if( stream_ReadDir( p_demux->s, p_node ) )
71     {
72         input_item_node_Delete( p_node );
73         return VLC_EGENERIC;
74     }
75     else
76         msg_Warn( p_demux, "unable to read directory" );
77
78     input_item_node_PostAndDelete( p_node );
79     return VLC_SUCCESS;
80 }