2002-07-28 01:54:42 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wim.taymans@chello.be>
|
2005-03-07 18:27:42 +00:00
|
|
|
* 2005 Wim Taymans <wim@fluendo.com>
|
2002-07-28 01:54:42 +00:00
|
|
|
*
|
|
|
|
* gstformat.c: GstFormat 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.
|
|
|
|
*/
|
2005-10-15 16:01:57 +00:00
|
|
|
|
2005-08-30 17:23:19 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstformat
|
|
|
|
* @short_description: Dynamically register new data formats
|
|
|
|
* @see_also: #GstPad, #GstElement
|
|
|
|
*
|
2005-10-15 16:01:57 +00:00
|
|
|
* GstFormats functions are used to register a new format to the gstreamer
|
|
|
|
* core. Formats can be used to perform seeking or conversions/query
|
|
|
|
* operations.
|
2005-08-30 17:23:19 +00:00
|
|
|
*/
|
2002-07-28 01:54:42 +00:00
|
|
|
|
2002-07-28 13:04:33 +00:00
|
|
|
|
2004-05-03 16:03:24 +00:00
|
|
|
#include "gst_private.h"
|
2006-05-04 15:20:14 +00:00
|
|
|
#include <string.h>
|
2002-07-28 01:54:42 +00:00
|
|
|
#include "gstformat.h"
|
2006-05-10 14:05:46 +00:00
|
|
|
#include "gstenumtypes.h"
|
2002-07-28 01:54:42 +00:00
|
|
|
|
2005-03-07 18:27:42 +00:00
|
|
|
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
2002-07-28 01:54:42 +00:00
|
|
|
static GList *_gst_formats = NULL;
|
2002-09-29 17:17:28 +00:00
|
|
|
static GHashTable *_nick_to_format = NULL;
|
|
|
|
static GHashTable *_format_to_nick = NULL;
|
2005-03-07 18:27:42 +00:00
|
|
|
static guint32 _n_values = 1; /* we start from 1 because 0 reserved for UNDEFINED */
|
2002-07-28 01:54:42 +00:00
|
|
|
|
|
|
|
static GstFormatDefinition standard_definitions[] = {
|
2005-11-19 18:57:00 +00:00
|
|
|
{GST_FORMAT_DEFAULT, "default", "Default format for the media type", 0},
|
|
|
|
{GST_FORMAT_BYTES, "bytes", "Bytes", 0},
|
|
|
|
{GST_FORMAT_TIME, "time", "Time", 0},
|
|
|
|
{GST_FORMAT_BUFFERS, "buffers", "Buffers", 0},
|
|
|
|
{GST_FORMAT_PERCENT, "percent", "Percent", 0},
|
|
|
|
{0, NULL, NULL, 0}
|
2002-07-28 01:54:42 +00:00
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
2002-07-28 01:54:42 +00:00
|
|
|
_gst_format_initialize (void)
|
|
|
|
{
|
|
|
|
GstFormatDefinition *standards = standard_definitions;
|
|
|
|
|
2005-03-07 18:27:42 +00:00
|
|
|
g_static_mutex_lock (&mutex);
|
2002-09-29 17:17:28 +00:00
|
|
|
if (_nick_to_format == NULL) {
|
|
|
|
_nick_to_format = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
_format_to_nick = g_hash_table_new (NULL, NULL);
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-07-28 01:54:42 +00:00
|
|
|
while (standards->nick) {
|
2005-11-19 18:57:00 +00:00
|
|
|
standards->quark = g_quark_from_static_string (standards->nick);
|
2002-09-29 17:17:28 +00:00
|
|
|
g_hash_table_insert (_nick_to_format, standards->nick, standards);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_hash_table_insert (_format_to_nick, GINT_TO_POINTER (standards->value),
|
2004-03-15 19:27:17 +00:00
|
|
|
standards);
|
2002-09-29 17:17:28 +00:00
|
|
|
|
|
|
|
_gst_formats = g_list_append (_gst_formats, standards);
|
2002-07-28 01:54:42 +00:00
|
|
|
standards++;
|
2002-07-28 02:05:45 +00:00
|
|
|
_n_values++;
|
2002-07-28 01:54:42 +00:00
|
|
|
}
|
2006-05-10 14:05:46 +00:00
|
|
|
/* getting the type registers the enum */
|
|
|
|
gst_format_get_type ();
|
2005-03-07 18:27:42 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
2002-07-28 01:54:42 +00:00
|
|
|
}
|
|
|
|
|
2005-11-20 14:50:43 +00:00
|
|
|
/**
|
|
|
|
* gst_format_get_name:
|
|
|
|
* @format: a #GstFormat
|
|
|
|
*
|
|
|
|
* Get a printable name for the given format. Do not modify or free.
|
|
|
|
*
|
2006-03-14 19:16:45 +00:00
|
|
|
* Returns: a reference to the static name of the format or NULL if
|
|
|
|
* the format is unknown.
|
2005-11-20 14:50:43 +00:00
|
|
|
*/
|
2005-11-19 18:57:00 +00:00
|
|
|
const gchar *
|
|
|
|
gst_format_get_name (GstFormat format)
|
|
|
|
{
|
|
|
|
const GstFormatDefinition *def;
|
2006-03-14 19:16:45 +00:00
|
|
|
const gchar *result;
|
2005-11-19 18:57:00 +00:00
|
|
|
|
2006-03-14 19:16:45 +00:00
|
|
|
if ((def = gst_format_get_details (format)) != NULL)
|
|
|
|
result = def->nick;
|
|
|
|
else
|
|
|
|
result = NULL;
|
2005-11-19 18:57:00 +00:00
|
|
|
|
2006-03-14 19:16:45 +00:00
|
|
|
return result;
|
2005-11-19 18:57:00 +00:00
|
|
|
}
|
|
|
|
|
2005-11-20 14:50:43 +00:00
|
|
|
/**
|
|
|
|
* gst_format_to_quark:
|
|
|
|
* @format: a #GstFormat
|
|
|
|
*
|
|
|
|
* Get the unique quark for the given format.
|
|
|
|
*
|
2006-03-14 19:16:45 +00:00
|
|
|
* Returns: the quark associated with the format or 0 if the format
|
|
|
|
* is unknown.
|
2005-11-20 14:50:43 +00:00
|
|
|
*/
|
2005-11-19 18:57:00 +00:00
|
|
|
GQuark
|
|
|
|
gst_format_to_quark (GstFormat format)
|
|
|
|
{
|
|
|
|
const GstFormatDefinition *def;
|
2006-03-14 19:16:45 +00:00
|
|
|
GQuark result;
|
2005-11-19 18:57:00 +00:00
|
|
|
|
2006-03-14 19:16:45 +00:00
|
|
|
if ((def = gst_format_get_details (format)) != NULL)
|
|
|
|
result = def->quark;
|
|
|
|
else
|
|
|
|
result = 0;
|
2005-11-19 18:57:00 +00:00
|
|
|
|
2006-03-14 19:16:45 +00:00
|
|
|
return result;
|
2005-11-19 18:57:00 +00:00
|
|
|
}
|
|
|
|
|
2002-07-28 01:54:42 +00:00
|
|
|
/**
|
|
|
|
* gst_format_register:
|
|
|
|
* @nick: The nick of the new format
|
|
|
|
* @description: The description of the new format
|
|
|
|
*
|
|
|
|
* Create a new GstFormat based on the nick or return an
|
2005-03-07 18:27:42 +00:00
|
|
|
* already registered format with that nick.
|
2002-07-28 01:54:42 +00:00
|
|
|
*
|
|
|
|
* Returns: A new GstFormat or an already registered format
|
|
|
|
* with the same nick.
|
2005-03-07 18:27:42 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
2002-07-28 01:54:42 +00:00
|
|
|
*/
|
|
|
|
GstFormat
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_format_register (const gchar * nick, const gchar * description)
|
2002-07-28 01:54:42 +00:00
|
|
|
{
|
|
|
|
GstFormatDefinition *format;
|
|
|
|
GstFormat query;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-07-28 01:54:42 +00:00
|
|
|
g_return_val_if_fail (nick != NULL, 0);
|
|
|
|
g_return_val_if_fail (description != NULL, 0);
|
|
|
|
|
|
|
|
query = gst_format_get_by_nick (nick);
|
|
|
|
if (query != GST_FORMAT_UNDEFINED)
|
|
|
|
return query;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2006-09-17 19:26:16 +00:00
|
|
|
g_static_mutex_lock (&mutex);
|
2002-07-28 01:54:42 +00:00
|
|
|
format = g_new0 (GstFormatDefinition, 1);
|
|
|
|
format->value = _n_values;
|
|
|
|
format->nick = g_strdup (nick);
|
|
|
|
format->description = g_strdup (description);
|
2005-11-19 18:57:00 +00:00
|
|
|
format->quark = g_quark_from_static_string (format->nick);
|
2002-07-28 01:54:42 +00:00
|
|
|
|
2002-09-29 17:17:28 +00:00
|
|
|
g_hash_table_insert (_nick_to_format, format->nick, format);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_hash_table_insert (_format_to_nick, GINT_TO_POINTER (format->value),
|
|
|
|
format);
|
2002-09-29 17:17:28 +00:00
|
|
|
_gst_formats = g_list_append (_gst_formats, format);
|
2002-07-28 01:54:42 +00:00
|
|
|
_n_values++;
|
2005-03-07 18:27:42 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-07-28 01:54:42 +00:00
|
|
|
return format->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_format_get_by_nick:
|
|
|
|
* @nick: The nick of the format
|
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* Return the format registered with the given nick.
|
2002-07-28 01:54:42 +00:00
|
|
|
*
|
|
|
|
* Returns: The format with @nick or GST_FORMAT_UNDEFINED
|
|
|
|
* if the format was not registered.
|
|
|
|
*/
|
|
|
|
GstFormat
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_format_get_by_nick (const gchar * nick)
|
2002-07-28 01:54:42 +00:00
|
|
|
{
|
|
|
|
GstFormatDefinition *format;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-07-28 01:54:42 +00:00
|
|
|
g_return_val_if_fail (nick != NULL, 0);
|
|
|
|
|
2005-03-07 18:27:42 +00:00
|
|
|
g_static_mutex_lock (&mutex);
|
2002-09-29 17:17:28 +00:00
|
|
|
format = g_hash_table_lookup (_nick_to_format, nick);
|
2005-03-07 18:27:42 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-09-29 17:17:28 +00:00
|
|
|
if (format != NULL)
|
|
|
|
return format->value;
|
|
|
|
else
|
|
|
|
return GST_FORMAT_UNDEFINED;
|
2002-07-28 01:54:42 +00:00
|
|
|
}
|
|
|
|
|
2002-12-22 20:21:27 +00:00
|
|
|
/**
|
|
|
|
* gst_formats_contains:
|
|
|
|
* @formats: The format array to search
|
|
|
|
* @format: the format to find
|
|
|
|
*
|
|
|
|
* See if the given format is inside the format array.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the format is found inside the array
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_formats_contains (const GstFormat * formats, GstFormat format)
|
2002-12-22 20:21:27 +00:00
|
|
|
{
|
|
|
|
if (!formats)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (*formats) {
|
|
|
|
if (*formats == format)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
formats++;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-28 01:54:42 +00:00
|
|
|
/**
|
|
|
|
* gst_format_get_details:
|
|
|
|
* @format: The format to get details of
|
|
|
|
*
|
|
|
|
* Get details about the given format.
|
|
|
|
*
|
2002-09-29 17:17:28 +00:00
|
|
|
* Returns: The #GstFormatDefinition for @format or NULL on failure.
|
2005-03-07 18:27:42 +00:00
|
|
|
*
|
|
|
|
* MT safe.
|
2002-07-28 01:54:42 +00:00
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
const GstFormatDefinition *
|
2002-09-29 17:17:28 +00:00
|
|
|
gst_format_get_details (GstFormat format)
|
2002-07-28 01:54:42 +00:00
|
|
|
{
|
2005-03-07 18:27:42 +00:00
|
|
|
const GstFormatDefinition *result;
|
|
|
|
|
|
|
|
g_static_mutex_lock (&mutex);
|
|
|
|
result = g_hash_table_lookup (_format_to_nick, GINT_TO_POINTER (format));
|
|
|
|
g_static_mutex_unlock (&mutex);
|
|
|
|
|
|
|
|
return result;
|
2002-09-29 17:17:28 +00:00
|
|
|
}
|
2002-07-28 01:54:42 +00:00
|
|
|
|
2002-09-29 17:17:28 +00:00
|
|
|
/**
|
2005-03-07 18:27:42 +00:00
|
|
|
* gst_format_iterate_definitions:
|
2002-09-29 17:17:28 +00:00
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* Iterate all the registered formats. The format definition is read
|
2005-03-07 18:27:42 +00:00
|
|
|
* only.
|
2002-09-29 17:17:28 +00:00
|
|
|
*
|
2005-03-07 18:27:42 +00:00
|
|
|
* Returns: A GstIterator of #GstFormatDefinition.
|
2002-09-29 17:17:28 +00:00
|
|
|
*/
|
2005-03-07 18:27:42 +00:00
|
|
|
GstIterator *
|
|
|
|
gst_format_iterate_definitions (void)
|
2002-09-29 17:17:28 +00:00
|
|
|
{
|
2005-03-07 18:27:42 +00:00
|
|
|
GstIterator *result;
|
|
|
|
|
|
|
|
g_static_mutex_lock (&mutex);
|
2005-10-07 00:14:45 +00:00
|
|
|
/* FIXME: register a boxed type for GstFormatDefinition */
|
|
|
|
result = gst_iterator_new_list (G_TYPE_POINTER,
|
|
|
|
g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_formats,
|
|
|
|
NULL, NULL, NULL);
|
2005-03-07 18:27:42 +00:00
|
|
|
g_static_mutex_unlock (&mutex);
|
|
|
|
|
|
|
|
return result;
|
2002-07-28 01:54:42 +00:00
|
|
|
}
|