source: trunk/third/gstreamer/gst/gstquery.c @ 21005

Revision 21005, 4.7 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
1/* GStreamer
2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 *                    2000 Wim Taymans <wim.taymans@chello.be>
4 *
5 * gstquery.c: GstQueryType registration
6 *
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.
11 *
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.
16 *
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.
21 */
22
23#include <string.h>
24
25#include "gst_private.h"
26#include "gstquery.h"
27
28static GList *_gst_queries = NULL;
29static GHashTable *_nick_to_query = NULL;
30static GHashTable *_query_type_to_nick = NULL;
31static gint _n_values = 1;      /* we start from 1 because 0 reserved for NONE */
32
33static GstQueryTypeDefinition standard_definitions[] = {
34  {GST_QUERY_TOTAL, "total", "Total length"},
35  {GST_QUERY_POSITION, "position", "Current Position"},
36  {GST_QUERY_LATENCY, "latency", "Latency"},
37  {GST_QUERY_JITTER, "jitter", "Jitter"},
38  {GST_QUERY_START, "start", "Start position of stream"},
39  {GST_QUERY_SEGMENT_END, "segment_end", "End position of the stream"},
40  {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1"},
41  {0, NULL, NULL}
42};
43
44void
45_gst_query_type_initialize (void)
46{
47  GstQueryTypeDefinition *standards = standard_definitions;
48
49  if (_nick_to_query == NULL) {
50    _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
51    _query_type_to_nick = g_hash_table_new (NULL, NULL);
52  }
53
54  while (standards->nick) {
55    g_hash_table_insert (_nick_to_query, standards->nick, standards);
56    g_hash_table_insert (_query_type_to_nick,
57        GINT_TO_POINTER (standards->value), standards);
58
59    _gst_queries = g_list_append (_gst_queries, standards);
60    standards++;
61    _n_values++;
62  }
63}
64
65/**
66 * gst_query_type_register:
67 * @nick: The nick of the new query
68 * @description: The description of the new query
69 *
70 * Create a new GstQueryType based on the nick or return an
71 * allrady registered query with that nick
72 *
73 * Returns: A new GstQueryType or an already registered query
74 * with the same nick.
75 */
76GstQueryType
77gst_query_type_register (const gchar * nick, const gchar * description)
78{
79  GstQueryTypeDefinition *query;
80  GstQueryType lookup;
81
82  g_return_val_if_fail (nick != NULL, 0);
83  g_return_val_if_fail (description != NULL, 0);
84
85  lookup = gst_query_type_get_by_nick (nick);
86  if (lookup != GST_QUERY_NONE)
87    return lookup;
88
89  query = g_new0 (GstQueryTypeDefinition, 1);
90  query->value = _n_values;
91  query->nick = g_strdup (nick);
92  query->description = g_strdup (description);
93
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),
96      query);
97  _gst_queries = g_list_append (_gst_queries, query);
98  _n_values++;
99
100  return query->value;
101}
102
103/**
104 * gst_query_type_get_by_nick:
105 * @nick: The nick of the query
106 *
107 * Return the query registered with the given nick.
108 *
109 * Returns: The query with @nick or GST_QUERY_NONE
110 * if the query was not registered.
111 */
112GstQueryType
113gst_query_type_get_by_nick (const gchar * nick)
114{
115  GstQueryTypeDefinition *query;
116
117  g_return_val_if_fail (nick != NULL, 0);
118
119  query = g_hash_table_lookup (_nick_to_query, nick);
120
121  if (query != NULL)
122    return query->value;
123  else
124    return GST_QUERY_NONE;
125}
126
127/**
128 * gst_query_types_contains:
129 * @types: The query array to search
130 * @type: the querytype to find
131 *
132 * See if the given query is inside the query array.
133 *
134 * Returns: TRUE if the query is found inside the array
135 */
136gboolean
137gst_query_types_contains (const GstQueryType * types, GstQueryType type)
138{
139  if (!types)
140    return FALSE;
141
142  while (*types) {
143    if (*types == type)
144      return TRUE;
145
146    types++;
147  }
148  return FALSE;
149}
150
151
152/**
153 * gst_query_type_get_details:
154 * @type: The query to get details of
155 *
156 * Get details about the given query.
157 *
158 * Returns: The #GstQueryTypeDefinition for @query or NULL on failure.
159 */
160const GstQueryTypeDefinition *
161gst_query_type_get_details (GstQueryType type)
162{
163  return g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
164}
165
166/**
167 * gst_query_type_get_definitions:
168 *
169 * Get a list of all the registered query types.
170 *
171 * Returns: A GList of #GstQueryTypeDefinition.
172 */
173const GList *
174gst_query_type_get_definitions (void)
175{
176  return _gst_queries;
177}
Note: See TracBrowser for help on using the repository browser.