0001-quit-when-pipeline-interrupted.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. diff -Naur a/tools/gst-play.c b/tools/gst-play.c
  2. --- a/tools/gst-play.c 2021-08-23 21:24:52.832142074 +0800
  3. +++ b/tools/gst-play.c 2021-08-23 19:27:34.292506541 +0800
  4. @@ -104,6 +104,32 @@
  5. gdouble rate;
  6. } GstPlay;
  7. +#if defined(G_OS_UNIX)
  8. +static guint signal_watch_intr_id;
  9. +#endif
  10. +
  11. +#if defined(G_OS_UNIX)
  12. +/* As the interrupt handler is dispatched from GMainContext as a GSourceFunc
  13. + * handler, we can react to this by posting a message. */
  14. +static gboolean
  15. +intr_handler (gpointer user_data)
  16. +{
  17. + GstElement *pipeline = (GstElement *) user_data;
  18. + GstPlay *play = (GstPlay *) user_data;
  19. + gst_print ("handling interrupt.\n");
  20. +
  21. + /* post an application specific message */
  22. + gst_element_post_message (GST_ELEMENT (play->playbin),
  23. + gst_message_new_application (GST_OBJECT (play->playbin),
  24. + gst_structure_new ("GstLaunchInterrupt",
  25. + "message", G_TYPE_STRING, "Pipeline interrupted", NULL)));
  26. +
  27. + /* remove signal handler */
  28. + signal_watch_intr_id = 0;
  29. + return G_SOURCE_REMOVE;
  30. +}
  31. +#endif /* G_OS_UNIX */
  32. +
  33. static gboolean quiet = FALSE;
  34. static gboolean instant_rate_changes = FALSE;
  35. @@ -594,6 +620,24 @@
  36. }
  37. break;
  38. }
  39. + case GST_MESSAGE_APPLICATION:{
  40. + const GstStructure *s;
  41. +
  42. + s = gst_message_get_structure (msg);
  43. +
  44. + if (gst_structure_has_name (s, "GstLaunchInterrupt")) {
  45. + /* this application message is posted when we caught an interrupt and
  46. + * we need to stop the pipeline. */
  47. +
  48. + gst_print (_("Interrupt: GST_MESSAGE_APPLICATION ...\n"));
  49. + if (play->desired_state == GST_STATE_PLAYING){
  50. + gst_print (_("Interrupt: Stopping pipeline ...\n"));
  51. + g_main_loop_quit (play->loop);
  52. + }
  53. +
  54. + }
  55. + break;
  56. + }
  57. default:
  58. if (gst_is_missing_plugin_message (msg)) {
  59. gchar *desc;
  60. @@ -1622,6 +1666,12 @@
  61. }
  62. }
  63. +#ifdef G_OS_UNIX
  64. + gst_print("g_source_remove signal_watch_intr_id \n");
  65. + signal_watch_intr_id =
  66. + g_unix_signal_add (SIGINT, (GSourceFunc) intr_handler, play);
  67. +#endif
  68. +
  69. /* play */
  70. do_play (play);
  71. @@ -1632,6 +1682,14 @@
  72. g_free (video_sink);
  73. gst_print ("\n");
  74. +
  75. +#ifdef G_OS_UNIX
  76. + if (signal_watch_intr_id > 0){
  77. + gst_print("g_source_remove signal_watch_intr_id \n");
  78. + g_source_remove (signal_watch_intr_id);
  79. + }
  80. +#endif
  81. +
  82. gst_deinit ();
  83. return 0;
  84. }