baseparse: modify API to a _finish_frame based approach

... which aligns it with other baseclass in the wild, and should give
converter parsers a bit cleaner freedom.
This commit is contained in:
Mark Nauwelaerts 2012-02-13 18:22:37 +01:00
parent c6a1bed1ad
commit b761f5479a
2 changed files with 381 additions and 338 deletions

View file

@ -50,14 +50,16 @@
* <listitem> * <listitem>
* <itemizedlist><title>Set-up phase</title> * <itemizedlist><title>Set-up phase</title>
* <listitem><para> * <listitem><para>
* GstBaseParse class calls @set_sink_caps to inform the subclass about
* incoming sinkpad caps. Subclass should set the srcpad caps accordingly.
* </para></listitem>
* <listitem><para>
* GstBaseParse calls @start to inform subclass that data processing is * GstBaseParse calls @start to inform subclass that data processing is
* about to start now. * about to start now.
* </para></listitem> * </para></listitem>
* <listitem><para> * <listitem><para>
* GstBaseParse class calls @set_sink_caps to inform the subclass about
* incoming sinkpad caps. Subclass could already set the srcpad caps
* accordingly, but this might be delayed until calling
* gst_base_parse_finish_frame() with a non-queued frame.
* </para></listitem>
* <listitem><para>
* At least at 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 * 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().
@ -78,34 +80,39 @@
* </para></listitem> * </para></listitem>
* <listitem><para> * <listitem><para>
* A buffer of (at least) min_frame_size bytes is passed to subclass with * A buffer of (at least) min_frame_size bytes is passed to subclass with
* @check_valid_frame. Subclass checks the contents and returns TRUE * @handle_frame. Subclass checks the contents and can optionally
* if the buffer contains a valid frame. It also needs to set the * return GST_FLOW_OK along with an amount of data to be skipped to find
* @framesize according to the detected frame size. If buffer didn't * a valid frame (which will result in a subsequent DISCONT).
* contain a valid frame, this call must return FALSE and optionally * If, otherwise, the buffer does not hold a complete frame,
* set the @skipsize value to inform base class that how many bytes * @handle_frame can merely return and will be called again when additional
* it needs to skip in order to find a valid frame. @framesize can always * data is available. In push mode this amounts to an
* indicate a new minimum for current frame parsing. Indicating G_MAXUINT * additional input buffer (thus minimal additional latency), in pull mode
* for requested amount means subclass simply needs best available * this amounts to some arbitrary reasonable buffer size increase.
* subsequent data. In push mode this amounts to an additional input buffer * Of course, gst_base_parse_set_min_size() could also be used if a very
* (thus minimal additional latency), in pull mode this amounts to some * specific known amount of additional data is required.
* arbitrary reasonable buffer size increase. The passed buffer * If, however, the buffer holds a complete valid frame, it can pass
* is read-only. Note that @check_valid_frame might receive any small * the size of this frame to gst_base_parse_finish_frame().
* amount of input data when leftover data is being drained (e.g. at EOS). * If acting as a converter, it can also merely indicate consumed input data
* </para></listitem> * while simultaneously providing custom output data.
* <listitem><para> * Note that baseclass performs some processing (such as tracking
* After valid frame is found, it will be passed again to subclass with * overall consumed data rate versus duration) for each finished frame,
* @parse_frame call. Now subclass is responsible for parsing the * but other state is only updated upon each call to @handle_frame
* frame contents and setting the caps, and buffer metadata (e.g. * (such as tracking upstream input timestamp).
* buffer timestamp and duration, or keyframe if applicable). * </para><para>
* Subclass is also responsible for setting the buffer metadata
* (e.g. buffer timestamp and duration, or keyframe if applicable).
* (although the latter can also be done by GstBaseParse if it is * (although the latter can also be done by GstBaseParse if it is
* appropriately configured, see below). Frame is provided with * appropriately configured, see below). Frame is provided with
* timestamp derived from upstream (as much as generally possible), * timestamp derived from upstream (as much as generally possible),
* duration obtained from configuration (see below), and offset * duration obtained from configuration (see below), and offset
* if meaningful (in pull mode). * if meaningful (in pull mode).
* </para><para>
* 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> * </para></listitem>
* <listitem><para> * <listitem><para>
* Finally the buffer can be pushed downstream and the parsing loop starts * As part of finish frame processing,
* over again. Just prior to actually pushing the buffer in question, * just prior to actually pushing the buffer in question,
* it is passed to @pre_push_frame 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) * last chance to examine buffer metadata, or to send some custom (tag)
* events, or to perform custom (segment) filtering. * events, or to perform custom (segment) filtering.
@ -154,12 +161,9 @@
* done with gst_base_parse_set_min_frame_size() function. * done with gst_base_parse_set_min_frame_size() function.
* </para></listitem> * </para></listitem>
* <listitem><para> * <listitem><para>
* Examine data chunks passed to subclass with @check_valid_frame * Examine data chunks passed to subclass with @handle_frame and pass
* and tell if they contain a valid frame * proper frame(s) to gst_base_parse_finish_frame(), and setting src pad
* </para></listitem> * caps and timestamps on frame.
* <listitem><para>
* Set the caps and timestamp to frame that is passed to subclass with
* @parse_frame function.
* </para></listitem> * </para></listitem>
* <listitem><para>Provide conversion functions</para></listitem> * <listitem><para>Provide conversion functions</para></listitem>
* <listitem><para> * <listitem><para>
@ -262,6 +266,7 @@ struct _GstBaseParsePrivate
GstClockTime frame_duration; GstClockTime frame_duration;
gboolean seen_keyframe; gboolean seen_keyframe;
gboolean is_video; gboolean is_video;
gint flushed;
guint64 framecount; guint64 framecount;
guint64 bytecount; guint64 bytecount;
@ -317,8 +322,14 @@ struct _GstBaseParsePrivate
/* Newsegment event to be sent after SEEK */ /* Newsegment event to be sent after SEEK */
GstEvent *pending_segment; GstEvent *pending_segment;
/* push mode helper frame */ /* frame previously passed to subclass (might be re-used) */
GstBaseParseFrame frame; GstBaseParseFrame *prev_frame;
/* offset corresponding to above frame */
gint64 prev_offset;
/* whether we are merely scanning for a frame */
gboolean scanning;
/* ... and resulting frame, if any */
GstBaseParseFrame *scanned_frame;
/* TRUE if we're still detecting the format, i.e. /* TRUE if we're still detecting the format, i.e.
* if ::detect() is still called for future buffers */ * if ::detect() is still called for future buffers */
@ -405,8 +416,6 @@ static GstFlowReturn gst_base_parse_chain (GstPad * pad, GstObject * parent,
GstBuffer * buffer); GstBuffer * buffer);
static void gst_base_parse_loop (GstPad * pad); static void gst_base_parse_loop (GstPad * pad);
static gboolean gst_base_parse_check_frame (GstBaseParse * parse,
GstBaseParseFrame * frame, guint * framesize, gint * skipsize);
static GstFlowReturn gst_base_parse_parse_frame (GstBaseParse * parse, static GstFlowReturn gst_base_parse_parse_frame (GstBaseParse * parse,
GstBaseParseFrame * frame); GstBaseParseFrame * frame);
@ -510,8 +519,6 @@ gst_base_parse_class_init (GstBaseParseClass * klass)
#endif #endif
/* Default handlers */ /* Default handlers */
klass->check_valid_frame = gst_base_parse_check_frame;
klass->parse_frame = gst_base_parse_parse_frame;
klass->src_event = gst_base_parse_src_eventfunc; klass->src_event = gst_base_parse_src_eventfunc;
klass->convert = gst_base_parse_convert_default; klass->convert = gst_base_parse_convert_default;
@ -748,9 +755,10 @@ gst_base_parse_reset (GstBaseParse * parse)
gst_adapter_clear (parse->priv->adapter); gst_adapter_clear (parse->priv->adapter);
/* we know it is not alloc'ed, but maybe other stuff to free, some day ... */ /* we know it is not alloc'ed, but maybe other stuff to free, some day ... */
parse->priv->frame._private_flags |= if (parse->priv->prev_frame) {
GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC; gst_base_parse_frame_free (parse->priv->prev_frame);
gst_base_parse_frame_free (&parse->priv->frame); parse->priv->prev_frame = NULL;
}
g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref, NULL); g_list_foreach (parse->priv->detect_buffers, (GFunc) gst_buffer_unref, NULL);
g_list_free (parse->priv->detect_buffers); g_list_free (parse->priv->detect_buffers);
@ -759,27 +767,6 @@ gst_base_parse_reset (GstBaseParse * parse)
GST_OBJECT_UNLOCK (parse); GST_OBJECT_UNLOCK (parse);
} }
/* gst_base_parse_check_frame:
* @parse: #GstBaseParse.
* @buffer: GstBuffer.
* @framesize: This will be set to tell the found frame size in bytes.
* @skipsize: Output parameter that tells how much data needs to be skipped
* in order to find the following frame header.
*
* Default callback for check_valid_frame.
*
* Returns: Always TRUE.
*/
static gboolean
gst_base_parse_check_frame (GstBaseParse * parse,
GstBaseParseFrame * frame, guint * framesize, gint * skipsize)
{
*framesize = gst_buffer_get_size (frame->buffer);
*skipsize = 0;
return TRUE;
}
/* gst_base_parse_parse_frame: /* gst_base_parse_parse_frame:
* @parse: #GstBaseParse. * @parse: #GstBaseParse.
* @buffer: #GstBuffer. * @buffer: #GstBuffer.
@ -1091,9 +1078,10 @@ gst_base_parse_sink_eventfunc (GstBaseParse * parse, GstEvent * event)
parse->priv->flushing = FALSE; parse->priv->flushing = FALSE;
parse->priv->discont = TRUE; parse->priv->discont = TRUE;
parse->priv->last_ts = GST_CLOCK_TIME_NONE; parse->priv->last_ts = GST_CLOCK_TIME_NONE;
parse->priv->frame._private_flags |= if (parse->priv->prev_frame) {
GST_BASE_PARSE_FRAME_PRIVATE_FLAG_NOALLOC; gst_base_parse_frame_free (parse->priv->prev_frame);
gst_base_parse_frame_free (&parse->priv->frame); parse->priv->prev_frame = NULL;
}
break; break;
case GST_EVENT_EOS: case GST_EVENT_EOS:
@ -1688,6 +1676,120 @@ gst_base_parse_queue_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
} }
} }
/* makes sure that @buf is properly prepared and decorated for passing
* to baseclass, and an equally setup frame is returned setup with @buf.
* Takes ownership of @buf. */
static GstBaseParseFrame *
gst_base_parse_prepare_frame (GstBaseParse * parse, GstBuffer * buffer)
{
GstBaseParseFrame *frame = NULL;
buffer = gst_buffer_make_writable (buffer);
GST_LOG_OBJECT (parse,
"preparing frame at offset %" G_GUINT64_FORMAT
" (%#" G_GINT64_MODIFIER "x) of size %" G_GSIZE_FORMAT,
GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET (buffer),
gst_buffer_get_size (buffer));
if (parse->priv->discont) {
GST_DEBUG_OBJECT (parse, "marking DISCONT");
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
parse->priv->discont = FALSE;
}
GST_BUFFER_OFFSET (buffer) = parse->priv->offset;
if (parse->priv->prev_frame) {
if (parse->priv->prev_offset == parse->priv->offset) {
frame = parse->priv->prev_frame;
} else {
gst_base_parse_frame_free (parse->priv->prev_frame);
}
parse->priv->prev_frame = NULL;
}
if (!frame) {
frame = gst_base_parse_frame_new (buffer, 0, 0);
}
/* also ensure to update state flags */
gst_base_parse_frame_update (parse, frame, buffer);
gst_buffer_unref (buffer);
frame->offset = parse->priv->prev_offset = parse->priv->offset;
/* use default handler to provide initial (upstream) metadata */
gst_base_parse_parse_frame (parse, frame);
return frame;
}
static void
gst_base_parse_unprepare_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
{
g_assert (parse->priv->prev_frame == NULL);
parse->priv->prev_frame = frame;
gst_base_parse_frame_update (parse, frame, NULL);
}
/* takes ownership of @buffer */
static GstFlowReturn
gst_base_parse_handle_buffer (GstBaseParse * parse, GstBuffer * buffer,
gint * skip, gint * flushed)
{
GstBaseParseClass *klass = GST_BASE_PARSE_GET_CLASS (parse);
GstBaseParseFrame *frame;
GstFlowReturn ret;
g_return_val_if_fail (skip != NULL || flushed != NULL, GST_FLOW_ERROR);
/* track what is being flushed during this single round of frame processing */
parse->priv->flushed = 0;
*skip = 0;
/* make it easy for _finish_frame to pick up input data */
if (parse->priv->pad_mode == GST_PAD_MODE_PULL) {
gst_buffer_ref (buffer);
gst_adapter_push (parse->priv->adapter, buffer);
}
frame = gst_base_parse_prepare_frame (parse, buffer);
ret = klass->handle_frame (parse, frame, skip);
gst_base_parse_unprepare_frame (parse, frame);
if (parse->priv->pad_mode == GST_PAD_MODE_PULL) {
gst_adapter_clear (parse->priv->adapter);
}
*flushed = parse->priv->flushed;
GST_LOG_OBJECT (parse, "handle_frame skipped %d, flushed %d",
*skip, *flushed);
/* subclass can only do one of these, or semantics are too unclear */
g_assert (*skip == 0 || *flushed == 0);
/* if it did something, clear frame state,
* though this should also trigger the offset check anyway */
if (*skip != 0 || *flushed != 0) {
GST_LOG_OBJECT (parse, "clearing prev frame");
gst_base_parse_frame_free (parse->priv->prev_frame);
parse->priv->prev_frame = NULL;
}
parse->priv->offset += *flushed;
#ifndef GST_DISABLE_GST_DEBUG
if (ret != GST_FLOW_OK) {
GST_DEBUG_OBJECT (parse, "handle_frame returned %d", ret);
}
#endif
return ret;
}
/* gst_base_parse_handle_and_push_buffer: /* gst_base_parse_handle_and_push_buffer:
* @parse: #GstBaseParse. * @parse: #GstBaseParse.
* @klass: #GstBaseParseClass. * @klass: #GstBaseParseClass.
@ -1702,48 +1804,25 @@ gst_base_parse_queue_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
*/ */
static GstFlowReturn static GstFlowReturn
gst_base_parse_handle_and_push_frame (GstBaseParse * parse, gst_base_parse_handle_and_push_frame (GstBaseParse * parse,
GstBaseParseClass * klass, GstBaseParseFrame * frame) GstBaseParseFrame * frame)
{ {
GstFlowReturn ret;
gint64 offset; gint64 offset;
GstBuffer *buffer; GstBuffer *buffer;
g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR); g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR);
buffer = frame->buffer;
if (parse->priv->discont) {
GST_DEBUG_OBJECT (parse, "marking DISCONT");
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
parse->priv->discont = FALSE;
}
/* some one-time start-up */ /* some one-time start-up */
if (G_UNLIKELY (!parse->priv->framecount)) { if (G_UNLIKELY (!parse->priv->framecount)) {
gst_base_parse_check_seekability (parse); gst_base_parse_check_seekability (parse);
gst_base_parse_check_upstream (parse); gst_base_parse_check_upstream (parse);
} }
GST_LOG_OBJECT (parse,
"parsing frame at offset %" G_GUINT64_FORMAT
" (%#" G_GINT64_MODIFIER "x) of size %" G_GSIZE_FORMAT,
GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET (buffer),
gst_buffer_get_size (buffer));
/* use default handler to provide initial (upstream) metadata */
gst_base_parse_parse_frame (parse, frame);
/* store offset as it might get overwritten */
offset = GST_BUFFER_OFFSET (buffer);
ret = klass->parse_frame (parse, frame);
/* sync */
buffer = frame->buffer; buffer = frame->buffer;
/* subclass must play nice */ offset = frame->offset;
g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
/* check if subclass/format can provide ts. /* check if subclass/format can provide ts.
* If so, that allows and enables extra seek and duration determining options */ * 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 (G_UNLIKELY (parse->priv->first_frame_offset < 0)) {
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) && parse->priv->has_timing_info if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer) && parse->priv->has_timing_info
&& parse->priv->pad_mode == GST_PAD_MODE_PULL) { && parse->priv->pad_mode == GST_PAD_MODE_PULL) {
parse->priv->first_frame_offset = offset; parse->priv->first_frame_offset = offset;
@ -1787,19 +1866,6 @@ gst_base_parse_handle_and_push_frame (GstBaseParse * parse,
GST_BUFFER_TIMESTAMP (buffer), GST_BUFFER_TIMESTAMP (buffer),
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT), FALSE); !GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT), FALSE);
/* First buffers are dropped, this means that the subclass needs more
* 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_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 */ /* All OK, push queued frames if there are any */
if (G_UNLIKELY (!g_queue_is_empty (&parse->priv->queued_frames))) { if (G_UNLIKELY (!g_queue_is_empty (&parse->priv->queued_frames))) {
GstBaseParseFrame *queued_frame; GstBaseParseFrame *queued_frame;
@ -1815,12 +1881,11 @@ gst_base_parse_handle_and_push_frame (GstBaseParse * parse,
/** /**
* gst_base_parse_push_frame: * gst_base_parse_push_frame:
* @parse: #GstBaseParse. * @parse: #GstBaseParse.
* @frame: (transfer full): a #GstBaseParseFrame * @frame: (transfer none): a #GstBaseParseFrame
* *
* Pushes the frame downstream, sends any pending events and * Pushes the frame's buffer downstream, sends any pending events and
* does some timestamp and segment handling. Takes ownership * does some timestamp and segment handling. Takes ownership of
* of @frame and will clear it (if it was initialised with * frame's buffer, though caller retains ownership of @frame.
* gst_base_parse_frame_init()) or free it.
* *
* This must be called with sinkpad STREAM_LOCK held. * This must be called with sinkpad STREAM_LOCK held.
* *
@ -1852,8 +1917,7 @@ gst_base_parse_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
/* update stats */ /* update stats */
size = gst_buffer_get_size (buffer); parse->priv->bytecount += frame->size;
parse->priv->bytecount += size;
if (G_LIKELY (!(frame->flags & GST_BASE_PARSE_FRAME_FLAG_NO_FRAME))) { if (G_LIKELY (!(frame->flags & GST_BASE_PARSE_FRAME_FLAG_NO_FRAME))) {
parse->priv->framecount++; parse->priv->framecount++;
if (GST_BUFFER_DURATION_IS_VALID (buffer)) { if (GST_BUFFER_DURATION_IS_VALID (buffer)) {
@ -1968,12 +2032,20 @@ gst_base_parse_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
} }
/* take final ownership of frame buffer */ /* take final ownership of frame buffer */
buffer = frame->buffer; if (frame->out_buffer) {
frame->buffer = NULL; buffer = frame->out_buffer;
frame->out_buffer = NULL;
gst_buffer_replace (&frame->buffer, NULL);
} else {
buffer = frame->buffer;
frame->buffer = NULL;
}
/* subclass must play nice */ /* subclass must play nice */
g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR); g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
size = gst_buffer_get_size (buffer);
parse->priv->seen_keyframe |= parse->priv->is_video && parse->priv->seen_keyframe |= parse->priv->is_video &&
!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); !GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
@ -2035,8 +2107,6 @@ gst_base_parse_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
parse->segment.position < last_stop) parse->segment.position < last_stop)
parse->segment.position = last_stop; parse->segment.position = last_stop;
gst_base_parse_frame_free (frame);
return ret; return ret;
/* ERRORS */ /* ERRORS */
@ -2047,6 +2117,93 @@ no_caps:
} }
} }
/**
* gst_base_parse_finish_frame:
* @parse: a #GstBaseParse
* @frame: a #GstBaseParseFrame
* @size: consumed input data represented by frame
*
* Collects parsed data and pushes this downstream.
* Source pad caps must be set when this is called.
*
* If @frame's out_buffer is set, that will be used as subsequent frame data.
* Otherwise, @size samples will be taken from the input and used for output,
* and the output's metadata (timestamps etc) will be taken as (optionally)
* set by the subclass on @frame's (input) buffer.
*
* Note that the latter buffer is invalidated by this call, whereas the
* caller retains ownership of @frame.
*
* Returns: a #GstFlowReturn that should be escalated to caller (of caller)
*
* Since: 0.11.1
*/
GstFlowReturn
gst_base_parse_finish_frame (GstBaseParse * parse, GstBaseParseFrame * frame,
gint size)
{
GstFlowReturn ret = GST_FLOW_OK;
g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (frame->buffer != NULL, GST_FLOW_ERROR);
g_return_val_if_fail (size > 0 || frame->out_buffer, GST_FLOW_ERROR);
g_return_val_if_fail (gst_adapter_available (parse->priv->adapter) >= size,
GST_FLOW_ERROR);
GST_LOG_OBJECT (parse, "finished frame at offset %" G_GUINT64_FORMAT ", "
"flushing size %d", frame->offset, size);
if (parse->priv->scanning && frame->buffer) {
if (!parse->priv->scanned_frame) {
parse->priv->scanned_frame = gst_base_parse_frame_copy (frame);
}
goto exit;
}
parse->priv->flushed += size;
/* either PUSH or PULL mode arranges for adapter data */
/* ensure output buffer */
if (!frame->out_buffer) {
GstBuffer *src, *dest;
frame->out_buffer = gst_adapter_take_buffer (parse->priv->adapter, size);
dest = frame->out_buffer;
src = frame->buffer;
GST_BUFFER_PTS (dest) = GST_BUFFER_PTS (src);
GST_BUFFER_DTS (dest) = GST_BUFFER_DTS (src);
GST_BUFFER_OFFSET (dest) = GST_BUFFER_OFFSET (src);
GST_BUFFER_DURATION (dest) = GST_BUFFER_DURATION (src);
GST_BUFFER_OFFSET_END (dest) = GST_BUFFER_OFFSET_END (src);
GST_MINI_OBJECT_FLAGS (dest) = GST_MINI_OBJECT_FLAGS (src);
} else {
gst_adapter_flush (parse->priv->adapter, size);
}
/* use as input for subsequent processing */
gst_buffer_replace (&frame->buffer, frame->out_buffer);
gst_buffer_unref (frame->out_buffer);
frame->out_buffer = NULL;
/* subclass might queue frames/data internally if it needs more
* frames to decide on the format, or might request us to queue here. */
if (frame->flags & GST_BASE_PARSE_FRAME_FLAG_DROP) {
gst_buffer_replace (&frame->buffer, NULL);
goto exit;
} else if (frame->flags & GST_BASE_PARSE_FRAME_FLAG_QUEUE) {
GstBaseParseFrame *copy;
copy = gst_base_parse_frame_copy (frame);
copy->flags &= ~GST_BASE_PARSE_FRAME_FLAG_QUEUE;
gst_base_parse_queue_frame (parse, copy);
goto exit;
}
ret = gst_base_parse_handle_and_push_frame (parse, frame);
exit:
return ret;
}
/* gst_base_parse_drain: /* gst_base_parse_drain:
* *
@ -2265,9 +2422,8 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
guint fsize = 1; guint fsize = 1;
gint skip = -1; gint skip = -1;
const guint8 *data; const guint8 *data;
guint old_min_size = 0, min_size, av; guint min_size, av;
GstClockTime timestamp; GstClockTime timestamp;
GstBaseParseFrame *frame;
parse = GST_BASE_PARSE (parent); parse = GST_BASE_PARSE (parent);
bclass = GST_BASE_PARSE_GET_CLASS (parse); bclass = GST_BASE_PARSE_GET_CLASS (parse);
@ -2347,16 +2503,18 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
/* And now handle the current buffer if detection worked */ /* And now handle the current buffer if detection worked */
} }
frame = &parse->priv->frame;
if (G_LIKELY (buffer)) { if (G_LIKELY (buffer)) {
GST_LOG_OBJECT (parse, GST_LOG_OBJECT (parse,
"buffer size: %" G_GSIZE_FORMAT ", offset = %" G_GINT64_FORMAT, "buffer size: %" G_GSIZE_FORMAT ", offset = %" G_GINT64_FORMAT,
gst_buffer_get_size (buffer), GST_BUFFER_OFFSET (buffer)); gst_buffer_get_size (buffer), GST_BUFFER_OFFSET (buffer));
if (G_UNLIKELY (parse->priv->passthrough)) { if (G_UNLIKELY (parse->priv->passthrough)) {
gst_base_parse_frame_init (frame); GstBaseParseFrame frame;
frame->buffer = gst_buffer_make_writable (buffer);
return gst_base_parse_push_frame (parse, frame); gst_base_parse_frame_init (&frame);
frame.buffer = gst_buffer_make_writable (buffer);
ret = gst_base_parse_push_frame (parse, &frame);
gst_base_parse_frame_free (&frame);
return ret;
} }
/* upstream feeding us in reverse playback; /* upstream feeding us in reverse playback;
* gather each fragment, then process it in single run */ * gather each fragment, then process it in single run */
@ -2371,25 +2529,11 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
gst_adapter_push (parse->priv->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 */ /* Parse and push as many frames as possible */
/* Stop either when adapter is empty or we are flushing */ /* Stop either when adapter is empty or we are flushing */
while (!parse->priv->flushing) { while (!parse->priv->flushing) {
gboolean res; gint flush = 0;
/* 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 */ /* Synchronization loop */
for (;;) { for (;;) {
/* note: if subclass indicates MAX fsize, /* note: if subclass indicates MAX fsize,
@ -2397,16 +2541,10 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
min_size = MAX (parse->priv->min_frame_size, fsize); min_size = MAX (parse->priv->min_frame_size, fsize);
av = gst_adapter_available (parse->priv->adapter); av = gst_adapter_available (parse->priv->adapter);
/* loop safety check */
if (G_UNLIKELY (old_min_size >= min_size))
goto invalid_min;
old_min_size = min_size;
if (G_UNLIKELY (parse->priv->drain)) { if (G_UNLIKELY (parse->priv->drain)) {
min_size = av; min_size = av;
GST_DEBUG_OBJECT (parse, "draining, data left: %d", min_size); GST_DEBUG_OBJECT (parse, "draining, data left: %d", min_size);
if (G_UNLIKELY (!min_size)) { if (G_UNLIKELY (!min_size)) {
gst_buffer_unref (tmpbuf);
goto done; goto done;
} }
} }
@ -2415,42 +2553,33 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
if (av < min_size) { if (av < min_size) {
GST_DEBUG_OBJECT (parse, "not enough data available (only %d bytes)", GST_DEBUG_OBJECT (parse, "not enough data available (only %d bytes)",
av); av);
gst_buffer_unref (tmpbuf);
goto done; goto done;
} }
/* move along with upstream timestamp (if any),
* but interpolate in between */
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;
}
/* always pass all available data */ /* always pass all available data */
data = gst_adapter_map (parse->priv->adapter, av); data = gst_adapter_map (parse->priv->adapter, av);
/* arrange for actual data to be copied if subclass tries to,
* since what is passed is tied to the adapter */
tmpbuf = gst_buffer_new ();
gst_buffer_take_memory (tmpbuf, -1, gst_buffer_take_memory (tmpbuf, -1,
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY |
(gpointer) data, NULL, av, 0, av)); GST_MEMORY_FLAG_NO_SHARE, (gpointer) data, NULL, av, 0, av));
GST_BUFFER_OFFSET (tmpbuf) = parse->priv->offset;
if (parse->priv->discont) { /* keep the adapter mapped, so keep track of what has to be flushed */
GST_DEBUG_OBJECT (parse, "marking DISCONT"); ret = gst_base_parse_handle_buffer (parse, tmpbuf, &skip, &flush);
GST_BUFFER_FLAG_SET (tmpbuf, GST_BUFFER_FLAG_DISCONT); tmpbuf = NULL;
}
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_adapter_unmap (parse->priv->adapter);
gst_buffer_replace (&frame->buffer, NULL); if (ret != GST_FLOW_OK) {
gst_buffer_remove_memory_range (tmpbuf, 0, -1); goto done;
if (res) {
if (gst_adapter_available (parse->priv->adapter) < fsize) {
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;
}
GST_LOG_OBJECT (parse, "valid frame of size %d at pos %d", fsize, skip);
break;
}
if (skip == -1) {
/* subclass didn't touch this value. By default we skip 1 byte */
skip = 1;
} }
if (skip > 0) { if (skip > 0) {
GST_LOG_OBJECT (parse, "finding sync, skipping %d bytes", skip); GST_LOG_OBJECT (parse, "finding sync, skipping %d bytes", skip);
@ -2468,28 +2597,18 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
} else { } else {
gst_adapter_flush (parse->priv->adapter, skip); gst_adapter_flush (parse->priv->adapter, skip);
} }
parse->priv->offset += skip;
if (!parse->priv->discont) if (!parse->priv->discont)
parse->priv->sync_offset = parse->priv->offset; parse->priv->sync_offset = parse->priv->offset;
parse->priv->offset += skip;
parse->priv->discont = TRUE; parse->priv->discont = TRUE;
/* something changed least; nullify loop check */ } else if (!flush) {
old_min_size = 0; GST_LOG_OBJECT (parse, "nothing skipped and no frames finished, "
} "breaking to get more data");
/* skip == 0 should imply subclass set min_size to need more data; goto done;
* we check this shortly */ }
if ((ret = gst_base_parse_check_sync (parse)) != GST_FLOW_OK) { if ((ret = gst_base_parse_check_sync (parse)) != GST_FLOW_OK) {
gst_buffer_unref (tmpbuf);
goto done; goto done;
} }
}
gst_buffer_unref (tmpbuf);
tmpbuf = NULL;
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->priv->adapter, skip);
parse->priv->offset += skip;
} }
/* Grab lock to prevent a race with FLUSH_START handler */ /* Grab lock to prevent a race with FLUSH_START handler */
@ -2501,47 +2620,11 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
GST_PAD_STREAM_UNLOCK (parse->srcpad); GST_PAD_STREAM_UNLOCK (parse->srcpad);
break; break;
} }
/* move along with upstream timestamp (if any),
* but interpolate in between */
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->priv->adapter, fsize);
outbuf = gst_buffer_make_writable (outbuf);
/* Subclass may want to know the data offset */
GST_BUFFER_OFFSET (outbuf) = parse->priv->offset;
parse->priv->offset += fsize;
GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
frame->buffer = outbuf;
ret = gst_base_parse_handle_and_push_frame (parse, bclass, frame);
GST_PAD_STREAM_UNLOCK (parse->srcpad);
if (ret != GST_FLOW_OK) {
GST_LOG_OBJECT (parse, "push returned %d", ret);
break;
}
} }
done: done:
GST_LOG_OBJECT (parse, "chain leaving"); GST_LOG_OBJECT (parse, "chain leaving");
return ret; return ret;
/* ERRORS */
invalid_min:
{
GST_ELEMENT_ERROR (parse, STREAM, FAILED, (NULL),
("min_size evolution %d -> %d; breaking to avoid looping",
old_min_size, min_size));
return GST_FLOW_ERROR;
}
} }
/* pull @size bytes at current offset, /* pull @size bytes at current offset,
@ -2686,15 +2769,14 @@ exit:
* ajusts sync, drain and offset going along */ * ajusts sync, drain and offset going along */
static GstFlowReturn static GstFlowReturn
gst_base_parse_scan_frame (GstBaseParse * parse, GstBaseParseClass * klass, gst_base_parse_scan_frame (GstBaseParse * parse, GstBaseParseClass * klass,
GstBaseParseFrame * frame, gboolean full) gboolean full)
{ {
GstBuffer *buffer, *outbuf; GstBuffer *buffer, *outbuf;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
guint fsize = 1, min_size, old_min_size = 0; guint fsize, min_size;
gint flushed = 0;
gint skip = 0; gint skip = 0;
g_return_val_if_fail (frame != NULL, GST_FLOW_ERROR);
GST_LOG_OBJECT (parse, "scanning for frame at offset %" G_GUINT64_FORMAT GST_LOG_OBJECT (parse, "scanning for frame at offset %" G_GUINT64_FORMAT
" (%#" G_GINT64_MODIFIER "x)", parse->priv->offset, parse->priv->offset); " (%#" G_GINT64_MODIFIER "x)", parse->priv->offset, parse->priv->offset);
@ -2705,23 +2787,12 @@ gst_base_parse_scan_frame (GstBaseParse * parse, GstBaseParseClass * klass,
fsize = 64 * 1024; fsize = 64 * 1024;
while (TRUE) { while (TRUE) {
gboolean res;
min_size = MAX (parse->priv->min_frame_size, fsize); min_size = MAX (parse->priv->min_frame_size, fsize);
/* loop safety check */
if (G_UNLIKELY (old_min_size >= min_size))
goto invalid_min;
old_min_size = min_size;
ret = gst_base_parse_pull_range (parse, min_size, &buffer); ret = gst_base_parse_pull_range (parse, min_size, &buffer);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto done; goto done;
if (parse->priv->discont) {
GST_DEBUG_OBJECT (parse, "marking DISCONT");
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
}
/* if we got a short read, inform subclass we are draining leftover /* if we got a short read, inform subclass we are draining leftover
* and no more is to be expected */ * and no more is to be expected */
if (gst_buffer_get_size (buffer) < min_size) if (gst_buffer_get_size (buffer) < min_size)
@ -2751,18 +2822,12 @@ gst_base_parse_scan_frame (GstBaseParse * parse, GstBaseParseClass * klass,
/* Else handle this buffer normally */ /* Else handle this buffer normally */
} }
skip = -1; /* might need it later on */
gst_base_parse_frame_update (parse, frame, buffer); gst_buffer_ref (buffer);
res = klass->check_valid_frame (parse, frame, &fsize, &skip); ret = gst_base_parse_handle_buffer (parse, buffer, &skip, &flushed);
gst_buffer_replace (&frame->buffer, NULL); if (ret != GST_FLOW_OK)
if (res) {
parse->priv->drain = FALSE;
GST_LOG_OBJECT (parse, "valid frame of size %d at pos %d", fsize, skip);
break; break;
}
parse->priv->drain = FALSE;
if (skip == -1)
skip = 1;
if (skip > 0) { if (skip > 0) {
GST_LOG_OBJECT (parse, "finding sync, skipping %d bytes", skip); GST_LOG_OBJECT (parse, "finding sync, skipping %d bytes", skip);
if (full && parse->segment.rate < 0.0 && !parse->priv->buffers_queued) { if (full && parse->segment.rate < 0.0 && !parse->priv->buffers_queued) {
@ -2774,61 +2839,38 @@ gst_base_parse_scan_frame (GstBaseParse * parse, GstBaseParseClass * klass,
g_slist_prepend (parse->priv->buffers_pending, outbuf); g_slist_prepend (parse->priv->buffers_pending, outbuf);
outbuf = NULL; outbuf = NULL;
} }
parse->priv->offset += skip;
if (!parse->priv->discont) if (!parse->priv->discont)
parse->priv->sync_offset = parse->priv->offset; parse->priv->sync_offset = parse->priv->offset;
parse->priv->offset += skip;
parse->priv->discont = TRUE; parse->priv->discont = TRUE;
/* something changed at least; nullify loop check */ } else {
if (fsize == G_MAXUINT) /* default to reasonable increase */
fsize = old_min_size + 64 * 1024; fsize += 64 * 1024;
old_min_size = 0;
} }
/* skip == 0 should imply subclass set min_size to need more data; /* no longer needed */
* we check this shortly */
GST_DEBUG_OBJECT (parse, "finding sync...");
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
/* changed offset means something happened,
* and we should bail out of this loop so as not to occupy
* the task thread indefinitely */
if (flushed) {
GST_LOG_OBJECT (parse, "frame finished, breaking loop");
break;
}
/* nothing flushed, no skip and draining, so nothing left to do */
if (!skip && parse->priv->drain) {
GST_LOG_OBJECT (parse, "no activity or result when draining; "
"breaking loop and marking EOS");
ret = GST_FLOW_EOS;
break;
}
parse->priv->drain = FALSE;
if ((ret = gst_base_parse_check_sync (parse)) != GST_FLOW_OK) { if ((ret = gst_base_parse_check_sync (parse)) != GST_FLOW_OK) {
goto done; goto done;
} }
} }
/* Does the subclass want to skip too? */
if (skip > 0)
parse->priv->offset += skip;
else if (skip < 0)
skip = 0;
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);
} else {
gst_buffer_unref (buffer);
ret = gst_base_parse_pull_range (parse, fsize, &outbuf);
if (ret != GST_FLOW_OK)
goto done;
if (gst_buffer_get_size (outbuf) < fsize) {
gst_buffer_unref (outbuf);
ret = GST_FLOW_EOS;
}
}
parse->priv->offset += fsize;
frame->buffer = outbuf;
done: done:
return ret; return ret;
/* ERRORS */
invalid_min:
{
GST_ELEMENT_ERROR (parse, STREAM, FAILED, (NULL),
("min_size evolution %d -> %d; breaking to avoid looping",
old_min_size, min_size));
return GST_FLOW_ERROR;
}
} }
/* Loop that is used in pull mode to retrieve data from upstream */ /* Loop that is used in pull mode to retrieve data from upstream */
@ -2838,7 +2880,6 @@ gst_base_parse_loop (GstPad * pad)
GstBaseParse *parse; GstBaseParse *parse;
GstBaseParseClass *klass; GstBaseParseClass *klass;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstBaseParseFrame frame;
parse = GST_BASE_PARSE (gst_pad_get_parent (pad)); parse = GST_BASE_PARSE (gst_pad_get_parent (pad));
klass = GST_BASE_PARSE_GET_CLASS (parse); klass = GST_BASE_PARSE_GET_CLASS (parse);
@ -2855,14 +2896,10 @@ gst_base_parse_loop (GstPad * pad)
} }
} }
gst_base_parse_frame_init (&frame); ret = gst_base_parse_scan_frame (parse, klass, TRUE);
ret = gst_base_parse_scan_frame (parse, klass, &frame, TRUE);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto done; goto done;
/* This always cleans up frame, even if error occurs */
ret = gst_base_parse_handle_and_push_frame (parse, klass, &frame);
/* eat expected eos signalling past segment in reverse playback */ /* eat expected eos signalling past segment in reverse playback */
if (parse->segment.rate < 0.0 && ret == GST_FLOW_EOS && if (parse->segment.rate < 0.0 && ret == GST_FLOW_EOS &&
parse->segment.position >= parse->segment.stop) { parse->segment.position >= parse->segment.stop) {
@ -3460,7 +3497,7 @@ gst_base_parse_find_frame (GstBaseParse * parse, gint64 * pos,
gboolean orig_drain, orig_discont; gboolean orig_drain, orig_discont;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
GstBaseParseFrame frame; GstBaseParseFrame *sframe = NULL;
g_return_val_if_fail (pos != NULL, GST_FLOW_ERROR); 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 (time != NULL, GST_FLOW_ERROR);
@ -3479,37 +3516,36 @@ gst_base_parse_find_frame (GstBaseParse * parse, gint64 * pos,
GST_DEBUG_OBJECT (parse, "scanning for frame starting at %" G_GINT64_FORMAT GST_DEBUG_OBJECT (parse, "scanning for frame starting at %" G_GINT64_FORMAT
" (%#" G_GINT64_MODIFIER "x)", *pos, *pos); " (%#" G_GINT64_MODIFIER "x)", *pos, *pos);
gst_base_parse_frame_init (&frame);
/* jump elsewhere and locate next frame */ /* jump elsewhere and locate next frame */
parse->priv->offset = *pos; parse->priv->offset = *pos;
ret = gst_base_parse_scan_frame (parse, klass, &frame, FALSE); /* mark as scanning so frames don't get processed all the way */
if (ret != GST_FLOW_OK) parse->priv->scanning = TRUE;
ret = gst_base_parse_scan_frame (parse, klass, FALSE);
parse->priv->scanning = FALSE;
/* retrieve frame found during scan */
sframe = parse->priv->scanned_frame;
parse->priv->scanned_frame = NULL;
if (ret != GST_FLOW_OK || !sframe)
goto done; goto done;
buf = frame.buffer;
GST_LOG_OBJECT (parse,
"peek parsing frame at offset %" G_GUINT64_FORMAT
" (%#" 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 */ /* get offset first, subclass parsing might dump other stuff in there */
*pos = GST_BUFFER_OFFSET (buf); *pos = sframe->offset;
ret = klass->parse_frame (parse, &frame); buf = sframe->buffer;
buf = frame.buffer; g_assert (buf);
/* but it should provide proper time */ /* but it should provide proper time */
*time = GST_BUFFER_TIMESTAMP (buf); *time = GST_BUFFER_TIMESTAMP (buf);
*duration = GST_BUFFER_DURATION (buf); *duration = GST_BUFFER_DURATION (buf);
gst_base_parse_frame_free (&frame);
GST_LOG_OBJECT (parse, GST_LOG_OBJECT (parse,
"frame with time %" GST_TIME_FORMAT " at offset %" G_GINT64_FORMAT, "frame with time %" GST_TIME_FORMAT " at offset %" G_GINT64_FORMAT,
GST_TIME_ARGS (*time), *pos); GST_TIME_ARGS (*time), *pos);
done: done:
if (sframe)
gst_base_parse_frame_free (sframe);
/* restore state */ /* restore state */
parse->priv->offset = orig_offset; parse->priv->offset = orig_offset;
parse->priv->discont = orig_discont; parse->priv->discont = orig_discont;

View file

@ -65,16 +65,6 @@ G_BEGIN_DECLS
*/ */
#define GST_BASE_PARSE_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS #define GST_BASE_PARSE_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS
/**
* GST_BASE_PARSE_FLOW_QUEUED:
*
* A #GstFlowReturn that can be returned from parse frame to indicate that
* the buffer will be queued to be pushed when the next OK
*
* Since: 0.10.33
*/
#define GST_BASE_PARSE_FLOW_QUEUED GST_FLOW_CUSTOM_SUCCESS_1
/* not public API, use accessor macros below */ /* not public API, use accessor macros below */
#define GST_BASE_PARSE_FLAG_LOST_SYNC (1 << 0) #define GST_BASE_PARSE_FLAG_LOST_SYNC (1 << 0)
#define GST_BASE_PARSE_FLAG_DRAINING (1 << 1) #define GST_BASE_PARSE_FLAG_DRAINING (1 << 1)
@ -110,6 +100,11 @@ G_BEGIN_DECLS
* @GST_BASE_PARSE_FRAME_FLAG_CLIP: @pre_push_frame can set this to indicate * @GST_BASE_PARSE_FRAME_FLAG_CLIP: @pre_push_frame can set this to indicate
* that regular segment clipping can still be performed (as opposed to * that regular segment clipping can still be performed (as opposed to
* any custom one having been done). * any custom one having been done).
* @GST_BASE_PARSE_FRAME_FLAG_DROP: indicates to @finish_frame that the
* the frame should be dropped (and might be handled internall by subclass)
* @GST_BASE_PARSE_FRAME_FLAG_QUEUE: indicates to @finish_frame that the
* the frame should be queued for now and processed fully later
* when the first non-queued frame is finished
* *
* Flags to be used in a #GstBaseParseFrame. * Flags to be used in a #GstBaseParseFrame.
* *
@ -118,13 +113,17 @@ G_BEGIN_DECLS
typedef enum { typedef enum {
GST_BASE_PARSE_FRAME_FLAG_NONE = 0, GST_BASE_PARSE_FRAME_FLAG_NONE = 0,
GST_BASE_PARSE_FRAME_FLAG_NO_FRAME = (1 << 0), GST_BASE_PARSE_FRAME_FLAG_NO_FRAME = (1 << 0),
GST_BASE_PARSE_FRAME_FLAG_CLIP = (1 << 1) GST_BASE_PARSE_FRAME_FLAG_CLIP = (1 << 1),
GST_BASE_PARSE_FRAME_FLAG_DROP = (1 << 2),
GST_BASE_PARSE_FRAME_FLAG_QUEUE = (1 << 3)
} GstBaseParseFrameFlags; } GstBaseParseFrameFlags;
/** /**
* GstBaseParseFrame: * GstBaseParseFrame:
* @buffer: data to check for valid frame or parsed frame. * @buffer: input data to be parsed for frames.
* Subclass is allowed to replace this buffer. * @out_buffer: (optional) (replacement) output data.
* @offset: media specific offset of input frame
* Note that a converter may have a different one on the frame's buffer.
* @overhead: subclass can set this to indicates the metadata overhead * @overhead: subclass can set this to indicates the metadata overhead
* for the given frame, which is then used to enable more accurate bitrate * for the given frame, which is then used to enable more accurate bitrate
* computations. If this is -1, it is assumed that this frame should be * computations. If this is -1, it is assumed that this frame should be
@ -145,9 +144,12 @@ typedef enum {
*/ */
typedef struct { typedef struct {
GstBuffer * buffer; GstBuffer * buffer;
GstBuffer * out_buffer;
guint flags; guint flags;
guint64 offset;
gint overhead; gint overhead;
/*< private >*/ /*< private >*/
gint size;
guint _gst_reserved_i[2]; guint _gst_reserved_i[2];
gpointer _gst_reserved_p[2]; gpointer _gst_reserved_p[2];
guint _private_flags; guint _private_flags;
@ -192,12 +194,17 @@ struct _GstBaseParse {
* Allows closing external resources. * Allows closing external resources.
* @set_sink_caps: allows the subclass to be notified of the actual caps set. * @set_sink_caps: allows the subclass to be notified of the actual caps set.
* @get_sink_caps: allows the subclass to do its own sink get caps if needed. * @get_sink_caps: allows the subclass to do its own sink get caps if needed.
* @check_valid_frame: Check if the given piece of data contains a valid * @handle_frame: Parses the input data into valid frames as defined by subclass
* frame. * which should be passed to gst_base_parse_finish_frame().
* @parse_frame: Parse the already checked frame. Subclass need to * The frame's input buffer is guaranteed writable,
* set the buffer timestamp, duration, caps and possibly * whereas the input frame ownership is held by caller
* other necessary metadata. This is called with srcpad's * (so subclass should make a copy if it needs to hang on).
* STREAM_LOCK held. * Input buffer (data) is equally managed by baseclass and should also be
* copied (e.g. gst_buffer_copy_region()) when needed.
* Time metadata will already be set as much as possible by baseclass
* according to upstream information and/or subclass settings,
* though subclass may still set buffer timestamp and duration
* if desired.
* @convert: Optional. * @convert: Optional.
* Convert between formats. * Convert between formats.
* @event: Optional. * @event: Optional.
@ -234,14 +241,10 @@ struct _GstBaseParseClass {
gboolean (*set_sink_caps) (GstBaseParse * parse, gboolean (*set_sink_caps) (GstBaseParse * parse,
GstCaps * caps); GstCaps * caps);
gboolean (*check_valid_frame) (GstBaseParse * parse, GstFlowReturn (*handle_frame) (GstBaseParse * parse,
GstBaseParseFrame * frame, GstBaseParseFrame * frame,
guint * framesize,
gint * skipsize); gint * skipsize);
GstFlowReturn (*parse_frame) (GstBaseParse * parse,
GstBaseParseFrame * frame);
GstFlowReturn (*pre_push_frame) (GstBaseParse * parse, GstFlowReturn (*pre_push_frame) (GstBaseParse * parse,
GstBaseParseFrame * frame); GstBaseParseFrame * frame);
@ -282,6 +285,10 @@ void gst_base_parse_frame_free (GstBaseParseFrame * frame);
GstFlowReturn gst_base_parse_push_frame (GstBaseParse * parse, GstFlowReturn gst_base_parse_push_frame (GstBaseParse * parse,
GstBaseParseFrame * frame); GstBaseParseFrame * frame);
GstFlowReturn gst_base_parse_finish_frame (GstBaseParse * parse,
GstBaseParseFrame * frame,
gint size);
void gst_base_parse_set_duration (GstBaseParse * parse, void gst_base_parse_set_duration (GstBaseParse * parse,
GstFormat fmt, GstFormat fmt,
gint64 duration, gint64 duration,