Guest User

Untitled

a guest
Nov 24th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. #include <gst/gst.h>
  2.  
  3.  
  4. static gboolean
  5. timeout_cb (gpointer user_data);
  6.  
  7. static gboolean
  8. bus_cb (GstBus * bus, GstMessage * msg, gpointer user_data);
  9. static gboolean
  10. timeout_cb (gpointer user_data)
  11. {
  12. g_print("timeout callback is called \n");
  13. GstElement *interpipesrc = (GstElement *) user_data;
  14. g_object_set (interpipesrc, "listen-to", "interpipesink2", NULL);
  15. return TRUE;
  16. }
  17.  
  18. static gboolean
  19. bus_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
  20. {
  21. GMainLoop *loop = user_data;
  22. switch (GST_MESSAGE_TYPE (msg)) {
  23. case GST_MESSAGE_ERROR:{
  24. GError *err = NULL;
  25. gchar *dbg;
  26.  
  27. gst_message_parse_error (msg, &err, &dbg);
  28. gst_object_default_error (msg->src, err, dbg);
  29. g_clear_error (&err);
  30. g_free (dbg);
  31. g_main_loop_quit (loop);
  32. break;
  33. }
  34. default:
  35. break;
  36. }
  37. return TRUE;
  38. }
  39.  
  40. int main(int argc, char *argv[]) {
  41. GstElement *pipeline1, *source1, *interpipesink1;
  42. GstElement *pipeline2, *source2, *interpipesink2;
  43. GstElement *pipeline, *interpipesrc, *sink;
  44. GstBus *bus;
  45. GstMessage *msg;
  46. GstStateChangeReturn ret;
  47. GMainLoop *loop;
  48.  
  49. /* Initialize GStreamer */
  50. gst_init (&argc, &argv);
  51.  
  52. /* Create the elements */
  53. source1 = gst_element_factory_make ("videotestsrc", "source1");
  54. g_object_set (source1, "pattern", 18, NULL);
  55.  
  56. interpipesink1 = gst_element_factory_make("interpipesink", "interpipesink1");
  57. /* Create the empty pipeline */
  58. pipeline1 = gst_pipeline_new ("test-pipeline1");
  59.  
  60. if (!pipeline1 || !source1 || !interpipesink1) {
  61. g_printerr ("Not all elements could be created.\n");
  62. return -1;
  63. }
  64.  
  65. /* Build the pipeline */
  66. gst_bin_add_many (GST_BIN (pipeline1), source1, interpipesink1, NULL);
  67. if (gst_element_link (source1, interpipesink1) != TRUE) {
  68. g_printerr ("Elements could not be linked.\n");
  69. gst_object_unref (pipeline1);
  70. return -1;
  71. }
  72.  
  73. /* Create the elements */
  74. source2 = gst_element_factory_make ("videotestsrc", "source2");
  75. g_object_set (source2, "pattern", 12, NULL);
  76.  
  77. interpipesink2 = gst_element_factory_make("interpipesink", "interpipesink2");
  78. /* Create the empty pipeline */
  79. pipeline2 = gst_pipeline_new ("test-pipeline2");
  80.  
  81. if (!pipeline2 || !source2 || !interpipesink2) {
  82. g_printerr ("Not all elements could be created.\n");
  83. return -1;
  84. }
  85.  
  86. /* Build the pipeline */
  87. gst_bin_add_many (GST_BIN (pipeline2), source2, interpipesink2, NULL);
  88. if (gst_element_link (source2, interpipesink2) != TRUE) {
  89. g_printerr ("Elements could not be linked.\n");
  90. gst_object_unref (pipeline1);
  91. return -1;
  92. }
  93.  
  94. pipeline = gst_pipeline_new ("feed-pipeline");
  95. interpipesrc = gst_element_factory_make ("interpipesrc", "interpipesrc");
  96. g_object_set (interpipesrc, "listen-to", "interpipesink2", NULL);
  97. g_object_set(interpipesrc, "is-live", TRUE, "allow-renegotiation", TRUE, "stream-sync", 2, NULL);
  98. sink = gst_element_factory_make ("autovideosink", "sink");
  99.  
  100.  
  101. // Build feed pipeline
  102. gst_bin_add_many (GST_BIN (pipeline), interpipesrc, sink, NULL);
  103. if (gst_element_link (interpipesrc, sink) != TRUE) {
  104. g_printerr ("Elements could not be linked.\n");
  105. gst_object_unref (pipeline1);
  106. return -1;
  107. }
  108.  
  109. /* Start playing */
  110. ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
  111. if (ret == GST_STATE_CHANGE_FAILURE) {
  112. g_printerr ("Unable to set the pipeline to the playing state.\n");
  113. gst_object_unref (pipeline);
  114. return -1;
  115. }
  116.  
  117. ret = gst_element_set_state (pipeline1, GST_STATE_PLAYING);
  118. if (ret == GST_STATE_CHANGE_FAILURE) {
  119. g_printerr ("Unable to set the pipeline to the playing state.\n");
  120. gst_object_unref (pipeline1);
  121. return -1;
  122. }
  123.  
  124. ret = gst_element_set_state (pipeline2, GST_STATE_PLAYING);
  125. if (ret == GST_STATE_CHANGE_FAILURE) {
  126. g_printerr ("Unable to set the pipeline to the playing state.\n");
  127. gst_object_unref (pipeline2);
  128. return -1;
  129. }
  130.  
  131. loop = g_main_loop_new (NULL, FALSE);
  132.  
  133. gst_bus_add_watch (GST_ELEMENT_BUS (pipeline), bus_cb, loop);
  134.  
  135. g_print("scheduling timeout every 20 seconds.\n");
  136. g_timeout_add_seconds(20, timeout_cb, interpipesrc);
  137.  
  138. g_main_loop_run (loop);
  139.  
  140. /* Wait until error or EOS */
  141. // bus = gst_element_get_bus (pipeline);
  142. // msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
  143.  
  144. /* Free resources */
  145. gst_object_unref (bus);
  146. gst_element_set_state (pipeline, GST_STATE_NULL);
  147. gst_element_set_state (pipeline1, GST_STATE_NULL);
  148. gst_element_set_state (pipeline2, GST_STATE_NULL);
  149.  
  150. gst_object_unref (pipeline);
  151. return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment