From 73fb107a855910e3ff8558fd14ba5233a314fb13 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 17 Mar 2021 13:18:34 +0530 Subject: [PATCH] rtspsrc: Fix accumulation of before-send signal return values Since glib 2.62, the accumulated return values in RUN_CLEANUP override the accumulated return values in RUN_FIRST. Since: 1. We have a default handler that always returns TRUE, and 2. User handlers are only run in RUN_FIRST, and 3. Our accumulator just takes the latest return value We were discarding the return value from the user handler and always sending messages even if the user handler said not to. See https://gitlab.gnome.org/GNOME/glib/-/issues/2352 for more details. This signal does not need RUN_CLEANUP or RUN_FIRST, so just change it to RUN_LAST so that it's emitted exactly once and accumulated once. With this fix, this signal can now be used to intercept PAUSE when going to GST_STATE_NULL so that the server does a TEARDOWN (if necessary) and not a PAUSE, which will confuse other RTSP clients when playing shared media. Part-of: --- gst/rtsp/gstrtspsrc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gst/rtsp/gstrtspsrc.c b/gst/rtsp/gstrtspsrc.c index 0f4f9aa..ac9d2a7 100644 --- a/gst/rtsp/gstrtspsrc.c +++ b/gst/rtsp/gstrtspsrc.c @@ -85,6 +85,14 @@ * ]| Establish a connection to an RTSP server and send the raw RTP packets to a * fakesink. * + * NOTE: rtspsrc will send a PAUSE command to the server if you set the + * element to the PAUSED state, and will send a PLAY command if you set it to + * the PLAYING state. + * + * Unfortunately, going to the NULL state involves going through PAUSED, so + * rtspsrc does not know the difference and will send a PAUSE when you wanted + * a TEARDOWN. The workaround is to hook into the `before-send` signal and + * return FALSE in this case. */ #ifdef HAVE_CONFIG_H @@ -1126,7 +1134,7 @@ gst_rtspsrc_class_init (GstRTSPSrcClass * klass) */ gst_rtspsrc_signals[SIGNAL_BEFORE_SEND] = g_signal_new_class_handler ("before-send", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_CLEANUP, + G_SIGNAL_RUN_LAST, (GCallback) default_before_send, before_send_accum, NULL, NULL, G_TYPE_BOOLEAN, 1, GST_TYPE_RTSP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE); -- 2.7.4