Add internal helpers for pre-registering quarks from static strings and using the quark values directly instead of lo...

Original commit message from CVS:
* docs/gst/gstreamer-sections.txt:
* gst/Makefile.am:
* gst/gst.c: (init_post):
* gst/gst_private.h:
* gst/gstquark.c: (_priv_gst_quarks_initialize):
* gst/gstquark.h:
* gst/gstquery.c: (gst_query_new_position),
(gst_query_set_position), (gst_query_parse_position),
(gst_query_new_duration), (gst_query_set_duration),
(gst_query_parse_duration), (gst_query_new_convert),
(gst_query_set_convert), (gst_query_parse_convert),
(gst_query_new_segment), (gst_query_set_segment),
(gst_query_parse_segment), (gst_query_new_seeking),
(gst_query_set_seeking), (gst_query_parse_seeking):
Add internal helpers for pre-registering quarks from static strings
and using the quark values directly instead of looking them up when
creating and parsing queries. Can be used for event construction too.
Closes #350432.
This commit is contained in:
Jan Schmidt 2006-08-16 11:47:54 +00:00
parent 6072def8ed
commit 5736de1957
8 changed files with 208 additions and 66 deletions

View file

@ -1,3 +1,24 @@
2006-08-16 Jan Schmidt <thaytan@mad.scientist.com>
* docs/gst/gstreamer-sections.txt:
* gst/Makefile.am:
* gst/gst.c: (init_post):
* gst/gst_private.h:
* gst/gstquark.c: (_priv_gst_quarks_initialize):
* gst/gstquark.h:
* gst/gstquery.c: (gst_query_new_position),
(gst_query_set_position), (gst_query_parse_position),
(gst_query_new_duration), (gst_query_set_duration),
(gst_query_parse_duration), (gst_query_new_convert),
(gst_query_set_convert), (gst_query_parse_convert),
(gst_query_new_segment), (gst_query_set_segment),
(gst_query_parse_segment), (gst_query_new_seeking),
(gst_query_set_seeking), (gst_query_parse_seeking):
Add internal helpers for pre-registering quarks from static strings
and using the quark values directly instead of looking them up when
creating and parsing queries. Can be used for event construction too.
Closes #350432.
2006-08-16 Wim Taymans <wim@fluendo.com>
* gst/gstbin.c:

View file

@ -30,6 +30,8 @@ gst_segtrap_set_enabled
gst_registry_fork_is_enabled
gst_registry_fork_set_enabled
<SUBSECTION Private>
GST_QUARK
GstQuarkId
</SECTION>
<SECTION>

View file

@ -99,6 +99,7 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \
gstpipeline.c \
gstplugin.c \
gstpluginfeature.c \
gstquark.c \
gstquery.c \
gstregistry.c \
gstsegment.c \
@ -208,6 +209,7 @@ noinst_HEADERS = \
glib-compat-private.h \
gst-i18n-lib.h \
gst-i18n-app.h \
gstquark.h \
gst_private.h
gstmarshal.h: gstmarshal.list

View file

@ -797,6 +797,7 @@ init_post (void)
llf = G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL;
g_log_set_handler (g_log_domain_gstreamer, llf, debug_log_handler, NULL);
_priv_gst_quarks_initialize ();
_gst_format_initialize ();
_gst_query_initialize ();
gst_object_get_type ();

View file

@ -41,6 +41,9 @@ G_BEGIN_DECLS
gboolean __gst_in_valgrind (void);
/* Initialize GStreamer private quark storage */
void _priv_gst_quarks_initialize (void);
/*** debugging categories *****************************************************/
#ifndef GST_DISABLE_GST_DEBUG

45
gst/gstquark.c Normal file
View file

@ -0,0 +1,45 @@
/* GStreamer
* Copyright (C) 2006 Jan Schmidt <thaytan@noraisin.net>
*
* gstquark.c: Registered quarks for the _priv_gst_quark_table, private to
* GStreamer
*
* 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 "gst_private.h"
#include "gstquark.h"
/* These strings must match order and number declared in the GstQuarkId
* enum in gstquark.h! */
static const gchar *_quark_strings[] = {
"format", "current", "duration", "rate",
"seekable", "segment-start", "segment-end",
"src_format", "src_value", "dest_format", "dest_value",
"start_format", "start_value", "stop_format", "stop_value"
};
GQuark _priv_gst_quark_table[GST_QUARK_MAX];
void
_priv_gst_quarks_initialize (void)
{
gint i;
for (i = 0; i < GST_QUARK_MAX; i++) {
_priv_gst_quark_table[i] = g_quark_from_static_string (_quark_strings[i]);
}
}

52
gst/gstquark.h Normal file
View file

