Always start calls with camera disabled
Simplifies the code quite a bit WIP: Renegotiate to enable camera
This commit is contained in:
@@ -277,9 +277,7 @@ void CallManager::acceptCall()
|
|||||||
updateTurnServers();
|
updateTurnServers();
|
||||||
// TODO wait until candidates are here
|
// TODO wait until candidates are here
|
||||||
|
|
||||||
// TODO make video configurable
|
m_session = CallSession::acceptCall(m_incomingSdp, m_incomingCandidates, m_cachedTurnUris, m_remoteUser->id(), this);
|
||||||
// change true to false if you don't have a camera
|
|
||||||
m_session = CallSession::acceptCall(true, m_incomingSdp, m_incomingCandidates, m_cachedTurnUris, m_remoteUser->id(), this);
|
|
||||||
m_participants->clear();
|
m_participants->clear();
|
||||||
connect(m_session, &CallSession::stateChanged, this, [this] {
|
connect(m_session, &CallSession::stateChanged, this, [this] {
|
||||||
Q_EMIT stateChanged();
|
Q_EMIT stateChanged();
|
||||||
@@ -350,7 +348,7 @@ void CallManager::ignoreCall()
|
|||||||
setRemoteUser(nullptr);
|
setRemoteUser(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallManager::startCall(NeoChatRoom *room, bool sendVideo)
|
void CallManager::startCall(NeoChatRoom *room)
|
||||||
{
|
{
|
||||||
if (m_session) {
|
if (m_session) {
|
||||||
// Don't start calls if there already is one
|
// Don't start calls if there already is one
|
||||||
@@ -363,7 +361,7 @@ void CallManager::startCall(NeoChatRoom *room, bool sendVideo)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto missingPlugins = m_session->missingPlugins(sendVideo);
|
auto missingPlugins = m_session->missingPlugins();
|
||||||
if (!missingPlugins.isEmpty()) {
|
if (!missingPlugins.isEmpty()) {
|
||||||
qCCritical(voip) << "Missing GStreamer plugins:" << missingPlugins;
|
qCCritical(voip) << "Missing GStreamer plugins:" << missingPlugins;
|
||||||
Q_EMIT Controller::instance().errorOccured("Missing GStreamer plugins.");
|
Q_EMIT Controller::instance().errorOccured("Missing GStreamer plugins.");
|
||||||
@@ -377,6 +375,7 @@ void CallManager::startCall(NeoChatRoom *room, bool sendVideo)
|
|||||||
updateTurnServers();
|
updateTurnServers();
|
||||||
|
|
||||||
setCallId(generateCallId());
|
setCallId(generateCallId());
|
||||||
|
setPartyId(generatePartyId());
|
||||||
|
|
||||||
for (const auto &user : m_room->users()) {
|
for (const auto &user : m_room->users()) {
|
||||||
auto participant = new CallParticipant(m_session);
|
auto participant = new CallParticipant(m_session);
|
||||||
@@ -384,7 +383,7 @@ void CallManager::startCall(NeoChatRoom *room, bool sendVideo)
|
|||||||
m_participants->addParticipant(participant);
|
m_participants->addParticipant(participant);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_session = CallSession::startCall(sendVideo, m_cachedTurnUris, this);
|
m_session = CallSession::startCall(m_cachedTurnUris, this);
|
||||||
setGlobalState(OUTGOING);
|
setGlobalState(OUTGOING);
|
||||||
connect(m_session, &CallSession::stateChanged, this, [this] {
|
connect(m_session, &CallSession::stateChanged, this, [this] {
|
||||||
Q_EMIT stateChanged();
|
Q_EMIT stateChanged();
|
||||||
@@ -393,7 +392,6 @@ void CallManager::startCall(NeoChatRoom *room, bool sendVideo)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
qWarning() << "waiting for createoffer";
|
|
||||||
connectSingleShot(m_session, &CallSession::offerCreated, this, [this](const QString &_sdp, const QVector<Candidate> &candidates) {
|
connectSingleShot(m_session, &CallSession::offerCreated, this, [this](const QString &_sdp, const QVector<Candidate> &candidates) {
|
||||||
const auto &[uuids, sdp] = mangleSdp(_sdp);
|
const auto &[uuids, sdp] = mangleSdp(_sdp);
|
||||||
QVector<std::pair<QString, QString>> msidToPurpose;
|
QVector<std::pair<QString, QString>> msidToPurpose;
|
||||||
@@ -415,10 +413,11 @@ void CallManager::startCall(NeoChatRoom *room, bool sendVideo)
|
|||||||
msidToPurpose += {uuid, "m.usermedia"}; // TODO
|
msidToPurpose += {uuid, "m.usermedia"}; // TODO
|
||||||
}
|
}
|
||||||
QJsonObject json{
|
QJsonObject json{
|
||||||
{QStringLiteral("lifetime"), 6000},
|
{QStringLiteral("lifetime"), 60000},
|
||||||
{QStringLiteral("version"), 1},
|
{QStringLiteral("version"), 1},
|
||||||
{QStringLiteral("description"), QJsonObject{{QStringLiteral("type"), QStringLiteral("answer")}, {QStringLiteral("sdp"), _sdp}}},
|
{QStringLiteral("description"), QJsonObject{{QStringLiteral("type"), QStringLiteral("answer")}, {QStringLiteral("sdp"), _sdp}}},
|
||||||
{QStringLiteral("party_id"), "todopartyid"},
|
{QStringLiteral("party_id"), m_partyId},
|
||||||
|
{QStringLiteral("call_id"), m_callId},
|
||||||
};
|
};
|
||||||
QJsonObject metadata;
|
QJsonObject metadata;
|
||||||
for (const auto &[stream, purpose] : msidToPurpose) {
|
for (const auto &[stream, purpose] : msidToPurpose) {
|
||||||
@@ -608,7 +607,7 @@ QString CallManager::partyId() const
|
|||||||
|
|
||||||
bool CallManager::checkPlugins() const
|
bool CallManager::checkPlugins() const
|
||||||
{
|
{
|
||||||
auto missingPlugins = m_session->missingPlugins(true);
|
auto missingPlugins = m_session->missingPlugins();
|
||||||
if (!missingPlugins.isEmpty()) {
|
if (!missingPlugins.isEmpty()) {
|
||||||
qCCritical(voip) << "Missing GStreamer plugins:" << missingPlugins;
|
qCCritical(voip) << "Missing GStreamer plugins:" << missingPlugins;
|
||||||
Q_EMIT Controller::instance().errorOccured("Missing GStreamer plugins.");
|
Q_EMIT Controller::instance().errorOccured("Missing GStreamer plugins.");
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public:
|
|||||||
|
|
||||||
void handleCallEvent(NeoChatRoom *room, const RoomEvent *event);
|
void handleCallEvent(NeoChatRoom *room, const RoomEvent *event);
|
||||||
|
|
||||||
Q_INVOKABLE void startCall(NeoChatRoom *room, bool camera);
|
Q_INVOKABLE void startCall(NeoChatRoom *room);
|
||||||
Q_INVOKABLE void acceptCall();
|
Q_INVOKABLE void acceptCall();
|
||||||
Q_INVOKABLE void hangupCall();
|
Q_INVOKABLE void hangupCall();
|
||||||
Q_INVOKABLE void ignoreCall();
|
Q_INVOKABLE void ignoreCall();
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ void CallSession::renegotiateOffer(const QString &_offer, const QString &userId)
|
|||||||
g_signal_emit_by_name(webrtcbin, "create-answer", nullptr, promise);
|
g_signal_emit_by_name(webrtcbin, "create-answer", nullptr, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallSession::acceptOffer(bool sendVideo, const QString &sdp, const QVector<Candidate> remoteCandidates, const QString &userId)
|
void CallSession::acceptOffer(const QString &sdp, const QVector<Candidate> remoteCandidates, const QString &userId)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!sdp.isEmpty());
|
Q_ASSERT(!sdp.isEmpty());
|
||||||
Q_ASSERT(!remoteCandidates.isEmpty());
|
Q_ASSERT(!remoteCandidates.isEmpty());
|
||||||
@@ -539,7 +539,7 @@ void CallSession::acceptOffer(bool sendVideo, const QString &sdp, const QVector<
|
|||||||
gst_webrtc_session_description_free(offer);
|
gst_webrtc_session_description_free(offer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
startPipeline(sendVideo);
|
startPipeline();
|
||||||
|
|
||||||
QThread::msleep(1000); // ?
|
QThread::msleep(1000); // ?
|
||||||
|
|
||||||
@@ -550,14 +550,14 @@ void CallSession::acceptOffer(bool sendVideo, const QString &sdp, const QVector<
|
|||||||
gst_webrtc_session_description_free(offer);
|
gst_webrtc_session_description_free(offer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallSession::createCall(bool sendVideo)
|
void CallSession::createCall()
|
||||||
{
|
{
|
||||||
qCDebug(voip) << "Creating call";
|
qCDebug(voip) << "Creating call";
|
||||||
m_isOffering = true;
|
m_isOffering = true;
|
||||||
startPipeline(sendVideo);
|
startPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallSession::startPipeline(bool sendVideo)
|
void CallSession::startPipeline()
|
||||||
{
|
{
|
||||||
qCDebug(voip) << "Starting Pipeline";
|
qCDebug(voip) << "Starting Pipeline";
|
||||||
if (m_state != CallSession::DISCONNECTED) {
|
if (m_state != CallSession::DISCONNECTED) {
|
||||||
@@ -566,7 +566,7 @@ void CallSession::startPipeline(bool sendVideo)
|
|||||||
m_state = CallSession::INITIATING;
|
m_state = CallSession::INITIATING;
|
||||||
Q_EMIT stateChanged();
|
Q_EMIT stateChanged();
|
||||||
|
|
||||||
createPipeline(sendVideo);
|
createPipeline();
|
||||||
|
|
||||||
auto webrtcbin = binGetByName(m_pipe, "webrtcbin");
|
auto webrtcbin = binGetByName(m_pipe, "webrtcbin");
|
||||||
Q_ASSERT(webrtcbin);
|
Q_ASSERT(webrtcbin);
|
||||||
@@ -633,7 +633,7 @@ void CallSession::end()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallSession::createPipeline(bool sendVideo)
|
void CallSession::createPipeline()
|
||||||
{
|
{
|
||||||
qCWarning(voip) << "Creating Pipeline";
|
qCWarning(voip) << "Creating Pipeline";
|
||||||
auto device = AudioSources::instance().currentDevice();
|
auto device = AudioSources::instance().currentDevice();
|
||||||
@@ -677,9 +677,9 @@ void CallSession::createPipeline(bool sendVideo)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendVideo) {
|
// if (sendVideo) {
|
||||||
addVideoPipeline();
|
// TODO where? addVideoPipeline();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallSession::toggleCamera()
|
void CallSession::toggleCamera()
|
||||||
@@ -822,7 +822,7 @@ void CallSession::acceptCandidates(const QVector<Candidate> &candidates)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CallSession::missingPlugins(bool video) const
|
QStringList CallSession::missingPlugins() const
|
||||||
{
|
{
|
||||||
GstRegistry *registry = gst_registry_get();
|
GstRegistry *registry = gst_registry_get();
|
||||||
static const QVector<QString> videoPlugins = {
|
static const QVector<QString> videoPlugins = {
|
||||||
@@ -847,7 +847,7 @@ QStringList CallSession::missingPlugins(bool video) const
|
|||||||
QStringLiteral("webrtc"),
|
QStringLiteral("webrtc"),
|
||||||
};
|
};
|
||||||
QStringList missingPlugins;
|
QStringList missingPlugins;
|
||||||
for (const auto &pluginName : video ? videoPlugins + audioPlugins : audioPlugins) {
|
for (const auto &pluginName : videoPlugins + audioPlugins) {
|
||||||
auto plugin = gst_registry_find_plugin(registry, pluginName.toLatin1().data());
|
auto plugin = gst_registry_find_plugin(registry, pluginName.toLatin1().data());
|
||||||
if (!plugin) {
|
if (!plugin) {
|
||||||
missingPlugins << pluginName;
|
missingPlugins << pluginName;
|
||||||
@@ -883,25 +883,21 @@ bool CallSession::muted() const
|
|||||||
return muted;
|
return muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallSession *CallSession::acceptCall(bool sendVideo,
|
CallSession *
|
||||||
const QString &sdp,
|
CallSession::acceptCall(const QString &sdp, const QVector<Candidate> &candidates, const QStringList &turnUris, const QString &userId, QObject *parent)
|
||||||
const QVector<Candidate> &candidates,
|
|
||||||
const QStringList &turnUris,
|
|
||||||
const QString &userId,
|
|
||||||
QObject *parent)
|
|
||||||
{
|
{
|
||||||
auto instance = new CallSession(parent);
|
auto instance = new CallSession(parent);
|
||||||
instance->setTurnServers(turnUris);
|
instance->setTurnServers(turnUris);
|
||||||
instance->acceptOffer(sendVideo, sdp, candidates, userId);
|
instance->acceptOffer(sdp, candidates, userId);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallSession *CallSession::startCall(bool sendVideo, const QStringList &turnUris, QObject *parent)
|
CallSession *CallSession::startCall(const QStringList &turnUris, QObject *parent)
|
||||||
{
|
{
|
||||||
auto instance = new CallSession(parent);
|
auto instance = new CallSession(parent);
|
||||||
|
|
||||||
instance->setTurnServers(turnUris);
|
instance->setTurnServers(turnUris);
|
||||||
instance->createCall(sendVideo);
|
instance->createCall();
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,23 +53,19 @@ public:
|
|||||||
Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged)
|
Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged)
|
||||||
|
|
||||||
// For outgoing calls
|
// For outgoing calls
|
||||||
static CallSession *startCall(bool sendVideo, const QStringList &turnUris, QObject *parent = nullptr);
|
static CallSession *startCall(const QStringList &turnUris, QObject *parent = nullptr);
|
||||||
void acceptAnswer(const QString &sdp, const QVector<Candidate> &candidates, const QString &parent);
|
void acceptAnswer(const QString &sdp, const QVector<Candidate> &candidates, const QString &parent);
|
||||||
|
|
||||||
// For incoming calls
|
// For incoming calls
|
||||||
static CallSession *acceptCall(bool sendVideo,
|
static CallSession *
|
||||||
const QString &sdp,
|
acceptCall(const QString &sdp, const QVector<Candidate> &candidates, const QStringList &turnUris, const QString &userId, QObject *parent = nullptr);
|
||||||
const QVector<Candidate> &candidates,
|
|
||||||
const QStringList &turnUris,
|
|
||||||
const QString &userId,
|
|
||||||
QObject *parent = nullptr);
|
|
||||||
|
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
void renegotiateOffer(const QString &offer, const QString &userId);
|
void renegotiateOffer(const QString &offer, const QString &userId);
|
||||||
void setTurnServers(QStringList servers);
|
void setTurnServers(QStringList servers);
|
||||||
|
|
||||||
QStringList missingPlugins(bool video) const;
|
QStringList missingPlugins() const;
|
||||||
|
|
||||||
CallSession::State state() const;
|
CallSession::State state() const;
|
||||||
|
|
||||||
@@ -93,12 +89,12 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CallSession(QObject *parent = nullptr);
|
CallSession(QObject *parent = nullptr);
|
||||||
void acceptOffer(bool sendVideo, const QString &sdp, const QVector<Candidate> remoteCandidates, const QString &userId);
|
void acceptOffer(const QString &sdp, const QVector<Candidate> remoteCandidates, const QString &userId);
|
||||||
void createCall(bool sendVideo);
|
void createCall();
|
||||||
|
|
||||||
void setRemoteDescription(GstWebRTCSessionDescription *remote, const QString &userId, GstPromise *promise = nullptr);
|
void setRemoteDescription(GstWebRTCSessionDescription *remote, const QString &userId, GstPromise *promise = nullptr);
|
||||||
void startPipeline(bool sendVideo);
|
void startPipeline();
|
||||||
void createPipeline(bool sendVideo);
|
void createPipeline();
|
||||||
bool addVideoPipeline();
|
bool addVideoPipeline();
|
||||||
|
|
||||||
void setState(CallSession::State state);
|
void setState(CallSession::State state);
|
||||||
|
|||||||
Reference in New Issue
Block a user