2011-02-10 11:17:50 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Thibault Saunier <thibault.saunier@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:25:20 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-02-10 11:17:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-07 19:02:48 +00:00
|
|
|
* SECTION:geseffect
|
2016-02-26 19:42:41 +00:00
|
|
|
* @short_description: adds an effect build from a parse-launch style
|
2014-02-26 03:17:36 +00:00
|
|
|
* bin description to a stream in a GESSourceClip or a GESLayer
|
2011-02-10 11:17:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ges-internal.h"
|
2012-11-20 02:42:47 +00:00
|
|
|
#include "ges-extractable.h"
|
2013-01-26 15:31:33 +00:00
|
|
|
#include "ges-track-element.h"
|
2013-01-26 15:35:19 +00:00
|
|
|
#include "ges-base-effect.h"
|
2013-03-14 15:14:31 +00:00
|
|
|
#include "ges-effect-asset.h"
|
2013-01-26 15:40:51 +00:00
|
|
|
#include "ges-effect.h"
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2012-11-20 02:42:47 +00:00
|
|
|
static void ges_extractable_interface_init (GESExtractableInterface * iface);
|
|
|
|
|
2013-01-26 15:40:51 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GESEffect,
|
|
|
|
ges_effect, GES_TYPE_BASE_EFFECT,
|
2012-11-20 02:42:47 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
|
|
|
|
ges_extractable_interface_init));
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2013-01-26 15:40:51 +00:00
|
|
|
static void ges_effect_dispose (GObject * object);
|
|
|
|
static void ges_effect_finalize (GObject * object);
|
|
|
|
static GstElement *ges_effect_create_element (GESTrackElement * self);
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2013-01-26 15:40:51 +00:00
|
|
|
struct _GESEffectPrivate
|
2011-02-10 11:17:50 +00:00
|
|
|
{
|
|
|
|
gchar *bin_description;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_BIN_DESCRIPTION,
|
|
|
|
};
|
|
|
|
|
2012-11-20 02:42:47 +00:00
|
|
|
static gchar *
|
|
|
|
extractable_check_id (GType type, const gchar * id, GError ** error)
|
|
|
|
{
|
2016-01-25 14:57:22 +00:00
|
|
|
gchar *bin_desc, *real_id;
|
|
|
|
GESTrackType ttype;
|
2012-11-20 02:42:47 +00:00
|
|
|
|
2016-01-25 14:57:22 +00:00
|
|
|
bin_desc = ges_effect_assect_id_get_type_and_bindesc (id, &ttype, error);
|
|
|
|
|
|
|
|
if (bin_desc == NULL)
|
2012-11-20 02:42:47 +00:00
|
|
|
return NULL;
|
|
|
|
|
2016-01-25 14:57:22 +00:00
|
|
|
if (ttype == GES_TRACK_TYPE_AUDIO)
|
|
|
|
real_id = g_strdup_printf ("audio %s", bin_desc);
|
|
|
|
else if (ttype == GES_TRACK_TYPE_VIDEO)
|
|
|
|
real_id = g_strdup_printf ("video %s", bin_desc);
|
|
|
|
else
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
return real_id;
|
2012-11-20 02:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GParameter *
|
|
|
|
extractable_get_parameters_from_id (const gchar * id, guint * n_params)
|
|
|
|
{
|
2016-01-25 14:57:22 +00:00
|
|
|
GParameter *params = g_new0 (GParameter, 3);
|
|
|
|
gchar *bin_desc;
|
|
|
|
GESTrackType ttype;
|
|
|
|
|
|
|
|
bin_desc = ges_effect_assect_id_get_type_and_bindesc (id, &ttype, NULL);
|
2012-11-20 02:42:47 +00:00
|
|
|
|
2012-12-29 20:52:42 +00:00
|
|
|
params[0].name = "bin-description";
|
2012-11-20 02:42:47 +00:00
|
|
|
g_value_init (¶ms[0].value, G_TYPE_STRING);
|
2016-01-25 14:57:22 +00:00
|
|
|
g_value_set_string (¶ms[0].value, bin_desc);
|
|
|
|
|
|
|
|
params[1].name = "track-type";
|
|
|
|
g_value_init (¶ms[1].value, GES_TYPE_TRACK_TYPE);
|
|
|
|
g_value_set_flags (¶ms[1].value, ttype);
|
2012-11-20 02:42:47 +00:00
|
|
|
|
2016-01-25 14:57:22 +00:00
|
|
|
*n_params = 2;
|
2012-11-20 02:42:47 +00:00
|
|
|
|
2016-01-25 14:57:22 +00:00
|
|
|
g_free (bin_desc);
|
2012-11-20 02:42:47 +00:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
extractable_get_id (GESExtractable * self)
|
|
|
|
{
|
2013-01-26 15:40:51 +00:00
|
|
|
return g_strdup (GES_EFFECT (self)->priv->bin_description);
|
2012-11-20 02:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_extractable_interface_init (GESExtractableInterface * iface)
|
|
|
|
{
|
2013-03-14 15:14:31 +00:00
|
|
|
iface->asset_type = GES_TYPE_EFFECT_ASSET;
|
2012-11-20 02:42:47 +00:00
|
|
|
iface->check_id = (GESExtractableCheckId) extractable_check_id;
|
|
|
|
iface->get_parameters_from_id = extractable_get_parameters_from_id;
|
|
|
|
iface->get_id = extractable_get_id;
|
|
|
|
}
|
|
|
|
|
2011-02-10 11:17:50 +00:00
|
|
|
static void
|
2013-01-26 15:40:51 +00:00
|
|
|
ges_effect_get_property (GObject * object,
|
2011-02-10 11:17:50 +00:00
|
|
|
guint property_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-01-26 15:40:51 +00:00
|
|
|
GESEffectPrivate *priv = GES_EFFECT (object)->priv;
|
2011-06-21 18:35:47 +00:00
|
|
|
|
2011-02-10 11:17:50 +00:00
|
|
|
switch (property_id) {
|
2011-06-21 18:35:47 +00:00
|
|
|
case PROP_BIN_DESCRIPTION:
|
|
|
|
g_value_set_string (value, priv->bin_description);
|
|
|
|
break;
|
2011-02-10 11:17:50 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 15:40:51 +00:00
|
|
|
ges_effect_set_property (GObject * object,
|
2011-02-10 11:17:50 +00:00
|
|
|
guint property_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-01-26 15:40:51 +00:00
|
|
|
GESEffect *self = GES_EFFECT (object);
|
2011-02-10 11:17:50 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_BIN_DESCRIPTION:
|
|
|
|
self->priv->bin_description = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 15:40:51 +00:00
|
|
|
ges_effect_class_init (GESEffectClass * klass)
|
2011-02-10 11:17:50 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
2013-01-26 15:31:33 +00:00
|
|
|
GESTrackElementClass *obj_bg_class;
|
2011-02-10 11:17:50 +00:00
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2013-01-26 15:31:33 +00:00
|
|
|
obj_bg_class = GES_TRACK_ELEMENT_CLASS (klass);
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2013-01-26 15:40:51 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GESEffectPrivate));
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2013-01-26 15:40:51 +00:00
|
|
|
object_class->get_property = ges_effect_get_property;
|
|
|
|
object_class->set_property = ges_effect_set_property;
|
|
|
|
object_class->dispose = ges_effect_dispose;
|
|
|
|
object_class->finalize = ges_effect_finalize;
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2013-01-26 15:40:51 +00:00
|
|
|
obj_bg_class->create_element = ges_effect_create_element;
|
2011-02-10 11:17:50 +00:00
|
|
|
|
Handle changing playback rate
Before this patch, NLE and GES did not support NleOperations (respectively
GESEffects) that changed the speed/tempo/rate at which the source plays. For
example, the 'pitch' element can make audio play faster or slower. In GES 1.5.90
and before, an NleOperation containing the pitch element to change the rate (or
tempo) would cause a pipeline state change to PAUSED after that stack; that has
been fixed in 1.5.91 (see #755012 [0]). But even then, in 1.5.91 and later,
NleComposition would send segment events to its NleSources assuming that one
source second is equal to one pipeline second. The resulting early EOS event
(in the case of a source rate higher than 1.0) would cause it to switch stacks
too early, causing confusion in the timeline and spectacularly messed up
output.
This patch fixes that by searching for rate-changing elements in
GESTrackElements such as GESEffects. If such rate-changing elements are found,
their final effect on the playing rate is stored in the corresponding NleObject
as the 'media duration factor', named like this because the 'media duration',
or source duration, of an NleObject can be computed by multiplying the duration
with the media duration factor of that object and its parents (this is called
the 'recursive media duration factor'). For example, a 4-second NleSource with
an NleOperation with a media duration factor of 2.0 will have an 8-second media
duration, which means that for playing 4 seconds in the pipeline, the seek
event sent to it must span 8 seconds of media. (So, the 'duration' of an
NleObject or GES object always refers to its duration in the timeline, not the
media duration.)
To summarize:
* Rate-changing elements are registered in the GESEffectClass (pitch::tempo and
pitch::rate are registered by default);
* GESTimelineElement is responsible for detecting rate-changing elements and
computing the media_duration_factor;
* GESTrackElement is responsible for storing the media_duration_factor in
NleObject;
* NleComposition is responsible for the recursive_media_duration_factor;
* The latter property finally fixes media time computations in NleObject.
NLE and GES tests are included.
[0] https://bugzilla.gnome.org/show_bug.cgi?id=755012
Differential Revision: https://phabricator.freedesktop.org/D276
2015-12-20 13:03:57 +00:00
|
|
|
klass->rate_properties = NULL;
|
2016-02-26 19:42:41 +00:00
|
|
|
ges_effect_class_register_rate_property (klass, "scaletempo", "rate");
|
Handle changing playback rate
Before this patch, NLE and GES did not support NleOperations (respectively
GESEffects) that changed the speed/tempo/rate at which the source plays. For
example, the 'pitch' element can make audio play faster or slower. In GES 1.5.90
and before, an NleOperation containing the pitch element to change the rate (or
tempo) would cause a pipeline state change to PAUSED after that stack; that has
been fixed in 1.5.91 (see #755012 [0]). But even then, in 1.5.91 and later,
NleComposition would send segment events to its NleSources assuming that one
source second is equal to one pipeline second. The resulting early EOS event
(in the case of a source rate higher than 1.0) would cause it to switch stacks
too early, causing confusion in the timeline and spectacularly messed up
output.
This patch fixes that by searching for rate-changing elements in
GESTrackElements such as GESEffects. If such rate-changing elements are found,
their final effect on the playing rate is stored in the corresponding NleObject
as the 'media duration factor', named like this because the 'media duration',
or source duration, of an NleObject can be computed by multiplying the duration
with the media duration factor of that object and its parents (this is called
the 'recursive media duration factor'). For example, a 4-second NleSource with
an NleOperation with a media duration factor of 2.0 will have an 8-second media
duration, which means that for playing 4 seconds in the pipeline, the seek
event sent to it must span 8 seconds of media. (So, the 'duration' of an
NleObject or GES object always refers to its duration in the timeline, not the
media duration.)
To summarize:
* Rate-changing elements are registered in the GESEffectClass (pitch::tempo and
pitch::rate are registered by default);
* GESTimelineElement is responsible for detecting rate-changing elements and
computing the media_duration_factor;
* GESTrackElement is responsible for storing the media_duration_factor in
NleObject;
* NleComposition is responsible for the recursive_media_duration_factor;
* The latter property finally fixes media time computations in NleObject.
NLE and GES tests are included.
[0] https://bugzilla.gnome.org/show_bug.cgi?id=755012
Differential Revision: https://phabricator.freedesktop.org/D276
2015-12-20 13:03:57 +00:00
|
|
|
ges_effect_class_register_rate_property (klass, "pitch", "tempo");
|
|
|
|
ges_effect_class_register_rate_property (klass, "pitch", "rate");
|
|
|
|
|
2011-02-10 11:17:50 +00:00
|
|
|
/**
|
2013-01-26 15:40:51 +00:00
|
|
|
* GESEffect:bin-description:
|
2011-02-10 11:17:50 +00:00
|
|
|
*
|
|
|
|
* The description of the effect bin with a gst-launch-style
|
|
|
|
* pipeline description.
|
2011-05-06 17:38:26 +00:00
|
|
|
*
|
|
|
|
* Example: "videobalance saturation=1.5 hue=+0.5"
|
2011-02-10 11:17:50 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_BIN_DESCRIPTION,
|
|
|
|
g_param_spec_string ("bin-description",
|
|
|
|
"bin description",
|
|
|
|
"Bin description of the effect",
|
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 15:40:51 +00:00
|
|
|
ges_effect_init (GESEffect * self)
|
2011-02-10 11:17:50 +00:00
|
|
|
{
|
|
|
|
self->priv =
|
2013-01-26 15:40:51 +00:00
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (self, GES_TYPE_EFFECT, GESEffectPrivate);
|
2011-02-10 11:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 15:40:51 +00:00
|
|
|
ges_effect_dispose (GObject * object)
|
2011-02-10 11:17:50 +00:00
|
|
|
{
|
2013-01-26 15:40:51 +00:00
|
|
|
G_OBJECT_CLASS (ges_effect_parent_class)->dispose (object);
|
2011-02-10 11:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 15:40:51 +00:00
|
|
|
ges_effect_finalize (GObject * object)
|
2011-02-10 11:17:50 +00:00
|
|
|
{
|
2013-01-26 15:40:51 +00:00
|
|
|
GESEffect *self = GES_EFFECT (object);
|
2011-02-10 11:17:50 +00:00
|
|
|
|
|
|
|
if (self->priv->bin_description)
|
|
|
|
g_free (self->priv->bin_description);
|
|
|
|
|
2013-01-26 15:40:51 +00:00
|
|
|
G_OBJECT_CLASS (ges_effect_parent_class)->finalize (object);
|
2011-02-10 11:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
2013-01-26 15:40:51 +00:00
|
|
|
ges_effect_create_element (GESTrackElement * object)
|
2011-02-10 11:17:50 +00:00
|
|
|
{
|
|
|
|
GstElement *effect;
|
2011-03-16 21:06:08 +00:00
|
|
|
gchar *bin_desc;
|
2011-02-10 11:17:50 +00:00
|
|
|
|
|
|
|
GError *error = NULL;
|
2013-01-26 15:40:51 +00:00
|
|
|
GESEffect *self = GES_EFFECT (object);
|
2013-08-27 03:31:14 +00:00
|
|
|
const gchar *wanted_categories[] = { "Effect", NULL };
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2016-01-25 14:57:22 +00:00
|
|
|
GESTrackType type = ges_track_element_get_track_type (object);
|
2011-03-16 21:06:08 +00:00
|
|
|
|
2016-01-25 14:57:22 +00:00
|
|
|
if (type == GES_TRACK_TYPE_VIDEO) {
|
2011-10-11 07:51:43 +00:00
|
|
|
bin_desc = g_strconcat ("videoconvert name=pre_video_convert ! ",
|
|
|
|
self->priv->bin_description, " ! videoconvert name=post_video_convert",
|
2011-05-07 11:41:11 +00:00
|
|
|
NULL);
|
2016-01-25 14:57:22 +00:00
|
|
|
} else if (type == GES_TRACK_TYPE_AUDIO) {
|
2011-05-06 17:39:26 +00:00
|
|
|
bin_desc =
|
|
|
|
g_strconcat ("audioconvert ! audioresample !",
|
|
|
|
self->priv->bin_description, NULL);
|
2011-03-16 21:06:08 +00:00
|
|
|
} else {
|
2016-01-25 14:57:22 +00:00
|
|
|
g_assert_not_reached ();
|
2011-03-16 21:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
effect = gst_parse_bin_from_description (bin_desc, TRUE, &error);
|
|
|
|
|
|
|
|
g_free (bin_desc);
|
2011-02-10 11:17:50 +00:00
|
|
|
|
|
|
|
if (error != NULL) {
|
2011-05-07 11:41:11 +00:00
|
|
|
GST_ERROR ("An error occured while creating the GstElement: %s",
|
2011-05-06 17:39:26 +00:00
|
|
|
error->message);
|
2011-03-16 21:06:08 +00:00
|
|
|
g_error_free (error);
|
2011-02-10 11:17:50 +00:00
|
|
|
return NULL;
|
2011-03-16 21:06:08 +00:00
|
|
|
}
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2011-05-06 17:38:26 +00:00
|
|
|
GST_DEBUG ("Created effect %p", effect);
|
2011-02-10 11:17:50 +00:00
|
|
|
|
2013-08-27 03:31:14 +00:00
|
|
|
ges_track_element_add_children_props (object, effect, wanted_categories,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2011-02-10 11:17:50 +00:00
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-26 15:40:51 +00:00
|
|
|
* ges_effect_new:
|
2011-05-06 17:38:26 +00:00
|
|
|
* @bin_description: The gst-launch like bin description of the effect
|
|
|
|
*
|
2016-01-25 14:57:22 +00:00
|
|
|
* Creates a new #GESEffect from the description of the bin. It should be
|
|
|
|
* possible to determine the type of the effect through the element
|
|
|
|
* 'klass' metadata of the GstElements that will be created.
|
|
|
|
* In that corner case, you should use:
|
|
|
|
* #ges_asset_request (GES_TYPE_EFFECT, "audio your ! bin ! description", NULL);
|
|
|
|
* and extract that asset to be in full control.
|
2011-05-06 17:38:26 +00:00
|
|
|
*
|
2013-01-26 15:40:51 +00:00
|
|
|
* Returns: a newly created #GESEffect, or %NULL if something went
|
2011-05-06 17:38:26 +00:00
|
|
|
* wrong.
|
|
|
|
*/
|
2013-01-26 15:40:51 +00:00
|
|
|
GESEffect *
|
|
|
|
ges_effect_new (const gchar * bin_description)
|
2011-02-10 11:17:50 +00:00
|
|
|
{
|
2013-03-14 15:14:31 +00:00
|
|
|
GESEffect *effect;
|
|
|
|
GESAsset *asset = ges_asset_request (GES_TYPE_EFFECT,
|
2011-02-10 11:17:50 +00:00
|
|
|
bin_description, NULL);
|
2013-03-14 15:14:31 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (asset, NULL);
|
|
|
|
|
|
|
|
effect = GES_EFFECT (ges_asset_extract (asset, NULL));
|
|
|
|
|
|
|
|
gst_object_unref (asset);
|
|
|
|
|
|
|
|
return effect;
|
2011-02-10 11:17:50 +00:00
|
|
|
}
|
Handle changing playback rate
Before this patch, NLE and GES did not support NleOperations (respectively
GESEffects) that changed the speed/tempo/rate at which the source plays. For
example, the 'pitch' element can make audio play faster or slower. In GES 1.5.90
and before, an NleOperation containing the pitch element to change the rate (or
tempo) would cause a pipeline state change to PAUSED after that stack; that has
been fixed in 1.5.91 (see #755012 [0]). But even then, in 1.5.91 and later,
NleComposition would send segment events to its NleSources assuming that one
source second is equal to one pipeline second. The resulting early EOS event
(in the case of a source rate higher than 1.0) would cause it to switch stacks
too early, causing confusion in the timeline and spectacularly messed up
output.
This patch fixes that by searching for rate-changing elements in
GESTrackElements such as GESEffects. If such rate-changing elements are found,
their final effect on the playing rate is stored in the corresponding NleObject
as the 'media duration factor', named like this because the 'media duration',
or source duration, of an NleObject can be computed by multiplying the duration
with the media duration factor of that object and its parents (this is called
the 'recursive media duration factor'). For example, a 4-second NleSource with
an NleOperation with a media duration factor of 2.0 will have an 8-second media
duration, which means that for playing 4 seconds in the pipeline, the seek
event sent to it must span 8 seconds of media. (So, the 'duration' of an
NleObject or GES object always refers to its duration in the timeline, not the
media duration.)
To summarize:
* Rate-changing elements are registered in the GESEffectClass (pitch::tempo and
pitch::rate are registered by default);
* GESTimelineElement is responsible for detecting rate-changing elements and
computing the media_duration_factor;
* GESTrackElement is responsible for storing the media_duration_factor in
NleObject;
* NleComposition is responsible for the recursive_media_duration_factor;
* The latter property finally fixes media time computations in NleObject.
NLE and GES tests are included.
[0] https://bugzilla.gnome.org/show_bug.cgi?id=755012
Differential Revision: https://phabricator.freedesktop.org/D276
2015-12-20 13:03:57 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
property_name_compare (gconstpointer s1, gconstpointer s2)
|
|
|
|
{
|
|
|
|
return g_strcmp0 ((const gchar *) s1, (const gchar *) s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_effect_class_register_rate_property:
|
|
|
|
* @klass: Instance of the GESEffectClass
|
|
|
|
* @element_name: Name of the GstElement that changes the rate
|
|
|
|
* @property_name: Name of the property that changes the rate
|
|
|
|
*
|
|
|
|
* Register an element that can change the rate at which media is playing. The
|
|
|
|
* property type must be float or double, and must be a factor of the rate,
|
|
|
|
* i.e. a value of 2.0 must mean that the media plays twice as fast. For
|
|
|
|
* example, this is true for the properties 'rate' and 'tempo' of the element
|
|
|
|
* 'pitch', which is already registered by default. By registering the element,
|
|
|
|
* timeline duration can be correctly converted into media duration, allowing
|
|
|
|
* the right segment seeks to be sent to the sources.
|
|
|
|
*
|
|
|
|
* A reference to the GESEffectClass can be obtained as follows:
|
|
|
|
* GES_EFFECT_CLASS (g_type_class_ref (GES_TYPE_EFFECT));
|
|
|
|
*
|
|
|
|
* Returns: whether the rate property was succesfully registered. When this
|
|
|
|
* method returns false, a warning is emitted with more information.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
ges_effect_class_register_rate_property (GESEffectClass * klass,
|
|
|
|
const gchar * element_name, const gchar * property_name)
|
|
|
|
{
|
|
|
|
GstElementFactory *element_factory = NULL;
|
|
|
|
GstElement *element = NULL;
|
|
|
|
GParamSpec *pspec = NULL;
|
|
|
|
gchar *full_property_name = NULL;
|
|
|
|
GType param_type;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
element_factory = gst_element_factory_find (element_name);
|
|
|
|
if (element_factory == NULL) {
|
|
|
|
GST_WARNING
|
|
|
|
("Did not add rate property '%s' for element '%s': the element factory could not be found",
|
|
|
|
property_name, element_name);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = gst_element_factory_create (element_factory, NULL);
|
|
|
|
if (element == NULL) {
|
|
|
|
GST_WARNING
|
|
|
|
("Did not add rate property '%s' for element '%s': the element could not be constructed",
|
|
|
|
property_name, element_name);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
pspec =
|
|
|
|
g_object_class_find_property (G_OBJECT_GET_CLASS (element),
|
|
|
|
property_name);
|
|
|
|
if (pspec == NULL) {
|
|
|
|
GST_WARNING
|
|
|
|
("Did not add rate property '%s' for element '%s': the element did not have the property name specified",
|
|
|
|
property_name, element_name);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
param_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
|
|
|
|
if (param_type != G_TYPE_FLOAT && param_type != G_TYPE_DOUBLE) {
|
|
|
|
GST_WARNING
|
|
|
|
("Did not add rate property '%s' for element '%s': the property is not of float or double type",
|
|
|
|
property_name, element_name);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
full_property_name = g_strdup_printf ("%s::%s",
|
|
|
|
g_type_name (gst_element_factory_get_element_type (element_factory)),
|
|
|
|
property_name);
|
|
|
|
|
|
|
|
if (g_list_find_custom (klass->rate_properties, full_property_name,
|
|
|
|
property_name_compare) == NULL) {
|
|
|
|
klass->rate_properties =
|
|
|
|
g_list_append (klass->rate_properties, full_property_name);
|
|
|
|
GST_DEBUG ("Added rate property %s", full_property_name);
|
|
|
|
} else {
|
|
|
|
g_free (full_property_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (element_factory != NULL)
|
|
|
|
gst_object_unref (element_factory);
|
|
|
|
if (element != NULL)
|
|
|
|
gst_object_unref (element);
|
|
|
|
if (pspec != NULL)
|
|
|
|
g_param_spec_unref (pspec);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|