2008-11-13 12:59:34 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Contact: Stefan Kost <stefan.kost@nokia.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-11-13 12:59:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GST_BASE_PARSE_H__
|
|
|
|
#define __GST_BASE_PARSE_H__
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
#define GST_TYPE_BASE_PARSE (gst_base_parse_get_type())
|
|
|
|
#define GST_BASE_PARSE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_PARSE,GstBaseParse))
|
2008-11-13 12:59:34 +00:00
|
|
|
#define GST_BASE_PARSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_PARSE,GstBaseParseClass))
|
|
|
|
#define GST_BASE_PARSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_PARSE,GstBaseParseClass))
|
2011-03-12 16:16:22 +00:00
|
|
|
#define GST_IS_BASE_PARSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_PARSE))
|
2008-11-13 12:59:34 +00:00
|
|
|
#define GST_IS_BASE_PARSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_PARSE))
|
2011-03-12 16:16:22 +00:00
|
|
|
#define GST_BASE_PARSE_CAST(obj) ((GstBaseParse *)(obj))
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_PARSE_SRC_PAD:
|
|
|
|
* @obj: base parse instance
|
|
|
|
*
|
|
|
|
* Gives the pointer to the source #GstPad object of the element.
|
|
|
|
*/
|
2011-03-12 16:16:22 +00:00
|
|
|
#define GST_BASE_PARSE_SRC_PAD(obj) (GST_BASE_PARSE_CAST (obj)->srcpad)
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_PARSE_SINK_PAD:
|
|
|
|
* @obj: base parse instance
|
|
|
|
*
|
|
|
|
* Gives the pointer to the sink #GstPad object of the element.
|
|
|
|
*/
|
2011-03-12 16:16:22 +00:00
|
|
|
#define GST_BASE_PARSE_SINK_PAD(obj) (GST_BASE_PARSE_CAST (obj)->sinkpad)
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_PARSE_FLOW_DROPPED:
|
|
|
|
*
|
|
|
|
* A #GstFlowReturn that can be returned from parse_frame to
|
2011-10-20 14:59:01 +00:00
|
|
|
* indicate that no output buffer was generated, or from pre_push_frame to
|
2010-09-17 15:21:46 +00:00
|
|
|
* to forego pushing buffer.
|
2008-11-13 12:59:34 +00:00
|
|
|
*/
|
2011-01-10 15:59:59 +00:00
|
|
|
#define GST_BASE_PARSE_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-04-04 16:58:59 +00:00
|
|
|
/* not public API, use accessor macros below */
|
|
|
|
#define GST_BASE_PARSE_FLAG_LOST_SYNC (1 << 0)
|
|
|
|
#define GST_BASE_PARSE_FLAG_DRAINING (1 << 1)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_PARSE_LOST_SYNC:
|
|
|
|
* @parse: base parse instance
|
|
|
|
*
|
|
|
|
* Obtains current sync status.
|
|
|
|
*/
|
|
|
|
#define GST_BASE_PARSE_LOST_SYNC(parse) (!!(GST_BASE_PARSE_CAST(parse)->flags & GST_BASE_PARSE_FLAG_LOST_SYNC))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_PARSE_DRAINING:
|
|
|
|
* @parse: base parse instance
|
|
|
|
*
|
|
|
|
* Obtains current drain status (ie. whether EOS has been received and
|
|
|
|
* the parser is now processing the frames at the end of the stream)
|
|
|
|
*/
|
|
|
|
#define GST_BASE_PARSE_DRAINING(parse) (!!(GST_BASE_PARSE_CAST(parse)->flags & GST_BASE_PARSE_FLAG_DRAINING))
|
|
|
|
|
2010-09-17 15:21:46 +00:00
|
|
|
/**
|
2011-01-10 14:34:48 +00:00
|
|
|
* GstBaseParseFrameFlags:
|
|
|
|
* @GST_BASE_PARSE_FRAME_FLAG_NONE: no flag
|
2012-02-15 16:11:54 +00:00
|
|
|
* @GST_BASE_PARSE_FRAME_FLAG_NEW_FRAME: set by baseclass if current frame
|
|
|
|
* is passed for processing to the subclass for the first time
|
|
|
|
* (and not set on subsequent calls with same data).
|
2011-01-10 14:34:48 +00:00
|
|
|
* @GST_BASE_PARSE_FRAME_FLAG_NO_FRAME: set to indicate this buffer should not be
|
|
|
|
* counted as frame, e.g. if this frame is dependent on a previous one.
|
|
|
|
* As it is not counted as a frame, bitrate increases but frame to time
|
|
|
|
* conversions are maintained.
|
2011-10-20 14:59:01 +00:00
|
|
|
* @GST_BASE_PARSE_FRAME_FLAG_CLIP: @pre_push_frame can set this to indicate
|
2011-01-10 14:34:48 +00:00
|
|
|
* that regular segment clipping can still be performed (as opposed to
|
|
|
|
* any custom one having been done).
|
2012-02-13 17:22:37 +00:00
|
|
|
* @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
|
2010-09-17 15:21:46 +00:00
|
|
|
*
|
2011-01-10 14:34:48 +00:00
|
|
|
* Flags to be used in a #GstBaseParseFrame.
|
2010-09-17 15:21:46 +00:00
|
|
|
*/
|
2011-01-10 14:34:48 +00:00
|
|
|
typedef enum {
|
|
|
|
GST_BASE_PARSE_FRAME_FLAG_NONE = 0,
|
2012-02-15 16:11:54 +00:00
|
|
|
GST_BASE_PARSE_FRAME_FLAG_NEW_FRAME = (1 << 0),
|
2012-03-07 10:23:56 +00:00
|
|
|
GST_BASE_PARSE_FRAME_FLAG_NO_FRAME = (1 << 1),
|
|
|
|
GST_BASE_PARSE_FRAME_FLAG_CLIP = (1 << 2),
|
|
|
|
GST_BASE_PARSE_FRAME_FLAG_DROP = (1 << 3),
|
|
|
|
GST_BASE_PARSE_FRAME_FLAG_QUEUE = (1 << 4)
|
2011-01-10 14:34:48 +00:00
|
|
|
} GstBaseParseFrameFlags;
|
2010-09-17 15:21:46 +00:00
|
|
|
|
2009-10-29 14:18:37 +00:00
|
|
|
/**
|
2011-01-10 14:34:48 +00:00
|
|
|
* GstBaseParseFrame:
|
2012-02-13 17:22:37 +00:00
|
|
|
* @buffer: input data to be parsed for frames.
|
|
|
|
* @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.
|
2011-01-10 14:34:48 +00:00
|
|
|
* @overhead: subclass can set this to indicates the metadata overhead
|
|
|
|
* 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
|
|
|
|
* skipped in bitrate calculation.
|
|
|
|
* @flags: a combination of input and output #GstBaseParseFrameFlags that
|
|
|
|
* convey additional context to subclass or allow subclass to tune
|
|
|
|
* subsequent #GstBaseParse actions.
|
2009-10-29 14:18:37 +00:00
|
|
|
*
|
2011-01-10 14:34:48 +00:00
|
|
|
* Frame (context) data passed to each frame parsing virtual methods. In
|
|
|
|
* addition to providing the data to be checked for a valid frame or an already
|
|
|
|
* identified frame, it conveys additional metadata or control information
|
|
|
|
* from and to the subclass w.r.t. the particular frame in question (rather
|
|
|
|
* than global parameters). Some of these may apply to each parsing stage, others
|
|
|
|
* only to some a particular one. These parameters are effectively zeroed at start
|
|
|
|
* of each frame's processing, i.e. parsing virtual method invocation sequence.
|
2009-10-29 14:18:37 +00:00
|
|
|
*/
|
2011-01-10 14:34:48 +00:00
|
|
|
typedef struct {
|
2011-03-12 16:16:22 +00:00
|
|
|
GstBuffer * buffer;
|
2012-02-13 17:22:37 +00:00
|
|
|
GstBuffer * out_buffer;
|
2011-03-12 16:16:22 +00:00
|
|
|
guint flags;
|
2012-02-13 17:22:37 +00:00
|
|
|
guint64 offset;
|
2011-03-12 16:16:22 +00:00
|
|
|
gint overhead;
|
2011-04-02 13:18:57 +00:00
|
|
|
/*< private >*/
|
2012-02-13 17:22:37 +00:00
|
|
|
gint size;
|
2011-04-15 16:41:02 +00:00
|
|
|
guint _gst_reserved_i[2];
|
2011-04-02 13:18:57 +00:00
|
|
|
gpointer _gst_reserved_p[2];
|
2011-04-15 16:41:02 +00:00
|
|
|
guint _private_flags;
|
2011-01-10 14:34:48 +00:00
|
|
|
} GstBaseParseFrame;
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
typedef struct _GstBaseParse GstBaseParse;
|
|
|
|
typedef struct _GstBaseParseClass GstBaseParseClass;
|
|
|
|
typedef struct _GstBaseParsePrivate GstBaseParsePrivate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstBaseParse:
|
|
|
|
* @element: the parent element.
|
|
|
|
*
|
|
|
|
* The opaque #GstBaseParse data structure.
|
|
|
|
*/
|
|
|
|
struct _GstBaseParse {
|
2010-09-16 09:51:20 +00:00
|
|
|
GstElement element;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/*< protected >*/
|
|
|
|
/* source and sink pads */
|
2010-09-16 09:51:20 +00:00
|
|
|
GstPad *sinkpad;
|
|
|
|
GstPad *srcpad;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-04-04 16:58:59 +00:00
|
|
|
guint flags;
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
/* MT-protected (with STREAM_LOCK) */
|
2010-09-16 09:51:20 +00:00
|
|
|
GstSegment segment;
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
gpointer _gst_reserved[GST_PADDING_LARGE];
|
|
|
|
GstBaseParsePrivate *priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstBaseParseClass:
|
2011-03-31 14:50:22 +00:00
|
|
|
* @parent_class: the parent class
|
2008-11-13 12:59:34 +00:00
|
|
|
* @start: Optional.
|
|
|
|
* Called when the element starts processing.
|
|
|
|
* Allows opening external resources.
|
|
|
|
* @stop: Optional.
|
|
|
|
* Called when the element stops processing.
|
|
|
|
* Allows closing external resources.
|
|
|
|
* @set_sink_caps: allows the subclass to be notified of the actual caps set.
|
2011-10-17 17:42:08 +00:00
|
|
|
* @get_sink_caps: allows the subclass to do its own sink get caps if needed.
|
2012-02-13 17:22:37 +00:00
|
|
|
* @handle_frame: Parses the input data into valid frames as defined by subclass
|
|
|
|
* which should be passed to gst_base_parse_finish_frame().
|
|
|
|
* The frame's input buffer is guaranteed writable,
|
|
|
|
* whereas the input frame ownership is held by caller
|
|
|
|
* (so subclass should make a copy if it needs to hang on).
|
2012-02-15 16:12:09 +00:00
|
|
|
* Input buffer (data) is provided by baseclass with as much
|
|
|
|
* metadata set as possible by baseclass according to upstream
|
|
|
|
* information and/or subclass settings,
|
2012-02-13 17:22:37 +00:00
|
|
|
* though subclass may still set buffer timestamp and duration
|
|
|
|
* if desired.
|
2008-11-13 12:59:34 +00:00
|
|
|
* @convert: Optional.
|
|
|
|
* Convert between formats.
|
2012-03-30 09:58:20 +00:00
|
|
|
* @sink_event: Optional.
|
2012-02-15 09:11:35 +00:00
|
|
|
* Event handler on the sink pad. This function should chain
|
|
|
|
* up to the parent implementation to let the default handler
|
|
|
|
* run.
|
2008-11-13 12:59:34 +00:00
|
|
|
* @src_event: Optional.
|
2012-02-15 09:11:35 +00:00
|
|
|
* Event handler on the source pad. Should chain up to the
|
|
|
|
* parent to let the default handler run.
|
2011-02-17 21:22:28 +00:00
|
|
|
* @pre_push_frame: Optional.
|
2010-09-17 15:21:46 +00:00
|
|
|
* Called just prior to pushing a frame (after any pending
|
|
|
|
* events have been sent) to give subclass a chance to perform
|
|
|
|
* additional actions at this time (e.g. tag sending) or to
|
2011-01-07 14:58:49 +00:00
|
|
|
* decide whether this buffer should be dropped or not
|
2010-09-17 15:21:46 +00:00
|
|
|
* (e.g. custom segment clipping).
|
2011-10-20 06:31:18 +00:00
|
|
|
* @detect: Optional.
|
|
|
|
* Called until it doesn't return GST_FLOW_OK anymore for
|
|
|
|
* the first buffers. Can be used by the subclass to detect
|
2012-07-10 09:46:41 +00:00
|
|
|
* the stream format.
|
2010-09-17 15:21:46 +00:00
|
|
|
*
|
2008-11-13 12:59:34 +00:00
|
|
|
* Subclasses can override any of the available virtual methods or not, as
|
|
|
|
* needed. At minimum @check_valid_frame and @parse_frame needs to be
|
|
|
|
* overridden.
|
|
|
|
*/
|
|
|
|
struct _GstBaseParseClass {
|
|
|
|
GstElementClass parent_class;
|
|
|
|
|
|
|
|
/*< public >*/
|
|
|
|
/* virtual methods for subclasses */
|
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
gboolean (*start) (GstBaseParse * parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
gboolean (*stop) (GstBaseParse * parse);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
gboolean (*set_sink_caps) (GstBaseParse * parse,
|
|
|
|
GstCaps * caps);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
GstFlowReturn (*handle_frame) (GstBaseParse * parse,
|
2011-03-12 16:16:22 +00:00
|
|
|
GstBaseParseFrame * frame,
|
|
|
|
gint * skipsize);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
GstFlowReturn (*pre_push_frame) (GstBaseParse * parse,
|
|
|
|
GstBaseParseFrame * frame);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
|
|
|
gboolean (*convert) (GstBaseParse * parse,
|
2011-03-12 16:16:22 +00:00
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat dest_format,
|
|
|
|
gint64 * dest_value);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2012-03-30 09:58:20 +00:00
|
|
|
gboolean (*sink_event) (GstBaseParse * parse,
|
2011-03-12 16:16:22 +00:00
|
|
|
GstEvent * event);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
gboolean (*src_event) (GstBaseParse * parse,
|
|
|
|
GstEvent * event);
|
2008-11-13 12:59:34 +00:00
|
|
|
|
2011-10-21 08:52:46 +00:00
|
|
|
GstCaps * (*get_sink_caps) (GstBaseParse * parse,
|
2011-11-11 16:17:43 +00:00
|
|
|
GstCaps * filter);
|
2011-10-17 17:42:08 +00:00
|
|
|
|
2011-10-20 06:31:18 +00:00
|
|
|
GstFlowReturn (*detect) (GstBaseParse * parse,
|
|
|
|
GstBuffer * buffer);
|
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
/*< private >*/
|
2011-11-11 16:17:43 +00:00
|
|
|
gpointer _gst_reserved[GST_PADDING_LARGE];
|
2008-11-13 12:59:34 +00:00
|
|
|
};
|
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
GType gst_base_parse_get_type (void);
|
|
|
|
|
2011-04-15 14:02:20 +00:00
|
|
|
GType gst_base_parse_frame_get_type (void);
|
|
|
|
|
2011-04-15 16:41:02 +00:00
|
|
|
GstBaseParseFrame * gst_base_parse_frame_new (GstBuffer * buffer,
|
|
|
|
GstBaseParseFrameFlags flags,
|
|
|
|
gint overhead);
|
|
|
|
|
2011-04-15 17:00:21 +00:00
|
|
|
void gst_base_parse_frame_init (GstBaseParseFrame * frame);
|
2011-03-12 16:16:22 +00:00
|
|
|
|
2011-04-15 18:07:55 +00:00
|
|
|
void gst_base_parse_frame_free (GstBaseParseFrame * frame);
|
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
GstFlowReturn gst_base_parse_push_frame (GstBaseParse * parse,
|
|
|
|
GstBaseParseFrame * frame);
|
|
|
|
|
2012-02-13 17:22:37 +00:00
|
|
|
GstFlowReturn gst_base_parse_finish_frame (GstBaseParse * parse,
|
|
|
|
GstBaseParseFrame * frame,
|
|
|
|
gint size);
|
|
|
|
|
2011-03-12 16:16:22 +00:00
|
|
|
void gst_base_parse_set_duration (GstBaseParse * parse,
|
|
|
|
GstFormat fmt,
|
|
|
|
gint64 duration,
|
|
|
|
gint interval);
|
|
|
|
|
2011-03-31 13:48:47 +00:00
|
|
|
void gst_base_parse_set_average_bitrate (GstBaseParse * parse,
|
|
|
|
guint bitrate);
|
2011-03-12 16:16:22 +00:00
|
|
|
|
|
|
|
void gst_base_parse_set_min_frame_size (GstBaseParse * parse,
|
|
|
|
guint min_size);
|
|
|
|
|
2011-04-06 16:43:27 +00:00
|
|
|
void gst_base_parse_set_has_timing_info (GstBaseParse * parse,
|
|
|
|
gboolean has_timing);
|
|
|
|
|
|
|
|
void gst_base_parse_set_syncable (GstBaseParse * parse,
|
|
|
|
gboolean syncable);
|
|
|
|
|
|
|
|
void gst_base_parse_set_passthrough (GstBaseParse * parse,
|
|
|
|
gboolean passthrough);
|
2011-03-12 16:16:22 +00:00
|
|
|
|
2012-09-13 08:48:08 +00:00
|
|
|
void gst_base_parse_set_pts_interpolation (GstBaseParse * parse,
|
|
|
|
gboolean pts_interpolate);
|
|
|
|
|
2011-04-08 14:31:14 +00:00
|
|
|
void gst_base_parse_set_frame_rate (GstBaseParse * parse,
|
2011-03-12 16:16:22 +00:00
|
|
|
guint fps_num,
|
|
|
|
guint fps_den,
|
|
|
|
guint lead_in,
|
|
|
|
guint lead_out);
|
2011-01-10 15:59:59 +00:00
|
|
|
|
2011-05-12 09:55:20 +00:00
|
|
|
void gst_base_parse_set_latency (GstBaseParse * parse,
|
|
|
|
GstClockTime min_latency,
|
|
|
|
GstClockTime max_latency);
|
|
|
|
|
2011-01-10 15:59:59 +00:00
|
|
|
gboolean gst_base_parse_convert_default (GstBaseParse * parse,
|
2011-03-12 16:16:22 +00:00
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat dest_format,
|
|
|
|
gint64 * dest_value);
|
2011-01-10 15:59:59 +00:00
|
|
|
|
|
|
|
gboolean gst_base_parse_add_index_entry (GstBaseParse * parse,
|
2011-03-12 16:16:22 +00:00
|
|
|
guint64 offset,
|
|
|
|
GstClockTime ts,
|
|
|
|
gboolean key,
|
|
|
|
gboolean force);
|
2010-09-21 08:57:04 +00:00
|
|
|
|
2008-11-13 12:59:34 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_BASE_PARSE_H__ */
|