*
* It provides for:
* <itemizedlist>
- * <listitem><para>One sinkpad and one srcpad</para></listitem>
- * <listitem><para>Handles state changes</para></listitem>
- * <listitem><para>Does flushing</para></listitem>
- * <listitem><para>Push mode</para></listitem>
- * <listitem><para>Pull mode</para></listitem>
- * <listitem><para>Handles events (NEWSEGMENT/EOS/FLUSH)</para></listitem>
- * <listitem><para>Handles seeking in both modes</para></listitem>
+ * <listitem><para>provides one sink pad and one source pad</para></listitem>
+ * <listitem><para>handles state changes</para></listitem>
+ * <listitem><para>can operate in pull mode or push mode</para></listitem>
+ * <listitem><para>handles seeking in both modes</para></listitem>
+ * <listitem><para>handles events (NEWSEGMENT/EOS/FLUSH)</para></listitem>
* <listitem><para>
- * Handles POSITION/DURATION/SEEKING/FORMAT/CONVERT queries
+ * handles queries (POSITION/DURATION/SEEKING/FORMAT/CONVERT)
* </para></listitem>
+ * <listitem><para>handles flushing</para></listitem>
* </itemizedlist>
*
- * The purpose of this base class is to provide a basic functionality of
+ * The purpose of this base class is to provide the basic functionality of
* a parser and share a lot of rather complex code.
*
* Description of the parsing mechanism:
* about to start now.
* </para></listitem>
* <listitem><para>
- * At least in this point subclass needs to tell the GstBaseParse class
+ * At least at this point subclass needs to tell the GstBaseParse class
* how big data chunks it wants to receive (min_frame_size). It can do
- * this with @gst_base_parse_set_min_frame_size.
+ * this with gst_base_parse_set_min_frame_size().
* </para></listitem>
* <listitem><para>
* GstBaseParse class sets up appropriate data passing mode (pull/push)
* <title>Parsing phase</title>
* <listitem><para>
* GstBaseParse gathers at least min_frame_size bytes of data either
- * by pulling it from upstream or collecting buffers into internal
+ * by pulling it from upstream or collecting buffers in an internal
* #GstAdapter.
* </para></listitem>
* <listitem><para>
* contain a valid frame, this call must return FALSE and optionally
* set the @skipsize value to inform base class that how many bytes
* it needs to skip in order to find a valid frame. @framesize can always
- * indicate a new minimum for current frame parsing. The passed buffer
+ * indicate a new minimum for current frame parsing. Indicating G_MAXUINT
+ * for requested amount means subclass simply needs best available
+ * subsequent data. In push mode this amounts to an additional input buffer
+ * (thus minimal additional latency), in pull mode this amounts to some
+ * arbitrary reasonable buffer size increase. The passed buffer
* is read-only. Note that @check_valid_frame might receive any small
* amount of input data when leftover data is being drained (e.g. at EOS).
* </para></listitem>
* (although the latter can also be done by GstBaseParse if it is
* appropriately configured, see below). Frame is provided with
* timestamp derived from upstream (as much as generally possible),
- * duration obtained form configuration (see below), and offset
+ * duration obtained from configuration (see below), and offset
* if meaningful (in pull mode).
* </para></listitem>
* <listitem><para>
- * Finally the buffer can be pushed downstream and parsing loop starts
+ * 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
* last chance to examine buffer metadata, or to send some custom (tag)
* events, or to perform custom (segment) filtering.
* </para></listitem>
* <listitem><para>
- * During the parsing process GstBaseParseClass will handle both srcpad and
- * sinkpad events. They will be passed to subclass if @event or
+ * During the parsing process GstBaseParseClass will handle both srcpad
+ * and sinkpad events. They will be passed to subclass if @event or
* @src_event callbacks have been provided.
* </para></listitem>
* </itemizedlist>
* needs to set the fixed caps on srcpad, when the format is ensured (e.g.
* when base class calls subclass' @set_sink_caps function).
*
- * This base class uses GST_FORMAT_DEFAULT as a meaning of frames. So,
+ * This base class uses #GST_FORMAT_DEFAULT as a meaning of frames. So,
* subclass conversion routine needs to know that conversion from
- * GST_FORMAT_TIME to GST_FORMAT_DEFAULT must return the
+ * #GST_FORMAT_TIME to #GST_FORMAT_DEFAULT must return the
* frame number that can be found from the given byte position.
*
- * GstBaseParse uses subclasses conversion methods also for seeking (or otherwise
- * uses its own default one, see also below).
+ * GstBaseParse uses subclasses conversion methods also for seeking (or
+ * otherwise uses its own default one, see also below).
*
* Subclass @start and @stop functions will be called to inform the beginning
* and end of data processing.
* </para></listitem>
* <listitem><para>
* Inform base class how big data chunks should be retrieved. This is
- * done with @gst_base_parse_set_min_frame_size function.
+ * done with gst_base_parse_set_min_frame_size() function.
* </para></listitem>
* <listitem><para>
* Examine data chunks passed to subclass with @check_valid_frame
* </para></listitem>
* <listitem><para>Provide conversion functions</para></listitem>
* <listitem><para>
- * Update the duration information with @gst_base_parse_set_duration
+ * Update the duration information with gst_base_parse_set_duration()
* </para></listitem>
* <listitem><para>
- * Optionally passthrough using @gst_base_parse_set_format
+ * Optionally passthrough using gst_base_parse_set_passthrough()
* </para></listitem>
* <listitem><para>
- * Configure various baseparse parameters using @gst_base_parse_set_seek and
- * @gst_base_parse_set_frame_props.
+ * Configure various baseparse parameters using
+ * gst_base_parse_set_average_bitrate(), gst_base_parse_set_syncable()
+ * and gst_base_parse_set_frame_rate().
* </para></listitem>
* <listitem><para>
* In particular, if subclass is unable to determine a duration, but
* parsing (or specs) yields a frames per seconds rate, then this can be
* provided to GstBaseParse to enable it to cater for
- * buffer time metadata (which will be taken from upstream as much as possible).
- * Internally keeping track of frame durations and respective
- * sizes that have been pushed provides GstBaseParse with an estimated bitrate.
- * A default @convert (used if not overriden) will then use these
- * rates to perform obvious conversions. These rates are also used to update
- * (estimated) duration at regular frame intervals.
+ * buffer time metadata (which will be taken from upstream as much as
+ * possible). Internally keeping track of frame durations and respective
+ * sizes that have been pushed provides GstBaseParse with an estimated
+ * bitrate. A default @convert (used if not overriden) will then use these
+ * rates to perform obvious conversions. These rates are also used to
+ * update (estimated) duration at regular frame intervals.
* </para></listitem>
* </itemizedlist>
*
#include <stdlib.h>
#include <string.h>
+#include <gst/base/gstadapter.h>
+
#include "gstbaseparse.h"
+#define GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC (1 << 0)
+
#define MIN_FRAMES_TO_POST_BITRATE 10
#define TARGET_DIFFERENCE (20 * GST_SECOND)
#define GST_CAT_DEFAULT gst_base_parse_debug
/* Supported formats */
-static GstFormat fmtlist[] = {
+static const GstFormat fmtlist[] = {
GST_FORMAT_DEFAULT,
GST_FORMAT_BYTES,
GST_FORMAT_TIME,
{
GstActivateMode pad_mode;
+ GstAdapter *adapter;
+
gint64 duration;
GstFormat duration_fmt;
gint64 estimated_duration;
guint min_frame_size;
- guint format;
+ gboolean passthrough;
+ gboolean syncable;
+ gboolean has_timing_info;
guint fps_num, fps_den;
gint update_interval;
guint bitrate;
guint lead_in, lead_out;
GstClockTime lead_in_ts, lead_out_ts;
- GstBaseParseSeekable seekable;
+ GstClockTime min_latency, max_latency;
gboolean discont;
gboolean flushing;
GList *pending_events;
+ /* frames/buffers that are queued and ready to go on OK */
+ GQueue queued_frames;
+
GstBuffer *cache;
/* index entry storage, either ours or provided */
GstIndex *index;
gint index_id;
gboolean own_index;
+ GStaticMutex index_lock;
+
/* seek table entries only maintained if upstream is BYTE seekable */
gboolean upstream_seekable;
gboolean upstream_has_duration;
GSList *buffers_send;
GstClockTime last_ts;
gint64 last_offset;
+
+ /* Newsegment event to be sent after SEEK */
+ GstEvent *pending_segment;
+
+ /* Segment event that closes the running segment prior to SEEK */
+ GstEvent *close_segment;
+
+ /* push mode helper frame */
+ GstBaseParseFrame frame;
};
typedef struct _GstBaseParseSeek
GstClockTime start_ts;
} GstBaseParseSeek;
-#define GST_BASE_PARSE_PASSTHROUGH(parse) \
- (parse->priv->format & GST_BASE_PARSE_FORMAT_PASSTHROUGH)
-#define GST_BASE_PARSE_HAS_TIME(parse) \
- (parse->priv->format & GST_BASE_PARSE_FORMAT_HAS_TIME)
-
-
static GstElementClass *parent_class = NULL;
static void gst_base_parse_class_init (GstBaseParseClass * klass);
GType
gst_base_parse_get_type (void)
{
- static GType base_parse_type = 0;
+ static volatile gsize base_parse_type = 0;
- if (!base_parse_type) {
+ if (g_once_init_enter (&base_parse_type)) {
static const GTypeInfo base_parse_info = {
sizeof (GstBaseParseClass),
(GBaseInitFunc) NULL,
0,
(GInstanceInitFunc) gst_base_parse_init,
};
+ GType _type;
- base_parse_type = g_type_register_static (GST_TYPE_ELEMENT,
- "GstBaseParseBad", &base_parse_info, G_TYPE_FLAG_ABSTRACT);
+ _type = g_type_register_static (GST_TYPE_ELEMENT,
+ "GstBaseParse", &base_parse_info, G_TYPE_FLAG_ABSTRACT);
+ g_once_init_leave (&base_parse_type, _type);
}
- return base_parse_type;
+ return (GType) base_parse_type;
}
static void gst_base_parse_finalize (GObject * object);
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 GstFlowReturn gst_base_parse_chain (GstPad * pad, GstBuffer * buffer);
static GstFlowReturn gst_base_parse_process_fragment (GstBaseParse * parse,
gboolean push_only);
+static gboolean gst_base_parse_is_seekable (GstBaseParse * parse);
+
static void
gst_base_parse_clear_queues (GstBaseParse * parse)
{
GstBaseParse *parse = GST_BASE_PARSE (object);
GstEvent **p_ev;
- g_object_unref (parse->adapter);
+ g_object_unref (parse->priv->adapter);
- if (parse->pending_segment) {
- p_ev = &parse->pending_segment;
+ if (parse->priv->pending_segment) {
+ p_ev = &parse->priv->pending_segment;
gst_event_replace (p_ev, NULL);
}
- if (parse->close_segment) {
- p_ev = &parse->close_segment;
+ if (parse->priv->close_segment) {
+ p_ev = &parse->priv->close_segment;
gst_event_replace (p_ev, NULL);
}
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);
+
gst_base_parse_clear_queues (parse);
G_OBJECT_CLASS (parent_class)->finalize (object);
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_chain_function (parse->sinkpad,
GST_DEBUG_FUNCPTR (gst_base_parse_chain));
gst_pad_set_activate_function (parse->sinkpad,
gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
GST_DEBUG_OBJECT (parse, "src created");
- parse->adapter = gst_adapter_new ();
+ g_queue_init (&parse->priv->queued_frames);
+
+ parse->priv->adapter = gst_adapter_new ();
parse->priv->pad_mode = GST_ACTIVATE_NONE;
+ g_static_mutex_init (&parse->priv->index_lock);
+
/* init state */
gst_base_parse_reset (parse);
GST_DEBUG_OBJECT (parse, "init ok");
}
+static GstBaseParseFrame *
+gst_base_parse_frame_copy (GstBaseParseFrame * frame)
+{
+ GstBaseParseFrame *copy;
+
+ copy = g_slice_dup (GstBaseParseFrame, frame);
+ copy->buffer = gst_buffer_ref (frame->buffer);
+ copy->_private_flags &= ~GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC;
+
+ GST_TRACE ("copied frame %p -> %p", frame, copy);
+
+ return copy;
+}
+
+void
+gst_base_parse_frame_free (GstBaseParseFrame * frame)
+{
+ GST_TRACE ("freeing frame %p", frame);
+
+ if (frame->buffer) {
+ gst_buffer_unref (frame->buffer);
+ frame->buffer = NULL;
+ }
+
+ if (!(frame->_private_flags & GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC)) {
+ g_slice_free (GstBaseParseFrame, frame);
+ } else {
+ memset (frame, 0, sizeof (*frame));
+ }
+}
+
+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;
+}
+
/**
* gst_base_parse_frame_init:
- * @parse: #GstBaseParse.
- * @fmt: #GstBaseParseFrame.
+ * @frame: #GstBaseParseFrame.
*
* Sets a #GstBaseParseFrame to initial state. Currently this means
- * all fields are zero-ed.
+ * all public fields are zero-ed and a private flag is set to make
+ * sure gst_base_parse_frame_free() only frees the contents but not
+ * the actual frame. Use this function to initialise a #GstBaseParseFrame
+ * allocated on the stack.
+ *
+ * Since: 0.10.33
*/
void
-gst_base_parse_frame_init (GstBaseParse * parse, GstBaseParseFrame * frame)
+gst_base_parse_frame_init (GstBaseParseFrame * frame)
{
- memset (frame, 0, sizeof (*frame));
+ memset (frame, 0, sizeof (GstBaseParseFrame));
+ frame->_private_flags = GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC;
+ GST_TRACE ("inited frame %p", frame);
}
-/* clear == frame no longer to be used following this */
-static void
-gst_base_parse_frame_clear (GstBaseParse * parse, GstBaseParseFrame * frame)
+/**
+ * gst_base_parse_frame_new:
+ * @buffer: (transfer none): a #GstBuffer
+ * @flags: the flags
+ * @overhead: number of bytes in this frame which should be counted as
+ * metadata overhead, ie. not used to calculate the average bitrate.
+ * Set to -1 to mark the entire frame as metadata. If in doubt, set to 0.
+ *
+ * Allocates a new #GstBaseParseFrame. This function is mainly for bindings,
+ * elements written in C should usually allocate the frame on the stack and
+ * then use gst_base_parse_frame_init() to initialise it.
+ *
+ * Returns: a newly-allocated #GstBaseParseFrame. Free with
+ * gst_base_parse_frame_free() when no longer needed, unless you gave
+ * away ownership to gst_base_parse_push_frame().
+ *
+ * Since: 0.10.33
+ */
+GstBaseParseFrame *
+gst_base_parse_frame_new (GstBuffer * buffer, GstBaseParseFrameFlags flags,
+ gint overhead)
{
- /* limited for now */
- if (frame->buffer) {
- gst_buffer_unref (frame->buffer);
- frame->buffer = NULL;
- }
+ GstBaseParseFrame *frame;
+
+ frame = g_slice_new0 (GstBaseParseFrame);
+ frame->buffer = gst_buffer_ref (buffer);
+
+ GST_TRACE ("created frame %p", frame);
+ return frame;
}
static inline void
GstBuffer * buf)
{
gst_buffer_replace (&frame->buffer, buf);
- if (parse->priv->drain) {
- frame->flags |= GST_BASE_PARSE_FRAME_FLAG_DRAIN;
- } else {
- frame->flags &= ~(GST_BASE_PARSE_FRAME_FLAG_DRAIN);
- }
+
+ parse->flags = 0;
+
+ /* set flags one by one for clarity */
+ if (G_UNLIKELY (parse->priv->drain))
+ parse->flags |= GST_BASE_PARSE_FLAG_DRAINING;
+
/* losing sync is pretty much a discont (and vice versa), no ? */
- if (!parse->priv->discont) {
- frame->flags |= GST_BASE_PARSE_FRAME_FLAG_SYNC;
- } else {
- frame->flags &= ~(GST_BASE_PARSE_FRAME_FLAG_SYNC);
- }
+ if (G_UNLIKELY (parse->priv->discont))
+ parse->flags |= GST_BASE_PARSE_FLAG_LOST_SYNC;
}
static void
parse->priv->frame_duration = GST_CLOCK_TIME_NONE;
parse->priv->lead_in = parse->priv->lead_out = 0;
parse->priv->lead_in_ts = parse->priv->lead_out_ts = 0;
- parse->priv->seekable = GST_BASE_PARSE_SEEK_DEFAULT;
parse->priv->bitrate = 0;
parse->priv->framecount = 0;
parse->priv->bytecount = 0;
parse->priv->first_frame_offset = -1;
parse->priv->estimated_duration = -1;
parse->priv->next_ts = 0;
- parse->priv->format = 0;
+ parse->priv->syncable = TRUE;
+ parse->priv->passthrough = FALSE;
+ parse->priv->has_timing_info = FALSE;
parse->priv->post_min_bitrate = TRUE;
parse->priv->post_avg_bitrate = TRUE;
parse->priv->post_max_bitrate = TRUE;
parse->priv->last_ts = GST_CLOCK_TIME_NONE;
parse->priv->last_offset = 0;
- if (parse->pending_segment) {
- gst_event_unref (parse->pending_segment);
- parse->pending_segment = NULL;
+ if (parse->priv->pending_segment) {
+ gst_event_unref (parse->priv->pending_segment);
+ parse->priv->pending_segment = NULL;
}
g_list_foreach (parse->priv->pending_events, (GFunc) gst_mini_object_unref,
g_slist_free (parse->priv->pending_seeks);
parse->priv->pending_seeks = NULL;
+ /* 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);
GST_OBJECT_UNLOCK (parse);
}
-/**
- * gst_base_parse_check_frame:
+/* gst_base_parse_check_frame:
* @parse: #GstBaseParse.
* @buffer: GstBuffer.
* @framesize: This will be set to tell the found frame size in bytes.
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;
}
-/**
- * gst_base_parse_parse_frame:
+/* gst_base_parse_parse_frame:
* @parse: #GstBaseParse.
* @buffer: #GstBuffer.
*
return GST_FLOW_OK;
}
-/**
- * gst_base_parse_convert:
+/* gst_base_parse_convert:
* @parse: #GstBaseParse.
* @src_format: #GstFormat describing the source format.
* @src_value: Source value to be converted.
return ret;
}
-/**
- * gst_base_parse_sink_event:
+/* gst_base_parse_sink_event:
* @pad: #GstPad that received the event.
* @event: #GstEvent to be handled.
*
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->pending_segment && GST_EVENT_TYPE (event) != GST_EVENT_EOS
- && GST_EVENT_TYPE (event) != GST_EVENT_NEWSEGMENT
+ if (parse->priv->pending_segment && GST_EVENT_TYPE (event) != GST_EVENT_EOS
+ && GST_EVENT_TYPE (event) != GST_EVENT_SEGMENT
&& GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_START
&& GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP) {
}
-/**
- * gst_base_parse_sink_eventfunc:
+/* gst_base_parse_sink_eventfunc:
* @parse: #GstBaseParse.
* @event: #GstEvent to be handled.
*
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);
+
+ 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;
+
+ event = gst_event_new_segment (&out_segment);
+
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) {
+ 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
* the segment. */
- eventp = &parse->pending_segment;
+ eventp = &parse->priv->pending_segment;
gst_event_replace (eventp, event);
gst_event_unref (event);
handled = TRUE;
/* 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->adapter);
+ gst_adapter_clear (parse->priv->adapter);
+
parse->priv->offset = offset;
parse->priv->sync_offset = offset;
parse->priv->next_ts = next_ts;
break;
case GST_EVENT_FLUSH_STOP:
- gst_adapter_clear (parse->adapter);
+ gst_adapter_clear (parse->priv->adapter);
gst_base_parse_clear_queues (parse);
parse->priv->flushing = FALSE;
parse->priv->discont = TRUE;
parse->priv->last_ts = GST_CLOCK_TIME_NONE;
+ parse->priv->frame._private_flags |=
+ GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC;
+ gst_base_parse_frame_free (&parse->priv->frame);
break;
case GST_EVENT_EOS:
("No valid frames found before end of stream"), (NULL));
}
/* newsegment before eos */
- if (parse->pending_segment) {
- gst_pad_push_event (parse->srcpad, parse->pending_segment);
- parse->pending_segment = NULL;
+ if (parse->priv->pending_segment) {
+ gst_pad_push_event (parse->srcpad, parse->priv->pending_segment);
+ parse->priv->pending_segment = NULL;
}
break;
}
-/**
- * gst_base_parse_src_event:
+/* gst_base_parse_src_event:
* @pad: #GstPad that received the event.
* @event: #GstEvent that was received.
*
return ret;
}
+static gboolean
+gst_base_parse_is_seekable (GstBaseParse * parse)
+{
+ /* FIXME: could do more here, e.g. check index or just send data from 0
+ * in pull mode and let decoder/sink clip */
+ return parse->priv->syncable;
+}
-/**
- * gst_base_parse_src_eventfunc:
+/* gst_base_parse_src_eventfunc:
* @parse: #GstBaseParse.
* @event: #GstEvent that was received.
*
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEEK:
{
- if (parse->priv->seekable > GST_BASE_PARSE_SEEK_NONE) {
+ if (gst_base_parse_is_seekable (parse)) {
handled = gst_base_parse_handle_seek (parse, event);
}
break;
* Default implementation of "convert" vmethod in #GstBaseParse class.
*
* Returns: TRUE if conversion was successful.
+ *
+ * Since: 0.10.33
*/
gboolean
gst_base_parse_convert_default (GstBaseParse * parse,
return ret;
}
-/**
- * gst_base_parse_update_duration:
- * @parse: #GstBaseParse.
- *
- */
static void
-gst_base_parse_update_duration (GstBaseParse * aacparse)
+gst_base_parse_update_duration (GstBaseParse * baseparse)
{
GstPad *peer;
GstBaseParse *parse;
- parse = GST_BASE_PARSE (aacparse);
+ parse = GST_BASE_PARSE (baseparse);
peer = gst_pad_get_peer (parse->sinkpad);
if (peer) {
gst_base_parse_post_bitrates (GstBaseParse * parse, gboolean post_min,
gboolean post_avg, gboolean post_max)
{
- GstTagList *taglist = gst_tag_list_new ();
+ GstTagList *taglist = NULL;
+
+ if (post_min && parse->priv->post_min_bitrate) {
+ taglist = gst_tag_list_new ();
- if (post_min && parse->priv->post_min_bitrate)
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 ();
+
parse->priv->posted_avg_bitrate = parse->priv->avg_bitrate;
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_BITRATE,
parse->priv->avg_bitrate, NULL);
}
- if (post_max && parse->priv->post_max_bitrate)
+ if (post_max && parse->priv->post_max_bitrate) {
+ if (taglist == NULL)
+ taglist = gst_tag_list_new ();
+
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
GST_TAG_MAXIMUM_BITRATE, parse->priv->max_bitrate, NULL);
+ }
GST_DEBUG_OBJECT (parse, "Updated bitrates. Min: %u, Avg: %u, Max: %u",
parse->priv->min_bitrate, parse->priv->avg_bitrate,
parse->priv->max_bitrate);
- gst_element_found_tags_for_pad (GST_ELEMENT (parse), parse->srcpad, taglist);
+ if (taglist != NULL) {
+ gst_element_found_tags_for_pad (GST_ELEMENT_CAST (parse), parse->srcpad,
+ taglist);
+ }
}
-/**
- * gst_base_parse_update_bitrates:
+/* gst_base_parse_update_bitrates:
* @parse: #GstBaseParse.
* @buffer: Current frame as a #GstBuffer
*
/* Only update the tag on a 10 kbps delta */
static const gint update_threshold = 10000;
- GstBaseParseClass *klass;
guint64 data_len, frame_dur;
gint overhead, frame_bitrate, old_avg_bitrate;
gboolean update_min = FALSE, update_avg = FALSE, update_max = FALSE;
GstBuffer *buffer = frame->buffer;
- klass = GST_BASE_PARSE_GET_CLASS (parse);
-
overhead = frame->overhead;
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,
* to the new entry, etc.
*
* Returns: #gboolean indicating whether entry was added
+ *
+ * Since: 0.10.33
*/
gboolean
gst_base_parse_add_index_entry (GstBaseParse * parse, guint64 offset,
associations[1].value = offset;
/* index might change on-the-fly, although that would be nutty app ... */
- GST_OBJECT_LOCK (parse);
+ g_static_mutex_lock (&parse->priv->index_lock);
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);
- GST_OBJECT_UNLOCK (parse);
+ g_static_mutex_unlock (&parse->priv->index_lock);
if (key) {
parse->priv->index_last_offset = offset;
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_base_parse_handle_and_push_buffer:
+/* takes ownership of frame */
+static void
+gst_base_parse_queue_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
+{
+ if (!(frame->_private_flags & GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC)) {
+ /* frame allocated on the heap, we can just take ownership */
+ g_queue_push_tail (&parse->priv->queued_frames, frame);
+ GST_TRACE ("queued frame %p", frame);
+ } else {
+ GstBaseParseFrame *copy;
+
+ /* probably allocated on the stack, must make a proper copy */
+ copy = gst_base_parse_frame_copy (frame);
+ g_queue_push_tail (&parse->priv->queued_frames, copy);
+ GST_TRACE ("queued frame %p (copy of %p)", copy, frame);
+ gst_base_parse_frame_free (frame);
+ }
+}
+
+/* gst_base_parse_handle_and_push_buffer:
* @parse: #GstBaseParse.
* @klass: #GstBaseParseClass.
- * @buffer: #GstBuffer.
+ * @frame: (transfer full): a #GstBaseParseFrame
*
* Parses the frame from given buffer and pushes it forward. Also performs
* timestamp handling and checks the segment limits.
"parsing frame at offset %" G_GUINT64_FORMAT
" (%#" G_GINT64_MODIFIER "x) of size %d",
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);
/* check if subclass/format can provide ts.
* 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) &&
- GST_BASE_PARSE_HAS_TIME (parse) &&
- parse->priv->pad_mode == GST_ACTIVATE_PULL) {
+ if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) && parse->priv->has_timing_info
+ && parse->priv->pad_mode == GST_ACTIVATE_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
* frames to decide on the format and queues them internally */
/* convert internal flow to OK and mark discont for the next buffer. */
if (ret == GST_BASE_PARSE_FLOW_DROPPED) {
- gst_base_parse_frame_clear (parse, frame);
+ gst_base_parse_frame_free (frame);
+ return GST_FLOW_OK;
+ } else if (ret == GST_BASE_PARSE_FLOW_QUEUED) {
+ gst_base_parse_queue_frame (parse, frame);
return GST_FLOW_OK;
} else if (ret != GST_FLOW_OK) {
return ret;
}
+ /* All OK, push queued frames if there are any */
+ if (G_UNLIKELY (!g_queue_is_empty (&parse->priv->queued_frames))) {
+ GstBaseParseFrame *queued_frame;
+
+ while ((queued_frame = g_queue_pop_head (&parse->priv->queued_frames))) {
+ gst_base_parse_push_frame (parse, queued_frame);
+ gst_base_parse_frame_free (queued_frame);
+ }
+ }
+
return gst_base_parse_push_frame (parse, frame);
}
/**
* gst_base_parse_push_frame:
* @parse: #GstBaseParse.
- * @frame: #GstBaseParseFrame.
+ * @frame: (transfer full): a #GstBaseParseFrame
*
* Pushes the frame downstream, sends any pending events and
- * does some timestamp and segment handling.
+ * does some timestamp and segment handling. Takes ownership
+ * of @frame and will clear it (if it was initialised with
+ * gst_base_parse_frame_init()) or free it.
*
* This must be called with sinkpad STREAM_LOCK held.
*
* Returns: #GstFlowReturn
+ *
+ * Since: 0.10.33
*/
GstFlowReturn
gst_base_parse_push_frame (GstBaseParse * parse, GstBaseParseFrame * 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);
+ GST_TRACE_OBJECT (parse, "pushing frame %p", frame);
+
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),
+ ", 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);
+ g_return_val_if_fail (gst_pad_has_current_caps (parse->srcpad),
+ GST_FLOW_ERROR);
/* segment adjustment magic; only if we are running the whole show */
- if (!GST_BASE_PARSE_PASSTHROUGH (parse) && parse->segment.rate > 0.0 &&
+ if (!parse->priv->passthrough && parse->segment.rate > 0.0 &&
(parse->priv->pad_mode == GST_ACTIVATE_PULL ||
parse->priv->upstream_seekable)) {
/* segment times are typically estimates,
* actual frame data might lead subclass to different timestamps,
* so override segment start from what is supplied there */
- if (G_UNLIKELY (parse->pending_segment && !parse->priv->exact_position &&
- GST_CLOCK_TIME_IS_VALID (last_start))) {
- gst_event_unref (parse->pending_segment);
+ if (G_UNLIKELY (parse->priv->pending_segment && !parse->priv->exact_position
+ && GST_CLOCK_TIME_IS_VALID (last_start))) {
+ 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->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);
- 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))) {
+ 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 "). "
+ "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->pending_segment)) {
- gst_event_unref (parse->pending_segment);
+
+ if (G_UNLIKELY (parse->priv->pending_segment)) {
+ gst_event_unref (parse->priv->pending_segment);
parse->segment.start = last_start;
- parse->pending_segment =
- gst_event_new_new_segment (FALSE, parse->segment.rate,
- parse->segment.format, parse->segment.start, parse->segment.stop,
- parse->segment.start);
+ parse->segment.time = last_start;
+ parse->priv->pending_segment =
+ 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;
}
}
}
/* and should then also be linked downstream, so safe to send some events */
- if (G_UNLIKELY (parse->close_segment)) {
+ if (G_UNLIKELY (parse->priv->close_segment)) {
/* only set up by loop */
GST_DEBUG_OBJECT (parse, "loop sending close segment");
- gst_pad_push_event (parse->srcpad, parse->close_segment);
- parse->close_segment = NULL;
+ gst_pad_push_event (parse->srcpad, parse->priv->close_segment);
+ parse->priv->close_segment = NULL;
}
- if (G_UNLIKELY (parse->pending_segment)) {
+ if (G_UNLIKELY (parse->priv->pending_segment)) {
GST_DEBUG_OBJECT (parse, "%s push pending segment",
parse->priv->pad_mode == GST_ACTIVATE_PULL ? "loop" : "chain");
- gst_pad_push_event (parse->srcpad, parse->pending_segment);
- parse->pending_segment = NULL;
+ gst_pad_push_event (parse->srcpad, parse->priv->pending_segment);
+ parse->priv->pending_segment = NULL;
/* have caps; check identity */
gst_base_parse_check_media (parse);
/* 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);
}
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) {
ret = gst_pad_push (parse->srcpad, buffer);
- GST_LOG_OBJECT (parse, "frame (%d bytes) pushed: %s",
- GST_BUFFER_SIZE (buffer), gst_flow_get_name (ret));
+ GST_LOG_OBJECT (parse, "frame (%" G_GSIZE_FORMAT " bytes) pushed: %s",
+ size, 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_buffer_unref (buffer);
- 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));
/* if we are not sufficiently in control, let upstream decide on EOS */
if (ret == GST_FLOW_UNEXPECTED &&
- (GST_BASE_PARSE_PASSTHROUGH (parse) ||
+ (parse->priv->passthrough ||
(parse->priv->pad_mode == GST_ACTIVATE_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_clear (parse, frame);
+ gst_base_parse_frame_free (frame);
return ret;
}
-/**
- * gst_base_parse_drain:
- * @parse: #GstBaseParse.
+/* gst_base_parse_drain:
*
* Drains the adapter until it is empty. It decreases the min_frame_size to
* match the current adapter size and calls chain method until the adapter
parse->priv->drain = TRUE;
for (;;) {
- avail = gst_adapter_available (parse->adapter);
+ avail = gst_adapter_available (parse->priv->adapter);
if (!avail)
break;
}
/* nothing changed, maybe due to truncated frame; break infinite loop */
- if (avail == gst_adapter_available (parse->adapter)) {
+ if (avail == gst_adapter_available (parse->priv->adapter)) {
GST_DEBUG_OBJECT (parse, "no change during draining; flushing");
- gst_adapter_clear (parse->adapter);
+ gst_adapter_clear (parse->priv->adapter);
}
}
parse->priv->drain = FALSE;
}
-/**
- * gst_base_parse_process_fragment:
- * @parse: #GstBaseParse.
+/* gst_base_parse_send_buffers
*
* Sends buffers collected in send_buffers downstream, and ensures that list
* is empty at the end (errors or not).
return ret;
}
-/**
- * gst_base_parse_process_fragment:
- * @parse: #GstBaseParse.
+/* gst_base_parse_process_fragment:
*
* Processes a reverse playback (forward) fragment:
* - append head of last fragment that was skipped to current fragment data
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_adapter_push (parse->adapter, buf);
+ gst_buffer_get_size (buf));
+ gst_adapter_push (parse->priv->adapter, buf);
parse->priv->buffers_pending =
g_slist_delete_link (parse->priv->buffers_pending,
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;
ret = gst_base_parse_send_buffers (parse);
/* any trailing unused no longer usable (ideally none) */
- if (G_UNLIKELY (gst_adapter_available (parse->adapter))) {
+ if (G_UNLIKELY (gst_adapter_available (parse->priv->adapter))) {
GST_DEBUG_OBJECT (parse, "discarding %d trailing bytes",
- gst_adapter_available (parse->adapter));
- gst_adapter_clear (parse->adapter);
+ gst_adapter_available (parse->priv->adapter));
+ gst_adapter_clear (parse->priv->adapter);
}
return ret;
return GST_FLOW_OK;
}
-
-/**
- * gst_base_parse_chain:
- * @pad: #GstPad.
- * @buffer: #GstBuffer.
- *
- * Returns: #GstFlowReturn.
- */
static GstFlowReturn
gst_base_parse_chain (GstPad * pad, GstBuffer * buffer)
{
const guint8 *data;
guint old_min_size = 0, min_size, av;
GstClockTime timestamp;
- GstBaseParseFrame _frame = { 0, };
GstBaseParseFrame *frame;
parse = GST_BASE_PARSE (GST_OBJECT_PARENT (pad));
bclass = GST_BASE_PARSE_GET_CLASS (parse);
- frame = &_frame;
+ 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));
- if (G_UNLIKELY (GST_BASE_PARSE_PASSTHROUGH (parse))) {
- frame->buffer = gst_buffer_make_metadata_writable (buffer);
+ 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_writable (buffer);
return gst_base_parse_push_frame (parse, frame);
}
/* upstream feeding us in reverse playback;
GST_DEBUG_OBJECT (parse, "buffer starts new reverse playback fragment");
ret = gst_base_parse_process_fragment (parse, FALSE);
}
- gst_adapter_push (parse->adapter, buffer);
+ gst_adapter_push (parse->priv->adapter, buffer);
return ret;
}
- gst_adapter_push (parse->adapter, buffer);
+ gst_adapter_push (parse->priv->adapter, buffer);
+ }
+
+ if (G_UNLIKELY (buffer &&
+ GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))) {
+ frame->_private_flags |= GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC;
+ gst_base_parse_frame_free (frame);
}
/* Parse and push as many frames as possible */
while (!parse->priv->flushing) {
gboolean res;
+ /* maintain frame state for a single frame parsing round across _chain calls,
+ * so only init when needed */
+ if (!frame->_private_flags)
+ gst_base_parse_frame_init (frame);
+
tmpbuf = gst_buffer_new ();
old_min_size = 0;
/* Synchronization loop */
for (;;) {
+ /* note: if subclass indicates MAX fsize,
+ * this will not likely be available anyway ... */
min_size = MAX (parse->priv->min_frame_size, fsize);
- av = gst_adapter_available (parse->adapter);
+ av = gst_adapter_available (parse->priv->adapter);
/* loop safety check */
if (G_UNLIKELY (old_min_size >= min_size))
}
/* always pass all available data */
- data = gst_adapter_peek (parse->adapter, av);
- GST_BUFFER_DATA (tmpbuf) = (guint8 *) data;
- GST_BUFFER_SIZE (tmpbuf) = min_size;
+ 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, 0);
gst_buffer_replace (&frame->buffer, NULL);
if (res) {
- if (gst_adapter_available (parse->adapter) < fsize) {
+ if (gst_adapter_available (parse->priv->adapter) < fsize) {
GST_DEBUG_OBJECT (parse,
"found valid frame but not enough data available (only %d bytes)",
- gst_adapter_available (parse->adapter));
+ gst_adapter_available (parse->priv->adapter));
gst_buffer_unref (tmpbuf);
goto done;
}
/* 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 ... */
- timestamp = gst_adapter_prev_timestamp (parse->adapter, NULL);
- outbuf = gst_adapter_take_buffer (parse->adapter, skip);
- outbuf = gst_buffer_make_metadata_writable (outbuf);
+ timestamp = gst_adapter_prev_timestamp (parse->priv->adapter, NULL);
+ outbuf = gst_adapter_take_buffer (parse->priv->adapter, skip);
+ outbuf = gst_buffer_make_writable (outbuf);
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
parse->priv->buffers_pending =
g_slist_prepend (parse->priv->buffers_pending, outbuf);
outbuf = NULL;
} else {
- gst_adapter_flush (parse->adapter, skip);
+ gst_adapter_flush (parse->priv->adapter, skip);
}
parse->priv->offset += skip;
if (!parse->priv->discont)
if (skip > 0) {
/* Subclass found the sync, but still wants to skip some data */
GST_LOG_OBJECT (parse, "skipping %d bytes", skip);
- gst_adapter_flush (parse->adapter, skip);
+ gst_adapter_flush (parse->priv->adapter, skip);
parse->priv->offset += skip;
}
/* move along with upstream timestamp (if any),
* but interpolate in between */
- timestamp = gst_adapter_prev_timestamp (parse->adapter, NULL);
+ timestamp = gst_adapter_prev_timestamp (parse->priv->adapter, NULL);
if (GST_CLOCK_TIME_IS_VALID (timestamp) &&
(parse->priv->prev_ts != timestamp)) {
parse->priv->prev_ts = parse->priv->next_ts = timestamp;
}
/* FIXME: Would it be more efficient to make a subbuffer instead? */
- outbuf = gst_adapter_take_buffer (parse->adapter, fsize);
- outbuf = gst_buffer_make_metadata_writable (outbuf);
+ outbuf = gst_adapter_take_buffer (parse->priv->adapter, fsize);
+ 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));
+ 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;
/* offset will increase again as fragment is processed/parsed */
parse->priv->last_offset = offset;
- gst_adapter_push (parse->adapter, buffer);
+ gst_adapter_push (parse->priv->adapter, buffer);
ret = gst_base_parse_process_fragment (parse, FALSE);
if (ret != GST_FLOW_OK)
goto exit;
GST_LOG_OBJECT (parse, "scanning for frame at offset %" G_GUINT64_FORMAT
" (%#" G_GINT64_MODIFIER "x)", parse->priv->offset, parse->priv->offset);
+ /* let's make this efficient for all subclass once and for all;
+ * maybe it does not need this much, but in the latter case, we know we are
+ * in pull mode here and might as well try to read and supply more anyway
+ * (so does the buffer caching mechanism) */
+ fsize = 64 * 1024;
+
while (TRUE) {
gboolean res;
/* 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;
skip = -1;
/* 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;
if (!parse->priv->discont)
parse->priv->sync_offset = parse->priv->offset;
parse->priv->discont = TRUE;
- /* something changed least; nullify loop check */
+ /* something changed at least; nullify loop check */
+ if (fsize == G_MAXUINT)
+ fsize = old_min_size + 64 * 1024;
old_min_size = 0;
}
/* skip == 0 should imply subclass set min_size to need more data;
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;
}
}
}
-/**
- * gst_base_parse_loop:
- * @pad: GstPad
- *
- * Loop that is used in pull mode to retrieve data from upstream.
- */
+/* Loop that is used in pull mode to retrieve data from upstream */
static void
gst_base_parse_loop (GstPad * pad)
{
GstBaseParse *parse;
GstBaseParseClass *klass;
GstFlowReturn ret = GST_FLOW_OK;
- GstBaseParseFrame frame = { 0, };
+ GstBaseParseFrame frame;
parse = GST_BASE_PARSE (gst_pad_get_parent (pad));
klass = GST_BASE_PARSE_GET_CLASS (parse);
}
}
+ gst_base_parse_frame_init (&frame);
ret = gst_base_parse_scan_frame (parse, klass, &frame, TRUE);
if (ret != GST_FLOW_OK)
goto done;
/* 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) {
+ 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);
}
if (push_eos) {
/* newsegment before eos */
- if (parse->pending_segment) {
- gst_pad_push_event (parse->srcpad, parse->pending_segment);
- parse->pending_segment = NULL;
+ if (parse->priv->pending_segment) {
+ gst_pad_push_event (parse->srcpad, parse->priv->pending_segment);
+ parse->priv->pending_segment = NULL;
}
gst_pad_push_event (parse->srcpad, gst_event_new_eos ());
}
}
}
-
-/**
- * gst_base_parse_sink_activate:
- * @sinkpad: #GstPad to be activated.
- *
- * Returns: TRUE if activation succeeded.
- */
static gboolean
gst_base_parse_sink_activate (GstPad * sinkpad)
{
GstBaseParse *parse;
gboolean result = TRUE;
+ GstQuery *query;
+ gboolean pull_mode;
parse = GST_BASE_PARSE (gst_pad_get_parent (sinkpad));
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) {
+ gst_query_parse_scheduling (query, &pull_mode, NULL, NULL, NULL, NULL,
+ NULL);
+ } 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);
} else {
return result;
}
-
-/**
- * gst_base_parse_activate:
- * @parse: #GstBaseParse.
- * @active: TRUE if element will be activated, FALSE if deactivated.
- *
- * Returns: TRUE if the operation succeeded.
- */
static gboolean
gst_base_parse_activate (GstBaseParse * parse, gboolean active)
{
return result;
}
-
-/**
- * gst_base_parse_sink_activate_push:
- * @pad: #GstPad to be (de)activated.
- * @active: TRUE when activating, FALSE when deactivating.
- *
- * Returns: TRUE if (de)activation succeeded.
- */
static gboolean
gst_base_parse_sink_activate_push (GstPad * pad, gboolean active)
{
return result;
}
-
-/**
- * gst_base_parse_sink_activate_pull:
- * @sinkpad: #GstPad to be (de)activated.
- * @active: TRUE when activating, FALSE when deactivating.
- *
- * Returns: TRUE if (de)activation succeeded.
- */
static gboolean
gst_base_parse_sink_activate_pull (GstPad * sinkpad, gboolean active)
{
if (result) {
if (active) {
- parse->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);
+ parse->priv->pending_segment = gst_event_new_segment (&parse->segment);
+ result &=
+ gst_pad_start_task (sinkpad, (GstTaskFunction) gst_base_parse_loop,
+ sinkpad);
} else {
result &= gst_pad_stop_task (sinkpad);
}
* @parse: #GstBaseParse.
* @fmt: #GstFormat.
* @duration: duration value.
+ * @interval: how often to update the duration estimate based on bitrate, or 0.
*
* Sets the duration of the currently playing media. Subclass can use this
* when it is able to determine duration and/or notices a change in the media
* duration. Alternatively, if @interval is non-zero (default), then stream
* duration is determined based on estimated bitrate, and updated every @interval
- * frames. */
+ * frames.
+ *
+ * Since: 0.10.33
+ */
void
gst_base_parse_set_duration (GstBaseParse * parse,
GstFormat fmt, gint64 duration, gint interval)
}
/**
- * gst_base_parse_set_seek:
+ * gst_base_parse_set_average_bitrate:
* @parse: #GstBaseParse.
- * @seek: #GstBaseParseSeekable.
- * @abitrate: average bitrate.
+ * @bitrate: average bitrate in bits/second
*
- * Sets whether and how the media is seekable (in time).
- * Also optionally provides average bitrate detected in media (if non-zero),
+ * Optionally sets the average bitrate detected in media (if non-zero),
* e.g. based on metadata, as it will be posted to the application.
*
- * By default, announced average bitrate is estimated, and seekability is assumed
- * possible based on estimated bitrate.
+ * By default, announced average bitrate is estimated. The average bitrate
+ * is used to estimate the total duration of the stream and to estimate
+ * a seek position, if there's no index and the format is syncable
+ * (see gst_base_parse_set_syncable()).
+ *
+ * Since: 0.10.33
*/
void
-gst_base_parse_set_seek (GstBaseParse * parse,
- GstBaseParseSeekable seek, guint bitrate)
+gst_base_parse_set_average_bitrate (GstBaseParse * parse, guint bitrate)
{
- parse->priv->seekable = seek;
parse->priv->bitrate = bitrate;
- GST_DEBUG_OBJECT (parse, "seek %d, bitrate %d", seek, bitrate);
+ GST_DEBUG_OBJECT (parse, "bitrate %u", bitrate);
}
-
/**
* gst_base_parse_set_min_frame_size:
* @parse: #GstBaseParse.
*
* Subclass can use this function to tell the base class that it needs to
* give at least #min_size buffers.
+ *
+ * Since: 0.10.33
*/
void
gst_base_parse_set_min_frame_size (GstBaseParse * parse, guint min_size)
}
/**
- * gst_base_parse_set_format:
- * @parse: the #GstBaseParseFormat to set or unset
- * @flags: format flag to enable or disable
- * @on: whether or not to enable
- *
- * Set flags describing characteristics of parsed format.
- */
-void
-gst_base_parse_set_format (GstBaseParse * parse, GstBaseParseFormat flag,
- gboolean on)
-{
- g_return_if_fail (parse != NULL);
-
- GST_LOG_OBJECT (parse, "set flag %d to %d", flag, on);
- if (on)
- parse->priv->format |= flag;
- else
- parse->priv->format &= ~flag;
-}
-
-/**
- * gst_base_parse_set_frame_props:
+ * gst_base_parse_set_frame_rate:
* @parse: the #GstBaseParse to set
* @fps_num: frames per second (numerator).
* @fps_den: frames per second (denominator).
* location, a corresponding decoder might need an initial @lead_in and a
* following @lead_out number of frames to ensure the desired segment is
* entirely filled upon decoding.
+ *
+ * Since: 0.10.33
*/
void
-gst_base_parse_set_frame_props (GstBaseParse * parse, guint fps_num,
+gst_base_parse_set_frame_rate (GstBaseParse * parse, guint fps_num,
guint fps_den, guint lead_in, guint lead_out)
{
g_return_if_fail (parse != NULL);
lead_out, parse->priv->lead_out_ts / GST_MSECOND);
}
+/**
+ * gst_base_parse_set_has_timing_info:
+ * @parse: a #GstBaseParse
+ * @has_timing: whether frames carry timing information
+ *
+ * Set if frames carry timing information which the subclass can (generally)
+ * parse and provide. In particular, intrinsic (rather than estimated) time
+ * can be obtained following a seek.
+ *
+ * Since: 0.10.33
+ */
+void
+gst_base_parse_set_has_timing_info (GstBaseParse * parse, gboolean has_timing)
+{
+ parse->priv->has_timing_info = has_timing;
+ GST_INFO_OBJECT (parse, "has_timing: %s", (has_timing) ? "yes" : "no");
+}
+
+/**
+ * gst_base_parse_set_syncable:
+ * @parse: a #GstBaseParse
+ * @syncable: set if frame starts can be identified
+ *
+ * Set if frame starts can be identified. This is set by default and
+ * determines whether seeking based on bitrate averages
+ * is possible for a format/stream.
+ *
+ * Since: 0.10.33
+ */
+void
+gst_base_parse_set_syncable (GstBaseParse * parse, gboolean syncable)
+{
+ parse->priv->syncable = syncable;
+ GST_INFO_OBJECT (parse, "syncable: %s", (syncable) ? "yes" : "no");
+}
+
+/**
+ * gst_base_parse_set_passthrough:
+ * @parse: a #GstBaseParse
+ * @passthrough: %TRUE if parser should run in passthrough mode
+ *
+ * Set if the nature of the format or configuration does not allow (much)
+ * 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,
+ * so subclass can perform as much or as little is appropriate for
+ * passthrough semantics in @pre_push_buffer.
+ *
+ * Since: 0.10.33
+ */
+void
+gst_base_parse_set_passthrough (GstBaseParse * parse, gboolean passthrough)
+{
+ parse->priv->passthrough = passthrough;
+ GST_INFO_OBJECT (parse, "passthrough: %s", (passthrough) ? "yes" : "no");
+}
+
+/**
+ * gst_base_parse_set_latency:
+ * @parse: a #GstBaseParse
+ * @min_latency: minimum parse latency
+ * @max_latency: maximum parse latency
+ *
+ * Sets the minimum and maximum (which may likely be equal) latency introduced
+ * 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
+ */
+void
+gst_base_parse_set_latency (GstBaseParse * parse, GstClockTime min_latency,
+ GstClockTime max_latency)
+{
+ GST_OBJECT_LOCK (parse);
+ parse->priv->min_latency = min_latency;
+ parse->priv->max_latency = max_latency;
+ GST_OBJECT_UNLOCK (parse);
+ GST_INFO_OBJECT (parse, "min/max latency %" GST_TIME_FORMAT ", %"
+ GST_TIME_FORMAT, GST_TIME_ARGS (min_latency),
+ GST_TIME_ARGS (max_latency));
+}
+
static gboolean
gst_base_parse_get_duration (GstBaseParse * parse, GstFormat format,
GstClockTime * duration)
return res;
}
-/**
- * gst_base_parse_get_querytypes:
- * @pad: GstPad
- *
- * Returns: A table of #GstQueryType items describing supported query types.
- */
static const GstQueryType *
gst_base_parse_get_querytypes (GstPad * pad)
{
return list;
}
-
-/**
- * gst_base_parse_query:
- * @pad: #GstPad.
- * @query: #GstQuery.
- *
- * Returns: TRUE on success.
- */
static gboolean
gst_base_parse_query (GstPad * pad, GstQuery * query)
{
dest_value = parse->priv->offset;
res = TRUE;
} else if (format == parse->segment.format &&
- GST_CLOCK_TIME_IS_VALID (parse->segment.last_stop)) {
- dest_value = parse->segment.last_stop;
+ GST_CLOCK_TIME_IS_VALID (parse->segment.position)) {
+ dest_value = parse->segment.position;
res = TRUE;
}
GST_OBJECT_UNLOCK (parse);
res = gst_pad_query_default (pad, query);
/* we may be able to help if in TIME */
- if (fmt == GST_FORMAT_TIME &&
- parse->priv->seekable > GST_BASE_PARSE_SEEK_NONE) {
+ if (fmt == GST_FORMAT_TIME && gst_base_parse_is_seekable (parse)) {
gst_query_parse_seeking (query, &fmt, &seekable, NULL, NULL);
/* already OK if upstream takes care */
GST_LOG_OBJECT (parse, "upstream handled %d, seekable %d",
}
break;
}
+ case GST_QUERY_LATENCY:
+ {
+ if ((res = gst_pad_peer_query (parse->sinkpad, query))) {
+ gboolean live;
+ GstClockTime min_latency, max_latency;
+
+ gst_query_parse_latency (query, &live, &min_latency, &max_latency);
+ GST_DEBUG_OBJECT (parse, "Peer latency: live %d, min %"
+ GST_TIME_FORMAT " max %" GST_TIME_FORMAT, live,
+ GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
+
+ GST_OBJECT_LOCK (parse);
+ /* add our latency */
+ if (min_latency != -1)
+ min_latency += parse->priv->min_latency;
+ if (max_latency != -1)
+ max_latency += parse->priv->max_latency;
+ GST_OBJECT_UNLOCK (parse);
+
+ gst_query_set_latency (query, live, min_latency, max_latency);
+ }
+ break;
+ }
default:
res = gst_pad_query_default (pad, query);
break;
gboolean orig_drain, orig_discont;
GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *buf = NULL;
- GstBaseParseFrame frame = { 0, };
+ GstBaseParseFrame frame;
- g_return_val_if_fail (GST_FLOW_ERROR, pos != NULL);
- g_return_val_if_fail (GST_FLOW_ERROR, time != NULL);
- g_return_val_if_fail (GST_FLOW_ERROR, duration != NULL);
+ g_return_val_if_fail (pos != NULL, GST_FLOW_ERROR);
+ g_return_val_if_fail (time != NULL, GST_FLOW_ERROR);
+ g_return_val_if_fail (duration != NULL, GST_FLOW_ERROR);
klass = GST_BASE_PARSE_GET_CLASS (parse);
GST_DEBUG_OBJECT (parse, "scanning for frame starting at %" G_GINT64_FORMAT
" (%#" G_GINT64_MODIFIER "x)", *pos, *pos);
+ gst_base_parse_frame_init (&frame);
+
/* jump elsewhere and locate next frame */
parse->priv->offset = *pos;
ret = gst_base_parse_scan_frame (parse, klass, &frame, FALSE);
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));
+ 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);
/* but it should provide proper time */
*time = GST_BUFFER_TIMESTAMP (buf);
*duration = GST_BUFFER_DURATION (buf);
- gst_base_parse_frame_clear (parse, &frame);
+
+ gst_base_parse_frame_free (&frame);
GST_LOG_OBJECT (parse,
"frame with time %" GST_TIME_FORMAT " at offset %" G_GINT64_FORMAT,
goto exit;
}
- GST_OBJECT_LOCK (parse);
+ g_static_mutex_lock (&parse->priv->index_lock);
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,
ts = GST_CLOCK_TIME_NONE;
}
}
- GST_OBJECT_UNLOCK (parse);
+ g_static_mutex_unlock (&parse->priv->index_lock);
exit:
if (_ts)
return bytes;
}
-
-/**
- * gst_base_parse_handle_seek:
- * @parse: #GstBaseParse.
- * @event: #GstEvent.
- *
- * Returns: TRUE if seek succeeded.
- */
+/* returns TRUE if seek succeeded */
static gboolean
gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event)
{
/* 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;
+ start_ts = seeksegment.position;
dstformat = GST_FORMAT_BYTES;
- if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.last_stop,
+ if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.position,
&dstformat, &seekpos))
goto convert_failed;
if (!gst_pad_query_convert (parse->srcpad, format, seeksegment.stop,
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->close_segment)
- gst_event_unref (parse->close_segment);
-
- parse->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));
/* store the newsegment event so it can be sent from the streaming thread. */
- if (parse->pending_segment)
- gst_event_unref (parse->pending_segment);
+ if (parse->priv->pending_segment)
+ gst_event_unref (parse->priv->pending_segment);
/* This will be sent later in _loop() */
- parse->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, flush,
GST_SEEK_TYPE_SET, seekpos, stop_type, seekstop);
}
}
-/**
- * gst_base_parse_handle_tag:
- * @parse: #GstBaseParse.
- * @event: #GstEvent.
- *
- * Checks if bitrates are available from upstream tags so that we don't
+/* Checks if bitrates are available from upstream tags so that we don't
* override them later
*/
static void
}
}
-/**
- * gst_base_parse_sink_setcaps:
- * @pad: #GstPad.
- * @caps: #GstCaps.
- *
- * Returns: TRUE if caps were accepted.
- */
-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;
-}
-
static void
gst_base_parse_set_index (GstElement * element, GstIndex * index)
{
GstBaseParse *parse = GST_BASE_PARSE (element);
- GST_OBJECT_LOCK (parse);
+ g_static_mutex_lock (&parse->priv->index_lock);
if (parse->priv->index)
gst_object_unref (parse->priv->index);
if (index) {
parse->priv->index = gst_object_ref (index);
- gst_index_get_writer_id (index, GST_OBJECT (element),
+ gst_index_get_writer_id (index, GST_OBJECT_CAST (element),
&parse->priv->index_id);
parse->priv->own_index = FALSE;
- } else
+ } else {
parse->priv->index = NULL;
- GST_OBJECT_UNLOCK (parse);
+ }
+ g_static_mutex_unlock (&parse->priv->index_lock);
}
static GstIndex *
GstBaseParse *parse = GST_BASE_PARSE (element);
GstIndex *result = NULL;
- GST_OBJECT_LOCK (parse);
+ g_static_mutex_lock (&parse->priv->index_lock);
if (parse->priv->index)
result = gst_object_ref (parse->priv->index);
- GST_OBJECT_UNLOCK (parse);
+ g_static_mutex_unlock (&parse->priv->index_lock);
return result;
}
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);
if (parse->priv->own_index) {
gst_object_unref (parse->priv->index);
parse->priv->index = NULL;
&parse->priv->index_id);
parse->priv->own_index = TRUE;
}
+ g_static_mutex_unlock (&parse->priv->index_lock);
break;
default:
break;