2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstquery.c: GstQueryType registration
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
29 static GList *_gst_queries = NULL;
30 static GHashTable *_nick_to_query = NULL;
31 static GHashTable *_query_type_to_nick = NULL;
32 static gint _n_values = 1; /* we start from 1 because 0 reserved for NONE */
34 static GstQueryTypeDefinition standard_definitions[] = {
35 { GST_QUERY_TOTAL, "total", "Total length" },
36 { GST_QUERY_POSITION, "position", "Current Position" },
37 { GST_QUERY_LATENCY, "latency", "Latency" },
38 { GST_QUERY_JITTER, "jitter", "Jitter" },
39 { GST_QUERY_START, "start", "Start position of stream" },
40 { GST_QUERY_SEGMENT_END, "segment_end", "End position of the stream" },
41 { GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1" },
46 _gst_query_type_initialize (void)
48 GstQueryTypeDefinition *standards = standard_definitions;
50 if (_nick_to_query == NULL) {
51 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
52 _query_type_to_nick = g_hash_table_new (NULL, NULL);
55 while (standards->nick) {
56 g_hash_table_insert (_nick_to_query, standards->nick, standards);
57 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (standards->value), standards);
59 _gst_queries = g_list_append (_gst_queries, standards);
66 * gst_query_type_register:
67 * @nick: The nick of the new query
68 * @description: The description of the new query
70 * Create a new GstQueryType based on the nick or return an
71 * allrady registered query with that nick
73 * Returns: A new GstQueryType or an already registered query
77 gst_query_type_register (const gchar *nick, const gchar *description)
79 GstQueryTypeDefinition *query;
82 g_return_val_if_fail (nick != NULL, 0);
83 g_return_val_if_fail (description != NULL, 0);
85 lookup = gst_query_type_get_by_nick (nick);
86 if (lookup != GST_QUERY_NONE)
89 query = g_new0 (GstQueryTypeDefinition, 1);
90 query->value = _n_values;
91 query->nick = g_strdup (nick);
92 query->description = g_strdup (description);
94 g_hash_table_insert (_nick_to_query, query->nick, query);
95 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value), query);
96 _gst_queries = g_list_append (_gst_queries, query);
103 * gst_query_type_get_by_nick:
104 * @nick: The nick of the query
106 * Return the query registered with the given nick.
108 * Returns: The query with @nick or GST_QUERY_NONE
109 * if the query was not registered.
112 gst_query_type_get_by_nick (const gchar *nick)
114 GstQueryTypeDefinition *query;
116 g_return_val_if_fail (nick != NULL, 0);
118 query = g_hash_table_lookup (_nick_to_query, nick);
123 return GST_QUERY_NONE;
127 * gst_query_types_contains:
128 * @types: The query array to search
129 * @type: the querytype to find
131 * See if the given query is inside the query array.
133 * Returns: TRUE if the query is found inside the array
136 gst_query_types_contains (const GstQueryType *types, GstQueryType type)
152 * gst_query_type_get_details:
153 * @type: The query to get details of
155 * Get details about the given query.
157 * Returns: The #GstQueryTypeDefinition for @query or NULL on failure.
159 const GstQueryTypeDefinition*
160 gst_query_type_get_details (GstQueryType type)
162 return g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
166 * gst_query_type_get_definitions:
168 * Get a list of all the registered query types.
170 * Returns: A GList of #GstQueryTypeDefinition.
173 gst_query_type_get_definitions (void)