mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 20:42:30 +00:00
clean up object init
Make an _init method where the parent mini-object and other fields are initialized. Check that the passed structure doesn't already have a parent. Use the _new_custom () constructors
This commit is contained in:
parent
86c15749a4
commit
151d7faca3
3 changed files with 107 additions and 92 deletions
|
@ -251,6 +251,8 @@ _gst_event_copy (GstEvent * event)
|
|||
GST_EVENT_STRUCTURE (copy) = gst_structure_copy (s);
|
||||
gst_structure_set_parent_refcount (GST_EVENT_STRUCTURE (copy),
|
||||
©->event.mini_object.refcount);
|
||||
} else {
|
||||
GST_EVENT_STRUCTURE (copy) = NULL;
|
||||
}
|
||||
return GST_EVENT_CAST (copy);
|
||||
}
|
||||
|
@ -268,20 +270,6 @@ gst_event_init (GstEventImpl * event, gsize size, GstEventType type)
|
|||
GST_EVENT_SEQNUM (event) = gst_util_seqnum_next ();
|
||||
}
|
||||
|
||||
static GstEvent *
|
||||
gst_event_new (GstEventType type)
|
||||
{
|
||||
GstEventImpl *event;
|
||||
|
||||
event = g_slice_new0 (GstEventImpl);
|
||||
|
||||
GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
|
||||
gst_event_type_get_name (type), type);
|
||||
|
||||
gst_event_init (event, sizeof (GstEventImpl), type);
|
||||
|
||||
return GST_EVENT_CAST (event);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_event_new_custom:
|
||||
|
@ -305,23 +293,30 @@ gst_event_new (GstEventType type)
|
|||
GstEvent *
|
||||
gst_event_new_custom (GstEventType type, GstStructure * structure)
|
||||
{
|
||||
GstEvent *event;
|
||||
GstEventImpl *event;
|
||||
|
||||
event = g_slice_new0 (GstEventImpl);
|
||||
|
||||
GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
|
||||
gst_event_type_get_name (type), type);
|
||||
|
||||
/* structure must not have a parent */
|
||||
event = gst_event_new (type);
|
||||
if (structure) {
|
||||
/* structure must not have a parent */
|
||||
if (!gst_structure_set_parent_refcount (structure,
|
||||
&event->mini_object.refcount))
|
||||
&event->event.mini_object.refcount))
|
||||
goto had_parent;
|
||||
|
||||
GST_EVENT_STRUCTURE (event) = structure;
|
||||
}
|
||||
return event;
|
||||
gst_event_init (event, sizeof (GstEventImpl), type);
|
||||
|
||||
GST_EVENT_STRUCTURE (event) = structure;
|
||||
|
||||
return GST_EVENT_CAST (event);
|
||||
|
||||
/* ERRORS */
|
||||
had_parent:
|
||||
{
|
||||
gst_event_unref (event);
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event);
|
||||
g_warning ("structure is already owned by another object");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -484,7 +479,7 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
|
|||
GstEvent *
|
||||
gst_event_new_flush_start (void)
|
||||
{
|
||||
return gst_event_new (GST_EVENT_FLUSH_START);
|
||||
return gst_event_new_custom (GST_EVENT_FLUSH_START, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -562,7 +557,7 @@ gst_event_parse_flush_stop (GstEvent * event, gboolean * reset_time)
|
|||
GstEvent *
|
||||
gst_event_new_eos (void)
|
||||
{
|
||||
return gst_event_new (GST_EVENT_EOS);
|
||||
return gst_event_new_custom (GST_EVENT_EOS, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1605,5 +1600,5 @@ gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
|
|||
GstEvent *
|
||||
gst_event_new_stream_start (void)
|
||||
{
|
||||
return gst_event_new (GST_EVENT_STREAM_START);
|
||||
return gst_event_new_custom (GST_EVENT_STREAM_START, NULL);
|
||||
}
|
||||
|
|
|
@ -200,6 +200,10 @@ _gst_message_free (GstMessage * message)
|
|||
g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_message_init (GstMessageImpl * message, gsize size, GstMessageType type,
|
||||
GstObject * src);
|
||||
|
||||
static GstMessage *
|
||||
_gst_message_copy (GstMessage * message)
|
||||
{
|
||||
|
@ -212,31 +216,45 @@ _gst_message_copy (GstMessage * message)
|
|||
|
||||
copy = g_slice_new0 (GstMessageImpl);
|
||||
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (copy),
|
||||
_gst_message_type, sizeof (GstMessageImpl));
|
||||
gst_message_init (copy, sizeof (GstMessageImpl), GST_MESSAGE_TYPE (message),
|
||||
GST_MESSAGE_SRC (message));
|
||||
|
||||
copy->message.mini_object.copy =
|
||||
(GstMiniObjectCopyFunction) _gst_message_copy;
|
||||
copy->message.mini_object.free =
|
||||
(GstMiniObjectFreeFunction) _gst_message_free;
|
||||
|
||||
GST_MESSAGE_TYPE (copy) = GST_MESSAGE_TYPE (message);
|
||||
GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
|
||||
GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
|
||||
if (GST_MESSAGE_SRC (message)) {
|
||||
GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
|
||||
}
|
||||
|
||||
structure = GST_MESSAGE_STRUCTURE (message);
|
||||
if (structure) {
|
||||
copy->structure = gst_structure_copy (structure);
|
||||
gst_structure_set_parent_refcount (copy->structure,
|
||||
GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
|
||||
gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
|
||||
©->message.mini_object.refcount);
|
||||
} else {
|
||||
GST_MESSAGE_STRUCTURE (copy) = NULL;
|
||||
}
|
||||
|
||||
return GST_MESSAGE_CAST (copy);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_message_init (GstMessageImpl * message, gsize size, GstMessageType type,
|
||||
GstObject * src)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type,
|
||||
size);
|
||||
|
||||
message->message.mini_object.copy =
|
||||
(GstMiniObjectCopyFunction) _gst_message_copy;
|
||||
message->message.mini_object.free =
|
||||
(GstMiniObjectFreeFunction) _gst_message_free;
|
||||
|
||||
GST_MESSAGE_TYPE (message) = type;
|
||||
if (src)
|
||||
gst_object_ref (src);
|
||||
GST_MESSAGE_SRC (message) = src;
|
||||
GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
|
||||
GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gst_message_new_custom:
|
||||
* @type: The #GstMessageType to distinguish messages
|
||||
|
@ -260,32 +278,29 @@ gst_message_new_custom (GstMessageType type, GstObject * src,
|
|||
|
||||
message = g_slice_new0 (GstMessageImpl);
|
||||
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (message),
|
||||
_gst_message_type, sizeof (GstMessageImpl));
|
||||
|
||||
message->message.mini_object.copy =
|
||||
(GstMiniObjectCopyFunction) _gst_message_copy;
|
||||
message->message.mini_object.free =
|
||||
(GstMiniObjectFreeFunction) _gst_message_free;
|
||||
|
||||
GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
|
||||
(src ? GST_OBJECT_NAME (src) : "NULL"), message,
|
||||
gst_message_type_get_name (type));
|
||||
|
||||
GST_MESSAGE_TYPE (message) = type;
|
||||
if (src)
|
||||
gst_object_ref (src);
|
||||
GST_MESSAGE_SRC (message) = src;
|
||||
GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
|
||||
GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
|
||||
|
||||
if (structure) {
|
||||
gst_structure_set_parent_refcount (structure,
|
||||
&message->message.mini_object.refcount);
|
||||
/* structure must not have a parent */
|
||||
if (!gst_structure_set_parent_refcount (structure,
|
||||
&message->message.mini_object.refcount))
|
||||
goto had_parent;
|
||||
}
|
||||
message->structure = structure;
|
||||
gst_message_init (message, sizeof (GstMessageImpl), type, src);
|
||||
|
||||
GST_MESSAGE_STRUCTURE (message) = structure;
|
||||
|
||||
return GST_MESSAGE_CAST (message);
|
||||
|
||||
/* ERRORS */
|
||||
had_parent:
|
||||
{
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
|
||||
g_warning ("structure is already owned by another object");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -339,41 +339,25 @@ _gst_query_free (GstQuery * query)
|
|||
g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
|
||||
}
|
||||
|
||||
static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
|
||||
|
||||
static GstQuery *
|
||||
_gst_query_copy (GstQuery * query)
|
||||
{
|
||||
GstQuery *copy;
|
||||
|
||||
copy = gst_query_new (query->type, GST_QUERY_STRUCTURE (query));
|
||||
copy = gst_query_new_custom (query->type, GST_QUERY_STRUCTURE (query));
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
static GstQuery *
|
||||
gst_query_new (GstQueryType type, GstStructure * structure)
|
||||
static void
|
||||
gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
|
||||
{
|
||||
GstQueryImpl *query;
|
||||
|
||||
query = g_slice_new0 (GstQueryImpl);
|
||||
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
|
||||
_gst_query_type, sizeof (GstQueryImpl));
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
|
||||
|
||||
query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
|
||||
query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
|
||||
|
||||
GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
|
||||
|
||||
GST_QUERY_TYPE (query) = type;
|
||||
query->structure = structure;
|
||||
|
||||
if (structure)
|
||||
gst_structure_set_parent_refcount (structure,
|
||||
&query->query.mini_object.refcount);
|
||||
|
||||
return GST_QUERY_CAST (query);
|
||||
GST_EVENT_TYPE (query) = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -398,7 +382,7 @@ gst_query_new_position (GstFormat format)
|
|||
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
|
||||
GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_POSITION, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_POSITION, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -477,7 +461,7 @@ gst_query_new_duration (GstFormat format)
|
|||
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
|
||||
GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_DURATION, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_DURATION, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -557,7 +541,7 @@ gst_query_new_latency (void)
|
|||
GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
|
||||
GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_LATENCY, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -647,7 +631,7 @@ gst_query_new_convert (GstFormat src_format, gint64 value,
|
|||
GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
|
||||
GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_CONVERT, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -741,7 +725,7 @@ gst_query_new_segment (GstFormat format)
|
|||
GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
|
||||
GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_SEGMENT, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -835,10 +819,31 @@ gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
|
|||
GstQuery *
|
||||
gst_query_new_custom (GstQueryType type, GstStructure * structure)
|
||||
{
|
||||
g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
|
||||
g_return_val_if_fail (structure != NULL, NULL);
|
||||
GstQueryImpl *query;
|
||||
|
||||
return gst_query_new (type, structure);
|
||||
query = g_slice_new0 (GstQueryImpl);
|
||||
|
||||
GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
|
||||
|
||||
if (structure) {
|
||||
/* structure must not have a parent */
|
||||
if (!gst_structure_set_parent_refcount (structure,
|
||||
&query->query.mini_object.refcount))
|
||||
goto had_parent;
|
||||
}
|
||||
gst_query_init (query, sizeof (GstQueryImpl), type);
|
||||
|
||||
GST_QUERY_STRUCTURE (query) = structure;
|
||||
|
||||
return GST_QUERY_CAST (query);
|
||||
|
||||
/* ERRORS */
|
||||
had_parent:
|
||||
{
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
|
||||
g_warning ("structure is already owned by another object");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -901,7 +906,7 @@ gst_query_new_seeking (GstFormat format)
|
|||
GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
|
||||
GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_SEEKING, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -1014,7 +1019,7 @@ gst_query_new_formats (void)
|
|||
GstStructure *structure;
|
||||
|
||||
structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
|
||||
query = gst_query_new (GST_QUERY_FORMATS, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -1193,7 +1198,7 @@ gst_query_new_buffering (GstFormat format)
|
|||
GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
|
||||
GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_BUFFERING, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -1527,7 +1532,7 @@ gst_query_new_uri (void)
|
|||
structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
|
||||
GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_URI, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_URI, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -1606,7 +1611,7 @@ gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
|
|||
GST_QUARK (ALIGN), G_TYPE_UINT, 0,
|
||||
GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
|
||||
|
||||
query = gst_query_new (GST_QUERY_ALLOCATION, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -1913,7 +1918,7 @@ gst_query_new_scheduling (void)
|
|||
GST_QUARK (MINSIZE), G_TYPE_INT, 1,
|
||||
GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
|
||||
GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
|
||||
query = gst_query_new (GST_QUERY_SCHEDULING, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -2096,7 +2101,7 @@ gst_query_new_accept_caps (GstCaps * caps)
|
|||
structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
|
||||
GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
|
||||
GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
|
||||
query = gst_query_new (GST_QUERY_ACCEPT_CAPS, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -2179,7 +2184,7 @@ gst_query_new_caps (GstCaps * filter)
|
|||
structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
|
||||
GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
|
||||
GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
|
||||
query = gst_query_new (GST_QUERY_CAPS, structure);
|
||||
query = gst_query_new_custom (GST_QUERY_CAPS, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue