container: Let subclasses handle the height
authorThibault Saunier <thibault.saunier@collabora.com>
Sun, 24 Mar 2013 17:42:55 +0000 (18:42 +0100)
committerThibault Saunier <thibault.saunier@collabora.com>
Thu, 28 Mar 2013 10:16:41 +0000 (11:16 +0100)
+ Fix tests (starting using GESTestClip instead of GESCustomClip)

Now the height is not only growing, but can also go down, as the value
is just simply computed

API:
GESContainer::compute_height virtual method

ges/ges-clip.c
ges/ges-container.c
ges/ges-container.h
tests/check/ges/simplelayer.c

index 61f6b1e..d4358d3 100644 (file)
@@ -90,6 +90,28 @@ static GParamSpec *properties[PROP_LAST];
  *                                                  *
  ****************************************************/
 
+static guint32
+_compute_height (GESContainer * container)
+{
+  GList *tmp;
+  guint32 min_prio = G_MAXUINT32, max_prio = 0;
+
+  if (container->children == NULL)
+    return 0;
+
+  /* Go over all childs and check if height has changed */
+  for (tmp = container->children; tmp; tmp = tmp->next) {
+    guint tck_priority = _PRIORITY (tmp->data);
+
+    if (tck_priority < min_prio)
+      min_prio = tck_priority;
+    if (tck_priority > max_prio)
+      max_prio = tck_priority;
+  }
+
+  return max_prio - min_prio + 1;
+}
+
 static void
 _get_priorty_range (GESContainer * container, guint32 * min_priority,
     guint32 * max_priority)
@@ -469,6 +491,7 @@ ges_clip_class_init (GESClipClass * klass)
   /* TODO implement the deep_copy Virtual method */
 
   container_class->get_priorty_range = _get_priorty_range;
+  container_class->compute_height = _compute_height;
   container_class->add_child = _add_child;
   container_class->remove_child = _remove_child;
   container_class->ungroup = _ungroup;
index 80b79b7..0cd674a 100644 (file)
@@ -92,36 +92,20 @@ enum
 static GParamSpec *properties[PROP_LAST];
 
 /************************
- *                      *
  *   Private  methods   *
- *                      *
  ************************/
 static void
 update_height (GESContainer * container)
 {
-  GList *tmp;
-  guint32 min_prio = G_MAXUINT32, max_prio = 0;
-
-  GST_FIXME_OBJECT (container, "No children, we should reset our height to 0");
-  if (container->children == NULL)
-    return;
+  guint32 height;
 
-  /* Go over all childs and check if height has changed */
-  for (tmp = container->children; tmp; tmp = tmp->next) {
-    guint tck_priority = _PRIORITY (tmp->data);
+  height = GES_CONTAINER_GET_CLASS (container)->compute_height (container);
 
-    if (tck_priority < min_prio)
-      min_prio = tck_priority;
-    if (tck_priority > max_prio)
-      max_prio = tck_priority;
-  }
-
-  if (container->height < (max_prio - min_prio + 1)) {
-    container->height = max_prio - min_prio + 1;
+  if (container->height != height) {
+    container->height = height;
     GST_DEBUG_OBJECT (container, "Updating height %i", container->height);
     g_object_notify (G_OBJECT (container), "height");
-  } else
-    GST_FIXME_OBJECT (container, "We only grow the height!");
+  }
 }
 
 static void
index 3953118..86ac355 100644 (file)
@@ -100,6 +100,7 @@ struct _GESContainer
  * @ungroup: Ungroups the #GESTimelineElement contained in this #GESContainer, creating new
  * @group: Groups the #GESContainers together
  * #GESContainer containing those #GESTimelineElement apropriately.
