[vlc-commits] [Git][videolan/vlc][master] 4 commits: qt: player: use lambda to static initialize cbs

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Wed Jul 14 18:19:36 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
1f743fa7 by Alexandre Janniaux at 2021-07-14T17:57:42+00:00
qt: player: use lambda to static initialize cbs

The callbacks needed to be defined with the correct order and without
oversight since C++14 doesn't support designated initializer. But
vlc_player callbacks are all optional and there's no point in having
such constraint for C++ code. Use a static lambda initializer with an
initial zero-initializer to circumvent this limitation.

- - - - -
2cb3c1f0 by Alexandre Janniaux at 2021-07-14T17:57:42+00:00
qt: playlist_controller: use lambda to static initialize cbs

The callbacks needed to be defined with the correct order and without
oversight since C++14 doesn't support designated initializer. But
vlc+playlist callbacks are all optional and there's no point in having
such constraint for C++ code. Use a static lambda initializer with an
initial zero-initializer to circumvent this limitation.

- - - - -
31b125d4 by Alexandre Janniaux at 2021-07-14T17:57:42+00:00
qt: playlist_model: use lambda to static initialize cbs

The callbacks needed to be defined with the correct order and without
oversight since C++14 doesn't support designated initializer. But
vlc+playlist callbacks are all optional and there's no point in having
such constraint for C++ code. Use a static lambda initializer with an
initial zero-initializer to circumvent this limitation.

- - - - -
2828c950 by Alexandre Janniaux at 2021-07-14T17:57:42+00:00
skins2: vlcproc: use lambda to static initialize cbs

The callbacks needed to be defined with the correct order and without
oversight since C++14 doesn't support designated initializer. But
vlc_player and playlist callbacks are all optional and there's no point
in having such constraint for C++ code. Use a static lambda initializer
with an initial zero-initializer to circumvent this limitation.

- - - - -


4 changed files:

- modules/gui/qt/player/player_controller.cpp
- modules/gui/qt/playlist/playlist_controller.cpp
- modules/gui/qt/playlist/playlist_model.cpp
- modules/gui/skins2/src/vlcproc.cpp


Changes:

=====================================
modules/gui/qt/player/player_controller.cpp
=====================================
@@ -988,21 +988,26 @@ static const struct vlc_player_cbs player_cbs = {
     on_player_playback_restore_queried
 };
 
-static const struct vlc_player_vout_cbs player_vout_cbs = {
-    on_player_vout_fullscreen_changed,
-    on_player_vout_wallpaper_mode_changed
-};
-
-static const struct vlc_player_aout_cbs player_aout_cbs = {
-    on_player_aout_volume_changed,
-    on_player_aout_mute_changed,
-    nullptr
-};
-
-static const struct vlc_player_timer_cbs player_timer_cbs = {
-    on_player_timer_update,
-    on_player_timer_discontinuity,
-};
+static const vlc_player_vout_cbs player_vout_cbs = []{
+    struct vlc_player_vout_cbs cbs{};
+    cbs.on_fullscreen_changed = on_player_vout_fullscreen_changed;
+    cbs.on_wallpaper_mode_changed = on_player_vout_wallpaper_mode_changed;
+    return cbs;
+}();
+
+static const vlc_player_aout_cbs player_aout_cbs = []{
+    struct vlc_player_aout_cbs cbs{};
+    cbs.on_volume_changed = on_player_aout_volume_changed;
+    cbs.on_mute_changed = on_player_aout_mute_changed;
+    return cbs;
+}();
+
+static const vlc_player_timer_cbs player_timer_cbs = []{
+    struct vlc_player_timer_cbs cbs {};
+    cbs.on_update = on_player_timer_update;
+    cbs.on_discontinuity = on_player_timer_discontinuity;
+    return cbs;
+}();
 
 PlayerControllerPrivate::PlayerControllerPrivate(PlayerController *playercontroller, qt_intf_t *p_intf)
     : q_ptr(playercontroller)


