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

dbus: use playlist item IDs rather input item IDs

parent c90fc91a
......@@ -1146,9 +1146,9 @@ int DemarshalSetPropertyValue( DBusMessage *p_msg, void *p_arg )
free( psz ); \
}
int GetInputMeta( input_item_t* p_input,
DBusMessageIter *args )
int GetInputMeta( playlist_item_t *item, DBusMessageIter *args )
{
input_item_t *p_input = item->p_input;
DBusMessageIter dict, dict_entry, variant, list;
/** The duration of the track can be expressed in second, milli-seconds and
µ-seconds */
......@@ -1157,7 +1157,7 @@ int GetInputMeta( input_item_t* p_input,
dbus_int64_t i_length = i_mtime / 1000;
char *psz_trackid;
if( -1 == asprintf( &psz_trackid, MPRIS_TRACKID_FORMAT, p_input->i_id ) )
if( -1 == asprintf( &psz_trackid, MPRIS_TRACKID_FORMAT, item->i_id ) )
return VLC_ENOMEM;
const char* ppsz_meta_items[] =
......
......@@ -139,7 +139,7 @@ enum
};
int DemarshalSetPropertyValue( DBusMessage *p_msg, void *p_arg );
int GetInputMeta ( input_item_t* p_input, DBusMessageIter *args );
int GetInputMeta( playlist_item_t *, DBusMessageIter *args );
int AddProperty ( intf_thread_t *p_intf,
DBusMessageIter *p_container,
const char* psz_property_name,
......
......@@ -66,14 +66,17 @@ DBUS_METHOD( SetPosition )
REPLY_INIT;
dbus_int64_t i_pos;
char *psz_trackid, *psz_dbus_trackid;
input_item_t *p_item;
const char *psz_trackid;
playlist_t *playlist = pl_Get(p_this);
playlist_item_t *item;
input_thread_t *input = NULL;
int i_id;
DBusError error;
dbus_error_init( &error );
dbus_message_get_args( p_from, &error,
DBUS_TYPE_OBJECT_PATH, &psz_dbus_trackid,
DBUS_TYPE_OBJECT_PATH, &psz_trackid,
DBUS_TYPE_INT64, &i_pos,
DBUS_TYPE_INVALID );
......@@ -85,29 +88,21 @@ DBUS_METHOD( SetPosition )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
input_thread_t *p_input = pl_CurrentInput( p_this );
if( sscanf( psz_trackid, MPRIS_TRACKID_FORMAT, &i_id ) < 1 )
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
if( p_input )
{
if( ( p_item = input_GetItem( p_input ) ) )
{
if( -1 == asprintf( &psz_trackid,
MPRIS_TRACKID_FORMAT,
p_item->i_id ) )
{
vlc_object_release( p_input );
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
if( !strcmp( psz_trackid, psz_dbus_trackid ) )
var_SetInteger( p_input, "time", i_pos );
free( psz_trackid );
}
playlist_Lock( playlist );
item = playlist_CurrentPlayingItem( playlist );
if( item != NULL && item->i_id == i_id )
input = playlist_CurrentInputLocked( playlist );
playlist_Unlock( playlist );
vlc_object_release( p_input );
if( input != NULL )
{
var_SetInteger( input, "time", i_pos );
vlc_object_release( input );
}
REPLY_SEND;
}
......@@ -513,37 +508,27 @@ DBUS_METHOD( LoopStatusSet )
static int
MarshalMetadata( intf_thread_t *p_intf, DBusMessageIter *container )
{
DBusMessageIter a;
input_thread_t *p_input = pl_CurrentInput( p_intf );
input_item_t *p_item = NULL;
playlist_t *playlist = pl_Get( p_intf );
playlist_item_t *item;
int result = VLC_SUCCESS;
if( p_input != NULL )
{
p_item = input_GetItem( p_input );
if( p_item )
{
int result = GetInputMeta( p_item, container );
if (result != VLC_SUCCESS)
{
vlc_object_release( (vlc_object_t*) p_input );
return result;
}
}
playlist_Lock( playlist );
item = playlist_CurrentPlayingItem( playlist );
vlc_object_release( (vlc_object_t*) p_input );
}
if( item != NULL )
result = GetInputMeta( item, container );
else
{ // avoid breaking the type marshalling
DBusMessageIter a;
if (!p_item)
{
// avoid breaking the type marshalling
if( !dbus_message_iter_open_container( container, DBUS_TYPE_ARRAY, "{sv}", &a ) ||
!dbus_message_iter_close_container( container, &a ) )
return VLC_ENOMEM;
if( !dbus_message_iter_open_container( container, DBUS_TYPE_ARRAY,
"{sv}", &a ) ||
!dbus_message_iter_close_container( container, &a ) )
result = VLC_ENOMEM;
}
return VLC_SUCCESS;
playlist_Unlock( playlist );
return result;
}
......
......@@ -44,32 +44,20 @@
*
* This function must be called with the playlist locked
*
* @param playlist_t* p_playlist The playlist
* @param input_item_t* i_input_id An input item ID
* @param playlist playlist
* @param id playlist item ID
*
* @return int The position of the input item or a VLC error constant
* @return The position of the input item or -1
*/
static int getInputPosition( playlist_t* p_playlist, int i_input_id )
static int getInputPosition( playlist_t* playlist, int id )
{
input_item_t* p_input = NULL;
assert( playlist != NULL );
assert( p_playlist );
assert( i_input_id >= 0 );
playlist_AssertLocked( p_playlist );
for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
{
p_input = p_playlist->current.p_elems[i]->p_input;
if( !p_input )
return VLC_EGENERIC;
if( p_input->i_id == i_input_id )
for( int i = 0; i < playlist->current.i_size; i++ )
if( playlist->current.p_elems[i]->i_id == id )
return i;
}
return VLC_ENOITEM;
return -1;
}
DBUS_METHOD( AddTrack )
......@@ -150,7 +138,6 @@ DBUS_METHOD( GetTracksMetadata )
const char *psz_track_id = NULL;
playlist_t *p_playlist = PL;
input_item_t *p_input = NULL;
DBusMessageIter in_args, track_ids, meta;
dbus_message_iter_init( p_from, &in_args );
......@@ -177,13 +164,13 @@ DBUS_METHOD( GetTracksMetadata )
}
PL_LOCK;
for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
for( int i = 0; i < p_playlist->current.i_size; i++ )
{
p_input = p_playlist->current.p_elems[i]->p_input;
playlist_item_t *item = p_playlist->current.p_elems[i];
if( i_track_id == p_input->i_id )
if( item->i_id == i_track_id )
{
GetInputMeta( p_input, &meta );
GetInputMeta( item, &meta );
break;
}
}
......@@ -227,13 +214,14 @@ DBUS_METHOD( GoTo )
PL_LOCK;
for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
for( int i = 0; i < p_playlist->current.i_size; i++ )
{
if( i_track_id == p_playlist->current.p_elems[i]->p_input->i_id )
playlist_item_t *item = p_playlist->current.p_elems[i];
if( item->i_id == i_track_id )
{
playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, true,
p_playlist->current.p_elems[i]->p_parent,
p_playlist->current.p_elems[i] );
item->p_parent, item );
break;
}
}
......@@ -249,10 +237,9 @@ DBUS_METHOD( RemoveTrack )
DBusError error;
dbus_error_init( &error );
int i_id = -1, i;
int i_id = -1;
char *psz_id = NULL;
playlist_t *p_playlist = PL;
input_item_t *p_input = NULL;
dbus_message_get_args( p_from, &error,
DBUS_TYPE_OBJECT_PATH, &psz_id,
......@@ -274,13 +261,13 @@ DBUS_METHOD( RemoveTrack )
PL_LOCK;
for( i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
for( int i = 0; i < p_playlist->current.i_size; i++ )
{
p_input = p_playlist->current.p_elems[i]->p_input;
playlist_item_t *item = p_playlist->current.p_elems[i];
if( i_id == p_input->i_id )
if( item->i_id == i_id )
{
playlist_DeleteFromInput( p_playlist, p_input, true );
playlist_NodeDelete( p_playlist, item, true, false );
break;
}
}
......@@ -295,20 +282,19 @@ MarshalTracks( intf_thread_t *p_intf, DBusMessageIter *container )
DBusMessageIter tracks;
char *psz_track_id = NULL;
playlist_t *p_playlist = p_intf->p_sys->p_playlist;
input_item_t *p_input = NULL;
dbus_message_iter_open_container( container, DBUS_TYPE_ARRAY, "o",
&tracks );
PL_LOCK;
for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ )
for( int i = 0; i < p_playlist->current.i_size; i++ )
{
p_input = p_playlist->current.p_elems[i]->p_input;
playlist_item_t *item = p_playlist->current.p_elems[i];
if( ( -1 == asprintf( &psz_track_id,
MPRIS_TRACKID_FORMAT,
p_input->i_id ) ) ||
item->i_id ) ) ||
!dbus_message_iter_append_basic( &tracks,
DBUS_TYPE_OBJECT_PATH,
&psz_track_id ) )
......
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