summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-12-02 19:47:46 +0100
committerWim Taymans <wim@metal.(none)>2009-12-26 00:02:17 +0100
commit67bd9529d0eaa169a2361fde91f4948ebaedbb98 (patch)
tree7906265f4ffec7dec464e6b609c6744cf24cc74b
parentd7ecbc6ac300feccb17e88a4b3bc7723bb88eb53 (diff)
buffer: remove subbuffer subclass
Move the parent buffer pointer into the GstBuffer struct so that we can remove the subbuffer class and type. This is interesting because it allows us to more naturally implement methods to get the real type and parent of a subbuffer (See #545501). It should also be slightly faster because there is no extra object hierarchy to initialize and free.
-rw-r--r--gst/gstbuffer.c68
-rw-r--r--gst/gstbuffer.h5
2 files changed, 14 insertions, 59 deletions
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c
index b56b16c66d..beec71bec0 100644
--- a/gst/gstbuffer.c
+++ b/gst/gstbuffer.c
@@ -119,25 +119,22 @@
#include "gstinfo.h"
#include "gstutils.h"
#include "gstminiobject.h"
static void gst_buffer_finalize (GstBuffer * buffer);
static GstBuffer *_gst_buffer_copy (GstBuffer * buffer);
-static GType gst_subbuffer_get_type (void);
-static GType _gst_subbuffer_type = 0;
static GType _gst_buffer_type = 0;
void
_gst_buffer_initialize (void)
{
/* the GstMiniObject types need to be class_ref'd once before it can be
* done from multiple threads;
* see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
g_type_class_ref (gst_buffer_get_type ());
- g_type_class_ref (gst_subbuffer_get_type ());
}
#define _do_init \
{ \
_gst_buffer_type = g_define_type_id; \
}
@@ -162,12 +159,15 @@ gst_buffer_finalize (GstBuffer * buffer)
/* free our data */
if (G_LIKELY (buffer->malloc_data))
buffer->free_func (buffer->malloc_data);
gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL);
+ if (buffer->parent)
+ gst_buffer_unref (buffer->parent);
+
/* ((GstMiniObjectClass *) */
/* gst_buffer_parent_class)->finalize (GST_MINI_OBJECT_CAST (buffer)); */
}
/**
* gst_buffer_copy_metadata:
@@ -451,61 +451,13 @@ gst_buffer_make_metadata_writable (GstBuffer * buf)
gst_buffer_unref (buf);
}
return ret;
}
-typedef struct _GstSubBuffer GstSubBuffer;
-typedef struct _GstSubBufferClass GstSubBufferClass;
-
-#define GST_IS_SUBBUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), _gst_subbuffer_type))
-#define GST_SUBBUFFER_CAST(obj) ((GstSubBuffer *)(obj))
-
-struct _GstSubBuffer
-{
- GstBuffer buffer;
-
- GstBuffer *parent;
-};
-
-struct _GstSubBufferClass
-{
- GstBufferClass buffer_class;
-};
-
-static void gst_subbuffer_finalize (GstSubBuffer * buffer);
-
-#define _do_init_sub \
-{ \
- _gst_subbuffer_type = g_define_type_id; \
-}
-
-G_DEFINE_TYPE_WITH_CODE (GstSubBuffer, gst_subbuffer, GST_TYPE_BUFFER,
- _do_init_sub);
-
-static void
-gst_subbuffer_class_init (GstSubBufferClass * klass)
-{
- klass->buffer_class.mini_object_class.finalize =
- (GstMiniObjectFinalizeFunction) gst_subbuffer_finalize;
-}
-
-static void
-gst_subbuffer_finalize (GstSubBuffer * buffer)
-{
- gst_buffer_unref (buffer->parent);
-
- ((GstMiniObjectClass *) gst_subbuffer_parent_class)->finalize
- (GST_MINI_OBJECT_CAST (buffer));
-}
-
-static void
-gst_subbuffer_init (GstSubBuffer * instance)
-{
- GST_BUFFER_FLAG_SET (GST_BUFFER_CAST (instance), GST_BUFFER_FLAG_READONLY);
-}
+#define GST_IS_SUBBUFFER(obj) (GST_BUFFER_CAST(obj)->parent != NULL)
/**
* gst_buffer_create_sub:
* @parent: a #GstBuffer.
* @offset: the offset into parent #GstBuffer at which the new sub-buffer
* begins.
@@ -524,31 +476,32 @@ gst_subbuffer_init (GstSubBuffer * instance)
* Returns: the new #GstBuffer.
* Returns NULL if the arguments were invalid.
*/
GstBuffer *
gst_buffer_create_sub (GstBuffer * buffer, guint offset, guint size)
{
- GstSubBuffer *subbuffer;
+ GstBuffer *subbuffer;
GstBuffer *parent;
gboolean complete;
g_return_val_if_fail (buffer != NULL, NULL);
g_return_val_if_fail (buffer->mini_object.refcount > 0, NULL);
g_return_val_if_fail (buffer->size >= offset + size, NULL);
/* find real parent */
if (GST_IS_SUBBUFFER (buffer)) {
- parent = GST_SUBBUFFER_CAST (buffer)->parent;
+ parent = buffer->parent;
} else {
parent = buffer;
}
gst_buffer_ref (parent);
/* create the new buffer */
- subbuffer = (GstSubBuffer *) gst_mini_object_new (_gst_subbuffer_type);
+ subbuffer = gst_buffer_new ();
subbuffer->parent = parent;
+ GST_BUFFER_FLAG_SET (GST_BUFFER_CAST (subbuffer), GST_BUFFER_FLAG_READONLY);
GST_CAT_LOG (GST_CAT_BUFFER, "new subbuffer %p (parent %p)", subbuffer,
parent);
/* set the right values in the child */
GST_BUFFER_DATA (GST_BUFFER_CAST (subbuffer)) = buffer->data + offset;
@@ -613,14 +566,13 @@ gst_buffer_is_span_fast (GstBuffer * buf1, GstBuffer * buf2)
g_return_val_if_fail (buf1 != NULL && buf2 != NULL, FALSE);
g_return_val_if_fail (buf1->mini_object.refcount > 0, FALSE);
g_return_val_if_fail (buf2->mini_object.refcount > 0, FALSE);
/* it's only fast if we have subbuffers of the same parent */
return (GST_IS_SUBBUFFER (buf1) &&
- GST_IS_SUBBUFFER (buf2) &&
- (GST_SUBBUFFER_CAST (buf1)->parent == GST_SUBBUFFER_CAST (buf2)->parent)
+ GST_IS_SUBBUFFER (buf2) && (buf1->parent == buf2->parent)
&& ((buf1->data + buf1->size) == buf2->data));
}
/**
* gst_buffer_span:
* @buf1: the first source #GstBuffer to merge.
@@ -654,13 +606,13 @@ gst_buffer_span (GstBuffer * buf1, guint32 offset, GstBuffer * buf2,
g_return_val_if_fail (buf2->mini_object.refcount > 0, NULL);
g_return_val_if_fail (len > 0, NULL);
g_return_val_if_fail (len <= buf1->size + buf2->size - offset, NULL);
/* if the two buffers have the same parent and are adjacent */
if (gst_buffer_is_span_fast (buf1, buf2)) {
- GstBuffer *parent = GST_SUBBUFFER_CAST (buf1)->parent;
+ GstBuffer *parent = buf1->parent;
/* we simply create a subbuffer of the common parent */
newbuf = gst_buffer_create_sub (parent,
buf1->data - parent->data + offset, len);
} else {
GST_CAT_DEBUG (GST_CAT_BUFFER,
diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h
index f6d96e9ea3..4314d0b83d 100644
--- a/gst/gstbuffer.h
+++ b/gst/gstbuffer.h
@@ -255,12 +255,13 @@ typedef enum {
* @offset_end: the last offset contained in this buffer. It has the same
* format as @offset.
* @malloc_data: a pointer to the allocated memory associated with this buffer.
* When the buffer is freed, this data will freed with @free_func.
* @free_func: a custom function that will be called with @malloc_data, defaults
* to g_free(). Since 0.10.22.
+ * @parent: the parent buffer if this is a subbuffer. Since 0.10.26.
*
* The structure of a #GstBuffer. Use the associated macros to access the public
* variables.
*/
struct _GstBuffer {
GstMiniObject mini_object;
@@ -280,16 +281,18 @@ struct _GstBuffer {
/* media specific offset */
guint64 offset;
guint64 offset_end;
guint8 *malloc_data;
+ /* ABI Added */
GFreeFunc free_func;
+ GstBuffer *parent;
/*< private >*/
- gpointer _gst_reserved[GST_PADDING - 1];
+ gpointer _gst_reserved[GST_PADDING - 2];
};
struct _GstBufferClass {
GstMiniObjectClass mini_object_class;
};