[vlc-devel] [PATCH 10/14] vlm: extract core-part to a separate file
Romain Vimont
rom1v at videolabs.io
Tue Sep 15 19:37:42 CEST 2020
This prepares moving the remaining parts to a separate module.
---
src/Makefile.am | 3 +-
src/input/vlm.c | 109 +-------------------
src/input/vlm_internal.h | 3 +
src/input/vlmcore.c | 211 +++++++++++++++++++++++++++++++++++++++
src/input/vlmshell.c | 71 -------------
5 files changed, 217 insertions(+), 180 deletions(-)
create mode 100644 src/input/vlmcore.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 6dc46ab3d6..408a4354c2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -512,7 +512,8 @@ libvlccore_la_SOURCES += \
stream_output/sap.c \
stream_output/stream_output.c stream_output/stream_output.h
if ENABLE_VLM
-libvlccore_la_SOURCES += input/vlm.c input/vlm_event.c input/vlmshell.c
+libvlccore_la_SOURCES += input/vlm.c input/vlm_event.c input/vlmshell.c \
+ input/vlmcore.c
endif
endif
diff --git a/src/input/vlm.c b/src/input/vlm.c
index caef8b3693..5abba9ed17 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -46,15 +46,6 @@
#include "vlm_event.h"
#include <vlc_sout.h>
#include <vlc_url.h>
-#include "../libvlc.h"
-
-typedef struct vlm_priv
-{
- vlm_t vlm;
- unsigned users;
-} vlm_priv_t ;
-
-#define vlm_priv(v) container_of(v, vlm_priv_t, vlm)
/*****************************************************************************
* Local prototypes.
@@ -108,8 +99,6 @@ static void player_on_state_changed(vlc_player_t *player,
vlc_mutex_unlock( &sys->lock_manage );
}
-static vlc_mutex_t vlm_mutex = VLC_STATIC_MUTEX;
-
static int ExecuteCommandImpl( vlm_t *vlm, const char *cmd,
vlm_message_t **msg_out );
static int VaControlImpl( vlm_t *vlm, int query, va_list args );
@@ -124,7 +113,7 @@ static const struct vlm_ops vlm_ops = {
/*****************************************************************************
* vlm_New:
*****************************************************************************/
-static int vlm_Open( vlm_t *p_vlm )
+int vlm_Open( vlm_t *p_vlm )
{
vlm_sys_t *sys = p_vlm->sys = malloc( sizeof( *sys ) );
if (!sys)
@@ -151,76 +140,6 @@ static int vlm_Open( vlm_t *p_vlm )
return VLC_SUCCESS;
}
-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);
-
- /* Avoid multiple creation */
- vlc_mutex_lock( &vlm_mutex );
-
- p_vlm = *pp_vlm;
- if( p_vlm )
- { /* VLM already exists */
- vlm_priv_t *priv = vlm_priv( p_vlm );
- if( likely( priv->users < UINT_MAX ) )
- priv->users++;
- else
- p_vlm = NULL;
- vlc_mutex_unlock( &vlm_mutex );
- return p_vlm;
- }
-
- msg_Dbg( p_this, "creating VLM" );
-
- vlm_priv_t *priv = vlc_custom_create( p_this, sizeof( *priv ), "vlm daemon" );
- if( !priv )
- {
- vlc_mutex_unlock( &vlm_mutex );
- return NULL;
- }
-
- priv->users = 1;
-
- p_vlm = &priv->vlm;
-
- int ret = vlm_Open(p_vlm);
- if (ret != VLC_SUCCESS)
- {
- vlc_object_delete(p_vlm);
- vlc_mutex_unlock( &vlm_mutex );
- return NULL;
- }
-
- *pp_vlm = p_vlm; /* for future reference */
-
- vlc_mutex_unlock( &vlm_mutex );
-
- return p_vlm;
-}
-
-int vlm_LoadFile( vlm_t *p_vlm, const char *psz_vlmconf )
-{
- vlm_message_t *p_message = NULL;
- char *psz_buffer = NULL;
-
- 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;
- }
-
- vlm_MessageDelete( p_message );
- free( psz_buffer );
-
- return VLC_SUCCESS;
-}
-
/*****************************************************************************
* vlm_Delete:
*****************************************************************************/
@@ -246,32 +165,6 @@ static void vlm_Close( vlm_t *p_vlm )
free(sys);
}
-void vlm_Delete( vlm_t *p_vlm )
-{
- /* vlm_Delete() is serialized against itself, and against vlm_New().
- * This mutex protects libvlc_priv->p_vlm and p_vlm->users. */
- vlc_mutex_lock( &vlm_mutex );
-
- vlm_priv_t *priv = vlm_priv( p_vlm );
- assert( priv->users > 0 );
- if( --priv->users == 0 )
- assert( libvlc_priv(vlc_object_instance(p_vlm))->p_vlm == p_vlm );
- else
- p_vlm = NULL;
-
- if( p_vlm == NULL )
- {
- vlc_mutex_unlock( &vlm_mutex );
- return;
- }
-
- libvlc_priv(vlc_object_instance(p_vlm))->p_vlm = NULL;
- vlc_mutex_unlock( &vlm_mutex );
-
- p_vlm->ops->close(p_vlm);
- vlc_object_delete(p_vlm);
-}
-
/*****************************************************************************
* vlm_ExecuteCommand:
*****************************************************************************/
diff --git a/src/input/vlm_internal.h b/src/input/vlm_internal.h
index 32e41ccaf6..d92b803468 100644
--- a/src/input/vlm_internal.h
+++ b/src/input/vlm_internal.h
@@ -98,4 +98,7 @@ int vlm_ControlInternal( vlm_t *p_vlm, int i_query, ... );
int ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched );
+/* Tempory, until the VLM implementation is actually moved to a module */
+int vlm_Open(vlm_t *vlm);
+
#endif
diff --git a/src/input/vlmcore.c b/src/input/vlmcore.c
new file mode 100644
index 0000000000..b8180604c6
--- /dev/null
+++ b/src/input/vlmcore.c
@@ -0,0 +1,211 @@
+/*****************************************************************************
+ * vlmcore.c
+ *****************************************************************************
+ * Copyright (C) 2000-2005 VLC authors and VideoLAN
+ *
+ * Authors: Simon Latapie <garf at videolan.org>
+ * Laurent Aimar <fenrir at videolan.org>
+ * Gildas Bazin <gbazin at videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_vlm.h>
+#include <limits.h>
+#include "vlm_internal.h"
+#include "../libvlc.h"
+
+typedef struct vlm_priv
+{
+ vlm_t vlm;
+ unsigned users;
+} vlm_priv_t ;
+
+#define vlm_priv(v) container_of(v, vlm_priv_t, vlm)
+
+static vlc_mutex_t vlm_mutex = VLC_STATIC_MUTEX;
+
+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);
+
+ /* Avoid multiple creation */
+ vlc_mutex_lock( &vlm_mutex );
+
+ p_vlm = *pp_vlm;
+ if( p_vlm )
+ { /* VLM already exists */
+ vlm_priv_t *priv = vlm_priv( p_vlm );
+ if( likely( priv->users < UINT_MAX ) )
+ priv->users++;
+ else
+ p_vlm = NULL;
+ vlc_mutex_unlock( &vlm_mutex );
+ return p_vlm;
+ }
+
+ msg_Dbg( p_this, "creating VLM" );
+
+ vlm_priv_t *priv = vlc_custom_create( p_this, sizeof( *priv ), "vlm daemon" );
+ if( !priv )
+ {
+ vlc_mutex_unlock( &vlm_mutex );
+ return NULL;
+ }
+
+ priv->users = 1;
+
+ p_vlm = &priv->vlm;
+
+ int ret = vlm_Open(p_vlm);
+ if (ret != VLC_SUCCESS)
+ {
+ vlc_object_delete(p_vlm);
+ vlc_mutex_unlock( &vlm_mutex );
+ return NULL;
+ }
+
+ *pp_vlm = p_vlm; /* for future reference */
+
+ vlc_mutex_unlock( &vlm_mutex );
+
+ return p_vlm;
+}
+
+void vlm_Delete( vlm_t *p_vlm )
+{
+ /* vlm_Delete() is serialized against itself, and against vlm_New().
+ * This mutex protects libvlc_priv->p_vlm and p_vlm->users. */
+ vlc_mutex_lock( &vlm_mutex );
+
+ vlm_priv_t *priv = vlm_priv( p_vlm );
+ assert( priv->users > 0 );
+ if( --priv->users == 0 )
+ assert( libvlc_priv(vlc_object_instance(p_vlm))->p_vlm == p_vlm );
+ else
+ p_vlm = NULL;
+
+ if( p_vlm == NULL )
+ {
+ vlc_mutex_unlock( &vlm_mutex );
+ return;
+ }
+
+ libvlc_priv(vlc_object_instance(p_vlm))->p_vlm = NULL;
+ vlc_mutex_unlock( &vlm_mutex );
+
+ p_vlm->ops->close(p_vlm);
+ vlc_object_delete(p_vlm);
+}
+
+int vlm_LoadFile( vlm_t *p_vlm, const char *psz_vlmconf )
+{
+ vlm_message_t *p_message = NULL;
+ char *psz_buffer = NULL;
+
+ 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;
+ }
+
+ vlm_MessageDelete( p_message );
+ free( psz_buffer );
+
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Message handling functions
+ *****************************************************************************/
+vlm_message_t *vlm_MessageSimpleNew( const char *psz_name )
+{
+ if( !psz_name ) return NULL;
+
+ vlm_message_t *p_message = malloc( sizeof(*p_message) );
+ if( !p_message )
+ return NULL;
+
+ p_message->psz_name = strdup( psz_name );
+ if( !p_message->psz_name )
+ {
+ free( p_message );
+ return NULL;
+ }
+ p_message->psz_value = NULL;
+ p_message->i_child = 0;
+ p_message->child = NULL;
+
+ return p_message;
+}
+
+vlm_message_t *vlm_MessageNew( const char *psz_name,
+ const char *psz_format, ... )
+{
+ vlm_message_t *p_message = vlm_MessageSimpleNew( psz_name );
+ va_list args;
+
+ if( !p_message )
+ return NULL;
+
+ assert( psz_format );
+ va_start( args, psz_format );
+ if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
+ p_message->psz_value = NULL;
+ va_end( args );
+
+ if( !p_message->psz_value )
+ {
+ vlm_MessageDelete( p_message );
+ return NULL;
+ }
+ return p_message;
+}
+
+void vlm_MessageDelete( vlm_message_t *p_message )
+{
+ free( p_message->psz_name );
+ free( p_message->psz_value );
+ while( p_message->i_child-- )
+ vlm_MessageDelete( p_message->child[p_message->i_child] );
+ free( p_message->child );
+ free( p_message );
+}
+
+/* Add a child */
+vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
+ vlm_message_t *p_child )
+{
+ if( p_message == NULL ) return NULL;
+
+ if( p_child )
+ {
+ TAB_APPEND( p_message->i_child, p_message->child, p_child );
+ }
+
+ return p_child;
+}
+
diff --git a/src/input/vlmshell.c b/src/input/vlmshell.c
index e3970aa0da..5f3070d080 100644
--- a/src/input/vlmshell.c
+++ b/src/input/vlmshell.c
@@ -1194,77 +1194,6 @@ static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
return 0;
}
-/*****************************************************************************
- * Message handling functions
- *****************************************************************************/
-vlm_message_t *vlm_MessageSimpleNew( const char *psz_name )
-{
- if( !psz_name ) return NULL;
-
- vlm_message_t *p_message = malloc( sizeof(*p_message) );
- if( !p_message )
- return NULL;
-
- p_message->psz_name = strdup( psz_name );
- if( !p_message->psz_name )
- {
- free( p_message );
- return NULL;
- }
- p_message->psz_value = NULL;
- p_message->i_child = 0;
- p_message->child = NULL;
-
- return p_message;
-}
-
-vlm_message_t *vlm_MessageNew( const char *psz_name,
- const char *psz_format, ... )
-{
- vlm_message_t *p_message = vlm_MessageSimpleNew( psz_name );
- va_list args;
-
- if( !p_message )
- return NULL;
-
- assert( psz_format );
- va_start( args, psz_format );
- if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
- p_message->psz_value = NULL;
- va_end( args );
-
- if( !p_message->psz_value )
- {
- vlm_MessageDelete( p_message );
- return NULL;
- }
- return p_message;
-}
-
-void vlm_MessageDelete( vlm_message_t *p_message )
-{
- free( p_message->psz_name );
- free( p_message->psz_value );
- while( p_message->i_child-- )
- vlm_MessageDelete( p_message->child[p_message->i_child] );
- free( p_message->child );
- free( p_message );
-}
-
-/* Add a child */
-vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
- vlm_message_t *p_child )
-{
- if( p_message == NULL ) return NULL;
-
- if( p_child )
- {
- TAB_APPEND( p_message->i_child, p_message->child, p_child );
- }
-
- return p_child;
-}
-
/*****************************************************************************
* Misc utility functions
*****************************************************************************/
--
2.28.0
More information about the vlc-devel
mailing list