mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:56:14 +00:00
Fix compile warning.
Original commit message from CVS: * configure.ac: * ext/amrnb/amrnbparse.c: (gst_amrnbparse_read_header): Fix compile warning. * ext/lame/gstlame.c: (gst_lame_class_init), (gst_lame_src_getcaps), (gst_lame_src_setcaps), (gst_lame_sink_setcaps), (gst_lame_init), (gst_lame_sink_event), (gst_lame_chain), (gst_lame_change_state): * ext/lame/gstlame.h: Port lame plugin
This commit is contained in:
parent
841d43b9e3
commit
4bd0e6e60b
5 changed files with 250 additions and 151 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2005-08-16 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
|
* configure.ac:
|
||||||
|
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_read_header):
|
||||||
|
Fix compile warning.
|
||||||
|
|
||||||
|
* ext/lame/gstlame.c: (gst_lame_class_init),
|
||||||
|
(gst_lame_src_getcaps), (gst_lame_src_setcaps),
|
||||||
|
(gst_lame_sink_setcaps), (gst_lame_init), (gst_lame_sink_event),
|
||||||
|
(gst_lame_chain), (gst_lame_change_state):
|
||||||
|
* ext/lame/gstlame.h:
|
||||||
|
Port lame plugin
|
||||||
|
|
||||||
2005-08-16 Andy Wingo <wingo@pobox.com>
|
2005-08-16 Andy Wingo <wingo@pobox.com>
|
||||||
|
|
||||||
* ext/raw1394/gstdv1394src.c (gst_dv1394src_iso_receive): Note
|
* ext/raw1394/gstdv1394src.c (gst_dv1394src_iso_receive): Note
|
||||||
|
|
28
configure.ac
28
configure.ac
|
@ -265,8 +265,7 @@ dnl =================================================
|
||||||
# we set the defaults always to make sure we have non-empty variables
|
# we set the defaults always to make sure we have non-empty variables
|
||||||
# for the Makefile
|
# for the Makefile
|
||||||
|
|
||||||
PKG_CHECK_MODULES(LIBOIL, liboil-0.2, HAVE_LIBOIL=yes, HAVE_LIBOIL=no)
|
PKG_CHECK_MODULES(LIBOIL, liboil-0.3 >= 0.3.0, HAVE_LIBOIL=yes, HAVE_LIBOIL=no)
|
||||||
#PKG_CHECK_MODULES(LIBOIL, liboil-0.3 >= 0.3.0, HAVE_LIBOIL=yes, HAVE_LIBOIL=no)
|
|
||||||
AC_SUBST(LIBOIL_CFLAGS)
|
AC_SUBST(LIBOIL_CFLAGS)
|
||||||
AC_SUBST(LIBOIL_LIBS)
|
AC_SUBST(LIBOIL_LIBS)
|
||||||
if test "x${HAVE_LIBOIL}" = xyes ; then
|
if test "x${HAVE_LIBOIL}" = xyes ; then
|
||||||
|
@ -411,6 +410,30 @@ return 0;
|
||||||
AC_SUBST(FAAD_LIBS)
|
AC_SUBST(FAAD_LIBS)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
dnl *** lame ***
|
||||||
|
translit(dnm, m, l) AM_CONDITIONAL(USE_LAME, true)
|
||||||
|
GST_CHECK_FEATURE(LAME, [lame mp3 encoder library], lame, [
|
||||||
|
GST_CHECK_LIBHEADER(LAME, mp3lame, lame_init, -lm, lame/lame.h,
|
||||||
|
[
|
||||||
|
HAVE_LAME="yes"
|
||||||
|
LAME_LIBS="-lmp3lame -lm"
|
||||||
|
dnl is lame presets available
|
||||||
|
LAME_CFLAGS=""
|
||||||
|
AC_TRY_RUN([
|
||||||
|
#include <lame/lame.h>
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
printf("%d\n", MEDIUM);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[LAME_CFLAGS="-DGSTLAME_PRESET"],
|
||||||
|
[LAME_CFLAGS=""]
|
||||||
|
)
|
||||||
|
AC_SUBST(LAME_CFLAGS)
|
||||||
|
AC_SUBST(LAME_LIBS)
|
||||||
|
])
|
||||||
|
])
|
||||||
|
|
||||||
dnl *** libcaca ***
|
dnl *** libcaca ***
|
||||||
translit(dnm, m, l) AM_CONDITIONAL(USE_LIBCACA, true)
|
translit(dnm, m, l) AM_CONDITIONAL(USE_LIBCACA, true)
|
||||||
|
@ -629,6 +652,7 @@ ext/Makefile
|
||||||
ext/aalib/Makefile
|
ext/aalib/Makefile
|
||||||
ext/dv/Makefile
|
ext/dv/Makefile
|
||||||
ext/gconf/Makefile
|
ext/gconf/Makefile
|
||||||
|
ext/lame/Makefile
|
||||||
ext/libcaca/Makefile
|
ext/libcaca/Makefile
|
||||||
ext/libpng/Makefile
|
ext/libpng/Makefile
|
||||||
ext/mad/Makefile
|
ext/mad/Makefile
|
||||||
|
|
|
@ -322,7 +322,7 @@ gst_amrnbparse_read_header (GstAmrnbParse * amrnbparse)
|
||||||
{
|
{
|
||||||
GstBuffer *buffer;
|
GstBuffer *buffer;
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
gint8 *data;
|
guint8 *data;
|
||||||
gint size;
|
gint size;
|
||||||
|
|
||||||
ret =
|
ret =
|
||||||
|
|
|
@ -35,7 +35,7 @@ static GstElementDetails gst_lame_details = {
|
||||||
"L.A.M.E. mp3 encoder",
|
"L.A.M.E. mp3 encoder",
|
||||||
"Codec/Encoder/Audio",
|
"Codec/Encoder/Audio",
|
||||||
"High-quality free MP3 encoder",
|
"High-quality free MP3 encoder",
|
||||||
"Erik Walthinsen <omega@cse.ogi.edu>",
|
"Erik Walthinsen <omega@cse.ogi.edu>, " "Wim Taymans <wim@fluendo.com>",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* LAME can do MPEG-1, MPEG-2, and MPEG-2.5, so it has 9 possible
|
/* LAME can do MPEG-1, MPEG-2, and MPEG-2.5, so it has 9 possible
|
||||||
|
@ -230,7 +230,8 @@ static void gst_lame_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
static void gst_lame_get_property (GObject * object, guint prop_id,
|
static void gst_lame_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
GValue * value, GParamSpec * pspec);
|
||||||
static void gst_lame_chain (GstPad * pad, GstData * _data);
|
static gboolean gst_lame_sink_event (GstPad * pad, GstEvent * event);
|
||||||
|
static GstFlowReturn gst_lame_chain (GstPad * pad, GstBuffer * buf);
|
||||||
static gboolean gst_lame_setup (GstLame * lame);
|
static gboolean gst_lame_setup (GstLame * lame);
|
||||||
static GstElementStateReturn gst_lame_change_state (GstElement * element);
|
static GstElementStateReturn gst_lame_change_state (GstElement * element);
|
||||||
|
|
||||||
|
@ -294,6 +295,9 @@ gst_lame_class_init (GstLameClass * klass)
|
||||||
|
|
||||||
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
|
gobject_class->set_property = gst_lame_set_property;
|
||||||
|
gobject_class->get_property = gst_lame_get_property;
|
||||||
|
|
||||||
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BITRATE,
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BITRATE,
|
||||||
g_param_spec_int ("bitrate", "Bitrate (kb/s)", "Bitrate in kbit/sec",
|
g_param_spec_int ("bitrate", "Bitrate (kb/s)", "Bitrate in kbit/sec",
|
||||||
8, 320, 128, G_PARAM_READWRITE));
|
8, 320, 128, G_PARAM_READWRITE));
|
||||||
|
@ -407,8 +411,6 @@ gst_lame_class_init (GstLameClass * klass)
|
||||||
g_param_spec_enum ("preset", "Lame Preset", "Lame Preset",
|
g_param_spec_enum ("preset", "Lame Preset", "Lame Preset",
|
||||||
GST_TYPE_LAME_PRESET, 0, G_PARAM_READWRITE));
|
GST_TYPE_LAME_PRESET, 0, G_PARAM_READWRITE));
|
||||||
#endif
|
#endif
|
||||||
gobject_class->set_property = gst_lame_set_property;
|
|
||||||
gobject_class->get_property = gst_lame_get_property;
|
|
||||||
|
|
||||||
gstelement_class->change_state = gst_lame_change_state;
|
gstelement_class->change_state = gst_lame_change_state;
|
||||||
}
|
}
|
||||||
|
@ -423,22 +425,25 @@ gst_lame_src_getcaps (GstPad * pad)
|
||||||
|
|
||||||
if (!gst_lame_setup (lame)) {
|
if (!gst_lame_setup (lame)) {
|
||||||
GST_DEBUG_OBJECT (lame, "problem doing lame setup");
|
GST_DEBUG_OBJECT (lame, "problem doing lame setup");
|
||||||
return
|
caps =
|
||||||
gst_caps_copy (gst_pad_template_get_caps (gst_static_pad_template_get
|
gst_caps_copy (gst_pad_template_get_caps (gst_static_pad_template_get
|
||||||
(&gst_lame_src_template)));
|
(&gst_lame_src_template)));
|
||||||
|
} else {
|
||||||
|
caps = gst_caps_new_simple ("audio/mpeg",
|
||||||
|
"mpegversion", G_TYPE_INT, 1,
|
||||||
|
"layer", G_TYPE_INT, 3,
|
||||||
|
"rate", G_TYPE_INT, lame_get_out_samplerate (lame->lgf),
|
||||||
|
"channels", G_TYPE_INT, lame->num_channels, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
caps = gst_caps_new_simple ("audio/mpeg",
|
gst_object_unref (lame);
|
||||||
"mpegversion", G_TYPE_INT, 1,
|
|
||||||
"layer", G_TYPE_INT, 3,
|
|
||||||
"rate", G_TYPE_INT, lame_get_out_samplerate (lame->lgf),
|
|
||||||
"channels", G_TYPE_INT, lame->num_channels, NULL);
|
|
||||||
|
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstPadLinkReturn
|
#if 0
|
||||||
gst_lame_src_link (GstPad * pad, const GstCaps * caps)
|
static gboolean
|
||||||
|
gst_lame_src_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstLame *lame;
|
GstLame *lame;
|
||||||
gint out_samplerate;
|
gint out_samplerate;
|
||||||
|
@ -446,15 +451,17 @@ gst_lame_src_link (GstPad * pad, const GstCaps * caps)
|
||||||
GstCaps *othercaps, *channelcaps;
|
GstCaps *othercaps, *channelcaps;
|
||||||
GstPadLinkReturn result;
|
GstPadLinkReturn result;
|
||||||
|
|
||||||
lame = GST_LAME (gst_pad_get_parent (pad));
|
lame = GST_LAME (GST_PAD_PARENT (pad));
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
if (!gst_structure_get_int (structure, "rate", &out_samplerate) ||
|
/* we need channels and rate */
|
||||||
!gst_structure_get_int (structure, "channels", &lame->num_channels))
|
if (!gst_structure_get_int (structure, "rate", &out_samplerate));
|
||||||
g_return_val_if_reached (GST_PAD_LINK_REFUSED);
|
goto no_rate;
|
||||||
|
if (!gst_structure_get_int (structure, "channels", &lame->num_channels));
|
||||||
|
goto no_channels;
|
||||||
|
|
||||||
if (lame_set_out_samplerate (lame->lgf, out_samplerate) != 0)
|
if (lame_set_out_samplerate (lame->lgf, out_samplerate) != 0)
|
||||||
return GST_PAD_LINK_REFUSED;
|
goto could_not_set_samplerate;
|
||||||
|
|
||||||
/* we don't do channel conversion */
|
/* we don't do channel conversion */
|
||||||
channelcaps = gst_caps_new_simple ("audio/x-raw-int", "channels", G_TYPE_INT,
|
channelcaps = gst_caps_new_simple ("audio/x-raw-int", "channels", G_TYPE_INT,
|
||||||
|
@ -480,10 +487,27 @@ gst_lame_src_link (GstPad * pad, const GstCaps * caps)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
static GstPadLinkReturn
|
no_rate:
|
||||||
gst_lame_sink_link (GstPad * pad, const GstCaps * caps)
|
{
|
||||||
|
GST_DEBUG ("no rate specified in caps");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
no_channels:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("no channels specified in caps");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
could_not_set_samplerate:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("could not set samplerate");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_lame_sink_setcaps (GstPad * pad, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstLame *lame;
|
GstLame *lame;
|
||||||
gint out_samplerate;
|
gint out_samplerate;
|
||||||
|
@ -493,16 +517,15 @@ gst_lame_sink_link (GstPad * pad, const GstCaps * caps)
|
||||||
lame = GST_LAME (gst_pad_get_parent (pad));
|
lame = GST_LAME (gst_pad_get_parent (pad));
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
if (!gst_structure_get_int (structure, "rate", &lame->samplerate) ||
|
if (!gst_structure_get_int (structure, "rate", &lame->samplerate))
|
||||||
!gst_structure_get_int (structure, "channels", &lame->num_channels))
|
goto no_rate;
|
||||||
g_return_val_if_reached (GST_PAD_LINK_REFUSED);
|
if (!gst_structure_get_int (structure, "channels", &lame->num_channels))
|
||||||
|
goto no_channels;
|
||||||
|
|
||||||
|
/* let lame choose a default samplerate */
|
||||||
lame_set_out_samplerate (lame->lgf, 0);
|
lame_set_out_samplerate (lame->lgf, 0);
|
||||||
if (!gst_lame_setup (lame)) {
|
if (!gst_lame_setup (lame))
|
||||||
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
|
goto setup_failed;
|
||||||
("could not initialize encoder (wrong parameters?)"));
|
|
||||||
return GST_PAD_LINK_REFUSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
out_samplerate = lame_get_out_samplerate (lame->lgf);
|
out_samplerate = lame_get_out_samplerate (lame->lgf);
|
||||||
othercaps =
|
othercaps =
|
||||||
|
@ -512,7 +535,30 @@ gst_lame_sink_link (GstPad * pad, const GstCaps * caps)
|
||||||
"channels", G_TYPE_INT, lame->num_channels,
|
"channels", G_TYPE_INT, lame->num_channels,
|
||||||
"rate", G_TYPE_INT, out_samplerate, NULL);
|
"rate", G_TYPE_INT, out_samplerate, NULL);
|
||||||
|
|
||||||
return gst_pad_try_set_caps (lame->srcpad, othercaps);
|
/* and use these caps */
|
||||||
|
gst_pad_set_caps (lame->srcpad, othercaps);
|
||||||
|
gst_caps_unref (othercaps);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
no_rate:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
|
||||||
|
("no rate specified in input"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
no_channels:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
|
||||||
|
("no channels specified in input"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
setup_failed:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
|
||||||
|
("could not initialize encoder (wrong parameters?)"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -523,17 +569,16 @@ gst_lame_init (GstLame * lame)
|
||||||
lame->sinkpad =
|
lame->sinkpad =
|
||||||
gst_pad_new_from_template (gst_static_pad_template_get
|
gst_pad_new_from_template (gst_static_pad_template_get
|
||||||
(&gst_lame_sink_template), "sink");
|
(&gst_lame_sink_template), "sink");
|
||||||
gst_element_add_pad (GST_ELEMENT (lame), lame->sinkpad);
|
gst_pad_set_event_function (lame->sinkpad, gst_lame_sink_event);
|
||||||
gst_pad_set_chain_function (lame->sinkpad, gst_lame_chain);
|
gst_pad_set_chain_function (lame->sinkpad, gst_lame_chain);
|
||||||
gst_pad_set_link_function (lame->sinkpad, gst_lame_sink_link);
|
gst_pad_set_setcaps_function (lame->sinkpad, gst_lame_sink_setcaps);
|
||||||
|
gst_element_add_pad (GST_ELEMENT (lame), lame->sinkpad);
|
||||||
|
|
||||||
lame->srcpad =
|
lame->srcpad =
|
||||||
gst_pad_new_from_template (gst_static_pad_template_get
|
gst_pad_new_from_template (gst_static_pad_template_get
|
||||||
(&gst_lame_src_template), "src");
|
(&gst_lame_src_template), "src");
|
||||||
gst_element_add_pad (GST_ELEMENT (lame), lame->srcpad);
|
|
||||||
gst_pad_set_link_function (lame->srcpad, gst_lame_src_link);
|
|
||||||
gst_pad_set_getcaps_function (lame->srcpad, gst_lame_src_getcaps);
|
gst_pad_set_getcaps_function (lame->srcpad, gst_lame_src_getcaps);
|
||||||
GST_FLAG_SET (lame, GST_ELEMENT_EVENT_AWARE);
|
gst_element_add_pad (GST_ELEMENT (lame), lame->srcpad);
|
||||||
|
|
||||||
GST_DEBUG ("setting up lame encoder");
|
GST_DEBUG ("setting up lame encoder");
|
||||||
lame->lgf = lame_init ();
|
lame->lgf = lame_init ();
|
||||||
|
@ -581,7 +626,6 @@ gst_lame_init (GstLame * lame)
|
||||||
|
|
||||||
id3tag_init (lame->lgf);
|
id3tag_init (lame->lgf);
|
||||||
|
|
||||||
lame->newmediacount = 0;
|
|
||||||
GST_DEBUG_OBJECT (lame, "done initializing");
|
GST_DEBUG_OBJECT (lame, "done initializing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -912,116 +956,124 @@ gst_lame_get_property (GObject * object, guint prop_id, GValue * value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
gst_lame_chain (GstPad * pad, GstData * _data)
|
gst_lame_sink_event (GstPad * pad, GstEvent * event)
|
||||||
|
{
|
||||||
|
GstLame *lame;
|
||||||
|
|
||||||
|
lame = GST_LAME (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
|
case GST_EVENT_EOS:
|
||||||
|
GST_DEBUG_OBJECT (lame, "handling EOS event");
|
||||||
|
/* FIXME, push last data packet */
|
||||||
|
|
||||||
|
gst_pad_push_event (lame->srcpad, event);
|
||||||
|
break;
|
||||||
|
case GST_EVENT_FLUSH_START:
|
||||||
|
GST_DEBUG_OBJECT (lame, "handling FLUSH start event");
|
||||||
|
/* forward event */
|
||||||
|
gst_pad_push_event (lame->srcpad, event);
|
||||||
|
|
||||||
|
/* make streaming stop */
|
||||||
|
GST_STREAM_LOCK (pad);
|
||||||
|
GST_STREAM_UNLOCK (pad);
|
||||||
|
break;
|
||||||
|
case GST_EVENT_FLUSH_STOP:
|
||||||
|
{
|
||||||
|
guchar *mp3_data = NULL;
|
||||||
|
gint mp3_buffer_size, mp3_size = 0;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (lame, "handling FLUSH stop event");
|
||||||
|
|
||||||
|
/* clear buffers */
|
||||||
|
GST_STREAM_LOCK (pad);
|
||||||
|
mp3_buffer_size = 7200;
|
||||||
|
mp3_data = g_malloc (mp3_buffer_size);
|
||||||
|
mp3_size = lame_encode_flush (lame->lgf, mp3_data, mp3_buffer_size);
|
||||||
|
|
||||||
|
gst_pad_push_event (lame->srcpad, event);
|
||||||
|
GST_STREAM_UNLOCK (pad);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GST_EVENT_TAG:
|
||||||
|
GST_DEBUG_OBJECT (lame, "handling TAG event");
|
||||||
|
if (lame->tags) {
|
||||||
|
GstTagList *taglist;
|
||||||
|
|
||||||
|
gst_event_parse_tag (event, &taglist),
|
||||||
|
gst_tag_list_insert (lame->tags, taglist,
|
||||||
|
gst_tag_setter_get_merge_mode (GST_TAG_SETTER (lame)));
|
||||||
|
} else {
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
gst_pad_push_event (lame->srcpad, event);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gst_pad_push_event (lame->srcpad, event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_lame_chain (GstPad * pad, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstBuffer *buf = GST_BUFFER (_data);
|
|
||||||
GstLame *lame;
|
GstLame *lame;
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
gchar *mp3_data = NULL;
|
guchar *mp3_data = NULL;
|
||||||
gint mp3_buffer_size, mp3_size = 0;
|
gint mp3_buffer_size, mp3_size = 0;
|
||||||
gboolean eos = FALSE;
|
gint64 duration;
|
||||||
|
GstFlowReturn result;
|
||||||
|
|
||||||
lame = GST_LAME (gst_pad_get_parent (pad));
|
lame = GST_LAME (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
GST_LOG_OBJECT (lame, "entered chain");
|
GST_LOG_OBJECT (lame, "entered chain");
|
||||||
|
|
||||||
if (GST_IS_EVENT (buf)) {
|
if (!lame->initialized)
|
||||||
switch (GST_EVENT_TYPE (buf)) {
|
goto not_initialized;
|
||||||
case GST_EVENT_EOS:
|
|
||||||
GST_DEBUG_OBJECT (lame, "handling EOS event");
|
|
||||||
eos = TRUE;
|
|
||||||
case GST_EVENT_FLUSH:
|
|
||||||
GST_DEBUG_OBJECT (lame, "handling FLUSH event");
|
|
||||||
mp3_buffer_size = 7200;
|
|
||||||
mp3_data = g_malloc (mp3_buffer_size);
|
|
||||||
|
|
||||||
mp3_size = lame_encode_flush (lame->lgf, mp3_data, mp3_buffer_size);
|
/* allocate space for output */
|
||||||
gst_event_unref (GST_EVENT (buf));
|
mp3_buffer_size =
|
||||||
break;
|
((GST_BUFFER_SIZE (buf) / (2 + lame->num_channels)) * 1.25) + 7200;
|
||||||
case GST_EVENT_TAG:
|
mp3_data = g_malloc (mp3_buffer_size);
|
||||||
GST_DEBUG_OBJECT (lame, "handling TAG event");
|
|
||||||
if (lame->tags) {
|
|
||||||
gst_tag_list_insert (lame->tags,
|
|
||||||
gst_event_tag_get_list (GST_EVENT (buf)),
|
|
||||||
gst_tag_setter_get_merge_mode (GST_TAG_SETTER (lame)));
|
|
||||||
} else {
|
|
||||||
g_assert_not_reached ();
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_pad_event_default (pad, GST_EVENT (buf));
|
/* lame seems to be too stupid to get mono interleaved going */
|
||||||
break;
|
if (lame->num_channels == 1) {
|
||||||
case GST_EVENT_DISCONTINUOUS:
|
mp3_size = lame_encode_buffer (lame->lgf,
|
||||||
if (GST_EVENT_DISCONT_NEW_MEDIA (GST_EVENT (buf))) {
|
(short int *) (GST_BUFFER_DATA (buf)),
|
||||||
/* do not re-initialise if it is first new media discont */
|
(short int *) (GST_BUFFER_DATA (buf)),
|
||||||
if (lame->newmediacount++ > 0) {
|
GST_BUFFER_SIZE (buf) / 2, mp3_data, mp3_buffer_size);
|
||||||
lame_close (lame->lgf);
|
|
||||||
lame->lgf = lame_init ();
|
|
||||||
lame->initialized = FALSE;
|
|
||||||
lame->last_ts = GST_CLOCK_TIME_NONE;
|
|
||||||
|
|
||||||
gst_lame_setup (lame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gst_pad_event_default (pad, GST_EVENT (buf));
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
gst_pad_event_default (pad, GST_EVENT (buf));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
gint64 duration;
|
mp3_size = lame_encode_buffer_interleaved (lame->lgf,
|
||||||
|
(short int *) (GST_BUFFER_DATA (buf)),
|
||||||
if (!lame->initialized) {
|
GST_BUFFER_SIZE (buf) / 2 / lame->num_channels,
|
||||||
gst_buffer_unref (buf);
|
mp3_data, mp3_buffer_size);
|
||||||
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
|
|
||||||
("encoder not initialized (input is not audio?)"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* allocate space for output */
|
|
||||||
mp3_buffer_size =
|
|
||||||
((GST_BUFFER_SIZE (buf) / (2 + lame->num_channels)) * 1.25) + 7200;
|
|
||||||
mp3_data = g_malloc (mp3_buffer_size);
|
|
||||||
|
|
||||||
/* lame seems to be too stupid to get mono interleaved going */
|
|
||||||
if (lame->num_channels == 1) {
|
|
||||||
mp3_size = lame_encode_buffer (lame->lgf,
|
|
||||||
(short int *) (GST_BUFFER_DATA (buf)),
|
|
||||||
(short int *) (GST_BUFFER_DATA (buf)),
|
|
||||||
GST_BUFFER_SIZE (buf) / 2, mp3_data, mp3_buffer_size);
|
|
||||||
} else {
|
|
||||||
mp3_size = lame_encode_buffer_interleaved (lame->lgf,
|
|
||||||
(short int *) (GST_BUFFER_DATA (buf)),
|
|
||||||
GST_BUFFER_SIZE (buf) / 2 / lame->num_channels,
|
|
||||||
mp3_data, mp3_buffer_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_LOG_OBJECT (lame, "encoded %d bytes of audio to %d bytes of mp3",
|
|
||||||
GST_BUFFER_SIZE (buf), mp3_size);
|
|
||||||
|
|
||||||
duration = (GST_SECOND * GST_BUFFER_SIZE (buf) /
|
|
||||||
(2 * lame->samplerate * lame->num_channels));
|
|
||||||
|
|
||||||
if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE &&
|
|
||||||
GST_BUFFER_DURATION (buf) != duration)
|
|
||||||
GST_DEBUG_OBJECT (lame, "incoming buffer had incorrect duration "
|
|
||||||
GST_TIME_FORMAT "outgoing buffer will have correct duration "
|
|
||||||
GST_TIME_FORMAT,
|
|
||||||
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_TIME_ARGS (duration));
|
|
||||||
|
|
||||||
if (lame->last_ts == GST_CLOCK_TIME_NONE) {
|
|
||||||
lame->last_ts = GST_BUFFER_TIMESTAMP (buf);
|
|
||||||
lame->last_offs = GST_BUFFER_OFFSET (buf);
|
|
||||||
lame->last_duration = duration;
|
|
||||||
} else {
|
|
||||||
lame->last_duration += duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_buffer_unref (buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (lame, "encoded %d bytes of audio to %d bytes of mp3",
|
||||||
|
GST_BUFFER_SIZE (buf), mp3_size);
|
||||||
|
|
||||||
|
duration = (GST_SECOND * GST_BUFFER_SIZE (buf) /
|
||||||
|
(2 * lame->samplerate * lame->num_channels));
|
||||||
|
|
||||||
|
if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE &&
|
||||||
|
GST_BUFFER_DURATION (buf) != duration)
|
||||||
|
GST_DEBUG_OBJECT (lame, "incoming buffer had incorrect duration %"
|
||||||
|
GST_TIME_FORMAT "outgoing buffer will have correct duration %"
|
||||||
|
GST_TIME_FORMAT,
|
||||||
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_TIME_ARGS (duration));
|
||||||
|
|
||||||
|
if (lame->last_ts == GST_CLOCK_TIME_NONE) {
|
||||||
|
lame->last_ts = GST_BUFFER_TIMESTAMP (buf);
|
||||||
|
lame->last_offs = GST_BUFFER_OFFSET (buf);
|
||||||
|
lame->last_duration = duration;
|
||||||
|
} else {
|
||||||
|
lame->last_duration += duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_buffer_unref (buf);
|
||||||
|
|
||||||
if (mp3_size > 0) {
|
if (mp3_size > 0) {
|
||||||
outbuf = gst_buffer_new ();
|
outbuf = gst_buffer_new ();
|
||||||
GST_BUFFER_DATA (outbuf) = mp3_data;
|
GST_BUFFER_DATA (outbuf) = mp3_data;
|
||||||
|
@ -1030,16 +1082,25 @@ gst_lame_chain (GstPad * pad, GstData * _data)
|
||||||
GST_BUFFER_OFFSET (outbuf) = lame->last_offs;
|
GST_BUFFER_OFFSET (outbuf) = lame->last_offs;
|
||||||
GST_BUFFER_DURATION (outbuf) = lame->last_duration;
|
GST_BUFFER_DURATION (outbuf) = lame->last_duration;
|
||||||
|
|
||||||
gst_pad_push (lame->srcpad, GST_DATA (outbuf));
|
result = gst_pad_push (lame->srcpad, outbuf);
|
||||||
|
|
||||||
lame->last_ts = GST_CLOCK_TIME_NONE;
|
lame->last_ts = GST_CLOCK_TIME_NONE;
|
||||||
} else {
|
} else {
|
||||||
g_free (mp3_data);
|
g_free (mp3_data);
|
||||||
|
result = GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
gst_object_unref (lame);
|
||||||
|
|
||||||
if (eos) {
|
return result;
|
||||||
gst_pad_push (lame->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
|
||||||
gst_element_set_eos (GST_ELEMENT (lame));
|
/* ERRORS */
|
||||||
|
not_initialized:
|
||||||
|
{
|
||||||
|
gst_buffer_unref (buf);
|
||||||
|
GST_ELEMENT_ERROR (lame, CORE, NEGOTIATION, (NULL),
|
||||||
|
("encoder not initialized (input is not audio?)"));
|
||||||
|
gst_object_unref (lame);
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,18 +1196,26 @@ static GstElementStateReturn
|
||||||
gst_lame_change_state (GstElement * element)
|
gst_lame_change_state (GstElement * element)
|
||||||
{
|
{
|
||||||
GstLame *lame;
|
GstLame *lame;
|
||||||
|
gint transition;
|
||||||
g_return_val_if_fail (GST_IS_LAME (element), GST_STATE_FAILURE);
|
GstElementStateReturn result;
|
||||||
|
|
||||||
lame = GST_LAME (element);
|
lame = GST_LAME (element);
|
||||||
|
|
||||||
GST_DEBUG ("state pending %d", GST_STATE_PENDING (element));
|
transition = GST_STATE_TRANSITION (lame);
|
||||||
|
|
||||||
switch (GST_STATE_TRANSITION (element)) {
|
switch (transition) {
|
||||||
case GST_STATE_READY_TO_PAUSED:
|
case GST_STATE_READY_TO_PAUSED:
|
||||||
lame->last_ts = GST_CLOCK_TIME_NONE;
|
lame->last_ts = GST_CLOCK_TIME_NONE;
|
||||||
break;
|
break;
|
||||||
case GST_STATE_READY_TO_NULL:
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if we haven't failed already, give the parent class a chance to ;-) */
|
||||||
|
result = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
||||||
|
|
||||||
|
switch (transition) {
|
||||||
|
case GST_STATE_PAUSED_TO_READY:
|
||||||
if (lame->initialized) {
|
if (lame->initialized) {
|
||||||
lame_close (lame->lgf);
|
lame_close (lame->lgf);
|
||||||
lame->lgf = lame_init ();
|
lame->lgf = lame_init ();
|
||||||
|
@ -1157,11 +1226,7 @@ gst_lame_change_state (GstElement * element)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we haven't failed already, give the parent class a chance to ;-) */
|
return result;
|
||||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
||||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
||||||
|
|
||||||
return GST_STATE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
@ -100,9 +100,6 @@ struct _GstLame {
|
||||||
|
|
||||||
/* time tracker */
|
/* time tracker */
|
||||||
guint64 last_ts, last_offs, last_duration;
|
guint64 last_ts, last_offs, last_duration;
|
||||||
|
|
||||||
/* new media count */
|
|
||||||
gint16 newmediacount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstLameClass {
|
struct _GstLameClass {
|
||||||
|
|
Loading…
Reference in a new issue