Commit 599af07a authored by Renato Araujo Oliveira Filho's avatar Renato Araujo Oliveira Filho Committed by Wim Taymans

Added new plugin amrwb parse.

Original commit message from CVS:
Patch by: Renato Araujo Oliveira Filho <renatox at gmail dot com>
* configure.ac:
* ext/Makefile.am:
* ext/amrwb/Makefile.am:
* ext/amrwb/README:
* ext/amrwb/amrwb-code/Makefile.am:
* ext/amrwb/amrwb-code/run.sh:
* ext/amrwb/gstamrwb.c: (plugin_init):
* ext/amrwb/gstamrwbdec.c: (gst_amrwbdec_base_init),
(gst_amrwbdec_class_init), (gst_amrwbdec_init),
(gst_amrwbdec_setcaps), (gst_amrwbdec_event), (gst_amrwbdec_chain),
(gst_amrwbdec_state_change):
* ext/amrwb/gstamrwbdec.h:
* ext/amrwb/gstamrwbenc.c: (gst_amrwbenc_base_init),
(gst_amrwbenc_class_init), (gst_amrwbenc_init),
(gst_amrwbenc_finalize), (gst_amrwbenc_setcaps),
(gst_amrwbenc_chain), (gst_amrwbenc_state_change):
* ext/amrwb/gstamrwbenc.h:
* ext/amrwb/gstamrwbparse.c: (gst_amrwbparse_base_init),
(gst_amrwbparse_class_init), (gst_amrwbparse_init),
(gst_amrwbparse_querytypes), (gst_amrwbparse_query),
(gst_amrwbparse_chain), (gst_amrwbparse_read_header),
(gst_amrwbparse_loop), (gst_amrwbparse_sink_activate),
(gst_amrwbparse_sink_activate_pull), (gst_amrwbparse_state_change):
* ext/amrwb/gstamrwbparse.h:
Added new plugin amrwb parse.
Renamed audio/AMR to audio/AMR-WB as per spec.
Fixes #333307
parent 882324f2
2006-03-29 Wim Taymans <wim@fluendo.com>
Patch by: Renato Araujo Oliveira Filho <renatox at gmail dot com>
* configure.ac:
* ext/Makefile.am:
* ext/amrwb/Makefile.am:
* ext/amrwb/README:
* ext/amrwb/amrwb-code/Makefile.am:
* ext/amrwb/amrwb-code/run.sh:
* ext/amrwb/gstamrwb.c: (plugin_init):
* ext/amrwb/gstamrwbdec.c: (gst_amrwbdec_base_init),
(gst_amrwbdec_class_init), (gst_amrwbdec_init),
(gst_amrwbdec_setcaps), (gst_amrwbdec_event), (gst_amrwbdec_chain),
(gst_amrwbdec_state_change):
* ext/amrwb/gstamrwbdec.h:
* ext/amrwb/gstamrwbenc.c: (gst_amrwbenc_base_init),
(gst_amrwbenc_class_init), (gst_amrwbenc_init),
(gst_amrwbenc_finalize), (gst_amrwbenc_setcaps),
(gst_amrwbenc_chain), (gst_amrwbenc_state_change):
* ext/amrwb/gstamrwbenc.h:
* ext/amrwb/gstamrwbparse.c: (gst_amrwbparse_base_init),
(gst_amrwbparse_class_init), (gst_amrwbparse_init),
(gst_amrwbparse_querytypes), (gst_amrwbparse_query),
(gst_amrwbparse_chain), (gst_amrwbparse_read_header),
(gst_amrwbparse_loop), (gst_amrwbparse_sink_activate),
(gst_amrwbparse_sink_activate_pull), (gst_amrwbparse_state_change):
* ext/amrwb/gstamrwbparse.h:
Added new plugin amrwb parse.
Renamed audio/AMR to audio/AMR-WB as per spec.
Fixes #333307
2006-03-27 Edgard Lima <edgard.lima@indt.org.br>
* gst-plugins-bad/sys/v4l2/v4l2src_calls.c: (gst_v4l2src_capture_init):
......
......@@ -433,6 +433,19 @@ GST_CHECK_FEATURE(XSHM, [X Shared Memory extension], [ximagesrc w/ xshm], [
AC_SUBST(XSHM_LIBS)
] )
dnl *** amrwb ***
translit(dnm, m, l) AM_CONDITIONAL(USE_AMRWB, true)
GST_CHECK_FEATURE(AMRWB, [amrwb code], amrwb, [
if test -f "ext/amrwb/amrwb-code/readme.txt"; then
HAVE_AMRWB="yes"
else
AC_MSG_WARN(Not amrwb code found. See README at ext/amrwb/)
HAVE_AMRWB="no"
fi
AC_SUBST(HAVE_AMRWB)
])
dnl *** BZ2 ***
translit(dnm, m, l) AM_CONDITIONAL(USE_BZ2, true)
GST_CHECK_FEATURE(BZ2, [bz2 library], bz2, [
......@@ -822,6 +835,8 @@ sys/v4l2/Makefile
examples/Makefile
examples/directfb/Makefile
ext/Makefile
ext/amrwb/Makefile
ext/amrwb/amrwb-code/Makefile
ext/bz2/Makefile
ext/directfb/Makefile
ext/faac/Makefile
......
if USE_AMRWB
AMRWB_DIR = amrwb
else
AMRWB_DIR =
endif
# if USE_ARTS
# ARTS_DIR=arts
# else
......@@ -221,6 +228,7 @@ XVID_DIR=
endif
SUBDIRS=\
$(AMRWB_DIR) \
$(ARTS_DIR) \
$(ARTSC_DIR) \
$(AUDIOFILE_DIR) \
......@@ -260,6 +268,7 @@ SUBDIRS=\
$(XVID_DIR)
DIST_SUBDIRS= \
amrwb \
bz2 \
directfb \
faac \
......
SUBDIRS = amrwb-code
plugin_LTLIBRARIES = libgstamrwb.la
libgstamrwb_la_SOURCES = \
gstamrwb.c \
gstamrwbdec.c \
gstamrwbenc.c \
gstamrwbparse.c
libgstamrwb_la_CFLAGS = $(GST_CFLAGS) $(AMRWB_CFLAGS) -Iamrwb-code/
libgstamrwb_la_LIBADD = $(GST_BASE_LIBS) $(AMRWB_LIBS) amrwb-code/libamrwb.la
libgstamrwb_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = \
gstamrwbdec.h \
gstamrwbenc.h \
gstamrwbparse.h
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.
noinst_LTLIBRARIES = libamrwb.la
libamrwb_la_SOURCES = \
enc_acelp.c \
enc_dtx.c \
enc_gain.c \
enc_if.c \
enc_lpc.c \
enc_main.c \
enc_rom.c \
enc_util.c \
if_rom.c \
dec_acelp.c \
dec_dtx.c \
dec_gain.c \
dec_if.c \
dec_lpc.c \
dec_main.c \
dec_rom.c \
dec_util.c
libamrwb_la_CFLAGS = -I./amrwb-code/c-code
libamrwb_la_LIBADD = $(GST_BASE_LIBS) $(AMRWB_LIBS)
libamrwb_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = \
dec_acelp.h \
dec_dtx.h \
dec_gain.h \
dec.h \
dec_if.h \
dec_lpc.h \
dec_main.h \
dec_util.h \
enc_acelp.h \
enc_dtx.h \
enc_gain.h \
enc.h \
enc_if.h \
enc_lpc.h \
enc_main.h \
enc_util.h \
if_rom.h \
typedef.h
wget http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-600.zip
unzip 26204-600.zip
unzip 26204-600_ANSI-C_source_code.zip
mv c-code/* .
rm -rf c-code/ 26204-600.zip 26204-600_ANSI-C_source_code.zip
echo "" >> typedef.h # to remove compilation warning (no newline at end of file)
/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin
* Copyright (C) 2006 Edgard Lima <edgard.lima@indt.org.br>
*
* 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, GST_ORIGIN);
/* GStreamer Adaptive Multi-Rate Narrow-Band (AMR-NB) plugin
* Copyright (C) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
*
* 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"
static GstElementDetails gst_amrwbdec_details = {
"AMR-WB decoder",
"Codec/Decoder/Audio",
"Adaptive Multi-Rate Wideband audio decoder",
"Renato Araujo <renato.filho@indt.org.br>"
};
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")
);
extern const UWord8 block_size[];
static void gst_amrwbdec_base_init (gpointer klass);
static void gst_amrwbdec_class_init (GstAmrwbDecClass * klass);
static void gst_amrwbdec_init (GstAmrwbDec * amrwbdec,
GstAmrwbDecClass * klass);
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);
GST_BOILERPLATE (GstAmrwbDec, gst_amrwbdec, GstElement, GST_TYPE_ELEMENT)
static void gst_amrwbdec_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
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, &gst_amrwbdec_details);
}
static void
gst_amrwbdec_class_init (GstAmrwbDecClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
element_class->change_state = gst_amrwbdec_state_change;
}
static void
gst_amrwbdec_init (GstAmrwbDec * amrwbdec, GstAmrwbDecClass * klass)
{
/* create the sink pad */
amrwbdec->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get (&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_template (gst_static_pad_template_get (&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 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;
default:
ret = gst_pad_push_event (amrwbdec->srcpad, event);
break;
}
gst_object_unref (amrwbdec);
return ret;
}
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) {
GST_ELEMENT_ERROR (amrwbdec, STREAM, TYPE_NOT_FOUND, (NULL),
("Decoder is not initialized"));
ret = GST_FLOW_NOT_NEGOTIATED;
goto done;
}
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer))
amrwbdec->ts = GST_BUFFER_TIMESTAMP (buffer);
gst_adapter_push (amrwbdec->adapter, buffer);
while (TRUE) {
GstBuffer *out;
UWord8 *data;
Word16 block, mode;
if (gst_adapter_available (amrwbdec->adapter) < 1)
break;
data = (UWord8 *) gst_adapter_peek (amrwbdec->adapter, 1);
/* get size */
mode = (Word16) (data[0] >> 3) & 0x0F;
block = block_size[mode];
if (gst_adapter_available (amrwbdec->adapter) < block) {
break;
}
/* the library seems to write into the source data, hence
* the copy. */
data = (UWord8 *) gst_adapter_take (amrwbdec->adapter, block);
/* get output */
out = gst_buffer_new_and_alloc (sizeof (Word16) * L_FRAME16k);
GST_BUFFER_DURATION (out) = amrwbdec->duration;
GST_BUFFER_TIMESTAMP (out) = amrwbdec->ts;
if (amrwbdec->ts != -1)
amrwbdec->ts += GST_BUFFER_DURATION (out);
gst_buffer_set_caps (out, GST_PAD_CAPS (amrwbdec->srcpad));
/* decode */
D_IF_decode (amrwbdec->handle, data,
(Word16 *) GST_BUFFER_DATA (out), _good_frame);
g_free (data);
/* play */
ret = gst_pad_push (amrwbdec->srcpad, out);
}
done:
gst_object_unref (amrwbdec);
return ret;
}
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;
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;
}
}
/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin
* Copyright (C) 2006 Edgard Lima <edgard.lima@indt.org.br>
*
* 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 <gst/gst.h>
#include <gst/base/gstadapter.h>
#include "typedef.h"
#include "dec_if.h"
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, GstAmrwbDec))
#define GST_IS_AMRWBDEC(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AMRWBDEC))
#define GST_IS_AMRWBDEC_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AMRWBDEC))
typedef struct _GstAmrwbDec GstAmrwbDec;
typedef struct _GstAmrwbDecClass GstAmrwbDecClass;
struct _GstAmrwbDec {
GstElement element;
/* pads */
GstPad *sinkpad, *srcpad;
guint64 ts;
GstAdapter *adapter;
/* library handle */
void *handle;
/* output settings */
gint channels, rate;
gint duration;
};
struct _GstAmrwbDecClass {
GstElementClass parent_class;
};
GType gst_amrwbdec_get_type (void);
G_END_DECLS
#endif /* __GST_AMRWBDEC_H__ */
/* GStreamer Adaptive Multi-Rate Wide-Band (AMR-WB) plugin
* Copyright (C) 2006 Edgard Lima <edgard.lima@indt.org.br>
*
* 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 GstElementDetails gst_amrwbenc_details = {
"AMR-WB encoder",
"Codec/Encoder/Audio",
"Adaptive Multi-Rate Wideband audio encoder",
"Renato Araujo <renato.filho@indt.org.br>"
};
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")
);
static void gst_amrwbenc_base_init (gpointer klass);
static void gst_amrwbenc_class_init (GstAmrwbEncClass * klass);
static void gst_amrwbenc_init (GstAmrwbEnc * amrwbenc,
GstAmrwbEncClass * klass);
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);
GST_BOILERPLATE (GstAmrwbEnc, gst_amrwbenc, GstElement, GST_TYPE_ELEMENT)
static void gst_amrwbenc_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
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, &gst_amrwbenc_details);
}
static void
gst_amrwbenc_class_init (GstAmrwbEncClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
object_class->finalize = gst_amrwbenc_finalize;
element_class->change_state = gst_amrwbenc_state_change;
}
static void
gst_amrwbenc_init (GstAmrwbEnc * amrwbenc, GstAmrwbEncClass * klass)
{
/* create the sink pad */
amrwbenc->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get (&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_template (gst_static_pad_template_get (&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