GstCaps *current_caps;
gint64 size;
+ GstClockTime duration;
GstAppStreamType stream_type;
guint64 max_bytes;
GstFormat format;
#define DEFAULT_PROP_EMIT_SIGNALS TRUE
#define DEFAULT_PROP_MIN_PERCENT 0
#define DEFAULT_PROP_CURRENT_LEVEL_BYTES 0
+#define DEFAULT_PROP_DURATION GST_CLOCK_TIME_NONE
enum
{
PROP_EMIT_SIGNALS,
PROP_MIN_PERCENT,
PROP_CURRENT_LEVEL_BYTES,
+ PROP_DURATION,
PROP_LAST
};
0, G_MAXUINT64, DEFAULT_PROP_CURRENT_LEVEL_BYTES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ /**
+ * GstAppSrc::duration:
+ *
+ * The total duration in nanoseconds of the data stream. If the total duration is known, it
+ * is recommended to configure it with this property.
+ *
+ * Since: 1.10
+ */
+ g_object_class_install_property (gobject_class, PROP_DURATION,
+ g_param_spec_uint64 ("duration", "Duration",
+ "The duration of the data stream in nanoseconds (GST_CLOCK_TIME_NONE if unknown)",
+ 0, G_MAXUINT64, DEFAULT_PROP_DURATION,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstAppSrc::need-data:
priv->queue = g_queue_new ();
priv->size = DEFAULT_PROP_SIZE;
+ priv->duration = DEFAULT_PROP_DURATION;
priv->stream_type = DEFAULT_PROP_STREAM_TYPE;
priv->max_bytes = DEFAULT_PROP_MAX_BYTES;
priv->format = DEFAULT_PROP_FORMAT;
case PROP_MIN_PERCENT:
priv->min_percent = g_value_get_uint (value);
break;
+ case PROP_DURATION:
+ gst_app_src_set_duration (appsrc, g_value_get_uint64 (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
case PROP_CURRENT_LEVEL_BYTES:
g_value_set_uint64 (value, gst_app_src_get_current_level_bytes (appsrc));
break;
+ case PROP_DURATION:
+ g_value_set_uint64 (value, gst_app_src_get_duration (appsrc));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
if (format == GST_FORMAT_BYTES) {
gst_query_set_duration (query, format, priv->size);
res = TRUE;
+ } else if (format == GST_FORMAT_TIME) {
+ gst_query_set_duration (query, format, priv->duration);
+ res = TRUE;
} else {
res = FALSE;
}
gst_element_post_message (GST_ELEMENT (appsrc),
gst_message_new_duration_changed (GST_OBJECT (appsrc)));
+ } else if (G_UNLIKELY (priv->duration != bsrc->segment.duration &&
+ bsrc->segment.format == GST_FORMAT_TIME)) {
+ GST_DEBUG_OBJECT (appsrc,
+ "Duration changed from %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (bsrc->segment.duration), GST_TIME_ARGS (priv->duration));
+ bsrc->segment.duration = priv->duration;
+ GST_OBJECT_UNLOCK (appsrc);
+
+ gst_element_post_message (GST_ELEMENT (appsrc),
+ gst_message_new_duration_changed (GST_OBJECT (appsrc)));
} else {
GST_OBJECT_UNLOCK (appsrc);
}
}
/**
+ * gst_app_src_set_duration:
+ * @appsrc: a #GstAppSrc
+ * @duration: the duration to set
+ *
+ * Set the duration of the stream in nanoseconds. A value of GST_CLOCK_TIME_NONE means that the duration is
+ * not known.
+ *
+ * Since: 1.10
+ */
+void
+gst_app_src_set_duration (GstAppSrc * appsrc, GstClockTime duration)
+{
+ GstAppSrcPrivate *priv;
+
+ g_return_if_fail (GST_IS_APP_SRC (appsrc));
+
+ priv = appsrc->priv;
+
+ GST_OBJECT_LOCK (appsrc);
+ GST_DEBUG_OBJECT (appsrc, "setting duration of %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (duration));
+ priv->duration = duration;
+ GST_OBJECT_UNLOCK (appsrc);
+}
+
+/**
+ * gst_app_src_get_duration:
+ * @appsrc: a #GstAppSrc
+ *
+ * Get the duration of the stream in nanoseconds. A value of GST_CLOCK_TIME_NONE means that the duration is
+ * not known.
+ *
+ * Returns: the duration of the stream previously set with gst_app_src_set_duration();
+ *
+ * Since: 1.10
+ */
+GstClockTime
+gst_app_src_get_duration (GstAppSrc * appsrc)
+{
+ GstClockTime duration;
+ GstAppSrcPrivate *priv;
+
+ g_return_val_if_fail (GST_IS_APP_SRC (appsrc), GST_CLOCK_TIME_NONE);
+
+ priv = appsrc->priv;
+
+ GST_OBJECT_LOCK (appsrc);
+ duration = priv->duration;
+ GST_DEBUG_OBJECT (appsrc, "getting duration of %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (duration));
+ GST_OBJECT_UNLOCK (appsrc);
+
+ return duration;
+}
+
+/**
* gst_app_src_set_stream_type:
* @appsrc: a #GstAppSrc
* @type: the new state