/**
* SECTION:gstquery
- * @short_description: Dynamically register new query types. Provide functions
- * to create queries, and to set and parse values in them.
+ * @short_description: Provide functions to create queries, and to set and parse
+ * values in them.
* @see_also: #GstPad, #GstElement
*
- * GstQuery functions are used to register new query types to the gstreamer
- * core and use them.
* Queries can be performed on pads (gst_pad_query()) and elements
* (gst_element_query()). Please note that some queries might need a running
* pipeline to work.
* </programlisting>
* </example>
*
- * Last reviewed on 2006-02-14 (0.10.4)
+ * Last reviewed on 2012-03-29 (0.11.3)
*/
+
#include "gst_private.h"
#include "gstinfo.h"
#include "gstquery.h"
#define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
-/* GstQueryBufferingRange: internal struct for GArray */
+
typedef struct
{
- gint64 start;
- gint64 stop;
-} GstQueryBufferingRange;
-
-static GMutex mutex;
-static GList *_gst_queries = NULL;
-static GHashTable *_nick_to_query = NULL;
-static GHashTable *_query_type_to_nick = NULL;
-static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
-
-static GstQueryTypeDefinition standard_definitions[] = {
- {GST_QUERY_POSITION, "position", "Current position", 0},
- {GST_QUERY_DURATION, "duration", "Total duration", 0},
- {GST_QUERY_LATENCY, "latency", "Latency", 0},
- {GST_QUERY_JITTER, "jitter", "Jitter", 0},
- {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
- {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
- {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
- {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
- {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
- {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
- {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
- {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
- {GST_QUERY_ALLOCATION, "allocation", "Allocation properties", 0},
- {GST_QUERY_SCHEDULING, "scheduling", "Scheduling properties", 0},
- {GST_QUERY_ACCEPT_CAPS, "accept-caps", "Accept caps", 0},
- {GST_QUERY_CAPS, "caps", "Caps", 0},
- {GST_QUERY_NONE, NULL, NULL, 0}
+ const gint type;
+ const gchar *name;
+ GQuark quark;
+} GstQueryQuarks;
+
+static GstQueryQuarks query_quarks[] = {
+ {GST_QUERY_UNKNOWN, "unknown", 0},
+ {GST_QUERY_POSITION, "position", 0},
+ {GST_QUERY_DURATION, "duration", 0},
+ {GST_QUERY_LATENCY, "latency", 0},
+ {GST_QUERY_JITTER, "jitter", 0},
+ {GST_QUERY_RATE, "rate", 0},
+ {GST_QUERY_SEEKING, "seeking", 0},
+ {GST_QUERY_SEGMENT, "segment", 0},
+ {GST_QUERY_CONVERT, "convert", 0},
+ {GST_QUERY_FORMATS, "formats", 0},
+ {GST_QUERY_BUFFERING, "buffering", 0},
+ {GST_QUERY_CUSTOM, "custom", 0},
+ {GST_QUERY_URI, "uri", 0},
+ {GST_QUERY_ALLOCATION, "allocation", 0},
+ {GST_QUERY_SCHEDULING, "scheduling", 0},
+ {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
+ {GST_QUERY_CAPS, "caps", 0},
+ {GST_QUERY_DRAIN, "drain", 0},
+ {GST_QUERY_TOC, "toc", 0},
+
+ {0, NULL, 0}
};
GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
void
_priv_gst_query_initialize (void)
{
- GstQueryTypeDefinition *standards = standard_definitions;
+ gint i;
- GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
+ _gst_query_type = gst_query_get_type ();
GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
- g_mutex_lock (&mutex);
- if (_nick_to_query == NULL) {
- _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
- _query_type_to_nick = g_hash_table_new (NULL, NULL);
+ for (i = 0; query_quarks[i].name; i++) {
+ query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
}
-
- while (standards->nick) {
- standards->quark = g_quark_from_static_string (standards->nick);
- g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
- g_hash_table_insert (_query_type_to_nick,
- GINT_TO_POINTER (standards->value), standards);
-
- _gst_queries = g_list_append (_gst_queries, standards);
- standards++;
- _n_values++;
- }
- g_mutex_unlock (&mutex);
-
- _gst_query_type = gst_query_get_type ();
}
/**
* gst_query_type_get_name:
- * @query: the query type
+ * @type: the query type
*
* Get a printable name for the given query type. Do not modify or free.
*
* Returns: a reference to the static name of the query.
*/
const gchar *
-gst_query_type_get_name (GstQueryType query)
+gst_query_type_get_name (GstQueryType type)
{
- const GstQueryTypeDefinition *def;
-
- def = gst_query_type_get_details (query);
- g_return_val_if_fail (def != NULL, NULL);
+ gint i;
- return def->nick;
+ for (i = 0; query_quarks[i].name; i++) {
+ if (type == query_quarks[i].type)
+ return query_quarks[i].name;
+ }
+ return "unknown";
}
/**
* gst_query_type_to_quark:
- * @query: the query type
+ * @type: the query type
*
* Get the unique quark for the given query type.
*
* Returns: the quark associated with the query type
*/
GQuark
-gst_query_type_to_quark (GstQueryType query)
-{
- const GstQueryTypeDefinition *def;
-
- def = gst_query_type_get_details (query);
- g_return_val_if_fail (def != NULL, 0);
-
- return def->quark;
-}
-
-/**
- * gst_query_type_register:
- * @nick: The nick of the new query
- * @description: The description of the new query
- *
- * Create a new GstQueryType based on the nick or return an
- * already registered query with that nick
- *
- * Returns: A new GstQueryType or an already registered query
- * with the same nick.
- */
-GstQueryType
-gst_query_type_register (const gchar * nick, const gchar * description)
+gst_query_type_to_quark (GstQueryType type)
{
- GstQueryTypeDefinition *query;
- GstQueryType lookup;
-
- g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
- g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
-
- lookup = gst_query_type_get_by_nick (nick);
- if (lookup != GST_QUERY_NONE)
- return lookup;
-
- query = g_slice_new (GstQueryTypeDefinition);
- query->value = (GstQueryType) _n_values;
- query->nick = g_strdup (nick);
- query->description = g_strdup (description);
- query->quark = g_quark_from_static_string (query->nick);
-
- g_mutex_lock (&mutex);
- g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
- g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
- query);
- _gst_queries = g_list_append (_gst_queries, query);
- _n_values++;
- g_mutex_unlock (&mutex);
-
- return query->value;
-}
-
-/**
- * gst_query_type_get_by_nick:
- * @nick: The nick of the query
- *
- * Get the query type registered with @nick.
- *
- * Returns: The query registered with @nick or #GST_QUERY_NONE
- * if the query was not registered.
- */
-GstQueryType
-gst_query_type_get_by_nick (const gchar * nick)
-{
- GstQueryTypeDefinition *query;
-
- g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
-
- g_mutex_lock (&mutex);
- query = g_hash_table_lookup (_nick_to_query, nick);
- g_mutex_unlock (&mutex);
-
- if (query != NULL)
- return query->value;
- else
- return GST_QUERY_NONE;
-}
-
-/**
- * gst_query_types_contains:
- * @types: The query array to search
- * @type: the #GstQueryType to find
- *
- * See if the given #GstQueryType is inside the @types query types array.
- *
- * Returns: TRUE if the type is found inside the array
- */
-gboolean
-gst_query_types_contains (const GstQueryType * types, GstQueryType type)
-{
- if (!types)
- return FALSE;
-
- while (*types) {
- if (*types == type)
- return TRUE;
+ gint i;
- types++;
+ for (i = 0; query_quarks[i].name; i++) {
+ if (type == query_quarks[i].type)
+ return query_quarks[i].quark;
}
- return FALSE;
+ return 0;
}
-
/**
- * gst_query_type_get_details:
+ * gst_query_type_get_flags:
* @type: a #GstQueryType
*
- * Get details about the given #GstQueryType.
+ * Gets the #GstQueryTypeFlags associated with @type.
*
- * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
+ * Returns: a #GstQueryTypeFlags.
*/
-const GstQueryTypeDefinition *
-gst_query_type_get_details (GstQueryType type)
+GstQueryTypeFlags
+gst_query_type_get_flags (GstQueryType type)
{
- const GstQueryTypeDefinition *result;
+ GstQueryTypeFlags ret;
- g_mutex_lock (&mutex);
- result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
- g_mutex_unlock (&mutex);
+ ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
- return result;
-}
-
-/**
- * gst_query_type_iterate_definitions:
- *
- * Get a #GstIterator of all the registered query types. The definitions
- * iterated over are read only.
- *
- * Free-function: gst_iterator_free
- *
- * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
- */
-GstIterator *
-gst_query_type_iterate_definitions (void)
-{
- GstIterator *result;
-
- g_mutex_lock (&mutex);
- /* FIXME: register a boxed type for GstQueryTypeDefinition */
- result = gst_iterator_new_list (G_TYPE_POINTER,
- &mutex, &_n_values, &_gst_queries, NULL, NULL);
- g_mutex_unlock (&mutex);
-
- return result;
+ return ret;
}
static void
g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
}
-static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
-
static GstQuery *
_gst_query_copy (GstQuery * query)
{
GstQuery *copy;
+ GstStructure *s;
- copy = gst_query_new (query->type, GST_QUERY_STRUCTURE (query));
+ s = GST_QUERY_STRUCTURE (query);
+ if (s) {
+ s = gst_structure_copy (s);
+ }
+ copy = gst_query_new_custom (query->type, s);
return copy;
}
-static GstQuery *
-gst_query_new (GstQueryType type, GstStructure * structure)
+static void
+gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
{
- GstQueryImpl *query;
-
- query = g_slice_new0 (GstQueryImpl);
-
- gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
- _gst_query_type, sizeof (GstQueryImpl));
+ gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
- GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
-
GST_QUERY_TYPE (query) = type;
- query->structure = structure;
-
- if (structure)
- gst_structure_set_parent_refcount (structure,
- &query->query.mini_object.refcount);
-
- return GST_QUERY_CAST (query);
}
/**
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
- query = gst_query_new (GST_QUERY_POSITION, structure);
+ query = gst_query_new_custom (GST_QUERY_POSITION, structure);
return query;
}
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
- query = gst_query_new (GST_QUERY_DURATION, structure);
+ query = gst_query_new_custom (GST_QUERY_DURATION, structure);
return query;
}
GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
- query = gst_query_new (GST_QUERY_LATENCY, structure);
+ query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
return query;
}
* gst_query_set_latency:
* @query: a #GstQuery
* @live: if there is a live element upstream
- * @min_latency: the minimal latency of the live element
- * @max_latency: the maximal latency of the live element
+ * @min_latency: the minimal latency of the upstream elements
+ * @max_latency: the maximal latency of the upstream elements
*
* Answer a latency query by setting the requested values in the given format.
*
GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
- query = gst_query_new (GST_QUERY_CONVERT, structure);
+ query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
return query;
}
GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
- query = gst_query_new (GST_QUERY_SEGMENT, structure);
+ query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
return query;
}
GstQuery *
gst_query_new_custom (GstQueryType type, GstStructure * structure)
{
- g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
- g_return_val_if_fail (structure != NULL, NULL);
+ GstQueryImpl *query;
+
+ query = g_slice_new0 (GstQueryImpl);
+
+ GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
+
+ if (structure) {
+ /* structure must not have a parent */
+ if (!gst_structure_set_parent_refcount (structure,
+ &query->query.mini_object.refcount))
+ goto had_parent;
+ }
+ gst_query_init (query, sizeof (GstQueryImpl), type);
- return gst_query_new (type, structure);
+ GST_QUERY_STRUCTURE (query) = structure;
+
+ return GST_QUERY_CAST (query);
+
+ /* ERRORS */
+had_parent:
+ {
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
+ g_warning ("structure is already owned by another object");
+ return NULL;
+ }
}
/**
* gst_query_writable_structure:
* @query: a #GstQuery
*
- * Get the structure of a query.
+ * Get the structure of a query. This method should be called with a writable
+ * @query so that the returned structure is guranteed to be writable.
*
* Returns: (transfer none): the #GstStructure of the query. The structure is
* still owned by the query and will therefore be freed when the query
GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
- query = gst_query_new (GST_QUERY_SEEKING, structure);
+ query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
return query;
}
GstStructure *structure;
structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
- query = gst_query_new (GST_QUERY_FORMATS, structure);
+ query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
return query;
}
GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
- query = gst_query_new (GST_QUERY_BUFFERING, structure);
+ query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
return query;
}
GST_QUARK (ESTIMATED_TOTAL)));
}
+/* GstQueryBufferingRange: internal struct for GArray */
+typedef struct
+{
+ gint64 start;
+ gint64 stop;
+} GstQueryBufferingRange;
+
/**
* gst_query_add_buffering_range:
* @query: a GST_QUERY_BUFFERING type query #GstQuery
array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
sizeof (GstQueryBufferingRange), NULL);
-
- if (index >= array->len)
- return FALSE;
+ g_return_val_if_fail (index < array->len, FALSE);
range = &g_array_index (array, GstQueryBufferingRange, index);
structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
- query = gst_query_new (GST_QUERY_URI, structure);
+ query = gst_query_new_custom (GST_QUERY_URI, structure);
return query;
}
structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
- GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
- GST_QUARK (SIZE), G_TYPE_UINT, 0,
- GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
- GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
- GST_QUARK (PREFIX), G_TYPE_UINT, 0,
- GST_QUARK (ALIGN), G_TYPE_UINT, 0,
- GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
+ GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
- query = gst_query_new (GST_QUERY_ALLOCATION, structure);
+ query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
return query;
}
/**
* gst_query_parse_allocation:
* @query: a #GstQuery
- * @caps: (out callee-allocates) (allow-none): The #GstCaps
+ * @caps: (out) (transfer none) (allow-none): The #GstCaps
* @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
*
* Parse an allocation query, writing the requested caps in @caps and
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
structure = GST_QUERY_STRUCTURE (query);
+ if (caps) {
+ *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
+ GST_QUARK (CAPS)));
+ }
gst_structure_id_get (structure,
- GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
}
+typedef struct
+{
+ GstBufferPool *pool;
+ guint size;
+ guint min_buffers;
+ guint max_buffers;
+} AllocationPool;
+
+static void
+allocation_pool_free (AllocationPool * ap)
+{
+ if (ap->pool)
+ gst_object_unref (ap->pool);
+}
+
/**
- * gst_query_set_allocation_params:
+ * gst_query_add_allocation_pool:
* @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
+ * @pool: the #GstBufferPool
* @size: the size
* @min_buffers: the min buffers
* @max_buffers: the max buffers
- * @prefix: the prefix
- * @alignment: the alignment
- * @pool: the #GstBufferPool
*
- * Set the allocation parameters in @query.
+ * Set the pool parameters in @query.
*/
void
-gst_query_set_allocation_params (GstQuery * query, guint size,
- guint min_buffers, guint max_buffers, guint prefix,
- guint alignment, GstBufferPool * pool)
+gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
+ guint size, guint min_buffers, guint max_buffers)
{
+ GArray *array;
GstStructure *structure;
+ AllocationPool ap;
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
g_return_if_fail (gst_query_is_writable (query));
- g_return_if_fail (((alignment + 1) & alignment) == 0);
- g_return_if_fail (size != 0 || pool == NULL);
+ g_return_if_fail (size != 0);
structure = GST_QUERY_STRUCTURE (query);
- gst_structure_id_set (structure,
- GST_QUARK (SIZE), G_TYPE_UINT, size,
- GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
- GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
- GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
- GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
- GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
+ array = ensure_array (structure, GST_QUARK (POOL),
+ sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+
+ if ((ap.pool = pool))
+ gst_object_ref (pool);
+ ap.size = size;
+ ap.min_buffers = min_buffers;
+ ap.max_buffers = max_buffers;
+
+ g_array_append_val (array, ap);
}
+
/**
- * gst_query_parse_allocation_params:
+ * gst_query_get_n_allocation_pools:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ *
+ * Retrieve the number of values currently stored in the
+ * pool array of the query's structure.
+ *
+ * Returns: the pool array size as a #guint.
+ */
+guint
+gst_query_get_n_allocation_pools (GstQuery * query)
+{
+ GArray *array;
+ GstStructure *structure;
+
+ g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
+
+ structure = GST_QUERY_STRUCTURE (query);
+ array = ensure_array (structure, GST_QUARK (POOL),
+ sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+
+ return array->len;
+}
+
+/**
+ * gst_query_parse_nth_allocation_pool:
* @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
+ * @index: index to parse
+ * @pool: (out) (allow-none) (transfer none): the #GstBufferPool
* @size: (out) (allow-none): the size
* @min_buffers: (out) (allow-none): the min buffers
* @max_buffers: (out) (allow-none): the max buffers
- * @prefix: (out) (allow-none): the prefix
- * @alignment: (out) (allow-none): the alignment
- * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
*
- * Get the allocation parameters in @query.
+ * Get the pool parameters in @query.
*/
void
-gst_query_parse_allocation_params (GstQuery * query, guint * size,
- guint * min_buffers, guint * max_buffers, guint * prefix,
- guint * alignment, GstBufferPool ** pool)
+gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
+ GstBufferPool ** pool, guint * size, guint * min_buffers,
+ guint * max_buffers)
{
+ GArray *array;
GstStructure *structure;
+ AllocationPool *ap;
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
structure = GST_QUERY_STRUCTURE (query);
- gst_structure_id_get (structure,
- GST_QUARK (SIZE), G_TYPE_UINT, size,
- GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
- GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
- GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
- GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
- GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
+ array = ensure_array (structure, GST_QUARK (POOL),
+ sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+ g_return_if_fail (index < array->len);
+
+ ap = &g_array_index (array, AllocationPool, index);
+
+ if (pool)
+ if ((*pool = ap->pool))
+ gst_object_ref (*pool);
+ if (size)
+ *size = ap->size;
+ if (min_buffers)
+ *min_buffers = ap->min_buffers;
+ if (max_buffers)
+ *max_buffers = ap->max_buffers;
+}
+
+/**
+ * gst_query_set_nth_allocation_pool:
+ * @index: index to modify
+ * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
+ * @pool: the #GstBufferPool
+ * @size: the size
+ * @min_buffers: the min buffers
+ * @max_buffers: the max buffers
+ *
+ * Set the pool parameters in @query.
+ */
+void
+gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
+ GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
+{
+ GArray *array;
+ GstStructure *structure;
+ AllocationPool *oldap, ap;
+
+ g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+
+ structure = GST_QUERY_STRUCTURE (query);
+ array = ensure_array (structure, GST_QUARK (POOL),
+ sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+ g_return_if_fail (index < array->len);
+
+ oldap = &g_array_index (array, AllocationPool, index);
+ allocation_pool_free (oldap);
+
+ if ((ap.pool = pool))
+ gst_object_ref (pool);
+ ap.size = size;
+ ap.min_buffers = min_buffers;
+ ap.max_buffers = max_buffers;
+ g_array_index (array, AllocationPool, index) = ap;
}
/**
* Add @api as aone of the supported metadata API to @query.
*/
void
-gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
+gst_query_add_allocation_meta (GstQuery * query, GType api)
{
GArray *array;
GstStructure *structure;
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
- g_return_if_fail (api != NULL);
+ g_return_if_fail (api != 0);
g_return_if_fail (gst_query_is_writable (query));
structure = GST_QUERY_STRUCTURE (query);
- array =
- ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
+ array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
- api = g_intern_string (api);
g_array_append_val (array, api);
}
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
structure = GST_QUERY_STRUCTURE (query);
- array =
- ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
+ array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
return array->len;
}
* Parse an available query and get the metadata API
* at @index of the metadata API array.
*
- * Returns: a #gchar of the metadata API at @index.
+ * Returns: a #GType of the metadata API at @index.
*/
-const gchar *
+GType
gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
{
GArray *array;
- const gchar *ret = NULL;
GstStructure *structure;
- g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
+ g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
structure = GST_QUERY_STRUCTURE (query);
- array =
- ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
+ array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
- if (index < array->len)
- ret = g_array_index (array, const gchar *, index);
+ g_return_val_if_fail (index < array->len, 0);
- return ret;
+ return g_array_index (array, GType, index);
+}
+
+/**
+ * gst_query_remove_nth_allocation_meta:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ * @index: position in the metadata API array to remove
+ *
+ * Remove the metadata API at @index of the metadata API array.
+ */
+void
+gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
+{
+ GArray *array;
+ GstStructure *structure;
+
+ g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+ g_return_if_fail (gst_query_is_writable (query));
+
+ structure = GST_QUERY_STRUCTURE (query);
+ array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
+ g_return_if_fail (index < array->len);
+
+ g_array_remove_index (array, index);
}
/**
* Returns: TRUE when @api is in the list of metadata.
*/
gboolean
-gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
+gst_query_has_allocation_meta (GstQuery * query, GType api)
{
GArray *array;
GstStructure *structure;
guint i, len;
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
- g_return_val_if_fail (api != NULL, FALSE);
+ g_return_val_if_fail (api != 0, FALSE);
structure = GST_QUERY_STRUCTURE (query);
- array =
- ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
+ array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
len = array->len;
for (i = 0; i < len; i++) {
- if (strcmp (api, g_array_index (array, const gchar *, i)) == 0)
+ if (g_array_index (array, GType, i) == api)
return TRUE;
}
return FALSE;
}
+typedef struct
+{
+ GstAllocator *allocator;
+ GstAllocationParams params;
+} AllocationParam;
+
+static void
+allocation_param_free (AllocationParam * ap)
+{
+ if (ap->allocator)
+ gst_allocator_unref (ap->allocator);
+}
+
/**
- * gst_query_add_allocation_memory:
+ * gst_query_add_allocation_param:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery
* @allocator: the memory allocator
+ * @params: a #GstAllocationParams
*
- * Add @allocator as a supported memory allocator.
+ * Add @allocator and its @params as a supported memory allocator.
*/
void
-gst_query_add_allocation_memory (GstQuery * query, GstAllocator * allocator)
+gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
+ const GstAllocationParams * params)
{
GArray *array;
GstStructure *structure;
+ AllocationParam ap;
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
g_return_if_fail (gst_query_is_writable (query));
- g_return_if_fail (allocator != NULL);
+ g_return_if_fail (allocator != NULL || params != NULL);
structure = GST_QUERY_STRUCTURE (query);
- array =
- ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
- (GDestroyNotify) gst_allocator_unref);
+ array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+ sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
- g_array_append_val (array, allocator);
+ if ((ap.allocator = allocator))
+ gst_allocator_ref (allocator);
+ if (params)
+ ap.params = *params;
+ else
+ gst_allocation_params_init (&ap.params);
+
+ g_array_append_val (array, ap);
}
/**
- * gst_query_get_n_allocation_memories:
+ * gst_query_get_n_allocation_params:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery
*
* Retrieve the number of values currently stored in the
- * allocator array of the query's structure.
+ * allocator params array of the query's structure.
*
* If no memory allocator is specified, the downstream element can handle
* the default memory allocator.
* Returns: the allocator array size as a #guint.
*/
guint
-gst_query_get_n_allocation_memories (GstQuery * query)
+gst_query_get_n_allocation_params (GstQuery * query)
{
GArray *array;
GstStructure *structure;
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
structure = GST_QUERY_STRUCTURE (query);
- array =
- ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
- (GDestroyNotify) gst_allocator_unref);
+ array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+ sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
return array->len;
}
/**
- * gst_query_parse_nth_allocation_memory:
+ * gst_query_parse_nth_allocation_param:
* @query: a GST_QUERY_ALLOCATION type query #GstQuery
* @index: position in the allocator array to read
+ * @allocator: (transfer none): variable to hold the result
+ * @params: parameters for the allocator
*
- * Parse an available query and get the alloctor
+ * Parse an available query and get the alloctor and its params
* at @index of the allocator array.
+ */
+void
+gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
+ GstAllocator ** allocator, GstAllocationParams * params)
+{
+ GArray *array;
+ GstStructure *structure;
+ AllocationParam *ap;
+
+ g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+
+ structure = GST_QUERY_STRUCTURE (query);
+ array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+ sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
+ g_return_if_fail (index < array->len);
+
+ ap = &g_array_index (array, AllocationParam, index);
+
+ if (allocator)
+ if ((*allocator = ap->allocator))
+ gst_allocator_ref (*allocator);
+ if (params)
+ *params = ap->params;
+}
+
+/**
+ * gst_query_set_nth_allocation_param:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ * @index: position in the allocator array to set
+ * @allocator: (transfer full): new allocator to set
+ * @params: parameters for the allocator
*
- * Returns: (transfer none): the allocator at @index. The allocator remains
- * valid for as long as @query is valid.
+ * Parse an available query and get the alloctor and its params
+ * at @index of the allocator array.
*/
-GstAllocator *
-gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
+void
+gst_query_set_nth_allocation_param (GstQuery * query, guint index,
+ GstAllocator * allocator, const GstAllocationParams * params)
{
GArray *array;
- GstAllocator *ret = NULL;
GstStructure *structure;
+ AllocationParam *old, ap;
- g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
+ g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
structure = GST_QUERY_STRUCTURE (query);
- array =
- ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
- (GDestroyNotify) gst_allocator_unref);
+ array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+ sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
+ g_return_if_fail (index < array->len);
- if (index < array->len)
- ret = g_array_index (array, GstAllocator *, index);
+ old = &g_array_index (array, AllocationParam, index);
+ allocation_param_free (old);
- return ret;
+ if ((ap.allocator = allocator))
+ gst_allocator_ref (allocator);
+ if (params)
+ ap.params = *params;
+ else
+ gst_allocation_params_init (&ap.params);
+
+ g_array_index (array, AllocationParam, index) = ap;
}
/**
GST_QUARK (MINSIZE), G_TYPE_INT, 1,
GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
- query = gst_query_new (GST_QUERY_SCHEDULING, structure);
+ query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
return query;
}
GstPadMode
gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
{
- GstPadMode ret = GST_PAD_MODE_NONE;
GstStructure *structure;
GArray *array;
- g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, ret);
+ g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
+ GST_PAD_MODE_NONE);
structure = GST_QUERY_STRUCTURE (query);
array =
ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
+ g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
- if (index < array->len)
- ret = g_array_index (array, GstPadMode, index);
-
- return ret;
+ return g_array_index (array, GstPadMode, index);
}
/**
/**
* gst_query_new_accept_caps:
- * @caps: a #GstCaps
+ * @caps: a fixed #GstCaps
*
* Constructs a new query object for querying if @caps are accepted.
*
GstQuery *query;
GstStructure *structure;
+ g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
+
structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
- query = gst_query_new (GST_QUERY_ACCEPT_CAPS, structure);
+ query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
return query;
}
*
* Constructs a new query object for querying the caps.
*
- * The CAPS query should return the* allowable caps for a pad in the context
+ * The CAPS query should return the allowable caps for a pad in the context
* of the element's state, its link to other elements, and the devices or files
* it has opened. These caps must be a subset of the pad template caps. In the
* NULL state with no links, the CAPS query should ideally return the same caps
* the CAPS query should return the most specific caps it reasonably can, since this
* helps with autoplugging.
*
+ * The @filter is used to restrict the result caps, only the caps matching
+ * @filter should be returned from the CAPS query. Specifying a filter might
+ * greatly reduce the amount of processing an element needs to do.
+ *
* Free-function: gst_query_unref
*
* Returns: (transfer full): a new #GstQuery
structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
- query = gst_query_new (GST_QUERY_CAPS, structure);
+ query = gst_query_new_custom (GST_QUERY_CAPS, structure);
return query;
}
gst_query_set_caps_result (query, res);
gst_caps_unref (res);
}
+
+/**
+ * gst_query_new_drain:
+ *
+ * Constructs a new query object for querying the drain state.
+ *
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
+ */
+GstQuery *
+gst_query_new_drain (void)
+{
+ GstQuery *query;
+ GstStructure *structure;
+
+ structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
+ query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
+
+ return query;
+}
+
+/**
+ * gst_query_new_toc:
+ *
+ * Constructs a new query TOC query object. Use gst_query_unref()
+ * when done with it. A TOC query is used to query the full TOC with
+ * the UID marker for TOC extending (to insert some new entries).
+ *
+ * Returns: A #GstQuery.
+ */
+GstQuery *
+gst_query_new_toc (void)
+{
+ GstQuery *query;
+ GstStructure *structure;
+
+ structure = gst_structure_new_id_empty (GST_QUARK (QUERY_TOC));
+ query = gst_query_new_custom (GST_QUERY_TOC, structure);
+
+ return query;
+}
+
+/**
+ * gst_query_set_toc:
+ * @query: a #GstQuery with query type GST_QUERY_TOC.
+ * @toc: the GstToc to set.
+ * @extend_uid: UID which can be used for TOC extending (may be NULL),
+ * 0 means root TOC level.
+ *
+ * Answer a TOC query by setting appropriate #GstToc structure.
+ */
+void
+gst_query_set_toc (GstQuery * query, GstToc * toc, const gchar * extend_uid)
+{
+ GstStructure *structure;
+ GstStructure *old_structure;
+
+ g_return_if_fail (query != NULL);
+ g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_TOC);
+ g_return_if_fail (toc != NULL);
+
+ structure = __gst_toc_to_structure (toc);
+
+ g_return_if_fail (structure != NULL);
+
+ /* that shouldn't be happen in normal usage */
+ old_structure = GST_QUERY_STRUCTURE (query);
+ if (old_structure) {
+ gst_structure_set_parent_refcount (old_structure, NULL);
+ gst_structure_free (old_structure);
+ }
+
+ if (extend_uid != NULL)
+ __gst_toc_structure_set_extend_uid (structure, extend_uid);
+
+ gst_structure_set_parent_refcount (structure, &(query->mini_object.refcount));
+ GST_QUERY_STRUCTURE (query) = structure;
+}
+
+/**
+ * gst_query_parse_toc:
+ * @query: a #GstQuery.
+ * @toc: (out): the storage for the received TOC (may be NULL).
+ * @extend_uid: (out): the storage for the received extend UID marker (may be NULL),
+ * 0 means root TOC level.
+ *
+ * Parse a TOC query, writing the TOC into @toc as a newly
+ * allocated #GstToc and extend UID into @extend_uid, if the respective parameters
+ * are non-NULL. Use @extend_uid value to insert new entries into the TOC (@extend_uid will
+ * act as root entry for newly inserted entries).
+ * Free @toc with gst_toc_free() and @extend_uid with g_free() after usage.
+ */
+void
+gst_query_parse_toc (GstQuery * query, GstToc ** toc, gchar ** extend_uid)
+{
+ const GstStructure *structure;
+
+ g_return_if_fail (query != NULL);
+ g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_TOC);
+
+ structure = gst_query_get_structure (query);
+
+ g_return_if_fail (structure != NULL);
+
+ if (toc != NULL)
+ *toc = __gst_toc_from_structure (structure);
+
+ if (extend_uid != NULL)
+ *extend_uid = __gst_toc_structure_get_extend_uid (structure);
+}