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_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)
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 GRecMutex stream_lock;
113 /* MT-protected (with STREAM_LOCK) */
117 GstAudioEncoderPrivate *priv;
119 gpointer _gst_reserved[GST_PADDING_LARGE];
123 * GstAudioEncoderClass:
124 * @element_class: The parent class structure
126 * Called when the element starts processing.
127 * Allows opening external resources.
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().
140 * Instructs subclass to clear any codec caches and discard
141 * any pending samples and not yet returned encoded data.
142 * @sink_event: Optional.
143 * Event handler on the sink pad. Subclasses should chain up to
144 * the parent implementation to invoke the default handler.
145 * @src_event: Optional.
146 * Event handler on the src pad. Subclasses should chain up to
147 * the parent implementation to invoke the default handler.
148 * @pre_push: Optional.
149 * Called just prior to pushing (encoded data) buffer downstream.
150 * Subclass has full discretionary access to buffer,
151 * and a not OK flow return will abort downstream pushing.
152 * @getcaps: Optional.
153 * Allows for a custom sink getcaps implementation (e.g.
154 * for multichannel input specification). If not implemented,
155 * default returns gst_audio_encoder_proxy_getcaps
156 * applied to sink template caps.
158 * Called when the element changes to GST_STATE_READY.
159 * Allows opening external resources. Since: 0.10.37.
161 * Called when the element changes to GST_STATE_NULL.
162 * Allows closing external resources. Since: 0.10.37.
164 * Subclasses can override any of the available virtual methods or not, as
165 * needed. At minimum @set_format and @handle_frame needs to be overridden.
169 struct _GstAudioEncoderClass {
170 GstElementClass element_class;
173 /* virtual methods for subclasses */
175 gboolean (*start) (GstAudioEncoder *enc);
177 gboolean (*stop) (GstAudioEncoder *enc);
179 gboolean (*set_format) (GstAudioEncoder *enc,
182 GstFlowReturn (*handle_frame) (GstAudioEncoder *enc,
185 void (*flush) (GstAudioEncoder *enc);
187 GstFlowReturn (*pre_push) (GstAudioEncoder *enc,
190 gboolean (*sink_event) (GstAudioEncoder *enc,
193 gboolean (*src_event) (GstAudioEncoder *enc,
196 GstCaps * (*getcaps) (GstAudioEncoder *enc, GstCaps *filter);
198 gboolean (*open) (GstAudioEncoder *enc);
200 gboolean (*close) (GstAudioEncoder *enc);
203 gpointer _gst_reserved[GST_PADDING_LARGE-2];
206 GType gst_audio_encoder_get_type (void);
208 GstFlowReturn gst_audio_encoder_finish_frame (GstAudioEncoder * enc,
212 GstCaps * gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc,
215 gboolean gst_audio_encoder_set_output_format (GstAudioEncoder * enc,
219 /* context parameters */
220 GstAudioInfo * gst_audio_encoder_get_audio_info (GstAudioEncoder * enc);
222 gint gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc);
224 void gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num);
226 gint gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc);
228 void gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num);
230 gint gst_audio_encoder_get_frame_max (GstAudioEncoder * enc);
232 void gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num);
234 gint gst_audio_encoder_get_lookahead (GstAudioEncoder * enc);
236 void gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num);
238 void gst_audio_encoder_get_latency (GstAudioEncoder * enc,
242 void gst_audio_encoder_set_latency (GstAudioEncoder * enc,
246 /* object properties */
248 void gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc,
251 gboolean gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc);
253 void gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc,
256 gboolean gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc);
258 void gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc,
261 gboolean gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc);
263 void gst_audio_encoder_set_tolerance (GstAudioEncoder * enc,
266 gint64 gst_audio_encoder_get_tolerance (GstAudioEncoder * enc);
268 void gst_audio_encoder_set_hard_min (GstAudioEncoder * enc,
271 gboolean gst_audio_encoder_get_hard_min (GstAudioEncoder * enc);
273 void gst_audio_encoder_set_drainable (GstAudioEncoder * enc,
276 gboolean gst_audio_encoder_get_drainable (GstAudioEncoder * enc);
278 void gst_audio_encoder_merge_tags (GstAudioEncoder * enc,
279 const GstTagList * tags, GstTagMergeMode mode);
283 #endif /* __GST_AUDIO_ENCODER_H__ */