Add a GESEffectAsset class, and make sure to set the GESTrackType asap on effects

+ Make use of the asset in ges_effect_new
This commit is contained in:
Thibault Saunier 2013-03-14 11:14:31 -04:00
parent eaf30dd4c5
commit b397a41f2f
4 changed files with 191 additions and 1 deletions

View file

@ -58,6 +58,7 @@ libges_@GST_API_VERSION@_la_SOURCES = \
ges-auto-transition.c \
ges-timeline-element.c \
ges-container.c \
ges-effect-asset.c \
ges-utils.c
libges_@GST_API_VERSION@includedir = $(includedir)/gstreamer-@GST_API_VERSION@/ges/
@ -112,6 +113,7 @@ libges_@GST_API_VERSION@include_HEADERS = \
ges-xml-formatter.h \
ges-timeline-element.h \
ges-container.h \
ges-effect-asset.h \
ges-utils.h
noinst_HEADERS = \

119
ges/ges-effect-asset.c Normal file
View file

@ -0,0 +1,119 @@
/* Gstreamer Editing Services
*
* Copyright (C) <2012> Thibault Saunier <thibault.saunier@collabora.com>
*
* 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
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* SECTION: ges-effect-asset
* @short_description: A GESAsset subclass specialized in GESEffect extraction
*/
#include "ges-effect-asset.h"
#include "ges-track-element.h"
#include "ges-internal.h"
G_DEFINE_TYPE (GESEffectAsset, ges_effect_asset, GES_TYPE_TRACK_ELEMENT_ASSET);
struct _GESEffectAssetPrivate
{
GESTrackType track_type;
};
/* GESAsset virtual methods implementation */
static void
_fill_track_type (GESAsset * asset)
{
GList *tmp;
GstElement *effect = gst_parse_bin_from_description (ges_asset_get_id (asset),
TRUE, NULL);
if (effect == NULL)
return;
for (tmp = GST_BIN_CHILDREN (effect); tmp; tmp = tmp->next) {
GstElementFactory *factory =
gst_element_get_factory (GST_ELEMENT (tmp->data));
const gchar *klass =
gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
if (g_strrstr (klass, "Effect")) {
if (g_strrstr (klass, "Audio")) {
GES_EFFECT_ASSET (asset)->priv->track_type = GES_TRACK_TYPE_AUDIO;
break;
} else if (g_strrstr (klass, "Video")) {
GES_EFFECT_ASSET (asset)->priv->track_type = GES_TRACK_TYPE_VIDEO;
break;
}
}
}
gst_object_unref (effect);
return;
}
static GESExtractable *
_extract (GESAsset * asset, GError ** error)
{
GESExtractable *effect;
if (GES_EFFECT_ASSET (asset)->priv->track_type == GES_TRACK_TYPE_UNKNOWN)
_fill_track_type (asset);
effect = GES_ASSET_CLASS (ges_effect_asset_parent_class)->extract (asset,
error);
if (effect == NULL || (error && *error)) {
effect = NULL;
return NULL;
}
ges_track_element_set_track_type (GES_TRACK_ELEMENT (effect),
GES_EFFECT_ASSET (asset)->priv->track_type);
return effect;
}
static void
ges_effect_asset_init (GESEffectAsset * self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
GES_TYPE_EFFECT_ASSET, GESEffectAssetPrivate);
self->priv->track_type = GES_TRACK_TYPE_UNKNOWN;
}
static void
ges_effect_asset_finalize (GObject * object)
{
/* TODO: Add deinitalization code here */
G_OBJECT_CLASS (ges_effect_asset_parent_class)->finalize (object);
}
static void
ges_effect_asset_class_init (GESEffectAssetClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GESAssetClass *asset_class = GES_ASSET_CLASS (klass);
g_type_class_add_private (klass, sizeof (GESEffectAssetPrivate));
object_class->finalize = ges_effect_asset_finalize;
asset_class->extract = _extract;
}

58
ges/ges-effect-asset.h Normal file
View file

@ -0,0 +1,58 @@
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */
/*
* gst-editing-services
* Copyright (C) 2013 Thibault Saunier <thibault.saunier@collabora.com>
*
gst-editing-services is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gst-editing-services 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*/
#ifndef _GES_EFFECT_ASSET_H_
#define _GES_EFFECT_ASSET_H_
#include <glib-object.h>
#include "ges-track-element-asset.h"
G_BEGIN_DECLS
#define GES_TYPE_EFFECT_ASSET (ges_effect_asset_get_type ())
#define GES_EFFECT_ASSET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GES_TYPE_EFFECT_ASSET, GESEffectAsset))
#define GES_EFFECT_ASSET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GES_TYPE_EFFECT_ASSET, GESEffectAssetClass))
#define GES_IS_EFFECT_ASSET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GES_TYPE_EFFECT_ASSET))
#define GES_IS_EFFECT_ASSET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GES_TYPE_EFFECT_ASSET))
#define GES_EFFECT_ASSET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GES_TYPE_EFFECT_ASSET, GESEffectAssetClass))
typedef struct _GESEffectAssetClass GESEffectAssetClass;
typedef struct _GESEffectAsset GESEffectAsset;
typedef struct _GESEffectAssetPrivate GESEffectAssetPrivate;
struct _GESEffectAssetClass
{
GESTrackElementAssetClass parent_class;
};
struct _GESEffectAsset
{
GESTrackElementAsset parent_instance;
GESEffectAssetPrivate *priv;
};
GType ges_effect_asset_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* _GES_EFFECT_ASSET_H_ */

View file

@ -27,6 +27,7 @@
#include "ges-extractable.h"
#include "ges-track-element.h"
#include "ges-base-effect.h"
#include "ges-effect-asset.h"
#include "ges-effect.h"
static void ges_extractable_interface_init (GESExtractableInterface * iface);
@ -86,6 +87,7 @@ extractable_get_id (GESExtractable * self)
static void
ges_extractable_interface_init (GESExtractableInterface * iface)
{
iface->asset_type = GES_TYPE_EFFECT_ASSET;
iface->check_id = (GESExtractableCheckId) extractable_check_id;
iface->get_parameters_from_id = extractable_get_parameters_from_id;
iface->get_id = extractable_get_id;
@ -238,6 +240,15 @@ ges_effect_create_element (GESTrackElement * object)
GESEffect *
ges_effect_new (const gchar * bin_description)
{
return g_object_new (GES_TYPE_EFFECT, "bin-description",
GESEffect *effect;
GESAsset *asset = ges_asset_request (GES_TYPE_EFFECT,
bin_description, NULL);
g_return_val_if_fail (asset, NULL);
effect = GES_EFFECT (ges_asset_extract (asset, NULL));
gst_object_unref (asset);
return effect;
}