[vlc-devel] [PATCH 07/14] vlm: move vlm fields to sys
Romain Vimont
rom1v at videolabs.io
Tue Sep 15 19:37:39 CEST 2020
This paves the way to move the implementation to a separate module.
---
include/vlc_vlm.h | 6 ++
src/input/vlm.c | 166 +++++++++++++++++++++++----------------
src/input/vlm_internal.h | 6 +-
src/input/vlmshell.c | 58 ++++++++------
4 files changed, 141 insertions(+), 95 deletions(-)
diff --git a/include/vlc_vlm.h b/include/vlc_vlm.h
index 2f2032f47c..1338f8af72 100644
--- a/include/vlc_vlm.h
+++ b/include/vlc_vlm.h
@@ -26,6 +26,12 @@
#include <vlc_input.h>
+struct vlm_t
+{
+ struct vlc_object_t obj;
+ void *sys;
+};
+
/**
* \defgroup server VLM
* \ingroup interface
diff --git a/src/input/vlm.c b/src/input/vlm.c
index bd75108498..bb876011dc 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -68,6 +68,7 @@ static void player_on_state_changed(vlc_player_t *player,
vlm_media_sys_t *p_media = data;
vlm_t *p_vlm = p_media->vlm;
assert( p_vlm );
+ vlm_sys_t *sys = p_vlm->sys;
const char *psz_instance_name = NULL;
for( int i = 0; i < p_media->i_instance; i++ )
@@ -101,10 +102,10 @@ static void player_on_state_changed(vlc_player_t *player,
}
vlm_SendEventMediaInstanceState( p_vlm, p_media->cfg.id, p_media->cfg.psz_name, psz_instance_name, vlm_state );
- vlc_mutex_lock( &p_vlm->lock_manage );
- p_vlm->input_state_changed = true;
- vlc_cond_signal( &p_vlm->wait_manage );
- vlc_mutex_unlock( &p_vlm->lock_manage );
+ vlc_mutex_lock( &sys->lock_manage );
+ sys->input_state_changed = true;
+ vlc_cond_signal( &sys->wait_manage );
+ vlc_mutex_unlock( &sys->lock_manage );
}
static vlc_mutex_t vlm_mutex = VLC_STATIC_MUTEX;
@@ -145,18 +146,27 @@ vlm_t *vlm_New( libvlc_int_t *libvlc )
p_vlm = &priv->vlm;
- vlc_mutex_init( &p_vlm->lock );
- vlc_mutex_init( &p_vlm->lock_manage );
- vlc_cond_init( &p_vlm->wait_manage );
- p_vlm->input_state_changed = false;
- p_vlm->exiting = false;
- p_vlm->i_id = 1;
- TAB_INIT( p_vlm->i_media, p_vlm->media );
- TAB_INIT( p_vlm->i_schedule, p_vlm->schedule );
+ vlm_sys_t *sys = p_vlm->sys = malloc( sizeof( *sys ) );
+ if (!sys)
+ {
+ vlc_mutex_unlock( &vlm_mutex );
+ vlc_object_delete( p_vlm );
+ return NULL;
+ }
+
+ vlc_mutex_init( &sys->lock );
+ vlc_mutex_init( &sys->lock_manage );
+ vlc_cond_init( &sys->wait_manage );
+ sys->input_state_changed = false;
+ sys->exiting = false;
+ sys->i_id = 1;
+ TAB_INIT( sys->i_media, sys->media );
+ TAB_INIT( sys->i_schedule, sys->schedule );
var_Create( p_vlm, "intf-event", VLC_VAR_ADDRESS );
- if( vlc_clone( &p_vlm->thread, Manage, p_vlm, VLC_THREAD_PRIORITY_LOW ) )
+ if( vlc_clone( &sys->thread, Manage, p_vlm, VLC_THREAD_PRIORITY_LOW ) )
{
+ free(sys);
vlc_object_delete(p_vlm);
vlc_mutex_unlock( &vlm_mutex );
return NULL;
@@ -213,24 +223,27 @@ void vlm_Delete( vlm_t *p_vlm )
return;
}
+ vlm_sys_t *sys = p_vlm->sys;
+
/* Destroy and release VLM */
- vlc_mutex_lock( &p_vlm->lock );
+ vlc_mutex_lock( &sys->lock );
vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
- TAB_CLEAN( p_vlm->i_media, p_vlm->media );
+ TAB_CLEAN( sys->i_media, sys->media );
vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
- TAB_CLEAN( p_vlm->i_schedule, p_vlm->schedule );
- vlc_mutex_unlock( &p_vlm->lock );
+ TAB_CLEAN( sys->i_schedule, sys->schedule );
+ vlc_mutex_unlock( &sys->lock );
- vlc_mutex_lock( &p_vlm->lock_manage );
- p_vlm->exiting = true;
- vlc_cond_signal( &p_vlm->wait_manage );
- vlc_mutex_unlock( &p_vlm->lock_manage );
+ vlc_mutex_lock( &sys->lock_manage );
+ sys->exiting = true;
+ vlc_cond_signal( &sys->wait_manage );
+ vlc_mutex_unlock( &sys->lock_manage );
libvlc_priv(vlc_object_instance(p_vlm))->p_vlm = NULL;
vlc_mutex_unlock( &vlm_mutex );
- vlc_join( p_vlm->thread, NULL );
+ vlc_join( sys->thread, NULL );
+ free(sys);
vlc_object_delete(p_vlm);
}
@@ -242,9 +255,11 @@ int vlm_ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
{
int i_result;
- vlc_mutex_lock( &p_vlm->lock );
+ vlm_sys_t *sys = p_vlm->sys;
+
+ vlc_mutex_lock( &sys->lock );
i_result = ExecuteCommand( p_vlm, psz_command, pp_message );
- vlc_mutex_unlock( &p_vlm->lock );
+ vlc_mutex_unlock( &sys->lock );
return i_result;
}
@@ -255,6 +270,7 @@ int vlm_ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
static void* Manage( void* p_object )
{
vlm_t *vlm = (vlm_t*)p_object;
+ vlm_sys_t *sys = vlm->sys;
time_t lastcheck;
bool exiting;
@@ -266,10 +282,10 @@ static void* Manage( void* p_object )
int i_scheduled_commands = 0;
/* destroy the inputs that wants to die, and launch the next input */
- vlc_mutex_lock( &vlm->lock );
- for( int i = 0; i < vlm->i_media; i++ )
+ vlc_mutex_lock( &sys->lock );
+ for( int i = 0; i < sys->i_media; i++ )
{
- vlm_media_sys_t *p_media = vlm->media[i];
+ vlm_media_sys_t *p_media = sys->media[i];
for( int j = 0; j < p_media->i_instance; )
{
@@ -306,43 +322,43 @@ static void* Manage( void* p_object )
time(&now);
- for( int i = 0; i < vlm->i_schedule; i++ )
+ for( int i = 0; i < sys->i_schedule; i++ )
{
- time_t real_date = vlm->schedule[i]->date;
+ time_t real_date = sys->schedule[i]->date;
- if( vlm->schedule[i]->b_enabled )
+ if( sys->schedule[i]->b_enabled )
{
bool b_now = false;
- if( vlm->schedule[i]->date == 0 ) // now !
+ if( sys->schedule[i]->date == 0 ) // now !
{
- vlm->schedule[i]->date = now;
+ sys->schedule[i]->date = now;
real_date = now;
b_now = true;
}
- else if( vlm->schedule[i]->period != 0 )
+ else if( sys->schedule[i]->period != 0 )
{
int j = 0;
- while( ((vlm->schedule[i]->date + j *
- vlm->schedule[i]->period) <= lastcheck) &&
- ( vlm->schedule[i]->i_repeat > j ||
- vlm->schedule[i]->i_repeat < 0 ) )
+ while( ((sys->schedule[i]->date + j *
+ sys->schedule[i]->period) <= lastcheck) &&
+ ( sys->schedule[i]->i_repeat > j ||
+ sys->schedule[i]->i_repeat < 0 ) )
{
j++;
}
- real_date = vlm->schedule[i]->date + j *
- vlm->schedule[i]->period;
+ real_date = sys->schedule[i]->date + j *
+ sys->schedule[i]->period;
}
if( real_date <= now )
{
if( real_date > lastcheck || b_now )
{
- for( int j = 0; j < vlm->schedule[i]->i_command; j++ )
+ for( int j = 0; j < sys->schedule[i]->i_command; j++ )
{
TAB_APPEND( i_scheduled_commands,
ppsz_scheduled_commands,
- strdup(vlm->schedule[i]->command[j] ) );
+ strdup(sys->schedule[i]->command[j] ) );
}
}
}
@@ -368,24 +384,24 @@ static void* Manage( void* p_object )
}
lastcheck = now;
- vlc_mutex_unlock( &vlm->lock );
+ vlc_mutex_unlock( &sys->lock );
- vlc_mutex_lock( &vlm->lock_manage );
+ vlc_mutex_lock( &sys->lock_manage );
- while( !vlm->input_state_changed && !(exiting = vlm->exiting) )
+ while( !sys->input_state_changed && !(exiting = sys->exiting) )
{
if( nextschedule )
{
- if( vlc_cond_timedwait_daytime( &vlm->wait_manage,
- &vlm->lock_manage,
+ if( vlc_cond_timedwait_daytime( &sys->wait_manage,
+ &sys->lock_manage,
nextschedule ) )
break;
}
else
- vlc_cond_wait( &vlm->wait_manage, &vlm->lock_manage );
+ vlc_cond_wait( &sys->wait_manage, &sys->lock_manage );
}
- vlm->input_state_changed = false;
- vlc_mutex_unlock( &vlm->lock_manage );
+ sys->input_state_changed = false;
+ vlc_mutex_unlock( &sys->lock_manage );
}
while( !exiting );
@@ -410,33 +426,36 @@ typedef struct
/* */
static vlm_media_sys_t *vlm_ControlMediaGetById( vlm_t *p_vlm, int64_t id )
{
- for( int i = 0; i < p_vlm->i_media; i++ )
+ vlm_sys_t *sys = p_vlm->sys;
+ for( int i = 0; i < sys->i_media; i++ )
{
- if( p_vlm->media[i]->cfg.id == id )
- return p_vlm->media[i];
+ if( sys->media[i]->cfg.id == id )
+ return sys->media[i];
}
return NULL;
}
static vlm_media_sys_t *vlm_ControlMediaGetByName( vlm_t *p_vlm, const char *psz_name )
{
- for( int i = 0; i < p_vlm->i_media; i++ )
+ vlm_sys_t *sys = p_vlm->sys;
+ for( int i = 0; i < sys->i_media; i++ )
{
- if( !strcmp( p_vlm->media[i]->cfg.psz_name, psz_name ) )
- return p_vlm->media[i];
+ if( !strcmp( sys->media[i]->cfg.psz_name, psz_name ) )
+ return sys->media[i];
}
return NULL;
}
static int vlm_MediaDescriptionCheck( vlm_t *p_vlm, vlm_media_t *p_cfg )
{
+ vlm_sys_t *sys = p_vlm->sys;
if( !p_cfg || !p_cfg->psz_name ||
!strcmp( p_cfg->psz_name, "all" ) || !strcmp( p_cfg->psz_name, "media" ) || !strcmp( p_cfg->psz_name, "schedule" ) )
return VLC_EGENERIC;
- for( int i = 0; i < p_vlm->i_media; i++ )
+ for( int i = 0; i < sys->i_media; i++ )
{
- if( p_vlm->media[i]->cfg.id == p_cfg->id )
+ if( sys->media[i]->cfg.id == p_cfg->id )
continue;
- if( !strcmp( p_vlm->media[i]->cfg.psz_name, p_cfg->psz_name ) )
+ if( !strcmp( sys->media[i]->cfg.psz_name, p_cfg->psz_name ) )
return VLC_EGENERIC;
}
return VLC_SUCCESS;
@@ -476,6 +495,7 @@ static int vlm_ControlMediaChange( vlm_t *p_vlm, vlm_media_t *p_cfg )
static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id )
{
+ vlm_sys_t *sys = p_vlm->sys;
vlm_media_sys_t *p_media;
if( vlm_MediaDescriptionCheck( p_vlm, p_cfg ) || vlm_ControlMediaGetByName( p_vlm, p_cfg->psz_name ) )
@@ -491,13 +511,13 @@ static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id
p_media->vlm = p_vlm;
vlm_media_Copy( &p_media->cfg, p_cfg );
- p_media->cfg.id = p_vlm->i_id++;
+ p_media->cfg.id = sys->i_id++;
/* FIXME do we do something here if enabled is true ? */
TAB_INIT( p_media->i_instance, p_media->instance );
/* */
- TAB_APPEND( p_vlm->i_media, p_vlm->media, p_media );
+ TAB_APPEND( sys->i_media, sys->media, p_media );
if( p_id )
*p_id = p_media->cfg.id;
@@ -509,6 +529,7 @@ static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id
static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id )
{
+ vlm_sys_t *sys = p_vlm->sys;
vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
if( !p_media )
@@ -522,7 +543,7 @@ static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id )
vlm_media_Clean( &p_media->cfg );
- TAB_REMOVE( p_vlm->i_media, p_vlm->media, p_media );
+ TAB_REMOVE( sys->i_media, sys->media, p_media );
free(p_media);
return VLC_SUCCESS;
@@ -530,13 +551,15 @@ static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id )
static int vlm_ControlMediaGets( vlm_t *p_vlm, vlm_media_t ***ppp_dsc, int *pi_dsc )
{
+ vlm_sys_t *sys = p_vlm->sys;
+
vlm_media_t **pp_dsc;
int i_dsc;
TAB_INIT( i_dsc, pp_dsc );
- for( int i = 0; i < p_vlm->i_media; i++ )
+ for( int i = 0; i < sys->i_media; i++ )
{
- vlm_media_t *p_dsc = vlm_media_Duplicate( &p_vlm->media[i]->cfg );
+ vlm_media_t *p_dsc = vlm_media_Duplicate( &sys->media[i]->cfg );
TAB_APPEND( i_dsc, pp_dsc, p_dsc );
}
@@ -547,8 +570,10 @@ static int vlm_ControlMediaGets( vlm_t *p_vlm, vlm_media_t ***ppp_dsc, int *pi_d
}
static int vlm_ControlMediaClear( vlm_t *p_vlm )
{
- while( p_vlm->i_media > 0 )
- vlm_ControlMediaDel( p_vlm, p_vlm->media[0]->cfg.id );
+ vlm_sys_t *sys = p_vlm->sys;
+
+ while( sys->i_media > 0 )
+ vlm_ControlMediaDel( p_vlm, sys->media[0]->cfg.id );
return VLC_SUCCESS;
}
@@ -840,8 +865,9 @@ static int vlm_ControlMediaInstanceClear( vlm_t *p_vlm, int64_t id )
static int vlm_ControlScheduleClear( vlm_t *p_vlm )
{
- while( p_vlm->i_schedule > 0 )
- vlm_ScheduleDelete( p_vlm, p_vlm->schedule[0] );
+ vlm_sys_t *sys = p_vlm->sys;
+ while( sys->i_schedule > 0 )
+ vlm_ScheduleDelete( p_vlm, sys->schedule[0] );
return VLC_SUCCESS;
}
@@ -971,14 +997,16 @@ int vlm_ControlInternal( vlm_t *p_vlm, int i_query, ... )
int vlm_Control( vlm_t *p_vlm, int i_query, ... )
{
+ vlm_sys_t *sys = p_vlm->sys;
+
va_list args;
int i_result;
va_start( args, i_query );
- vlc_mutex_lock( &p_vlm->lock );
+ vlc_mutex_lock( &sys->lock );
i_result = vlm_vaControlInternal( p_vlm, i_query, args );
- vlc_mutex_unlock( &p_vlm->lock );
+ vlc_mutex_unlock( &sys->lock );
va_end( args );
diff --git a/src/input/vlm_internal.h b/src/input/vlm_internal.h
index c54779ef96..32e41ccaf6 100644
--- a/src/input/vlm_internal.h
+++ b/src/input/vlm_internal.h
@@ -72,10 +72,8 @@ typedef struct
} vlm_schedule_sys_t;
-struct vlm_t
+typedef struct vlm_sys
{
- struct vlc_object_t obj;
-
vlc_mutex_t lock;
vlc_thread_t thread;
vlc_mutex_t lock_manage;
@@ -94,7 +92,7 @@ struct vlm_t
/* Schedule list */
int i_schedule;
vlm_schedule_sys_t **schedule;
-};
+} vlm_sys_t;
int vlm_ControlInternal( vlm_t *p_vlm, int i_query, ... );
int ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
diff --git a/src/input/vlmshell.c b/src/input/vlmshell.c
index 086c595bc7..e3970aa0da 100644
--- a/src/input/vlmshell.c
+++ b/src/input/vlmshell.c
@@ -628,10 +628,12 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
}
*pp_status = vlm_MessageSimpleNew( psz_cmd );
- vlc_mutex_lock( &p_vlm->lock_manage );
- p_vlm->input_state_changed = true;
- vlc_cond_signal( &p_vlm->wait_manage );
- vlc_mutex_unlock( &p_vlm->lock_manage );
+ vlm_sys_t *sys = p_vlm->sys;
+
+ vlc_mutex_lock( &sys->lock_manage );
+ sys->input_state_changed = true;
+ vlc_cond_signal( &sys->wait_manage );
+ vlc_mutex_unlock( &sys->lock_manage );
return VLC_SUCCESS;
@@ -933,12 +935,14 @@ error:
*****************************************************************************/
vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
{
+ vlm_sys_t *sys = vlm->sys;
+
int i;
- for( i = 0; i < vlm->i_media; i++ )
+ for( i = 0; i < sys->i_media; i++ )
{
- if( strcmp( psz_name, vlm->media[i]->cfg.psz_name ) == 0 )
- return vlm->media[i];
+ if( strcmp( psz_name, sys->media[i]->cfg.psz_name ) == 0 )
+ return sys->media[i];
}
return NULL;
@@ -964,7 +968,9 @@ static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
p_sched->period = 0;
p_sched->i_repeat = -1;
- TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
+ vlm_sys_t *sys = vlm->sys;
+
+ TAB_APPEND( sys->i_schedule, sys->schedule, p_sched );
return p_sched;
}
@@ -972,12 +978,14 @@ static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
/* for now, simple delete. After, del with options (last arg) */
void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched )
{
+ vlm_sys_t *sys = vlm->sys;
+
int i;
if( sched == NULL ) return;
- TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
+ TAB_REMOVE( sys->i_schedule, sys->schedule, sched );
- if( vlm->i_schedule == 0 ) free( vlm->schedule );
+ if( sys->i_schedule == 0 ) free( sys->schedule );
free( sched->psz_name );
for ( i = 0; i < sched->i_command; i++ )
@@ -988,13 +996,15 @@ void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched )
static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
{
+ vlm_sys_t *sys = vlm->sys;
+
int i;
- for( i = 0; i < vlm->i_schedule; i++ )
+ for( i = 0; i < sys->i_schedule; i++ )
{
- if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
+ if( strcmp( psz_name, sys->schedule[i]->psz_name ) == 0 )
{
- return vlm->schedule[i];
+ return sys->schedule[i];
}
}
@@ -1341,6 +1351,8 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
vlm_schedule_sys_t *schedule,
const char *psz_filter )
{
+ vlm_sys_t *sys = vlm->sys;
+
if( media != NULL )
{
vlm_message_t *p_msg = vlm_MessageSimpleNew( "show" );
@@ -1427,14 +1439,14 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
{
vlm_message_t *p_msg;
vlm_message_t *p_msg_child;
- int i_broadcast = vlm->i_media;
+ int i_broadcast = sys->i_media;
p_msg = vlm_MessageSimpleNew( "show" );
p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media",
"( %d broadcast )", i_broadcast ) );
- for( int i = 0; i < vlm->i_media; i++ )
- vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) );
+ for( int i = 0; i < sys->i_media; i++ )
+ vlm_MessageAdd( p_msg_child, vlm_ShowMedia( sys->media[i] ) );
return p_msg;
}
@@ -1448,9 +1460,9 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
msg = vlm_MessageSimpleNew( "show" );
msg_child = vlm_MessageAdd( msg, vlm_MessageSimpleNew( "schedule" ) );
- for( i = 0; i < vlm->i_schedule; i++ )
+ for( i = 0; i < sys->i_schedule; i++ )
{
- vlm_schedule_sys_t *s = vlm->schedule[i];
+ vlm_schedule_sys_t *s = sys->schedule[i];
vlm_message_t *msg_schedule;
time_t now, next_date;
@@ -1560,6 +1572,8 @@ static int Load( vlm_t *vlm, char *file )
static char *Save( vlm_t *vlm )
{
+ vlm_sys_t *sys = vlm->sys;
+
const char *psz_header = "\n"
"# VLC media player VLM command batch\n"
"# http://www.videolan.org/vlc/\n\n" ;
@@ -1569,9 +1583,9 @@ static char *Save( vlm_t *vlm )
vlc_memstream_open( &stream );
vlc_memstream_puts( &stream, psz_header );
- for( int i = 0; i < vlm->i_media; i++ )
+ for( int i = 0; i < sys->i_media; i++ )
{
- vlm_media_sys_t *media = vlm->media[i];
+ vlm_media_sys_t *media = sys->media[i];
vlm_media_t *p_cfg = &media->cfg;
vlc_memstream_printf( &stream, "new %s broadcast %sabled",
@@ -1596,9 +1610,9 @@ static char *Save( vlm_t *vlm )
}
/* and now, the schedule scripts */
- for( int i = 0; i < vlm->i_schedule; i++ )
+ for( int i = 0; i < sys->i_schedule; i++ )
{
- vlm_schedule_sys_t *schedule = vlm->schedule[i];
+ vlm_schedule_sys_t *schedule = sys->schedule[i];
struct tm tm;
localtime_r( &schedule->date, &tm );
--
2.28.0
More information about the vlc-devel
mailing list