Advertisement
Guest User

Untitled

a guest
Nov 24th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 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. g_object_set (source1, "is-live", TRUE, NULL);
  56.  
  57. interpipesink1 = gst_element_factory_make("interpipesink", "interpipesink1");
  58. /* Create the empty pipeline */
  59. pipeline1 = gst_pipeline_new ("test-pipeline1");
  60.  
  61. if (!pipeline1 || !source1 || !interpipesink1) {
  62. g_printerr ("Not all elements could be created.\n");
  63. return -1;
  64. }
  65.  
  66. /* Build the pipeline */
  67. gst_bin_add_many (GST_BIN (pipeline1), source1, interpipesink1, NULL);
  68. if (gst_element_link (source1, interpipesink1) != TRUE) {
  69. g_printerr ("Elements could not be linked.\n");
  70. gst_object_unref (pipeline1);
  71. return -1;
  72. }
  73.  
  74. /* Create the elements */
  75. source2 = gst_element_factory_make ("videotestsrc", "source2");
  76. g_object_set (source2, "pattern", 12, NULL);
  77. g_object_set (source2, "is-live", TRUE, NULL);
  78.  
  79. interpipesink2 = gst_element_factory_make("interpipesink", "interpipesink2");
  80. /* Create the empty pipeline */
  81. pipeline2 = gst_pipeline_new ("test-pipeline2");
  82.  
  83. if (!pipeline2 || !source2 || !interpipesink2) {
  84. g_printerr ("Not all elements could be created.\n");
  85. return -1;
  86. }
  87.  
  88. /* Build the pipeline */
  89. gst_bin_add_many (GST_BIN (pipeline2), source2, interpipesink2, NULL);
  90. if (gst_element_link (source2, interpipesink2) != TRUE) {
  91. g_printerr ("Elements could not be linked.\n");
  92. gst_object_unref (pipeline1);
  93. return -1;
  94. }
  95.  
  96. pipeline = gst_pipeline_new ("feed-pipeline");
  97. interpipesrc = gst_element_factory_make ("interpipesrc", "interpipesrc");
  98. g_object_set (interpipesrc, "listen-to", "interpipesink1", NULL);
  99. g_object_set(interpipesrc, "is-live", TRUE, "allow-renegotiation", TRUE, "stream-sync", 2, NULL);
  100. g_object_set(interpipesrc, "max-buffers", 200, "leaky-type", 2, NULL);
  101. sink = gst_element_factory_make ("autovideosink", "sink");
  102.  
  103.  
  104. // Build feed pipeline
  105. gst_bin_add_many (GST_BIN (pipeline), interpipesrc, sink, NULL);
  106. if (gst_element_link (interpipesrc, sink) != TRUE) {
  107. g_printerr ("Elements could not be linked.\n");
  108. gst_object_unref (pipeline1);
  109. return -1;
  110. }
  111.  
  112. /* Start playing */
  113. ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
  114. if (ret == GST_STATE_CHANGE_FAILURE) {
  115. g_printerr ("Unable to set the pipeline to the playing state.\n");
  116. gst_object_unref (pipeline);
  117. return -1;
  118. }
  119.  
  120. ret = gst_element_set_state (pipeline1, GST_STATE_PLAYING);
  121. if (ret == GST_STATE_CHANGE_FAILURE) {
  122. g_printerr ("Unable to set the pipeline to the playing state.\n");
  123. gst_object_unref (pipeline1);
  124. return -1;
  125. }
  126.  
  127. ret = gst_element_set_state (pipeline2, GST_STATE_PLAYING);
  128. if (ret == GST_STATE_CHANGE_FAILURE) {
  129. g_printerr ("Unable to set the pipeline to the playing state.\n");
  130. gst_object_unref (pipeline2);
  131. return -1;
  132. }
  133.  
  134. loop = g_main_loop_new (NULL, FALSE);
  135.  
  136. gst_bus_add_watch (GST_ELEMENT_BUS (pipeline), bus_cb, loop);
  137.  
  138. g_print("scheduling timeout every 20 seconds.\n");
  139. g_timeout_add_seconds(20, timeout_cb, interpipesrc);
  140.  
  141. g_main_loop_run (loop);
  142.  
  143. /* Wait until error or EOS */
  144. // bus = gst_element_get_bus (pipeline);
  145. // msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
  146.  
  147. /* Free resources */
  148. gst_object_unref (bus);
  149. gst_element_set_state (pipeline, GST_STATE_NULL);
  150. gst_element_set_state (pipeline1, GST_STATE_NULL);
  151. gst_element_set_state (pipeline2, GST_STATE_NULL);
  152.  
  153. gst_object_unref (pipeline);
  154. return 0;
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement