diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-08-07 14:41:31 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-08-07 14:47:30 +0200 |
commit | 782965be9f6442155a3754def8dc05d8f4db0394 (patch) | |
tree | 09cd39e340088ec33e29073d8124f67dd1fb6cbc /ext/gme | |
parent | 222322e7f372397c18a9bd092be1ba8581586799 (diff) |
gmedec: Use GstAdapter instead of many buffer joins
This reduces the number of reallocations and memcpys drastically.
Also free the input data as soon as it's complete and passed to GME
as it's not needed anymore.
Diffstat (limited to 'ext/gme')
-rw-r--r-- | ext/gme/Makefile.am | 4 | ||||
-rw-r--r-- | ext/gme/gstgme.c | 35 | ||||
-rw-r--r-- | ext/gme/gstgme.h | 3 |
3 files changed, 19 insertions, 23 deletions
diff --git a/ext/gme/Makefile.am b/ext/gme/Makefile.am index c84d340ef..f9a7b139b 100644 --- a/ext/gme/Makefile.am +++ b/ext/gme/Makefile.am @@ -2,8 +2,8 @@ plugin_LTLIBRARIES = libgstgme.la libgstgme_la_SOURCES = gstgme.c -libgstgme_la_CFLAGS = $(GST_CFLAGS) $(GME_CFLAGS) -libgstgme_la_LIBADD = $(GST_LIBS) $(GME_LIBS) +libgstgme_la_CFLAGS = $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GME_CFLAGS) +libgstgme_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(GME_LIBS) libgstgme_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstgme_la_LIBTOOLFLAGS = --tag=disable-static diff --git a/ext/gme/gstgme.c b/ext/gme/gstgme.c index ff4e41d6d..e3f145c53 100644 --- a/ext/gme/gstgme.c +++ b/ext/gme/gstgme.c @@ -159,7 +159,7 @@ gst_gme_dec_init (GstGmeDec * gme, GstGmeDecClass * klass) gst_pad_use_fixed_caps (gme->srcpad); gst_element_add_pad (GST_ELEMENT (gme), gme->srcpad); - gme->buf = NULL; + gme->adapter = gst_adapter_new (); gme->player = NULL; gme->total_duration = GST_CLOCK_TIME_NONE; gme->initialized = FALSE; @@ -170,9 +170,9 @@ gst_gme_dec_dispose (GObject * object) { GstGmeDec *gme = GST_GME_DEC (object); - if (gme->buf) { - gst_buffer_unref (gme->buf); - gme->buf = NULL; + if (gme->adapter) { + gst_object_unref (gme->adapter); + gme->adapter = NULL; } } @@ -182,11 +182,7 @@ gst_gme_dec_chain (GstPad * pad, GstBuffer * buffer) GstGmeDec *gme = GST_GME_DEC (gst_pad_get_parent (pad)); /* Accumulate GME data until end-of-stream, then commence playback. */ - if (gme->buf) { - gme->buf = gst_buffer_join (gme->buf, buffer); - } else { - gme->buf = buffer; - } + gst_adapter_push (gme->adapter, buffer); gst_object_unref (gme); @@ -421,14 +417,21 @@ gme_setup (GstGmeDec * gme) gme_err_t gme_err = NULL; GstTagList *taglist; guint64 total_duration; + GstBuffer *buffer; - if (!gme->buf || !gme_negotiate (gme)) { + if (!gst_adapter_available (gme->adapter) || !gme_negotiate (gme)) { return FALSE; } + buffer = + gst_adapter_take_buffer (gme->adapter, + gst_adapter_available (gme->adapter)); + gme_err = - gme_open_data (GST_BUFFER_DATA (gme->buf), GST_BUFFER_SIZE (gme->buf), + gme_open_data (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), &gme->player, 32000); + gst_buffer_unref (buffer); + if (gme_err || !gme->player) { if (gme->player) { gme_delete (gme->player); @@ -491,11 +494,6 @@ gme_setup (GstGmeDec * gme) gst_pad_start_task (gme->srcpad, (GstTaskFunction) gst_gme_play, gme->srcpad); - /* We can't unreference this buffer because we might need to re-initialize - * the emulator with the original data during a reverse seek - * gst_buffer_unref (gme->buf); - * gme->buf = NULL; - */ gme->initialized = TRUE; gme->seeking = FALSE; gme->seekpoint = 0; @@ -524,10 +522,7 @@ gst_gme_dec_change_state (GstElement * element, GstStateChange transition) switch (transition) { case GST_STATE_CHANGE_PAUSED_TO_READY: - if (dec->buf) { - gst_buffer_unref (dec->buf); - dec->buf = NULL; - } + gst_adapter_clear (dec->adapter); break; default: break; diff --git a/ext/gme/gstgme.h b/ext/gme/gstgme.h index f1ba39d93..5fe969d3f 100644 --- a/ext/gme/gstgme.h +++ b/ext/gme/gstgme.h @@ -22,6 +22,7 @@ #define __GST_GME_DEC_H__ #include <gst/gst.h> +#include <gst/base/gstadapter.h> #include <gme/gme.h> @@ -48,7 +49,7 @@ struct _GstGmeDec GstPad *sinkpad; GstPad *srcpad; - GstBuffer *buf; + GstAdapter *adapter; Music_Emu *player; gboolean initialized; gboolean seeking; |