Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit da725066 authored by Jan Grulich's avatar Jan Grulich

Move some stream related code from screencast portal to screencast stream

parent 31363e46
......@@ -70,7 +70,6 @@ const QDBusArgument &operator << (QDBusArgument &arg, const ScreenCastPortal::St
ScreenCastPortal::ScreenCastPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
, m_streamingEnabled(false)
{
qDBusRegisterMetaType<ScreenCastPortal::Stream>();
qDBusRegisterMetaType<ScreenCastPortal::Streams>();
......@@ -78,27 +77,15 @@ ScreenCastPortal::ScreenCastPortal(QObject *parent)
ScreenCastPortal::~ScreenCastPortal()
{
m_stream->deleteLater();
if (m_stream) {
delete m_stream;
}
}
void ScreenCastPortal::createPipeWireStream(const QSize &resolution)
{
m_stream = new ScreenCastStream(resolution);
m_stream->init();
connect(m_stream, &ScreenCastStream::streamReady, this, [] (uint nodeId) {
qCDebug(XdgDesktopPortalKdeScreenCast) << "Pipewire stream is ready: " << nodeId;
});
connect(WaylandIntegration::waylandIntegration(), &WaylandIntegration::WaylandIntegration::newBuffer, m_stream, &ScreenCastStream::recordFrame);
connect(m_stream, &ScreenCastStream::startStreaming, this, [this] {
qCDebug(XdgDesktopPortalKdeScreenCast) << "Start streaming";
m_streamingEnabled = true;
WaylandIntegration::startStreaming();
});
connect(m_stream, &ScreenCastStream::stopStreaming, this, &ScreenCastPortal::stopStreaming);
}
uint ScreenCastPortal::CreateSession(const QDBusObjectPath &handle,
......@@ -224,8 +211,6 @@ uint ScreenCastPortal::Start(const QDBusObjectPath &handle,
// TODO support multiple outputs
qCDebug(XdgDesktopPortalKdeScreenCast) << "Pipewire node id: " << m_stream->nodeId();
WaylandIntegration::bindOutput(selectedOutput.waylandOutputName(), selectedOutput.waylandOutputVersion());
Stream stream;
......@@ -241,10 +226,8 @@ uint ScreenCastPortal::Start(const QDBusObjectPath &handle,
void ScreenCastPortal::stopStreaming()
{
if (m_streamingEnabled) {
qCDebug(XdgDesktopPortalKdeScreenCast) << "Stop streaming";
WaylandIntegration::stopStreaming();
m_streamingEnabled = false;
if (m_stream) {
m_stream->stopStream();
delete m_stream;
m_stream = nullptr;
}
......
......@@ -80,8 +80,6 @@ private:
void createPipeWireStream(const QSize &resolution);
ScreenCastStream *m_stream;
bool m_streamingEnabled;
};
#endif // XDG_DESKTOP_PORTAL_KDE_SCREENCAST_H
......
......@@ -19,6 +19,7 @@
*/
#include "screencaststream.h"
#include "waylandintegration.h"
#include <math.h>
#include <sys/mman.h>
......@@ -156,7 +157,7 @@ static void onStateChanged(void *data, pw_remote_state old, pw_remote_state stat
// TODO notify error
qCDebug(XdgDesktopPortalKdeScreenCastStream) << "Remote state: " << pw_remote_state_as_string(state);
if (!pw->createStream()) {
pw->stopStreaming();
Q_EMIT pw->stoppedStreaming();
}
break;
default:
......@@ -183,12 +184,16 @@ static void onStreamStateChanged(void *data, pw_stream_state old, pw_stream_stat
case PW_STREAM_STATE_CONNECTING:
case PW_STREAM_STATE_READY:
case PW_STREAM_STATE_PAUSED:
qCDebug(XdgDesktopPortalKdeScreenCastStream) << "Stream state: " << pw_stream_state_as_string(state);
Q_EMIT pw->stopStreaming();
qCDebug(XdgDesktopPortalKdeScreenCastStream) << "Stream state: " << pw_stream_state_as_string(state) << pw->streaming;
if (pw->streaming) {
pw->stopStream();
}
break;
case PW_STREAM_STATE_STREAMING:
qCDebug(XdgDesktopPortalKdeScreenCastStream) << "Stream state: " << pw_stream_state_as_string(state);
Q_EMIT pw->startStreaming();
pw->streaming = true;
WaylandIntegration::startStreaming();
Q_EMIT pw->startedStreaming();
break;
}
}
......@@ -308,6 +313,8 @@ void ScreenCastStream::init()
pw_remote_add_listener(pwRemote, &remoteListener, &pwRemoteEvents, this);
pw_remote_connect(pwRemote);
connect(WaylandIntegration::waylandIntegration(), &WaylandIntegration::WaylandIntegration::newBuffer, this, &ScreenCastStream::recordFrame);
}
uint ScreenCastStream::nodeId()
......@@ -351,7 +358,7 @@ bool ScreenCastStream::createStream()
pwCoreType->param.idEnumFormat, pwCoreType->spa_format,
"I", pwType->media_type.video,
"I", pwType->media_subtype.raw,
":", pwType->format_video.format, "I", pwType->video_format.RGBx,
":", pwType->format_video.format, "I", pwType->video_format.xRGB,
":", pwType->format_video.size, "Rru", &maxResolution, SPA_POD_PROP_MIN_MAX(&minResolution, &maxResolution),
":", pwType->format_video.framerate, "F", &paramFraction,
":", pwType->format_video.max_framerate, "Fru", &maxFramerate, PROP_RANGE (&minFramerate, &maxFramerate));
......@@ -448,6 +455,18 @@ void ScreenCastStream::removeStream()
pw_stream_disconnect(pwStream);
}
void ScreenCastStream::stopStream()
{
qCDebug(XdgDesktopPortalKdeScreenCastStream) << "Stop streaming";
streaming = false;
WaylandIntegration::stopStreaming();
// removeStream();
Q_EMIT stoppedStreaming();
}
void ScreenCastStream::initializePwTypes()
{
// raw C-like ScreenCastStream type map
......
......@@ -71,14 +71,15 @@ public:
// Public because we need access from static functions
bool createStream();
void removeStream();
void stopStream();
public Q_SLOTS:
bool recordFrame(uint8_t *screenData);
Q_SIGNALS:
void streamReady(uint nodeId);
void startStreaming();
void stopStreaming();
void startedStreaming();
void stoppedStreaming();
private:
void initializePwTypes();
......@@ -87,6 +88,7 @@ private Q_SLOTS:
void processPipewireEvents();
public:
bool streaming = false;
pw_core *pwCore = nullptr;
pw_loop *pwLoop = nullptr;
pw_node *pwNode = nullptr;
......
......@@ -327,8 +327,6 @@ void WaylandIntegration::WaylandIntegrationPrivate::processBuffer(const KWayland
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << QString("Incoming GBM fd %1, %2x%3, stride %4, fourcc 0x%5").arg(gbmHandle).arg(width).arg(height).arg(stride).arg(QString::number(format, 16));
// TODO streaming m_streamingEnabled
if (!m_streamingEnabled) {
qCDebug(XdgDesktopPortalKdeWaylandIntegration) << "Streaming is disabled";
close(gbmHandle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment