audioencoder: Rename ::event() to ::sink_event() and add ::src_event()
[platform/upstream/gstreamer.git] / gst-libs / gst / audio / gstaudioencoder.h
1 /* GStreamer
2  * Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
3  * Copyright (C) 2011 Nokia Corporation. All rights reserved.
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_AUDIO_ENCODER_H__
23 #define __GST_AUDIO_ENCODER_H__
24
25 #include <gst/gst.h>
26 #include <gst/audio/audio.h>
27
28 G_BEGIN_DECLS
29
30 #define GST_TYPE_AUDIO_ENCODER             (gst_audio_encoder_get_type())
31 #define GST_AUDIO_ENCODER(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_ENCODER,GstAudioEncoder))
32 #define GST_AUDIO_ENCODER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_ENCODER,GstAudioEncoderClass))
33 #define GST_AUDIO_ENCODER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_AUDIO_ENCODER,GstAudioEncoderClass))
34 #define GST_IS_AUDIO_ENCODER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_ENCODER))
35 #define GST_IS_AUDIO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_ENCODER))
36 #define GST_AUDIO_ENCODER_CAST(obj)     ((GstAudioEncoder *)(obj))
37
38 /**
39  * GST_AUDIO_ENCODER_SINK_NAME:
40  *
41  * the name of the templates for the sink pad
42  *
43  * Since: 0.10.36
44  */
45 #define GST_AUDIO_ENCODER_SINK_NAME     "sink"
46 /**
47  * GST_AUDIO_ENCODER_SRC_NAME:
48  *
49  * the name of the templates for the source pad
50  *
51  * Since: 0.10.36
52  */
53 #define GST_AUDIO_ENCODER_SRC_NAME              "src"
54
55 /**
56  * GST_AUDIO_ENCODER_SRC_PAD:
57  * @obj: base parse instance
58  *
59  * Gives the pointer to the source #GstPad object of the element.
60  *
61  * Since: 0.10.36
62  */
63 #define GST_AUDIO_ENCODER_SRC_PAD(obj)  (GST_AUDIO_ENCODER_CAST (obj)->srcpad)
64
65 /**
66  * GST_AUDIO_ENCODER_SINK_PAD:
67  * @obj: base parse instance
68  *
69  * Gives the pointer to the sink #GstPad object of the element.
70  *
71  * Since: 0.10.36
72  */
73 #define GST_AUDIO_ENCODER_SINK_PAD(obj) (GST_AUDIO_ENCODER_CAST (obj)->sinkpad)
74
75 /**
76  * GST_AUDIO_ENCODER_SEGMENT:
77  * @obj: base parse instance
78  *
79  * Gives the segment of the element.
80  *
81  * Since: 0.10.36
82  */
83 #define GST_AUDIO_ENCODER_SEGMENT(obj)     (GST_AUDIO_ENCODER_CAST (obj)->segment)
84
85 #define GST_AUDIO_ENCODER_STREAM_LOCK(enc)   g_rec_mutex_lock (&GST_AUDIO_ENCODER (enc)->stream_lock)
86 #define GST_AUDIO_ENCODER_STREAM_UNLOCK(enc) g_rec_mutex_unlock (&GST_AUDIO_ENCODER (enc)->stream_lock)
87
88 typedef struct _GstAudioEncoder GstAudioEncoder;
89 typedef struct _GstAudioEncoderClass GstAudioEncoderClass;
90
91 typedef struct _GstAudioEncoderPrivate GstAudioEncoderPrivate;
92
93 /**
94  * GstAudioEncoder:
95  *
96  * The opaque #GstAudioEncoder data structure.
97  *
98  * Since: 0.10.36
99  */
100 struct _GstAudioEncoder {
101   GstElement     element;
102
103   /*< protected >*/
104   /* source and sink pads */
105   GstPad         *sinkpad;
106   GstPad         *srcpad;
107
108   /* protects all data processing, i.e. is locked
109    * in the chain function, finish_frame and when
110    * processing serialized events */
111   GRecMutex       stream_lock;
112
113   /* MT-protected (with STREAM_LOCK) */
114   GstSegment      segment;
115
116   /*< private >*/
117   GstAudioEncoderPrivate *priv;
118
119   gpointer       _gst_reserved[GST_PADDING_LARGE];
120 };
121
122 /**
123  * GstAudioEncoderClass:
124  * @element_class:  The parent class structure
125  * @start:          Optional.
126  *                  Called when the element starts processing.
127  *                  Allows opening external resources.
128  * @stop:           Optional.
129  *                  Called when the element stops processing.
130  *                  Allows closing external resources.
131  * @set_format:     Notifies subclass of incoming data format.
132  *                  GstAudioInfo contains the format according to provided caps.
133  * @handle_frame:   Provides input samples (or NULL to clear any remaining data)
134  *                  according to directions as configured by the subclass
135  *                  using the API.  Input data ref management is performed
136  *                  by base class, subclass should not care or intervene,
137  *                  and input data is only valid until next call to base class,
138  *                  most notably a call to gst_audio_encoder_finish_frame().
139  * @flush:          Optional.
140  *                  Instructs subclass to clear any codec caches and discard
141  *                  any pending samples and not yet returned encoded data.
142  * @sink_event:     Optional.
143  *                  Event handler on the sink pad. Subclasses should chain up to
144  *                  the parent implementation to invoke the default handler.
145  * @src_event:      Optional.
146  *                  Event handler on the src pad. Subclasses should chain up to
147  *                  the parent implementation to invoke the default handler.
148  * @pre_push:       Optional.
149  *                  Called just prior to pushing (encoded data) buffer downstream.
150  *                  Subclass has full discretionary access to buffer,
151  *                  and a not OK flow return will abort downstream pushing.
152  * @getcaps:        Optional.
153  *                  Allows for a custom sink getcaps implementation (e.g.
154  *                  for multichannel input specification).  If not implemented,
155  *                  default returns gst_audio_encoder_proxy_getcaps
156  *                  applied to sink template caps.
157  * @open:           Optional.
158  *                  Called when the element changes to GST_STATE_READY.
159  *                  Allows opening external resources. Since: 0.10.37.
160  * @close:          Optional.
161  *                  Called when the element changes to GST_STATE_NULL.
162  *                  Allows closing external resources. Since: 0.10.37.
163  *
164  * Subclasses can override any of the available virtual methods or not, as
165  * needed. At minimum @set_format and @handle_frame needs to be overridden.
166  *
167  * Since: 0.10.36
168  */
169 struct _GstAudioEncoderClass {
170   GstElementClass element_class;
171
172   /*< public >*/
173   /* virtual methods for subclasses */
174
175   gboolean      (*start)              (GstAudioEncoder *enc);
176
177   gboolean      (*stop)               (GstAudioEncoder *enc);
178
179   gboolean      (*set_format)         (GstAudioEncoder *enc,
180                                        GstAudioInfo        *info);
181
182   GstFlowReturn (*handle_frame)       (GstAudioEncoder *enc,
183                                        GstBuffer *buffer);
184
185   void          (*flush)              (GstAudioEncoder *enc);
186
187   GstFlowReturn (*pre_push)           (GstAudioEncoder *enc,
188                                        GstBuffer **buffer);
189
190   gboolean      (*sink_event)         (GstAudioEncoder *enc,
191                                        GstEvent *event);
192
193   gboolean      (*src_event)          (GstAudioEncoder *enc,
194                                        GstEvent *event);
195
196   GstCaps *     (*getcaps)            (GstAudioEncoder *enc, GstCaps *filter);
197
198   gboolean      (*open)               (GstAudioEncoder *enc);
199
200   gboolean      (*close)              (GstAudioEncoder *enc);
201
202   /*< private >*/
203   gpointer       _gst_reserved[GST_PADDING_LARGE-2];
204 };
205
206 GType           gst_audio_encoder_get_type         (void);
207
208 GstFlowReturn   gst_audio_encoder_finish_frame (GstAudioEncoder * enc,
209                                                 GstBuffer       * buffer,
210                                                 gint              samples);
211
212 GstCaps *       gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc,
213                                                  GstCaps         * caps);
214
215 gboolean        gst_audio_encoder_set_output_format  (GstAudioEncoder    * enc,
216                                                       GstCaps            * caps);
217
218
219 /* context parameters */
220 GstAudioInfo  * gst_audio_encoder_get_audio_info (GstAudioEncoder * enc);
221
222 gint            gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc);
223
224 void            gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num);
225
226 gint            gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc);
227
228 void            gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num);
229
230 gint            gst_audio_encoder_get_frame_max (GstAudioEncoder * enc);
231
232 void            gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num);
233
234 gint            gst_audio_encoder_get_lookahead (GstAudioEncoder * enc);
235
236 void            gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num);
237
238 void            gst_audio_encoder_get_latency (GstAudioEncoder * enc,
239                                                GstClockTime    * min,
240                                                GstClockTime    * max);
241
242 void            gst_audio_encoder_set_latency (GstAudioEncoder * enc,
243                                                GstClockTime      min,
244                                                GstClockTime      max);
245
246 /* object properties */
247
248 void            gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc,
249                                                     gboolean enabled);
250
251 gboolean        gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc);
252
253 void            gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc,
254                                                          gboolean          enabled);
255
256 gboolean        gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc);
257
258 void            gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc,
259                                                    gboolean          enabled);
260
261 gboolean        gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc);
262
263 void            gst_audio_encoder_set_tolerance (GstAudioEncoder * enc,
264                                                  gint64            tolerance);
265
266 gint64          gst_audio_encoder_get_tolerance (GstAudioEncoder * enc);
267
268 void            gst_audio_encoder_set_hard_min (GstAudioEncoder * enc,
269                                                 gboolean enabled);
270
271 gboolean        gst_audio_encoder_get_hard_min (GstAudioEncoder * enc);
272
273 void            gst_audio_encoder_set_drainable (GstAudioEncoder * enc,
274                                                  gboolean enabled);
275
276 gboolean        gst_audio_encoder_get_drainable (GstAudioEncoder * enc);
277
278 void            gst_audio_encoder_merge_tags (GstAudioEncoder * enc,
279                                               const GstTagList * tags, GstTagMergeMode mode);
280
281 G_END_DECLS
282
283 #endif /* __GST_AUDIO_ENCODER_H__ */