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_FLOW_DROPPED:
74 * A #GstFlowReturn that can be returned from parse_frame to
75 * indicate that no output buffer was generated.
79 #define GST_BASE_PARSE_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS
82 * GST_BASE_PARSE_LOCK:
83 * @obj: base parse instance
85 * Obtain a lock to protect the parse function from concurrent access.
89 #define GST_BASE_PARSE_LOCK(obj) g_mutex_lock (GST_BASE_PARSE_CAST (obj)->parse_lock)
92 * GST_BASE_PARSE_UNLOCK:
93 * @obj: base parse instance
95 * Release the lock that protects the parse function from concurrent access.
99 #define GST_BASE_PARSE_UNLOCK(obj) g_mutex_unlock (GST_BASE_PARSE_CAST (obj)->parse_lock)
101 typedef struct _GstBaseParse GstBaseParse;
102 typedef struct _GstBaseParseClass GstBaseParseClass;
103 typedef struct _GstBaseParsePrivate GstBaseParsePrivate;
104 typedef struct _GstBaseParseClassPrivate GstBaseParseClassPrivate;
108 * @element: the parent element.
110 * The opaque #GstBaseParse data structure.
112 struct _GstBaseParse {
117 /* source and sink pads */
121 /* MT-protected (with STREAM_LOCK) */
124 /* Newsegment event to be sent after SEEK */
125 GstEvent *pending_segment;
127 /* Segment event that closes the running segment prior to SEEK */
128 GstEvent *close_segment;
130 /* Caps nego done already? */
136 gpointer _gst_reserved[GST_PADDING_LARGE];
137 GstBaseParsePrivate *priv;
143 * Called when the element starts processing.
144 * Allows opening external resources.
146 * Called when the element stops processing.
147 * Allows closing external resources.
148 * @set_sink_caps: allows the subclass to be notified of the actual caps set.
149 * @check_valid_frame: Check if the given piece of data contains a valid
151 * @parse_frame: Parse the already checked frame. Subclass need to
152 * set the buffer timestamp, duration, caps and possibly
153 * other necessary metadata. This is called with srcpad's
155 * @convert: Optional.
156 * Convert between formats.
157 * @find_frame: Optional.
158 * Finds a frame. Gets a position passed and should return
159 * TRUE and the offset in bytes where this position is.
160 * Will only be called in pull mode and the subclass can pull
161 * whatever it wants from upstream. If not implemented,
162 * the base class will implement it by calling
163 * @check_valid_frame and @parse_frame to find the wanted
164 * frame and build a seek table.
166 * Event handler on the sink pad. This function should return
167 * TRUE if the event was handled and can be dropped.
168 * @src_event: Optional.
169 * Event handler on the source pad. Should return TRUE
170 * if the event was handled and can be dropped.
171 * @is_seekable: Optional.
172 * Subclass can override this if it wants to control the
173 * seekability of the stream. Otherwise the element assumes
174 * that stream is always seekable.
176 * Subclasses can override any of the available virtual methods or not, as
177 * needed. At minimum @check_valid_frame and @parse_frame needs to be
180 struct _GstBaseParseClass {
181 GstElementClass parent_class;
184 /* virtual methods for subclasses */
186 gboolean (*start) (GstBaseParse *parse);
188 gboolean (*stop) (GstBaseParse *parse);
190 gboolean (*set_sink_caps) (GstBaseParse *parse,
193 gboolean (*check_valid_frame) (GstBaseParse *parse,
198 GstFlowReturn (*parse_frame) (GstBaseParse *parse,
201 gboolean (*convert) (GstBaseParse * parse,
202 GstFormat src_format,
204 GstFormat dest_format,
205 gint64 * dest_value);
207 gboolean (*find_frame) (GstBaseParse *parse,
208 GstFormat src_format,
210 gint64 * dest_value);
212 gboolean (*event) (GstBaseParse *parse,
215 gboolean (*src_event) (GstBaseParse *parse,
218 gboolean (*is_seekable) (GstBaseParse *parse);
221 gpointer _gst_reserved[GST_PADDING_LARGE];
222 GstBaseParseClassPrivate *priv;
225 GType gst_base_parse_get_type (void);
228 GstFlowReturn gst_base_parse_push_buffer (GstBaseParse *parse,
231 void gst_base_parse_set_duration (GstBaseParse *parse,
235 void gst_base_parse_set_min_frame_size (GstBaseParse *parse,
240 #endif /* __GST_BASE_PARSE_H__ */