gstreamer/ges/ges-audio-transition.c

299 lines
9 KiB
C
Raw Normal View History

/* 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.
*/
/**
* SECTION:gesaudiotransition
* @title: GESAudioTransition
2010-07-01 14:48:45 +00:00
* @short_description: implements audio crossfade transition
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ges-internal.h"
#include "ges-track-element.h"
#include "ges-audio-transition.h"
#include <gst/controller/gstdirectcontrolbinding.h>
struct _GESAudioTransitionPrivate
2010-12-04 18:54:13 +00:00
{
/* these enable volume interpolation. Unlike video, both inputs are adjusted
* simultaneously */
GstControlSource *a_control_source;
GstControlSource *b_control_source;
2010-12-04 18:54:13 +00:00
};
enum
{
PROP_0,
};
G_DEFINE_TYPE_WITH_PRIVATE (GESAudioTransition, ges_audio_transition,
GES_TYPE_TRANSITION);
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
ges_audio_transition_duration_changed (GESTrackElement * self, guint64);
2010-06-18 13:04:50 +00:00
static GstElement *ges_audio_transition_create_element (GESTrackElement * self);
2010-06-18 13:04:50 +00:00
static void ges_audio_transition_dispose (GObject * object);
static void ges_audio_transition_finalize (GObject * object);
static void ges_audio_transition_get_property (GObject * object, guint
property_id, GValue * value, GParamSpec * pspec);
static void ges_audio_transition_set_property (GObject * object, guint
property_id, const GValue * value, GParamSpec * pspec);
static void
duration_changed_cb (GESTrackElement * self, GParamSpec * arg G_GNUC_UNUSED)
{
ges_audio_transition_duration_changed (self,
ges_timeline_element_get_duration (GES_TIMELINE_ELEMENT (self)));
}
static void
ges_audio_transition_class_init (GESAudioTransitionClass * klass)
{
GObjectClass *object_class;
GESTrackElementClass *toclass;
object_class = G_OBJECT_CLASS (klass);
toclass = GES_TRACK_ELEMENT_CLASS (klass);
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;
toclass->create_element = ges_audio_transition_create_element;
2010-06-18 13:04:50 +00:00
}
static void
ges_audio_transition_init (GESAudioTransition * self)
{
2010-12-04 18:54:13 +00:00
self->priv = ges_audio_transition_get_instance_private (self);
}
static void
ges_audio_transition_dispose (GObject * object)
{
GESAudioTransition *self;
self = GES_AUDIO_TRANSITION (object);
if (self->priv->a_control_source) {
if (self->priv->a_control_source)
gst_object_unref (self->priv->a_control_source);
self->priv->a_control_source = NULL;
}
if (self->priv->b_control_source) {
if (self->priv->b_control_source)
gst_object_unref (self->priv->b_control_source);
self->priv->b_control_source = NULL;
}
g_signal_handlers_disconnect_by_func (GES_TRACK_ELEMENT (self),
duration_changed_cb, NULL);
G_OBJECT_CLASS (ges_audio_transition_parent_class)->dispose (object);
}
static void
ges_audio_transition_finalize (GObject * object)
{
G_OBJECT_CLASS (ges_audio_transition_parent_class)->finalize (object);
}
static void
ges_audio_transition_get_property (GObject * object,
guint property_id, GValue * value, GParamSpec * pspec)
{
switch (property_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
ges_audio_transition_set_property (GObject * object,
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);
GstElement *resample = gst_element_factory_make ("audioresample", NULL);
2010-06-18 13:04:50 +00:00
gst_bin_add (bin, volume);
gst_bin_add (bin, resample);
2010-06-18 13:04:50 +00:00
2010-07-14 11:29:23 +00:00
if (!fast_element_link (element, volume) ||
!fast_element_link (volume, resample) ||
!gst_element_link_pads_full (resample, "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 *
ges_audio_transition_create_element (GESTrackElement * track_element)
2010-06-18 13:04:50 +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;
guint64 duration;
GstControlSource *acontrol_source, *bcontrol_source;
2010-06-18 13:04:50 +00:00
self = GES_AUDIO_TRANSITION (track_element);
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 ("audiomixer", NULL);
2010-06-18 13:04:50 +00:00
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 ();
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 ();
g_object_set (bcontrol_source, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
self->priv->a_control_source = acontrol_source;
self->priv->b_control_source = bcontrol_source;
duration =
ges_timeline_element_get_duration (GES_TIMELINE_ELEMENT (track_element));
ges_audio_transition_duration_changed (track_element, duration);
g_signal_connect (track_element, "notify::duration",
G_CALLBACK (duration_changed_cb), NULL);
gst_object_add_control_binding (GST_OBJECT (atarget),
gst_direct_control_binding_new (GST_OBJECT (atarget), propname,
acontrol_source));
gst_object_add_control_binding (GST_OBJECT (btarget),
gst_direct_control_binding_new (GST_OBJECT (btarget), propname,
bcontrol_source));
2010-06-18 13:04:50 +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
ges_audio_transition_duration_changed (GESTrackElement * track_element,
guint64 duration)
2010-06-18 13:04:50 +00:00
{
GESAudioTransition *self;
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
GstElement *nleobj = ges_track_element_get_nleobject (track_element);
GstTimedValueControlSource *ta, *tb;
2010-06-18 13:04:50 +00:00
self = GES_AUDIO_TRANSITION (track_element);
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
GST_INFO ("updating controller: nleobj (%p)", nleobj);
2010-06-18 13:04:50 +00:00
if (G_UNLIKELY ((!self->priv->a_control_source ||
!self->priv->b_control_source)))
return;
2010-06-18 13:04:50 +00:00
GST_INFO ("setting values on controller");
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
gst_timed_value_control_source_unset_all (ta);
gst_timed_value_control_source_unset_all (tb);
/* The volume property goes from 0 to 10, so we want to interpolate between
* 0 and 0.1 */
gst_timed_value_control_source_set (ta, 0, 0.1);
gst_timed_value_control_source_set (ta, duration, 0.0);
2010-06-18 13:04:50 +00:00
gst_timed_value_control_source_set (tb, 0, 0.0);
gst_timed_value_control_source_set (tb, duration, 0.1);
2010-06-18 13:04:50 +00:00
GST_INFO ("done updating controller");
2010-06-18 13:04:50 +00:00
}
/**
* ges_audio_transition_new:
*
* Creates a new #GESAudioTransition.
*
* Returns: (transfer floating): The newly created #GESAudioTransition.
*/
GESAudioTransition *
ges_audio_transition_new (void)
{
return g_object_new (GES_TYPE_AUDIO_TRANSITION, "track-type",
GES_TRACK_TYPE_AUDIO, NULL);
}