From f2515d6d7979b921aaeb6149829a60379a124f36 Mon Sep 17 00:00:00 2001 From: James DeLisle Date: Fri, 18 Feb 2022 16:10:35 -0500 Subject: Add internal ability to adjust RTSP latency When using the gstreamer backend, the RTSP latency is set to 2000ms by default. This latency creates issues for cases where near realtime camera feedback is critical for directing the user. This change adds the ability to turn 3 knobs in the RTSP jitter buffer pipeline using the following environment variables: 1. QT_MEDIA_RTSP_LATENCY An unsigned integer value expressed in ms. This dictates the high water mark of the latency buffer. Default: 2000 ms 2. QT_MEDIA_RTSP_DROP_ON_LATENCY May be set to 1 for on or 0 for off When turned on, the jitter buffer will drop packets that arrive after the high water mark of the buffer has been filled. No new packets will be accepted until the high water mark recedes sufficiently to allow new packets to be stored in the buffer. Default: off 3. QT_MEDIA_RTSP_DO_RETRANSMISSION May be set to 1 for on or 0 for off When set to true, the jitter buffer will request a re-send of dropped packets. Default: off This change is strictly for a customer project, but may be helpful in understanding what additions to the public API would be helpful in the future. Change-Id: Icede93161d72936970f4835c6443e369789b4c38 Reviewed-by: Lars Knoll Reviewed-by: Doris Verria (cherry picked from commit 2fcf1212ff78f02e7c7d408c2719a0369eab5bad) Reviewed-by: Qt Cherry-pick Bot --- .../gstreamer/common/qgstreamermediaplayer.cpp | 34 ++++++++++++++++++++++ .../gstreamer/common/qgstreamermediaplayer_p.h | 1 + 2 files changed, 35 insertions(+) diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp index e3b2cf600..b46479bcc 100644 --- a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp +++ b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp @@ -599,6 +599,39 @@ void QGstreamerMediaPlayer::uridecodebinElementAddedCallback(GstElement */*uride } } +void QGstreamerMediaPlayer::sourceSetupCallback(GstElement *uridecodebin, GstElement *source, QGstreamerMediaPlayer *that) +{ + Q_UNUSED(uridecodebin) + Q_UNUSED(that) + + qCDebug(qLcMediaPlayer) << "Setting up source:" << g_type_name_from_instance((GTypeInstance*)source); + + if (QLatin1String("GstRTSPSrc") == QString::fromUtf8(g_type_name_from_instance((GTypeInstance*)source))) { + QGstElement s(source); + int latency{40}; + bool ok{false}; + int v = QString::fromLocal8Bit(qgetenv("QT_MEDIA_RTSP_LATENCY")).toUInt(&ok); + if (ok) + latency = v; + qCDebug(qLcMediaPlayer) << " -> setting source latency to:" << latency << "ms"; + s.set("latency", latency); + + bool drop{true}; + v = QString::fromLocal8Bit(qgetenv("QT_MEDIA_RTSP_DROP_ON_LATENCY")).toUInt(&ok); + if (ok && v == 0) + drop = false; + qCDebug(qLcMediaPlayer) << " -> setting drop-on-latency to:" << drop; + s.set("drop-on-latency", drop); + + bool retrans{false}; + v = QString::fromLocal8Bit(qgetenv("QT_MEDIA_RTSP_DO_RETRANSMISSION")).toUInt(&ok); + if (ok && v not_eq 0) + retrans = true; + qCDebug(qLcMediaPlayer) << " -> setting do-retransmission to:" << retrans; + s.set("do-retransmission", retrans); + } +} + void QGstreamerMediaPlayer::setMedia(const QUrl &content, QIODevice *stream) { qCDebug(qLcMediaPlayer) << Q_FUNC_INFO << "setting location to" << content; @@ -655,6 +688,7 @@ void QGstreamerMediaPlayer::setMedia(const QUrl &content, QIODevice *stream) playerPipeline.add(decoder); // can't set post-stream-topology to true, as uridecodebin doesn't have the property. Use a hack decoder.connect("element-added", GCallback(QGstreamerMediaPlayer::uridecodebinElementAddedCallback), this); + decoder.connect("source-setup", GCallback(QGstreamerMediaPlayer::sourceSetupCallback), this); decoder.set("uri", content.toEncoded().constData()); if (m_bufferProgress != 0) { diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h index 7afad3ba7..dc77ad9e3 100644 --- a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h +++ b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h @@ -107,6 +107,7 @@ private: void decoderPadAdded(const QGstElement &src, const QGstPad &pad); void decoderPadRemoved(const QGstElement &src, const QGstPad &pad); static void uridecodebinElementAddedCallback(GstElement *uridecodebin, GstElement *child, QGstreamerMediaPlayer *that); + static void sourceSetupCallback(GstElement *uridecodebin, GstElement *source, QGstreamerMediaPlayer *that); void parseStreamsAndMetadata(); void connectOutput(TrackSelector &ts); void removeOutput(TrackSelector &ts); -- cgit v1.2.3