configure.ac: Added mpegaudioparse

Original commit message from CVS:
* configure.ac:
Added mpegaudioparse

* ext/lame/gstlame.c: (gst_lame_src_getcaps),
(gst_lame_src_setcaps), (gst_lame_sink_setcaps),
(gst_lame_sink_event), (gst_lame_chain):
Some cleanups.
Fix memleak.

* gst/mpegaudioparse/gstmpegaudioparse.c:
(gst_mp3parse_class_init), (gst_mp3parse_init),
(gst_mp3parse_chain), (gst_mp3parse_change_state):
* gst/mpegaudioparse/gstmpegaudioparse.h:
Ported mpegaudioparse
This commit is contained in:
Wim Taymans 2005-08-17 19:05:51 +00:00
parent 07dbb08aab
commit ba5b1e6c8e
4 changed files with 54 additions and 73 deletions

View file

@ -1,3 +1,20 @@
2005-08-17 Wim Taymans <wim@fluendo.com>
* configure.ac:
Added mpegaudioparse
* ext/lame/gstlame.c: (gst_lame_src_getcaps),
(gst_lame_src_setcaps), (gst_lame_sink_setcaps),
(gst_lame_sink_event), (gst_lame_chain):
Some cleanups.
Fix memleak.
* gst/mpegaudioparse/gstmpegaudioparse.c:
(gst_mp3parse_class_init), (gst_mp3parse_init),
(gst_mp3parse_chain), (gst_mp3parse_change_state):
* gst/mpegaudioparse/gstmpegaudioparse.h:
Ported mpegaudioparse
2005-08-17 Wim Taymans <wim@fluendo.com> 2005-08-17 Wim Taymans <wim@fluendo.com>
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_open), (gst_rtspsrc_play): * gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_open), (gst_rtspsrc_play):

View file

@ -633,6 +633,7 @@ gst/fdsrc/Makefile
gst/goom/Makefile gst/goom/Makefile
gst/law/Makefile gst/law/Makefile
gst/level/Makefile gst/level/Makefile
gst/mpegaudioparse/Makefile
gst/realmedia/Makefile gst/realmedia/Makefile
gst/rtp/Makefile gst/rtp/Makefile
gst/rtsp/Makefile gst/rtsp/Makefile

View file

