base: port to 0.11
[platform/upstream/gstreamer.git] / gst-libs / gst / audio / gstbaseaudioencoder.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_BASE_AUDIO_ENCODER_H__
23 #define __GST_BASE_AUDIO_ENCODER_H__
24
25 #ifndef GST_USE_UNSTABLE_API
26 #warning "GstBaseAudioEncoder is unstable API and may change in future."
27 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
28 #endif
29
30 #include <gst/gst.h>
31 #include <gst/audio/audio.h>
32
33 G_BEGIN_DECLS
34
35 #define GST_TYPE_BASE_AUDIO_ENCODER                (gst_base_audio_encoder_get_type())
36 #define GST_BASE_AUDIO_ENCODER(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_AUDIO_ENCODER,GstBaseAudioEncoder))
37 #define GST_BASE_AUDIO_ENCODER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_AUDIO_ENCODER,GstBaseAudioEncoderClass))
38 #define GST_BASE_AUDIO_ENCODER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_AUDIO_ENCODER,GstBaseAudioEncoderClass))
39 #define GST_IS_BASE_AUDIO_ENCODER(obj)     (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_AUDIO_ENCODER))
40 #define GST_IS_BASE_AUDIO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_AUDIO_ENCODER))
41 #define GST_BASE_AUDIO_ENCODER_CAST(obj)        ((GstBaseAudioEncoder *)(obj))
42
43 /**
44  * GST_BASE_AUDIO_ENCODER_SINK_NAME:
45  *
46  * the name of the templates for the sink pad
47  *
48  * Since: 0.10.36
49  */
50 #define GST_BASE_AUDIO_ENCODER_SINK_NAME        "sink"
51 /**
52  * GST_BASE_AUDIO_ENCODER_SRC_NAME:
53  *
54  * the name of the templates for the source pad
55  *
56  * Since: 0.10.36
57  */
58 #define GST_BASE_AUDIO_ENCODER_SRC_NAME         "src"
59
60 /**
61  * GST_BASE_AUDIO_ENCODER_SRC_PAD:
62  * @obj: base parse instance
63  *
64  * Gives the pointer to the source #GstPad object of the element.
65  *
66  * Since: 0.10.36
67  */
68 #define GST_BASE_AUDIO_ENCODER_SRC_PAD(obj)     (GST_BASE_AUDIO_ENCODER_CAST (obj)->srcpad)
69
70 /**
71  * GST_BASE_AUDIO_ENCODER_SINK_PAD:
72  * @obj: base parse instance
73  *
74  * Gives the pointer to the sink #GstPad object of the element.
75  *
76  * Since: 0.10.36
77  */
78 #define GST_BASE_AUDIO_ENCODER_SINK_PAD(obj)    (GST_BASE_AUDIO_ENCODER_CAST (obj)->sinkpad)
79
80 /**
81  * GST_BASE_AUDIO_ENCODER_SEGMENT:
82  * @obj: base parse instance
83  *
84  * Gives the segment of the element.
85  *
86  * Since: 0.10.36
87  */
88 #define GST_BASE_AUDIO_ENCODER_SEGMENT(obj)     (GST_BASE_AUDIO_ENCODER_CAST (obj)->segment)
89
90
91 typedef struct _GstBaseAudioEncoder GstBaseAudioEncoder;
92 typedef struct _GstBaseAudioEncoderClass GstBaseAudioEncoderClass;
93
94 typedef struct _GstBaseAudioEncoderPrivate GstBaseAudioEncoderPrivate;
95
96 /**
97  * GstBaseAudioEncoder:
98  * @element: the parent element.
99  *
100  * The opaque #GstBaseAudioEncoder data structure.
101  *
102  * Since: 0.10.36
103  */
104 struct _GstBaseAudioEncoder {
105   GstElement     element;
106
107   /*< protected >*/
108   /* source and sink pads */
109   GstPad         *sinkpad;
110   GstPad         *srcpad;
111
112   /* MT-protected (with STREAM_LOCK) */
113   GstSegment      segment;
114
115   /*< private >*/
116   GstBaseAudioEncoderPrivate *priv;
117   gpointer       _gst_reserved[GST_PADDING_LARGE];
118 };
119
120 /**
121  * GstBaseAudioEncoderClass:
122  * @start:          Optional.
123  *                  Called when the element starts processing.
124  *                  Allows opening external resources.
125  * @stop:           Optional.
126  *                  Called when the element stops processing.
127  *                  Allows closing external resources.
128  * @set_format:     Notifies subclass of incoming data format.
129  *                  GstAudioInfo contains the format according to provided caps.
130  * @handle_frame:   Provides input samples (or NULL to clear any remaining data)
131  *                  according to directions as provided by subclass in the
132  *                  #GstBaseAudioEncoderContext.  Input data ref management
133  *                  is performed by base class, subclass should not care or
134  *                  intervene.
135  * @flush:          Optional.
136  *                  Instructs subclass to clear any codec caches and discard
137  *                  any pending samples and not yet returned encoded data.
138  * @event:          Optional.
139  *                  Event handler on the sink pad. This function should return
140  *                  TRUE if the event was handled and should be discarded
141  *                  (i.e. not unref'ed).
142  * @pre_push:       Optional.
143  *                  Called just prior to pushing (encoded data) buffer downstream.
144  *                  Subclass has full discretionary access to buffer,
145  *                  and a not OK flow return will abort downstream pushing.
146  * @getcaps:        Optional.
147  *                  Allows for a custom sink getcaps implementation (e.g.
148  *                  for multichannel input specification).  If not implemented,
149  *                  default returns gst_base_audio_encoder_proxy_getcaps
150  *                  applied to sink template caps.
151  *
152  * Subclasses can override any of the available virtual methods or not, as
153  * needed. At minimum @set_format and @handle_frame needs to be overridden.
154  *
155  * Since: 0.10.36
156  */
157 struct _GstBaseAudioEncoderClass {
158   GstElementClass parent_class;
159
160   /*< public >*/
161   /* virtual methods for subclasses */
162
163   gboolean      (*start)              (GstBaseAudioEncoder *enc);
164
165   gboolean      (*stop)               (GstBaseAudioEncoder *enc);
166
167   gboolean      (*set_format)         (GstBaseAudioEncoder *enc,
168                                        GstAudioInfo        *info);
169
170   GstFlowReturn (*handle_frame)       (GstBaseAudioEncoder *enc,
171                                        GstBuffer *buffer);
172
173   void          (*flush)              (GstBaseAudioEncoder *enc);
174
175   GstFlowReturn (*pre_push)           (GstBaseAudioEncoder *enc,
176                                        GstBuffer **buffer);
177
178   gboolean      (*event)              (GstBaseAudioEncoder *enc,
179                                        GstEvent *event);
180
181   GstCaps *     (*getcaps)            (GstBaseAudioEncoder *enc, GstCaps * filter);
182
183   /*< private >*/
184   gpointer       _gst_reserved[GST_PADDING_LARGE];
185 };
186
187 GType           gst_base_audio_encoder_get_type         (void);
188
189 GstFlowReturn   gst_base_audio_encoder_finish_frame (GstBaseAudioEncoder * enc,
190                                         GstBuffer *buffer, gint samples);
191
192 GstCaps *       gst_base_audio_encoder_proxy_getcaps (GstBaseAudioEncoder * enc,
193                                                       GstCaps * caps);
194
195
196 /* context parameters */
197 GstAudioInfo  * gst_base_audio_encoder_get_audio_info (GstBaseAudioEncoder * enc);
198
199 gint            gst_base_audio_encoder_get_frame_samples (GstBaseAudioEncoder * enc);
200 void            gst_base_audio_encoder_set_frame_samples (GstBaseAudioEncoder * enc,
201                                                           gint num);
202
203 gint            gst_base_audio_encoder_get_frame_max (GstBaseAudioEncoder * enc);
204 void            gst_base_audio_encoder_set_frame_max (GstBaseAudioEncoder * enc,
205                                                       gint num);
206
207 gint            gst_base_audio_encoder_get_lookahead (GstBaseAudioEncoder * enc);
208 void            gst_base_audio_encoder_set_lookahead (GstBaseAudioEncoder * enc,
209                                                       gint num);
210
211 void            gst_base_audio_encoder_get_latency (GstBaseAudioEncoder * enc,
212                                                     GstClockTime * min, GstClockTime * max);
213 void            gst_base_audio_encoder_set_latency (GstBaseAudioEncoder * enc,
214                                                     GstClockTime min, GstClockTime max);
215
216 /* object properties */
217 void            gst_base_audio_encoder_set_mark_granule (GstBaseAudioEncoder * enc,
218                                                     gboolean enabled);
219 gboolean        gst_base_audio_encoder_get_mark_granule (GstBaseAudioEncoder * enc);
220
221 void            gst_base_audio_encoder_set_perfect_timestamp (GstBaseAudioEncoder * enc,
222                                                       gboolean enabled);
223 gboolean        gst_base_audio_encoder_get_perfect_timestamp (GstBaseAudioEncoder * enc);
224
225 void            gst_base_audio_encoder_set_hard_resync (GstBaseAudioEncoder * enc,
226                                                         gboolean enabled);
227 gboolean        gst_base_audio_encoder_get_hard_resync (GstBaseAudioEncoder * enc);
228
229 void            gst_base_audio_encoder_set_tolerance (GstBaseAudioEncoder * enc,
230                                                       gint64 tolerance);
231 gint64          gst_base_audio_encoder_get_tolerance (GstBaseAudioEncoder * enc);
232
233 G_END_DECLS
234
235 #endif /* __GST_BASE_AUDIO_ENCODER_H__ */