From 328ddd73631d44b646b3a41514c3ce90877f83b8 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Mon, 9 May 2005 06:21:10 +0000 Subject: [PATCH] gst/gstiterator.h: Add some includes. Original commit message from CVS: 2005-05-09 Andy Wingo * gst/gstiterator.h: Add some includes. * gst/gstqueryutils.h: Include more headers. * gst/gstpad.h: * gst/gstpad.c (gst_pad_query_position): New routine, replaces some uses of gst_pad_query. * gst/gstqueryutils.c: Build fixes. Make parse functions ignore NULL out parameters. (gst_query_new_position): New proc, allocates a new position query. * gst/Makefile.am (libgstreamer_@GST_MAJORMINOR@_la_SOURCES): Add gstqueryutils.c to the build. * gst/gststructure.c (gst_structure_set_valist): Implement with the generic G_VALUE_COLLECT. --- ChangeLog | 21 ++++++++++++++ gst/Makefile.am | 1 + gst/gstiterator.h | 1 + gst/gstpad.c | 33 ++++++++++++++++++++++ gst/gstpad.h | 5 ++++ gst/gstqueryutils.c | 45 ++++++++++++++++++++++-------- gst/gstqueryutils.h | 4 +++ gst/gststructure.c | 80 ++++------------------------------------------------- 8 files changed, 104 insertions(+), 86 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89de351..f661d61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2005-05-09 Andy Wingo + + * gst/gstiterator.h: Add some includes. + + * gst/gstqueryutils.h: Include more headers. + + * gst/gstpad.h: + * gst/gstpad.c (gst_pad_query_position): New routine, replaces + some uses of gst_pad_query. + + * gst/gstqueryutils.c: Build fixes. Make parse functions ignore + NULL out parameters. + (gst_query_new_position): New proc, allocates a new position + query. + + * gst/Makefile.am (libgstreamer_@GST_MAJORMINOR@_la_SOURCES): Add + gstqueryutils.c to the build. + + * gst/gststructure.c (gst_structure_set_valist): Implement with + the generic G_VALUE_COLLECT. + 2005-05-08 Edward Hervey * gst/Makefile.am: (gst_headers): diff --git a/gst/Makefile.am b/gst/Makefile.am index e30130b..47236f2 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -101,6 +101,7 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \ gstpluginfeature.c \ gstprobe.c \ gstquery.c \ + gstqueryutils.c \ gstqueue.c \ gstscheduler.c \ gststructure.c \ diff --git a/gst/gstiterator.h b/gst/gstiterator.h index 37d04ce..69c2c75 100644 --- a/gst/gstiterator.h +++ b/gst/gstiterator.h @@ -23,6 +23,7 @@ #define __GST_ITERATOR_H__ #include +#include /* for GValue in the fold */ G_BEGIN_DECLS diff --git a/gst/gstpad.c b/gst/gstpad.c index 92ee6e0..cc63fca 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -3863,6 +3863,39 @@ gst_pad_query2_default (GstPad * pad, GstQuery * query) } } +/** + * gst_pad_query_position: + * @pad: a #GstPad to invoke the default query on. + * @format: a pointer to the #GstFormat asked for. + * On return contains the #GstFormat used. + * @cur: A location in which to store the current position, or NULL. + * @end: A location in which to store the end position (length), or NULL. + * + * Queries a pad for the stream position and length. + * + * Returns: TRUE if the query could be performed. + */ +gboolean +gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur, + gint64 * end) +{ + GstQuery *query; + gboolean ret; + + g_return_val_if_fail (GST_IS_PAD (pad), FALSE); + g_return_val_if_fail (format != NULL, FALSE); + + query = gst_query_new_position (*format); + ret = gst_pad_query2 (pad, query); + + if (ret) + gst_query_parse_position_response (query, format, cur, end); + + gst_query_unref (query); + + return ret; +} + static gboolean gst_pad_get_formats_dispatcher (GstPad * pad, const GstFormat ** data) { diff --git a/gst/gstpad.h b/gst/gstpad.h index 02cfeeb..b560b80 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -578,6 +579,10 @@ gboolean gst_pad_query2 (GstPad *pad, GstQuery *query); void gst_pad_set_query2_function (GstPad *pad, GstPadQuery2Function query); gboolean gst_pad_query2_default (GstPad *pad, GstQuery *query); +/* util query functions */ +gboolean gst_pad_query_position (GstPad *pad, GstFormat *format, + gint64 *cur, gint64 *end); + /* misc helper functions */ gboolean gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch, gpointer data); diff --git a/gst/gstqueryutils.c b/gst/gstqueryutils.c index b106458..25a39f5 100644 --- a/gst/gstqueryutils.c +++ b/gst/gstqueryutils.c @@ -23,10 +23,22 @@ #include #include "gstqueryutils.h" +#include "gstenumtypes.h" +#include "gstvalue.h" +#include "gst_private.h" /* some macros are just waiting to be defined here */ +GstQuery * +gst_query_new_position (GstFormat format) +{ + GstStructure *structure = gst_structure_new ("query", + "format", GST_TYPE_FORMAT, format, NULL); + + return gst_query_new_application (GST_QUERY_POSITION, structure); +} + void gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur, gint64 end) @@ -49,7 +61,8 @@ gst_query_parse_position_query (GstQuery * query, GstFormat * format) g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION); structure = gst_query_get_structure (query); - *format = g_value_get_enum (gst_structure_get_value (structure, "format")); + if (format) + *format = g_value_get_enum (gst_structure_get_value (structure, "format")); } void @@ -61,9 +74,12 @@ gst_query_parse_position_response (GstQuery * query, GstFormat * format, g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION); structure = gst_query_get_structure (query); - *format = g_value_get_enum (gst_structure_get_value (structure, "format")); - *cur = g_value_get_int64 (gst_structure_get_value (structure, "cur")); - *end = g_value_get_int64 (gst_structure_get_value (structure, "end")); + if (format) + *format = g_value_get_enum (gst_structure_get_value (structure, "format")); + if (cur) + *cur = g_value_get_int64 (gst_structure_get_value (structure, "cur")); + if (end) + *end = g_value_get_int64 (gst_structure_get_value (structure, "end")); } void @@ -74,7 +90,8 @@ gst_query_parse_seeking_query (GstQuery * query, GstFormat * format) g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING); structure = gst_query_get_structure (query); - *format = g_value_get_enum (gst_structure_get_value (structure, "format")); + if (format) + *format = g_value_get_enum (gst_structure_get_value (structure, "format")); } void @@ -102,13 +119,17 @@ gst_query_parse_seeking_response (GstQuery * query, GstFormat * format, g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING); structure = gst_query_get_structure (query); - *format = g_value_get_enum (gst_structure_get_value (structure, "format")); - *seekable = g_value_get_boolean (gst_structure_get_value - (structure, "seekable")); - *segment_start = g_value_get_int64 (gst_structure_get_value - (structure, "segment-start")); - *segment_end = g_value_get_int64 (gst_structure_get_value - (structure, "segment-end")); + if (format) + *format = g_value_get_enum (gst_structure_get_value (structure, "format")); + if (seekable) + *seekable = g_value_get_boolean (gst_structure_get_value + (structure, "seekable")); + if (segment_start) + *segment_start = g_value_get_int64 (gst_structure_get_value + (structure, "segment-start")); + if (segment_end) + *segment_end = g_value_get_int64 (gst_structure_get_value + (structure, "segment-end")); } void diff --git a/gst/gstqueryutils.h b/gst/gstqueryutils.h index 3486d72..d59a804 100644 --- a/gst/gstqueryutils.h +++ b/gst/gstqueryutils.h @@ -20,9 +20,13 @@ */ +#include + +#include #include +GstQuery* gst_query_new_position (GstFormat format); void gst_query_set_position (GstQuery *query, GstFormat format, gint64 cur, gint64 end); void gst_query_parse_position_query (GstQuery *query, GstFormat *format); diff --git a/gst/gststructure.c b/gst/gststructure.c index e90ff31..1db1931 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -403,11 +403,8 @@ void gst_structure_set_valist (GstStructure * structure, const gchar * fieldname, va_list varargs) { + gchar *err = NULL; GType type; - int i; - double d; - char *s; - gpointer p; g_return_if_fail (structure != NULL); g_return_if_fail (IS_MUTABLE (structure)); @@ -418,77 +415,12 @@ gst_structure_set_valist (GstStructure * structure, field.name = g_quark_from_string (fieldname); type = va_arg (varargs, GType); - - switch (type) { - case G_TYPE_INT: - i = va_arg (varargs, int); - - g_value_init (&field.value, G_TYPE_INT); - g_value_set_int (&field.value, i); - break; - case G_TYPE_DOUBLE: - d = va_arg (varargs, double); - - g_value_init (&field.value, G_TYPE_DOUBLE); - g_value_set_double (&field.value, d); - break; - case G_TYPE_BOOLEAN: - i = va_arg (varargs, int); - - g_value_init (&field.value, G_TYPE_BOOLEAN); - g_value_set_boolean (&field.value, i); - break; - case G_TYPE_STRING: - s = va_arg (varargs, char *); - - g_value_init (&field.value, G_TYPE_STRING); - g_value_set_string (&field.value, s); - break; - case G_TYPE_POINTER: - p = va_arg (varargs, gpointer); - - g_value_init (&field.value, G_TYPE_POINTER); - g_value_set_pointer (&field.value, p); - break; - default: - if (type == GST_TYPE_FOURCC) { - i = va_arg (varargs, int); - - g_value_init (&field.value, GST_TYPE_FOURCC); - gst_value_set_fourcc (&field.value, i); - } else if (type == GST_TYPE_INT_RANGE) { - int min, max; - min = va_arg (varargs, int); - max = va_arg (varargs, int); - - g_value_init (&field.value, GST_TYPE_INT_RANGE); - gst_value_set_int_range (&field.value, min, max); - } else if (type == GST_TYPE_DOUBLE_RANGE) { - double min, max; - min = va_arg (varargs, double); - max = va_arg (varargs, double); - - g_value_init (&field.value, GST_TYPE_DOUBLE_RANGE); - gst_value_set_double_range (&field.value, min, max); - } else if (type == GST_TYPE_BUFFER) { - GstBuffer *buffer = va_arg (varargs, GstBuffer *); - - g_value_init (&field.value, GST_TYPE_BUFFER); - g_value_set_boxed (&field.value, buffer); - } else if (type == GST_TYPE_FRACTION) { - gint n, d; - n = va_arg (varargs, int); - d = va_arg (varargs, int); - - g_value_init (&field.value, GST_TYPE_FRACTION); - gst_value_set_fraction (&field.value, n, d); - } else { - g_critical ("unimplemented vararg field type %d\n", (int) type); - return; - } - break; + g_value_init (&field.value, type); + G_VALUE_COLLECT (&field.value, varargs, 0, &err); + if (err) { + g_critical ("%s", err); + return; } - gst_structure_set_field (structure, &field); fieldname = va_arg (varargs, gchar *); -- 2.7.4