tizen 2.3 release
[framework/multimedia/gst-plugins-base0.10.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_static_rec_mutex_lock (&GST_AUDIO_ENCODER (enc)->stream_lock)
86 #define GST_AUDIO_ENCODER_STREAM_UNLOCK(enc) g_static_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   GStaticRecMutex stream_lock;
112
113   /* MT-protected (with STREAM_LOCK) */
114   GstSegment      segment;
115
116   /*< private >*/
117   GstAudioEncoderPrivate *priv;
118   gpointer       _gst_reserved[GST_PADDING_LARGE];
119 };
120
121 /**
122  * GstAudioEncoderClass:
123  * @element_class:  The parent class structure
124  * @start:          Optional.
125  *                  Called when the element starts processing.
126  *                  Allows opening external resources.
127  * @stop:           Optional.
128  *                  Called when the element stops processing.
129  *                  Allows closing external resources.
130  * @set_format:     Notifies subclass of incoming data format.
131  *                  GstAudioInfo contains the format according to provided caps.
132  * @handle_frame:   Provides input samples (or NULL to clear any remaining data)
133  *                  according to directions as configured by the subclass
134  *                  using the API.  Input data ref management is performed
135  *                  by base class, subclass should not care or intervene,
136  *                  and input data is only valid until next call to base class,
137  *                  most notably a call to gst_audio_encoder_finish_frame().
138  * @flush:          Optional.
139  *                  Instructs subclass to clear any codec caches and discard
140  *                  any pending samples and not yet returned encoded data.
141  * @event:          Optional.
142  *                  Event handler on the sink pad. This function should return
143  *                  TRUE if the event was handled and should be discarded
144  *                  (i.e. not unref'ed).
145  * @pre_push:       Optional.
146  *                  Called just prior to pushing (encoded data) buffer downstream.
147  *                  Subclass has full discretionary access to buffer,
148  *                  and a not OK flow return will abort downstream pushing.
149  * @getcaps:        Optional.
150  *                  Allows for a custom sink getcaps implementation (e.g.
151  *                  for multichannel input specification).  If not implemented,
152  *                  default returns gst_audio_encoder_proxy_getcaps
153  *                  applied to sink template caps.
154  *
155  * Subclasses can override any of the available virtual methods or not, as
156  * needed. At minimum @set_format and @handle_frame needs to be overridden.
157  *
158  * Since: 0.10.36
159  */
160 struct _GstAudioEncoderClass {
161   GstElementClass element_class;
162
163   /*< public >*/
164   /* virtual methods for subclasses */
165
166   gboolean      (*start)              (GstAudioEncoder *enc);
167
168   gboolean      (*stop)               (GstAudioEncoder *enc);
169
170   gboolean      (*set_format)         (GstAudioEncoder *enc,
171                                        GstAudioInfo        *info);
172
173   GstFlowReturn (*handle_frame)       (GstAudioEncoder *enc,
174                                        GstBuffer *buffer);
175
176   void          (*flush)              (GstAudioEncoder *enc);
177
178   GstFlowReturn (*pre_push)           (GstAudioEncoder *enc,
179                                        GstBuffer **buffer);
180
181   gboolean      (*event)              (GstAudioEncoder *enc,
182                                        GstEvent *event);
183
184   GstCaps *     (*getcaps)            (GstAudioEncoder *enc);
185
186   /*< private >*/
187   gpointer       _gst_reserved[GST_PADDING_LARGE];
188 };
189
190 GType           gst_audio_encoder_get_type         (void);
191
192 GstFlowReturn   gst_audio_encoder_finish_frame (GstAudioEncoder * enc,
193                                                 GstBuffer       * buffer,
194                                                 gint              samples);
195
196 GstCaps *       gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc,
197                                                  GstCaps         * caps);
198
199
200 /* context parameters */
201 GstAudioInfo  * gst_audio_encoder_get_audio_info (GstAudioEncoder * enc);
202
203 gint            gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc);
204
205 void            gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num);
206
207 gint            gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc);
208
209 void            gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num);
210
211 gint            gst_audio_encoder_get_frame_max (GstAudioEncoder * enc);
212
213 void            gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num);
214
215 gint            gst_audio_encoder_get_lookahead (GstAudioEncoder * enc);
216
217 void            gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num);
218
219 void            gst_audio_encoder_get_latency (GstAudioEncoder * enc,
220                                                GstClockTime    * min,
221                                                GstClockTime    * max);
222
223 void            gst_audio_encoder_set_latency (GstAudioEncoder * enc,
224                                                GstClockTime      min,
225                                                GstClockTime      max);
226
227 /* object properties */
228
229 void            gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc,
230                                                     gboolean enabled);
231
232 gboolean        gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc);
233
234 void            gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc,
235                                                          gboolean          enabled);
236
237 gboolean        gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc);
238
239 void            gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc,
240                                                    gboolean          enabled);
241
242 gboolean        gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc);
243
244 void            gst_audio_encoder_set_tolerance (GstAudioEncoder * enc,
245                                                  gint64            tolerance);
246
247 gint64          gst_audio_encoder_get_tolerance (GstAudioEncoder * enc);
248
249 void            gst_audio_encoder_set_hard_min (GstAudioEncoder * enc,
250                                                 gboolean enabled);
251
252 gboolean        gst_audio_encoder_get_hard_min (GstAudioEncoder * enc);
253
254 void            gst_audio_encoder_set_drainable (GstAudioEncoder * enc,
255                                                  gboolean enabled);
256
257 gboolean        gst_audio_encoder_get_drainable (GstAudioEncoder * enc);
258
259 void            gst_audio_encoder_merge_tags (GstAudioEncoder * enc,
260                                               const GstTagList * tags, GstTagMergeMode mode);
261
262 G_END_DECLS
263
264 #endif /* __GST_AUDIO_ENCODER_H__ */