=====================================
modules/gui/qt/playlist/playlist_controller.cpp
=====================================
@@ -267,19 +267,20 @@ on_playlist_has_next_changed(vlc_playlist_t *playlist, bool has_next,
 
 } // extern "C"
 
-static const struct vlc_playlist_callbacks playlist_callbacks = {
-    /* C++ (before C++20) does not support designated initializers */
-    on_playlist_items_reset,
-    on_playlist_items_added,
-    on_playlist_items_moved,
-    on_playlist_items_removed,
-    on_playlist_items_updated,
-    on_playlist_playback_repeat_changed,
-    on_playlist_playback_order_changed,
-    on_playlist_current_item_changed,
-    on_playlist_has_prev_changed,
-    on_playlist_has_next_changed,
-};
+static const struct vlc_playlist_callbacks playlist_callbacks = []{
+    struct vlc_playlist_callbacks cbs {};
+    cbs.on_items_reset = on_playlist_items_reset;
+    cbs.on_items_added = on_playlist_items_added;
+    cbs.on_items_moved = on_playlist_items_moved;
+    cbs.on_items_removed = on_playlist_items_removed;
+    cbs.on_items_updated = on_playlist_items_updated;
+    cbs.on_playback_repeat_changed = on_playlist_playback_repeat_changed;
+    cbs.on_playback_order_changed= on_playlist_playback_order_changed;
+    cbs.on_current_index_changed = on_playlist_current_item_changed;
+    cbs.on_has_next_changed = on_playlist_has_prev_changed;
+    cbs.on_has_prev_changed = on_playlist_has_next_changed;
+    return cbs;
+}();
 
 
 //private API


=====================================
modules/gui/qt/playlist/playlist_model.cpp
=====================================
@@ -143,19 +143,16 @@ on_playlist_current_item_changed(vlc_playlist_t *playlist, ssize_t index,
 
 } // extern "C"
 
-static const struct vlc_playlist_callbacks playlist_callbacks = {
-    /* C++ (before C++20) does not support designated initializers */
-    on_playlist_items_reset,
-    on_playlist_items_added,
-    on_playlist_items_moved,
-    on_playlist_items_removed,
-    on_playlist_items_updated,
-    nullptr,
-    nullptr,
-    on_playlist_current_item_changed,
-    nullptr,
-    nullptr,
-};
+static const struct vlc_playlist_callbacks playlist_callbacks = []{
+    struct vlc_playlist_callbacks cbs {};
+    cbs.on_items_reset = on_playlist_items_reset;
+    cbs.on_items_added = on_playlist_items_added;
+    cbs.on_items_moved = on_playlist_items_moved;
+    cbs.on_items_removed = on_playlist_items_removed;
+    cbs.on_items_updated = on_playlist_items_updated;
+    cbs.on_current_index_changed = on_playlist_current_item_changed;
+    return cbs;
+}();
 
 // private API
 


=====================================
modules/gui/skins2/src/vlcproc.cpp
=====================================
@@ -366,66 +366,39 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
         pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
     }
 
-    static const struct vlc_playlist_callbacks playlist_cbs = {
-    on_playlist_items_reset,
-    on_playlist_items_added,
-    NULL, // on_playlist_items_moved,
-    on_playlist_items_removed,
-    on_playlist_items_updated,
-    on_playlist_playback_repeat_changed,
-    on_playlist_playback_order_changed,
-    on_playlist_current_index_changed,
-    NULL, // on_playlist_has_prev_changed
-    NULL, // on_playlist_has_next_changed
-    };
-
-    static const struct vlc_player_cbs player_cbs = {
-    on_player_current_media_changed,
-    on_player_state_changed,
-    NULL, //on_player_error_changed,
-    NULL, //on_player_buffering,
-    on_player_rate_changed,
-    on_player_capabilities_changed,
-    on_player_position_changed,
-    NULL, //on_player_length_changed,
-    NULL, //on_player_track_list_changed,
-    on_player_track_selection_changed,
-    NULL, //on_player_track_delay_changed,
-    NULL, //on_player_program_list_changed,
-    NULL, //on_player_program_selection_changed,
-    on_player_titles_changed,
-    NULL, //on_player_title_selection_changed,
-    NULL, //on_player_chapter_selection_changed,
-    NULL, //on_player_teletext_menu_changed,
-    NULL, //on_player_teletext_enabled_changed,
-    NULL, //on_player_teletext_page_changed,
-    NULL, //on_player_teletext_transparency_changed,
-    NULL, //on_player_category_delay_changed,
-    NULL, //on_player_associated_subs_fps_changed,
-    NULL, //on_player_renderer_changed,
-    on_player_recording_changed,
-    NULL, //on_player_signal_changed,
-    NULL, //on_player_stats_changed,
-    NULL, //on_player_atobloop_changed,
-    NULL, //on_player_media_stopped_action_changed,
-    NULL, //on_player_media_meta_changed,
-    NULL, //on_player_media_epg_changed,
-    NULL, //on_player_subitems_changed,
-    on_player_vout_changed,
-    NULL, //on_player_corks_changed
-    NULL, //on_playback_restore_queried
-    };
-
-    static const struct vlc_player_vout_cbs player_vout_cbs = {
-    NULL, // on_player_vout_fullscreen_changed,
-    NULL, // on_player_vout_wallpaper_mode_changed
-    };
-
-    static const struct vlc_player_aout_cbs player_aout_cbs = {
-    on_player_aout_volume_changed,
-    on_player_aout_mute_changed,
-    NULL, //on_player_device_changed,
-    };
+    static const struct vlc_playlist_callbacks playlist_cbs = []{
+        struct vlc_playlist_callbacks cbs {};
+        cbs.on_items_reset = on_playlist_items_reset;
+        cbs.on_items_added = on_playlist_items_added;
+        cbs.on_items_removed = on_playlist_items_removed;
+        cbs.on_items_updated = on_playlist_items_updated;
+        cbs.on_playback_repeat_changed = on_playlist_playback_repeat_changed;
+        cbs.on_playback_order_changed = on_playlist_playback_order_changed;
+        cbs.on_current_index_changed = on_playlist_current_index_changed;
+        return cbs;
+    }();
+
+    static const struct vlc_player_cbs player_cbs = []{
+        struct vlc_player_cbs cbs {};
+        cbs.on_current_media_changed = on_player_current_media_changed;
+        cbs.on_state_changed = on_player_state_changed;
+        cbs.on_rate_changed = on_player_rate_changed;
+        cbs.on_capabilities_changed = on_player_capabilities_changed;
+        cbs.on_position_changed = on_player_position_changed;
+        cbs.on_track_selection_changed = on_player_track_selection_changed;
+        cbs.on_titles_changed = on_player_titles_changed;
+        cbs.on_recording_changed = on_player_recording_changed;
+        cbs.on_vout_changed = on_player_vout_changed;
+        return cbs;
+    }();
+
+    static const struct vlc_player_vout_cbs player_vout_cbs {};
+    static const struct vlc_player_aout_cbs player_aout_cbs = []{
+        struct vlc_player_aout_cbs cbs {};
+        cbs.on_volume_changed = on_player_aout_volume_changed;
+        cbs.on_mute_changed = on_player_aout_mute_changed;
+        return cbs;
+    }();
 
     // Add various listeners
     vlc_playlist_Lock( getPL() );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a28a9dd75c12a917f5b8b60eae4f5db147d83ee2...2828c9500409bcdfac07f69fd17fd890bc561279

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a28a9dd75c12a917f5b8b60eae4f5db147d83ee2...2828c9500409bcdfac07f69fd17fd890bc561279
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list