From e134f7f75b339618c986582cd299e0602488a5b7 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Mon, 16 May 2005 20:21:55 +0000 Subject: [PATCH] check/Makefile.am: remove GstData checks Original commit message from CVS: * check/Makefile.am: remove GstData checks * check/gst-libs/gdp.c: (START_TEST): fix for API changes * gst/Makefile.am: add miniobject, remove data * gst/gst.h: add miniobject, remove data * gst/gstdata.c: remove * gst/gstdata.h: remove * gst/gstdata_private.h: remove * gst/gsttypes.h: remove GstEvent and GstMessage * gst/gstelement.c: (gst_element_post_message): fix for API changes * gst/gstmarshal.list: change BOXED -> OBJECT Implement GstMiniObject. * gst/gstminiobject.c: * gst/gstminiobject.h: Modify to be subclasses of GstMiniObject. * gst/gstbuffer.c: (_gst_buffer_initialize), (gst_buffer_get_type), (gst_buffer_class_init), (gst_buffer_finalize), (_gst_buffer_copy), (gst_buffer_init), (gst_buffer_new), (gst_buffer_new_and_alloc), (gst_subbuffer_get_type), (gst_subbuffer_init), (gst_buffer_create_sub), (gst_buffer_is_span_fast), (gst_buffer_span): * gst/gstbuffer.h: * gst/gstevent.c: (_gst_event_initialize), (gst_event_get_type), (gst_event_class_init), (gst_event_init), (gst_event_finalize), (_gst_event_copy), (gst_event_new): * gst/gstevent.h: * gst/gstmessage.c: (_gst_message_initialize), (gst_message_get_type), (gst_message_class_init), (gst_message_init), (gst_message_finalize), (_gst_message_copy), (gst_message_new), (gst_message_new_error), (gst_message_new_warning), (gst_message_new_tag), (gst_message_new_state_changed), (gst_message_new_application): * gst/gstmessage.h: * gst/gstprobe.c: (gst_probe_perform), (gst_probe_dispatcher_dispatch): * gst/gstprobe.h: * gst/gstquery.c: (_gst_query_initialize), (gst_query_get_type), (gst_query_class_init), (gst_query_finalize), (gst_query_init), (_gst_query_copy), (gst_query_new): Update elements for GstData -> GstMiniObject changes * gst/gstquery.h: * gst/gstqueue.c: (gst_queue_finalize), (gst_queue_locked_flush), (gst_queue_chain), (gst_queue_loop): * gst/elements/gstbufferstore.c: (gst_buffer_store_add_buffer_func), (gst_buffer_store_cleared_func), (gst_buffer_store_get_buffer): * gst/elements/gstfakesink.c: (gst_fakesink_class_init), (gst_fakesink_render): * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init): * gst/elements/gstfilesrc.c: (gst_mmap_buffer_get_type), (gst_mmap_buffer_class_init), (gst_mmap_buffer_init), (gst_mmap_buffer_finalize), (gst_filesrc_map_region), (gst_filesrc_create_read): * gst/elements/gstidentity.c: (gst_identity_class_init): * gst/elements/gsttypefindelement.c: (gst_type_find_element_src_event), (free_entry_buffers), (gst_type_find_element_handle_event): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_header_from_buffer): * libs/gst/dataprotocol/dataprotocol.h: * libs/gst/dataprotocol/dp-private.h: --- ChangeLog | 66 +++++ check/Makefile.am | 1 - check/gst-libs/gdp.c | 7 +- gst/Makefile.am | 5 +- gst/elements/gstbufferstore.c | 18 +- gst/elements/gstfakesink.c | 6 +- gst/elements/gstfakesrc.c | 3 +- gst/elements/gstfilesrc.c | 111 ++++++-- gst/elements/gstidentity.c | 3 +- gst/elements/gsttypefindelement.c | 6 +- gst/gst.h | 1 + gst/gstbuffer.c | 306 +++++++++++----------- gst/gstbuffer.h | 94 +++---- gst/gstdata.c | 292 --------------------- gst/gstdata.h | 111 -------- gst/gstdata_private.h | 35 --- gst/gstelement.c | 2 +- gst/gstevent.c | 143 +++++----- gst/gstevent.h | 30 ++- gst/gstmarshal.list | 1 + gst/gstmessage.c | 145 ++++++----- gst/gstmessage.h | 31 ++- gst/gstminiobject.c | 360 ++++++++++++++++++++++++++ gst/gstminiobject.h | 92 +++++++ gst/gstprobe.c | 8 +- gst/gstprobe.h | 8 +- gst/gstquery.c | 137 ++++++---- gst/gstquery.h | 30 ++- gst/gstqueue.c | 12 +- gst/gsttypes.h | 2 - libs/gst/dataprotocol/dataprotocol.c | 6 +- libs/gst/dataprotocol/dataprotocol.h | 1 - libs/gst/dataprotocol/dp-private.h | 1 - plugins/elements/gstbufferstore.c | 18 +- plugins/elements/gstfakesink.c | 6 +- plugins/elements/gstfakesrc.c | 3 +- plugins/elements/gstfilesrc.c | 111 ++++++-- plugins/elements/gstidentity.c | 3 +- plugins/elements/gstqueue.c | 12 +- plugins/elements/gsttypefindelement.c | 6 +- tests/check/Makefile.am | 1 - tests/check/libs/gdp.c | 7 +- 42 files changed, 1246 insertions(+), 995 deletions(-) delete mode 100644 gst/gstdata.c delete mode 100644 gst/gstdata.h delete mode 100644 gst/gstdata_private.h create mode 100644 gst/gstminiobject.c create mode 100644 gst/gstminiobject.h diff --git a/ChangeLog b/ChangeLog index 2a6383fc96..a76cc801b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,69 @@ +2005-05-15 David Schleef + + * check/Makefile.am: remove GstData checks + * check/gst-libs/gdp.c: (START_TEST): fix for API changes + * gst/Makefile.am: add miniobject, remove data + * gst/gst.h: add miniobject, remove data + * gst/gstdata.c: remove + * gst/gstdata.h: remove + * gst/gstdata_private.h: remove + * gst/gsttypes.h: remove GstEvent and GstMessage + * gst/gstelement.c: (gst_element_post_message): fix for API changes + * gst/gstmarshal.list: change BOXED -> OBJECT + + Implement GstMiniObject. + * gst/gstminiobject.c: + * gst/gstminiobject.h: + + Modify to be subclasses of GstMiniObject. + * gst/gstbuffer.c: (_gst_buffer_initialize), (gst_buffer_get_type), + (gst_buffer_class_init), (gst_buffer_finalize), (_gst_buffer_copy), + (gst_buffer_init), (gst_buffer_new), (gst_buffer_new_and_alloc), + (gst_subbuffer_get_type), (gst_subbuffer_init), + (gst_buffer_create_sub), (gst_buffer_is_span_fast), + (gst_buffer_span): + * gst/gstbuffer.h: + * gst/gstevent.c: (_gst_event_initialize), (gst_event_get_type), + (gst_event_class_init), (gst_event_init), (gst_event_finalize), + (_gst_event_copy), (gst_event_new): + * gst/gstevent.h: + * gst/gstmessage.c: (_gst_message_initialize), + (gst_message_get_type), (gst_message_class_init), + (gst_message_init), (gst_message_finalize), (_gst_message_copy), + (gst_message_new), (gst_message_new_error), + (gst_message_new_warning), (gst_message_new_tag), + (gst_message_new_state_changed), (gst_message_new_application): + * gst/gstmessage.h: + * gst/gstprobe.c: (gst_probe_perform), + (gst_probe_dispatcher_dispatch): + * gst/gstprobe.h: + * gst/gstquery.c: (_gst_query_initialize), (gst_query_get_type), + (gst_query_class_init), (gst_query_finalize), (gst_query_init), + (_gst_query_copy), (gst_query_new): + + Update elements for GstData -> GstMiniObject changes + * gst/gstquery.h: + * gst/gstqueue.c: (gst_queue_finalize), (gst_queue_locked_flush), + (gst_queue_chain), (gst_queue_loop): + * gst/elements/gstbufferstore.c: + (gst_buffer_store_add_buffer_func), + (gst_buffer_store_cleared_func), (gst_buffer_store_get_buffer): + * gst/elements/gstfakesink.c: (gst_fakesink_class_init), + (gst_fakesink_render): + * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init): + * gst/elements/gstfilesrc.c: (gst_mmap_buffer_get_type), + (gst_mmap_buffer_class_init), (gst_mmap_buffer_init), + (gst_mmap_buffer_finalize), (gst_filesrc_map_region), + (gst_filesrc_create_read): + * gst/elements/gstidentity.c: (gst_identity_class_init): + * gst/elements/gsttypefindelement.c: + (gst_type_find_element_src_event), (free_entry_buffers), + (gst_type_find_element_handle_event): + * libs/gst/dataprotocol/dataprotocol.c: + (gst_dp_header_from_buffer): + * libs/gst/dataprotocol/dataprotocol.h: + * libs/gst/dataprotocol/dp-private.h: + 2005-05-15 David Schleef * gst/elements/gstelements.c: Don't include headers that were diff --git a/check/Makefile.am b/check/Makefile.am index 0f94ba1ca6..6fb53659fc 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -26,7 +26,6 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gstbin \ gst/gstbus \ gst/gstcaps \ - gst/gstdata \ gst/gstiterator \ gst/gstmessage \ gst/gstobject \ diff --git a/check/gst-libs/gdp.c b/check/gst-libs/gdp.c index df79c8d1c0..fdcb0cf450 100644 --- a/check/gst-libs/gdp.c +++ b/check/gst-libs/gdp.c @@ -98,8 +98,7 @@ START_TEST (test_buffer) GST_BUFFER_DURATION (buffer) = (GstClockTime) GST_SECOND; GST_BUFFER_OFFSET (buffer) = (guint64) 10; GST_BUFFER_OFFSET_END (buffer) = (guint64) 19; - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_IN_CAPS); - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_SUBBUFFER); + GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS); memmove (GST_BUFFER_DATA (buffer), "a buffer", 8); /* create a buffer with CRC checking */ @@ -136,9 +135,7 @@ START_TEST (test_buffer) "Offsets don't match !"); fail_unless (GST_BUFFER_OFFSET_END (newbuffer) == GST_BUFFER_OFFSET_END (buffer), "Offset ends don't match !"); - fail_if (GST_BUFFER_FLAG_IS_SET (newbuffer, GST_BUFFER_SUBBUFFER), - "GST_BUFFER_SUBBUFFER flag should not have been copied !"); - fail_unless (GST_BUFFER_FLAG_IS_SET (newbuffer, GST_BUFFER_IN_CAPS), + fail_unless (GST_BUFFER_FLAG_IS_SET (newbuffer, GST_BUFFER_FLAG_IN_CAPS), "GST_BUFFER_IN_CAPS flag should have been copied !"); g_free (header); diff --git a/gst/Makefile.am b/gst/Makefile.am index 47236f2534..322c83e060 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -82,7 +82,6 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \ gstbus.c \ gstcaps.c \ gstclock.c \ - gstdata.c \ gstelement.c \ gstelementfactory.c \ gsterror.c \ @@ -95,6 +94,7 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \ gstiterator.c \ gstmemchunk.c \ gstmessage.c \ + gstminiobject.c \ gstpad.c \ gstpipeline.c \ gstplugin.c \ @@ -157,7 +157,6 @@ gst_headers = \ gstcaps.h \ gstclock.h \ gstcompat.h \ - gstdata.h \ gstelement.h \ gsterror.h \ gstevent.h \ @@ -170,6 +169,7 @@ gst_headers = \ gstmacros.h \ gstmemchunk.h \ gstmessage.h \ + gstminiobject.h \ gstpad.h \ gstpipeline.h \ gstplugin.h \ @@ -206,7 +206,6 @@ noinst_HEADERS = \ gst-i18n-lib.h \ gst-i18n-app.h \ gst_private.h \ - gstdata_private.h \ gstarch.h \ cothreads.h diff --git a/gst/elements/gstbufferstore.c b/gst/elements/gstbufferstore.c index f3d8e55089..d9f1d40a23 100644 --- a/gst/elements/gstbufferstore.c +++ b/gst/elements/gstbufferstore.c @@ -135,7 +135,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) /* the starting buffer had an invalid offset, in that case we assume continuous buffers */ GST_LOG_OBJECT (store, "adding buffer %p with invalid offset and size %u", buffer, GST_BUFFER_SIZE (buffer)); - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); store->buffers = g_list_append (store->buffers, buffer); return TRUE; } else { @@ -176,14 +176,14 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) g_assert (sub); buffer = sub; } else { - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); } /* replace current buffer with new one */ GST_INFO_OBJECT (store, "replacing buffer %p with buffer %p with offset %" G_GINT64_FORMAT " and size %u", current_list->data, buffer, GST_BUFFER_OFFSET (buffer), GST_BUFFER_SIZE (buffer)); - gst_data_unref (GST_DATA (current_list->data)); + gst_mini_object_unref (GST_MINI_OBJECT (current_list->data)); current_list->data = buffer; buffer = NULL; break; @@ -215,7 +215,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) GST_BUFFER_OFFSET (sub) = start_offset + GST_BUFFER_OFFSET (buffer); buffer = sub; } else { - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); } GST_INFO_OBJECT (store, "adding buffer %p with offset %" G_GINT64_FORMAT " and size %u", @@ -228,7 +228,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) } } if (buffer) { - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); GST_INFO_OBJECT (store, "adding buffer %p with offset %" G_GINT64_FORMAT " and size %u", buffer, GST_BUFFER_OFFSET (buffer), GST_BUFFER_SIZE (buffer)); @@ -245,7 +245,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) static void gst_buffer_store_cleared_func (GstBufferStore * store) { - g_list_foreach (store->buffers, (GFunc) gst_data_unref, NULL); + g_list_foreach (store->buffers, (GFunc) gst_mini_object_unref, NULL); g_list_free (store->buffers); store->buffers = NULL; } @@ -355,8 +355,8 @@ gst_buffer_store_get_buffer (GstBufferStore * store, guint64 offset, guint size) "found matching buffer %p for offset %" G_GUINT64_FORMAT " and size %u", current, offset, size); ret = current; - gst_data_ref (GST_DATA (ret)); - GST_LOG_OBJECT (store, "refcount %d", GST_DATA_REFCOUNT_VALUE (ret)); + gst_mini_object_ref (GST_MINI_OBJECT (ret)); + GST_LOG_OBJECT (store, "refcount %d", GST_MINI_OBJECT (ret)->refcount); break; } else if (cur_offset + GST_BUFFER_SIZE (current) > offset) { if (cur_offset + GST_BUFFER_SIZE (current) >= offset + size) { @@ -384,7 +384,7 @@ gst_buffer_store_get_buffer (GstBufferStore * store, guint64 offset, guint size) GST_DEBUG_OBJECT (store, "not all data for offset %" G_GUINT64_FORMAT " and remaining size %u available, aborting", offset, size); - gst_data_unref (GST_DATA (ret)); + gst_mini_object_unref (GST_MINI_OBJECT (ret)); ret = NULL; goto out; } diff --git a/gst/elements/gstfakesink.c b/gst/elements/gstfakesink.c index 3448d157c1..a6887b4026 100644 --- a/gst/elements/gstfakesink.c +++ b/gst/elements/gstfakesink.c @@ -172,8 +172,8 @@ gst_fakesink_class_init (GstFakeSinkClass * klass) gst_fakesink_signals[SIGNAL_HANDOFF] = g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstFakeSinkClass, handoff), NULL, NULL, - gst_marshal_VOID__BOXED_OBJECT, G_TYPE_NONE, 2, - GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE, GST_TYPE_PAD); + gst_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, + G_TYPE_OBJECT, GST_TYPE_PAD); gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_fakesink_change_state); @@ -317,7 +317,7 @@ gst_fakesink_render (GstBaseSink * bsink, GstBuffer * buf) GST_BUFFER_SIZE (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf), - GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf); + GST_BUFFER_OFFSET_END (buf), GST_MINI_OBJECT (buf)->flags, buf); g_object_notify (G_OBJECT (sink), "last_message"); } diff --git a/gst/elements/gstfakesrc.c b/gst/elements/gstfakesrc.c index 4715db5113..9695549d74 100644 --- a/gst/elements/gstfakesrc.c +++ b/gst/elements/gstfakesrc.c @@ -288,8 +288,7 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) gst_fakesrc_signals[SIGNAL_HANDOFF] = g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstFakeSrcClass, handoff), NULL, NULL, - gst_marshal_VOID__BOXED_OBJECT, G_TYPE_NONE, 1, - GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE); + gst_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); /*gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_fakesrc_is_seekable); */ gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_fakesrc_start); diff --git a/gst/elements/gstfilesrc.c b/gst/elements/gstfilesrc.c index 22f93d57c7..27421e85ce 100644 --- a/gst/elements/gstfilesrc.c +++ b/gst/elements/gstfilesrc.c @@ -350,22 +350,92 @@ gst_filesrc_get_property (GObject * object, guint prop_id, GValue * value, */ #ifdef HAVE_MMAP + +/* GstMmapBuffer */ + +typedef struct _GstMmapBuffer GstMmapBuffer; +typedef struct _GstMmapBufferClass GstMmapBufferClass; + +#define GST_TYPE_MMAP_BUFFER (gst_mmap_buffer_get_type()) + +#define GST_IS_MMAP_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MMAP_BUFFER)) +#define GST_IS_MMAP_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MMAP_BUFFER)) +#define GST_MMAP_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MMAP_BUFFER, GstMmapBufferClass)) +#define GST_MMAP_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MMAP_BUFFER, GstMmapBuffer)) +#define GST_MMAP_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MMAP_BUFFER, GstMmapBufferClass)) + + + +struct _GstMmapBuffer +{ + GstBuffer buffer; + + GstFileSrc *filesrc; +}; + +struct _GstMmapBufferClass +{ + GstBufferClass buffer_class; +}; + +static void gst_mmap_buffer_init (GTypeInstance * instance, gpointer g_class); +static void gst_mmap_buffer_class_init (gpointer g_class, gpointer class_data); +static void gst_mmap_buffer_finalize (GstMmapBuffer * mmap_buffer); + +static GType +gst_mmap_buffer_get_type (void) +{ + static GType _gst_mmap_buffer_type; + + if (G_UNLIKELY (_gst_mmap_buffer_type == 0)) { + static const GTypeInfo mmap_buffer_info = { + sizeof (GstMmapBufferClass), + NULL, + NULL, + gst_mmap_buffer_class_init, + NULL, + NULL, + sizeof (GstMmapBuffer), + 0, + gst_mmap_buffer_init, + NULL + }; + + _gst_mmap_buffer_type = g_type_register_static (GST_TYPE_BUFFER, + "GstMmapBuffer", &mmap_buffer_info, 0); + } + return _gst_mmap_buffer_type; +} + static void -gst_filesrc_free_parent_mmap (GstBuffer * buf) +gst_mmap_buffer_class_init (gpointer g_class, gpointer class_data) +{ + GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class); + + mini_object_class->finalize = + (GstMiniObjectFinalizeFunction) gst_mmap_buffer_finalize; +} + +static void +gst_mmap_buffer_init (GTypeInstance * instance, gpointer g_class) +{ + +} + +static void +gst_mmap_buffer_finalize (GstMmapBuffer * mmap_buffer) { guint size; - guint64 offset; gpointer data; - GstBaseSrc *src; + guint64 offset; + GstFileSrc *src; + GstBuffer *buffer = GST_BUFFER (mmap_buffer); /* get info */ - size = GST_BUFFER_MAXSIZE (buf); - offset = GST_BUFFER_OFFSET (buf); - data = GST_BUFFER_DATA (buf); - src = (GstBaseSrc *) GST_BUFFER_PRIVATE (buf); - - if (!GST_IS_BASESRC (src)) - goto wrong_buffer; + size = GST_BUFFER_SIZE (buffer); + offset = GST_BUFFER_OFFSET (buffer); + data = GST_BUFFER_DATA (buffer); + src = mmap_buffer->filesrc; GST_LOG ("freeing mmap()d buffer at %" G_GUINT64_FORMAT "+%u", offset, size); @@ -385,15 +455,6 @@ gst_filesrc_free_parent_mmap (GstBuffer * buf) * guint64 as hex */ GST_LOG ("unmapped region %08lx+%08lx at %p", (gulong) offset, (gulong) size, data); - - GST_BUFFER_DATA (buf) = NULL; - return; - -wrong_buffer: - { - GST_WARNING ("freeing wrong mmap buffer"); - return; - } } static GstBuffer * @@ -416,9 +477,10 @@ gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size) (gulong) offset, (gulong) size, mmapregion); /* time to allocate a new mapbuf */ - buf = gst_buffer_new (); + buf = (GstBuffer *) gst_mini_object_new (GST_TYPE_MMAP_BUFFER); /* mmap() the data into this new buffer */ GST_BUFFER_DATA (buf) = mmapregion; + GST_MMAP_BUFFER (buf)->filesrc = src; #ifdef MADV_SEQUENTIAL /* madvise to tell the kernel what to do with it */ @@ -428,15 +490,13 @@ gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size) #endif /* fill in the rest of the fields */ - GST_BUFFER_FLAG_SET (buf, GST_BUFFER_READONLY); - GST_BUFFER_FLAG_SET (buf, GST_BUFFER_ORIGINAL); + /* FIXME */ + //GST_BUFFER_FLAG_SET (buf, GST_BUFFER_READONLY); + //GST_BUFFER_FLAG_SET (buf, GST_BUFFER_ORIGINAL); GST_BUFFER_SIZE (buf) = size; - GST_BUFFER_MAXSIZE (buf) = size; GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + size; GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_PRIVATE (buf) = src; - GST_BUFFER_FREE_DATA_FUNC (buf) = gst_filesrc_free_parent_mmap; return buf; @@ -661,7 +721,6 @@ gst_filesrc_create_read (GstFileSrc * src, guint64 offset, guint length, length = ret; GST_BUFFER_SIZE (buf) = length; - GST_BUFFER_MAXSIZE (buf) = length; GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + length; diff --git a/gst/elements/gstidentity.c b/gst/elements/gstidentity.c index b80c1a275b..8d08aaf3f1 100644 --- a/gst/elements/gstidentity.c +++ b/gst/elements/gstidentity.c @@ -182,8 +182,7 @@ gst_identity_class_init (GstIdentityClass * klass) gst_identity_signals[SIGNAL_HANDOFF] = g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL, - gst_marshal_VOID__BOXED, G_TYPE_NONE, 1, - GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE); + gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_identity_finalize); diff --git a/gst/elements/gsttypefindelement.c b/gst/elements/gsttypefindelement.c index 7d424a29e2..33f920181a 100644 --- a/gst/elements/gsttypefindelement.c +++ b/gst/elements/gsttypefindelement.c @@ -359,7 +359,7 @@ gst_type_find_element_src_event (GstPad * pad, GstEvent * event) if (typefind->mode != MODE_NORMAL) { /* need to do more? */ - gst_data_unref (GST_DATA (event)); + gst_mini_object_unref (GST_MINI_OBJECT (event)); return FALSE; } return gst_pad_event_default (pad, event); @@ -385,7 +385,7 @@ new_entry (void) static void free_entry_buffers (TypeFindEntry * entry) { - g_list_foreach (entry->buffers, (GFunc) gst_data_unref, NULL); + g_list_foreach (entry->buffers, (GFunc) gst_mini_object_unref, NULL); g_list_free (entry->buffers); entry->buffers = NULL; } @@ -539,7 +539,7 @@ gst_type_find_element_handle_event (GstPad * pad, GstEvent * event) } break; default: - gst_data_unref (GST_DATA (event)); + gst_mini_object_unref (GST_MINI_OBJECT (event)); res = TRUE; break; } diff --git a/gst/gst.h b/gst/gst.h index 04318684d7..c7724eed1d 100644 --- a/gst/gst.h +++ b/gst/gst.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index c0bcd4ae0b..0aa4b71e2d 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -22,13 +22,10 @@ #include "gst_private.h" -#include "gstdata_private.h" #include "gstbuffer.h" -#include "gstmemchunk.h" #include "gstinfo.h" #include "gstutils.h" - -GType _gst_buffer_type = 0; +#include "gstminiobject.h" #ifndef GST_DISABLE_TRACE /* #define GST_WITH_ALLOC_TRACE */ @@ -37,10 +34,11 @@ GType _gst_buffer_type = 0; static GstAllocTrace *_gst_buffer_trace; #endif -static GstMemChunk *chunk; +static void gst_buffer_init (GTypeInstance * instance, gpointer g_class); +static void gst_buffer_class_init (gpointer g_class, gpointer class_data); +static void gst_buffer_finalize (GstBuffer * buffer); +static GstBuffer *_gst_buffer_copy (GstBuffer * buffer); -static GstBuffer *gst_buffer_alloc_chunk (void); -static void gst_buffer_free_chunk (GstBuffer * buffer); void _gst_buffer_initialize (void) @@ -50,119 +48,89 @@ _gst_buffer_initialize (void) #ifndef GST_DISABLE_TRACE _gst_buffer_trace = gst_alloc_trace_register (GST_BUFFER_TRACE_NAME); #endif - - chunk = gst_mem_chunk_new ("GstBufferChunk", sizeof (GstBuffer), - sizeof (GstBuffer) * 200, 0); - - GST_CAT_LOG (GST_CAT_BUFFER, "Buffers are initialized now"); } GType gst_buffer_get_type (void) { + static GType _gst_buffer_type; + if (G_UNLIKELY (_gst_buffer_type == 0)) { - _gst_buffer_type = g_boxed_type_register_static ("GstBuffer", - (GBoxedCopyFunc) gst_data_copy, (GBoxedFreeFunc) gst_data_unref); + static const GTypeInfo buffer_info = { + sizeof (GstBufferClass), + NULL, + NULL, + gst_buffer_class_init, + NULL, + NULL, + sizeof (GstBuffer), + 0, + gst_buffer_init, + NULL + }; + + _gst_buffer_type = g_type_register_static (GST_TYPE_MINI_OBJECT, + "GstBuffer", &buffer_info, 0); } return _gst_buffer_type; } static void -_gst_buffer_sub_free (GstBuffer * buffer) +gst_buffer_class_init (gpointer g_class, gpointer class_data) { - gst_data_unref (GST_DATA (buffer->buffer_private)); + GstBufferClass *buffer_class = GST_BUFFER_CLASS (g_class); - GST_BUFFER_DATA (buffer) = NULL; - GST_BUFFER_SIZE (buffer) = 0; - gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL); + buffer_class->mini_object_class.copy = + (GstMiniObjectCopyFunction) _gst_buffer_copy; + buffer_class->mini_object_class.finalize = + (GstMiniObjectFinalizeFunction) gst_buffer_finalize; - _GST_DATA_DISPOSE (GST_DATA (buffer)); - - gst_buffer_free_chunk (buffer); } -/** - * gst_buffer_default_free: - * @buffer: a #GstBuffer to free. - * - * Frees the memory associated with the buffer including the buffer data, - * unless the GST_BUFFER_DONTFREE flags was set or the buffer data is NULL. - * - * MT safe. - */ -void -gst_buffer_default_free (GstBuffer * buffer) +static void +gst_buffer_finalize (GstBuffer * buffer) { g_return_if_fail (buffer != NULL); /* free our data */ - if (GST_BUFFER_FREE_DATA_FUNC (buffer)) { - GST_BUFFER_FREE_DATA_FUNC (buffer) (buffer); - } else if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_DONTFREE)) { - g_free (GST_BUFFER_DATA (buffer)); + if (buffer->malloc_data) { + g_free (buffer->malloc_data); } - /* set to safe values */ - GST_BUFFER_DATA (buffer) = NULL; - GST_BUFFER_SIZE (buffer) = 0; gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL); - - _GST_DATA_DISPOSE (GST_DATA (buffer)); - - gst_buffer_free_chunk (buffer); } - -/** - * gst_buffer_default_copy: - * @buffer: a #GstBuffer to make a copy of. - * - * Make a full newly allocated copy of the given buffer, data and all. - * Note that the caps on the buffer are not copied but their refcount - * is increased. - * - * Returns: the new #GstBuffer. - * - * MT safe. - */ -GstBuffer * -gst_buffer_default_copy (GstBuffer * buffer) +static GstBuffer * +_gst_buffer_copy (GstBuffer * buffer) { GstBuffer *copy; - guint16 flags; + guint mask; g_return_val_if_fail (buffer != NULL, NULL); /* create a fresh new buffer */ - copy = gst_buffer_alloc_chunk (); + copy = gst_buffer_new (); GST_CAT_LOG (GST_CAT_BUFFER, "copy %p to %p", buffer, copy); /* copy relevant flags */ - flags = GST_DATA_FLAG_SHIFT (GST_BUFFER_PREROLL) | - GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS) | - GST_DATA_FLAG_SHIFT (GST_BUFFER_DELTA_UNIT); - flags = GST_BUFFER_FLAGS (buffer) & flags; - - _GST_DATA_INIT (GST_DATA (copy), - _gst_buffer_type, - flags, - (GstDataFreeFunction) gst_buffer_default_free, - (GstDataCopyFunction) gst_buffer_default_copy); + mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS | + GST_BUFFER_FLAG_DELTA_UNIT; + GST_MINI_OBJECT (copy)->flags |= GST_MINI_OBJECT (buffer)->flags & mask; /* we simply copy everything from our parent */ - GST_BUFFER_DATA (copy) = g_memdup (GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); - GST_BUFFER_SIZE (copy) = GST_BUFFER_SIZE (buffer); - GST_BUFFER_MAXSIZE (copy) = GST_BUFFER_SIZE (buffer); + if (buffer->malloc_data) { + copy->malloc_data = g_memdup (buffer->data, buffer->size); + copy->data = copy->malloc_data; + } + + copy->size = buffer->size; GST_BUFFER_TIMESTAMP (copy) = GST_BUFFER_TIMESTAMP (buffer); GST_BUFFER_DURATION (copy) = GST_BUFFER_DURATION (buffer); GST_BUFFER_OFFSET (copy) = GST_BUFFER_OFFSET (buffer); GST_BUFFER_OFFSET_END (copy) = GST_BUFFER_OFFSET_END (buffer); - GST_BUFFER_FREE_DATA_FUNC (copy) = NULL; - GST_BUFFER_PRIVATE (copy) = NULL; if (GST_BUFFER_CAPS (buffer)) GST_BUFFER_CAPS (copy) = gst_caps_ref (GST_BUFFER_CAPS (buffer)); else @@ -171,26 +139,22 @@ gst_buffer_default_copy (GstBuffer * buffer) return copy; } -static GstBuffer * -gst_buffer_alloc_chunk (void) -{ - GstBuffer *newbuf; - - newbuf = gst_mem_chunk_alloc (chunk); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_new (_gst_buffer_trace, newbuf); -#endif - - return newbuf; -} - static void -gst_buffer_free_chunk (GstBuffer * buffer) +gst_buffer_init (GTypeInstance * instance, gpointer g_class) { - gst_mem_chunk_free (chunk, GST_DATA (buffer)); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_free (_gst_buffer_trace, buffer); -#endif + GstBuffer *buffer; + + buffer = (GstBuffer *) instance; + + GST_CAT_LOG (GST_CAT_BUFFER, "init %p", buffer); + + //GST_BUFFER_DATA (buffer) = NULL; + //GST_BUFFER_SIZE (buffer) = 0; + GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE; + GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE; + GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE; + GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE; + //GST_BUFFER_CAPS (buffer) = NULL; } /** @@ -207,27 +171,10 @@ gst_buffer_new (void) { GstBuffer *newbuf; - newbuf = gst_buffer_alloc_chunk (); + newbuf = (GstBuffer *) gst_mini_object_new (GST_TYPE_BUFFER); GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf); - _GST_DATA_INIT (GST_DATA (newbuf), - _gst_buffer_type, - 0, - (GstDataFreeFunction) gst_buffer_default_free, - (GstDataCopyFunction) gst_buffer_default_copy); - - GST_BUFFER_DATA (newbuf) = NULL; - GST_BUFFER_SIZE (newbuf) = 0; - GST_BUFFER_MAXSIZE (newbuf) = GST_BUFFER_MAXSIZE_NONE; - GST_BUFFER_TIMESTAMP (newbuf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_DURATION (newbuf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_OFFSET (newbuf) = GST_BUFFER_OFFSET_NONE; - GST_BUFFER_OFFSET_END (newbuf) = GST_BUFFER_OFFSET_NONE; - GST_BUFFER_FREE_DATA_FUNC (newbuf) = NULL; - GST_BUFFER_PRIVATE (newbuf) = NULL; - GST_BUFFER_CAPS (newbuf) = NULL; - return newbuf; } @@ -248,9 +195,9 @@ gst_buffer_new_and_alloc (guint size) newbuf = gst_buffer_new (); - GST_BUFFER_DATA (newbuf) = g_malloc (size); + newbuf->malloc_data = g_malloc (size); + GST_BUFFER_DATA (newbuf) = newbuf->malloc_data; GST_BUFFER_SIZE (newbuf) = size; - GST_BUFFER_MAXSIZE (newbuf) = size; return newbuf; } @@ -302,8 +249,62 @@ gst_buffer_set_caps (GstBuffer * buffer, GstCaps * caps) gst_caps_replace (&GST_BUFFER_CAPS (buffer), caps); } + +typedef struct _GstSubBuffer GstSubBuffer; +typedef struct _GstSubBufferClass GstSubBufferClass; + +#define GST_TYPE_SUBBUFFER (gst_subbuffer_get_type()) + +#define GST_IS_SUBBUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER)) +#define GST_SUBBUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SUBBUFFER, GstSubBuffer)) + +struct _GstSubBuffer +{ + GstBuffer buffer; + + GstBuffer *parent; +}; + +struct _GstSubBufferClass +{ + GstBufferClass buffer_class; +}; + +static void gst_subbuffer_init (GTypeInstance * instance, gpointer g_class); + +static GType +gst_subbuffer_get_type (void) +{ + static GType _gst_subbuffer_type; + + if (G_UNLIKELY (_gst_subbuffer_type == 0)) { + static const GTypeInfo subbuffer_info = { + sizeof (GstSubBufferClass), + NULL, + NULL, + NULL, + NULL, + NULL, + sizeof (GstSubBuffer), + 0, + gst_subbuffer_init, + NULL + }; + + _gst_subbuffer_type = g_type_register_static (GST_TYPE_BUFFER, + "GstSubBuffer", &subbuffer_info, 0); + } + return _gst_subbuffer_type; +} + +static void +gst_subbuffer_init (GTypeInstance * instance, gpointer g_class) +{ + +} + /** - * gst_buffer_create_sub: + * gst_buffer_create_subbuffer: * @parent: a parent #GstBuffer to create a subbuffer from. * @offset: the offset into parent #GstBuffer. * @size: the size of the new #GstBuffer sub-buffer (with size > 0). @@ -319,64 +320,51 @@ gst_buffer_set_caps (GstBuffer * buffer, GstCaps * caps) * MT safe. */ GstBuffer * -gst_buffer_create_sub (GstBuffer * parent, guint offset, guint size) +gst_buffer_create_sub (GstBuffer * buffer, guint offset, guint size) { - GstBuffer *buffer; - gpointer buffer_data; + GstSubBuffer *subbuffer; + GstBuffer *parent; - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (parent) > 0, NULL); + g_return_val_if_fail (buffer != NULL, NULL); + g_return_val_if_fail (buffer->mini_object.refcount > 0, NULL); g_return_val_if_fail (size > 0, NULL); - g_return_val_if_fail (parent->size >= offset + size, NULL); + g_return_val_if_fail (buffer->size >= offset + size, NULL); - /* remember the data for the new buffer */ - buffer_data = parent->data + offset; - /* make sure we're child not child from a child buffer */ - while (GST_BUFFER_FLAG_IS_SET (parent, GST_BUFFER_SUBBUFFER)) { - parent = GST_BUFFER (parent->buffer_private); + /* find real parent */ + if (GST_IS_SUBBUFFER (buffer)) { + parent = GST_SUBBUFFER (buffer)->parent; + } else { + parent = buffer; } - /* ref the real parent */ - gst_data_ref (GST_DATA (parent)); + gst_buffer_ref (parent); /* create the new buffer */ - buffer = gst_buffer_alloc_chunk (); + subbuffer = (GstSubBuffer *) gst_mini_object_new (GST_TYPE_SUBBUFFER); + subbuffer->parent = parent; - GST_CAT_LOG (GST_CAT_BUFFER, "new subbuffer %p (parent %p)", buffer, parent); - - /* make sure nobody overwrites data in the new buffer - * by setting the READONLY flag */ - _GST_DATA_INIT (GST_DATA (buffer), - _gst_buffer_type, - GST_DATA_FLAG_SHIFT (GST_BUFFER_SUBBUFFER) | - GST_DATA_FLAG_SHIFT (GST_DATA_READONLY), - (GstDataFreeFunction) _gst_buffer_sub_free, - (GstDataCopyFunction) gst_buffer_default_copy); + GST_CAT_LOG (GST_CAT_BUFFER, "new subbuffer %p (parent %p)", subbuffer, + parent); /* set the right values in the child */ - GST_BUFFER_DATA (buffer) = buffer_data; - GST_BUFFER_SIZE (buffer) = size; - GST_BUFFER_MAXSIZE (buffer) = size; - GST_BUFFER_FREE_DATA_FUNC (buffer) = NULL; - GST_BUFFER_PRIVATE (buffer) = parent; + GST_BUFFER_DATA (GST_BUFFER (subbuffer)) = buffer->data + offset; + GST_BUFFER_SIZE (GST_BUFFER (subbuffer)) = size; + /* we can copy the timestamp and offset if the new buffer starts at * offset 0 */ if (offset == 0) { - GST_BUFFER_TIMESTAMP (buffer) = GST_BUFFER_TIMESTAMP (parent); - GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET (parent); + GST_BUFFER_TIMESTAMP (subbuffer) = GST_BUFFER_TIMESTAMP (buffer); + GST_BUFFER_OFFSET (subbuffer) = GST_BUFFER_OFFSET (buffer); } else { - GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE; - GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE; + GST_BUFFER_TIMESTAMP (subbuffer) = GST_CLOCK_TIME_NONE; + GST_BUFFER_OFFSET (subbuffer) = GST_BUFFER_OFFSET_NONE; } - GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE; - GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE; + GST_BUFFER_DURATION (subbuffer) = GST_CLOCK_TIME_NONE; + GST_BUFFER_OFFSET_END (subbuffer) = GST_BUFFER_OFFSET_NONE; - if (GST_BUFFER_FLAG_IS_SET (parent, GST_BUFFER_READONLY)) { - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_READONLY); - } - GST_BUFFER_CAPS (buffer) = NULL; + GST_BUFFER_CAPS (subbuffer) = NULL; - return buffer; + return GST_BUFFER (subbuffer); } /** @@ -395,6 +383,8 @@ gst_buffer_create_sub (GstBuffer * parent, guint offset, guint size) gboolean gst_buffer_is_span_fast (GstBuffer * buf1, GstBuffer * buf2) { + return FALSE; +#if 0 g_return_val_if_fail (buf1 != NULL && buf2 != NULL, FALSE); g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buf1) > 0, FALSE); g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buf2) > 0, FALSE); @@ -404,6 +394,7 @@ gst_buffer_is_span_fast (GstBuffer * buf1, GstBuffer * buf2) (GST_BUFFER_FLAG_IS_SET (buf2, GST_BUFFER_SUBBUFFER)) && (buf1->buffer_private == buf2->buffer_private) && ((buf1->data + buf1->size) == buf2->data)); +#endif } /** @@ -432,6 +423,8 @@ GstBuffer * gst_buffer_span (GstBuffer * buf1, guint32 offset, GstBuffer * buf2, guint32 len) { + return NULL; +#if 0 GstBuffer *newbuf; g_return_val_if_fail (buf1 != NULL && buf2 != NULL, NULL); @@ -481,4 +474,5 @@ gst_buffer_span (GstBuffer * buf1, guint32 offset, GstBuffer * buf2, } return newbuf; +#endif } diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 915e5e6d97..ee245cb135 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -24,45 +24,36 @@ #ifndef __GST_BUFFER_H__ #define __GST_BUFFER_H__ -#include +#include #include #include G_BEGIN_DECLS typedef struct _GstBuffer GstBuffer; - -typedef void (*GstBufferFreeDataFunc) (GstBuffer *buffer); +typedef struct _GstBufferClass GstBufferClass; #define GST_BUFFER_TRACE_NAME "GstBuffer" -extern GType _gst_buffer_type; - #define GST_TYPE_BUFFER (gst_buffer_get_type()) +#define GST_IS_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER)) +#define GST_IS_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER)) +#define GST_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER, GstBufferClass)) +#define GST_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER, GstBuffer)) +#define GST_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER, GstBufferClass)) -#define GST_BUFFER(buf) ((GstBuffer *)(buf)) -#define GST_IS_BUFFER(buf) (GST_DATA_TYPE(buf) == GST_TYPE_BUFFER) - -#define GST_BUFFER_REFCOUNT(buf) GST_DATA_REFCOUNT(buf) -#define GST_BUFFER_REFCOUNT_VALUE(buf) GST_DATA_REFCOUNT_VALUE(buf) -#define GST_BUFFER_COPY_FUNC(buf) GST_DATA_COPY_FUNC(buf) -#define GST_BUFFER_FREE_FUNC(buf) GST_DATA_FREE_FUNC(buf) - -#define GST_BUFFER_FLAGS(buf) GST_DATA_FLAGS(buf) -#define GST_BUFFER_FLAG_IS_SET(buf,flag) GST_DATA_FLAG_IS_SET (buf, flag) -#define GST_BUFFER_FLAG_SET(buf,flag) GST_DATA_FLAG_SET (buf, flag) -#define GST_BUFFER_FLAG_UNSET(buf,flag) GST_DATA_FLAG_UNSET (buf, flag) +#define GST_BUFFER_FLAGS(buf) GST_MINI_OBJECT_FLAGS(buf) +#define GST_BUFFER_FLAG_IS_SET(buf,flag) GST_MINI_OBJECT_FLAG_IS_SET (buf, flag) +#define GST_BUFFER_FLAG_SET(buf,flag) GST_MINI_OBJECT_FLAG_SET (buf, flag) +#define GST_BUFFER_FLAG_UNSET(buf,flag) GST_MINI_OBJECT_FLAG_UNSET (buf, flag) #define GST_BUFFER_DATA(buf) (GST_BUFFER(buf)->data) #define GST_BUFFER_SIZE(buf) (GST_BUFFER(buf)->size) -#define GST_BUFFER_MAXSIZE(buf) (GST_BUFFER(buf)->maxsize) #define GST_BUFFER_TIMESTAMP(buf) (GST_BUFFER(buf)->timestamp) #define GST_BUFFER_DURATION(buf) (GST_BUFFER(buf)->duration) #define GST_BUFFER_CAPS(buf) (GST_BUFFER(buf)->caps) #define GST_BUFFER_OFFSET(buf) (GST_BUFFER(buf)->offset) #define GST_BUFFER_OFFSET_END(buf) (GST_BUFFER(buf)->offset_end) -#define GST_BUFFER_FREE_DATA_FUNC(buf) (GST_BUFFER(buf)->free_data) -#define GST_BUFFER_PRIVATE(buf) (GST_BUFFER(buf)->buffer_private) #define GST_BUFFER_OFFSET_NONE ((guint64)-1) #define GST_BUFFER_MAXSIZE_NONE ((guint)0) @@ -75,44 +66,37 @@ extern GType _gst_buffer_type; /** * GstBufferFlag: - * @GST_BUFFER_READONLY: the buffer is read-only. - * @GST_BUFFER_SUBBUFFER: the buffer is a subbuffer, the parent buffer can be - * found with the GST_BUFFER_POOL_PRIVATE() macro. - * @GST_BUFFER_ORIGINAL: buffer is not a copy of another buffer. - * @GST_BUFFER_DONTFREE: do not try to free the data when this buffer is - * unreferenced. - * @GST_BUFFER_PREROLL: the buffer is part of a preroll and should not be + * @GST_BUFFER_FLAG_READONLY: the buffer is read-only. + * @GST_BUFFER_FLAG_ORIGINAL: buffer is not a copy of another buffer. + * @GST_BUFFER_FLAG_PREROLL: the buffer is part of a preroll and should not be * displayed. - * @GST_BUFFER_DISCONT: the buffer marks a discontinuity in the stream. - * @GST_BUFFER_IN_CAPS: the buffer has been added as a field in a #GstCaps. - * @GST_BUFFER_GAP: the buffer has been created to fill a gap in the stream. - * @GST_BUFFER_DELTA_UNIT: this unit cannot be decoded independently. + * @GST_BUFFER_FLAG_DISCONT: the buffer marks a discontinuity in the stream. + * @GST_BUFFER_FLAG_IN_CAPS: the buffer has been added as a field in a #GstCaps. + * @GST_BUFFER_FLAG_GAP: the buffer has been created to fill a gap in the stream. + * @GST_BUFFER_FLAG_DELTA_UNIT: this unit cannot be decoded independently. * Since 0.8.5 * @GST_BUFFER_FLAG_LAST: additional flags can be added starting from this flag. * * A set of buffer flags used to describe properties of a #GstBuffer. */ typedef enum { - GST_BUFFER_READONLY = GST_DATA_READONLY, - GST_BUFFER_SUBBUFFER = GST_DATA_FLAG_LAST, - GST_BUFFER_ORIGINAL, /* original data, not copied, not currently used */ - GST_BUFFER_DONTFREE, /* buffer data is managed by somebody else and cannot be freeed */ - GST_BUFFER_PREROLL, /* sample should not be displayed */ - GST_BUFFER_DISCONT, /* buffer is first after discontinuity in the stream */ - GST_BUFFER_IN_CAPS, /* buffer is also part of caps */ - GST_BUFFER_GAP, /* buffer has been created to fill a gap in the stream */ - GST_BUFFER_DELTA_UNIT, /* can't be used as sync point in stream */ - GST_BUFFER_FLAG_LAST = GST_DATA_FLAG_LAST + 8 + GST_BUFFER_FLAG_READONLY = GST_MINI_OBJECT_FLAG_READONLY, + GST_BUFFER_FLAG_ORIGINAL = (GST_MINI_OBJECT_FLAG_LAST << 0), /* original data, not copied, not currently used */ + GST_BUFFER_FLAG_PREROLL = (GST_MINI_OBJECT_FLAG_LAST << 1), /* sample should not be displayed */ + GST_BUFFER_FLAG_DISCONT = (GST_MINI_OBJECT_FLAG_LAST << 2), /* buffer is first after discontinuity in the stream */ + GST_BUFFER_FLAG_IN_CAPS = (GST_MINI_OBJECT_FLAG_LAST << 3), /* buffer is also part of caps */ + GST_BUFFER_FLAG_GAP = (GST_MINI_OBJECT_FLAG_LAST << 4), /* buffer has been created to fill a gap in the stream */ + GST_BUFFER_FLAG_DELTA_UNIT = (GST_MINI_OBJECT_FLAG_LAST << 5), /* can't be used as sync point in stream */ + GST_BUFFER_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 8) } GstBufferFlag; struct _GstBuffer { - GstData data_type; + GstMiniObject mini_object; /*< public >*/ /* with COW */ /* pointer to data and its size */ guint8 *data; /* pointer to buffer data */ guint size; /* size of buffer data */ - guint maxsize; /* max size of this buffer */ /* timestamp */ GstClockTime timestamp; @@ -131,14 +115,17 @@ struct _GstBuffer { guint64 offset; guint64 offset_end; - /*< protected >*/ - GstBufferFreeDataFunc free_data; - gpointer buffer_private; - /*< private >*/ + guint8 *malloc_data; + gpointer _gst_reserved[GST_PADDING]; }; +struct _GstBufferClass { + GstMiniObjectClass mini_object_class; + +}; + /* allocation */ GType gst_buffer_get_type (void); GstBuffer* gst_buffer_new (void); @@ -151,15 +138,14 @@ G_STMT_START { \ } G_STMT_END /* refcounting */ -#define gst_buffer_ref(buf) GST_BUFFER (gst_data_ref (GST_DATA (buf))) -#define gst_buffer_ref_by_count(buf,c) GST_BUFFER (gst_data_ref_by_count (GST_DATA (buf), c)) -#define gst_buffer_unref(buf) gst_data_unref (GST_DATA (buf)) +#define gst_buffer_ref(buf) GST_BUFFER (gst_mini_object_ref (GST_MINI_OBJECT (buf))) +#define gst_buffer_unref(buf) gst_mini_object_unref (GST_MINI_OBJECT (buf)) /* copy buffer */ -#define gst_buffer_copy(buf) GST_BUFFER (gst_data_copy (GST_DATA (buf))) -#define gst_buffer_is_writable(buf) gst_data_is_writable (GST_DATA (buf)) -#define gst_buffer_copy_on_write(buf) GST_BUFFER (gst_data_copy_on_write (GST_DATA (buf))) +#define gst_buffer_copy(buf) GST_BUFFER (gst_mini_object_copy (GST_MINI_OBJECT (buf))) +#define gst_buffer_is_writable(buf) gst_mini_object_is_writable (GST_MINI_OBJECT (buf)) +#define gst_buffer_make_writable(buf) GST_BUFFER (gst_mini_object_make_writable (GST_MINI_OBJECT (buf))) -#define gst_buffer_replace(obuf,nbuf) gst_data_replace ((GstData **)(obuf), GST_DATA (nbuf)) +#define gst_buffer_replace(obuf,nbuf) gst_mini_object_replace ((GstMiniObject **)(obuf), GST_MINI_OBJECT (nbuf)) GstCaps* gst_buffer_get_caps (GstBuffer *buffer); void gst_buffer_set_caps (GstBuffer *buffer, GstCaps *caps); diff --git a/gst/gstdata.c b/gst/gstdata.c deleted file mode 100644 index ba1bfe28f9..0000000000 --- a/gst/gstdata.c +++ /dev/null @@ -1,292 +0,0 @@ -/* GStreamer - * Copyright (C) 1999,2000 Erik Walthinsen - * 2000 Wim Taymans - * - * gstdata.c: Data operations - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "gst_private.h" - -#include "gstdata.h" -#include "gstdata_private.h" -#include "gstinfo.h" -#include "gstutils.h" - -GType -gst_data_get_type (void) -{ - static GType type = 0; - - if (!type) - type = g_boxed_type_register_static ("GstData", - (GBoxedCopyFunc) gst_data_copy, (GBoxedFreeFunc) gst_data_unref); - return type; -} - -/** - * gst_data_init: - * @data: a #GstData to initialize - * @type: the type of this data - * @flags: flags for this data - * @free: a free function - * @copy: a copy function - * - * Initialize the given data structure with the given parameters. - * The free and copy function will be called when this data is freed - * or copied, respectively. - */ -void -gst_data_init (GstData * data, GType type, guint16 flags, - GstDataFreeFunction free, GstDataCopyFunction copy) -{ - g_return_if_fail (data != NULL); - - _GST_DATA_INIT (data, type, flags, free, copy); -} - -/** - * gst_data_copy_into: - * @data: a #GstData to copy - * @target: the target #GstData to copy into - * - * Copy the GstData into the specified target GstData structure. - * This method is mainly used by subclasses when they want to copy - * the relevant GstData info. - */ -void -gst_data_copy_into (const GstData * data, GstData * target) -{ - g_return_if_fail (data != NULL); -} - -/** - * gst_data_dispose: - * @data: a #GstData to dispose - * - * Free all the resources allocated in the gst_data_init() function, - * mainly used by subclass implementors. - */ -void -gst_data_dispose (GstData * data) -{ - g_return_if_fail (data != NULL); - - _GST_DATA_DISPOSE (data); -} - -/** - * gst_data_copy: - * @data: a #GstData to copy - * - * Copies the given #GstData. This function will call the custom subclass - * copy function or return NULL if no function was provided by the subclass. - * - * Returns: a copy of the data or NULL if the data cannot be copied. - * The refcount of the original buffer is not changed so you should unref it - * when you don't need it anymore. - * - * MT safe. - */ -GstData * -gst_data_copy (const GstData * data) -{ - g_return_val_if_fail (data != NULL, NULL); - - if (data->copy) - return data->copy (data); - - return NULL; -} - -/** - * gst_data_is_writable: - * @data: a #GstData to check - * - * Query if the data needs to be copied before it can safely be modified. - * - * Returns: FALSE if the given #GstData is potentially shared and needs to - * be copied before it can be modified safely. - * - * MT safe. - */ -gboolean -gst_data_is_writable (GstData * data) -{ - gint refcount; - - g_return_val_if_fail (data != NULL, FALSE); - - refcount = g_atomic_int_get (&data->refcount); - - /* if we have the only ref and the data is not readonly, we can - * safely write */ - if (refcount == 1 && !GST_DATA_FLAG_IS_SET (data, GST_DATA_READONLY)) - return TRUE; - - return FALSE; -} - -/** - * gst_data_copy_on_write: - * @data: a #GstData to copy - * - * Copies the given #GstData if the refcount is greater than 1 so that the - * #GstData object can be written to safely. - * - * Returns: a copy of the data if the refcount is > 1 or the buffer is - * marked READONLY, data if the refcount == 1, - * or NULL if the data could not be copied. - * - * The refcount of the passed @data is decreased when a copy is made, so - * you are not supposed to use it anymore after a call to this function. - * - * MT safe. - */ -GstData * -gst_data_copy_on_write (GstData * data) -{ - gint refcount; - - g_return_val_if_fail (data != NULL, NULL); - - refcount = g_atomic_int_get (&data->refcount); - - /* if we have the only ref and the data is not readonly, we can - * safely write, so we return the input data */ - if (refcount == 1 && !GST_DATA_FLAG_IS_SET (data, GST_DATA_READONLY)) - return GST_DATA (data); - - if (data->copy) { - GstData *copy = data->copy (data); - - gst_data_unref (data); - return copy; - } - - return NULL; -} - -/** - * gst_data_ref: - * @data: a #GstData to reference - * - * Increments the reference count of this data. - * - * Returns: the data - * - * MT safe. - */ -GstData * -gst_data_ref (GstData * data) -{ - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (GST_DATA_REFCOUNT_VALUE (data) > 0, NULL); - - GST_CAT_LOG (GST_CAT_BUFFER, "%p %d->%d", data, - GST_DATA_REFCOUNT_VALUE (data), GST_DATA_REFCOUNT_VALUE (data) + 1); - - g_atomic_int_inc (&data->refcount); - - return data; -} - -/** - * gst_data_ref_by_count: - * @data: a #GstData to reference - * @count: the number to increment the reference count by - * - * Increments the reference count of this data by the given number. - * - * Returns: the data - * - * MT safe. - */ -GstData * -gst_data_ref_by_count (GstData * data, gint count) -{ - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (count >= 0, NULL); - g_return_val_if_fail (GST_DATA_REFCOUNT_VALUE (data) > 0, NULL); - - GST_CAT_LOG (GST_CAT_BUFFER, "%p %d->%d", data, - GST_DATA_REFCOUNT_VALUE (data), GST_DATA_REFCOUNT_VALUE (data) + count); - - g_atomic_int_add (&data->refcount, count); - - return data; -} - -/** - * gst_data_unref: - * @data: a #GstData to unreference - * - * Decrements the refcount of this data. If the refcount is - * zero, the data will be freed. - * - * When you move data out of your element into the pipeline, - * the pipeline takes ownership of the - * data. When the data has been consumed by some element, it must unref() it. - * Applications usually don't need to unref() @data. - * - * MT safe. - */ -void -gst_data_unref (GstData * data) -{ - gint zero; - - g_return_if_fail (data != NULL); - - GST_CAT_LOG (GST_CAT_BUFFER, "%p %d->%d", data, - GST_DATA_REFCOUNT_VALUE (data), GST_DATA_REFCOUNT_VALUE (data) - 1); - g_return_if_fail (GST_DATA_REFCOUNT_VALUE (data) > 0); - - zero = g_atomic_int_dec_and_test (&data->refcount); - - /* if we ended up with the refcount at zero, free the data */ - if (zero) { - if (data->free) - data->free (data); - } -} - -/** - * gst_data_replace: - * @olddata: pointer to place of old GstData - * @newdata: new GstData - * - * Unrefs the data pointer to by olddata, refs the newdata and - * puts the newdata in *olddata. Be carefull when calling this - * function, it does not take any locks. You might want to lock - * the object owning the olddata pointer before calling this - * function. - * - * MT safe. - */ -void -gst_data_replace (GstData ** olddata, GstData * newdata) -{ - if (G_LIKELY (*olddata != newdata)) { - if (newdata) - gst_data_ref (newdata); - if (*olddata) - gst_data_unref (*olddata); - - *olddata = newdata; - } -} diff --git a/gst/gstdata.h b/gst/gstdata.h deleted file mode 100644 index 7d94fb845f..0000000000 --- a/gst/gstdata.h +++ /dev/null @@ -1,111 +0,0 @@ -/* GStreamer - * Copyright (C) 1999,2000 Erik Walthinsen - * 2000 Wim Taymans - * - * gstdata.h: Header for GstData objects (used for data passing) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#ifndef __GST_DATA_H__ -#define __GST_DATA_H__ - -#include -#include - -G_BEGIN_DECLS - -/* type */ -#define GST_DATA(data) ((GstData*)(data)) -#define GST_DATA_TYPE(data) (GST_DATA(data)->type) - -/* flags */ -#define GST_DATA_FLAGS(data) (GST_DATA(data)->flags) -#define GST_DATA_FLAG_SHIFT(flag) (1<<(flag)) -#define GST_DATA_FLAG_IS_SET(data,flag) (GST_DATA_FLAGS(data) & (1<<(flag))) -#define GST_DATA_FLAG_SET(data,flag) G_STMT_START{ (GST_DATA_FLAGS(data) |= (1<<(flag))); }G_STMT_END -#define GST_DATA_FLAG_UNSET(data,flag) G_STMT_START{ (GST_DATA_FLAGS(data) &= ~(1<<(flag))); }G_STMT_END - -/* Macros for the GType */ -#define GST_TYPE_DATA (gst_data_get_type ()) - -typedef struct _GstData GstData; - -typedef void (*GstDataFreeFunction) (GstData *data); -typedef GstData* (*GstDataCopyFunction) (const GstData *data); - -typedef enum -{ - GST_DATA_READONLY = 1, - - /* insert more */ - GST_DATA_FLAG_LAST = 8 -} GstDataFlags; - -/* refcount */ -#define GST_DATA_REFCOUNT(data) ((GST_DATA(data))->refcount) -#define GST_DATA_REFCOUNT_VALUE(data) (g_atomic_int_get (&(GST_DATA(data))->refcount)) - -/* copy/free functions */ -#define GST_DATA_COPY_FUNC(data) (GST_DATA(data)->copy) -#define GST_DATA_FREE_FUNC(data) (GST_DATA(data)->free) - - -struct _GstData { - GType type; - - /*< public >*/ /* with COW */ - /* refcounting */ - gint refcount; - - guint16 flags; - - /*< protected >*/ - /* utility function pointers, can override default */ - GstDataFreeFunction free; /* free the data */ - GstDataCopyFunction copy; /* copy the data */ - - /*< private >*/ - gpointer _gst_reserved[GST_PADDING]; -}; - -/* function used by subclasses only */ -void gst_data_init (GstData *data, GType type, guint16 flags, - GstDataFreeFunction free, - GstDataCopyFunction copy); -void gst_data_dispose (GstData *data); -void gst_data_copy_into (const GstData *data, GstData *target); - -/* basic operations on data */ -GstData* gst_data_copy (const GstData *data); -gboolean gst_data_is_writable (GstData *data); -GstData* gst_data_copy_on_write (GstData *data); - -/* reference counting */ -GstData* gst_data_ref (GstData* data); -GstData* gst_data_ref_by_count (GstData* data, gint count); -void gst_data_unref (GstData* data); - -/* replace data pointer */ -void gst_data_replace (GstData** olddata, GstData *newdata); - -/* GType for GstData */ -GType gst_data_get_type (void); - -G_END_DECLS - -#endif /* __GST_DATA_H__ */ diff --git a/gst/gstdata_private.h b/gst/gstdata_private.h deleted file mode 100644 index 7f5f55ab8c..0000000000 --- a/gst/gstdata_private.h +++ /dev/null @@ -1,35 +0,0 @@ -/* GStreamer - * Copyright (C) 1999,2000 Erik Walthinsen - * 2000 Wim Taymans - * - * gstdata_private.h: private gstdata stuff - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#define _GST_DATA_INIT(data, ptype, pflags, pfree, pcopy) \ -G_STMT_START { \ - (data)->refcount = 1; \ - (data)->type = ptype; \ - (data)->flags = pflags; \ - (data)->free = pfree; \ - (data)->copy = pcopy; \ -} G_STMT_END; - -#define _GST_DATA_DISPOSE(data) \ -G_STMT_START { \ -} G_STMT_END; - diff --git a/gst/gstelement.c b/gst/gstelement.c index 326c1ce7a3..acc037f5b0 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -1245,7 +1245,7 @@ gst_element_post_message (GstElement * element, GstMessage * message) if (G_UNLIKELY (bus == NULL)) { GST_DEBUG ("... but I won't because I have no bus"); GST_UNLOCK (element); - gst_data_unref (GST_DATA (message)); + gst_message_unref (message); return FALSE; } gst_object_ref (GST_OBJECT (bus)); diff --git a/gst/gstevent.c b/gst/gstevent.c index 831ac8cc63..78433a25d7 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -23,7 +23,6 @@ #include /* memcpy */ #include "gst_private.h" -#include "gstdata_private.h" #include "gstinfo.h" #include "gstmemchunk.h" @@ -37,62 +36,74 @@ static GstAllocTrace *_event_trace; #endif -static GstMemChunk *chunk; - -/* #define MEMPROF */ - -GType _gst_event_type; +static void gst_event_init (GTypeInstance * instance, gpointer g_class); +static void gst_event_class_init (gpointer g_class, gpointer class_data); +static void gst_event_finalize (GstEvent * event); +static GstEvent *_gst_event_copy (GstEvent * event); void _gst_event_initialize (void) { - /* register the type */ - _gst_event_type = g_boxed_type_register_static ("GstEvent", - (GBoxedCopyFunc) gst_data_copy, (GBoxedFreeFunc) gst_data_unref); + gst_event_get_type (); #ifndef GST_DISABLE_TRACE _event_trace = gst_alloc_trace_register (GST_EVENT_TRACE_NAME); #endif - - chunk = gst_mem_chunk_new ("GstEventChunk", sizeof (GstEvent), - sizeof (GstEvent) * 50, 0); } -static GstEvent * -_gst_event_copy (GstEvent * event) +GType +gst_event_get_type (void) { - GstEvent *copy; + static GType _gst_event_type; - copy = gst_mem_chunk_alloc (chunk); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_new (_event_trace, copy); -#endif + if (G_UNLIKELY (_gst_event_type == 0)) { + static const GTypeInfo event_info = { + sizeof (GstEventClass), + NULL, + NULL, + gst_event_class_init, + NULL, + NULL, + sizeof (GstEvent), + 0, + gst_event_init, + NULL + }; - memcpy (copy, event, sizeof (GstEvent)); - if (GST_EVENT_SRC (copy)) { - gst_object_ref (GST_EVENT_SRC (copy)); + _gst_event_type = g_type_register_static (GST_TYPE_MINI_OBJECT, + "GstEvent", &event_info, 0); } - /* FIXME copy/ref additional fields */ - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_TAG: - copy->event_data.structure.structure = - gst_tag_list_copy ((GstTagList *) event->event_data.structure. - structure); - break; - case GST_EVENT_NAVIGATION: - copy->event_data.structure.structure = - gst_structure_copy (event->event_data.structure.structure); - default: - break; - } - - return copy; + return _gst_event_type; } static void -_gst_event_free (GstEvent * event) +gst_event_class_init (gpointer g_class, gpointer class_data) { + GstEventClass *event_class = GST_EVENT_CLASS (g_class); + + event_class->mini_object_class.copy = + (GstMiniObjectCopyFunction) _gst_event_copy; + event_class->mini_object_class.finalize = + (GstMiniObjectFinalizeFunction) gst_event_finalize; +} + +static void +gst_event_init (GTypeInstance * instance, gpointer g_class) +{ + GstEvent *event; + + event = GST_EVENT (instance); + + GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE; +} + +static void +gst_event_finalize (GstEvent * event) +{ + g_return_if_fail (event != NULL); + g_return_if_fail (GST_IS_EVENT (event)); + GST_CAT_INFO (GST_CAT_EVENT, "freeing event %p", event); if (GST_EVENT_SRC (event)) { @@ -113,11 +124,38 @@ _gst_event_free (GstEvent * event) default: break; } - _GST_DATA_DISPOSE (GST_DATA (event)); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_free (_event_trace, event); -#endif - gst_mem_chunk_free (chunk, event); +} + + +static GstEvent * +_gst_event_copy (GstEvent * event) +{ + GstEvent *copy; + + copy = gst_event_new (event->type); + + copy->timestamp = event->timestamp; + if (event->src) { + copy->src = gst_object_ref (event->src); + } + + memcpy (©->event_data, &event->event_data, sizeof (event->event_data)); + + /* FIXME copy/ref additional fields */ + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_TAG: + copy->event_data.structure.structure = + gst_tag_list_copy ((GstTagList *) event->event_data.structure. + structure); + break; + case GST_EVENT_NAVIGATION: + copy->event_data.structure.structure = + gst_structure_copy (event->event_data.structure.structure); + default: + break; + } + + return copy; } /** @@ -148,12 +186,6 @@ gst_event_masks_contains (const GstEventMask * masks, GstEventMask * mask) return FALSE; } -GType -gst_event_get_type (void) -{ - return _gst_event_type; -} - /** * gst_event_new: * @type: The type of the new event @@ -167,22 +199,11 @@ gst_event_new (GstEventType type) { GstEvent *event; - event = gst_mem_chunk_alloc0 (chunk); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_new (_event_trace, event); -#endif + event = (GstEvent *) gst_mini_object_new (GST_TYPE_EVENT); GST_CAT_INFO (GST_CAT_EVENT, "creating new event type %d: %p", type, event); - _GST_DATA_INIT (GST_DATA (event), - _gst_event_type, - 0, - (GstDataFreeFunction) _gst_event_free, - (GstDataCopyFunction) _gst_event_copy); - GST_EVENT_TYPE (event) = type; - GST_EVENT_TIMESTAMP (event) = G_GINT64_CONSTANT (0); - GST_EVENT_SRC (event) = NULL; return event; } diff --git a/gst/gstevent.h b/gst/gstevent.h index 515f0bca72..624172b154 100644 --- a/gst/gstevent.h +++ b/gst/gstevent.h @@ -25,15 +25,13 @@ #define __GST_EVENT_H__ #include -#include +#include #include #include #include G_BEGIN_DECLS -GST_EXPORT GType _gst_event_type; - /** * GstEventType: * @GST_EVENT_UNKNOWN: @@ -63,9 +61,15 @@ typedef enum { #define GST_EVENT_TRACE_NAME "GstEvent" -#define GST_TYPE_EVENT (_gst_event_type) -#define GST_EVENT(event) ((GstEvent*)(event)) -#define GST_IS_EVENT(event) (GST_DATA_TYPE(event) == GST_TYPE_EVENT) +typedef struct _GstEvent GstEvent; +typedef struct _GstEventClass GstEventClass; + +#define GST_TYPE_EVENT (gst_event_get_type()) +#define GST_IS_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_EVENT)) +#define GST_IS_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_EVENT)) +#define GST_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_EVENT, GstEventClass)) +#define GST_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_EVENT, GstEvent)) +#define GST_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_EVENT, GstEventClass)) #define GST_EVENT_TYPE(event) (GST_EVENT(event)->type) #define GST_EVENT_TIMESTAMP(event) (GST_EVENT(event)->timestamp) @@ -166,7 +170,7 @@ typedef struct #define GST_EVENT_RATE_VALUE(event) (GST_EVENT(event)->event_data.rate.value) struct _GstEvent { - GstData data; + GstMiniObject mini_object; /*< public >*/ /* with COW */ GstEventType type; @@ -204,17 +208,21 @@ struct _GstEvent { gpointer _gst_reserved[GST_PADDING]; }; +struct _GstEventClass { + GstMiniObjectClass mini_object_class; + +}; + void _gst_event_initialize (void); GType gst_event_get_type (void); GstEvent* gst_event_new (GstEventType type); /* refcounting */ -#define gst_event_ref(ev) GST_EVENT (gst_data_ref (GST_DATA (ev))) -#define gst_event_ref_by_count(ev,c) GST_EVENT (gst_data_ref_by_count (GST_DATA (ev), c)) -#define gst_event_unref(ev) gst_data_unref (GST_DATA (ev)) +#define gst_event_ref(ev) GST_EVENT (gst_mini_object_ref (GST_MINI_OBJECT (ev))) +#define gst_event_unref(ev) gst_mini_object_unref (GST_MINI_OBJECT (ev)) /* copy buffer */ -#define gst_event_copy(ev) GST_EVENT (gst_data_copy (GST_DATA (ev))) +#define gst_event_copy(ev) GST_EVENT (gst_mini_object_copy (GST_MINI_OBJECT (ev))) gboolean gst_event_masks_contains (const GstEventMask *masks, GstEventMask *mask); diff --git a/gst/gstmarshal.list b/gst/gstmarshal.list index 30d2349080..7d34089efd 100644 --- a/gst/gstmarshal.list +++ b/gst/gstmarshal.list @@ -7,6 +7,7 @@ VOID:BOXED,OBJECT VOID:POINTER VOID:POINTER,OBJECT VOID:OBJECT +VOID:OBJECT,OBJECT VOID:OBJECT,PARAM VOID:OBJECT,POINTER VOID:OBJECT,BOXED diff --git a/gst/gstmessage.c b/gst/gstmessage.c index ab887a8a13..272945f47a 100644 --- a/gst/gstmessage.c +++ b/gst/gstmessage.c @@ -23,7 +23,6 @@ #include /* memcpy */ #include "gst_private.h" -#include "gstdata_private.h" #include "gstinfo.h" #include "gstmemchunk.h" #include "gstmessage.h" @@ -36,59 +35,72 @@ static GstAllocTrace *_message_trace; #endif -static GstMemChunk *chunk; - -/* #define MEMPROF */ - -GType _gst_message_type; +static void gst_message_init (GTypeInstance * instance, gpointer g_class); +static void gst_message_class_init (gpointer g_class, gpointer class_data); +static void gst_message_finalize (GstMessage * message); +static GstMessage *_gst_message_copy (GstMessage * message); void _gst_message_initialize (void) { GST_CAT_INFO (GST_CAT_GST_INIT, "init messages"); - /* register the type */ - _gst_message_type = g_boxed_type_register_static ("GstMessage", - (GBoxedCopyFunc) gst_data_copy, (GBoxedFreeFunc) gst_data_unref); + gst_message_get_type (); #ifndef GST_DISABLE_TRACE _message_trace = gst_alloc_trace_register (GST_MESSAGE_TRACE_NAME); #endif - - chunk = gst_mem_chunk_new ("GstMessageChunk", sizeof (GstMessage), - sizeof (GstMessage) * 50, 0); } -static GstMessage * -_gst_message_copy (GstMessage * message) +GType +gst_message_get_type (void) { - GstMessage *copy; + static GType _gst_message_type; - GST_CAT_INFO (GST_CAT_MESSAGE, "copy message %p", message); + if (G_UNLIKELY (_gst_message_type == 0)) { + static const GTypeInfo message_info = { + sizeof (GstMessageClass), + NULL, + NULL, + gst_message_class_init, + NULL, + NULL, + sizeof (GstMessage), + 0, + gst_message_init, + NULL + }; - copy = gst_mem_chunk_alloc (chunk); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_new (_message_trace, copy); -#endif - - memcpy (copy, message, sizeof (GstMessage)); - if (GST_MESSAGE_SRC (copy)) { - gst_object_ref (GST_MESSAGE_SRC (copy)); + _gst_message_type = g_type_register_static (GST_TYPE_MINI_OBJECT, + "GstMessage", &message_info, 0); } - - if (message->structure) { - copy->structure = gst_structure_copy (message->structure); - gst_structure_set_parent_refcount (copy->structure, - &GST_DATA_REFCOUNT (message)); - } - - return copy; + return _gst_message_type; } static void -_gst_message_free (GstMessage * message) +gst_message_class_init (gpointer g_class, gpointer class_data) { - GST_CAT_INFO (GST_CAT_MESSAGE, "freeing message %p", message); + GstMessageClass *message_class = GST_MESSAGE_CLASS (g_class); + + message_class->mini_object_class.copy = + (GstMiniObjectCopyFunction) _gst_message_copy; + message_class->mini_object_class.finalize = + (GstMiniObjectFinalizeFunction) gst_message_finalize; +} + +static void +gst_message_init (GTypeInstance * instance, gpointer g_class) +{ + GstMessage *message = GST_MESSAGE (instance); + + message->timestamp = GST_CLOCK_TIME_NONE; + +} + +static void +gst_message_finalize (GstMessage * message) +{ + g_return_if_fail (message != NULL); if (GST_MESSAGE_SRC (message)) { gst_object_unref (GST_MESSAGE_SRC (message)); @@ -104,18 +116,36 @@ _gst_message_free (GstMessage * message) gst_structure_set_parent_refcount (message->structure, NULL); gst_structure_free (message->structure); } - - _GST_DATA_DISPOSE (GST_DATA (message)); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_free (_message_trace, message); -#endif - gst_mem_chunk_free (chunk, message); } -GType -gst_message_get_type (void) +static GstMessage * +_gst_message_copy (GstMessage * message) { - return _gst_message_type; + GstMessage *copy; + + GST_CAT_INFO (GST_CAT_MESSAGE, "copy message %p", message); + + copy = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE); + + /* FIXME */ + //memcpy (copy, message, sizeof (GstMessage)); + + copy->lock = message->lock; + copy->cond = message->cond; + copy->type = message->type; + copy->timestamp = message->timestamp; + + if (GST_MESSAGE_SRC (message)) { + GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message)); + } + + if (message->structure) { + copy->structure = gst_structure_copy (message->structure); + gst_structure_set_parent_refcount (copy->structure, + &message->mini_object.refcount); + } + + return copy; } /** @@ -133,32 +163,21 @@ gst_message_new (GstMessageType type, GstObject * src) { GstMessage *message; - message = gst_mem_chunk_alloc0 (chunk); -#ifndef GST_DISABLE_TRACE - gst_alloc_trace_new (_message_trace, message); -#endif + message = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE); GST_CAT_INFO (GST_CAT_MESSAGE, "creating new message %p %d", message, type); - _GST_DATA_INIT (GST_DATA (message), - _gst_message_type, - 0, - (GstDataFreeFunction) _gst_message_free, - (GstDataCopyFunction) _gst_message_copy); - - GST_MESSAGE_TYPE (message) = type; - GST_MESSAGE_TIMESTAMP (message) = G_GINT64_CONSTANT (0); + message->type = type; if (src) { - GST_MESSAGE_SRC (message) = gst_object_ref (src); + message->src = gst_object_ref (src); } else { - GST_MESSAGE_SRC (message) = NULL; + message->src = NULL; } message->structure = NULL; return message; } - /** * gst_message_new_eos: * @@ -200,7 +219,7 @@ gst_message_new_error (GstObject * src, GError * error, gchar * debug) message = gst_message_new (GST_MESSAGE_ERROR, src); s = gst_structure_new ("GstMessageError", "gerror", G_TYPE_POINTER, error, "debug", G_TYPE_STRING, debug, NULL); - gst_structure_set_parent_refcount (s, &GST_DATA_REFCOUNT (message)); + gst_structure_set_parent_refcount (s, &message->mini_object.refcount); message->structure = s; return message; @@ -228,7 +247,7 @@ gst_message_new_warning (GstObject * src, GError * error, gchar * debug) message = gst_message_new (GST_MESSAGE_WARNING, src); s = gst_structure_new ("GstMessageWarning", "gerror", G_TYPE_POINTER, error, "debug", G_TYPE_STRING, debug, NULL); - gst_structure_set_parent_refcount (s, &GST_DATA_REFCOUNT (message)); + gst_structure_set_parent_refcount (s, &message->mini_object.refcount); message->structure = s; return message; @@ -253,7 +272,7 @@ gst_message_new_tag (GstObject * src, GstTagList * tag_list) g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL); message = gst_message_new (GST_MESSAGE_TAG, src); - gst_structure_set_parent_refcount (tag_list, &GST_DATA_REFCOUNT (message)); + gst_structure_set_parent_refcount (tag_list, &message->mini_object.refcount); message->structure = tag_list; return message; @@ -282,7 +301,7 @@ gst_message_new_state_changed (GstObject * src, GstElementState old, s = gst_structure_new ("GstMessageError", "old-state", G_TYPE_INT, (gint) old, "new-state", G_TYPE_INT, (gint) new, NULL); - gst_structure_set_parent_refcount (s, &GST_DATA_REFCOUNT (message)); + gst_structure_set_parent_refcount (s, &message->mini_object.refcount); message->structure = s; return message; @@ -308,7 +327,7 @@ gst_message_new_application (GstStructure * structure) g_return_val_if_fail (GST_IS_STRUCTURE (structure), NULL); message = gst_message_new (GST_MESSAGE_APPLICATION, NULL); - gst_structure_set_parent_refcount (structure, &GST_DATA_REFCOUNT (message)); + gst_structure_set_parent_refcount (structure, &message->mini_object.refcount); message->structure = structure; return message; diff --git a/gst/gstmessage.h b/gst/gstmessage.h index 91a5743b1a..3d1846fced 100644 --- a/gst/gstmessage.h +++ b/gst/gstmessage.h @@ -23,15 +23,13 @@ #define __GST_MESSAGE_H__ #include -#include +#include #include #include #include G_BEGIN_DECLS -GST_EXPORT GType _gst_message_type; - /** * GstMessageType: * @GST_MESSAGE_UNKNOWN: an undefined message @@ -71,9 +69,15 @@ typedef enum #define GST_MESSAGE_TRACE_NAME "GstMessage" -#define GST_TYPE_MESSAGE (_gst_message_type) -#define GST_MESSAGE(message) ((GstMessage*)(message)) -#define GST_IS_MESSAGE(message) (GST_DATA_TYPE(message) == GST_TYPE_MESSAGE) +typedef struct _GstMessage GstMessage; +typedef struct _GstMessageClass GstMessageClass; + +#define GST_TYPE_MESSAGE (gst_message_get_type()) +#define GST_IS_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MESSAGE)) +#define GST_IS_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MESSAGE)) +#define GST_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MESSAGE, GstMessageClass)) +#define GST_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MESSAGE, GstMessage)) +#define GST_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MESSAGE, GstMessageClass)) /* the lock is used to handle the synchronous handling of messages, * the emiting thread is block until the handling thread processed @@ -91,7 +95,7 @@ typedef enum struct _GstMessage { - GstData data; + GstMiniObject mini_object; /*< public > *//* with MESSAGE_LOCK */ GMutex *lock; /* lock and cond for async delivery */ @@ -108,17 +112,20 @@ struct _GstMessage gpointer _gst_reserved[GST_PADDING]; }; +struct _GstMessageClass { + GstMiniObjectClass mini_object_class; +}; + void _gst_message_initialize (void); GType gst_message_get_type (void); /* refcounting */ -#define gst_message_ref(msg) GST_MESSAGE (gst_data_ref (GST_DATA (msg))) -#define gst_message_ref_by_count(msg,c) GST_MESSAGE (gst_data_ref_by_count (GST_DATA (msg), (c))) -#define gst_message_unref(msg) gst_data_unref (GST_DATA (msg)) +#define gst_message_ref(msg) GST_MESSAGE (gst_mini_object_ref (GST_MINI_OBJECT (msg))) +#define gst_message_unref(msg) gst_mini_object_unref (GST_MINI_OBJECT (msg)) /* copy message */ -#define gst_message_copy(msg) GST_MESSAGE (gst_data_copy (GST_DATA (msg))) -#define gst_message_copy_on_write(msg) GST_MESSAGE (gst_data_copy_on_write (GST_DATA (msg))) +#define gst_message_copy(msg) GST_MESSAGE (gst_mini_object_copy (GST_MINI_OBJECT (msg))) +#define gst_message_make_writable(msg) GST_MESSAGE (gst_mini_object_make_writable (GST_MINI_OBJECT (msg))) GstMessage * gst_message_new_eos (GstObject * src); GstMessage * gst_message_new_error (GstObject * src, GError * error, gchar * debug); diff --git a/gst/gstminiobject.c b/gst/gstminiobject.c new file mode 100644 index 0000000000..39b1d297ac --- /dev/null +++ b/gst/gstminiobject.c @@ -0,0 +1,360 @@ +/* GStreamer + * Copyright (C) 2005 David Schleef + * + * gstminiobject.h: Header for GstMiniObject + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gst/gstminiobject.h" +#include "gst/gstinfo.h" +#include "gst/gst_private.h" +#include + +static void gst_mini_object_base_init (gpointer g_class); +static void gst_mini_object_base_finalize (gpointer g_class); +static void gst_mini_object_class_init (gpointer g_class, gpointer class_data); +static void gst_mini_object_init (GTypeInstance * instance, gpointer klass); + +static void gst_value_mini_object_init (GValue * value); +static void gst_value_mini_object_free (GValue * value); +static void gst_value_mini_object_copy (const GValue * src_value, + GValue * dest_value); +static gpointer gst_value_mini_object_peek_pointer (const GValue * value); +static gchar *gst_value_mini_object_collect (GValue * value, + guint n_collect_values, GTypeCValue * collect_values, guint collect_flags); +static gchar *gst_value_mini_object_lcopy (const GValue * value, + guint n_collect_values, GTypeCValue * collect_values, guint collect_flags); + +GType +gst_mini_object_get_type (void) +{ + static GType _gst_mini_object_type; + + if (!_gst_mini_object_type) { + GTypeValueTable value_table = { + gst_value_mini_object_init, + gst_value_mini_object_free, + gst_value_mini_object_copy, + gst_value_mini_object_peek_pointer, + "p", + gst_value_mini_object_collect, + "p", + gst_value_mini_object_lcopy + }; + GTypeInfo mini_object_info = { + sizeof (GstMiniObjectClass), + gst_mini_object_base_init, + gst_mini_object_base_finalize, + gst_mini_object_class_init, + NULL, + NULL, + sizeof (GstMiniObject), + 0, + (GInstanceInitFunc) gst_mini_object_init, + NULL + }; + static const GTypeFundamentalInfo mini_object_fundamental_info = { + (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | + G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) + }; + + mini_object_info.value_table = &value_table; + + _gst_mini_object_type = g_type_fundamental_next (); + g_type_register_fundamental (_gst_mini_object_type, "GstMiniObject", + &mini_object_info, &mini_object_fundamental_info, G_TYPE_FLAG_ABSTRACT); + } + + return _gst_mini_object_type; +} + +static void +gst_mini_object_base_init (gpointer g_class) +{ + /* do nothing */ +} + +static void +gst_mini_object_base_finalize (gpointer g_class) +{ + /* do nothing */ +} + +static void +gst_mini_object_class_init (gpointer g_class, gpointer class_data) +{ + /* do nothing */ +} + +static void +gst_mini_object_init (GTypeInstance * instance, gpointer klass) +{ + GstMiniObject *mini_object = GST_MINI_OBJECT (instance); + + mini_object->refcount = 1; +} + +GstMiniObject * +gst_mini_object_new (GType type) +{ + //GstMiniObjectClass *klass; + GstMiniObject *mini_object; + +#if 0 + klass = g_type_class_peek_static (type); + if (!klass) { + g_warning ("cannot find class for type '%s'", g_type_name (type)); + return NULL; + } +#endif + /* we don't support dynamic types because they really aren't useful, + * and could cause refcount problems */ + + mini_object = (GstMiniObject *) g_type_create_instance (type); + + return mini_object; +} + +GstMiniObject * +gst_mini_object_copy (const GstMiniObject * mini_object) +{ + GstMiniObjectClass *mo_class; + + mo_class = GST_MINI_OBJECT_GET_CLASS (mini_object); + + return mo_class->copy (mini_object); +} + +gboolean +gst_mini_object_is_writable (const GstMiniObject * mini_object) +{ + return (mini_object->refcount == 1) && + ((mini_object->flags & GST_MINI_OBJECT_FLAG_READONLY) == 0); +} + +GstMiniObject * +gst_mini_object_make_writable (const GstMiniObject * mini_object) +{ + if (gst_mini_object_is_writable (mini_object)) { + return (GstMiniObject *) mini_object; + } + return gst_mini_object_copy (mini_object); +} + +GstMiniObject * +gst_mini_object_ref (GstMiniObject * mini_object) +{ + g_return_val_if_fail (mini_object != NULL, NULL); + + g_atomic_int_inc (&mini_object->refcount); + + return mini_object; +} + + +static void +gst_mini_object_free (GstMiniObject * mini_object) +{ + GstMiniObjectClass *mo_class; + + mo_class = GST_MINI_OBJECT_GET_CLASS (mini_object); + mo_class->finalize (mini_object); + + g_type_free_instance ((GTypeInstance *) mini_object); +} + +void +gst_mini_object_unref (GstMiniObject * mini_object) +{ + g_return_if_fail (mini_object != NULL); + g_return_if_fail (mini_object->refcount > 0); + + if (g_atomic_int_dec_and_test (&mini_object->refcount)) { + gst_mini_object_free (mini_object); + } +} + +void +gst_mini_object_replace (GstMiniObject ** olddata, GstMiniObject * newdata) +{ + GstMiniObject *olddata_val; + + if (newdata) { + gst_mini_object_ref (newdata); + } + + do { + olddata_val = *olddata; + } while (!g_atomic_pointer_compare_and_exchange ((gpointer *) olddata, + olddata_val, newdata)); + + if (olddata_val) { + gst_mini_object_unref (olddata_val); + } +} + +static void +gst_value_mini_object_init (GValue * value) +{ + value->data[0].v_pointer = NULL; +} + +static void +gst_value_mini_object_free (GValue * value) +{ + if (value->data[0].v_pointer) { + gst_mini_object_unref (GST_MINI_OBJECT (value->data[0].v_pointer)); + } +} + +static void +gst_value_mini_object_copy (const GValue * src_value, GValue * dest_value) +{ + if (src_value->data[0].v_pointer) { + dest_value->data[0].v_pointer = + gst_mini_object_ref (GST_MINI_OBJECT (src_value->data[0].v_pointer)); + } else { + dest_value->data[0].v_pointer = NULL; + } +} + +static gpointer +gst_value_mini_object_peek_pointer (const GValue * value) +{ + return value->data[0].v_pointer; +} + +static gchar * +gst_value_mini_object_collect (GValue * value, guint n_collect_values, + GTypeCValue * collect_values, guint collect_flags) +{ + value->data[0].v_pointer = collect_values[0].v_pointer; + + return NULL; +} + +static gchar * +gst_value_mini_object_lcopy (const GValue * value, guint n_collect_values, + GTypeCValue * collect_values, guint collect_flags) +{ + gpointer *mini_object_p = collect_values[0].v_pointer; + + if (!mini_object_p) { + return g_strdup_printf ("value location for '%s' passed as NULL", + G_VALUE_TYPE_NAME (value)); + } + + *mini_object_p = value->data[0].v_pointer; + + return NULL; +} + +/* param spec */ + +static GType gst_param_spec_mini_object_get_type (void); + +#define GST_TYPE_PARAM_SPEC_MINI_OBJECT (gst_param_spec_mini_object_get_type()) +#define GST_PARAM_SPEC_MINI_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_PARAM_SPEC_MINI_OBJECT, GstParamSpecMiniObject)) + +typedef struct _GstParamSpecMiniObject GstParamSpecMiniObject; +struct _GstParamSpecMiniObject +{ + GParamSpec parent_instance; +}; + +static void +param_mini_object_init (GParamSpec * pspec) +{ + /* GParamSpecMiniObject *ospec = G_PARAM_SPEC_MINI_OBJECT (pspec); */ +} + +static void +param_mini_object_set_default (GParamSpec * pspec, GValue * value) +{ + value->data[0].v_pointer = NULL; +} + +static gboolean +param_mini_object_validate (GParamSpec * pspec, GValue * value) +{ + GstParamSpecMiniObject *ospec = GST_PARAM_SPEC_MINI_OBJECT (pspec); + GstMiniObject *mini_object = value->data[0].v_pointer; + guint changed = 0; + + if (mini_object + && !g_value_type_compatible (G_OBJECT_TYPE (mini_object), + G_PARAM_SPEC_VALUE_TYPE (ospec))) { + gst_mini_object_unref (mini_object); + value->data[0].v_pointer = NULL; + changed++; + } + + return changed; +} + +static gint +param_mini_object_values_cmp (GParamSpec * pspec, + const GValue * value1, const GValue * value2) +{ + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; + + /* not much to compare here, try to at least provide stable lesser/greater result */ + + return p1 < p2 ? -1 : p1 > p2; +} + +static GType +gst_param_spec_mini_object_get_type (void) +{ + static GType type; + + if (G_UNLIKELY (type) == 0) { + static const GParamSpecTypeInfo pspec_info = { + sizeof (GstParamSpecMiniObject), /* instance_size */ + 16, /* n_preallocs */ + param_mini_object_init, /* instance_init */ + G_TYPE_OBJECT, /* value_type */ + NULL, /* finalize */ + param_mini_object_set_default, /* value_set_default */ + param_mini_object_validate, /* value_validate */ + param_mini_object_values_cmp, /* values_cmp */ + }; + type = g_param_type_register_static ("GParamSpecMiniObject", &pspec_info); + } + + return type; +} + +GParamSpec * +gst_param_spec_mini_object (const char *name, const char *nick, + const char *blurb, GType object_type, GParamFlags flags) +{ + GstParamSpecMiniObject *ospec; + + g_return_val_if_fail (g_type_is_a (object_type, GST_TYPE_MINI_OBJECT), NULL); + + ospec = g_param_spec_internal (GST_TYPE_PARAM_SPEC_MINI_OBJECT, + name, nick, blurb, flags); + G_PARAM_SPEC (ospec)->value_type = object_type; + + return G_PARAM_SPEC (ospec); +} diff --git a/gst/gstminiobject.h b/gst/gstminiobject.h new file mode 100644 index 0000000000..c055c402fe --- /dev/null +++ b/gst/gstminiobject.h @@ -0,0 +1,92 @@ +/* GStreamer + * Copyright (C) 2005 David Schleef + * + * gstminiobject.h: Header for GstMiniObject + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_MINI_OBJECT_H__ +#define __GST_MINI_OBJECT_H__ + +#include +#include "gst/gsttypes.h" + +G_BEGIN_DECLS + +#define GST_TYPE_MINI_OBJECT (gst_mini_object_get_type()) +#define GST_IS_MINI_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MINI_OBJECT)) +#define GST_IS_MINI_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MINI_OBJECT)) +#define GST_MINI_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MINI_OBJECT, GstMiniObjectClass)) +#define GST_MINI_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MINI_OBJECT, GstMiniObject)) +#define GST_MINI_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MINI_OBJECT, GstMiniObjectClass)) + +typedef struct _GstMiniObject GstMiniObject; +typedef struct _GstMiniObjectClass GstMiniObjectClass; + +typedef GstMiniObject * (*GstMiniObjectCopyFunction) (const GstMiniObject *); +typedef void (*GstMiniObjectFinalizeFunction) (GstMiniObject *); + +#define GST_MINI_OBJECT_FLAGS(obj) (GST_MINI_OBJECT(obj)->flags) +#define GST_MINI_OBJECT_FLAG_IS_SET(obj,flag) (GST_MINI_OBJECT_FLAGS(obj) & (flag)) +#define GST_MINI_OBJECT_FLAG_SET(obj,flag) (GST_MINI_OBJECT_FLAGS (obj) |= (flag)) +#define GST_MINI_OBJECT_FLAG_UNSET(obj,flag) (GST_MINI_OBJECT_FLAGS (obj) &= ~(flag)) + +typedef enum +{ + GST_MINI_OBJECT_FLAG_READONLY = (1<<0), + GST_MINI_OBJECT_FLAG_STATIC = (1<<1), + GST_MINI_OBJECT_FLAG_LAST = (1<<4) +} GstMiniObjectFlags; + + +struct _GstMiniObject { + GTypeInstance instance; + gint refcount; + guint flags; + + gpointer _gst_reserved[GST_PADDING]; +}; + +struct _GstMiniObjectClass { + GTypeClass type_class; + + GstMiniObjectCopyFunction copy; + GstMiniObjectFinalizeFunction finalize; + + gpointer _gst_reserved[GST_PADDING]; +}; + +GType gst_mini_object_get_type (void); + +GstMiniObject * gst_mini_object_new (GType type); +GstMiniObject * gst_mini_object_copy (const GstMiniObject *mini_object); +gboolean gst_mini_object_is_writable (const GstMiniObject *mini_object); +GstMiniObject * gst_mini_object_make_writable (const GstMiniObject *mini_object); + +GstMiniObject * gst_mini_object_ref (GstMiniObject *mini_object); +void gst_mini_object_unref (GstMiniObject *mini_object); + +void gst_mini_object_replace (GstMiniObject **olddata, GstMiniObject *newdata); + +GParamSpec * gst_param_spec_mini_object (const char *name, const char *nick, + const char *blurb, GType object_type, GParamFlags flags); + +G_END_DECLS + +#endif + diff --git a/gst/gstprobe.c b/gst/gstprobe.c index eb9fd576c2..65f88fccf8 100644 --- a/gst/gstprobe.c +++ b/gst/gstprobe.c @@ -95,14 +95,14 @@ gst_probe_destroy (GstProbe * probe) /** * gst_probe_perform: * @probe: The probe to trigger - * @data: the GstData that triggered the probe. + * @mini_object: the GstMiniObject that triggered the probe. * * Perform the callback associated with the given probe. * * Returns: the result of the probe callback function. */ gboolean -gst_probe_perform (GstProbe * probe, GstData ** data) +gst_probe_perform (GstProbe * probe, GstMiniObject ** mini_object) { gboolean res = TRUE; @@ -111,7 +111,7 @@ gst_probe_perform (GstProbe * probe, GstData ** data) GST_CAT_DEBUG (GST_CAT_PROBE, "performing probe %p", probe); if (probe->callback) - res = probe->callback (probe, data, probe->user_data); + res = probe->callback (probe, mini_object, probe->user_data); return res; } @@ -235,7 +235,7 @@ gst_probe_dispatcher_remove_probe (GstProbeDispatcher * disp, GstProbe * probe) * Returns: TRUE if all callbacks returned TRUE. */ gboolean -gst_probe_dispatcher_dispatch (GstProbeDispatcher * disp, GstData ** data) +gst_probe_dispatcher_dispatch (GstProbeDispatcher * disp, GstMiniObject ** data) { GSList *walk; gboolean res = TRUE; diff --git a/gst/gstprobe.h b/gst/gstprobe.h index 99235eab68..6afe506fa5 100644 --- a/gst/gstprobe.h +++ b/gst/gstprobe.h @@ -25,7 +25,7 @@ #define __GST_PROBE_H__ #include -#include +#include G_BEGIN_DECLS @@ -38,7 +38,7 @@ GType gst_probe_get_type (void); /* the callback should return FALSE if the data should be discarded */ typedef gboolean (*GstProbeCallback) (GstProbe *probe, - GstData **data, + GstMiniObject **data, gpointer user_data); struct _GstProbe { @@ -54,7 +54,7 @@ GstProbe* gst_probe_new (gboolean single_shot, gpointer user_data); void gst_probe_destroy (GstProbe *probe); -gboolean gst_probe_perform (GstProbe *probe, GstData **data); +gboolean gst_probe_perform (GstProbe *probe, GstMiniObject **data); typedef struct _GstProbeDispatcher GstProbeDispatcher; @@ -72,7 +72,7 @@ void gst_probe_dispatcher_set_active (GstProbeDispatcher *disp, gboolean acti void gst_probe_dispatcher_add_probe (GstProbeDispatcher *disp, GstProbe *probe); void gst_probe_dispatcher_remove_probe (GstProbeDispatcher *disp, GstProbe *probe); -gboolean gst_probe_dispatcher_dispatch (GstProbeDispatcher *disp, GstData **data); +gboolean gst_probe_dispatcher_dispatch (GstProbeDispatcher *disp, GstMiniObject **data); G_END_DECLS diff --git a/gst/gstquery.c b/gst/gstquery.c index 9b57fb370e..1f5335c121 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -27,12 +27,15 @@ #include "gstquery.h" #include "gstmemchunk.h" #include "gstenumtypes.h" -#include "gstdata_private.h" GST_DEBUG_CATEGORY_STATIC (gst_query_debug); #define GST_CAT_DEFAULT gst_query_debug -GType _gst_query_type; +static void gst_query_init (GTypeInstance * instance, gpointer g_class); +static void gst_query_class_init (gpointer g_class, gpointer class_data); +static void gst_query_finalize (GstQuery * query); +static GstQuery *_gst_query_copy (GstQuery * query); + static GStaticMutex mutex = G_STATIC_MUTEX_INIT; static GList *_gst_queries = NULL; @@ -82,14 +85,86 @@ _gst_query_initialize (void) } g_static_mutex_unlock (&mutex); - /* register the type */ - _gst_query_type = g_boxed_type_register_static ("GstQuery", - (GBoxedCopyFunc) gst_data_copy, (GBoxedFreeFunc) gst_data_unref); + gst_query_get_type (); chunk = gst_mem_chunk_new ("GstQueryChunk", sizeof (GstQuery), sizeof (GstQuery) * 20, 0); } +GType +gst_query_get_type (void) +{ + static GType _gst_query_type; + + if (G_UNLIKELY (_gst_query_type == 0)) { + static const GTypeInfo query_info = { + sizeof (GstQueryClass), + NULL, + NULL, + gst_query_class_init, + NULL, + NULL, + sizeof (GstQuery), + 0, + gst_query_init, + NULL + }; + + _gst_query_type = g_type_register_static (GST_TYPE_MINI_OBJECT, + "GstQuery", &query_info, 0); + } + return _gst_query_type; +} + +static void +gst_query_class_init (gpointer g_class, gpointer class_data) +{ + GstQueryClass *query_class = GST_QUERY_CLASS (g_class); + + query_class->mini_object_class.copy = + (GstMiniObjectCopyFunction) _gst_query_copy; + query_class->mini_object_class.finalize = + (GstMiniObjectFinalizeFunction) gst_query_finalize; + +} + +static void +gst_query_finalize (GstQuery * query) +{ + g_return_if_fail (query != NULL); + + if (query->structure) { + gst_structure_set_parent_refcount (query->structure, NULL); + gst_structure_free (query->structure); + } +} + +static void +gst_query_init (GTypeInstance * instance, gpointer g_class) +{ + +} + +static GstQuery * +_gst_query_copy (GstQuery * query) +{ + GstQuery *copy; + + copy = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY); + + copy->type = query->type; + + if (query->structure) { + copy->structure = gst_structure_copy (query->structure); + gst_structure_set_parent_refcount (copy->structure, + &query->mini_object.refcount); + } + + return copy; +} + + + /** * gst_query_type_register: * @nick: The nick of the new query @@ -222,67 +297,21 @@ gst_query_type_iterate_definitions (void) return result; } -GType -gst_query_get_type (void) -{ - return _gst_query_type; -} - -static GstQuery * -_gst_query_copy (GstQuery * query) -{ - GstQuery *copy; - - GST_LOG ("copy query %p", query); - - copy = gst_mem_chunk_alloc (chunk); - - memcpy (copy, query, sizeof (GstQuery)); - - if (query->structure) { - copy->structure = gst_structure_copy (query->structure); - gst_structure_set_parent_refcount (copy->structure, - &GST_DATA_REFCOUNT (query)); - } - - return copy; -} - -static void -_gst_query_free (GstQuery * query) -{ - GST_LOG ("freeing query %p", query); - - if (query->structure) { - gst_structure_set_parent_refcount (query->structure, NULL); - gst_structure_free (query->structure); - } - - _GST_DATA_DISPOSE (GST_DATA (query)); - gst_mem_chunk_free (chunk, query); -} - static GstQuery * gst_query_new (GstQueryType type, GstStructure * structure) { GstQuery *query; - query = gst_mem_chunk_alloc0 (chunk); + query = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY); GST_DEBUG ("creating new query %p %d", query, type); - _GST_DATA_INIT (GST_DATA (query), - _gst_query_type, - 0, - (GstDataFreeFunction) _gst_query_free, - (GstDataCopyFunction) _gst_query_copy); - - GST_QUERY_TYPE (query) = type; + query->type = type; if (structure) { query->structure = structure; gst_structure_set_parent_refcount (query->structure, - &GST_DATA_REFCOUNT (query)); + &query->mini_object.refcount); } else { query->structure = NULL; } diff --git a/gst/gstquery.h b/gst/gstquery.h index 3501c47006..8fe3d32f3a 100644 --- a/gst/gstquery.h +++ b/gst/gstquery.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include @@ -53,6 +53,7 @@ typedef enum { typedef struct _GstQueryTypeDefinition GstQueryTypeDefinition; typedef struct _GstQuery GstQuery; +typedef struct _GstQueryClass GstQueryClass; struct _GstQueryTypeDefinition { @@ -85,16 +86,18 @@ functionname (type object) \ } #endif -GST_EXPORT GType _gst_query_type; +#define GST_TYPE_QUERY (gst_query_get_type()) +#define GST_IS_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_QUERY)) +#define GST_IS_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_QUERY)) +#define GST_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_QUERY, GstQueryClass)) +#define GST_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_QUERY, GstQuery)) +#define GST_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_QUERY, GstQueryClass)) -#define GST_TYPE_QUERY (_gst_query_type) -#define GST_QUERY(query) ((GstQuery*)(query)) -#define GST_IS_QUERY(query) (GST_DATA_TYPE(query) == GST_TYPE_QUERY) -#define GST_QUERY_TYPE(query) (((GstQuery*)(query))->type) +#define GST_QUERY_TYPE(query) (((GstQuery*)(query))->type) struct _GstQuery { - GstData data; + GstMiniObject mini_object; /*< public > */ GstQueryType type; @@ -105,6 +108,10 @@ struct _GstQuery gpointer _gst_reserved[GST_PADDING]; }; +struct _GstQueryClass { + GstMiniObjectClass mini_object_class; +}; + void _gst_query_initialize (void); GType gst_query_get_type (void); @@ -123,12 +130,11 @@ G_CONST_RETURN GstQueryTypeDefinition* GstIterator* gst_query_type_iterate_definitions (void); /* refcounting */ -#define gst_query_ref(msg) GST_QUERY (gst_data_ref (GST_DATA (msg))) -#define gst_query_ref_by_count(msg,c) GST_QUERY (gst_data_ref_by_count (GST_DATA (msg), (c))) -#define gst_query_unref(msg) gst_data_unref (GST_DATA (msg)) +#define gst_query_ref(msg) GST_QUERY (gst_mini_object_ref (GST_MINI_OBJECT (msg))) +#define gst_query_unref(msg) gst_mini_object_unref (GST_MINI_OBJECT (msg)) /* copy query */ -#define gst_query_copy(msg) GST_QUERY (gst_data_copy (GST_DATA (msg))) -#define gst_query_copy_on_write(msg) GST_QUERY (gst_data_copy_on_write (GST_DATA (msg))) +#define gst_query_copy(msg) GST_QUERY (gst_mini_object_copy (GST_MINI_OBJECT (msg))) +#define gst_query_make_writable(msg) GST_QUERY (gst_mini_object_make_writable (GST_MINI_OBJECT (msg))) /* position query */ GstQuery* gst_query_new_position (GstFormat format); diff --git a/gst/gstqueue.c b/gst/gstqueue.c index aa2b905d99..fb52be20fc 100644 --- a/gst/gstqueue.c +++ b/gst/gstqueue.c @@ -358,9 +358,9 @@ gst_queue_finalize (GObject * object) GST_DEBUG_OBJECT (queue, "finalizing queue"); while (!g_queue_is_empty (queue->queue)) { - GstData *data = g_queue_pop_head (queue->queue); + GstMiniObject *data = g_queue_pop_head (queue->queue); - gst_data_unref (data); + gst_mini_object_unref (data); } g_queue_free (queue->queue); GST_CAT_DEBUG_OBJECT (GST_CAT_THREAD, queue, "free mutex"); @@ -436,11 +436,11 @@ static void gst_queue_locked_flush (GstQueue * queue) { while (!g_queue_is_empty (queue->queue)) { - GstData *data = g_queue_pop_head (queue->queue); + GstMiniObject *data = g_queue_pop_head (queue->queue); /* Then loose another reference because we are supposed to destroy that data when flushing */ - gst_data_unref (data); + gst_mini_object_unref (data); } queue->cur_level.buffers = 0; queue->cur_level.bytes = 0; @@ -586,7 +586,7 @@ gst_queue_chain (GstPad * pad, GstBuffer * buffer) * and find the first buffer from the head on. We'll * unref that and "fix up" the GQueue object... */ GList *item; - GstData *leak = NULL; + GstMiniObject *leak = NULL; GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "queue is full, leaking buffer on downstream end"); @@ -690,7 +690,7 @@ static void gst_queue_loop (GstPad * pad) { GstQueue *queue; - GstData *data; + GstMiniObject *data; gboolean restart = TRUE; queue = GST_QUEUE (GST_PAD_PARENT (pad)); diff --git a/gst/gsttypes.h b/gst/gsttypes.h index a6e3a51047..dcc13c682a 100644 --- a/gst/gsttypes.h +++ b/gst/gsttypes.h @@ -40,8 +40,6 @@ typedef struct _GstBus GstBus; typedef struct _GstBusClass GstBusClass; typedef struct _GstScheduler GstScheduler; typedef struct _GstSchedulerClass GstSchedulerClass; -typedef struct _GstEvent GstEvent; -typedef struct _GstMessage GstMessage; typedef enum { GST_STATE_VOID_PENDING = 0, diff --git a/libs/gst/dataprotocol/dataprotocol.c b/libs/gst/dataprotocol/dataprotocol.c index 9210f29901..dabcb202e9 100644 --- a/libs/gst/dataprotocol/dataprotocol.c +++ b/libs/gst/dataprotocol/dataprotocol.c @@ -167,7 +167,6 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, guint16 flags_mask; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); - g_return_val_if_fail (GST_BUFFER_REFCOUNT_VALUE (buffer) > 0, FALSE); g_return_val_if_fail (header, FALSE); *length = GST_DP_HEADER_LENGTH; @@ -188,9 +187,8 @@ gst_dp_header_from_buffer (const GstBuffer * buffer, GstDPHeaderFlag flags, /* data flags */ /* we only copy KEY_UNIT,DELTA_UNIT and IN_CAPS flags */ - flags_mask = GST_DATA_FLAG_SHIFT (GST_BUFFER_PREROLL) | - GST_DATA_FLAG_SHIFT (GST_BUFFER_IN_CAPS) | - GST_DATA_FLAG_SHIFT (GST_BUFFER_DELTA_UNIT); + flags_mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS | + GST_BUFFER_FLAG_DELTA_UNIT; GST_WRITE_UINT16_BE (h + 40, GST_BUFFER_FLAGS (buffer) & flags_mask); diff --git a/libs/gst/dataprotocol/dataprotocol.h b/libs/gst/dataprotocol/dataprotocol.h index ca394ccf9a..da3c2b9337 100644 --- a/libs/gst/dataprotocol/dataprotocol.h +++ b/libs/gst/dataprotocol/dataprotocol.h @@ -24,7 +24,6 @@ #ifndef __GST_DATA_PROTOCOL_H__ #define __GST_DATA_PROTOCOL_H__ -#include #include #include #include diff --git a/libs/gst/dataprotocol/dp-private.h b/libs/gst/dataprotocol/dp-private.h index befd501b0a..c74837b326 100644 --- a/libs/gst/dataprotocol/dp-private.h +++ b/libs/gst/dataprotocol/dp-private.h @@ -23,7 +23,6 @@ #ifndef __GST_DP_PRIVATE_H__ #define __GST_DP_PRIVATE_H__ -#include #include #include #include diff --git a/plugins/elements/gstbufferstore.c b/plugins/elements/gstbufferstore.c index f3d8e55089..d9f1d40a23 100644 --- a/plugins/elements/gstbufferstore.c +++ b/plugins/elements/gstbufferstore.c @@ -135,7 +135,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) /* the starting buffer had an invalid offset, in that case we assume continuous buffers */ GST_LOG_OBJECT (store, "adding buffer %p with invalid offset and size %u", buffer, GST_BUFFER_SIZE (buffer)); - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); store->buffers = g_list_append (store->buffers, buffer); return TRUE; } else { @@ -176,14 +176,14 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) g_assert (sub); buffer = sub; } else { - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); } /* replace current buffer with new one */ GST_INFO_OBJECT (store, "replacing buffer %p with buffer %p with offset %" G_GINT64_FORMAT " and size %u", current_list->data, buffer, GST_BUFFER_OFFSET (buffer), GST_BUFFER_SIZE (buffer)); - gst_data_unref (GST_DATA (current_list->data)); + gst_mini_object_unref (GST_MINI_OBJECT (current_list->data)); current_list->data = buffer; buffer = NULL; break; @@ -215,7 +215,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) GST_BUFFER_OFFSET (sub) = start_offset + GST_BUFFER_OFFSET (buffer); buffer = sub; } else { - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); } GST_INFO_OBJECT (store, "adding buffer %p with offset %" G_GINT64_FORMAT " and size %u", @@ -228,7 +228,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) } } if (buffer) { - gst_data_ref (GST_DATA (buffer)); + gst_mini_object_ref (GST_MINI_OBJECT (buffer)); GST_INFO_OBJECT (store, "adding buffer %p with offset %" G_GINT64_FORMAT " and size %u", buffer, GST_BUFFER_OFFSET (buffer), GST_BUFFER_SIZE (buffer)); @@ -245,7 +245,7 @@ gst_buffer_store_add_buffer_func (GstBufferStore * store, GstBuffer * buffer) static void gst_buffer_store_cleared_func (GstBufferStore * store) { - g_list_foreach (store->buffers, (GFunc) gst_data_unref, NULL); + g_list_foreach (store->buffers, (GFunc) gst_mini_object_unref, NULL); g_list_free (store->buffers); store->buffers = NULL; } @@ -355,8 +355,8 @@ gst_buffer_store_get_buffer (GstBufferStore * store, guint64 offset, guint size) "found matching buffer %p for offset %" G_GUINT64_FORMAT " and size %u", current, offset, size); ret = current; - gst_data_ref (GST_DATA (ret)); - GST_LOG_OBJECT (store, "refcount %d", GST_DATA_REFCOUNT_VALUE (ret)); + gst_mini_object_ref (GST_MINI_OBJECT (ret)); + GST_LOG_OBJECT (store, "refcount %d", GST_MINI_OBJECT (ret)->refcount); break; } else if (cur_offset + GST_BUFFER_SIZE (current) > offset) { if (cur_offset + GST_BUFFER_SIZE (current) >= offset + size) { @@ -384,7 +384,7 @@ gst_buffer_store_get_buffer (GstBufferStore * store, guint64 offset, guint size) GST_DEBUG_OBJECT (store, "not all data for offset %" G_GUINT64_FORMAT " and remaining size %u available, aborting", offset, size); - gst_data_unref (GST_DATA (ret)); + gst_mini_object_unref (GST_MINI_OBJECT (ret)); ret = NULL; goto out; } diff --git a/plugins/elements/gstfakesink.c b/plugins/elements/gstfakesink.c index 3448d157c1..a6887b4026 100644 --- a/plugins/elements/gstfakesink.c +++ b/plugins/elements/gstfakesink.c @@ -172,8 +172,8 @@ gst_fakesink_class_init (GstFakeSinkClass * klass) gst_fakesink_signals[SIGNAL_HANDOFF] = g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstFakeSinkClass, handoff), NULL, NULL, - gst_marshal_VOID__BOXED_OBJECT, G_TYPE_NONE, 2, - GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE, GST_TYPE_PAD); + gst_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, + G_TYPE_OBJECT, GST_TYPE_PAD); gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_fakesink_change_state); @@ -317,7 +317,7 @@ gst_fakesink_render (GstBaseSink * bsink, GstBuffer * buf) GST_BUFFER_SIZE (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf), - GST_BUFFER_OFFSET_END (buf), GST_BUFFER_FLAGS (buf), buf); + GST_BUFFER_OFFSET_END (buf), GST_MINI_OBJECT (buf)->flags, buf); g_object_notify (G_OBJECT (sink), "last_message"); } diff --git a/plugins/elements/gstfakesrc.c b/plugins/elements/gstfakesrc.c index 4715db5113..9695549d74 100644 --- a/plugins/elements/gstfakesrc.c +++ b/plugins/elements/gstfakesrc.c @@ -288,8 +288,7 @@ gst_fakesrc_class_init (GstFakeSrcClass * klass) gst_fakesrc_signals[SIGNAL_HANDOFF] = g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstFakeSrcClass, handoff), NULL, NULL, - gst_marshal_VOID__BOXED_OBJECT, G_TYPE_NONE, 1, - GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE); + gst_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); /*gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_fakesrc_is_seekable); */ gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_fakesrc_start); diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index 22f93d57c7..27421e85ce 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -350,22 +350,92 @@ gst_filesrc_get_property (GObject * object, guint prop_id, GValue * value, */ #ifdef HAVE_MMAP + +/* GstMmapBuffer */ + +typedef struct _GstMmapBuffer GstMmapBuffer; +typedef struct _GstMmapBufferClass GstMmapBufferClass; + +#define GST_TYPE_MMAP_BUFFER (gst_mmap_buffer_get_type()) + +#define GST_IS_MMAP_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MMAP_BUFFER)) +#define GST_IS_MMAP_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MMAP_BUFFER)) +#define GST_MMAP_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MMAP_BUFFER, GstMmapBufferClass)) +#define GST_MMAP_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MMAP_BUFFER, GstMmapBuffer)) +#define GST_MMAP_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MMAP_BUFFER, GstMmapBufferClass)) + + + +struct _GstMmapBuffer +{ + GstBuffer buffer; + + GstFileSrc *filesrc; +}; + +struct _GstMmapBufferClass +{ + GstBufferClass buffer_class; +}; + +static void gst_mmap_buffer_init (GTypeInstance * instance, gpointer g_class); +static void gst_mmap_buffer_class_init (gpointer g_class, gpointer class_data); +static void gst_mmap_buffer_finalize (GstMmapBuffer * mmap_buffer); + +static GType +gst_mmap_buffer_get_type (void) +{ + static GType _gst_mmap_buffer_type; + + if (G_UNLIKELY (_gst_mmap_buffer_type == 0)) { + static const GTypeInfo mmap_buffer_info = { + sizeof (GstMmapBufferClass), + NULL, + NULL, + gst_mmap_buffer_class_init, + NULL, + NULL, + sizeof (GstMmapBuffer), + 0, + gst_mmap_buffer_init, + NULL + }; + + _gst_mmap_buffer_type = g_type_register_static (GST_TYPE_BUFFER, + "GstMmapBuffer", &mmap_buffer_info, 0); + } + return _gst_mmap_buffer_type; +} + static void -gst_filesrc_free_parent_mmap (GstBuffer * buf) +gst_mmap_buffer_class_init (gpointer g_class, gpointer class_data) +{ + GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class); + + mini_object_class->finalize = + (GstMiniObjectFinalizeFunction) gst_mmap_buffer_finalize; +} + +static void +gst_mmap_buffer_init (GTypeInstance * instance, gpointer g_class) +{ + +} + +static void +gst_mmap_buffer_finalize (GstMmapBuffer * mmap_buffer) { guint size; - guint64 offset; gpointer data; - GstBaseSrc *src; + guint64 offset; + GstFileSrc *src; + GstBuffer *buffer = GST_BUFFER (mmap_buffer); /* get info */ - size = GST_BUFFER_MAXSIZE (buf); - offset = GST_BUFFER_OFFSET (buf); - data = GST_BUFFER_DATA (buf); - src = (GstBaseSrc *) GST_BUFFER_PRIVATE (buf); - - if (!GST_IS_BASESRC (src)) - goto wrong_buffer; + size = GST_BUFFER_SIZE (buffer); + offset = GST_BUFFER_OFFSET (buffer); + data = GST_BUFFER_DATA (buffer); + src = mmap_buffer->filesrc; GST_LOG ("freeing mmap()d buffer at %" G_GUINT64_FORMAT "+%u", offset, size); @@ -385,15 +455,6 @@ gst_filesrc_free_parent_mmap (GstBuffer * buf) * guint64 as hex */ GST_LOG ("unmapped region %08lx+%08lx at %p", (gulong) offset, (gulong) size, data); - - GST_BUFFER_DATA (buf) = NULL; - return; - -wrong_buffer: - { - GST_WARNING ("freeing wrong mmap buffer"); - return; - } } static GstBuffer * @@ -416,9 +477,10 @@ gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size) (gulong) offset, (gulong) size, mmapregion); /* time to allocate a new mapbuf */ - buf = gst_buffer_new (); + buf = (GstBuffer *) gst_mini_object_new (GST_TYPE_MMAP_BUFFER); /* mmap() the data into this new buffer */ GST_BUFFER_DATA (buf) = mmapregion; + GST_MMAP_BUFFER (buf)->filesrc = src; #ifdef MADV_SEQUENTIAL /* madvise to tell the kernel what to do with it */ @@ -428,15 +490,13 @@ gst_filesrc_map_region (GstFileSrc * src, off_t offset, size_t size) #endif /* fill in the rest of the fields */ - GST_BUFFER_FLAG_SET (buf, GST_BUFFER_READONLY); - GST_BUFFER_FLAG_SET (buf, GST_BUFFER_ORIGINAL); + /* FIXME */ + //GST_BUFFER_FLAG_SET (buf, GST_BUFFER_READONLY); + //GST_BUFFER_FLAG_SET (buf, GST_BUFFER_ORIGINAL); GST_BUFFER_SIZE (buf) = size; - GST_BUFFER_MAXSIZE (buf) = size; GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + size; GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_PRIVATE (buf) = src; - GST_BUFFER_FREE_DATA_FUNC (buf) = gst_filesrc_free_parent_mmap; return buf; @@ -661,7 +721,6 @@ gst_filesrc_create_read (GstFileSrc * src, guint64 offset, guint length, length = ret; GST_BUFFER_SIZE (buf) = length; - GST_BUFFER_MAXSIZE (buf) = length; GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + length; diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index b80c1a275b..8d08aaf3f1 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -182,8 +182,7 @@ gst_identity_class_init (GstIdentityClass * klass) gst_identity_signals[SIGNAL_HANDOFF] = g_signal_new ("handoff", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstIdentityClass, handoff), NULL, NULL, - gst_marshal_VOID__BOXED, G_TYPE_NONE, 1, - GST_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE); + gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_identity_finalize); diff --git a/plugins/elements/gstqueue.c b/plugins/elements/gstqueue.c index aa2b905d99..fb52be20fc 100644 --- a/plugins/elements/gstqueue.c +++ b/plugins/elements/gstqueue.c @@ -358,9 +358,9 @@ gst_queue_finalize (GObject * object) GST_DEBUG_OBJECT (queue, "finalizing queue"); while (!g_queue_is_empty (queue->queue)) { - GstData *data = g_queue_pop_head (queue->queue); + GstMiniObject *data = g_queue_pop_head (queue->queue); - gst_data_unref (data); + gst_mini_object_unref (data); } g_queue_free (queue->queue); GST_CAT_DEBUG_OBJECT (GST_CAT_THREAD, queue, "free mutex"); @@ -436,11 +436,11 @@ static void gst_queue_locked_flush (GstQueue * queue) { while (!g_queue_is_empty (queue->queue)) { - GstData *data = g_queue_pop_head (queue->queue); + GstMiniObject *data = g_queue_pop_head (queue->queue); /* Then loose another reference because we are supposed to destroy that data when flushing */ - gst_data_unref (data); + gst_mini_object_unref (data); } queue->cur_level.buffers = 0; queue->cur_level.bytes = 0; @@ -586,7 +586,7 @@ gst_queue_chain (GstPad * pad, GstBuffer * buffer) * and find the first buffer from the head on. We'll * unref that and "fix up" the GQueue object... */ GList *item; - GstData *leak = NULL; + GstMiniObject *leak = NULL; GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "queue is full, leaking buffer on downstream end"); @@ -690,7 +690,7 @@ static void gst_queue_loop (GstPad * pad) { GstQueue *queue; - GstData *data; + GstMiniObject *data; gboolean restart = TRUE; queue = GST_QUEUE (GST_PAD_PARENT (pad)); diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c index 7d424a29e2..33f920181a 100644 --- a/plugins/elements/gsttypefindelement.c +++ b/plugins/elements/gsttypefindelement.c @@ -359,7 +359,7 @@ gst_type_find_element_src_event (GstPad * pad, GstEvent * event) if (typefind->mode != MODE_NORMAL) { /* need to do more? */ - gst_data_unref (GST_DATA (event)); + gst_mini_object_unref (GST_MINI_OBJECT (event)); return FALSE; } return gst_pad_event_default (pad, event); @@ -385,7 +385,7 @@ new_entry (void) static void free_entry_buffers (TypeFindEntry * entry) { - g_list_foreach (entry->buffers, (GFunc) gst_data_unref, NULL); + g_list_foreach (entry->buffers, (GFunc) gst_mini_object_unref, NULL); g_list_free (entry->buffers); entry->buffers = NULL; } @@ -539,7 +539,7 @@ gst_type_find_element_handle_event (GstPad * pad, GstEvent * event) } break; default: - gst_data_unref (GST_DATA (event)); + gst_mini_object_unref (GST_MINI_OBJECT (event)); res = TRUE; break; } diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 0f94ba1ca6..6fb53659fc 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -26,7 +26,6 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gstbin \ gst/gstbus \ gst/gstcaps \ - gst/gstdata \ gst/gstiterator \ gst/gstmessage \ gst/gstobject \ diff --git a/tests/check/libs/gdp.c b/tests/check/libs/gdp.c index df79c8d1c0..fdcb0cf450 100644 --- a/tests/check/libs/gdp.c +++ b/tests/check/libs/gdp.c @@ -98,8 +98,7 @@ START_TEST (test_buffer) GST_BUFFER_DURATION (buffer) = (GstClockTime) GST_SECOND; GST_BUFFER_OFFSET (buffer) = (guint64) 10; GST_BUFFER_OFFSET_END (buffer) = (guint64) 19; - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_IN_CAPS); - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_SUBBUFFER); + GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS); memmove (GST_BUFFER_DATA (buffer), "a buffer", 8); /* create a buffer with CRC checking */ @@ -136,9 +135,7 @@ START_TEST (test_buffer) "Offsets don't match !"); fail_unless (GST_BUFFER_OFFSET_END (newbuffer) == GST_BUFFER_OFFSET_END (buffer), "Offset ends don't match !"); - fail_if (GST_BUFFER_FLAG_IS_SET (newbuffer, GST_BUFFER_SUBBUFFER), - "GST_BUFFER_SUBBUFFER flag should not have been copied !"); - fail_unless (GST_BUFFER_FLAG_IS_SET (newbuffer, GST_BUFFER_IN_CAPS), + fail_unless (GST_BUFFER_FLAG_IS_SET (newbuffer, GST_BUFFER_FLAG_IN_CAPS), "GST_BUFFER_IN_CAPS flag should have been copied !"); g_free (header);