From cbafc0d49b7fe2b13417bdde8738b3815372e4c0 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Tue, 4 May 2004 02:33:41 +0000 Subject: [PATCH] testsuite/caps/renegotiate.c: Another test. Original commit message from CVS: * testsuite/caps/renegotiate.c: (my_fixate), (main): Another test. --- ChangeLog | 4 ++ tests/old/testsuite/caps/renegotiate.c | 108 +++++++++++++++++++++++++++++++++ testsuite/caps/renegotiate.c | 108 +++++++++++++++++++++++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 tests/old/testsuite/caps/renegotiate.c create mode 100644 testsuite/caps/renegotiate.c diff --git a/ChangeLog b/ChangeLog index d797f25..dafee18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2004-05-03 David Schleef + * testsuite/caps/renegotiate.c: (my_fixate), (main): Another test. + +2004-05-03 David Schleef + * testsuite/caps/deserialize.c: (main): Use the srcdir environment variable to find our source file. diff --git a/tests/old/testsuite/caps/renegotiate.c b/tests/old/testsuite/caps/renegotiate.c new file mode 100644 index 0000000..797b7d6 --- /dev/null +++ b/tests/old/testsuite/caps/renegotiate.c @@ -0,0 +1,108 @@ + +#include +#include + +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_free (icaps); + g_print ("returning %d\n", rate); + return gst_caps_copy (mycaps); + } + gst_caps_free (icaps); + } + + return NULL; +} + +int +main (int argc, char *argv[]) +{ + GstElement *pipeline; + const GList *list; + const GList *l2; + int i; + int ret; + + gst_init (&argc, &argv); + + pipeline = gst_parse_launch ("sinesrc ! audioconvert ! " + "audio/x-raw-int, channels=2, rate=48000;" + "audio/x-raw-int, channels=1, rate=44100 !" "fakesink", NULL); + + list = gst_bin_get_list (GST_BIN (pipeline)); + while (list) { + GstElement *element = GST_ELEMENT (list->data); + + l2 = gst_element_get_pad_list (element); + while (l2) { + GstPad *pad = GST_PAD (l2->data); + + if (gst_pad_get_direction (pad) == GST_PAD_SRC) { + g_signal_connect (G_OBJECT (pad), "fixate", G_CALLBACK (my_fixate), + NULL); + } + l2 = g_list_next (l2); + } + list = g_list_next (list); + } + + 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); + } + } + + return 0; +} diff --git a/testsuite/caps/renegotiate.c b/testsuite/caps/renegotiate.c new file mode 100644 index 0000000..797b7d6 --- /dev/null +++ b/testsuite/caps/renegotiate.c @@ -0,0 +1,108 @@ + +#include +#include + +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_free (icaps); + g_print ("returning %d\n", rate); + return gst_caps_copy (mycaps); + } + gst_caps_free (icaps); + } + + return NULL; +} + +int +main (int argc, char *argv[]) +{ + GstElement *pipeline; + const GList *list; + const GList *l2; + int i; + int ret; + + gst_init (&argc, &argv); + + pipeline = gst_parse_launch ("sinesrc ! audioconvert ! " + "audio/x-raw-int, channels=2, rate=48000;" + "audio/x-raw-int, channels=1, rate=44100 !" "fakesink", NULL); + + list = gst_bin_get_list (GST_BIN (pipeline)); + while (list) { + GstElement *element = GST_ELEMENT (list->data); + + l2 = gst_element_get_pad_list (element); + while (l2) { + GstPad *pad = GST_PAD (l2->data); + + if (gst_pad_get_direction (pad) == GST_PAD_SRC) { + g_signal_connect (G_OBJECT (pad), "fixate", G_CALLBACK (my_fixate), + NULL); + } + l2 = g_list_next (l2); + } + list = g_list_next (list); + } + + 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); + } + } + + return 0; +} -- 2.7.4