Commit d91fcec7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

DBus: retain the playlist throughout

We register callbacks, so we might as well keep track of the playlist.
This avoids pointless hold/release atomic ops and simplifies the code.
parent 2422af29
......@@ -105,6 +105,7 @@ enum
struct intf_sys_t
{
DBusConnection *p_conn;
playlist_t *p_playlist;
bool b_meta_read;
dbus_int32_t i_caps;
bool b_dead;
......@@ -119,6 +120,9 @@ typedef struct
int i_input_state;
} callback_info_t;
#define INTF ((intf_thread_t *)p_this)
#define PL (INTF->p_sys->p_playlist)
/*****************************************************************************
* Module descriptor
......@@ -142,7 +146,7 @@ vlc_module_end ()
DBUS_METHOD( Quit )
{ /* exits vlc */
REPLY_INIT;
libvlc_Quit(((vlc_object_t*)p_this)->p_libvlc);
libvlc_Quit(INTF->p_libvlc);
REPLY_SEND;
}
......@@ -178,8 +182,7 @@ DBUS_METHOD( PositionGet )
OUT_ARGUMENTS;
dbus_int32_t i_pos;
playlist_t *p_playlist = pl_Hold( ((vlc_object_t*) p_this) );
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
input_thread_t *p_input = playlist_CurrentInput( PL );
if( !p_input )
i_pos = 0;
......@@ -188,7 +191,6 @@ DBUS_METHOD( PositionGet )
i_pos = var_GetTime( p_input, "time" ) / 1000;
vlc_object_release( p_input );
}
pl_Release( ((vlc_object_t*) p_this) );
ADD_INT32( &i_pos );
REPLY_SEND;
}
......@@ -198,7 +200,6 @@ DBUS_METHOD( PositionSet )
REPLY_INIT;
vlc_value_t position;
playlist_t* p_playlist = NULL;
dbus_int32_t i_pos;
DBusError error;
......@@ -215,8 +216,7 @@ DBUS_METHOD( PositionSet )
dbus_error_free( &error );
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
p_playlist = pl_Hold( ((vlc_object_t*) p_this) );
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
input_thread_t *p_input = playlist_CurrentInput( PL );
if( p_input )
{
......@@ -224,7 +224,6 @@ DBUS_METHOD( PositionSet )
var_Set( p_input, "time", position );
vlc_object_release( p_input );
}
pl_Release( ((vlc_object_t*) p_this) );
REPLY_SEND;
}
......@@ -236,9 +235,7 @@ DBUS_METHOD( VolumeGet )
audio_volume_t i_vol;
/* 2nd argument of aout_VolumeGet is int32 */
playlist_t *p_playlist = pl_Hold( ((vlc_object_t*) p_this) );
aout_VolumeGet( p_playlist, &i_vol );
pl_Release( ((vlc_object_t*) p_this) );
aout_VolumeGet( PL, &i_vol );
double f_vol = 100. * i_vol / AOUT_VOLUME_MAX;
i_dbus_vol = round( f_vol );
......@@ -270,36 +267,28 @@ DBUS_METHOD( VolumeSet )
double f_vol = AOUT_VOLUME_MAX * i_dbus_vol / 100.;
i_vol = round( f_vol );
playlist_t *p_playlist = pl_Hold( ((vlc_object_t*) p_this) );
aout_VolumeSet( p_playlist, i_vol );
pl_Release( ((vlc_object_t*) p_this) );
aout_VolumeSet( PL, i_vol );
REPLY_SEND;
}
DBUS_METHOD( Next )
{ /* next playlist item */
REPLY_INIT;
playlist_t *p_playlist = pl_Hold( ((vlc_object_t*) p_this) );
playlist_Next( p_playlist );
pl_Release( ((vlc_object_t*) p_this) );
playlist_Next( PL );
REPLY_SEND;
}
DBUS_METHOD( Prev )
{ /* previous playlist item */
REPLY_INIT;
playlist_t *p_playlist = pl_Hold( ((vlc_object_t*) p_this) );
playlist_Prev( p_playlist );
pl_Release( ((vlc_object_t*) p_this) );
playlist_Prev( PL );
REPLY_SEND;
}
DBUS_METHOD( Stop )
{ /* stop playing */
REPLY_INIT;
playlist_t *p_playlist = pl_Hold( ((vlc_object_t*) p_this) );
playlist_Stop( p_playlist );
pl_Release( ((vlc_object_t*) p_this) );
playlist_Stop( PL );
REPLY_SEND;
}
......@@ -322,18 +311,15 @@ DBUS_METHOD( GetStatus )
DBUS_METHOD( Pause )
{
REPLY_INIT;
playlist_t *p_playlist = pl_Hold( (vlc_object_t*) p_this );
playlist_Pause( p_playlist );
pl_Release( (vlc_object_t*) p_this );
playlist_Pause( PL );
REPLY_SEND;
}
DBUS_METHOD( Play )
{
REPLY_INIT;
playlist_t *p_playlist = pl_Hold( (vlc_object_t*) p_this );
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
input_thread_t *p_input = playlist_CurrentInput( PL );
if( p_input )
{
......@@ -342,9 +328,8 @@ DBUS_METHOD( Play )
vlc_object_release( p_input );
}
else
playlist_Play( p_playlist );
playlist_Play( PL );
pl_Release( (vlc_object_t*) p_this );
REPLY_SEND;
}
......@@ -352,13 +337,13 @@ DBUS_METHOD( GetCurrentMetadata )
{
REPLY_INIT;
OUT_ARGUMENTS;
playlist_t* p_playlist = pl_Hold( (vlc_object_t*) p_this );
playlist_t *p_playlist = PL;
PL_LOCK;
playlist_item_t* p_item = playlist_CurrentPlayingItem( p_playlist );
if( p_item )
GetInputMeta( p_item->p_input, &args );
PL_UNLOCK;
pl_Release( (vlc_object_t*) p_this );
REPLY_SEND;
}
......@@ -367,7 +352,7 @@ DBUS_METHOD( GetCaps )
REPLY_INIT;
OUT_ARGUMENTS;
ADD_INT32( &((intf_thread_t*)p_this)->p_sys->i_caps );
ADD_INT32( &INTF->p_sys->i_caps );
REPLY_SEND;
}
......@@ -380,6 +365,7 @@ DBUS_METHOD( Identity )
REPLY_INIT;
OUT_ARGUMENTS;
char *psz_identity;
if( asprintf( &psz_identity, "%s %s", PACKAGE, VERSION ) != -1 )
{
ADD_STRING( &psz_identity );
......@@ -400,7 +386,6 @@ DBUS_METHOD( AddTrack )
DBusError error;
dbus_error_init( &error );
playlist_t* p_playlist = NULL;
char *psz_mrl;
dbus_bool_t b_play;
......@@ -418,11 +403,9 @@ DBUS_METHOD( AddTrack )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
p_playlist = pl_Hold( (vlc_object_t*) p_this );
playlist_Add( p_playlist, psz_mrl, NULL, PLAYLIST_APPEND |
playlist_Add( PL, psz_mrl, NULL, PLAYLIST_APPEND |
( ( b_play == TRUE ) ? PLAYLIST_GO : 0 ) ,
PLAYLIST_END, true, false );
pl_Release( (vlc_object_t*) p_this );
dbus_int32_t i_success = 0;
ADD_INT32( &i_success );
......@@ -435,9 +418,8 @@ DBUS_METHOD( GetCurrentTrack )
REPLY_INIT;
OUT_ARGUMENTS;
playlist_t *p_playlist = pl_Hold( (vlc_object_t*) p_this );
dbus_int32_t i_position = p_playlist->i_current_index;
pl_Release( (vlc_object_t*) p_this );
/* XXX: how about locking?! */
dbus_int32_t i_position = PL->i_current_index;
ADD_INT32( &i_position );
REPLY_SEND;
......@@ -451,7 +433,7 @@ DBUS_METHOD( GetMetadata )
dbus_error_init( &error );
dbus_int32_t i_position;
playlist_t *p_playlist;
playlist_t *p_playlist = PL;
dbus_message_get_args( p_from, &error,
DBUS_TYPE_INT32, &i_position,
......@@ -465,7 +447,6 @@ DBUS_METHOD( GetMetadata )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
p_playlist = pl_Hold( (vlc_object_t*) p_this );
PL_LOCK;
if( i_position < p_playlist->current.i_size )
{
......@@ -473,7 +454,6 @@ DBUS_METHOD( GetMetadata )
}
PL_UNLOCK;
pl_Release( (vlc_object_t*) p_this );
REPLY_SEND;
}
......@@ -482,9 +462,8 @@ DBUS_METHOD( GetLength )
REPLY_INIT;
OUT_ARGUMENTS;
playlist_t *p_playlist = pl_Hold( (vlc_object_t*) p_this );
dbus_int32_t i_elements = p_playlist->current.i_size;
pl_Release( (vlc_object_t*) p_this );
/* XXX: how about locking */
dbus_int32_t i_elements = PL->current.i_size;
ADD_INT32( &i_elements );
REPLY_SEND;
......@@ -498,7 +477,7 @@ DBUS_METHOD( DelTrack )
dbus_error_init( &error );
dbus_int32_t i_position;
playlist_t *p_playlist;
playlist_t *p_playlist = PL;
dbus_message_get_args( p_from, &error,
DBUS_TYPE_INT32, &i_position,
......@@ -512,7 +491,6 @@ DBUS_METHOD( DelTrack )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
p_playlist = pl_Hold( (vlc_object_t*) p_this );
PL_LOCK;
if( i_position < p_playlist->current.i_size )
{
......@@ -522,8 +500,6 @@ DBUS_METHOD( DelTrack )
}
PL_UNLOCK;
pl_Release( (vlc_object_t*) p_this );
REPLY_SEND;
}
......@@ -534,7 +510,6 @@ DBUS_METHOD( SetLoop )
DBusError error;
dbus_bool_t b_loop;
playlist_t* p_playlist;
dbus_error_init( &error );
dbus_message_get_args( p_from, &error,
......@@ -549,9 +524,7 @@ DBUS_METHOD( SetLoop )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
p_playlist = pl_Hold( (vlc_object_t*) p_this );
var_SetBool( p_playlist, "loop", ( b_loop == TRUE ) );
pl_Release( ((vlc_object_t*) p_this) );
var_SetBool( PL, "loop", ( b_loop == TRUE ) );
REPLY_SEND;
}
......@@ -563,7 +536,6 @@ DBUS_METHOD( Repeat )
DBusError error;
dbus_bool_t b_repeat;
playlist_t* p_playlist;
dbus_error_init( &error );
dbus_message_get_args( p_from, &error,
......@@ -578,9 +550,7 @@ DBUS_METHOD( Repeat )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
p_playlist = pl_Hold( (vlc_object_t*) p_this );
var_SetBool( p_playlist, "repeat", ( b_repeat == TRUE ) );
pl_Release( ((vlc_object_t*) p_this) );
var_SetBool( PL, "repeat", ( b_repeat == TRUE ) );
REPLY_SEND;
}
......@@ -592,7 +562,6 @@ DBUS_METHOD( SetRandom )
DBusError error;
dbus_bool_t b_random;
playlist_t* p_playlist;
dbus_error_init( &error );
dbus_message_get_args( p_from, &error,
......@@ -607,9 +576,7 @@ DBUS_METHOD( SetRandom )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
p_playlist = pl_Hold( (vlc_object_t*) p_this );
var_SetBool( p_playlist, "random", ( b_random == TRUE ) );
pl_Release( ((vlc_object_t*) p_this) );
var_SetBool( PL, "random", ( b_random == TRUE ) );
REPLY_SEND;
}
......@@ -773,6 +740,8 @@ static int Open( vlc_object_t *p_this )
vlc_mutex_init( &p_sys->lock );
p_playlist = pl_Hold( p_intf );
p_sys->p_playlist = p_playlist;
PL_LOCK;
var_AddCallback( p_playlist, "item-current", AllCallback, p_intf );
var_AddCallback( p_playlist, "intf-change", AllCallback, p_intf );
......@@ -782,7 +751,6 @@ static int Open( vlc_object_t *p_this )
var_AddCallback( p_playlist, "repeat", AllCallback, p_intf );
var_AddCallback( p_playlist, "loop", AllCallback, p_intf );
PL_UNLOCK;
pl_Release( p_intf );
UpdateCaps( p_intf );
......@@ -796,7 +764,8 @@ static int Open( vlc_object_t *p_this )
static void Close ( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t*) p_this;
playlist_t *p_playlist = pl_Hold( p_intf );;
intf_sys_t *p_sys = p_intf->p_sys;
playlist_t *p_playlist = p_sys->p_playlist;
input_thread_t *p_input;
var_DelCallback( p_playlist, "item-current", AllCallback, p_intf );
......@@ -813,20 +782,19 @@ static void Close ( vlc_object_t *p_this )
var_DelCallback( p_input, "state", AllCallback, p_intf );
vlc_object_release( p_input );
}
pl_Release( p_intf );
dbus_connection_unref( p_intf->p_sys->p_conn );
dbus_connection_unref( p_sys->p_conn );
// Free the events array
for( int i = 0; i < vlc_array_count( p_intf->p_sys->p_events ); i++ )
for( int i = 0; i < vlc_array_count( p_sys->p_events ); i++ )
{
callback_info_t* info = vlc_array_item_at_index( p_intf->p_sys->p_events, i );
callback_info_t* info = vlc_array_item_at_index( p_sys->p_events, i );
free( info );
}
vlc_mutex_destroy( &p_intf->p_sys->lock );
vlc_array_destroy( p_intf->p_sys->p_events );
free( p_intf->p_sys );
vlc_mutex_destroy( &p_sys->lock );
vlc_array_destroy( p_sys->p_events );
free( p_sys );
}
/*****************************************************************************
......@@ -957,9 +925,8 @@ DBUS_SIGNAL( TrackListChangeSignal )
SIGNAL_INIT("TrackListChange");
OUT_ARGUMENTS;
playlist_t *p_playlist = pl_Hold( (vlc_object_t*) p_data );
dbus_int32_t i_elements = p_playlist->current.i_size;
pl_Release( (vlc_object_t*) p_data );
/* XXX: locking */
dbus_int32_t i_elements = ((intf_thread_t*)p_data)->p_sys->p_playlist->current.i_size;
ADD_INT32( &i_elements );
SIGNAL_SEND;
......@@ -975,7 +942,7 @@ static int TrackListChangeEmit( intf_thread_t *p_intf, int signal, int i_node )
if( signal == SIGNAL_PLAYLIST_ITEM_APPEND )
{
/* don't signal when items are added/removed in p_category */
playlist_t *p_playlist = pl_Hold( p_intf );
playlist_t *p_playlist = p_intf->p_sys->p_playlist;
PL_LOCK;
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_node );
assert( p_item );
......@@ -984,11 +951,9 @@ static int TrackListChangeEmit( intf_thread_t *p_intf, int signal, int i_node )
if( p_item == p_playlist->p_root_category )
{
PL_UNLOCK;
pl_Release( p_intf );
return VLC_SUCCESS;
}
PL_UNLOCK;
pl_Release( p_intf );
}
if( p_intf->p_sys->b_dead )
......@@ -1037,7 +1002,7 @@ DBUS_SIGNAL( StatusChangeSignal )
static int StateChange( intf_thread_t *p_intf, int i_input_state )
{
intf_sys_t *p_sys = p_intf->p_sys;
playlist_t *p_playlist;
playlist_t *p_playlist = p_sys->p_playlist;
input_thread_t *p_input;
input_item_t *p_item;
......@@ -1048,7 +1013,6 @@ static int StateChange( intf_thread_t *p_intf, int i_input_state )
if( !p_sys->b_meta_read && i_input_state == PLAYING_S )
{
p_playlist = pl_Hold( p_intf );
p_input = playlist_CurrentInput( p_playlist );
if( p_input )
{
......@@ -1060,7 +1024,6 @@ static int StateChange( intf_thread_t *p_intf, int i_input_state )
}
vlc_object_release( p_input );
}
pl_Release( p_intf );
}
if( i_input_state == PLAYING_S || i_input_state == PAUSE_S ||
......@@ -1091,7 +1054,7 @@ static int StatusChangeEmit( intf_thread_t * p_intf )
static int TrackChange( intf_thread_t *p_intf )
{
intf_sys_t *p_sys = p_intf->p_sys;
playlist_t *p_playlist;
playlist_t *p_playlist = p_sys->p_playlist;
input_thread_t *p_input = NULL;
input_item_t *p_item = NULL;
......@@ -1100,16 +1063,12 @@ static int TrackChange( intf_thread_t *p_intf )
p_sys->b_meta_read = false;
p_playlist = pl_Hold( p_intf );
p_input = playlist_CurrentInput( p_playlist );
if( !p_input )
{
pl_Release( p_intf );
return VLC_SUCCESS;
}
pl_Release( p_intf );
p_item = input_GetItem( p_input );
if( !p_item )
{
......@@ -1137,7 +1096,7 @@ static int UpdateCaps( intf_thread_t* p_intf )
{
intf_sys_t* p_sys = p_intf->p_sys;
dbus_int32_t i_caps = CAPS_CAN_HAS_TRACKLIST;
playlist_t* p_playlist = pl_Hold( p_intf );
playlist_t* p_playlist = p_sys->p_playlist;
PL_LOCK;
if( p_playlist->current.i_size > 0 )
......@@ -1156,8 +1115,6 @@ static int UpdateCaps( intf_thread_t* p_intf )
vlc_object_release( p_input );
}
pl_Release( p_intf );
if( p_sys->b_meta_read )
i_caps |= CAPS_CAN_PROVIDE_METADATA;
......@@ -1260,11 +1217,9 @@ static int MarshalStatus( intf_thread_t* p_intf, DBusMessageIter* args )
DBusMessageIter status;
dbus_int32_t i_state, i_random, i_repeat, i_loop;
int i_val;
playlist_t* p_playlist = NULL;
playlist_t* p_playlist = p_intf->p_sys->p_playlist;
input_thread_t* p_input = NULL;
p_playlist = pl_Hold( p_intf );
i_state = 2;
p_input = playlist_CurrentInput( p_playlist );
......@@ -1286,8 +1241,6 @@ static int MarshalStatus( intf_thread_t* p_intf, DBusMessageIter* args )
i_loop = var_CreateGetBool( p_playlist, "loop" );
pl_Release( p_intf );
dbus_message_iter_open_container( args, DBUS_TYPE_STRUCT, NULL, &status );
dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_state );
dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_random );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment