From 657cc3e6d630dc29101a25a383cb530e7aa3c002 Mon Sep 17 00:00:00 2001 From: Bruce Liang Date: Wed, 24 Aug 2022 19:50:19 +0800 Subject: [PATCH] gst-rtsp-server: Fix pushing backlog to client Check back pressure of a stream transport before popping buffer from its backlog. If the stream transport is not experiencing back pressure, the buffer can be popped from backlog and pushed to client. Fixes:#1298 Part-of: --- .../gst/rtsp-server/rtsp-server-internal.h | 2 ++ .../gst/rtsp-server/rtsp-stream-transport.c | 19 +++++++++++++++++++ .../gst/rtsp-server/rtsp-stream.c | 18 +++++++++++------- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server-internal.h b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server-internal.h index b5aaefffc7..6015d6840e 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server-internal.h +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-server-internal.h @@ -40,6 +40,8 @@ gboolean gst_rtsp_stream_transport_backlog_pop (GstRTSPStreamT GstBufferList **buffer_list, gboolean *is_rtp); +gboolean gst_rtsp_stream_transport_backlog_peek_is_rtp (GstRTSPStreamTransport * trans); + gboolean gst_rtsp_stream_transport_backlog_is_empty (GstRTSPStreamTransport *trans); void gst_rtsp_stream_transport_clear_backlog (GstRTSPStreamTransport * trans); diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream-transport.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream-transport.c index d293a95138..4502ec1fd5 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream-transport.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream-transport.c @@ -950,6 +950,25 @@ gst_rtsp_stream_transport_backlog_pop (GstRTSPStreamTransport * trans, return TRUE; } +/* Not MT-safe, caller should ensure consistent locking. + * See gst_rtsp_stream_transport_lock_backlog() */ +gboolean +gst_rtsp_stream_transport_backlog_peek_is_rtp (GstRTSPStreamTransport * trans) +{ + BackLogItem *item; + GstRTSPStreamTransportPrivate *priv; + + g_return_val_if_fail (!gst_rtsp_stream_transport_backlog_is_empty (trans), + FALSE); + + priv = trans->priv; + + item = (BackLogItem *) gst_queue_array_peek_head_struct (priv->items); + + return item->is_rtp; +} + + /* Not MT-safe, caller should ensure consistent locking. * See gst_rtsp_stream_transport_lock_backlog() */ gboolean diff --git a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c index fed62d8c82..99d87e9d97 100644 --- a/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c +++ b/subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-stream.c @@ -2644,16 +2644,20 @@ check_transport_backlog (GstRTSPStream * stream, GstRTSPStreamTransport * trans) gboolean is_rtp; gboolean popped; - popped = - gst_rtsp_stream_transport_backlog_pop (trans, &buffer, &buffer_list, - &is_rtp); + is_rtp = gst_rtsp_stream_transport_backlog_peek_is_rtp (trans); - g_assert (popped == TRUE); + if (!gst_rtsp_stream_transport_check_back_pressure (trans, is_rtp)) { + popped = + gst_rtsp_stream_transport_backlog_pop (trans, &buffer, &buffer_list, + &is_rtp); - send_ret = push_data (stream, trans, buffer, buffer_list, is_rtp); + g_assert (popped == TRUE); - gst_clear_buffer (&buffer); - gst_clear_buffer_list (&buffer_list); + send_ret = push_data (stream, trans, buffer, buffer_list, is_rtp); + + gst_clear_buffer (&buffer); + gst_clear_buffer_list (&buffer_list); + } } gst_rtsp_stream_transport_unlock_backlog (trans);