mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 04:22:27 +00:00
message/query: Simplify CONTEXT messages/queries to only contain a single type
This commit is contained in:
parent
2ae9809ae8
commit
51982d158a
6 changed files with 39 additions and 216 deletions
113
gst/gstmessage.c
113
gst/gstmessage.c
|
@ -2226,6 +2226,7 @@ gst_message_parse_group_id (GstMessage * message, guint * group_id)
|
|||
/**
|
||||
* gst_message_new_need_context:
|
||||
* @src: (transfer none): The object originating the message.
|
||||
* @context_type: The context type that is needed
|
||||
*
|
||||
* This message is posted when an element needs a specific #GstContext.
|
||||
*
|
||||
|
@ -2236,133 +2237,47 @@ gst_message_parse_group_id (GstMessage * message, guint * group_id)
|
|||
* Since: 1.2
|
||||
*/
|
||||
GstMessage *
|
||||
gst_message_new_need_context (GstObject * src)
|
||||
gst_message_new_need_context (GstObject * src, const gchar * context_type)
|
||||
{
|
||||
GstMessage *message;
|
||||
GstStructure *structure;
|
||||
|
||||
structure = gst_structure_new_id_empty (GST_QUARK (MESSAGE_NEED_CONTEXT));
|
||||
g_return_val_if_fail (context_type != NULL, NULL);
|
||||
|
||||
structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEED_CONTEXT),
|
||||
GST_QUARK (CONTEXT_TYPE), context_type, NULL);
|
||||
message = gst_message_new_custom (GST_MESSAGE_NEED_CONTEXT, src, structure);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
static GArray *
|
||||
ensure_array (GstStructure * s, GQuark quark, gsize element_size,
|
||||
GDestroyNotify clear_func)
|
||||
{
|
||||
GArray *array;
|
||||
const GValue *value;
|
||||
|
||||
value = gst_structure_id_get_value (s, quark);
|
||||
if (value) {
|
||||
array = (GArray *) g_value_get_boxed (value);
|
||||
} else {
|
||||
GValue new_array_val = { 0, };
|
||||
|
||||
array = g_array_new (FALSE, TRUE, element_size);
|
||||
if (clear_func)
|
||||
g_array_set_clear_func (array, clear_func);
|
||||
|
||||
g_value_init (&new_array_val, G_TYPE_ARRAY);
|
||||
g_value_take_boxed (&new_array_val, array);
|
||||
|
||||
gst_structure_id_take_value (s, quark, &new_array_val);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static void
|
||||
free_array_string (gpointer ptr)
|
||||
{
|
||||
gchar *str = *(gchar **) ptr;
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_message_add_context_type:
|
||||
* @message: a GST_MESSAGE_NEED_CONTEXT type message
|
||||
* @context_type: a context type
|
||||
*
|
||||
* Add a new context type to @message.
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
void
|
||||
gst_message_add_context_type (GstMessage * message, const gchar * context_type)
|
||||
{
|
||||
GstStructure *structure;
|
||||
GArray *array;
|
||||
gchar *copy;
|
||||
|
||||
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT);
|
||||
g_return_if_fail (gst_message_is_writable (message));
|
||||
|
||||
structure = GST_MESSAGE_STRUCTURE (message);
|
||||
array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
|
||||
sizeof (gchar *), free_array_string);
|
||||
|
||||
copy = g_strdup (context_type);
|
||||
g_array_append_val (array, copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_message_get_n_context_types:
|
||||
* @message: a GST_MESSAGE_NEED_CONTEXT type message
|
||||
*
|
||||
* Retrieve the number of values currently stored in the
|
||||
* context-types array of the message's structure.
|
||||
*
|
||||
* Returns: the context-types array size as a #guint.
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
guint
|
||||
gst_message_get_n_context_types (GstMessage * message)
|
||||
{
|
||||
GstStructure *structure;
|
||||
GArray *array;
|
||||
|
||||
g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT,
|
||||
0);
|
||||
|
||||
structure = GST_MESSAGE_STRUCTURE (message);
|
||||
array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
|
||||
sizeof (gchar *), free_array_string);
|
||||
|
||||
return array->len;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_message_parse_nth_context_type:
|
||||
* gst_message_parse_context_type:
|
||||
* @message: a GST_MESSAGE_NEED_CONTEXT type message
|
||||
* @context_type: (out) (allow-none): the context type, or NULL
|
||||
*
|
||||
* Parse a context type from an existing GST_MESSAGE_NEED_CONTEXT message
|
||||
* from @index.
|
||||
* Parse a context type from an existing GST_MESSAGE_NEED_CONTEXT message.
|
||||
*
|
||||
* Returns: a #gboolean indicating if the parsing succeeded.
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
gboolean
|
||||
gst_message_parse_nth_context_type (GstMessage * message, guint index,
|
||||
gst_message_parse_context_type (GstMessage * message,
|
||||
const gchar ** context_type)
|
||||
{
|
||||
GstStructure *structure;
|
||||
GArray *array;
|
||||
const GValue *value;
|
||||
|
||||
g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT,
|
||||
FALSE);
|
||||
|
||||
structure = GST_MESSAGE_STRUCTURE (message);
|
||||
|
||||
array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
|
||||
sizeof (gchar *), free_array_string);
|
||||
g_return_val_if_fail (index < array->len, FALSE);
|
||||
|
||||
if (context_type)
|
||||
*context_type = g_array_index (array, gchar *, index);
|
||||
if (context_type) {
|
||||
value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
|
||||
*context_type = g_value_get_string (value);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -565,10 +565,8 @@ void gst_message_set_group_id (GstMessage *message, guint grou
|
|||
gboolean gst_message_parse_group_id (GstMessage *message, guint *group_id);
|
||||
|
||||
/* NEED_CONTEXT */
|
||||
GstMessage * gst_message_new_need_context (GstObject * src) G_GNUC_MALLOC;
|
||||
void gst_message_add_context_type (GstMessage * message, const gchar * context_type);
|
||||
guint gst_message_get_n_context_types (GstMessage * message);
|
||||
gboolean gst_message_parse_nth_context_type (GstMessage * message, guint i, const gchar ** context_type);
|
||||
GstMessage * gst_message_new_need_context (GstObject * src, const gchar * context_type) G_GNUC_MALLOC;
|
||||
gboolean gst_message_parse_context_type (GstMessage * message, const gchar ** context_type);
|
||||
|
||||
/* HAVE_CONTEXT */
|
||||
GstMessage * gst_message_new_have_context (GstObject * src, GstContext *context) G_GNUC_MALLOC;
|
||||
|
|
|
@ -67,7 +67,7 @@ static const gchar *_quark_strings[] = {
|
|||
"GstMessageToc", "GstEventTocGlobal", "GstEventTocCurrent",
|
||||
"GstEventSegmentDone",
|
||||
"GstEventStreamStart", "stream-id", "GstQueryContext",
|
||||
"GstMessageNeedContext", "GstMessageHaveContext", "context", "context-types",
|
||||
"GstMessageNeedContext", "GstMessageHaveContext", "context", "context-type",
|
||||
"GstMessageStreamStart", "group-id", "uri-redirection"
|
||||
};
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ typedef enum _GstQuarkId
|
|||
GST_QUARK_MESSAGE_NEED_CONTEXT = 163,
|
||||
GST_QUARK_MESSAGE_HAVE_CONTEXT = 164,
|
||||
GST_QUARK_CONTEXT = 165,
|
||||
GST_QUARK_CONTEXT_TYPES = 166,
|
||||
GST_QUARK_CONTEXT_TYPE = 166,
|
||||
GST_QUARK_MESSAGE_STREAM_START = 167,
|
||||
GST_QUARK_GROUP_ID = 168,
|
||||
GST_QUARK_URI_REDIRECTION = 169,
|
||||
|
|
125
gst/gstquery.c
125
gst/gstquery.c
|
@ -2489,6 +2489,7 @@ gst_query_new_drain (void)
|
|||
|
||||
/**
|
||||
* gst_query_new_context:
|
||||
* @context_type: Context type to query
|
||||
*
|
||||
* Constructs a new query object for querying the pipeline-local context.
|
||||
*
|
||||
|
@ -2499,12 +2500,15 @@ gst_query_new_drain (void)
|
|||
* Since: 1.2
|
||||
*/
|
||||
GstQuery *
|
||||
gst_query_new_context (void)
|
||||
gst_query_new_context (const gchar * context_type)
|
||||
{
|
||||
GstQuery *query;
|
||||
GstStructure *structure;
|
||||
|
||||
structure = gst_structure_new_id_empty (GST_QUARK (QUERY_CONTEXT));
|
||||
g_return_val_if_fail (context_type != NULL, NULL);
|
||||
|
||||
structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
|
||||
GST_QUARK (CONTEXT_TYPE), context_type, NULL);
|
||||
query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
|
||||
|
||||
return query;
|
||||
|
@ -2523,9 +2527,14 @@ void
|
|||
gst_query_set_context (GstQuery * query, GstContext * context)
|
||||
{
|
||||
GstStructure *s;
|
||||
const gchar *context_type;
|
||||
|
||||
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
|
||||
|
||||
gst_query_parse_context_type (query, &context_type);
|
||||
g_return_if_fail (strcmp (gst_context_get_context_type (context),
|
||||
context_type) == 0);
|
||||
|
||||
s = GST_QUERY_STRUCTURE (query);
|
||||
|
||||
gst_structure_id_set (s,
|
||||
|
@ -2559,127 +2568,31 @@ gst_query_parse_context (GstQuery * query, GstContext ** context)
|
|||
*context = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
free_array_string (gpointer ptr)
|
||||
{
|
||||
gchar *str = *(gchar **) ptr;
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_add_context_type:
|
||||
* @query: a GST_QUERY_CONTEXT type query
|
||||
* @context_type: a context type
|
||||
*
|
||||
* Add a new context type to @query.
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
void
|
||||
gst_query_add_context_type (GstQuery * query, const gchar * context_type)
|
||||
{
|
||||
GstStructure *structure;
|
||||
GArray *array;
|
||||
gchar *copy;
|
||||
|
||||
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
|
||||
g_return_if_fail (gst_query_is_writable (query));
|
||||
|
||||
structure = GST_QUERY_STRUCTURE (query);
|
||||
array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
|
||||
sizeof (gchar *), free_array_string);
|
||||
|
||||
copy = g_strdup (context_type);
|
||||
g_array_append_val (array, copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_get_n_context_types:
|
||||
* @query: a GST_QUERY_CONTEXT type query
|
||||
*
|
||||
* Retrieve the number of values currently stored in the
|
||||
* context-types array of the query's structure.
|
||||
*
|
||||
* Returns: the context-types array size as a #guint.
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
guint
|
||||
gst_query_get_n_context_types (GstQuery * query)
|
||||
{
|
||||
GstStructure *structure;
|
||||
GArray *array;
|
||||
|
||||
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, 0);
|
||||
|
||||
structure = GST_QUERY_STRUCTURE (query);
|
||||
array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
|
||||
sizeof (gchar *), free_array_string);
|
||||
|
||||
return array->len;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_parse_nth_context_type:
|
||||
* gst_query_parse_context_type:
|
||||
* @query: a GST_QUERY_CONTEXT type query
|
||||
* @context_type: (out) (transfer none) (allow-none): the context type, or NULL
|
||||
*
|
||||
* Parse a context type from an existing GST_QUERY_CONTEXT query
|
||||
* from @index.
|
||||
* Parse a context type from an existing GST_QUERY_CONTEXT query.
|
||||
*
|
||||
* Returns: a #gboolean indicating if the parsing succeeded.
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
gboolean
|
||||
gst_query_parse_nth_context_type (GstQuery * query, guint index,
|
||||
const gchar ** context_type)
|
||||
gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
|
||||
{
|
||||
GstStructure *structure;
|
||||
GArray *array;
|
||||
const GValue *value;
|
||||
|
||||
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
|
||||
|
||||
structure = GST_QUERY_STRUCTURE (query);
|
||||
|
||||
array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
|
||||
sizeof (gchar *), free_array_string);
|
||||
g_return_val_if_fail (index < array->len, FALSE);
|
||||
|
||||
if (context_type)
|
||||
*context_type = g_array_index (array, gchar *, index);
|
||||
if (context_type) {
|
||||
value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
|
||||
*context_type = g_value_get_string (value);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_has_context_type:
|
||||
* @query: a GST_QUERY_CONTEXT type query
|
||||
* @context_type: the context type
|
||||
*
|
||||
* Check if @query is asking for @context_type.
|
||||
*
|
||||
* Returns: %TRUE if @context_type is requested.
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
gboolean
|
||||
gst_query_has_context_type (GstQuery * query, const gchar * context_type)
|
||||
{
|
||||
guint i, n;
|
||||
|
||||
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
|
||||
g_return_val_if_fail (context_type != NULL, FALSE);
|
||||
|
||||
n = gst_query_get_n_context_types (query);
|
||||
for (i = 0; i < n; i++) {
|
||||
const gchar *tmp;
|
||||
|
||||
if (gst_query_parse_nth_context_type (query, i, &tmp) &&
|
||||
strcmp (tmp, context_type) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -486,11 +486,8 @@ void gst_query_parse_caps_result (GstQuery *query, GstCaps **c
|
|||
GstQuery * gst_query_new_drain (void) G_GNUC_MALLOC;
|
||||
|
||||
/* context query */
|
||||
GstQuery * gst_query_new_context (void) G_GNUC_MALLOC;
|
||||
void gst_query_add_context_type (GstQuery * query, const gchar * context_type);
|
||||
guint gst_query_get_n_context_types (GstQuery * query);
|
||||
gboolean gst_query_parse_nth_context_type (GstQuery * query, guint i, const gchar ** context_type);
|
||||
gboolean gst_query_has_context_type (GstQuery * query, const gchar * context_type);
|
||||
GstQuery * gst_query_new_context (const gchar * context_type) G_GNUC_MALLOC;
|
||||
gboolean gst_query_parse_context_type (GstQuery * query, const gchar ** context_type);
|
||||
void gst_query_set_context (GstQuery *query, GstContext *context);
|
||||
void gst_query_parse_context (GstQuery *query, GstContext **context);
|
||||
|
||||
|
|
Loading…
Reference in a new issue