diff -r 9b2c3c7a1a9c -r 567bb019e3e3 gstreamer_core/gst/gstquery.c --- a/gstreamer_core/gst/gstquery.c Wed Mar 31 22:03:18 2010 +0300 +++ b/gstreamer_core/gst/gstquery.c Tue Aug 31 15:30:33 2010 +0300 @@ -65,7 +65,7 @@ #include "gstvalue.h" #include "gstenumtypes.h" #include "gstquark.h" - +#include "gsturi.h" #ifdef __SYMBIAN32__ #include #endif @@ -73,7 +73,6 @@ GST_DEBUG_CATEGORY_STATIC (gst_query_debug); #define GST_CAT_DEFAULT gst_query_debug -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); @@ -95,6 +94,9 @@ {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}, + {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0}, + {GST_QUERY_CUSTOM, "custom", "Custom query", 0}, + {GST_QUERY_URI, "uri", "URI of the source or sink", 0}, {0, NULL, NULL, 0} }; #ifdef __SYMBIAN32__ @@ -175,48 +177,23 @@ return def->quark; } -#ifdef __SYMBIAN32__ -EXPORT_C -#endif - -GType -gst_query_get_type (void) -{ - static GType _gst_query_type; +G_DEFINE_TYPE (GstQuery, gst_query, GST_TYPE_MINI_OBJECT); - if (G_UNLIKELY (_gst_query_type == 0)) { - static const GTypeInfo query_info = { - sizeof (GstQueryClass), - NULL, - NULL, - gst_query_class_init, - NULL, - NULL, - sizeof (GstQuery), - 0, - NULL, - NULL - }; +static void +gst_query_class_init (GstQueryClass * klass) +{ + parent_class = g_type_class_peek_parent (klass); - _gst_query_type = g_type_register_static (GST_TYPE_MINI_OBJECT, - "GstQuery", &query_info, 0); - } - return _gst_query_type; + klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_query_copy; + klass->mini_object_class.finalize = + (GstMiniObjectFinalizeFunction) gst_query_finalize; + } static void -gst_query_class_init (gpointer g_class, gpointer class_data) +gst_query_init (GstQuery * query) { - GstQueryClass *query_class = GST_QUERY_CLASS (g_class); - - parent_class = g_type_class_peek_parent (g_class); - - query_class->mini_object_class.copy = - (GstMiniObjectCopyFunction) _gst_query_copy; - query_class->mini_object_class.finalize = - (GstMiniObjectFinalizeFunction) gst_query_finalize; - } static void @@ -229,7 +206,7 @@ gst_structure_free (query->structure); } - GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (query)); +/* GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (query)); */ } static GstQuery * @@ -449,10 +426,9 @@ GstQuery *query; GstStructure *structure; - structure = gst_structure_empty_new ("GstQueryPosition"); - gst_structure_id_set (structure, + structure = gst_structure_id_new (GST_QUARK (QUERY_POSITION), GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, - GST_QUARK (CURRENT), G_TYPE_INT64, (gint64) - 1, NULL); + GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL); query = gst_query_new (GST_QUERY_POSITION, structure); @@ -534,10 +510,9 @@ GstQuery *query; GstStructure *structure; - structure = gst_structure_empty_new ("GstQueryDuration"); - gst_structure_id_set (structure, + structure = gst_structure_id_new (GST_QUARK (QUERY_DURATION), GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, - GST_QUARK (DURATION), G_TYPE_INT64, (gint64) - 1, NULL); + GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL); query = gst_query_new (GST_QUERY_DURATION, structure); @@ -621,11 +596,10 @@ GstQuery *query; GstStructure *structure; - structure = gst_structure_empty_new ("GstQueryLatency"); - gst_structure_set (structure, - "live", G_TYPE_BOOLEAN, FALSE, - "min-latency", G_TYPE_UINT64, (gint64) 0, - "max-latency", G_TYPE_UINT64, (gint64) - 1, NULL); + structure = gst_structure_id_new (GST_QUARK (QUERY_LATENCY), + GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE, + GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0), + GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL); query = gst_query_new (GST_QUERY_LATENCY, structure); @@ -656,10 +630,10 @@ g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY); structure = gst_query_get_structure (query); - gst_structure_set (structure, - "live", G_TYPE_BOOLEAN, live, - "min-latency", G_TYPE_UINT64, min_latency, - "max-latency", G_TYPE_UINT64, max_latency, NULL); + gst_structure_id_set (structure, + GST_QUARK (LIVE), G_TYPE_BOOLEAN, live, + GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency, + GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL); } /** @@ -687,13 +661,15 @@ structure = gst_query_get_structure (query); if (live) - *live = g_value_get_boolean (gst_structure_get_value (structure, "live")); + *live = + g_value_get_boolean (gst_structure_id_get_value (structure, + GST_QUARK (LIVE))); if (min_latency) - *min_latency = g_value_get_uint64 (gst_structure_get_value (structure, - "min-latency")); + *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure, + GST_QUARK (MIN_LATENCY))); if (max_latency) - *max_latency = g_value_get_uint64 (gst_structure_get_value (structure, - "max-latency")); + *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure, + GST_QUARK (MAX_LATENCY))); } /** @@ -719,14 +695,11 @@ GstQuery *query; GstStructure *structure; - g_return_val_if_fail (value >= 0, NULL); - - structure = gst_structure_empty_new ("GstQueryConvert"); - gst_structure_id_set (structure, + structure = gst_structure_id_new (GST_QUARK (QUERY_CONVERT), 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); + GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL); query = gst_query_new (GST_QUERY_CONVERT, structure); @@ -760,7 +733,7 @@ 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); + GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL); } /** @@ -821,12 +794,11 @@ GstQuery *query; GstStructure *structure; - structure = gst_structure_empty_new ("GstQuerySegment"); - gst_structure_id_set (structure, + structure = gst_structure_id_new (GST_QUARK (QUERY_SEGMENT), GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, - GST_QUARK (START_VALUE), G_TYPE_INT64, (gint64) - 1, - GST_QUARK (STOP_VALUE), G_TYPE_INT64, (gint64) - 1, NULL); + GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), + GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL); query = gst_query_new (GST_QUERY_SEGMENT, structure); @@ -958,7 +930,7 @@ } /** - * gst_query_new_seeking (GstFormat *format) + * gst_query_new_seeking: * @format: the default #GstFormat for the new query * * Constructs a new query object for querying seeking properties of @@ -968,19 +940,19 @@ */ #ifdef __SYMBIAN32__ EXPORT_C -#endif +#endif + GstQuery * gst_query_new_seeking (GstFormat format) { GstQuery *query; GstStructure *structure; - structure = gst_structure_empty_new ("GstQuerySeeking"); - gst_structure_id_set (structure, + structure = gst_structure_id_new (GST_QUARK (QUERY_SEEKING), 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); + GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1), + GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL); query = gst_query_new (GST_QUERY_SEEKING, structure); @@ -1076,7 +1048,7 @@ GstQuery *query; GstStructure *structure; - structure = gst_structure_new ("GstQueryFormats", NULL); + structure = gst_structure_id_empty_new (GST_QUARK (QUERY_FORMATS)); query = gst_query_new (GST_QUERY_FORMATS, structure); return query; @@ -1235,3 +1207,322 @@ } } } + +/** + * gst_query_new_buffering + * @format: the default #GstFormat for the new query + * + * Constructs a new query object for querying the buffering status of + * a stream. + * + * Returns: A #GstQuery + * + * Since: 0.10.20 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +GstQuery * +gst_query_new_buffering (GstFormat format) +{ + GstQuery *query; + GstStructure *structure; + + /* by default, we configure the answer as no buffering with a 100% buffering + * progress */ + structure = gst_structure_id_new (GST_QUARK (QUERY_BUFFERING), + GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE, + GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100, + GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM, + GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1, + GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1, + GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0), + GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1), + GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, + GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), + GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL); + + query = gst_query_new (GST_QUERY_BUFFERING, structure); + + return query; +} + +/** + * gst_query_set_buffering_percent + * @query: A valid #GstQuery of type GST_QUERY_BUFFERING. + * @busy: if buffering is busy + * @percent: a buffering percent + * + * Set the percentage of buffered data. This is a value between 0 and 100. + * The @busy indicator is %TRUE when the buffering is in progress. + * + * Since: 0.10.20 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent) +{ + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING); + g_return_if_fail (percent >= 0 && percent <= 100); + + gst_structure_id_set (query->structure, + GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, + GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL); +} + +/** + * gst_query_parse_buffering_percent + * @query: A valid #GstQuery of type GST_QUERY_BUFFERING. + * @busy: if buffering is busy + * @percent: a buffering percent + * + * Get the percentage of buffered data. This is a value between 0 and 100. + * The @busy indicator is %TRUE when the buffering is in progress. + * + * Since: 0.10.20 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy, + gint * percent) +{ + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING); + + if (busy) + *busy = g_value_get_boolean (gst_structure_id_get_value (query->structure, + GST_QUARK (BUSY))); + if (percent) + *percent = g_value_get_int (gst_structure_id_get_value (query->structure, + GST_QUARK (BUFFER_PERCENT))); +} + +/** + * gst_query_set_buffering_stats: + * @query: A valid #GstQuery of type GST_QUERY_BUFFERING. + * @mode: a buffering mode + * @avg_in: the average input rate + * @avg_out: the average output rate + * @buffering_left: amount of buffering time left + * + * Configures the buffering stats values in @query. + * + * Since: 0.10.20 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode, + gint avg_in, gint avg_out, gint64 buffering_left) +{ + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING); + + gst_structure_id_set (query->structure, + GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode, + GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in, + GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out, + GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL); +} + +/** + * gst_query_parse_buffering_stats: + * @query: A valid #GstQuery of type GST_QUERY_BUFFERING. + * @mode: a buffering mode + * @avg_in: the average input rate + * @avg_out: the average output rate + * @buffering_left: amount of buffering time left + * + * Extracts the buffering stats values from @query. + * + * Since: 0.10.20 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_parse_buffering_stats (GstQuery * query, + GstBufferingMode * mode, gint * avg_in, gint * avg_out, + gint64 * buffering_left) +{ + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING); + + if (mode) + *mode = g_value_get_enum (gst_structure_id_get_value (query->structure, + GST_QUARK (BUFFERING_MODE))); + if (avg_in) + *avg_in = g_value_get_int (gst_structure_id_get_value (query->structure, + GST_QUARK (AVG_IN_RATE))); + if (avg_out) + *avg_out = g_value_get_int (gst_structure_id_get_value (query->structure, + GST_QUARK (AVG_OUT_RATE))); + if (buffering_left) + *buffering_left = + g_value_get_int64 (gst_structure_id_get_value (query->structure, + GST_QUARK (BUFFERING_LEFT))); +} + + +/** + * gst_query_set_buffering_range: + * @query: a #GstQuery + * @format: the format to set for the @start and @stop values + * @start: the start to set + * @stop: the stop to set + * @estimated_total: estimated total amount of download time + * + * Set the available query result fields in @query. + * + * Since: 0.10.20 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_set_buffering_range (GstQuery * query, GstFormat format, + gint64 start, gint64 stop, gint64 estimated_total) +{ + GstStructure *structure; + + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING); + + structure = gst_query_get_structure (query); + gst_structure_id_set (structure, + GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, + GST_QUARK (START_VALUE), G_TYPE_INT64, start, + GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop, + GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL); +} + +/** + * gst_query_parse_buffering_range: + * @query: a GST_QUERY_SEEKING type query #GstQuery + * @format: the format to set for the @segment_start and @segment_end values + * @start: the start to set + * @stop: the stop to set + * @estimated_total: estimated total amount of download time + * + * Parse an available query, writing the format into @format, and + * other results into the passed parameters, if the respective parameters + * are non-NULL + * + * Since: 0.10.20 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_parse_buffering_range (GstQuery * query, GstFormat * format, + gint64 * start, gint64 * stop, gint64 * estimated_total) +{ + GstStructure *structure; + + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING); + + structure = gst_query_get_structure (query); + if (format) + *format = g_value_get_enum (gst_structure_id_get_value (structure, + GST_QUARK (FORMAT))); + if (start) + *start = g_value_get_int64 (gst_structure_id_get_value (structure, + GST_QUARK (START_VALUE))); + if (stop) + *stop = g_value_get_int64 (gst_structure_id_get_value (structure, + GST_QUARK (STOP_VALUE))); + if (estimated_total) + *estimated_total = + g_value_get_int64 (gst_structure_id_get_value (structure, + GST_QUARK (ESTIMATED_TOTAL))); +} + +/** + * gst_query_new_uri: + * + * Constructs a new query URI query object. Use gst_query_unref() + * when done with it. An URI query is used to query the current URI + * that is used by the source or sink. + * + * Returns: A #GstQuery + * + * Since: 0.10.22 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +GstQuery * +gst_query_new_uri (void) +{ + GstQuery *query; + GstStructure *structure; + + structure = gst_structure_id_new (GST_QUARK (QUERY_URI), + GST_QUARK (URI), G_TYPE_STRING, NULL, NULL); + + query = gst_query_new (GST_QUERY_URI, structure); + + return query; +} + +/** + * gst_query_set_uri: + * @query: a #GstQuery with query type GST_QUERY_URI + * @uri: the URI to set + * + * Answer a URI query by setting the requested URI. + * + * Since: 0.10.22 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_set_uri (GstQuery * query, const gchar * uri) +{ + GstStructure *structure; + + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI); + g_return_if_fail (gst_uri_is_valid (uri)); + + structure = gst_query_get_structure (query); + gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL); +} + +/** + * gst_query_parse_uri: + * @query: a #GstQuery + * @uri: the storage for the current URI (may be NULL) + * + * Parse an URI query, writing the URI into @uri as a newly + * allocated string, if the respective parameters are non-NULL. + * Free the string with g_free() after usage. + * + * Since: 0.10.22 + */ +#ifdef __SYMBIAN32__ +EXPORT_C +#endif + +void +gst_query_parse_uri (GstQuery * query, gchar ** uri) +{ + GstStructure *structure; + + g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI); + + structure = gst_query_get_structure (query); + if (uri) + *uri = g_value_dup_string (gst_structure_id_get_value (structure, + GST_QUARK (URI))); +}