Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- static gboolean
- timeout_cb (gpointer user_data);
- static gboolean
- bus_cb (GstBus * bus, GstMessage * msg, gpointer user_data);
- static gboolean
- timeout_cb (gpointer user_data)
- {
- g_print("timeout callback is called \n");
- GstElement *interpipesrc = (GstElement *) user_data;
- g_object_set (interpipesrc, "listen-to", "interpipesink2", NULL);
- return TRUE;
- }
- static gboolean
- bus_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
- {
- GMainLoop *loop = user_data;
- switch (GST_MESSAGE_TYPE (msg)) {
- case GST_MESSAGE_ERROR:{
- GError *err = NULL;
- gchar *dbg;
- gst_message_parse_error (msg, &err, &dbg);
- gst_object_default_error (msg->src, err, dbg);
- g_clear_error (&err);
- g_free (dbg);
- g_main_loop_quit (loop);
- break;
- }
- default:
- break;
- }
- return TRUE;
- }
- int main(int argc, char *argv[]) {
- GstElement *pipeline1, *source1, *interpipesink1;
- GstElement *pipeline2, *source2, *interpipesink2;
- GstElement *pipeline, *interpipesrc, *sink;
- GstBus *bus;
- GstMessage *msg;
- GstStateChangeReturn ret;
- GMainLoop *loop;
- /* Initialize GStreamer */
- gst_init (&argc, &argv);
- /* Create the elements */
- source1 = gst_element_factory_make ("videotestsrc", "source1");
- g_object_set (source1, "pattern", 18, NULL);
- g_object_set (source1, "is-live", TRUE, NULL);
- interpipesink1 = gst_element_factory_make("interpipesink", "interpipesink1");
- /* Create the empty pipeline */
- pipeline1 = gst_pipeline_new ("test-pipeline1");
- if (!pipeline1 || !source1 || !interpipesink1) {
- g_printerr ("Not all elements could be created.\n");
- return -1;
- }
- /* Build the pipeline */
- gst_bin_add_many (GST_BIN (pipeline1), source1, interpipesink1, NULL);
- if (gst_element_link (source1, interpipesink1) != TRUE) {
- g_printerr ("Elements could not be linked.\n");
- gst_object_unref (pipeline1);
- return -1;
- }
- /* Create the elements */
- source2 = gst_element_factory_make ("videotestsrc", "source2");
- g_object_set (source2, "pattern", 12, NULL);
- g_object_set (source2, "is-live", TRUE, NULL);
- interpipesink2 = gst_element_factory_make("interpipesink", "interpipesink2");
- /* Create the empty pipeline */
- pipeline2 = gst_pipeline_new ("test-pipeline2");
- if (!pipeline2 || !source2 || !interpipesink2) {
- g_printerr ("Not all elements could be created.\n");
- return -1;
- }
- /* Build the pipeline */
- gst_bin_add_many (GST_BIN (pipeline2), source2, interpipesink2, NULL);
- if (gst_element_link (source2, interpipesink2) != TRUE) {
- g_printerr ("Elements could not be linked.\n");
- gst_object_unref (pipeline1);
- return -1;
- }
- pipeline = gst_pipeline_new ("feed-pipeline");
- interpipesrc = gst_element_factory_make ("interpipesrc", "interpipesrc");
- g_object_set (interpipesrc, "listen-to", "interpipesink1", NULL);
- g_object_set(interpipesrc, "is-live", TRUE, "allow-renegotiation", TRUE, "stream-sync", 2, NULL);
- g_object_set(interpipesrc, "max-buffers", 200, "leaky-type", 2, NULL);
- sink = gst_element_factory_make ("autovideosink", "sink");
- // Build feed pipeline
- gst_bin_add_many (GST_BIN (pipeline), interpipesrc, sink, NULL);
- if (gst_element_link (interpipesrc, sink) != TRUE) {
- g_printerr ("Elements could not be linked.\n");
- gst_object_unref (pipeline1);
- return -1;
- }
- /* Start playing */
- ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr ("Unable to set the pipeline to the playing state.\n");
- gst_object_unref (pipeline);
- return -1;
- }
- ret = gst_element_set_state (pipeline1, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr ("Unable to set the pipeline to the playing state.\n");
- gst_object_unref (pipeline1);
- return -1;
- }
- ret = gst_element_set_state (pipeline2, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr ("Unable to set the pipeline to the playing state.\n");
- gst_object_unref (pipeline2);
- return -1;
- }
- loop = g_main_loop_new (NULL, FALSE);
- gst_bus_add_watch (GST_ELEMENT_BUS (pipeline), bus_cb, loop);
- g_print("scheduling timeout every 20 seconds.\n");
- g_timeout_add_seconds(20, timeout_cb, interpipesrc);
- g_main_loop_run (loop);
- /* Wait until error or EOS */
- // bus = gst_element_get_bus (pipeline);
- // msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
- /* Free resources */
- gst_object_unref (bus);
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_element_set_state (pipeline1, GST_STATE_NULL);
- gst_element_set_state (pipeline2, GST_STATE_NULL);
- gst_object_unref (pipeline);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement