* Copyright (C) 2008 Nokia Corporation. All rights reserved.
* Contact: Stefan Kost <stefan.kost@nokia.com>
* Copyright (C) 2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>.
+ * Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
+ * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* <listitem><para>
* Finally the buffer can be pushed downstream and the parsing loop starts
* over again. Just prior to actually pushing the buffer in question,
- * it is passed to @pre_push_buffer which gives subclass yet one
+ * it is passed to @pre_push_frame which gives subclass yet one
* last chance to examine buffer metadata, or to send some custom (tag)
* events, or to perform custom (segment) filtering.
* </para></listitem>
#include "gstbaseparse.h"
+/* FIXME: get rid of old GstIndex code */
+#include "gstindex.h"
+#include "gstindex.c"
+#include "gstmemindex.c"
+
#define GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC (1 << 0)
#define MIN_FRAMES_TO_POST_BITRATE 10
struct _GstBaseParsePrivate
{
- GstActivateMode pad_mode;
+ GstPadMode pad_mode;
GstAdapter *adapter;
gint64 duration;
GstFormat duration_fmt;
gint64 estimated_duration;
+ gint64 estimated_drift;
guint min_frame_size;
gboolean passthrough;
GstIndex *index;
gint index_id;
gboolean own_index;
- GStaticMutex index_lock;
+ GMutex index_lock;
/* seek table entries only maintained if upstream is BYTE seekable */
gboolean upstream_seekable;
/* push mode helper frame */
GstBaseParseFrame frame;
+
+ /* TRUE if we're still detecting the format, i.e.
+ * if ::detect() is still called for future buffers */
+ gboolean detecting;
+ GList *detect_buffers;
+ guint detect_buffers_size;
};
typedef struct _GstBaseParseSeek
GstClockTime start_ts;
} GstBaseParseSeek;
+#define GST_BASE_PARSE_INDEX_LOCK(parse) \
+ g_mutex_lock (&parse->priv->index_lock);
+#define GST_BASE_PARSE_INDEX_UNLOCK(parse) \
+ g_mutex_unlock (&parse->priv->index_lock);
+
static GstElementClass *parent_class = NULL;
static void gst_base_parse_class_init (GstBaseParseClass * klass);
GstStateChange transition);
static void gst_base_parse_reset (GstBaseParse * parse);
+#if 0
static void gst_base_parse_set_index (GstElement * element, GstIndex * index);
static GstIndex *gst_base_parse_get_index (GstElement * element);
+#endif
-static gboolean gst_base_parse_sink_activate (GstPad * sinkpad);
-static gboolean gst_base_parse_sink_activate_push (GstPad * pad,
- gboolean active);
-static gboolean gst_base_parse_sink_activate_pull (GstPad * pad,
- gboolean active);
+static gboolean gst_base_parse_sink_activate (GstPad * sinkpad,
+ GstObject * parent);
+static gboolean gst_base_parse_sink_activate_mode (GstPad * pad,
+ GstObject * parent, GstPadMode mode, gboolean active);
static gboolean gst_base_parse_handle_seek (GstBaseParse * parse,
GstEvent * event);
static void gst_base_parse_handle_tag (GstBaseParse * parse, GstEvent * event);
-static gboolean gst_base_parse_src_event (GstPad * pad, GstEvent * event);
-static gboolean gst_base_parse_sink_event (GstPad * pad, GstEvent * event);
-static gboolean gst_base_parse_query (GstPad * pad, GstQuery * query);
-static gboolean gst_base_parse_sink_setcaps (GstPad * pad, GstCaps * caps);
-static const GstQueryType *gst_base_parse_get_querytypes (GstPad * pad);
+static gboolean gst_base_parse_src_event (GstPad * pad, GstObject * parent,
+ GstEvent * event);
+static gboolean gst_base_parse_src_query (GstPad * pad, GstObject * parent,
+ GstQuery * query);
+
+static gboolean gst_base_parse_sink_event (GstPad * pad, GstObject * parent,
+ GstEvent * event);
+static gboolean gst_base_parse_sink_query (GstPad * pad, GstObject * parent,
+ GstQuery * query);
-static GstFlowReturn gst_base_parse_chain (GstPad * pad, GstBuffer * buffer);
+static GstFlowReturn gst_base_parse_chain (GstPad * pad, GstObject * parent,
+ GstBuffer * buffer);
static void gst_base_parse_loop (GstPad * pad);
static gboolean gst_base_parse_check_frame (GstBaseParse * parse,
g_slist_foreach (parse->priv->buffers_send, (GFunc) gst_buffer_unref, NULL);
g_slist_free (parse->priv->buffers_send);
parse->priv->buffers_send = NULL;
+
+ g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref, NULL);
+ g_list_free (parse->priv->detect_buffers);
+ parse->priv->detect_buffers = NULL;
+ parse->priv->detect_buffers_size = 0;
+
+ g_queue_foreach (&parse->priv->queued_frames,
+ (GFunc) gst_base_parse_frame_free, NULL);
+ g_queue_clear (&parse->priv->queued_frames);
}
static void
g_list_free (parse->priv->pending_events);
parse->priv->pending_events = NULL;
- g_queue_foreach (&parse->priv->queued_frames,
- (GFunc) gst_base_parse_frame_free, NULL);
- g_queue_clear (&parse->priv->queued_frames);
-
if (parse->priv->index) {
gst_object_unref (parse->priv->index);
parse->priv->index = NULL;
}
-
- g_static_mutex_free (&parse->priv->index_lock);
+ g_mutex_clear (&parse->priv->index_lock);
gst_base_parse_clear_queues (parse);
gstelement_class = (GstElementClass *) klass;
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_base_parse_change_state);
+
+#if 0
gstelement_class->set_index = GST_DEBUG_FUNCPTR (gst_base_parse_set_index);
gstelement_class->get_index = GST_DEBUG_FUNCPTR (gst_base_parse_get_index);
+#endif
/* Default handlers */
klass->check_valid_frame = gst_base_parse_check_frame;
parse->sinkpad = gst_pad_new_from_template (pad_template, "sink");
gst_pad_set_event_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_parse_sink_event));
- gst_pad_set_setcaps_function (parse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_base_parse_sink_setcaps));
+ gst_pad_set_query_function (parse->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_base_parse_sink_query));
gst_pad_set_chain_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_parse_chain));
gst_pad_set_activate_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_parse_sink_activate));
- gst_pad_set_activatepush_function (parse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_base_parse_sink_activate_push));
- gst_pad_set_activatepull_function (parse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_base_parse_sink_activate_pull));
+ gst_pad_set_activatemode_function (parse->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_base_parse_sink_activate_mode));
gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
GST_DEBUG_OBJECT (parse, "sinkpad created");
parse->srcpad = gst_pad_new_from_template (pad_template, "src");
gst_pad_set_event_function (parse->srcpad,
GST_DEBUG_FUNCPTR (gst_base_parse_src_event));
- gst_pad_set_query_type_function (parse->srcpad,
- GST_DEBUG_FUNCPTR (gst_base_parse_get_querytypes));
gst_pad_set_query_function (parse->srcpad,
- GST_DEBUG_FUNCPTR (gst_base_parse_query));
+ GST_DEBUG_FUNCPTR (gst_base_parse_src_query));
gst_pad_use_fixed_caps (parse->srcpad);
gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
GST_DEBUG_OBJECT (parse, "src created");
parse->priv->adapter = gst_adapter_new ();
- parse->priv->pad_mode = GST_ACTIVATE_NONE;
+ parse->priv->pad_mode = GST_PAD_MODE_NONE;
- g_static_mutex_init (&parse->priv->index_lock);
+ g_mutex_init (&parse->priv->index_lock);
/* init state */
gst_base_parse_reset (parse);
GST_DEBUG_OBJECT (parse, "init ok");
+
+ GST_OBJECT_FLAG_SET (parse, GST_ELEMENT_FLAG_INDEXABLE);
}
static GstBaseParseFrame *
}
}
-GType
-gst_base_parse_frame_get_type (void)
-{
- static volatile gsize frame_type = 0;
-
- if (g_once_init_enter (&frame_type)) {
- GType _type;
-
- _type = g_boxed_type_register_static ("GstBaseParseFrame",
- (GBoxedCopyFunc) gst_base_parse_frame_copy,
- (GBoxedFreeFunc) gst_base_parse_frame_free);
- g_once_init_leave (&frame_type, _type);
- }
- return (GType) frame_type;
-}
+G_DEFINE_BOXED_TYPE (GstBaseParseFrame, gst_base_parse_frame,
+ (GBoxedCopyFunc) gst_base_parse_frame_copy,
+ (GBoxedFreeFunc) gst_base_parse_frame_free);
/**
* gst_base_parse_frame_init:
parse->priv->first_frame_ts = GST_CLOCK_TIME_NONE;
parse->priv->first_frame_offset = -1;
parse->priv->estimated_duration = -1;
+ parse->priv->estimated_drift = 0;
parse->priv->next_ts = 0;
parse->priv->syncable = TRUE;
parse->priv->passthrough = FALSE;
g_slist_free (parse->priv->pending_seeks);
parse->priv->pending_seeks = NULL;
+ if (parse->priv->adapter)
+ gst_adapter_clear (parse->priv->adapter);
+
/* we know it is not alloc'ed, but maybe other stuff to free, some day ... */
parse->priv->frame._private_flags |=
GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC;
gst_base_parse_frame_free (&parse->priv->frame);
+
+ g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref, NULL);
+ g_list_free (parse->priv->detect_buffers);
+ parse->priv->detect_buffers = NULL;
+ parse->priv->detect_buffers_size = 0;
GST_OBJECT_UNLOCK (parse);
}
gst_base_parse_check_frame (GstBaseParse * parse,
GstBaseParseFrame * frame, guint * framesize, gint * skipsize)
{
- *framesize = GST_BUFFER_SIZE (frame->buffer);
+ *framesize = gst_buffer_get_size (frame->buffer);
*skipsize = 0;
return TRUE;
}
* Returns: TRUE if the event was handled.
*/
static gboolean
-gst_base_parse_sink_event (GstPad * pad, GstEvent * event)
+gst_base_parse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
GstBaseParse *parse;
GstBaseParseClass *bclass;
gboolean handled = FALSE;
gboolean ret = TRUE;
- parse = GST_BASE_PARSE (gst_pad_get_parent (pad));
+ parse = GST_BASE_PARSE (parent);
bclass = GST_BASE_PARSE_GET_CLASS (parse);
GST_DEBUG_OBJECT (parse, "handling event %d, %s", GST_EVENT_TYPE (event),
GST_EVENT_TYPE_NAME (event));
- /* Cache all events except EOS, NEWSEGMENT and FLUSH_STOP if we have a
+ /* Cache all events except EOS, SEGMENT and FLUSH_STOP if we have a
* pending segment */
if (parse->priv->pending_segment && GST_EVENT_TYPE (event) != GST_EVENT_EOS
- && GST_EVENT_TYPE (event) != GST_EVENT_NEWSEGMENT
+ && GST_EVENT_TYPE (event) != GST_EVENT_SEGMENT
&& GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_START
- && GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP) {
+ && GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP
+ && GST_EVENT_TYPE (event) != GST_EVENT_CAPS) {
if (GST_EVENT_TYPE (event) == GST_EVENT_TAG)
/* See if any bitrate tags were posted */
handled = gst_base_parse_sink_eventfunc (parse, event);
if (!handled)
- ret = gst_pad_event_default (pad, event);
+ ret = gst_pad_event_default (pad, parent, event);
}
- gst_object_unref (parse);
GST_DEBUG_OBJECT (parse, "event handled");
+
return ret;
}
GstEvent **eventp;
switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_NEWSEGMENT:
+ case GST_EVENT_CAPS:
+ {
+ GstCaps *caps;
+ GstBaseParseClass *klass;
+
+ klass = GST_BASE_PARSE_GET_CLASS (parse);
+
+ gst_event_parse_caps (event, &caps);
+ GST_DEBUG_OBJECT (parse, "caps: %" GST_PTR_FORMAT, caps);
+
+ if (klass->set_sink_caps)
+ klass->set_sink_caps (parse, caps);
+
+ /* will send our own caps downstream */
+ gst_event_unref (event);
+ handled = TRUE;
+ break;
+ }
+ case GST_EVENT_SEGMENT:
{
+ const GstSegment *in_segment;
+ GstSegment out_segment;
+ gint64 offset = 0, next_ts;
+
+#if 0
gdouble rate, applied_rate;
GstFormat format;
- gint64 start, stop, pos, next_ts, offset = 0;
+ gint64 start, stop, pos, next_ts;
gboolean update;
+#endif
- gst_event_parse_new_segment_full (event, &update, &rate, &applied_rate,
- &format, &start, &stop, &pos);
+ gst_event_parse_segment (event, &in_segment);
+ gst_segment_init (&out_segment, GST_FORMAT_TIME);
- GST_DEBUG_OBJECT (parse, "newseg rate %g, applied rate %g, "
- "format %d, start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT
- ", pos = %" GST_TIME_FORMAT, rate, applied_rate, format,
- GST_TIME_ARGS (start), GST_TIME_ARGS (stop), GST_TIME_ARGS (pos));
+ GST_DEBUG_OBJECT (parse, "segment %" GST_SEGMENT_FORMAT, in_segment);
- if (format == GST_FORMAT_BYTES) {
- GstClockTime seg_start, seg_stop;
+ if (in_segment->format == GST_FORMAT_BYTES) {
GstBaseParseSeek *seek = NULL;
GSList *node;
/* stop time is allowed to be open-ended, but not start & pos */
- seg_stop = GST_CLOCK_TIME_NONE;
- seg_start = 0;
- offset = pos;
+ offset = in_segment->time;
GST_OBJECT_LOCK (parse);
for (node = parse->priv->pending_seeks; node; node = node->next) {
GstBaseParseSeek *tmp = node->data;
- if (tmp->offset == pos) {
+ if (tmp->offset == offset) {
seek = tmp;
break;
}
GST_DEBUG_OBJECT (parse,
"Matched newsegment to%s seek: %" GST_SEGMENT_FORMAT,
seek->accurate ? " accurate" : "", &seek->segment);
- seg_start = seek->segment.start;
- seg_stop = seek->segment.stop;
+
+ out_segment.start = seek->segment.start;
+ out_segment.stop = seek->segment.stop;
+ out_segment.time = seek->segment.start;
+
next_ts = seek->start_ts;
parse->priv->exact_position = seek->accurate;
g_free (seek);
/* best attempt convert */
/* as these are only estimates, stop is kept open-ended to avoid
* premature cutting */
- gst_base_parse_convert (parse, GST_FORMAT_BYTES, start,
- GST_FORMAT_TIME, (gint64 *) & seg_start);
- parse->priv->exact_position = (start == 0);
- next_ts = seg_start;
+ gst_base_parse_convert (parse, GST_FORMAT_BYTES, in_segment->start,
+ GST_FORMAT_TIME, (gint64 *) & next_ts);
+
+ out_segment.start = next_ts;
+ out_segment.stop = GST_CLOCK_TIME_NONE;
+ out_segment.time = next_ts;
+
+ parse->priv->exact_position = (in_segment->start == 0);
}
gst_event_unref (event);
- event = gst_event_new_new_segment_full (update, rate, applied_rate,
- GST_FORMAT_TIME, seg_start, seg_stop, seg_start);
- format = GST_FORMAT_TIME;
- start = seg_start;
- stop = seg_stop;
- GST_DEBUG_OBJECT (parse, "Converted incoming segment to TIME. "
- "start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT,
- GST_TIME_ARGS (seg_start), GST_TIME_ARGS (seg_stop));
- } else if (format != GST_FORMAT_TIME) {
+
+ event = gst_event_new_segment (&out_segment);
+
+ GST_DEBUG_OBJECT (parse, "Converted incoming segment to TIME. %"
+ GST_SEGMENT_FORMAT, in_segment);
+
+ } else if (in_segment->format != GST_FORMAT_TIME) {
/* Unknown incoming segment format. Output a default open-ended
* TIME segment */
gst_event_unref (event);
- event = gst_event_new_new_segment_full (update, rate, applied_rate,
- GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, 0);
- format = GST_FORMAT_TIME;
- next_ts = start = 0;
- stop = GST_CLOCK_TIME_NONE;
+
+ out_segment.start = 0;
+ out_segment.stop = GST_CLOCK_TIME_NONE;;
+ out_segment.time = 0;;
+
+ event = gst_event_new_segment (&out_segment);
+
+ next_ts = 0;
} else {
/* not considered BYTE seekable if it is talking to us in TIME,
* whatever else it might claim */
parse->priv->upstream_seekable = FALSE;
- next_ts = start;
+ next_ts = in_segment->start;
}
- gst_segment_set_newsegment_full (&parse->segment, update, rate,
- applied_rate, format, start, stop, start);
+ memcpy (&parse->segment, &out_segment, sizeof (GstSegment));
+
+ /*
+ gst_segment_set_newsegment (&parse->segment, update, rate,
+ applied_rate, format, start, stop, start);
+ */
/* save the segment for later, right before we push a new buffer so that
* the caps are fixed and the next linked element can receive
/* but finish the current segment */
GST_DEBUG_OBJECT (parse, "draining current segment");
- if (parse->segment.rate > 0.0)
+ if (in_segment->rate > 0.0)
gst_base_parse_drain (parse);
else
gst_base_parse_process_fragment (parse, FALSE);
gst_adapter_clear (parse->priv->adapter);
+
parse->priv->offset = offset;
parse->priv->sync_offset = offset;
parse->priv->next_ts = next_ts;
return handled;
}
+static gboolean
+gst_base_parse_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
+{
+ GstBaseParse *parse;
+ GstBaseParseClass *bclass;
+ gboolean res;
+
+ parse = GST_BASE_PARSE (parent);
+ bclass = GST_BASE_PARSE_GET_CLASS (parse);
+
+ switch (GST_QUERY_TYPE (query)) {
+ case GST_QUERY_CAPS:
+ {
+ if (bclass->get_sink_caps) {
+ GstCaps *caps, *filter;
+
+ gst_query_parse_caps (query, &filter);
+ caps = bclass->get_sink_caps (parse, filter);
+ GST_LOG_OBJECT (parse, "sink getcaps returning caps %" GST_PTR_FORMAT,
+ caps);
+ gst_query_set_caps_result (query, caps);
+ gst_caps_unref (caps);
+
+ res = TRUE;
+ } else {
+ GstCaps *caps, *template_caps, *filter;
+
+ gst_query_parse_caps (query, &filter);
+ template_caps = gst_pad_get_pad_template_caps (pad);
+ if (filter != NULL) {
+ caps =
+ gst_caps_intersect_full (filter, template_caps,
+ GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref (template_caps);
+ } else {
+ caps = template_caps;
+ }
+ gst_query_set_caps_result (query, caps);
+ gst_caps_unref (caps);
+
+ res = TRUE;
+ }
+ break;
+ }
+ default:
+ {
+ res = gst_pad_query_default (pad, parent, query);
+ break;
+ }
+ }
+
+ return res;
+}
+
/* gst_base_parse_src_event:
* @pad: #GstPad that received the event.
* Returns: TRUE if the event was handled.
*/
static gboolean
-gst_base_parse_src_event (GstPad * pad, GstEvent * event)
+gst_base_parse_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
GstBaseParse *parse;
GstBaseParseClass *bclass;
gboolean handled = FALSE;
gboolean ret = TRUE;
- parse = GST_BASE_PARSE (gst_pad_get_parent (pad));
+ parse = GST_BASE_PARSE (parent);
bclass = GST_BASE_PARSE_GET_CLASS (parse);
GST_DEBUG_OBJECT (parse, "event %d, %s", GST_EVENT_TYPE (event),
handled = bclass->src_event (parse, event);
if (!handled)
- ret = gst_pad_event_default (pad, event);
+ ret = gst_pad_event_default (pad, parent, event);
- gst_object_unref (parse);
return ret;
}
peer = gst_pad_get_peer (parse->sinkpad);
if (peer) {
- GstFormat pformat = GST_FORMAT_BYTES;
gboolean qres = FALSE;
gint64 ptot, dest_value;
- qres = gst_pad_query_duration (peer, &pformat, &ptot);
+ qres = gst_pad_query_duration (peer, GST_FORMAT_BYTES, &ptot);
gst_object_unref (GST_OBJECT (peer));
if (qres) {
- if (gst_base_parse_convert (parse, pformat, ptot,
+ if (gst_base_parse_convert (parse, GST_FORMAT_BYTES, ptot,
GST_FORMAT_TIME, &dest_value)) {
+
+ /* inform if duration changed, but try to avoid spamming */
+ parse->priv->estimated_drift +=
+ dest_value - parse->priv->estimated_duration;
+ if (parse->priv->estimated_drift > GST_SECOND ||
+ parse->priv->estimated_drift < -GST_SECOND) {
+ gst_element_post_message (GST_ELEMENT (parse),
+ gst_message_new_duration (GST_OBJECT (parse),
+ GST_FORMAT_TIME, dest_value));
+ parse->priv->estimated_drift = 0;
+ }
parse->priv->estimated_duration = dest_value;
GST_LOG_OBJECT (parse,
"updated estimated duration to %" GST_TIME_FORMAT,
GstTagList *taglist = NULL;
if (post_min && parse->priv->post_min_bitrate) {
- taglist = gst_tag_list_new ();
+ taglist = gst_tag_list_new_empty ();
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
GST_TAG_MINIMUM_BITRATE, parse->priv->min_bitrate, NULL);
if (post_avg && parse->priv->post_avg_bitrate) {
if (taglist == NULL)
- taglist = gst_tag_list_new ();
+ taglist = gst_tag_list_new_empty ();
parse->priv->posted_avg_bitrate = parse->priv->avg_bitrate;
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_BITRATE,
if (post_max && parse->priv->post_max_bitrate) {
if (taglist == NULL)
- taglist = gst_tag_list_new ();
+ taglist = gst_tag_list_new_empty ();
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
GST_TAG_MAXIMUM_BITRATE, parse->priv->max_bitrate, NULL);
parse->priv->max_bitrate);
if (taglist != NULL) {
- gst_element_found_tags_for_pad (GST_ELEMENT_CAST (parse), parse->srcpad,
- taglist);
+ gst_pad_push_event (parse->srcpad, gst_event_new_tag (taglist));
}
}
if (overhead == -1)
return;
- data_len = GST_BUFFER_SIZE (buffer) - overhead;
+ data_len = gst_buffer_get_size (buffer) - overhead;
parse->priv->data_bytecount += data_len;
/* duration should be valid by now,
associations[1].value = offset;
/* index might change on-the-fly, although that would be nutty app ... */
- g_static_mutex_lock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_LOCK (parse);
gst_index_add_associationv (parse->priv->index, parse->priv->index_id,
- (key) ? GST_ASSOCIATION_FLAG_KEY_UNIT : GST_ASSOCIATION_FLAG_DELTA_UNIT,
- 2, (const GstIndexAssociation *) &associations);
- g_static_mutex_unlock (&parse->priv->index_lock);
+ (key) ? GST_INDEX_ASSOCIATION_FLAG_KEY_UNIT :
+ GST_INDEX_ASSOCIATION_FLAG_DELTA_UNIT, 2,
+ (const GstIndexAssociation *) &associations);
+ GST_BASE_PARSE_INDEX_UNLOCK (parse);
if (key) {
parse->priv->index_last_offset = offset;
/* try harder to query upstream size if we didn't get it the first time */
if (seekable && stop == -1) {
- GstFormat fmt = GST_FORMAT_BYTES;
-
GST_DEBUG_OBJECT (parse, "doing duration query to fix up unset stop");
- gst_pad_query_peer_duration (parse->sinkpad, &fmt, &stop);
+ gst_pad_peer_query_duration (parse->sinkpad, GST_FORMAT_BYTES, &stop);
}
/* if upstream doesn't know the size, it's likely that it's not seekable in
static void
gst_base_parse_check_upstream (GstBaseParse * parse)
{
- GstFormat fmt = GST_FORMAT_TIME;
gint64 stop;
- if (gst_pad_query_peer_duration (parse->sinkpad, &fmt, &stop))
+ if (gst_pad_peer_query_duration (parse->sinkpad, GST_FORMAT_TIME, &stop))
if (GST_CLOCK_TIME_IS_VALID (stop) && stop) {
/* upstream has one, accept it also, and no further updates */
gst_base_parse_set_duration (parse, GST_FORMAT_TIME, stop, 0);
GstCaps *caps;
GstStructure *s;
- caps = GST_PAD_CAPS (parse->srcpad);
+ caps = gst_pad_get_current_caps (parse->srcpad);
if (G_LIKELY (caps) && (s = gst_caps_get_structure (caps, 0))) {
parse->priv->is_video =
g_str_has_prefix (gst_structure_get_name (s), "video");
/* historical default */
parse->priv->is_video = FALSE;
}
+ if (caps)
+ gst_caps_unref (caps);
GST_DEBUG_OBJECT (parse, "media is video: %d", parse->priv->is_video);
}
GST_LOG_OBJECT (parse,
"parsing frame at offset %" G_GUINT64_FORMAT
- " (%#" G_GINT64_MODIFIER "x) of size %d",
+ " (%#" G_GINT64_MODIFIER "x) of size %" G_GSIZE_FORMAT,
GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET (buffer),
- GST_BUFFER_SIZE (buffer));
+ gst_buffer_get_size (buffer));
/* use default handler to provide initial (upstream) metadata */
gst_base_parse_parse_frame (parse, frame);
* If so, that allows and enables extra seek and duration determining options */
if (G_UNLIKELY (parse->priv->first_frame_offset < 0 && ret == GST_FLOW_OK)) {
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) && parse->priv->has_timing_info
- && parse->priv->pad_mode == GST_ACTIVATE_PULL) {
+ && parse->priv->pad_mode == GST_PAD_MODE_PULL) {
parse->priv->first_frame_offset = offset;
parse->priv->first_frame_ts = GST_BUFFER_TIMESTAMP (buffer);
GST_DEBUG_OBJECT (parse, "subclass provided ts %" GST_TIME_FORMAT
GstBaseParseFrame *queued_frame;
while ((queued_frame = g_queue_pop_head (&parse->priv->queued_frames))) {
- queued_frame->buffer =
- gst_buffer_make_metadata_writable (queued_frame->buffer);
- gst_buffer_set_caps (queued_frame->buffer,
- GST_PAD_CAPS (GST_BASE_PARSE_SRC_PAD (parse)));
gst_base_parse_push_frame (parse, queued_frame);
- gst_base_parse_frame_free (queued_frame);
}
}
GstClockTime last_stop = GST_CLOCK_TIME_NONE;
GstBaseParseClass *klass = GST_BASE_PARSE_GET_CLASS (parse);
GstBuffer *buffer;
+ gsize size;
g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (frame->buffer != NULL, GST_FLOW_ERROR);
buffer = frame->buffer;
GST_LOG_OBJECT (parse,
- "processing buffer of size %d with ts %" GST_TIME_FORMAT
- ", duration %" GST_TIME_FORMAT, GST_BUFFER_SIZE (buffer),
+ "processing buffer of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT
+ ", duration %" GST_TIME_FORMAT, gst_buffer_get_size (buffer),
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
/* update stats */
- parse->priv->bytecount += GST_BUFFER_SIZE (buffer);
+ size = gst_buffer_get_size (buffer);
+ parse->priv->bytecount += size;
if (G_LIKELY (!(frame->flags & GST_BASE_PARSE_FRAME_FLAG_NO_FRAME))) {
parse->priv->framecount++;
if (GST_BUFFER_DURATION_IS_VALID (buffer)) {
last_stop = last_start + GST_BUFFER_DURATION (buffer);
/* should have caps by now */
- g_return_val_if_fail (GST_PAD_CAPS (parse->srcpad), GST_FLOW_ERROR);
+ if (!gst_pad_has_current_caps (parse->srcpad))
+ goto no_caps;
/* segment adjustment magic; only if we are running the whole show */
if (!parse->priv->passthrough && parse->segment.rate > 0.0 &&
- (parse->priv->pad_mode == GST_ACTIVATE_PULL ||
+ (parse->priv->pad_mode == GST_PAD_MODE_PULL ||
parse->priv->upstream_seekable)) {
/* segment times are typically estimates,
* actual frame data might lead subclass to different timestamps,
gst_event_unref (parse->priv->pending_segment);
parse->segment.start =
MIN ((guint64) last_start, (guint64) parse->segment.stop);
+
GST_DEBUG_OBJECT (parse,
"adjusting pending segment start to %" GST_TIME_FORMAT,
GST_TIME_ARGS (parse->segment.start));
- parse->priv->pending_segment =
- gst_event_new_new_segment (FALSE, parse->segment.rate,
- parse->segment.format, parse->segment.start,
- parse->segment.stop, parse->segment.start);
+
+ parse->priv->pending_segment = gst_event_new_segment (&parse->segment);
}
/* handle gaps, e.g. non-zero start-time, in as much not handled by above */
- if (GST_CLOCK_TIME_IS_VALID (parse->segment.last_stop) &&
+ if (GST_CLOCK_TIME_IS_VALID (parse->segment.position) &&
GST_CLOCK_TIME_IS_VALID (last_start)) {
GstClockTimeDiff diff;
/* only send newsegments with increasing start times,
* otherwise if these go back and forth downstream (sinks) increase
* accumulated time and running_time */
- diff = GST_CLOCK_DIFF (parse->segment.last_stop, last_start);
+ diff = GST_CLOCK_DIFF (parse->segment.position, last_start);
if (G_UNLIKELY (diff > 2 * GST_SECOND
&& last_start > parse->segment.start
&& (!GST_CLOCK_TIME_IS_VALID (parse->segment.stop)
|| last_start < parse->segment.stop))) {
+
GST_DEBUG_OBJECT (parse,
"Gap of %" G_GINT64_FORMAT " ns detected in stream " "(%"
GST_TIME_FORMAT " -> %" GST_TIME_FORMAT "). "
"Sending updated NEWSEGMENT events", diff,
- GST_TIME_ARGS (parse->segment.last_stop),
+ GST_TIME_ARGS (parse->segment.position),
GST_TIME_ARGS (last_start));
+
if (G_UNLIKELY (parse->priv->pending_segment)) {
gst_event_unref (parse->priv->pending_segment);
parse->segment.start = last_start;
+ parse->segment.time = last_start;
parse->priv->pending_segment =
- gst_event_new_new_segment (FALSE, parse->segment.rate,
- parse->segment.format, parse->segment.start,
- parse->segment.stop, parse->segment.start);
+ gst_event_new_segment (&parse->segment);
} else {
- /* send newsegment events such that the gap is not accounted in
- * accum time, hence running_time */
- /* close ahead of gap */
- gst_pad_push_event (parse->srcpad,
- gst_event_new_new_segment (TRUE, parse->segment.rate,
- parse->segment.format, parse->segment.last_stop,
- parse->segment.last_stop, parse->segment.last_stop));
- /* skip gap */
+ /* skip gap FIXME */
gst_pad_push_event (parse->srcpad,
- gst_event_new_new_segment (FALSE, parse->segment.rate,
- parse->segment.format, last_start,
- parse->segment.stop, last_start));
+ gst_event_new_segment (&parse->segment));
}
- /* align segment view with downstream,
- * prevents double-counting accum when closing segment */
- gst_segment_set_newsegment (&parse->segment, FALSE,
- parse->segment.rate, parse->segment.format, last_start,
- parse->segment.stop, last_start);
- parse->segment.last_stop = last_start;
+ parse->segment.position = last_start;
}
}
}
parse->priv->pending_segment = NULL;
GST_DEBUG_OBJECT (parse, "%s push pending segment",
- parse->priv->pad_mode == GST_ACTIVATE_PULL ? "loop" : "chain");
+ parse->priv->pad_mode == GST_PAD_MODE_PULL ? "loop" : "chain");
gst_pad_push_event (parse->srcpad, pending_segment);
/* have caps; check identity */
/* subclass must play nice */
g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
- /* decorate */
- buffer = gst_buffer_make_metadata_writable (buffer);
- gst_buffer_set_caps (buffer, GST_PAD_CAPS (parse->srcpad));
-
parse->priv->seen_keyframe |= parse->priv->is_video &&
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
GST_BUFFER_TIMESTAMP (buffer) >
parse->segment.stop + parse->priv->lead_out_ts) {
GST_LOG_OBJECT (parse, "Dropped frame, after segment");
- ret = GST_FLOW_UNEXPECTED;
+ ret = GST_FLOW_EOS;
} else if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) &&
GST_BUFFER_DURATION_IS_VALID (buffer) &&
GST_CLOCK_TIME_IS_VALID (parse->segment.start) &&
}
if (ret == GST_BASE_PARSE_FLOW_DROPPED) {
- GST_LOG_OBJECT (parse, "frame (%d bytes) dropped",
- GST_BUFFER_SIZE (buffer));
+ GST_LOG_OBJECT (parse, "frame (%" G_GSIZE_FORMAT " bytes) dropped", size);
gst_buffer_unref (buffer);
ret = GST_FLOW_OK;
} else if (ret == GST_FLOW_OK) {
if (parse->segment.rate > 0.0) {
- GST_LOG_OBJECT (parse, "pushing frame (%d bytes) now..",
- GST_BUFFER_SIZE (buffer));
+ GST_LOG_OBJECT (parse, "pushing frame (%" G_GSIZE_FORMAT " bytes) now..",
+ size);
ret = gst_pad_push (parse->srcpad, buffer);
GST_LOG_OBJECT (parse, "frame pushed, flow %s", gst_flow_get_name (ret));
} else {
- GST_LOG_OBJECT (parse, "frame (%d bytes) queued for now",
- GST_BUFFER_SIZE (buffer));
+ GST_LOG_OBJECT (parse, "frame (%" G_GSIZE_FORMAT " bytes) queued for now",
+ size);
parse->priv->buffers_queued =
g_slist_prepend (parse->priv->buffers_queued, buffer);
ret = GST_FLOW_OK;
}
} else {
- GST_LOG_OBJECT (parse, "frame (%d bytes) not pushed: %s",
- GST_BUFFER_SIZE (buffer), gst_flow_get_name (ret));
+ GST_LOG_OBJECT (parse, "frame (%" G_GSIZE_FORMAT " bytes) not pushed: %s",
+ size, gst_flow_get_name (ret));
gst_buffer_unref (buffer);
/* if we are not sufficiently in control, let upstream decide on EOS */
- if (ret == GST_FLOW_UNEXPECTED &&
+ if (ret == GST_FLOW_EOS &&
(parse->priv->passthrough ||
- (parse->priv->pad_mode == GST_ACTIVATE_PUSH &&
+ (parse->priv->pad_mode == GST_PAD_MODE_PUSH &&
!parse->priv->upstream_seekable)))
ret = GST_FLOW_OK;
}
/* Update current running segment position */
if (ret == GST_FLOW_OK && last_stop != GST_CLOCK_TIME_NONE &&
- parse->segment.last_stop < last_stop)
- gst_segment_set_last_stop (&parse->segment, GST_FORMAT_TIME, last_stop);
+ parse->segment.position < last_stop)
+ parse->segment.position = last_stop;
gst_base_parse_frame_free (frame);
return ret;
+
+ /* ERRORS */
+no_caps:
+ {
+ GST_ELEMENT_ERROR (parse, STREAM, DECODE, ("No caps set"), (NULL));
+ return GST_FLOW_ERROR;
+ }
}
if (!avail)
break;
- if (gst_base_parse_chain (parse->sinkpad, NULL) != GST_FLOW_OK) {
+ if (gst_base_parse_chain (parse->sinkpad, GST_OBJECT_CAST (parse),
+ NULL) != GST_FLOW_OK) {
break;
}
parse->priv->buffers_pending = g_slist_reverse (parse->priv->buffers_pending);
while (parse->priv->buffers_pending) {
buf = GST_BUFFER_CAST (parse->priv->buffers_pending->data);
- GST_LOG_OBJECT (parse, "adding pending buffer (size %d)",
- GST_BUFFER_SIZE (buf));
+ GST_LOG_OBJECT (parse, "adding pending buffer (size %" G_GSIZE_FORMAT ")",
+ gst_buffer_get_size (buf));
gst_adapter_push (parse->priv->adapter, buf);
parse->priv->buffers_pending =
g_slist_delete_link (parse->priv->buffers_pending,
* ok if taken from subclass or upstream */
parse->priv->next_ts = GST_CLOCK_TIME_NONE;
/* prevent it hanging around stop all the time */
- parse->segment.last_stop = GST_CLOCK_TIME_NONE;
+ parse->segment.position = GST_CLOCK_TIME_NONE;
/* mark next run */
parse->priv->discont = TRUE;
/* any trailing unused no longer usable (ideally none) */
if (G_UNLIKELY (gst_adapter_available (parse->priv->adapter))) {
- GST_DEBUG_OBJECT (parse, "discarding %d trailing bytes",
+ GST_DEBUG_OBJECT (parse, "discarding %" G_GSIZE_FORMAT " trailing bytes",
gst_adapter_available (parse->priv->adapter));
gst_adapter_clear (parse->priv->adapter);
}
}
static GstFlowReturn
-gst_base_parse_chain (GstPad * pad, GstBuffer * buffer)
+gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{
GstBaseParseClass *bclass;
GstBaseParse *parse;
GstClockTime timestamp;
GstBaseParseFrame *frame;
- parse = GST_BASE_PARSE (GST_OBJECT_PARENT (pad));
+ parse = GST_BASE_PARSE (parent);
bclass = GST_BASE_PARSE_GET_CLASS (parse);
+
+ if (parse->priv->detecting) {
+ GstBuffer *detect_buf;
+
+ if (parse->priv->detect_buffers_size == 0) {
+ detect_buf = gst_buffer_ref (buffer);
+ } else {
+ GList *l;
+ guint offset = 0;
+
+ detect_buf = gst_buffer_new ();
+
+ for (l = parse->priv->detect_buffers; l; l = l->next) {
+ gsize tmpsize = gst_buffer_get_size (l->data);
+
+ gst_buffer_copy_into (detect_buf, GST_BUFFER_CAST (l->data),
+ GST_BUFFER_COPY_MEMORY, offset, tmpsize);
+ offset += tmpsize;
+ }
+ if (buffer)
+ gst_buffer_copy_into (detect_buf, buffer, GST_BUFFER_COPY_MEMORY,
+ offset, gst_buffer_get_size (buffer));
+ }
+
+ ret = bclass->detect (parse, detect_buf);
+ gst_buffer_unref (detect_buf);
+
+ if (ret == GST_FLOW_OK) {
+ GList *l;
+
+ /* Detected something */
+ parse->priv->detecting = FALSE;
+
+ for (l = parse->priv->detect_buffers; l; l = l->next) {
+ if (ret == GST_FLOW_OK && !parse->priv->flushing)
+ ret =
+ gst_base_parse_chain (GST_BASE_PARSE_SINK_PAD (parse),
+ parent, GST_BUFFER_CAST (l->data));
+ else
+ gst_buffer_unref (GST_BUFFER_CAST (l->data));
+ }
+ g_list_free (parse->priv->detect_buffers);
+ parse->priv->detect_buffers = NULL;
+ parse->priv->detect_buffers_size = 0;
+
+ if (ret != GST_FLOW_OK) {
+ return ret;
+ }
+
+ /* Handle the current buffer */
+ } else if (ret == GST_FLOW_NOT_NEGOTIATED) {
+ /* Still detecting, append buffer or error out if draining */
+
+ if (parse->priv->drain) {
+ GST_DEBUG_OBJECT (parse, "Draining but did not detect format yet");
+ return GST_FLOW_ERROR;
+ } else if (parse->priv->flushing) {
+ g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref,
+ NULL);
+ g_list_free (parse->priv->detect_buffers);
+ parse->priv->detect_buffers = NULL;
+ parse->priv->detect_buffers_size = 0;
+ } else {
+ parse->priv->detect_buffers =
+ g_list_append (parse->priv->detect_buffers, buffer);
+ parse->priv->detect_buffers_size += gst_buffer_get_size (buffer);
+ return GST_FLOW_OK;
+ }
+ } else {
+ /* Something went wrong, subclass responsible for error reporting */
+ return ret;
+ }
+
+ /* And now handle the current buffer if detection worked */
+ }
+
frame = &parse->priv->frame;
if (G_LIKELY (buffer)) {
- GST_LOG_OBJECT (parse, "buffer size: %d, offset = %" G_GINT64_FORMAT,
- GST_BUFFER_SIZE (buffer), GST_BUFFER_OFFSET (buffer));
+ GST_LOG_OBJECT (parse,
+ "buffer size: %" G_GSIZE_FORMAT ", offset = %" G_GINT64_FORMAT,
+ gst_buffer_get_size (buffer), GST_BUFFER_OFFSET (buffer));
if (G_UNLIKELY (parse->priv->passthrough)) {
gst_base_parse_frame_init (frame);
- frame->buffer = gst_buffer_make_metadata_writable (buffer);
+ frame->buffer = gst_buffer_make_writable (buffer);
return gst_base_parse_push_frame (parse, frame);
}
/* upstream feeding us in reverse playback;
}
/* always pass all available data */
- data = gst_adapter_peek (parse->priv->adapter, av);
- GST_BUFFER_DATA (tmpbuf) = (guint8 *) data;
- GST_BUFFER_SIZE (tmpbuf) = av;
+ data = gst_adapter_map (parse->priv->adapter, av);
+ gst_buffer_take_memory (tmpbuf, -1,
+ gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
+ (gpointer) data, NULL, av, 0, av));
GST_BUFFER_OFFSET (tmpbuf) = parse->priv->offset;
- GST_BUFFER_FLAG_SET (tmpbuf, GST_MINI_OBJECT_FLAG_READONLY);
if (parse->priv->discont) {
GST_DEBUG_OBJECT (parse, "marking DISCONT");
skip = -1;
gst_base_parse_frame_update (parse, frame, tmpbuf);
res = bclass->check_valid_frame (parse, frame, &fsize, &skip);
+ gst_adapter_unmap (parse->priv->adapter);
gst_buffer_replace (&frame->buffer, NULL);
+ gst_buffer_remove_memory_range (tmpbuf, 0, -1);
if (res) {
if (gst_adapter_available (parse->priv->adapter) < fsize) {
- GST_DEBUG_OBJECT (parse,
- "found valid frame but not enough data available (only %d bytes)",
+ GST_DEBUG_OBJECT (parse, "found valid frame but not enough data"
+ " available (only %" G_GSIZE_FORMAT " bytes)",
gst_adapter_available (parse->priv->adapter));
gst_buffer_unref (tmpbuf);
goto done;
* fragment coming later, hopefully subclass skips efficiently ... */
timestamp = gst_adapter_prev_timestamp (parse->priv->adapter, NULL);
outbuf = gst_adapter_take_buffer (parse->priv->adapter, skip);
- outbuf = gst_buffer_make_metadata_writable (outbuf);
+ outbuf = gst_buffer_make_writable (outbuf);
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
parse->priv->buffers_pending =
g_slist_prepend (parse->priv->buffers_pending, outbuf);
/* FIXME: Would it be more efficient to make a subbuffer instead? */
outbuf = gst_adapter_take_buffer (parse->priv->adapter, fsize);
- outbuf = gst_buffer_make_metadata_writable (outbuf);
+ outbuf = gst_buffer_make_writable (outbuf);
/* Subclass may want to know the data offset */
GST_BUFFER_OFFSET (outbuf) = parse->priv->offset;
* We do it mainly to avoid pulling buffers of 1 byte all the time */
if (parse->priv->cache) {
gint64 cache_offset = GST_BUFFER_OFFSET (parse->priv->cache);
- gint cache_size = GST_BUFFER_SIZE (parse->priv->cache);
+ gint cache_size = gst_buffer_get_size (parse->priv->cache);
if (cache_offset <= parse->priv->offset &&
(parse->priv->offset + size) <= (cache_offset + cache_size)) {
- *buffer = gst_buffer_create_sub (parse->priv->cache,
+ *buffer = gst_buffer_copy_region (parse->priv->cache, GST_BUFFER_COPY_ALL,
parse->priv->offset - cache_offset, size);
GST_BUFFER_OFFSET (*buffer) = parse->priv->offset;
return GST_FLOW_OK;
return ret;
}
- if (GST_BUFFER_SIZE (parse->priv->cache) >= size) {
- *buffer = gst_buffer_create_sub (parse->priv->cache, 0, size);
+ if (gst_buffer_get_size (parse->priv->cache) >= size) {
+ *buffer =
+ gst_buffer_copy_region (parse->priv->cache, GST_BUFFER_COPY_ALL, 0,
+ size);
GST_BUFFER_OFFSET (*buffer) = parse->priv->offset;
return GST_FLOW_OK;
}
return ret;
}
- if (GST_BUFFER_SIZE (parse->priv->cache) < size) {
+ if (gst_buffer_get_size (parse->priv->cache) < size) {
GST_DEBUG_OBJECT (parse, "Returning short buffer at offset %"
- G_GUINT64_FORMAT ": wanted %u bytes, got %u bytes", parse->priv->offset,
- size, GST_BUFFER_SIZE (parse->priv->cache));
+ G_GUINT64_FORMAT ": wanted %u bytes, got %" G_GSIZE_FORMAT " bytes",
+ parse->priv->offset, size, gst_buffer_get_size (parse->priv->cache));
*buffer = parse->priv->cache;
parse->priv->cache = NULL;
return GST_FLOW_OK;
}
- *buffer = gst_buffer_create_sub (parse->priv->cache, 0, size);
+ *buffer =
+ gst_buffer_copy_region (parse->priv->cache, GST_BUFFER_COPY_ALL, 0, size);
GST_BUFFER_OFFSET (*buffer) = parse->priv->offset;
return GST_FLOW_OK;
if (!parse->priv->last_offset || parse->priv->last_ts <= parse->segment.start) {
GST_DEBUG_OBJECT (parse, "past start of segment %" GST_TIME_FORMAT,
GST_TIME_ARGS (parse->segment.start));
- ret = GST_FLOW_UNEXPECTED;
+ ret = GST_FLOW_EOS;
goto exit;
}
if (parse->priv->exact_position) {
offset = gst_base_parse_find_offset (parse, ts, TRUE, NULL);
} else {
- GstFormat dstformat = GST_FORMAT_BYTES;
-
if (!gst_pad_query_convert (parse->srcpad, GST_FORMAT_TIME, ts,
- &dstformat, &offset)) {
+ GST_FORMAT_BYTES, &offset)) {
GST_DEBUG_OBJECT (parse, "conversion failed, only BYTE based");
}
}
/* if we got a short read, inform subclass we are draining leftover
* and no more is to be expected */
- if (GST_BUFFER_SIZE (buffer) < min_size)
+ if (gst_buffer_get_size (buffer) < min_size)
parse->priv->drain = TRUE;
+ if (parse->priv->detecting) {
+ ret = klass->detect (parse, buffer);
+ if (ret == GST_FLOW_NOT_NEGOTIATED) {
+ /* If draining we error out, otherwise request a buffer
+ * with 64kb more */
+ if (parse->priv->drain) {
+ gst_buffer_unref (buffer);
+ GST_ERROR_OBJECT (parse, "Failed to detect format but draining");
+ return GST_FLOW_ERROR;
+ } else {
+ fsize += 64 * 1024;
+ gst_buffer_unref (buffer);
+ continue;
+ }
+ } else if (ret != GST_FLOW_OK) {
+ gst_buffer_unref (buffer);
+ GST_ERROR_OBJECT (parse, "detect() returned %s",
+ gst_flow_get_name (ret));
+ return ret;
+ }
+
+ /* Else handle this buffer normally */
+ }
+
skip = -1;
gst_base_parse_frame_update (parse, frame, buffer);
res = klass->check_valid_frame (parse, frame, &fsize, &skip);
/* reverse playback, and no frames found yet, so we are skipping
* the leading part of a fragment, which may form the tail of
* fragment coming later, hopefully subclass skips efficiently ... */
- outbuf = gst_buffer_create_sub (buffer, 0, skip);
+ outbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, skip);
parse->priv->buffers_pending =
g_slist_prepend (parse->priv->buffers_pending, outbuf);
outbuf = NULL;
else if (skip < 0)
skip = 0;
- if (fsize + skip <= GST_BUFFER_SIZE (buffer)) {
- outbuf = gst_buffer_create_sub (buffer, skip, fsize);
+ if (fsize + skip <= gst_buffer_get_size (buffer)) {
+ outbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, skip, fsize);
GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buffer) + skip;
GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
gst_buffer_unref (buffer);
ret = gst_base_parse_pull_range (parse, fsize, &outbuf);
if (ret != GST_FLOW_OK)
goto done;
- if (GST_BUFFER_SIZE (outbuf) < fsize) {
+ if (gst_buffer_get_size (outbuf) < fsize) {
gst_buffer_unref (outbuf);
- ret = GST_FLOW_UNEXPECTED;
+ ret = GST_FLOW_EOS;
}
}
ret = gst_base_parse_handle_and_push_frame (parse, klass, &frame);
/* eat expected eos signalling past segment in reverse playback */
- if (parse->segment.rate < 0.0 && ret == GST_FLOW_UNEXPECTED &&
- parse->segment.last_stop >= parse->segment.stop) {
+ if (parse->segment.rate < 0.0 && ret == GST_FLOW_EOS &&
+ parse->segment.position >= parse->segment.stop) {
GST_DEBUG_OBJECT (parse, "downstream has reached end of segment");
/* push what was accumulated during loop run */
gst_base_parse_process_fragment (parse, TRUE);
}
done:
- if (ret == GST_FLOW_UNEXPECTED)
+ if (ret == GST_FLOW_EOS)
goto eos;
else if (ret != GST_FLOW_OK)
goto pause;
/* ERRORS */
eos:
{
- ret = GST_FLOW_UNEXPECTED;
+ ret = GST_FLOW_EOS;
GST_DEBUG_OBJECT (parse, "eos");
/* fall-through */
}
gst_flow_get_name (ret));
gst_pad_pause_task (parse->sinkpad);
- if (ret == GST_FLOW_UNEXPECTED) {
+ if (ret == GST_FLOW_EOS) {
/* handle end-of-stream/segment */
if (parse->segment.flags & GST_SEEK_FLAG_SEGMENT) {
gint64 stop;
}
push_eos = TRUE;
}
- } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_UNEXPECTED) {
+ } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
/* for fatal errors we post an error message, wrong-state is
* not fatal because it happens due to flushes and only means
* that we should stop now. */
}
static gboolean
-gst_base_parse_sink_activate (GstPad * sinkpad)
+gst_base_parse_sink_activate (GstPad * sinkpad, GstObject * parent)
{
GstBaseParse *parse;
gboolean result = TRUE;
+ GstQuery *query;
+ gboolean pull_mode;
- parse = GST_BASE_PARSE (gst_pad_get_parent (sinkpad));
+ parse = GST_BASE_PARSE (parent);
GST_DEBUG_OBJECT (parse, "sink activate");
- if (gst_pad_check_pull_range (sinkpad)) {
+ query = gst_query_new_scheduling ();
+ result = gst_pad_peer_query (sinkpad, query);
+ if (result) {
+ pull_mode = gst_query_has_scheduling_mode (query, GST_PAD_MODE_PULL);
+ } else {
+ pull_mode = FALSE;
+ }
+ gst_query_unref (query);
+
+ if (pull_mode) {
GST_DEBUG_OBJECT (parse, "trying to activate in pull mode");
- result = gst_pad_activate_pull (sinkpad, TRUE);
+ result = gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PULL, TRUE);
} else {
GST_DEBUG_OBJECT (parse, "trying to activate in push mode");
- result = gst_pad_activate_push (sinkpad, TRUE);
+ result = gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PUSH, TRUE);
}
GST_DEBUG_OBJECT (parse, "sink activate return %d", result);
- gst_object_unref (parse);
return result;
}
gst_base_parse_activate (GstBaseParse * parse, gboolean active)
{
GstBaseParseClass *klass;
- gboolean result = FALSE;
+ gboolean result = TRUE;
GST_DEBUG_OBJECT (parse, "activate %d", active);
klass = GST_BASE_PARSE_GET_CLASS (parse);
if (active) {
- if (parse->priv->pad_mode == GST_ACTIVATE_NONE && klass->start)
+ if (parse->priv->pad_mode == GST_PAD_MODE_NONE && klass->start)
result = klass->start (parse);
+
+ /* If the subclass implements ::detect we want to
+ * call it for the first buffers now */
+ parse->priv->detecting = (klass->detect != NULL);
} else {
/* We must make sure streaming has finished before resetting things
* and calling the ::stop vfunc */
GST_PAD_STREAM_LOCK (parse->sinkpad);
GST_PAD_STREAM_UNLOCK (parse->sinkpad);
- if (parse->priv->pad_mode != GST_ACTIVATE_NONE && klass->stop)
+ if (parse->priv->pad_mode != GST_PAD_MODE_NONE && klass->stop)
result = klass->stop (parse);
- parse->priv->pad_mode = GST_ACTIVATE_NONE;
+ parse->priv->pad_mode = GST_PAD_MODE_NONE;
}
GST_DEBUG_OBJECT (parse, "activate return: %d", result);
return result;
}
static gboolean
-gst_base_parse_sink_activate_push (GstPad * pad, gboolean active)
+gst_base_parse_sink_activate_mode (GstPad * pad, GstObject * parent,
+ GstPadMode mode, gboolean active)
{
gboolean result = TRUE;
GstBaseParse *parse;
- parse = GST_BASE_PARSE (gst_pad_get_parent (pad));
+ parse = GST_BASE_PARSE (parent);
- GST_DEBUG_OBJECT (parse, "sink activate push %d", active);
-
- result = gst_base_parse_activate (parse, active);
-
- if (result)
- parse->priv->pad_mode = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
-
- GST_DEBUG_OBJECT (parse, "sink activate push return: %d", result);
-
- gst_object_unref (parse);
- return result;
-}
-
-static gboolean
-gst_base_parse_sink_activate_pull (GstPad * sinkpad, gboolean active)
-{
- gboolean result = FALSE;
- GstBaseParse *parse;
-
- parse = GST_BASE_PARSE (gst_pad_get_parent (sinkpad));
-
- GST_DEBUG_OBJECT (parse, "activate pull %d", active);
+ GST_DEBUG_OBJECT (parse, "sink activate mode %d, %d", mode, active);
result = gst_base_parse_activate (parse, active);
if (result) {
- if (active) {
- parse->priv->pending_segment = gst_event_new_new_segment (FALSE,
- parse->segment.rate, parse->segment.format,
- parse->segment.start, parse->segment.stop, parse->segment.last_stop);
- result &=
- gst_pad_start_task (sinkpad, (GstTaskFunction) gst_base_parse_loop,
- sinkpad);
- } else {
- result &= gst_pad_stop_task (sinkpad);
+ switch (mode) {
+ case GST_PAD_MODE_PULL:
+ if (active) {
+ parse->priv->pending_segment =
+ gst_event_new_segment (&parse->segment);
+ result &=
+ gst_pad_start_task (pad, (GstTaskFunction) gst_base_parse_loop,
+ pad);
+ } else {
+ result &= gst_pad_stop_task (pad);
+ }
+ break;
+ default:
+ break;
}
}
-
if (result)
- parse->priv->pad_mode = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
+ parse->priv->pad_mode = active ? mode : GST_PAD_MODE_NONE;
- GST_DEBUG_OBJECT (parse, "sink activate pull return: %d", result);
+ GST_DEBUG_OBJECT (parse, "sink activate return: %d", result);
- gst_object_unref (parse);
return result;
}
-
/**
* gst_base_parse_set_duration:
* @parse: #GstBaseParse.
* parsing, and the parser should operate in passthrough mode (which only
* applies when operating in push mode). That is, incoming buffers are
* pushed through unmodified, i.e. no @check_valid_frame or @parse_frame
- * callbacks will be invoked, but @pre_push_buffer will still be invoked,
+ * callbacks will be invoked, but @pre_push_frame will still be invoked,
* so subclass can perform as much or as little is appropriate for
- * passthrough semantics in @pre_push_buffer.
+ * passthrough semantics in @pre_push_frame.
*
* Since: 0.10.33
*/
* by the parsing process. If there is such a latency, which depends on the
* particular parsing of the format, it typically corresponds to 1 frame duration.
*
- * Since: 0.10.34
+ * Since: 0.10.36
*/
void
gst_base_parse_set_latency (GstBaseParse * parse, GstClockTime min_latency,
return res;
}
-static const GstQueryType *
-gst_base_parse_get_querytypes (GstPad * pad)
-{
- static const GstQueryType list[] = {
- GST_QUERY_POSITION,
- GST_QUERY_DURATION,
- GST_QUERY_FORMATS,
- GST_QUERY_SEEKING,
- GST_QUERY_CONVERT,
- GST_QUERY_NONE
- };
-
- return list;
-}
-
static gboolean
-gst_base_parse_query (GstPad * pad, GstQuery * query)
+gst_base_parse_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
{
GstBaseParse *parse;
gboolean res = FALSE;
- parse = GST_BASE_PARSE (GST_PAD_PARENT (pad));
+ parse = GST_BASE_PARSE (parent);
GST_LOG_OBJECT (parse, "handling query: %" GST_PTR_FORMAT, query);
gst_query_parse_position (query, &format, NULL);
/* try upstream first */
- res = gst_pad_query_default (pad, query);
+ res = gst_pad_query_default (pad, parent, query);
if (!res) {
/* Fall back on interpreting segment */
GST_OBJECT_LOCK (parse);
dest_value = parse->priv->offset;
res = TRUE;
} else if (format == parse->segment.format &&
- GST_CLOCK_TIME_IS_VALID (parse->segment.last_stop)) {
+ GST_CLOCK_TIME_IS_VALID (parse->segment.position)) {
dest_value = gst_segment_to_stream_time (&parse->segment,
- parse->segment.format, parse->segment.last_stop);
+ parse->segment.format, parse->segment.position);
res = TRUE;
}
GST_OBJECT_UNLOCK (parse);
- if (res)
- gst_query_set_position (query, format, dest_value);
- else {
+ if (!res) {
/* no precise result, upstream no idea either, then best estimate */
/* priv->offset is updated in both PUSH/PULL modes */
res = gst_base_parse_convert (parse,
GST_FORMAT_BYTES, parse->priv->offset, format, &dest_value);
}
+ if (res)
+ gst_query_set_position (query, format, dest_value);
}
break;
}
gst_query_parse_duration (query, &format, NULL);
/* consult upstream */
- res = gst_pad_query_default (pad, query);
+ res = gst_pad_query_default (pad, parent, query);
/* otherwise best estimate from us */
if (!res) {
gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
/* consult upstream */
- res = gst_pad_query_default (pad, query);
+ res = gst_pad_query_default (pad, parent, query);
/* we may be able to help if in TIME */
if (fmt == GST_FORMAT_TIME && gst_base_parse_is_seekable (parse)) {
break;
}
default:
- res = gst_pad_query_default (pad, query);
+ res = gst_pad_query_default (pad, parent, query);
break;
}
return res;
buf = frame.buffer;
GST_LOG_OBJECT (parse,
"peek parsing frame at offset %" G_GUINT64_FORMAT
- " (%#" G_GINT64_MODIFIER "x) of size %d",
- GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET (buf), GST_BUFFER_SIZE (buf));
+ " (%#" G_GINT64_MODIFIER "x) of size %" G_GSIZE_FORMAT,
+ GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET (buf),
+ gst_buffer_get_size (buf));
/* get offset first, subclass parsing might dump other stuff in there */
*pos = GST_BUFFER_OFFSET (buf);
g_return_val_if_fail (_time != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (_offset != NULL, GST_FLOW_ERROR);
+ GST_DEBUG_OBJECT (parse, "Bisecting for time %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (*_time));
+
/* TODO also make keyframe aware if useful some day */
time = *_time;
/* need initial positions; start and end */
lpos = parse->priv->first_frame_offset;
ltime = parse->priv->first_frame_ts;
- htime = parse->priv->duration;
+ if (!gst_base_parse_get_duration (parse, GST_FORMAT_TIME, &htime)) {
+ GST_DEBUG_OBJECT (parse, "Unknown time duration, cannot bisect");
+ return GST_FLOW_ERROR;
+ }
hpos = parse->priv->upstream_size;
+ GST_DEBUG_OBJECT (parse,
+ "Bisection initial bounds: bytes %" G_GINT64_FORMAT " %" G_GINT64_FORMAT
+ ", times %" GST_TIME_FORMAT " %" GST_TIME_FORMAT, lpos, htime,
+ GST_TIME_ARGS (ltime), GST_TIME_ARGS (htime));
+
/* check preconditions are satisfied;
* start and end are needed, except for special case where we scan for
* last frame to determine duration */
- if (parse->priv->pad_mode != GST_ACTIVATE_PULL || !hpos ||
+ if (parse->priv->pad_mode != GST_PAD_MODE_PULL || !hpos ||
!GST_CLOCK_TIME_IS_VALID (ltime) ||
(!GST_CLOCK_TIME_IS_VALID (htime) && time != G_MAXINT64)) {
return GST_FLOW_OK;
GST_TIME_ARGS (time), newpos);
ret = gst_base_parse_find_frame (parse, &newpos, &newtime, &dur);
- if (ret == GST_FLOW_UNEXPECTED) {
+ if (ret == GST_FLOW_EOS) {
/* heuristic HACK */
hpos = MAX (lpos, hpos - chunk);
continue;
goto exit;
}
- g_static_mutex_lock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_LOCK (parse);
if (parse->priv->index) {
/* Let's check if we have an index entry for that time */
entry = gst_index_get_assoc_entry (parse->priv->index,
parse->priv->index_id,
before ? GST_INDEX_LOOKUP_BEFORE : GST_INDEX_LOOKUP_AFTER,
- GST_ASSOCIATION_FLAG_KEY_UNIT, GST_FORMAT_TIME, time);
+ GST_INDEX_ASSOCIATION_FLAG_KEY_UNIT, GST_FORMAT_TIME, time);
}
if (entry) {
ts = GST_CLOCK_TIME_NONE;
}
}
- g_static_mutex_unlock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_UNLOCK (parse);
exit:
if (_ts)
gboolean flush, update, res = TRUE, accurate;
gint64 cur, stop, seekpos, seekstop;
GstSegment seeksegment = { 0, };
- GstFormat dstformat;
GstClockTime start_ts;
gst_event_parse_seek (event, &rate, &format, &flags,
cur_type, GST_TIME_ARGS (cur), stop_type, GST_TIME_ARGS (stop));
/* no negative rates in push mode */
- if (rate < 0.0 && parse->priv->pad_mode == GST_ACTIVATE_PUSH)
+ if (rate < 0.0 && parse->priv->pad_mode == GST_PAD_MODE_PUSH)
goto negative_rate;
if (cur_type != GST_SEEK_TYPE_SET ||
/* copy segment, we need this because we still need the old
* segment when we close the current segment. */
- memcpy (&seeksegment, &parse->segment, sizeof (GstSegment));
+ gst_segment_copy_into (&parse->segment, &seeksegment);
GST_DEBUG_OBJECT (parse, "configuring seek");
- gst_segment_set_seek (&seeksegment, rate, format, flags,
+ gst_segment_do_seek (&seeksegment, rate, format, flags,
cur_type, cur, stop_type, stop, &update);
/* accurate seeking implies seek tables are used to obtain position,
accurate = flags & GST_SEEK_FLAG_ACCURATE;
/* maybe we can be accurate for (almost) free */
- gst_base_parse_find_offset (parse, seeksegment.last_stop, TRUE, &start_ts);
- if (seeksegment.last_stop <= start_ts + TARGET_DIFFERENCE) {
+ gst_base_parse_find_offset (parse, seeksegment.position, TRUE, &start_ts);
+ if (seeksegment.position <= start_ts + TARGET_DIFFERENCE) {
GST_DEBUG_OBJECT (parse, "accurate seek possible");
accurate = TRUE;
}
if (accurate) {
- GstClockTime startpos = seeksegment.last_stop;
+ GstClockTime startpos = seeksegment.position;
/* accurate requested, so ... seek a bit before target */
if (startpos < parse->priv->lead_in_ts)
seekstop = gst_base_parse_find_offset (parse, seeksegment.stop, FALSE,
NULL);
} else {
- start_ts = seeksegment.last_stop;
- dstformat = GST_FORMAT_BYTES;
- if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.last_stop,
- &dstformat, &seekpos))
+ start_ts = seeksegment.position;
+ if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.position,
+ GST_FORMAT_BYTES, &seekpos))
goto convert_failed;
if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.stop,
- &dstformat, &seekstop))
+ GST_FORMAT_BYTES, &seekstop))
goto convert_failed;
}
"seek stop %" G_GINT64_FORMAT " in bytes: %" G_GINT64_FORMAT,
seeksegment.stop, seekstop);
- if (parse->priv->pad_mode == GST_ACTIVATE_PULL) {
+ if (parse->priv->pad_mode == GST_PAD_MODE_PULL) {
gint64 last_stop;
GST_DEBUG_OBJECT (parse, "seek in PULL mode");
GST_PAD_STREAM_LOCK (parse->sinkpad);
/* save current position */
- last_stop = parse->segment.last_stop;
+ last_stop = parse->segment.position;
GST_DEBUG_OBJECT (parse, "stopped streaming at %" G_GINT64_FORMAT,
last_stop);
/* prepare for streaming again */
if (flush) {
GST_DEBUG_OBJECT (parse, "sending flush stop");
- gst_pad_push_event (parse->srcpad, gst_event_new_flush_stop ());
- gst_pad_push_event (parse->sinkpad, gst_event_new_flush_stop ());
+ gst_pad_push_event (parse->srcpad, gst_event_new_flush_stop (TRUE));
+ gst_pad_push_event (parse->sinkpad, gst_event_new_flush_stop (TRUE));
gst_base_parse_clear_queues (parse);
} else {
- if (parse->priv->close_segment)
- gst_event_unref (parse->priv->close_segment);
-
- parse->priv->close_segment = gst_event_new_new_segment (TRUE,
- parse->segment.rate, parse->segment.format,
- parse->segment.accum, parse->segment.last_stop, parse->segment.accum);
-
- /* keep track of our last_stop */
- seeksegment.accum = parse->segment.last_stop;
-
- GST_DEBUG_OBJECT (parse, "Created close seg format %d, "
- "start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT
- ", pos = %" GST_TIME_FORMAT, format,
- GST_TIME_ARGS (parse->segment.accum),
- GST_TIME_ARGS (parse->segment.last_stop),
- GST_TIME_ARGS (parse->segment.accum));
+ /* keep track of our position */
+ seeksegment.base = gst_segment_to_running_time (&seeksegment,
+ seeksegment.format, parse->segment.position);
}
memcpy (&parse->segment, &seeksegment, sizeof (GstSegment));
gst_event_unref (parse->priv->pending_segment);
/* This will be sent later in _loop() */
- parse->priv->pending_segment =
- gst_event_new_new_segment (FALSE, parse->segment.rate,
- parse->segment.format, parse->segment.start,
- parse->segment.stop, parse->segment.start);
+ parse->priv->pending_segment = gst_event_new_segment (&parse->segment);
GST_DEBUG_OBJECT (parse, "Created newseg format %d, "
"start = %" GST_TIME_FORMAT ", stop = %" GST_TIME_FORMAT
* maybe scan and subclass can find where to go */
if (!accurate) {
gint64 scanpos;
- GstClockTime ts = seeksegment.last_stop;
+ GstClockTime ts = seeksegment.position;
gst_base_parse_locate_time (parse, &ts, &scanpos);
if (scanpos >= 0) {
seek event (in bytes) to upstream. Segment / flush handling happens
in corresponding src event handlers */
GST_DEBUG_OBJECT (parse, "seek in PUSH mode");
- if (seekstop >= 0 && seekpos <= seekpos)
+ if (seekstop >= 0 && seekstop <= seekpos)
seekstop = seekpos;
new_event = gst_event_new_seek (rate, GST_FORMAT_BYTES, flags,
GST_SEEK_TYPE_SET, seekpos, stop_type, seekstop);
}
}
-static gboolean
-gst_base_parse_sink_setcaps (GstPad * pad, GstCaps * caps)
-{
- GstBaseParse *parse;
- GstBaseParseClass *klass;
- gboolean res = TRUE;
-
- parse = GST_BASE_PARSE (GST_PAD_PARENT (pad));
- klass = GST_BASE_PARSE_GET_CLASS (parse);
-
- GST_DEBUG_OBJECT (parse, "caps: %" GST_PTR_FORMAT, caps);
-
- if (klass->set_sink_caps)
- res = klass->set_sink_caps (parse, caps);
-
- return res;
-}
-
+#if 0
static void
gst_base_parse_set_index (GstElement * element, GstIndex * index)
{
GstBaseParse *parse = GST_BASE_PARSE (element);
- g_static_mutex_lock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_LOCK (parse);
if (parse->priv->index)
gst_object_unref (parse->priv->index);
if (index) {
} else {
parse->priv->index = NULL;
}
- g_static_mutex_unlock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_UNLOCK (parse);
}
static GstIndex *
GstBaseParse *parse = GST_BASE_PARSE (element);
GstIndex *result = NULL;
- g_static_mutex_lock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_LOCK (parse);
if (parse->priv->index)
result = gst_object_ref (parse->priv->index);
- g_static_mutex_unlock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_UNLOCK (parse);
return result;
}
+#endif
static GstStateChangeReturn
gst_base_parse_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_READY_TO_PAUSED:
/* If this is our own index destroy it as the
* old entries might be wrong for the new stream */
- g_static_mutex_lock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_LOCK (parse);
if (parse->priv->own_index) {
gst_object_unref (parse->priv->index);
parse->priv->index = NULL;
if (G_UNLIKELY (!parse->priv->index)) {
GST_DEBUG_OBJECT (parse, "no index provided creating our own");
- parse->priv->index = gst_index_factory_make ("memindex");
+ parse->priv->index = g_object_new (gst_mem_index_get_type (), NULL);
gst_index_get_writer_id (parse->priv->index, GST_OBJECT (parse),
&parse->priv->index_id);
parse->priv->own_index = TRUE;
}
- g_static_mutex_unlock (&parse->priv->index_lock);
+ GST_BASE_PARSE_INDEX_UNLOCK (parse);
break;
default:
break;