[vlc-devel] [PATCH 04/14] vlm: load file using a separate function
Romain Vimont
rom1v at videolabs.io
Tue Sep 15 19:37:36 CEST 2020
The "constructor" vlm_New() allowed to optionally load a VLM file.
But vlm_New() internally manages a single refcounted instance,
initialized only the first time.
Therefore, if a VLM instance was already created, the VLM file was just
ignored.
To avoid the confusion, load the file using a separate function.
---
include/vlc_vlm.h | 4 +++-
modules/gui/qt/dialogs/vlm/vlm.cpp | 2 +-
modules/lua/libs/vlm.c | 2 +-
src/input/vlm.c | 36 +++++++++++++++++-------------
src/libvlc.c | 8 ++++++-
5 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/include/vlc_vlm.h b/include/vlc_vlm.h
index cb2ebb8760..2f2032f47c 100644
--- a/include/vlc_vlm.h
+++ b/include/vlc_vlm.h
@@ -186,11 +186,13 @@ struct vlm_message_t
extern "C" {
#endif
-VLC_API vlm_t * vlm_New( libvlc_int_t *, const char *path );
+VLC_API vlm_t * vlm_New( libvlc_int_t * );
VLC_API void vlm_Delete( vlm_t * );
VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
+VLC_API int vlm_LoadFile( vlm_t *p_vlm, const char *psz_vlmconf );
+
VLC_API vlm_message_t * vlm_MessageSimpleNew( const char * );
VLC_API vlm_message_t * vlm_MessageNew( const char *, const char *, ... ) VLC_FORMAT( 2, 3 );
VLC_API vlm_message_t * vlm_MessageAdd( vlm_message_t *, vlm_message_t * );
diff --git a/modules/gui/qt/dialogs/vlm/vlm.cpp b/modules/gui/qt/dialogs/vlm/vlm.cpp
index ce24eefa44..fdbbc116ee 100644
--- a/modules/gui/qt/dialogs/vlm/vlm.cpp
+++ b/modules/gui/qt/dialogs/vlm/vlm.cpp
@@ -54,7 +54,7 @@
VLMDialog::VLMDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
{
- vlm_t *p_vlm = vlm_New( vlc_object_instance(p_intf), NULL );
+ vlm_t *p_vlm = vlm_New( vlc_object_instance(p_intf) );
if( !p_vlm )
{
diff --git a/modules/lua/libs/vlm.c b/modules/lua/libs/vlm.c
index eeb19b164d..167dbebe0c 100644
--- a/modules/lua/libs/vlm.c
+++ b/modules/lua/libs/vlm.c
@@ -52,7 +52,7 @@ static const luaL_Reg vlclua_vlm_reg[] = {
static int vlclua_vlm_new( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
- vlm_t *p_vlm = vlm_New( vlc_object_instance(p_this), NULL );
+ vlm_t *p_vlm = vlm_New( vlc_object_instance(p_this) );
if( !p_vlm )
return luaL_error( L, "Cannot start VLM." );
diff --git a/src/input/vlm.c b/src/input/vlm.c
index da05442d77..ad69d476a0 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -106,7 +106,7 @@ static vlc_mutex_t vlm_mutex = VLC_STATIC_MUTEX;
/*****************************************************************************
* vlm_New:
*****************************************************************************/
-vlm_t *vlm_New( libvlc_int_t *libvlc, const char *psz_vlmconf )
+vlm_t *vlm_New( libvlc_int_t *libvlc )
{
vlm_t *p_vlm = NULL, **pp_vlm = &(libvlc_priv(libvlc)->p_vlm);
vlc_object_t *p_this = VLC_OBJECT(libvlc);
@@ -156,25 +156,29 @@ vlm_t *vlm_New( libvlc_int_t *libvlc, const char *psz_vlmconf )
vlc_mutex_unlock( &vlm_mutex );
- /* Load our configuration file */
- if( psz_vlmconf != NULL )
- {
- vlm_message_t *p_message = NULL;
- char *psz_buffer = NULL;
+ return p_vlm;
+}
- msg_Dbg( p_this, "loading VLM configuration" );
- if( asprintf(&psz_buffer, "load %s", psz_vlmconf ) != -1 )
- {
- msg_Dbg( p_this, "%s", psz_buffer );
- if( vlm_ExecuteCommand( p_vlm, psz_buffer, &p_message ) )
- msg_Warn( p_this, "error while loading the configuration file" );
+int vlm_LoadFile( vlm_t *p_vlm, const char *psz_vlmconf )
+{
+ vlm_message_t *p_message = NULL;
+ char *psz_buffer = NULL;
- vlm_MessageDelete( p_message );
- free( psz_buffer );
- }
+ msg_Dbg( p_vlm, "loading VLM configuration" );
+ if( asprintf(&psz_buffer, "load %s", psz_vlmconf ) == -1 )
+ return VLC_ENOMEM;
+
+ msg_Dbg( p_vlm, "%s", psz_buffer );
+ if( vlm_ExecuteCommand( p_vlm, psz_buffer, &p_message ) )
+ {
+ msg_Warn( p_vlm, "error while loading the configuration file" );
+ return VLC_EGENERIC;
}
- return p_vlm;
+ vlm_MessageDelete( p_message );
+ free( psz_buffer );
+
+ return VLC_SUCCESS;
}
/*****************************************************************************
diff --git a/src/libvlc.c b/src/libvlc.c
index c1dcde276d..36707c7e71 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -266,9 +266,15 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
char *psz_parser = var_InheritString( p_libvlc, "vlm-conf" );
if( psz_parser )
{
- priv->p_vlm = vlm_New( p_libvlc, psz_parser );
+ priv->p_vlm = vlm_New( p_libvlc );
if( !priv->p_vlm )
msg_Err( p_libvlc, "VLM initialization failed" );
+ else if( vlm_LoadFile( priv->p_vlm, psz_parser ) != VLC_SUCCESS )
+ {
+ msg_Err( p_libvlc, "VLM file loading failed" );
+ vlm_Delete( priv->p_vlm );
+ }
+
free( psz_parser );
}
#endif
--
2.28.0
More information about the vlc-devel
mailing list