1 /* GStreamer Editing Services
2 * Copyright (C) 2011 Thibault Saunier <thibault.saunier@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.
21 * SECTION: geseffectclip
22 * @title: GESEffectClip
23 * @short_description: An effect created by parse-launch style bin descriptions
26 * The effect will be applied on the sources that have lower priorities
27 * (higher number) between the inpoint and the end of it.
29 * The asset ID of an effect clip is in the form:
32 * "audio ! bin ! description || video ! bin ! description"
40 #include "ges-internal.h"
41 #include "ges-types.h"
43 struct _GESEffectClipPrivate
45 gchar *video_bin_description;
46 gchar *audio_bin_description;
49 static void ges_extractable_interface_init (GESExtractableInterface * iface);
50 G_DEFINE_TYPE_WITH_CODE (GESEffectClip, ges_effect_clip,
51 GES_TYPE_BASE_EFFECT_CLIP, G_ADD_PRIVATE (GESEffectClip)
52 G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
53 ges_extractable_interface_init));
58 PROP_VIDEO_BIN_DESCRIPTION,
59 PROP_AUDIO_BIN_DESCRIPTION,
62 static void ges_effect_clip_finalize (GObject * object);
63 static GESTrackElement *_create_track_element (GESClip * self,
66 G_GNUC_BEGIN_IGNORE_DEPRECATIONS; /* Start ignoring GParameter deprecation */
68 extractable_get_parameters_from_id (const gchar * id, guint * n_params)
72 GParameter *params = g_new0 (GParameter, 2);
73 gchar **effects_desc = g_strsplit (id, "||", -1);
78 if (g_strv_length (effects_desc) > 2)
79 GST_ERROR ("EffectClip id %s contains too many effect descriptions", id);
81 for (i = 0; effects_desc[i] && i < 2; i++) {
83 ges_effect_asset_id_get_type_and_bindesc (effects_desc[i], &ttype,
86 if (ttype == GES_TRACK_TYPE_AUDIO) {
87 *n_params = *n_params + 1;
88 params[*n_params - 1].name = "audio-bin-description";
89 } else if (ttype == GES_TRACK_TYPE_VIDEO) {
90 *n_params = *n_params + 1;
91 params[i].name = "video-bin-description";
94 GST_ERROR ("Could not find effect type for %s", effects_desc[i]);
98 g_value_init (¶ms[*n_params - 1].value, G_TYPE_STRING);
99 g_value_set_string (¶ms[*n_params - 1].value, bin_desc);
103 g_strfreev (effects_desc);
107 G_GNUC_END_IGNORE_DEPRECATIONS; /* End ignoring GParameter deprecation */
110 extractable_check_id (GType type, const gchar * id, GError ** error)
112 return g_strdup (id);
116 extractable_get_id (GESExtractable * self)
118 GString *id = g_string_new (NULL);
119 GESEffectClipPrivate *priv = GES_EFFECT_CLIP (self)->priv;
121 if (priv->audio_bin_description)
122 g_string_append_printf (id, "audio %s ||", priv->audio_bin_description);
123 if (priv->video_bin_description)
124 g_string_append_printf (id, "video %s", priv->video_bin_description);
126 return g_string_free (id, FALSE);
130 ges_extractable_interface_init (GESExtractableInterface * iface)
132 iface->asset_type = GES_TYPE_ASSET;
133 iface->check_id = extractable_check_id;
134 iface->get_parameters_from_id = extractable_get_parameters_from_id;
135 iface->get_id = extractable_get_id;
140 ges_effect_clip_finalize (GObject * object)
142 GESEffectClipPrivate *priv = GES_EFFECT_CLIP (object)->priv;
144 g_free (priv->audio_bin_description);
145 g_free (priv->video_bin_description);
147 G_OBJECT_CLASS (ges_effect_clip_parent_class)->finalize (object);
151 ges_effect_clip_get_property (GObject * object,
152 guint property_id, GValue * value, GParamSpec * pspec)
154 GESEffectClipPrivate *priv = GES_EFFECT_CLIP (object)->priv;
156 switch (property_id) {
157 case PROP_VIDEO_BIN_DESCRIPTION:
158 g_value_set_string (value, priv->video_bin_description);
160 case PROP_AUDIO_BIN_DESCRIPTION:
161 g_value_set_string (value, priv->audio_bin_description);
164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
169 ges_effect_clip_set_property (GObject * object,
170 guint property_id, const GValue * value, GParamSpec * pspec)
172 GESEffectClip *self = GES_EFFECT_CLIP (object);
174 switch (property_id) {
175 case PROP_VIDEO_BIN_DESCRIPTION:
176 self->priv->video_bin_description = g_value_dup_string (value);
178 case PROP_AUDIO_BIN_DESCRIPTION:
179 self->priv->audio_bin_description = g_value_dup_string (value);
182 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
187 ges_effect_clip_class_init (GESEffectClipClass * klass)
189 GObjectClass *object_class = G_OBJECT_CLASS (klass);
190 GESClipClass *timobj_class = GES_CLIP_CLASS (klass);
192 object_class->get_property = ges_effect_clip_get_property;
193 object_class->set_property = ges_effect_clip_set_property;
194 object_class->finalize = ges_effect_clip_finalize;
197 * GESEffectClip:video-bin-description:
199 * The description of the video track of the effect bin with a gst-launch-style
200 * pipeline description. This should be used for test purposes.
202 * Example: "videobalance saturation=1.5 hue=+0.5"
204 g_object_class_install_property (object_class, PROP_VIDEO_BIN_DESCRIPTION,
205 g_param_spec_string ("video-bin-description",
206 "Video bin description",
207 "Description of the video track of the effect",
208 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
211 * GESEffectClip:audio-bin-description:
213 * The description of the audio track of the effect bin with a gst-launch-style
214 * pipeline description. This should be used for test purposes.
216 * Example: "audiopanorama panorama=1.0"
218 g_object_class_install_property (object_class, PROP_AUDIO_BIN_DESCRIPTION,
219 g_param_spec_string ("audio-bin-description",
221 "Bin description of the audio track of the effect",
222 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
224 timobj_class->create_track_element = _create_track_element;
228 ges_effect_clip_init (GESEffectClip * self)
230 self->priv = ges_effect_clip_get_instance_private (self);
233 static GESTrackElement *
234 _create_track_element (GESClip * self, GESTrackType type)
236 const gchar *bin_description = NULL;
237 GESEffectClip *effect = GES_EFFECT_CLIP (self);
239 if (type == GES_TRACK_TYPE_VIDEO) {
240 bin_description = effect->priv->video_bin_description;
241 } else if (type == GES_TRACK_TYPE_AUDIO) {
242 bin_description = effect->priv->audio_bin_description;
246 return GES_TRACK_ELEMENT (ges_effect_new (bin_description));
248 GST_WARNING ("Effect doesn't handle this track type");
253 * ges_effect_clip_new:
254 * @video_bin_description: The gst-launch like bin description of the effect
255 * @audio_bin_description: The gst-launch like bin description of the effect
257 * Creates a new #GESEffectClip from the description of the bin.
259 * Returns: (transfer floating) (nullable): a newly created #GESEffectClip, or
260 * %NULL if something went wrong.
263 ges_effect_clip_new (const gchar * video_bin_description,
264 const gchar * audio_bin_description)
268 GString *id = g_string_new (NULL);
270 if (audio_bin_description)
271 g_string_append_printf (id, "audio %s ||", audio_bin_description);
272 if (video_bin_description)
273 g_string_append_printf (id, "video %s", video_bin_description);
275 asset = ges_asset_request (GES_TYPE_EFFECT_CLIP, id->str, NULL);
276 res = GES_EFFECT_CLIP (ges_asset_extract (asset, NULL));
277 g_string_free (id, TRUE);
278 gst_object_unref (asset);