[gst-devel] a52dec ported to gstreamer 0.9
Josef Zlomek
josef.zlomek at xeris.cz
Tue Oct 11 05:08:38 CEST 2005
Hello,
I have ported the a52dec plugin (gst-plugins-ugly/ext/a52dec)
to GStreamer 0.9.
The patch is attached.
Joe Zlomek
-------------- next part --------------
Index: configure.ac
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/configure.ac,v
retrieving revision 1.592
diff -c -p -r1.592 configure.ac
*** configure.ac 3 Oct 2005 17:59:55 -0000 1.592
--- configure.ac 11 Oct 2005 12:03:31 -0000
*************** dnl ###########################
*** 249,254 ****
--- 249,260 ----
dnl # Configure external libs #
dnl ###########################
+ dnl *** a52dec ***
+ translit(dnm, m, l) AM_CONDITIONAL(USE_A52DEC, true)
+ GST_CHECK_FEATURE(A52DEC, [a52dec], a52dec, [
+ AC_CHECK_A52DEC(HAVE_A52DEC=yes, HAVE_A52DEC=no)
+ ])
+
dnl *** AMR-NB ***
translit(dnm, m, l) AM_CONDITIONAL(USE_AMRNB, true)
GST_CHECK_FEATURE(AMRNB, [AMR-NB], amrnbdec amrnbenc, [
*************** gst/iec958/Makefile
*** 388,393 ****
--- 394,400 ----
gst/mpegaudioparse/Makefile
gst/realmedia/Makefile
ext/Makefile
+ ext/a52dec/Makefile
ext/amrnb/Makefile
ext/lame/Makefile
ext/mad/Makefile
Index: ext/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/ext/Makefile.am,v
retrieving revision 1.146
diff -c -p -r1.146 Makefile.am
*** ext/Makefile.am 31 Aug 2005 17:57:35 -0000 1.146
--- ext/Makefile.am 11 Oct 2005 12:03:31 -0000
***************
*** 1,8 ****
! # if USE_A52DEC
! # A52DEC_DIR = a52dec
! # else
A52DEC_DIR =
! # endif
if USE_AMRNB
AMRNB_DIR = amrnb
--- 1,8 ----
! if USE_A52DEC
! A52DEC_DIR = a52dec
! else
A52DEC_DIR =
! endif
if USE_AMRNB
AMRNB_DIR = amrnb
Index: ext/a52dec/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/ext/a52dec/Makefile.am,v
retrieving revision 1.9
diff -c -p -r1.9 Makefile.am
*** ext/a52dec/Makefile.am 11 Sep 2003 19:57:53 -0000 1.9
--- ext/a52dec/Makefile.am 11 Oct 2005 12:03:31 -0000
*************** plugin_LTLIBRARIES = libgsta52dec.la
*** 3,9 ****
libgsta52dec_la_SOURCES = gsta52dec.c
libgsta52dec_la_CFLAGS = $(GST_CFLAGS)
! libgsta52dec_la_LIBADD = $(A52DEC_LIBS)
libgsta52dec_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gsta52dec.h
--- 3,9 ----
libgsta52dec_la_SOURCES = gsta52dec.c
libgsta52dec_la_CFLAGS = $(GST_CFLAGS)
! libgsta52dec_la_LIBADD = $(A52DEC_LIBS) -lgstaudio- at GST_MAJORMINOR@
libgsta52dec_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gsta52dec.h
Index: ext/a52dec/gsta52dec.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/ext/a52dec/gsta52dec.c,v
retrieving revision 1.49
diff -c -p -r1.49 gsta52dec.c
*** ext/a52dec/gsta52dec.c 2 Sep 2005 15:43:51 -0000 1.49
--- ext/a52dec/gsta52dec.c 11 Oct 2005 12:03:31 -0000
*************** static GstStaticPadTemplate src_factory
*** 79,89 ****
"channels = (int) [ 1, 6 ], " "buffer-frames = (int) 0")
);
! static void gst_a52dec_base_init (gpointer g_class);
static void gst_a52dec_class_init (GstA52DecClass * klass);
static void gst_a52dec_init (GstA52Dec * a52dec);
! static void gst_a52dec_chain (GstPad * pad, GstData * data);
static GstStateChangeReturn gst_a52dec_change_state (GstElement * element,
GstStateChange transition);
--- 79,90 ----
"channels = (int) [ 1, 6 ], " "buffer-frames = (int) 0")
);
! static void gst_a52dec_base_init (GstA52DecClass * klass);
static void gst_a52dec_class_init (GstA52DecClass * klass);
static void gst_a52dec_init (GstA52Dec * a52dec);
! static GstFlowReturn gst_a52dec_chain (GstPad * pad, GstBuffer * buffer);
! static gboolean gst_a52dec_sink_event (GstPad * pad, GstEvent * event);
static GstStateChangeReturn gst_a52dec_change_state (GstElement * element,
GstStateChange transition);
*************** gst_a52dec_get_type (void)
*** 104,111 ****
if (!a52dec_type) {
static const GTypeInfo a52dec_info = {
sizeof (GstA52DecClass),
! gst_a52dec_base_init,
! NULL, (GClassInitFunc) gst_a52dec_class_init,
NULL,
NULL,
sizeof (GstA52Dec),
--- 105,113 ----
if (!a52dec_type) {
static const GTypeInfo a52dec_info = {
sizeof (GstA52DecClass),
! (GBaseInitFunc) gst_a52dec_base_init,
! NULL,
! (GClassInitFunc) gst_a52dec_class_init,
NULL,
NULL,
sizeof (GstA52Dec),
*************** gst_a52dec_get_type (void)
*** 123,131 ****
}
static void
! gst_a52dec_base_init (gpointer g_class)
{
! GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
--- 125,133 ----
}
static void
! gst_a52dec_base_init (GstA52DecClass *klass)
{
! GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
*************** gst_a52dec_class_init (GstA52DecClass *
*** 143,175 ****
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
- parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
- g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DRC,
- g_param_spec_boolean ("drc", "Dynamic Range Compression",
- "Use Dynamic Range Compression", FALSE, G_PARAM_READWRITE));
-
gobject_class->set_property = gst_a52dec_set_property;
gobject_class->get_property = gst_a52dec_get_property;
gstelement_class->change_state = gst_a52dec_change_state;
}
static void
gst_a52dec_init (GstA52Dec * a52dec)
{
! GST_FLAG_SET (GST_ELEMENT (a52dec), GST_ELEMENT_EVENT_AWARE);
/* create the sink and src pads */
! a52dec->sinkpad =
! gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT
! (a52dec), "sink"), "sink");
gst_pad_set_chain_function (a52dec->sinkpad, gst_a52dec_chain);
gst_element_add_pad (GST_ELEMENT (a52dec), a52dec->sinkpad);
! a52dec->srcpad =
! gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT
! (a52dec), "src"), "src");
! gst_pad_use_explicit_caps (a52dec->srcpad);
gst_element_add_pad (GST_ELEMENT (a52dec), a52dec->srcpad);
a52dec->dynamic_range_compression = FALSE;
--- 145,176 ----
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gobject_class->set_property = gst_a52dec_set_property;
gobject_class->get_property = gst_a52dec_get_property;
gstelement_class->change_state = gst_a52dec_change_state;
+
+ parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DRC,
+ g_param_spec_boolean ("drc", "Dynamic Range Compression",
+ "Use Dynamic Range Compression", FALSE, G_PARAM_READWRITE));
}
static void
gst_a52dec_init (GstA52Dec * a52dec)
{
! GstElementClass *klass = GST_ELEMENT_GET_CLASS (a52dec);
/* create the sink and src pads */
! a52dec->sinkpad = gst_pad_new_from_template (
! gst_element_class_get_pad_template (klass, "sink"), "sink");
gst_pad_set_chain_function (a52dec->sinkpad, gst_a52dec_chain);
+ gst_pad_set_event_function (a52dec->sinkpad, gst_a52dec_sink_event);
gst_element_add_pad (GST_ELEMENT (a52dec), a52dec->sinkpad);
! a52dec->srcpad = gst_pad_new_from_template (
! gst_element_class_get_pad_template (klass, "src"), "src");
! gst_pad_use_fixed_caps (a52dec->srcpad);
gst_element_add_pad (GST_ELEMENT (a52dec), a52dec->srcpad);
a52dec->dynamic_range_compression = FALSE;
*************** gst_a52dec_channels (int flags, GstAudio
*** 259,280 ****
return chans;
}
! static int
gst_a52dec_push (GstA52Dec * a52dec,
GstPad * srcpad, int flags, sample_t * samples, GstClockTime timestamp)
{
GstBuffer *buf;
int chans, n, c;
flags &= (A52_CHANNEL_MASK | A52_LFE);
chans = gst_a52dec_channels (flags, NULL);
if (!chans) {
! return 1;
}
! buf = gst_buffer_new ();
! GST_BUFFER_SIZE (buf) = 256 * chans * (SAMPLE_WIDTH / 8);
! GST_BUFFER_DATA (buf) = g_malloc (GST_BUFFER_SIZE (buf));
for (n = 0; n < 256; n++) {
for (c = 0; c < chans; c++) {
((sample_t *) GST_BUFFER_DATA (buf))[n * chans + c] =
--- 260,284 ----
return chans;
}
! static GstFlowReturn
gst_a52dec_push (GstA52Dec * a52dec,
GstPad * srcpad, int flags, sample_t * samples, GstClockTime timestamp)
{
GstBuffer *buf;
int chans, n, c;
+ GstFlowReturn result;
flags &= (A52_CHANNEL_MASK | A52_LFE);
chans = gst_a52dec_channels (flags, NULL);
if (!chans) {
! return GST_FLOW_ERROR;
}
! result = gst_pad_alloc_buffer (srcpad, 0, 256 * chans * (SAMPLE_WIDTH / 8),
! GST_PAD_CAPS (srcpad), &buf);
! if (result != GST_FLOW_OK)
! return result;
!
for (n = 0; n < 256; n++) {
for (c = 0; c < chans; c++) {
((sample_t *) GST_BUFFER_DATA (buf))[n * chans + c] =
*************** gst_a52dec_push (GstA52Dec * a52dec,
*** 289,297 ****
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
! gst_pad_push (srcpad, GST_DATA (buf));
!
! return 0;
}
static gboolean
--- 293,299 ----
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
! return gst_pad_push (srcpad, buf);
}
static gboolean
*************** gst_a52dec_reneg (GstPad * pad)
*** 300,309 ****
GstAudioChannelPosition *pos;
GstA52Dec *a52dec = GST_A52DEC (gst_pad_get_parent (pad));
gint channels = gst_a52dec_channels (a52dec->using_channels, &pos);
! GstCaps *caps;
if (!channels)
! return FALSE;
GST_INFO ("a52dec: reneg channels:%d rate:%d\n",
channels, a52dec->sample_rate);
--- 302,312 ----
GstAudioChannelPosition *pos;
GstA52Dec *a52dec = GST_A52DEC (gst_pad_get_parent (pad));
gint channels = gst_a52dec_channels (a52dec->using_channels, &pos);
! GstCaps *caps = NULL;
! gboolean result = FALSE;
if (!channels)
! goto done;
GST_INFO ("a52dec: reneg channels:%d rate:%d\n",
channels, a52dec->sample_rate);
*************** gst_a52dec_reneg (GstPad * pad)
*** 317,354 ****
gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
g_free (pos);
! return gst_pad_set_explicit_caps (pad, caps);
}
! static void
! gst_a52dec_handle_event (GstA52Dec * a52dec, GstEvent * event)
{
GST_LOG ("Handling event of type %d timestamp %llu", GST_EVENT_TYPE (event),
GST_EVENT_TIMESTAMP (event));
switch (GST_EVENT_TYPE (event)) {
! case GST_EVENT_DISCONTINUOUS:{
gint64 val;
! if (!gst_event_discont_get_value (event, GST_FORMAT_TIME, &val)
|| !GST_CLOCK_TIME_IS_VALID (val)) {
! GST_WARNING ("No time discont value in event %p", event);
} else {
! a52dec->time = val;
}
}
! /* fall-through */
! case GST_EVENT_FLUSH:
if (a52dec->cache) {
gst_buffer_unref (a52dec->cache);
a52dec->cache = NULL;
}
break;
default:
break;
}
! gst_pad_event_default (a52dec->sinkpad, event);
}
static void
--- 320,389 ----
gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
g_free (pos);
! if (!gst_pad_set_caps (pad, caps))
! goto done;
!
! result = TRUE;
!
! done:
! if (caps)
! gst_caps_unref (caps);
! gst_object_unref (GST_OBJECT (a52dec));
! return result;
}
! static gboolean
! gst_a52dec_sink_event (GstPad * pad, GstEvent * event)
{
+ GstA52Dec *a52dec = GST_A52DEC (gst_pad_get_parent (pad));
+ gboolean ret = TRUE;
+
GST_LOG ("Handling event of type %d timestamp %llu", GST_EVENT_TYPE (event),
GST_EVENT_TIMESTAMP (event));
switch (GST_EVENT_TYPE (event)) {
! case GST_EVENT_NEWSEGMENT:{
! GstFormat format;
gint64 val;
! GST_STREAM_LOCK(pad);
! gst_event_parse_newsegment (event, NULL, &format, &val, NULL, NULL);
! if (format != GST_FORMAT_TIME
|| !GST_CLOCK_TIME_IS_VALID (val)) {
! GST_WARNING ("No time in newsegment event %p", event);
} else {
! a52dec->time = val;
! }
!
! if (a52dec->cache) {
! gst_buffer_unref (a52dec->cache);
! a52dec->cache = NULL;
}
+ ret = gst_pad_event_default (pad, event);
+ GST_STREAM_UNLOCK(pad);
+ break;
}
! case GST_EVENT_FLUSH_START:
! ret = gst_pad_event_default (pad, event);
! break;
! case GST_EVENT_FLUSH_STOP:
! GST_STREAM_LOCK (pad);
if (a52dec->cache) {
gst_buffer_unref (a52dec->cache);
a52dec->cache = NULL;
}
+ ret = gst_pad_event_default (pad, event);
+ GST_STREAM_UNLOCK (pad);
break;
default:
+ GST_STREAM_LOCK (pad);
+ ret = gst_pad_event_default (pad, event);
+ GST_STREAM_UNLOCK (pad);
break;
}
! gst_object_unref (GST_OBJECT (a52dec));
! return ret;
}
static void
*************** gst_a52dec_update_streaminfo (GstA52Dec
*** 362,371 ****
GST_TAG_BITRATE, (guint) a52dec->bit_rate, NULL);
gst_element_found_tags_for_pad (GST_ELEMENT (a52dec),
! GST_PAD (a52dec->srcpad), a52dec->time, taglist);
}
! static gboolean
gst_a52dec_handle_frame (GstA52Dec * a52dec, guint8 * data,
guint length, gint flags, gint sample_rate, gint bit_rate)
{
--- 397,406 ----
GST_TAG_BITRATE, (guint) a52dec->bit_rate, NULL);
gst_element_found_tags_for_pad (GST_ELEMENT (a52dec),
! GST_PAD (a52dec->srcpad), taglist);
}
! static GstFlowReturn
gst_a52dec_handle_frame (GstA52Dec * a52dec, guint8 * data,
guint length, gint flags, gint sample_rate, gint bit_rate)
{
*************** gst_a52dec_handle_frame (GstA52Dec * a52
*** 393,399 ****
a52dec->level = 1;
if (a52_frame (a52dec->state, data, &flags, &a52dec->level, a52dec->bias)) {
GST_WARNING ("a52_frame error");
! return TRUE;
}
channels = flags & (A52_CHANNEL_MASK | A52_LFE);
if (a52dec->using_channels != channels) {
--- 428,434 ----
a52dec->level = 1;
if (a52_frame (a52dec->state, data, &flags, &a52dec->level, a52dec->bias)) {
GST_WARNING ("a52_frame error");
! return GST_FLOW_OK;
}
channels = flags & (A52_CHANNEL_MASK | A52_LFE);
if (a52dec->using_channels != channels) {
*************** gst_a52dec_handle_frame (GstA52Dec * a52
*** 407,413 ****
a52dec->sample_rate, a52dec->stream_channels, a52dec->using_channels);
if (!gst_a52dec_reneg (a52dec->srcpad)) {
GST_ELEMENT_ERROR (a52dec, CORE, NEGOTIATION, (NULL), (NULL));
! return FALSE;
}
}
--- 442,448 ----
a52dec->sample_rate, a52dec->stream_channels, a52dec->using_channels);
if (!gst_a52dec_reneg (a52dec->srcpad)) {
GST_ELEMENT_ERROR (a52dec, CORE, NEGOTIATION, (NULL), (NULL));
! return GST_FLOW_ERROR;
}
}
*************** gst_a52dec_handle_frame (GstA52Dec * a52
*** 420,452 ****
if (a52_block (a52dec->state)) {
GST_WARNING ("a52_block error %d", i);
} else {
/* push on */
! gst_a52dec_push (a52dec, a52dec->srcpad, a52dec->using_channels,
a52dec->samples, a52dec->time);
}
a52dec->time += 256 * GST_SECOND / a52dec->sample_rate;
}
! return TRUE;
}
! static void
! gst_a52dec_chain (GstPad * pad, GstData * _data)
{
GstA52Dec *a52dec = GST_A52DEC (gst_pad_get_parent (pad));
- GstBuffer *buf;
guint8 *data;
guint size;
gint length = 0, flags, sample_rate, bit_rate;
!
! /* event handling */
! if (GST_IS_EVENT (_data)) {
! gst_a52dec_handle_event (a52dec, GST_EVENT (_data));
! return;
! }
/* merge with cache, if any. Also make sure timestamps match */
- buf = GST_BUFFER (_data);
if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
a52dec->time = GST_BUFFER_TIMESTAMP (buf);
GST_DEBUG_OBJECT (a52dec,
--- 455,484 ----
if (a52_block (a52dec->state)) {
GST_WARNING ("a52_block error %d", i);
} else {
+ GstFlowReturn ret;
+
/* push on */
! ret = gst_a52dec_push (a52dec, a52dec->srcpad, a52dec->using_channels,
a52dec->samples, a52dec->time);
+ if (ret != GST_FLOW_OK)
+ return ret;
}
a52dec->time += 256 * GST_SECOND / a52dec->sample_rate;
}
! return GST_FLOW_OK;
}
! static GstFlowReturn
! gst_a52dec_chain (GstPad * pad, GstBuffer *buf)
{
GstA52Dec *a52dec = GST_A52DEC (gst_pad_get_parent (pad));
guint8 *data;
guint size;
gint length = 0, flags, sample_rate, bit_rate;
! GstFlowReturn result = GST_FLOW_OK;
/* merge with cache, if any. Also make sure timestamps match */
if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
a52dec->time = GST_BUFFER_TIMESTAMP (buf);
GST_DEBUG_OBJECT (a52dec,
*************** gst_a52dec_chain (GstPad * pad, GstData
*** 474,481 ****
size--;
} else if (length <= size) {
GST_DEBUG ("Sync: %d", length);
! if (!gst_a52dec_handle_frame (a52dec, data,
! length, flags, sample_rate, bit_rate)) {
size = 0;
break;
}
--- 506,514 ----
size--;
} else if (length <= size) {
GST_DEBUG ("Sync: %d", length);
! result = gst_a52dec_handle_frame (a52dec, data,
! length, flags, sample_rate, bit_rate);
! if (result != GST_FLOW_OK) {
size = 0;
break;
}
*************** gst_a52dec_chain (GstPad * pad, GstData
*** 497,513 ****
--- 530,553 ----
GST_BUFFER_SIZE (buf) - size, size);
}
gst_buffer_unref (buf);
+ gst_object_unref (GST_OBJECT (a52dec));
+
+ return result;
}
static GstStateChangeReturn
gst_a52dec_change_state (GstElement * element, GstStateChange transition)
{
GstA52Dec *a52dec = GST_A52DEC (element);
+
+ #if 0
GstCPUFlags cpuflags;
uint32_t a52_cpuflags = 0;
+ #endif
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
+ #if 0
cpuflags = gst_cpu_get_flags ();
if (cpuflags & GST_CPU_FLAG_MMX)
a52_cpuflags |= MM_ACCEL_X86_MMX;
*************** gst_a52dec_change_state (GstElement * el
*** 517,522 ****
--- 557,564 ----
a52_cpuflags |= MM_ACCEL_X86_MMXEXT;
a52dec->state = a52_init (a52_cpuflags);
+ #endif
+ a52dec->state = a52_init (0);
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
a52dec->samples = a52_samples (a52dec->state);
*************** gst_a52dec_get_property (GObject * objec
*** 595,604 ****
static gboolean
plugin_init (GstPlugin * plugin)
{
-
- if (!gst_library_load ("gstaudio"))
- return FALSE;
-
if (!gst_element_register (plugin, "a52dec", GST_RANK_PRIMARY,
GST_TYPE_A52DEC))
return FALSE;
--- 637,642 ----
Index: ext/a52dec/gsta52dec.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/ext/a52dec/gsta52dec.h,v
retrieving revision 1.13
diff -c -p -r1.13 gsta52dec.h
*** ext/a52dec/gsta52dec.h 6 Dec 2004 10:28:13 -0000 1.13
--- ext/a52dec/gsta52dec.h 11 Oct 2005 12:03:31 -0000
***************
*** 22,28 ****
#define __GST_A52DEC_H__
#include <gst/gst.h>
- #include <gst/bytestream/bytestream.h>
G_BEGIN_DECLS
--- 22,27 ----
*************** struct _GstA52DecClass {
*** 66,71 ****
--- 65,72 ----
GstElementClass parent_class;
};
+ GType gst_a52dec_get_type (void);
+
G_END_DECLS
#endif /* __GST_A52DEC_H__ */
More information about the gstreamer-devel
mailing list