demux: heif: refactor extents reading
[vlc.git] / lib / media_library.c
blobe0ef3cb7d2e8f6974d76c650b8de24f293331e46
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/vlc.h>
31 #include <vlc_common.h>
33 #include "libvlc_internal.h"
34 #include "media_list_internal.h"
36 struct libvlc_media_library_t
38 libvlc_event_manager_t event_manager;
39 libvlc_instance_t * p_libvlc_instance;
40 int i_refcount;
41 libvlc_media_list_t * p_mlist;
46 * Private functions
50 * Public libvlc functions
53 /**************************************************************************
54 * new (Public)
55 **************************************************************************/
56 libvlc_media_library_t *
57 libvlc_media_library_new( libvlc_instance_t * p_inst )
59 libvlc_media_library_t * p_mlib;
61 p_mlib = malloc(sizeof(libvlc_media_library_t));
63 if( !p_mlib )
65 libvlc_printerr( "Not enough memory" );
66 return NULL;
69 p_mlib->p_libvlc_instance = p_inst;
70 p_mlib->i_refcount = 1;
71 p_mlib->p_mlist = NULL;
73 libvlc_event_manager_init( &p_mlib->event_manager, p_mlib );
74 libvlc_retain( p_inst );
75 return p_mlib;
78 /**************************************************************************
79 * release (Public)
80 **************************************************************************/
81 void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
83 p_mlib->i_refcount--;
85 if( p_mlib->i_refcount > 0 )
86 return;
88 libvlc_event_manager_destroy( &p_mlib->event_manager );
89 libvlc_release( p_mlib->p_libvlc_instance );
90 free( p_mlib );
93 /**************************************************************************
94 * retain (Public)
95 **************************************************************************/
96 void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
98 p_mlib->i_refcount++;
101 /**************************************************************************
102 * load (Public)
104 * It doesn't yet load the playlists
105 **************************************************************************/
106 int libvlc_media_library_load( libvlc_media_library_t * p_mlib )
108 char *psz_datadir = config_GetUserDir( VLC_USERDATA_DIR );
109 char * psz_uri;
111 if( psz_datadir == NULL
112 || asprintf( &psz_uri, "file/directory://%s" DIR_SEP "ml.xsp",
113 psz_datadir ) == -1 )
114 psz_uri = NULL;
115 free( psz_datadir );
117 if( psz_uri == NULL )
119 libvlc_printerr( "Not enough memory" );
120 return -1;
123 if( p_mlib->p_mlist )
124 libvlc_media_list_release( p_mlib->p_mlist );
126 p_mlib->p_mlist = libvlc_media_list_new( p_mlib->p_libvlc_instance );
128 int ret = libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri );
129 free( psz_uri );
130 return ret;
133 /**************************************************************************
134 * media_list (Public)
135 **************************************************************************/
136 libvlc_media_list_t *
137 libvlc_media_library_media_list( libvlc_media_library_t * p_mlib )
139 if( p_mlib->p_mlist )
140 libvlc_media_list_retain( p_mlib->p_mlist );
141 return p_mlib->p_mlist;