From 8d46970ed83785aa39649e244ddb4ec7b74ce896 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 19 Nov 2005 18:57:00 +0000 Subject: [PATCH] Add type to quark and type to string conversions. Original commit message from CVS: * docs/design/part-TODO.txt: * gst/gstformat.c: (_gst_format_initialize), (gst_format_get_name), (gst_format_to_quark), (gst_format_register): * gst/gstformat.h: * gst/gstquery.c: (_gst_query_initialize), (gst_query_type_get_name), (gst_query_type_to_quark), (gst_query_type_register): * gst/gstquery.h: Add type to quark and type to string conversions. --- ChangeLog | 12 +++++++++++ docs/design/part-TODO.txt | 2 -- gst/gstformat.c | 34 +++++++++++++++++++++++++------ gst/gstformat.h | 11 ++++++++-- gst/gstquery.c | 42 +++++++++++++++++++++++++++++---------- gst/gstquery.h | 7 +++++++ 6 files changed, 88 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9821255b1e..86fd74ef5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-11-19 Wim Taymans + + * docs/design/part-TODO.txt: + * gst/gstformat.c: (_gst_format_initialize), (gst_format_get_name), + (gst_format_to_quark), (gst_format_register): + * gst/gstformat.h: + * gst/gstquery.c: (_gst_query_initialize), + (gst_query_type_get_name), (gst_query_type_to_quark), + (gst_query_type_register): + * gst/gstquery.h: + Add type to quark and type to string conversions. + 2005-11-19 Andy Wingo * gst/gstbuffer.h (GST_BUFFER_FLAG_ORIGINAL): Removed. Fixes diff --git a/docs/design/part-TODO.txt b/docs/design/part-TODO.txt index 5bdc146bbd..548f874991 100644 --- a/docs/design/part-TODO.txt +++ b/docs/design/part-TODO.txt @@ -11,8 +11,6 @@ API/ABI - make it possible to seek on other formats than bytes in basesrc. -- GstFormat, GstQuery quarks, get_name. - - GstEvent, GstMessage register like GstFormat or GstQuery. - unblocking while seeking. gst_element_flush_pads (GstElement, gboolean); diff --git a/gst/gstformat.c b/gst/gstformat.c index 7695de01b0..abf64eaf36 100644 --- a/gst/gstformat.c +++ b/gst/gstformat.c @@ -43,12 +43,12 @@ static GHashTable *_format_to_nick = NULL; static guint32 _n_values = 1; /* we start from 1 because 0 reserved for UNDEFINED */ static GstFormatDefinition standard_definitions[] = { - {GST_FORMAT_DEFAULT, "default", "Default format for the media type"}, - {GST_FORMAT_BYTES, "bytes", "Bytes"}, - {GST_FORMAT_TIME, "time", "Time"}, - {GST_FORMAT_BUFFERS, "buffers", "Buffers"}, - {GST_FORMAT_PERCENT, "percent", "Percent"}, - {0, NULL, NULL} + {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} }; void @@ -63,6 +63,7 @@ _gst_format_initialize (void) } 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 (_format_to_nick, GINT_TO_POINTER (standards->value), standards); @@ -74,6 +75,26 @@ _gst_format_initialize (void) g_static_mutex_unlock (&mutex); } +const gchar * +gst_format_get_name (GstFormat format) +{ + const GstFormatDefinition *def; + + def = gst_format_get_details (format); + + return def->nick; +} + +GQuark +gst_format_to_quark (GstFormat format) +{ + const GstFormatDefinition *def; + + def = gst_format_get_details (format); + + return def->quark; +} + /** * gst_format_register: * @nick: The nick of the new format @@ -104,6 +125,7 @@ gst_format_register (const gchar * nick, const gchar * description) format->value = _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); diff --git a/gst/gstformat.h b/gst/gstformat.h index d1c7ce3771..7f0f2bf03e 100644 --- a/gst/gstformat.h +++ b/gst/gstformat.h @@ -34,7 +34,8 @@ G_BEGIN_DECLS /** * GstFormat: * @GST_FORMAT_UNDEFINED: undefined format - * @GST_FORMAT_DEFAULT: the default format of the pad/element + * @GST_FORMAT_DEFAULT: the default format of the pad/element. This can be + * samples for raw audio, frames/fields for raw video. * @GST_FORMAT_BYTES: bytes * @GST_FORMAT_TIME: time in nanoseconds * @GST_FORMAT_BUFFERS: buffers @@ -42,9 +43,11 @@ G_BEGIN_DECLS * * Standard predefined formats */ +/* NOTE: don't forget to update the table in gstformat.c when changing + * this enum */ typedef enum { GST_FORMAT_UNDEFINED = 0, /* must be first in list */ - GST_FORMAT_DEFAULT = 1, /* samples for raw audio, frames/fields for raw video */ + GST_FORMAT_DEFAULT = 1, GST_FORMAT_BYTES = 2, GST_FORMAT_TIME = 3, GST_FORMAT_BUFFERS = 4, @@ -81,10 +84,14 @@ struct _GstFormatDefinition GstFormat value; gchar *nick; gchar *description; + GQuark quark; }; void _gst_format_initialize (void); +const gchar* gst_format_get_name (GstFormat format); +GQuark gst_format_to_quark (GstFormat format); + /* register a new format */ GstFormat gst_format_register (const gchar *nick, const gchar *description); diff --git a/gst/gstquery.c b/gst/gstquery.c index 6ccdfa529b..d56fe291eb 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -58,16 +58,16 @@ static GHashTable *_query_type_to_nick = NULL; static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */ static GstQueryTypeDefinition standard_definitions[] = { - {GST_QUERY_POSITION, "position", "Current position"}, - {GST_QUERY_DURATION, "duration", "Total duration"}, - {GST_QUERY_LATENCY, "latency", "Latency"}, - {GST_QUERY_JITTER, "jitter", "Jitter"}, - {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1"}, - {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters"}, - {GST_QUERY_SEGMENT, "segment", "currently configured segment"}, - {GST_QUERY_CONVERT, "convert", "Converting between formats"}, - {GST_QUERY_FORMATS, "formats", "Supported formats for conversion"}, - {0, NULL, NULL} + {GST_QUERY_POSITION, "position", "Current position", 0}, + {GST_QUERY_DURATION, "duration", "Total duration", 0}, + {GST_QUERY_LATENCY, "latency", "Latency", 0}, + {GST_QUERY_JITTER, "jitter", "Jitter", 0}, + {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0}, + {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0}, + {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0}, + {GST_QUERY_CONVERT, "convert", "Converting between formats", 0}, + {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0}, + {0, NULL, NULL, 0} }; void @@ -86,6 +86,7 @@ _gst_query_initialize (void) } while (standards->nick) { + standards->quark = g_quark_from_static_string (standards->nick); g_hash_table_insert (_nick_to_query, standards->nick, standards); g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (standards->value), standards); @@ -99,6 +100,26 @@ _gst_query_initialize (void) gst_query_get_type (); } +const gchar * +gst_query_type_get_name (GstQueryType query) +{ + const GstQueryTypeDefinition *def; + + def = gst_query_type_get_details (query); + + return def->nick; +} + +GQuark +gst_query_type_to_quark (GstQueryType query) +{ + const GstQueryTypeDefinition *def; + + def = gst_query_type_get_details (query); + + return def->quark; +} + GType gst_query_get_type (void) { @@ -201,6 +222,7 @@ gst_query_type_register (const gchar * nick, const gchar * description) query->value = _n_values; query->nick = g_strdup (nick); query->description = g_strdup (description); + query->quark = g_quark_from_static_string (query->nick); g_static_mutex_lock (&mutex); g_hash_table_insert (_nick_to_query, query->nick, query); diff --git a/gst/gstquery.h b/gst/gstquery.h index 25b693bb9d..c884850b10 100644 --- a/gst/gstquery.h +++ b/gst/gstquery.h @@ -49,6 +49,8 @@ G_BEGIN_DECLS * * Standard predefined Query types */ +/* NOTE: don't forget to update the table in gstquery.c when changing + * this enum */ typedef enum { GST_QUERY_NONE = 0, GST_QUERY_POSITION, @@ -86,6 +88,7 @@ struct _GstQueryTypeDefinition GstQueryType value; gchar *nick; gchar *description; + GQuark quark; }; #define GST_TYPE_QUERY (gst_query_get_type()) @@ -118,6 +121,10 @@ struct _GstQueryClass { }; void _gst_query_initialize (void); + +const gchar* gst_query_type_get_name (GstQueryType query); +GQuark gst_query_type_to_quark (GstQueryType query); + GType gst_query_get_type (void); /* register a new query */