gstreamer/testsuite/caps/renegotiate.c
Andy Wingo 7c0804b15c testsuite/caps/value_serialize.c: merge from HEAD.
Original commit message from CVS:
2005-02-10  Andy Wingo  <wingo@pobox.com>

* testsuite/caps/value_serialize.c: merge from HEAD.

* testsuite/caps/subtract.c:
* testsuite/caps/filtercaps.c:
* testsuite/caps/enumcaps.c:
* testsuite/caps/deserialize.c:
* testsuite/caps/caps.c:
* testsuite/caps/audioscale.c: Unref caps, not free.

* testsuite/caps/caps_strings: Merged from HEAD.

* gst/elements/gstidentity.c (gst_identity_proxy_getcaps): Getcaps
implementation for identity.

* gst/gststructure.h
* gst/gststructure.c
(gst_caps_structure_fixate_field_nearest_double):
(gst_caps_structure_fixate_field_nearest_int): Moved from
gstcaps.c because we need the private IS_MUTABLE macro.
(IS_MUTABLE): New macro, determines if a
structure is mutable or not.
(gst_structure_free): Don't allow free while holding a pointer to
a parent's refcount.
(gst_structure_set_name): Check for writability.
(gst_structure_id_set_value): Same.
(gst_structure_set_value): Same.
(gst_structure_set_valist): Same.
(gst_structure_remove_field): Same.
(gst_structure_remove_all_fields): Same.
(gst_structure_map_in_place): New routine, like _foreach but
allows the function to mutate the value (via a non-const
prototype). Check for writability.
(gst_structure_foreach): Redefine to only take non-mutating
functions.

* gst/gstcaps.c (IS_WRITABLE): New macro, returns TRUE if the caps
are writable.
(gst_caps_copy): Add some docs about mutability, etc.
(_gst_caps_free): Set the parent refcount pointer on structures to
NULL before freeing them.
(gst_caps_ref): Document.
(gst_caps_make_writable): Doc.
(gst_caps_make_writable): Changed to make_writable, get_writable
sounds too much like retrieving a property.
(gst_caps_copy_1): Removed, not very useful.
(gst_caps_ref_by_count): Removed, no need to have something GLib
doesn't.
(gst_caps_copy_conditional): Ref instead of copying.
(gst_static_caps_get): Retain a reference to the returned caps, so
that the static caps will remain immutable.
(gst_caps_remove_and_get_structure): Set the parent refcount to
NULL when removing the structure.
(gst_caps_append): Fix to work with structure parent refcounts.
Check for writability.
(gst_caps_append_structure): Check for writability, work with
parent refcounts.
(gst_caps_remove_structure): Check for writability.
(gst_caps_set_simple): Check for writability.
(gst_caps_set_simple_valist): Check for writability.
(gst_caps_is_fixed_foreach): Update for non-mutating foreach.
(gst_structure_is_equal_foreach): Same.
(gst_caps_structure_intersect_field): Same.
(gst_caps_structure_subtract_field): Same. Make static.
(gst_caps_normalize_foreach): Same.
(gst_caps_structure_figure_out_union): Same.
(gst_caps_switch_structures): New static function, switches out
structures inside a caps, taking care of parent_refcount setting.

* gst/gstpad.c (gst_pad_get_allowed_caps): Remove the restriction
on only src pads, wim von masterhack claims it was bogus.

* testsuite/caps/Makefile.am
* testsuite/caps/app_fixate.c: Removed app_fixate test, things are
done a bit differently in THREADED.
2005-02-10 19:40:23 +00:00

150 lines
3.7 KiB
C

#include <gst/gst.h>
#include <string.h>
#include <unistd.h>
static GstPad *sinesrcpad;
static GstStaticCaps caps1 = GST_STATIC_CAPS ("audio/x-raw-int, "
"endianness=(int)1234, "
"signed=(boolean)true, "
"width=(int)16, " "depth=(int)16, " "rate=(int)48000, " "channels=(int)1");
static GstStaticCaps caps2 = GST_STATIC_CAPS ("audio/x-raw-int, "
"endianness=(int)1234, "
"signed=(boolean)true, "
"width=(int)16, " "depth=(int)16, " "rate=(int)44100, " "channels=(int)1");
int stage = 0;
static GstCaps *
my_fixate (GstPad * pad, GstCaps * caps, gpointer user_data)
{
const char *element_name;
const char *pad_name;
element_name = gst_element_get_name (gst_pad_get_parent (pad));
pad_name = gst_pad_get_name (pad);
g_print ("%s:%s: %s\n", element_name, pad_name, gst_caps_to_string (caps));
if (strcmp (element_name, "sinesrc0") == 0 && strcmp (pad_name, "src") == 0) {
GstCaps *icaps;
const GstCaps *mycaps;
int rate;
sinesrcpad = pad;
if (stage == 0) {
mycaps = gst_static_caps_get (&caps1);
rate = 48000;
} else {
mycaps = gst_static_caps_get (&caps2);
rate = 44100;
}
icaps = gst_caps_intersect (caps, mycaps);
if (!gst_caps_is_empty (icaps)) {
gst_caps_unref (icaps);
g_print ("returning %d\n", rate);
return gst_caps_copy (mycaps);
}
gst_caps_unref (icaps);
}
return NULL;
}
int
main (int argc, char *argv[])
{
GstElement *pipeline;
GError *error = NULL;
GstIterator *iter1, *iter2;
gint done1 = FALSE, done2 = FALSE;
gpointer element;
gst_init (&argc, &argv);
/* change sinesrk to sinesrc once gst_parse_launch is fixed */
pipeline = gst_parse_launch ("sinesrc ! audioconvert ! "
"audio/x-raw-int, channels=2, rate=48000;"
"audio/x-raw-int, channels=1, rate=44100 !" "fakesink", &error);
if (error != NULL) {
g_print
("oops, couldn't build pipeline. You probably don't have audioconvert or sinesrc\n"
"the error was: %s\n", error->message);
g_error_free (error);
exit (0);
}
iter1 = gst_bin_iterate_elements (GST_BIN (pipeline));
while (!done1) {
switch (gst_iterator_next (iter1, &element)) {
case GST_ITERATOR_OK:
{
gpointer pad;
iter2 = gst_element_iterate_pads (element);
while (!done2) {
switch (gst_iterator_next (iter2, &pad)) {
case GST_ITERATOR_OK:
if (gst_pad_get_direction (pad) == GST_PAD_SRC) {
g_signal_connect (G_OBJECT (pad), "fixate",
G_CALLBACK (my_fixate), NULL);
}
gst_object_unref (pad);
break;
case GST_ITERATOR_DONE:
done2 = TRUE;
break;
case GST_ITERATOR_RESYNC:
case GST_ITERATOR_ERROR:
exit (1);
break;
}
}
gst_iterator_free (iter2);
gst_object_unref (element);
break;
}
case GST_ITERATOR_DONE:
done1 = TRUE;
break;
case GST_ITERATOR_RESYNC:
case GST_ITERATOR_ERROR:
exit (1);
break;
}
}
gst_iterator_free (iter1);
/*g_signal_connect (pipeline, "deep_notify",
G_CALLBACK (gst_element_default_deep_notify), NULL); */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/*
i = 0;
while (1) {
gst_bin_iterate (GST_BIN (pipeline));
i++;
if (i == 10) {
stage = 1;
g_print ("10 iterations\n");
ret = gst_pad_renegotiate (sinesrcpad);
g_print ("negotiation returned %d\n", ret);
}
if (i == 20) {
g_print ("20 iterations\n");
exit (0);
}
}
*/
/* Like totally not sure how to do this in THREADED. Punting for now! */
sleep (5);
return 0;
}