Commit 0176d5a0 authored by Wim Taymans's avatar Wim Taymans

Seriously, this is better than a previous commit as we only need to notify the...

Seriously, this is better than a previous commit as we only need to notify the fact that an element changed state in ...

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/gstbin.c: (gst_bin_class_init), (gst_bin_recalc_func),
(bin_bus_handler):
* gst/gstelement.c: (gst_element_abort_state),
(gst_element_commit_state), (gst_element_lost_state):
* gst/gstmessage.c: (gst_message_new_state_changed),
(gst_message_new_state_dirty), (gst_message_new_segment_start),
(gst_message_new_segment_done), (gst_message_new_duration),
(gst_message_parse_state_changed),
(gst_message_parse_segment_start),
(gst_message_parse_segment_done), (gst_message_parse_duration):
* gst/gstmessage.h:
* tools/gst-launch.c: (event_loop):
Seriously, this is better than a previous commit as we only need
to notify the fact that an element changed state in a streaming
thread, marking the state of the parents dirty, hence the
STATE_DIRTY message instead of abusing a boolean in a STATE_CHANGE
message.
parent 2c61a2f4
2005-10-18 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/gstbin.c: (gst_bin_class_init), (gst_bin_recalc_func),
(bin_bus_handler):
* gst/gstelement.c: (gst_element_abort_state),
(gst_element_commit_state), (gst_element_lost_state):
* gst/gstmessage.c: (gst_message_new_state_changed),
(gst_message_new_state_dirty), (gst_message_new_segment_start),
(gst_message_new_segment_done), (gst_message_new_duration),
(gst_message_parse_state_changed),
(gst_message_parse_segment_start),
(gst_message_parse_segment_done), (gst_message_parse_duration):
* gst/gstmessage.h:
* tools/gst-launch.c: (event_loop):
Seriously, this is better than a previous commit as we only need
to notify the fact that an element changed state in a streaming
thread, marking the state of the parents dirty, hence the
STATE_DIRTY message instead of abusing a boolean in a STATE_CHANGE
message.
2005-10-18 Wim Taymans <wim@fluendo.com>
* gst/gstbin.c: (gst_bin_class_init), (gst_bin_get_state_func),
......
......@@ -464,11 +464,10 @@ GST_END_TEST;
{ \
GstMessage *msg; \
GstState old = 0, new = 0, pending = 0; \
gboolean async; \
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, &async, &old, &new, &pending); \
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 " \
......@@ -713,13 +712,12 @@ GST_START_TEST (test_children_state_change_order_two_sink)
{
GstMessage *msg;
GstState old = 0, new = 0, pending = 0;
gboolean async;
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, &async, &old, &new, &pending);
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),
......@@ -729,7 +727,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, &async, &old, &new, &pending);
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),
......
......@@ -121,29 +121,22 @@ GST_START_TEST (test_parsing)
/* GST_MESSAGE_STATE_CHANGED */
{
GstState oldstate, newstate, pending;
gboolean async;
async = TRUE;
oldstate = GST_STATE_PAUSED;
newstate = GST_STATE_PLAYING;
pending = GST_STATE_VOID_PENDING;
message =
gst_message_new_state_changed (NULL, async, oldstate, newstate,
pending);
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 */
async = FALSE;
oldstate = GST_STATE_READY;
newstate = GST_STATE_READY;
pending = GST_STATE_READY;
gst_message_parse_state_changed (message, &async, &oldstate, &newstate,
&pending);
fail_unless (async == TRUE);
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);
......
......@@ -84,11 +84,10 @@ GST_START_TEST (test_async_state_change_fake)
while (!done) {
GstMessage *message;
GstState old, new, pending;
gboolean async;
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
if (message) {
gst_message_parse_state_changed (message, &async, &old, &new, &pending);
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;
......@@ -139,10 +138,9 @@ message_received (GstBus * bus, GstMessage * message, gpointer data)
case GST_MESSAGE_STATE_CHANGED:
{
GstState old, new, pending;
gboolean async;
GST_DEBUG ("state change message received");
gst_message_parse_state_changed (message, &async, &old, &new, &pending);
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");
......
......@@ -1626,9 +1626,8 @@ bin_bus_handler (GstBus * bus, GstMessage * message, GstBin * bin)
{
GstState old, new, pending;
GstObject *src;
gboolean async;
gst_message_parse_state_changed (message, &async, &old, &new, &pending);
gst_message_parse_state_changed (message, &old, &new, &pending);
src = GST_MESSAGE_SRC (message);
/* ref src, as we need it after we post the message up */
gst_object_ref (src);
......
......@@ -1851,7 +1851,7 @@ gst_element_commit_state (GstElement * element)
gst_element_state_get_name (pending));
message = gst_message_new_state_changed (GST_OBJECT (element),
FALSE, old_state, next, pending);
old_state, next, pending);
gst_element_post_message (element, message);
if (pending != GST_STATE_VOID_PENDING) {
......@@ -1921,7 +1921,7 @@ gst_element_lost_state (GstElement * element)
GST_STATE_RETURN (element) = GST_STATE_CHANGE_ASYNC;
message = gst_message_new_state_changed (GST_OBJECT (element),
FALSE, current_state, current_state, current_state);
current_state, current_state, current_state);
gst_element_post_message (element, message);
return;
......
......@@ -82,6 +82,7 @@ static GstMessageQuarks message_quarks[] = {
{GST_MESSAGE_TAG, "tag", 0},
{GST_MESSAGE_BUFFERING, "buffering", 0},
{GST_MESSAGE_STATE_CHANGED, "state-changed", 0},
{GST_MESSAGE_STATE_DIRTY, "state-dirty", 0},
{GST_MESSAGE_STEP_DONE, "step-done", 0},
{GST_MESSAGE_CLOCK_PROVIDE, "clock-provide", 0},
{GST_MESSAGE_CLOCK_LOST, "clock-lost", 0},
......@@ -385,7 +386,6 @@ gst_message_new_tag (GstObject * src, GstTagList * tag_list)
/**
* gst_message_new_state_changed:
* @src: the object originating the message
* @async: if this is a state change from a streaming thread
* @oldstate: the previous state
* @newstate: the new (current) state
* @pending: the pending (target) state
......@@ -398,14 +398,13 @@ gst_message_new_tag (GstObject * src, GstTagList * tag_list)
* MT safe.
*/
GstMessage *
gst_message_new_state_changed (GstObject * src, gboolean async,
gst_message_new_state_changed (GstObject * src,
GstState oldstate, GstState newstate, GstState pending)
{
GstMessage *message;
message = gst_message_new_custom (GST_MESSAGE_STATE_CHANGED, src,
gst_structure_new ("GstMessageState",
"async", G_TYPE_BOOLEAN, async,
"old-state", GST_TYPE_STATE, (gint) oldstate,
"new-state", GST_TYPE_STATE, (gint) newstate,
"pending-state", GST_TYPE_STATE, (gint) pending, NULL));
......@@ -413,6 +412,28 @@ gst_message_new_state_changed (GstObject * src, gboolean async,
return message;
}
/**
* gst_message_new_state_dirty:
* @src: the object originating the message
*
* Create a state dirty message. This message is posted whenever an element
* changed its state asynchronously and is used internally to update the
* states of container objects.
*
* Returns: The new state dirty message.
*
* MT safe.
*/
GstMessage *
gst_message_new_state_dirty (GstObject * src)
{
GstMessage *message;
message = gst_message_new_custom (GST_MESSAGE_STATE_DIRTY, src, NULL);
return message;
}
/**
* gst_message_new_clock_provide:
* @src: The object originating the message.
......@@ -664,7 +685,6 @@ gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
/**
* gst_message_parse_state_changed:
* @message: a valid #GstMessage of type GST_MESSAGE_STATE_CHANGED
* @async: is this an async state change
* @oldstate: the previous state
* @newstate: the new (current) state
* @pending: the pending (target) state
......@@ -674,14 +694,12 @@ gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
* MT safe.
*/
void
gst_message_parse_state_changed (GstMessage * message, gboolean * async,
gst_message_parse_state_changed (GstMessage * message,
GstState * oldstate, GstState * newstate, GstState * pending)
{
g_return_if_fail (GST_IS_MESSAGE (message));
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
if (async)
gst_structure_get_boolean (message->structure, "async", async);
if (oldstate)
gst_structure_get_enum (message->structure, "old-state",
GST_TYPE_STATE, (gint *) oldstate);
......
......@@ -67,17 +67,18 @@ typedef enum
GST_MESSAGE_TAG = (1 << 4),
GST_MESSAGE_BUFFERING = (1 << 5),
GST_MESSAGE_STATE_CHANGED = (1 << 6),
GST_MESSAGE_STEP_DONE = (1 << 7),
GST_MESSAGE_CLOCK_PROVIDE = (1 << 8),
GST_MESSAGE_CLOCK_LOST = (1 << 9),
GST_MESSAGE_NEW_CLOCK = (1 << 10),
GST_MESSAGE_STRUCTURE_CHANGE = (1 << 11),
GST_MESSAGE_STREAM_STATUS = (1 << 12),
GST_MESSAGE_APPLICATION = (1 << 13),
GST_MESSAGE_ELEMENT = (1 << 14),
GST_MESSAGE_SEGMENT_START = (1 << 15),
GST_MESSAGE_SEGMENT_DONE = (1 << 16),
GST_MESSAGE_DURATION = (1 << 17),
GST_MESSAGE_STATE_DIRTY = (1 << 7),
GST_MESSAGE_STEP_DONE = (1 << 8),
GST_MESSAGE_CLOCK_PROVIDE = (1 << 9),
GST_MESSAGE_CLOCK_LOST = (1 << 10),
GST_MESSAGE_NEW_CLOCK = (1 << 11),
GST_MESSAGE_STRUCTURE_CHANGE = (1 << 12),
GST_MESSAGE_STREAM_STATUS = (1 << 13),
GST_MESSAGE_APPLICATION = (1 << 14),
GST_MESSAGE_ELEMENT = (1 << 15),
GST_MESSAGE_SEGMENT_START = (1 << 16),
GST_MESSAGE_SEGMENT_DONE = (1 << 17),
GST_MESSAGE_DURATION = (1 << 18),
GST_MESSAGE_ANY = 0xffffffff
} GstMessageType;
......@@ -190,8 +191,9 @@ GstMessage * gst_message_new_eos (GstObject * src);
GstMessage * gst_message_new_error (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_state_changed (GstObject * src, gboolean async, GstState oldstate,
GstMessage * gst_message_new_state_changed (GstObject * src, GstState oldstate,
GstState newstate, GstState pending);
GstMessage * gst_message_new_state_dirty (GstObject * src);
GstMessage * gst_message_new_clock_provide (GstObject * src, GstClock *clock, gboolean ready);
GstMessage * gst_message_new_clock_lost (GstObject * src, GstClock *clock);
GstMessage * gst_message_new_new_clock (GstObject * src, GstClock *clock);
......@@ -207,7 +209,7 @@ GstMessage * gst_message_new_custom (GstMessageType type,
void gst_message_parse_error (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_state_changed (GstMessage *message, gboolean *async, GstState *oldstate,
void gst_message_parse_state_changed (GstMessage *message, GstState *oldstate,
GstState *newstate, GstState *pending);
void gst_message_parse_clock_provide (GstMessage *message, GstClock **clock, gboolean *ready);
void gst_message_parse_clock_lost (GstMessage *message, GstClock **clock);
......
......@@ -464,11 +464,10 @@ GST_END_TEST;
{ \
GstMessage *msg; \
GstState old = 0, new = 0, pending = 0; \
gboolean async; \
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, &async, &old, &new, &pending); \
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 " \
......@@ -713,13 +712,12 @@ GST_START_TEST (test_children_state_change_order_two_sink)
{
GstMessage *msg;
GstState old = 0, new = 0, pending = 0;
gboolean async;
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, &async, &old, &new, &pending);
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),
......@@ -729,7 +727,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, &async, &old, &new, &pending);
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),
......
......@@ -121,29 +121,22 @@ GST_START_TEST (test_parsing)
/* GST_MESSAGE_STATE_CHANGED */
{
GstState oldstate, newstate, pending;
gboolean async;
async = TRUE;
oldstate = GST_STATE_PAUSED;
newstate = GST_STATE_PLAYING;
pending = GST_STATE_VOID_PENDING;
message =
gst_message_new_state_changed (NULL, async, oldstate, newstate,
pending);
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 */
async = FALSE;
oldstate = GST_STATE_READY;
newstate = GST_STATE_READY;
pending = GST_STATE_READY;
gst_message_parse_state_changed (message, &async, &oldstate, &newstate,
&pending);
fail_unless (async == TRUE);
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);
......
......@@ -84,11 +84,10 @@ GST_START_TEST (test_async_state_change_fake)
while (!done) {
GstMessage *message;
GstState old, new, pending;
gboolean async;
message = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
if (message) {
gst_message_parse_state_changed (message, &async, &old, &new, &pending);
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;
......@@ -139,10 +138,9 @@ message_received (GstBus * bus, GstMessage * message, gpointer data)
case GST_MESSAGE_STATE_CHANGED:
{
GstState old, new, pending;
gboolean async;
GST_DEBUG ("state change message received");
gst_message_parse_state_changed (message, &async, &old, &new, &pending);
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");
......
......@@ -453,9 +453,8 @@ event_loop (GstElement * pipeline, gboolean blocking)
}
case GST_MESSAGE_STATE_CHANGED:{
GstState old, new, pending;
gboolean async;
gst_message_parse_state_changed (message, &async, &old, &new, &pending);
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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment