miniobject: make miniobject a boxed type

First attempt at making miniobject a simple boxed type.
This commit is contained in:
Wim Taymans 2009-11-29 00:21:24 +01:00
parent 1218511185
commit 086aac764d
7 changed files with 47 additions and 153 deletions

View file

@ -131,7 +131,18 @@
static void gst_buffer_finalize (GstBuffer * buffer);
static GstBuffer *_gst_buffer_copy (GstBuffer * buffer);
static GType _gst_buffer_type = 0;
GType
gst_buffer_get_type (void)
{
static GType gst_buffer_type = 0;
if (G_UNLIKELY (gst_buffer_type == 0)) {
gst_buffer_type = g_boxed_type_register_static ("GstBuffer",
(GBoxedCopyFunc) gst_buffer_copy_conditional,
(GBoxedFreeFunc) gst_buffer_unref);
}
return gst_buffer_type;
}
/* buffer alignment in bytes
* an alignment of 8 would be the same as malloc() guarantees
@ -172,21 +183,6 @@ _gst_buffer_initialize (void)
#endif
}
#define _do_init \
{ \
_gst_buffer_type = g_define_type_id; \
}
G_DEFINE_TYPE_WITH_CODE (GstBuffer, gst_buffer, GST_TYPE_MINI_OBJECT, _do_init);
static void
gst_buffer_class_init (GstBufferClass * klass)
{
klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy;
klass->mini_object_class.finalize =
(GstMiniObjectFinalizeFunction) gst_buffer_finalize;
}
static void
gst_buffer_finalize (GstBuffer * buffer)
{
@ -202,9 +198,6 @@ gst_buffer_finalize (GstBuffer * buffer)
if (buffer->parent)
gst_buffer_unref (buffer->parent);
/* ((GstMiniObjectClass *) */
/* gst_buffer_parent_class)->finalize (GST_MINI_OBJECT_CAST (buffer)); */
}
/**
@ -310,6 +303,9 @@ gst_buffer_init (GstBuffer * buffer)
{
GST_CAT_LOG (GST_CAT_BUFFER, "init %p", buffer);
buffer->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy;
buffer->mini_object.free = (GstMiniObjectFreeeFunction) gst_buffer_finalize;
GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
@ -331,7 +327,7 @@ gst_buffer_new (void)
{
GstBuffer *newbuf;
newbuf = (GstBuffer *) gst_mini_object_new (_gst_buffer_type);
newbuf = (GstBuffer *) gst_mini_object_new (GST_TYPE_BUFFER);
GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);

View file

@ -31,7 +31,6 @@
G_BEGIN_DECLS
typedef struct _GstBuffer GstBuffer;
typedef struct _GstBufferClass GstBufferClass;
/**
* GST_BUFFER_TRACE_NAME:
@ -41,12 +40,9 @@ typedef struct _GstBufferClass GstBufferClass;
#define GST_BUFFER_TRACE_NAME "GstBuffer"
#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_IS_BUFFER(obj) (GST_MINI_OBJECT_TYPE(obj) == GST_TYPE_BUFFER)
#define GST_BUFFER_CAST(obj) ((GstBuffer *)(obj))
#define GST_BUFFER(obj) (GST_BUFFER_CAST(obj))
/**
* GST_BUFFER_FLAGS:
@ -233,7 +229,7 @@ typedef enum {
GST_BUFFER_FLAG_MEDIA1 = (GST_MINI_OBJECT_FLAG_LAST << 5),
GST_BUFFER_FLAG_MEDIA2 = (GST_MINI_OBJECT_FLAG_LAST << 6),
GST_BUFFER_FLAG_MEDIA3 = (GST_MINI_OBJECT_FLAG_LAST << 7),
GST_BUFFER_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 8)
GST_BUFFER_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 16)
} GstBufferFlag;
/**
@ -291,10 +287,6 @@ struct _GstBuffer {
gpointer _gst_reserved[GST_PADDING];
};
struct _GstBufferClass {
GstMiniObjectClass mini_object_class;
};
GType gst_buffer_get_type (void);
/* allocation */
@ -484,7 +476,7 @@ GstBuffer* gst_buffer_span (GstBuffer *buf1, guint32 offset
*
* Sets @b as the value of @v. Caller retains reference to buffer.
*/
#define gst_value_set_buffer(v,b) gst_value_set_mini_object(v, GST_MINI_OBJECT_CAST(b))
#define gst_value_set_buffer(v,b) g_value_set_boxed((v),(b))
/**
* gst_value_take_buffer:
* @v: a #GValue to receive the data
@ -492,7 +484,7 @@ GstBuffer* gst_buffer_span (GstBuffer *buf1, guint32 offset
*
* Sets @b as the value of @v. Caller gives away reference to buffer.
*/
#define gst_value_take_buffer(v,b) gst_value_take_mini_object(v, GST_MINI_OBJECT_CAST(b))
#define gst_value_take_buffer(v,b) g_value_take_boxed(v,(b))
/**
* gst_value_get_buffer:
* @v: a #GValue to query
@ -503,7 +495,7 @@ GstBuffer* gst_buffer_span (GstBuffer *buf1, guint32 offset
*
* Returns: (transfer none): buffer
*/
#define gst_value_get_buffer(v) GST_BUFFER_CAST (gst_value_get_mini_object(v))
#define gst_value_get_buffer(v) GST_BUFFER_CAST (g_value_get_boxed(v))
G_END_DECLS

View file

@ -117,21 +117,12 @@ typedef struct _GstStaticCaps GstStaticCaps;
/**
* GstCaps:
* @type: GType of the caps
* @refcount: the atomic refcount value
* @flags: extra flags for the caps, read only.
* @mini_object: the parent type
*
* Object describing media types.
*/
struct _GstCaps {
GType type;
/*< public >*/ /* with COW */
/* refcounting */
gint refcount;
/*< public >*/ /* read only */
GstCapsFlags flags;
GstMiniObject mini_object;
/*< private >*/
GPtrArray *structs;

View file

@ -157,7 +157,6 @@ typedef enum {
#define GST_EVENT_TRACE_NAME "GstEvent"
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))
@ -364,13 +363,6 @@ struct _GstEvent {
gpointer _gst_reserved[GST_PADDING];
};
struct _GstEventClass {
GstMiniObjectClass mini_object_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
const gchar* gst_event_type_get_name (GstEventType type);
GQuark gst_event_type_to_quark (GstEventType type);
GstEventTypeFlags

View file

@ -25,7 +25,6 @@
G_BEGIN_DECLS
typedef struct _GstMessage GstMessage;
typedef struct _GstMessageClass GstMessageClass;
/**
* GstMessageType:
@ -142,12 +141,9 @@ typedef enum
#define GST_MESSAGE_TRACE_NAME "GstMessage"
#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))
#define GST_IS_MESSAGE(obj) (GST_MINI_OBJECT_TYPE (obj) == GST_TYPE_MESSAGE)
#define GST_MESSAGE_CAST(obj) ((GstMessage*)(obj))
#define GST_MESSAGE(obj) (GST_MESSAGE_CAST(obj))
/* the lock is used to handle the synchronous handling of messages,
* the emiting thread is block until the handling thread processed
@ -303,13 +299,6 @@ struct _GstMessage
gpointer _gst_reserved[GST_PADDING];
};
struct _GstMessageClass {
GstMiniObjectClass mini_object_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GType gst_message_get_type (void);
const gchar* gst_message_type_get_name (GstMessageType type);

View file

@ -29,17 +29,10 @@
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))
#define GST_MINI_OBJECT_CAST(obj) ((GstMiniObject*)(obj))
#define GST_MINI_OBJECT_CONST_CAST(obj) ((const GstMiniObject*)(obj))
typedef struct _GstMiniObject GstMiniObject;
typedef struct _GstMiniObjectClass GstMiniObjectClass;
/**
* GstMiniObjectCopyFunction:
@ -51,17 +44,24 @@ typedef struct _GstMiniObjectClass GstMiniObjectClass;
*/
typedef GstMiniObject * (*GstMiniObjectCopyFunction) (const GstMiniObject *obj);
/**
* GstMiniObjectFinalizeFunction:
* @obj: MiniObject to finalize
* GstMiniObjectFreeFunction:
* @obj: MiniObject to free
*
* Virtual function prototype for methods to free ressources used by
* mini-objects. Subclasses of the mini object are allowed to revive the
* passed object by doing a gst_mini_object_ref(). If the object is not
* revived after the finalize function, the memory associated with the
* revived after the free function, the memory associated with the
* object is freed.
*/
typedef void (*GstMiniObjectFinalizeFunction) (GstMiniObject *obj);
typedef void (*GstMiniObjectFreeFunction) (GstMiniObject *obj);
/**
* GST_MINI_OBJECT_FLAGS:
* @obj: MiniObject to return flags for.
*
* This macro returns the entire set of flags for the mini-object.
*/
#define GST_MINI_OBJECT_TYPE(obj) (GST_MINI_OBJECT_CAST(obj)->type)
/**
* GST_MINI_OBJECT_FLAGS:
* @obj: MiniObject to return flags for.
@ -94,14 +94,6 @@ typedef void (*GstMiniObjectFinalizeFunction) (GstMiniObject *obj);
*/
#define GST_MINI_OBJECT_FLAG_UNSET(obj,flag) (GST_MINI_OBJECT_FLAGS (obj) &= ~(flag))
/**
* GST_VALUE_HOLDS_MINI_OBJECT:
* @value: the #GValue to check
*
* Checks if the given #GValue contains a #GST_TYPE_MINI_OBJECT value.
*/
#define GST_VALUE_HOLDS_MINI_OBJECT(value) (G_VALUE_HOLDS(value, GST_TYPE_MINI_OBJECT))
/**
* GstMiniObjectFlags:
* @GST_MINI_OBJECT_FLAG_READONLY: is the miniobject readonly or writable
@ -111,7 +103,6 @@ typedef void (*GstMiniObjectFinalizeFunction) (GstMiniObject *obj);
*
* Flags for the mini object
*/
typedef enum
{
GST_MINI_OBJECT_FLAG_READONLY = (1<<0),
@ -148,28 +139,18 @@ typedef enum
* Get Value Func: gst_value_get_mini_object
*/
struct _GstMiniObject {
GTypeInstance instance;
GType type;
/*< public >*/ /* with COW */
gint refcount;
guint flags;
/*< private >*/
gpointer _gst_reserved;
};
struct _GstMiniObjectClass {
GTypeClass type_class;
gint refcount;
guint flags;
GstMiniObjectCopyFunction copy;
GstMiniObjectFinalizeFunction finalize;
/*< private >*/
gpointer _gst_reserved;
GstMiniObjectFreeFunction free;
};
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 (GstMiniObject *mini_object);
@ -177,45 +158,9 @@ GstMiniObject* gst_mini_object_make_writable (GstMiniObject *mini_object);
/* refcounting */
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 */
#define GST_TYPE_PARAM_MINI_OBJECT (gst_param_spec_mini_object_get_type())
#define GST_IS_PARAM_SPEC_MINI_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), \
GST_TYPE_PARAM_MINI_OBJECT))
#define GST_PARAM_SPEC_MINI_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), \
GST_TYPE_PARAM_MINI_OBJECT, \
GstParamSpecMiniObject))
typedef struct _GstParamSpecMiniObject GstParamSpecMiniObject;
/**
* GstParamSpecMiniObject:
* @parent_instance: private %GParamSpec portion
*
* A %GParamSpec derived structure that contains the meta data
* for %GstMiniObject properties.
*/
struct _GstParamSpecMiniObject
{
GParamSpec parent_instance;
};
GType gst_param_spec_mini_object_get_type (void);
GParamSpec* gst_param_spec_mini_object (const char *name, const char *nick,
const char *blurb, GType object_type,
GParamFlags flags);
/* GValue stuff */
void gst_value_set_mini_object (GValue *value, GstMiniObject *mini_object);
void gst_value_take_mini_object (GValue *value, GstMiniObject *mini_object);
GstMiniObject* gst_value_get_mini_object (const GValue *value);
GstMiniObject* gst_value_dup_mini_object (const GValue *value);
G_END_DECLS

View file

@ -90,7 +90,6 @@ typedef enum {
typedef struct _GstQueryTypeDefinition GstQueryTypeDefinition;
typedef struct _GstQuery GstQuery;
typedef struct _GstQueryClass GstQueryClass;
/**
* GstQueryTypeDefinition:
@ -109,13 +108,10 @@ struct _GstQueryTypeDefinition
GQuark quark;
};
#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_CAST(obj) ((GstQuery*)(obj)) /* only since 0.10.23 */
#define GST_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_QUERY, GstQueryClass))
#define GST_TYPE_QUERY (gst_query_get_type())
#define GST_IS_QUERY(obj) (GST_MINI_OBJECT_TYPE (obj) == GST_TYPE_QUERY)
#define GST_QUERY_CAST(obj) ((GstQuery*)(obj))
#define GST_QUERY(obj) (GST_QUERY_CAST(obj))
/**
@ -158,13 +154,6 @@ struct _GstQuery
gpointer _gst_reserved;
};
struct _GstQueryClass {
GstMiniObjectClass mini_object_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
const gchar* gst_query_type_get_name (GstQueryType query);
GQuark gst_query_type_to_quark (GstQueryType query);