utilities: Make internal utilities instead of copy/pasting functions

This commit is contained in:
Thibault Saunier 2013-01-10 11:15:32 -03:00
parent 3e310e5960
commit af326df8bd
5 changed files with 57 additions and 70 deletions

View file

@ -208,4 +208,10 @@ G_GNUC_INTERNAL void set_property_foreach (GQuark field_id
G_GNUC_INTERNAL void _init_standard_transition_assets (void);
G_GNUC_INTERNAL void _init_formatter_assets (void);
/* Utilities */
G_GNUC_INTERNAL gint track_object_start_compare (GESTrackObject * a,
GESTrackObject * b);
G_GNUC_INTERNAL gint timeline_object_start_compare (GESTimelineObject * a,
GESTimelineObject * b);
#endif /* __GES_INTERNAL_H__ */

View file

@ -210,24 +210,6 @@ ges_timeline_layer_init (GESTimelineLayer * self)
self->max_gnl_priority = LAYER_HEIGHT;
}
/* Private methods and utils */
static gint
objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
{
if (a->start == b->start) {
if (a->priority < b->priority)
return -1;
if (a->priority > b->priority)
return 1;
return 0;
}
if (a->start < b->start)
return -1;
if (a->start > b->start)
return 1;
return 0;
}
static GList *
track_get_by_layer (GESTimelineLayer * layer, GESTrack * track)
{
@ -895,8 +877,6 @@ ges_timeline_layer_get_priority (GESTimelineLayer * layer)
GList *
ges_timeline_layer_get_objects (GESTimelineLayer * layer)
{
GList *ret = NULL;
GList *tmp;
GESTimelineLayerClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
@ -907,13 +887,9 @@ ges_timeline_layer_get_objects (GESTimelineLayer * layer)
return klass->get_objects (layer);
}
for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
ret = g_list_prepend (ret, tmp->data);
g_object_ref (tmp->data);
}
ret = g_list_reverse (ret);
return ret;
return g_list_sort (g_list_copy_deep (layer->priv->objects_start,
(GCopyFunc) gst_object_ref, NULL),
(GCompareFunc) timeline_object_start_compare);
}
/**
@ -1010,7 +986,7 @@ ges_timeline_layer_add_object (GESTimelineLayer * layer,
/* Take a reference to the object and store it stored by start/priority */
priv->objects_start = g_list_insert_sorted (priv->objects_start, object,
(GCompareFunc) objects_start_compare);
(GCompareFunc) timeline_object_start_compare);
/* Inform the object it's now in this layer */
ges_timeline_object_set_layer (object, layer);

View file

@ -572,30 +572,13 @@ timeline_update_duration (GESTimeline * timeline)
}
}
static gint
objects_start_compare (GESTrackObject * a, GESTrackObject * b)
{
if (a->start == b->start) {
if (a->priority < b->priority)
return -1;
if (a->priority > b->priority)
return 1;
return 0;
}
if (a->start < b->start)
return -1;
if (a->start > b->start)
return 1;
return 0;
}
static inline void
sort_track_objects (GESTimeline * timeline, GESTrackObject * obj)
{
TrackObjIters *iters = g_hash_table_lookup (timeline->priv->obj_iters, obj);
g_sequence_sort_changed (iters->iter_obj,
(GCompareDataFunc) objects_start_compare, NULL);
(GCompareDataFunc) track_object_start_compare, NULL);
}
static gint
@ -709,7 +692,7 @@ start_tracking_track_obj (GESTimeline * timeline, GESTrackObject * tckobj)
(GCompareDataFunc) compare_uint64, NULL);
iters->iter_obj =
g_sequence_insert_sorted (priv->tracksources, g_object_ref (tckobj),
(GCompareDataFunc) objects_start_compare, NULL);
(GCompareDataFunc) track_object_start_compare, NULL);
g_hash_table_insert (priv->by_start, tckobj, pstart);
g_hash_table_insert (priv->by_object, pstart, tckobj);

View file

@ -92,27 +92,6 @@ static void composition_duration_cb (GstElement * composition, GParamSpec * arg
G_GNUC_UNUSED, GESTrack * obj);
/* Private methods/functions/callbacks */
/* Utilities */
static gint
objects_start_compare (GESTrackObject * a, GESTrackObject * b,
gpointer user_data)
{
if (a->start == b->start) {
if (a->priority < b->priority)
return -1;
if (a->priority > b->priority)
return 1;
return 0;
}
if (a->start < b->start)
return -1;
if (a->start > b->start)
return 1;
return 0;
}
static void
add_trackobj_to_list_foreach (GESTrackObject * trackobj, GList ** list)
{
@ -248,7 +227,7 @@ static inline void
resort_and_fill_gaps (GESTrack * track)
{
g_sequence_sort (track->priv->tckobjs_by_start,
(GCompareDataFunc) objects_start_compare, NULL);
(GCompareDataFunc) track_object_start_compare, NULL);
if (track->priv->updating == TRUE) {
update_gaps (track);
@ -770,7 +749,7 @@ ges_track_add_object (GESTrack * track, GESTrackObject * object)
g_object_ref_sink (object);
g_hash_table_insert (track->priv->tckobjs_iter, object,
g_sequence_insert_sorted (track->priv->tckobjs_by_start, object,
(GCompareDataFunc) objects_start_compare, NULL));
(GCompareDataFunc) track_object_start_compare, NULL));
g_signal_emit (track, ges_track_signals[TRACK_OBJECT_ADDED], 0,
GES_TRACK_OBJECT (object));

View file

@ -58,3 +58,46 @@ ges_timeline_new_audio_video (void)
return timeline;
}
/* Internal utilities */
gint
track_object_start_compare (GESTrackObject * a, GESTrackObject * b)
{
if (a->start == b->start) {
if (a->priority < b->priority)
return -1;
if (a->priority > b->priority)
return 1;
if (a->duration < b->duration)
return -1;
if (a->duration > b->duration)
return 1;
return 0;
}
if (a->start < b->start)
return -1;
if (a->start > b->start)
return 1;
return 0;
}
gint
timeline_object_start_compare (GESTimelineObject * a, GESTimelineObject * b)
{
if (a->start == b->start) {
if (a->priority < b->priority)
return -1;
if (a->priority > b->priority)
return 1;
if (a->duration < b->duration)
return -1;
if (a->duration > b->duration)
return 1;
return 0;
}
if (a->start < b->start)
return -1;
if (a->start > b->start)
return 1;
return 0;
}