@ -0,0 +1,52 @@
/* GStreamer
* Copyright (C) 2006 Jan Schmidt <thaytan@noraisin.net>
*
* gstquark.h: Private header for storing quark info
*
* 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.
*/
#ifndef __GST_QUARK_H__
#define __GST_QUARK_H__
/* These enums need to match the number and order
* of strings declared in _quark_table, in gstquark.c */
typedef enum _GstQuarkId
{
GST_QUARK_FORMAT = 0,
GST_QUARK_CURRENT = 1,
GST_QUARK_DURATION = 2,
GST_QUARK_RATE = 3,
GST_QUARK_SEEKABLE = 4,
GST_QUARK_SEGMENT_START = 5,
GST_QUARK_SEGMENT_END = 6,
GST_QUARK_SRC_FORMAT = 7,
GST_QUARK_SRC_VALUE = 8,
GST_QUARK_DEST_FORMAT = 9,
GST_QUARK_DEST_VALUE = 10,
GST_QUARK_START_FORMAT = 11,
GST_QUARK_START_VALUE = 12,
GST_QUARK_STOP_FORMAT = 13,
GST_QUARK_STOP_VALUE = 14,
GST_QUARK_MAX = 15
} GstQuarkId;
extern GQuark _priv_gst_quark_table[GST_QUARK_MAX];
#define GST_QUARK(q) _priv_gst_quark_table[GST_QUARK_##q]
#endif

View file

