diff options
author | David Elsing <david.elsing@posteo.net> | 2023-03-26 23:08:43 +0200 |
---|---|---|
committer | David Elsing <david.elsing@posteo.net> | 2023-03-30 17:36:40 +0200 |
commit | 2aadc7c2c49f0b49459600c01d6b2db3cd09dfe5 (patch) | |
tree | 7001cf4a6653114f5a2ce160b39a1a56f74af913 /src | |
parent | Add missing license headers (diff) | |
download | nheko-2aadc7c2c49f0b49459600c01d6b2db3cd09dfe5.tar.xz |
Improve choosing screen share type
Diffstat (limited to 'src')
-rw-r--r-- | src/voip/CallManager.cpp | 67 | ||||
-rw-r--r-- | src/voip/CallManager.h | 6 |
2 files changed, 44 insertions, 29 deletions
diff --git a/src/voip/CallManager.cpp b/src/voip/CallManager.cpp index 4471a0c2..e7bd45e4 100644 --- a/src/voip/CallManager.cpp +++ b/src/voip/CallManager.cpp @@ -68,12 +68,23 @@ CallManager::CallManager(QObject *parent) qRegisterMetaType<mtx::events::voip::CallCandidates::Candidate>(); qRegisterMetaType<mtx::responses::TurnServer>(); - if (screenShareX11Available()) { - screenShareType_ = ScreenShareType::X11; - } else { +#ifdef GSTREAMER_AVAILABLE + std::string errorMessage; + if (session_.havePlugins(true, true, ScreenShareType::XDP, &errorMessage)) { + screenShareTypes_.push_back(ScreenShareType::XDP); screenShareType_ = ScreenShareType::XDP; } + if (std::getenv("DISPLAY")) { + screenShareTypes_.push_back(ScreenShareType::X11); + if (QGuiApplication::platformName() != QStringLiteral("wayland")) { + // Selected by default + screenShareType_ = ScreenShareType::X11; + std::swap(screenShareTypes_[0], screenShareTypes_[1]); + } + } +#endif + connect( &session_, &WebRTCSession::offerCreated, @@ -208,13 +219,6 @@ CallManager::sendInvite(const QString &roomid, CallType callType, unsigned int w auto roomInfo = cache::singleRoomInfo(roomid.toStdString()); std::string errorMessage; - if (!session_.havePlugins(callType != CallType::VOICE, - callType == CallType::SCREEN, - screenShareType_, - &errorMessage)) { - emit ChatPage::instance()->showNotification(QString::fromStdString(errorMessage)); - return; - } callType_ = callType; roomid_ = roomid; @@ -745,16 +749,6 @@ CallManager::callsSupported() #endif } -bool -CallManager::screenShareX11Available() -{ -#ifdef GSTREAMER_AVAILABLE - return std::getenv("DISPLAY"); -#else - return false; -#endif -} - QStringList CallManager::devices(bool isVideo) const { @@ -863,9 +857,29 @@ CallManager::screenShareReady() const } QStringList +CallManager::screenShareTypeList() +{ + QStringList ret; + ret.reserve(2); + for (ScreenShareType type : screenShareTypes_) { + switch (type) { + case ScreenShareType::X11: + ret.append(tr("X11")); + break; + case ScreenShareType::XDP: + ret.append(tr("Stream from xdg-desktop-portal")); + break; + } + } + + return ret; +} + +QStringList CallManager::windowList() { - if (!screenShareX11Available()) { + if (!(std::find(screenShareTypes_.begin(), screenShareTypes_.end(), ScreenShareType::X11) != + screenShareTypes_.end())) { return {}; } @@ -998,7 +1012,7 @@ CallManager::previewWindow(unsigned int index) const } if (screenShareType_ == ScreenShareType::X11 && - (!screenShareX11Available() || windows_.empty() || index >= windows_.size())) { + (windows_.empty() || index >= windows_.size())) { nhlog::ui()->error("X11 screencast not available"); return; } @@ -1085,19 +1099,20 @@ CallManager::setupScreenShareXDP() #ifdef GSTREAMER_AVAILABLE ScreenCastPortal &sc_portal = ScreenCastPortal::instance(); sc_portal.init(); - screenShareType_ = ScreenShareType::XDP; #endif } void -CallManager::setScreenShareType(webrtc::ScreenShareType screenShareType) +CallManager::setScreenShareType(unsigned int index) { #ifdef GSTREAMER_AVAILABLE closeScreenShare(); - screenShareType_ = screenShareType; + if (index >= screenShareTypes_.size()) + nhlog::ui()->error("WebRTC: Screen share type index out of range"); + screenShareType_ = screenShareTypes_[index]; emit screenShareChanged(); #else - (void)screenShareType; + (void)index; #endif } diff --git a/src/voip/CallManager.h b/src/voip/CallManager.h index 5d7ebda9..bbc7a903 100644 --- a/src/voip/CallManager.h +++ b/src/voip/CallManager.h @@ -44,7 +44,6 @@ class CallManager final : public QObject Q_PROPERTY(QStringList mics READ mics NOTIFY devicesChanged) Q_PROPERTY(QStringList cameras READ cameras NOTIFY devicesChanged) Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT) - Q_PROPERTY(bool screenShareX11Available READ screenShareX11Available CONSTANT) Q_PROPERTY(bool screenShareReady READ screenShareReady NOTIFY screenShareChanged) public: @@ -68,7 +67,6 @@ public: bool screenShareReady() const; static bool callsSupported(); - static bool screenShareX11Available(); public slots: void sendInvite(const QString &roomid, webrtc::CallType, unsigned int windowIndex = 0); @@ -80,8 +78,9 @@ public slots: mtx::events::voip::CallHangUp::Reason = mtx::events::voip::CallHangUp::Reason::UserHangUp); void rejectInvite(); void setupScreenShareXDP(); - void setScreenShareType(webrtc::ScreenShareType); + void setScreenShareType(unsigned int index); void closeScreenShare(); + QStringList screenShareTypeList(); QStringList windowList(); void previewWindow(unsigned int windowIndex) const; @@ -126,6 +125,7 @@ private: std::vector<std::string> turnURIs_; QTimer turnServerTimer_; QMediaPlayer player_; + std::vector<webrtc::ScreenShareType> screenShareTypes_; std::vector<std::pair<QString, uint32_t>> windows_; std::vector<std::string> rejectCallPartyIDs_; |