1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Edward Hervey <edward.hervey@collabora.co.uk>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @title: GES utilities
23 * @short_description: Convenience methods
32 #include "ges-internal.h"
33 #include "ges-timeline.h"
34 #include "ges-track.h"
35 #include "ges-layer.h"
37 #include <gst/base/base.h>
39 static GstElementFactory *compositor_factory = NULL;
42 * ges_timeline_new_audio_video:
44 * Creates a new timeline containing a single #GESAudioTrack and a
45 * single #GESVideoTrack.
47 * Returns: (transfer floating): The new timeline, or %NULL if the tracks
48 * could not be created and added.
52 ges_timeline_new_audio_video (void)
54 GESTrack *tracka, *trackv;
55 GESTimeline *timeline;
57 /* This is our main GESTimeline */
58 timeline = ges_timeline_new ();
60 tracka = GES_TRACK (ges_audio_track_new ());
61 trackv = GES_TRACK (ges_video_track_new ());
63 if (!ges_timeline_add_track (timeline, trackv) ||
64 !ges_timeline_add_track (timeline, tracka)) {
65 gst_object_unref (timeline);
72 /* Internal utilities */
74 element_start_compare (GESTimelineElement * a, GESTimelineElement * b)
76 if (a->start == b->start) {
77 if (a->priority < b->priority)
79 if (a->priority > b->priority)
81 if (a->duration < b->duration)
83 if (a->duration > b->duration)
86 } else if (a->start < b->start)
93 element_end_compare (GESTimelineElement * a, GESTimelineElement * b)
95 if (GES_TIMELINE_ELEMENT_END (a) == GES_TIMELINE_ELEMENT_END (b)) {
96 if (a->priority < b->priority)
98 if (a->priority > b->priority)
100 if (a->duration < b->duration)
102 if (a->duration > b->duration)
105 } else if (GES_TIMELINE_ELEMENT_END (a) < (GES_TIMELINE_ELEMENT_END (b)))
112 ges_pspec_equal (gconstpointer key_spec_1, gconstpointer key_spec_2)
114 const GParamSpec *key1 = key_spec_1;
115 const GParamSpec *key2 = key_spec_2;
117 return (key1->owner_type == key2->owner_type &&
118 strcmp (key1->name, key2->name) == 0);
122 ges_pspec_hash (gconstpointer key_spec)
124 const GParamSpec *key = key_spec;
126 guint h = key->owner_type;
128 for (p = key->name; *p; p++)
129 h = (h << 5) - h + *p;
135 find_compositor (GstPluginFeatureFilter * feature, gpointer udata)
137 gboolean res = FALSE;
139 GstPluginFeature *loaded_feature = NULL;
141 if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature)))
144 klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY_CAST (feature),
145 GST_ELEMENT_METADATA_KLASS);
147 if (strstr (klass, "Compositor") == NULL)
150 loaded_feature = gst_plugin_feature_load (feature);
151 if (!loaded_feature) {
152 GST_ERROR ("Could not load feature: %" GST_PTR_FORMAT, feature);
157 g_type_is_a (gst_element_factory_get_element_type (GST_ELEMENT_FACTORY
158 (loaded_feature)), GST_TYPE_AGGREGATOR);
159 gst_object_unref (loaded_feature);
164 ges_util_structure_get_clocktime (GstStructure * structure, const gchar * name,
165 GstClockTime * val, GESFrameNumber * frames)
167 gboolean found = FALSE;
169 const GValue *gvalue;
174 gvalue = gst_structure_get_value (structure, name);
179 *frames = GES_FRAME_NUMBER_NONE;
182 if (val && G_VALUE_TYPE (gvalue) == GST_TYPE_CLOCK_TIME) {
183 *val = (GstClockTime) g_value_get_uint64 (gvalue);
184 } else if (val && G_VALUE_TYPE (gvalue) == G_TYPE_UINT64) {
185 *val = (GstClockTime) g_value_get_uint64 (gvalue);
186 } else if (val && G_VALUE_TYPE (gvalue) == G_TYPE_UINT) {
187 *val = (GstClockTime) g_value_get_uint (gvalue);
188 } else if (val && G_VALUE_TYPE (gvalue) == G_TYPE_INT) {
189 *val = (GstClockTime) g_value_get_int (gvalue);
190 } else if (val && G_VALUE_TYPE (gvalue) == G_TYPE_INT64) {
191 *val = (GstClockTime) g_value_get_int64 (gvalue);
192 } else if (val && G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE) {
193 gdouble d = g_value_get_double (gvalue);
196 *val = GST_CLOCK_TIME_NONE;
198 *val = d * GST_SECOND;
199 } else if (frames && G_VALUE_TYPE (gvalue) == G_TYPE_STRING) {
200 const gchar *str = g_value_get_string (gvalue);
203 if (str && str[0] == 'f') {
204 GValue v = G_VALUE_INIT;
206 g_value_init (&v, G_TYPE_UINT64);
207 if (gst_value_deserialize (&v, &str[1])) {
208 *frames = g_value_get_uint64 (&v);
210 *val = GST_CLOCK_TIME_NONE;
225 ges_get_compositor_factory (void)
229 if (compositor_factory)
230 return compositor_factory;
232 result = gst_registry_feature_filter (gst_registry_get (),
233 (GstPluginFeatureFilter) find_compositor, FALSE, NULL);
235 /* sort on rank and name */
236 result = g_list_sort (result, gst_plugin_feature_rank_compare_func);
239 compositor_factory = result->data;
240 gst_plugin_feature_list_free (result);
242 return compositor_factory;
246 ges_idle_add (GSourceFunc func, gpointer udata, GDestroyNotify notify)
248 GMainContext *context = g_main_context_get_thread_default ();
249 GSource *source = g_idle_source_new ();
251 context = g_main_context_default ();
253 g_source_set_callback (source, func, udata, notify);
254 g_source_attach (source, context);
259 ges_nle_composition_add_object (GstElement * comp, GstElement * object)
261 return gst_bin_add (GST_BIN (comp), object);
265 ges_nle_composition_remove_object (GstElement * comp, GstElement * object)
267 return gst_bin_remove (GST_BIN (comp), object);
271 ges_nle_object_commit (GstElement * nlesource, gboolean recurse)
275 g_signal_emit_by_name (nlesource, "commit", recurse, &ret);