From c8d3e2e9a964f344fe18f6a49c9b0deb7070d3d5 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 28 Jul 2002 01:54:42 +0000 Subject: [PATCH] Make the formats dynamic so that plugins can register new seek/query formats Original commit message from CVS: Make the formats dynamic so that plugins can register new seek/query formats --- gst/Makefile.am | 1 + gst/gst.c | 1 + gst/gstformat.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gst/gstformat.h | 27 +++++++--- 4 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 gst/gstformat.c diff --git a/gst/Makefile.am b/gst/Makefile.am index 8a15a23..0cb9666 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -64,6 +64,7 @@ libgstreamer_la_SOURCES = \ gstelementfactory.c \ gstevent.c \ gstextratypes.c \ + gstformat.c \ gstinfo.c \ gstmemchunk.c \ gstpad.c \ diff --git a/gst/gst.c b/gst/gst.c index 02de29d..5c6e182 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -351,6 +351,7 @@ init_post (void) GST_INFO (GST_CAT_GST_INIT, "Initializing GStreamer Core Library version %s %s", GST_VERSION, _gst_use_threads?"":"(no threads)"); + _gst_format_initialize (); gst_object_get_type (); gst_pad_get_type (); gst_real_pad_get_type (); diff --git a/gst/gstformat.c b/gst/gstformat.c new file mode 100644 index 0000000..9963759 --- /dev/null +++ b/gst/gstformat.c @@ -0,0 +1,161 @@ +/* GStreamer + * Copyright (C) 1999,2000 Erik Walthinsen + * 2000 Wim Taymans + * + * 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. + */ + +#include "gstlog.h" + +#include "gstformat.h" + +static GList *_gst_formats = NULL; +static gint _n_values = 1; /* we start from 1 because 0 reserved for UNDEFINED */ + +typedef struct _GstFormatDefinition GstFormatDefinition; + +struct _GstFormatDefinition +{ + GstFormat value; + gchar *nick; + gchar *description; +}; + +static GstFormatDefinition standard_definitions[] = { + { GST_FORMAT_DEFAULT, "default", "Default" }, + { GST_FORMAT_BYTES, "bytes", "Bytes" }, + { GST_FORMAT_TIME, "time", "Time" }, + { GST_FORMAT_BUFFERS, "buffers", "Buffers" }, + { GST_FORMAT_PERCENT, "percent", "Percent" }, + { GST_FORMAT_UNITS, "units", "Units as defined by the media type" }, + { 0, NULL, NULL } +}; + +void +_gst_format_initialize (void) +{ + GstFormatDefinition *standards = standard_definitions; + + while (standards->nick) { + _gst_formats = g_list_prepend (_gst_formats, standards); + standards++; + } +} + +/** + * 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 + * allrady registered format with that nick + * + * Returns: A new GstFormat or an already registered format + * with the same nick. + */ +GstFormat +gst_format_register (const gchar *nick, const gchar *description) +{ + GstFormatDefinition *format; + GstFormat query; + + 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; + + format = g_new0 (GstFormatDefinition, 1); + format->value = _n_values; + format->nick = g_strdup (nick); + format->description = g_strdup (description); + + _gst_formats = g_list_prepend (_gst_formats, format); + + _n_values++; + + return format->value; +} + +/** + * gst_format_get_by_nick: + * @nick: The nick of the format + * + * Return the format registered with the given nick. + * + * Returns: The format with @nick or GST_FORMAT_UNDEFINED + * if the format was not registered. + */ +GstFormat +gst_format_get_by_nick (const gchar *nick) +{ + GList *walk; + GstFormatDefinition *format; + + g_return_val_if_fail (nick != NULL, 0); + + walk = _gst_formats; + + while (walk) { + format = (GstFormatDefinition *) walk->data; + + if (!strcmp (format->nick, nick)) + return format->value; + + walk = g_list_next (walk); + } + + return GST_FORMAT_UNDEFINED; +} + +/** + * gst_format_get_details: + * @format: The format to get details of + * @nick: The nick of the format + * @description: The description of the format + * + * Get details about the given format. + * + * Returns: TRUE if the format was registered, FALSE otherwise + */ +gboolean +gst_format_get_details (GstFormat format, const gchar **nick, const gchar **description) +{ + GList *walk; + GstFormatDefinition *walk_format; + + g_return_val_if_fail (nick != NULL, FALSE); + g_return_val_if_fail (description != NULL, FALSE); + + walk = _gst_formats; + + while (walk) { + walk_format = (GstFormatDefinition *) walk->data; + + if (walk_format->value == format) { + *nick = walk_format->nick; + *description = walk_format->description; + + return TRUE; + } + + walk = g_list_next (walk); + } + return FALSE; +} diff --git a/gst/gstformat.h b/gst/gstformat.h index 2c4f01d..8c5e2da 100644 --- a/gst/gstformat.h +++ b/gst/gstformat.h @@ -2,7 +2,8 @@ * Copyright (C) 1999,2000 Erik Walthinsen * 2000 Wim Taymans * - * gstformat.h: Header for GstFormat types of offset + * gstformat.h: Header for GstFormat types used in queries and + * seeking. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,14 +30,14 @@ G_BEGIN_DECLS typedef enum { - GST_FORMAT_NONE = 0, - GST_FORMAT_DEFAULT = 1, - GST_FORMAT_BYTES = 2, - GST_FORMAT_TIME = 3, - GST_FORMAT_BUFFERS = 4, - GST_FORMAT_PERCENT = 5, + GST_FORMAT_UNDEFINED = 0, + GST_FORMAT_DEFAULT = 1, + GST_FORMAT_BYTES = 2, + GST_FORMAT_TIME = 3, + GST_FORMAT_BUFFERS = 4, + GST_FORMAT_PERCENT = 5, /* samples for audio, frames/fields for video */ - GST_FORMAT_UNITS = 6, + GST_FORMAT_UNITS = 6, } GstFormat; #define GST_FORMATS_FUNCTION(functionname, a...) \ @@ -50,6 +51,16 @@ functionname (GstPad *pad) \ return formats; \ } +void _gst_format_initialize (void); + +/* register a new format */ +GstFormat gst_format_register (const gchar *nick, const gchar *description); + +GstFormat gst_format_get_by_nick (const gchar *nick); + +/* query for format details */ +gboolean gst_format_get_details (GstFormat format, const gchar **nick, const gchar **description); + G_END_DECLS -- 2.7.4