1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
3 * 2010 Nokia Corporation
4 * Copyright (C) 2020 Igalia S.L
5 * Author: 2020 Thibault Saunier <tsaunier@igalia.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * SECTION:gesvideotestsource
25 * @title: GESVideoTestSource
26 * @short_description: produce solid colors and patterns, possibly with a time
33 #include "ges-internal.h"
34 #include "ges-track-element.h"
35 #include "ges-video-test-source.h"
37 #define DEFAULT_VPATTERN GES_VIDEO_TEST_PATTERN_SMPTE
39 struct _GESVideoTestSourcePrivate
41 GESVideoTestPattern pattern;
43 GstElement *capsfilter;
47 ges_extractable_interface_init (GESExtractableInterface * iface)
49 iface->check_id = ges_test_source_asset_check_id;
50 iface->asset_type = GES_TYPE_TRACK_ELEMENT_ASSET;
54 ges_video_test_source_asset_get_config (GESAsset * asset)
56 const gchar *id = ges_asset_get_id (asset);
57 if (g_strcmp0 (id, g_type_name (ges_asset_get_extractable_type (asset))))
58 return gst_structure_from_string (ges_asset_get_id (asset), NULL);
63 G_DEFINE_TYPE_WITH_CODE (GESVideoTestSource, ges_video_test_source,
64 GES_TYPE_VIDEO_SOURCE, G_ADD_PRIVATE (GESVideoTestSource)
65 G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
66 ges_extractable_interface_init));
68 static GstElement *ges_video_test_source_create_source (GESSource * source);
71 get_natural_size (GESVideoSource * source, gint * width, gint * height)
74 GESTimelineElement *parent = GES_TIMELINE_ELEMENT_PARENT (source);
77 GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (parent));
80 res = ges_test_clip_asset_get_natural_size (asset, width, height);
84 *width = DEFAULT_WIDTH;
85 *height = DEFAULT_HEIGHT;
92 _set_parent (GESTimelineElement * element, GESTimelineElement * parent)
94 gint width, height, fps_n, fps_d;
96 GESVideoTestSource *self = GES_VIDEO_TEST_SOURCE (element);
102 g_assert (self->priv->capsfilter);
103 /* Setting the parent ourself as we need it to get the natural size */
104 element->parent = parent;
105 if (!ges_video_source_get_natural_size (GES_VIDEO_SOURCE (self), &width,
107 width = DEFAULT_WIDTH;
108 height = DEFAULT_HEIGHT;
111 if (!ges_timeline_element_get_natural_framerate (parent, &fps_n, &fps_d)) {
112 fps_n = DEFAULT_FRAMERATE_N;
113 fps_d = DEFAULT_FRAMERATE_D;
116 caps = gst_caps_new_simple ("video/x-raw",
117 "width", G_TYPE_INT, width,
118 "height", G_TYPE_INT, height,
119 "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL);
120 g_object_set (self->priv->capsfilter, "caps", caps, NULL);
121 gst_caps_unref (caps);
125 GES_TIMELINE_ELEMENT_CLASS
126 (ges_video_test_source_parent_class)->set_parent (element, parent);
130 _get_natural_framerate (GESTimelineElement * element, gint * fps_n,
133 gboolean res = FALSE;
134 GESTimelineElement *parent = GES_TIMELINE_ELEMENT_PARENT (element);
137 GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (parent));
141 ges_clip_asset_get_natural_framerate (GES_CLIP_ASSET (asset), fps_n,
147 *fps_n = DEFAULT_FRAMERATE_N;
148 *fps_d = DEFAULT_FRAMERATE_D;
155 dispose (GObject * object)
157 G_OBJECT_CLASS (ges_video_test_source_parent_class)->dispose (object);
161 ges_video_test_source_class_init (GESVideoTestSourceClass * klass)
163 GObjectClass *object_class = G_OBJECT_CLASS (klass);
164 GESVideoSourceClass *vsource_class = GES_VIDEO_SOURCE_CLASS (klass);
165 GESSourceClass *source_class = GES_SOURCE_CLASS (klass);
167 source_class->create_source = ges_video_test_source_create_source;
168 vsource_class->ABI.abi.get_natural_size = get_natural_size;
170 object_class->dispose = dispose;
172 GES_TIMELINE_ELEMENT_CLASS (klass)->set_parent = _set_parent;
173 GES_TIMELINE_ELEMENT_CLASS (klass)->get_natural_framerate =
174 _get_natural_framerate;
178 ges_video_test_source_init (GESVideoTestSource * self)
180 self->priv = ges_video_test_source_get_instance_private (self);
182 self->priv->pattern = DEFAULT_VPATTERN;
185 static GstStructure *
186 ges_video_test_source_get_config (GESVideoTestSource * self)
188 GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (self));
190 return ges_video_test_source_asset_get_config (asset);
196 ges_video_test_source_create_overlay (GESVideoTestSource * self)
198 const gchar *bindesc = NULL;
199 GstStructure *config = ges_video_test_source_get_config (self);
204 if (gst_structure_has_name (config, "time-overlay")) {
205 gboolean disable_timecodestamper;
207 if (gst_structure_get_boolean (config, "disable-timecodestamper",
208 &disable_timecodestamper))
209 bindesc = "timeoverlay";
211 bindesc = "timecodestamper ! timeoverlay";
213 gst_structure_free (config);
218 return gst_parse_bin_from_description (bindesc, TRUE, NULL);
222 ges_video_test_source_create_source (GESSource * source)
226 GstElement *testsrc, *res;
228 const gchar *props[] =
229 { "pattern", "background-color", "foreground-color", NULL };
231 GESVideoTestSource *self = GES_VIDEO_TEST_SOURCE (source);
232 GESTrackElement *element = GES_TRACK_ELEMENT (source);
234 g_assert (!GES_TIMELINE_ELEMENT_PARENT (source));
235 testsrc = gst_element_factory_make ("videotestsrc", NULL);
236 self->priv->capsfilter = gst_element_factory_make ("capsfilter", NULL);
237 pattern = self->priv->pattern;
239 g_object_set (testsrc, "pattern", pattern, NULL);
241 elements = g_ptr_array_new ();
242 g_ptr_array_add (elements, self->priv->capsfilter);
243 caps = gst_caps_new_simple ("video/x-raw",
244 "width", G_TYPE_INT, DEFAULT_WIDTH,
245 "height", G_TYPE_INT, DEFAULT_HEIGHT,
246 "framerate", GST_TYPE_FRACTION, DEFAULT_FRAMERATE_N, DEFAULT_FRAMERATE_D,
248 g_object_set (self->priv->capsfilter, "caps", caps, NULL);
249 gst_caps_unref (caps);
251 overlay = ges_video_test_source_create_overlay (self);
253 const gchar *overlay_props[] =
254 { "time-mode", "text-y", "text-x", "text-width", "test-height",
255 "halignment", "valignment", "font-desc", NULL
258 ges_track_element_add_children_props (element, overlay, NULL,
259 NULL, overlay_props);
260 g_ptr_array_add (elements, overlay);
263 ges_track_element_add_children_props (element, testsrc, NULL, NULL, props);
265 res = ges_source_create_topbin (GES_SOURCE (element), "videotestsrc", testsrc,
272 * ges_video_test_source_set_pattern:
273 * @self: a #GESVideoTestSource
274 * @pattern: a #GESVideoTestPattern
276 * Sets the source to use the given @pattern.
279 ges_video_test_source_set_pattern (GESVideoTestSource
280 * self, GESVideoTestPattern pattern)
282 GstElement *element =
283 ges_track_element_get_element (GES_TRACK_ELEMENT (self));
285 self->priv->pattern = pattern;
290 g_value_init (&val, GES_VIDEO_TEST_PATTERN_TYPE);
291 g_value_set_enum (&val, pattern);
292 ges_track_element_set_child_property (GES_TRACK_ELEMENT (self), "pattern",
298 * ges_video_test_source_get_pattern:
299 * @source: a #GESVideoTestPattern
301 * Get the video pattern used by the @source.
303 * Returns: The video pattern used by the @source.
306 ges_video_test_source_get_pattern (GESVideoTestSource * source)
310 ges_track_element_get_child_property (GES_TRACK_ELEMENT (source), "pattern",
312 return g_value_get_enum (&val);
316 * ges_video_test_source_new:
318 * Creates a new #GESVideoTestSource.
320 * Returns: (transfer floating) (nullable): The newly created
321 * #GESVideoTestSource, or %NULL if there was an error.
324 ges_video_test_source_new (void)
326 GESVideoTestSource *res;
327 GESAsset *asset = ges_asset_request (GES_TYPE_VIDEO_TEST_SOURCE, NULL, NULL);
329 res = GES_VIDEO_TEST_SOURCE (ges_asset_extract (asset, NULL));
330 gst_object_unref (asset);