timeline-element: Add a method to retrieve layer priority

Each timeline element is in a layer (potentially spanning
over several), it is very often useful to retrieve an element
layer priority (from an app perspective more than the element
priority itself as that is a bit of an implementation detail
in the end).

Port tests to it
This commit is contained in:
Thibault Saunier 2019-03-01 19:08:39 -03:00 committed by Thibault Saunier
parent fe1595aef1
commit 7c5f2d11b2
7 changed files with 78 additions and 33 deletions

View file

@ -257,6 +257,17 @@ _set_priority (GESTimelineElement * element, guint32 priority)
return TRUE;
}
static guint32
_get_layer_priority (GESTimelineElement * element)
{
GESClip *clip = GES_CLIP (element);
if (clip->priv->layer == NULL)
return GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY;
return ges_layer_get_priority (clip->priv->layer);
}
/****************************************************
* *
* GESContainer virtual methods implementation *
@ -833,6 +844,7 @@ ges_clip_class_init (GESClipClass * klass)
element_class->paste = _paste;
element_class->deep_copy = _deep_copy;
element_class->lookup_child = _lookup_child;
element_class->get_layer_priority = _get_layer_priority;
container_class->add_child = _add_child;
container_class->remove_child = _remove_child;

View file

@ -118,7 +118,7 @@ _update_our_values (GESGroup * group)
for (tmp = GES_CONTAINER_CHILDREN (group); tmp; tmp = tmp->next) {
GESTimelineElement *child = tmp->data;
guint32 child_prio = GES_IS_CLIP (child) ?
ges_clip_get_layer_priority (GES_CLIP (child)) : _PRIORITY (child);
GES_TIMELINE_ELEMENT_LAYER_PRIORITY (child) : _PRIORITY (child);
_ges_container_set_priority_offset (container,
child, min_layer_prio - child_prio);
@ -159,7 +159,7 @@ _child_clip_changed_layer_cb (GESTimelineElement * clip,
ChildSignalIds *sigids;
gchar *signals_ids_key;
GESLayer *old_layer, *new_layer;
gint offset, layer_prio = ges_clip_get_layer_priority (GES_CLIP (clip));
gint offset, layer_prio = GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip);
GESContainer *container = GES_CONTAINER (group);
offset = _ges_container_get_priority_offset (container, clip);
@ -335,11 +335,10 @@ _set_priority (GESTimelineElement * element, guint32 priority)
if (child != container->initiated_move) {
if (GES_IS_CLIP (child)) {
guint32 layer_prio =
ges_clip_get_layer_priority (GES_CLIP (child)) + diff;
guint32 layer_prio = GES_TIMELINE_ELEMENT_LAYER_PRIORITY (child) + diff;
GST_DEBUG_OBJECT (child, "moving from layer: %i to %i",
ges_clip_get_layer_priority (GES_CLIP (child)), layer_prio);
GES_TIMELINE_ELEMENT_LAYER_PRIORITY (child), layer_prio);
ges_clip_move_to_layer (GES_CLIP (child),
g_list_nth_data (layers, layer_prio));
} else if (GES_IS_GROUP (child)) {

View file

@ -1853,6 +1853,26 @@ ges_timeline_element_paste (GESTimelineElement * self,
return g_object_ref (res);
}
/**
* ges_timeline_element_get_layer_priority:
* @self: A #GESTimelineElement
*
* Returns: The priority of the first layer the element is in (note that only
* groups can span over several layers). %GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY
* means that the element is not in a layer.
*/
guint32
ges_timeline_element_get_layer_priority (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self),
GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY);
if (!GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_layer_priority)
return self->priority;
return GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_layer_priority (self);
}
/* Internal */
gdouble
ges_timeline_element_get_media_duration_factor (GESTimelineElement * self)
@ -1912,18 +1932,6 @@ ges_timeline_element_flags (GESTimelineElement * self)
return self->priv->flags;
}
gint32
_layer_priority (GESTimelineElement * element)
{
if (GES_IS_CLIP (element))
return ges_clip_get_layer_priority (GES_CLIP (element));
if (GES_IS_TRACK_ELEMENT (element))
return element->priority / LAYER_HEIGHT;
return element->priority;
}
void
ges_timeline_element_set_flags (GESTimelineElement * self,
GESTimelineElementFlags flags)

View file

@ -84,6 +84,21 @@ typedef struct _GESTimelineElementPrivate GESTimelineElementPrivate;
*/
#define GES_TIMELINE_ELEMENT_PRIORITY(obj) (((GESTimelineElement*)obj)->priority)
/**
* GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY:
*
* Layer priority when the element is not in a layer
*/
#define GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY ((guint32) -1)
/**
* GES_TIMELINE_ELEMENT_LAYER_PRIORITY:
* @obj: The object to retrieve the layer priority from
*
* See #ges_timeline_element_get_layer_priority
*/
#define GES_TIMELINE_ELEMENT_LAYER_PRIORITY(obj) (ges_timeline_element_get_layer_priority(((GESTimelineElement*)obj)))
/**
* GES_TIMELINE_ELEMENT_PARENT:
* @obj: a #GESTimelineElement
@ -198,9 +213,11 @@ struct _GESTimelineElementClass
void (*set_child_property) (GESTimelineElement * self, GObject *child,
GParamSpec *pspec, GValue *value);
guint32 (*get_layer_priority) (GESTimelineElement *self);
/*< private > */
/* Padding for API extension */
gpointer _ges_reserved[GES_PADDING_LARGE - 3];
gpointer _ges_reserved[GES_PADDING_LARGE - 4];
};
GES_API
@ -319,6 +336,9 @@ GESTimelineElement * ges_timeline_element_paste (GESTimelineElement * self,
GES_API
GESTrackType ges_timeline_element_get_track_types (GESTimelineElement * self);
GES_API
guint32 ges_timeline_element_get_layer_priority (GESTimelineElement * self);
G_END_DECLS
#endif /* _GES_TIMELINE_ELEMENT_H_ */

View file

@ -122,6 +122,15 @@ strv_find_str (const gchar ** strv, const char *str)
return FALSE;
}
static guint32
_get_layer_priority (GESTimelineElement * element)
{
if (!element->parent)
return GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY;
return ges_timeline_element_get_layer_priority (element->parent);
}
static void
ges_track_element_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
@ -310,6 +319,7 @@ ges_track_element_class_init (GESTrackElementClass * klass)
element_class->set_priority = _set_priority;
element_class->get_track_types = _get_track_types;
element_class->deep_copy = ges_track_element_copy_properties;
element_class->get_layer_priority = _get_layer_priority;
klass->create_gnl_object = ges_track_element_create_gnl_object_func;
klass->list_children_properties = default_list_children_properties;

View file

@ -565,15 +565,15 @@ GST_START_TEST (test_group_in_group_layer_moving)
CHECK_OBJECT_PROPS (c, 10, 0, 10);
CHECK_OBJECT_PROPS (c1, 20, 0, 10);
CHECK_OBJECT_PROPS (group, 10, 0, 20);
assert_equals_int (ges_clip_get_layer_priority (c), 0);
assert_equals_int (ges_clip_get_layer_priority (c1), 1);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 0);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1);
ges_layer_set_priority (layer2, 0);
ges_layer_set_priority (layer, 1);
ges_layer_set_priority (layer1, 2);
assert_equals_int (ges_clip_get_layer_priority (c), 1);
assert_equals_int (ges_clip_get_layer_priority (c1), 2);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 1);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 2);
/* Our timeline
*
@ -595,8 +595,8 @@ GST_START_TEST (test_group_in_group_layer_moving)
CHECK_OBJECT_PROPS (c, 10, 0, 10);
CHECK_OBJECT_PROPS (c1, 20, 0, 10);
CHECK_OBJECT_PROPS (group, 10, 0, 20);
assert_equals_int (ges_clip_get_layer_priority (c), 0);
assert_equals_int (ges_clip_get_layer_priority (c1), 1);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 0);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1);
/* Our timeline
*
@ -617,8 +617,8 @@ GST_START_TEST (test_group_in_group_layer_moving)
CHECK_OBJECT_PROPS (c, 10, 0, 10);
CHECK_OBJECT_PROPS (c1, 20, 0, 10);
CHECK_OBJECT_PROPS (group, 10, 0, 20);
assert_equals_int (ges_clip_get_layer_priority (c), 1);
assert_equals_int (ges_clip_get_layer_priority (c1), 2);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 1);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 2);
gst_object_unref (timeline);
gst_object_unref (asset);

View file

@ -738,9 +738,7 @@ GST_START_TEST (test_timeline_edition_mode)
CHECK_OBJECT_PROPS (trackelement, 32, 5, 3);
CHECK_OBJECT_PROPS (trackelement1, 20, 0, 10);
CHECK_OBJECT_PROPS (trackelement2, 35, 0, 60);
layer = ges_clip_get_layer (GES_CLIP (clip));
assert_equals_int (ges_layer_get_priority (layer), 2);
gst_object_unref (layer);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip), 2);
/* Roll end clip to 50
* New timeline:
@ -802,10 +800,8 @@ GST_START_TEST (test_timeline_edition_mode)
GES_EDGE_END, 52) == TRUE);
CHECK_OBJECT_PROPS (trackelement, 32, 5, 20);
CHECK_OBJECT_PROPS (trackelement1, 20, 0, 10);
CHECK_OBJECT_PROPS (trackelement2, 52, 0, 60)
layer = ges_clip_get_layer (GES_CLIP (clip));
assert_equals_int (ges_layer_get_priority (layer), 2);
gst_object_unref (layer);
CHECK_OBJECT_PROPS (trackelement2, 52, 0, 60);
assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip), 2);
/* Little check that we have 4 layers in the timeline */