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.
This commit is contained in:
Wim Taymans 2005-10-08 08:58:45 +00:00
parent 8e213e710b
commit ce081d6341
11 changed files with 74 additions and 40 deletions

View file

@ -1,3 +1,17 @@
2005-10-08 Wim Taymans <wim@fluendo.com>
* 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 <wim@fluendo.com> 2005-10-08 Wim Taymans <wim@fluendo.com>
* gst/gstbus.c: (gst_bus_pop): * gst/gstbus.c: (gst_bus_pop):

View file

@ -448,11 +448,11 @@ GST_END_TEST;
#define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \ #define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \
{ \ { \
GstMessage *msg; \ 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); \ msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); \
fail_if (msg == NULL, "No state change message within 1 second (#" \ fail_if (msg == NULL, "No state change message within 1 second (#" \
G_STRINGIFY (num) ")"); \ 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) \ fail_if (msg->src != GST_OBJECT (element), G_STRINGIFY(element) \
" should have changed state next (#" G_STRINGIFY (num) ")"); \ " should have changed state next (#" G_STRINGIFY (num) ")"); \
fail_if (old != old_state || new != new_state, "state change is not " \ 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 */ /* NULL => READY */
{ {
GstMessage *msg; GstMessage *msg;
GstState old = 0, new = 0; GstState old = 0, new = 0, pending = 0;
GstObject *first, *second; GstObject *first, *second;
msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
fail_if (msg == NULL, "No state change message within 1 second (#201)"); 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); first = gst_object_ref (msg->src);
fail_if (first != GST_OBJECT (sink1) && first != GST_OBJECT (sink2), 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); msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
fail_if (msg == NULL, "No state change message within 1 second (#201)"); 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); second = gst_object_ref (msg->src);
fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2), fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2),

View file

@ -120,21 +120,26 @@ GST_START_TEST (test_parsing)
} }
/* GST_MESSAGE_STATE_CHANGED */ /* GST_MESSAGE_STATE_CHANGED */
{ {
GstState oldstate, newstate; GstState oldstate, newstate, pending;
oldstate = GST_STATE_PAUSED; oldstate = GST_STATE_PAUSED;
newstate = GST_STATE_PLAYING; 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_if (message == NULL);
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
fail_unless (GST_MESSAGE_SRC (message) == NULL); 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; oldstate = GST_STATE_READY;
newstate = 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 (oldstate == GST_STATE_PAUSED);
fail_unless (newstate == GST_STATE_PLAYING); fail_unless (newstate == GST_STATE_PLAYING);
fail_unless (pending == GST_STATE_VOID_PENDING);
gst_message_unref (message); gst_message_unref (message);
} }

View file

@ -86,11 +86,11 @@ GST_START_TEST (test_async_state_change_fake)
while (!done) { while (!done) {
GstMessage *message; GstMessage *message;
GstState old, new; GstState old, new, pending;
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1); message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
if (message) { 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); GST_DEBUG_OBJECT (message->src, "state change from %d to %d", old, new);
if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING)
done = TRUE; done = TRUE;
@ -141,10 +141,10 @@ message_received (GstBus * bus, GstMessage * message, gpointer data)
switch (type) { switch (type) {
case GST_MESSAGE_STATE_CHANGED: case GST_MESSAGE_STATE_CHANGED:
{ {
GstState old, new; GstState old, new, pending;
GST_DEBUG ("state change message received"); 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); GST_DEBUG ("new state %d", new);
if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) { if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) {
GST_DEBUG ("quitting main loop"); GST_DEBUG ("quitting main loop");

View file

@ -1770,7 +1770,7 @@ gst_element_commit_state (GstElement * element)
GST_STATE_ERROR (element) = FALSE; GST_STATE_ERROR (element) = FALSE;
message = gst_message_new_state_changed (GST_OBJECT (element), message = gst_message_new_state_changed (GST_OBJECT (element),
old_state, pending); old_state, pending, pending);
gst_element_post_message (element, message); gst_element_post_message (element, message);
GST_STATE_BROADCAST (element); GST_STATE_BROADCAST (element);
} }
@ -1810,7 +1810,7 @@ gst_element_lost_state (GstElement * element)
GST_STATE_ERROR (element) = FALSE; GST_STATE_ERROR (element) = FALSE;
message = gst_message_new_state_changed (GST_OBJECT (element), 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); gst_element_post_message (element, message);
} }
} }

