GstClockTimeDiff ts_offset;
gboolean do_timestamp;
+ volatile gint dynamic_size;
/* stream sequence number */
guint32 seqnum;
/* pending events (TAG, CUSTOM_BOTH, CUSTOM_DOWNSTREAM) to be
* pushed in the data stream */
- GList *pending_tags;
- volatile gint have_tags;
-
GList *pending_events;
volatile gint have_events;
static GstFlowReturn gst_base_src_get_range (GstBaseSrc * src, guint64 offset,
guint length, GstBuffer ** buf);
static gboolean gst_base_src_seekable (GstBaseSrc * src);
+static gboolean gst_base_src_update_length (GstBaseSrc * src, guint64 offset,
+ guint * length);
static void
gst_base_src_base_init (gpointer g_class)
basesrc->data.ABI.typefind = DEFAULT_TYPEFIND;
basesrc->priv->do_timestamp = DEFAULT_DO_TIMESTAMP;
g_atomic_int_set (&basesrc->priv->have_events, FALSE);
- g_atomic_int_set (&basesrc->priv->have_tags, FALSE);
GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
GST_OBJECT_FLAG_SET (basesrc, GST_ELEMENT_IS_SOURCE);
event_p = &basesrc->data.ABI.pending_seek;
gst_event_replace (event_p, NULL);
- if (basesrc->priv->pending_tags) {
- g_list_foreach (basesrc->priv->pending_tags, (GFunc) gst_event_unref, NULL);
- g_list_free (basesrc->priv->pending_tags);
- }
-
if (basesrc->priv->pending_events) {
g_list_foreach (basesrc->priv->pending_events, (GFunc) gst_event_unref,
NULL);
}
/**
+ * gst_base_src_set_dynamic_size:
+ * @src: base source instance
+ * @dynamic: new dynamic size mode
+ *
+ * If not @dynamic, size is only updated when needed, such as when trying to
+ * read past current tracked size. Otherwise, size is checked for upon each
+ * read.
+ *
+ * Since: 0.10.35
+ */
+void
+gst_base_src_set_dynamic_size (GstBaseSrc * src, gboolean dynamic)
+{
+ g_return_if_fail (GST_IS_BASE_SRC (src));
+
+ g_atomic_int_set (&src->priv->dynamic_size, dynamic);
+}
+
+/**
* gst_base_src_query_latency:
* @src: the source
* @live: (out) (allow-none): if the source is live
{
gint64 duration;
GstFormat seg_format;
+ guint length = 0;
+
+ /* may have to refresh duration */
+ if (g_atomic_int_get (&src->priv->dynamic_size))
+ gst_base_src_update_length (src, 0, &length);
- GST_OBJECT_LOCK (src);
/* this is the duration as configured by the subclass. */
+ GST_OBJECT_LOCK (src);
duration = src->segment.duration;
seg_format = src->segment.format;
GST_OBJECT_UNLOCK (src);
GstClockTime min, max;
gboolean live;
- /* Subclasses should override and implement something usefull */
+ /* Subclasses should override and implement something useful */
res = gst_base_src_query_latency (src, &live, &min, &max);
GST_LOG_OBJECT (src, "report latency: live %d, min %" GST_TIME_FORMAT
gboolean result = FALSE;
src = GST_BASE_SRC (gst_pad_get_parent (pad));
+ if (G_UNLIKELY (src == NULL))
+ return FALSE;
bclass = GST_BASE_SRC_GET_CLASS (src);
/* If we configured the seeksegment above, don't overwrite it now. Otherwise
* copy the current segment info into the temp segment that we can actually
- * attempt the seek with. We only update the real segment if the seek suceeds. */
+ * attempt the seek with. We only update the real segment if the seek succeeds. */
if (!seekseg_configured) {
memcpy (&seeksegment, &src->segment, sizeof (GstSegment));
* first and do EOS instead of entering it.
* - If we are in the _create function or we did not manage to set the
* flag fast enough and we are about to enter the _create function,
- * we unlock it so that we exit with WRONG_STATE immediatly. We then
+ * we unlock it so that we exit with WRONG_STATE immediately. We then
* check the EOS flag and do the EOS logic.
*/
g_atomic_int_set (&src->priv->pending_eos, TRUE);
/* sending random NEWSEGMENT downstream can break sync. */
break;
case GST_EVENT_TAG:
- /* Insert TAG in the dataflow */
- GST_OBJECT_LOCK (src);
- src->priv->pending_tags = g_list_append (src->priv->pending_tags, event);
- g_atomic_int_set (&src->priv->have_tags, TRUE);
- GST_OBJECT_UNLOCK (src);
- event = NULL;
- result = TRUE;
- break;
case GST_EVENT_CUSTOM_DOWNSTREAM:
case GST_EVENT_CUSTOM_BOTH:
- /* Insert CUSTOM_DOWNSTREAM, CUSTOM_BOTH in the dataflow */
+ /* Insert TAG, CUSTOM_DOWNSTREAM, CUSTOM_BOTH in the dataflow */
GST_OBJECT_LOCK (src);
src->priv->pending_events =
g_list_append (src->priv->pending_events, event);
gboolean result = FALSE;
src = GST_BASE_SRC (gst_pad_get_parent (pad));
+ if (G_UNLIKELY (src == NULL)) {
+ gst_event_unref (event);
+ return FALSE;
+ }
+
bclass = GST_BASE_SRC_GET_CLASS (src);
if (bclass->event) {
GstBaseSrcClass *bclass;
GstFormat format;
gint64 stop;
+ gboolean dynamic;
bclass = GST_BASE_SRC_GET_CLASS (src);
", segment.stop %" G_GINT64_FORMAT ", maxsize %" G_GINT64_FORMAT, offset,
*length, size, stop, maxsize);
+ dynamic = g_atomic_int_get (&src->priv->dynamic_size);
+ GST_DEBUG_OBJECT (src, "dynamic size: %d", dynamic);
+
/* check size if we have one */
if (maxsize != -1) {
/* if we run past the end, check if the file became bigger and
* retry. */
- if (G_UNLIKELY (offset + *length >= maxsize)) {
+ if (G_UNLIKELY (offset + *length >= maxsize || dynamic)) {
/* see if length of the file changed */
if (bclass->get_size)
if (!bclass->get_size (src, &size))
* segment is in bytes, we checked that above. */
GST_OBJECT_LOCK (src);
gst_segment_set_duration (&src->segment, GST_FORMAT_BYTES, size);
- gst_segment_set_last_stop (&src->segment, GST_FORMAT_BYTES, offset);
GST_OBJECT_UNLOCK (src);
return TRUE;
if (G_UNLIKELY (!gst_base_src_update_length (src, offset, &length)))
goto unexpected_length;
+ /* track position */
+ GST_OBJECT_LOCK (src);
+ if (src->segment.format == GST_FORMAT_BYTES)
+ gst_segment_set_last_stop (&src->segment, GST_FORMAT_BYTES, offset);
+ GST_OBJECT_UNLOCK (src);
+
/* normally we don't count buffers */
if (G_UNLIKELY (src->num_buffers_left >= 0)) {
if (src->num_buffers_left == 0)
/* no timestamp set and we are at offset 0, we can timestamp with 0 */
if (offset == 0 && src->segment.time == 0
- && GST_BUFFER_TIMESTAMP (*buf) == -1) {
+ && GST_BUFFER_TIMESTAMP (*buf) == -1 && !src->is_live) {
*buf = gst_buffer_make_metadata_writable (*buf);
GST_BUFFER_TIMESTAMP (*buf) = 0;
}
gint64 position;
gboolean eos;
gulong blocksize;
- GList *pending_tags = NULL, *pending_events = NULL, *tmp;
+ GList *pending_events = NULL, *tmp;
eos = FALSE;
}
src->priv->newsegment_pending = FALSE;
- if (g_atomic_int_get (&src->priv->have_tags)) {
- GST_OBJECT_LOCK (src);
- /* take the events */
- pending_tags = src->priv->pending_tags;
- src->priv->pending_tags = NULL;
- g_atomic_int_set (&src->priv->have_tags, FALSE);
- GST_OBJECT_UNLOCK (src);
- }
-
- /* Push out pending tags if any */
- if (G_UNLIKELY (pending_tags != NULL)) {
- for (tmp = pending_tags; tmp; tmp = g_list_next (tmp)) {
- GstEvent *ev = (GstEvent *) tmp->data;
- gst_pad_push_event (pad, ev);
- }
- g_list_free (pending_tags);
- }
-
if (g_atomic_int_get (&src->priv->have_events)) {
GST_OBJECT_LOCK (src);
/* take the events */
* already did this */
/* FIXME, deprecate this behaviour, it is very dangerous.
- * the prefered way of sending EOS downstream is by sending
+ * the preferred way of sending EOS downstream is by sending
* the EOS event to the element */
if (!basesrc->priv->last_sent_eos) {
GST_DEBUG_OBJECT (basesrc, "Sending EOS event");