2003-01-01 03:09:39 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wim.taymans@chello.be>
|
2005-01-06 18:17:12 +00:00
|
|
|
* 2005 Wim Taymans <wim@fluendo.com>
|
2003-01-01 03:09:39 +00:00
|
|
|
*
|
|
|
|
* gstquery.c: GstQueryType registration
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-05-03 16:03:24 +00:00
|
|
|
#include "gst_private.h"
|
2004-05-07 02:36:28 +00:00
|
|
|
#include "gstquery.h"
|
2003-01-01 03:09:39 +00:00
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
2003-01-01 03:09:39 +00:00
|
|
|
static GList *_gst_queries = NULL;
|
|
|
|
static GHashTable *_nick_to_query = NULL;
|
|
|
|
static GHashTable *_query_type_to_nick = NULL;
|
2005-01-06 18:17:12 +00:00
|
|
|
static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
|
2003-01-01 03:09:39 +00:00
|
|
|
|
|
|
|
static GstQueryTypeDefinition standard_definitions[] = {
|
2004-03-13 15:27:01 +00:00
|
|
|
{GST_QUERY_TOTAL, "total", "Total length"},
|
|
|
|
{GST_QUERY_POSITION, "position", "Current Position"},
|
|
|
|
{GST_QUERY_LATENCY, "latency", "Latency"},
|
|
|
|
{GST_QUERY_JITTER, "jitter", "Jitter"},
|
|
|
|
{GST_QUERY_START, "start", "Start position of stream"},
|
|
|
|
{GST_QUERY_SEGMENT_END, "segment_end", "End position of the stream"},
|
|
|
|
{GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1"},
|
|
|
|
{0, NULL, NULL}
|
2003-01-01 03:09:39 +00:00
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
2003-01-01 03:09:39 +00:00
|
|
|
_gst_query_type_initialize (void)
|
|
|
|
{
|
|
|
|
GstQueryTypeDefinition *standards = standard_definitions;
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
g_static_mutex_lock (&mutex);
|
2003-01-01 03:09:39 +00:00
|
|
|
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);
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-01 03:09:39 +00:00
|
|
|
while (standards->nick) {
|
|
|
|
g_hash_table_insert (_nick_to_query, standards->nick, standards);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_hash_table_insert (_query_type_to_nick,
|
2004-03-15 19:27:17 +00:00
|
|
|
GINT_TO_POINTER (standards->value), standards);
|
2003-01-01 03:09:39 +00:00
|
|
|
|
|
|
|
_gst_queries = g_list_append (_gst_queries, standards);
|
|
|
|
standards++;
|
|
|
|
_n_values++;
|
|
|
|
}
|
2005-01-06 18:17:12 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
2003-01-01 03:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* allrady registered query with that nick
|
|
|
|
*
|
|
|
|
* Returns: A new GstQueryType or an already registered query
|
|
|
|
* with the same nick.
|
|
|
|
*/
|
|
|
|
GstQueryType
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_query_type_register (const gchar * nick, const gchar * description)
|
2003-01-01 03:09:39 +00:00
|
|
|
{
|
|
|
|
GstQueryTypeDefinition *query;
|
|
|
|
GstQueryType lookup;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-01 03:09:39 +00:00
|
|
|
g_return_val_if_fail (nick != NULL, 0);
|
|
|
|
g_return_val_if_fail (description != NULL, 0);
|
|
|
|
|
|
|
|
lookup = gst_query_type_get_by_nick (nick);
|
|
|
|
if (lookup != GST_QUERY_NONE)
|
|
|
|
return lookup;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-01 03:09:39 +00:00
|
|
|
query = g_new0 (GstQueryTypeDefinition, 1);
|
|
|
|
query->value = _n_values;
|
|
|
|
query->nick = g_strdup (nick);
|
|
|
|
query->description = g_strdup (description);
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
g_static_mutex_lock (&mutex);
|
2003-01-01 03:09:39 +00:00
|
|
|
g_hash_table_insert (_nick_to_query, query->nick, query);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
|
|
|
|
query);
|
2003-01-01 03:09:39 +00:00
|
|
|
_gst_queries = g_list_append (_gst_queries, query);
|
|
|
|
_n_values++;
|
2005-01-06 18:17:12 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-01 03:09:39 +00:00
|
|
|
return query->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_query_type_get_by_nick:
|
|
|
|
* @nick: The nick of the query
|
|
|
|
*
|
|
|
|
* Return the query registered with the given nick.
|
|
|
|
*
|
|
|
|
* Returns: The query with @nick or GST_QUERY_NONE
|
|
|
|
* if the query was not registered.
|
|
|
|
*/
|
|
|
|
GstQueryType
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_query_type_get_by_nick (const gchar * nick)
|
2003-01-01 03:09:39 +00:00
|
|
|
{
|
|
|
|
GstQueryTypeDefinition *query;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-01 03:09:39 +00:00
|
|
|
g_return_val_if_fail (nick != NULL, 0);
|
|
|
|
|
2005-01-06 18:17:12 +00:00
|
|
|
g_static_mutex_lock (&mutex);
|
2003-01-01 03:09:39 +00:00
|
|
|
query = g_hash_table_lookup (_nick_to_query, nick);
|
2005-01-06 18:17:12 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-01 03:09:39 +00:00
|
|
|
if (query != NULL)
|
|
|
|
return query->value;
|
|
|
|
else
|
|
|
|
return GST_QUERY_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-01-02 18:56:09 +00:00
|
|
|
* gst_query_types_contains:
|
|
|
|
* @types: The query array to search
|
|
|
|
* @type: the querytype to find
|
2003-01-01 03:09:39 +00:00
|
|
|
*
|
|
|
|
* See if the given query is inside the query array.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the query is found inside the array
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_query_types_contains (const GstQueryType * types, GstQueryType type)
|
2003-01-01 03:09:39 +00:00
|
|
|
{
|
2003-01-02 18:56:09 +00:00
|
|
|
if (!types)
|
2003-01-01 03:09:39 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2003-01-02 18:56:09 +00:00
|
|
|
while (*types) {
|
|
|
|
if (*types == type)
|
2003-01-01 03:09:39 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2003-01-02 18:56:09 +00:00
|
|
|
types++;
|
2003-01-01 03:09:39 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_query_type_get_details:
|
2003-01-02 18:56:09 +00:00
|
|
|
* @type: The query to get details of
|
2003-01-01 03:09:39 +00:00
|
|
|
*
|
|
|
|
* Get details about the given query.
|
|
|
|
*
|
|
|
|
* Returns: The #GstQueryTypeDefinition for @query or NULL on failure.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
const GstQueryTypeDefinition *
|
2003-01-02 18:56:09 +00:00
|
|
|
gst_query_type_get_details (GstQueryType type)
|
2003-01-01 03:09:39 +00:00
|
|
|
{
|
2005-01-06 18:17:12 +00:00
|
|
|
const GstQueryTypeDefinition *result;
|
|
|
|
|
|
|
|
g_static_mutex_lock (&mutex);
|
|
|
|
result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
|
|
|
|
g_static_mutex_unlock (&mutex);
|
|
|
|
|
|
|
|
return result;
|
2003-01-01 03:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-01-06 18:17:12 +00:00
|
|
|
* gst_query_type_iterate_definitions:
|
2003-01-01 03:09:39 +00:00
|
|
|
*
|
2005-01-06 18:17:12 +00:00
|
|
|
* Get an Iterator of all the registered query types. The querytype
|
|
|
|
* definition is read only.
|
2003-01-01 03:09:39 +00:00
|
|
|
*
|
2005-01-06 18:17:12 +00:00
|
|
|
* Returns: A #GstIterator of #GstQueryTypeDefinition.
|
2003-01-01 03:09:39 +00:00
|
|
|
*/
|
2005-01-06 18:17:12 +00:00
|
|
|
GstIterator *
|
|
|
|
gst_query_type_iterate_definitions (void)
|
2003-01-01 03:09:39 +00:00
|
|
|
{
|
2005-01-06 18:17:12 +00:00
|
|
|
GstIterator *result;
|
|
|
|
|
|
|
|
g_static_mutex_lock (&mutex);
|
|
|
|
result = gst_iterator_new_list (g_static_mutex_get_mutex (&mutex),
|
2005-01-26 10:56:09 +00:00
|
|
|
&_n_values, &_gst_queries, NULL, NULL, NULL);
|
2005-01-06 18:17:12 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
|
|
|
|
|
|
|
return result;
|
2003-01-01 03:09:39 +00:00
|
|
|
}
|