From 1a293825c71a0803c9032f357f934aee6b54fe79 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Dec 2004 17:54:16 +0000 Subject: Various plugin updates to have something to play with. Original commit message from CVS: Various plugin updates to have something to play with. --- examples/negotiation/Makefile.am | 7 ++ examples/negotiation/colorspace.c | 97 +++++++++++++++++++++++++ examples/negotiation/queue.c | 147 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 examples/negotiation/Makefile.am create mode 100644 examples/negotiation/colorspace.c create mode 100644 examples/negotiation/queue.c (limited to 'examples') diff --git a/examples/negotiation/Makefile.am b/examples/negotiation/Makefile.am new file mode 100644 index 00000000..ccd7e4b4 --- /dev/null +++ b/examples/negotiation/Makefile.am @@ -0,0 +1,7 @@ +examples = queue colorspace + +noinst_PROGRAMS = $(examples) + +# we have nothing but apps here, we can do this safely +LIBS = $(GST_LIBS) $(GTK_LIBS) $(GST_CONTROL_LIBS) +AM_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) diff --git a/examples/negotiation/colorspace.c b/examples/negotiation/colorspace.c new file mode 100644 index 00000000..b970a1c7 --- /dev/null +++ b/examples/negotiation/colorspace.c @@ -0,0 +1,97 @@ +/* + * colorspace.c + * + * demo application for negotiation of a simple plugin. + */ + +#include +#include + +static GstElement *pipeline; +static GstElement *space; + +static GstPad *src; +static GstPad *sink; +static GstPad *test; + +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 GstFlowReturn +my_chain (GstPad * pad, GstBuffer * buffer) +{ + g_print ("got buffer\n"); + return GST_FLOW_OK; +} + +int +main (int argc, char *argv[]) +{ + GstBus *bus; + GstBuffer *buffer; + + 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); + + space = gst_element_factory_make ("ffmpegcolorspace", "space"); + + gst_bin_add (GST_BIN (pipeline), space); + + sink = gst_element_get_pad (space, "sink"); + src = gst_element_get_pad (space, "src"); + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + test = gst_pad_new ("test", GST_PAD_SINK); + gst_pad_set_chain_function (test, my_chain); + + gst_pad_link (src, test); + gst_pad_set_active (test, TRUE); + + gst_pad_set_caps (sink, + 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)); + + while (g_main_context_iteration (NULL, FALSE)); + + buffer = gst_buffer_new (); + + GST_REAL_PAD (sink)->chainfunc (sink, buffer); + + while (g_main_context_iteration (NULL, FALSE)); + + gst_element_set_state (pipeline, GST_STATE_NULL); + + gst_object_unref (GST_OBJECT (pipeline)); + + return 0; +} 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 +#include +#include + +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; +} -- cgit v1.2.1