Advertisement
Guest User

Untitled

a guest
Aug 8th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.65 KB | None | 0 0
  1. #include <gst/gst.h>
  2.  
  3. static GstElement *common_pipeline;
  4.  
  5. static gboolean bus_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
  6. {
  7.     GMainLoop *loop = user_data;
  8.  
  9.     switch (GST_MESSAGE_TYPE (msg)) {
  10.         case GST_MESSAGE_ERROR:{
  11.             GError *err = NULL;
  12.             gchar *dbg;
  13.  
  14.             gst_message_parse_error (msg, &err, &dbg);
  15.             gst_object_default_error (msg->src, err, dbg);
  16.             g_clear_error (&err);
  17.             g_free (dbg);
  18.             g_main_loop_quit (loop);
  19.             break;
  20.         }
  21.         default:
  22.             break;
  23.     }
  24.     return TRUE;
  25. }
  26.  
  27. int
  28. main (int argc, char **argv)
  29. {
  30.     GstElement *v_src1, *v_convert1, *v_queue1, *ip_sink1;
  31.     GstElement *ip_src, *queue, *videosink;
  32.  
  33.     gst_init(&argc, &argv);
  34.  
  35.     common_pipeline = gst_pipeline_new("main_pipeline");
  36.  
  37.     v_src1 = gst_element_factory_make("videotestsrc", "v_src1");
  38.     v_convert1 = gst_element_factory_make("videoconvert", "v_convert1");
  39.     v_queue1 = gst_element_factory_make("queue", "v_queue1");
  40.     ip_sink1 = gst_element_factory_make("interpipesink", "v_source1");
  41.  
  42.     ip_src = gst_element_factory_make("interpipesrc", "v_sink");
  43.     queue = gst_element_factory_make("queue", "v_queue");
  44.     videosink = gst_element_factory_make("autovideosink", "videosink");
  45.  
  46.     g_object_set(v_src1,
  47.                  "is_live", TRUE,
  48.                  NULL);
  49.     g_object_set(ip_sink1,
  50.                  "sync", FALSE,
  51.                  "async", FALSE,
  52.                  NULL);
  53.     g_object_set(ip_src,
  54.                  "listen-to", "v_source1",
  55.                  "is-live", TRUE,
  56.                  "allow-renegotiation", TRUE,
  57.                  "stream-sync", 2,
  58.                  NULL);
  59.  
  60.     gst_bin_add_many(GST_BIN(common_pipeline),
  61.                      v_src1, v_convert1, v_queue1, ip_sink1,
  62.                      ip_src, queue, videosink,
  63.                      NULL);
  64.     gst_element_link_many(v_src1, v_convert1, v_queue1, ip_sink1, NULL);
  65.     gst_element_link_many(ip_src, queue, videosink, NULL);
  66.  
  67.     GMainLoop *loop = g_main_loop_new (NULL, FALSE);
  68.     gst_element_set_state(common_pipeline, GST_STATE_READY);
  69.  
  70.     GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(common_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "common_pipeline");
  71.  
  72.     gst_element_set_state(common_pipeline, GST_STATE_PLAYING);
  73.     GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(common_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "common_pipeline_playing");
  74.  
  75.     gst_bus_add_watch (GST_ELEMENT_BUS (common_pipeline), bus_cb, loop);
  76.  
  77.     g_main_loop_run (loop);
  78.  
  79.     gst_element_set_state (common_pipeline, GST_STATE_NULL);
  80.     gst_object_unref (common_pipeline);
  81.  
  82.     return 0;
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement