dcf9dab6a444b01d2604a9cf97ee717becb00d32
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / ext / fdkaac / gstfdkaacenc.c
1 /*
2  * Copyright (C) 2016 Sebastian Dröge <sebastian@centricular.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "gstfdkaac.h"
25 #include "gstfdkaacenc.h"
26
27 #include <gst/pbutils/pbutils.h>
28
29 #include <string.h>
30
31 /* TODO:
32  * - Add support for other AOT / profiles
33  * - Expose more properties, e.g. afterburner and vbr
34  * - Signal encoder delay
35  * - LOAS / LATM support
36  */
37
38 enum
39 {
40   PROP_0,
41   PROP_BITRATE
42 };
43
44 #define DEFAULT_BITRATE (0)
45
46 #define SAMPLE_RATES " 8000, " \
47                     "11025, " \
48                     "12000, " \
49                     "16000, " \
50                     "22050, " \
51                     "24000, " \
52                     "32000, " \
53                     "44100, " \
54                     "48000, " \
55                     "64000, " \
56                     "88200, " \
57                     "96000"
58
59 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
60     GST_PAD_SINK,
61     GST_PAD_ALWAYS,
62     GST_STATIC_CAPS ("audio/x-raw, "
63         "format = (string) " GST_AUDIO_NE (S16) ", "
64         "layout = (string) interleaved, "
65         "rate = (int) { " SAMPLE_RATES " }, "
66         "channels = (int) {1, 2, 3, 4, 5, 6, 8}")
67     );
68
69 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
70     GST_PAD_SRC,
71     GST_PAD_ALWAYS,
72     GST_STATIC_CAPS ("audio/mpeg, "
73         "mpegversion = (int) 4, "
74         "rate = (int) { " SAMPLE_RATES " }, "
75         "channels = (int) {1, 2, 3, 4, 5, 6, 8}, "
76         "stream-format = (string) { adts, adif, raw }, "
77         "profile = (string) { lc, sbr, ps, ld }, " "framed = (boolean) true")
78     );
79
80 GST_DEBUG_CATEGORY_STATIC (gst_fdkaacenc_debug);
81 #define GST_CAT_DEFAULT gst_fdkaacenc_debug
82
83 static void gst_fdkaacenc_set_property (GObject * object, guint prop_id,
84     const GValue * value, GParamSpec * pspec);
85 static void gst_fdkaacenc_get_property (GObject * object, guint prop_id,
86     GValue * value, GParamSpec * pspec);
87 static gboolean gst_fdkaacenc_start (GstAudioEncoder * enc);
88 static gboolean gst_fdkaacenc_stop (GstAudioEncoder * enc);
89 static gboolean gst_fdkaacenc_set_format (GstAudioEncoder * enc,
90     GstAudioInfo * info);
91 static GstFlowReturn gst_fdkaacenc_handle_frame (GstAudioEncoder * enc,
92     GstBuffer * in_buf);
93 static GstCaps *gst_fdkaacenc_get_caps (GstAudioEncoder * enc,
94     GstCaps * filter);
95 static void gst_fdkaacenc_flush (GstAudioEncoder * enc);
96
97 G_DEFINE_TYPE (GstFdkAacEnc, gst_fdkaacenc, GST_TYPE_AUDIO_ENCODER);
98 GST_ELEMENT_REGISTER_DEFINE (fdkaacenc, "fdkaacenc", GST_RANK_PRIMARY,
99     GST_TYPE_FDKAACENC);
100
101 static void
102 gst_fdkaacenc_set_property (GObject * object, guint prop_id,
103     const GValue * value, GParamSpec * pspec)
104 {
105   GstFdkAacEnc *self = GST_FDKAACENC (object);
106
107   switch (prop_id) {
108     case PROP_BITRATE:
109       self->bitrate = g_value_get_int (value);
110       break;
111     default:
112       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
113       break;
114   }
115   return;
116 }
117
118 static void
119 gst_fdkaacenc_get_property (GObject * object, guint prop_id,
120     GValue * value, GParamSpec * pspec)
121 {
122   GstFdkAacEnc *self = GST_FDKAACENC (object);
123
124   switch (prop_id) {
125     case PROP_BITRATE:
126       g_value_set_int (value, self->bitrate);
127       break;
128     default:
129       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
130       break;
131   }
132   return;
133 }
134
135 static gboolean
136 gst_fdkaacenc_start (GstAudioEncoder * enc)
137 {
138   GstFdkAacEnc *self = GST_FDKAACENC (enc);
139
140   GST_DEBUG_OBJECT (self, "start");
141
142   return TRUE;
143 }
144
145 static gboolean
146 gst_fdkaacenc_stop (GstAudioEncoder * enc)
147 {
148   GstFdkAacEnc *self = GST_FDKAACENC (enc);
149
150   GST_DEBUG_OBJECT (self, "stop");
151
152   if (self->enc) {
153     aacEncClose (&self->enc);
154     self->enc = NULL;
155   }
156
157   self->is_drained = TRUE;
158   return TRUE;
159 }
160
161 static GstCaps *
162 gst_fdkaacenc_get_caps (GstAudioEncoder * enc, GstCaps * filter)
163 {
164   const GstFdkAacChannelLayout *layout;
165   GstCaps *res, *caps, *allowed_caps;
166   gboolean allow_mono = TRUE;
167
168   allowed_caps = gst_pad_get_allowed_caps (GST_AUDIO_ENCODER_SRC_PAD (enc));
169   GST_DEBUG_OBJECT (enc, "allowed caps %" GST_PTR_FORMAT, allowed_caps);
170
171   /* We need at least 2 channels if Parametric Stereo is in use. */
172   if (allowed_caps && gst_caps_get_size (allowed_caps) > 0) {
173     GstStructure *s = gst_caps_get_structure (allowed_caps, 0);
174     const gchar *profile = NULL;
175
176     if ((profile = gst_structure_get_string (s, "profile"))
177         && strcmp (profile, "ps") == 0) {
178       allow_mono = FALSE;
179     }
180   }
181   gst_clear_caps (&allowed_caps);
182
183   caps = gst_caps_new_empty ();
184
185   for (layout = channel_layouts; layout->channels; layout++) {
186     GstCaps *tmp;
187     gint channels = layout->channels;
188
189     if (channels == 1 && !allow_mono)
190       continue;
191
192     tmp = gst_caps_make_writable (gst_pad_get_pad_template_caps
193         (GST_AUDIO_ENCODER_SINK_PAD (enc)));
194
195     if (channels == 1) {
196       gst_caps_set_simple (tmp, "channels", G_TYPE_INT, channels, NULL);
197     } else {
198       guint64 channel_mask;
199       gst_audio_channel_positions_to_mask (layout->positions, channels, FALSE,
200           &channel_mask);
201       gst_caps_set_simple (tmp, "channels", G_TYPE_INT, channels,
202           "channel-mask", GST_TYPE_BITMASK, channel_mask, NULL);
203     }
204
205     gst_caps_append (caps, tmp);
206   }
207
208   res = gst_audio_encoder_proxy_getcaps (enc, caps, filter);
209   gst_caps_unref (caps);
210
211   return res;
212 }
213
214 static gboolean
215 gst_fdkaacenc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
216 {
217   GstFdkAacEnc *self = GST_FDKAACENC (enc);
218   gboolean ret = FALSE;
219   GstCaps *allowed_caps;
220   GstCaps *src_caps;
221   AACENC_ERROR err;
222   gint transmux = 0, aot = AOT_AAC_LC;
223   gint mpegversion = 4;
224   CHANNEL_MODE channel_mode;
225   AACENC_InfoStruct enc_info = { 0 };
226   gint bitrate, signaling_mode;
227   const gchar *ext_profile;
228
229   if (self->enc && !self->is_drained) {
230     /* drain */
231     gst_fdkaacenc_handle_frame (enc, NULL);
232     aacEncClose (&self->enc);
233     self->is_drained = TRUE;
234   }
235
236   allowed_caps = gst_pad_get_allowed_caps (GST_AUDIO_ENCODER_SRC_PAD (self));
237
238   GST_DEBUG_OBJECT (self, "allowed caps: %" GST_PTR_FORMAT, allowed_caps);
239
240   if (allowed_caps && gst_caps_get_size (allowed_caps) > 0) {
241     GstStructure *s = gst_caps_get_structure (allowed_caps, 0);
242     const gchar *str = NULL;
243
244     if ((str = gst_structure_get_string (s, "stream-format"))) {
245       if (strcmp (str, "adts") == 0) {
246         GST_DEBUG_OBJECT (self, "use ADTS format for output");
247         transmux = 2;
248       } else if (strcmp (str, "adif") == 0) {
249         GST_DEBUG_OBJECT (self, "use ADIF format for output");
250         transmux = 1;
251       } else if (strcmp (str, "raw") == 0) {
252         GST_DEBUG_OBJECT (self, "use RAW format for output");
253         transmux = 0;
254       }
255     }
256
257     if ((str = gst_structure_get_string (s, "profile"))) {
258       if (strcmp (str, "lc") == 0) {
259         GST_DEBUG_OBJECT (self, "using AAC-LC profile for output");
260         aot = AOT_AAC_LC;
261       } else if (strcmp (str, "sbr") == 0) {
262         GST_DEBUG_OBJECT (self, "using SBR (HE-AAC) profile for output");
263         aot = AOT_SBR;
264       } else if (strcmp (str, "ps") == 0) {
265         GST_DEBUG_OBJECT (self, "using PS (HE-AACv2) profile for output");
266         aot = AOT_PS;
267       } else if (strcmp (str, "ld") == 0) {
268         GST_DEBUG_OBJECT (self, "using AAC-LD profile for output");
269         aot = AOT_ER_AAC_LD;
270       }
271     }
272
273     gst_structure_get_int (s, "mpegversion", &mpegversion);
274   }
275   if (allowed_caps)
276     gst_caps_unref (allowed_caps);
277
278   err = aacEncOpen (&self->enc, 0, GST_AUDIO_INFO_CHANNELS (info));
279   if (err != AACENC_OK) {
280     GST_ERROR_OBJECT (self, "Unable to open encoder: %d", err);
281     return FALSE;
282   }
283
284   if ((err = aacEncoder_SetParam (self->enc, AACENC_AOT, aot)) != AACENC_OK) {
285     GST_ERROR_OBJECT (self, "Unable to set AOT %d: %d", aot, err);
286     return FALSE;
287   }
288
289   /* Use explicit hierarchical signaling (2) with raw output stream-format
290    * and implicit signaling (0) with ADTS/ADIF */
291   if (transmux == 0)
292     signaling_mode = 2;
293   else
294     signaling_mode = 0;
295
296   if ((err = aacEncoder_SetParam (self->enc, AACENC_SIGNALING_MODE,
297               signaling_mode)) != AACENC_OK) {
298     GST_ERROR_OBJECT (self, "Unable to set signaling mode %d: %d",
299         signaling_mode, err);
300     return FALSE;
301   }
302
303   if ((err = aacEncoder_SetParam (self->enc, AACENC_SAMPLERATE,
304               GST_AUDIO_INFO_RATE (info))) != AACENC_OK) {
305     GST_ERROR_OBJECT (self, "Unable to set sample rate %d: %d",
306         GST_AUDIO_INFO_RATE (info), err);
307     return FALSE;
308   }
309
310   if (GST_AUDIO_INFO_CHANNELS (info) == 1) {
311     channel_mode = MODE_1;
312     self->need_reorder = FALSE;
313     self->aac_positions = NULL;
314   } else {
315     gint in_channels = GST_AUDIO_INFO_CHANNELS (info);
316     const GstAudioChannelPosition *in_positions =
317         &GST_AUDIO_INFO_POSITION (info, 0);
318     guint64 in_channel_mask;
319     const GstFdkAacChannelLayout *layout;
320
321     gst_audio_channel_positions_to_mask (in_positions, in_channels, FALSE,
322         &in_channel_mask);
323
324     for (layout = channel_layouts; layout->channels; layout++) {
325       gint channels = layout->channels;
326       const GstAudioChannelPosition *positions = layout->positions;
327       guint64 channel_mask;
328
329       if (channels != in_channels)
330         continue;
331
332       gst_audio_channel_positions_to_mask (positions, channels, FALSE,
333           &channel_mask);
334       if (channel_mask != in_channel_mask)
335         continue;
336
337       channel_mode = layout->mode;
338       self->need_reorder = memcmp (positions, in_positions,
339           channels * sizeof *positions) != 0;
340       self->aac_positions = positions;
341       break;
342     }
343
344     if (!layout->channels) {
345       GST_ERROR_OBJECT (self, "Couldn't find a valid channel layout");
346       return FALSE;
347     }
348   }
349
350   if ((err = aacEncoder_SetParam (self->enc, AACENC_CHANNELMODE,
351               channel_mode)) != AACENC_OK) {
352     GST_ERROR_OBJECT (self, "Unable to set channel mode %d: %d", channel_mode,
353         err);
354     return FALSE;
355   }
356
357   /* MPEG channel order */
358   if ((err = aacEncoder_SetParam (self->enc, AACENC_CHANNELORDER,
359               0)) != AACENC_OK) {
360     GST_ERROR_OBJECT (self, "Unable to set channel order %d: %d", channel_mode,
361         err);
362     return FALSE;
363   }
364
365   bitrate = self->bitrate;
366   /* See
367    * http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#Recommended_Sampling_Rate_and_Bitrate_Combinations
368    */
369   if (bitrate == 0) {
370     if (GST_AUDIO_INFO_CHANNELS (info) == 1) {
371       if (GST_AUDIO_INFO_RATE (info) < 16000) {
372         bitrate = 8000;
373       } else if (GST_AUDIO_INFO_RATE (info) == 16000) {
374         bitrate = 16000;
375       } else if (GST_AUDIO_INFO_RATE (info) < 32000) {
376         bitrate = 24000;
377       } else if (GST_AUDIO_INFO_RATE (info) == 32000) {
378         bitrate = 32000;
379       } else if (GST_AUDIO_INFO_RATE (info) <= 44100) {
380         bitrate = 56000;
381       } else {
382         bitrate = 160000;
383       }
384     } else if (GST_AUDIO_INFO_CHANNELS (info) == 2) {
385       if (GST_AUDIO_INFO_RATE (info) < 16000) {
386         bitrate = 16000;
387       } else if (GST_AUDIO_INFO_RATE (info) == 16000) {
388         bitrate = 24000;
389       } else if (GST_AUDIO_INFO_RATE (info) < 22050) {
390         bitrate = 32000;
391       } else if (GST_AUDIO_INFO_RATE (info) < 32000) {
392         bitrate = 40000;
393       } else if (GST_AUDIO_INFO_RATE (info) == 32000) {
394         bitrate = 96000;
395       } else if (GST_AUDIO_INFO_RATE (info) <= 44100) {
396         bitrate = 112000;
397       } else {
398         bitrate = 320000;
399       }
400     } else {
401       /* 5, 5.1 */
402       if (GST_AUDIO_INFO_RATE (info) < 32000) {
403         bitrate = 160000;
404       } else if (GST_AUDIO_INFO_RATE (info) <= 44100) {
405         bitrate = 240000;
406       } else {
407         bitrate = 320000;
408       }
409     }
410   }
411
412   if ((err = aacEncoder_SetParam (self->enc, AACENC_TRANSMUX,
413               transmux)) != AACENC_OK) {
414     GST_ERROR_OBJECT (self, "Unable to set transmux %d: %d", transmux, err);
415     return FALSE;
416   }
417
418   if ((err = aacEncoder_SetParam (self->enc, AACENC_BITRATE,
419               bitrate)) != AACENC_OK) {
420     GST_ERROR_OBJECT (self, "Unable to set bitrate %d: %d", bitrate, err);
421     return FALSE;
422   }
423
424   if ((err = aacEncEncode (self->enc, NULL, NULL, NULL, NULL)) != AACENC_OK) {
425     GST_ERROR_OBJECT (self, "Unable to initialize encoder: %d", err);
426     return FALSE;
427   }
428
429   if ((err = aacEncInfo (self->enc, &enc_info)) != AACENC_OK) {
430     GST_ERROR_OBJECT (self, "Unable to get encoder info: %d", err);
431     return FALSE;
432   }
433
434   gst_audio_encoder_set_frame_max (enc, 1);
435   gst_audio_encoder_set_frame_samples_min (enc, enc_info.frameLength);
436   gst_audio_encoder_set_frame_samples_max (enc, enc_info.frameLength);
437   gst_audio_encoder_set_hard_min (enc, FALSE);
438   self->outbuf_size = enc_info.maxOutBufBytes;
439   self->samples_per_frame = enc_info.frameLength;
440
441   src_caps = gst_caps_new_simple ("audio/mpeg",
442       "mpegversion", G_TYPE_INT, mpegversion,
443       "channels", G_TYPE_INT, GST_AUDIO_INFO_CHANNELS (info),
444       "framed", G_TYPE_BOOLEAN, TRUE,
445       "rate", G_TYPE_INT, GST_AUDIO_INFO_RATE (info), NULL);
446
447   /* raw */
448   if (transmux == 0) {
449     GstBuffer *codec_data =
450         gst_buffer_new_memdup (enc_info.confBuf, enc_info.confSize);
451     gst_caps_set_simple (src_caps, "codec_data", GST_TYPE_BUFFER, codec_data,
452         "stream-format", G_TYPE_STRING, "raw", NULL);
453     gst_buffer_unref (codec_data);
454   } else if (transmux == 1) {
455     gst_caps_set_simple (src_caps, "stream-format", G_TYPE_STRING, "adif",
456         NULL);
457   } else if (transmux == 2) {
458     gst_caps_set_simple (src_caps, "stream-format", G_TYPE_STRING, "adts",
459         NULL);
460   } else {
461     g_assert_not_reached ();
462   }
463
464   gst_codec_utils_aac_caps_set_level_and_profile (src_caps, enc_info.confBuf,
465       enc_info.confSize);
466
467   /* The above only parses the "base" profile, which is always going to be LC.
468    * Let's retrieve the extension AOT and set it as our profile in the caps. */
469   ext_profile = gst_codec_utils_aac_get_extension_profile (enc_info.confBuf,
470       enc_info.confSize);
471
472   if (ext_profile)
473     gst_caps_set_simple (src_caps, "profile", G_TYPE_STRING, ext_profile, NULL);
474
475   ret = gst_audio_encoder_set_output_format (enc, src_caps);
476   gst_caps_unref (src_caps);
477
478   return ret;
479 }
480
481 static GstFlowReturn
482 gst_fdkaacenc_handle_frame (GstAudioEncoder * enc, GstBuffer * inbuf)
483 {
484   GstFdkAacEnc *self = GST_FDKAACENC (enc);
485   GstFlowReturn ret = GST_FLOW_OK;
486   GstAudioInfo *info;
487   GstMapInfo imap, omap;
488   GstBuffer *outbuf;
489   AACENC_BufDesc in_desc = { 0 };
490   AACENC_BufDesc out_desc = { 0 };
491   AACENC_InArgs in_args = { 0 };
492   AACENC_OutArgs out_args = { 0 };
493   gint in_id = IN_AUDIO_DATA, out_id = OUT_BITSTREAM_DATA;
494   gint in_sizes, out_sizes;
495   gint in_el_sizes, out_el_sizes;
496   AACENC_ERROR err;
497
498   info = gst_audio_encoder_get_audio_info (enc);
499
500   if (inbuf) {
501     if (self->need_reorder) {
502       inbuf = gst_buffer_copy (inbuf);
503       gst_buffer_map (inbuf, &imap, GST_MAP_READWRITE);
504       gst_audio_reorder_channels (imap.data, imap.size,
505           GST_AUDIO_INFO_FORMAT (info), GST_AUDIO_INFO_CHANNELS (info),
506           &GST_AUDIO_INFO_POSITION (info, 0), self->aac_positions);
507     } else {
508       gst_buffer_map (inbuf, &imap, GST_MAP_READ);
509     }
510
511     in_args.numInSamples = imap.size / GST_AUDIO_INFO_BPS (info);
512
513     in_sizes = imap.size;
514     in_el_sizes = GST_AUDIO_INFO_BPS (info);
515     in_desc.numBufs = 1;
516   } else {
517     in_args.numInSamples = -1;
518
519     in_sizes = 0;
520     in_el_sizes = 0;
521     in_desc.numBufs = 0;
522   }
523   /* We unset is_drained even if there's no inbuf. Basically this is a
524    * workaround for aacEncEncode always producing 1024 bytes even without any
525    * input, thus messing up with the base class counting */
526   self->is_drained = FALSE;
527
528   in_desc.bufferIdentifiers = &in_id;
529   in_desc.bufs = (void *) &imap.data;
530   in_desc.bufSizes = &in_sizes;
531   in_desc.bufElSizes = &in_el_sizes;
532
533   outbuf = gst_audio_encoder_allocate_output_buffer (enc, self->outbuf_size);
534   if (!outbuf) {
535     ret = GST_FLOW_ERROR;
536     goto out;
537   }
538
539   gst_buffer_map (outbuf, &omap, GST_MAP_WRITE);
540   out_sizes = omap.size;
541   out_el_sizes = 1;
542   out_desc.bufferIdentifiers = &out_id;
543   out_desc.numBufs = 1;
544   out_desc.bufs = (void *) &omap.data;
545   out_desc.bufSizes = &out_sizes;
546   out_desc.bufElSizes = &out_el_sizes;
547
548   err = aacEncEncode (self->enc, &in_desc, &out_desc, &in_args, &out_args);
549   if (err == AACENC_ENCODE_EOF && !inbuf)
550     goto out;
551   else if (err != AACENC_OK) {
552     GST_ERROR_OBJECT (self, "Failed to encode data: %d", err);
553     ret = GST_FLOW_ERROR;
554     goto out;
555   }
556
557   if (inbuf) {
558     gst_buffer_unmap (inbuf, &imap);
559     if (self->need_reorder)
560       gst_buffer_unref (inbuf);
561     inbuf = NULL;
562   }
563
564   if (!out_args.numOutBytes)
565     goto out;
566
567   gst_buffer_unmap (outbuf, &omap);
568   gst_buffer_set_size (outbuf, out_args.numOutBytes);
569
570   ret = gst_audio_encoder_finish_frame (enc, outbuf, self->samples_per_frame);
571   outbuf = NULL;
572
573 out:
574   if (outbuf) {
575     gst_buffer_unmap (outbuf, &omap);
576     gst_buffer_unref (outbuf);
577   }
578   if (inbuf) {
579     gst_buffer_unmap (inbuf, &imap);
580     if (self->need_reorder)
581       gst_buffer_unref (inbuf);
582   }
583
584   return ret;
585 }
586
587 static void
588 gst_fdkaacenc_flush (GstAudioEncoder * enc)
589 {
590   GstFdkAacEnc *self = GST_FDKAACENC (enc);
591   GstAudioInfo *info = gst_audio_encoder_get_audio_info (enc);
592
593   aacEncClose (&self->enc);
594   self->enc = NULL;
595   self->is_drained = TRUE;
596
597   if (GST_AUDIO_INFO_IS_VALID (info))
598     gst_fdkaacenc_set_format (enc, info);
599 }
600
601 static void
602 gst_fdkaacenc_init (GstFdkAacEnc * self)
603 {
604   self->bitrate = DEFAULT_BITRATE;
605   self->enc = NULL;
606   self->is_drained = TRUE;
607
608   gst_audio_encoder_set_drainable (GST_AUDIO_ENCODER (self), TRUE);
609 }
610
611 static void
612 gst_fdkaacenc_class_init (GstFdkAacEncClass * klass)
613 {
614   GObjectClass *object_class = G_OBJECT_CLASS (klass);
615   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
616   GstAudioEncoderClass *base_class = GST_AUDIO_ENCODER_CLASS (klass);
617
618   object_class->set_property = GST_DEBUG_FUNCPTR (gst_fdkaacenc_set_property);
619   object_class->get_property = GST_DEBUG_FUNCPTR (gst_fdkaacenc_get_property);
620
621   base_class->start = GST_DEBUG_FUNCPTR (gst_fdkaacenc_start);
622   base_class->stop = GST_DEBUG_FUNCPTR (gst_fdkaacenc_stop);
623   base_class->set_format = GST_DEBUG_FUNCPTR (gst_fdkaacenc_set_format);
624   base_class->getcaps = GST_DEBUG_FUNCPTR (gst_fdkaacenc_get_caps);
625   base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_fdkaacenc_handle_frame);
626   base_class->flush = GST_DEBUG_FUNCPTR (gst_fdkaacenc_flush);
627
628   g_object_class_install_property (object_class, PROP_BITRATE,
629       g_param_spec_int ("bitrate",
630           "Bitrate",
631           "Target Audio Bitrate (0 = fixed value based on "
632           " sample rate and channel count)",
633           0, G_MAXINT, DEFAULT_BITRATE,
634           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
635
636   gst_element_class_add_static_pad_template (element_class, &sink_template);
637   gst_element_class_add_static_pad_template (element_class, &src_template);
638
639   gst_element_class_set_static_metadata (element_class, "FDK AAC audio encoder",
640       "Codec/Encoder/Audio/Converter", "FDK AAC audio encoder",
641       "Sebastian Dröge <sebastian@centricular.com>");
642
643   GST_DEBUG_CATEGORY_INIT (gst_fdkaacenc_debug, "fdkaacenc", 0,
644       "fdkaac encoder");
645 }