vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Sat Oct 17 12:21:24 2020 +0300| [1bc4ded1928d74f268f64f9a831d9ef68a5e2a6e] | committer: Rémi Denis-Courmont
cli: move player callback registration to player.c > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1bc4ded1928d74f268f64f9a831d9ef68a5e2a6e --- modules/control/cli/cli.c | 34 +++++---------------------- modules/control/cli/cli.h | 9 ++++--- modules/control/cli/player.c | 56 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 35 deletions(-) diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c index 32eeab82b4..63549d7e79 100644 --- a/modules/control/cli/cli.c +++ b/modules/control/cli/cli.c @@ -749,7 +749,6 @@ static int Activate( vlc_object_t *p_this ) p_sys->last_state = VLC_PLAYER_STATE_STOPPED; p_sys->b_input_buffering = false; p_sys->playlist = vlc_intf_GetMainPlaylist(p_intf);; - vlc_player_t *player = vlc_playlist_GetPlayer(p_sys->playlist); /* Non-buffered stdout */ setvbuf( stdout, (char *)NULL, _IOLBF, 0 ); @@ -762,35 +761,18 @@ static int Activate( vlc_object_t *p_this ) intf_consoleIntroMsg( p_intf ); #endif - if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) ) + p_sys->player_cli = RegisterPlayer(p_intf); + if (unlikely(p_sys->player_cli == NULL)) goto error; - msg_rc( "%s", _("Remote control interface initialized. Type `help' for help.") ); - - vlc_player_Lock(player); - p_sys->player_listener = - vlc_player_AddListener(player, &player_cbs, p_intf); - if (!p_sys->player_listener) - { - vlc_player_Unlock(player); + if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) ) goto error; - } - p_sys->player_aout_listener = - vlc_player_aout_AddListener(player, &player_aout_cbs, p_intf); - vlc_player_Unlock(player); - if (!p_sys->player_aout_listener) - goto error; + msg_rc( "%s", _("Remote control interface initialized. Type `help' for help.") ); return VLC_SUCCESS; error: - if (p_sys->player_listener) - { - vlc_player_Lock(player); - vlc_player_RemoveListener(player, p_sys->player_listener); - vlc_player_Unlock(player); - } net_ListenClose( pi_socket ); free( psz_unix_path ); free( p_sys ); @@ -805,15 +787,11 @@ static void Deactivate( vlc_object_t *p_this ) intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_sys_t *p_sys = p_intf->p_sys; - vlc_player_t *player = vlc_playlist_GetPlayer(p_sys->playlist); - vlc_player_Lock(player); - vlc_player_aout_RemoveListener(player, p_sys->player_aout_listener); - vlc_player_RemoveListener(player, p_sys->player_listener); - vlc_player_Unlock(player); - vlc_cancel( p_sys->thread ); vlc_join( p_sys->thread, NULL ); + DeregisterPlayer(p_intf, p_sys->player_cli); + net_ListenClose( p_sys->pi_socket_listen ); if( p_sys->i_socket != -1 ) net_Close( p_sys->i_socket ); diff --git a/modules/control/cli/cli.h b/modules/control/cli/cli.h index 4f4e57e108..f6b3ea6db2 100644 --- a/modules/control/cli/cli.h +++ b/modules/control/cli/cli.h @@ -27,11 +27,10 @@ struct intf_sys_t { vlc_thread_t thread; + void *player_cli; /* playlist */ vlc_playlist_t *playlist; - vlc_player_listener_id *player_listener; - vlc_player_aout_listener_id *player_aout_listener; /* status changes */ vlc_mutex_t status_lock; @@ -54,9 +53,6 @@ void msg_print(intf_thread_t *p_intf, const char *psz_fmt, ...); #define msg_rc(...) msg_print(p_intf, __VA_ARGS__) #define STATUS_CHANGE "status change: " -extern const struct vlc_player_cbs player_cbs; -extern const struct vlc_player_aout_cbs player_aout_cbs; - void PlayerPause(intf_thread_t *intf); void PlayerFastForward(intf_thread_t *intf); void PlayerRewind(intf_thread_t *intf); @@ -82,6 +78,9 @@ void AudioChannel(intf_thread_t *intf, char const *cmd, vlc_value_t cur); void Statistics(intf_thread_t *intf); void IsPlaying(intf_thread_t *intf); +void *RegisterPlayer(intf_thread_t *intf); +void DeregisterPlayer(intf_thread_t *intf, void *); + void PlaylistPrev(intf_thread_t *intf); void PlaylistNext(intf_thread_t *intf); void PlaylistPlay(intf_thread_t *intf); diff --git a/modules/control/cli/player.c b/modules/control/cli/player.c index 74d7aa3c84..bdb9671ffd 100644 --- a/modules/control/cli/player.c +++ b/modules/control/cli/player.c @@ -36,6 +36,11 @@ #include "cli.h" +struct player_cli { + vlc_player_listener_id *player_listener; + vlc_player_aout_listener_id *player_aout_listener; +}; + /******************************************************************** * Status callback routines ********************************************************************/ @@ -99,7 +104,7 @@ player_on_position_changed(vlc_player_t *player, vlc_mutex_unlock(&sys->status_lock); } -const struct vlc_player_cbs player_cbs = +static const struct vlc_player_cbs player_cbs = { .on_state_changed = player_on_state_changed, .on_buffering_changed = player_on_buffering_changed, @@ -117,7 +122,7 @@ player_aout_on_volume_changed(audio_output_t *aout, float volume, void *data) vlc_mutex_unlock(&p_intf->p_sys->status_lock); } -const struct vlc_player_aout_cbs player_aout_cbs = +static const struct vlc_player_aout_cbs player_aout_cbs = { .on_volume_changed = player_aout_on_volume_changed, }; @@ -715,3 +720,50 @@ void IsPlaying(intf_thread_t *intf) sys->last_state == VLC_PLAYER_STATE_PLAYING || sys->last_state == VLC_PLAYER_STATE_PAUSED); } + +void *RegisterPlayer(intf_thread_t *intf) +{ + vlc_playlist_t *playlist = vlc_intf_GetMainPlaylist(intf);; + vlc_player_t *player = vlc_playlist_GetPlayer(playlist); + struct player_cli *pc = malloc(sizeof (*pc)); + + if (unlikely(pc == NULL)) + return NULL; + + vlc_player_Lock(player); + pc->player_listener = vlc_player_AddListener(player, &player_cbs, intf); + + if (unlikely(pc->player_listener == NULL)) + goto error; + + pc->player_aout_listener = + vlc_player_aout_AddListener(player, &player_aout_cbs, intf); + + if (pc->player_aout_listener == NULL) + { + vlc_player_RemoveListener(player, pc->player_listener); + goto error; + } + + vlc_player_Unlock(player); + return pc; + +error: + vlc_player_Unlock(player); + free(pc); + return NULL; +} + +void DeregisterPlayer(intf_thread_t *intf, void *data) +{ + vlc_playlist_t *playlist = vlc_intf_GetMainPlaylist(intf);; + vlc_player_t *player = vlc_playlist_GetPlayer(playlist); + struct player_cli *pc = data; + + vlc_player_Lock(player); + vlc_player_aout_RemoveListener(player, pc->player_aout_listener); + vlc_player_RemoveListener(player, pc->player_listener); + vlc_player_Unlock(player); + free(pc); + (void) intf; +} _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
