2020-07-11 02:19:48 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
2021-02-07 19:47:47 +03:00
|
|
|
#include "CallDevices.h"
|
2020-07-11 02:19:48 +03:00
|
|
|
#include "mtx/events/voip.hpp"
|
|
|
|
|
|
|
|
typedef struct _GstElement GstElement;
|
2020-10-27 20:14:06 +03:00
|
|
|
class QQuickItem;
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-09-22 19:07:36 +03:00
|
|
|
namespace webrtc {
|
|
|
|
Q_NAMESPACE
|
|
|
|
|
|
|
|
enum class State
|
|
|
|
{
|
|
|
|
DISCONNECTED,
|
|
|
|
ICEFAILED,
|
|
|
|
INITIATING,
|
|
|
|
INITIATED,
|
|
|
|
OFFERSENT,
|
|
|
|
ANSWERSENT,
|
|
|
|
CONNECTING,
|
|
|
|
CONNECTED
|
|
|
|
|
|
|
|
};
|
|
|
|
Q_ENUM_NS(State)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
class WebRTCSession : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-08-01 21:31:10 +03:00
|
|
|
static WebRTCSession &instance()
|
2020-07-11 02:19:48 +03:00
|
|
|
{
|
2020-08-01 21:31:10 +03:00
|
|
|
static WebRTCSession instance;
|
|
|
|
return instance;
|
2020-07-11 02:19:48 +03:00
|
|
|
}
|
|
|
|
|
2020-10-27 20:14:06 +03:00
|
|
|
bool havePlugins(bool isVideo, std::string *errorMessage = nullptr);
|
2020-09-22 19:07:36 +03:00
|
|
|
webrtc::State state() const { return state_; }
|
2020-10-27 20:14:06 +03:00
|
|
|
bool isVideo() const { return isVideo_; }
|
2020-12-17 20:45:54 +03:00
|
|
|
bool haveLocalVideo() const;
|
2020-10-27 20:14:06 +03:00
|
|
|
bool isOffering() const { return isOffering_; }
|
|
|
|
bool isRemoteVideoRecvOnly() const { return isRemoteVideoRecvOnly_; }
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-10-27 20:14:06 +03:00
|
|
|
bool createOffer(bool isVideo);
|
2020-07-11 02:19:48 +03:00
|
|
|
bool acceptOffer(const std::string &sdp);
|
|
|
|
bool acceptAnswer(const std::string &sdp);
|
2020-08-01 21:31:10 +03:00
|
|
|
void acceptICECandidates(const std::vector<mtx::events::msg::CallCandidates::Candidate> &);
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-09-25 17:26:36 +03:00
|
|
|
bool isMicMuted() const;
|
|
|
|
bool toggleMicMute();
|
2020-11-09 18:51:17 +03:00
|
|
|
void toggleCameraView();
|
2020-07-11 02:19:48 +03:00
|
|
|
void end();
|
|
|
|
|
2020-08-01 21:31:10 +03:00
|
|
|
void setTurnServers(const std::vector<std::string> &uris) { turnServers_ = uris; }
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-10-27 20:14:06 +03:00
|
|
|
void setVideoItem(QQuickItem *item) { videoItem_ = item; }
|
|
|
|
QQuickItem *getVideoItem() const { return videoItem_; }
|
2020-08-06 00:56:44 +03:00
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
signals:
|
2020-08-01 21:31:10 +03:00
|
|
|
void offerCreated(const std::string &sdp,
|
|
|
|
const std::vector<mtx::events::msg::CallCandidates::Candidate> &);
|
|
|
|
void answerCreated(const std::string &sdp,
|
|
|
|
const std::vector<mtx::events::msg::CallCandidates::Candidate> &);
|
|
|
|
void newICECandidate(const mtx::events::msg::CallCandidates::Candidate &);
|
2020-09-22 19:07:36 +03:00
|
|
|
void stateChanged(webrtc::State);
|
2020-07-23 04:15:45 +03:00
|
|
|
|
|
|
|
private slots:
|
2020-09-22 19:07:36 +03:00
|
|
|
void setState(webrtc::State state) { state_ = state; }
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
private:
|
2020-07-23 04:15:45 +03:00
|
|
|
WebRTCSession();
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2021-02-07 19:47:47 +03:00
|
|
|
CallDevices &devices_;
|
2020-10-27 20:14:06 +03:00
|
|
|
bool initialised_ = false;
|
|
|
|
bool haveVoicePlugins_ = false;
|
|
|
|
bool haveVideoPlugins_ = false;
|
|
|
|
webrtc::State state_ = webrtc::State::DISCONNECTED;
|
|
|
|
bool isVideo_ = false;
|
|
|
|
bool isOffering_ = false;
|
|
|
|
bool isRemoteVideoRecvOnly_ = false;
|
|
|
|
QQuickItem *videoItem_ = nullptr;
|
|
|
|
GstElement *pipe_ = nullptr;
|
|
|
|
GstElement *webrtc_ = nullptr;
|
|
|
|
unsigned int busWatchId_ = 0;
|
2020-07-11 02:19:48 +03:00
|
|
|
std::vector<std::string> turnServers_;
|
|
|
|
|
2020-10-27 20:14:06 +03:00
|
|
|
bool init(std::string *errorMessage = nullptr);
|
|
|
|
bool startPipeline(int opusPayloadType, int vp8PayloadType);
|
|
|
|
bool createPipeline(int opusPayloadType, int vp8PayloadType);
|
|
|
|
bool addVideoPipeline(int vp8PayloadType);
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
public:
|
2020-08-01 21:31:10 +03:00
|
|
|
WebRTCSession(WebRTCSession const &) = delete;
|
|
|
|
void operator=(WebRTCSession const &) = delete;
|
2020-07-11 02:19:48 +03:00
|
|
|
};
|