2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstformat.c: GstFormat 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.
27 #include "gstformat.h"
29 static GList *_gst_formats = NULL;
30 static gint _n_values = 1; /* we start from 1 because 0 reserved for UNDEFINED */
32 typedef struct _GstFormatDefinition GstFormatDefinition;
34 struct _GstFormatDefinition
41 static GstFormatDefinition standard_definitions[] = {
42 { GST_FORMAT_DEFAULT, "default", "Default" },
43 { GST_FORMAT_BYTES, "bytes", "Bytes" },
44 { GST_FORMAT_TIME, "time", "Time" },
45 { GST_FORMAT_BUFFERS, "buffers", "Buffers" },
46 { GST_FORMAT_PERCENT, "percent", "Percent" },
47 { GST_FORMAT_UNITS, "units", "Units as defined by the media type" },
52 _gst_format_initialize (void)
54 GstFormatDefinition *standards = standard_definitions;
56 while (standards->nick) {
57 _gst_formats = g_list_prepend (_gst_formats, standards);
64 * gst_format_register:
65 * @nick: The nick of the new format
66 * @description: The description of the new format
68 * Create a new GstFormat based on the nick or return an
69 * allrady registered format with that nick
71 * Returns: A new GstFormat or an already registered format
75 gst_format_register (const gchar *nick, const gchar *description)
77 GstFormatDefinition *format;
80 g_return_val_if_fail (nick != NULL, 0);
81 g_return_val_if_fail (description != NULL, 0);
83 query = gst_format_get_by_nick (nick);
84 if (query != GST_FORMAT_UNDEFINED)
87 format = g_new0 (GstFormatDefinition, 1);
88 format->value = _n_values;
89 format->nick = g_strdup (nick);
90 format->description = g_strdup (description);
92 _gst_formats = g_list_prepend (_gst_formats, format);
100 * gst_format_get_by_nick:
101 * @nick: The nick of the format
103 * Return the format registered with the given nick.
105 * Returns: The format with @nick or GST_FORMAT_UNDEFINED
106 * if the format was not registered.
109 gst_format_get_by_nick (const gchar *nick)
112 GstFormatDefinition *format;
114 g_return_val_if_fail (nick != NULL, 0);
119 format = (GstFormatDefinition *) walk->data;
121 if (!strcmp (format->nick, nick))
122 return format->value;
124 walk = g_list_next (walk);
127 return GST_FORMAT_UNDEFINED;
131 * gst_format_get_details:
132 * @format: The format to get details of
133 * @nick: The nick of the format
134 * @description: The description of the format
136 * Get details about the given format.
138 * Returns: TRUE if the format was registered, FALSE otherwise
141 gst_format_get_details (GstFormat format, const gchar **nick, const gchar **description)
144 GstFormatDefinition *walk_format;
146 g_return_val_if_fail (nick != NULL, FALSE);
147 g_return_val_if_fail (description != NULL, FALSE);
152 walk_format = (GstFormatDefinition *) walk->data;
154 if (walk_format->value == format) {
155 *nick = walk_format->nick;
156 *description = walk_format->description;
161 walk = g_list_next (walk);