mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
ges: Keep layers sorted by priorities in the timeline
This commit is contained in:
parent
ee5c67de2f
commit
2bbcbab174
1 changed files with 34 additions and 3 deletions
|
@ -246,6 +246,26 @@ ges_timeline_init (GESTimeline * self)
|
|||
gst_discoverer_start (self->priv->discoverer);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_layers (gpointer a, gpointer b)
|
||||
{
|
||||
GESTimelineLayer *layer_a, *layer_b;
|
||||
guint prio_a, prio_b;
|
||||
|
||||
layer_a = GES_TIMELINE_LAYER (a);
|
||||
layer_b = GES_TIMELINE_LAYER (b);
|
||||
|
||||
prio_a = ges_timeline_layer_get_priority (layer_a);
|
||||
prio_b = ges_timeline_layer_get_priority (layer_b);
|
||||
|
||||
if ((gint) prio_a > (guint) prio_b)
|
||||
return 1;
|
||||
if ((guint) prio_a < (guint) prio_b)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_new:
|
||||
*
|
||||
|
@ -613,6 +633,13 @@ layer_object_added_cb (GESTimelineLayer * layer, GESTimelineObject * object,
|
|||
GST_DEBUG ("done");
|
||||
}
|
||||
|
||||
static void
|
||||
layer_priority_changed_cb (GESTimelineLayer * layer,
|
||||
GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
|
||||
{
|
||||
timeline->priv->layers = g_list_sort (timeline->priv->layers, (GCompareFunc)
|
||||
sort_layers);
|
||||
}
|
||||
|
||||
static void
|
||||
layer_object_removed_cb (GESTimelineLayer * layer, GESTimelineObject * object,
|
||||
|
@ -688,7 +715,8 @@ ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
|
|||
}
|
||||
|
||||
g_object_ref_sink (layer);
|
||||
priv->layers = g_list_append (priv->layers, layer);
|
||||
priv->layers = g_list_insert_sorted (priv->layers, layer,
|
||||
(GCompareFunc) sort_layers);
|
||||
|
||||
/* Inform the layer that it belongs to a new timeline */
|
||||
ges_timeline_layer_set_timeline (layer, timeline);
|
||||
|
@ -698,6 +726,8 @@ ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
|
|||
timeline);
|
||||
g_signal_connect (layer, "object-removed",
|
||||
G_CALLBACK (layer_object_removed_cb), timeline);
|
||||
g_signal_connect (layer, "notify::priority",
|
||||
G_CALLBACK (layer_priority_changed_cb), timeline);
|
||||
|
||||
GST_DEBUG ("Done adding layer, emitting 'layer-added' signal");
|
||||
g_signal_emit (timeline, ges_timeline_signals[LAYER_ADDED], 0, layer);
|
||||
|
@ -1022,7 +1052,7 @@ ges_timeline_get_tracks (GESTimeline * timeline)
|
|||
* Get the list of #GESTimelineLayer present in the Timeline.
|
||||
*
|
||||
* Returns: (transfer full) (element-type GESTimelineLayer): the list of
|
||||
* #GESTimelineLayer present in the Timeline.
|
||||
* #GESTimelineLayer present in the Timeline sorted by priority.
|
||||
* The caller should unref each Layer once he is done with them.
|
||||
*/
|
||||
GList *
|
||||
|
@ -1031,7 +1061,8 @@ ges_timeline_get_layers (GESTimeline * timeline)
|
|||
GList *tmp, *res = NULL;
|
||||
|
||||
for (tmp = timeline->priv->layers; tmp; tmp = g_list_next (tmp)) {
|
||||
res = g_list_append (res, g_object_ref (tmp->data));
|
||||
res = g_list_insert_sorted (res, g_object_ref (tmp->data),
|
||||
(GCompareFunc) sort_layers);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
Loading…
Reference in a new issue