2010-06-18 09:09:28 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
|
|
|
|
* 2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* 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.
|
2010-06-18 09:09:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-01-27 15:44:13 +00:00
|
|
|
* SECTION:ges-audio-transition
|
2010-07-01 14:48:45 +00:00
|
|
|
* @short_description: implements audio crossfade transition
|
2010-06-18 09:09:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ges-internal.h"
|
2013-01-26 15:31:33 +00:00
|
|
|
#include "ges-track-element.h"
|
2013-01-27 15:44:13 +00:00
|
|
|
#include "ges-audio-transition.h"
|
2010-06-18 09:09:28 +00:00
|
|
|
|
2012-02-10 19:01:03 +00:00
|
|
|
#include <gst/controller/gstdirectcontrolbinding.h>
|
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
G_DEFINE_TYPE (GESAudioTransition, ges_audio_transition, GES_TYPE_TRANSITION);
|
2010-06-18 09:09:28 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
struct _GESAudioTransitionPrivate
|
2010-12-04 18:54:13 +00:00
|
|
|
{
|
2011-01-06 15:35:20 +00:00
|
|
|
/* these enable volume interpolation. Unlike video, both inputs are adjusted
|
|
|
|
* simultaneously */
|
2012-02-10 19:01:03 +00:00
|
|
|
GstControlSource *a_control_source;
|
2011-01-06 15:35:20 +00:00
|
|
|
|
2012-02-10 19:01:03 +00:00
|
|
|
GstControlSource *b_control_source;
|
2011-01-06 15:35:20 +00:00
|
|
|
|
2010-12-04 18:54:13 +00:00
|
|
|
};
|
|
|
|
|
2010-06-18 09:09:28 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
};
|
|
|
|
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2010-07-14 11:29:23 +00:00
|
|
|
#define fast_element_link(a,b) gst_element_link_pads_full((a),"src",(b),"sink",GST_PAD_LINK_CHECK_NOTHING)
|
|
|
|
|
2010-06-18 13:04:50 +00:00
|
|
|
static void
|
2013-01-27 15:44:13 +00:00
|
|
|
ges_audio_transition_duration_changed (GESTrackElement * self, guint64);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
static GstElement *ges_audio_transition_create_element (GESTrackElement * self);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
static void ges_audio_transition_dispose (GObject * object);
|
2010-06-18 09:09:28 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
static void ges_audio_transition_finalize (GObject * object);
|
2010-06-18 09:09:28 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
static void ges_audio_transition_get_property (GObject * object, guint
|
2010-06-18 09:09:28 +00:00
|
|
|
property_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
static void ges_audio_transition_set_property (GObject * object, guint
|
2010-06-18 09:09:28 +00:00
|
|
|
property_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static void
|
2013-01-27 15:44:13 +00:00
|
|
|
ges_audio_transition_class_init (GESAudioTransitionClass * klass)
|
2010-06-18 09:09:28 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
2013-01-26 15:31:33 +00:00
|
|
|
GESTrackElementClass *toclass;
|
2010-06-18 09:09:28 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GESAudioTransitionPrivate));
|
2010-12-04 18:54:13 +00:00
|
|
|
|
2010-06-18 09:09:28 +00:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2013-01-26 15:31:33 +00:00
|
|
|
toclass = GES_TRACK_ELEMENT_CLASS (klass);
|
2010-06-18 09:09:28 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
object_class->get_property = ges_audio_transition_get_property;
|
|
|
|
object_class->set_property = ges_audio_transition_set_property;
|
|
|
|
object_class->dispose = ges_audio_transition_dispose;
|
|
|
|
object_class->finalize = ges_audio_transition_finalize;
|
2010-06-18 09:09:28 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
toclass->duration_changed = ges_audio_transition_duration_changed;
|
2010-07-08 11:20:56 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
toclass->create_element = ges_audio_transition_create_element;
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2010-06-18 09:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-27 15:44:13 +00:00
|
|
|
ges_audio_transition_init (GESAudioTransition * self)
|
2010-06-18 09:09:28 +00:00
|
|
|
{
|
2010-12-04 18:54:13 +00:00
|
|
|
|
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
2013-01-27 15:44:13 +00:00
|
|
|
GES_TYPE_AUDIO_TRANSITION, GESAudioTransitionPrivate);
|
2010-06-18 09:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-27 15:44:13 +00:00
|
|
|
ges_audio_transition_dispose (GObject * object)
|
2010-06-18 09:09:28 +00:00
|
|
|
{
|
2013-01-27 15:44:13 +00:00
|
|
|
GESAudioTransition *self;
|
2010-06-18 13:21:02 +00:00
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
self = GES_AUDIO_TRANSITION (object);
|
2010-06-18 13:21:02 +00:00
|
|
|
|
2011-12-30 16:15:07 +00:00
|
|
|
if (self->priv->a_control_source) {
|
2011-01-06 15:35:20 +00:00
|
|
|
if (self->priv->a_control_source)
|
|
|
|
gst_object_unref (self->priv->a_control_source);
|
|
|
|
self->priv->a_control_source = NULL;
|
2010-06-18 13:21:02 +00:00
|
|
|
}
|
|
|
|
|
2011-12-30 16:15:07 +00:00
|
|
|
if (self->priv->b_control_source) {
|
2011-01-06 15:35:20 +00:00
|
|
|
if (self->priv->b_control_source)
|
|
|
|
gst_object_unref (self->priv->b_control_source);
|
|
|
|
self->priv->b_control_source = NULL;
|
2010-06-18 13:21:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 15:44:13 +00:00
|
|
|
G_OBJECT_CLASS (ges_audio_transition_parent_class)->dispose (object);
|
2010-06-18 09:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-27 15:44:13 +00:00
|
|
|
ges_audio_transition_finalize (GObject * object)
|
2010-06-18 09:09:28 +00:00
|
|
|
{
|
2013-01-27 15:44:13 +00:00
|
|
|
G_OBJECT_CLASS (ges_audio_transition_parent_class)->finalize (object);
|
2010-06-18 09:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-27 15:44:13 +00:00
|
|
|
ges_audio_transition_get_property (GObject * object,
|
2010-06-18 09:09:28 +00:00
|
|
|
guint property_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (property_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-27 15:44:13 +00:00
|
|
|
ges_audio_transition_set_property (GObject * object,
|
2010-06-18 09:09:28 +00:00
|
|
|
guint property_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (property_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-18 13:04:50 +00:00
|
|
|
static GObject *
|
|
|
|
link_element_to_mixer_with_volume (GstBin * bin, GstElement * element,
|
|
|
|
GstElement * mixer)
|
|
|
|
{
|
|
|
|
GstElement *volume = gst_element_factory_make ("volume", NULL);
|
2011-12-30 16:15:07 +00:00
|
|
|
|
2010-06-18 13:04:50 +00:00
|
|
|
gst_bin_add (bin, volume);
|
|
|
|
|
2010-07-14 11:29:23 +00:00
|
|
|
if (!fast_element_link (element, volume) ||
|
2012-05-01 17:43:02 +00:00
|
|
|
!gst_element_link_pads_full (volume, "src", mixer, "sink_%u",
|
2010-07-14 11:29:23 +00:00
|
|
|
GST_PAD_LINK_CHECK_NOTHING))
|
|
|
|
GST_ERROR_OBJECT (bin, "Error linking volume to mixer");
|
2010-06-18 13:04:50 +00:00
|
|
|
|
|
|
|
return G_OBJECT (volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
2013-02-15 02:34:48 +00:00
|
|
|
ges_audio_transition_create_element (GESTrackElement * track_element)
|
2010-06-18 13:04:50 +00:00
|
|
|
{
|
2013-01-27 15:44:13 +00:00
|
|
|
GESAudioTransition *self;
|
2010-06-18 13:04:50 +00:00
|
|
|
GstElement *topbin, *iconva, *iconvb, *oconv;
|
|
|
|
GObject *atarget, *btarget = NULL;
|
|
|
|
const gchar *propname = "volume";
|
|
|
|
GstElement *mixer = NULL;
|
|
|
|
GstPad *sinka_target, *sinkb_target, *src_target, *sinka, *sinkb, *src;
|
2012-02-10 19:01:03 +00:00
|
|
|
GstControlSource *acontrol_source, *bcontrol_source;
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
self = GES_AUDIO_TRANSITION (track_element);
|
2010-06-18 13:21:02 +00:00
|
|
|
|
2010-06-18 13:04:50 +00:00
|
|
|
|
|
|
|
GST_LOG ("creating an audio bin");
|
|
|
|
|
|
|
|
topbin = gst_bin_new ("transition-bin");
|
|
|
|
iconva = gst_element_factory_make ("audioconvert", "tr-aconv-a");
|
|
|
|
iconvb = gst_element_factory_make ("audioconvert", "tr-aconv-b");
|
|
|
|
oconv = gst_element_factory_make ("audioconvert", "tr-aconv-output");
|
|
|
|
|
|
|
|
gst_bin_add_many (GST_BIN (topbin), iconva, iconvb, oconv, NULL);
|
|
|
|
|
|
|
|
mixer = gst_element_factory_make ("adder", NULL);
|
|
|
|
gst_bin_add (GST_BIN (topbin), mixer);
|
|
|
|
|
|
|
|
atarget = link_element_to_mixer_with_volume (GST_BIN (topbin), iconva, mixer);
|
|
|
|
btarget = link_element_to_mixer_with_volume (GST_BIN (topbin), iconvb, mixer);
|
|
|
|
|
|
|
|
g_assert (atarget && btarget);
|
|
|
|
|
2010-07-14 11:29:23 +00:00
|
|
|
fast_element_link (mixer, oconv);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
|
|
|
sinka_target = gst_element_get_static_pad (iconva, "sink");
|
|
|
|
sinkb_target = gst_element_get_static_pad (iconvb, "sink");
|
|
|
|
src_target = gst_element_get_static_pad (oconv, "src");
|
|
|
|
|
|
|
|
sinka = gst_ghost_pad_new ("sinka", sinka_target);
|
|
|
|
sinkb = gst_ghost_pad_new ("sinkb", sinkb_target);
|
|
|
|
src = gst_ghost_pad_new ("src", src_target);
|
|
|
|
|
|
|
|
gst_element_add_pad (topbin, src);
|
|
|
|
gst_element_add_pad (topbin, sinka);
|
|
|
|
gst_element_add_pad (topbin, sinkb);
|
|
|
|
|
|
|
|
/* set up interpolation */
|
|
|
|
|
|
|
|
gst_object_unref (sinka_target);
|
|
|
|
gst_object_unref (sinkb_target);
|
|
|
|
gst_object_unref (src_target);
|
|
|
|
|
|
|
|
acontrol_source = gst_interpolation_control_source_new ();
|
2012-02-10 19:01:03 +00:00
|
|
|
gst_object_add_control_binding (GST_OBJECT (atarget),
|
|
|
|
gst_direct_control_binding_new (GST_OBJECT (atarget), propname,
|
|
|
|
acontrol_source));
|
2011-12-30 16:15:07 +00:00
|
|
|
g_object_set (acontrol_source, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
|
|
|
bcontrol_source = gst_interpolation_control_source_new ();
|
2012-02-10 19:01:03 +00:00
|
|
|
gst_object_add_control_binding (GST_OBJECT (btarget),
|
|
|
|
gst_direct_control_binding_new (GST_OBJECT (btarget), propname,
|
|
|
|
bcontrol_source));
|
2011-12-30 16:15:07 +00:00
|
|
|
g_object_set (acontrol_source, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2011-01-06 15:35:20 +00:00
|
|
|
self->priv->a_control_source = acontrol_source;
|
|
|
|
self->priv->b_control_source = bcontrol_source;
|
2010-06-18 13:04:50 +00:00
|
|
|
|
|
|
|
return topbin;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-02-15 02:34:48 +00:00
|
|
|
ges_audio_transition_duration_changed (GESTrackElement * track_element,
|
2010-07-08 11:20:56 +00:00
|
|
|
guint64 duration)
|
2010-06-18 13:04:50 +00:00
|
|
|
{
|
2013-01-27 15:44:13 +00:00
|
|
|
GESAudioTransition *self;
|
2013-02-15 02:34:48 +00:00
|
|
|
GstElement *gnlobj = ges_track_element_get_gnlobject (track_element);
|
2011-12-30 16:15:07 +00:00
|
|
|
GstTimedValueControlSource *ta, *tb;
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
self = GES_AUDIO_TRANSITION (track_element);
|
2010-06-18 13:21:02 +00:00
|
|
|
|
2011-12-30 16:15:07 +00:00
|
|
|
GST_LOG ("updating controller: gnlobj (%p)", gnlobj);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2011-01-06 15:35:20 +00:00
|
|
|
if (G_UNLIKELY ((!gnlobj || !self->priv->a_control_source ||
|
|
|
|
!self->priv->b_control_source)))
|
2010-12-21 14:24:26 +00:00
|
|
|
return;
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2010-07-06 17:06:24 +00:00
|
|
|
GST_INFO ("duration: %" G_GUINT64_FORMAT, duration);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
|
|
|
GST_LOG ("setting values on controller");
|
2011-12-30 16:15:07 +00:00
|
|
|
ta = GST_TIMED_VALUE_CONTROL_SOURCE (self->priv->a_control_source);
|
|
|
|
tb = GST_TIMED_VALUE_CONTROL_SOURCE (self->priv->b_control_source);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2011-12-30 16:15:07 +00:00
|
|
|
gst_timed_value_control_source_unset_all (ta);
|
|
|
|
gst_timed_value_control_source_set (ta, 0, 1.0);
|
|
|
|
gst_timed_value_control_source_set (ta, duration, 0.0);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
2011-12-30 16:15:07 +00:00
|
|
|
gst_timed_value_control_source_unset_all (tb);
|
|
|
|
gst_timed_value_control_source_set (tb, 0, 0.0);
|
|
|
|
gst_timed_value_control_source_set (tb, duration, 1.0);
|
2010-06-18 13:04:50 +00:00
|
|
|
|
|
|
|
GST_LOG ("done updating controller");
|
|
|
|
}
|
|
|
|
|
2011-01-10 13:28:35 +00:00
|
|
|
/**
|
2013-01-27 15:44:13 +00:00
|
|
|
* ges_audio_transition_new:
|
2011-01-10 13:28:35 +00:00
|
|
|
*
|
2013-01-27 15:44:13 +00:00
|
|
|
* Creates a new #GESAudioTransition.
|
2011-01-10 13:28:35 +00:00
|
|
|
*
|
2013-01-27 15:44:13 +00:00
|
|
|
* Returns: The newly created #GESAudioTransition.
|
2011-01-10 13:28:35 +00:00
|
|
|
*/
|
2013-01-27 15:44:13 +00:00
|
|
|
GESAudioTransition *
|
|
|
|
ges_audio_transition_new (void)
|
2010-06-18 09:09:28 +00:00
|
|
|
{
|
2013-01-27 15:44:13 +00:00
|
|
|
return g_object_new (GES_TYPE_AUDIO_TRANSITION, "track-type",
|
2012-12-20 23:23:54 +00:00
|
|
|
GES_TRACK_TYPE_AUDIO, NULL);
|
2010-06-18 09:09:28 +00:00
|
|
|
}
|