clapper: reactable: Inform which properties were updated

This commit is contained in:
Rafał Dzięgiel
2025-06-09 19:54:30 +02:00
parent c0b360dc0f
commit c354d31436
7 changed files with 54 additions and 19 deletions

View File

@@ -151,4 +151,23 @@ typedef enum
CLAPPER_ENHANCER_PARAM_DIRPATH = 1 << 20, CLAPPER_ENHANCER_PARAM_DIRPATH = 1 << 20,
} ClapperEnhancerParamFlags; } 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 G_END_DECLS

View File

@@ -471,7 +471,7 @@ _tags_replace_func (const GstTagList *tags, const gchar *tag, ClapperMediaItemTa
static gboolean static gboolean
clapper_media_item_insert_tags_internal (ClapperMediaItem *self, const GstTagList *tags, 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; ClapperMediaItemTagIterData data;
gboolean title_changed = FALSE, cont_changed = FALSE; 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); gst_tag_list_foreach (tags, (GstTagForeachFunc) _tags_replace_func, &data);
if (data.changed) { if (data.changed) {
title_changed = _refresh_tag_prop_unlocked (self, GST_TAG_TITLE, *flags |= CLAPPER_REACTABLE_ITEM_UPDATED_TAGS;
from_user, &self->title);
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, cont_changed = _refresh_tag_prop_unlocked (self, GST_TAG_CONTAINER_FORMAT,
from_user, &self->container_format); from_user, &self->container_format);
} }
@@ -548,6 +552,7 @@ clapper_media_item_populate_tags (ClapperMediaItem *self, const GstTagList *tags
{ {
ClapperPlayer *player; ClapperPlayer *player;
ClapperAppBus *app_bus = NULL; ClapperAppBus *app_bus = NULL;
ClapperReactableItemUpdatedFlags flags = 0;
gboolean changed; gboolean changed;
g_return_val_if_fail (CLAPPER_IS_MEDIA_ITEM (self), FALSE); 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)))) if ((player = clapper_player_get_from_ancestor (GST_OBJECT_CAST (self))))
app_bus = player->app_bus; 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) { if (changed && player) {
ClapperFeaturesManager *features_manager; ClapperFeaturesManager *features_manager;
if (player->reactables_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))) if ((features_manager = clapper_player_get_features_manager (player)))
clapper_features_manager_trigger_item_updated (features_manager, self); 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); GstTagScope scope = gst_tag_list_get_scope (tags);
if (scope == GST_TAG_SCOPE_GLOBAL) { 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) { if (changed) {
ClapperFeaturesManager *features_manager; ClapperFeaturesManager *features_manager;
if (player->reactables_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))) if ((features_manager = clapper_player_get_features_manager (player)))
clapper_features_manager_trigger_item_updated (features_manager, self); 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; ClapperPlayer *player;
GstDiscovererStreamInfo *sinfo; GstDiscovererStreamInfo *sinfo;
GstClockTime duration; GstClockTime duration;
ClapperReactableItemUpdatedFlags flags = 0;
gdouble val_dbl; gdouble val_dbl;
gboolean changed = FALSE; gboolean changed = FALSE;
@@ -634,7 +641,7 @@ clapper_media_item_update_from_discoverer_info (ClapperMediaItem *self, GstDisco
GstDiscovererContainerInfo *cinfo = (GstDiscovererContainerInfo *) sinfo; GstDiscovererContainerInfo *cinfo = (GstDiscovererContainerInfo *) sinfo;
if ((tags = gst_discoverer_container_info_get_tags (cinfo))) 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); gst_discoverer_stream_info_unref (sinfo);
} }
@@ -645,13 +652,16 @@ clapper_media_item_update_from_discoverer_info (ClapperMediaItem *self, GstDisco
duration = 0; duration = 0;
val_dbl = (gdouble) duration / GST_SECOND; 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) { if (changed) {
ClapperFeaturesManager *features_manager; ClapperFeaturesManager *features_manager;
if (player->reactables_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))) if ((features_manager = clapper_player_get_features_manager (player)))
clapper_features_manager_trigger_item_updated (features_manager, self); clapper_features_manager_trigger_item_updated (features_manager, self);
} }

