mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-05 18:22:23 +00:00
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.
This commit is contained in:
parent
222322e7f3
commit
782965be9f
3 changed files with 19 additions and 23 deletions
|
@ -2,8 +2,8 @@ plugin_LTLIBRARIES = libgstgme.la
|
||||||
|
|
||||||
libgstgme_la_SOURCES = gstgme.c
|
libgstgme_la_SOURCES = gstgme.c
|
||||||
|
|
||||||
libgstgme_la_CFLAGS = $(GST_CFLAGS) $(GME_CFLAGS)
|
libgstgme_la_CFLAGS = $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GME_CFLAGS)
|
||||||
libgstgme_la_LIBADD = $(GST_LIBS) $(GME_LIBS)
|
libgstgme_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(GME_LIBS)
|
||||||
libgstgme_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
libgstgme_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||||
libgstgme_la_LIBTOOLFLAGS = --tag=disable-static
|
libgstgme_la_LIBTOOLFLAGS = --tag=disable-static
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ gst_gme_dec_init (GstGmeDec * gme, GstGmeDecClass * klass)
|
||||||
gst_pad_use_fixed_caps (gme->srcpad);
|
gst_pad_use_fixed_caps (gme->srcpad);
|
||||||
gst_element_add_pad (GST_ELEMENT (gme), gme->srcpad);
|
gst_element_add_pad (GST_ELEMENT (gme), gme->srcpad);
|
||||||
|
|
||||||
gme->buf = NULL;
|
gme->adapter = gst_adapter_new ();
|
||||||
gme->player = NULL;
|
gme->player = NULL;
|
||||||
gme->total_duration = GST_CLOCK_TIME_NONE;
|
gme->total_duration = GST_CLOCK_TIME_NONE;
|
||||||
gme->initialized = FALSE;
|
gme->initialized = FALSE;
|
||||||
|
@ -170,9 +170,9 @@ gst_gme_dec_dispose (GObject * object)
|
||||||
{
|
{
|
||||||
GstGmeDec *gme = GST_GME_DEC (object);
|
GstGmeDec *gme = GST_GME_DEC (object);
|
||||||
|
|
||||||
if (gme->buf) {
|
if (gme->adapter) {
|
||||||
gst_buffer_unref (gme->buf);
|
gst_object_unref (gme->adapter);
|
||||||
gme->buf = NULL;
|
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));
|
GstGmeDec *gme = GST_GME_DEC (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
/* Accumulate GME data until end-of-stream, then commence playback. */
|
/* Accumulate GME data until end-of-stream, then commence playback. */
|
||||||
if (gme->buf) {
|
gst_adapter_push (gme->adapter, buffer);
|
||||||
gme->buf = gst_buffer_join (gme->buf, buffer);
|
|
||||||
} else {
|
|
||||||
gme->buf = buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_object_unref (gme);
|
gst_object_unref (gme);
|
||||||
|
|
||||||
|
@ -421,14 +417,21 @@ gme_setup (GstGmeDec * gme)
|
||||||
gme_err_t gme_err = NULL;
|
gme_err_t gme_err = NULL;
|
||||||
GstTagList *taglist;
|
GstTagList *taglist;
|
||||||
guint64 total_duration;
|
guint64 total_duration;
|
||||||
|
GstBuffer *buffer;
|
||||||
|
|
||||||
if (!gme->buf || !gme_negotiate (gme)) {
|
if (!gst_adapter_available (gme->adapter) || !gme_negotiate (gme)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer =
|
||||||
|
gst_adapter_take_buffer (gme->adapter,
|
||||||
|
gst_adapter_available (gme->adapter));
|
||||||
|
|
||||||
gme_err =
|
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);
|
&gme->player, 32000);
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
|
|
||||||
if (gme_err || !gme->player) {
|
if (gme_err || !gme->player) {
|
||||||
if (gme->player) {
|
if (gme->player) {
|
||||||
gme_delete (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);
|
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->initialized = TRUE;
|
||||||
gme->seeking = FALSE;
|
gme->seeking = FALSE;
|
||||||
gme->seekpoint = 0;
|
gme->seekpoint = 0;
|
||||||
|
@ -524,10 +522,7 @@ gst_gme_dec_change_state (GstElement * element, GstStateChange transition)
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
if (dec->buf) {
|
gst_adapter_clear (dec->adapter);
|
||||||
gst_buffer_unref (dec->buf);
|
|
||||||
dec->buf = NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#define __GST_GME_DEC_H__
|
#define __GST_GME_DEC_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
#include <gst/base/gstadapter.h>
|
||||||
|
|
||||||
#include <gme/gme.h>
|
#include <gme/gme.h>
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ struct _GstGmeDec
|
||||||
GstPad *sinkpad;
|
GstPad *sinkpad;
|
||||||
GstPad *srcpad;
|
GstPad *srcpad;
|
||||||
|
|
||||||
GstBuffer *buf;
|
GstAdapter *adapter;
|
||||||
Music_Emu *player;
|
Music_Emu *player;
|
||||||
gboolean initialized;
|
gboolean initialized;
|
||||||
gboolean seeking;
|
gboolean seeking;
|
||||||
|
|
Loading…
Reference in a new issue