track-element: Create nleobject on GESExtractable::set_asset

This means that we have all the information about the asset
when constructing the underlying GstElements.

This also allows to cleanup some code all around
This commit is contained in:
Thibault Saunier 2020-03-24 22:30:38 -03:00
parent c2287696b1
commit f99034a522
4 changed files with 48 additions and 50 deletions

View file

@ -98,26 +98,11 @@ ges_extractable_check_id (GType type, const gchar * id, GError ** error)
return g_strdup (id);
}
static void
extractable_set_asset (GESExtractable * self, GESAsset * asset)
{
/* FIXME That should go into #GESTrackElement, but
* some work is needed to make sure it works properly */
if (ges_track_element_get_track_type (GES_TRACK_ELEMENT (self)) ==
GES_TRACK_TYPE_UNKNOWN) {
ges_track_element_set_track_type (GES_TRACK_ELEMENT (self),
ges_track_element_asset_get_track_type (GES_TRACK_ELEMENT_ASSET
(asset)));
}
}
static void
ges_extractable_interface_init (GESExtractableInterface * iface)
{
iface->asset_type = GES_TYPE_URI_SOURCE_ASSET;
iface->check_id = ges_extractable_check_id;
iface->set_asset = extractable_set_asset;
}
G_DEFINE_TYPE_WITH_CODE (GESAudioUriSource, ges_audio_uri_source,

View file

@ -91,8 +91,20 @@ enum
static guint ges_track_element_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GESTrackElement, ges_track_element,
GES_TYPE_TIMELINE_ELEMENT);
static void ges_track_element_set_asset (GESExtractable * extractable,
GESAsset * asset);
static void
ges_extractable_interface_init (GESExtractableInterface * iface)
{
iface->set_asset = ges_track_element_set_asset;
iface->asset_type = GES_TYPE_TRACK_ELEMENT_ASSET;
}
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GESTrackElement, ges_track_element,
GES_TYPE_TIMELINE_ELEMENT, G_ADD_PRIVATE (GESTrackElement)
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
ges_extractable_interface_init));
static GstElement *ges_track_element_create_gnl_object_func (GESTrackElement *
object);
@ -266,15 +278,19 @@ ges_track_element_finalize (GObject * object)
}
static void
ges_track_element_constructed (GObject * gobject)
ges_track_element_set_asset (GESExtractable * extractable, GESAsset * asset)
{
GESTrackElementClass *class;
GstElement *nleobject;
gdouble media_duration_factor;
gchar *tmp;
GESTrackElement *object = GES_TRACK_ELEMENT (gobject);
GESTrackElement *object = GES_TRACK_ELEMENT (extractable);
GST_DEBUG_OBJECT (object, "Creating NleObject");
if (ges_track_element_get_track_type (object) == GES_TRACK_TYPE_UNKNOWN) {
ges_track_element_set_track_type (object,
ges_track_element_asset_get_track_type (GES_TRACK_ELEMENT_ASSET
(asset)));
}
class = GES_TRACK_ELEMENT_GET_CLASS (object);
g_assert (class->create_gnl_object);
@ -291,8 +307,6 @@ ges_track_element_constructed (GObject * gobject)
gst_object_set_name (GST_OBJECT (nleobject), tmp);
g_free (tmp);
GST_DEBUG_OBJECT (object, "Got a valid NleObject, now filling it in");
object->priv->nleobject = gst_object_ref (nleobject);
g_object_set_qdata (G_OBJECT (nleobject), NLE_OBJECT_TRACK_ELEMENT_QUARK,
object);
@ -310,16 +324,23 @@ ges_track_element_constructed (GObject * gobject)
(object));
g_object_set (object->priv->nleobject,
"media-duration-factor", media_duration_factor, NULL);
}
static void
ges_track_element_constructed (GObject * object)
{
GESTrackElement *self = GES_TRACK_ELEMENT (object);
if (self->priv->track_type == GES_TRACK_TYPE_UNKNOWN)
ges_track_element_set_track_type (GES_TRACK_ELEMENT (object),
GES_TRACK_ELEMENT_GET_CLASS (object)->ABI.abi.default_track_type);
/* set the default has-internal-source */
ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (gobject),
GES_TRACK_ELEMENT_CLASS_DEFAULT_HAS_INTERNAL_SOURCE (class));
ges_track_element_set_has_internal_source (self,
GES_TRACK_ELEMENT_CLASS_DEFAULT_HAS_INTERNAL_SOURCE
(GES_TRACK_ELEMENT_GET_CLASS (object)));
if (object->priv->track_type == GES_TRACK_TYPE_UNKNOWN)
ges_track_element_set_track_type (GES_TRACK_ELEMENT (gobject),
class->ABI.abi.default_track_type);
G_OBJECT_CLASS (ges_track_element_parent_class)->constructed (gobject);
G_OBJECT_CLASS (ges_track_element_parent_class)->constructed (object);
}
static void

View file

@ -56,6 +56,7 @@
#include "ges-extractable.h"
#define parent_class ges_video_source_parent_class
GESExtractableInterface *parent_extractable_iface = NULL;
struct _GESVideoSourcePrivate
{
@ -68,6 +69,8 @@ ges_video_source_set_asset (GESExtractable * extractable, GESAsset * asset)
{
GESVideoSource *self = GES_VIDEO_SOURCE (extractable);
parent_extractable_iface->set_asset (extractable, asset);
ges_video_source_get_natural_size (self,
&self->priv->positioner->natural_width,
&self->priv->positioner->natural_height);
@ -248,6 +251,16 @@ ges_video_source_class_init (GESVideoSourceClass * klass)
static void
ges_video_source_init (GESVideoSource * self)
{
if (g_once_init_enter (&parent_extractable_iface)) {
GESExtractableInterface *iface, *parent_iface;
iface =
G_TYPE_INSTANCE_GET_INTERFACE (self, GES_TYPE_EXTRACTABLE,
GESExtractableInterface);
parent_iface = g_type_interface_peek_parent (iface);
g_once_init_leave (&parent_extractable_iface, parent_iface);
}
self->priv = ges_video_source_get_instance_private (self);
self->priv->positioner = NULL;
self->priv->capsfilter = NULL;

View file

@ -204,32 +204,11 @@ ges_extractable_check_id (GType type, const gchar * id, GError ** error)
return g_strdup (id);
}
static void
extractable_set_asset (GESExtractable * extractable, GESAsset * asset)
{
GESExtractableInterface *piface, *iface;
/* FIXME That should go into #GESTrackElement, but
* some work is needed to make sure it works properly */
if (ges_track_element_get_track_type (GES_TRACK_ELEMENT (extractable)) ==
GES_TRACK_TYPE_UNKNOWN) {
ges_track_element_set_track_type (GES_TRACK_ELEMENT (extractable),
ges_track_element_asset_get_track_type (GES_TRACK_ELEMENT_ASSET
(asset)));
}
iface = G_TYPE_INSTANCE_GET_INTERFACE (extractable, GES_TYPE_EXTRACTABLE,
GESExtractableInterface);
piface = g_type_interface_peek_parent (iface);
piface->set_asset (extractable, asset);
}
static void
ges_extractable_interface_init (GESExtractableInterface * iface)
{
iface->asset_type = GES_TYPE_URI_SOURCE_ASSET;
iface->check_id = ges_extractable_check_id;
iface->set_asset = extractable_set_asset;
}
G_DEFINE_TYPE_WITH_CODE (GESVideoUriSource, ges_video_uri_source,