TimelineFileSource: Create instance private and move private variables to it
authorThibault Saunier <thibault.saunier@collabora.co.uk>
Sat, 8 Jan 2011 14:25:22 +0000 (15:25 +0100)
committerThibault Saunier <thibault.saunier@collabora.co.uk>
Sat, 8 Jan 2011 21:45:44 +0000 (22:45 +0100)
Fixe/Add getter and setters methods for those variables

Fixup documentation

docs/libs/ges-sections.txt
ges/ges-timeline-file-source.c
ges/ges-timeline-file-source.h
ges/ges-timeline.c
tests/examples/ges-ui.c

index 1b1b2fa20b823207872f3c63795a332a30e82739..6198a5f30c6e90cfe7d0de284bef696218f741b5 100644 (file)
@@ -351,8 +351,17 @@ GES_TYPE_TIMELINE_SOURCE
 <TITLE>GESTimelineFileSource</TITLE>
 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
 <SUBSECTION Standard>
 GESTimelineFileSourceClass
+GESTimelineFileSourcePrivate
 ges_timeline_filesource_get_type
 GES_IS_TIMELINE_FILE_SOURCE
 GES_IS_TIMELINE_FILE_SOURCE_CLASS
index 88e3bb7a1615ce2482f9de745a33a7a09d8a0208..33b248d56f0a2a12191d92931c4257a1950208a7 100644 (file)
 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);
   }
 
index 88c5d8d0411e83567c879dcccffefef316e4e194..7e46b99c4973d451072df07afd65039928f7956a 100644 (file)
@@ -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
index 55788130fd5a8c7838043edb5529a815ac8a69ce..a2ecbc1ab054c24a65d2d5043926890d46418aac 100644 (file)
@@ -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 {
index b63e64de5cd9446df5df9a894342521377c674aa..0e93fc9b036dff2d163ca4e46bf3cdd41e2cea7c 100644 (file)
@@ -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);
   }