| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <string> |
| 8 |
#include <vector> |
| 9 |
|
| 10 |
#include <QObject> |
| 11 |
#include <QQmlEngine> |
| 12 |
|
| 13 |
#include "mtx/events/voip.hpp" |
| 14 |
|
| 15 |
typedef struct _GstElement GstElement; |
| 16 |
class CallDevices; |
| 17 |
class QQuickItem; |
| 18 |
|
| 19 |
namespace webrtc { |
| 20 |
Q_NAMESPACE |
| 21 |
QML_NAMED_ELEMENT(Voip) |
| 22 |
|
| 23 |
enum class CallType |
| 24 |
{ |
| 25 |
VOICE, |
| 26 |
VIDEO, |
| 27 |
SCREEN |
| 28 |
}; |
| 29 |
Q_ENUM_NS(CallType) |
| 30 |
|
| 31 |
enum class ScreenShareType |
| 32 |
{ |
| 33 |
X11, |
| 34 |
XDP, |
| 35 |
D3D11 |
| 36 |
}; |
| 37 |
Q_ENUM_NS(ScreenShareType) |
| 38 |
|
| 39 |
enum class State |
| 40 |
{ |
| 41 |
DISCONNECTED, |
| 42 |
ICEFAILED, |
| 43 |
INITIATING, |
| 44 |
INITIATED, |
| 45 |
OFFERSENT, |
| 46 |
ANSWERSENT, |
| 47 |
CONNECTING, |
| 48 |
CONNECTED |
| 49 |
|
| 50 |
}; |
| 51 |
Q_ENUM_NS(State) |
| 52 |
} |
| 53 |
|
| 54 |
class WebRTCSession final : public QObject |
| 55 |
{ |
| 56 |
Q_OBJECT |
| 57 |
|
| 58 |
public: |
| 59 |
static WebRTCSession &instance() |
| 60 |
{ |
| 61 |
static WebRTCSession instance; |
| 62 |
return instance; |
| 63 |
} |
| 64 |
|
| 65 |
bool havePlugins(bool isVideo, |
| 66 |
bool isScreenshare, |
| 67 |
webrtc::ScreenShareType screenShareType, |
| 68 |
std::string *errorMessage = nullptr); |
| 69 |
webrtc::CallType callType() const { return callType_; } |
| 70 |
webrtc::State state() const { return state_; } |
| 71 |
bool haveLocalPiP() const; |
| 72 |
bool isOffering() const { return isOffering_; } |
| 73 |
bool isRemoteVideoRecvOnly() const { return isRemoteVideoRecvOnly_; } |
| 74 |
bool isRemoteVideoSendOnly() const { return isRemoteVideoSendOnly_; } |
| 75 |
|
| 76 |
bool createOffer(webrtc::CallType, webrtc::ScreenShareType, uint32_t shareWindowId); |
| 77 |
bool acceptOffer(const std::string &sdp); |
| 78 |
bool acceptAnswer(const std::string &sdp); |
| 79 |
bool acceptNegotiation(const std::string &sdp); |
| 80 |
void acceptICECandidates(const std::vector<mtx::events::voip::CallCandidates::Candidate> &); |
| 81 |
|
| 82 |
bool isMicMuted() const; |
| 83 |
bool toggleMicMute(); |
| 84 |
void toggleLocalPiP(); |
| 85 |
void end(); |
| 86 |
|
| 87 |
void setTurnServers(const std::vector<std::string> &uris) { turnServers_ = uris; } |
| 88 |
|
| 89 |
void setVideoItem(QQuickItem *item) { videoItem_ = item; } |
| 90 |
QQuickItem *getVideoItem() const { return videoItem_; } |
| 91 |
|
| 92 |
signals: |
| 93 |
void offerCreated(const std::string &sdp, |
| 94 |
const std::vector<mtx::events::voip::CallCandidates::Candidate> &); |
| 95 |
void answerCreated(const std::string &sdp, |
| 96 |
const std::vector<mtx::events::voip::CallCandidates::Candidate> &); |
| 97 |
void newICECandidate(const mtx::events::voip::CallCandidates::Candidate &); |
| 98 |
void stateChanged(webrtc::State); |
| 99 |
|
| 100 |
private slots: |
| 101 |
void setState(webrtc::State state) { state_ = state; } |
| 102 |
|
| 103 |
private: |
| 104 |
WebRTCSession(); |
| 105 |
|
| 106 |
CallDevices &devices_; |
| 107 |
bool initialised_ = false; |
| 108 |
bool haveVoicePlugins_ = false; |
| 109 |
bool haveVideoPlugins_ = false; |
| 110 |
webrtc::CallType callType_ = webrtc::CallType::VOICE; |
| 111 |
webrtc::ScreenShareType screenShareType_ = webrtc::ScreenShareType::X11; |
| 112 |
webrtc::State state_ = webrtc::State::DISCONNECTED; |
| 113 |
bool isOffering_ = false; |
| 114 |
bool isRemoteVideoRecvOnly_ = false; |
| 115 |
bool isRemoteVideoSendOnly_ = false; |
| 116 |
QQuickItem *videoItem_ = nullptr; |
| 117 |
GstElement *pipe_ = nullptr; |
| 118 |
GstElement *webrtc_ = nullptr; |
| 119 |
unsigned int busWatchId_ = 0; |
| 120 |
std::vector<std::string> turnServers_; |
| 121 |
uint32_t shareWindowId_ = 0; |
| 122 |
|
| 123 |
bool init(std::string *errorMessage = nullptr); |
| 124 |
bool startPipeline(int opusPayloadType, int vp8PayloadType); |
| 125 |
bool createPipeline(int opusPayloadType, int vp8PayloadType); |
| 126 |
bool addVideoPipeline(int vp8PayloadType); |
| 127 |
void clear(); |
| 128 |
|
| 129 |
public: |
| 130 |
WebRTCSession(WebRTCSession const &) = delete; |
| 131 |
void operator=(WebRTCSession const &) = delete; |
| 132 |
}; |