mux: mp4: add esds comments
[vlc.git] / lib / core.c
blob06fd52fbfa690f146bd90aab417c3cbb10b814ed
1 /*****************************************************************************
2 * core.c: Core libvlc new API functions : initialization
3 *****************************************************************************
4 * Copyright (C) 2005 VLC authors and VideoLAN
6 * Authors: Clément Stenac <zorglub@videolan.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include "libvlc_internal.h"
28 #include <vlc_modules.h>
29 #include <vlc/vlc.h>
31 #include <vlc_interface.h>
33 #include <stdarg.h>
34 #include <limits.h>
35 #include <assert.h>
37 #include "../src/revision.c"
39 libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
41 libvlc_threads_init ();
43 libvlc_instance_t *p_new = malloc (sizeof (*p_new));
44 if (unlikely(p_new == NULL))
45 return NULL;
47 const char *my_argv[argc + 2];
48 my_argv[0] = "libvlc"; /* dummy arg0, skipped by getopt() et al */
49 for( int i = 0; i < argc; i++ )
50 my_argv[i + 1] = argv[i];
51 my_argv[argc + 1] = NULL; /* C calling conventions require a NULL */
53 libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
54 if (unlikely (p_libvlc_int == NULL))
55 goto error;
57 if (libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv ))
59 libvlc_InternalDestroy( p_libvlc_int );
60 goto error;
63 p_new->p_libvlc_int = p_libvlc_int;
64 p_new->ref_count = 1;
65 p_new->p_callback_list = NULL;
66 vlc_mutex_init(&p_new->instance_lock);
67 return p_new;
69 error:
70 free (p_new);
71 libvlc_threads_deinit ();
72 return NULL;
75 void libvlc_retain( libvlc_instance_t *p_instance )
77 assert( p_instance != NULL );
78 assert( p_instance->ref_count < UINT_MAX );
80 vlc_mutex_lock( &p_instance->instance_lock );
81 p_instance->ref_count++;
82 vlc_mutex_unlock( &p_instance->instance_lock );
85 void libvlc_release( libvlc_instance_t *p_instance )
87 vlc_mutex_t *lock = &p_instance->instance_lock;
88 int refs;
90 vlc_mutex_lock( lock );
91 assert( p_instance->ref_count > 0 );
92 refs = --p_instance->ref_count;
93 vlc_mutex_unlock( lock );
95 if( refs == 0 )
97 vlc_mutex_destroy( lock );
98 libvlc_Quit( p_instance->p_libvlc_int );
99 libvlc_InternalCleanup( p_instance->p_libvlc_int );
100 libvlc_InternalDestroy( p_instance->p_libvlc_int );
101 free( p_instance );
102 libvlc_threads_deinit ();
106 void libvlc_set_exit_handler( libvlc_instance_t *p_i, void (*cb) (void *),
107 void *data )
109 libvlc_int_t *p_libvlc = p_i->p_libvlc_int;
110 libvlc_SetExitHandler( p_libvlc, cb, data );
113 void libvlc_set_user_agent (libvlc_instance_t *p_i,
114 const char *name, const char *http)
116 libvlc_int_t *p_libvlc = p_i->p_libvlc_int;
117 char *str;
119 var_SetString (p_libvlc, "user-agent", name);
120 if ((http != NULL)
121 && (asprintf (&str, "%s LibVLC/"PACKAGE_VERSION, http) != -1))
123 var_SetString (p_libvlc, "http-user-agent", str);
124 free (str);
128 void libvlc_set_app_id(libvlc_instance_t *p_i, const char *id,
129 const char *version, const char *icon)
131 libvlc_int_t *p_libvlc = p_i->p_libvlc_int;
133 var_SetString(p_libvlc, "app-id", id ? id : "");
134 var_SetString(p_libvlc, "app-version", version ? version : "");
135 var_SetString(p_libvlc, "app-icon-name", icon ? icon : "");
138 const char * libvlc_get_version(void)
140 return VERSION_MESSAGE;
143 const char * libvlc_get_compiler(void)
145 return VLC_Compiler();
148 const char * libvlc_get_changeset(void)
150 extern const char psz_vlc_changeset[];
151 return psz_vlc_changeset;
154 void libvlc_free( void *ptr )
156 free( ptr );
159 static libvlc_module_description_t *module_description_list_get(
160 libvlc_instance_t *p_instance, const char *capability )
162 libvlc_module_description_t *p_list = NULL,
163 *p_actual = NULL,
164 *p_previous = NULL;
165 size_t count;
166 module_t **module_list = module_list_get( &count );
168 for (size_t i = 0; i < count; i++)
170 module_t *p_module = module_list[i];
172 if ( !module_provides( p_module, capability ) )
173 continue;
175 p_actual = ( libvlc_module_description_t * ) malloc( sizeof( libvlc_module_description_t ) );
176 if ( p_actual == NULL )
178 libvlc_printerr( "Not enough memory" );
179 libvlc_module_description_list_release( p_list );
180 module_list_free( module_list );
181 return NULL;
184 if ( p_list == NULL )
185 p_list = p_actual;
187 const char* name = module_get_object( p_module );
188 const char* shortname = module_get_name( p_module, false );
189 const char* longname = module_get_name( p_module, true );
190 const char* help = module_get_help( p_module );
191 p_actual->psz_name = name ? strdup( name ) : NULL;
192 p_actual->psz_shortname = shortname ? strdup( shortname ) : NULL;
193 p_actual->psz_longname = longname ? strdup( longname ) : NULL;
194 p_actual->psz_help = help ? strdup( help ) : NULL;
196 p_actual->p_next = NULL;
197 if ( p_previous )
198 p_previous->p_next = p_actual;
199 p_previous = p_actual;
202 module_list_free( module_list );
203 VLC_UNUSED( p_instance );
204 return p_list;
207 void libvlc_module_description_list_release( libvlc_module_description_t *p_list )
209 libvlc_module_description_t *p_actual, *p_before;
210 p_actual = p_list;
212 while ( p_actual )
214 free( p_actual->psz_name );
215 free( p_actual->psz_shortname );
216 free( p_actual->psz_longname );
217 free( p_actual->psz_help );
218 p_before = p_actual;
219 p_actual = p_before->p_next;
220 free( p_before );
224 libvlc_module_description_t *libvlc_audio_filter_list_get( libvlc_instance_t *p_instance )
226 return module_description_list_get( p_instance, "audio filter" );
229 libvlc_module_description_t *libvlc_video_filter_list_get( libvlc_instance_t *p_instance )
231 return module_description_list_get( p_instance, "video filter" );
234 int64_t libvlc_clock(void)
236 return US_FROM_VLC_TICK(vlc_tick_now());
239 const char vlc_module_name[] = "libvlc";