Commit 76811d65 authored by Jan Grulich's avatar Jan Grulich
Browse files

Add screen cast portal

Summary:
Add support for screen casting, using pipewire for creating streams. Screen data
is supplied by KWin which sends us GBM fd using Remote Access interface from KWayland.

Note that this is meant for sandboxed and also not sandboxed applications as plan for Pipewire is that
if application talks directly to Pipewire, not calling xdg-desktop-portal (the middle man), then Pipewire
will still call backend implementation internally, in our case xdg-desktop-portal-kde to get screen cast stream.

Depends on D1231 and D1230

Reviewers: graesslin, Kanedias, romangg, davidedmundson

Reviewed By: Kanedias

Subscribers: #plasma

Maniphest Tasks: T7785

Differential Revision: https://phabricator.kde.org/D10965
parent 7adf7aad
......@@ -9,7 +9,7 @@ set(PROJECT_VERSION_MAJOR 5)
################# set KDE specific information #################
find_package(ECM 1.3.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(KDEInstallDirs)
include(KDECMakeSettings)
......@@ -19,6 +19,27 @@ include(ECMPackageConfigHelpers)
include(ECMOptionalAddSubdirectory)
include(FeatureSummary)
include(FindPkgConfig)
# remove?
pkg_check_modules(PIPEWIRE REQUIRED libpipewire-0.1)
pkg_check_modules(SPA REQUIRED libspa-0.1)
pkg_check_modules(GLIB REQUIRED glib-2.0)
find_package(gbm REQUIRED)
set_package_properties(gbm PROPERTIES DESCRIPTION "GBM - Generic Buffer Management"
TYPE REQUIRED
PURPOSE "Required for egl ouput of drm backend."
)
find_package(epoxy REQUIRED)
include_directories(${epoxy_INCLUDE_DIRS})
set_package_properties(epoxy PROPERTIES DESCRIPTION "libepoxy"
URL "http://github.com/anholt/libepoxy"
TYPE REQUIRED
PURPOSE "OpenGL dispatch library for GBM backend"
)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
DBus
......@@ -30,9 +51,10 @@ find_package(KF5 REQUIRED
CoreAddons
I18n
Notifications
Wayland
)
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0 -DQT_NO_KEYWORDS)
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FROM_BYTEARRAY)
......
# - Try to find libepoxy
# Once done this will define
#
# epoxy_FOUND - System has libepoxy
# epoxy_LIBRARY - The libepoxy library
# epoxy_INCLUDE_DIR - The libepoxy include dir
# epoxy_DEFINITIONS - Compiler switches required for using libepoxy
# epoxy_HAS_GLX - Whether GLX support is available
# Copyright (c) 2014 Fredrik Höglund <fredrik@kde.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
if (NOT WIN32)
find_package(PkgConfig)
pkg_check_modules(PKG_epoxy QUIET epoxy)
set(epoxy_DEFINITIONS ${PKG_epoxy_CFLAGS})
find_path(epoxy_INCLUDE_DIR NAMES epoxy/gl.h HINTS ${PKG_epoxy_INCLUDEDIR} ${PKG_epoxy_INCLUDE_DIRS})
find_library(epoxy_LIBRARY NAMES epoxy HINTS ${PKG_epoxy_LIBDIR} ${PKG_epoxy_LIBRARY_DIRS})
find_file(epoxy_GLX_HEADER NAMES epoxy/glx.h HINTS ${epoxy_INCLUDE_DIR})
if (epoxy_GLX_HEADER STREQUAL "epoxy_GLX_HEADER-NOTFOUND")
set(epoxy_HAS_GLX FALSE CACHE BOOL "whether glx is available")
else ()
set(epoxy_HAS_GLX TRUE CACHE BOOL "whether glx is available")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(epoxy DEFAULT_MSG epoxy_LIBRARY epoxy_INCLUDE_DIR)
mark_as_advanced(epoxy_INCLUDE_DIR epoxy_LIBRARY epoxy_HAS_GLX)
endif()
#.rst:
# Findgbm
# -------
#
# Try to find gbm on a Unix system.
#
# This will define the following variables:
#
# ``gbm_FOUND``
# True if (the requested version of) gbm is available
# ``gbm_VERSION``
# The version of gbm
# ``gbm_LIBRARIES``
# This can be passed to target_link_libraries() instead of the ``gbm::gbm``
# target
# ``gbm_INCLUDE_DIRS``
# This should be passed to target_include_directories() if the target is not
# used for linking
# ``gbm_DEFINITIONS``
# This should be passed to target_compile_options() if the target is not
# used for linking
#
# If ``gbm_FOUND`` is TRUE, it will also define the following imported target:
#
# ``gbm::gbm``
# The gbm library
#
# In general we recommend using the imported target, as it is easier to use.
# Bear in mind, however, that if the target is in the link interface of an
# exported library, it must be made available by the package config file.
#=============================================================================
# Copyright 2014 Alex Merry <alex.merry@kde.org>
# Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
if(CMAKE_VERSION VERSION_LESS 2.8.12)
message(FATAL_ERROR "CMake 2.8.12 is required by Findgbm.cmake")
endif()
if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.12)
message(AUTHOR_WARNING "Your project should require at least CMake 2.8.12 to use Findgbm.cmake")
endif()
if(NOT WIN32)
# Use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
pkg_check_modules(PKG_gbm QUIET gbm)
set(gbm_DEFINITIONS ${PKG_gbm_CFLAGS_OTHER})
set(gbm_VERSION ${PKG_gbm_VERSION})
find_path(gbm_INCLUDE_DIR
NAMES
gbm.h
HINTS
${PKG_gbm_INCLUDE_DIRS}
)
find_library(gbm_LIBRARY
NAMES
gbm
HINTS
${PKG_gbm_LIBRARY_DIRS}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(gbm
FOUND_VAR
gbm_FOUND
REQUIRED_VARS
gbm_LIBRARY
gbm_INCLUDE_DIR
VERSION_VAR
gbm_VERSION
)
if(gbm_FOUND AND NOT TARGET gbm::gbm)
add_library(gbm::gbm UNKNOWN IMPORTED)
set_target_properties(gbm::gbm PROPERTIES
IMPORTED_LOCATION "${gbm_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${gbm_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${gbm_INCLUDE_DIR}"
)
endif()
mark_as_advanced(gbm_LIBRARY gbm_INCLUDE_DIR)
# compatibility variables
set(gbm_LIBRARIES ${gbm_LIBRARY})
set(gbm_INCLUDE_DIRS ${gbm_INCLUDE_DIR})
set(gbm_VERSION_STRING ${gbm_VERSION})
else()
message(STATUS "Findgbm.cmake cannot find gbm on Windows systems.")
set(gbm_FOUND FALSE)
endif()
include(FeatureSummary)
set_package_properties(gbm PROPERTIES
URL "http://www.mesa3d.org"
DESCRIPTION "Mesa gbm library."
)
[portal]
DBusName=org.freedesktop.impl.portal.desktop.kde
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Email;org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.Inhibit;org.freedesktop.impl.portal.Notification;org.freedesktop.impl.portal.Print
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Email;org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.Inhibit;org.freedesktop.impl.portal.Notification;org.freedesktop.impl.portal.Print;org.freedesktop.impl.portal.ScreenCast
UseIn=KDE
......@@ -2,6 +2,8 @@ add_definitions(-DTRANSLATION_DOMAIN="xdg-desktop-portal-kde")
include_directories(
${Qt5PrintSupport_PRIVATE_INCLUDE_DIRS}
${PIPEWIRE_INCLUDE_DIRS} ${SPA_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS}
${gbm_INCLUDE_DIRS}
)
set(xdg_desktop_portal_kde_SRCS
......@@ -17,11 +19,16 @@ set(xdg_desktop_portal_kde_SRCS
notification.cpp
print.cpp
request.cpp
screencast.cpp
screencaststream.cpp
screenchooserdialog.cpp
session.cpp
)
ki18n_wrap_ui(xdg_desktop_portal_kde_SRCS
accessdialog.ui
appchooserdialog.ui
screenchooserdialog.ui
)
add_executable(xdg-desktop-portal-kde ${xdg_desktop_portal_kde_SRCS})
......@@ -34,6 +41,12 @@ target_link_libraries(xdg-desktop-portal-kde
KF5::CoreAddons
KF5::I18n
KF5::Notifications
KF5::WaylandClient
${PIPEWIRE_LIBRARIES}
${SPA_LIBRARIES}
${GLIB_LIBRARIES}
${epoxy_LIBRARY}
gbm::gbm
)
install(TARGETS xdg-desktop-portal-kde DESTINATION ${KDE_INSTALL_LIBEXECDIR})
......@@ -24,7 +24,7 @@
#include <KLocalizedString>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAccess, "xdg-desktop-portal-kde-access")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAccess, "xdp-kde-access")
AccessPortal::AccessPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
......
......@@ -26,7 +26,7 @@
#include <QStandardPaths>
#include <QPushButton>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAccessDialog, "xdg-desktop-portal-kde-access-dialog")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAccessDialog, "xdp-kde-access-dialog")
AccessDialog::AccessDialog(QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
......
......@@ -24,7 +24,7 @@
#include <KLocalizedString>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAppChooser, "xdg-desktop-portal-kde-app-chooser")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAppChooser, "xdp-kde-app-chooser")
AppChooserPortal::AppChooserPortal(QObject *parent)
......
......@@ -26,7 +26,7 @@
#include <QStandardPaths>
#include <QPushButton>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAppChooserDialog, "xdg-desktop-portal-kde-app-chooser-dialog")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAppChooserDialog, "xdp-kde-app-chooser-dialog")
AppChooserDialog::AppChooserDialog(const QStringList &choices, QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
......
......@@ -26,7 +26,7 @@
#include <QDBusConnection>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeDesktopPortal, "xdg-desktop-portal-kde-desktop-portal")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeDesktopPortal, "xdp-kde-desktop-portal")
DesktopPortal::DesktopPortal(QObject *parent)
: QObject(parent)
......@@ -37,6 +37,7 @@ DesktopPortal::DesktopPortal(QObject *parent)
, m_inhibit(new InhibitPortal(this))
, m_notification(new NotificationPortal(this))
, m_print(new PrintPortal(this))
, m_screenCast(new ScreenCastPortal(this))
{
}
......
......@@ -31,6 +31,7 @@
#include "inhibit.h"
#include "notification.h"
#include "print.h"
#include "screencast.h"
class DesktopPortal : public QObject
{
......@@ -47,6 +48,7 @@ private:
InhibitPortal *m_inhibit;
NotificationPortal *m_notification;
PrintPortal *m_print;
ScreenCastPortal *m_screenCast;
};
#endif // XDG_DESKTOP_PORTAL_KDE_DESKTOP_PORTAL_H
......
......@@ -24,7 +24,7 @@
#include <QLoggingCategory>
#include <QUrl>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeEmail, "xdg-desktop-portal-kde-email")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeEmail, "xdp-kde-email")
EmailPortal::EmailPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
......
......@@ -26,7 +26,7 @@
#include <QFileDialog>
#include <KLocalizedString>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeFileChooser, "xdg-desktop-portal-kde-file-chooser")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeFileChooser, "xdp-kde-file-chooser")
// Keep in sync with qflatpakfiledialog from flatpak-platform-plugin
Q_DECLARE_METATYPE(FileChooserPortal::Filter);
......
......@@ -29,7 +29,7 @@
#include <QDBusPendingCallWatcher>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeInhibit, "xdg-desktop-portal-kde-inhibit")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeInhibit, "xdp-kde-inhibit")
InhibitPortal::InhibitPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
......
......@@ -25,7 +25,7 @@
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeNotification, "xdg-desktop-portal-kde-notification")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeNotification, "xdp-kde-notification")
NotificationPortal::NotificationPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
......
......@@ -33,7 +33,7 @@
#include <QUrl>
#include <QTemporaryFile>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdePrint, "xdg-desktop-portal-kde-print")
Q_LOGGING_CATEGORY(XdgDesktopPortalKdePrint, "xdp-kde-print")
// INFO: code below is copied from Qt as there is no public API for converting key to PageSizeId
......
......@@ -28,7 +28,7 @@
#include <QDBusPendingCallWatcher>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(XdgRequestKdeRequest, "xdg-desktop-portal-kde-request")
Q_LOGGING_CATEGORY(XdgRequestKdeRequest, "xdp-kde-request")
Request::Request(QObject *parent, const QString &portalName, const QVariant &data)
: QDBusVirtualObject(parent)
......
This diff is collapsed.
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_SCREENCAST_H
#define XDG_DESKTOP_PORTAL_KDE_SCREENCAST_H
#include <QDBusAbstractAdaptor>
#include <QDBusObjectPath>
#include <QSize>
#include <gbm.h>
#include <epoxy/egl.h>
#include <epoxy/gl.h>
namespace KWayland {
namespace Client {
class ConnectionThread;
class EventQueue;
class OutputDevice;
class Registry;
class RemoteAccessManager;
class RemoteBuffer;
class Output;
}
}
class Session;
class ScreenChooserDialog;
class ScreenCastStream;
class ScreenCastPortalOutput
{
enum OutputType {
Laptop,
Monitor,
Television
};
void setOutputType(const QString &type);
QString manufacturer;
QString model;
QSize resolution;
OutputType outputType;
// Needed for later output binding
int waylandOutputName;
int waylandOutputVersion;
friend class ScreenCastPortal;
friend class ScreenChooserDialog;
};
class ScreenCastPortal : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.ScreenCast")
Q_PROPERTY(uint version READ version)
Q_PROPERTY(uint AvailableSourceTypes READ AvailableSourceTypes)
public:
typedef struct {
uint nodeId;
QVariantMap map;
} Stream;
typedef QList<Stream> Streams;
enum SourceType {
Any = 0,
Monitor,
Window
};
ScreenCastPortal(QObject *parent);
~ScreenCastPortal();
uint version() const { return 1; }
uint AvailableSourceTypes() const { return Monitor; };
public Q_SLOTS:
uint CreateSession(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QString &app_id,
const QVariantMap &options,
QVariantMap &results);
uint SelectSources(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QString &app_id,
const QVariantMap &options,
QVariantMap &results);
uint Start(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QString &app_id,
const QString &parent_window,
const QVariantMap &options,
QVariantMap &results);
private Q_SLOTS:
void addOutput(quint32 name, quint32 version);
void removeOutput(quint32 name);
void processBuffer(const KWayland::Client::RemoteBuffer *rbuf);
void setupRegistry();
private:
void initDrm();
void initEGL();
void initPipewire();
void initWayland();
bool m_registryInitialized;
bool m_streamingEnabled;
QMap<QString, Session*> m_sessionList;
QMap<quint32, ScreenCastPortalOutput> m_outputMap;
QList<KWayland::Client::Output*> m_bindOutputs;
QThread *m_thread;
ScreenCastStream *m_stream;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::EventQueue *m_queue;
KWayland::Client::Registry *m_registry;
KWayland::Client::RemoteAccessManager *m_remoteAccessManager;
qint32 m_drmFd = 0; // for GBM buffer mmap
gbm_device *m_gbmDevice = nullptr; // for passed GBM buffer retrieval
struct {
QList<QByteArray> extensions;
EGLDisplay display = EGL_NO_DISPLAY;
EGLContext context = EGL_NO_CONTEXT;
} m_egl;
};
#endif // XDG_DESKTOP_PORTAL_KDE_SCREENCAST_H
/*
* Copyright © 2018 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#include "screencaststream.h"
#include <math.h>
#include <sys/mman.h>
#include <stdio.h>
#include <QLoggingCategory>
#include <QTimer>
#include <QSize>
#include <QSocketNotifier>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeScreenCastStream, "xdp-kde-screencast-stream")
class PwFraction {
public:
int num;
int denom;
};
// Stolen from mutter
#define MAX_TERMS 30
#define MIN_DIVISOR 1.0e-10
#define MAX_ERROR 1.0e-20
#define PROP_RANGE(min, max) 2, (min), (max)
#define BITS_PER_PIXEL 4
static int greatestCommonDivisor(int a, int b)
{
while (b != 0) {
int temp = a;
a = b;
b = temp % b;
}
return ABS(a);
}
static PwFraction pipewireFractionFromDouble(double src)
{
double V, F; /* double being converted */
int N, D; /* will contain the result */
int A; /* current term in continued fraction */
int64_t N1, D1; /* numerator, denominator of last approx */