From bd13c9eb8ecee54e2e2c7cf9f8ca9b7191d37142 Mon Sep 17 00:00:00 2001 From: Erik Walthinsen Date: Tue, 11 Sep 2001 09:58:16 +0000 Subject: [PATCH] Sync with my copy before wtay starts hacking... Original commit message from CVS: Sync with my copy before wtay starts hacking... Decided to keep the GstBuffer name through most code because it's really messy otherwise, and it doesn't really mean much either way. Saves lots of stupid casting. fakesrc num_buffers=N ! fakesink ends with a segfault on EOS right now, not tracked down yet. --- gst/elements/gstfakesink.c | 17 +++++++++++------ gst/elements/gstfakesrc.c | 11 +++++------ gst/gst.h | 1 + gst/gstbuffer.c | 17 +++++++++++++++++ gst/gstbuffer.h | 9 +++++++-- gst/gstevent.h | 3 ++- plugins/elements/gstfakesink.c | 17 +++++++++++------ plugins/elements/gstfakesrc.c | 11 +++++------ 8 files changed, 59 insertions(+), 27 deletions(-) diff --git a/gst/elements/gstfakesink.c b/gst/elements/gstfakesink.c index 11eac007d1..7a4bdb1966 100644 --- a/gst/elements/gstfakesink.c +++ b/gst/elements/gstfakesink.c @@ -206,9 +206,9 @@ gst_fakesink_get_property (GObject *object, guint prop_id, GValue *value, GParam /** * gst_fakesink_chain: * @pad: the pad this faksink is connected to - * @buf: the buffer that has to be absorbed + * @buffer: the buffer or event that has to be absorbed * - * take the buffer from the pad and unref it without doing + * Take the buffer or event from the pad and unref it without doing * anything with it. */ static void @@ -221,12 +221,16 @@ gst_fakesink_chain (GstPad *pad, GstBuffer *buf) g_return_if_fail (buf != NULL); fakesink = GST_FAKESINK (gst_pad_get_parent (pad)); + + if (GST_IS_EVENT(buf)) { + g_print("fakesink: have event!\n"); + } + if (!fakesink->silent) g_print("fakesink: chain ******* (%s:%s)< (%d bytes, %lld) \n", - GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf)); - - g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0, - buf); + GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf)); + + g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0, buf); gst_buffer_unref (buf); } @@ -248,4 +252,5 @@ gst_fakesink_event (GstPad *pad, GstEventType event, guint64 timestamp, guint32 if (event == GST_EVENT_EOS) { GST_DEBUG(GST_CAT_EVENT, "have EOS\n"); } + return FALSE; } diff --git a/gst/elements/gstfakesrc.c b/gst/elements/gstfakesrc.c index d946529434..5ba39f3481 100644 --- a/gst/elements/gstfakesrc.c +++ b/gst/elements/gstfakesrc.c @@ -334,8 +334,8 @@ gst_fakesrc_get(GstPad *pad) g_return_val_if_fail (GST_IS_FAKESRC (src), NULL); if (src->num_buffers == 0) { - gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0); - return NULL; + g_print("fakesrc: sending EOS\n"); + return GST_BUFFER(gst_event_empty_new (GST_EVENT_EOS)); } else { if (src->num_buffers > 0) @@ -344,8 +344,8 @@ gst_fakesrc_get(GstPad *pad) if (src->eos) { GST_INFO (0, "fakesrc is setting eos on pad"); - gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0); - return NULL; + g_print("fakesrc: sending EOS\n"); + return GST_BUFFER(gst_event_empty_new (GST_EVENT_EOS)); } buf = gst_buffer_new(); @@ -397,8 +397,7 @@ gst_fakesrc_loop(GstElement *element) if (src->eos) { GST_INFO (0, "fakesrc is setting eos on pad"); - gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0); - return; + gst_pad_push(pad, GST_BUFFER(gst_event_empty_new (GST_EVENT_EOS))); } buf = gst_buffer_new(); diff --git a/gst/gst.h b/gst/gst.h index 948e25a7ef..9216029c4a 100644 --- a/gst/gst.h +++ b/gst/gst.h @@ -52,6 +52,7 @@ #include #include #include +#include #include #include diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index 3970c60176..d1a6e04fcf 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -27,6 +27,8 @@ #include "gstbuffer.h" +GType _gst_buffer_type; + static GMemChunk *_gst_buffer_chunk; static GMutex *_gst_buffer_chunk_lock; @@ -34,6 +36,17 @@ void _gst_buffer_initialize (void) { int buffersize = sizeof(GstBuffer); + static const GTypeInfo buffer_info = { + 0, // sizeof(class), + NULL, + NULL, + NULL, + NULL, + NULL, + 0, // sizeof(object), + 0, + NULL, + }; // round up to the nearest 32 bytes for cache-line and other efficiencies buffersize = (((buffersize-1) / 32) + 1) * 32; @@ -42,6 +55,8 @@ _gst_buffer_initialize (void) buffersize * 32, G_ALLOC_AND_FREE); _gst_buffer_chunk_lock = g_mutex_new (); + + _gst_buffer_type = g_type_register_static (G_TYPE_INT, "GstBuffer", &buffer_info, 0); } /** @@ -61,6 +76,8 @@ gst_buffer_new(void) g_mutex_unlock (_gst_buffer_chunk_lock); GST_INFO (GST_CAT_BUFFER,"creating new buffer %p",buffer); + GST_DATA_TYPE(buffer) = _gst_buffer_type; + buffer->lock = g_mutex_new (); #ifdef HAVE_ATOMIC_H atomic_set (&buffer->refcount, 1); diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 7e27e3aeb9..e1b6160e3a 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -24,6 +24,7 @@ #ifndef __GST_BUFFER_H__ #define __GST_BUFFER_H__ +#include #include #ifdef HAVE_CONFIG_H @@ -39,9 +40,11 @@ extern "C" { #endif /* __cplusplus */ +extern GType _gst_buffer_type; -#define GST_BUFFER(buf) \ - ((GstBuffer *)(buf)) +#define GST_TYPE_BUFFER (_gst_buffer_type) +#define GST_BUFFER(buf) ((GstBuffer *)(buf)) +#define GST_IS_BUFFER(buf) (GST_DATA_TYPE(buf) == GST_TYPE_BUFFER) #define GST_BUFFER_FLAGS(buf) \ (GST_BUFFER(buf)->flags) @@ -93,6 +96,8 @@ typedef void (*GstBufferCopyFunc) (GstBuffer *srcbuf,GstBuffer *dstbuf); #include struct _GstBuffer { + GstData data_type; + /* locking */ GMutex *lock; diff --git a/gst/gstevent.h b/gst/gstevent.h index b9f9467fa6..85623fc0a2 100644 --- a/gst/gstevent.h +++ b/gst/gstevent.h @@ -41,8 +41,9 @@ typedef enum { extern GType _gst_event_type; +#define GST_TYPE_EVENT (_gst_event_type) #define GST_EVENT(event) ((GstEvent*)(event)) -#define GST_IS_EVENT(event) (GST_DATA_TYPE(event) == _gst_event_type) +#define GST_IS_EVENT(event) (GST_DATA_TYPE(event) == GST_TYPE_EVENT) #define GST_EVENT_TYPE(event) (GST_EVENT(event)->type) diff --git a/plugins/elements/gstfakesink.c b/plugins/elements/gstfakesink.c index 11eac007d1..7a4bdb1966 100644 --- a/plugins/elements/gstfakesink.c +++ b/plugins/elements/gstfakesink.c @@ -206,9 +206,9 @@ gst_fakesink_get_property (GObject *object, guint prop_id, GValue *value, GParam /** * gst_fakesink_chain: * @pad: the pad this faksink is connected to - * @buf: the buffer that has to be absorbed + * @buffer: the buffer or event that has to be absorbed * - * take the buffer from the pad and unref it without doing + * Take the buffer or event from the pad and unref it without doing * anything with it. */ static void @@ -221,12 +221,16 @@ gst_fakesink_chain (GstPad *pad, GstBuffer *buf) g_return_if_fail (buf != NULL); fakesink = GST_FAKESINK (gst_pad_get_parent (pad)); + + if (GST_IS_EVENT(buf)) { + g_print("fakesink: have event!\n"); + } + if (!fakesink->silent) g_print("fakesink: chain ******* (%s:%s)< (%d bytes, %lld) \n", - GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf)); - - g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0, - buf); + GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf)); + + g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0, buf); gst_buffer_unref (buf); } @@ -248,4 +252,5 @@ gst_fakesink_event (GstPad *pad, GstEventType event, guint64 timestamp, guint32 if (event == GST_EVENT_EOS) { GST_DEBUG(GST_CAT_EVENT, "have EOS\n"); } + return FALSE; } diff --git a/plugins/elements/gstfakesrc.c b/plugins/elements/gstfakesrc.c index d946529434..5ba39f3481 100644 --- a/plugins/elements/gstfakesrc.c +++ b/plugins/elements/gstfakesrc.c @@ -334,8 +334,8 @@ gst_fakesrc_get(GstPad *pad) g_return_val_if_fail (GST_IS_FAKESRC (src), NULL); if (src->num_buffers == 0) { - gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0); - return NULL; + g_print("fakesrc: sending EOS\n"); + return GST_BUFFER(gst_event_empty_new (GST_EVENT_EOS)); } else { if (src->num_buffers > 0) @@ -344,8 +344,8 @@ gst_fakesrc_get(GstPad *pad) if (src->eos) { GST_INFO (0, "fakesrc is setting eos on pad"); - gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0); - return NULL; + g_print("fakesrc: sending EOS\n"); + return GST_BUFFER(gst_event_empty_new (GST_EVENT_EOS)); } buf = gst_buffer_new(); @@ -397,8 +397,7 @@ gst_fakesrc_loop(GstElement *element) if (src->eos) { GST_INFO (0, "fakesrc is setting eos on pad"); - gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0); - return; + gst_pad_push(pad, GST_BUFFER(gst_event_empty_new (GST_EVENT_EOS))); } buf = gst_buffer_new();