Correct spelling: s/[sS]yncro/[sS]ynchro/
[vlc.git] / lib / media_library.c
blob9edc5f787726df558ad9bf9b1a1661ad86e65589
1 /*****************************************************************************
2 * media_library.c: libvlc tags tree functions
3 * Create a tree of the 'tags' of a media_list's medias.
4 *****************************************************************************
5 * Copyright (C) 2007 VLC authors and VideoLAN
6 * $Id$
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <vlc/libvlc.h>
30 #include <vlc/libvlc_media.h>
31 #include <vlc/libvlc_media_list.h>
32 #include <vlc/libvlc_media_library.h>
33 #include <vlc/libvlc_events.h>
35 #include <vlc_common.h>
37 #include "libvlc_internal.h"
39 struct libvlc_media_library_t
41 libvlc_event_manager_t * p_event_manager;
42 libvlc_instance_t * p_libvlc_instance;
43 int i_refcount;
44 libvlc_media_list_t * p_mlist;
49 * Private functions
53 * Public libvlc functions
56 /**************************************************************************
57 * new (Public)
58 **************************************************************************/
59 libvlc_media_library_t *
60 libvlc_media_library_new( libvlc_instance_t * p_inst )
62 libvlc_media_library_t * p_mlib;
64 p_mlib = malloc(sizeof(libvlc_media_library_t));
66 if( !p_mlib )
68 libvlc_printerr( "Not enough memory" );
69 return NULL;
72 p_mlib->p_libvlc_instance = p_inst;
73 p_mlib->i_refcount = 1;
74 p_mlib->p_mlist = NULL;
76 p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst );
77 if( unlikely(p_mlib->p_event_manager == NULL) )
79 free(p_mlib);
80 return NULL;
83 return p_mlib;
86 /**************************************************************************
87 * release (Public)
88 **************************************************************************/
89 void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
91 p_mlib->i_refcount--;
93 if( p_mlib->i_refcount > 0 )
94 return;
96 libvlc_event_manager_release( p_mlib->p_event_manager );
97 free( p_mlib );
100 /**************************************************************************
101 * retain (Public)
102 **************************************************************************/
103 void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
105 p_mlib->i_refcount++;
108 /**************************************************************************
109 * load (Public)
111 * It doesn't yet load the playlists
112 **************************************************************************/
113 int libvlc_media_library_load( libvlc_media_library_t * p_mlib )
115 char *psz_datadir = config_GetUserDir( VLC_DATA_DIR );
116 char * psz_uri;
118 if( psz_datadir == NULL
119 || asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
120 psz_datadir ) == -1 )
121 psz_uri = NULL;
122 free( psz_datadir );
124 if( psz_uri == NULL )
126 libvlc_printerr( "Not enough memory" );
127 return -1;
130 if( p_mlib->p_mlist )
131 libvlc_media_list_release( p_mlib->p_mlist );
133 p_mlib->p_mlist = libvlc_media_list_new( p_mlib->p_libvlc_instance );
135 int ret = libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri );
136 free( psz_uri );
137 return ret;
140 /**************************************************************************
141 * media_list (Public)
142 **************************************************************************/
143 libvlc_media_list_t *
144 libvlc_media_library_media_list( libvlc_media_library_t * p_mlib )
146 if( p_mlib->p_mlist )
147 libvlc_media_list_retain( p_mlib->p_mlist );
148 return p_mlib->p_mlist;