1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Cleanup UI/CoreAV interface

This commit is contained in:
tux3 2015-10-07 20:11:19 +02:00
parent 73a4f40744
commit 41e0212f77
5 changed files with 42 additions and 174 deletions

View File

@ -83,6 +83,7 @@ void CoreAV::answerCall(uint32_t friendNum)
else else
{ {
qWarning() << "Failed to answer call with error"<<err; qWarning() << "Failed to answer call with error"<<err;
toxav_call_control(toxav, friendNum, TOXAV_CALL_CONTROL_CANCEL, nullptr);
calls.remove(friendNum); calls.remove(friendNum);
emit avCallFailed(friendNum); emit avCallFailed(friendNum);
} }
@ -90,6 +91,7 @@ void CoreAV::answerCall(uint32_t friendNum)
void CoreAV::startCall(uint32_t friendId, bool video) void CoreAV::startCall(uint32_t friendId, bool video)
{ {
qDebug() << QString("Starting call with %1").arg(friendId);
if(calls.contains(friendId)) if(calls.contains(friendId))
{ {
qWarning() << QString("Can't start call with %1, we're already in this call!").arg(friendId); qWarning() << QString("Can't start call with %1, we're already in this call!").arg(friendId);
@ -97,7 +99,6 @@ void CoreAV::startCall(uint32_t friendId, bool video)
return; return;
} }
qDebug() << QString("Starting call with %1").arg(friendId);
uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0; uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0;
if (!toxav_call(toxav, friendId, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr)) if (!toxav_call(toxav, friendId, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr))
{ {
@ -112,8 +113,13 @@ void CoreAV::startCall(uint32_t friendId, bool video)
void CoreAV::cancelCall(uint32_t friendId) void CoreAV::cancelCall(uint32_t friendId)
{ {
qDebug() << QString("Cancelling call with %1").arg(friendId); qDebug() << QString("Cancelling call with %1").arg(friendId);
toxav_call_control(toxav, friendId, TOXAV_CALL_CONTROL_CANCEL, nullptr); if (!toxav_call_control(toxav, friendId, TOXAV_CALL_CONTROL_CANCEL, nullptr))
{
qWarning() << QString("Failed to cancel call with %1").arg(friendId);
return;
}
calls.remove(friendId); calls.remove(friendId);
emit avCancel(friendId);
} }
bool CoreAV::sendCallAudio(uint32_t callId) bool CoreAV::sendCallAudio(uint32_t callId)
@ -342,6 +348,11 @@ void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool vid
void CoreAV::stateCallback(ToxAV *, uint32_t friendNum, uint32_t state, void *_self) void CoreAV::stateCallback(ToxAV *, uint32_t friendNum, uint32_t state, void *_self)
{ {
// This callback needs to run in the CoreAV thread.
// Otherwise, there's a deadlock between the Core thread holding an internal
// toxav lock and trying to lock the CameraSource to stop it, and the
// av thread holding the Camera
CoreAV* self = static_cast<CoreAV*>(_self); CoreAV* self = static_cast<CoreAV*>(_self);
assert(self->calls.contains(friendNum)); assert(self->calls.contains(friendNum));

View File

@ -94,13 +94,7 @@ signals:
void avCancel(uint32_t friendId); void avCancel(uint32_t friendId);
void avEnd(uint32_t friendId); void avEnd(uint32_t friendId);
void avRinging(uint32_t friendId, bool video); void avRinging(uint32_t friendId, bool video);
void avStarting(uint32_t friendId, bool video);
void avEnding(uint32_t friendId);
void avRequestTimeout(uint32_t friendId);
void avPeerTimeout(uint32_t friendId);
void avMediaChange(uint32_t friendId, bool videoEnabled);
void avCallFailed(uint32_t friendId); void avCallFailed(uint32_t friendId);
void avRejected(uint32_t friendId);
void videoFrameReceived(vpx_image* frame); void videoFrameReceived(vpx_image* frame);

View File

@ -313,10 +313,9 @@ void ChatForm::onAvStart(uint32_t FriendId, bool video)
if (video) if (video)
{ {
callButton->setObjectName("grey");
callButton->setToolTip("");
videoButton->setObjectName("red"); videoButton->setObjectName("red");
videoButton->setToolTip(tr("End video call")); videoButton->setToolTip(tr("End video call"));
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()), connect(videoButton, SIGNAL(clicked()),
this, SLOT(onHangupCallTriggered())); this, SLOT(onHangupCallTriggered()));
@ -326,14 +325,11 @@ void ChatForm::onAvStart(uint32_t FriendId, bool video)
{ {
callButton->setObjectName("red"); callButton->setObjectName("red");
callButton->setToolTip(tr("End audio call")); callButton->setToolTip(tr("End audio call"));
videoButton->setObjectName("grey"); callButton->style()->polish(callButton);
videoButton->setToolTip("");
connect(callButton, SIGNAL(clicked()), connect(callButton, SIGNAL(clicked()),
this, SLOT(onHangupCallTriggered())); this, SLOT(onHangupCallTriggered()));
hideNetcam(); hideNetcam();
} }
callButton->style()->polish(callButton);
videoButton->style()->polish(videoButton);
micButton->setObjectName("green"); micButton->setObjectName("green");
micButton->style()->polish(micButton); micButton->style()->polish(micButton);
@ -370,95 +366,6 @@ void ChatForm::onAvCancel(uint32_t FriendId)
QDateTime::currentDateTime()); QDateTime::currentDateTime());
} }
void ChatForm::onAvRinging(uint32_t FriendId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRinging";
callButton->disconnect();
videoButton->disconnect();
if (video)
{
callButton->setObjectName("grey");
callButton->style()->polish(callButton);
callButton->setToolTip("");
videoButton->setObjectName("yellow");
videoButton->style()->polish(videoButton);
videoButton->setToolTip(tr("Cancel video call"));
connect(videoButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
else
{
callButton->setObjectName("yellow");
callButton->style()->polish(callButton);
callButton->setToolTip(tr("Cancel audio call"));
videoButton->setObjectName("grey");
videoButton->style()->polish(videoButton);
videoButton->setToolTip("");
connect(callButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
addSystemInfoMessage(tr("Calling to %1").arg(f->getDisplayedName()),
ChatMessage::INFO,
QDateTime::currentDateTime());
Widget::getInstance()->updateFriendActivity(f);
}
void ChatForm::onAvStarting(uint32_t FriendId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvStarting";
disableCallButtons();
if (video)
{
callButton->setObjectName("grey");
callButton->style()->polish(callButton);
callButton->setToolTip("");
videoButton->setObjectName("red");
videoButton->style()->polish(videoButton);
videoButton->setToolTip(tr("End video call"));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
showNetcam();
}
else
{
callButton->setObjectName("red");
callButton->style()->polish(callButton);
callButton->setToolTip(tr("End audio call"));
videoButton->setObjectName("grey");
videoButton->style()->polish(videoButton);
videoButton->setToolTip("");
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
}
startCounter();
}
void ChatForm::onAvEnding(uint32_t FriendId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvEnding";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
CameraSource::getInstance().unsubscribe();
hideNetcam();
}
void ChatForm::onAvEnd(uint32_t FriendId) void ChatForm::onAvEnd(uint32_t FriendId)
{ {
if (FriendId != f->getFriendID()) if (FriendId != f->getFriendID())
@ -474,68 +381,36 @@ void ChatForm::onAvEnd(uint32_t FriendId)
hideNetcam(); hideNetcam();
} }
void ChatForm::onAvRequestTimeout(uint32_t FriendId) void ChatForm::onAvRinging(uint32_t FriendId, bool video)
{ {
if (FriendId != f->getFriendID()) if (FriendId != f->getFriendID())
return; return;
qDebug() << "onAvRequestTimeout"; qDebug() << "onAvRinging";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
hideNetcam();
}
void ChatForm::onAvPeerTimeout(uint32_t FriendId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvPeerTimeout";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
hideNetcam();
}
void ChatForm::onAvRejected(uint32_t FriendId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRejected";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
insertChatMessage(ChatMessage::createChatInfoMessage(tr("Call rejected"),
ChatMessage::INFO,
QDateTime::currentDateTime()));
hideNetcam();
}
void ChatForm::onAvMediaChange(uint32_t FriendId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvMediaChange";
disableCallButtons();
if (video) if (video)
showNetcam(); {
videoButton->setObjectName("yellow");
videoButton->style()->polish(videoButton);
videoButton->setToolTip(tr("Cancel video call"));
connect(videoButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
else else
hideNetcam(); {
callButton->setObjectName("yellow");
callButton->style()->polish(callButton);
callButton->setToolTip(tr("Cancel audio call"));
connect(callButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()),
ChatMessage::INFO,
QDateTime::currentDateTime());
Widget::getInstance()->updateFriendActivity(f);
} }
void ChatForm::onAnswerCallTriggered() void ChatForm::onAnswerCallTriggered()
@ -548,6 +423,8 @@ void ChatForm::onAnswerCallTriggered()
callConfirm = nullptr; callConfirm = nullptr;
} }
disableCallButtons();
audioInputFlag = true; audioInputFlag = true;
audioOutputFlag = true; audioOutputFlag = true;
emit answerCall(f->getFriendID()); emit answerCall(f->getFriendID());
@ -593,8 +470,7 @@ void ChatForm::onCallTriggered()
audioInputFlag = true; audioInputFlag = true;
audioOutputFlag = true; audioOutputFlag = true;
callButton->disconnect(); disableCallButtons();
videoButton->disconnect();
emit startCall(f->getFriendID(), false); emit startCall(f->getFriendID(), false);
} }
@ -604,8 +480,7 @@ void ChatForm::onVideoCallTriggered()
audioInputFlag = true; audioInputFlag = true;
audioOutputFlag = true; audioOutputFlag = true;
callButton->disconnect(); disableCallButtons();
videoButton->disconnect();
emit startCall(f->getFriendID(), true); emit startCall(f->getFriendID(), true);
} }

View File

@ -69,13 +69,7 @@ public slots:
void onAvCancel(uint32_t FriendId); void onAvCancel(uint32_t FriendId);
void onAvEnd(uint32_t FriendId); void onAvEnd(uint32_t FriendId);
void onAvRinging(uint32_t FriendId, bool video); void onAvRinging(uint32_t FriendId, bool video);
void onAvStarting(uint32_t FriendId, bool video);
void onAvEnding(uint32_t FriendId);
void onAvRequestTimeout(uint32_t FriendId);
void onAvPeerTimeout(uint32_t FriendId);
void onAvMediaChange(uint32_t FriendId, bool video);
void onAvCallFailed(uint32_t FriendId); void onAvCallFailed(uint32_t FriendId);
void onAvRejected(uint32_t FriendId);
void onMicMuteToggle(); void onMicMuteToggle();
void onVolMuteToggle(); void onVolMuteToggle();
void onAvatarChange(uint32_t FriendId, const QPixmap& pic); void onAvatarChange(uint32_t FriendId, const QPixmap& pic);

View File

@ -906,13 +906,7 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(coreav, &CoreAV::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel); connect(coreav, &CoreAV::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel);
connect(coreav, &CoreAV::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd); connect(coreav, &CoreAV::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd);
connect(coreav, &CoreAV::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging); connect(coreav, &CoreAV::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging);
connect(coreav, &CoreAV::avStarting, newfriend->getChatForm(), &ChatForm::onAvStarting);
connect(coreav, &CoreAV::avEnding, newfriend->getChatForm(), &ChatForm::onAvEnding);
connect(coreav, &CoreAV::avRequestTimeout, newfriend->getChatForm(), &ChatForm::onAvRequestTimeout);
connect(coreav, &CoreAV::avPeerTimeout, newfriend->getChatForm(), &ChatForm::onAvPeerTimeout);
connect(coreav, &CoreAV::avMediaChange, newfriend->getChatForm(), &ChatForm::onAvMediaChange);
connect(coreav, &CoreAV::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed); connect(coreav, &CoreAV::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed);
connect(coreav, &CoreAV::avRejected, newfriend->getChatForm(), &ChatForm::onAvRejected);
connect(core, &Core::friendAvatarChanged, newfriend->getChatForm(), &ChatForm::onAvatarChange); connect(core, &Core::friendAvatarChanged, newfriend->getChatForm(), &ChatForm::onAvatarChange);
connect(core, &Core::friendAvatarChanged, newfriend->getFriendWidget(), &FriendWidget::onAvatarChange); connect(core, &Core::friendAvatarChanged, newfriend->getFriendWidget(), &FriendWidget::onAvatarChange);
connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved); connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved);