From c354d314367a6fcafaa5dd5cf6247b51882f1dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Mon, 9 Jun 2025 19:54:30 +0200 Subject: [PATCH] clapper: reactable: Inform which properties were updated --- src/lib/clapper/clapper-enums.h | 19 ++++++++++++ src/lib/clapper/clapper-media-item.c | 30 ++++++++++++------- src/lib/clapper/clapper-playbin-bus.c | 6 ++-- src/lib/clapper/clapper-reactable.h | 3 +- .../clapper-reactables-manager-private.h | 2 +- src/lib/clapper/clapper-reactables-manager.c | 7 +++-- src/lib/clapper/clapper-timeline.c | 6 ++-- 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/lib/clapper/clapper-enums.h b/src/lib/clapper/clapper-enums.h index 70dc5841..2140e2e9 100644 --- a/src/lib/clapper/clapper-enums.h +++ b/src/lib/clapper/clapper-enums.h @@ -151,4 +151,23 @@ typedef enum CLAPPER_ENHANCER_PARAM_DIRPATH = 1 << 20, } ClapperEnhancerParamFlags; +/** + * ClapperReactableItemUpdatedFlags: + * @CLAPPER_REACTABLE_ITEM_UPDATED_TITLE: Media item title was updated. + * @CLAPPER_REACTABLE_ITEM_UPDATED_DURATION: Media item duration was updated. + * @CLAPPER_REACTABLE_ITEM_UPDATED_TIMELINE: Media item timeline was updated. + * @CLAPPER_REACTABLE_ITEM_UPDATED_TAGS: Media item tags were updated. + * + * Flags informing which properties were updated within [class@Clapper.MediaItem]. + * + * Since: 0.10 + */ +typedef enum +{ + CLAPPER_REACTABLE_ITEM_UPDATED_TITLE = 1 << 0, + CLAPPER_REACTABLE_ITEM_UPDATED_DURATION = 1 << 1, + CLAPPER_REACTABLE_ITEM_UPDATED_TIMELINE = 1 << 2, + CLAPPER_REACTABLE_ITEM_UPDATED_TAGS = 1 << 3, +} ClapperReactableItemUpdatedFlags; + G_END_DECLS diff --git a/src/lib/clapper/clapper-media-item.c b/src/lib/clapper/clapper-media-item.c index b4e925c7..522e2f59 100644 --- a/src/lib/clapper/clapper-media-item.c +++ b/src/lib/clapper/clapper-media-item.c @@ -471,7 +471,7 @@ _tags_replace_func (const GstTagList *tags, const gchar *tag, ClapperMediaItemTa static gboolean clapper_media_item_insert_tags_internal (ClapperMediaItem *self, const GstTagList *tags, - ClapperAppBus *app_bus, gboolean from_user) + ClapperAppBus *app_bus, gboolean from_user, ClapperReactableItemUpdatedFlags *flags) { ClapperMediaItemTagIterData data; gboolean title_changed = FALSE, cont_changed = FALSE; @@ -486,8 +486,12 @@ clapper_media_item_insert_tags_internal (ClapperMediaItem *self, const GstTagLis gst_tag_list_foreach (tags, (GstTagForeachFunc) _tags_replace_func, &data); if (data.changed) { - title_changed = _refresh_tag_prop_unlocked (self, GST_TAG_TITLE, - from_user, &self->title); + *flags |= CLAPPER_REACTABLE_ITEM_UPDATED_TAGS; + + if ((title_changed = _refresh_tag_prop_unlocked (self, GST_TAG_TITLE, + from_user, &self->title))) { + *flags |= CLAPPER_REACTABLE_ITEM_UPDATED_TITLE; + } cont_changed = _refresh_tag_prop_unlocked (self, GST_TAG_CONTAINER_FORMAT, from_user, &self->container_format); } @@ -548,6 +552,7 @@ clapper_media_item_populate_tags (ClapperMediaItem *self, const GstTagList *tags { ClapperPlayer *player; ClapperAppBus *app_bus = NULL; + ClapperReactableItemUpdatedFlags flags = 0; gboolean changed; g_return_val_if_fail (CLAPPER_IS_MEDIA_ITEM (self), FALSE); @@ -561,13 +566,13 @@ clapper_media_item_populate_tags (ClapperMediaItem *self, const GstTagList *tags if ((player = clapper_player_get_from_ancestor (GST_OBJECT_CAST (self)))) app_bus = player->app_bus; - changed = clapper_media_item_insert_tags_internal (self, tags, app_bus, TRUE); + changed = clapper_media_item_insert_tags_internal (self, tags, app_bus, TRUE, &flags); if (changed && player) { ClapperFeaturesManager *features_manager; if (player->reactables_manager) - clapper_reactables_manager_trigger_item_updated (player->reactables_manager, self); + clapper_reactables_manager_trigger_item_updated (player->reactables_manager, self, flags); if ((features_manager = clapper_player_get_features_manager (player))) clapper_features_manager_trigger_item_updated (features_manager, self); } @@ -600,13 +605,14 @@ clapper_media_item_update_from_tag_list (ClapperMediaItem *self, const GstTagLis GstTagScope scope = gst_tag_list_get_scope (tags); if (scope == GST_TAG_SCOPE_GLOBAL) { - gboolean changed = clapper_media_item_insert_tags_internal (self, tags, player->app_bus, FALSE); + ClapperReactableItemUpdatedFlags flags = 0; + gboolean changed = clapper_media_item_insert_tags_internal (self, tags, player->app_bus, FALSE, &flags); if (changed) { ClapperFeaturesManager *features_manager; if (player->reactables_manager) - clapper_reactables_manager_trigger_item_updated (player->reactables_manager, self); + clapper_reactables_manager_trigger_item_updated (player->reactables_manager, self, flags); if ((features_manager = clapper_player_get_features_manager (player))) clapper_features_manager_trigger_item_updated (features_manager, self); } @@ -619,6 +625,7 @@ clapper_media_item_update_from_discoverer_info (ClapperMediaItem *self, GstDisco ClapperPlayer *player; GstDiscovererStreamInfo *sinfo; GstClockTime duration; + ClapperReactableItemUpdatedFlags flags = 0; gdouble val_dbl; gboolean changed = FALSE; @@ -634,7 +641,7 @@ clapper_media_item_update_from_discoverer_info (ClapperMediaItem *self, GstDisco GstDiscovererContainerInfo *cinfo = (GstDiscovererContainerInfo *) sinfo; if ((tags = gst_discoverer_container_info_get_tags (cinfo))) - changed |= clapper_media_item_insert_tags_internal (self, tags, player->app_bus, FALSE); + changed |= clapper_media_item_insert_tags_internal (self, tags, player->app_bus, FALSE, &flags); } gst_discoverer_stream_info_unref (sinfo); } @@ -645,13 +652,16 @@ clapper_media_item_update_from_discoverer_info (ClapperMediaItem *self, GstDisco duration = 0; val_dbl = (gdouble) duration / GST_SECOND; - changed |= clapper_media_item_set_duration (self, val_dbl, player->app_bus); + if (clapper_media_item_set_duration (self, val_dbl, player->app_bus)) { + changed = TRUE; + flags |= CLAPPER_REACTABLE_ITEM_UPDATED_DURATION; + } if (changed) { ClapperFeaturesManager *features_manager; if (player->reactables_manager) - clapper_reactables_manager_trigger_item_updated (player->reactables_manager, self); + clapper_reactables_manager_trigger_item_updated (player->reactables_manager, self, flags); if ((features_manager = clapper_player_get_features_manager (player))) clapper_features_manager_trigger_item_updated (features_manager, self); } diff --git a/src/lib/clapper/clapper-playbin-bus.c b/src/lib/clapper/clapper-playbin-bus.c index 0260455b..05746c18 100644 --- a/src/lib/clapper/clapper-playbin-bus.c +++ b/src/lib/clapper/clapper-playbin-bus.c @@ -173,8 +173,10 @@ _update_current_duration (ClapperPlayer *player) if (clapper_media_item_set_duration (player->played_item, duration_dbl, player->app_bus)) { ClapperFeaturesManager *features_manager; - if (player->reactables_manager) - clapper_reactables_manager_trigger_item_updated (player->reactables_manager, player->played_item); + if (player->reactables_manager) { + clapper_reactables_manager_trigger_item_updated (player->reactables_manager, player->played_item, + CLAPPER_REACTABLE_ITEM_UPDATED_DURATION); + } if ((features_manager = clapper_player_get_features_manager (player))) clapper_features_manager_trigger_item_updated (features_manager, player->played_item); } diff --git a/src/lib/clapper/clapper-reactable.h b/src/lib/clapper/clapper-reactable.h index e53f2f8a..1ce1e810 100644 --- a/src/lib/clapper/clapper-reactable.h +++ b/src/lib/clapper/clapper-reactable.h @@ -130,6 +130,7 @@ struct _ClapperReactableInterface * ClapperReactableInterface::item_updated: * @reactable: a #ClapperReactable * @item: a #ClapperMediaItem that was updated + * @flags: flags informing which properties were updated * * An item in queue got updated. * @@ -140,7 +141,7 @@ struct _ClapperReactableInterface * * Since: 0.10 */ - void (* item_updated) (ClapperReactable *reactable, ClapperMediaItem *item); + void (* item_updated) (ClapperReactable *reactable, ClapperMediaItem *item, ClapperReactableItemUpdatedFlags flags); /** * ClapperReactableInterface::queue_item_added: diff --git a/src/lib/clapper/clapper-reactables-manager-private.h b/src/lib/clapper/clapper-reactables-manager-private.h index 80496648..1bef8f2c 100644 --- a/src/lib/clapper/clapper-reactables-manager-private.h +++ b/src/lib/clapper/clapper-reactables-manager-private.h @@ -62,7 +62,7 @@ G_GNUC_INTERNAL void clapper_reactables_manager_trigger_played_item_changed (ClapperReactablesManager *manager, ClapperMediaItem *item); G_GNUC_INTERNAL -void clapper_reactables_manager_trigger_item_updated (ClapperReactablesManager *manager, ClapperMediaItem *item); +void clapper_reactables_manager_trigger_item_updated (ClapperReactablesManager *manager, ClapperMediaItem *item, ClapperReactableItemUpdatedFlags flags); G_GNUC_INTERNAL void clapper_reactables_manager_trigger_queue_item_added (ClapperReactablesManager *manager, ClapperMediaItem *item, guint index); diff --git a/src/lib/clapper/clapper-reactables-manager.c b/src/lib/clapper/clapper-reactables-manager.c index 8971deb6..a527456a 100644 --- a/src/lib/clapper/clapper-reactables-manager.c +++ b/src/lib/clapper/clapper-reactables-manager.c @@ -271,7 +271,8 @@ clapper_reactables_manager_handle_event (ClapperReactablesManager *self, const G case _EVENT (ITEM_UPDATED): if (reactable_iface->item_updated) { reactable_iface->item_updated (data->reactable, - CLAPPER_MEDIA_ITEM_CAST (g_value_get_object (value))); + CLAPPER_MEDIA_ITEM_CAST (g_value_get_object (value)), + g_value_get_flags (extra_value)); } break; case _EVENT (QUEUE_ITEM_ADDED): @@ -428,9 +429,9 @@ clapper_reactables_manager_trigger_played_item_changed (ClapperReactablesManager } void -clapper_reactables_manager_trigger_item_updated (ClapperReactablesManager *self, ClapperMediaItem *item) +clapper_reactables_manager_trigger_item_updated (ClapperReactablesManager *self, ClapperMediaItem *item, ClapperReactableItemUpdatedFlags _flags) { - _BUS_POST_EVENT_SINGLE (_EVENT (ITEM_UPDATED), object, CLAPPER_TYPE_MEDIA_ITEM, item); + _BUS_POST_EVENT_DUAL (_EVENT (ITEM_UPDATED), object, CLAPPER_TYPE_MEDIA_ITEM, item, flags, CLAPPER_TYPE_REACTABLE_ITEM_UPDATED_FLAGS, _flags); } void diff --git a/src/lib/clapper/clapper-timeline.c b/src/lib/clapper/clapper-timeline.c index 2b4c9252..3642736b 100644 --- a/src/lib/clapper/clapper-timeline.c +++ b/src/lib/clapper/clapper-timeline.c @@ -113,8 +113,10 @@ clapper_timeline_post_item_updated (ClapperTimeline *self) if ((item = CLAPPER_MEDIA_ITEM_CAST (gst_object_get_parent (GST_OBJECT_CAST (self))))) { ClapperFeaturesManager *features_manager; - if (player->reactables_manager) - clapper_reactables_manager_trigger_item_updated (player->reactables_manager, item); + if (player->reactables_manager) { + clapper_reactables_manager_trigger_item_updated (player->reactables_manager, item, + CLAPPER_REACTABLE_ITEM_UPDATED_TIMELINE); + } if ((features_manager = clapper_player_get_features_manager (player))) clapper_features_manager_trigger_item_updated (features_manager, item);