GESTimelineFileSource: Add 'max-duration' and 'supported-formats' properties

* max-duration is the total length of the File.
* supported-formats is the various track types this filesource can produce
  trackobjects for. This should maybe be moved to parent classes in the
  future

Step 1 of GstDiscoverer integration
This commit is contained in:
Edward Hervey 2010-05-19 12:24:44 +02:00
parent 133e8ec94a
commit eb4b02f3ed
3 changed files with 86 additions and 4 deletions

View file

@ -18,6 +18,11 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
/**
* SECTION:ges-timeline-filesource
* @short_description:
*/
#include "ges-internal.h" #include "ges-internal.h"
#include "ges-timeline-file-source.h" #include "ges-timeline-file-source.h"
#include "ges-timeline-source.h" #include "ges-timeline-source.h"
@ -30,11 +35,16 @@ enum
{ {
PROP_0, PROP_0,
PROP_URI, PROP_URI,
PROP_MUTE PROP_MAX_DURATION,
PROP_MUTE,
PROP_SUPPORTED_FORMATS
}; };
static void static void
ges_tl_filesource_set_mute (GESTimelineFileSource * self, gboolean mute); ges_tl_filesource_set_mute (GESTimelineFileSource * self, gboolean mute);
static void
ges_tl_filesource_set_max_duration (GESTimelineFileSource * self,
guint64 maxduration);
static GESTrackObject static GESTrackObject
* ges_tl_filesource_create_track_object (GESTimelineObject * obj, * ges_tl_filesource_create_track_object (GESTimelineObject * obj,
@ -53,6 +63,12 @@ ges_tl_filesource_get_property (GObject * object, guint property_id,
case PROP_MUTE: case PROP_MUTE:
g_value_set_boolean (value, tfs->mute); g_value_set_boolean (value, tfs->mute);
break; break;
case PROP_MAX_DURATION:
g_value_set_uint64 (value, tfs->maxduration);
break;
case PROP_SUPPORTED_FORMATS:
g_value_set_flags (value, tfs->supportedformats);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
} }
@ -71,6 +87,12 @@ ges_tl_filesource_set_property (GObject * object, guint property_id,
case PROP_MUTE: case PROP_MUTE:
ges_tl_filesource_set_mute (tfs, g_value_get_boolean (value)); ges_tl_filesource_set_mute (tfs, g_value_get_boolean (value));
break; break;
case PROP_MAX_DURATION:
ges_tl_filesource_set_max_duration (tfs, g_value_get_uint64 (value));
break;
case PROP_SUPPORTED_FORMATS:
tfs->supportedformats = g_value_get_flags (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
} }
@ -105,7 +127,7 @@ ges_tl_filesource_class_init (GESTimelineFileSourceClass * klass)
/** /**
* GESTimelineFileSource:uri * GESTimelineFileSource:uri:
* *
* The location of the file/resource to use. * The location of the file/resource to use.
*/ */
@ -114,7 +136,20 @@ ges_tl_filesource_class_init (GESTimelineFileSourceClass * klass)
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/** /**
* GESTimelineFileSource:mute * GESTimelineFileSource:max-duration:
*
* The maximum duration (in nanoseconds) of the file.
*
* If not set before adding the object to a layer, it will be discovered
* asynchronously. Connect to 'notify::max-duration' to be notified of it.
*/
g_object_class_install_property (object_class, PROP_MAX_DURATION,
g_param_spec_uint64 ("max-duration", "Maximum duration",
"The duration of the file", 0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* GESTimelineFileSource:mute:
* *
* Whether the sound will be played or not. * Whether the sound will be played or not.
*/ */
@ -122,6 +157,16 @@ ges_tl_filesource_class_init (GESTimelineFileSourceClass * klass)
g_param_spec_boolean ("mute", "Mute", "Mute audio track", g_param_spec_boolean ("mute", "Mute", "Mute audio track",
FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* GESTimelineFileSource:supported-formats:
*
* Whether the sound will be played or not.
*/
g_object_class_install_property (object_class, PROP_SUPPORTED_FORMATS,
g_param_spec_flags ("supported-formats", "Supported formats",
"Formats supported by the file", GES_TYPE_TRACK_TYPE,
GES_TRACK_TYPE_UNKNOWN, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
timobj_class->create_track_object = ges_tl_filesource_create_track_object; timobj_class->create_track_object = ges_tl_filesource_create_track_object;
timobj_class->need_fill_track = FALSE; timobj_class->need_fill_track = FALSE;
} }
@ -129,6 +174,8 @@ ges_tl_filesource_class_init (GESTimelineFileSourceClass * klass)
static void static void
ges_tl_filesource_init (GESTimelineFileSource * self) ges_tl_filesource_init (GESTimelineFileSource * self)
{ {
/* Setting the duration to -1 by default. */
GES_TIMELINE_OBJECT (self)->duration = GST_CLOCK_TIME_NONE;
} }
static void static void
@ -150,6 +197,19 @@ ges_tl_filesource_set_mute (GESTimelineFileSource * self, gboolean mute)
} }
} }
static void
ges_tl_filesource_set_max_duration (GESTimelineFileSource * self,
guint64 maxduration)
{
GESTimelineObject *object = GES_TIMELINE_OBJECT (self);
self->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);
}
}
static GESTrackObject * static GESTrackObject *
ges_tl_filesource_create_track_object (GESTimelineObject * obj, ges_tl_filesource_create_track_object (GESTimelineObject * obj,
GESTrack * track) GESTrack * track)
@ -157,6 +217,11 @@ ges_tl_filesource_create_track_object (GESTimelineObject * obj,
GESTimelineFileSource *tfs = (GESTimelineFileSource *) obj; GESTimelineFileSource *tfs = (GESTimelineFileSource *) obj;
GESTrackObject *res; GESTrackObject *res;
if (!(tfs->supportedformats & track->type)) {
GST_DEBUG ("We don't support this track format");
return NULL;
}
GST_DEBUG ("Creating a GESTrackFileSource"); GST_DEBUG ("Creating a GESTrackFileSource");
/* FIXME : Implement properly ! */ /* FIXME : Implement properly ! */

View file

@ -24,6 +24,7 @@
#include <glib-object.h> #include <glib-object.h>
#include <ges/ges-types.h> #include <ges/ges-types.h>
#include <ges/ges-timeline-source.h> #include <ges/ges-timeline-source.h>
#include <ges/ges-track.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -52,6 +53,12 @@ struct _GESTimelineFileSource {
gchar *uri; gchar *uri;
gboolean mute; gboolean mute;
guint64 maxduration;
/* The formats supported by this filesource
* TODO : Could maybe be moved to a parent class */
GESTrackType supportedformats;
}; };
struct _GESTimelineFileSourceClass { struct _GESTimelineFileSourceClass {

View file

@ -43,6 +43,15 @@ GST_START_TEST (test_filesource_basic)
fail_unless (g_ascii_strcasecmp (uri, TEST_URI) == 0); fail_unless (g_ascii_strcasecmp (uri, TEST_URI) == 0);
g_free (uri); g_free (uri);
/* Make sure no track object is created for an incompatible
* track. */
trackobject =
ges_timeline_object_create_track_object (GES_TIMELINE_OBJECT (source),
track);
fail_unless (trackobject == NULL);
/* Make sure the track object is created for a compatible track. */
g_object_set (source, "supported-formats", GES_TRACK_TYPE_CUSTOM, NULL);
trackobject = trackobject =
ges_timeline_object_create_track_object (GES_TIMELINE_OBJECT (source), ges_timeline_object_create_track_object (GES_TIMELINE_OBJECT (source),
track); track);
@ -92,7 +101,8 @@ GST_START_TEST (test_filesource_properties)
/* Set some properties */ /* Set some properties */
g_object_set (object, "start", (guint64) 42, "duration", (guint64) 51, g_object_set (object, "start", (guint64) 42, "duration", (guint64) 51,
"in-point", (guint64) 12, NULL); "in-point", (guint64) 12, "supported-formats", GES_TRACK_TYPE_AUDIO,
NULL);
assert_equals_uint64 (GES_TIMELINE_OBJECT_START (object), 42); assert_equals_uint64 (GES_TIMELINE_OBJECT_START (object), 42);
assert_equals_uint64 (GES_TIMELINE_OBJECT_DURATION (object), 51); assert_equals_uint64 (GES_TIMELINE_OBJECT_DURATION (object), 51);
assert_equals_uint64 (GES_TIMELINE_OBJECT_INPOINT (object), 12); assert_equals_uint64 (GES_TIMELINE_OBJECT_INPOINT (object), 12);