Skip to content

Instantly share code, notes, and snippets.

@ndufresne
Created May 22, 2014 00:22
Show Gist options
  • Save ndufresne/8a663e3acf2fd77fb859 to your computer and use it in GitHub Desktop.
Save ndufresne/8a663e3acf2fd77fb859 to your computer and use it in GitHub Desktop.
From e538d4c244f01732ad89762e88990984f21368f7 Mon Sep 17 00:00:00 2001
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date: Wed, 21 May 2014 20:20:50 -0400
Subject: [PATCH] [FRC] multifilesrc: Add duration property
As multifilesrc can't figure-out, let the application tell the element the
duration of these files. This is done by adding two properties, duration
and duration-format.
---
gst/multifile/gstmultifilesrc.c | 41 +++++++++++++++++++++++++++++++++++++++--
gst/multifile/gstmultifilesrc.h | 2 ++
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/gst/multifile/gstmultifilesrc.c b/gst/multifile/gstmultifilesrc.c
index c1c1cf1..6189043 100644
--- a/gst/multifile/gstmultifilesrc.c
+++ b/gst/multifile/gstmultifilesrc.c
@@ -78,7 +78,9 @@ enum
ARG_START_INDEX,
ARG_STOP_INDEX,
ARG_CAPS,
- ARG_LOOP
+ ARG_LOOP,
+ ARG_DURATION,
+ ARG_DURATION_FORMAT
};
#define DEFAULT_LOCATION "%05d"
@@ -175,6 +177,16 @@ gst_multi_file_src_class_init (GstMultiFileSrcClass * klass)
g_param_spec_boolean ("loop", "Loop",
"Whether to repeat from the beginning when all files have been read.",
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_DURATION,
+ g_param_spec_uint64 ("duration", "Duration",
+ "Sets the duration of all files together.",
+ 0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_DURATION_FORMAT,
+ g_param_spec_enum ("duration-format", "Duration format",
+ "Set the format (see GstFormat) of the specified duration.",
+ GST_TYPE_FORMAT, GST_FORMAT_UNDEFINED,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gobject_class->dispose = gst_multi_file_src_dispose;
@@ -205,7 +217,7 @@ gst_multi_file_src_init (GstMultiFileSrc * multifilesrc)
multifilesrc->filename = g_strdup (DEFAULT_LOCATION);
multifilesrc->successful_read = FALSE;
multifilesrc->fps_n = multifilesrc->fps_d = -1;
-
+ multifilesrc->duration = GST_CLOCK_TIME_NONE;
}
static void
@@ -268,6 +280,19 @@ gst_multi_file_src_query (GstBaseSrc * src, GstQuery * query)
}
break;
}
+ case GST_QUERY_DURATION:
+ {
+ GstFormat format;
+ gst_query_parse_duration (query, &format, NULL);
+
+ if (format == mfsrc->duration_format) {
+ gst_query_set_duration (query, format, mfsrc->duration);
+ res = TRUE;
+ } else {
+ res = GST_BASE_SRC_CLASS (parent_class)->query (src, query);
+ }
+ break;
+ }
default:
res = GST_BASE_SRC_CLASS (parent_class)->query (src, query);
break;
@@ -336,6 +361,12 @@ gst_multi_file_src_set_property (GObject * object, guint prop_id,
case ARG_LOOP:
src->loop = g_value_get_boolean (value);
break;
+ case ARG_DURATION:
+ src->duration = g_value_get_uint64 (value);
+ break;
+ case ARG_DURATION_FORMAT:
+ src->duration_format = g_value_get_enum (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -367,6 +398,12 @@ gst_multi_file_src_get_property (GObject * object, guint prop_id,
case ARG_LOOP:
g_value_set_boolean (value, src->loop);
break;
+ case ARG_DURATION:
+ g_value_set_uint64 (value, src->duration);
+ break;
+ case ARG_DURATION_FORMAT:
+ g_value_set_enum (value, src->duration_format);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
diff --git a/gst/multifile/gstmultifilesrc.h b/gst/multifile/gstmultifilesrc.h
index 65b9730..e1c8a7a 100644
--- a/gst/multifile/gstmultifilesrc.h
+++ b/gst/multifile/gstmultifilesrc.h
@@ -58,6 +58,8 @@ struct _GstMultiFileSrc
gboolean successful_read;
gint fps_n, fps_d;
+ GstClockTime duration;
+ GstFormat duration_format;
};
struct _GstMultiFileSrcClass
--
1.9.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment