[vlc-commits] [Git][videolan/vlc][master] 2 commits: dbus: simplify previous/next detection

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Tue May 3 17:11:25 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
9a47f147 by Romain Vimont at 2022-05-03T16:36:38+00:00
dbus: simplify previous/next detection

Use the existing playlist API to detect if there is a previous or next
item in the playlist.

- - - - -
9c4f4942 by Romain Vimont at 2022-05-03T16:36:38+00:00
dbus: notify previous/next state changes

Changes of state indicating if "previous" and "next" actions are enabled
must be signaled to D-Bus.

Fixes #23603

- - - - -


3 changed files:

- modules/control/dbus/dbus.c
- modules/control/dbus/dbus_common.h
- modules/control/dbus/dbus_player.c


Changes:

=====================================
modules/control/dbus/dbus.c
=====================================
@@ -139,6 +139,10 @@ static void playlist_on_playback_order_changed(vlc_playlist_t *,
                                                void *);
 static void playlist_on_current_index_changed(vlc_playlist_t *,
                                               ssize_t, void *);
+static void playlist_on_has_prev_changed(vlc_playlist_t *playlist,
+                                         bool has_prev, void *data);
+static void playlist_on_has_next_changed(vlc_playlist_t *playlist,
+                                         bool has_next, void *data);
 
 static void player_on_state_changed(vlc_player_t *,
                                     enum vlc_player_state, void *);
@@ -265,6 +269,8 @@ static int Open( vlc_object_t *p_this )
         .on_playback_repeat_changed = playlist_on_playback_repeat_changed,
         .on_playback_order_changed = playlist_on_playback_order_changed,
         .on_current_index_changed = playlist_on_current_index_changed,
+        .on_has_prev_changed = playlist_on_has_prev_changed,
+        .on_has_next_changed = playlist_on_has_next_changed,
     };
     p_sys->playlist_listener =
         vlc_playlist_AddListener(playlist, &playlist_cbs, p_intf, false);
@@ -679,6 +685,12 @@ static void ProcessEvents( intf_thread_t *p_intf,
         case SIGNAL_SEEK:
             SeekedEmit( p_intf );
             break;
+        case SIGNAL_CAN_GO_PREVIOUS:
+            vlc_dictionary_insert( &player_properties, "CanGoPrevious", NULL );
+            break;
+        case SIGNAL_CAN_GO_NEXT:
+            vlc_dictionary_insert( &player_properties, "CanGoNext", NULL );
+            break;
         default:
             vlc_assert_unreachable();
         }
@@ -1031,6 +1043,24 @@ playlist_on_current_index_changed(vlc_playlist_t *playlist,
     (void) playlist; (void) index;
 }
 
+static void
+playlist_on_has_prev_changed(vlc_playlist_t *playlist, bool has_prev,
+                             void *data)
+{
+    add_event_signal(data,
+            &(callback_info_t){ .signal = SIGNAL_CAN_GO_PREVIOUS });
+    (void) playlist; (void) has_prev;
+}
+
+static void
+playlist_on_has_next_changed(vlc_playlist_t *playlist, bool has_next,
+                             void *data)
+{
+    add_event_signal(data,
+            &(callback_info_t){ .signal = SIGNAL_CAN_GO_NEXT });
+    (void) playlist; (void) has_next;
+}
+
 static void
 player_on_state_changed(vlc_player_t *player, enum vlc_player_state state,
                         void *data)


=====================================
modules/control/dbus/dbus_common.h
=====================================
@@ -128,6 +128,8 @@ enum
     SIGNAL_SEEK,
     SIGNAL_CAN_SEEK,
     SIGNAL_CAN_PAUSE,
+    SIGNAL_CAN_GO_PREVIOUS,
+    SIGNAL_CAN_GO_NEXT,
     SIGNAL_VOLUME_CHANGE,
     SIGNAL_VOLUME_MUTED,
     SIGNAL_FULLSCREEN


=====================================
modules/control/dbus/dbus_player.c
=====================================
@@ -256,16 +256,10 @@ MarshalCanGoNext( intf_thread_t *p_intf, DBusMessageIter *container )
 {
     vlc_playlist_t *playlist = p_intf->p_sys->playlist;
     vlc_playlist_Lock(playlist);
-    size_t count = vlc_playlist_Count(playlist);
-    ssize_t index = vlc_playlist_GetCurrentIndex(playlist);
-    enum vlc_playlist_playback_repeat repeat_mode =
-        vlc_playlist_GetPlaybackRepeat(playlist);
+    bool has_next = vlc_playlist_HasNext(playlist);
     vlc_playlist_Unlock(playlist);
 
-    dbus_bool_t b_can_go_next =
-        count != 0 &&
-        ((index != -1 && (size_t)index < count - 1) ||
-         repeat_mode != VLC_PLAYLIST_PLAYBACK_REPEAT_NONE);
+    dbus_bool_t b_can_go_next = has_next;
 
     if( !dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN,
                                          &b_can_go_next ) )
@@ -279,15 +273,10 @@ MarshalCanGoPrevious( intf_thread_t *p_intf, DBusMessageIter *container )
 {
     vlc_playlist_t *playlist = p_intf->p_sys->playlist;
     vlc_playlist_Lock(playlist);
-    size_t count = vlc_playlist_Count(playlist);
-    ssize_t index = vlc_playlist_GetCurrentIndex(playlist);
-    enum vlc_playlist_playback_repeat repeat_mode =
-        vlc_playlist_GetPlaybackRepeat(playlist);
+    bool has_prev = vlc_playlist_HasPrev(playlist);
     vlc_playlist_Unlock(playlist);
 
-    dbus_bool_t b_can_go_previous =
-        count != 0 &&
-        (index > 0 || repeat_mode != VLC_PLAYLIST_PLAYBACK_REPEAT_NONE);
+    dbus_bool_t b_can_go_previous = has_prev;
 
     if( !dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN,
                                          &b_can_go_previous ) )
@@ -848,6 +837,8 @@ PropertiesChangedSignal( intf_thread_t    *p_intf,
         PROPERTY_ENTRY( CanSeek,        "b"     )
         PROPERTY_ENTRY( CanPlay,        "b"     )
         PROPERTY_ENTRY( CanPause,       "b"     )
+        PROPERTY_ENTRY( CanGoPrevious,  "b"     )
+        PROPERTY_ENTRY( CanGoNext,      "b"     )
         PROPERTY_MAPPING_END
 
         free( ppsz_properties[i] );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3a44de136b28ef2bef25afd0005a1a5f9bd622d8...9c4f4942ed7e3879ab5a9ecf8128856b8e622a93

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3a44de136b28ef2bef25afd0005a1a5f9bd622d8...9c4f4942ed7e3879ab5a9ecf8128856b8e622a93
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list