base: GST_EXPORT -> GST_BASE_API
[platform/upstream/gstreamer.git] / libs / gst / base / gstbaseparse.h
1 /* GStreamer
2  * Copyright (C) 2008 Nokia Corporation. All rights reserved.
3  *
4  * Contact: Stefan Kost <stefan.kost@nokia.com>
5  *
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.
10  *
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.
15  *
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., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef __GST_BASE_PARSE_H__
23 #define __GST_BASE_PARSE_H__
24
25 #include <gst/gst.h>
26 #include <gst/base/base-prelude.h>
27
28 G_BEGIN_DECLS
29
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))
37
38 /**
39  * GST_BASE_PARSE_SRC_PAD:
40  * @obj: base parse instance
41  *
42  * Gives the pointer to the source #GstPad object of the element.
43  */
44 #define GST_BASE_PARSE_SRC_PAD(obj)    (GST_BASE_PARSE_CAST (obj)->srcpad)
45
46 /**
47  * GST_BASE_PARSE_SINK_PAD:
48  * @obj: base parse instance
49  *
50  * Gives the pointer to the sink #GstPad object of the element.
51  */
52 #define GST_BASE_PARSE_SINK_PAD(obj)    (GST_BASE_PARSE_CAST (obj)->sinkpad)
53
54 /**
55  * GST_BASE_PARSE_FLOW_DROPPED:
56  *
57  * A #GstFlowReturn that can be returned from parse_frame to
58  * indicate that no output buffer was generated, or from pre_push_frame to
59  * to forego pushing buffer.
60  */
61 #define GST_BASE_PARSE_FLOW_DROPPED     GST_FLOW_CUSTOM_SUCCESS
62
63 /* not public API, use accessor macros below */
64 #define GST_BASE_PARSE_FLAG_LOST_SYNC (1 << 0)
65 #define GST_BASE_PARSE_FLAG_DRAINING  (1 << 1)
66
67 /**
68  * GST_BASE_PARSE_LOST_SYNC:
69  * @parse: base parse instance
70  *
71  * Obtains current sync status.
72  */
73 #define GST_BASE_PARSE_LOST_SYNC(parse) (!!(GST_BASE_PARSE_CAST(parse)->flags & GST_BASE_PARSE_FLAG_LOST_SYNC))
74
75 /**
76  * GST_BASE_PARSE_DRAINING:
77  * @parse: base parse instance
78  *
79  * Obtains current drain status (ie. whether EOS has been received and
80  * the parser is now processing the frames at the end of the stream)
81  */
82 #define GST_BASE_PARSE_DRAINING(parse)  (!!(GST_BASE_PARSE_CAST(parse)->flags & GST_BASE_PARSE_FLAG_DRAINING))
83
84 /**
85  * GstBaseParseFrameFlags:
86  * @GST_BASE_PARSE_FRAME_FLAG_NONE: no flag
87  * @GST_BASE_PARSE_FRAME_FLAG_NEW_FRAME: set by baseclass if current frame
88  *   is passed for processing to the subclass for the first time
89  *   (and not set on subsequent calls with same data).
90  * @GST_BASE_PARSE_FRAME_FLAG_NO_FRAME: set to indicate this buffer should not be
91  *   counted as frame, e.g. if this frame is dependent on a previous one.
92  *   As it is not counted as a frame, bitrate increases but frame to time
93  *   conversions are maintained.
94  * @GST_BASE_PARSE_FRAME_FLAG_CLIP: @pre_push_frame can set this to indicate
95  *    that regular segment clipping can still be performed (as opposed to
96  *    any custom one having been done).
97  * @GST_BASE_PARSE_FRAME_FLAG_DROP: indicates to @finish_frame that the
98  *    the frame should be dropped (and might be handled internally by subclass)
99  * @GST_BASE_PARSE_FRAME_FLAG_QUEUE: indicates to @finish_frame that the
100  *    the frame should be queued for now and processed fully later
101  *    when the first non-queued frame is finished
102  *
103  * Flags to be used in a #GstBaseParseFrame.
104  */
105 typedef enum {
106   GST_BASE_PARSE_FRAME_FLAG_NONE         = 0,
107   GST_BASE_PARSE_FRAME_FLAG_NEW_FRAME    = (1 << 0),
108   GST_BASE_PARSE_FRAME_FLAG_NO_FRAME     = (1 << 1),
109   GST_BASE_PARSE_FRAME_FLAG_CLIP         = (1 << 2),
110   GST_BASE_PARSE_FRAME_FLAG_DROP         = (1 << 3),
111   GST_BASE_PARSE_FRAME_FLAG_QUEUE        = (1 << 4)
112 } GstBaseParseFrameFlags;
113
114 /**
115  * GstBaseParseFrame:
116  * @buffer: input data to be parsed for frames.
117  * @out_buffer: output data.
118  * @offset: media specific offset of input frame
119  *   Note that a converter may have a different one on the frame's buffer.
120  * @overhead: subclass can set this to indicates the metadata overhead
121  *   for the given frame, which is then used to enable more accurate bitrate
122  *   computations. If this is -1, it is assumed that this frame should be
123  *   skipped in bitrate calculation.
124  * @flags: a combination of input and output #GstBaseParseFrameFlags that
125  *  convey additional context to subclass or allow subclass to tune
126  *  subsequent #GstBaseParse actions.
127  *
128  * Frame (context) data passed to each frame parsing virtual methods.  In
129  * addition to providing the data to be checked for a valid frame or an already
130  * identified frame, it conveys additional metadata or control information
131  * from and to the subclass w.r.t. the particular frame in question (rather
132  * than global parameters).  Some of these may apply to each parsing stage, others
133  * only to some a particular one.  These parameters are effectively zeroed at start
134  * of each frame's processing, i.e. parsing virtual method invocation sequence.
135  */
136 typedef struct {
137   GstBuffer * buffer;
138   GstBuffer * out_buffer;
139   guint       flags;
140   guint64     offset;
141   gint        overhead;
142   /*< private >*/
143   gint        size;
144   guint       _gst_reserved_i[2];
145   gpointer    _gst_reserved_p[2];
146   guint       _private_flags;
147 } GstBaseParseFrame;
148
149 typedef struct _GstBaseParse GstBaseParse;
150 typedef struct _GstBaseParseClass GstBaseParseClass;
151 typedef struct _GstBaseParsePrivate GstBaseParsePrivate;
152
153 /**
154  * GstBaseParse:
155  * @element: the parent element.
156  *
157  * The opaque #GstBaseParse data structure.
158  */
159 struct _GstBaseParse {
160   /*< public >*/
161   GstElement     element;
162
163   /*< protected >*/
164   /* source and sink pads */
165   GstPad         *sinkpad;
166   GstPad         *srcpad;
167
168   guint           flags;
169
170   /* MT-protected (with STREAM_LOCK) */
171   GstSegment      segment;
172
173   /*< private >*/
174   gpointer       _gst_reserved[GST_PADDING_LARGE];
175   GstBaseParsePrivate *priv;
176 };
177
178 /**
179  * GstBaseParseClass:
180  * @parent_class: the parent class
181  * @start:          Optional.
182  *                  Called when the element starts processing.
183  *                  Allows opening external resources.
184  * @stop:           Optional.
185  *                  Called when the element stops processing.
186  *                  Allows closing external resources.
187  * @set_sink_caps:  Optional.
188  *                  Allows the subclass to be notified of the actual caps set.
189  * @get_sink_caps:  Optional.
190  *                  Allows the subclass to do its own sink get caps if needed.
191  * @handle_frame:   Parses the input data into valid frames as defined by subclass
192  *                  which should be passed to gst_base_parse_finish_frame().
193  *                  The frame's input buffer is guaranteed writable,
194  *                  whereas the input frame ownership is held by caller
195  *                  (so subclass should make a copy if it needs to hang on).
196  *                  Input buffer (data) is provided by baseclass with as much
197  *                  metadata set as possible by baseclass according to upstream
198  *                  information and/or subclass settings,
199  *                  though subclass may still set buffer timestamp and duration
200  *                  if desired.
201  * @convert:        Optional.
202  *                  Convert between formats.
203  * @sink_event:     Optional.
204  *                  Event handler on the sink pad. This function should chain
205  *                  up to the parent implementation to let the default handler
206  *                  run.
207  * @src_event:      Optional.
208  *                  Event handler on the source pad. Should chain up to the
209  *                  parent to let the default handler run.
210  * @pre_push_frame: Optional.
211  *                   Called just prior to pushing a frame (after any pending
212  *                   events have been sent) to give subclass a chance to perform
213  *                   additional actions at this time (e.g. tag sending) or to
214  *                   decide whether this buffer should be dropped or not
215  *                   (e.g. custom segment clipping).
216  * @detect:         Optional.
217  *                   Called until it doesn't return GST_FLOW_OK anymore for
218  *                   the first buffers. Can be used by the subclass to detect
219  *                   the stream format.
220  * @sink_query:     Optional.
221  *                   Query handler on the sink pad. This function should chain
222  *                   up to the parent implementation to let the default handler
223  *                   run (Since 1.2)
224  * @src_query:      Optional.
225  *                   Query handler on the source pad. Should chain up to the
226  *                   parent to let the default handler run (Since 1.2)
227  *
228  * Subclasses can override any of the available virtual methods or not, as
229  * needed. At minimum @handle_frame needs to be overridden.
230  */
231 struct _GstBaseParseClass {
232   GstElementClass parent_class;
233
234   /*< public >*/
235   /* virtual methods for subclasses */
236
237   gboolean      (*start)              (GstBaseParse * parse);
238
239   gboolean      (*stop)               (GstBaseParse * parse);
240
241   gboolean      (*set_sink_caps)      (GstBaseParse * parse,
242                                        GstCaps      * caps);
243
244   GstFlowReturn (*handle_frame)       (GstBaseParse      * parse,
245                                        GstBaseParseFrame * frame,
246                                        gint              * skipsize);
247
248   GstFlowReturn (*pre_push_frame)     (GstBaseParse      * parse,
249                                        GstBaseParseFrame * frame);
250
251   gboolean      (*convert)            (GstBaseParse * parse,
252                                        GstFormat      src_format,
253                                        gint64         src_value,
254                                        GstFormat      dest_format,
255                                        gint64       * dest_value);
256
257   gboolean      (*sink_event)         (GstBaseParse * parse,
258                                        GstEvent     * event);
259
260   gboolean      (*src_event)          (GstBaseParse * parse,
261                                        GstEvent     * event);
262
263   GstCaps *     (*get_sink_caps)      (GstBaseParse * parse,
264                                        GstCaps      * filter);
265
266   GstFlowReturn (*detect)             (GstBaseParse * parse,
267                                        GstBuffer    * buffer);
268
269   gboolean      (*sink_query)         (GstBaseParse * parse,
270                                        GstQuery     * query);
271
272   gboolean      (*src_query)          (GstBaseParse * parse,
273                                        GstQuery     * query);
274
275   /*< private >*/
276   gpointer       _gst_reserved[GST_PADDING_LARGE - 2];
277 };
278
279 GST_BASE_API
280 GType           gst_base_parse_get_type (void);
281
282 GST_BASE_API
283 GType           gst_base_parse_frame_get_type (void);
284
285 GST_BASE_API
286 GstBaseParseFrame * gst_base_parse_frame_new  (GstBuffer              * buffer,
287                                                GstBaseParseFrameFlags   flags,
288                                                gint                     overhead);
289 GST_BASE_API
290 void            gst_base_parse_frame_init      (GstBaseParseFrame * frame);
291
292 GST_BASE_API
293 GstBaseParseFrame * gst_base_parse_frame_copy  (GstBaseParseFrame * frame);
294 GST_BASE_API
295 void            gst_base_parse_frame_free      (GstBaseParseFrame * frame);
296
297 GST_BASE_API
298 GstFlowReturn   gst_base_parse_push_frame      (GstBaseParse      * parse,
299                                                 GstBaseParseFrame * frame);
300 GST_BASE_API
301 GstFlowReturn   gst_base_parse_finish_frame    (GstBaseParse * parse,
302                                                 GstBaseParseFrame * frame,
303                                                 gint size);
304 GST_BASE_API
305 void            gst_base_parse_set_duration    (GstBaseParse      * parse,
306                                                 GstFormat           fmt,
307                                                 gint64              duration,
308                                                 gint                interval);
309 GST_BASE_API
310 void            gst_base_parse_set_average_bitrate (GstBaseParse   * parse,
311                                                     guint            bitrate);
312 GST_BASE_API
313 void            gst_base_parse_set_min_frame_size (GstBaseParse    * parse,
314                                                    guint             min_size);
315 GST_BASE_API
316 void            gst_base_parse_set_has_timing_info (GstBaseParse   * parse,
317                                                     gboolean         has_timing);
318 GST_BASE_API
319 void            gst_base_parse_drain           (GstBaseParse * parse);
320
321 GST_BASE_API
322 void            gst_base_parse_set_syncable    (GstBaseParse * parse,
323                                                 gboolean       syncable);
324 GST_BASE_API
325 void            gst_base_parse_set_passthrough (GstBaseParse * parse,
326                                                 gboolean       passthrough);
327 GST_BASE_API
328 void            gst_base_parse_set_pts_interpolation (GstBaseParse * parse,
329                                                       gboolean pts_interpolate);
330 GST_BASE_API
331 void            gst_base_parse_set_infer_ts (GstBaseParse * parse,
332                                              gboolean infer_ts);
333 GST_BASE_API
334 void            gst_base_parse_set_frame_rate  (GstBaseParse * parse,
335                                                 guint          fps_num,
336                                                 guint          fps_den,
337                                                 guint          lead_in,
338                                                 guint          lead_out);
339 GST_BASE_API
340 void            gst_base_parse_set_latency     (GstBaseParse * parse,
341                                                 GstClockTime min_latency,
342                                                 GstClockTime max_latency);
343 GST_BASE_API
344 gboolean        gst_base_parse_convert_default (GstBaseParse * parse,
345                                                 GstFormat      src_format,
346                                                 gint64         src_value,
347                                                 GstFormat      dest_format,
348                                                 gint64       * dest_value);
349 GST_BASE_API
350 gboolean        gst_base_parse_add_index_entry (GstBaseParse * parse,
351                                                 guint64        offset,
352                                                 GstClockTime   ts,
353                                                 gboolean       key,
354                                                 gboolean       force);
355 GST_BASE_API
356 void            gst_base_parse_set_ts_at_offset (GstBaseParse *parse,
357                                                  gsize offset);
358 GST_BASE_API
359 void            gst_base_parse_merge_tags       (GstBaseParse  * parse,
360                                                  GstTagList    * tags,
361                                                  GstTagMergeMode mode);
362
363 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
364 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBaseParseFrame, gst_base_parse_frame_free)
365 #endif
366
367 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
368 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBaseParse, gst_object_unref)
369 #endif
370
371 G_END_DECLS
372
373 #endif /* __GST_BASE_PARSE_H__ */