0002-quit-when-pipeline-interrupted.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. diff -Naur a/tools/gst-play.c b/tools/gst-play.c
  2. --- a/tools/gst-play.c 2020-10-26 19:10:32.459882500 +0800
  3. +++ b/tools/gst-play.c 2022-04-07 14:13:15.126395339 +0800
  4. @@ -19,7 +19,6 @@
  5. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  6. * Boston, MA 02110-1301, USA.
  7. */
  8. -
  9. #ifdef HAVE_CONFIG_H
  10. #include "config.h"
  11. #endif
  12. @@ -40,6 +39,9 @@
  13. #include <glib/gprintf.h>
  14. #include "gst-play-kb.h"
  15. +#ifdef G_OS_UNIX
  16. +#include <glib-unix.h>
  17. +#endif
  18. #define VOLUME_STEPS 20
  19. @@ -104,6 +106,31 @@
  20. gdouble rate;
  21. } GstPlay;
  22. +#if defined(G_OS_UNIX)
  23. +static guint signal_watch_intr_id;
  24. +#endif
  25. +
  26. +#if defined(G_OS_UNIX)
  27. +/* As the interrupt handler is dispatched from GMainContext as a GSourceFunc
  28. + * handler, we can react to this by posting a message. */
  29. +static gboolean
  30. +intr_handler (gpointer user_data)
  31. +{
  32. + GstPlay *play = (GstPlay *) user_data;
  33. + gst_print ("handling interrupt.\n");
  34. +
  35. + /* post an application specific message */
  36. + gst_element_post_message (GST_ELEMENT (play->playbin),
  37. + gst_message_new_application (GST_OBJECT (play->playbin),
  38. + gst_structure_new ("GstLaunchInterrupt",
  39. + "message", G_TYPE_STRING, "Pipeline interrupted", NULL)));
  40. +
  41. + /* remove signal handler */
  42. + signal_watch_intr_id = 0;
  43. + return G_SOURCE_REMOVE;
  44. +}
  45. +#endif /* G_OS_UNIX */
  46. +
  47. static gboolean quiet = FALSE;
  48. static gboolean instant_rate_changes = FALSE;
  49. @@ -594,6 +621,24 @@
  50. }
  51. break;
  52. }
  53. + case GST_MESSAGE_APPLICATION:{
  54. + const GstStructure *s;
  55. +
  56. + s = gst_message_get_structure (msg);
  57. +
  58. + if (gst_structure_has_name (s, "GstLaunchInterrupt")) {
  59. + /* this application message is posted when we caught an interrupt and
  60. + * we need to stop the pipeline. */
  61. +
  62. + gst_print (_("Interrupt: GST_MESSAGE_APPLICATION ...\n"));
  63. + if (play->desired_state == GST_STATE_PLAYING){
  64. + gst_print (_("Interrupt: Stopping pipeline ...\n"));
  65. + g_main_loop_quit (play->loop);
  66. + }
  67. +
  68. + }
  69. + break;
  70. + }
  71. default:
  72. if (gst_is_missing_plugin_message (msg)) {
  73. gchar *desc;
  74. @@ -1622,6 +1667,12 @@
  75. }
  76. }
  77. +#ifdef G_OS_UNIX
  78. + gst_print("g_source_remove signal_watch_intr_id \n");
  79. + signal_watch_intr_id =
  80. + g_unix_signal_add (SIGINT, (GSourceFunc) intr_handler, play);
  81. +#endif
  82. +
  83. /* play */
  84. do_play (play);
  85. @@ -1632,6 +1683,14 @@
  86. g_free (video_sink);
  87. gst_print ("\n");
  88. +
  89. +#ifdef G_OS_UNIX
  90. + if (signal_watch_intr_id > 0){
  91. + gst_print("g_source_remove signal_watch_intr_id \n");
  92. + g_source_remove (signal_watch_intr_id);
  93. + }
  94. +#endif
  95. +
  96. gst_deinit ();
  97. return 0;
  98. }