mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
timeline-layer: Reorganize file
This commit is contained in:
parent
64b4a38494
commit
e172c294fe
1 changed files with 355 additions and 375 deletions
|
@ -37,21 +37,6 @@
|
|||
|
||||
#define LAYER_HEIGHT 1000
|
||||
|
||||
static void
|
||||
track_object_removed_cb (GESTrack * track, GESTrackObject * track_object);
|
||||
static void track_object_added_cb (GESTrack * track,
|
||||
GESTrackObject * track_object, GESTimelineLayer * layer);
|
||||
static void
|
||||
track_removed_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer);
|
||||
static void track_added_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer);
|
||||
static void track_object_changed_cb (GESTrackObject * track_object,
|
||||
GParamSpec * arg G_GNUC_UNUSED);
|
||||
static void calculate_transitions (GESTrackObject * track_object);
|
||||
static void calculate_next_transition (GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer);
|
||||
|
||||
static void
|
||||
timeline_object_height_changed_cb (GESTimelineObject * obj,
|
||||
GESTrackEffect * tr_eff, GESTimelineObject * second_obj);
|
||||
|
@ -64,11 +49,9 @@ struct _GESTimelineLayerPrivate
|
|||
GList *objects_start; /* The TimelineObjects sorted by start and
|
||||
* priority */
|
||||
|
||||
guint32 priority; /* The priority of the layer within the
|
||||
guint32 priority; /* The priority of the layer within the
|
||||
* containing timeline */
|
||||
|
||||
gboolean auto_transition;
|
||||
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -88,13 +71,7 @@ enum
|
|||
|
||||
static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static gboolean ges_timeline_layer_resync_priorities (GESTimelineLayer * layer);
|
||||
|
||||
static GList *track_get_by_layer (GESTimelineLayer * layer, GESTrack * track);
|
||||
|
||||
static void compare (GList * compared, GESTrackObject * track_object,
|
||||
gboolean ahead);
|
||||
|
||||
/* GObject standard vmethods */
|
||||
static void
|
||||
ges_timeline_layer_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
|
@ -218,70 +195,7 @@ ges_timeline_layer_init (GESTimelineLayer * self)
|
|||
self->max_gnl_priority = LAYER_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_new:
|
||||
*
|
||||
* Creates a new #GESTimelineLayer.
|
||||
*
|
||||
* Returns: A new #GESTimelineLayer
|
||||
*/
|
||||
GESTimelineLayer *
|
||||
ges_timeline_layer_new (void)
|
||||
{
|
||||
return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_get_timeline:
|
||||
* @layer: The #GESTimelineLayer to get the parent #GESTimeline from
|
||||
*
|
||||
* Get the #GESTimeline in which #GESTimelineLayer currently is.
|
||||
*
|
||||
* Returns: (transfer none): the #GESTimeline in which #GESTimelineLayer
|
||||
* currently is or %NULL if not in any timeline yet.
|
||||
*/
|
||||
GESTimeline *
|
||||
ges_timeline_layer_get_timeline (GESTimelineLayer * layer)
|
||||
{
|
||||
g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
|
||||
|
||||
return layer->timeline;
|
||||
}
|
||||
|
||||
void
|
||||
ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
|
||||
GESTimeline * timeline)
|
||||
{
|
||||
GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
|
||||
|
||||
if (layer->priv->auto_transition == TRUE) {
|
||||
if (layer->timeline != NULL) {
|
||||
g_signal_handlers_disconnect_by_func (layer->timeline, track_added_cb,
|
||||
layer);
|
||||
g_signal_handlers_disconnect_by_func (layer->timeline, track_removed_cb,
|
||||
layer);
|
||||
}
|
||||
|
||||
if (timeline != NULL) {
|
||||
GList *tmp, *tracks = ges_timeline_get_tracks (timeline);
|
||||
|
||||
g_signal_connect (timeline, "track-added", G_CALLBACK (track_added_cb),
|
||||
layer);
|
||||
g_signal_connect (timeline, "track-removed",
|
||||
G_CALLBACK (track_removed_cb), layer);
|
||||
|
||||
for (tmp = tracks; tmp; tmp = tmp->next) {
|
||||
g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
|
||||
G_CALLBACK (track_object_added_cb), layer);
|
||||
g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
|
||||
G_CALLBACK (track_object_removed_cb), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layer->timeline = timeline;
|
||||
}
|
||||
|
||||
/* Private methods and utils */
|
||||
static gint
|
||||
objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
|
||||
{
|
||||
|
@ -320,265 +234,6 @@ track_get_by_layer (GESTimelineLayer * layer, GESTrack * track)
|
|||
return return_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_add_object:
|
||||
* @layer: a #GESTimelineLayer
|
||||
* @object: (transfer full): the #GESTimelineObject to add.
|
||||
*
|
||||
* Adds the given object to the layer. Sets the object's parent, and thus
|
||||
* takes ownership of the object.
|
||||
*
|
||||
* An object can only be added to one layer.
|
||||
*
|
||||
* Calling this method will construct and properly set all the media related
|
||||
* elements on @object. If you need to know when those objects (actually #GESTrackObject)
|
||||
* are constructed, you should connect to the object::track-object-added signal which
|
||||
* is emited right after those elements are ready to be used.
|
||||
*
|
||||
* Returns: TRUE if the object was properly added to the layer, or FALSE
|
||||
* if the @layer refuses to add the object.
|
||||
*/
|
||||
gboolean
|
||||
ges_timeline_layer_add_object (GESTimelineLayer * layer,
|
||||
GESTimelineObject * object)
|
||||
{
|
||||
GESTimelineLayer *tl_obj_layer;
|
||||
guint32 maxprio, minprio, prio;
|
||||
|
||||
GST_DEBUG ("layer:%p, object:%p", layer, object);
|
||||
|
||||
tl_obj_layer = ges_timeline_object_get_layer (object);
|
||||
|
||||
if (G_UNLIKELY (tl_obj_layer)) {
|
||||
GST_WARNING ("TimelineObject %p already belongs to another layer", object);
|
||||
g_object_unref (tl_obj_layer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_object_ref_sink (object);
|
||||
|
||||
/* Take a reference to the object and store it stored by start/priority */
|
||||
layer->priv->objects_start =
|
||||
g_list_insert_sorted (layer->priv->objects_start, object,
|
||||
(GCompareFunc) objects_start_compare);
|
||||
|
||||
/* Inform the object it's now in this layer */
|
||||
ges_timeline_object_set_layer (object, layer);
|
||||
|
||||
GST_DEBUG ("current object priority : %d, layer min/max : %d/%d",
|
||||
GES_TIMELINE_OBJECT_PRIORITY (object),
|
||||
layer->min_gnl_priority, layer->max_gnl_priority);
|
||||
|
||||
/* Set the priority. */
|
||||
maxprio = layer->max_gnl_priority;
|
||||
minprio = layer->min_gnl_priority;
|
||||
prio = GES_TIMELINE_OBJECT_PRIORITY (object);
|
||||
if (minprio + prio > (maxprio)) {
|
||||
GST_WARNING ("%p is out of the layer %p space, setting its priority to "
|
||||
"setting its priority %d to failthe maximum priority of the layer %d",
|
||||
object, layer, prio, maxprio - minprio);
|
||||
ges_timeline_object_set_priority (object, LAYER_HEIGHT - 1);
|
||||
}
|
||||
/* If the object has an acceptable priority, we just let it with its current
|
||||
* priority */
|
||||
|
||||
ges_timeline_layer_resync_priorities (layer);
|
||||
|
||||
/* emit 'object-added' */
|
||||
g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
track_object_duration_cb (GESTrackObject * track_object,
|
||||
GParamSpec * arg G_GNUC_UNUSED)
|
||||
{
|
||||
GESTimelineLayer *layer;
|
||||
GESTimelineObject *tlobj;
|
||||
|
||||
tlobj = ges_track_object_get_timeline_object (track_object);
|
||||
layer = ges_timeline_object_get_layer (tlobj);
|
||||
if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
|
||||
calculate_next_transition (track_object, layer);
|
||||
}
|
||||
|
||||
static void
|
||||
track_object_removed_cb (GESTrack * track, GESTrackObject * track_object)
|
||||
{
|
||||
GList *track_objects, *tmp, *cur;
|
||||
GESTimelineLayer *layer;
|
||||
|
||||
track_objects = ges_track_get_objects (track);
|
||||
cur = g_list_find (track_objects, track_object);
|
||||
for (tmp = cur->next; tmp; tmp = tmp->next) {
|
||||
if (GES_IS_TRACK_SOURCE (tmp->data)) {
|
||||
break;
|
||||
}
|
||||
if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
|
||||
|| GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
|
||||
layer =
|
||||
ges_timeline_object_get_layer (ges_track_object_get_timeline_object
|
||||
(tmp->data));
|
||||
if (ges_timeline_layer_get_auto_transition (layer)) {
|
||||
ges_track_enable_update (track, FALSE);
|
||||
ges_timeline_layer_remove_object (layer,
|
||||
ges_track_object_get_timeline_object (tmp->data));
|
||||
ges_track_enable_update (track, TRUE);
|
||||
}
|
||||
g_object_unref (layer);
|
||||
}
|
||||
}
|
||||
|
||||
for (tmp = cur->prev; tmp; tmp = tmp->prev) {
|
||||
if (GES_IS_TRACK_SOURCE (tmp->data)) {
|
||||
break;
|
||||
}
|
||||
if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
|
||||
|| GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
|
||||
layer =
|
||||
ges_timeline_object_get_layer (ges_track_object_get_timeline_object
|
||||
(tmp->data));
|
||||
if (ges_timeline_layer_get_auto_transition (layer)) {
|
||||
ges_track_enable_update (track, FALSE);
|
||||
ges_timeline_layer_remove_object (layer,
|
||||
ges_track_object_get_timeline_object (tmp->data));
|
||||
ges_track_enable_update (track, TRUE);
|
||||
}
|
||||
g_object_unref (layer);
|
||||
}
|
||||
}
|
||||
g_object_unref (track_object);
|
||||
}
|
||||
|
||||
static void
|
||||
track_removed_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (track, track_object_added_cb, layer);
|
||||
g_signal_handlers_disconnect_by_func (track, track_object_removed_cb, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
track_added_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
g_signal_connect (track, "track-object-removed",
|
||||
(GCallback) track_object_removed_cb, NULL);
|
||||
g_signal_connect (track, "track-object-added",
|
||||
(GCallback) track_object_added_cb, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
track_object_added_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
GST_ERROR ("TRACKOBJECTADDED %i", GES_IS_TRACK_SOURCE (track_object));
|
||||
if (GES_IS_TRACK_SOURCE (track_object)) {
|
||||
g_signal_connect (G_OBJECT (track_object), "notify::start",
|
||||
G_CALLBACK (track_object_changed_cb), NULL);
|
||||
g_signal_connect (G_OBJECT (track_object), "notify::duration",
|
||||
G_CALLBACK (track_object_duration_cb), NULL);
|
||||
calculate_transitions (track_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
timeline_object_height_changed_cb (GESTimelineObject * obj,
|
||||
GESTrackEffect * tr_eff, GESTimelineObject * second_obj)
|
||||
{
|
||||
gint priority, height;
|
||||
g_object_get (obj, "height", &height, "priority", &priority, NULL);
|
||||
g_object_set (second_obj, "priority", priority + height, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
track_object_changed_cb (GESTrackObject * track_object,
|
||||
GParamSpec * arg G_GNUC_UNUSED)
|
||||
{
|
||||
if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
|
||||
calculate_transitions (track_object);
|
||||
}
|
||||
|
||||
static void
|
||||
calculate_next_transition_with_list (GESTrackObject * track_object,
|
||||
GList * tckobjs_in_layer, GESTimelineLayer * layer)
|
||||
{
|
||||
GList *compared;
|
||||
|
||||
if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
|
||||
return;
|
||||
|
||||
if (compared == NULL)
|
||||
/* This is the last TrackObject of the Track */
|
||||
return;
|
||||
|
||||
do {
|
||||
compared = compared->next;
|
||||
if (compared == NULL)
|
||||
return;
|
||||
} while (!GES_IS_TRACK_SOURCE (compared->data));
|
||||
|
||||
compare (compared, track_object, FALSE);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calculate_next_transition (GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
GESTrack *track;
|
||||
GList *tckobjs_in_layer;
|
||||
|
||||
if ((track = ges_track_object_get_track (track_object))) {
|
||||
tckobjs_in_layer = track_get_by_layer (layer, track);
|
||||
calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
|
||||
|
||||
g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
|
||||
g_list_free (tckobjs_in_layer);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
calculate_transitions (GESTrackObject * track_object)
|
||||
{
|
||||
GList *tckobjs_in_layer, *compared;
|
||||
GESTimelineLayer *layer;
|
||||
GESTimelineObject *tlobj;
|
||||
|
||||
GESTrack *track = ges_track_object_get_track (track_object);
|
||||
|
||||
if (track == NULL)
|
||||
return;
|
||||
|
||||
tlobj = ges_track_object_get_timeline_object (track_object);
|
||||
layer = ges_timeline_object_get_layer (tlobj);
|
||||
tckobjs_in_layer = track_get_by_layer (layer, track);
|
||||
if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
|
||||
return;
|
||||
do {
|
||||
compared = compared->prev;
|
||||
|
||||
if (compared == NULL) {
|
||||
/* Nothing before, let's check after */
|
||||
calculate_next_transition_with_list (track_object, tckobjs_in_layer,
|
||||
layer);
|
||||
goto done;
|
||||
|
||||
}
|
||||
} while (!GES_IS_TRACK_SOURCE (compared->data));
|
||||
|
||||
compare (compared, track_object, TRUE);
|
||||
|
||||
calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
|
||||
|
||||
done:
|
||||
g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
|
||||
g_list_free (tckobjs_in_layer);
|
||||
}
|
||||
|
||||
|
||||
/* Compare:
|
||||
* @compared: The #GList of #GESTrackObjects that we compare with @track_object
|
||||
* @track_object: The #GESTrackObject that serves as a reference
|
||||
|
@ -753,6 +408,84 @@ clean:
|
|||
g_object_unref (layer);
|
||||
}
|
||||
|
||||
static void
|
||||
calculate_next_transition_with_list (GESTrackObject * track_object,
|
||||
GList * tckobjs_in_layer, GESTimelineLayer * layer)
|
||||
{
|
||||
GList *compared;
|
||||
|
||||
if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
|
||||
return;
|
||||
|
||||
if (compared == NULL)
|
||||
/* This is the last TrackObject of the Track */
|
||||
return;
|
||||
|
||||
do {
|
||||
compared = compared->next;
|
||||
if (compared == NULL)
|
||||
return;
|
||||
} while (!GES_IS_TRACK_SOURCE (compared->data));
|
||||
|
||||
compare (compared, track_object, FALSE);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calculate_next_transition (GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
GESTrack *track;
|
||||
GList *tckobjs_in_layer;
|
||||
|
||||
if ((track = ges_track_object_get_track (track_object))) {
|
||||
tckobjs_in_layer = track_get_by_layer (layer, track);
|
||||
calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
|
||||
|
||||
g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
|
||||
g_list_free (tckobjs_in_layer);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
calculate_transitions (GESTrackObject * track_object)
|
||||
{
|
||||
GList *tckobjs_in_layer, *compared;
|
||||
GESTimelineLayer *layer;
|
||||
GESTimelineObject *tlobj;
|
||||
|
||||
GESTrack *track = ges_track_object_get_track (track_object);
|
||||
|
||||
if (track == NULL)
|
||||
return;
|
||||
|
||||
tlobj = ges_track_object_get_timeline_object (track_object);
|
||||
layer = ges_timeline_object_get_layer (tlobj);
|
||||
tckobjs_in_layer = track_get_by_layer (layer, track);
|
||||
if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
|
||||
return;
|
||||
do {
|
||||
compared = compared->prev;
|
||||
|
||||
if (compared == NULL) {
|
||||
/* Nothing before, let's check after */
|
||||
calculate_next_transition_with_list (track_object, tckobjs_in_layer,
|
||||
layer);
|
||||
goto done;
|
||||
|
||||
}
|
||||
} while (!GES_IS_TRACK_SOURCE (compared->data));
|
||||
|
||||
compare (compared, track_object, TRUE);
|
||||
|
||||
calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
|
||||
|
||||
done:
|
||||
g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
|
||||
g_list_free (tckobjs_in_layer);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
look_for_transition (GESTrackObject * track_object, GESTimelineLayer * layer)
|
||||
{
|
||||
|
@ -790,7 +523,147 @@ look_for_transition (GESTrackObject * track_object, GESTimelineLayer * layer)
|
|||
g_list_free (track_objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_resync_priorities:
|
||||
* @layer: a #GESTimelineLayer
|
||||
*
|
||||
* Resyncs the priorities of the objects controlled by @layer.
|
||||
* This method
|
||||
*/
|
||||
static gboolean
|
||||
ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
|
||||
{
|
||||
GList *tmp;
|
||||
GESTimelineObject *obj;
|
||||
|
||||
GST_DEBUG ("Resync priorities of %p", layer);
|
||||
|
||||
/* TODO : Inhibit composition updates while doing this.
|
||||
* Ideally we want to do it from an even higher level, but here will
|
||||
* do in the meantime. */
|
||||
|
||||
for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
|
||||
obj = GES_TIMELINE_OBJECT (tmp->data);
|
||||
ges_timeline_object_set_priority (obj, GES_TIMELINE_OBJECT_PRIORITY (obj));
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
|
||||
static void
|
||||
track_object_duration_cb (GESTrackObject * track_object,
|
||||
GParamSpec * arg G_GNUC_UNUSED)
|
||||
{
|
||||
GESTimelineLayer *layer;
|
||||
GESTimelineObject *tlobj;
|
||||
|
||||
tlobj = ges_track_object_get_timeline_object (track_object);
|
||||
layer = ges_timeline_object_get_layer (tlobj);
|
||||
if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
|
||||
calculate_next_transition (track_object, layer);
|
||||
}
|
||||
|
||||
static void
|
||||
track_object_removed_cb (GESTrack * track, GESTrackObject * track_object)
|
||||
{
|
||||
GList *track_objects, *tmp, *cur;
|
||||
GESTimelineLayer *layer;
|
||||
|
||||
track_objects = ges_track_get_objects (track);
|
||||
cur = g_list_find (track_objects, track_object);
|
||||
for (tmp = cur->next; tmp; tmp = tmp->next) {
|
||||
if (GES_IS_TRACK_SOURCE (tmp->data)) {
|
||||
break;
|
||||
}
|
||||
if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
|
||||
|| GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
|
||||
layer =
|
||||
ges_timeline_object_get_layer (ges_track_object_get_timeline_object
|
||||
(tmp->data));
|
||||
if (ges_timeline_layer_get_auto_transition (layer)) {
|
||||
ges_track_enable_update (track, FALSE);
|
||||
ges_timeline_layer_remove_object (layer,
|
||||
ges_track_object_get_timeline_object (tmp->data));
|
||||
ges_track_enable_update (track, TRUE);
|
||||
}
|
||||
g_object_unref (layer);
|
||||
}
|
||||
}
|
||||
|
||||
for (tmp = cur->prev; tmp; tmp = tmp->prev) {
|
||||
if (GES_IS_TRACK_SOURCE (tmp->data)) {
|
||||
break;
|
||||
}
|
||||
if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
|
||||
|| GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
|
||||
layer =
|
||||
ges_timeline_object_get_layer (ges_track_object_get_timeline_object
|
||||
(tmp->data));
|
||||
if (ges_timeline_layer_get_auto_transition (layer)) {
|
||||
ges_track_enable_update (track, FALSE);
|
||||
ges_timeline_layer_remove_object (layer,
|
||||
ges_track_object_get_timeline_object (tmp->data));
|
||||
ges_track_enable_update (track, TRUE);
|
||||
}
|
||||
g_object_unref (layer);
|
||||
}
|
||||
}
|
||||
g_object_unref (track_object);
|
||||
}
|
||||
|
||||
static void
|
||||
track_object_changed_cb (GESTrackObject * track_object,
|
||||
GParamSpec * arg G_GNUC_UNUSED)
|
||||
{
|
||||
if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
|
||||
calculate_transitions (track_object);
|
||||
}
|
||||
|
||||
static void
|
||||
track_object_added_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
GST_ERROR ("TRACKOBJECTADDED %i", GES_IS_TRACK_SOURCE (track_object));
|
||||
if (GES_IS_TRACK_SOURCE (track_object)) {
|
||||
g_signal_connect (G_OBJECT (track_object), "notify::start",
|
||||
G_CALLBACK (track_object_changed_cb), NULL);
|
||||
g_signal_connect (G_OBJECT (track_object), "notify::duration",
|
||||
G_CALLBACK (track_object_duration_cb), NULL);
|
||||
calculate_transitions (track_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
track_removed_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (track, track_object_added_cb, layer);
|
||||
g_signal_handlers_disconnect_by_func (track, track_object_removed_cb, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
track_added_cb (GESTrack * track, GESTrackObject * track_object,
|
||||
GESTimelineLayer * layer)
|
||||
{
|
||||
g_signal_connect (track, "track-object-removed",
|
||||
(GCallback) track_object_removed_cb, NULL);
|
||||
g_signal_connect (track, "track-object-added",
|
||||
(GCallback) track_object_added_cb, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
timeline_object_height_changed_cb (GESTimelineObject * obj,
|
||||
GESTrackEffect * tr_eff, GESTimelineObject * second_obj)
|
||||
{
|
||||
gint priority, height;
|
||||
g_object_get (obj, "height", &height, "priority", &priority, NULL);
|
||||
g_object_set (second_obj, "priority", priority + height, NULL);
|
||||
}
|
||||
|
||||
/* Public methods */
|
||||
/**
|
||||
* ges_timeline_layer_remove_object:
|
||||
* @layer: a #GESTimelineLayer
|
||||
|
@ -852,33 +725,6 @@ ges_timeline_layer_remove_object (GESTimelineLayer * layer,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_resync_priorities:
|
||||
* @layer: a #GESTimelineLayer
|
||||
*
|
||||
* Resyncs the priorities of the objects controlled by @layer.
|
||||
* This method
|
||||
*/
|
||||
gboolean
|
||||
ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
|
||||
{
|
||||
GList *tmp;
|
||||
GESTimelineObject *obj;
|
||||
|
||||
GST_DEBUG ("Resync priorities of %p", layer);
|
||||
|
||||
/* TODO : Inhibit composition updates while doing this.
|
||||
* Ideally we want to do it from an even higher level, but here will
|
||||
* do in the meantime. */
|
||||
|
||||
for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
|
||||
obj = GES_TIMELINE_OBJECT (tmp->data);
|
||||
ges_timeline_object_set_priority (obj, GES_TIMELINE_OBJECT_PRIORITY (obj));
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_set_priority:
|
||||
* @layer: a #GESTimelineLayer
|
||||
|
@ -1018,3 +864,137 @@ ges_timeline_layer_is_empty (GESTimelineLayer * layer)
|
|||
|
||||
return (layer->priv->objects_start == NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_add_object:
|
||||
* @layer: a #GESTimelineLayer
|
||||
* @object: (transfer full): the #GESTimelineObject to add.
|
||||
*
|
||||
* Adds the given object to the layer. Sets the object's parent, and thus
|
||||
* takes ownership of the object.
|
||||
*
|
||||
* An object can only be added to one layer.
|
||||
*
|
||||
* Calling this method will construct and properly set all the media related
|
||||
* elements on @object. If you need to know when those objects (actually #GESTrackObject)
|
||||
* are constructed, you should connect to the object::track-object-added signal which
|
||||
* is emited right after those elements are ready to be used.
|
||||
*
|
||||
* Returns: TRUE if the object was properly added to the layer, or FALSE
|
||||
* if the @layer refuses to add the object.
|
||||
*/
|
||||
gboolean
|
||||
ges_timeline_layer_add_object (GESTimelineLayer * layer,
|
||||
GESTimelineObject * object)
|
||||
{
|
||||
GESTimelineLayer *tl_obj_layer;
|
||||
guint32 maxprio, minprio, prio;
|
||||
|
||||
GST_DEBUG ("layer:%p, object:%p", layer, object);
|
||||
|
||||
tl_obj_layer = ges_timeline_object_get_layer (object);
|
||||
|
||||
if (G_UNLIKELY (tl_obj_layer)) {
|
||||
GST_WARNING ("TimelineObject %p already belongs to another layer", object);
|
||||
g_object_unref (tl_obj_layer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_object_ref_sink (object);
|
||||
|
||||
/* Take a reference to the object and store it stored by start/priority */
|
||||
layer->priv->objects_start =
|
||||
g_list_insert_sorted (layer->priv->objects_start, object,
|
||||
(GCompareFunc) objects_start_compare);
|
||||
|
||||
/* Inform the object it's now in this layer */
|
||||
ges_timeline_object_set_layer (object, layer);
|
||||
|
||||
GST_DEBUG ("current object priority : %d, layer min/max : %d/%d",
|
||||
GES_TIMELINE_OBJECT_PRIORITY (object),
|
||||
layer->min_gnl_priority, layer->max_gnl_priority);
|
||||
|
||||
/* Set the priority. */
|
||||
maxprio = layer->max_gnl_priority;
|
||||
minprio = layer->min_gnl_priority;
|
||||
prio = GES_TIMELINE_OBJECT_PRIORITY (object);
|
||||
if (minprio + prio > (maxprio)) {
|
||||
GST_WARNING ("%p is out of the layer %p space, setting its priority to "
|
||||
"setting its priority %d to failthe maximum priority of the layer %d",
|
||||
object, layer, prio, maxprio - minprio);
|
||||
ges_timeline_object_set_priority (object, LAYER_HEIGHT - 1);
|
||||
}
|
||||
/* If the object has an acceptable priority, we just let it with its current
|
||||
* priority */
|
||||
|
||||
ges_timeline_layer_resync_priorities (layer);
|
||||
|
||||
/* emit 'object-added' */
|
||||
g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_new:
|
||||
*
|
||||
* Creates a new #GESTimelineLayer.
|
||||
*
|
||||
* Returns: A new #GESTimelineLayer
|
||||
*/
|
||||
GESTimelineLayer *
|
||||
ges_timeline_layer_new (void)
|
||||
{
|
||||
return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* ges_timeline_layer_get_timeline:
|
||||
* @layer: The #GESTimelineLayer to get the parent #GESTimeline from
|
||||
*
|
||||
* Get the #GESTimeline in which #GESTimelineLayer currently is.
|
||||
*
|
||||
* Returns: (transfer none): the #GESTimeline in which #GESTimelineLayer
|
||||
* currently is or %NULL if not in any timeline yet.
|
||||
*/
|
||||
GESTimeline *
|
||||
ges_timeline_layer_get_timeline (GESTimelineLayer * layer)
|
||||
{
|
||||
g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
|
||||
|
||||
return layer->timeline;
|
||||
}
|
||||
|
||||
void
|
||||
ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
|
||||
GESTimeline * timeline)
|
||||
{
|
||||
GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
|
||||
|
||||
if (layer->priv->auto_transition == TRUE) {
|
||||
if (layer->timeline != NULL) {
|
||||
g_signal_handlers_disconnect_by_func (layer->timeline, track_added_cb,
|
||||
layer);
|
||||
g_signal_handlers_disconnect_by_func (layer->timeline, track_removed_cb,
|
||||
layer);
|
||||
}
|
||||
|
||||
if (timeline != NULL) {
|
||||
GList *tmp, *tracks = ges_timeline_get_tracks (timeline);
|
||||
|
||||
g_signal_connect (timeline, "track-added", G_CALLBACK (track_added_cb),
|
||||
layer);
|
||||
g_signal_connect (timeline, "track-removed",
|
||||
G_CALLBACK (track_removed_cb), layer);
|
||||
|
||||
for (tmp = tracks; tmp; tmp = tmp->next) {
|
||||
g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
|
||||
G_CALLBACK (track_object_added_cb), layer);
|
||||
g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
|
||||
G_CALLBACK (track_object_removed_cb), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layer->timeline = timeline;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue