summaryrefslogtreecommitdiffstats
path: root/examples/negotiation/queue.c
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2004-12-20 17:54:16 +0000
committerWim Taymans <wim.taymans@gmail.com>2004-12-20 17:54:16 +0000
commit1a293825c71a0803c9032f357f934aee6b54fe79 (patch)
treeb31779cc6a7142a781d7a782e9aa92766a5a6d6a /examples/negotiation/queue.c
parent4ad298d6806a7130c64fce65bf3aa3f7313bba8d (diff)
downloadgst-plugins-bad-1a293825c71a0803c9032f357f934aee6b54fe79.tar.gz
gst-plugins-bad-1a293825c71a0803c9032f357f934aee6b54fe79.tar.bz2
gst-plugins-bad-1a293825c71a0803c9032f357f934aee6b54fe79.zip
Various plugin updates to have something to play with.
Original commit message from CVS: Various plugin updates to have something to play with.
Diffstat (limited to 'examples/negotiation/queue.c')
-rw-r--r--examples/negotiation/queue.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/examples/negotiation/queue.c b/examples/negotiation/queue.c
new file mode 100644
index 00000000..c7903d9e
--- /dev/null
+++ b/examples/negotiation/queue.c
@@ -0,0 +1,147 @@
+/*
+ * queue.c
+ *
+ * demo application for negotiation over queues.
+ */
+
+#include <string.h>
+#include <gtk/gtk.h>
+#include <gst/gst.h>
+
+static GstElement *pipeline;
+static GstElement *src;
+static GstElement *queue;
+static GstElement *sink;
+
+static GstPad *pad1, *peer1;
+static GstPad *pad2, *peer2;
+
+static gboolean caught_error = FALSE;
+static GMainLoop *loop;
+
+static gboolean
+message_received (GstBus * bus, GstMessage * message, gpointer data)
+{
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_EOS:
+ if (g_main_loop_is_running (loop))
+ g_main_loop_quit (loop);
+ break;
+ case GST_MESSAGE_ERROR:
+ gst_object_default_error (GST_MESSAGE_SRC (message),
+ GST_MESSAGE_ERROR_GERROR (message),
+ GST_MESSAGE_ERROR_DEBUG (message));
+ caught_error = TRUE;
+ if (g_main_loop_is_running (loop))
+ g_main_loop_quit (loop);
+ break;
+ default:
+ break;
+ }
+ gst_message_unref (message);
+
+ return TRUE;
+}
+
+static void
+block_done (GstPad * pad, gboolean blocked, gpointer data)
+{
+ if (blocked) {
+ g_print ("pad blocked\n");
+ /* let's unlink to be cool too */
+ gst_pad_unlink (pad2, peer2);
+ } else {
+ g_print ("pad unblocked\n");
+ }
+}
+
+static gboolean
+do_block (GstPipeline * pipeline)
+{
+ static gint iter = 0;
+
+
+ if (iter++ % 2) {
+ g_print ("blocking pad..");
+ if (!gst_pad_set_blocked_async (pad2, TRUE, block_done, NULL))
+ g_print ("was blocked\n");
+ } else {
+ /* and relink */
+ gst_pad_link (pad2, peer2);
+ g_print ("unblocking pad..");
+ if (!gst_pad_set_blocked_async (pad2, FALSE, block_done, NULL))
+ g_print ("was unblocked\n");
+ }
+ return TRUE;
+}
+
+static gboolean
+do_renegotiate (GstPipeline * pipeline)
+{
+ GstCaps *caps;
+ static gint iter = 0;
+
+ g_print ("reneg\n");
+
+ if (iter++ % 2) {
+ caps = gst_caps_new_simple ("video/x-raw-yuv",
+ "format", GST_TYPE_FOURCC, GST_STR_FOURCC ("I420"),
+ "width", G_TYPE_INT, 320,
+ "height", G_TYPE_INT, 240, "framerate", G_TYPE_DOUBLE, 5.0, NULL);
+ } else {
+ caps = gst_caps_new_simple ("video/x-raw-yuv",
+ "format", GST_TYPE_FOURCC, GST_STR_FOURCC ("YUY2"),
+ "width", G_TYPE_INT, 240,
+ "height", G_TYPE_INT, 120, "framerate", G_TYPE_DOUBLE, 30.0, NULL);
+ }
+
+ gst_pad_relink_filtered (pad1, peer1, caps);
+ gst_caps_unref (caps);
+
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GstBus *bus;
+
+ gtk_init (&argc, &argv);
+ gst_init (&argc, &argv);
+
+ pipeline = gst_pipeline_new ("pipeline");
+ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+ loop = g_main_loop_new (NULL, FALSE);
+ gst_bus_add_watch (bus, message_received, pipeline);
+
+ src = gst_element_factory_make ("videotestsrc", "src");
+ queue = gst_element_factory_make ("queue", "queue");
+ sink = gst_element_factory_make ("xvimagesink", "sink");
+
+ gst_bin_add (GST_BIN (pipeline), src);
+ gst_bin_add (GST_BIN (pipeline), queue);
+ gst_bin_add (GST_BIN (pipeline), sink);
+
+ pad1 = gst_element_get_pad (src, "src");
+ peer1 = gst_element_get_pad (queue, "sink");
+
+ pad2 = gst_element_get_pad (queue, "src");
+ peer2 = gst_element_get_pad (sink, "sink");
+
+ gst_pad_link (pad1, peer1);
+ gst_pad_link (pad2, peer2);
+
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+
+ g_timeout_add (1000, (GSourceFunc) do_block, pipeline);
+
+ g_main_loop_run (loop);
+
+ g_timeout_add (200, (GSourceFunc) do_renegotiate, pipeline);
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+
+ gst_object_unref (GST_OBJECT (pipeline));
+
+ return 0;
+}