From e54cf647315c7050e04ada9ebb4e2124739a0aa9 Mon Sep 17 00:00:00 2001 From: alireza787b Date: Tue, 28 Jul 2026 05:36:25 +0000 Subject: [PATCH 1/8] feat(VideoManager): add HTTP MJPEG video source --- .github/build-config.json | 4 + .../GStreamer/tests/test_plugin_policy.cmake | 4 + .../qgc-user-guide/settings_view/general.md | 4 +- docs/en/qgc-user-guide/settings_view/video.md | 8 +- src/AppSettings/pages/Video.SettingsUI.json | 6 +- src/Settings/Video.SettingsGroup.json | 22 ++- src/Settings/VideoSettings.cc | 17 ++ src/Settings/VideoSettings.h | 4 + src/VideoManager/VideoManager.cc | 9 +- .../GStreamer/GstSourceFactory.cc | 120 +++++++++++- .../GStreamer/GstSourceFactory.h | 15 +- .../GStreamer/GstVideoReceiver.cc | 1 + test/VideoManager/GStreamer/GStreamerTest.cc | 3 + test/VideoManager/GStreamer/GStreamerTest.h | 3 + .../GStreamerSourceFactoryTest.cc | 181 ++++++++++++++++++ 15 files changed, 384 insertions(+), 17 deletions(-) diff --git a/.github/build-config.json b/.github/build-config.json index c27d970fb9c3..68d4af1dbdd5 100644 --- a/.github/build-config.json +++ b/.github/build-config.json @@ -38,9 +38,12 @@ "app", "coreelements", "isomp4", + "jpeg", + "jpegformat", "libav", "matroska", "mpegtsdemux", + "multipart", "multifile", "opengl", "openh264", @@ -49,6 +52,7 @@ "rtpmanager", "rtsp", "sdpelem", + "soup", "tcp", "typefindfunctions", "udp", diff --git a/cmake/GStreamer/tests/test_plugin_policy.cmake b/cmake/GStreamer/tests/test_plugin_policy.cmake index 95aca388866e..f68ffeea94f4 100644 --- a/cmake/GStreamer/tests/test_plugin_policy.cmake +++ b/cmake/GStreamer/tests/test_plugin_policy.cmake @@ -35,6 +35,10 @@ file(READ "${CMAKE_CURRENT_LIST_DIR}/../../../.github/build-config.json" QGC_BUI gstreamer_plugins_for(PLATFORM windows OUT_VAR _plugins_windows_real) qgc_test_assert_in_list("windows has d3d11" d3d11 _plugins_windows_real) qgc_test_assert_in_list("windows has d3d12" d3d12 _plugins_windows_real) +qgc_test_assert_in_list("common has native JPEG decoder" jpeg _plugins_windows_real) +qgc_test_assert_in_list("common has HTTP MJPEG jpeg parser" jpegformat _plugins_windows_real) +qgc_test_assert_in_list("common has HTTP MJPEG multipart demuxer" multipart _plugins_windows_real) +qgc_test_assert_in_list("common has HTTP client source" soup _plugins_windows_real) qgc_test_pass("plugins_for real windows d3d addenda") set(_req videoconvertscale videoconvert videoscale x264enc) diff --git a/docs/en/qgc-user-guide/settings_view/general.md b/docs/en/qgc-user-guide/settings_view/general.md index 70b5cb9af8ba..045e7f030a59 100644 --- a/docs/en/qgc-user-guide/settings_view/general.md +++ b/docs/en/qgc-user-guide/settings_view/general.md @@ -201,13 +201,15 @@ The _Video_ section is used to define the source and connection settings for vid The settings are: -- **Video Source**: Video Stream Disabled | RTSP Video Stream | UDP h.264 Video Stream | UDP h.265 Video Stream | TCP-MPEG2 Video Stream | MPEG-TS Video Stream | Integrated Camera +- **Video Source**: Video Stream Disabled | RTSP Video Stream | HTTP MJPEG Video Stream | UDP h.264 Video Stream | UDP h.265 Video Stream | TCP-MPEG2 Video Stream | MPEG-TS Video Stream | Integrated Camera ::: info If no video source is specified then no other video or _video recording_ settings will be displayed. ::: - **URL/Port**: Connection type-specific stream address (may be port or URL). + HTTP MJPEG requires a full `http://` or `https://` URL serving + `multipart/x-mixed-replace` JPEG frames. - **Aspect Ratio**: Aspect ratio for scaling video in video widget (set to 0.0 to ignore scaling) - **Disabled When Disarmed**: Disable video feed when vehicle is disarmed. - **Low Latency Mode**: Enabling low latency mode reduces the video stream latency, but may cause frame loss and choppy video (especially with a poor network connection). diff --git a/docs/en/qgc-user-guide/settings_view/video.md b/docs/en/qgc-user-guide/settings_view/video.md index 6287717c14e0..0c8412330da1 100644 --- a/docs/en/qgc-user-guide/settings_view/video.md +++ b/docs/en/qgc-user-guide/settings_view/video.md @@ -4,16 +4,22 @@ Configure video streaming and recording settings. ## Video Source -- **Source** — Video Stream Disabled / RTSP Video Stream / UDP h.264 / UDP h.265 / TCP-MPEG2 / MPEG-TS / Integrated Camera +- **Source** — Video Stream Disabled / RTSP Video Stream / HTTP MJPEG Video Stream / UDP h.264 / UDP h.265 / TCP-MPEG2 / MPEG-TS / Integrated Camera ## Connection Connection settings vary by source type: - **RTSP URL** — full RTSP stream address +- **HTTP MJPEG URL** — full `http://` or `https://` address of a multipart MJPEG stream - **TCP URL** — TCP stream address - **UDP URL** — UDP stream address and port (default: `0.0.0.0:5600`) +HTTP MJPEG expects a `multipart/x-mixed-replace` response containing JPEG frames. +It does not accept a web page, a single JPEG URL, or an arbitrary HTTP video file. +HTTPS certificate validation remains enabled in GStreamer, redirects are not followed, and URL user information +(`user:password@host`) is rejected. + ## Settings - **Aspect Ratio** — aspect ratio for scaling video in the display widget (default: 16:9; set to 0.0 to disable scaling) diff --git a/src/AppSettings/pages/Video.SettingsUI.json b/src/AppSettings/pages/Video.SettingsUI.json index 5a44c56b5496..9645d02988b2 100644 --- a/src/AppSettings/pages/Video.SettingsUI.json +++ b/src/AppSettings/pages/Video.SettingsUI.json @@ -23,13 +23,17 @@ }, { "heading": "Connection", - "keywords": ["rtsp", "tcp", "udp", "mpegts", "video url", "stream url"], + "keywords": ["rtsp", "http", "https", "mjpeg", "jpeg", "tcp", "udp", "mpegts", "video url", "stream url"], "showWhen": "!sourceDisabled && !autoStreamConfig", "controls": [ { "setting": "videoSettings.rtspUrl", "showWhen": "videoSource === QGroundControl.settingsManager.videoSettings.rtspVideoSource" }, + { + "setting": "videoSettings.httpMjpegUrl", + "showWhen": "videoSource === QGroundControl.settingsManager.videoSettings.httpMjpegVideoSource" + }, { "setting": "videoSettings.tcpUrl", "showWhen": "videoSource === QGroundControl.settingsManager.videoSettings.tcpVideoSource" diff --git a/src/Settings/Video.SettingsGroup.json b/src/Settings/Video.SettingsGroup.json index 901e050eb3f2..84df70c0b91d 100644 --- a/src/Settings/Video.SettingsGroup.json +++ b/src/Settings/Video.SettingsGroup.json @@ -4,8 +4,8 @@ "QGC.MetaData.Facts": [ { "name": "videoSource", - "shortDesc": "Source for video stream (UDP, TCP, RTSP, or connected USB camera).", - "longDesc": "Source for video. UDP, TCP, RTSP and UVC Cameras may be supported depending on Vehicle and ground station version.", + "shortDesc": "Source for video stream (UDP, TCP, RTSP, HTTP MJPEG, or connected USB camera).", + "longDesc": "Source for video. UDP, TCP, RTSP, HTTP multipart MJPEG and UVC cameras may be supported depending on the ground station build.", "type": "string", "default": "", "label": "Source", @@ -29,6 +29,15 @@ "label": "RTSP URL", "keywords": "rtsp,video url,stream url" }, + { + "name": "httpMjpegUrl", + "shortDesc": "Full URL for an HTTP multipart MJPEG stream.", + "longDesc": "Full http:// or https:// URL for a multipart MJPEG stream (multipart/x-mixed-replace with JPEG frames). User information in the URL is not supported.", + "type": "string", + "default": "", + "label": "HTTP MJPEG URL", + "keywords": "http,https,mjpeg,jpeg,video url,stream url" + }, { "name": "tcpUrl", "shortDesc": "Network address and port for TCP video stream (e.g. 192.168.143.200:3001).", @@ -117,13 +126,14 @@ }, { "name": "rtspTimeout", - "shortDesc": "RTSP Video Timeout", - "longDesc": "How long to wait before assuming RTSP link is gone.", + "shortDesc": "Network video timeout.", + "longDesc": "How long to wait before assuming a timeout-based network video source is unavailable.", "type": "uint32", "min": 1, "units": "s", "default": 8, - "label": "RTSP Video Timeout" + "label": "Network Video Timeout", + "keywords": "rtsp,http,mjpeg,network,video timeout" }, { "name": "streamEnabled", @@ -170,7 +180,7 @@ "type": "bool", "default": true, "label": "Auto-reconnect on stream loss", - "keywords": "rtsp,reconnect,watchdog,recovery,advanced" + "keywords": "rtsp,http,mjpeg,stream,reconnect,watchdog,recovery,advanced" }, { "name": "forceVideoDecoder", diff --git a/src/Settings/VideoSettings.cc b/src/Settings/VideoSettings.cc index ae43d03c6c1a..8d4b2fb8ad49 100644 --- a/src/Settings/VideoSettings.cc +++ b/src/Settings/VideoSettings.cc @@ -20,6 +20,9 @@ DECLARE_SETTINGGROUP(Video, "Video") // Setup enum values for videoSource settings into meta data QVariantList videoSourceList; videoSourceList.append(videoSourceRTSP); + if (kGstEnabled) { + videoSourceList.append(videoSourceHTTPMJPEG); + } videoSourceList.append(videoSourceUDPH264); videoSourceList.append(videoSourceUDPH265); videoSourceList.append(videoSourceTCP); @@ -220,6 +223,15 @@ DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl) return _rtspUrlFact; } +DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, httpMjpegUrl) +{ + if (!_httpMjpegUrlFact) { + _httpMjpegUrlFact = _createSettingsFact(httpMjpegUrlName); + connect(_httpMjpegUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged); + } + return _httpMjpegUrlFact; +} + DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl) { if (!_tcpUrlFact) { @@ -251,6 +263,11 @@ bool VideoSettings::streamConfigured(void) qCDebug(VideoSettingsLog) << "Testing configuration for RTSP Stream:" << rtspUrl()->rawValue().toString(); return !rtspUrl()->rawValue().toString().isEmpty(); } + //-- If HTTP MJPEG, check for URL + if (vSource == videoSourceHTTPMJPEG) { + qCDebug(VideoSettingsLog) << "Testing configuration for HTTP MJPEG Stream"; + return !httpMjpegUrl()->rawValue().toString().isEmpty(); + } //-- If TCP, check for URL if(vSource == videoSourceTCP) { qCDebug(VideoSettingsLog) << "Testing configuration for TCP Stream:" << tcpUrl()->rawValue().toString(); diff --git a/src/Settings/VideoSettings.h b/src/Settings/VideoSettings.h index 6bd21c19b1b5..9b83cdbf30aa 100644 --- a/src/Settings/VideoSettings.h +++ b/src/Settings/VideoSettings.h @@ -17,6 +17,7 @@ class VideoSettings : public SettingsGroup DEFINE_SETTINGFACT(udpUrl) DEFINE_SETTINGFACT(tcpUrl) DEFINE_SETTINGFACT(rtspUrl) + DEFINE_SETTINGFACT(httpMjpegUrl) DEFINE_SETTINGFACT(aspectRatio) DEFINE_SETTINGFACT(videoFit) DEFINE_SETTINGFACT(gridLines) @@ -37,6 +38,7 @@ class VideoSettings : public SettingsGroup Q_PROPERTY(bool streamConfigured READ streamConfigured NOTIFY streamConfiguredChanged) Q_PROPERTY(QString rtspVideoSource READ rtspVideoSource CONSTANT) + Q_PROPERTY(QString httpMjpegVideoSource READ httpMjpegVideoSource CONSTANT) Q_PROPERTY(QString udp264VideoSource READ udp264VideoSource CONSTANT) Q_PROPERTY(QString udp265VideoSource READ udp265VideoSource CONSTANT) Q_PROPERTY(QString tcpVideoSource READ tcpVideoSource CONSTANT) @@ -45,6 +47,7 @@ class VideoSettings : public SettingsGroup bool streamConfigured (); QString rtspVideoSource () { return videoSourceRTSP; } + QString httpMjpegVideoSource () { return videoSourceHTTPMJPEG; } QString udp264VideoSource () { return videoSourceUDPH264; } QString udp265VideoSource () { return videoSourceUDPH265; } QString tcpVideoSource () { return videoSourceTCP; } @@ -59,6 +62,7 @@ class VideoSettings : public SettingsGroup static constexpr const char* videoSourceNoVideo = QT_TRANSLATE_NOOP("VideoSettings", "No Video Available"); static constexpr const char* videoDisabled = QT_TRANSLATE_NOOP("VideoSettings", "Video Stream Disabled"); static constexpr const char* videoSourceRTSP = QT_TRANSLATE_NOOP("VideoSettings", "RTSP Video Stream"); + static constexpr const char* videoSourceHTTPMJPEG = QT_TRANSLATE_NOOP("VideoSettings", "HTTP MJPEG Video Stream"); static constexpr const char* videoSourceUDPH264 = QT_TRANSLATE_NOOP("VideoSettings", "UDP h.264 Video Stream"); static constexpr const char* videoSourceUDPH265 = QT_TRANSLATE_NOOP("VideoSettings", "UDP h.265 Video Stream"); static constexpr const char* videoSourceTCP = QT_TRANSLATE_NOOP("VideoSettings", "TCP-MPEG2 Video Stream"); diff --git a/src/VideoManager/VideoManager.cc b/src/VideoManager/VideoManager.cc index 72d47e207f7d..fe3c19c7eef1 100644 --- a/src/VideoManager/VideoManager.cc +++ b/src/VideoManager/VideoManager.cc @@ -177,6 +177,7 @@ void VideoManager::init(QQuickWindow *mainWindow) (void) connect(_videoSettings->videoSource(), &Fact::rawValueChanged, this, &VideoManager::_videoSourceChanged); (void) connect(_videoSettings->udpUrl(), &Fact::rawValueChanged, this, &VideoManager::_videoSourceChanged); (void) connect(_videoSettings->rtspUrl(), &Fact::rawValueChanged, this, &VideoManager::_videoSourceChanged); + (void) connect(_videoSettings->httpMjpegUrl(), &Fact::rawValueChanged, this, &VideoManager::_videoSourceChanged); (void) connect(_videoSettings->tcpUrl(), &Fact::rawValueChanged, this, &VideoManager::_videoSourceChanged); (void) connect(_videoSettings->aspectRatio(), &Fact::rawValueChanged, this, &VideoManager::aspectRatioChanged); (void) connect(_videoSettings->lowLatencyMode(), &Fact::rawValueChanged, this, [this](const QVariant &value) { Q_UNUSED(value); _restartAllVideos(); }); @@ -500,6 +501,7 @@ bool VideoManager::isStreamSource() const VideoSettings::videoSourceUDPH264, VideoSettings::videoSourceUDPH265, VideoSettings::videoSourceRTSP, + VideoSettings::videoSourceHTTPMJPEG, VideoSettings::videoSourceTCP, VideoSettings::videoSourceMPEGTS, VideoSettings::videoSource3DRSolo, @@ -701,6 +703,8 @@ bool VideoManager::_updateSettings(VideoReceiver *receiver) settingsChanged |= _updateVideoUri(receiver, QStringLiteral("mpegts://%1").arg(_videoSettings->udpUrl()->rawValue().toString())); } else if (source == VideoSettings::videoSourceRTSP) { settingsChanged |= _updateVideoUri(receiver, _videoSettings->rtspUrl()->rawValue().toString()); + } else if (source == VideoSettings::videoSourceHTTPMJPEG) { + settingsChanged |= _updateVideoUri(receiver, _videoSettings->httpMjpegUrl()->rawValue().toString()); } else if (source == VideoSettings::videoSourceTCP) { settingsChanged |= _updateVideoUri(receiver, QStringLiteral("tcp://%1").arg(_videoSettings->tcpUrl()->rawValue().toString())); } else if (source == VideoSettings::videoSource3DRSolo) { @@ -842,7 +846,10 @@ void VideoManager::_startReceiver(VideoReceiver *receiver) } const QString source = _videoSettings->videoSource()->rawValue().toString(); - const uint32_t timeout = ((source == VideoSettings::videoSourceRTSP) ? _videoSettings->rtspTimeout()->rawValue().toUInt() : 3); + const bool usesNetworkTimeout = + (source == VideoSettings::videoSourceRTSP) || (source == VideoSettings::videoSourceHTTPMJPEG); + // Keep the existing Fact/persistence key for compatibility while its UI meaning expands to timeout-based sources. + const uint32_t timeout = usesNetworkTimeout ? _videoSettings->rtspTimeout()->rawValue().toUInt() : 3; receiver->start(timeout); } diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc index d5a161ab464b..cca1589e036d 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -421,6 +422,118 @@ GstElement* buildUdpSource(const QUrl& sourceUrl, bool isUdpH264, bool isUdpH265 return source; } +void linkMultipartJpegPad(GstElement* element, GstPad* pad, gpointer data) +{ + GstElement* parser = GST_ELEMENT(data); + if (!element || !pad || !parser || (GST_PAD_DIRECTION(pad) != GST_PAD_SRC)) { + return; + } + + GstCaps* jpegCaps = gst_caps_from_string("image/jpeg"); + GstCaps* padCaps = gst_pad_get_current_caps(pad); + if (!padCaps) { + padCaps = gst_pad_query_caps(pad, nullptr); + } + const bool isJpeg = jpegCaps && padCaps && gst_caps_can_intersect(padCaps, jpegCaps); + gst_clear_caps(&padCaps); + gst_clear_caps(&jpegCaps); + if (!isJpeg) { + return; + } + + GstPad* parserSink = gst_element_get_static_pad(parser, "sink"); + if (!parserSink) { + qCWarning(GstSourceFactoryLog) << "HTTP MJPEG parser sink pad is unavailable"; + return; + } + + if (!gst_pad_is_linked(parserSink)) { + const GstPadLinkReturn result = gst_pad_link(pad, parserSink); + if (result != GST_PAD_LINK_OK) { + qCWarning(GstSourceFactoryLog) << "HTTP MJPEG demux/parser link failed:" << result; + } + } + gst_object_unref(parserSink); +} + +GstElement* buildHttpMjpegSource(const QUrl& sourceUrl, const Config& config) +{ + if (!sourceUrl.isValid() || sourceUrl.isRelative() || sourceUrl.host().isEmpty() || (sourceUrl.port() == 0)) { + qCWarning(GstSourceFactoryLog) << "Invalid HTTP MJPEG URL:" + << QGCNetworkHelper::redactedUrlForLogging(sourceUrl); + return nullptr; + } + if (!sourceUrl.userInfo().isEmpty()) { + qCWarning(GstSourceFactoryLog) << "HTTP MJPEG credentials in URLs are not supported"; + return nullptr; + } + + GstElement* source = gst_element_factory_make("souphttpsrc", "source"); + GstElement* demux = gst_element_factory_make("multipartdemux", "multipart-demux"); + GstElement* parser = gst_element_factory_make("jpegparse", "jpeg-parser"); + GstElement* bin = gst_bin_new("sourcebin"); + GstElement* sourceBin = nullptr; + + do { + if (!source || !demux || !parser || !bin) { + qCWarning(GstSourceFactoryLog) << "HTTP MJPEG requires souphttpsrc, multipartdemux, and jpegparse"; + break; + } + + QUrl cleanUrl(sourceUrl); + cleanUrl.setUserInfo(QString()); + cleanUrl.setFragment(QString()); + const QByteArray location = cleanUrl.toEncoded(QUrl::FullyEncoded); + const QByteArray userAgent = QGCNetworkHelper::defaultUserAgent().toUtf8(); + const guint timeoutS = std::clamp(config.timeoutS, 1u, 3600u); + g_object_set(source, "location", location.constData(), "method", "GET", "is-live", TRUE, "do-timestamp", TRUE, + "keep-alive", TRUE, "compress", FALSE, "iradio-mode", FALSE, "automatic-redirect", FALSE, + "retries", 0, "timeout", timeoutS, "ssl-strict", TRUE, "ssl-use-system-ca-file", TRUE, + "http-log-level", 0, "user-agent", userAgent.constData(), nullptr); + g_object_set(demux, "single-stream", TRUE, nullptr); + + if (!gst_bin_add(GST_BIN(bin), source)) { + qCWarning(GstSourceFactoryLog) << "Failed to add HTTP source to source bin"; + break; + } + GstElement* binSource = source; + source = nullptr; + + if (!gst_bin_add(GST_BIN(bin), demux)) { + qCWarning(GstSourceFactoryLog) << "Failed to add multipart demuxer to source bin"; + break; + } + GstElement* binDemux = demux; + demux = nullptr; + + if (!gst_bin_add(GST_BIN(bin), parser)) { + qCWarning(GstSourceFactoryLog) << "Failed to add JPEG parser to source bin"; + break; + } + GstElement* binParser = parser; + parser = nullptr; + + if (!gst_element_link(binSource, binDemux)) { + qCWarning(GstSourceFactoryLog) << "Failed to link HTTP source to multipart demuxer"; + break; + } + (void) g_signal_connect_object(binDemux, "pad-added", G_CALLBACK(linkMultipartJpegPad), binParser, + G_CONNECT_DEFAULT); + if (!addStaticGhostPad(binParser)) { + break; + } + + sourceBin = bin; + bin = nullptr; + } while (false); + + gst_clear_object(&bin); + gst_clear_object(&parser); + gst_clear_object(&demux); + gst_clear_object(&source); + return sourceBin; +} + // Wire upstream → (optional rtpjitterbuffer) → binParser, topology chosen by RTP probe (MPEG-TS // links via pad-added). Created elements join @p bin; returns false (logged) on failure. bool linkSourceToParser(GstElement* bin, GstElement* upstream, GstElement* binParser, const Config& config, @@ -526,12 +639,17 @@ GstElement* create(const QString& uri, const Config& config) const bool isUdpH265 = (scheme == QLatin1String("udp265")); const bool isUdpMPEGTS = (scheme == QLatin1String("mpegts")); const bool isTcpMPEGTS = (scheme == QLatin1String("tcp")); + const bool isHttpMjpeg = (scheme == QLatin1String("http")) || (scheme == QLatin1String("https")); - if (!isRtsp && !isUdpH264 && !isUdpH265 && !isUdpMPEGTS && !isTcpMPEGTS) { + if (!isRtsp && !isUdpH264 && !isUdpH265 && !isUdpMPEGTS && !isTcpMPEGTS && !isHttpMjpeg) { qCWarning(GstSourceFactoryLog) << "Unsupported URI scheme:" << scheme << "in" << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); return nullptr; } + if (isHttpMjpeg) { + return buildHttpMjpegSource(sourceUrl, config); + } + // Owning locals until gst_bin_add*, then nulled (non-owning alias used downstream) so the // unconditional gst_clear_object cleanup at the bottom stays safe. GstElement* source = nullptr; diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.h b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.h index 5b996afe2643..d89ff9b21045 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.h +++ b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace GStreamer::SourceFactory { @@ -22,15 +23,17 @@ struct Config JitterBuffer jitterBuffer = JitterBuffer::DropOnLatency; int latencyMs = 80; bool doRetransmission = true; + /// Blocking network I/O timeout for source elements that expose one, in seconds. + uint32_t timeoutS = 8; }; -/// Build a source bin (`source` [+ `tsdemux`] [+ `rtpjitterbuffer`] + `parsebin`) -/// for `uri`. Supported schemes: rtsp/rtspt, tcp:// (MPEG-TS), udp:// (H.264 RTP), -/// udp265:// (H.265 RTP), mpegts:// (MPEG-TS over UDP). +/// Build a source bin that exposes parsed encoded video for `uri`. +/// Supported schemes: rtsp/rtspt, tcp:// (MPEG-TS), udp:// (H.264 RTP), +/// udp265:// (H.265 RTP), mpegts:// (MPEG-TS over UDP), and http(s):// +/// (multipart MJPEG). /// -/// Ghost pads on the returned bin are wired lazily; for `rtspsrc`/`tsdemux`/`parsebin` -/// they appear only after upstream produces pads, so callers must connect any -/// downstream `pad-added` handlers before transitioning to PLAYING. +/// Ghost pads on RTP/MPEG-TS bins are wired lazily after upstream produces pads. +/// The HTTP MJPEG bin exposes its parsed-JPEG pad immediately. /// /// Returns the source bin or nullptr on failure. GstElement* create(const QString& uri, const Config& config); diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc b/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc index 395626a6a525..4cd862962c57 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstVideoReceiver.cc @@ -223,6 +223,7 @@ void GstVideoReceiver::start(uint32_t timeout) ? GStreamer::SourceFactory::JitterBuffer::DropOnLatency : GStreamer::SourceFactory::JitterBuffer::Buffered); sourceConfig.latencyMs = _rtpJitterLatencyMs; + sourceConfig.timeoutS = timeout; // do-retransmission needs ≥40 ms latency headroom over the default 20 ms rtx-delay; // forcibly disable for sub-frame latency configurations to avoid retransmit storms. sourceConfig.doRetransmission = (_rtpJitterLatencyMs >= 40) && (sourceConfig.jitterBuffer != GStreamer::SourceFactory::JitterBuffer::None); diff --git a/test/VideoManager/GStreamer/GStreamerTest.cc b/test/VideoManager/GStreamer/GStreamerTest.cc index 4d4d77713e3f..e53f0174bbab 100644 --- a/test/VideoManager/GStreamer/GStreamerTest.cc +++ b/test/VideoManager/GStreamer/GStreamerTest.cc @@ -904,6 +904,9 @@ QGC_GST_SKIP_TEST(_testSourceFactoryJitterBufferNone) QGC_GST_SKIP_TEST(_testSourceFactoryNoRetransmission) QGC_GST_SKIP_TEST(_testSourceFactoryRtspJitterBufferPolicy_data) QGC_GST_SKIP_TEST(_testSourceFactoryRtspJitterBufferPolicy) +QGC_GST_SKIP_TEST(_testSourceFactoryHttpMjpeg) +QGC_GST_SKIP_TEST(_testSourceFactoryHttpMjpegDelivery) +QGC_GST_SKIP_TEST(_testSourceFactoryRejectsUnsafeHttpMjpegUrl) QGC_GST_SKIP_TEST(_testSourceFactoryRejectsBadUri) QGC_GST_SKIP_TEST(_testSourceFactoryTcpMpegTs) QGC_GST_SKIP_TEST(_testSourceFactoryRejectsBadTcpUri) diff --git a/test/VideoManager/GStreamer/GStreamerTest.h b/test/VideoManager/GStreamer/GStreamerTest.h index a2a3db99ca20..003fc1b4033a 100644 --- a/test/VideoManager/GStreamer/GStreamerTest.h +++ b/test/VideoManager/GStreamer/GStreamerTest.h @@ -88,6 +88,9 @@ private slots: void _testSourceFactoryNoRetransmission(); void _testSourceFactoryRtspJitterBufferPolicy_data(); void _testSourceFactoryRtspJitterBufferPolicy(); + void _testSourceFactoryHttpMjpeg(); + void _testSourceFactoryHttpMjpegDelivery(); + void _testSourceFactoryRejectsUnsafeHttpMjpegUrl(); void _testSourceFactoryRejectsBadUri(); void _testSourceFactoryTcpMpegTs(); void _testSourceFactoryRejectsBadTcpUri(); diff --git a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc index c7228756a472..b9700a621df2 100644 --- a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc +++ b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc @@ -2,14 +2,27 @@ #ifdef QGC_GST_STREAMING +#include #include #include +#include +#include #include #include "GstSourceFactory.h" +#include "LocalHttpTestServer.h" +#include "QGCNetworkHelper.h" namespace { +GstSample* tryPullSampleOrPreroll(GstAppSink* sink) +{ + if (GstSample* sample = gst_app_sink_try_pull_sample(sink, 0)) { + return sample; + } + return gst_app_sink_try_pull_preroll(sink, 0); +} + // Borrowed (bin-owned) first child whose element-factory name matches, or nullptr. GstElement* findChildByFactoryName(GstElement* bin, const char* factoryName) { @@ -164,6 +177,174 @@ void GStreamerTest::_testSourceFactoryRtspJitterBufferPolicy() "rtspsrc owns its internal jitterbuffer; the factory must not add a second one"); } +void GStreamerTest::_testSourceFactoryHttpMjpeg() +{ + if (!gst_element_factory_find("souphttpsrc") || !gst_element_factory_find("multipartdemux") || + !gst_element_factory_find("jpegparse")) { + QSKIP("souphttpsrc/multipartdemux/jpegparse plugins unavailable"); + } + + GStreamer::SourceFactory::Config config; + config.timeoutS = 9; + GstElement* bin = GStreamer::SourceFactory::create( + QStringLiteral("https://video.example.test:8443/camera.mjpg?quality=80#local-view"), config); + QVERIFY(bin); + const auto cleanup = qScopeGuard([&] { gst_object_unref(bin); }); + + GstElement* source = findChildByFactoryName(bin, "souphttpsrc"); + GstElement* demux = findChildByFactoryName(bin, "multipartdemux"); + GstElement* parser = findChildByFactoryName(bin, "jpegparse"); + QVERIFY(source); + QVERIFY(demux); + QVERIFY(parser); + + gchar* location = nullptr; + gchar* method = nullptr; + gboolean isLive = FALSE; + gboolean doTimestamp = FALSE; + gboolean keepAlive = FALSE; + gboolean compress = TRUE; + gboolean iradioMode = TRUE; + gboolean automaticRedirect = TRUE; + gboolean sslStrict = FALSE; + gboolean sslUseSystemCaFile = FALSE; + gboolean singleStream = FALSE; + gint retries = -1; + guint timeout = 0; + gint httpLogLevel = -1; + gchar* userAgent = nullptr; + g_object_get(source, "location", &location, "method", &method, "is-live", &isLive, "do-timestamp", &doTimestamp, + "keep-alive", &keepAlive, "compress", &compress, "iradio-mode", &iradioMode, "automatic-redirect", + &automaticRedirect, "retries", &retries, "timeout", &timeout, "ssl-strict", &sslStrict, + "ssl-use-system-ca-file", &sslUseSystemCaFile, "http-log-level", &httpLogLevel, "user-agent", + &userAgent, nullptr); + const auto stringsCleanup = qScopeGuard([&] { + g_free(location); + g_free(method); + g_free(userAgent); + }); + g_object_get(demux, "single-stream", &singleStream, nullptr); + + QCOMPARE(QString::fromUtf8(location), QStringLiteral("https://video.example.test:8443/camera.mjpg?quality=80")); + QCOMPARE(QString::fromUtf8(method), QStringLiteral("GET")); + QCOMPARE(isLive, TRUE); + QCOMPARE(doTimestamp, TRUE); + QCOMPARE(keepAlive, TRUE); + QCOMPARE(compress, FALSE); + QCOMPARE(iradioMode, FALSE); + QCOMPARE(automaticRedirect, FALSE); + QCOMPARE(retries, 0); + QCOMPARE(timeout, 9u); + QCOMPARE(sslStrict, TRUE); + QCOMPARE(sslUseSystemCaFile, TRUE); + QCOMPARE(httpLogLevel, 0); + QCOMPARE(QString::fromUtf8(userAgent), QGCNetworkHelper::defaultUserAgent()); + QCOMPARE(singleStream, TRUE); + + static GstStaticPadTemplate jpegPadTemplate = + GST_STATIC_PAD_TEMPLATE("src_%u", GST_PAD_SRC, GST_PAD_SOMETIMES, GST_STATIC_CAPS("image/jpeg")); + GstPad* jpegPad = gst_pad_new_from_static_template(&jpegPadTemplate, "src_0"); + QVERIFY(jpegPad); + QVERIFY2(gst_element_add_pad(demux, jpegPad), "multipartdemux test pad must be accepted"); + + GstPad* parserSink = gst_element_get_static_pad(parser, "sink"); + QVERIFY(parserSink); + const auto parserSinkCleanup = qScopeGuard([&] { gst_object_unref(parserSink); }); + QVERIFY2(gst_pad_is_linked(parserSink), "multipart JPEG pad-added must link to jpegparse"); + GstPad* peer = gst_pad_get_peer(parserSink); + QVERIFY(peer); + QCOMPARE(peer, jpegPad); + gst_object_unref(peer); + QVERIFY(gst_element_remove_pad(demux, jpegPad)); + + GstPad* srcPad = gst_element_get_static_pad(bin, "src"); + QVERIFY2(srcPad, "HTTP MJPEG source bin must expose a static parsed-JPEG source pad"); + gst_object_unref(srcPad); +} + +void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() +{ + if (!gst_element_factory_find("souphttpsrc") || !gst_element_factory_find("multipartdemux") || + !gst_element_factory_find("jpegparse") || !gst_element_factory_find("appsink")) { + QSKIP("souphttpsrc/multipartdemux/jpegparse/appsink plugins unavailable"); + } + + QByteArray jpeg; + QBuffer jpegBuffer(&jpeg); + QVERIFY(jpegBuffer.open(QIODevice::WriteOnly)); + QImage image(16, 16, QImage::Format_RGB32); + image.fill(Qt::green); + QVERIFY2(image.save(&jpegBuffer, "JPEG"), "Qt JPEG encoder unavailable"); + + const QByteArray boundary("qgc-test-boundary"); + const QByteArray framePart = "--" + boundary + + "\r\n" + "Content-Type: image/jpeg\r\n" + "Content-Length: " + + QByteArray::number(jpeg.size()) + "\r\n\r\n" + jpeg + "\r\n"; + // A multipart video stream contains repeated images. Supplying two also + // verifies delivery after multipartdemux exposes and links its dynamic pad. + const QByteArray body = framePart + framePart + "--" + boundary + "--\r\n"; + const QByteArray response = + "HTTP/1.1 200 OK\r\n" + "Content-Type: multipart/x-mixed-replace; boundary=" + + boundary + + "\r\n" + "Connection: close\r\n" + "Content-Length: " + + QByteArray::number(body.size()) + "\r\n\r\n" + body; + + TestFixtures::LocalHttpTestServer server; + QVERIFY2(server.listen(), "Could not start local MJPEG test server"); + server.installRawResponder(response); + + GStreamer::SourceFactory::Config config; + config.timeoutS = 5; + GstElement* source = GStreamer::SourceFactory::create(server.url(QStringLiteral("/video_feed")), config); + GstElement* sink = gst_element_factory_make("appsink", "sink"); + GstElement* pipeline = gst_pipeline_new("http-mjpeg-delivery-test"); + if (!source || !sink || !pipeline) { + gst_clear_object(&source); + gst_clear_object(&sink); + gst_clear_object(&pipeline); + QFAIL("Could not create HTTP MJPEG delivery pipeline"); + } + const auto pipelineCleanup = qScopeGuard([&] { + (void) gst_element_set_state(pipeline, GST_STATE_NULL); + gst_object_unref(pipeline); + }); + + g_object_set(sink, "sync", FALSE, "max-buffers", 1u, "drop", TRUE, nullptr); + gst_bin_add_many(GST_BIN(pipeline), source, sink, nullptr); + QVERIFY2(gst_element_link(source, sink), "Could not link HTTP MJPEG source to appsink"); + QVERIFY2(gst_element_set_state(pipeline, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE, + "HTTP MJPEG delivery pipeline failed to start"); + + GstSample* sample = nullptr; + QTRY_VERIFY_WITH_TIMEOUT((sample = tryPullSampleOrPreroll(GST_APP_SINK(sink))) != nullptr, TestTimeout::mediumMs()); + const auto sampleCleanup = qScopeGuard([&] { gst_sample_unref(sample); }); + GstBuffer* buffer = gst_sample_get_buffer(sample); + QVERIFY(buffer); + QVERIFY(gst_buffer_get_size(buffer) > 0); + GstCaps* caps = gst_sample_get_caps(sample); + QVERIFY(caps); + QCOMPARE(QString::fromUtf8(gst_structure_get_name(gst_caps_get_structure(caps, 0))), QStringLiteral("image/jpeg")); +} + +void GStreamerTest::_testSourceFactoryRejectsUnsafeHttpMjpegUrl() +{ + ignoreLogMessage("Video.GStreamer.GstSourceFactory", QtWarningMsg, + QRegularExpression(QStringLiteral("Invalid HTTP MJPEG URL"))); + ignoreLogMessage("Video.GStreamer.GstSourceFactory", QtWarningMsg, + QRegularExpression(QStringLiteral("HTTP MJPEG credentials in URLs are not supported"))); + + GStreamer::SourceFactory::Config config; + QVERIFY(!GStreamer::SourceFactory::create(QStringLiteral("http:///camera.mjpg"), config)); + QVERIFY(!GStreamer::SourceFactory::create(QStringLiteral("http://video.example.test:0/camera.mjpg"), config)); + QVERIFY(!GStreamer::SourceFactory::create(QStringLiteral("https://operator:secret@video.example.test/camera.mjpg"), + config)); +} + void GStreamerTest::_testSourceFactoryRejectsBadUri() { ignoreLogMessage("Video.GStreamer.GstSourceFactory", QtCriticalMsg, From d7b14968da27fa8b113184e168a64cdd5156d507 Mon Sep 17 00:00:00 2001 From: alireza787b Date: Tue, 28 Jul 2026 08:12:58 +0000 Subject: [PATCH 2/8] fix(VideoManager): align HTTP video TLS and tests --- .../GStreamer/GstSourceFactory.cc | 7 +++++-- .../GStreamerSourceFactoryTest.cc | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc index cca1589e036d..9fc92cdd89eb 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc @@ -486,10 +486,13 @@ GstElement* buildHttpMjpegSource(const QUrl& sourceUrl, const Config& config) const QByteArray location = cleanUrl.toEncoded(QUrl::FullyEncoded); const QByteArray userAgent = QGCNetworkHelper::defaultUserAgent().toUtf8(); const guint timeoutS = std::clamp(config.timeoutS, 1u, 3600u); + // ssl-strict keeps certificate validation enabled. The active GLib TLS + // backend supplies the platform trust database; the legacy + // ssl-use-system-ca-file property is a no-op with libsoup3. g_object_set(source, "location", location.constData(), "method", "GET", "is-live", TRUE, "do-timestamp", TRUE, "keep-alive", TRUE, "compress", FALSE, "iradio-mode", FALSE, "automatic-redirect", FALSE, - "retries", 0, "timeout", timeoutS, "ssl-strict", TRUE, "ssl-use-system-ca-file", TRUE, - "http-log-level", 0, "user-agent", userAgent.constData(), nullptr); + "retries", 0, "timeout", timeoutS, "ssl-strict", TRUE, "http-log-level", 0, "user-agent", + userAgent.constData(), nullptr); g_object_set(demux, "single-stream", TRUE, nullptr); if (!gst_bin_add(GST_BIN(bin), source)) { diff --git a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc index b9700a621df2..0ba7f8d16b0a 100644 --- a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc +++ b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc @@ -207,7 +207,6 @@ void GStreamerTest::_testSourceFactoryHttpMjpeg() gboolean iradioMode = TRUE; gboolean automaticRedirect = TRUE; gboolean sslStrict = FALSE; - gboolean sslUseSystemCaFile = FALSE; gboolean singleStream = FALSE; gint retries = -1; guint timeout = 0; @@ -216,8 +215,7 @@ void GStreamerTest::_testSourceFactoryHttpMjpeg() g_object_get(source, "location", &location, "method", &method, "is-live", &isLive, "do-timestamp", &doTimestamp, "keep-alive", &keepAlive, "compress", &compress, "iradio-mode", &iradioMode, "automatic-redirect", &automaticRedirect, "retries", &retries, "timeout", &timeout, "ssl-strict", &sslStrict, - "ssl-use-system-ca-file", &sslUseSystemCaFile, "http-log-level", &httpLogLevel, "user-agent", - &userAgent, nullptr); + "http-log-level", &httpLogLevel, "user-agent", &userAgent, nullptr); const auto stringsCleanup = qScopeGuard([&] { g_free(location); g_free(method); @@ -236,7 +234,6 @@ void GStreamerTest::_testSourceFactoryHttpMjpeg() QCOMPARE(retries, 0); QCOMPARE(timeout, 9u); QCOMPARE(sslStrict, TRUE); - QCOMPARE(sslUseSystemCaFile, TRUE); QCOMPARE(httpLogLevel, 0); QCOMPARE(QString::fromUtf8(userAgent), QGCNetworkHelper::defaultUserAgent()); QCOMPARE(singleStream, TRUE); @@ -296,7 +293,6 @@ void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() TestFixtures::LocalHttpTestServer server; QVERIFY2(server.listen(), "Could not start local MJPEG test server"); - server.installRawResponder(response); GStreamer::SourceFactory::Config config; config.timeoutS = 5; @@ -320,6 +316,20 @@ void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() QVERIFY2(gst_element_set_state(pipeline, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE, "HTTP MJPEG delivery pipeline failed to start"); + QTcpSocket* client = server.waitForConnection(TestTimeout::mediumMs()); + QVERIFY2(client, "HTTP MJPEG source did not connect to the local test server"); + const auto clientCleanup = qScopeGuard([&] { + client->disconnectFromHost(); + client->deleteLater(); + }); + if (client->bytesAvailable() == 0) { + QVERIFY2(client->waitForReadyRead(TestTimeout::mediumMs()), "HTTP MJPEG source did not send a request"); + } + const QByteArray request = client->readAll(); + QVERIFY2(request.startsWith("GET /video_feed HTTP/1.1\r\n"), "HTTP MJPEG source sent an unexpected request"); + QCOMPARE(client->write(response), response.size()); + QVERIFY2(client->waitForBytesWritten(TestTimeout::mediumMs()), "Could not deliver the local MJPEG response"); + GstSample* sample = nullptr; QTRY_VERIFY_WITH_TIMEOUT((sample = tryPullSampleOrPreroll(GST_APP_SINK(sink))) != nullptr, TestTimeout::mediumMs()); const auto sampleCleanup = qScopeGuard([&] { gst_sample_unref(sample); }); From c7d33826de2b76b0324e534652637a0076834d8e Mon Sep 17 00:00:00 2001 From: alireza787b Date: Tue, 28 Jul 2026 09:38:47 +0000 Subject: [PATCH 3/8] test(VideoManager): stabilize MJPEG delivery coverage --- .../SourceFactory/GStreamerSourceFactoryTest.cc | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc index 0ba7f8d16b0a..ce5a01576f8c 100644 --- a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc +++ b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc @@ -293,6 +293,7 @@ void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() TestFixtures::LocalHttpTestServer server; QVERIFY2(server.listen(), "Could not start local MJPEG test server"); + server.installRawResponder(response); GStreamer::SourceFactory::Config config; config.timeoutS = 5; @@ -316,22 +317,8 @@ void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() QVERIFY2(gst_element_set_state(pipeline, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE, "HTTP MJPEG delivery pipeline failed to start"); - QTcpSocket* client = server.waitForConnection(TestTimeout::mediumMs()); - QVERIFY2(client, "HTTP MJPEG source did not connect to the local test server"); - const auto clientCleanup = qScopeGuard([&] { - client->disconnectFromHost(); - client->deleteLater(); - }); - if (client->bytesAvailable() == 0) { - QVERIFY2(client->waitForReadyRead(TestTimeout::mediumMs()), "HTTP MJPEG source did not send a request"); - } - const QByteArray request = client->readAll(); - QVERIFY2(request.startsWith("GET /video_feed HTTP/1.1\r\n"), "HTTP MJPEG source sent an unexpected request"); - QCOMPARE(client->write(response), response.size()); - QVERIFY2(client->waitForBytesWritten(TestTimeout::mediumMs()), "Could not deliver the local MJPEG response"); - GstSample* sample = nullptr; - QTRY_VERIFY_WITH_TIMEOUT((sample = tryPullSampleOrPreroll(GST_APP_SINK(sink))) != nullptr, TestTimeout::mediumMs()); + QTRY_VERIFY_WITH_TIMEOUT((sample = tryPullSampleOrPreroll(GST_APP_SINK(sink))) != nullptr, TestTimeout::longMs()); const auto sampleCleanup = qScopeGuard([&] { gst_sample_unref(sample); }); GstBuffer* buffer = gst_sample_get_buffer(sample); QVERIFY(buffer); From 9c45eed439b96cd8eb586eadc83cdd5f4cec9c62 Mon Sep 17 00:00:00 2001 From: alireza787b Date: Tue, 28 Jul 2026 10:53:21 +0000 Subject: [PATCH 4/8] fix(VideoManager): support older GLib connect flags --- src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc index 9fc92cdd89eb..69c5848bf629 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc @@ -521,7 +521,7 @@ GstElement* buildHttpMjpegSource(const QUrl& sourceUrl, const Config& config) break; } (void) g_signal_connect_object(binDemux, "pad-added", G_CALLBACK(linkMultipartJpegPad), binParser, - G_CONNECT_DEFAULT); + static_cast(0)); if (!addStaticGhostPad(binParser)) { break; } From 76ba8f4a7dc235ec93517356ed7f78ac7bbd84b3 Mon Sep 17 00:00:00 2001 From: alireza787b Date: Tue, 28 Jul 2026 11:28:02 +0000 Subject: [PATCH 5/8] test(VideoManager): keep MJPEG fixture responsive --- .../SourceFactory/GStreamerSourceFactoryTest.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc index ce5a01576f8c..1a05e8b6f249 100644 --- a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc +++ b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -314,11 +315,18 @@ void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() g_object_set(sink, "sync", FALSE, "max-buffers", 1u, "drop", TRUE, nullptr); gst_bin_add_many(GST_BIN(pipeline), source, sink, nullptr); QVERIFY2(gst_element_link(source, sink), "Could not link HTTP MJPEG source to appsink"); - QVERIFY2(gst_element_set_state(pipeline, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE, + + // souphttpsrc can wait for the HTTP response while changing state. Run that + // transition off-thread so this test's Qt event loop can serve the request. + const QFuture stateFuture = + QtConcurrent::run([pipeline]() { return gst_element_set_state(pipeline, GST_STATE_PLAYING); }); + QTRY_VERIFY_WITH_TIMEOUT(stateFuture.isFinished(), TestTimeout::mediumMs()); + QVERIFY2(stateFuture.result() != GST_STATE_CHANGE_FAILURE, "HTTP MJPEG delivery pipeline failed to start"); GstSample* sample = nullptr; - QTRY_VERIFY_WITH_TIMEOUT((sample = tryPullSampleOrPreroll(GST_APP_SINK(sink))) != nullptr, TestTimeout::longMs()); + QTRY_VERIFY_WITH_TIMEOUT((sample = tryPullSampleOrPreroll(GST_APP_SINK(sink))) != nullptr, + TestTimeout::mediumMs()); const auto sampleCleanup = qScopeGuard([&] { gst_sample_unref(sample); }); GstBuffer* buffer = gst_sample_get_buffer(sample); QVERIFY(buffer); From b9619ee3c18c2c2dc2889d41d44690d359a5ff96 Mon Sep 17 00:00:00 2001 From: alireza787b Date: Tue, 28 Jul 2026 15:45:03 +0000 Subject: [PATCH 6/8] test(VideoManager): serve MJPEG delivery synchronously --- .../GStreamerSourceFactoryTest.cc | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc index 1a05e8b6f249..5994582c60f3 100644 --- a/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc +++ b/test/VideoManager/GStreamer/SourceFactory/GStreamerSourceFactoryTest.cc @@ -2,10 +2,11 @@ #ifdef QGC_GST_STREAMING +#include #include +#include #include #include -#include #include #include #include @@ -16,9 +17,9 @@ namespace { -GstSample* tryPullSampleOrPreroll(GstAppSink* sink) +GstSample* tryPullSampleOrPreroll(GstAppSink* sink, GstClockTime timeout = 0) { - if (GstSample* sample = gst_app_sink_try_pull_sample(sink, 0)) { + if (GstSample* sample = gst_app_sink_try_pull_sample(sink, timeout)) { return sample; } return gst_app_sink_try_pull_preroll(sink, 0); @@ -280,21 +281,18 @@ void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() "Content-Type: image/jpeg\r\n" "Content-Length: " + QByteArray::number(jpeg.size()) + "\r\n\r\n" + jpeg + "\r\n"; - // A multipart video stream contains repeated images. Supplying two also - // verifies delivery after multipartdemux exposes and links its dynamic pad. - const QByteArray body = framePart + framePart + "--" + boundary + "--\r\n"; + // Keep the multipart response open like a camera stream so delivery does + // not depend on the timing of a finite response reaching EOS. const QByteArray response = "HTTP/1.1 200 OK\r\n" "Content-Type: multipart/x-mixed-replace; boundary=" + boundary + "\r\n" - "Connection: close\r\n" - "Content-Length: " + - QByteArray::number(body.size()) + "\r\n\r\n" + body; + "Connection: keep-alive\r\n\r\n" + + framePart + framePart; TestFixtures::LocalHttpTestServer server; QVERIFY2(server.listen(), "Could not start local MJPEG test server"); - server.installRawResponder(response); GStreamer::SourceFactory::Config config; config.timeoutS = 5; @@ -317,16 +315,40 @@ void GStreamerTest::_testSourceFactoryHttpMjpegDelivery() QVERIFY2(gst_element_link(source, sink), "Could not link HTTP MJPEG source to appsink"); // souphttpsrc can wait for the HTTP response while changing state. Run that - // transition off-thread so this test's Qt event loop can serve the request. + // transition off-thread so this thread can accept and serve the request. const QFuture stateFuture = QtConcurrent::run([pipeline]() { return gst_element_set_state(pipeline, GST_STATE_PLAYING); }); + + QTcpSocket* client = server.waitForConnection(TestTimeout::mediumMs()); + QVERIFY2(client, "HTTP MJPEG source did not connect to the local test server"); + const auto clientCleanup = qScopeGuard([&] { + client->disconnectFromHost(); + client->deleteLater(); + }); + + QByteArray request; + QDeadlineTimer requestDeadline(TestTimeout::mediumDuration()); + while (!request.contains(QByteArrayLiteral("\r\n\r\n")) && !requestDeadline.hasExpired()) { + request.append(client->readAll()); + if (!request.contains(QByteArrayLiteral("\r\n\r\n"))) { + (void) client->waitForReadyRead(static_cast(requestDeadline.remainingTime())); + } + } + QVERIFY2(request.startsWith(QByteArrayLiteral("GET /video_feed HTTP/1.1\r\n")), + "HTTP MJPEG source sent an unexpected request"); + + QCOMPARE(client->write(response), static_cast(response.size())); + QDeadlineTimer responseDeadline(TestTimeout::mediumDuration()); + while ((client->bytesToWrite() > 0) && !responseDeadline.hasExpired()) { + (void) client->waitForBytesWritten(static_cast(responseDeadline.remainingTime())); + } + QCOMPARE(client->bytesToWrite(), 0); + QTRY_VERIFY_WITH_TIMEOUT(stateFuture.isFinished(), TestTimeout::mediumMs()); - QVERIFY2(stateFuture.result() != GST_STATE_CHANGE_FAILURE, - "HTTP MJPEG delivery pipeline failed to start"); + QVERIFY2(stateFuture.result() != GST_STATE_CHANGE_FAILURE, "HTTP MJPEG delivery pipeline failed to start"); - GstSample* sample = nullptr; - QTRY_VERIFY_WITH_TIMEOUT((sample = tryPullSampleOrPreroll(GST_APP_SINK(sink))) != nullptr, - TestTimeout::mediumMs()); + GstSample* sample = tryPullSampleOrPreroll(GST_APP_SINK(sink), TestTimeout::mediumDuration().count() * GST_MSECOND); + QVERIFY2(sample, "HTTP MJPEG stream did not deliver a JPEG sample before timeout"); const auto sampleCleanup = qScopeGuard([&] { gst_sample_unref(sample); }); GstBuffer* buffer = gst_sample_get_buffer(sample); QVERIFY(buffer); From 5d29e216306c320c1e48a48526ffad70a0f7b07f Mon Sep 17 00:00:00 2001 From: alireza787b Date: Fri, 31 Jul 2026 01:23:25 +0000 Subject: [PATCH 7/8] style(VideoManager): format source factory changes --- src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc index 69c5848bf629..d518730fa63c 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc @@ -645,7 +645,8 @@ GstElement* create(const QString& uri, const Config& config) const bool isHttpMjpeg = (scheme == QLatin1String("http")) || (scheme == QLatin1String("https")); if (!isRtsp && !isUdpH264 && !isUdpH265 && !isUdpMPEGTS && !isTcpMPEGTS && !isHttpMjpeg) { - qCWarning(GstSourceFactoryLog) << "Unsupported URI scheme:" << scheme << "in" << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); + qCWarning(GstSourceFactoryLog) << "Unsupported URI scheme:" << scheme << "in" + << sourceUrl.toDisplayString(QUrl::RemoveUserInfo); return nullptr; } From d5ab4fbd5980522a788cb186c17c424d51b2ca8c Mon Sep 17 00:00:00 2001 From: alireza787b Date: Thu, 20 Aug 2026 09:12:11 +0000 Subject: [PATCH 8/8] fix(VideoManager): keep HTTP stack independent --- src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc index d518730fa63c..22f657f59597 100644 --- a/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc +++ b/src/VideoManager/VideoReceiver/GStreamer/GstSourceFactory.cc @@ -8,6 +8,7 @@ #include "GStreamerHelpers.h" #include "QGCLoggingCategory.h" +#include "QGCNetworkHelper.h" QGC_LOGGING_CATEGORY(GstSourceFactoryLog, "Video.GStreamer.GstSourceFactory") @@ -459,8 +460,7 @@ void linkMultipartJpegPad(GstElement* element, GstPad* pad, gpointer data) GstElement* buildHttpMjpegSource(const QUrl& sourceUrl, const Config& config) { if (!sourceUrl.isValid() || sourceUrl.isRelative() || sourceUrl.host().isEmpty() || (sourceUrl.port() == 0)) { - qCWarning(GstSourceFactoryLog) << "Invalid HTTP MJPEG URL:" - << QGCNetworkHelper::redactedUrlForLogging(sourceUrl); + qCWarning(GstSourceFactoryLog) << "Invalid HTTP MJPEG URL"; return nullptr; } if (!sourceUrl.userInfo().isEmpty()) {