2003-11-22 12:25:48 +00:00
|
|
|
/* GStreamer FAAC (Free AAC Encoder) plugin
|
|
|
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2009-08-30 21:00:35 +00:00
|
|
|
* Copyright (C) 2009 Mark Nauwelaerts <mnauw@users.sourceforge.net>
|
2003-11-22 12:25:48 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-09-05 19:35:19 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-faac
|
2010-01-05 15:10:13 +00:00
|
|
|
* @see_also: faad
|
2009-09-05 19:35:19 +00:00
|
|
|
*
|
2010-02-11 19:21:38 +00:00
|
|
|
* faac encodes raw audio to AAC (MPEG-4 part 3) streams.
|
2009-09-05 19:35:19 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
2010-02-16 07:49:05 +00:00
|
|
|
* |[
|
2009-09-05 19:35:19 +00:00
|
|
|
* gst-launch audiotestsrc wave=sine num-buffers=100 ! audioconvert ! faac ! matroskamux ! filesink location=sine.mkv
|
2010-02-16 07:49:05 +00:00
|
|
|
* ]| Encode a sine beep as aac and write to matroska container.
|
2009-09-05 19:35:19 +00:00
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2009-10-02 16:08:21 +00:00
|
|
|
#include <stdlib.h>
|
2006-09-21 13:41:42 +00:00
|
|
|
#include <string.h>
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2010-01-16 12:05:58 +00:00
|
|
|
#include <gst/audio/multichannel.h>
|
2011-05-27 08:11:32 +00:00
|
|
|
#include <gst/pbutils/codec-utils.h>
|
2010-01-16 12:05:58 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
#include "gstfaac.h"
|
2005-10-12 13:54:34 +00:00
|
|
|
|
2011-05-27 08:44:42 +00:00
|
|
|
#define SAMPLE_RATES " 8000, " \
|
|
|
|
"11025, " \
|
|
|
|
"12000, " \
|
|
|
|
"16000, " \
|
|
|
|
"22050, " \
|
|
|
|
"24000, " \
|
|
|
|
"32000, " \
|
|
|
|
"44100, " \
|
|
|
|
"48000, " \
|
|
|
|
"64000, " \
|
|
|
|
"88200, " \
|
|
|
|
"96000"
|
2005-10-12 13:54:34 +00:00
|
|
|
#define SINK_CAPS \
|
|
|
|
"audio/x-raw-int, " \
|
|
|
|
"endianness = (int) BYTE_ORDER, " \
|
|
|
|
"signed = (boolean) true, " \
|
|
|
|
"width = (int) 16, " \
|
|
|
|
"depth = (int) 16, " \
|
2011-05-27 08:44:42 +00:00
|
|
|
"rate = (int) {" SAMPLE_RATES "}, " \
|
2006-08-10 17:09:10 +00:00
|
|
|
"channels = (int) [ 1, 6 ] "
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
|
|
|
|
/* these don't seem to work? */
|
|
|
|
#if 0
|
|
|
|
"audio/x-raw-int, "
|
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"signed = (boolean) true, "
|
|
|
|
"width = (int) 32, "
|
|
|
|
"depth = (int) { 24, 32 }, "
|
|
|
|
"rate = (int) [ 8000, 96000], "
|
|
|
|
"channels = (int) [ 1, 6]; "
|
|
|
|
"audio/x-raw-float, "
|
|
|
|
"endianness = (int) BYTE_ORDER, "
|
|
|
|
"width = (int) 32, "
|
|
|
|
"rate = (int) [ 8000, 96000], " "channels = (int) [ 1, 6]"
|
|
|
|
#endif
|
2005-10-12 13:54:34 +00:00
|
|
|
#define SRC_CAPS \
|
|
|
|
"audio/mpeg, " \
|
2011-05-27 08:11:32 +00:00
|
|
|
"mpegversion = (int) 4, " \
|
2005-10-12 13:54:34 +00:00
|
|
|
"channels = (int) [ 1, 6 ], " \
|
2011-05-27 08:44:42 +00:00
|
|
|
"rate = (int) {" SAMPLE_RATES "}, " \
|
2011-05-27 08:11:32 +00:00
|
|
|
"stream-format = (string) { adts, raw }, " \
|
|
|
|
"base-profile = (string) { main, lc, ssr, ltp }; " \
|
|
|
|
"audio/mpeg, " \
|
|
|
|
"mpegversion = (int) 2, " \
|
|
|
|
"channels = (int) [ 1, 6 ], " \
|
2011-05-27 08:44:42 +00:00
|
|
|
"rate = (int) {" SAMPLE_RATES "}, " \
|
2011-05-27 08:11:32 +00:00
|
|
|
"stream-format = (string) { adts, raw }, " \
|
|
|
|
"profile = (string) { main, lc }"
|
2011-07-09 20:05:07 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
VBR = 1,
|
|
|
|
ABR
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2005-10-12 13:54:34 +00:00
|
|
|
GST_STATIC_CAPS (SRC_CAPS));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2005-10-12 13:54:34 +00:00
|
|
|
GST_STATIC_CAPS (SINK_CAPS));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2011-05-27 07:40:38 +00:00
|
|
|
PROP_0,
|
2011-07-09 20:05:07 +00:00
|
|
|
PROP_QUALITY,
|
2011-05-27 07:40:38 +00:00
|
|
|
PROP_BITRATE,
|
2011-07-09 20:05:07 +00:00
|
|
|
PROP_RATE_CONTROL,
|
2011-05-27 07:40:38 +00:00
|
|
|
PROP_PROFILE,
|
|
|
|
PROP_TNS,
|
|
|
|
PROP_MIDSIDE,
|
|
|
|
PROP_SHORTCTL
|
2003-11-22 12:25:48 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_faac_base_init (GstFaacClass * klass);
|
|
|
|
static void gst_faac_class_init (GstFaacClass * klass);
|
|
|
|
static void gst_faac_init (GstFaac * faac);
|
2009-08-30 21:00:35 +00:00
|
|
|
static void gst_faac_finalize (GObject * object);
|
2009-08-30 21:07:30 +00:00
|
|
|
static void gst_faac_reset (GstFaac * faac);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_faac_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_faac_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
static gboolean gst_faac_sink_event (GstPad * pad, GstEvent * event);
|
2009-08-30 21:06:24 +00:00
|
|
|
static gboolean gst_faac_configure_source_pad (GstFaac * faac);
|
2005-09-01 19:12:44 +00:00
|
|
|
static gboolean gst_faac_sink_setcaps (GstPad * pad, GstCaps * caps);
|
2010-01-16 12:05:58 +00:00
|
|
|
static GstCaps *gst_faac_sink_getcaps (GstPad * pad);
|
2009-08-30 21:06:24 +00:00
|
|
|
static GstFlowReturn gst_faac_push_buffers (GstFaac * faac, gboolean force);
|
2005-09-01 19:12:44 +00:00
|
|
|
static GstFlowReturn gst_faac_chain (GstPad * pad, GstBuffer * data);
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn gst_faac_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-11-15 16:50:18 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (faac_debug);
|
|
|
|
#define GST_CAT_DEFAULT faac_debug
|
|
|
|
|
2009-10-15 12:32:32 +00:00
|
|
|
#define FAAC_DEFAULT_OUTPUTFORMAT 0 /* RAW */
|
2011-07-09 20:05:07 +00:00
|
|
|
#define FAAC_DEFAULT_QUALITY 100
|
2009-10-15 12:32:32 +00:00
|
|
|
#define FAAC_DEFAULT_BITRATE 128 * 1000
|
2011-07-09 20:05:07 +00:00
|
|
|
#define FAAC_DEFAULT_RATE_CONTROL VBR
|
2009-10-15 12:32:32 +00:00
|
|
|
#define FAAC_DEFAULT_TNS FALSE
|
|
|
|
#define FAAC_DEFAULT_MIDSIDE TRUE
|
|
|
|
#define FAAC_DEFAULT_SHORTCTL SHORTCTL_NORMAL
|
2005-11-15 16:50:18 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
GType
|
|
|
|
gst_faac_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_faac_type = 0;
|
|
|
|
|
|
|
|
if (!gst_faac_type) {
|
|
|
|
static const GTypeInfo gst_faac_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstFaacClass),
|
2003-11-22 12:25:48 +00:00
|
|
|
(GBaseInitFunc) gst_faac_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_faac_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstFaac),
|
2003-11-22 12:25:48 +00:00
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_faac_init,
|
|
|
|
};
|
2009-05-04 10:30:26 +00:00
|
|
|
const GInterfaceInfo preset_interface_info = {
|
|
|
|
NULL, /* interface_init */
|
|
|
|
NULL, /* interface_finalize */
|
|
|
|
NULL /* interface_data */
|
|
|
|
};
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
gst_faac_type = g_type_register_static (GST_TYPE_ELEMENT,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstFaac", &gst_faac_info, 0);
|
2009-05-04 10:30:26 +00:00
|
|
|
|
|
|
|
g_type_add_interface_static (gst_faac_type, GST_TYPE_PRESET,
|
|
|
|
&preset_interface_info);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_faac_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_base_init (GstFaacClass * klass)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&src_template));
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2010-03-18 16:30:26 +00:00
|
|
|
gst_element_class_set_details_simple (element_class, "AAC audio encoder",
|
|
|
|
"Codec/Encoder/Audio",
|
|
|
|
"Free MPEG-2/4 AAC encoder",
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
2005-11-15 16:50:18 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (faac_debug, "faac", 0, "AAC encoding");
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 20:05:07 +00:00
|
|
|
#define GST_TYPE_FAAC_RATE_CONTROL (gst_faac_brtype_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_faac_brtype_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_faac_brtype_type = 0;
|
|
|
|
|
|
|
|
if (!gst_faac_brtype_type) {
|
|
|
|
static GEnumValue gst_faac_brtype[] = {
|
|
|
|
{VBR, "VBR", "VBR encoding"},
|
|
|
|
{ABR, "ABR", "ABR encoding"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
gst_faac_brtype_type = g_enum_register_static ("GstFaacBrtype",
|
|
|
|
gst_faac_brtype);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_faac_brtype_type;
|
|
|
|
}
|
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
#define GST_TYPE_FAAC_SHORTCTL (gst_faac_shortctl_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_faac_shortctl_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_faac_shortctl_type = 0;
|
|
|
|
|
|
|
|
if (!gst_faac_shortctl_type) {
|
|
|
|
static GEnumValue gst_faac_shortctl[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{SHORTCTL_NORMAL, "SHORTCTL_NORMAL", "Normal block type"},
|
|
|
|
{SHORTCTL_NOSHORT, "SHORTCTL_NOSHORT", "No short blocks"},
|
|
|
|
{SHORTCTL_NOLONG, "SHORTCTL_NOLONG", "No long blocks"},
|
|
|
|
{0, NULL, NULL},
|
2003-11-22 12:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gst_faac_shortctl_type = g_enum_register_static ("GstFaacShortCtl",
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_faac_shortctl);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gst_faac_shortctl_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_class_init (GstFaacClass * klass)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2005-09-01 19:12:44 +00:00
|
|
|
gobject_class->set_property = gst_faac_set_property;
|
|
|
|
gobject_class->get_property = gst_faac_get_property;
|
2009-08-30 21:00:35 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_faac_finalize);
|
2005-09-01 19:12:44 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
/* properties */
|
2011-07-09 20:05:07 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_QUALITY,
|
|
|
|
g_param_spec_int ("quality", "Quality (%)",
|
|
|
|
"Variable bitrate (VBR) quantizer quality in %", 1, 1000,
|
|
|
|
FAAC_DEFAULT_QUALITY, G_PARAM_READWRITE));
|
2011-05-27 07:40:38 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BITRATE,
|
2011-07-09 20:05:07 +00:00
|
|
|
g_param_spec_int ("bitrate", "Bitrate (bps)",
|
|
|
|
"Average bitrate (ABR) in bits/sec", 8 * 1000, 320 * 1000,
|
|
|
|
FAAC_DEFAULT_BITRATE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_RATE_CONTROL,
|
|
|
|
g_param_spec_enum ("rate-control", "Rate Control (ABR/VBR)",
|
|
|
|
"Encoding bitrate type (VBR/ABR)", GST_TYPE_FAAC_RATE_CONTROL,
|
|
|
|
FAAC_DEFAULT_RATE_CONTROL, G_PARAM_READWRITE));
|
2011-05-27 07:40:38 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TNS,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boolean ("tns", "TNS", "Use temporal noise shaping",
|
2010-10-19 13:23:23 +00:00
|
|
|
FAAC_DEFAULT_TNS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-05-27 07:40:38 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MIDSIDE,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boolean ("midside", "Midside", "Allow mid/side encoding",
|
2010-10-19 13:23:23 +00:00
|
|
|
FAAC_DEFAULT_MIDSIDE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-05-27 07:40:38 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SHORTCTL,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_enum ("shortctl", "Block type",
|
2004-03-15 19:32:27 +00:00
|
|
|
"Block type encorcing",
|
2010-10-19 13:23:23 +00:00
|
|
|
GST_TYPE_FAAC_SHORTCTL, FAAC_DEFAULT_SHORTCTL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2003-11-22 12:25:48 +00:00
|
|
|
|
|
|
|
/* virtual functions */
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_faac_change_state);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_init (GstFaac * faac)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
2007-06-22 10:46:33 +00:00
|
|
|
faac->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
gst_pad_set_chain_function (faac->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_faac_chain));
|
|
|
|
gst_pad_set_setcaps_function (faac->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_faac_sink_setcaps));
|
2010-01-16 12:05:58 +00:00
|
|
|
gst_pad_set_getcaps_function (faac->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_faac_sink_getcaps));
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
gst_pad_set_event_function (faac->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_faac_sink_event));
|
2005-09-01 19:12:44 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (faac), faac->sinkpad);
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2007-06-22 10:46:33 +00:00
|
|
|
faac->srcpad = gst_pad_new_from_static_template (&src_template, "src");
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
gst_pad_use_fixed_caps (faac->srcpad);
|
2003-11-22 12:25:48 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (faac), faac->srcpad);
|
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
faac->adapter = gst_adapter_new ();
|
|
|
|
|
2011-05-27 08:11:32 +00:00
|
|
|
faac->profile = LOW;
|
|
|
|
faac->mpegversion = 4;
|
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
/* default properties */
|
2011-07-09 20:05:07 +00:00
|
|
|
faac->quality = FAAC_DEFAULT_QUALITY;
|
2009-10-15 12:32:32 +00:00
|
|
|
faac->bitrate = FAAC_DEFAULT_BITRATE;
|
2011-07-09 20:05:07 +00:00
|
|
|
faac->brtype = FAAC_DEFAULT_RATE_CONTROL;
|
2009-10-15 12:32:32 +00:00
|
|
|
faac->shortctl = FAAC_DEFAULT_SHORTCTL;
|
|
|
|
faac->outputformat = FAAC_DEFAULT_OUTPUTFORMAT;
|
|
|
|
faac->tns = FAAC_DEFAULT_TNS;
|
|
|
|
faac->midside = FAAC_DEFAULT_MIDSIDE;
|
2009-08-30 21:07:30 +00:00
|
|
|
|
|
|
|
gst_faac_reset (faac);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_faac_reset (GstFaac * faac)
|
|
|
|
{
|
|
|
|
faac->handle = NULL;
|
|
|
|
faac->samplerate = -1;
|
|
|
|
faac->channels = -1;
|
|
|
|
faac->offset = 0;
|
|
|
|
gst_adapter_clear (faac->adapter);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
static void
|
|
|
|
gst_faac_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstFaac *faac = (GstFaac *) object;
|
|
|
|
|
|
|
|
g_object_unref (faac->adapter);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2009-08-30 21:06:24 +00:00
|
|
|
static void
|
|
|
|
gst_faac_close_encoder (GstFaac * faac)
|
|
|
|
{
|
|
|
|
if (faac->handle)
|
|
|
|
faacEncClose (faac->handle);
|
|
|
|
faac->handle = NULL;
|
|
|
|
gst_adapter_clear (faac->adapter);
|
|
|
|
faac->offset = 0;
|
|
|
|
}
|
|
|
|
|
2010-01-16 12:05:58 +00:00
|
|
|
static const GstAudioChannelPosition aac_channel_positions[][8] = {
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
|
2010-01-16 23:32:47 +00:00
|
|
|
{
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
2010-01-16 12:05:58 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
2010-01-16 23:32:47 +00:00
|
|
|
},
|
|
|
|
{
|
2010-01-16 12:05:58 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
2010-01-16 23:32:47 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
2010-01-16 12:05:58 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
2010-01-16 23:32:47 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER},
|
|
|
|
{
|
2010-01-16 12:05:58 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
2010-01-16 23:32:47 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
2010-01-16 12:05:58 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT},
|
2010-01-16 23:32:47 +00:00
|
|
|
{
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
2010-01-16 12:05:58 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
2010-01-16 23:32:47 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_LFE}
|
2010-01-16 12:05:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_faac_sink_getcaps (GstPad * pad)
|
|
|
|
{
|
|
|
|
static volatile gsize sinkcaps = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&sinkcaps)) {
|
|
|
|
GstCaps *tmp = gst_caps_new_empty ();
|
|
|
|
GstStructure *s, *t;
|
|
|
|
gint i, c;
|
2011-05-27 08:44:42 +00:00
|
|
|
static const int rates[] = {
|
|
|
|
8000, 11025, 12000, 16000, 22050, 24000,
|
|
|
|
32000, 44100, 48000, 64000, 88200, 96000
|
|
|
|
};
|
|
|
|
GValue rates_arr = { 0, };
|
|
|
|
GValue tmp_v = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&rates_arr, GST_TYPE_LIST);
|
|
|
|
g_value_init (&tmp_v, G_TYPE_INT);
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (rates); i++) {
|
|
|
|
g_value_set_int (&tmp_v, rates[i]);
|
|
|
|
gst_value_list_append_value (&rates_arr, &tmp_v);
|
|
|
|
}
|
|
|
|
g_value_unset (&tmp_v);
|
2010-01-16 12:05:58 +00:00
|
|
|
|
|
|
|
s = gst_structure_new ("audio/x-raw-int",
|
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
2011-05-27 08:44:42 +00:00
|
|
|
"width", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16, NULL);
|
|
|
|
gst_structure_set_value (s, "rate", &rates_arr);
|
2010-01-16 12:05:58 +00:00
|
|
|
|
|
|
|
for (i = 1; i <= 6; i++) {
|
|
|
|
GValue chanpos = { 0 };
|
|
|
|
GValue pos = { 0 };
|
|
|
|
|
|
|
|
t = gst_structure_copy (s);
|
|
|
|
|
|
|
|
gst_structure_set (t, "channels", G_TYPE_INT, i, NULL);
|
|
|
|
|
|
|
|
g_value_init (&chanpos, GST_TYPE_ARRAY);
|
|
|
|
g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
|
|
|
|
|
|
|
|
for (c = 0; c < i; c++) {
|
|
|
|
g_value_set_enum (&pos, aac_channel_positions[i - 1][c]);
|
|
|
|
gst_value_array_append_value (&chanpos, &pos);
|
|
|
|
}
|
|
|
|
g_value_unset (&pos);
|
|
|
|
|
|
|
|
gst_structure_set_value (t, "channel-positions", &chanpos);
|
|
|
|
g_value_unset (&chanpos);
|
|
|
|
gst_caps_append_structure (tmp, t);
|
|
|
|
}
|
|
|
|
gst_structure_free (s);
|
2011-05-27 08:44:42 +00:00
|
|
|
g_value_unset (&rates_arr);
|
2010-01-16 12:05:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "Generated sinkcaps: %" GST_PTR_FORMAT, tmp);
|
|
|
|
|
|
|
|
g_once_init_leave (&sinkcaps, (gsize) tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_caps_ref ((GstCaps *) sinkcaps);
|
|
|
|
}
|
|
|
|
|
2011-04-15 09:19:20 +00:00
|
|
|
/* check downstream caps to configure format */
|
|
|
|
static void
|
|
|
|
gst_faac_negotiate (GstFaac * faac)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_pad_get_allowed_caps (faac->srcpad);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (faac, "allowed caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
if (caps && gst_caps_get_size (caps) > 0) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (caps, 0);
|
|
|
|
const gchar *str = NULL;
|
2011-05-27 08:11:32 +00:00
|
|
|
gint i = 4;
|
2011-04-15 09:19:20 +00:00
|
|
|
|
|
|
|
if ((str = gst_structure_get_string (s, "stream-format"))) {
|
|
|
|
if (strcmp (str, "adts") == 0) {
|
|
|
|
GST_DEBUG_OBJECT (faac, "use ADTS format for output");
|
|
|
|
faac->outputformat = 1;
|
|
|
|
} else if (strcmp (str, "raw") == 0) {
|
|
|
|
GST_DEBUG_OBJECT (faac, "use RAW format for output");
|
|
|
|
faac->outputformat = 0;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (faac, "unknown stream-format: %s", str);
|
|
|
|
faac->outputformat = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-05-27 08:11:32 +00:00
|
|
|
|
|
|
|
if ((str = gst_structure_get_string (s, "profile"))) {
|
|
|
|
if (strcmp (str, "main") == 0) {
|
|
|
|
faac->profile = MAIN;
|
|
|
|
} else if (strcmp (str, "lc") == 0) {
|
|
|
|
faac->profile = LOW;
|
|
|
|
} else if (strcmp (str, "ssr") == 0) {
|
|
|
|
faac->profile = SSR;
|
|
|
|
} else if (strcmp (str, "ltp") == 0) {
|
|
|
|
faac->profile = LTP;
|
|
|
|
} else {
|
|
|
|
faac->profile = LOW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_get_int (s, "mpegversion", &i) || i == 4) {
|
|
|
|
faac->mpegversion = 4;
|
|
|
|
} else {
|
|
|
|
faac->mpegversion = 2;
|
|
|
|
}
|
2011-04-15 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (caps)
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
2005-09-01 19:12:44 +00:00
|
|
|
static gboolean
|
|
|
|
gst_faac_sink_setcaps (GstPad * pad, GstCaps * caps)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad));
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
|
|
|
faacEncHandle *handle;
|
2005-10-12 13:54:34 +00:00
|
|
|
gint channels, samplerate, width;
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
gulong samples, bytes, fmt = 0, bps = 0;
|
2005-10-12 12:53:07 +00:00
|
|
|
gboolean result = FALSE;
|
2003-11-22 12:25:48 +00:00
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
if (!gst_caps_is_fixed (caps))
|
2009-08-30 21:06:24 +00:00
|
|
|
goto refuse_caps;
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2005-10-12 13:54:34 +00:00
|
|
|
if (!gst_structure_get_int (structure, "channels", &channels) ||
|
|
|
|
!gst_structure_get_int (structure, "rate", &samplerate)) {
|
2009-08-30 21:06:24 +00:00
|
|
|
goto refuse_caps;
|
2005-10-12 13:54:34 +00:00
|
|
|
}
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
|
2005-10-12 13:54:34 +00:00
|
|
|
if (gst_structure_has_name (structure, "audio/x-raw-int")) {
|
|
|
|
gst_structure_get_int (structure, "width", &width);
|
|
|
|
switch (width) {
|
|
|
|
case 16:
|
|
|
|
fmt = FAAC_INPUT_16BIT;
|
|
|
|
bps = 2;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
case 32:
|
|
|
|
fmt = FAAC_INPUT_32BIT;
|
|
|
|
bps = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
}
|
|
|
|
} else if (gst_structure_has_name (structure, "audio/x-raw-float")) {
|
|
|
|
fmt = FAAC_INPUT_FLOAT;
|
|
|
|
bps = 4;
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
}
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2009-08-30 21:06:24 +00:00
|
|
|
if (!fmt)
|
|
|
|
goto refuse_caps;
|
|
|
|
|
|
|
|
/* If the encoder is initialized, do not
|
|
|
|
reinitialize it again if not necessary */
|
|
|
|
if (faac->handle) {
|
|
|
|
if (samplerate == faac->samplerate && channels == faac->channels &&
|
|
|
|
fmt == faac->format)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* clear out pending frames */
|
|
|
|
gst_faac_push_buffers (faac, TRUE);
|
|
|
|
|
|
|
|
gst_faac_close_encoder (faac);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 21:06:24 +00:00
|
|
|
if (!(handle = faacEncOpen (samplerate, channels, &samples, &bytes)))
|
|
|
|
goto setup_failed;
|
|
|
|
|
|
|
|
/* ok, record and set up */
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
faac->format = fmt;
|
|
|
|
faac->bps = bps;
|
|
|
|
faac->handle = handle;
|
|
|
|
faac->bytes = bytes;
|
|
|
|
faac->samples = samples;
|
|
|
|
faac->channels = channels;
|
|
|
|
faac->samplerate = samplerate;
|
|
|
|
|
2011-04-15 09:19:20 +00:00
|
|
|
gst_faac_negotiate (faac);
|
|
|
|
|
2009-08-30 21:06:24 +00:00
|
|
|
/* finish up */
|
|
|
|
result = gst_faac_configure_source_pad (faac);
|
2005-10-12 12:53:07 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
gst_object_unref (faac);
|
|
|
|
return result;
|
2009-08-30 21:06:24 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
setup_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (faac, LIBRARY, SETTINGS, (NULL), (NULL));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
refuse_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (faac, "refused caps %" GST_PTR_FORMAT, caps);
|
|
|
|
goto done;
|
|
|
|
}
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 19:12:44 +00:00
|
|
|
static gboolean
|
2005-11-15 16:50:18 +00:00
|
|
|
gst_faac_configure_source_pad (GstFaac * faac)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
2006-09-21 13:41:42 +00:00
|
|
|
GstCaps *srccaps;
|
2005-11-15 16:50:18 +00:00
|
|
|
gboolean ret = FALSE;
|
2006-09-21 13:41:42 +00:00
|
|
|
faacEncConfiguration *conf;
|
2008-10-03 17:11:12 +00:00
|
|
|
guint maxbitrate;
|
2005-11-15 16:50:18 +00:00
|
|
|
|
2006-09-21 13:41:42 +00:00
|
|
|
/* we negotiated caps update current configuration */
|
|
|
|
conf = faacEncGetCurrentConfiguration (faac->handle);
|
2011-05-27 08:11:32 +00:00
|
|
|
conf->mpegVersion = (faac->mpegversion == 4) ? MPEG4 : MPEG2;
|
2006-09-21 13:41:42 +00:00
|
|
|
conf->aacObjectType = faac->profile;
|
|
|
|
conf->allowMidside = faac->midside;
|
|
|
|
conf->useLfe = 0;
|
|
|
|
conf->useTns = faac->tns;
|
2011-07-09 20:05:07 +00:00
|
|
|
|
|
|
|
if (faac->brtype == VBR) {
|
|
|
|
conf->quantqual = faac->quality;
|
|
|
|
} else if (faac->brtype == ABR) {
|
|
|
|
conf->bitRate = faac->bitrate / faac->channels;
|
|
|
|
}
|
|
|
|
|
2006-09-21 13:41:42 +00:00
|
|
|
conf->inputFormat = faac->format;
|
|
|
|
conf->outputFormat = faac->outputformat;
|
|
|
|
conf->shortctl = faac->shortctl;
|
2008-10-03 17:11:12 +00:00
|
|
|
|
|
|
|
/* check, warn and correct if the max bitrate for the given samplerate is
|
|
|
|
* exceeded. Maximum of 6144 bit for a channel */
|
|
|
|
maxbitrate =
|
|
|
|
(unsigned int) (6144.0 * (double) faac->samplerate / (double) 1024.0 +
|
|
|
|
.5);
|
|
|
|
if (conf->bitRate > maxbitrate) {
|
|
|
|
GST_ELEMENT_WARNING (faac, RESOURCE, SETTINGS, (NULL),
|
2009-01-02 01:44:11 +00:00
|
|
|
("bitrate %lu exceeds maximum allowed bitrate of %u for samplerate %d. "
|
2008-10-03 17:11:12 +00:00
|
|
|
"Setting bitrate to %u", conf->bitRate, maxbitrate,
|
|
|
|
faac->samplerate, maxbitrate));
|
|
|
|
conf->bitRate = maxbitrate;
|
|
|
|
}
|
|
|
|
|
2010-01-12 18:33:37 +00:00
|
|
|
/* default 0 to start with, libfaac chooses based on bitrate */
|
|
|
|
conf->bandWidth = 0;
|
|
|
|
|
2006-09-21 13:41:42 +00:00
|
|
|
if (!faacEncSetConfiguration (faac->handle, conf))
|
|
|
|
goto set_failed;
|
|
|
|
|
2010-01-12 18:33:37 +00:00
|
|
|
/* let's see what really happened,
|
|
|
|
* note that this may not really match desired rate */
|
2010-01-22 09:48:26 +00:00
|
|
|
GST_DEBUG_OBJECT (faac, "average bitrate: %lu kbps",
|
2010-01-12 18:33:37 +00:00
|
|
|
(conf->bitRate + 500) / 1000 * faac->channels);
|
|
|
|
GST_DEBUG_OBJECT (faac, "quantization quality: %ld", conf->quantqual);
|
|
|
|
GST_DEBUG_OBJECT (faac, "bandwidth: %d Hz", conf->bandWidth);
|
|
|
|
|
2006-09-21 13:41:42 +00:00
|
|
|
/* now create a caps for it all */
|
|
|
|
srccaps = gst_caps_new_simple ("audio/mpeg",
|
2011-05-27 08:11:32 +00:00
|
|
|
"mpegversion", G_TYPE_INT, faac->mpegversion,
|
2005-11-15 16:50:18 +00:00
|
|
|
"channels", G_TYPE_INT, faac->channels,
|
2010-01-11 12:48:34 +00:00
|
|
|
"rate", G_TYPE_INT, faac->samplerate,
|
2010-01-11 16:13:41 +00:00
|
|
|
"stream-format", G_TYPE_STRING, (faac->outputformat ? "adts" : "raw"),
|
2010-01-11 12:48:34 +00:00
|
|
|
NULL);
|
2005-11-15 16:50:18 +00:00
|
|
|
|
2011-05-27 08:11:32 +00:00
|
|
|
/* DecoderSpecificInfo is only available for mpegversion=4 */
|
|
|
|
if (faac->mpegversion == 4) {
|
2006-09-21 13:41:42 +00:00
|
|
|
guint8 *config = NULL;
|
|
|
|
gulong config_len = 0;
|
|
|
|
|
|
|
|
/* get the config string */
|
|
|
|
GST_DEBUG_OBJECT (faac, "retrieving decoder info");
|
|
|
|
faacEncGetDecoderSpecificInfo (faac->handle, &config, &config_len);
|
|
|
|
|
2011-05-27 08:11:32 +00:00
|
|
|
if (!gst_codec_utils_aac_caps_set_level_and_profile (srccaps, config,
|
|
|
|
config_len)) {
|
|
|
|
free (config);
|
|
|
|
gst_caps_unref (srccaps);
|
|
|
|
goto invalid_codec_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!faac->outputformat) {
|
|
|
|
GstBuffer *codec_data;
|
|
|
|
|
|
|
|
/* copy it into a buffer */
|
|
|
|
codec_data = gst_buffer_new_and_alloc (config_len);
|
|
|
|
memcpy (GST_BUFFER_DATA (codec_data), config, config_len);
|
|
|
|
|
|
|
|
/* add to caps */
|
|
|
|
gst_caps_set_simple (srccaps,
|
|
|
|
"codec_data", GST_TYPE_BUFFER, codec_data, NULL);
|
|
|
|
|
|
|
|
gst_buffer_unref (codec_data);
|
|
|
|
}
|
2006-09-21 13:41:42 +00:00
|
|
|
|
2011-05-27 08:11:32 +00:00
|
|
|
free (config);
|
|
|
|
} else {
|
|
|
|
const gchar *profile;
|
2006-09-21 13:41:42 +00:00
|
|
|
|
2011-05-27 08:11:32 +00:00
|
|
|
/* Add least add the profile to the caps */
|
|
|
|
switch (faac->profile) {
|
|
|
|
case MAIN:
|
|
|
|
profile = "main";
|
|
|
|
break;
|
|
|
|
case LTP:
|
|
|
|
profile = "ltp";
|
|
|
|
break;
|
|
|
|
case SSR:
|
|
|
|
profile = "ssr";
|
|
|
|
break;
|
|
|
|
case LOW:
|
|
|
|
default:
|
|
|
|
profile = "lc";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_caps_set_simple (srccaps, "profile", G_TYPE_STRING, profile, NULL);
|
|
|
|
/* FIXME: How to get the profile for mpegversion==2? */
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2006-09-21 13:41:42 +00:00
|
|
|
GST_DEBUG_OBJECT (faac, "src pad caps: %" GST_PTR_FORMAT, srccaps);
|
2005-11-15 16:50:18 +00:00
|
|
|
|
2006-09-21 13:41:42 +00:00
|
|
|
ret = gst_pad_set_caps (faac->srcpad, srccaps);
|
|
|
|
gst_caps_unref (srccaps);
|
2005-11-15 16:50:18 +00:00
|
|
|
|
|
|
|
return ret;
|
2006-09-21 13:41:42 +00:00
|
|
|
|
|
|
|
/* ERROR */
|
2011-05-27 08:11:32 +00:00
|
|
|
set_failed:
|
2006-09-21 13:41:42 +00:00
|
|
|
{
|
2011-05-27 08:11:32 +00:00
|
|
|
GST_WARNING_OBJECT (faac, "Faac doesn't support the current configuration");
|
2006-09-21 13:41:42 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-05-27 08:11:32 +00:00
|
|
|
invalid_codec_data:
|
2006-09-21 13:41:42 +00:00
|
|
|
{
|
2011-05-27 08:11:32 +00:00
|
|
|
GST_ERROR_OBJECT (faac, "Invalid codec data");
|
2006-09-21 13:41:42 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_faac_push_buffers (GstFaac * faac, gboolean force)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
gint av, frame_size, size, ret_size;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
guint64 timestamp, distance;
|
|
|
|
const guint8 *data;
|
|
|
|
|
|
|
|
/* samples already considers channel count */
|
|
|
|
frame_size = faac->samples * faac->bps;
|
|
|
|
|
2009-09-06 09:49:17 +00:00
|
|
|
while (G_LIKELY (ret == GST_FLOW_OK)) {
|
2009-08-30 21:00:35 +00:00
|
|
|
|
|
|
|
av = gst_adapter_available (faac->adapter);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (faac, "pushing: force: %d, frame_size: %d, av: %d, "
|
|
|
|
"offset: %d", force, frame_size, av, faac->offset);
|
|
|
|
|
|
|
|
/* idea:
|
|
|
|
* - start of adapter corresponds with what has already been encoded
|
|
|
|
* (i.e. really returned by faac)
|
|
|
|
* - start + offset is what needs to be fed to faac next
|
|
|
|
* That way we can timestamp the output based
|
|
|
|
* on adapter provided timestamp (and duration is a fixed frame duration) */
|
|
|
|
|
|
|
|
/* not enough data for one frame and no flush forcing */
|
|
|
|
if (!force && (av < frame_size + faac->offset))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (G_LIKELY (av - faac->offset >= frame_size)) {
|
|
|
|
GST_LOG_OBJECT (faac, "encoding a frame");
|
|
|
|
data = gst_adapter_peek (faac->adapter, faac->offset + frame_size);
|
|
|
|
data += faac->offset;
|
|
|
|
size = frame_size;
|
|
|
|
} else if (av - faac->offset > 0) {
|
|
|
|
GST_LOG_OBJECT (faac, "encoding leftover");
|
|
|
|
data = gst_adapter_peek (faac->adapter, av);
|
|
|
|
data += faac->offset;
|
|
|
|
size = av - faac->offset;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (faac, "emptying encoder");
|
|
|
|
data = NULL;
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
outbuf = gst_buffer_new_and_alloc (faac->bytes);
|
|
|
|
|
2009-09-06 09:49:17 +00:00
|
|
|
if (G_UNLIKELY ((ret_size = faacEncEncode (faac->handle, (gint32 *) data,
|
|
|
|
size / faac->bps, GST_BUFFER_DATA (outbuf),
|
|
|
|
faac->bytes)) < 0)) {
|
2009-08-30 21:00:35 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
goto encode_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (faac, "encoder return: %d", ret_size);
|
|
|
|
|
|
|
|
/* consumed, advanced view */
|
|
|
|
faac->offset += size;
|
|
|
|
g_assert (faac->offset <= av);
|
|
|
|
|
2009-09-06 09:49:17 +00:00
|
|
|
if (G_UNLIKELY (!ret_size)) {
|
2009-08-30 21:00:35 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
if (size)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-10-11 15:05:28 +00:00
|
|
|
/* deal with encoder lead-out */
|
2009-09-06 09:44:27 +00:00
|
|
|
if (G_UNLIKELY (av == 0 && faac->offset == 0)) {
|
2010-10-11 15:05:28 +00:00
|
|
|
GST_DEBUG_OBJECT (faac, "encoder returned additional data");
|
|
|
|
/* continuous with previous output, ok to have 0 duration */
|
|
|
|
timestamp = faac->next_ts;
|
|
|
|
} else {
|
|
|
|
/* after some caching, finally some data */
|
|
|
|
/* adapter gives time */
|
|
|
|
timestamp = gst_adapter_prev_timestamp (faac->adapter, &distance);
|
2009-09-06 09:44:27 +00:00
|
|
|
}
|
|
|
|
|
2009-09-06 09:49:17 +00:00
|
|
|
if (G_LIKELY ((av = gst_adapter_available (faac->adapter)) >= frame_size)) {
|
2009-08-30 21:00:35 +00:00
|
|
|
/* must have then come from a complete frame */
|
|
|
|
gst_adapter_flush (faac->adapter, frame_size);
|
|
|
|
faac->offset -= frame_size;
|
|
|
|
size = frame_size;
|
|
|
|
} else {
|
|
|
|
/* otherwise leftover */
|
|
|
|
gst_adapter_clear (faac->adapter);
|
|
|
|
faac->offset = 0;
|
|
|
|
size = av;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (outbuf) = ret_size;
|
2009-09-06 09:49:17 +00:00
|
|
|
if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (timestamp)))
|
2009-08-30 21:00:35 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = timestamp +
|
|
|
|
GST_FRAMES_TO_CLOCK_TIME (distance / faac->channels / faac->bps,
|
|
|
|
faac->samplerate);
|
|
|
|
GST_BUFFER_DURATION (outbuf) =
|
|
|
|
GST_FRAMES_TO_CLOCK_TIME (size / faac->channels / faac->bps,
|
|
|
|
faac->samplerate);
|
2010-10-11 15:05:28 +00:00
|
|
|
faac->next_ts =
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) + GST_BUFFER_DURATION (outbuf);
|
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
/* perhaps check/set DISCONT based on timestamps ? */
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (faac, "Pushing out buffer time: %" GST_TIME_FORMAT
|
|
|
|
" duration: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)));
|
|
|
|
|
|
|
|
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (faac->srcpad));
|
|
|
|
ret = gst_pad_push (faac->srcpad, outbuf);
|
|
|
|
}
|
|
|
|
|
2009-09-06 09:44:27 +00:00
|
|
|
/* in case encoder returns less than expected, clear our view as well */
|
|
|
|
if (G_UNLIKELY (force)) {
|
2009-09-08 20:24:12 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if ((av = gst_adapter_available (faac->adapter)))
|
|
|
|
GST_WARNING_OBJECT (faac, "encoder left %d bytes; discarding", av);
|
|
|
|
#endif
|
2009-09-06 09:44:27 +00:00
|
|
|
gst_adapter_clear (faac->adapter);
|
|
|
|
faac->offset = 0;
|
|
|
|
}
|
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
encode_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (faac, LIBRARY, ENCODE, (NULL), (NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
static gboolean
|
|
|
|
gst_faac_sink_event (GstPad * pad, GstEvent * event)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
GstFaac *faac;
|
|
|
|
gboolean ret;
|
2003-11-22 12:25:48 +00:00
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
faac = GST_FAAC (gst_pad_get_parent (pad));
|
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
GST_LOG_OBJECT (faac, "received %s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
{
|
2009-08-30 21:00:35 +00:00
|
|
|
if (faac->handle) {
|
|
|
|
/* flush first */
|
|
|
|
GST_DEBUG_OBJECT (faac, "Pushing out remaining buffers because of EOS");
|
|
|
|
gst_faac_push_buffers (faac, TRUE);
|
2007-11-21 09:45:41 +00:00
|
|
|
}
|
2009-08-30 21:00:35 +00:00
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
ret = gst_pad_event_default (pad, event);
|
|
|
|
break;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
default:
|
|
|
|
ret = gst_pad_event_default (pad, event);
|
|
|
|
break;
|
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
gst_object_unref (faac);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_faac_chain (GstPad * pad, GstBuffer * inbuf)
|
|
|
|
{
|
|
|
|
GstFlowReturn result = GST_FLOW_OK;
|
|
|
|
GstFaac *faac;
|
2003-11-22 12:25:48 +00:00
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
faac = GST_FAAC (gst_pad_get_parent (pad));
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2006-09-21 13:41:42 +00:00
|
|
|
if (!faac->handle)
|
|
|
|
goto no_handle;
|
2003-11-22 12:25:48 +00:00
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
GST_LOG_OBJECT (faac, "Got buffer time: %" GST_TIME_FORMAT " duration: %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (inbuf)),
|
2008-08-29 11:36:41 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf)));
|
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
gst_adapter_push (faac->adapter, inbuf);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2009-08-30 21:00:35 +00:00
|
|
|
result = gst_faac_push_buffers (faac, FALSE);
|
2005-09-01 19:12:44 +00:00
|
|
|
|
2005-10-12 12:53:07 +00:00
|
|
|
done:
|
|
|
|
gst_object_unref (faac);
|
2006-09-21 13:41:42 +00:00
|
|
|
|
2005-09-01 19:12:44 +00:00
|
|
|
return result;
|
2006-09-21 13:41:42 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_handle:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (faac, CORE, NEGOTIATION, (NULL),
|
|
|
|
("format wasn't negotiated before chain function"));
|
|
|
|
gst_buffer_unref (inbuf);
|
|
|
|
result = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (object);
|
|
|
|
|
2005-11-21 16:37:18 +00:00
|
|
|
GST_OBJECT_LOCK (faac);
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
switch (prop_id) {
|
2011-07-09 20:05:07 +00:00
|
|
|
case PROP_QUALITY:
|
|
|
|
faac->quality = g_value_get_int (value);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_BITRATE:
|
2003-11-22 12:25:48 +00:00
|
|
|
faac->bitrate = g_value_get_int (value);
|
|
|
|
break;
|
2011-07-09 20:05:07 +00:00
|
|
|
case PROP_RATE_CONTROL:
|
|
|
|
faac->brtype = g_value_get_enum (value);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_TNS:
|
2003-11-22 12:25:48 +00:00
|
|
|
faac->tns = g_value_get_boolean (value);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_MIDSIDE:
|
2003-11-22 12:25:48 +00:00
|
|
|
faac->midside = g_value_get_boolean (value);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_SHORTCTL:
|
2003-11-22 12:25:48 +00:00
|
|
|
faac->shortctl = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
|
2005-11-21 16:37:18 +00:00
|
|
|
GST_OBJECT_UNLOCK (faac);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_faac_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
|
|
|
GstFaac *faac = GST_FAAC (object);
|
|
|
|
|
2005-11-21 16:37:18 +00:00
|
|
|
GST_OBJECT_LOCK (faac);
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
|
2003-11-22 12:25:48 +00:00
|
|
|
switch (prop_id) {
|
2011-07-09 20:05:07 +00:00
|
|
|
case PROP_QUALITY:
|
|
|
|
g_value_set_int (value, faac->quality);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_BITRATE:
|
2003-11-22 12:25:48 +00:00
|
|
|
g_value_set_int (value, faac->bitrate);
|
|
|
|
break;
|
2011-07-09 20:05:07 +00:00
|
|
|
case PROP_RATE_CONTROL:
|
|
|
|
g_value_set_enum (value, faac->brtype);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_TNS:
|
2003-11-22 12:25:48 +00:00
|
|
|
g_value_set_boolean (value, faac->tns);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_MIDSIDE:
|
2003-11-22 12:25:48 +00:00
|
|
|
g_value_set_boolean (value, faac->midside);
|
|
|
|
break;
|
2011-05-27 07:40:38 +00:00
|
|
|
case PROP_SHORTCTL:
|
2003-11-22 12:25:48 +00:00
|
|
|
g_value_set_enum (value, faac->shortctl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
|
2005-11-21 16:37:18 +00:00
|
|
|
GST_OBJECT_UNLOCK (faac);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_faac_change_state (GstElement * element, GstStateChange transition)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2003-11-22 12:25:48 +00:00
|
|
|
GstFaac *faac = GST_FAAC (element);
|
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
/* upwards state changes */
|
|
|
|
switch (transition) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
/* downwards state changes */
|
2005-09-05 17:20:29 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
{
|
2009-08-30 21:07:30 +00:00
|
|
|
gst_faac_close_encoder (faac);
|
|
|
|
gst_faac_reset (faac);
|
2003-11-22 12:25:48 +00:00
|
|
|
break;
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
}
|
2003-11-22 12:25:48 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
ext/faac/gstfaac.c: Gst09-ize code a little bit more: use gst_pad_alloc_buffer(), move event handling from chain func...
Original commit message from CVS:
* ext/faac/gstfaac.c: (gst_faac_class_init), (gst_faac_init),
(gst_faac_sink_setcaps), (gst_faac_src_setcaps),
(gst_faac_sink_event), (gst_faac_chain), (gst_faac_set_property),
(gst_faac_get_property), (gst_faac_change_state):
Gst09-ize code a little bit more: use gst_pad_alloc_buffer(),
move event handling from chain function into an event function,
add some locks here and there, do some cleanups; disable 32-bit
integer and float input formats until we're sure that those
actually work (couldn't play back the produced files with
anything).
2005-10-13 11:37:39 +00:00
|
|
|
return ret;
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2003-11-22 12:25:48 +00:00
|
|
|
{
|
2009-05-07 16:53:42 +00:00
|
|
|
return gst_element_register (plugin, "faac", GST_RANK_SECONDARY,
|
|
|
|
GST_TYPE_FAAC);
|
2003-11-22 12:25:48 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"faac",
|
|
|
|
"Free AAC Encoder (FAAC)",
|
2006-04-01 10:09:11 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|