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 *****************************************************************************/
27 #include "libvlc_internal.h"
28 #include <vlc_modules.h>
31 #include <vlc_interface.h>
38 libvlc_instance_t
* libvlc_new( int argc
, const char *const *argv
)
40 libvlc_threads_init ();
42 libvlc_instance_t
*p_new
= malloc (sizeof (*p_new
));
43 if (unlikely(p_new
== NULL
))
46 const char *my_argv
[argc
+ 2];
47 my_argv
[0] = "libvlc"; /* dummy arg0, skipped by getopt() et al */
48 for( int i
= 0; i
< argc
; i
++ )
49 my_argv
[i
+ 1] = argv
[i
];
50 my_argv
[argc
+ 1] = NULL
; /* C calling conventions require a NULL */
52 libvlc_int_t
*p_libvlc_int
= libvlc_InternalCreate();
53 if (unlikely (p_libvlc_int
== NULL
))
56 if (libvlc_InternalInit( p_libvlc_int
, argc
+ 1, my_argv
))
58 libvlc_InternalDestroy( p_libvlc_int
);
62 p_new
->p_libvlc_int
= p_libvlc_int
;
63 vlc_atomic_rc_init( &p_new
->ref_count
);
64 p_new
->p_callback_list
= NULL
;
69 libvlc_threads_deinit ();
73 void libvlc_retain( libvlc_instance_t
*p_instance
)
75 assert( p_instance
!= NULL
);
77 vlc_atomic_rc_inc( &p_instance
->ref_count
);
80 void libvlc_release( libvlc_instance_t
*p_instance
)
82 if(vlc_atomic_rc_dec( &p_instance
->ref_count
))
84 libvlc_Quit( p_instance
->p_libvlc_int
);
85 libvlc_InternalCleanup( p_instance
->p_libvlc_int
);
86 libvlc_InternalDestroy( p_instance
->p_libvlc_int
);
88 libvlc_threads_deinit ();
92 void libvlc_set_exit_handler( libvlc_instance_t
*p_i
, void (*cb
) (void *),
95 libvlc_int_t
*p_libvlc
= p_i
->p_libvlc_int
;
96 libvlc_SetExitHandler( p_libvlc
, cb
, data
);
99 void libvlc_set_user_agent (libvlc_instance_t
*p_i
,
100 const char *name
, const char *http
)
102 libvlc_int_t
*p_libvlc
= p_i
->p_libvlc_int
;
105 var_SetString (p_libvlc
, "user-agent", name
);
107 && (asprintf (&str
, "%s LibVLC/"PACKAGE_VERSION
, http
) != -1))
109 var_SetString (p_libvlc
, "http-user-agent", str
);
114 void libvlc_set_app_id(libvlc_instance_t
*p_i
, const char *id
,
115 const char *version
, const char *icon
)
117 libvlc_int_t
*p_libvlc
= p_i
->p_libvlc_int
;
119 var_SetString(p_libvlc
, "app-id", id
? id
: "");
120 var_SetString(p_libvlc
, "app-version", version
? version
: "");
121 var_SetString(p_libvlc
, "app-icon-name", icon
? icon
: "");
124 const char * libvlc_get_version(void)
126 return VERSION_MESSAGE
;
129 const char * libvlc_get_compiler(void)
131 return VLC_Compiler();
134 const char * libvlc_get_changeset(void)
136 extern const char psz_vlc_changeset
[];
137 return psz_vlc_changeset
;
140 void libvlc_free( void *ptr
)
145 static libvlc_module_description_t
*module_description_list_get(
146 libvlc_instance_t
*p_instance
, const char *capability
)
148 libvlc_module_description_t
*p_list
= NULL
,
152 module_t
**module_list
= module_list_get( &count
);
154 for (size_t i
= 0; i
< count
; i
++)
156 module_t
*p_module
= module_list
[i
];
158 if ( !module_provides( p_module
, capability
) )
161 p_actual
= ( libvlc_module_description_t
* ) malloc( sizeof( libvlc_module_description_t
) );
162 if ( p_actual
== NULL
)
164 libvlc_printerr( "Not enough memory" );
165 libvlc_module_description_list_release( p_list
);
166 module_list_free( module_list
);
170 if ( p_list
== NULL
)
173 const char* name
= module_get_object( p_module
);
174 const char* shortname
= module_get_name( p_module
, false );
175 const char* longname
= module_get_name( p_module
, true );
176 const char* help
= module_get_help( p_module
);
177 p_actual
->psz_name
= name
? strdup( name
) : NULL
;
178 p_actual
->psz_shortname
= shortname
? strdup( shortname
) : NULL
;
179 p_actual
->psz_longname
= longname
? strdup( longname
) : NULL
;
180 p_actual
->psz_help
= help
? strdup( help
) : NULL
;
182 p_actual
->p_next
= NULL
;
184 p_previous
->p_next
= p_actual
;
185 p_previous
= p_actual
;
188 module_list_free( module_list
);
189 VLC_UNUSED( p_instance
);
193 void libvlc_module_description_list_release( libvlc_module_description_t
*p_list
)
195 libvlc_module_description_t
*p_actual
, *p_before
;
200 free( p_actual
->psz_name
);
201 free( p_actual
->psz_shortname
);
202 free( p_actual
->psz_longname
);
203 free( p_actual
->psz_help
);
205 p_actual
= p_before
->p_next
;
210 libvlc_module_description_t
*libvlc_audio_filter_list_get( libvlc_instance_t
*p_instance
)
212 return module_description_list_get( p_instance
, "audio filter" );
215 libvlc_module_description_t
*libvlc_video_filter_list_get( libvlc_instance_t
*p_instance
)
217 return module_description_list_get( p_instance
, "video filter" );
220 int64_t libvlc_clock(void)
222 return US_FROM_VLC_TICK(vlc_tick_now());
225 const char vlc_module_name
[] = "libvlc";