From 29e39080324a4a5a3b4d5bbc3fc79213090c6b0a Mon Sep 17 00:00:00 2001 From: Iago Toral Date: Mon, 27 Jul 2009 19:55:27 +0200 Subject: amrwb: Remove AMR-WB parser and decoder and rename encoder plugin from amrwb to amrwbenc Partially fixes bug #584890. --- configure.ac | 10 +- docs/plugins/Makefile.am | 4 +- docs/plugins/gst-plugins-bad-plugins-docs.sgml | 5 +- docs/plugins/gst-plugins-bad-plugins-sections.txt | 28 - docs/plugins/inspect/plugin-amrwb.xml | 76 --- docs/plugins/inspect/plugin-amrwbenc.xml | 34 + ext/Makefile.am | 4 +- ext/amrwb/Makefile.am | 18 - ext/amrwb/README | 12 - ext/amrwb/gstamrwb.c | 45 -- ext/amrwb/gstamrwbdec.c | 372 ----------- ext/amrwb/gstamrwbdec.h | 78 --- ext/amrwb/gstamrwbenc.c | 372 ----------- ext/amrwb/gstamrwbenc.h | 70 -- ext/amrwb/gstamrwbparse.c | 767 ---------------------- ext/amrwb/gstamrwbparse.h | 77 --- ext/amrwbenc/GstAmrwbEnc.prs | 11 + ext/amrwbenc/Makefile.am | 19 + ext/amrwbenc/README | 12 + ext/amrwbenc/gstamrwb.c | 39 ++ ext/amrwbenc/gstamrwbenc.c | 385 +++++++++++ ext/amrwbenc/gstamrwbenc.h | 70 ++ 22 files changed, 579 insertions(+), 1929 deletions(-) delete mode 100644 docs/plugins/inspect/plugin-amrwb.xml create mode 100644 docs/plugins/inspect/plugin-amrwbenc.xml delete mode 100644 ext/amrwb/Makefile.am delete mode 100644 ext/amrwb/README delete mode 100644 ext/amrwb/gstamrwb.c delete mode 100644 ext/amrwb/gstamrwbdec.c delete mode 100644 ext/amrwb/gstamrwbdec.h delete mode 100644 ext/amrwb/gstamrwbenc.c delete mode 100644 ext/amrwb/gstamrwbenc.h delete mode 100644 ext/amrwb/gstamrwbparse.c delete mode 100644 ext/amrwb/gstamrwbparse.h create mode 100644 ext/amrwbenc/GstAmrwbEnc.prs create mode 100644 ext/amrwbenc/Makefile.am create mode 100644 ext/amrwbenc/README create mode 100644 ext/amrwbenc/gstamrwb.c create mode 100644 ext/amrwbenc/gstamrwbenc.c create mode 100644 ext/amrwbenc/gstamrwbenc.h diff --git a/configure.ac b/configure.ac index 7fa190ea..370886bc 100644 --- a/configure.ac +++ b/configure.ac @@ -450,12 +450,12 @@ AG_GST_CHECK_FEATURE(ASSRENDER, [ASS/SSA renderer], assrender, [ AC_SUBST(ASSRENDER_CFLAGS) AC_SUBST(ASSRENDER_LIBS) -dnl *** amrwb *** +dnl *** amrwb-enc *** translit(dnm, m, l) AM_CONDITIONAL(USE_AMRWB, true) -AG_GST_CHECK_FEATURE(AMRWB, [amrwb library], amrwb, [ +AG_GST_CHECK_FEATURE(AMRWB, [amrwb library], amrwbenc, [ AG_GST_CHECK_LIBHEADER(AMRWB, amrwb, - GP3D_IF_decode, , - amrwb/dec.h, + GP3E_IF_encode, , + amrwb/enc.h, AMRWB_LIBS="-lamrwb" AC_SUBST(AMRWB_LIBS)) ]) @@ -1707,7 +1707,7 @@ tests/examples/shapewipe/Makefile tests/examples/switch/Makefile tests/icles/Makefile ext/alsaspdif/Makefile -ext/amrwb/Makefile +ext/amrwbenc/Makefile ext/assrender/Makefile ext/apexsink/Makefile ext/bz2/Makefile diff --git a/docs/plugins/Makefile.am b/docs/plugins/Makefile.am index 0a43f4ca..7ac083ae 100644 --- a/docs/plugins/Makefile.am +++ b/docs/plugins/Makefile.am @@ -89,9 +89,7 @@ EXAMPLE_CFILES = \ $(top_srcdir)/ext/directfb/dfb-example.c EXTRA_HFILES = \ - $(top_srcdir)/ext/amrwb/gstamrwbdec.h \ - $(top_srcdir)/ext/amrwb/gstamrwbenc.h \ - $(top_srcdir)/ext/amrwb/gstamrwbparse.h \ + $(top_srcdir)/ext/amrwbenc/gstamrwbenc.h \ $(top_srcdir)/ext/celt/gstceltdec.h \ $(top_srcdir)/ext/celt/gstceltenc.h \ $(top_srcdir)/ext/dc1394/gstdc1394.h \ diff --git a/docs/plugins/gst-plugins-bad-plugins-docs.sgml b/docs/plugins/gst-plugins-bad-plugins-docs.sgml index f1a36d70..ef8eb36b 100644 --- a/docs/plugins/gst-plugins-bad-plugins-docs.sgml +++ b/docs/plugins/gst-plugins-bad-plugins-docs.sgml @@ -19,10 +19,7 @@ gst-plugins-bad Elements - - - @@ -100,7 +97,7 @@ - + diff --git a/docs/plugins/gst-plugins-bad-plugins-sections.txt b/docs/plugins/gst-plugins-bad-plugins-sections.txt index 09e0e3fc..c60e127c 100644 --- a/docs/plugins/gst-plugins-bad-plugins-sections.txt +++ b/docs/plugins/gst-plugins-bad-plugins-sections.txt @@ -26,20 +26,6 @@ GST_TYPE_AMRPARSE gst_amrparse_get_type -
-element-amrwbdec -amrwbdec -GstAmrwbDec - -GstAmrwbDecClass -GST_AMRWBDEC -GST_AMRWBDEC_CLASS -GST_IS_AMRWBDEC -GST_IS_AMRWBDEC_CLASS -GST_TYPE_AMRWBDEC -gst_amrwbdec_get_type -
-
element-amrwbenc amrwbenc @@ -54,20 +40,6 @@ GST_TYPE_AMRWBENC gst_amrwbenc_get_type
-
-element-amrwbparse -amrwbparse -GstAmrwbParse - -GstAmrwbParseClass -GST_AMRWBPARSE -GST_AMRWBPARSE_CLASS -GST_IS_AMRWBPARSE -GST_IS_AMRWBPARSE_CLASS -GST_TYPE_AMRWBPARSE -gst_amrwbparse_get_type -
-
element-audioparse audioparse diff --git a/docs/plugins/inspect/plugin-amrwb.xml b/docs/plugins/inspect/plugin-amrwb.xml deleted file mode 100644 index bd617351..00000000 --- a/docs/plugins/inspect/plugin-amrwb.xml +++ /dev/null @@ -1,76 +0,0 @@ - - amrwb - Adaptive Multi-Rate Wide-Band - ../../ext/amrwb/.libs/libgstamrwb.so - libgstamrwb.so - 0.10.13.1 - unknown - gst-plugins-bad - GStreamer Bad Plug-ins git/prerelease - http://gstreamer.freedesktop.org - - - amrwbdec - AMR-WB audio decoder - Codec/Decoder/Audio - Adaptive Multi-Rate Wideband audio decoder - Renato Araujo <renato.filho@indt.org.br> - - - src - source - always -
audio/x-raw-int, width=(int)16, depth=(int)16, signed=(boolean)true, endianness=(int)1234, rate=(int)16000, channels=(int)1
-
- - sink - sink - always -
audio/AMR-WB, rate=(int)16000, channels=(int)1
-
-
-
- - amrwbenc - AMR-WB audio encoder - Codec/Encoder/Audio - Adaptive Multi-Rate Wideband audio encoder - Renato Araujo <renato.filho@indt.org.br> - - - src - source - always -
audio/AMR-WB, rate=(int)16000, channels=(int)1
-
- - sink - sink - always -
audio/x-raw-int, width=(int)16, depth=(int)16, signed=(boolean)true, endianness=(int)1234, rate=(int)16000, channels=(int)1
-
-
-
- - amrwbparse - AMR-WB audio stream parser - Codec/Parser/Audio - Adaptive Multi-Rate WideBand audio parser - Renato Filho <renato.filho@indt.org.br> - - - src - source - always -
audio/AMR-WB, rate=(int)16000, channels=(int)1
-
- - sink - sink - always -
audio/x-amr-wb-sh
-
-
-
-
-
\ No newline at end of file diff --git a/docs/plugins/inspect/plugin-amrwbenc.xml b/docs/plugins/inspect/plugin-amrwbenc.xml new file mode 100644 index 00000000..9a7ada08 --- /dev/null +++ b/docs/plugins/inspect/plugin-amrwbenc.xml @@ -0,0 +1,34 @@ + + amrwbenc + Adaptive Multi-Rate Wide-Band Encoder + ../../ext/amrwb/.libs/libgstamrwbenc.so + libgstamrwbenc.so + 0.10.12.1 + unknown + gst-plugins-bad + GStreamer Bad Plug-ins git/prerelease + Unknown package origin + + + amrwbenc + AMR-WB audio encoder + Codec/Encoder/Audio + Adaptive Multi-Rate Wideband audio encoder + Renato Araujo <renato.filho@indt.org.br> + + + src + source + always +
audio/AMR-WB, rate=(int)16000, channels=(int)1
+
+ + sink + sink + always +
audio/x-raw-int, width=(int)16, depth=(int)16, signed=(boolean)true, endianness=(int)1234, rate=(int)16000, channels=(int)1
+
+
+
+
+
diff --git a/ext/Makefile.am b/ext/Makefile.am index fafa1146..e2e4cc52 100644 --- a/ext/Makefile.am +++ b/ext/Makefile.am @@ -11,7 +11,7 @@ ASSRENDER_DIR = endif if USE_AMRWB -AMRWB_DIR = amrwb +AMRWB_DIR = amrwbenc else AMRWB_DIR = endif @@ -402,7 +402,7 @@ SUBDIRS=\ DIST_SUBDIRS = \ alsaspdif \ - amrwb \ + amrwbenc \ assrender \ apexsink \ bz2 \ diff --git a/ext/amrwb/Makefile.am b/ext/amrwb/Makefile.am deleted file mode 100644 index c4060d7f..00000000 --- a/ext/amrwb/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -plugin_LTLIBRARIES = libgstamrwb.la - -libgstamrwb_la_SOURCES = \ - gstamrwb.c \ - gstamrwbdec.c \ - gstamrwbenc.c \ - gstamrwbparse.c - -libgstamrwb_la_CFLAGS = $(GST_CFLAGS) $(AMRWB_CFLAGS) -libgstamrwb_la_LIBADD = $(GST_BASE_LIBS) $(AMRWB_LIBS) -libgstamrwb_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -libgstamrwb_la_LIBTOOLFLAGS = --tag=disable-static - -noinst_HEADERS = \ - gstamrwbdec.h \ - gstamrwbenc.h \ - gstamrwbparse.h - diff --git a/ext/amrwb/README b/ext/amrwb/README deleted file mode 100644 index 82d33715..00000000 --- a/ext/amrwb/README +++ /dev/null @@ -1,12 +0,0 @@ -Compiling AMRWB codec: -====================== - -To compile the amrwb codec, you need to download the source code from -"http://www.3gpp.org/ftp/Specs/html-info/26204.htm" and uncompress the -files inside an amrwb-code directory; - -or execute this commands: -$cd amrwb-code -$sh ./run.sh - -and run the "autogen" script again. diff --git a/ext/amrwb/gstamrwb.c b/ext/amrwb/gstamrwb.c deleted file mode 100644 index fd47b371..00000000 --- a/ext/amrwb/gstamrwb.c +++ /dev/null @@ -1,45 +0,0 @@ -/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin - * Copyright (C) 2006 Edgard Lima - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstamrwbdec.h" -#include "gstamrwbenc.h" -#include "gstamrwbparse.h" - -static gboolean -plugin_init (GstPlugin * plugin) -{ - return gst_element_register (plugin, "amrwbdec", - GST_RANK_PRIMARY, GST_TYPE_AMRWBDEC) && - gst_element_register (plugin, "amrwbparse", - GST_RANK_PRIMARY, GST_TYPE_AMRWBPARSE) && - gst_element_register (plugin, "amrwbenc", - GST_RANK_NONE, GST_TYPE_AMRWBENC); -} - - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "amrwb", - "Adaptive Multi-Rate Wide-Band", - plugin_init, VERSION, GST_LICENSE_UNKNOWN, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN); diff --git a/ext/amrwb/gstamrwbdec.c b/ext/amrwb/gstamrwbdec.c deleted file mode 100644 index 54e8a830..00000000 --- a/ext/amrwb/gstamrwbdec.c +++ /dev/null @@ -1,372 +0,0 @@ -/* GStreamer Adaptive Multi-Rate Narrow-Band (AMR-NB) plugin - * Copyright (C) 2004 Ronald Bultje - * - * 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. - */ - -/** - * SECTION:element-amrwbdec - * @see_also: #GstAmrwbEnc, #GstAmrwbParse - * - * AMR wideband decoder based on the - * reference codec implementation. - * - * - * Example launch line - * |[ - * gst-launch filesrc location=abc.amr ! amrwbparse ! amrwbdec ! audioresample ! audioconvert ! alsasink - * ]| - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstamrwbdec.h" - -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/AMR-WB, " - "rate = (int) 16000, " "channels = (int) 1") - ); - -static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-int, " - "width = (int) 16, " - "depth = (int) 16, " - "signed = (boolean) TRUE, " - "endianness = (int) BYTE_ORDER, " - "rate = (int) 16000, " "channels = (int) 1") - ); - -GST_DEBUG_CATEGORY_STATIC (gst_amrwbdec_debug); -#define GST_CAT_DEFAULT gst_amrwbdec_debug - -extern const UWord8 block_size[]; - -static gboolean gst_amrwbdec_event (GstPad * pad, GstEvent * event); -static GstFlowReturn gst_amrwbdec_chain (GstPad * pad, GstBuffer * buffer); -static gboolean gst_amrwbdec_setcaps (GstPad * pad, GstCaps * caps); -static GstStateChangeReturn gst_amrwbdec_state_change (GstElement * element, - GstStateChange transition); - -static void gst_amrwbdec_finalize (GObject * object); - -#define _do_init(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_amrwbdec_debug, "amrwbdec", 0, "AMR-WB audio decoder"); - -GST_BOILERPLATE_FULL (GstAmrwbDec, gst_amrwbdec, GstElement, GST_TYPE_ELEMENT, - _do_init); - -static void -gst_amrwbdec_base_init (gpointer klass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - GstElementDetails details = GST_ELEMENT_DETAILS ("AMR-WB audio decoder", - "Codec/Decoder/Audio", - "Adaptive Multi-Rate Wideband audio decoder", - "Renato Araujo "); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_template)); - - gst_element_class_set_details (element_class, &details); -} - -static void -gst_amrwbdec_class_init (GstAmrwbDecClass * klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - object_class->finalize = gst_amrwbdec_finalize; - - element_class->change_state = GST_DEBUG_FUNCPTR (gst_amrwbdec_state_change); -} - -static void -gst_amrwbdec_init (GstAmrwbDec * amrwbdec, GstAmrwbDecClass * klass) -{ - /* create the sink pad */ - amrwbdec->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink"); - gst_pad_set_setcaps_function (amrwbdec->sinkpad, gst_amrwbdec_setcaps); - gst_pad_set_event_function (amrwbdec->sinkpad, gst_amrwbdec_event); - gst_pad_set_chain_function (amrwbdec->sinkpad, gst_amrwbdec_chain); - gst_element_add_pad (GST_ELEMENT (amrwbdec), amrwbdec->sinkpad); - - /* create the src pad */ - amrwbdec->srcpad = gst_pad_new_from_static_template (&src_template, "src"); - gst_pad_use_fixed_caps (amrwbdec->srcpad); - gst_element_add_pad (GST_ELEMENT (amrwbdec), amrwbdec->srcpad); - - amrwbdec->adapter = gst_adapter_new (); - - /* init rest */ - amrwbdec->handle = NULL; - amrwbdec->channels = 0; - amrwbdec->rate = 0; - amrwbdec->duration = 0; - amrwbdec->ts = -1; -} - -static void -gst_amrwbdec_finalize (GObject * object) -{ - GstAmrwbDec *amrwbdec; - - amrwbdec = GST_AMRWBDEC (object); - - gst_adapter_clear (amrwbdec->adapter); - g_object_unref (amrwbdec->adapter); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static gboolean -gst_amrwbdec_setcaps (GstPad * pad, GstCaps * caps) -{ - GstStructure *structure; - GstAmrwbDec *amrwbdec; - GstCaps *copy; - - amrwbdec = GST_AMRWBDEC (gst_pad_get_parent (pad)); - - structure = gst_caps_get_structure (caps, 0); - - /* get channel count */ - gst_structure_get_int (structure, "channels", &amrwbdec->channels); - gst_structure_get_int (structure, "rate", &amrwbdec->rate); - - /* create reverse caps */ - copy = gst_caps_new_simple ("audio/x-raw-int", - "channels", G_TYPE_INT, amrwbdec->channels, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "rate", G_TYPE_INT, amrwbdec->rate, "signed", G_TYPE_BOOLEAN, TRUE, NULL); - - amrwbdec->duration = gst_util_uint64_scale_int (GST_SECOND, L_FRAME16k, - amrwbdec->rate * amrwbdec->channels); - - gst_pad_set_caps (amrwbdec->srcpad, copy); - gst_caps_unref (copy); - - gst_object_unref (amrwbdec); - - return TRUE; -} - -static gboolean -gst_amrwbdec_event (GstPad * pad, GstEvent * event) -{ - GstAmrwbDec *amrwbdec; - gboolean ret = TRUE; - - amrwbdec = GST_AMRWBDEC (gst_pad_get_parent (pad)); - - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_FLUSH_START: - ret = gst_pad_push_event (amrwbdec->srcpad, event); - break; - case GST_EVENT_FLUSH_STOP: - ret = gst_pad_push_event (amrwbdec->srcpad, event); - gst_adapter_clear (amrwbdec->adapter); - amrwbdec->ts = -1; - break; - case GST_EVENT_EOS: - gst_adapter_clear (amrwbdec->adapter); - ret = gst_pad_push_event (amrwbdec->srcpad, event); - break; - case GST_EVENT_NEWSEGMENT: - { - GstFormat format; - gdouble rate, arate; - gint64 start, stop, time; - gboolean update; - - gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format, - &start, &stop, &time); - - /* we need time for now */ - if (format != GST_FORMAT_TIME) - goto newseg_wrong_format; - - GST_DEBUG_OBJECT (amrwbdec, - "newsegment: update %d, rate %g, arate %g, start %" GST_TIME_FORMAT - ", stop %" GST_TIME_FORMAT ", time %" GST_TIME_FORMAT, - update, rate, arate, GST_TIME_ARGS (start), GST_TIME_ARGS (stop), - GST_TIME_ARGS (time)); - - /* now configure the values */ - gst_segment_set_newsegment_full (&amrwbdec->segment, update, - rate, arate, format, start, stop, time); - ret = gst_pad_push_event (amrwbdec->srcpad, event); - } - break; - default: - ret = gst_pad_push_event (amrwbdec->srcpad, event); - break; - } -done: - gst_object_unref (amrwbdec); - - return ret; - - /* ERRORS */ -newseg_wrong_format: - { - GST_DEBUG_OBJECT (amrwbdec, "received non TIME newsegment"); - goto done; - } -} - -static GstFlowReturn -gst_amrwbdec_chain (GstPad * pad, GstBuffer * buffer) -{ - GstAmrwbDec *amrwbdec; - GstFlowReturn ret = GST_FLOW_OK; - - amrwbdec = GST_AMRWBDEC (gst_pad_get_parent (pad)); - - if (amrwbdec->rate == 0 || amrwbdec->channels == 0) - goto not_negotiated; - - /* discontinuity, don't combine samples before and after the - * DISCONT */ - if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { - gst_adapter_clear (amrwbdec->adapter); - amrwbdec->ts = -1; - amrwbdec->discont = TRUE; - } - - /* take latest timestamp, FIXME timestamp is the one of the - * first buffer in the adapter. */ - if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) - amrwbdec->ts = GST_BUFFER_TIMESTAMP (buffer); - - gst_adapter_push (amrwbdec->adapter, buffer); - - while (TRUE) { - GstBuffer *out; - const guint8 *data; - gint block, mode; - - /* need to peek data to get the size */ - if (gst_adapter_available (amrwbdec->adapter) < 1) - break; - data = gst_adapter_peek (amrwbdec->adapter, 1); - - /* get size */ - mode = (data[0] >> 3) & 0x0F; - block = block_size[mode]; - - GST_DEBUG_OBJECT (amrwbdec, "mode %d, block %d", mode, block); - - if (!block || gst_adapter_available (amrwbdec->adapter) < block) - break; - - /* the library seems to write into the source data, hence the copy. */ - data = gst_adapter_take (amrwbdec->adapter, block); - - /* get output */ - out = gst_buffer_new_and_alloc (sizeof (gint16) * L_FRAME16k); - - GST_BUFFER_DURATION (out) = amrwbdec->duration; - GST_BUFFER_TIMESTAMP (out) = amrwbdec->ts; - - if (amrwbdec->ts != -1) - amrwbdec->ts += amrwbdec->duration; - if (amrwbdec->discont) { - GST_BUFFER_FLAG_SET (out, GST_BUFFER_FLAG_DISCONT); - amrwbdec->discont = FALSE; - } - - gst_buffer_set_caps (out, GST_PAD_CAPS (amrwbdec->srcpad)); - - /* decode */ - D_IF_decode (amrwbdec->handle, (UWord8 *) data, - (Word16 *) GST_BUFFER_DATA (out), _good_frame); - - g_free ((gpointer) data); - - /* send out */ - ret = gst_pad_push (amrwbdec->srcpad, out); - } - - gst_object_unref (amrwbdec); - return ret; - - /* ERRORS */ -not_negotiated: - { - GST_ELEMENT_ERROR (amrwbdec, STREAM, TYPE_NOT_FOUND, (NULL), - ("Decoder is not initialized")); - gst_object_unref (amrwbdec); - return GST_FLOW_NOT_NEGOTIATED; - } -} - -static GstStateChangeReturn -gst_amrwbdec_state_change (GstElement * element, GstStateChange transition) -{ - GstAmrwbDec *amrwbdec; - GstStateChangeReturn ret; - - amrwbdec = GST_AMRWBDEC (element); - - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - if (!(amrwbdec->handle = D_IF_init ())) - goto init_failed; - break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - gst_adapter_clear (amrwbdec->adapter); - amrwbdec->rate = 0; - amrwbdec->channels = 0; - amrwbdec->ts = -1; - amrwbdec->discont = TRUE; - gst_segment_init (&amrwbdec->segment, GST_FORMAT_TIME); - break; - default: - break; - } - - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - switch (transition) { - case GST_STATE_CHANGE_READY_TO_NULL: - D_IF_exit (amrwbdec->handle); - break; - default: - break; - } - - return ret; - - /* ERRORS */ -init_failed: - { - GST_ELEMENT_ERROR (amrwbdec, LIBRARY, INIT, (NULL), - ("Failed to open AMR Decoder")); - return GST_STATE_CHANGE_FAILURE; - } -} diff --git a/ext/amrwb/gstamrwbdec.h b/ext/amrwb/gstamrwbdec.h deleted file mode 100644 index a7a5ce71..00000000 --- a/ext/amrwb/gstamrwbdec.h +++ /dev/null @@ -1,78 +0,0 @@ -/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin - * Copyright (C) 2006 Edgard Lima - * - * 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. - */ - -#ifndef __GST_AMRWBDEC_H__ -#define __GST_AMRWBDEC_H__ - -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_AMRWBDEC \ - (gst_amrwbdec_get_type()) -#define GST_AMRWBDEC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AMRWBDEC, GstAmrwbDec)) -#define GST_AMRWBDEC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AMRWBDEC, GstAmrwbDecClass)) -#define GST_IS_AMRWBDEC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AMRWBDEC)) -#define GST_IS_AMRWBDEC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AMRWBDEC)) - -typedef struct _GstAmrwbDec GstAmrwbDec; -typedef struct _GstAmrwbDecClass GstAmrwbDecClass; - -/** - * GstAmrwbDec: - * - * Opaque data structure. - */ -struct _GstAmrwbDec { - GstElement element; - - /* pads */ - GstPad *sinkpad, *srcpad; - guint64 ts; - - GstAdapter *adapter; - - /* library handle */ - void *handle; - - /* output settings */ - gint channels, rate; - gint duration; - - GstSegment segment; - gboolean discont; -}; - -struct _GstAmrwbDecClass { - GstElementClass parent_class; -}; - -GType gst_amrwbdec_get_type (void); - -G_END_DECLS - -#endif /* __GST_AMRWBDEC_H__ */ diff --git a/ext/amrwb/gstamrwbenc.c b/ext/amrwb/gstamrwbenc.c deleted file mode 100644 index caf2adb7..00000000 --- a/ext/amrwb/gstamrwbenc.c +++ /dev/null @@ -1,372 +0,0 @@ -/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin - * Copyright (C) 2006 Edgard Lima - * - * 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. - */ - -/** - * SECTION:element-amrwbenc - * @see_also: #GstAmrwbDec, #GstAmrwbParse - * - * AMR wideband encoder based on the - * reference codec implementation. - * - * - * Example launch line - * |[ - * gst-launch filesrc location=abc.wav ! wavparse ! audioresample ! audioconvert ! amrwbenc ! filesink location=abc.amr - * ]| - * Please not that the above stream misses the header, that is needed to play - * the stream. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstamrwbenc.h" - -/* these defines are not in all .h files */ -#ifndef MR660 -#define MR660 0 -#define MR885 1 -#define MR1265 2 -#define MR1425 2 -#define MR1585 3 -#define MR1825 4 -#define MR1985 5 -#define MR2305 6 -#define MR2385 7 -#define MRDTX 8 -#endif - -static GType -gst_amrwbenc_bandmode_get_type () -{ - static GType gst_amrwbenc_bandmode_type = 0; - static GEnumValue gst_amrwbenc_bandmode[] = { - {MR660, "MR660", "MR660"}, - {MR885, "MR885", "MR885"}, - {MR1265, "MR1265", "MR1265"}, - {MR1425, "MR1425", "MR1425"}, - {MR1585, "MR1585", "MR1585"}, - {MR1825, "MR1825", "MR1825"}, - {MR1985, "MR1985", "MR1985"}, - {MR2305, "MR2305", "MR2305"}, - {MR2385, "MR2385", "MR2385"}, - {MRDTX, "MRDTX", "MRDTX"}, - {0, NULL, NULL}, - }; - if (!gst_amrwbenc_bandmode_type) { - gst_amrwbenc_bandmode_type = - g_enum_register_static ("GstAmrwbEncBandMode", gst_amrwbenc_bandmode); - } - return gst_amrwbenc_bandmode_type; -} - -#define GST_AMRWBENC_BANDMODE_TYPE (gst_amrwbenc_bandmode_get_type()) - -#define BANDMODE_DEFAULT MR660 - -enum -{ - PROP_0, - PROP_BANDMODE -}; - -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-int, " - "width = (int) 16, " - "depth = (int) 16, " - "signed = (boolean) TRUE, " - "endianness = (int) BYTE_ORDER, " - "rate = (int) 16000, " "channels = (int) 1") - ); - -static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/AMR-WB, " - "rate = (int) 16000, " "channels = (int) 1") - ); - -GST_DEBUG_CATEGORY_STATIC (gst_amrwbenc_debug); -#define GST_CAT_DEFAULT gst_amrwbenc_debug - -static void gst_amrwbenc_finalize (GObject * object); - -static GstFlowReturn gst_amrwbenc_chain (GstPad * pad, GstBuffer * buffer); -static gboolean gst_amrwbenc_setcaps (GstPad * pad, GstCaps * caps); -static GstStateChangeReturn gst_amrwbenc_state_change (GstElement * element, - GstStateChange transition); - -#define _do_init(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_amrwbenc_debug, "amrwbenc", 0, "AMR-WB audio encoder"); - -GST_BOILERPLATE_FULL (GstAmrwbEnc, gst_amrwbenc, GstElement, GST_TYPE_ELEMENT, - _do_init); - -static void -gst_amrwbenc_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstAmrwbEnc *self = GST_AMRWBENC (object); - - switch (prop_id) { - case PROP_BANDMODE: - self->bandmode = g_value_get_enum (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } - - return; -} - -static void -gst_amrwbenc_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec) -{ - GstAmrwbEnc *self = GST_AMRWBENC (object); - - switch (prop_id) { - case PROP_BANDMODE: - g_value_set_enum (value, self->bandmode); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } - - return; -} - -static void -gst_amrwbenc_base_init (gpointer klass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - GstElementDetails details = GST_ELEMENT_DETAILS ("AMR-WB audio encoder", - "Codec/Encoder/Audio", - "Adaptive Multi-Rate Wideband audio encoder", - "Renato Araujo "); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_template)); - - gst_element_class_set_details (element_class, &details); -} - -static void -gst_amrwbenc_class_init (GstAmrwbEncClass * klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - object_class->finalize = gst_amrwbenc_finalize; - object_class->set_property = gst_amrwbenc_set_property; - object_class->get_property = gst_amrwbenc_get_property; - - g_object_class_install_property (object_class, PROP_BANDMODE, - g_param_spec_enum ("band-mode", "Band Mode", - "Encoding Band Mode (Kbps)", GST_AMRWBENC_BANDMODE_TYPE, - BANDMODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - element_class->change_state = GST_DEBUG_FUNCPTR (gst_amrwbenc_state_change); -} - -static void -gst_amrwbenc_init (GstAmrwbEnc * amrwbenc, GstAmrwbEncClass * klass) -{ - /* create the sink pad */ - amrwbenc->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink"); - gst_pad_set_setcaps_function (amrwbenc->sinkpad, gst_amrwbenc_setcaps); - gst_pad_set_chain_function (amrwbenc->sinkpad, gst_amrwbenc_chain); - gst_element_add_pad (GST_ELEMENT (amrwbenc), amrwbenc->sinkpad); - - /* create the src pad */ - amrwbenc->srcpad = gst_pad_new_from_static_template (&src_template, "src"); - gst_pad_use_fixed_caps (amrwbenc->srcpad); - gst_element_add_pad (GST_ELEMENT (amrwbenc), amrwbenc->srcpad); - - amrwbenc->adapter = gst_adapter_new (); - - /* init rest */ - amrwbenc->handle = NULL; - amrwbenc->channels = 0; - amrwbenc->rate = 0; - amrwbenc->ts = 0; -} - -static void -gst_amrwbenc_finalize (GObject * object) -{ - GstAmrwbEnc *amrwbenc; - - amrwbenc = GST_AMRWBENC (object); - - g_object_unref (G_OBJECT (amrwbenc->adapter)); - amrwbenc->adapter = NULL; - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static gboolean -gst_amrwbenc_setcaps (GstPad * pad, GstCaps * caps) -{ - GstStructure *structure; - GstAmrwbEnc *amrwbenc; - GstCaps *copy; - - amrwbenc = GST_AMRWBENC (GST_PAD_PARENT (pad)); - - structure = gst_caps_get_structure (caps, 0); - - /* get channel count */ - gst_structure_get_int (structure, "channels", &amrwbenc->channels); - gst_structure_get_int (structure, "rate", &amrwbenc->rate); - - /* this is not wrong but will sound bad */ - if (amrwbenc->channels != 1) { - GST_WARNING ("amrwbdec is only optimized for mono channels"); - } - if (amrwbenc->rate != 16000) { - GST_WARNING ("amrwbdec is only optimized for 16000 Hz samplerate"); - } - - /* create reverse caps */ - copy = gst_caps_new_simple ("audio/AMR-WB", - "channels", G_TYPE_INT, amrwbenc->channels, - "rate", G_TYPE_INT, amrwbenc->rate, NULL); - - gst_pad_set_caps (amrwbenc->srcpad, copy); - gst_caps_unref (copy); - - return TRUE; -} - -static GstFlowReturn -gst_amrwbenc_chain (GstPad * pad, GstBuffer * buffer) -{ - GstAmrwbEnc *amrwbenc; - GstFlowReturn ret = GST_FLOW_OK; - const int buffer_size = sizeof (Word16) * L_FRAME16k; - - amrwbenc = GST_AMRWBENC (gst_pad_get_parent (pad)); - - g_return_val_if_fail (amrwbenc->handle, GST_FLOW_WRONG_STATE); - - if (amrwbenc->rate == 0 || amrwbenc->channels == 0) { - ret = GST_FLOW_NOT_NEGOTIATED; - goto done; - } - - /* discontinuity clears adapter, FIXME, maybe we can set some - * encoder flag to mask the discont. */ - if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { - gst_adapter_clear (amrwbenc->adapter); - amrwbenc->ts = 0; - amrwbenc->discont = TRUE; - } - - if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) - amrwbenc->ts = GST_BUFFER_TIMESTAMP (buffer); - - ret = GST_FLOW_OK; - gst_adapter_push (amrwbenc->adapter, buffer); - - /* Collect samples until we have enough for an output frame */ - while (gst_adapter_available (amrwbenc->adapter) >= buffer_size) { - GstBuffer *out; - guint8 *data; - gint outsize; - - out = gst_buffer_new_and_alloc (buffer_size); - GST_BUFFER_DURATION (out) = GST_SECOND * L_FRAME16k / - (amrwbenc->rate * amrwbenc->channels); - GST_BUFFER_TIMESTAMP (out) = amrwbenc->ts; - if (amrwbenc->ts != -1) { - amrwbenc->ts += GST_BUFFER_DURATION (out); - } - if (amrwbenc->discont) { - GST_BUFFER_FLAG_SET (out, GST_BUFFER_FLAG_DISCONT); - amrwbenc->discont = FALSE; - } - gst_buffer_set_caps (out, gst_pad_get_caps (amrwbenc->srcpad)); - - data = (guint8 *) gst_adapter_peek (amrwbenc->adapter, buffer_size); - - /* encode */ - outsize = - E_IF_encode (amrwbenc->handle, amrwbenc->bandmode, (Word16 *) data, - (UWord8 *) GST_BUFFER_DATA (out), 0); - - gst_adapter_flush (amrwbenc->adapter, buffer_size); - GST_BUFFER_SIZE (out) = outsize; - - /* play */ - if ((ret = gst_pad_push (amrwbenc->srcpad, out)) != GST_FLOW_OK) - break; - } - -done: - - gst_object_unref (amrwbenc); - return ret; - -} - -static GstStateChangeReturn -gst_amrwbenc_state_change (GstElement * element, GstStateChange transition) -{ - GstAmrwbEnc *amrwbenc; - GstStateChangeReturn ret; - - amrwbenc = GST_AMRWBENC (element); - - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - if (!(amrwbenc->handle = E_IF_init ())) - return GST_STATE_CHANGE_FAILURE; - break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - amrwbenc->rate = 0; - amrwbenc->channels = 0; - amrwbenc->ts = 0; - amrwbenc->discont = FALSE; - gst_adapter_clear (amrwbenc->adapter); - break; - default: - break; - } - - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - switch (transition) { - case GST_STATE_CHANGE_READY_TO_NULL: - E_IF_exit (amrwbenc->handle); - break; - default: - break; - } - - return ret; -} diff --git a/ext/amrwb/gstamrwbenc.h b/ext/amrwb/gstamrwbenc.h deleted file mode 100644 index 034a5bed..00000000 --- a/ext/amrwb/gstamrwbenc.h +++ /dev/null @@ -1,70 +0,0 @@ -/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin - * Copyright (C) 2006 Edgard Lima - * - * 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. - */ - -#ifndef __GST_AMRWBENC_H__ -#define __GST_AMRWBENC_H__ - -#include -#include -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_AMRWBENC \ - (gst_amrwbenc_get_type()) -#define GST_AMRWBENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AMRWBENC, GstAmrwbEnc)) -#define GST_AMRWBENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AMRWBENC, GstAmrwbEncClass)) -#define GST_IS_AMRWBENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AMRWBENC)) -#define GST_IS_AMRWBENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AMRWBENC)) - -typedef struct _GstAmrwbEnc GstAmrwbEnc; -typedef struct _GstAmrwbEncClass GstAmrwbEncClass; - -struct _GstAmrwbEnc { - GstElement element; - - /* pads */ - GstPad *sinkpad, *srcpad; - guint64 ts; - gboolean discont; - - GstAdapter *adapter; - - /* library handle */ - void *handle; - - /* input settings */ - gint bandmode; - gint channels, rate; -}; - -struct _GstAmrwbEncClass { - GstElementClass parent_class; -}; - -GType gst_amrwbenc_get_type (void); - -G_END_DECLS - -#endif /* __GST_AMRWBENC_H__ */ diff --git a/ext/amrwb/gstamrwbparse.c b/ext/amrwb/gstamrwbparse.c deleted file mode 100644 index bcee1704..00000000 --- a/ext/amrwb/gstamrwbparse.c +++ /dev/null @@ -1,767 +0,0 @@ -/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin - * Copyright (C) 2006 Edgard Lima - * - * 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. - */ - -/** - * SECTION:element-amrwbparse - * @see_also: #GstAmrwbDec, #GstAmrwbEnc - * - * This is an AMR wideband parser. - * - * - * Example launch line - * |[ - * gst-launch filesrc location=abc.amr ! amrwbparse ! amrwbdec ! audioresample ! audioconvert ! alsasink - * ]| - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "gstamrwbparse.h" - -static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/AMR-WB, " - "rate = (int) 16000, " "channels = (int) 1") - ); - -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-amr-wb-sh") - ); - -GST_DEBUG_CATEGORY_STATIC (gst_amrwbparse_debug); -#define GST_CAT_DEFAULT gst_amrwbparse_debug - -extern const UWord8 block_size[]; - -#define AMRWB_HEADER_SIZE 9 -#define AMRWB_HEADER_STR "#!AMR-WB\n" - -static void gst_amrwbparse_base_init (gpointer klass); -static void gst_amrwbparse_class_init (GstAmrwbParseClass * klass); -static void gst_amrwbparse_init (GstAmrwbParse * amrwbparse, - GstAmrwbParseClass * klass); - -static const GstQueryType *gst_amrwbparse_querytypes (GstPad * pad); -static gboolean gst_amrwbparse_query (GstPad * pad, GstQuery * query); - -static gboolean gst_amrwbparse_sink_event (GstPad * pad, GstEvent * event); -static gboolean gst_amrwbparse_src_event (GstPad * pad, GstEvent * event); -static GstFlowReturn gst_amrwbparse_chain (GstPad * pad, GstBuffer * buffer); -static void gst_amrwbparse_loop (GstPad * pad); -static gboolean gst_amrwbparse_sink_activate (GstPad * sinkpad); -static gboolean gst_amrwbparse_sink_activate_pull (GstPad * sinkpad, - gboolean active); -static gboolean gst_amrwbparse_sink_activate_push (GstPad * sinkpad, - gboolean active); -static GstStateChangeReturn gst_amrwbparse_state_change (GstElement * element, - GstStateChange transition); - -static void gst_amrwbparse_finalize (GObject * object); - -#define _do_init(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_amrwbparse_debug, "amrwbparse", 0, "AMR-WB audio stream parser"); - -GST_BOILERPLATE_FULL (GstAmrwbParse, gst_amrwbparse, GstElement, - GST_TYPE_ELEMENT, _do_init); - -static void -gst_amrwbparse_base_init (gpointer klass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - GstElementDetails details = GST_ELEMENT_DETAILS ("AMR-WB audio stream parser", - "Codec/Parser/Audio", - "Adaptive Multi-Rate WideBand audio parser", - "Renato Filho "); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_template)); - - gst_element_class_set_details (element_class, &details); - -} - -static void -gst_amrwbparse_class_init (GstAmrwbParseClass * klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - object_class->finalize = gst_amrwbparse_finalize; - - element_class->change_state = GST_DEBUG_FUNCPTR (gst_amrwbparse_state_change); -} - -static void -gst_amrwbparse_init (GstAmrwbParse * amrwbparse, GstAmrwbParseClass * klass) -{ - /* create the sink pad */ - amrwbparse->sinkpad = - gst_pad_new_from_static_template (&sink_template, "sink"); - gst_pad_set_chain_function (amrwbparse->sinkpad, - GST_DEBUG_FUNCPTR (gst_amrwbparse_chain)); - gst_pad_set_event_function (amrwbparse->sinkpad, - GST_DEBUG_FUNCPTR (gst_amrwbparse_sink_event)); - gst_pad_set_activate_function (amrwbparse->sinkpad, - gst_amrwbparse_sink_activate); - gst_pad_set_activatepull_function (amrwbparse->sinkpad, - gst_amrwbparse_sink_activate_pull); - gst_pad_set_activatepush_function (amrwbparse->sinkpad, - gst_amrwbparse_sink_activate_push); - gst_element_add_pad (GST_ELEMENT (amrwbparse), amrwbparse->sinkpad); - - /* create the src pad */ - amrwbparse->srcpad = gst_pad_new_from_static_template (&src_template, "src"); - gst_pad_set_event_function (amrwbparse->srcpad, - GST_DEBUG_FUNCPTR (gst_amrwbparse_src_event)); - gst_pad_set_query_function (amrwbparse->srcpad, - GST_DEBUG_FUNCPTR (gst_amrwbparse_query)); - gst_pad_set_query_type_function (amrwbparse->srcpad, - GST_DEBUG_FUNCPTR (gst_amrwbparse_querytypes)); - gst_element_add_pad (GST_ELEMENT (amrwbparse), amrwbparse->srcpad); - - amrwbparse->adapter = gst_adapter_new (); - - /* init rest */ - amrwbparse->ts = 0; -} - -static void -gst_amrwbparse_finalize (GObject * object) -{ - GstAmrwbParse *amrwbparse; - - amrwbparse = GST_AMRWBPARSE (object); - - gst_adapter_clear (amrwbparse->adapter); - g_object_unref (amrwbparse->adapter); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - - -static const GstQueryType * -gst_amrwbparse_querytypes (GstPad * pad) -{ - static const GstQueryType list[] = { - GST_QUERY_POSITION, - GST_QUERY_DURATION, - 0 - }; - - return list; -} - -static gboolean -gst_amrwbparse_query (GstPad * pad, GstQuery * query) -{ - GstAmrwbParse *amrwbparse; - gboolean res = TRUE; - - amrwbparse = GST_AMRWBPARSE (gst_pad_get_parent (pad)); - - switch (GST_QUERY_TYPE (query)) { - case GST_QUERY_POSITION: - { - GstFormat format; - gint64 cur; - - gst_query_parse_position (query, &format, NULL); - - if (format != GST_FORMAT_TIME) { - res = FALSE; - break; - } - - cur = amrwbparse->ts; - - gst_query_set_position (query, GST_FORMAT_TIME, cur); - res = TRUE; - break; - } - case GST_QUERY_DURATION: - { - GstFormat format; - gint64 tot; - GstPad *peer; - - gst_query_parse_duration (query, &format, NULL); - - if (format != GST_FORMAT_TIME) { - res = FALSE; - break; - } - - tot = -1; - res = FALSE; - - peer = gst_pad_get_peer (amrwbparse->sinkpad); - if (peer) { - GstFormat pformat; - gint64 ptot; - - pformat = GST_FORMAT_BYTES; - res = gst_pad_query_duration (peer, &pformat, &ptot); - if (res && amrwbparse->block) { - tot = gst_util_uint64_scale_int (ptot, 20 * GST_MSECOND, - amrwbparse->block); - } - gst_object_unref (GST_OBJECT (peer)); - } - gst_query_set_duration (query, GST_FORMAT_TIME, tot); - res = TRUE; - break; - } - default: - res = gst_pad_query_default (pad, query); - break; - } - - gst_object_unref (amrwbparse); - return res; -} - - -static gboolean -gst_amrwbparse_handle_pull_seek (GstAmrwbParse * amrwbparse, GstPad * pad, - GstEvent * event) -{ - GstFormat format; - gdouble rate; - GstSeekFlags flags; - GstSeekType cur_type, stop_type; - gint64 cur, stop; - gint64 byte_cur = -1, byte_stop = -1; - gboolean flush; - - gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur, - &stop_type, &stop); - - GST_DEBUG_OBJECT (amrwbparse, "Performing seek to %" GST_TIME_FORMAT, - GST_TIME_ARGS (cur)); - - /* For any format other than TIME, see if upstream handles - * it directly or fail. For TIME, try upstream, but do it ourselves if - * it fails upstream */ - if (format != GST_FORMAT_TIME) { - return gst_pad_push_event (amrwbparse->sinkpad, event); - } else { - if (gst_pad_push_event (amrwbparse->sinkpad, event)) - return TRUE; - } - - flush = flags & GST_SEEK_FLAG_FLUSH; - - /* send flush start */ - if (flush) - gst_pad_push_event (amrwbparse->sinkpad, gst_event_new_flush_start ()); - /* we only handle FLUSH seeks at the moment */ - else - return FALSE; - - /* grab streaming lock, this should eventually be possible, either - * because the task is paused or our streaming thread stopped - * because our peer is flushing. */ - GST_PAD_STREAM_LOCK (amrwbparse->sinkpad); - - /* Convert the TIME to the appropriate BYTE position at which to resume - * decoding. */ - cur = cur / (20 * GST_MSECOND) * (20 * GST_MSECOND); - if (cur != -1) - byte_cur = amrwbparse->block * (cur / 20 / GST_MSECOND) + AMRWB_HEADER_SIZE; - if (stop != -1) - byte_stop = - amrwbparse->block * (stop / 20 / GST_MSECOND) + AMRWB_HEADER_SIZE; - amrwbparse->offset = byte_cur; - amrwbparse->ts = cur; - - GST_DEBUG_OBJECT (amrwbparse, "Seeking to byte range %" G_GINT64_FORMAT - " to %" G_GINT64_FORMAT, byte_cur, cur); - - /* and prepare to continue streaming */ - /* send flush stop, peer will accept data and events again. We - * are not yet providing data as we still have the STREAM_LOCK. */ - gst_pad_push_event (amrwbparse->sinkpad, gst_event_new_flush_stop ()); - gst_pad_push_event (amrwbparse->srcpad, gst_event_new_new_segment (FALSE, - rate, format, cur, -1, cur)); - - /* and restart the task in case it got paused explicitely or by - * the FLUSH_START event we pushed out. */ - gst_pad_start_task (amrwbparse->sinkpad, - (GstTaskFunction) gst_amrwbparse_loop, amrwbparse->sinkpad); - - /* and release the lock again so we can continue streaming */ - GST_PAD_STREAM_UNLOCK (amrwbparse->sinkpad); - - return TRUE; -} - -static gboolean -gst_amrwbparse_handle_push_seek (GstAmrwbParse * amrwbparse, GstPad * pad, - GstEvent * event) -{ - GstFormat format; - gdouble rate; - GstSeekFlags flags; - GstSeekType cur_type, stop_type; - gint64 cur, stop; - gint64 byte_cur = -1, byte_stop = -1; - - gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur, - &stop_type, &stop); - - GST_DEBUG_OBJECT (amrwbparse, "Performing seek to %" GST_TIME_FORMAT, - GST_TIME_ARGS (cur)); - - /* For any format other than TIME, see if upstream handles - * it directly or fail. For TIME, try upstream, but do it ourselves if - * it fails upstream */ - if (format != GST_FORMAT_TIME) { - return gst_pad_push_event (amrwbparse->sinkpad, event); - } else { - if (gst_pad_push_event (amrwbparse->sinkpad, event)) - return TRUE; - } - - /* Convert the TIME to the appropriate BYTE position at which to resume - * decoding. */ - cur = cur / (20 * GST_MSECOND) * (20 * GST_MSECOND); - if (cur != -1) - byte_cur = amrwbparse->block * (cur / 20 / GST_MSECOND) + AMRWB_HEADER_SIZE; - if (stop != -1) - byte_stop = - amrwbparse->block * (stop / 20 / GST_MSECOND) + AMRWB_HEADER_SIZE; - amrwbparse->ts = cur; - - GST_DEBUG_OBJECT (amrwbparse, "Seeking to byte range %" G_GINT64_FORMAT - " to %" G_GINT64_FORMAT, byte_cur, byte_stop); - - /* Send BYTE based seek upstream */ - event = gst_event_new_seek (rate, GST_FORMAT_BYTES, flags, cur_type, - byte_cur, stop_type, byte_stop); - - return gst_pad_push_event (amrwbparse->sinkpad, event); -} - -static gboolean -gst_amrwbparse_src_event (GstPad * pad, GstEvent * event) -{ - GstAmrwbParse *amrwbparse = GST_AMRWBPARSE (gst_pad_get_parent (pad)); - gboolean res; - - GST_DEBUG_OBJECT (amrwbparse, "handling event %d", GST_EVENT_TYPE (event)); - - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_SEEK: - if (amrwbparse->seek_handler) - res = amrwbparse->seek_handler (amrwbparse, pad, event); - else - res = FALSE; - break; - default: - res = gst_pad_push_event (amrwbparse->sinkpad, event); - break; - } - gst_object_unref (amrwbparse); - - return res; -} - - -/* - * Data reading. - */ -static gboolean -gst_amrwbparse_sink_event (GstPad * pad, GstEvent * event) -{ - GstAmrwbParse *amrwbparse; - gboolean res; - - amrwbparse = GST_AMRWBPARSE (gst_pad_get_parent (pad)); - - GST_LOG ("handling event %d", GST_EVENT_TYPE (event)); - - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_FLUSH_START: - res = gst_pad_push_event (amrwbparse->srcpad, event); - break; - case GST_EVENT_FLUSH_STOP: - gst_adapter_clear (amrwbparse->adapter); - gst_segment_init (&amrwbparse->segment, GST_FORMAT_TIME); - res = gst_pad_push_event (amrwbparse->srcpad, event); - break; - case GST_EVENT_EOS: - res = gst_pad_push_event (amrwbparse->srcpad, event); - break; - case GST_EVENT_NEWSEGMENT: - { - /* eat for now, we send a newsegment at start with infinite - * duration. */ - gst_event_unref (event); - res = TRUE; - break; - } - default: - res = gst_pad_push_event (amrwbparse->srcpad, event); - break; - } - gst_object_unref (amrwbparse); - - return res; -} - -/* streaming mode */ -static GstFlowReturn -gst_amrwbparse_chain (GstPad * pad, GstBuffer * buffer) -{ - GstAmrwbParse *amrwbparse; - GstFlowReturn res = GST_FLOW_OK; - gint mode; - const guint8 *data; - GstBuffer *out; - GstClockTime timestamp; - - amrwbparse = GST_AMRWBPARSE (gst_pad_get_parent (pad)); - - timestamp = GST_BUFFER_TIMESTAMP (buffer); - if (GST_CLOCK_TIME_IS_VALID (timestamp)) { - GST_DEBUG_OBJECT (amrwbparse, "Lock on timestamp %" GST_TIME_FORMAT, - GST_TIME_ARGS (timestamp)); - amrwbparse->ts = timestamp; - } - - gst_adapter_push (amrwbparse->adapter, buffer); - - /* init */ - if (amrwbparse->need_header) { - GstEvent *segev; - GstCaps *caps; - - if (gst_adapter_available (amrwbparse->adapter) < AMRWB_HEADER_SIZE) - goto done; - - data = gst_adapter_peek (amrwbparse->adapter, AMRWB_HEADER_SIZE); - if (memcmp (data, AMRWB_HEADER_STR, AMRWB_HEADER_SIZE) != 0) - goto done; - - gst_adapter_flush (amrwbparse->adapter, AMRWB_HEADER_SIZE); - - amrwbparse->need_header = FALSE; - - caps = gst_caps_new_simple ("audio/AMR-WB", - "rate", G_TYPE_INT, 16000, "channels", G_TYPE_INT, 1, NULL); - gst_pad_set_caps (amrwbparse->srcpad, caps); - gst_caps_unref (caps); - - GST_DEBUG_OBJECT (amrwbparse, "Sending first segment"); - segev = gst_event_new_new_segment_full (FALSE, 1.0, 1.0, - GST_FORMAT_TIME, 0, -1, 0); - - gst_pad_push_event (amrwbparse->srcpad, segev); - } - - while (TRUE) { - if (gst_adapter_available (amrwbparse->adapter) < 1) - break; - - data = gst_adapter_peek (amrwbparse->adapter, 1); - - /* get size */ - mode = (data[0] >> 3) & 0x0F; - amrwbparse->block = block_size[mode] + 1; /* add one for the mode */ - - if (gst_adapter_available (amrwbparse->adapter) < amrwbparse->block) - break; - - out = gst_buffer_new_and_alloc (amrwbparse->block); - - data = gst_adapter_peek (amrwbparse->adapter, amrwbparse->block); - memcpy (GST_BUFFER_DATA (out), data, amrwbparse->block); - - /* timestamp, all constants that won't overflow */ - GST_BUFFER_DURATION (out) = GST_SECOND * L_FRAME16k / 16000; - GST_BUFFER_TIMESTAMP (out) = amrwbparse->ts; - if (GST_CLOCK_TIME_IS_VALID (amrwbparse->ts)) - amrwbparse->ts += GST_BUFFER_DURATION (out); - - gst_buffer_set_caps (out, GST_PAD_CAPS (amrwbparse->srcpad)); - - GST_DEBUG_OBJECT (amrwbparse, "Pushing %d bytes of data", - amrwbparse->block); - - res = gst_pad_push (amrwbparse->srcpad, out); - - gst_adapter_flush (amrwbparse->adapter, amrwbparse->block); - } -done: - - gst_object_unref (amrwbparse); - return res; -} - -static gboolean -gst_amrwbparse_pull_header (GstAmrwbParse * amrwbparse) -{ - GstBuffer *buffer; - GstFlowReturn ret; - guint8 *data; - gint size; - - ret = gst_pad_pull_range (amrwbparse->sinkpad, G_GUINT64_CONSTANT (0), - AMRWB_HEADER_SIZE, &buffer); - if (ret != GST_FLOW_OK) - return FALSE; - - data = GST_BUFFER_DATA (buffer); - size = GST_BUFFER_SIZE (buffer); - - if (size < AMRWB_HEADER_SIZE) - goto not_enough; - - if (memcmp (data, AMRWB_HEADER_STR, AMRWB_HEADER_SIZE)) - goto no_header; - - gst_buffer_unref (buffer); - - amrwbparse->offset = AMRWB_HEADER_SIZE; - return TRUE; - -not_enough: - { - gst_buffer_unref (buffer); - return FALSE; - } -no_header: - { - gst_buffer_unref (buffer); - return FALSE; - } -} - -/* random access mode, could just read a fixed size buffer and push it to - * the chain function but we don't... */ -static void -gst_amrwbparse_loop (GstPad * pad) -{ - GstAmrwbParse *amrwbparse; - GstBuffer *buffer; - guint8 *data; - gint size; - gint block, mode; - GstFlowReturn ret = GST_FLOW_OK; - - amrwbparse = GST_AMRWBPARSE (GST_PAD_PARENT (pad)); - - /* init */ - if (G_UNLIKELY (amrwbparse->need_header)) { - GstCaps *caps; - - if (!gst_amrwbparse_pull_header (amrwbparse)) { - GST_ELEMENT_ERROR (amrwbparse, STREAM, WRONG_TYPE, (NULL), (NULL)); - GST_LOG_OBJECT (amrwbparse, "could not read header"); - goto need_pause; - } - - caps = gst_caps_new_simple ("audio/AMR-WB", - "rate", G_TYPE_INT, 16000, "channels", G_TYPE_INT, 1, NULL); - gst_pad_set_caps (amrwbparse->srcpad, caps); - gst_caps_unref (caps); - - GST_DEBUG_OBJECT (amrwbparse, "Sending newsegment event"); - gst_pad_push_event (amrwbparse->srcpad, - gst_event_new_new_segment_full (FALSE, 1.0, 1.0, - GST_FORMAT_TIME, 0, -1, 0)); - - amrwbparse->need_header = FALSE; - } - - ret = - gst_pad_pull_range (amrwbparse->sinkpad, amrwbparse->offset, 1, &buffer); - - if (ret == GST_FLOW_UNEXPECTED) - goto eos; - else if (ret != GST_FLOW_OK) - goto need_pause; - - data = GST_BUFFER_DATA (buffer); - size = GST_BUFFER_SIZE (buffer); - - /* EOS */ - if (size < 1) { - gst_buffer_unref (buffer); - goto eos; - } - - /* get size */ - mode = (data[0] >> 3) & 0x0F; - block = block_size[mode]; /* add one for the mode */ - - gst_buffer_unref (buffer); - - ret = gst_pad_pull_range (amrwbparse->sinkpad, - amrwbparse->offset, block, &buffer); - - if (ret == GST_FLOW_UNEXPECTED) - goto eos; - else if (ret != GST_FLOW_OK) - goto need_pause; - - amrwbparse->offset += block; - - /* output */ - GST_BUFFER_DURATION (buffer) = GST_SECOND * L_FRAME16k / 16000; - GST_BUFFER_TIMESTAMP (buffer) = amrwbparse->ts; - - gst_buffer_set_caps (buffer, - (GstCaps *) gst_pad_get_pad_template_caps (amrwbparse->srcpad)); - - ret = gst_pad_push (amrwbparse->srcpad, buffer); - - if (ret != GST_FLOW_OK) { - GST_DEBUG_OBJECT (amrwbparse, "Flow: %s", gst_flow_get_name (ret)); - if (GST_FLOW_IS_FATAL (ret)) { - GST_ELEMENT_ERROR (amrwbparse, STREAM, FAILED, (NULL), /* _("Internal data flow error.")), */ - ("streaming task paused, reason: %s", gst_flow_get_name (ret))); - gst_pad_push_event (pad, gst_event_new_eos ()); - } - goto need_pause; - } - - amrwbparse->ts += GST_BUFFER_DURATION (buffer); - - return; - -need_pause: - { - GST_LOG_OBJECT (amrwbparse, "pausing task"); - gst_pad_pause_task (pad); - return; - } -eos: - { - GST_LOG_OBJECT (amrwbparse, "pausing task %d", ret); - gst_pad_push_event (amrwbparse->srcpad, gst_event_new_eos ()); - gst_pad_pause_task (pad); - return; - } -} - -static gboolean -gst_amrwbparse_sink_activate (GstPad * sinkpad) -{ - gboolean result = FALSE; - GstAmrwbParse *amrwbparse; - - amrwbparse = GST_AMRWBPARSE (gst_pad_get_parent (sinkpad)); - - if (gst_pad_check_pull_range (sinkpad)) { - GST_DEBUG ("Trying to activate in pull mode"); - amrwbparse->seekable = TRUE; - amrwbparse->ts = 0; - result = gst_pad_activate_pull (sinkpad, TRUE); - } else { - GST_DEBUG ("Try to activate in push mode"); - amrwbparse->seekable = FALSE; - result = gst_pad_activate_push (sinkpad, TRUE); - } - - gst_object_unref (amrwbparse); - return result; -} - - - -static gboolean -gst_amrwbparse_sink_activate_push (GstPad * sinkpad, gboolean active) -{ - GstAmrwbParse *amrwbparse = GST_AMRWBPARSE (gst_pad_get_parent (sinkpad)); - - if (active) { - amrwbparse->seek_handler = gst_amrwbparse_handle_push_seek; - } else { - amrwbparse->seek_handler = NULL; - } - - gst_object_unref (amrwbparse); - return TRUE; -} - -static gboolean -gst_amrwbparse_sink_activate_pull (GstPad * sinkpad, gboolean active) -{ - gboolean result; - GstAmrwbParse *amrwbparse; - - amrwbparse = GST_AMRWBPARSE (gst_pad_get_parent (sinkpad)); - if (active) { - amrwbparse->seek_handler = gst_amrwbparse_handle_pull_seek; - result = gst_pad_start_task (sinkpad, - (GstTaskFunction) gst_amrwbparse_loop, sinkpad); - } else { - amrwbparse->seek_handler = NULL; - result = gst_pad_stop_task (sinkpad); - } - - gst_object_unref (amrwbparse); - return result; -} - - -static GstStateChangeReturn -gst_amrwbparse_state_change (GstElement * element, GstStateChange transition) -{ - GstAmrwbParse *amrwbparse; - GstStateChangeReturn ret; - - amrwbparse = GST_AMRWBPARSE (element); - - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - amrwbparse->need_header = TRUE; - amrwbparse->ts = -1; - amrwbparse->block = 0; - gst_segment_init (&amrwbparse->segment, GST_FORMAT_TIME); - break; - default: - break; - } - - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - switch (transition) { - case GST_STATE_CHANGE_PAUSED_TO_READY: - break; - case GST_STATE_CHANGE_READY_TO_NULL: - break; - default: - break; - } - - return ret; -} diff --git a/ext/amrwb/gstamrwbparse.h b/ext/amrwb/gstamrwbparse.h deleted file mode 100644 index 6cbe7b74..00000000 --- a/ext/amrwb/gstamrwbparse.h +++ /dev/null @@ -1,77 +0,0 @@ -/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin - * Copyright (C) 2006 Edgard Lima - * - * 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. - */ - -#ifndef __GST_AMRWBPARSE_H__ -#define __GST_AMRWBPARSE_H__ - -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_AMRWBPARSE \ - (gst_amrwbparse_get_type()) -#define GST_AMRWBPARSE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AMRWBPARSE, GstAmrwbParse)) -#define GST_AMRWBPARSE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AMRWBPARSE, GstAmrwbParseClass)) -#define GST_IS_AMRWBPARSE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AMRWBPARSE)) -#define GST_IS_AMRWBPARSE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AMRWBPARSE)) - -typedef struct _GstAmrwbParse GstAmrwbParse; -typedef struct _GstAmrwbParseClass GstAmrwbParseClass; - -typedef gboolean (*GstAmrwbSeekHandler) (GstAmrwbParse * amrwbparse, GstPad * pad, - GstEvent * event); - -struct _GstAmrwbParse { - GstElement element; - - /* pads */ - GstPad *sinkpad, *srcpad; - - GstAdapter *adapter; - - gboolean seekable; - gboolean need_header; - gint64 offset; - gint block; - - GstAmrwbSeekHandler seek_handler; - - guint64 ts; - - /* for seeking etc */ - GstSegment segment; -}; - -struct _GstAmrwbParseClass { - GstElementClass parent_class; -}; - -GType gst_amrwbparse_get_type (void); - -G_END_DECLS - -#endif /* __GST_AMRWBPARSE_H__ */ diff --git a/ext/amrwbenc/GstAmrwbEnc.prs b/ext/amrwbenc/GstAmrwbEnc.prs new file mode 100644 index 00000000..57658494 --- /dev/null +++ b/ext/amrwbenc/GstAmrwbEnc.prs @@ -0,0 +1,11 @@ +[_presets_] +version=0.10 +element-name=GstAmrwbEnc + +[enhance-size] +_meta/comment=Maximize compression, lowest bitrate +band-mode=0 + +[enhance-quality] +_meta/comment=Maximize quality, highest bitrate +band-mode=8 diff --git a/ext/amrwbenc/Makefile.am b/ext/amrwbenc/Makefile.am new file mode 100644 index 00000000..4c4ea3b3 --- /dev/null +++ b/ext/amrwbenc/Makefile.am @@ -0,0 +1,19 @@ +plugin_LTLIBRARIES = libgstamrwbenc.la + +libgstamrwbenc_la_SOURCES = \ + gstamrwb.c \ + gstamrwbenc.c + +libgstamrwbenc_la_CFLAGS = $(GST_CFLAGS) $(AMRWB_CFLAGS) +libgstamrwbenc_la_LIBADD = $(GST_BASE_LIBS) $(AMRWB_LIBS) +libgstamrwbenc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) +libgstamrwbenc_la_LIBTOOLFLAGS = --tag=disable-static + +noinst_HEADERS = \ + gstamrwbenc.h + +presetdir = $(datadir)/gstreamer-$(GST_MAJORMINOR)/presets +preset_DATA = GstAmrwbEnc.prs + +EXTRA_DIST = $(preset_DATA) + diff --git a/ext/amrwbenc/README b/ext/amrwbenc/README new file mode 100644 index 00000000..9d158728 --- /dev/null +++ b/ext/amrwbenc/README @@ -0,0 +1,12 @@ +Compiling AMRWB encoder: +======================== + +To compile the amrwb encoder, you need to download the source code from +"http://www.3gpp.org/ftp/Specs/html-info/26204.htm" and uncompress the +files inside an amrwb-code directory; + +or execute this commands: +$cd amrwb-code +$sh ./run.sh + +and run the "autogen" script again. diff --git a/ext/amrwbenc/gstamrwb.c b/ext/amrwbenc/gstamrwb.c new file mode 100644 index 00000000..6cd734b1 --- /dev/null +++ b/ext/amrwbenc/gstamrwb.c @@ -0,0 +1,39 @@ +/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) Encoder plugin + * Copyright (C) 2006 Edgard Lima + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstamrwbenc.h" + +static gboolean +plugin_init (GstPlugin * plugin) +{ + return gst_element_register (plugin, "amrwbenc", + GST_RANK_NONE, GST_TYPE_AMRWBENC); +} + + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "amrwbenc", + "Adaptive Multi-Rate Wide-Band Encoder", + plugin_init, VERSION, GST_LICENSE_UNKNOWN, GST_PACKAGE_NAME, + GST_PACKAGE_ORIGIN); diff --git a/ext/amrwbenc/gstamrwbenc.c b/ext/amrwbenc/gstamrwbenc.c new file mode 100644 index 00000000..89659e53 --- /dev/null +++ b/ext/amrwbenc/gstamrwbenc.c @@ -0,0 +1,385 @@ +/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin + * Copyright (C) 2006 Edgard Lima + * + * 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. + */ + +/** + * SECTION:element-amrwbenc + * @see_also: #GstAmrwbDec, #GstAmrwbParse + * + * AMR wideband encoder based on the + * reference codec implementation. + * + * + * Example launch line + * |[ + * gst-launch filesrc location=abc.wav ! wavparse ! audioresample ! audioconvert ! amrwbenc ! filesink location=abc.amr + * ]| + * Please not that the above stream misses the header, that is needed to play + * the stream. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstamrwbenc.h" + +/* these defines are not in all .h files */ +#ifndef MR660 +#define MR660 0 +#define MR885 1 +#define MR1265 2 +#define MR1425 2 +#define MR1585 3 +#define MR1825 4 +#define MR1985 5 +#define MR2305 6 +#define MR2385 7 +#define MRDTX 8 +#endif + +static GType +gst_amrwbenc_bandmode_get_type () +{ + static GType gst_amrwbenc_bandmode_type = 0; + static GEnumValue gst_amrwbenc_bandmode[] = { + {MR660, "MR660", "MR660"}, + {MR885, "MR885", "MR885"}, + {MR1265, "MR1265", "MR1265"}, + {MR1425, "MR1425", "MR1425"}, + {MR1585, "MR1585", "MR1585"}, + {MR1825, "MR1825", "MR1825"}, + {MR1985, "MR1985", "MR1985"}, + {MR2305, "MR2305", "MR2305"}, + {MR2385, "MR2385", "MR2385"}, + {MRDTX, "MRDTX", "MRDTX"}, + {0, NULL, NULL}, + }; + if (!gst_amrwbenc_bandmode_type) { + gst_amrwbenc_bandmode_type = + g_enum_register_static ("GstAmrwbEncBandMode", gst_amrwbenc_bandmode); + } + return gst_amrwbenc_bandmode_type; +} + +#define GST_AMRWBENC_BANDMODE_TYPE (gst_amrwbenc_bandmode_get_type()) + +#define BANDMODE_DEFAULT MR660 + +enum +{ + PROP_0, + PROP_BANDMODE +}; + +static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "width = (int) 16, " + "depth = (int) 16, " + "signed = (boolean) TRUE, " + "endianness = (int) BYTE_ORDER, " + "rate = (int) 16000, " "channels = (int) 1") + ); + +static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/AMR-WB, " + "rate = (int) 16000, " "channels = (int) 1") + ); + +GST_DEBUG_CATEGORY_STATIC (gst_amrwbenc_debug); +#define GST_CAT_DEFAULT gst_amrwbenc_debug + +static void gst_amrwbenc_finalize (GObject * object); + +static GstFlowReturn gst_amrwbenc_chain (GstPad * pad, GstBuffer * buffer); +static gboolean gst_amrwbenc_setcaps (GstPad * pad, GstCaps * caps); +static GstStateChangeReturn gst_amrwbenc_state_change (GstElement * element, + GstStateChange transition); + +static void +_do_init (GType object_type) +{ + const GInterfaceInfo preset_interface_info = { + NULL, /* interface init */ + NULL, /* interface finalize */ + NULL /* interface_data */ + }; + + g_type_add_interface_static (object_type, GST_TYPE_PRESET, + &preset_interface_info); + + GST_DEBUG_CATEGORY_INIT (gst_amrnbenc_debug, "amrwbenc", 0, + "AMR-WB audio encoder"); +} + +GST_BOILERPLATE_FULL (GstAmrwbEnc, gst_amrwbenc, GstElement, GST_TYPE_ELEMENT, + _do_init); + +static void +gst_amrwbenc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstAmrwbEnc *self = GST_AMRWBENC (object); + + switch (prop_id) { + case PROP_BANDMODE: + self->bandmode = g_value_get_enum (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + + return; +} + +static void +gst_amrwbenc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstAmrwbEnc *self = GST_AMRWBENC (object); + + switch (prop_id) { + case PROP_BANDMODE: + g_value_set_enum (value, self->bandmode); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + + return; +} + +static void +gst_amrwbenc_base_init (gpointer klass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstElementDetails details = GST_ELEMENT_DETAILS ("AMR-WB audio encoder", + "Codec/Encoder/Audio", + "Adaptive Multi-Rate Wideband audio encoder", + "Renato Araujo "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_template)); + + gst_element_class_set_details (element_class, &details); +} + +static void +gst_amrwbenc_class_init (GstAmrwbEncClass * klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + object_class->finalize = gst_amrwbenc_finalize; + object_class->set_property = gst_amrwbenc_set_property; + object_class->get_property = gst_amrwbenc_get_property; + + g_object_class_install_property (object_class, PROP_BANDMODE, + g_param_spec_enum ("band-mode", "Band Mode", + "Encoding Band Mode (Kbps)", GST_AMRWBENC_BANDMODE_TYPE, + BANDMODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + element_class->change_state = GST_DEBUG_FUNCPTR (gst_amrwbenc_state_change); +} + +static void +gst_amrwbenc_init (GstAmrwbEnc * amrwbenc, GstAmrwbEncClass * klass) +{ + /* create the sink pad */ + amrwbenc->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink"); + gst_pad_set_setcaps_function (amrwbenc->sinkpad, gst_amrwbenc_setcaps); + gst_pad_set_chain_function (amrwbenc->sinkpad, gst_amrwbenc_chain); + gst_element_add_pad (GST_ELEMENT (amrwbenc), amrwbenc->sinkpad); + + /* create the src pad */ + amrwbenc->srcpad = gst_pad_new_from_static_template (&src_template, "src"); + gst_pad_use_fixed_caps (amrwbenc->srcpad); + gst_element_add_pad (GST_ELEMENT (amrwbenc), amrwbenc->srcpad); + + amrwbenc->adapter = gst_adapter_new (); + + /* init rest */ + amrwbenc->handle = NULL; + amrwbenc->channels = 0; + amrwbenc->rate = 0; + amrwbenc->ts = 0; +} + +static void +gst_amrwbenc_finalize (GObject * object) +{ + GstAmrwbEnc *amrwbenc; + + amrwbenc = GST_AMRWBENC (object); + + g_object_unref (G_OBJECT (amrwbenc->adapter)); + amrwbenc->adapter = NULL; + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static gboolean +gst_amrwbenc_setcaps (GstPad * pad, GstCaps * caps) +{ + GstStructure *structure; + GstAmrwbEnc *amrwbenc; + GstCaps *copy; + + amrwbenc = GST_AMRWBENC (GST_PAD_PARENT (pad)); + + structure = gst_caps_get_structure (caps, 0); + + /* get channel count */ + gst_structure_get_int (structure, "channels", &amrwbenc->channels); + gst_structure_get_int (structure, "rate", &amrwbenc->rate); + + /* this is not wrong but will sound bad */ + if (amrwbenc->channels != 1) { + GST_WARNING ("amrwbdec is only optimized for mono channels"); + } + if (amrwbenc->rate != 16000) { + GST_WARNING ("amrwbdec is only optimized for 16000 Hz samplerate"); + } + + /* create reverse caps */ + copy = gst_caps_new_simple ("audio/AMR-WB", + "channels", G_TYPE_INT, amrwbenc->channels, + "rate", G_TYPE_INT, amrwbenc->rate, NULL); + + gst_pad_set_caps (amrwbenc->srcpad, copy); + gst_caps_unref (copy); + + return TRUE; +} + +static GstFlowReturn +gst_amrwbenc_chain (GstPad * pad, GstBuffer * buffer) +{ + GstAmrwbEnc *amrwbenc; + GstFlowReturn ret = GST_FLOW_OK; + const int buffer_size = sizeof (Word16) * L_FRAME16k; + + amrwbenc = GST_AMRWBENC (gst_pad_get_parent (pad)); + + g_return_val_if_fail (amrwbenc->handle, GST_FLOW_WRONG_STATE); + + if (amrwbenc->rate == 0 || amrwbenc->channels == 0) { + ret = GST_FLOW_NOT_NEGOTIATED; + goto done; + } + + /* discontinuity clears adapter, FIXME, maybe we can set some + * encoder flag to mask the discont. */ + if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { + gst_adapter_clear (amrwbenc->adapter); + amrwbenc->ts = 0; + amrwbenc->discont = TRUE; + } + + if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) + amrwbenc->ts = GST_BUFFER_TIMESTAMP (buffer); + + ret = GST_FLOW_OK; + gst_adapter_push (amrwbenc->adapter, buffer); + + /* Collect samples until we have enough for an output frame */ + while (gst_adapter_available (amrwbenc->adapter) >= buffer_size) { + GstBuffer *out; + guint8 *data; + gint outsize; + + out = gst_buffer_new_and_alloc (buffer_size); + GST_BUFFER_DURATION (out) = GST_SECOND * L_FRAME16k / + (amrwbenc->rate * amrwbenc->channels); + GST_BUFFER_TIMESTAMP (out) = amrwbenc->ts; + if (amrwbenc->ts != -1) { + amrwbenc->ts += GST_BUFFER_DURATION (out); + } + if (amrwbenc->discont) { + GST_BUFFER_FLAG_SET (out, GST_BUFFER_FLAG_DISCONT); + amrwbenc->discont = FALSE; + } + gst_buffer_set_caps (out, gst_pad_get_caps (amrwbenc->srcpad)); + + data = (guint8 *) gst_adapter_peek (amrwbenc->adapter, buffer_size); + + /* encode */ + outsize = + E_IF_encode (amrwbenc->handle, amrwbenc->bandmode, (Word16 *) data, + (UWord8 *) GST_BUFFER_DATA (out), 0); + + gst_adapter_flush (amrwbenc->adapter, buffer_size); + GST_BUFFER_SIZE (out) = outsize; + + /* play */ + if ((ret = gst_pad_push (amrwbenc->srcpad, out)) != GST_FLOW_OK) + break; + } + +done: + + gst_object_unref (amrwbenc); + return ret; + +} + +static GstStateChangeReturn +gst_amrwbenc_state_change (GstElement * element, GstStateChange transition) +{ + GstAmrwbEnc *amrwbenc; + GstStateChangeReturn ret; + + amrwbenc = GST_AMRWBENC (element); + + switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + if (!(amrwbenc->handle = E_IF_init ())) + return GST_STATE_CHANGE_FAILURE; + break; + case GST_STATE_CHANGE_READY_TO_PAUSED: + amrwbenc->rate = 0; + amrwbenc->channels = 0; + amrwbenc->ts = 0; + amrwbenc->discont = FALSE; + gst_adapter_clear (amrwbenc->adapter); + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + + switch (transition) { + case GST_STATE_CHANGE_READY_TO_NULL: + E_IF_exit (amrwbenc->handle); + break; + default: + break; + } + + return ret; +} diff --git a/ext/amrwbenc/gstamrwbenc.h b/ext/amrwbenc/gstamrwbenc.h new file mode 100644 index 00000000..034a5bed --- /dev/null +++ b/ext/amrwbenc/gstamrwbenc.h @@ -0,0 +1,70 @@ +/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin + * Copyright (C) 2006 Edgard Lima + * + * 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. + */ + +#ifndef __GST_AMRWBENC_H__ +#define __GST_AMRWBENC_H__ + +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define GST_TYPE_AMRWBENC \ + (gst_amrwbenc_get_type()) +#define GST_AMRWBENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AMRWBENC, GstAmrwbEnc)) +#define GST_AMRWBENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AMRWBENC, GstAmrwbEncClass)) +#define GST_IS_AMRWBENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AMRWBENC)) +#define GST_IS_AMRWBENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AMRWBENC)) + +typedef struct _GstAmrwbEnc GstAmrwbEnc; +typedef struct _GstAmrwbEncClass GstAmrwbEncClass; + +struct _GstAmrwbEnc { + GstElement element; + + /* pads */ + GstPad *sinkpad, *srcpad; + guint64 ts; + gboolean discont; + + GstAdapter *adapter; + + /* library handle */ + void *handle; + + /* input settings */ + gint bandmode; + gint channels, rate; +}; + +struct _GstAmrwbEncClass { + GstElementClass parent_class; +}; + +GType gst_amrwbenc_get_type (void); + +G_END_DECLS + +#endif /* __GST_AMRWBENC_H__ */ -- cgit v1.2.1