From ce081d6341c7bbc1d49bf574918f8a4dd4dd20ab Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 8 Oct 2005 08:58:45 +0000 Subject: [PATCH] Added extra field to STATE_CHANGE message with the pending state, which will be different from the new state soon. Original commit message from CVS: * check/gst/gstbin.c: (GST_START_TEST): * check/gst/gstmessage.c: (GST_START_TEST): * check/gst/gstpipeline.c: (GST_START_TEST), (message_received): * gst/gstelement.c: (gst_element_commit_state), (gst_element_lost_state): * gst/gstmessage.c: (gst_message_new_state_changed), (gst_message_parse_state_changed): * gst/gstmessage.h: * tools/gst-launch.c: (event_loop): Added extra field to STATE_CHANGE message with the pending state, which will be different from the new state soon. --- ChangeLog | 14 ++++++++++++++ check/gst/gstbin.c | 10 +++++----- check/gst/gstmessage.c | 11 ++++++++--- check/gst/gstpipeline.c | 8 ++++---- gst/gstelement.c | 4 ++-- gst/gstmessage.c | 30 ++++++++++++++++++++---------- gst/gstmessage.h | 4 ++-- tests/check/gst/gstbin.c | 10 +++++----- tests/check/gst/gstmessage.c | 11 ++++++++--- tests/check/gst/gstpipeline.c | 8 ++++---- tools/gst-launch.c | 4 ++-- 11 files changed, 74 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53b6a11cdb..366f02379e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-10-08 Wim Taymans + + * check/gst/gstbin.c: (GST_START_TEST): + * check/gst/gstmessage.c: (GST_START_TEST): + * check/gst/gstpipeline.c: (GST_START_TEST), (message_received): + * gst/gstelement.c: (gst_element_commit_state), + (gst_element_lost_state): + * gst/gstmessage.c: (gst_message_new_state_changed), + (gst_message_parse_state_changed): + * gst/gstmessage.h: + * tools/gst-launch.c: (event_loop): + Added extra field to STATE_CHANGE message with the pending + state, which will be different from the new state soon. + 2005-10-08 Wim Taymans * gst/gstbus.c: (gst_bus_pop): diff --git a/check/gst/gstbin.c b/check/gst/gstbin.c index 4d6c7f8832..020e9143a7 100644 --- a/check/gst/gstbin.c +++ b/check/gst/gstbin.c @@ -448,11 +448,11 @@ GST_END_TEST; #define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \ { \ GstMessage *msg; \ - GstState old = 0, new = 0; \ + GstState old = 0, new = 0, pending = 0; \ msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); \ fail_if (msg == NULL, "No state change message within 1 second (#" \ G_STRINGIFY (num) ")"); \ - gst_message_parse_state_changed (msg, &old, &new); \ + gst_message_parse_state_changed (msg, &old, &new, &pending); \ fail_if (msg->src != GST_OBJECT (element), G_STRINGIFY(element) \ " should have changed state next (#" G_STRINGIFY (num) ")"); \ fail_if (old != old_state || new != new_state, "state change is not " \ @@ -681,13 +681,13 @@ GST_START_TEST (test_children_state_change_order_two_sink) /* NULL => READY */ { GstMessage *msg; - GstState old = 0, new = 0; + GstState old = 0, new = 0, pending = 0; GstObject *first, *second; msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); fail_if (msg == NULL, "No state change message within 1 second (#201)"); - gst_message_parse_state_changed (msg, &old, &new); + gst_message_parse_state_changed (msg, &old, &new, &pending); first = gst_object_ref (msg->src); fail_if (first != GST_OBJECT (sink1) && first != GST_OBJECT (sink2), @@ -697,7 +697,7 @@ GST_START_TEST (test_children_state_change_order_two_sink) msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); fail_if (msg == NULL, "No state change message within 1 second (#201)"); - gst_message_parse_state_changed (msg, &old, &new); + gst_message_parse_state_changed (msg, &old, &new, &pending); second = gst_object_ref (msg->src); fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2), diff --git a/check/gst/gstmessage.c b/check/gst/gstmessage.c index cf0216fe41..a96711340e 100644 --- a/check/gst/gstmessage.c +++ b/check/gst/gstmessage.c @@ -120,21 +120,26 @@ GST_START_TEST (test_parsing) } /* GST_MESSAGE_STATE_CHANGED */ { - GstState oldstate, newstate; + GstState oldstate, newstate, pending; oldstate = GST_STATE_PAUSED; newstate = GST_STATE_PLAYING; + pending = GST_STATE_VOID_PENDING; - message = gst_message_new_state_changed (NULL, oldstate, newstate); + message = gst_message_new_state_changed (NULL, oldstate, newstate, pending); fail_if (message == NULL); fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); fail_unless (GST_MESSAGE_SRC (message) == NULL); + /* set some wrong values to check if the parse method overwrites them + * with the good values */ oldstate = GST_STATE_READY; newstate = GST_STATE_READY; - gst_message_parse_state_changed (message, &oldstate, &newstate); + pending = GST_STATE_READY; + gst_message_parse_state_changed (message, &oldstate, &newstate, &pending); fail_unless (oldstate == GST_STATE_PAUSED); fail_unless (newstate == GST_STATE_PLAYING); + fail_unless (pending == GST_STATE_VOID_PENDING); gst_message_unref (message); } diff --git a/check/gst/gstpipeline.c b/check/gst/gstpipeline.c index dbafeeeb8a..e516789869 100644 --- a/check/gst/gstpipeline.c +++ b/check/gst/gstpipeline.c @@ -86,11 +86,11 @@ GST_START_TEST (test_async_state_change_fake) while (!done) { GstMessage *message; - GstState old, new; + GstState old, new, pending; message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1); if (message) { - gst_message_parse_state_changed (message, &old, &new); + gst_message_parse_state_changed (message, &old, &new, &pending); GST_DEBUG_OBJECT (message->src, "state change from %d to %d", old, new); if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) done = TRUE; @@ -141,10 +141,10 @@ message_received (GstBus * bus, GstMessage * message, gpointer data) switch (type) { case GST_MESSAGE_STATE_CHANGED: { - GstState old, new; + GstState old, new, pending; GST_DEBUG ("state change message received"); - gst_message_parse_state_changed (message, &old, &new); + gst_message_parse_state_changed (message, &old, &new, &pending); GST_DEBUG ("new state %d", new); if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) { GST_DEBUG ("quitting main loop"); diff --git a/gst/gstelement.c b/gst/gstelement.c index 237f7288f9..e439101815 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -1770,7 +1770,7 @@ gst_element_commit_state (GstElement * element) GST_STATE_ERROR (element) = FALSE; message = gst_message_new_state_changed (GST_OBJECT (element), - old_state, pending); + old_state, pending, pending); gst_element_post_message (element, message); GST_STATE_BROADCAST (element); } @@ -1810,7 +1810,7 @@ gst_element_lost_state (GstElement * element) GST_STATE_ERROR (element) = FALSE; message = gst_message_new_state_changed (GST_OBJECT (element), - current_state, current_state); + current_state, current_state, current_state); gst_element_post_message (element, message); } } diff --git a/gst/gstmessage.c b/gst/gstmessage.c index 6448292a42..41d1b7c75a 100644 --- a/gst/gstmessage.c +++ b/gst/gstmessage.c @@ -354,6 +354,7 @@ gst_message_new_tag (GstObject * src, GstTagList * tag_list) * @src: The object originating the message. * @old: The previous state. * @new: The new (current) state. + * @pending: The pending (target) state. * * Create a state change message. This message is posted whenever an element changed * its state. @@ -363,15 +364,18 @@ gst_message_new_tag (GstObject * src, GstTagList * tag_list) * MT safe. */ GstMessage * -gst_message_new_state_changed (GstObject * src, GstState old, GstState new) +gst_message_new_state_changed (GstObject * src, + GstState old, GstState new, GstState pending) { GstMessage *message; GstStructure *s; message = gst_message_new (GST_MESSAGE_STATE_CHANGED, src); - s = gst_structure_new ("GstMessageState", "old-state", GST_TYPE_STATE, - (gint) old, "new-state", GST_TYPE_STATE, (gint) new, NULL); + s = gst_structure_new ("GstMessageState", + "old-state", GST_TYPE_STATE, (gint) old, + "new-state", GST_TYPE_STATE, (gint) new, + "pending-state", GST_TYPE_STATE, (gint) pending, NULL); gst_structure_set_parent_refcount (s, &message->mini_object.refcount); message->structure = s; @@ -545,6 +549,9 @@ gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list) /** * gst_message_parse_state_changed: * @message: A valid #GstMessage of type GST_MESSAGE_STATE_CHANGED. + * @old: The previous state. + * @new: The new (current) state. + * @pending: The pending (target) state. * * Extracts the old and new states from the GstMessage. * @@ -552,17 +559,20 @@ gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list) */ void gst_message_parse_state_changed (GstMessage * message, GstState * old, - GstState * new) + GstState * new, GstState * pending) { g_return_if_fail (GST_IS_MESSAGE (message)); g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); - if (!gst_structure_get_enum (message->structure, "old-state", - GST_TYPE_STATE, (gint *) old)) - g_assert_not_reached (); - if (!gst_structure_get_enum (message->structure, "new-state", - GST_TYPE_STATE, (gint *) new)) - g_assert_not_reached (); + if (old) + gst_structure_get_enum (message->structure, "old-state", + GST_TYPE_STATE, (gint *) old); + if (new) + gst_structure_get_enum (message->structure, "new-state", + GST_TYPE_STATE, (gint *) new); + if (pending) + gst_structure_get_enum (message->structure, "pending-state", + GST_TYPE_STATE, (gint *) pending); } /** diff --git a/gst/gstmessage.h b/gst/gstmessage.h index f2be6a9ecf..3138638731 100644 --- a/gst/gstmessage.h +++ b/gst/gstmessage.h @@ -145,7 +145,7 @@ GstMessage * gst_message_new_error (GstObject * src, GError * error, gchar * d GstMessage * gst_message_new_warning (GstObject * src, GError * error, gchar * debug); GstMessage * gst_message_new_tag (GstObject * src, GstTagList * tag_list); GstMessage * gst_message_new_state_changed (GstObject * src, GstState old_state, - GstState new_state); + GstState new_state, GstState pending); GstMessage * gst_message_new_segment_start (GstObject * src, GstClockTime timestamp); GstMessage * gst_message_new_segment_done (GstObject * src, GstClockTime timestamp); GstMessage * gst_message_new_application (GstObject * src, GstStructure * structure); @@ -158,7 +158,7 @@ void gst_message_parse_error (GstMessage *message, GError **gerror, gchar **de void gst_message_parse_warning (GstMessage *message, GError **gerror, gchar **debug); void gst_message_parse_tag (GstMessage *message, GstTagList **tag_list); void gst_message_parse_state_changed (GstMessage *message, GstState *old_state, - GstState *new_state); + GstState *new_state, GstState *pending); void gst_message_parse_segment_start (GstMessage *message, GstClockTime *timestamp); void gst_message_parse_segment_done (GstMessage *message, GstClockTime *timestamp); diff --git a/tests/check/gst/gstbin.c b/tests/check/gst/gstbin.c index 4d6c7f8832..020e9143a7 100644 --- a/tests/check/gst/gstbin.c +++ b/tests/check/gst/gstbin.c @@ -448,11 +448,11 @@ GST_END_TEST; #define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \ { \ GstMessage *msg; \ - GstState old = 0, new = 0; \ + GstState old = 0, new = 0, pending = 0; \ msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); \ fail_if (msg == NULL, "No state change message within 1 second (#" \ G_STRINGIFY (num) ")"); \ - gst_message_parse_state_changed (msg, &old, &new); \ + gst_message_parse_state_changed (msg, &old, &new, &pending); \ fail_if (msg->src != GST_OBJECT (element), G_STRINGIFY(element) \ " should have changed state next (#" G_STRINGIFY (num) ")"); \ fail_if (old != old_state || new != new_state, "state change is not " \ @@ -681,13 +681,13 @@ GST_START_TEST (test_children_state_change_order_two_sink) /* NULL => READY */ { GstMessage *msg; - GstState old = 0, new = 0; + GstState old = 0, new = 0, pending = 0; GstObject *first, *second; msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); fail_if (msg == NULL, "No state change message within 1 second (#201)"); - gst_message_parse_state_changed (msg, &old, &new); + gst_message_parse_state_changed (msg, &old, &new, &pending); first = gst_object_ref (msg->src); fail_if (first != GST_OBJECT (sink1) && first != GST_OBJECT (sink2), @@ -697,7 +697,7 @@ GST_START_TEST (test_children_state_change_order_two_sink) msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); fail_if (msg == NULL, "No state change message within 1 second (#201)"); - gst_message_parse_state_changed (msg, &old, &new); + gst_message_parse_state_changed (msg, &old, &new, &pending); second = gst_object_ref (msg->src); fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2), diff --git a/tests/check/gst/gstmessage.c b/tests/check/gst/gstmessage.c index cf0216fe41..a96711340e 100644 --- a/tests/check/gst/gstmessage.c +++ b/tests/check/gst/gstmessage.c @@ -120,21 +120,26 @@ GST_START_TEST (test_parsing) } /* GST_MESSAGE_STATE_CHANGED */ { - GstState oldstate, newstate; + GstState oldstate, newstate, pending; oldstate = GST_STATE_PAUSED; newstate = GST_STATE_PLAYING; + pending = GST_STATE_VOID_PENDING; - message = gst_message_new_state_changed (NULL, oldstate, newstate); + message = gst_message_new_state_changed (NULL, oldstate, newstate, pending); fail_if (message == NULL); fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); fail_unless (GST_MESSAGE_SRC (message) == NULL); + /* set some wrong values to check if the parse method overwrites them + * with the good values */ oldstate = GST_STATE_READY; newstate = GST_STATE_READY; - gst_message_parse_state_changed (message, &oldstate, &newstate); + pending = GST_STATE_READY; + gst_message_parse_state_changed (message, &oldstate, &newstate, &pending); fail_unless (oldstate == GST_STATE_PAUSED); fail_unless (newstate == GST_STATE_PLAYING); + fail_unless (pending == GST_STATE_VOID_PENDING); gst_message_unref (message); } diff --git a/tests/check/gst/gstpipeline.c b/tests/check/gst/gstpipeline.c index dbafeeeb8a..e516789869 100644 --- a/tests/check/gst/gstpipeline.c +++ b/tests/check/gst/gstpipeline.c @@ -86,11 +86,11 @@ GST_START_TEST (test_async_state_change_fake) while (!done) { GstMessage *message; - GstState old, new; + GstState old, new, pending; message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1); if (message) { - gst_message_parse_state_changed (message, &old, &new); + gst_message_parse_state_changed (message, &old, &new, &pending); GST_DEBUG_OBJECT (message->src, "state change from %d to %d", old, new); if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) done = TRUE; @@ -141,10 +141,10 @@ message_received (GstBus * bus, GstMessage * message, gpointer data) switch (type) { case GST_MESSAGE_STATE_CHANGED: { - GstState old, new; + GstState old, new, pending; GST_DEBUG ("state change message received"); - gst_message_parse_state_changed (message, &old, &new); + gst_message_parse_state_changed (message, &old, &new, &pending); GST_DEBUG ("new state %d", new); if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) { GST_DEBUG ("quitting main loop"); diff --git a/tools/gst-launch.c b/tools/gst-launch.c index 38239e317a..301351f532 100644 --- a/tools/gst-launch.c +++ b/tools/gst-launch.c @@ -438,9 +438,9 @@ event_loop (GstElement * pipeline, gboolean blocking) return TRUE; } case GST_MESSAGE_STATE_CHANGED:{ - GstState old, new; + GstState old, new, pending; - gst_message_parse_state_changed (message, &old, &new); + gst_message_parse_state_changed (message, &old, &new, &pending); if (!(old == GST_STATE_PLAYING && new == GST_STATE_PAUSED && GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline))) { gst_message_unref (message);