View file

@ -354,6 +354,7 @@ gst_message_new_tag (GstObject * src, GstTagList * tag_list)
* @src: The object originating the message. * @src: The object originating the message.
* @old: The previous state. * @old: The previous state.
* @new: The new (current) state. * @new: The new (current) state.
* @pending: The pending (target) state.
* *
* Create a state change message. This message is posted whenever an element changed * Create a state change message. This message is posted whenever an element changed
* its state. * its state.
@ -363,15 +364,18 @@ gst_message_new_tag (GstObject * src, GstTagList * tag_list)
* MT safe. * MT safe.
*/ */
GstMessage * 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; GstMessage *message;
GstStructure *s; GstStructure *s;
message = gst_message_new (GST_MESSAGE_STATE_CHANGED, src); message = gst_message_new (GST_MESSAGE_STATE_CHANGED, src);
s = gst_structure_new ("GstMessageState", "old-state", GST_TYPE_STATE, s = gst_structure_new ("GstMessageState",
(gint) old, "new-state", GST_TYPE_STATE, (gint) new, NULL); "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); gst_structure_set_parent_refcount (s, &message->mini_object.refcount);
message->structure = s; message->structure = s;
@ -545,6 +549,9 @@ gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
/** /**
* gst_message_parse_state_changed: * gst_message_parse_state_changed:
* @message: A valid #GstMessage of type GST_MESSAGE_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. * Extracts the old and new states from the GstMessage.
* *
@ -552,17 +559,20 @@ gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
*/ */
void void
gst_message_parse_state_changed (GstMessage * message, GstState * old, 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_IS_MESSAGE (message));
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
if (!gst_structure_get_enum (message->structure, "old-state", if (old)
GST_TYPE_STATE, (gint *) old)) gst_structure_get_enum (message->structure, "old-state",
g_assert_not_reached (); GST_TYPE_STATE, (gint *) old);
if (!gst_structure_get_enum (message->structure, "new-state", if (new)
GST_TYPE_STATE, (gint *) new)) gst_structure_get_enum (message->structure, "new-state",
g_assert_not_reached (); GST_TYPE_STATE, (gint *) new);
if (pending)
gst_structure_get_enum (message->structure, "pending-state",
GST_TYPE_STATE, (gint *) pending);
} }
/** /**

View file

@ -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_warning (GstObject * src, GError * error, gchar * debug);
GstMessage * gst_message_new_tag (GstObject * src, GstTagList * tag_list); GstMessage * gst_message_new_tag (GstObject * src, GstTagList * tag_list);
GstMessage * gst_message_new_state_changed (GstObject * src, GstState old_state, 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_start (GstObject * src, GstClockTime timestamp);
GstMessage * gst_message_new_segment_done (GstObject * src, GstClockTime timestamp); GstMessage * gst_message_new_segment_done (GstObject * src, GstClockTime timestamp);
GstMessage * gst_message_new_application (GstObject * src, GstStructure * structure); 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_warning (GstMessage *message, GError **gerror, gchar **debug);
void gst_message_parse_tag (GstMessage *message, GstTagList **tag_list); void gst_message_parse_tag (GstMessage *message, GstTagList **tag_list);
void gst_message_parse_state_changed (GstMessage *message, GstState *old_state, 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_start (GstMessage *message, GstClockTime *timestamp);
void gst_message_parse_segment_done (GstMessage *message, GstClockTime *timestamp); void gst_message_parse_segment_done (GstMessage *message, GstClockTime *timestamp);

View file

@ -448,11 +448,11 @@ GST_END_TEST;
#define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \ #define ASSERT_STATE_CHANGE_MSG(bus,element,old_state,new_state,num) \
{ \ { \
GstMessage *msg; \ 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); \ msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); \
fail_if (msg == NULL, "No state change message within 1 second (#" \ fail_if (msg == NULL, "No state change message within 1 second (#" \
G_STRINGIFY (num) ")"); \ 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) \ fail_if (msg->src != GST_OBJECT (element), G_STRINGIFY(element) \
" should have changed state next (#" G_STRINGIFY (num) ")"); \ " should have changed state next (#" G_STRINGIFY (num) ")"); \
fail_if (old != old_state || new != new_state, "state change is not " \ 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 */ /* NULL => READY */
{ {
GstMessage *msg; GstMessage *msg;
GstState old = 0, new = 0; GstState old = 0, new = 0, pending = 0;
GstObject *first, *second; GstObject *first, *second;
msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND); msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
fail_if (msg == NULL, "No state change message within 1 second (#201)"); 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); first = gst_object_ref (msg->src);
fail_if (first != GST_OBJECT (sink1) && first != GST_OBJECT (sink2), 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); msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, GST_SECOND);
fail_if (msg == NULL, "No state change message within 1 second (#201)"); 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); second = gst_object_ref (msg->src);
fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2), fail_if (second != GST_OBJECT (sink1) && second != GST_OBJECT (sink2),

View file

@ -120,21 +120,26 @@ GST_START_TEST (test_parsing)
} }
/* GST_MESSAGE_STATE_CHANGED */ /* GST_MESSAGE_STATE_CHANGED */
{ {
GstState oldstate, newstate; GstState oldstate, newstate, pending;
oldstate = GST_STATE_PAUSED; oldstate = GST_STATE_PAUSED;
newstate = GST_STATE_PLAYING; 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_if (message == NULL);
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED); fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
fail_unless (GST_MESSAGE_SRC (message) == NULL); 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; oldstate = GST_STATE_READY;
newstate = 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 (oldstate == GST_STATE_PAUSED);
fail_unless (newstate == GST_STATE_PLAYING); fail_unless (newstate == GST_STATE_PLAYING);
fail_unless (pending == GST_STATE_VOID_PENDING);
gst_message_unref (message); gst_message_unref (message);
} }

