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>
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.
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.
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.
22 #ifndef __GST_BASE_AUDIO_ENCODER_H__
23 #define __GST_BASE_AUDIO_ENCODER_H__
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."
31 #include <gst/audio/audio.h>
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))
44 * GST_BASE_AUDIO_ENCODER_SINK_NAME:
46 * the name of the templates for the sink pad
50 #define GST_BASE_AUDIO_ENCODER_SINK_NAME "sink"
52 * GST_BASE_AUDIO_ENCODER_SRC_NAME:
54 * the name of the templates for the source pad
58 #define GST_BASE_AUDIO_ENCODER_SRC_NAME "src"
61 * GST_BASE_AUDIO_ENCODER_SRC_PAD:
62 * @obj: base parse instance
64 * Gives the pointer to the source #GstPad object of the element.
68 #define GST_BASE_AUDIO_ENCODER_SRC_PAD(obj) (GST_BASE_AUDIO_ENCODER_CAST (obj)->srcpad)
71 * GST_BASE_AUDIO_ENCODER_SINK_PAD:
72 * @obj: base parse instance
74 * Gives the pointer to the sink #GstPad object of the element.
78 #define GST_BASE_AUDIO_ENCODER_SINK_PAD(obj) (GST_BASE_AUDIO_ENCODER_CAST (obj)->sinkpad)
81 * GST_BASE_AUDIO_ENCODER_SEGMENT:
82 * @obj: base parse instance
84 * Gives the segment of the element.
88 #define GST_BASE_AUDIO_ENCODER_SEGMENT(obj) (GST_BASE_AUDIO_ENCODER_CAST (obj)->segment)
91 typedef struct _GstBaseAudioEncoder GstBaseAudioEncoder;
92 typedef struct _GstBaseAudioEncoderClass GstBaseAudioEncoderClass;
94 typedef struct _GstBaseAudioEncoderPrivate GstBaseAudioEncoderPrivate;
97 * GstBaseAudioEncoder:
98 * @element: the parent element.
100 * The opaque #GstBaseAudioEncoder data structure.
104 struct _GstBaseAudioEncoder {
108 /* source and sink pads */
112 /* MT-protected (with STREAM_LOCK) */
116 GstBaseAudioEncoderPrivate *priv;
117 gpointer _gst_reserved[GST_PADDING_LARGE];
121 * GstBaseAudioEncoderClass:
123 * Called when the element starts processing.
124 * Allows opening external resources.
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
136 * Instructs subclass to clear any codec caches and discard
137 * any pending samples and not yet returned encoded data.
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.
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.
157 struct _GstBaseAudioEncoderClass {
158 GstElementClass parent_class;
161 /* virtual methods for subclasses */
163 gboolean (*start) (GstBaseAudioEncoder *enc);
165 gboolean (*stop) (GstBaseAudioEncoder *enc);
167 gboolean (*set_format) (GstBaseAudioEncoder *enc,
170 GstFlowReturn (*handle_frame) (GstBaseAudioEncoder *enc,
173 void (*flush) (GstBaseAudioEncoder *enc);
175 GstFlowReturn (*pre_push) (GstBaseAudioEncoder *enc,
178 gboolean (*event) (GstBaseAudioEncoder *enc,
181 GstCaps * (*getcaps) (GstBaseAudioEncoder *enc);
184 gpointer _gst_reserved[GST_PADDING_LARGE];
187 GType gst_base_audio_encoder_get_type (void);
189 GstFlowReturn gst_base_audio_encoder_finish_frame (GstBaseAudioEncoder * enc,
190 GstBuffer *buffer, gint samples);
192 GstCaps * gst_base_audio_encoder_proxy_getcaps (GstBaseAudioEncoder * enc,
196 /* context parameters */
197 GstAudioInfo * gst_base_audio_encoder_get_audio_info (GstBaseAudioEncoder * enc);
199 gint gst_base_audio_encoder_get_frame_samples (GstBaseAudioEncoder * enc);
200 void gst_base_audio_encoder_set_frame_samples (GstBaseAudioEncoder * enc,
203 gint gst_base_audio_encoder_get_frame_max (GstBaseAudioEncoder * enc);
204 void gst_base_audio_encoder_set_frame_max (GstBaseAudioEncoder * enc,
207 gint gst_base_audio_encoder_get_lookahead (GstBaseAudioEncoder * enc);
208 void gst_base_audio_encoder_set_lookahead (GstBaseAudioEncoder * enc,
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);
216 /* object properties */
217 void gst_base_audio_encoder_set_mark_granule (GstBaseAudioEncoder * enc,
219 gboolean gst_base_audio_encoder_get_mark_granule (GstBaseAudioEncoder * enc);
221 void gst_base_audio_encoder_set_perfect_timestamp (GstBaseAudioEncoder * enc,
223 gboolean gst_base_audio_encoder_get_perfect_timestamp (GstBaseAudioEncoder * enc);
225 void gst_base_audio_encoder_set_hard_resync (GstBaseAudioEncoder * enc,
227 gboolean gst_base_audio_encoder_get_hard_resync (GstBaseAudioEncoder * enc);
229 void gst_base_audio_encoder_set_tolerance (GstBaseAudioEncoder * enc,
231 gint64 gst_base_audio_encoder_get_tolerance (GstBaseAudioEncoder * enc);
235 #endif /* __GST_BASE_AUDIO_ENCODER_H__ */