Change GST_MESSAGE_SRC to be a GObject rather than a GstObject, so that applications can sensibly post custom message...

Original commit message from CVS:
* check/gst/gstbin.c: (GST_START_TEST):
* gst/gstbin.c: (bin_bus_handler):
* gst/gstmessage.c: (gst_message_finalize), (_gst_message_copy),
(gst_message_new), (gst_message_new_eos), (gst_message_new_error),
(gst_message_new_warning), (gst_message_new_tag),
(gst_message_new_state_changed), (gst_message_new_segment_start),
(gst_message_new_segment_done), (gst_message_new_custom):
* gst/gstmessage.h:
* tools/gst-launch.c: (event_loop):
* tools/gst-md5sum.c: (event_loop):
Change GST_MESSAGE_SRC to be a GObject rather than a GstObject, so
that applications can sensibly post custom messages with references
to their own objects.
This commit is contained in:
Jan Schmidt 2005-08-24 11:54:37 +00:00
parent 15af2428df
commit 59a41141ca
8 changed files with 59 additions and 22 deletions

View file

@ -1,3 +1,19 @@
2005-08-24 Jan Schmidt <thaytan@mad.scientist.com>
* check/gst/gstbin.c: (GST_START_TEST):
* gst/gstbin.c: (bin_bus_handler):
* gst/gstmessage.c: (gst_message_finalize), (_gst_message_copy),
(gst_message_new), (gst_message_new_eos), (gst_message_new_error),
(gst_message_new_warning), (gst_message_new_tag),
(gst_message_new_state_changed), (gst_message_new_segment_start),
(gst_message_new_segment_done), (gst_message_new_custom):
* gst/gstmessage.h:
* tools/gst-launch.c: (event_loop):
* tools/gst-md5sum.c: (event_loop):
Change GST_MESSAGE_SRC to be a GObject rather than a GstObject, so
that applications can sensibly post custom messages with references
to their own objects.
2005-08-24 Andy Wingo <wingo@pobox.com>
* gst/gstpad.c (gst_pad_fixate_caps): Check if the caps is fixed

View file

@ -170,7 +170,7 @@ GST_START_TEST (test_message_state_changed_child)
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
message = gst_bus_pop (bus);
fail_unless (message->src == GST_OBJECT (src));
fail_unless (GST_MESSAGE_SRC (message) == G_OBJECT (src));
gst_message_unref (message);
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
@ -181,7 +181,7 @@ GST_START_TEST (test_message_state_changed_child)
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
message = gst_bus_pop (bus);
fail_unless (message->src == GST_OBJECT (bin));
fail_unless (GST_MESSAGE_SRC (message) == G_OBJECT (bin));
gst_message_unref (message);
ASSERT_OBJECT_REFCOUNT (src, "src", 1);

View file

