mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-13 23:22:54 +00:00
docs/gst/gstreamer-sections.txt: Reworked query docs.
Original commit message from CVS: * docs/gst/gstreamer-sections.txt: Reworked query docs. * gst/gstquery.c: (gst_query_new_formats), (gst_query_list_add_format), (gst_query_set_formats), (gst_query_set_formatsv), (gst_query_parse_formats_length), (gst_query_parse_formats_nth): * gst/gstquery.h: Flesh out formats query, added some new methods. Fix part of #324398. * tests/check/gst/gstquery.c: (GST_START_TEST), (gstquery_suite): Added query creation tests.
This commit is contained in:
parent
43fc573b56
commit
2fbeada812
5 changed files with 282 additions and 28 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2006-02-14 Wim Taymans <wim@fluendo.com>
|
||||
|
||||
* docs/gst/gstreamer-sections.txt:
|
||||
Reworked query docs.
|
||||
|
||||
* gst/gstquery.c: (gst_query_new_formats),
|
||||
(gst_query_list_add_format), (gst_query_set_formats),
|
||||
(gst_query_set_formatsv), (gst_query_parse_formats_length),
|
||||
(gst_query_parse_formats_nth):
|
||||
* gst/gstquery.h:
|
||||
Flesh out formats query, added some new methods.
|
||||
Fix part of #324398.
|
||||
|
||||
* tests/check/gst/gstquery.c: (GST_START_TEST), (gstquery_suite):
|
||||
Added query creation tests.
|
||||
|
||||
2006-02-14 Jan Schmidt <thaytan@mad.scientist.com>
|
||||
|
||||
* gst/gstpad.c: (fixate_value):
|
||||
|
|
|
@ -1523,30 +1523,40 @@ gst_query_type_register
|
|||
gst_query_type_get_by_nick
|
||||
gst_query_types_contains
|
||||
gst_query_type_get_details
|
||||
|
||||
gst_query_copy
|
||||
gst_query_get_structure
|
||||
gst_query_make_writable
|
||||
gst_query_new_application
|
||||
gst_query_new_convert
|
||||
gst_query_new_position
|
||||
gst_query_new_duration
|
||||
gst_query_new_seeking
|
||||
gst_query_parse_convert
|
||||
gst_query_parse_position
|
||||
gst_query_parse_duration
|
||||
gst_query_parse_seeking
|
||||
gst_query_ref
|
||||
gst_query_set_convert
|
||||
gst_query_set_formats
|
||||
gst_query_set_position
|
||||
gst_query_set_duration
|
||||
gst_query_set_seeking
|
||||
gst_query_type_iterate_definitions
|
||||
gst_query_unref
|
||||
|
||||
gst_query_set_segment
|
||||
gst_query_ref
|
||||
gst_query_unref
|
||||
gst_query_copy
|
||||
gst_query_make_writable
|
||||
|
||||
gst_query_new_application
|
||||
gst_query_get_structure
|
||||
|
||||
gst_query_new_convert
|
||||
gst_query_set_convert
|
||||
gst_query_parse_convert
|
||||
|
||||
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_seeking
|
||||
gst_query_set_seeking
|
||||
gst_query_parse_seeking
|
||||
|
||||
gst_query_new_formats
|
||||
gst_query_set_formats
|
||||
gst_query_set_formatsv
|
||||
gst_query_parse_formats_length
|
||||
gst_query_parse_formats_nth
|
||||
|
||||
gst_query_new_segment
|
||||
gst_query_set_segment
|
||||
gst_query_parse_segment
|
||||
|
||||
<SUBSECTION Standard>
|
||||
|
|
134
gst/gstquery.c
134
gst/gstquery.c
|
@ -799,6 +799,39 @@ gst_query_parse_seeking (GstQuery * query, GstFormat * format,
|
|||
g_value_get_int64 (gst_structure_get_value (structure, "segment-end"));
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_new_formats:
|
||||
*
|
||||
* Constructs a new query object for querying formats of
|
||||
* the stream.
|
||||
*
|
||||
* Returns: A #GstQuery
|
||||
*
|
||||
* Since: 0.10.4
|
||||
*/
|
||||
GstQuery *
|
||||
gst_query_new_formats (void)
|
||||
{
|
||||
GstQuery *query;
|
||||
GstStructure *structure;
|
||||
|
||||
structure = gst_structure_new ("GstQueryFormats", NULL);
|
||||
query = gst_query_new (GST_QUERY_FORMATS, structure);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_query_list_add_format (GValue * list, GstFormat format)
|
||||
{
|
||||
GValue item = { 0, };
|
||||
|
||||
g_value_init (&item, GST_TYPE_FORMAT);
|
||||
g_value_set_enum (&item, format);
|
||||
gst_value_list_append_value (list, &item);
|
||||
g_value_unset (&item);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_set_formats:
|
||||
* @query: a #GstQuery
|
||||
|
@ -813,23 +846,110 @@ gst_query_set_formats (GstQuery * query, gint n_formats, ...)
|
|||
{
|
||||
va_list ap;
|
||||
GValue list = { 0, };
|
||||
GValue item = { 0, };
|
||||
GstStructure *structure;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
|
||||
|
||||
g_value_init (&list, GST_TYPE_LIST);
|
||||
|
||||
va_start (ap, n_formats);
|
||||
|
||||
for (i = 0; i < n_formats; i++) {
|
||||
g_value_init (&item, GST_TYPE_FORMAT);
|
||||
g_value_set_enum (&item, va_arg (ap, GstFormat));
|
||||
gst_value_list_append_value (&list, &item);
|
||||
g_value_unset (&item);
|
||||
gst_query_list_add_format (&list, va_arg (ap, GstFormat));
|
||||
}
|
||||
|
||||
va_end (ap);
|
||||
|
||||
structure = gst_query_get_structure (query);
|
||||
gst_structure_set_value (structure, "formats", &list);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_set_formatsv:
|
||||
* @query: a #GstQuery
|
||||
* @n_formats: the number of formats to set.
|
||||
* @formats: An array containing @n_formats @GstFormat values.
|
||||
*
|
||||
* Set the formats query result fields in @query. The number of formats passed
|
||||
* in the @formats array must be equal to @n_formats.
|
||||
*
|
||||
* Since: 0.10.4
|
||||
*/
|
||||
void
|
||||
gst_query_set_formatsv (GstQuery * query, gint n_formats, GstFormat * formats)
|
||||
{
|
||||
GValue list = { 0, };
|
||||
GstStructure *structure;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
|
||||
|
||||
g_value_init (&list, GST_TYPE_LIST);
|
||||
for (i = 0; i < n_formats; i++) {
|
||||
gst_query_list_add_format (&list, formats[i]);
|
||||
}
|
||||
structure = gst_query_get_structure (query);
|
||||
gst_structure_set_value (structure, "formats", &list);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_parse_formats_length:
|
||||
* @query: a #GstQuery
|
||||
* @n_formats: the number of formats in this query.
|
||||
*
|
||||
* Parse the number of formats in the formats @query.
|
||||
*
|
||||
* Since: 0.10.4
|
||||
*/
|
||||
void
|
||||
gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
|
||||
{
|
||||
GstStructure *structure;
|
||||
|
||||
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
|
||||
|
||||
if (n_formats) {
|
||||
const GValue *list;
|
||||
|
||||
structure = gst_query_get_structure (query);
|
||||
list = gst_structure_get_value (structure, "formats");
|
||||
if (list == NULL)
|
||||
*n_formats = 0;
|
||||
else
|
||||
*n_formats = gst_value_list_get_size (list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_query_parse_formats_nth:
|
||||
* @query: a #GstQuery
|
||||
* @nth: the nth format to retrieve.
|
||||
* @format: a pointer to store the nth format
|
||||
*
|
||||
* Parse the format query and retrieve the @nth format from it into
|
||||
* @format. If the list contains less elements than @nth, @format will be
|
||||
* set to GST_FORMAT_UNDEFINED.
|
||||
*
|
||||
* Since: 0.10.4
|
||||
*/
|
||||
void
|
||||
gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format)
|
||||
{
|
||||
GstStructure *structure;
|
||||
|
||||
g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
|
||||
|
||||
if (format) {
|
||||
const GValue *list;
|
||||
|
||||
structure = gst_query_get_structure (query);
|
||||
list = gst_structure_get_value (structure, "formats");
|
||||
if (list == NULL) {
|
||||
*format = GST_FORMAT_UNDEFINED;
|
||||
} else {
|
||||
if (nth < gst_value_list_get_size (list)) {
|
||||
*format = g_value_get_enum (gst_value_list_get_value (list, nth));
|
||||
} else
|
||||
*format = GST_FORMAT_UNDEFINED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,7 +244,11 @@ void gst_query_parse_seeking (GstQuery *query, GstFormat *for
|
|||
gint64 *segment_start,
|
||||
gint64 *segment_end);
|
||||
|
||||
GstQuery* gst_query_new_formats (void);
|
||||
void gst_query_set_formats (GstQuery *query, gint n_formats, ...);
|
||||
void gst_query_set_formatsv (GstQuery *query, gint n_formats, GstFormat *formats);
|
||||
void gst_query_parse_formats_length (GstQuery *query, guint *n_formats);
|
||||
void gst_query_parse_formats_nth (GstQuery *query, guint nth, GstFormat *format);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -21,6 +21,109 @@
|
|||
|
||||
|
||||
#include <gst/check/gstcheck.h>
|
||||
GST_START_TEST (create_queries)
|
||||
{
|
||||
GstQuery *query;
|
||||
|
||||
/* POSITION */
|
||||
{
|
||||
GstFormat format;
|
||||
gint64 position;
|
||||
|
||||
query = gst_query_new_position (GST_FORMAT_TIME);
|
||||
fail_if (query == NULL);
|
||||
fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
|
||||
|
||||
gst_query_parse_position (query, &format, NULL);
|
||||
fail_if (format != GST_FORMAT_TIME);
|
||||
|
||||
gst_query_set_position (query, GST_FORMAT_TIME, 0xdeadbeaf);
|
||||
|
||||
gst_query_parse_position (query, &format, &position);
|
||||
fail_if (format != GST_FORMAT_TIME);
|
||||
fail_if (position != 0xdeadbeaf);
|
||||
|
||||
gst_query_unref (query);
|
||||
}
|
||||
/* DURATION */
|
||||
{
|
||||
GstFormat format;
|
||||
gint64 duration;
|
||||
|
||||
query = gst_query_new_duration (GST_FORMAT_TIME);
|
||||
fail_if (query == NULL);
|
||||
fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
|
||||
|
||||
gst_query_parse_duration (query, &format, NULL);
|
||||
fail_if (format != GST_FORMAT_TIME);
|
||||
|
||||
gst_query_set_duration (query, GST_FORMAT_TIME, 0xdeadbeaf);
|
||||
|
||||
gst_query_parse_duration (query, &format, &duration);
|
||||
fail_if (format != GST_FORMAT_TIME);
|
||||
fail_if (duration != 0xdeadbeaf);
|
||||
|
||||
gst_query_unref (query);
|
||||
}
|
||||
{
|
||||
/* FIXME make tests for:
|
||||
*
|
||||
* LATENCY
|
||||
* JITTER
|
||||
* RATE
|
||||
* SEEKING
|
||||
* SEGMENT
|
||||
* CONVERT
|
||||
*/
|
||||
}
|
||||
|
||||
/* FORMATS */
|
||||
{
|
||||
guint size;
|
||||
GstFormat format;
|
||||
|
||||
query = gst_query_new_formats ();
|
||||
fail_if (query == NULL);
|
||||
fail_unless (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
|
||||
|
||||
gst_query_parse_formats_length (query, &size);
|
||||
fail_if (size != 0);
|
||||
|
||||
gst_query_parse_formats_nth (query, 0, &format);
|
||||
fail_if (format != GST_FORMAT_UNDEFINED);
|
||||
gst_query_parse_formats_nth (query, 1, &format);
|
||||
fail_if (format != GST_FORMAT_UNDEFINED);
|
||||
|
||||
gst_query_set_formats (query, 2, GST_FORMAT_TIME, GST_FORMAT_BYTES);
|
||||
|
||||
gst_query_parse_formats_length (query, &size);
|
||||
fail_if (size != 2);
|
||||
|
||||
format = GST_FORMAT_UNDEFINED;
|
||||
|
||||
gst_query_parse_formats_nth (query, 0, &format);
|
||||
fail_if (format != GST_FORMAT_TIME);
|
||||
gst_query_parse_formats_nth (query, 1, &format);
|
||||
fail_if (format != GST_FORMAT_BYTES);
|
||||
|
||||
/* out of bounds, should return UNDEFINED */
|
||||
gst_query_parse_formats_nth (query, 2, &format);
|
||||
fail_if (format != GST_FORMAT_UNDEFINED);
|
||||
|
||||
gst_query_set_formats (query, 3, GST_FORMAT_TIME, GST_FORMAT_BYTES,
|
||||
GST_FORMAT_PERCENT);
|
||||
|
||||
gst_query_parse_formats_length (query, &size);
|
||||
fail_if (size != 3);
|
||||
|
||||
gst_query_parse_formats_nth (query, 2, &format);
|
||||
fail_if (format != GST_FORMAT_PERCENT);
|
||||
|
||||
gst_query_unref (query);
|
||||
}
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_queries)
|
||||
{
|
||||
|
@ -103,6 +206,7 @@ gstquery_suite (void)
|
|||
tcase_set_timeout (tc_chain, 20);
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, create_queries);
|
||||
tcase_add_test (tc_chain, test_queries);
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue