aacparse: Add function for the baseparse subclass to push buffers downstream
[platform/upstream/gst-plugins-good.git] / gst / aacparse / 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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, 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/gstadapter.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_SINK_NAME:
40  *
41  * the name of the templates for the sink pad
42  */
43 #define GST_BASE_PARSE_SINK_NAME        "sink"
44 /**
45  * GST_BASE_PARSE_SRC_NAME:
46  *
47  * the name of the templates for the source pad
48  */
49 #define GST_BASE_PARSE_SRC_NAME "src"
50
51 /**
52  * GST_BASE_PARSE_SRC_PAD:
53  * @obj: base parse instance
54  *
55  * Gives the pointer to the source #GstPad object of the element.
56  *
57  * Since: 0.10.x
58  */
59 #define GST_BASE_PARSE_SRC_PAD(obj)             (GST_BASE_PARSE_CAST (obj)->srcpad)
60
61 /**
62  * GST_BASE_PARSE_SINK_PAD:
63  * @obj: base parse instance
64  *
65  * Gives the pointer to the sink #GstPad object of the element.
66  *
67  * Since: 0.10.x
68  */
69 #define GST_BASE_PARSE_SINK_PAD(obj)    (GST_BASE_PARSE_CAST (obj)->sinkpad)
70
71 /**
72  * GST_BASE_PARSE_FLOW_DROPPED:
73  *
74  * A #GstFlowReturn that can be returned from parse_frame to
75  * indicate that no output buffer was generated.
76  *
77  * Since: 0.10.x
78  */
79 #define GST_BASE_PARSE_FLOW_DROPPED   GST_FLOW_CUSTOM_SUCCESS
80
81 /**
82  * GST_BASE_PARSE_LOCK:
83  * @obj: base parse instance
84  *
85  * Obtain a lock to protect the parse function from concurrent access.
86  *
87  * Since: 0.10.x
88  */
89 #define GST_BASE_PARSE_LOCK(obj)   g_mutex_lock (GST_BASE_PARSE_CAST (obj)->parse_lock)
90
91 /**
92  * GST_BASE_PARSE_UNLOCK:
93  * @obj: base parse instance
94  *
95  * Release the lock that protects the parse function from concurrent access.
96  *
97  * Since: 0.10.x
98  */
99 #define GST_BASE_PARSE_UNLOCK(obj) g_mutex_unlock (GST_BASE_PARSE_CAST (obj)->parse_lock)
100
101 typedef struct _GstBaseParse GstBaseParse;
102 typedef struct _GstBaseParseClass GstBaseParseClass;
103 typedef struct _GstBaseParsePrivate GstBaseParsePrivate;
104 typedef struct _GstBaseParseClassPrivate GstBaseParseClassPrivate;
105
106 /**
107  * GstBaseParse:
108  * @element: the parent element.
109  *
110  * The opaque #GstBaseParse data structure.
111  */
112 struct _GstBaseParse {
113   GstElement     element;
114   GstAdapter   *adapter;
115
116   /*< protected >*/
117   /* source and sink pads */
118   GstPad        *sinkpad;
119   GstPad        *srcpad;
120
121   /* MT-protected (with STREAM_LOCK) */
122   GstSegment     segment;
123
124   /* Newsegment event to be sent after SEEK */
125   GstEvent       *pending_segment;
126
127   /* Segment event that closes the running segment prior to SEEK */
128   GstEvent       *close_segment;
129
130   /* Caps nego done already? */
131   gboolean   negotiated;
132
133   GMutex        *parse_lock;
134
135   /*< private >*/
136   gpointer       _gst_reserved[GST_PADDING_LARGE];
137   GstBaseParsePrivate *priv;
138 };
139
140 /**
141  * GstBaseParseClass:
142  * @start:          Optional.
143  *                  Called when the element starts processing.
144  *                  Allows opening external resources.
145  * @stop:           Optional.
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
150  *                      frame.
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
154  *                  STREAM_LOCK held.
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.
165  * @event:          Optional.
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.
175  *
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
178  * overridden.
179  */
180 struct _GstBaseParseClass {
181   GstElementClass parent_class;
182
183   /*< public >*/
184   /* virtual methods for subclasses */
185
186   gboolean      (*start)              (GstBaseParse *parse);
187
188   gboolean      (*stop)               (GstBaseParse *parse);
189
190   gboolean      (*set_sink_caps)      (GstBaseParse *parse,
191                                        GstCaps *caps);
192
193   gboolean      (*check_valid_frame)  (GstBaseParse *parse,
194                                        GstBuffer *buffer,
195                                        guint *framesize,
196                                        gint *skipsize);
197
198   GstFlowReturn (*parse_frame)        (GstBaseParse *parse,
199                                        GstBuffer *buffer);
200
201   gboolean      (*convert)            (GstBaseParse * parse,
202                                        GstFormat src_format,
203                                        gint64 src_value,
204                                        GstFormat dest_format,
205                                        gint64 * dest_value);
206
207   gboolean      (*find_frame)         (GstBaseParse *parse,
208                                        GstFormat src_format,
209                                        gint64 src_value,
210                                        gint64 * dest_value);
211
212   gboolean      (*event)              (GstBaseParse *parse,
213                                        GstEvent *event);
214
215   gboolean      (*src_event)          (GstBaseParse *parse,
216                                        GstEvent *event);
217
218   gboolean      (*is_seekable)        (GstBaseParse *parse);
219
220   /*< private >*/
221   gpointer       _gst_reserved[GST_PADDING_LARGE];  
222   GstBaseParseClassPrivate *priv;
223 };
224
225 GType           gst_base_parse_get_type         (void);
226
227
228 GstFlowReturn gst_base_parse_push_buffer (GstBaseParse *parse,
229                                           GstBuffer *buffer);
230
231 void gst_base_parse_set_duration (GstBaseParse *parse,
232                                   GstFormat fmt,
233                                   gint64 duration);
234
235 void gst_base_parse_set_min_frame_size (GstBaseParse *parse,
236                                         guint min_size);
237
238 G_END_DECLS
239
240 #endif /* __GST_BASE_PARSE_H__ */