defs: update
[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  * @event:          Optional.
143  *                  Event handler on the sink pad. This function should return
144  *                  TRUE if the event was handled and should be discarded
145  *                  (i.e. not unref'ed).
146  * @pre_push:       Optional.
147  *                  Called just prior to pushing (encoded data) buffer downstream.
148  *                  Subclass has full discretionary access to buffer,
149  *                  and a not OK flow return will abort downstream pushing.
150  * @getcaps:        Optional.
151  *                  Allows for a custom sink getcaps implementation (e.g.
152  *                  for multichannel input specification).  If not implemented,
153  *                  default returns gst_audio_encoder_proxy_getcaps
154  *                  applied to sink template caps.
155  *
156  * Subclasses can override any of the available virtual methods or not, as
157  * needed. At minimum @set_format and @handle_frame needs to be overridden.
158  *
159  * Since: 0.10.36
160  */
161 struct _GstAudioEncoderClass {
162   GstElementClass element_class;
163
164   /*< public >*/
165   /* virtual methods for subclasses */
166
167   gboolean      (*start)              (GstAudioEncoder *enc);
168
169   gboolean      (*stop)               (GstAudioEncoder *enc);
170
171   gboolean      (*set_format)         (GstAudioEncoder *enc,
172                                        GstAudioInfo        *info);
173
174   GstFlowReturn (*handle_frame)       (GstAudioEncoder *enc,
175                                        GstBuffer *buffer);
176
177   void          (*flush)              (GstAudioEncoder *enc);
178
179   GstFlowReturn (*pre_push)           (GstAudioEncoder *enc,
180                                        GstBuffer **buffer);
181
182   gboolean      (*event)              (GstAudioEncoder *enc,
183                                        GstEvent *event);
184
185   GstCaps *     (*getcaps)            (GstAudioEncoder *enc, GstCaps *filter);
186
187   /*< private >*/
188   gpointer       _gst_reserved[GST_PADDING_LARGE];
189 };
190
191 GType           gst_audio_encoder_get_type         (void);
192
193 GstFlowReturn   gst_audio_encoder_finish_frame (GstAudioEncoder * enc,
194                                                 GstBuffer       * buffer,
195                                                 gint              samples);
196
197 GstCaps *       gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc,
198                                                  GstCaps         * caps);
199
200 gboolean        gst_audio_encoder_set_output_format  (GstAudioEncoder    * enc,
201                                                       GstCaps            * caps);
202
203
204 /* context parameters */
205 GstAudioInfo  * gst_audio_encoder_get_audio_info (GstAudioEncoder * enc);
206
207 gint            gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc);
208
209 void            gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num);
210
211 gint            gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc);
212
213 void            gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num);
214
215 gint            gst_audio_encoder_get_frame_max (GstAudioEncoder * enc);
216
217 void            gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num);
218
219 gint            gst_audio_encoder_get_lookahead (GstAudioEncoder * enc);
220
221 void            gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num);
222
223 void            gst_audio_encoder_get_latency (GstAudioEncoder * enc,
224                                                GstClockTime    * min,
225                                                GstClockTime    * max);
226
227 void            gst_audio_encoder_set_latency (GstAudioEncoder * enc,
228                                                GstClockTime      min,
229                                                GstClockTime      max);
230
231 /* object properties */
232
233 void            gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc,
234                                                     gboolean enabled);
235
236 gboolean        gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc);
237
238 void            gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc,
239                                                          gboolean          enabled);
240
241 gboolean        gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc);
242
243 void            gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc,
244                                                    gboolean          enabled);
245
246 gboolean        gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc);
247
248 void            gst_audio_encoder_set_tolerance (GstAudioEncoder * enc,
249                                                  gint64            tolerance);
250
251 gint64          gst_audio_encoder_get_tolerance (GstAudioEncoder * enc);
252
253 void            gst_audio_encoder_set_hard_min (GstAudioEncoder * enc,
254                                                 gboolean enabled);
255
256 gboolean        gst_audio_encoder_get_hard_min (GstAudioEncoder * enc);
257
258 void            gst_audio_encoder_set_drainable (GstAudioEncoder * enc,
259                                                  gboolean enabled);
260
261 gboolean        gst_audio_encoder_get_drainable (GstAudioEncoder * enc);
262
263 void            gst_audio_encoder_merge_tags (GstAudioEncoder * enc,
264                                               const GstTagList * tags, GstTagMergeMode mode);
265
266 G_END_DECLS
267
268 #endif /* __GST_AUDIO_ENCODER_H__ */