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., 51 Franklin St, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef __GST_AUDIO_AUDIO_H__ 23 #include <gst/audio/audio.h> 24 #endif 25 26 #ifndef __GST_AUDIO_ENCODER_H__ 27 #define __GST_AUDIO_ENCODER_H__ 28 29 #include <gst/gst.h> 30 31 G_BEGIN_DECLS 32 33 #define GST_TYPE_AUDIO_ENCODER (gst_audio_encoder_get_type()) 34 #define GST_AUDIO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_ENCODER,GstAudioEncoder)) 35 #define GST_AUDIO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_ENCODER,GstAudioEncoderClass)) 36 #define GST_AUDIO_ENCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_AUDIO_ENCODER,GstAudioEncoderClass)) 37 #define GST_IS_AUDIO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_ENCODER)) 38 #define GST_IS_AUDIO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_ENCODER)) 39 #define GST_AUDIO_ENCODER_CAST(obj) ((GstAudioEncoder *)(obj)) 40 41 /** 42 * GST_AUDIO_ENCODER_SINK_NAME: 43 * 44 * the name of the templates for the sink pad 45 */ 46 #define GST_AUDIO_ENCODER_SINK_NAME "sink" 47 /** 48 * GST_AUDIO_ENCODER_SRC_NAME: 49 * 50 * the name of the templates for the source pad 51 */ 52 #define GST_AUDIO_ENCODER_SRC_NAME "src" 53 54 /** 55 * GST_AUDIO_ENCODER_SRC_PAD: 56 * @obj: audio encoder instance 57 * 58 * Gives the pointer to the source #GstPad object of the element. 59 */ 60 #define GST_AUDIO_ENCODER_SRC_PAD(obj) (GST_AUDIO_ENCODER_CAST (obj)->srcpad) 61 62 /** 63 * GST_AUDIO_ENCODER_SINK_PAD: 64 * @obj: audio encoder instance 65 * 66 * Gives the pointer to the sink #GstPad object of the element. 67 */ 68 #define GST_AUDIO_ENCODER_SINK_PAD(obj) (GST_AUDIO_ENCODER_CAST (obj)->sinkpad) 69 70 /** 71 * GST_AUDIO_ENCODER_INPUT_SEGMENT: 72 * @obj: base parse instance 73 * 74 * Gives the input segment of the element. 75 */ 76 #define GST_AUDIO_ENCODER_INPUT_SEGMENT(obj) (GST_AUDIO_ENCODER_CAST (obj)->input_segment) 77 78 /** 79 * GST_AUDIO_ENCODER_OUTPUT_SEGMENT: 80 * @obj: base parse instance 81 * 82 * Gives the output segment of the element. 83 */ 84 #define GST_AUDIO_ENCODER_OUTPUT_SEGMENT(obj) (GST_AUDIO_ENCODER_CAST (obj)->output_segment) 85 86 #define GST_AUDIO_ENCODER_STREAM_LOCK(enc) g_rec_mutex_lock (&GST_AUDIO_ENCODER (enc)->stream_lock) 87 #define GST_AUDIO_ENCODER_STREAM_UNLOCK(enc) g_rec_mutex_unlock (&GST_AUDIO_ENCODER (enc)->stream_lock) 88 89 typedef struct _GstAudioEncoder GstAudioEncoder; 90 typedef struct _GstAudioEncoderClass GstAudioEncoderClass; 91 92 typedef struct _GstAudioEncoderPrivate GstAudioEncoderPrivate; 93 94 /** 95 * GstAudioEncoder: 96 * 97 * The opaque #GstAudioEncoder data structure. 98 */ 99 struct _GstAudioEncoder { 100 GstElement element; 101 102 /*< protected >*/ 103 /* source and sink pads */ 104 GstPad *sinkpad; 105 GstPad *srcpad; 106 107 /* protects all data processing, i.e. is locked 108 * in the chain function, finish_frame and when 109 * processing serialized events */ 110 GRecMutex stream_lock; 111 112 /* MT-protected (with STREAM_LOCK) */ 113 GstSegment input_segment; 114 GstSegment output_segment; 115 116 /*< private >*/ 117 GstAudioEncoderPrivate *priv; 118 119 gpointer _gst_reserved[GST_PADDING_LARGE]; 120 }; 121 122 /** 123 * GstAudioEncoderClass: 124 * @element_class: The parent class structure 125 * @start: Optional. 126 * Called when the element starts processing. 127 * Allows opening external resources. 128 * @stop: Optional. 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(). 139 * @flush: Optional. 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. 157 * @open: Optional. 158 * Called when the element changes to GST_STATE_READY. 159 * Allows opening external resources. 160 * @close: Optional. 161 * Called when the element changes to GST_STATE_NULL. 162 * Allows closing external resources. 163 * @negotiate: Optional. 164 * Negotiate with downstream and configure buffer pools, etc. 165 * Subclasses should chain up to the parent implementation to 166 * invoke the default handler. 167 * @decide_allocation: Optional. 168 * Setup the allocation parameters for allocating output 169 * buffers. The passed in query contains the result of the 170 * downstream allocation query. 171 * Subclasses should chain up to the parent implementation to 172 * invoke the default handler. 173 * @propose_allocation: Optional. 174 * Propose buffer allocation parameters for upstream elements. 175 * Subclasses should chain up to the parent implementation to 176 * invoke the default handler. 177 * @transform_meta: Optional. Transform the metadata on the input buffer to the 178 * output buffer. By default this method copies all meta without 179 * tags and meta with only the "audio" tag. subclasses can 180 * implement this method and return %TRUE if the metadata is to be 181 * copied. Since: 1.6 182 * @sink_query: Optional. 183 * Query handler on the sink pad. This function should 184 * return TRUE if the query could be performed. Subclasses 185 * should chain up to the parent implementation to invoke the 186 * default handler. Since: 1.6 187 * @src_query: Optional. 188 * Query handler on the source pad. This function should 189 * return TRUE if the query could be performed. Subclasses 190 * should chain up to the parent implementation to invoke the 191 * default handler. Since: 1.6 192 * 193 * Subclasses can override any of the available virtual methods or not, as 194 * needed. At minimum @set_format and @handle_frame needs to be overridden. 195 */ 196 struct _GstAudioEncoderClass { 197 GstElementClass element_class; 198 199 /*< public >*/ 200 /* virtual methods for subclasses */ 201 202 gboolean (*start) (GstAudioEncoder *enc); 203 204 gboolean (*stop) (GstAudioEncoder *enc); 205 206 gboolean (*set_format) (GstAudioEncoder *enc, 207 GstAudioInfo *info); 208 209 GstFlowReturn (*handle_frame) (GstAudioEncoder *enc, 210 GstBuffer *buffer); 211 212 void (*flush) (GstAudioEncoder *enc); 213 214 GstFlowReturn (*pre_push) (GstAudioEncoder *enc, 215 GstBuffer **buffer); 216 217 gboolean (*sink_event) (GstAudioEncoder *enc, 218 GstEvent *event); 219 220 gboolean (*src_event) (GstAudioEncoder *enc, 221 GstEvent *event); 222 223 GstCaps * (*getcaps) (GstAudioEncoder *enc, GstCaps *filter); 224 225 gboolean (*open) (GstAudioEncoder *enc); 226 227 gboolean (*close) (GstAudioEncoder *enc); 228 229 gboolean (*negotiate) (GstAudioEncoder *enc); 230 231 gboolean (*decide_allocation) (GstAudioEncoder *enc, GstQuery *query); 232 233 gboolean (*propose_allocation) (GstAudioEncoder * enc, 234 GstQuery * query); 235 236 gboolean (*transform_meta) (GstAudioEncoder *enc, GstBuffer *outbuf, 237 GstMeta *meta, GstBuffer *inbuf); 238 239 gboolean (*sink_query) (GstAudioEncoder *encoder, 240 GstQuery *query); 241 242 gboolean (*src_query) (GstAudioEncoder *encoder, 243 GstQuery *query); 244 245 246 /*< private >*/ 247 gpointer _gst_reserved[GST_PADDING_LARGE-3]; 248 }; 249 250 GST_AUDIO_API 251 GType gst_audio_encoder_get_type (void); 252 253 GST_AUDIO_API 254 GstFlowReturn gst_audio_encoder_finish_frame (GstAudioEncoder * enc, 255 GstBuffer * buffer, 256 gint samples); 257 258 GST_AUDIO_API 259 GstCaps * gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc, 260 GstCaps * caps, 261 GstCaps * filter); 262 263 GST_AUDIO_API 264 gboolean gst_audio_encoder_set_output_format (GstAudioEncoder * enc, 265 GstCaps * caps); 266 267 GST_AUDIO_API 268 gboolean gst_audio_encoder_negotiate (GstAudioEncoder * enc); 269 270 GST_AUDIO_API 271 GstBuffer * gst_audio_encoder_allocate_output_buffer (GstAudioEncoder * enc, 272 gsize size); 273 274 /* context parameters */ 275 276 GST_AUDIO_API 277 GstAudioInfo * gst_audio_encoder_get_audio_info (GstAudioEncoder * enc); 278 279 GST_AUDIO_API 280 gint gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc); 281 282 GST_AUDIO_API 283 void gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num); 284 285 GST_AUDIO_API 286 gint gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc); 287 288 GST_AUDIO_API 289 void gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num); 290 291 GST_AUDIO_API 292 gint gst_audio_encoder_get_frame_max (GstAudioEncoder * enc); 293 294 GST_AUDIO_API 295 void gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num); 296 297 GST_AUDIO_API 298 gint gst_audio_encoder_get_lookahead (GstAudioEncoder * enc); 299 300 GST_AUDIO_API 301 void gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num); 302 303 GST_AUDIO_API 304 void gst_audio_encoder_get_latency (GstAudioEncoder * enc, 305 GstClockTime * min, 306 GstClockTime * max); 307 308 GST_AUDIO_API 309 void gst_audio_encoder_set_latency (GstAudioEncoder * enc, 310 GstClockTime min, 311 GstClockTime max); 312 313 GST_AUDIO_API 314 void gst_audio_encoder_set_headers (GstAudioEncoder * enc, 315 GList * headers); 316 317 GST_AUDIO_API 318 void gst_audio_encoder_set_allocation_caps (GstAudioEncoder * enc, 319 GstCaps * allocation_caps); 320 321 /* object properties */ 322 323 GST_AUDIO_API 324 void gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc, 325 gboolean enabled); 326 327 GST_AUDIO_API 328 gboolean gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc); 329 330 GST_AUDIO_API 331 void gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc, 332 gboolean enabled); 333 334 GST_AUDIO_API 335 gboolean gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc); 336 337 GST_AUDIO_API 338 void gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc, 339 gboolean enabled); 340 341 GST_AUDIO_API 342 gboolean gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc); 343 344 GST_AUDIO_API 345 void gst_audio_encoder_set_tolerance (GstAudioEncoder * enc, 346 GstClockTime tolerance); 347 348 GST_AUDIO_API 349 GstClockTime gst_audio_encoder_get_tolerance (GstAudioEncoder * enc); 350 351 GST_AUDIO_API 352 void gst_audio_encoder_set_hard_min (GstAudioEncoder * enc, 353 gboolean enabled); 354 355 GST_AUDIO_API 356 gboolean gst_audio_encoder_get_hard_min (GstAudioEncoder * enc); 357 358 GST_AUDIO_API 359 void gst_audio_encoder_set_drainable (GstAudioEncoder * enc, 360 gboolean enabled); 361 362 GST_AUDIO_API 363 gboolean gst_audio_encoder_get_drainable (GstAudioEncoder * enc); 364 365 GST_AUDIO_API 366 void gst_audio_encoder_get_allocator (GstAudioEncoder * enc, 367 GstAllocator ** allocator, 368 GstAllocationParams * params); 369 370 GST_AUDIO_API 371 void gst_audio_encoder_merge_tags (GstAudioEncoder * enc, 372 const GstTagList * tags, GstTagMergeMode mode); 373 374 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAudioEncoder, gst_object_unref) 375 376 G_END_DECLS 377 378 #endif /* __GST_AUDIO_ENCODER_H__ */ 379