From 98b51d8cd1dda509cf508254455fc88d43ee3902 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Sat, 8 Jan 2011 15:25:22 +0100 Subject: [PATCH] TimelineFileSource: Create instance private and move private variables to it Fixe/Add getter and setters methods for those variables Fixup documentation --- docs/libs/ges-sections.txt | 9 ++ ges/ges-timeline-file-source.c | 183 ++++++++++++++++++++++++++++----- ges/ges-timeline-file-source.h | 37 +++++-- ges/ges-timeline.c | 34 ++++-- tests/examples/ges-ui.c | 23 +++-- 5 files changed, 229 insertions(+), 57 deletions(-) diff --git a/docs/libs/ges-sections.txt b/docs/libs/ges-sections.txt index 1b1b2fa20b..6198a5f30c 100644 --- a/docs/libs/ges-sections.txt +++ b/docs/libs/ges-sections.txt @@ -351,8 +351,17 @@ GES_TYPE_TIMELINE_SOURCE GESTimelineFileSource GESTimelineFileSource ges_timeline_filesource_new +ges_timeline_filesource_get_max_duration +ges_timeline_filesource_get_supported_formats +ges_timeline_filesource_get_uri +ges_timeline_filesource_is_image +ges_timeline_filesource_is_muted +ges_timeline_filesource_set_is_image +ges_timeline_filesource_set_max_duration +ges_timeline_filesource_set_mute GESTimelineFileSourceClass +GESTimelineFileSourcePrivate ges_timeline_filesource_get_type GES_IS_TIMELINE_FILE_SOURCE GES_IS_TIMELINE_FILE_SOURCE_CLASS diff --git a/ges/ges-timeline-file-source.c b/ges/ges-timeline-file-source.c index 88e3bb7a16..33b248d56f 100644 --- a/ges/ges-timeline-file-source.c +++ b/ges/ges-timeline-file-source.c @@ -36,6 +36,20 @@ G_DEFINE_TYPE (GESTimelineFileSource, ges_timeline_filesource, GES_TYPE_TIMELINE_SOURCE); +struct _GESTimelineFileSourcePrivate +{ + gchar *uri; + + gboolean mute; + gboolean is_image; + + guint64 maxduration; + + /* The formats supported by this filesource + * TODO : Could maybe be moved to a parent class */ + GESTrackType supportedformats; +}; + enum { PROP_0, @@ -46,11 +60,6 @@ enum PROP_IS_IMAGE, }; -static void -ges_timeline_filesource_set_mute (GESTimelineFileSource * self, gboolean mute); -static void -ges_timeline_filesource_set_max_duration (GESTimelineFileSource * self, - guint64 maxduration); static GESTrackObject * ges_timeline_filesource_create_track_object (GESTimelineObject * obj, @@ -60,23 +69,23 @@ static void ges_timeline_filesource_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) { - GESTimelineFileSource *tfs = GES_TIMELINE_FILE_SOURCE (object); + GESTimelineFileSourcePrivate *priv = GES_TIMELINE_FILE_SOURCE (object)->priv; switch (property_id) { case PROP_URI: - g_value_set_string (value, tfs->uri); + g_value_set_string (value, priv->uri); break; case PROP_MUTE: - g_value_set_boolean (value, tfs->mute); + g_value_set_boolean (value, priv->mute); break; case PROP_MAX_DURATION: - g_value_set_uint64 (value, tfs->maxduration); + g_value_set_uint64 (value, priv->maxduration); break; case PROP_SUPPORTED_FORMATS: - g_value_set_flags (value, tfs->supportedformats); + g_value_set_flags (value, priv->supportedformats); break; case PROP_IS_IMAGE: - g_value_set_boolean (value, tfs->is_image); + g_value_set_boolean (value, priv->is_image); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -91,7 +100,7 @@ ges_timeline_filesource_set_property (GObject * object, guint property_id, switch (property_id) { case PROP_URI: - tfs->uri = g_value_dup_string (value); + tfs->priv->uri = g_value_dup_string (value); break; case PROP_MUTE: ges_timeline_filesource_set_mute (tfs, g_value_get_boolean (value)); @@ -101,10 +110,11 @@ ges_timeline_filesource_set_property (GObject * object, guint property_id, g_value_get_uint64 (value)); break; case PROP_SUPPORTED_FORMATS: - tfs->supportedformats = g_value_get_flags (value); + ges_timeline_filesource_set_supported_formats (tfs, + g_value_get_flags (value)); break; case PROP_IS_IMAGE: - tfs->is_image = g_value_get_boolean (value); + ges_timeline_filesource_set_is_image (tfs, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -114,10 +124,10 @@ ges_timeline_filesource_set_property (GObject * object, guint property_id, static void ges_timeline_filesource_finalize (GObject * object) { - GESTimelineFileSource *tfs = GES_TIMELINE_FILE_SOURCE (object); + GESTimelineFileSourcePrivate *priv = GES_TIMELINE_FILE_SOURCE (object)->priv; - if (tfs->uri) - g_free (tfs->uri); + if (priv->uri) + g_free (priv->uri); G_OBJECT_CLASS (ges_timeline_filesource_parent_class)->finalize (object); } @@ -127,6 +137,8 @@ ges_timeline_filesource_class_init (GESTimelineFileSourceClass * klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); GESTimelineObjectClass *timobj_class = GES_TIMELINE_OBJECT_CLASS (klass); + g_type_class_add_private (klass, sizeof (GESTimelineFileSourcePrivate)); + object_class->get_property = ges_timeline_filesource_get_property; object_class->set_property = ges_timeline_filesource_set_property; object_class->finalize = ges_timeline_filesource_finalize; @@ -192,11 +204,22 @@ ges_timeline_filesource_class_init (GESTimelineFileSourceClass * klass) static void ges_timeline_filesource_init (GESTimelineFileSource * self) { + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + GES_TYPE_TIMELINE_FILE_SOURCE, GESTimelineFileSourcePrivate); + /* Setting the duration to -1 by default. */ GES_TIMELINE_OBJECT (self)->duration = GST_CLOCK_TIME_NONE; } -static void +/** + * ges_timeline_filesource_set_mute: + * @self: the #GESTimelineFileSource on which to mute or unmute the audio track + * @mute: %TRUE to mute @self audio track, %FALSE to unmute it + * + * Sets whether the audio track of this timeline object is muted or not. + * + */ +void ges_timeline_filesource_set_mute (GESTimelineFileSource * self, gboolean mute) { GList *tmp, *trackobjects; @@ -204,7 +227,7 @@ ges_timeline_filesource_set_mute (GESTimelineFileSource * self, gboolean mute) GST_DEBUG ("self:%p, mute:%d", self, mute); - self->mute = mute; + self->priv->mute = mute; /* Go over tracked objects, and update 'active' status on all audio objects */ trackobjects = ges_timeline_object_get_track_objects (object); @@ -219,38 +242,142 @@ ges_timeline_filesource_set_mute (GESTimelineFileSource * self, gboolean mute) g_list_free (trackobjects); } -static void +/** + * ges_timeline_filesource_set_max_duration: + * @self: the #GESTimelineFileSource to set the maximum duration on + * @maxduration: the maximum duration of @self + * + * Sets the maximum duration (in nanoseconds) of the file. + * + */ +void ges_timeline_filesource_set_max_duration (GESTimelineFileSource * self, guint64 maxduration) { GESTimelineObject *object = GES_TIMELINE_OBJECT (self); - self->maxduration = maxduration; + self->priv->maxduration = maxduration; if (object->duration == GST_CLOCK_TIME_NONE || object->duration == 0) { /* If we don't have a valid duration, use the max duration */ - g_object_set (self, "duration", self->maxduration - object->inpoint, NULL); + g_object_set (self, "duration", self->priv->maxduration - object->inpoint, + NULL); } } +/** + * ges_timeline_filesource_set_supported_formats: + * @self: the #GESTimelineFileSource to set supported formats on + * @supportedformats: the #GESTrackType defining formats supported by @self + * + * Sets the formats supported by the file. + * + */ +void +ges_timeline_filesource_set_supported_formats (GESTimelineFileSource * self, + GESTrackType supportedformats) +{ + self->priv->supportedformats = supportedformats; +} + +/** + * ges_timeline_filesource_set_is_image: + * @self: the #GESTimelineFileSource + * @is_image: %TRUE if @self is a still image, %FALSE otherwize + * + * Sets whether the timeline object is a still image or not. + * + */ +void +ges_timeline_filesource_set_is_image (GESTimelineFileSource * self, + gboolean is_image) +{ + self->priv->is_image = is_image; +} + +/** + * ges_timeline_filesource_is_muted: + * @self: the #GESTimelineFileSource + * + * Returns: %TRUE if the audio track of @self is muted, %FALSE otherwize. + * + */ +gboolean +ges_timeline_filesource_is_muted (GESTimelineFileSource * self) +{ + return self->priv->mute; +} + +/** + * ges_timeline_filesource_get_max_duration: + * @self: the #GESTimelineFileSource + * + * Returns: The duration of @self. + * + */ +guint64 +ges_timeline_filesource_get_max_duration (GESTimelineFileSource * self) +{ + return self->priv->maxduration; +} + +/** + * ges_timeline_filesource_is_image: + * @self: the #GESTimelineFileSource + * + * Returns: %TRUE if @self is a still image %FALSE otherwize. + * + */ +gboolean +ges_timeline_filesource_is_image (GESTimelineFileSource * self) +{ + return self->priv->is_image; +} + +/** + * ges_timeline_filesource_get_uri: + * @self: the #GESTimelineFileSource + * + * Returns: The location of the ressource. + * + */ +const gchar * +ges_timeline_filesource_get_uri (GESTimelineFileSource * self) +{ + return self->priv->uri; +} + +/** + * ges_timeline_filesource_get_supported_formats: + * @self: the #GESTimelineFileSource + * + * Returns: The formats supported by @self. + * + */ +GESTrackType +ges_timeline_filesource_get_supported_formats (GESTimelineFileSource * self) +{ + return self->priv->supportedformats; +} + static GESTrackObject * ges_timeline_filesource_create_track_object (GESTimelineObject * obj, GESTrack * track) { - GESTimelineFileSource *tfs = (GESTimelineFileSource *) obj; + GESTimelineFileSourcePrivate *priv = GES_TIMELINE_FILE_SOURCE (obj)->priv; GESTrackObject *res; - if (!(tfs->supportedformats & track->type)) { + if (!(priv->supportedformats & track->type)) { GST_DEBUG ("We don't support this track format"); return NULL; } - if (tfs->is_image) { + if (priv->is_image) { if (track->type != GES_TRACK_TYPE_VIDEO) { GST_DEBUG ("Object is still image, creating silent audio source"); res = (GESTrackObject *) ges_track_audio_test_source_new (); } else { GST_DEBUG ("Creating a GESTrackImageSource"); - res = (GESTrackObject *) ges_track_image_source_new (tfs->uri); + res = (GESTrackObject *) ges_track_image_source_new (priv->uri); } } @@ -258,10 +385,10 @@ ges_timeline_filesource_create_track_object (GESTimelineObject * obj, GST_DEBUG ("Creating a GESTrackFileSource"); /* FIXME : Implement properly ! */ - res = (GESTrackObject *) ges_track_filesource_new (tfs->uri); + res = (GESTrackObject *) ges_track_filesource_new (priv->uri); /* If mute and track is audio, deactivate the track object */ - if (track->type == GES_TRACK_TYPE_AUDIO && tfs->mute) + if (track->type == GES_TRACK_TYPE_AUDIO && priv->mute) ges_track_object_set_active (res, FALSE); } diff --git a/ges/ges-timeline-file-source.h b/ges/ges-timeline-file-source.h index 88c5d8d041..7e46b99c49 100644 --- a/ges/ges-timeline-file-source.h +++ b/ges/ges-timeline-file-source.h @@ -45,25 +45,18 @@ G_BEGIN_DECLS #define GES_TIMELINE_FILE_SOURCE_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS ((obj), GES_TYPE_TIMELINE_FILE_SOURCE, GESTimelineFileSourceClass)) +typedef struct _GESTimelineFileSourcePrivate GESTimelineFileSourcePrivate; + /** * GESTimelineSource: * */ struct _GESTimelineFileSource { - /*< private >*/ GESTimelineSource parent; - gchar *uri; - - gboolean mute; - gboolean is_image; - - guint64 maxduration; - - /* The formats supported by this filesource - * TODO : Could maybe be moved to a parent class */ - GESTrackType supportedformats; + /*< private >*/ + GESTimelineFileSourcePrivate *priv; /* Padding for API extension */ gpointer _ges_reserved[GES_PADDING]; @@ -83,6 +76,28 @@ struct _GESTimelineFileSourceClass { GType ges_timeline_filesource_get_type (void); +void +ges_timeline_filesource_set_mute (GESTimelineFileSource * self, gboolean mute); + +void +ges_timeline_filesource_set_max_duration (GESTimelineFileSource * self, + guint64 maxduration); + +void +ges_timeline_filesource_set_supported_formats (GESTimelineFileSource * self, + GESTrackType supportedformats); + +void +ges_timeline_filesource_set_is_image (GESTimelineFileSource * self, + gboolean is_image); + +gboolean ges_timeline_filesource_is_muted (GESTimelineFileSource * self); +guint64 ges_timeline_filesource_get_max_duration (GESTimelineFileSource * self); +gboolean ges_timeline_filesource_is_image (GESTimelineFileSource * self); +const gchar *ges_timeline_filesource_get_uri (GESTimelineFileSource * self); +GESTrackType +ges_timeline_filesource_get_supported_formats (GESTimelineFileSource * self); + GESTimelineFileSource* ges_timeline_filesource_new (gchar *uri); G_END_DECLS diff --git a/ges/ges-timeline.c b/ges/ges-timeline.c index 55788130fd..a2ecbc1ab0 100644 --- a/ges/ges-timeline.c +++ b/ges/ges-timeline.c @@ -447,7 +447,7 @@ discoverer_discovered_cb (GstDiscoverer * discoverer, for (tmp = priv->pendingobjects; tmp; tmp = tmp->next) { tfs = (GESTimelineFileSource *) tmp->data; - if (!g_strcmp0 (tfs->uri, uri)) { + if (!g_strcmp0 (ges_timeline_filesource_get_uri (tfs), uri)) { found = TRUE; break; } @@ -455,6 +455,7 @@ discoverer_discovered_cb (GstDiscoverer * discoverer, if (found) { GList *stream_list; + GESTrackType tfs_supportedformats; /* Remove object from list */ priv->pendingobjects = g_list_delete_link (priv->pendingobjects, tmp); @@ -466,13 +467,22 @@ discoverer_discovered_cb (GstDiscoverer * discoverer, for (tmp = stream_list; tmp; tmp = tmp->next) { GstDiscovererStreamInfo *sinf = (GstDiscovererStreamInfo *) tmp->data; - if (GST_IS_DISCOVERER_AUDIO_INFO (sinf)) - tfs->supportedformats |= GES_TRACK_TYPE_AUDIO; - else if (GST_IS_DISCOVERER_VIDEO_INFO (sinf)) { - tfs->supportedformats |= GES_TRACK_TYPE_VIDEO; + tfs_supportedformats = + ges_timeline_filesource_get_supported_formats (tfs); + + if (GST_IS_DISCOVERER_AUDIO_INFO (sinf)) { + tfs_supportedformats |= GES_TRACK_TYPE_AUDIO; + ges_timeline_filesource_set_supported_formats (tfs, + tfs_supportedformats); + } else if (GST_IS_DISCOVERER_VIDEO_INFO (sinf)) { + tfs_supportedformats |= GES_TRACK_TYPE_VIDEO; + ges_timeline_filesource_set_supported_formats (tfs, + tfs_supportedformats); if (gst_discoverer_video_info_is_image ((GstDiscovererVideoInfo *) sinf)) { - tfs->supportedformats |= GES_TRACK_TYPE_AUDIO; + tfs_supportedformats |= GES_TRACK_TYPE_AUDIO; + ges_timeline_filesource_set_supported_formats (tfs, + tfs_supportedformats); is_image = TRUE; } } @@ -543,19 +553,23 @@ layer_object_added_cb (GESTimelineLayer * layer, GESTimelineObject * object, if (GES_IS_TIMELINE_FILE_SOURCE (object)) { GESTimelineFileSource *tfs = GES_TIMELINE_FILE_SOURCE (object); + GESTrackType tfs_supportedformats = + ges_timeline_filesource_get_supported_formats (tfs); + guint64 tfs_maxdur = ges_timeline_filesource_get_max_duration (tfs); + const gchar *tfs_uri; /* Send the filesource to the discoverer if: * * it doesn't have specified supported formats * * OR it doesn't have a specified max-duration * * OR it doesn't have a valid duration */ - if (tfs->supportedformats == GES_TRACK_TYPE_UNKNOWN || - tfs->maxduration == GST_CLOCK_TIME_NONE || object->duration == 0) { + if (tfs_supportedformats == GES_TRACK_TYPE_UNKNOWN || + tfs_maxdur == GST_CLOCK_TIME_NONE || object->duration == 0) { GST_LOG ("Incomplete TimelineFileSource, discovering it"); + tfs_uri = ges_timeline_filesource_get_uri (tfs); timeline->priv->pendingobjects = g_list_append (timeline->priv->pendingobjects, object); - gst_discoverer_discover_uri_async (timeline->priv->discoverer, - GES_TIMELINE_FILE_SOURCE (object)->uri); + gst_discoverer_discover_uri_async (timeline->priv->discoverer, tfs_uri); } else add_object_to_tracks (timeline, object); } else { diff --git a/tests/examples/ges-ui.c b/tests/examples/ges-ui.c index b63e64de5c..0e93fc9b03 100644 --- a/tests/examples/ges-ui.c +++ b/tests/examples/ges-ui.c @@ -243,7 +243,9 @@ filesource_notify_duration_cb (GESTimelineObject * object, { guint64 duration, max_inpoint; duration = GES_TIMELINE_OBJECT_DURATION (object); - max_inpoint = GES_TIMELINE_FILE_SOURCE (object)->maxduration - duration; + max_inpoint = + ges_timeline_filesource_get_max_duration (GES_TIMELINE_FILE_SOURCE + (object)) - duration; gtk_range_set_value (GTK_RANGE (app->duration), duration); gtk_range_set_fill_level (GTK_RANGE (app->in_point), max_inpoint); @@ -257,10 +259,12 @@ static void filesource_notify_max_duration_cb (GESTimelineObject * object, GParamSpec * arg G_GNUC_UNUSED, App * app) { - gtk_range_set_range (GTK_RANGE (app->duration), - 0, (gdouble) GES_TIMELINE_FILE_SOURCE (object)->maxduration); - gtk_range_set_range (GTK_RANGE (app->in_point), - 0, (gdouble) GES_TIMELINE_FILE_SOURCE (object)->maxduration); + gtk_range_set_range (GTK_RANGE (app->duration), 0, (gdouble) + ges_timeline_filesource_get_max_duration (GES_TIMELINE_FILE_SOURCE + (object))); + gtk_range_set_range (GTK_RANGE (app->in_point), 0, (gdouble) + ges_timeline_filesource_get_max_duration (GES_TIMELINE_FILE_SOURCE + (object))); } static void @@ -1460,7 +1464,9 @@ duration_scale_change_value_cb (GtkRange * range, GtkScrollType unused, for (i = app->selected_objects; i; i = i->next) { guint64 duration, maxduration; - maxduration = GES_TIMELINE_FILE_SOURCE (i->data)->maxduration; + maxduration = + ges_timeline_filesource_get_max_duration (GES_TIMELINE_FILE_SOURCE + (i->data)); duration = (value < maxduration ? (value > 0 ? value : 0) : maxduration); g_object_set (G_OBJECT (i->data), "duration", (guint64) duration, NULL); } @@ -1475,8 +1481,9 @@ in_point_scale_change_value_cb (GtkRange * range, GtkScrollType unused, for (i = app->selected_objects; i; i = i->next) { guint64 in_point, maxduration; - maxduration = GES_TIMELINE_FILE_SOURCE (i->data)->maxduration - - GES_TIMELINE_OBJECT_DURATION (i->data); + maxduration = + ges_timeline_filesource_get_max_duration (GES_TIMELINE_FILE_SOURCE + (i->data)) - GES_TIMELINE_OBJECT_DURATION (i->data); in_point = (value < maxduration ? (value > 0 ? value : 0) : maxduration); g_object_set (G_OBJECT (i->data), "in-point", (guint64) in_point, NULL); }