@ -64,6 +64,7 @@
#include "gstquery.h"
#include "gstvalue.h"
#include "gstenumtypes.h"
#include "gstquark.h"
GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
#define GST_CAT_DEFAULT gst_query_debug
@ -73,7 +74,6 @@ static void gst_query_class_init (gpointer g_class, gpointer class_data);
static void gst_query_finalize (GstQuery * query);
static GstQuery *_gst_query_copy (GstQuery * query);
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
static GList *_gst_queries = NULL;
static GHashTable *_nick_to_query = NULL;
@ -406,9 +406,11 @@ gst_query_new_position (GstFormat format)
GstQuery *query;
GstStructure *structure;
structure = gst_structure_new ("GstQueryPosition",
"format", GST_TYPE_FORMAT, format,
"cur", G_TYPE_INT64, (gint64) - 1, NULL);
structure = gst_structure_empty_new ("GstQueryPosition");
gst_structure_id_set (structure,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (CURRENT), G_TYPE_INT64, (gint64) - 1, NULL);
query = gst_query_new (GST_QUERY_POSITION, structure);
return query;
@ -430,8 +432,9 @@ gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
structure = gst_query_get_structure (query);
gst_structure_set (structure,
"format", GST_TYPE_FORMAT, format, "cur", G_TYPE_INT64, cur, NULL);
gst_structure_id_set (structure,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
}
/**
@ -452,9 +455,11 @@ gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
structure = gst_query_get_structure (query);
if (format)
*format = g_value_get_enum (gst_structure_get_value (structure, "format"));
*format = g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (FORMAT)));
if (cur)
*cur = g_value_get_int64 (gst_structure_get_value (structure, "cur"));
*cur = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (CURRENT)));
}
@ -474,9 +479,11 @@ gst_query_new_duration (GstFormat format)
GstQuery *query;
GstStructure *structure;
structure = gst_structure_new ("GstQueryDuration",
"format", GST_TYPE_FORMAT, format,
"duration", G_TYPE_INT64, (gint64) - 1, NULL);
structure = gst_structure_empty_new ("GstQueryDuration");
gst_structure_id_set (structure,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (DURATION), G_TYPE_INT64, (gint64) - 1, NULL);
query = gst_query_new (GST_QUERY_DURATION, structure);
return query;
@ -498,9 +505,9 @@ gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
structure = gst_query_get_structure (query);
gst_structure_set (structure,
"format", GST_TYPE_FORMAT, format,
"duration", G_TYPE_INT64, duration, NULL);
gst_structure_id_set (structure,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
}
/**
@ -522,10 +529,11 @@ gst_query_parse_duration (GstQuery * query, GstFormat * format,
structure = gst_query_get_structure (query);
if (format)
*format = g_value_get_enum (gst_structure_get_value (structure, "format"));
*format = g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (FORMAT)));
if (duration)
*duration =
g_value_get_int64 (gst_structure_get_value (structure, "duration"));
*duration = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (DURATION)));
}
/**
@ -549,11 +557,13 @@ gst_query_new_convert (GstFormat src_format, gint64 value,
g_return_val_if_fail (value >= 0, NULL);
structure = gst_structure_new ("GstQueryConvert",
"src_format", GST_TYPE_FORMAT, src_format,
"src_value", G_TYPE_INT64, value,
"dest_format", GST_TYPE_FORMAT, dest_format,
"dest_value", G_TYPE_INT64, (gint64) - 1, NULL);
structure = gst_structure_empty_new ("GstQueryConvert");
gst_structure_id_set (structure,
GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
GST_QUARK (DEST_VALUE), G_TYPE_INT64, (gint64) - 1, NULL);
query = gst_query_new (GST_QUERY_CONVERT, structure);
return query;
@ -578,11 +588,11 @@ gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
structure = gst_query_get_structure (query);
gst_structure_set (structure,
"src_format", GST_TYPE_FORMAT, src_format,
"src_value", G_TYPE_INT64, src_value,
"dest_format", GST_TYPE_FORMAT, dest_format,
"dest_value", G_TYPE_INT64, dest_value, NULL);
gst_structure_id_set (structure,
GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
GST_QUARK (DEST_VALUE), G_TYPE_INT64, (gint64) dest_value, NULL);
}
/**
@ -606,17 +616,17 @@ gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
structure = gst_query_get_structure (query);
if (src_format)
*src_format =
g_value_get_enum (gst_structure_get_value (structure, "src_format"));
*src_format = g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (SRC_FORMAT)));
if (src_value)
*src_value =
g_value_get_int64 (gst_structure_get_value (structure, "src_value"));
*src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (SRC_VALUE)));
if (dest_format)
*dest_format =
g_value_get_enum (gst_structure_get_value (structure, "dest_format"));
*dest_format = g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (DEST_FORMAT)));
if (dest_value)
*dest_value =
g_value_get_int64 (gst_structure_get_value (structure, "dest_value"));
*dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (DEST_VALUE)));
}
/**
@ -635,8 +645,10 @@ gst_query_new_segment (GstFormat format)
GstQuery *query;
GstStructure *structure;
structure = gst_structure_new ("GstQuerySegment",
"format", GST_TYPE_FORMAT, format, NULL);
structure = gst_structure_empty_new ("GstQuerySegment");
gst_structure_id_set (structure,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, NULL);
query = gst_query_new (GST_QUERY_SEGMENT, structure);
return query;
@ -671,11 +683,11 @@ gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
structure = gst_query_get_structure (query);
gst_structure_set (structure,
"rate", G_TYPE_DOUBLE, rate,
"format", GST_TYPE_FORMAT, format,
"start_value", G_TYPE_INT64, start_value,
"stop_value", G_TYPE_INT64, stop_value, NULL);
gst_structure_id_set (structure,
GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
}
/**
@ -701,15 +713,17 @@ gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
structure = gst_query_get_structure (query);
if (rate)
*rate = g_value_get_double (gst_structure_get_value (structure, "rate"));
*rate = g_value_get_double (gst_structure_id_get_value (structure,
GST_QUARK (RATE)));
if (format)
*format = g_value_get_enum (gst_structure_get_value (structure, "format"));
*format = g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (FORMAT)));
if (start_value)
*start_value =
g_value_get_int64 (gst_structure_get_value (structure, "start_value"));
*start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (START_VALUE)));
if (stop_value)
*stop_value =
g_value_get_int64 (gst_structure_get_value (structure, "stop_value"));
*stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (STOP_VALUE)));
}
/**
@ -763,11 +777,13 @@ gst_query_new_seeking (GstFormat format)
GstQuery *query;
GstStructure *structure;
structure = gst_structure_new ("GstQuerySeeking",
"format", GST_TYPE_FORMAT, format,
"seekable", G_TYPE_BOOLEAN, FALSE,
"segment-start", G_TYPE_INT64, (gint64) - 1,
"segment-end", G_TYPE_INT64, (gint64) - 1, NULL);
structure = gst_structure_empty_new ("GstQuerySeeking");
gst_structure_id_set (structure,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
GST_QUARK (SEGMENT_START), G_TYPE_INT64, (gint64) - 1,
GST_QUARK (SEGMENT_END), G_TYPE_INT64, (gint64) - 1, NULL);
query = gst_query_new (GST_QUERY_SEEKING, structure);
return query;
@ -792,11 +808,11 @@ gst_query_set_seeking (GstQuery * query, GstFormat format,
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
structure = gst_query_get_structure (query);
gst_structure_set (structure,
"format", GST_TYPE_FORMAT, format,
"seekable", G_TYPE_BOOLEAN, seekable,
"segment-start", G_TYPE_INT64, segment_start,
"segment-end", G_TYPE_INT64, segment_end, NULL);
gst_structure_id_set (structure,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
}
/**
@ -821,17 +837,17 @@ gst_query_parse_seeking (GstQuery * query, GstFormat * format,
structure = gst_query_get_structure (query);
if (format)
*format = g_value_get_enum (gst_structure_get_value (structure, "format"));
*format = g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (FORMAT)));
if (seekable)
*seekable =
g_value_get_boolean (gst_structure_get_value (structure, "seekable"));
*seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
GST_QUARK (SEEKABLE)));
if (segment_start)
*segment_start =
g_value_get_int64 (gst_structure_get_value (structure,
"segment-start"));
*segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (SEGMENT_START)));
if (segment_end)
*segment_end =
g_value_get_int64 (gst_structure_get_value (structure, "segment-end"));
*segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (SEGMENT_END)));
}
/**