@ -67,8 +67,8 @@ static void gst_mp3parse_class_init (GstMPEGAudioParseClass * klass);
static void gst_mp3parse_base_init (GstMPEGAudioParseClass * klass); static void gst_mp3parse_base_init (GstMPEGAudioParseClass * klass);
static void gst_mp3parse_init (GstMPEGAudioParse * mp3parse); static void gst_mp3parse_init (GstMPEGAudioParse * mp3parse);
static void gst_mp3parse_chain (GstPad * pad, GstData * _data); static GstFlowReturn gst_mp3parse_chain (GstPad * pad, GstBuffer * buffer);
static long bpf_from_header (GstMPEGAudioParse * parse, unsigned long header);
static int head_check (unsigned long head); static int head_check (unsigned long head);
static void gst_mp3parse_set_property (GObject * object, guint prop_id, static void gst_mp3parse_set_property (GObject * object, guint prop_id,
@ -239,14 +239,18 @@ gst_mp3parse_class_init (GstMPEGAudioParseClass * klass)
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SKIP, g_param_spec_int ("skip", "skip", "skip", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BIT_RATE, g_param_spec_int ("bitrate", "Bitrate", "Bit Rate", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */
parent_class = g_type_class_ref (GST_TYPE_ELEMENT); parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gobject_class->set_property = gst_mp3parse_set_property; gobject_class->set_property = gst_mp3parse_set_property;
gobject_class->get_property = gst_mp3parse_get_property; gobject_class->get_property = gst_mp3parse_get_property;
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SKIP,
g_param_spec_int ("skip", "skip", "skip",
G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BIT_RATE,
g_param_spec_int ("bitrate", "Bitrate", "Bit Rate",
G_MININT, G_MAXINT, 0, G_PARAM_READABLE));
gstelement_class->change_state = gst_mp3parse_change_state; gstelement_class->change_state = gst_mp3parse_change_state;
} }
@ -256,16 +260,14 @@ gst_mp3parse_init (GstMPEGAudioParse * mp3parse)
mp3parse->sinkpad = mp3parse->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_template (gst_static_pad_template_get
(&mp3_sink_template), "sink"); (&mp3_sink_template), "sink");
gst_element_add_pad (GST_ELEMENT (mp3parse), mp3parse->sinkpad);
gst_pad_set_chain_function (mp3parse->sinkpad, gst_mp3parse_chain); gst_pad_set_chain_function (mp3parse->sinkpad, gst_mp3parse_chain);
gst_element_set_loop_function (GST_ELEMENT (mp3parse), NULL); gst_element_add_pad (GST_ELEMENT (mp3parse), mp3parse->sinkpad);
mp3parse->srcpad = mp3parse->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_template (gst_static_pad_template_get
(&mp3_src_template), "src"); (&mp3_src_template), "src");
gst_pad_use_fixed_caps (mp3parse->srcpad);
gst_element_add_pad (GST_ELEMENT (mp3parse), mp3parse->srcpad); gst_element_add_pad (GST_ELEMENT (mp3parse), mp3parse->srcpad);
gst_pad_use_explicit_caps (mp3parse->srcpad);
/*gst_pad_set_type_id(mp3parse->srcpad, mp3frametype); */ /*gst_pad_set_type_id(mp3parse->srcpad, mp3frametype); */
mp3parse->partialbuf = NULL; mp3parse->partialbuf = NULL;
@ -275,10 +277,10 @@ gst_mp3parse_init (GstMPEGAudioParse * mp3parse)
mp3parse->rate = mp3parse->channels = mp3parse->layer = -1; mp3parse->rate = mp3parse->channels = mp3parse->layer = -1;
} }
static void /* FIXME, use adapter */
gst_mp3parse_chain (GstPad * pad, GstData * _data) static GstFlowReturn
gst_mp3parse_chain (GstPad * pad, GstBuffer * buf)
{ {
GstBuffer *buf = GST_BUFFER (_data);
GstMPEGAudioParse *mp3parse; GstMPEGAudioParse *mp3parse;
guchar *data; guchar *data;
glong size, offset = 0; glong size, offset = 0;
@ -287,26 +289,12 @@ gst_mp3parse_chain (GstPad * pad, GstData * _data)
GstBuffer *outbuf; GstBuffer *outbuf;
guint64 last_ts; guint64 last_ts;
g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_PAD (pad));
g_return_if_fail (buf != NULL);
/* g_return_if_fail(GST_IS_BUFFER(buf)); */
mp3parse = GST_MP3PARSE (gst_pad_get_parent (pad)); mp3parse = GST_MP3PARSE (gst_pad_get_parent (pad));
GST_DEBUG ("mp3parse: received buffer of %d bytes", GST_BUFFER_SIZE (buf)); GST_DEBUG ("mp3parse: received buffer of %d bytes", GST_BUFFER_SIZE (buf));
last_ts = GST_BUFFER_TIMESTAMP (buf); last_ts = GST_BUFFER_TIMESTAMP (buf);
/* FIXME, do flush */
/*
if (mp3parse->partialbuf) {
gst_buffer_unref(mp3parse->partialbuf);
mp3parse->partialbuf = NULL;
}
mp3parse->in_flush = TRUE;
*/
/* if we have something left from the previous frame */ /* if we have something left from the previous frame */
if (mp3parse->partialbuf) { if (mp3parse->partialbuf) {
GstBuffer *newbuf; GstBuffer *newbuf;
@ -332,15 +320,19 @@ gst_mp3parse_chain (GstPad * pad, GstData * _data)
/* search for a possible start byte */ /* search for a possible start byte */
for (; ((offset < size - 4) && (data[offset] != 0xff)); offset++) for (; ((offset < size - 4) && (data[offset] != 0xff)); offset++)
skipped++; skipped++;
if (skipped && !mp3parse->in_flush) { if (skipped) {
GST_DEBUG ("mp3parse: **** now at %ld skipped %d bytes", offset, skipped); GST_DEBUG ("mp3parse: **** now at %ld skipped %d bytes", offset, skipped);
} }
/* construct the header word */ /* construct the header word */
header = GST_READ_UINT32_BE (data + offset); header = GST_READ_UINT32_BE (data + offset);
/* if it's a valid header, go ahead and send off the frame */ /* if it's a valid header, go ahead and send off the frame */
if (head_check (header)) { if (head_check (header)) {
/* calculate the bpf of the frame */ guint bitrate = 0, layer = 0, rate = 0, channels = 0;
bpf = bpf_from_header (mp3parse, header);
if (!(bpf = mp3_type_frame_length_from_header (header, &layer,
&channels, &bitrate, &rate))) {
g_error ("Header failed internal error");
}
/******************************************************************************** /********************************************************************************
* robust seek support * robust seek support
@ -387,18 +379,13 @@ gst_mp3parse_chain (GstPad * pad, GstData * _data)
bpf); bpf);
break; break;
} else { } else {
guint bitrate, layer, rate, channels;
if (!mp3_type_frame_length_from_header (header, &layer,
&channels, &bitrate, &rate)) {
g_error ("Header failed internal error");
}
if (channels != mp3parse->channels || if (channels != mp3parse->channels ||
rate != mp3parse->rate || rate != mp3parse->rate ||
layer != mp3parse->layer || bitrate != mp3parse->bit_rate) { layer != mp3parse->layer || bitrate != mp3parse->bit_rate) {
GstCaps *caps = mp3_caps_create (layer, channels, bitrate, rate); GstCaps *caps = mp3_caps_create (layer, channels, bitrate, rate);
gst_pad_set_explicit_caps (mp3parse->srcpad, caps); gst_pad_set_caps (mp3parse->srcpad, caps);
gst_caps_unref (caps);
mp3parse->channels = channels; mp3parse->channels = channels;
mp3parse->layer = layer; mp3parse->layer = layer;
@ -412,23 +399,18 @@ gst_mp3parse_chain (GstPad * pad, GstData * _data)
if (mp3parse->skip == 0) { if (mp3parse->skip == 0) {
GST_DEBUG ("mp3parse: pushing buffer of %d bytes", GST_DEBUG ("mp3parse: pushing buffer of %d bytes",
GST_BUFFER_SIZE (outbuf)); GST_BUFFER_SIZE (outbuf));
if (mp3parse->in_flush) {
/* FIXME do some sort of flush event */
mp3parse->in_flush = FALSE;
}
GST_BUFFER_TIMESTAMP (outbuf) = last_ts; GST_BUFFER_TIMESTAMP (outbuf) = last_ts;
if (mp3parse->layer == 1) { if (mp3parse->layer == 1) {
GST_BUFFER_DURATION (outbuf) = 384 * GST_SECOND / mp3parse->rate; GST_BUFFER_DURATION (outbuf) = 384 * GST_SECOND / mp3parse->rate;
} else { } else {
GST_BUFFER_DURATION (outbuf) = 1152 * GST_SECOND / mp3parse->rate; GST_BUFFER_DURATION (outbuf) = 1152 * GST_SECOND / mp3parse->rate;
} }
if (GST_PAD_CAPS (mp3parse->srcpad) != NULL) { gst_buffer_set_caps (outbuf, GST_PAD_CAPS (pad));
gst_pad_push (mp3parse->srcpad, GST_DATA (outbuf));
} else { gst_pad_push (mp3parse->srcpad, outbuf);
GST_DEBUG ("No capsnego yet, delaying buffer push");
gst_buffer_unref (outbuf);
}
} else { } else {
GST_DEBUG ("mp3parse: skipping buffer of %d bytes", GST_DEBUG ("mp3parse: skipping buffer of %d bytes",
GST_BUFFER_SIZE (outbuf)); GST_BUFFER_SIZE (outbuf));
@ -438,7 +420,6 @@ gst_mp3parse_chain (GstPad * pad, GstData * _data)
} }
} else { } else {
offset++; offset++;
if (!mp3parse->in_flush)
GST_DEBUG ("mp3parse: *** wrong header, skipping byte (FIXME?)"); GST_DEBUG ("mp3parse: *** wrong header, skipping byte (FIXME?)");
} }
} }
@ -457,19 +438,10 @@ gst_mp3parse_chain (GstPad * pad, GstData * _data)
gst_buffer_unref (mp3parse->partialbuf); gst_buffer_unref (mp3parse->partialbuf);
mp3parse->partialbuf = NULL; mp3parse->partialbuf = NULL;
} }
}
static long gst_object_unref (mp3parse);
bpf_from_header (GstMPEGAudioParse * parse, unsigned long header)
{
guint bitrate, layer, rate, channels, length;
if (!(length = mp3_type_frame_length_from_header (header, &layer, return GST_FLOW_OK;
&channels, &bitrate, &rate))) {
return 0;
}
return length;
} }
static gboolean static gboolean
@ -561,8 +533,8 @@ static GstElementStateReturn
gst_mp3parse_change_state (GstElement * element) gst_mp3parse_change_state (GstElement * element)
{ {
GstMPEGAudioParse *src; GstMPEGAudioParse *src;
GstElementStateReturn result;
g_return_val_if_fail (GST_IS_MP3PARSE (element), GST_STATE_FAILURE);
src = GST_MP3PARSE (element); src = GST_MP3PARSE (element);
switch (GST_STATE_TRANSITION (element)) { switch (GST_STATE_TRANSITION (element)) {
@ -575,10 +547,9 @@ gst_mp3parse_change_state (GstElement * element)
break; break;
} }
if (GST_ELEMENT_CLASS (parent_class)->change_state) result = GST_ELEMENT_CLASS (parent_class)->change_state (element);
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
return GST_STATE_SUCCESS; return result;
} }
static gboolean static gboolean

View file

@ -24,11 +24,7 @@
#include <gst/gst.h> #include <gst/gst.h>
G_BEGIN_DECLS
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GST_TYPE_MP3PARSE \ #define GST_TYPE_MP3PARSE \
(gst_mp3parse_get_type()) (gst_mp3parse_get_type())
@ -62,10 +58,6 @@ struct _GstMPEGAudioParseClass {
GType gst_mp3parse_get_type(void); GType gst_mp3parse_get_type(void);
G_END_DECLS
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __MP3PARSE_H__ */ #endif /* __MP3PARSE_H__ */