+ * @compute_height: Return the @height of the container
  */
 struct _GESContainerClass
 {
@@ -115,6 +116,7 @@ struct _GESContainerClass
   void (*get_priorty_range)       (GESContainer *container, guint32 *min_prio, guint32 *max_prio);
   GList* (*ungroup)               (GESContainer *container, gboolean recursive);
   GESContainer * (*group)         (GList *containers);
+  guint32 (*compute_height)       (GESContainer *container);
 
 
   /*< private >*/
index 6b7b5db..41edf24 100644 (file)
@@ -40,27 +40,6 @@ my_fill_track_func (GESClip * clip,
   return TRUE;
 }
 
-static gboolean
-arbitrary_fill_track_func (GESClip * clip,
-    GESTrackElement * track_element, GstElement * gnlobj, gpointer user_data)
-{
-  GstElement *src;
-
-  g_assert (user_data);
-
-  GST_DEBUG ("element:%s, timelineobj:%p, trackelements:%p, gnlobj:%p,",
-      (const gchar *) user_data, clip, track_element, gnlobj);
-
-  /* interpret user_data as name of element to create */
-  src = gst_element_factory_make (user_data, NULL);
-
-  /* If this fails... that means that there already was something
-   * in it */
-  fail_unless (gst_bin_add (GST_BIN (gnlobj), src));
-
-  return TRUE;
-}
-
 GST_START_TEST (test_gsl_add)
 {
   GESTimeline *timeline;
@@ -235,7 +214,7 @@ GST_START_TEST (test_gsl_with_transitions)
   GESTimeline *timeline;
   GESTimelineLayer *layer;
   GESTrack *track;
-  GESCustomSourceClip *source1, *source2, *source3, *source4;
+  GESTestClip *source1, *source2, *source3, *source4;
   GESTransitionClip *tr1, *tr2, *tr3, *tr4, *tr5;
   GESSimpleTimelineLayer *gstl;
   gboolean valid;
@@ -260,31 +239,23 @@ GST_START_TEST (test_gsl_with_transitions)
   fail_unless (ges_timeline_add_track (timeline, track));
 
 
-#define ELEMENT "videotestsrc"
-
   /* Create four 1s sources */
-  source1 = ges_custom_source_clip_new (arbitrary_fill_track_func,
-      (gpointer) ELEMENT);
+  source1 = ges_test_clip_new ();
   g_object_set (source1, "duration", GST_SECOND, "start", (guint64) 42, NULL);
   fail_unless_equals_uint64 (_DURATION (source1), GST_SECOND);
 
   /* make this source taller than the others, so we can check that
    * gstlrecalculate handles this properly */
 
-  source2 = ges_custom_source_clip_new (arbitrary_fill_track_func,
-      (gpointer) ELEMENT);
+  source2 = ges_test_clip_new ();
   g_object_set (source2, "duration", GST_SECOND, "start", (guint64) 42, NULL);
-  GES_CONTAINER_HEIGHT (source2) = 4;
 
   fail_unless_equals_uint64 (_DURATION (source2), GST_SECOND);
-
-  source3 = ges_custom_source_clip_new (arbitrary_fill_track_func,
-      (gpointer) ELEMENT);
+  source3 = ges_test_clip_new ();
   g_object_set (source3, "duration", GST_SECOND, "start", (guint64) 42, NULL);
   fail_unless_equals_uint64 (_DURATION (source3), GST_SECOND);
 
-  source4 = ges_custom_source_clip_new (arbitrary_fill_track_func,
-      (gpointer) ELEMENT);
+  source4 = ges_test_clip_new ();
   g_object_set (source4, "duration", GST_SECOND, "start", (guint64) 42, NULL);
   fail_unless_equals_uint64 (_DURATION (source4), GST_SECOND);
 
@@ -319,11 +290,8 @@ GST_START_TEST (test_gsl_with_transitions)
   /* 1        [1-tr1--]                                   */
   /* 2 [0--source1----][3-tr2--]                          */
   /* 3        [2---source2-----]                          */
-  /* 4        [2---source2-----]                          */
-  /* 5        [2---source2-----]                          */
-  /* 6        [2---source2-----]                          */
-  /* 7                 [4---source3---]                   */
-  /* 8                                [5---source4-----]  */
+  /* 4                 [4---source3---]                   */
+  /* 5                                [5---source4-----]  */
 
 
   gstl = GES_SIMPLE_TIMELINE_LAYER (layer);
@@ -376,7 +344,7 @@ GST_START_TEST (test_gsl_with_transitions)
   fail_unless_equals_uint64 (_PRIORITY (source2), 3);
   fail_unless_equals_uint64 (_DURATION (source3), GST_SECOND);
   fail_unless_equals_uint64 (_START (source3), SECOND (1.5));
-  fail_unless_equals_uint64 (_PRIORITY (source3), 7);
+  fail_unless_equals_uint64 (_PRIORITY (source3), 4);
 
   /* now add the second transition */
 
@@ -397,7 +365,7 @@ GST_START_TEST (test_gsl_with_transitions)
   fail_unless_equals_uint64 (_PRIORITY (tr2), 2);
   fail_unless_equals_uint64 (_DURATION (source3), GST_SECOND);
   fail_unless_equals_uint64 (_START (source3), GST_SECOND);
-  fail_unless_equals_uint64 (_PRIORITY (source3), 7);
+  fail_unless_equals_uint64 (_PRIORITY (source3), 4);
 
   /* fourth source */
 
@@ -419,10 +387,10 @@ GST_START_TEST (test_gsl_with_transitions)
   fail_unless_equals_uint64 (_PRIORITY (tr2), 2);
   fail_unless_equals_uint64 (_DURATION (source3), GST_SECOND);
   fail_unless_equals_uint64 (_START (source3), GST_SECOND);
-  fail_unless_equals_uint64 (_PRIORITY (source3), 7);
+  fail_unless_equals_uint64 (_PRIORITY (source3), 4);
   fail_unless_equals_uint64 (_DURATION (source4), GST_SECOND);
   fail_unless_equals_uint64 (_START (source4), SECOND (2));
-  fail_unless_equals_uint64 (_PRIORITY (source4), 8);
+  fail_unless_equals_uint64 (_PRIORITY (source4), 5);
 
   /* check that any insertion which might result in two adjacent transitions
    * will fail */