@ -1539,7 +1539,13 @@ bin_bus_handler (GstBus * bus, GstMessage * message, GstBin * bin)
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_EOS:{
gchar *name = gst_object_get_name (GST_MESSAGE_SRC (message));
GObject *src = GST_MESSAGE_SRC (message);
gchar *name;
if (src && GST_IS_OBJECT (src))
name = gst_object_get_name (GST_OBJECT (src));
else
name = g_strdup ("(null)");
GST_DEBUG_OBJECT (bin, "got EOS message from %s", name);
g_free (name);

View file

@ -106,7 +106,10 @@ gst_message_finalize (GstMessage * message)
GST_CAT_INFO (GST_CAT_MESSAGE, "finalize message %p", message);
if (GST_MESSAGE_SRC (message)) {
gst_object_unref (GST_MESSAGE_SRC (message));
if (GST_IS_OBJECT (GST_MESSAGE_SRC (message)))
gst_object_unref (GST_OBJECT (GST_MESSAGE_SRC (message)));
else
g_object_unref (GST_MESSAGE_SRC (message));
GST_MESSAGE_SRC (message) = NULL;
}
@ -140,7 +143,11 @@ _gst_message_copy (GstMessage * message)
GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
if (GST_MESSAGE_SRC (message)) {
GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
if (GST_IS_OBJECT (GST_MESSAGE_SRC (message)))
GST_MESSAGE_SRC (copy) =
gst_object_ref (GST_OBJECT (GST_MESSAGE_SRC (message)));
else
GST_MESSAGE_SRC (copy) = g_object_ref (GST_MESSAGE_SRC (message));
}
if (message->structure) {
@ -153,7 +160,7 @@ _gst_message_copy (GstMessage * message)
}
static GstMessage *
gst_message_new (GstMessageType type, GstObject * src)
gst_message_new (GstMessageType type, GObject * src)
{
GstMessage *message;
@ -163,7 +170,11 @@ gst_message_new (GstMessageType type, GstObject * src)
message->type = type;
if (src) {
message->src = gst_object_ref (src);
if (GST_IS_OBJECT (src))
message->src = gst_object_ref (GST_OBJECT (src));
else
message->src = g_object_ref (src);
GST_CAT_DEBUG_OBJECT (GST_CAT_MESSAGE, src, "message source");
} else {
message->src = NULL;
@ -190,7 +201,7 @@ gst_message_new_eos (GstObject * src)
{
GstMessage *message;
message = gst_message_new (GST_MESSAGE_EOS, src);
message = gst_message_new (GST_MESSAGE_EOS, (GObject *) (src));
return message;
}
@ -215,7 +226,7 @@ gst_message_new_error (GstObject * src, GError * error, gchar * debug)
GstMessage *message;
GstStructure *s;
message = gst_message_new (GST_MESSAGE_ERROR, src);
message = gst_message_new (GST_MESSAGE_ERROR, (GObject *) (src));
/* gst_structure_new takes copies of the types passed in */
s = gst_structure_new ("GstMessageError", "gerror", GST_TYPE_G_ERROR, error,
"debug", G_TYPE_STRING, debug, NULL);
@ -244,7 +255,7 @@ gst_message_new_warning (GstObject * src, GError * error, gchar * debug)
GstMessage *message;
GstStructure *s;
message = gst_message_new (GST_MESSAGE_WARNING, src);
message = gst_message_new (GST_MESSAGE_WARNING, (GObject *) (src));
/* gst_structure_new takes copies of the types passed in */
s = gst_structure_new ("GstMessageWarning", "gerror", GST_TYPE_G_ERROR, error,
"debug", G_TYPE_STRING, debug, NULL);
@ -273,7 +284,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);
message = gst_message_new (GST_MESSAGE_TAG, (GObject *) (src));
gst_structure_set_parent_refcount (tag_list, &message->mini_object.refcount);
message->structure = tag_list;
@ -300,7 +311,7 @@ gst_message_new_state_changed (GstObject * src, GstElementState old,
GstMessage *message;
GstStructure *s;
message = gst_message_new (GST_MESSAGE_STATE_CHANGED, src);
message = gst_message_new (GST_MESSAGE_STATE_CHANGED, (GObject *) (src));
s = gst_structure_new ("GstMessageState", "old-state", G_TYPE_INT, (gint) old,
"new-state", G_TYPE_INT, (gint) new, NULL);
@ -330,7 +341,7 @@ gst_message_new_segment_start (GstObject * src, GstClockTime timestamp)
GstMessage *message;
GstStructure *s;
message = gst_message_new (GST_MESSAGE_SEGMENT_START, src);
message = gst_message_new (GST_MESSAGE_SEGMENT_START, (GObject *) (src));
s = gst_structure_new ("GstMessageSegmentStart", "timestamp", G_TYPE_INT64,
(gint64) timestamp, NULL);
@ -360,7 +371,7 @@ gst_message_new_segment_done (GstObject * src, GstClockTime timestamp)
GstMessage *message;
GstStructure *s;
message = gst_message_new (GST_MESSAGE_SEGMENT_DONE, src);
message = gst_message_new (GST_MESSAGE_SEGMENT_DONE, (GObject *) (src));
s = gst_structure_new ("GstMessageSegmentDone", "timestamp", G_TYPE_INT64,
(gint64) timestamp, NULL);
@ -385,7 +396,7 @@ gst_message_new_segment_done (GstObject * src, GstClockTime timestamp)
* MT safe.
*/
GstMessage *
gst_message_new_custom (GstMessageType type, GstObject * src,
gst_message_new_custom (GstMessageType type, GObject * src,
GstStructure * structure)
{
GstMessage *message;

View file

@ -108,7 +108,7 @@ struct _GstMessage
/*< public > *//* with COW */
GstMessageType type;
guint64 timestamp;
GstObject *src;
GObject *src;
GstStructure *structure;
@ -143,7 +143,7 @@ GstMessage * gst_message_new_state_changed (GstObject * src, GstElementState ol
GstMessage * gst_message_new_segment_start (GstObject * src, GstClockTime timestamp);
GstMessage * gst_message_new_segment_done (GstObject * src, GstClockTime timestamp);
GstMessage * gst_message_new_custom (GstMessageType type,
GstObject * src,
GObject * src,
GstStructure * structure);
#define gst_message_new_application(src, str) \
gst_message_new_custom (GST_MESSAGE_APPLICATION, src, str)

View file

@ -170,7 +170,7 @@ GST_START_TEST (test_message_state_changed_child)
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
message = gst_bus_pop (bus);
fail_unless (message->src == GST_OBJECT (src));
fail_unless (GST_MESSAGE_SRC (message) == G_OBJECT (src));
gst_message_unref (message);
ASSERT_OBJECT_REFCOUNT (src, "src", 1);
@ -181,7 +181,7 @@ GST_START_TEST (test_message_state_changed_child)
== GST_MESSAGE_STATE_CHANGED, "did not get GST_MESSAGE_STATE_CHANGED");
message = gst_bus_pop (bus);
fail_unless (message->src == GST_OBJECT (bin));
fail_unless (GST_MESSAGE_SRC (message) == G_OBJECT (bin));
gst_message_unref (message);
ASSERT_OBJECT_REFCOUNT (src, "src", 1);

View file

@ -431,7 +431,9 @@ event_loop (GstElement * pipeline, gboolean blocking)
gchar *debug;
gst_message_parse_error (message, &gerror, &debug);
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
if (GST_IS_OBJECT (GST_MESSAGE_SRC (message)))
gst_object_default_error (GST_OBJECT (GST_MESSAGE_SRC (message)),
gerror, debug);
gst_message_unref (message);
if (gerror)
g_error_free (gerror);
@ -444,7 +446,7 @@ event_loop (GstElement * pipeline, gboolean blocking)
gst_message_parse_state_changed (message, &old, &new);
if (!(old == GST_STATE_PLAYING && new == GST_STATE_PAUSED &&
GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline))) {
GST_MESSAGE_SRC (message) == G_OBJECT (pipeline))) {
gst_message_unref (message);
break;
}

View file

@ -34,7 +34,9 @@ event_loop (GstElement * pipeline)
gst_message_parse_error (message, &gerror, &debug);
gst_message_unref (message);
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
if (GST_IS_OBJECT (GST_MESSAGE_SRC (message)))
gst_object_default_error (GST_OBJECT (GST_MESSAGE_SRC (message)),
gerror, debug);
g_error_free (gerror);
g_free (debug);
return TRUE;