2 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
4 * Contact: Stefan Kost <stefan.kost@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #ifndef __GST_BASE_PARSE_H__
23 #define __GST_BASE_PARSE_H__
26 #include <gst/base/gstadapter.h>
30 #define GST_TYPE_BASE_PARSE (gst_base_parse_get_type())
31 #define GST_BASE_PARSE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_PARSE,GstBaseParse))
32 #define GST_BASE_PARSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_PARSE,GstBaseParseClass))
33 #define GST_BASE_PARSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_PARSE,GstBaseParseClass))
34 #define GST_IS_BASE_PARSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_PARSE))
35 #define GST_IS_BASE_PARSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_PARSE))
36 #define GST_BASE_PARSE_CAST(obj) ((GstBaseParse *)(obj))
39 * GST_BASE_PARSE_SINK_NAME:
41 * the name of the templates for the sink pad
43 #define GST_BASE_PARSE_SINK_NAME "sink"
45 * GST_BASE_PARSE_SRC_NAME:
47 * the name of the templates for the source pad
49 #define GST_BASE_PARSE_SRC_NAME "src"
52 * GST_BASE_PARSE_SRC_PAD:
53 * @obj: base parse instance
55 * Gives the pointer to the source #GstPad object of the element.
59 #define GST_BASE_PARSE_SRC_PAD(obj) (GST_BASE_PARSE_CAST (obj)->srcpad)
62 * GST_BASE_PARSE_SINK_PAD:
63 * @obj: base parse instance
65 * Gives the pointer to the sink #GstPad object of the element.
69 #define GST_BASE_PARSE_SINK_PAD(obj) (GST_BASE_PARSE_CAST (obj)->sinkpad)
72 * GST_BASE_PARSE_SEGMENT:
73 * @obj: base parse instance
75 * Gives the segment of the element.
79 #define GST_BASE_PARSE_SEGMENT(obj) (GST_BASE_PARSE_CAST (obj)->segment)
82 * GST_BASE_PARSE_FLOW_DROPPED:
84 * A #GstFlowReturn that can be returned from parse_frame to
85 * indicate that no output buffer was generated, or from pre_push_buffer to
86 * to forego pushing buffer.
90 #define GST_BASE_PARSE_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS
93 * GstBaseParseFrameFlags:
94 * @GST_BASE_PARSE_FRAME_FLAG_NONE: no flag
95 * @GST_BASE_PARSE_FRAME_FLAG_SYNC: indicates if parsing is 'in sync'
96 * @GST_BASE_PARSE_FRAME_FLAG_DRAIN: indicates if parser is 'draining'.
97 * That is, leftover data (e.g. in FLUSH or EOS situation) is being parsed.
98 * @GST_BASE_PARSE_FRAME_FLAG_NO_FRAME: set to indicate this buffer should not be
99 * counted as frame, e.g. if this frame is dependent on a previous one.
100 * As it is not counted as a frame, bitrate increases but frame to time
101 * conversions are maintained.
102 * @GST_BASE_PARSE_FRAME_FLAG_CLIP: @pre_push_buffer can set this to indicate
103 * that regular segment clipping can still be performed (as opposed to
104 * any custom one having been done).
106 * Flags to be used in a #GstBaseParseFrame.
111 GST_BASE_PARSE_FRAME_FLAG_NONE = 0,
112 GST_BASE_PARSE_FRAME_FLAG_SYNC = (1 << 0),
113 GST_BASE_PARSE_FRAME_FLAG_DRAIN = (1 << 1),
114 GST_BASE_PARSE_FRAME_FLAG_NO_FRAME = (1 << 2),
115 GST_BASE_PARSE_FRAME_FLAG_CLIP = (1 << 3)
116 } GstBaseParseFrameFlags;
120 * @buffer: data to check for valid frame or parsed frame.
121 * Subclass is allowed to replace this buffer.
122 * @overhead: subclass can set this to indicates the metadata overhead
123 * for the given frame, which is then used to enable more accurate bitrate
124 * computations. If this is -1, it is assumed that this frame should be
125 * skipped in bitrate calculation.
126 * @flags: a combination of input and output #GstBaseParseFrameFlags that
127 * convey additional context to subclass or allow subclass to tune
128 * subsequent #GstBaseParse actions.
130 * Frame (context) data passed to each frame parsing virtual methods. In
131 * addition to providing the data to be checked for a valid frame or an already
132 * identified frame, it conveys additional metadata or control information
133 * from and to the subclass w.r.t. the particular frame in question (rather
134 * than global parameters). Some of these may apply to each parsing stage, others
135 * only to some a particular one. These parameters are effectively zeroed at start
136 * of each frame's processing, i.e. parsing virtual method invocation sequence.
147 * GST_BASE_PARSE_FRAME_SYNC:
148 * @frame: base parse frame instance
150 * Obtains current sync status indicated in frame.
154 #define GST_BASE_PARSE_FRAME_SYNC(frame) (!!(frame->flags & GST_BASE_PARSE_FRAME_FLAG_SYNC))
157 * GST_BASE_PARSE_FRAME_DRAIN:
158 * @frame: base parse frame instance
160 * Obtains current drain status indicated in frame.
164 #define GST_BASE_PARSE_FRAME_DRAIN(frame) (!!(frame->flags & GST_BASE_PARSE_FRAME_FLAG_DRAIN))
167 * GstBaseParseFormat:
168 * @GST_BASE_PARSE_FORMAT_NONE: default setting
169 * @GST_BASE_PARSE_FORMAT_PASSTHROUGH: nature of format or configuration
170 * does not allow (much) parsing, so parser should operate in passthrough mode
171 * (which only applies operating in pull mode). That is, incoming buffers
172 * are pushed through unmodified, i.e. no @check_valid_frame or @parse_frame
173 * callbacks will be invoked. On the other hand, @pre_push_buffer is still invoked,
174 * where subclass can perform as much or as little is appropriate for
175 * "passthrough" semantics.
176 * @GST_BASE_PARSE_FORMAT_HAS_TIME: frames carry timing info which subclass
177 * can (generally) parse and provide. In particular, intrinsic time
178 * (rather than estimated) can be obtained following seek.
182 typedef enum _GstBaseParseFormat {
183 GST_BASE_PARSE_FORMAT_NONE = 0,
184 GST_BASE_PARSE_FORMAT_PASSTHROUGH = (1 << 0),
185 GST_BASE_PARSE_FORMAT_HAS_TIME = (1 << 1),
186 } GstBaseParseFormat;
189 * GstBaseParseSeekable:
190 * @GST_BASE_PARSE_SEEK_NONE: No seeking possible.
191 * @GST_BASE_PARSE_SEEK_DEFAULT: Default seeking possible using estimated bitrate.
192 * @GST_BASE_PARSE_SEEK_TABLE: Additional metadata provides more accurate seeking.
194 * Indicates what level (of quality) of seeking is possible.
198 typedef enum _GstBaseParseSeekable {
199 GST_BASE_PARSE_SEEK_NONE,
200 GST_BASE_PARSE_SEEK_DEFAULT,
201 GST_BASE_PARSE_SEEK_TABLE
202 } GstBaseParseSeekable;
204 typedef struct _GstBaseParse GstBaseParse;
205 typedef struct _GstBaseParseClass GstBaseParseClass;
206 typedef struct _GstBaseParsePrivate GstBaseParsePrivate;
210 * @element: the parent element.
212 * The opaque #GstBaseParse data structure.
214 struct _GstBaseParse {
219 /* source and sink pads */
223 /* MT-protected (with STREAM_LOCK) */
226 /* Newsegment event to be sent after SEEK */
227 GstEvent *pending_segment;
229 /* Segment event that closes the running segment prior to SEEK */
230 GstEvent *close_segment;
233 gpointer _gst_reserved[GST_PADDING_LARGE];
234 GstBaseParsePrivate *priv;
240 * Called when the element starts processing.
241 * Allows opening external resources.
243 * Called when the element stops processing.
244 * Allows closing external resources.
245 * @set_sink_caps: allows the subclass to be notified of the actual caps set.
246 * @check_valid_frame: Check if the given piece of data contains a valid
248 * @parse_frame: Parse the already checked frame. Subclass need to
249 * set the buffer timestamp, duration, caps and possibly
250 * other necessary metadata. This is called with srcpad's
252 * @convert: Optional.
253 * Convert between formats.
254 * @find_frame: Optional.
255 * Finds a frame. Gets a position passed and should return
256 * TRUE and the offset in bytes where this position is.
257 * Will only be called in pull mode and the subclass can pull
258 * whatever it wants from upstream. If not implemented,
259 * the base class will implement it by calling
260 * @check_valid_frame and @parse_frame to find the wanted
261 * frame and build a seek table.
263 * Event handler on the sink pad. This function should return
264 * TRUE if the event was handled and can be dropped.
265 * @src_event: Optional.
266 * Event handler on the source pad. Should return TRUE
267 * if the event was handled and can be dropped.
269 * @get_frame_overhead: Finds the metadata overhead for the given frame. This
270 * is used to enable more accurate bitrate computations.
271 * If NULL, the per-frame overhead is assumed to be 0. If
272 * this returns -1, it is assumed that this frame should
273 * be skipped in bitrate calculation.
275 * @pre_push_buffer: Optional.
276 * Called just prior to pushing a frame (after any pending
277 * events have been sent) to give subclass a chance to perform
278 * additional actions at this time (e.g. tag sending) or to
279 * decide whether this buffer should be dropped or not
280 * (e.g. custom segment clipping).
282 * Subclasses can override any of the available virtual methods or not, as
283 * needed. At minimum @check_valid_frame and @parse_frame needs to be
286 struct _GstBaseParseClass {
287 GstElementClass parent_class;
290 /* virtual methods for subclasses */
292 gboolean (*start) (GstBaseParse *parse);
294 gboolean (*stop) (GstBaseParse *parse);
296 gboolean (*set_sink_caps) (GstBaseParse *parse,
299 gboolean (*check_valid_frame) (GstBaseParse *parse,
300 GstBaseParseFrame *frame,
304 GstFlowReturn (*parse_frame) (GstBaseParse *parse,
305 GstBaseParseFrame *frame);
307 GstFlowReturn (*pre_push_frame) (GstBaseParse *parse,
308 GstBaseParseFrame *frame);
310 gboolean (*convert) (GstBaseParse * parse,
311 GstFormat src_format,
313 GstFormat dest_format,
314 gint64 * dest_value);
316 gboolean (*event) (GstBaseParse *parse,
319 gboolean (*src_event) (GstBaseParse *parse,
323 gpointer _gst_reserved[GST_PADDING_LARGE];
326 GType gst_base_parse_get_type (void);
328 void gst_base_parse_frame_init (GstBaseParse * parse, GstBaseParseFrame * frame);
330 GstFlowReturn gst_base_parse_push_frame (GstBaseParse *parse,
331 GstBaseParseFrame *frame);
333 void gst_base_parse_set_duration (GstBaseParse *parse,
334 GstFormat fmt, gint64 duration, gint interval);
336 void gst_base_parse_set_seek (GstBaseParse * parse,
337 GstBaseParseSeekable seek, guint bitrate);
339 void gst_base_parse_set_min_frame_size (GstBaseParse *parse, guint min_size);
341 void gst_base_parse_set_format (GstBaseParse * parse, GstBaseParseFormat flag,
344 void gst_base_parse_set_frame_props (GstBaseParse * parse, guint fps_num,
345 guint fps_den, guint lead_in, guint lead_out);
347 gboolean gst_base_parse_convert_default (GstBaseParse * parse,
348 GstFormat src_format, gint64 src_value,
349 GstFormat dest_format, gint64 * dest_value);
351 gboolean gst_base_parse_add_index_entry (GstBaseParse * parse, guint64 offset,
352 GstClockTime ts, gboolean key, gboolean force);
356 #endif /* __GST_BASE_PARSE_H__ */