* operations.
*/
-#include <string.h>
#include "gst_private.h"
+#include <string.h>
#include "gstformat.h"
+#include "gstenumtypes.h"
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
static GList *_gst_formats = NULL;
{GST_FORMAT_TIME, "time", "Time", 0},
{GST_FORMAT_BUFFERS, "buffers", "Buffers", 0},
{GST_FORMAT_PERCENT, "percent", "Percent", 0},
- {0, NULL, NULL, 0}
+ {GST_FORMAT_UNDEFINED, NULL, NULL, 0}
};
void
-_gst_format_initialize (void)
+_priv_gst_format_initialize (void)
{
GstFormatDefinition *standards = standard_definitions;
while (standards->nick) {
standards->quark = g_quark_from_static_string (standards->nick);
- g_hash_table_insert (_nick_to_format, standards->nick, standards);
+ g_hash_table_insert (_nick_to_format, (gpointer) standards->nick,
+ standards);
g_hash_table_insert (_format_to_nick, GINT_TO_POINTER (standards->value),
standards);
standards++;
_n_values++;
}
+ /* getting the type registers the enum */
+ g_type_class_ref (gst_format_get_type ());
g_static_mutex_unlock (&mutex);
}
*
* Get a printable name for the given format. Do not modify or free.
*
- * Returns: a reference to the static name of the format.
+ * Returns: a reference to the static name of the format or NULL if
+ * the format is unknown.
*/
const gchar *
gst_format_get_name (GstFormat format)
{
const GstFormatDefinition *def;
+ const gchar *result;
- def = gst_format_get_details (format);
+ if ((def = gst_format_get_details (format)) != NULL)
+ result = def->nick;
+ else
+ result = NULL;
- return def->nick;
+ return result;
}
/**
*
* Get the unique quark for the given format.
*
- * Returns: the quark associated with the format
+ * Returns: the quark associated with the format or 0 if the format
+ * is unknown.
*/
GQuark
gst_format_to_quark (GstFormat format)
{
const GstFormatDefinition *def;
+ GQuark result;
- def = gst_format_get_details (format);
+ if ((def = gst_format_get_details (format)) != NULL)
+ result = def->quark;
+ else
+ result = 0;
- return def->quark;
+ return result;
}
/**
GstFormatDefinition *format;
GstFormat query;
- g_return_val_if_fail (nick != NULL, 0);
- g_return_val_if_fail (description != NULL, 0);
+ g_return_val_if_fail (nick != NULL, GST_FORMAT_UNDEFINED);
+ g_return_val_if_fail (description != NULL, GST_FORMAT_UNDEFINED);
query = gst_format_get_by_nick (nick);
if (query != GST_FORMAT_UNDEFINED)
return query;
- format = g_new0 (GstFormatDefinition, 1);
- format->value = _n_values;
+ g_static_mutex_lock (&mutex);
+ format = g_slice_new (GstFormatDefinition);
+ format->value = (GstFormat) _n_values;
format->nick = g_strdup (nick);
format->description = g_strdup (description);
format->quark = g_quark_from_static_string (format->nick);
- g_static_mutex_lock (&mutex);
- g_hash_table_insert (_nick_to_format, format->nick, format);
+ g_hash_table_insert (_nick_to_format, (gpointer) format->nick, format);
g_hash_table_insert (_format_to_nick, GINT_TO_POINTER (format->value),
format);
_gst_formats = g_list_append (_gst_formats, format);
{
GstFormatDefinition *format;
- g_return_val_if_fail (nick != NULL, 0);
+ g_return_val_if_fail (nick != NULL, GST_FORMAT_UNDEFINED);
g_static_mutex_lock (&mutex);
format = g_hash_table_lookup (_nick_to_format, nick);
* Iterate all the registered formats. The format definition is read
* only.
*
- * Returns: A GstIterator of #GstFormatDefinition.
+ * Returns: (transfer full): a GstIterator of #GstFormatDefinition.
*/
GstIterator *
gst_format_iterate_definitions (void)
g_static_mutex_lock (&mutex);
/* 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);
+ g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_formats, NULL, NULL);
g_static_mutex_unlock (&mutex);
return result;