From d35582a50bdf1a0657c1f7c092bc15421c3b4cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 28 Mar 2006 15:10:18 +0000 Subject: [PATCH] ext/lame/gstlame.c: On EOS, flush encoder and send remaining data. Fix return value handling in sink event function. Original commit message from CVS: * ext/lame/gstlame.c: (gst_lame_sink_event): On EOS, flush encoder and send remaining data. Fix return value handling in sink event function. --- ext/lame/gstlame.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ext/lame/gstlame.c b/ext/lame/gstlame.c index 7ea7adedcf..ef93fd4330 100644 --- a/ext/lame/gstlame.c +++ b/ext/lame/gstlame.c @@ -947,22 +947,36 @@ gst_lame_get_property (GObject * object, guint prop_id, GValue * value, static gboolean gst_lame_sink_event (GstPad * pad, GstEvent * event) { + gboolean ret; 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 */ + case GST_EVENT_EOS:{ + GstBuffer *buf; + gint size; - gst_pad_push_event (lame->srcpad, event); + GST_DEBUG_OBJECT (lame, "handling EOS event"); + buf = gst_buffer_new_and_alloc (7200); + size = lame_encode_flush (lame->lgf, GST_BUFFER_DATA (buf), 7200); + if (size > 0) { + GST_BUFFER_SIZE (buf) = size; + GST_DEBUG_OBJECT (lame, "pushing final packet of %u bytes", size); + gst_buffer_set_caps (buf, GST_PAD_CAPS (lame->srcpad)); + gst_pad_push (lame->srcpad, buf); + } else { + GST_DEBUG_OBJECT (lame, "no final packet (size=%d)", size); + gst_buffer_unref (buf); + } + + ret = gst_pad_event_default (pad, event); break; + } case GST_EVENT_FLUSH_START: GST_DEBUG_OBJECT (lame, "handling FLUSH start event"); /* forward event */ - gst_pad_push_event (lame->srcpad, event); - + ret = gst_pad_push_event (lame->srcpad, event); break; case GST_EVENT_FLUSH_STOP: { @@ -976,7 +990,7 @@ gst_lame_sink_event (GstPad * pad, GstEvent * event) 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); + ret = gst_pad_push_event (lame->srcpad, event); break; } case GST_EVENT_TAG: @@ -990,14 +1004,14 @@ gst_lame_sink_event (GstPad * pad, GstEvent * event) } else { g_assert_not_reached (); } - gst_pad_push_event (lame->srcpad, event); + ret = gst_pad_push_event (lame->srcpad, event); break; default: - gst_pad_push_event (lame->srcpad, event); + ret = gst_pad_event_default (pad, event); break; } gst_object_unref (lame); - return TRUE; + return ret; } static GstFlowReturn