Faac (AAC Encoder) ported for GStreamer 0.9

Original commit message from CVS:
Faac (AAC Encoder) ported for GStreamer 0.9
This commit is contained in:
Flavio Oliveira 2005-09-01 19:12:44 +00:00
parent e05ab72ace
commit ea6821e293
6 changed files with 67 additions and 55 deletions

View file

@ -1,3 +1,10 @@
2005-08-31 Flavio Oliveira <flavio.oliveira@indt.org.br>
* configure.ac:
* ext/Makefile.am:
* ext/faac/Makefile.am:
* ext/faac/gstfaac.c: Ported to GStreamer 0.9.
2005-08-31 Thomas Vander Stichele <thomas at apestaart dot org> 2005-08-31 Thomas Vander Stichele <thomas at apestaart dot org>
* configure.ac: * configure.ac:

2
common

@ -1 +1 @@
Subproject commit 74223ba3ec3be64622ac71d682b36c1f8f01350e Subproject commit b0ee0e4262014001faceb47d71c3a44c75ab86b4

View file

@ -322,6 +322,14 @@ dnl ###########################
dnl # Configure external libs # dnl # Configure external libs #
dnl ########################### dnl ###########################
dnl **** Free AAC Encoder (FAAC) ****
translit(dnm, m, l) AM_CONDITIONAL(USE_FAAC, true)
GST_CHECK_FEATURE(FAAC, [AAC encoder plug-in], faac, [
GST_CHECK_LIBHEADER(FAAC, faac, faacEncOpen, -lm, faac.h, FAAC_LIBS="-lfaac -lm")
AS_SCRUB_INCLUDE(FAAC_CFLAGS)
AC_SUBST(FAAC_LIBS)
])
dnl **** Free AAC Decoder (FAAD) **** dnl **** Free AAC Decoder (FAAD) ****
translit(dnm, m, l) AM_CONDITIONAL(USE_FAAD, true) translit(dnm, m, l) AM_CONDITIONAL(USE_FAAD, true)
GST_CHECK_FEATURE(FAAD, [AAC decoder plug-in], faad, [ GST_CHECK_FEATURE(FAAD, [AAC decoder plug-in], faad, [
@ -414,6 +422,7 @@ gst/Makefile
gst/qtdemux/Makefile gst/qtdemux/Makefile
sys/Makefile sys/Makefile
ext/Makefile ext/Makefile
ext/faac/Makefile
ext/faad/Makefile ext/faad/Makefile
common/Makefile common/Makefile
common/m4/Makefile common/m4/Makefile

View file

@ -58,11 +58,11 @@ DIVX_DIR=
DTS_DIR= DTS_DIR=
# endif # endif
# if USE_FAAC if USE_FAAC
# FAAC_DIR=faac FAAC_DIR=faac
# else else
FAAC_DIR= FAAC_DIR=
# endif endif
if USE_FAAD if USE_FAAD
FAAD_DIR=faad FAAD_DIR=faad
@ -259,6 +259,7 @@ SUBDIRS=\
DIST_SUBDIRS=\ DIST_SUBDIRS=\
amrnb \ amrnb \
faac \
faad \ faad \
lame \ lame \
mad \ mad \

View file

@ -1,8 +1,9 @@
plugin_LTLIBRARIES = libgstfaac.la plugin_LTLIBRARIES = libgstfaac.la
libgstfaac_la_SOURCES = gstfaac.c libgstfaac_la_SOURCES = gstfaac.c
libgstfaac_la_CFLAGS = $(FAAC_CFLAGS) $(GST_CFLAGS) libgstfaac_la_CFLAGS = $(FAAC_CFLAGS) $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
libgstfaac_la_LIBADD = $(FAAC_LIBS) libgstfaac_la_LIBADD = $(FAAC_LIBS) $(GST_PLUGINS_BASE_LIBS) \
-lgstaudio-@GST_MAJORMINOR@
libgstfaac_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstfaac_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstfaac.h noinst_HEADERS = gstfaac.h

View file

@ -59,11 +59,9 @@ static void gst_faac_set_property (GObject * object,
static void gst_faac_get_property (GObject * object, static void gst_faac_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec); guint prop_id, GValue * value, GParamSpec * pspec);
static GstPadLinkReturn static gboolean gst_faac_sink_setcaps (GstPad * pad, GstCaps * caps);
gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps); static gboolean gst_faac_src_setcaps (GstPad * pad, GstCaps * caps);
static GstPadLinkReturn static GstFlowReturn gst_faac_chain (GstPad * pad, GstBuffer * data);
gst_faac_srcconnect (GstPad * pad, const GstCaps * caps);
static void gst_faac_chain (GstPad * pad, GstData * data);
static GstElementStateReturn gst_faac_change_state (GstElement * element); static GstElementStateReturn gst_faac_change_state (GstElement * element);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -185,6 +183,9 @@ gst_faac_class_init (GstFaacClass * klass)
parent_class = g_type_class_ref (GST_TYPE_ELEMENT); parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property = gst_faac_set_property;
gobject_class->get_property = gst_faac_get_property;
/* properties */ /* properties */
g_object_class_install_property (gobject_class, ARG_BITRATE, g_object_class_install_property (gobject_class, ARG_BITRATE,
g_param_spec_int ("bitrate", "Bitrate (bps)", "Bitrate in bits/sec", g_param_spec_int ("bitrate", "Bitrate (bps)", "Bitrate in bits/sec",
@ -209,9 +210,6 @@ gst_faac_class_init (GstFaacClass * klass)
/* virtual functions */ /* virtual functions */
gstelement_class->change_state = gst_faac_change_state; gstelement_class->change_state = gst_faac_change_state;
gobject_class->set_property = gst_faac_set_property;
gobject_class->get_property = gst_faac_get_property;
} }
static void static void
@ -224,20 +222,18 @@ gst_faac_init (GstFaac * faac)
faac->cache_time = GST_CLOCK_TIME_NONE; faac->cache_time = GST_CLOCK_TIME_NONE;
faac->cache_duration = 0; faac->cache_duration = 0;
GST_FLAG_SET (faac, GST_ELEMENT_EVENT_AWARE);
faac->sinkpad = faac->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get (&sink_template), gst_pad_new_from_template (gst_static_pad_template_get (&sink_template),
"sink"); "sink");
gst_element_add_pad (GST_ELEMENT (faac), faac->sinkpad);
gst_pad_set_chain_function (faac->sinkpad, gst_faac_chain); gst_pad_set_chain_function (faac->sinkpad, gst_faac_chain);
gst_pad_set_link_function (faac->sinkpad, gst_faac_sinkconnect); gst_pad_set_setcaps_function (faac->sinkpad, gst_faac_sink_setcaps);
gst_element_add_pad (GST_ELEMENT (faac), faac->sinkpad);
faac->srcpad = faac->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get (&src_template), gst_pad_new_from_template (gst_static_pad_template_get (&src_template),
"src"); "src");
gst_pad_set_setcaps_function (faac->srcpad, gst_faac_src_setcaps);
gst_element_add_pad (GST_ELEMENT (faac), faac->srcpad); gst_element_add_pad (GST_ELEMENT (faac), faac->srcpad);
gst_pad_set_link_function (faac->srcpad, gst_faac_srcconnect);
/* default properties */ /* default properties */
faac->bitrate = 1024 * 128; faac->bitrate = 1024 * 128;
@ -248,8 +244,8 @@ gst_faac_init (GstFaac * faac)
faac->midside = TRUE; faac->midside = TRUE;
} }
static GstPadLinkReturn static gboolean
gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps) gst_faac_sink_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad)); GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad));
GstStructure *structure = gst_caps_get_structure (caps, 0); GstStructure *structure = gst_caps_get_structure (caps, 0);
@ -258,7 +254,7 @@ gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps)
gulong samples, bytes, fmt = 0, bps = 0; gulong samples, bytes, fmt = 0, bps = 0;
if (!gst_caps_is_fixed (caps)) if (!gst_caps_is_fixed (caps))
return GST_PAD_LINK_DELAYED; return FALSE; /* GST_PAD_LINK_DELAYED; */
if (faac->handle) { if (faac->handle) {
faacEncClose (faac->handle); faacEncClose (faac->handle);
@ -275,7 +271,7 @@ gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps)
/* open a new handle to the encoder */ /* open a new handle to the encoder */
if (!(handle = faacEncOpen (samplerate, channels, &samples, &bytes))) if (!(handle = faacEncOpen (samplerate, channels, &samples, &bytes)))
return GST_PAD_LINK_REFUSED; return FALSE;
switch (depth) { switch (depth) {
case 16: case 16:
@ -294,7 +290,7 @@ gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps)
if (!fmt) { if (!fmt) {
faacEncClose (handle); faacEncClose (handle);
return GST_PAD_LINK_REFUSED; return FALSE;
} }
faac->format = fmt; faac->format = fmt;
@ -307,21 +303,21 @@ gst_faac_sinkconnect (GstPad * pad, const GstCaps * caps)
/* if the other side was already set-up, redo that */ /* if the other side was already set-up, redo that */
if (GST_PAD_CAPS (faac->srcpad)) if (GST_PAD_CAPS (faac->srcpad))
return gst_faac_srcconnect (faac->srcpad, return gst_faac_src_setcaps (faac->srcpad,
gst_pad_get_allowed_caps (faac->srcpad)); gst_pad_get_allowed_caps (faac->srcpad));
/* else, that'll be done later */ /* else, that'll be done later */
return GST_PAD_LINK_OK; return TRUE;
} }
static GstPadLinkReturn static gboolean
gst_faac_srcconnect (GstPad * pad, const GstCaps * caps) gst_faac_src_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad)); GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad));
gint n; gint n;
if (!faac->handle || (faac->samplerate == -1 || faac->channels == -1)) { if (!faac->handle || (faac->samplerate == -1 || faac->channels == -1)) {
return GST_PAD_LINK_DELAYED; return FALSE;
} }
/* we do samplerate/channels ourselves */ /* we do samplerate/channels ourselves */
@ -339,7 +335,6 @@ gst_faac_srcconnect (GstPad * pad, const GstCaps * caps)
faacEncConfiguration *conf; faacEncConfiguration *conf;
gint mpegversion = 0; gint mpegversion = 0;
GstCaps *newcaps; GstCaps *newcaps;
GstPadLinkReturn ret;
gst_structure_get_int (structure, "mpegversion", &mpegversion); gst_structure_get_int (structure, "mpegversion", &mpegversion);
@ -363,28 +358,25 @@ gst_faac_srcconnect (GstPad * pad, const GstCaps * caps)
"mpegversion", G_TYPE_INT, mpegversion, "mpegversion", G_TYPE_INT, mpegversion,
"channels", G_TYPE_INT, faac->channels, "channels", G_TYPE_INT, faac->channels,
"rate", G_TYPE_INT, faac->samplerate, NULL); "rate", G_TYPE_INT, faac->samplerate, NULL);
ret = gst_pad_try_set_caps (faac->srcpad, newcaps);
switch (ret) { /* negotiate with these caps */
case GST_PAD_LINK_OK: GST_DEBUG ("here are the caps: %" GST_PTR_FORMAT, newcaps);
case GST_PAD_LINK_DONE: if (gst_pad_set_caps (faac->srcpad, newcaps) == TRUE)
return GST_PAD_LINK_DONE; return TRUE;
case GST_PAD_LINK_DELAYED: else
return GST_PAD_LINK_DELAYED; return FALSE;
default:
break;
}
} }
return GST_PAD_LINK_REFUSED; return FALSE;
} }
static void static GstFlowReturn
gst_faac_chain (GstPad * pad, GstData * data) gst_faac_chain (GstPad * pad, GstBuffer * data)
{ {
GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad)); GstFaac *faac = GST_FAAC (gst_pad_get_parent (pad));
GstBuffer *inbuf, *outbuf, *subbuf; GstBuffer *inbuf, *outbuf, *subbuf;
guint size, ret_size, in_size, frame_size; guint size, ret_size, in_size, frame_size;
GstFlowReturn result = GST_FLOW_OK;
if (GST_IS_EVENT (data)) { if (GST_IS_EVENT (data)) {
GstEvent *event = GST_EVENT (data); GstEvent *event = GST_EVENT (data);
@ -399,25 +391,25 @@ gst_faac_chain (GstPad * pad, GstData * data)
GST_ELEMENT_ERROR (faac, LIBRARY, ENCODE, (NULL), (NULL)); GST_ELEMENT_ERROR (faac, LIBRARY, ENCODE, (NULL), (NULL));
gst_event_unref (event); gst_event_unref (event);
gst_buffer_unref (outbuf); gst_buffer_unref (outbuf);
return; return GST_FLOW_ERROR;
} }
if (ret_size > 0) { if (ret_size > 0) {
GST_BUFFER_SIZE (outbuf) = ret_size; GST_BUFFER_SIZE (outbuf) = ret_size;
GST_BUFFER_TIMESTAMP (outbuf) = 0; GST_BUFFER_TIMESTAMP (outbuf) = 0;
GST_BUFFER_DURATION (outbuf) = 0; GST_BUFFER_DURATION (outbuf) = 0;
gst_pad_push (faac->srcpad, GST_DATA (outbuf)); gst_pad_push (faac->srcpad, outbuf);
} else { } else {
break; break;
} }
} }
gst_element_set_eos (GST_ELEMENT (faac)); gst_pad_push_event (faac->srcpad, gst_event_new_eos ());
gst_pad_push (faac->srcpad, data); gst_pad_push (faac->srcpad, data);
return; return result;
default: default:
gst_pad_event_default (pad, event); gst_pad_event_default (pad, event);
return; return result;
} }
} }
@ -427,16 +419,16 @@ gst_faac_chain (GstPad * pad, GstData * data)
GST_ELEMENT_ERROR (faac, CORE, NEGOTIATION, (NULL), GST_ELEMENT_ERROR (faac, CORE, NEGOTIATION, (NULL),
("format wasn't negotiated before chain function")); ("format wasn't negotiated before chain function"));
gst_buffer_unref (inbuf); gst_buffer_unref (inbuf);
return; return GST_FLOW_ERROR;
} }
if (!GST_PAD_CAPS (faac->srcpad)) { if (!GST_PAD_CAPS (faac->srcpad)) {
if (gst_faac_srcconnect (faac->srcpad, if (gst_faac_src_setcaps (faac->srcpad,
gst_pad_get_allowed_caps (faac->srcpad)) <= 0) { gst_pad_get_allowed_caps (faac->srcpad)) <= 0) {
GST_ELEMENT_ERROR (faac, CORE, NEGOTIATION, (NULL), GST_ELEMENT_ERROR (faac, CORE, NEGOTIATION, (NULL),
("failed to negotiate MPEG/AAC format with next element")); ("failed to negotiate MPEG/AAC format with next element"));
gst_buffer_unref (inbuf); gst_buffer_unref (inbuf);
return; return GST_FLOW_ERROR;
} }
} }
@ -473,7 +465,7 @@ gst_faac_chain (GstPad * pad, GstData * data)
gst_buffer_unref (inbuf); gst_buffer_unref (inbuf);
} }
return; return result;
} }
/* create the frame */ /* create the frame */
@ -506,7 +498,7 @@ gst_faac_chain (GstPad * pad, GstData * data)
GST_ELEMENT_ERROR (faac, LIBRARY, ENCODE, (NULL), (NULL)); GST_ELEMENT_ERROR (faac, LIBRARY, ENCODE, (NULL), (NULL));
gst_buffer_unref (inbuf); gst_buffer_unref (inbuf);
gst_buffer_unref (subbuf); gst_buffer_unref (subbuf);
return; return GST_FLOW_ERROR;
} }
if (ret_size > 0) { if (ret_size > 0) {
@ -521,7 +513,7 @@ gst_faac_chain (GstPad * pad, GstData * data)
GST_BUFFER_DURATION (outbuf) += faac->cache_duration; GST_BUFFER_DURATION (outbuf) += faac->cache_duration;
faac->cache_duration = 0; faac->cache_duration = 0;
} }
gst_pad_push (faac->srcpad, GST_DATA (outbuf)); gst_pad_push (faac->srcpad, outbuf);
} else { } else {
/* FIXME: what I'm doing here isn't fully correct, but there /* FIXME: what I'm doing here isn't fully correct, but there
* really isn't a better way yet. * really isn't a better way yet.
@ -540,6 +532,8 @@ gst_faac_chain (GstPad * pad, GstData * data)
in_size -= frame_size; in_size -= frame_size;
gst_buffer_unref (subbuf); gst_buffer_unref (subbuf);
} }
return result;
} }
static void static void