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