Skip to content

Commit

Permalink
GStreamer: introduce qiodevice:/ uri scheme
Browse files Browse the repository at this point in the history
Using `QGstAppSource` to inject data into GStreamer has a few problems:

* it is a bit cumbersome to use, as it requires going through
signal/slot connections
* it is not possible to use the same stream in multiple locations (e.g.
player and discoverer)
* it is not thread-safe (gst_play sends on_need_data after the stream is
closed by another thread)
* the ownership of QGstAppSource is rather complicated, as it's owned by
both

So we replace the QGstAppSource by a qiodevice:/ uri scheme:
* multiple threads may access the same QIODevice in a thread-safe manner
* gstreamer handles the element construction under the hood

Task-number: QTBUG-129467
Pick-to: 6.5 6.7 6.8
Change-Id: I041d1e42368d19fb2ee64b6f3730c204458a6e85
Reviewed-by: Artem Dyomin <[email protected]>
  • Loading branch information
timblechmann committed Oct 2, 2024
1 parent e829737 commit 43083d6
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 341 deletions.
3 changes: 2 additions & 1 deletion src/plugins/multimedia/gstreamer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ qt_internal_add_module(QGstreamerMediaPluginImplPrivate
common/qgst_bus.cpp common/qgst_bus_p.h
common/qgst_debug.cpp common/qgst_debug_p.h
common/qgst_handle_types_p.h
common/qgstappsource.cpp common/qgstappsource_p.h
common/qgstreameraudioinput.cpp common/qgstreameraudioinput_p.h
common/qgstreameraudiooutput.cpp common/qgstreameraudiooutput_p.h
common/qgstreamerbufferprobe.cpp common/qgstreamerbufferprobe_p.h
Expand All @@ -36,6 +35,7 @@ qt_internal_add_module(QGstreamerMediaPluginImplPrivate
mediacapture/qgstreamerimagecapture.cpp mediacapture/qgstreamerimagecapture_p.h
mediacapture/qgstreamermediacapturesession.cpp mediacapture/qgstreamermediacapturesession_p.h
mediacapture/qgstreamermediarecorder.cpp mediacapture/qgstreamermediarecorder_p.h
uri_handler/qgstreamer_qiodevice_handler.cpp uri_handler/qgstreamer_qiodevice_handler_p.h
uri_handler/qgstreamer_qrc_handler.cpp uri_handler/qgstreamer_qrc_handler_p.h

NO_UNITY_BUILD_SOURCES
Expand All @@ -44,6 +44,7 @@ qt_internal_add_module(QGstreamerMediaPluginImplPrivate
common/qgstreamervideosink.cpp

# preprocessor / internal linkage
uri_handler/qgstreamer_qiodevice_handler.cpp
uri_handler/qgstreamer_qrc_handler.cpp
NO_GENERATE_CPP_EXPORTS
DEFINES
Expand Down
20 changes: 3 additions & 17 deletions src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <audio/qgstreameraudiodecoder_p.h>

#include <common/qgst_debug_p.h>
#include <common/qgstappsource_p.h>
#include <common/qgstreamermessage_p.h>
#include <common/qgstutils_p.h>
#include <uri_handler/qgstreamer_qiodevice_handler_p.h>

#include <gst/gstvalue.h>
#include <gst/base/gstbasesrc.h>
Expand Down Expand Up @@ -71,9 +71,6 @@ QGstreamerAudioDecoder::QGstreamerAudioDecoder(QAudioDecoder *parent)

g_object_set(m_playbin.object(), "audio-sink", m_outputBin.element(), NULL);

m_deepNotifySourceConnection = m_playbin.connect(
"deep-notify::source", (GCallback)&configureAppSrcElement, (gpointer)this);

// Set volume to 100%
gdouble volume = 1.0;
m_playbin.set("volume", volume);
Expand All @@ -86,18 +83,6 @@ QGstreamerAudioDecoder::~QGstreamerAudioDecoder()
m_playbin.removeMessageFilter(this);
}

void QGstreamerAudioDecoder::configureAppSrcElement([[maybe_unused]] GObject *object, GObject *orig,
[[maybe_unused]] GParamSpec *pspec,
QGstreamerAudioDecoder *self)
{
QGstElementHandle appsrc;
g_object_get(orig, "source", &appsrc, NULL);

GstAppSrc *gstAppSrc = qGstSafeCast<GstAppSrc>(appsrc.release());
if (gstAppSrc)
QGstAppSource::attachQIODeviceToGstAppSrc(gstAppSrc, self->mDevice);
}

bool QGstreamerAudioDecoder::processBusMessage(const QGstreamerMessage &message)
{
qCDebug(qLcGstreamerAudioDecoder) << "received bus message:" << message;
Expand Down Expand Up @@ -310,7 +295,8 @@ void QGstreamerAudioDecoder::start()
return;
}

m_playbin.set("uri", "appsrc://");
QUrl streamURL = qGstRegisterQIODevice(mDevice);
m_playbin.set("uri", streamURL.toEncoded().constData());
} else {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ private slots:
static GstFlowReturn new_sample(GstAppSink *sink, gpointer user_data);
GstFlowReturn newSample(GstAppSink *sink);

static void configureAppSrcElement(GObject *, GObject *, GParamSpec *,
QGstreamerAudioDecoder *_this);

void setAudioFlags(bool wantNativeAudio);
void addAppSink();
void removeAppSink();
Expand Down
233 changes: 0 additions & 233 deletions src/plugins/multimedia/gstreamer/common/qgstappsource.cpp

This file was deleted.

72 changes: 0 additions & 72 deletions src/plugins/multimedia/gstreamer/common/qgstappsource_p.h

This file was deleted.

Loading

0 comments on commit 43083d6

Please sign in to comment.