View file

@ -86,11 +86,11 @@ GST_START_TEST (test_async_state_change_fake)
while (!done) { while (!done) {
GstMessage *message; GstMessage *message;
GstState old, new; GstState old, new, pending;
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1); message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
if (message) { 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); GST_DEBUG_OBJECT (message->src, "state change from %d to %d", old, new);
if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING)
done = TRUE; done = TRUE;
@ -141,10 +141,10 @@ message_received (GstBus * bus, GstMessage * message, gpointer data)
switch (type) { switch (type) {
case GST_MESSAGE_STATE_CHANGED: case GST_MESSAGE_STATE_CHANGED:
{ {
GstState old, new; GstState old, new, pending;
GST_DEBUG ("state change message received"); 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); GST_DEBUG ("new state %d", new);
if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) { if (message->src == GST_OBJECT (pipeline) && new == GST_STATE_PLAYING) {
GST_DEBUG ("quitting main loop"); GST_DEBUG ("quitting main loop");

View file

@ -438,9 +438,9 @@ event_loop (GstElement * pipeline, gboolean blocking)
return TRUE; return TRUE;
} }
case GST_MESSAGE_STATE_CHANGED:{ 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 && if (!(old == GST_STATE_PLAYING && new == GST_STATE_PAUSED &&
GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline))) { GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline))) {
gst_message_unref (message); gst_message_unref (message);