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_AUDIO_ENCODER_H__
23 #define __GST_AUDIO_ENCODER_H__
26 #include <gst/audio/audio.h>
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))
39 * GST_AUDIO_ENCODER_SINK_NAME:
41 * the name of the templates for the sink pad
45 #define GST_AUDIO_ENCODER_SINK_NAME "sink"
47 * GST_AUDIO_ENCODER_SRC_NAME:
49 * the name of the templates for the source pad
53 #define GST_AUDIO_ENCODER_SRC_NAME "src"
56 * GST_AUDIO_ENCODER_SRC_PAD:
57 * @obj: base parse instance
59 * Gives the pointer to the source #GstPad object of the element.
63 #define GST_AUDIO_ENCODER_SRC_PAD(obj) (GST_AUDIO_ENCODER_CAST (obj)->srcpad)
66 * GST_AUDIO_ENCODER_SINK_PAD:
67 * @obj: base parse instance
69 * Gives the pointer to the sink #GstPad object of the element.
73 #define GST_AUDIO_ENCODER_SINK_PAD(obj) (GST_AUDIO_ENCODER_CAST (obj)->sinkpad)
76 * GST_AUDIO_ENCODER_SEGMENT:
77 * @obj: base parse instance
79 * Gives the segment of the element.
83 #define GST_AUDIO_ENCODER_SEGMENT(obj) (GST_AUDIO_ENCODER_CAST (obj)->segment)
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)
88 typedef struct _GstAudioEncoder GstAudioEncoder;
89 typedef struct _GstAudioEncoderClass GstAudioEncoderClass;
91 typedef struct _GstAudioEncoderPrivate GstAudioEncoderPrivate;
96 * The opaque #GstAudioEncoder data structure.
100 struct _GstAudioEncoder {
104 /* source and sink pads */
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;
113 /* MT-protected (with STREAM_LOCK) */
117 GstAudioEncoderPrivate *priv;
118 gpointer _gst_reserved[GST_PADDING_LARGE];
122 * GstAudioEncoderClass:
123 * @element_class: The parent class structure
125 * Called when the element starts processing.
126 * Allows opening external resources.
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().
139 * Instructs subclass to clear any codec caches and discard
140 * any pending samples and not yet returned encoded data.
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.
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.
160 struct _GstAudioEncoderClass {
161 GstElementClass element_class;
164 /* virtual methods for subclasses */
166 gboolean (*start) (GstAudioEncoder *enc);
168 gboolean (*stop) (GstAudioEncoder *enc);
170 gboolean (*set_format) (GstAudioEncoder *enc,
173 GstFlowReturn (*handle_frame) (GstAudioEncoder *enc,
176 void (*flush) (GstAudioEncoder *enc);
178 GstFlowReturn (*pre_push) (GstAudioEncoder *enc,
181 gboolean (*event) (GstAudioEncoder *enc,
184 GstCaps * (*getcaps) (GstAudioEncoder *enc);
187 gpointer _gst_reserved[GST_PADDING_LARGE];
190 GType gst_audio_encoder_get_type (void);
192 GstFlowReturn gst_audio_encoder_finish_frame (GstAudioEncoder * enc,
196 GstCaps * gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc,
200 /* context parameters */
201 GstAudioInfo * gst_audio_encoder_get_audio_info (GstAudioEncoder * enc);
203 gint gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc);
205 void gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num);
207 gint gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc);
209 void gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num);
211 gint gst_audio_encoder_get_frame_max (GstAudioEncoder * enc);
213 void gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num);
215 gint gst_audio_encoder_get_lookahead (GstAudioEncoder * enc);
217 void gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num);
219 void gst_audio_encoder_get_latency (GstAudioEncoder * enc,
223 void gst_audio_encoder_set_latency (GstAudioEncoder * enc,
227 /* object properties */
229 void gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc,
232 gboolean gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc);
234 void gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc,
237 gboolean gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc);
239 void gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc,
242 gboolean gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc);
244 void gst_audio_encoder_set_tolerance (GstAudioEncoder * enc,
247 gint64 gst_audio_encoder_get_tolerance (GstAudioEncoder * enc);
249 void gst_audio_encoder_set_hard_min (GstAudioEncoder * enc,
252 gboolean gst_audio_encoder_get_hard_min (GstAudioEncoder * enc);
254 void gst_audio_encoder_set_drainable (GstAudioEncoder * enc,
257 gboolean gst_audio_encoder_get_drainable (GstAudioEncoder * enc);
259 void gst_audio_encoder_merge_tags (GstAudioEncoder * enc,
260 const GstTagList * tags, GstTagMergeMode mode);
264 #endif /* __GST_AUDIO_ENCODER_H__ */