Macro to check check mutability in set_property functions
@ocrete
Submitted by Olivier Crête Link to original bug (#644776)
Description
Now that we have GST_PARAM_MUTABLE_*, we should add a way to enforce them.
I suggest having a macro like the following and putting it as the first line of the set_property() function in the various elements after adding the mutability flags.
#define GST_PARAM_CHECK_MUTABILITY(element, pspec) G_STMT_START { \
GstState state; \
\
g_return_if_fail ((element) != NULL && GST_IS_ELEMENT (element)); \
GST_OBJECT_LOCK (element); \
state = GST_STATE (element); \
GST_OBJECT_UNLOCK (element); \
g_return_if_fail (state == GST_STATE_PLAYING || \
(pspec)->flags & GST_PARAM_MUTABLE_PLAYING); \
g_return_if_fail (state >= GST_STATE_PAUSED || \
(pspec)->flags & GST_PARAM_MUTABLE_PAUSED); \
g_return_if_fail (state >= GST_STATE_READY || \
(pspec)->flags & GST_PARAM_MUTABLE_READY); \
} G_STMT_END
We may want to have a version that doesn't release the object lock if the paramspec is mutable above NULL, since I guess for many cases, we'd want to make the change atomic, but that means being a little more clever (and maybe we want to use GST_ERROR_OBJECT() instead of g_warning .. maybe g_critical?