test-source: Respect asset natural size
authorThibault Saunier <tsaunier@igalia.com>
Wed, 13 Jan 2021 18:18:04 +0000 (15:18 -0300)
committerThibault Saunier <tsaunier@igalia.com>
Tue, 9 Feb 2021 21:10:33 +0000 (18:10 -0300)
We had cases where the frame positioner had the default natural size for
video test sources instead of the user provided one.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/227>

ges/ges-video-source.c
ges/ges-video-test-source.c

index bd3e38d..a9e11ce 100644 (file)
@@ -89,6 +89,25 @@ _set_priority (GESTimelineElement * element, guint32 priority)
   return res;
 }
 
+
+static gboolean
+_set_parent (GESTimelineElement * element, GESTimelineElement * parent)
+{
+  GESVideoSource *self = GES_VIDEO_SOURCE (element);
+
+  if (!parent)
+    return TRUE;
+
+  /* Some subclass might have different access to its natural size only
+   * once it knows its parent */
+  ges_video_source_get_natural_size (GES_VIDEO_SOURCE (self),
+      &self->priv->positioner->natural_width,
+      &self->priv->positioner->natural_height);
+
+  return TRUE;
+}
+
+
 static gboolean
 ges_video_source_create_filters (GESVideoSource * self, GPtrArray * elements,
     gboolean needs_converters)
@@ -223,6 +242,7 @@ ges_video_source_class_init (GESVideoSourceClass * klass)
 
   element_class->set_priority = _set_priority;
   element_class->lookup_child = _lookup_child;
+  element_class->set_parent = _set_parent;
 
   track_element_class->nleobject_factorytype = "nlesource";
   track_element_class->create_element = ges_video_source_create_element;
index 2f8face..9df3746 100644 (file)
@@ -91,35 +91,39 @@ get_natural_size (GESVideoSource * source, gint * width, gint * height)
 static gboolean
 _set_parent (GESTimelineElement * element, GESTimelineElement * parent)
 {
+  gint width, height, fps_n, fps_d;
+  GstCaps *caps;
   GESVideoTestSource *self = GES_VIDEO_TEST_SOURCE (element);
 
 
-  if (parent) {
-    gint width, height, fps_n, fps_d;
-    GstCaps *caps;
-
-    g_assert (self->priv->capsfilter);
-    /* Setting the parent ourself as we need it to get the natural size */
-    element->parent = parent;
-    if (!ges_video_source_get_natural_size (GES_VIDEO_SOURCE (self), &width,
-            &height)) {
-      width = DEFAULT_WIDTH;
-      height = DEFAULT_HEIGHT;
-    }
-    if (!ges_timeline_element_get_natural_framerate (parent, &fps_n, &fps_d)) {
-      fps_n = DEFAULT_FRAMERATE_N;
-      fps_d = DEFAULT_FRAMERATE_D;
-    }
+  if (!parent)
+    goto done;
 
-    caps = gst_caps_new_simple ("video/x-raw",
-        "width", G_TYPE_INT, width,
-        "height", G_TYPE_INT, height,
-        "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL);
-    g_object_set (self->priv->capsfilter, "caps", caps, NULL);
-    gst_caps_unref (caps);
+  g_assert (self->priv->capsfilter);
+  /* Setting the parent ourself as we need it to get the natural size */
+  element->parent = parent;
+  if (!ges_video_source_get_natural_size (GES_VIDEO_SOURCE (self), &width,
+          &height)) {
+    width = DEFAULT_WIDTH;
+    height = DEFAULT_HEIGHT;
   }
 
-  return TRUE;
+  if (!ges_timeline_element_get_natural_framerate (parent, &fps_n, &fps_d)) {
+    fps_n = DEFAULT_FRAMERATE_N;
+    fps_d = DEFAULT_FRAMERATE_D;
+  }
+
+  caps = gst_caps_new_simple ("video/x-raw",
+      "width", G_TYPE_INT, width,
+      "height", G_TYPE_INT, height,
+      "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL);
+  g_object_set (self->priv->capsfilter, "caps", caps, NULL);
+  gst_caps_unref (caps);
+
+done:
+  return
+      GES_TIMELINE_ELEMENT_CLASS
+      (ges_video_test_source_parent_class)->set_parent (element, parent);
 }
 
 static gboolean