View File

@@ -173,8 +173,10 @@ _update_current_duration (ClapperPlayer *player)
if (clapper_media_item_set_duration (player->played_item, duration_dbl, player->app_bus)) { if (clapper_media_item_set_duration (player->played_item, duration_dbl, player->app_bus)) {
ClapperFeaturesManager *features_manager; ClapperFeaturesManager *features_manager;
if (player->reactables_manager) if (player->reactables_manager) {
clapper_reactables_manager_trigger_item_updated (player->reactables_manager, player->played_item); 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))) if ((features_manager = clapper_player_get_features_manager (player)))
clapper_features_manager_trigger_item_updated (features_manager, player->played_item); clapper_features_manager_trigger_item_updated (features_manager, player->played_item);
} }

View File

@@ -130,6 +130,7 @@ struct _ClapperReactableInterface
* ClapperReactableInterface::item_updated: * ClapperReactableInterface::item_updated:
* @reactable: a #ClapperReactable * @reactable: a #ClapperReactable
* @item: a #ClapperMediaItem that was updated * @item: a #ClapperMediaItem that was updated
* @flags: flags informing which properties were updated
* *
* An item in queue got updated. * An item in queue got updated.
* *
@@ -140,7 +141,7 @@ struct _ClapperReactableInterface
* *
* Since: 0.10 * Since: 0.10
*/ */
void (* item_updated) (ClapperReactable *reactable, ClapperMediaItem *item); void (* item_updated) (ClapperReactable *reactable, ClapperMediaItem *item, ClapperReactableItemUpdatedFlags flags);
/** /**
* ClapperReactableInterface::queue_item_added: * ClapperReactableInterface::queue_item_added:

View File

@@ -62,7 +62,7 @@ G_GNUC_INTERNAL
void clapper_reactables_manager_trigger_played_item_changed (ClapperReactablesManager *manager, ClapperMediaItem *item); void clapper_reactables_manager_trigger_played_item_changed (ClapperReactablesManager *manager, ClapperMediaItem *item);
G_GNUC_INTERNAL 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 G_GNUC_INTERNAL
void clapper_reactables_manager_trigger_queue_item_added (ClapperReactablesManager *manager, ClapperMediaItem *item, guint index); void clapper_reactables_manager_trigger_queue_item_added (ClapperReactablesManager *manager, ClapperMediaItem *item, guint index);

View File

@@ -271,7 +271,8 @@ clapper_reactables_manager_handle_event (ClapperReactablesManager *self, const G
case _EVENT (ITEM_UPDATED): case _EVENT (ITEM_UPDATED):
if (reactable_iface->item_updated) { if (reactable_iface->item_updated) {
reactable_iface->item_updated (data->reactable, 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; break;
case _EVENT (QUEUE_ITEM_ADDED): case _EVENT (QUEUE_ITEM_ADDED):
@@ -428,9 +429,9 @@ clapper_reactables_manager_trigger_played_item_changed (ClapperReactablesManager
} }
void 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 void

View File

@@ -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))))) { if ((item = CLAPPER_MEDIA_ITEM_CAST (gst_object_get_parent (GST_OBJECT_CAST (self))))) {
ClapperFeaturesManager *features_manager; ClapperFeaturesManager *features_manager;
if (player->reactables_manager) if (player->reactables_manager) {
clapper_reactables_manager_trigger_item_updated (player->reactables_manager, item); clapper_reactables_manager_trigger_item_updated (player->reactables_manager, item,
CLAPPER_REACTABLE_ITEM_UPDATED_TIMELINE);
}
if ((features_manager = clapper_player_get_features_manager (player))) if ((features_manager = clapper_player_get_features_manager (player)))
clapper_features_manager_trigger_item_updated (features_manager, item); clapper_features_manager_trigger_item_updated (features_manager, item);