2009-08-07 14:45:16 +00:00
|
|
|
/* GStreamer Editing Services
|
2009-11-30 14:14:25 +00:00
|
|
|
* Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
* 2009 Nokia Corporation
|
2009-08-07 14:45:16 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2009-08-07 14:45:16 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-10 16:40:51 +00:00
|
|
|
/**
|
2013-01-17 03:35:39 +00:00
|
|
|
* SECTION:ges-custom-source-clip
|
|
|
|
* @short_description: Convenience GESSourceClip
|
2009-09-10 16:40:51 +00:00
|
|
|
*
|
2013-01-17 03:35:39 +00:00
|
|
|
* #GESCustomSourceClip allows creating #GESSourceClip(s) without the
|
2009-09-10 16:40:51 +00:00
|
|
|
* need to subclass.
|
2012-09-18 12:42:58 +00:00
|
|
|
*
|
2009-09-10 16:40:51 +00:00
|
|
|
* Its usage should be limited to testing and prototyping purposes.
|
2012-09-18 12:42:58 +00:00
|
|
|
*
|
2013-01-17 03:35:39 +00:00
|
|
|
* To instanciate a asset to extract GESCustomSourceClip-s the expected
|
2012-09-18 12:42:58 +00:00
|
|
|
* ID is:
|
|
|
|
* 'PointerToFuncAsInt!PointerToUDataAsInt'
|
|
|
|
*
|
2013-01-17 03:35:39 +00:00
|
|
|
* You should use the #ges_asset_custom_source_clip_new helper to create
|
|
|
|
* a new GESAsset letting you extract GESCustomSourceClip.
|
2009-09-10 16:40:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-08-07 14:45:16 +00:00
|
|
|
#include "ges-internal.h"
|
2013-01-17 03:35:39 +00:00
|
|
|
#include "ges-custom-source-clip.h"
|
|
|
|
#include "ges-source-clip.h"
|
2013-01-26 16:08:20 +00:00
|
|
|
#include "ges-source.h"
|
2012-09-18 12:42:58 +00:00
|
|
|
#include "ges-extractable.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_FILL_FUNC,
|
|
|
|
PROP_USER_DATA
|
|
|
|
};
|
2009-08-07 14:45:16 +00:00
|
|
|
|
2013-01-17 03:35:39 +00:00
|
|
|
struct _GESCustomSourceClipPrivate
|
2010-11-26 17:43:36 +00:00
|
|
|
{
|
2013-01-26 15:31:33 +00:00
|
|
|
GESFillTrackElementUserFunc filltrackelementfunc;
|
2010-11-26 17:43:36 +00:00
|
|
|
gpointer user_data;
|
|
|
|
};
|
|
|
|
|
2012-09-18 12:42:58 +00:00
|
|
|
static void ges_extractable_interface_init (GESExtractableInterface * iface);
|
|
|
|
|
2013-01-17 03:35:39 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GESCustomSourceClip, ges_custom_source_clip,
|
|
|
|
GES_TYPE_SOURCE_CLIP,
|
2012-09-18 12:42:58 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
|
|
|
|
ges_extractable_interface_init));
|
|
|
|
|
|
|
|
static GParameter *
|
|
|
|
extractable_get_parameters_from_id (const gchar * id, guint * n_params)
|
|
|
|
{
|
|
|
|
gchar **func_udata;
|
2012-11-18 15:46:05 +00:00
|
|
|
GParameter *params = g_new0 (GParameter, 3);
|
|
|
|
*n_params = 3;
|
2012-09-18 12:42:58 +00:00
|
|
|
|
|
|
|
/* We already know that we have a valid ID here */
|
|
|
|
func_udata = g_strsplit (id, "!", -1);
|
|
|
|
|
2012-12-29 20:52:42 +00:00
|
|
|
params[0].name = "fill-func";
|
2012-09-18 12:42:58 +00:00
|
|
|
g_value_init (¶ms[0].value, G_TYPE_POINTER);
|
|
|
|
g_value_set_pointer (¶ms[0].value,
|
|
|
|
GUINT_TO_POINTER (g_ascii_strtoll (func_udata[0], NULL, 10)));
|
|
|
|
|
2012-12-29 20:52:42 +00:00
|
|
|
params[1].name = "user-data";
|
2012-09-18 12:42:58 +00:00
|
|
|
g_value_init (¶ms[1].value, G_TYPE_POINTER);
|
|
|
|
g_value_set_pointer (¶ms[1].value,
|
|
|
|
GUINT_TO_POINTER (g_ascii_strtoll (func_udata[1], NULL, 10)));
|
|
|
|
|
2012-12-29 20:52:42 +00:00
|
|
|
params[2].name = "supported-formats";
|
2013-03-03 14:50:10 +00:00
|
|
|
g_value_init (¶ms[2].value, GES_TYPE_TRACK_TYPE);
|
|
|
|
g_value_set_flags (¶ms[2].value, GES_TRACK_TYPE_CUSTOM);
|
2012-11-18 15:46:05 +00:00
|
|
|
|
2012-09-18 12:42:58 +00:00
|
|
|
g_strfreev (func_udata);
|
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
extractable_check_id (GType type, const gchar * id)
|
|
|
|
{
|
|
|
|
|
|
|
|
gchar *ret, **strv = g_strsplit (id, "!", -1);
|
|
|
|
|
|
|
|
if (g_strv_length (strv) != 2) {
|
|
|
|
g_strfreev (strv);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove any whitespace */
|
|
|
|
strv[0] = g_strstrip (strv[0]);
|
|
|
|
strv[1] = g_strstrip (strv[1]);
|
|
|
|
ret = g_strjoinv ("!", strv);
|
|
|
|
|
|
|
|
g_strfreev (strv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
extractable_get_id (GESExtractable * self)
|
|
|
|
{
|
2013-01-17 03:35:39 +00:00
|
|
|
GESCustomSourceClipPrivate *priv = GES_CUSTOM_SOURCE_CLIP (self)->priv;
|
2012-09-18 12:42:58 +00:00
|
|
|
|
2013-01-26 15:31:33 +00:00
|
|
|
return g_strdup_printf ("%i!%i", GPOINTER_TO_INT (priv->filltrackelementfunc),
|
2012-09-18 12:42:58 +00:00
|
|
|
GPOINTER_TO_INT (priv->user_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_extractable_interface_init (GESExtractableInterface * iface)
|
|
|
|
{
|
|
|
|
iface->check_id = (GESExtractableCheckId) extractable_check_id;
|
|
|
|
iface->get_id = extractable_get_id;
|
|
|
|
iface->get_parameters_from_id = extractable_get_parameters_from_id;
|
|
|
|
}
|
2009-08-07 14:45:16 +00:00
|
|
|
|
2009-11-25 10:55:50 +00:00
|
|
|
static gboolean
|
2013-02-15 02:34:48 +00:00
|
|
|
ges_custom_source_clip_fill_track_element (GESClip * clip,
|
|
|
|
GESTrackElement * track_element, GstElement * gnlobj);
|
2009-08-07 14:45:16 +00:00
|
|
|
|
2013-01-26 15:31:33 +00:00
|
|
|
static GESTrackElement *
|
2013-02-15 02:34:48 +00:00
|
|
|
ges_custom_source_clip_create_track_element (GESClip * clip, GESTrackType type)
|
2010-12-08 15:09:35 +00:00
|
|
|
{
|
2013-01-26 16:08:20 +00:00
|
|
|
return g_object_new (GES_TYPE_SOURCE, "track-type", type, NULL);
|
2010-12-08 15:09:35 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 12:42:58 +00:00
|
|
|
static void
|
|
|
|
_set_property (GObject * object, guint property_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-01-17 03:35:39 +00:00
|
|
|
GESCustomSourceClipPrivate *priv = GES_CUSTOM_SOURCE_CLIP (object)->priv;
|
2012-09-18 12:42:58 +00:00
|
|
|
switch (property_id) {
|
|
|
|
case PROP_FILL_FUNC:
|
2013-01-26 15:31:33 +00:00
|
|
|
priv->filltrackelementfunc = g_value_get_pointer (value);
|
2012-09-18 12:42:58 +00:00
|
|
|
break;
|
|
|
|
case PROP_USER_DATA:
|
|
|
|
priv->user_data = g_value_get_pointer (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-07 14:45:16 +00:00
|
|
|
static void
|
2013-01-17 03:35:39 +00:00
|
|
|
ges_custom_source_clip_class_init (GESCustomSourceClipClass * klass)
|
2009-08-07 14:45:16 +00:00
|
|
|
{
|
2012-09-18 12:42:58 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2013-01-20 15:42:29 +00:00
|
|
|
GESClipClass *clip_class = GES_CLIP_CLASS (klass);
|
2009-08-07 14:45:16 +00:00
|
|
|
|
2013-01-17 03:35:39 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GESCustomSourceClipPrivate));
|
2010-11-26 17:43:36 +00:00
|
|
|
|
2013-01-26 15:31:33 +00:00
|
|
|
clip_class->fill_track_element = ges_custom_source_clip_fill_track_element;
|
|
|
|
clip_class->create_track_element =
|
|
|
|
ges_custom_source_clip_create_track_element;
|
2012-09-18 12:42:58 +00:00
|
|
|
|
|
|
|
object_class->set_property = _set_property;
|
|
|
|
|
|
|
|
/**
|
2013-01-17 03:35:39 +00:00
|
|
|
* GESCustomSourceClip:fill-func:
|
2012-09-18 12:42:58 +00:00
|
|
|
*
|
2013-01-26 15:31:33 +00:00
|
|
|
* The function pointer to create the TrackElement content
|
2012-09-18 12:42:58 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_FILL_FUNC,
|
|
|
|
g_param_spec_pointer ("fill-func", "Fill func",
|
2013-01-26 15:31:33 +00:00
|
|
|
"A pointer to a GESFillTrackElementUserFunc",
|
2012-09-18 12:42:58 +00:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
/**
|
2013-01-17 03:35:39 +00:00
|
|
|
* GESCustomSourceClip:user-data:
|
2012-09-18 12:42:58 +00:00
|
|
|
*
|
|
|
|
* The user data that will be passed
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_USER_DATA,
|
|
|
|
g_param_spec_pointer ("user-data", "User data",
|
2013-01-26 15:31:33 +00:00
|
|
|
"The user data pointer that will be passed when creating TrackElements",
|
2012-09-18 12:42:58 +00:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
|
2009-08-07 14:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-17 03:35:39 +00:00
|
|
|
ges_custom_source_clip_init (GESCustomSourceClip * self)
|
2009-08-07 14:45:16 +00:00
|
|
|
{
|
2010-11-26 17:43:36 +00:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
2013-01-17 03:35:39 +00:00
|
|
|
GES_TYPE_CUSTOM_SOURCE_CLIP, GESCustomSourceClipPrivate);
|
2009-08-07 14:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-02-15 02:34:48 +00:00
|
|
|
ges_custom_source_clip_fill_track_element (GESClip * clip,
|
|
|
|
GESTrackElement * track_element, GstElement * gnlobj)
|
2009-08-07 14:45:16 +00:00
|
|
|
{
|
|
|
|
gboolean res;
|
2013-01-17 03:35:39 +00:00
|
|
|
GESCustomSourceClipPrivate *priv;
|
2009-08-07 14:45:16 +00:00
|
|
|
|
2013-01-26 15:31:33 +00:00
|
|
|
GST_DEBUG ("Calling callback (timelineobj:%p, trackelement:%p, gnlobj:%p)",
|
2013-02-15 02:34:48 +00:00
|
|
|
clip, track_element, gnlobj);
|
2009-08-07 14:45:16 +00:00
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
priv = GES_CUSTOM_SOURCE_CLIP (clip)->priv;
|
|
|
|
res = priv->filltrackelementfunc (clip, track_element, gnlobj,
|
|
|
|
priv->user_data);
|
2009-08-07 14:45:16 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("Returning res:%d", res);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:37:45 +00:00
|
|
|
/**
|
2013-01-17 03:35:39 +00:00
|
|
|
* ges_custom_source_clip_new:
|
2013-01-26 15:31:33 +00:00
|
|
|
* @func: (scope notified): The #GESFillTrackElementUserFunc that will be used to fill the track
|
2011-05-07 14:59:06 +00:00
|
|
|
* objects.
|
|
|
|
* @user_data: (closure): a gpointer that will be used when @func is called.
|
2009-09-16 10:37:45 +00:00
|
|
|
*
|
2013-01-17 03:35:39 +00:00
|
|
|
* Creates a new #GESCustomSourceClip.
|
2009-09-16 10:37:45 +00:00
|
|
|
*
|
2013-01-17 03:35:39 +00:00
|
|
|
* Returns: The new #GESCustomSourceClip.
|
2009-09-16 10:37:45 +00:00
|
|
|
*/
|
2013-01-17 03:35:39 +00:00
|
|
|
GESCustomSourceClip *
|
2013-01-26 15:31:33 +00:00
|
|
|
ges_custom_source_clip_new (GESFillTrackElementUserFunc func,
|
|
|
|
gpointer user_data)
|
2009-08-07 14:45:16 +00:00
|
|
|
{
|
2013-01-17 03:35:39 +00:00
|
|
|
GESCustomSourceClip *src;
|
2013-03-03 14:50:10 +00:00
|
|
|
GESAsset *asset = ges_asset_custom_source_clip_new (func, user_data);
|
2009-08-07 14:45:16 +00:00
|
|
|
|
2013-03-03 14:50:10 +00:00
|
|
|
src = GES_CUSTOM_SOURCE_CLIP (ges_asset_extract (asset, NULL));
|
|
|
|
gst_object_unref (asset);
|
2009-08-07 14:45:16 +00:00
|
|
|
|
|
|
|
return src;
|
|
|
|
}
|
2012-09-18 12:42:58 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-17 03:35:39 +00:00
|
|
|
* ges_asset_custom_source_clip_new:
|
2013-01-26 15:31:33 +00:00
|
|
|
* @func: (scope notified): The #GESFillTrackElementUserFunc that will be used to fill the track
|
2012-09-18 12:42:58 +00:00
|
|
|
* objects.
|
|
|
|
* @user_data: (closure): a gpointer that will be used when @func is called.
|
|
|
|
*
|
|
|
|
* Helper constructor to instanciate a new #GESAsset from which you can
|
2013-01-17 03:35:39 +00:00
|
|
|
* extract #GESCustomSourceClip-s
|
2012-09-18 12:42:58 +00:00
|
|
|
*
|
|
|
|
* Returns: The new #GESAsset.
|
|
|
|
*/
|
|
|
|
GESAsset *
|
2013-01-26 15:31:33 +00:00
|
|
|
ges_asset_custom_source_clip_new (GESFillTrackElementUserFunc func,
|
2012-09-18 12:42:58 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GESAsset *asset;
|
|
|
|
gchar *id = g_strdup_printf ("%i!%i", GPOINTER_TO_INT (func),
|
|
|
|
GPOINTER_TO_INT (user_data));
|
|
|
|
|
2013-01-17 03:35:39 +00:00
|
|
|
asset = ges_asset_request (GES_TYPE_CUSTOM_SOURCE_CLIP, id, NULL);
|
2012-09-18 12:42:58 +00:00
|
|
|
|
|
|
|
g_free (id);
|
|
|
|
|
|
|
|
return asset;
|
|
|
|
}
|