mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(core): Changed Core interface, added documentation
Implementation by @antis81
This commit is contained in:
parent
74eb06b2aa
commit
5d6445065e
|
@ -112,6 +112,11 @@ Core* Core::getInstance()
|
||||||
return Nexus::getCore();
|
return Nexus::getCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CoreAV *Core::getAv() const
|
||||||
|
{
|
||||||
|
return av;
|
||||||
|
}
|
||||||
|
|
||||||
CoreAV *Core::getAv()
|
CoreAV *Core::getAv()
|
||||||
{
|
{
|
||||||
return av;
|
return av;
|
||||||
|
|
|
@ -47,6 +47,7 @@ class Core : public QObject
|
||||||
public:
|
public:
|
||||||
explicit Core(QThread* coreThread, Profile& profile);
|
explicit Core(QThread* coreThread, Profile& profile);
|
||||||
static Core* getInstance();
|
static Core* getInstance();
|
||||||
|
const CoreAV* getAv() const;
|
||||||
CoreAV* getAv();
|
CoreAV* getAv();
|
||||||
~Core();
|
~Core();
|
||||||
|
|
||||||
|
@ -88,6 +89,8 @@ public:
|
||||||
|
|
||||||
bool isReady();
|
bool isReady();
|
||||||
|
|
||||||
|
void sendFile(uint32_t friendId, QString filename, QString filePath, long long filesize);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void start();
|
void start();
|
||||||
void reset();
|
void reset();
|
||||||
|
@ -116,7 +119,6 @@ public slots:
|
||||||
int sendAction(uint32_t friendId, const QString& action);
|
int sendAction(uint32_t friendId, const QString& action);
|
||||||
void sendTyping(uint32_t friendId, bool typing);
|
void sendTyping(uint32_t friendId, bool typing);
|
||||||
|
|
||||||
void sendFile(uint32_t friendId, QString filename, QString filePath, long long filesize);
|
|
||||||
void sendAvatarFile(uint32_t friendId, const QByteArray& data);
|
void sendAvatarFile(uint32_t friendId, const QByteArray& data);
|
||||||
void cancelFileSend(uint32_t friendId, uint32_t fileNum);
|
void cancelFileSend(uint32_t friendId, uint32_t fileNum);
|
||||||
void cancelFileRecv(uint32_t friendId, uint32_t fileNum);
|
void cancelFileRecv(uint32_t friendId, uint32_t fileNum);
|
||||||
|
@ -127,7 +129,6 @@ public slots:
|
||||||
|
|
||||||
void setNospam(uint32_t nospam);
|
void setNospam(uint32_t nospam);
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connected();
|
void connected();
|
||||||
void disconnected();
|
void disconnected();
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "coreav.h"
|
#include "coreav.h"
|
||||||
#include "src/audio/audio.h"
|
#include "src/audio/audio.h"
|
||||||
|
#include "src/friend.h"
|
||||||
|
#include "src/group.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
#include "src/video/videoframe.h"
|
#include "src/video/videoframe.h"
|
||||||
#include "src/video/corevideosource.h"
|
#include "src/video/corevideosource.h"
|
||||||
|
@ -157,19 +159,42 @@ void CoreAV::process()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check, that and calls are active now
|
* @brief Check, if any calls are currently active.
|
||||||
* @return True is any calls are currently active, False otherwise
|
* @return true if any calls are currently active, false otherwise
|
||||||
* @note A call about to start is not yet active
|
* @note A call about to start is not yet active.
|
||||||
*/
|
*/
|
||||||
bool CoreAV::anyActiveCalls()
|
bool CoreAV::anyActiveCalls() const
|
||||||
{
|
{
|
||||||
return !calls.isEmpty();
|
return !calls.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoreAV::isCallVideoEnabled(uint32_t friendNum)
|
/**
|
||||||
|
* @brief Checks the call status for a Tox friend.
|
||||||
|
* @param f the friend to check
|
||||||
|
* @return true, if call is active for the friend, false otherwise
|
||||||
|
*/
|
||||||
|
bool CoreAV::isCallActive(const Friend* f) const
|
||||||
{
|
{
|
||||||
assert(calls.contains(friendNum));
|
return f && calls.contains(f->getFriendID());
|
||||||
return calls[friendNum].videoEnabled;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks the call status for a Tox group.
|
||||||
|
* @param g the group to check
|
||||||
|
* @return true, if the call is active for the group, false otherwise
|
||||||
|
*/
|
||||||
|
bool CoreAV::isCallActive(const Group* g) const
|
||||||
|
{
|
||||||
|
return g && groupCalls.contains(g->getGroupId())
|
||||||
|
? !(groupCalls[g->getGroupId()].inactive)
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CoreAV::isCallVideoEnabled(const Friend* f) const
|
||||||
|
{
|
||||||
|
return f && calls.contains(f->getFriendID())
|
||||||
|
? calls[f->getFriendID()].videoEnabled
|
||||||
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoreAV::answerCall(uint32_t friendNum)
|
bool CoreAV::answerCall(uint32_t friendNum)
|
||||||
|
@ -269,7 +294,9 @@ bool CoreAV::cancelCall(uint32_t friendNum)
|
||||||
qWarning() << QString("Failed to cancel call with %1").arg(friendNum);
|
qWarning() << QString("Failed to cancel call with %1").arg(friendNum);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
calls.remove(friendNum);
|
calls.remove(friendNum);
|
||||||
|
emit avEnd(friendNum);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +317,6 @@ void CoreAV::timeoutCall(uint32_t friendNum)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "Call with friend"<<friendNum<<"timed out";
|
qDebug() << "Call with friend"<<friendNum<<"timed out";
|
||||||
emit avEnd(friendNum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -388,16 +414,30 @@ void CoreAV::sendCallVideo(uint32_t callId, std::shared_ptr<VideoFrame> vframe)
|
||||||
qDebug() << "toxav_video_send_frame error: Lock busy, dropping frame";
|
qDebug() << "toxav_video_send_frame error: Lock busy, dropping frame";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::micMuteToggle(uint32_t callId)
|
/**
|
||||||
|
* @brief Toggles the mute state of the call's input (microphone).
|
||||||
|
* @param f The friend assigned to the call
|
||||||
|
*/
|
||||||
|
void CoreAV::toggleMuteCallInput(const Friend* f)
|
||||||
{
|
{
|
||||||
if (calls.contains(callId))
|
if (f && calls.contains(f->getFriendID()))
|
||||||
calls[callId].muteMic = !calls[callId].muteMic;
|
{
|
||||||
|
ToxCall& call = calls[f->getFriendID()];
|
||||||
|
call.muteMic = !call.muteMic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::volMuteToggle(uint32_t callId)
|
/**
|
||||||
|
* @brief Toggles the mute state of the call's output (speaker).
|
||||||
|
* @param f The friend assigned to the call
|
||||||
|
*/
|
||||||
|
void CoreAV::toggleMuteCallOutput(const Friend* f)
|
||||||
{
|
{
|
||||||
if (calls.contains(callId))
|
if (f && calls.contains(f->getFriendID()))
|
||||||
calls[callId].muteVol = !calls[callId].muteVol;
|
{
|
||||||
|
ToxCall& call = calls[f->getFriendID()];
|
||||||
|
call.muteVol = !call.muteVol;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -499,34 +539,50 @@ bool CoreAV::sendGroupCallAudio(int groupId, const int16_t *pcm, size_t samples,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::disableGroupCallMic(int groupId)
|
/**
|
||||||
|
* @brief Mutes or unmutes the group call's input (microphone).
|
||||||
|
* @param g The group
|
||||||
|
* @param mute True to mute, false to unmute
|
||||||
|
*/
|
||||||
|
void CoreAV::muteCallInput(const Group* g, bool mute)
|
||||||
{
|
{
|
||||||
groupCalls[groupId].muteMic = true;
|
if (g && groupCalls.contains(g->getGroupId()))
|
||||||
|
groupCalls[g->getGroupId()].muteMic = mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::disableGroupCallVol(int groupId)
|
/**
|
||||||
|
* @brief Mutes or unmutes the group call's output (speaker).
|
||||||
|
* @param g The group
|
||||||
|
* @param mute True to mute, false to unmute
|
||||||
|
*/
|
||||||
|
void CoreAV::muteCallOutput(const Group* g, bool mute)
|
||||||
{
|
{
|
||||||
groupCalls[groupId].muteVol = true;
|
if (g && groupCalls.contains(g->getGroupId()))
|
||||||
|
groupCalls[g->getGroupId()].muteVol = mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::enableGroupCallMic(int groupId)
|
/**
|
||||||
|
* @brief Returns the group calls input (microphone) state.
|
||||||
|
* @param groupId The group id to check
|
||||||
|
* @return true when muted, false otherwise
|
||||||
|
*/
|
||||||
|
bool CoreAV::isGroupCallInputMuted(const Group* g) const
|
||||||
{
|
{
|
||||||
groupCalls[groupId].muteMic = false;
|
return g && groupCalls.contains(g->getGroupId())
|
||||||
|
? groupCalls[g->getGroupId()].muteMic
|
||||||
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::enableGroupCallVol(int groupId)
|
/**
|
||||||
|
* @brief Returns the group calls output (speaker) state.
|
||||||
|
* @param groupId The group id to check
|
||||||
|
* @return true when muted, false otherwise
|
||||||
|
*/
|
||||||
|
bool CoreAV::isGroupCallOutputMuted(const Group* g) const
|
||||||
{
|
{
|
||||||
groupCalls[groupId].muteVol = false;
|
return g && groupCalls.contains(g->getGroupId())
|
||||||
}
|
? groupCalls[g->getGroupId()].muteVol
|
||||||
|
: false;
|
||||||
bool CoreAV::isGroupCallMicEnabled(int groupId) const
|
|
||||||
{
|
|
||||||
return !groupCalls[groupId].muteMic;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CoreAV::isGroupCallVolEnabled(int groupId) const
|
|
||||||
{
|
|
||||||
return !groupCalls[groupId].muteVol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -539,6 +595,30 @@ bool CoreAV::isGroupAvEnabled(int groupId) const
|
||||||
return tox_group_get_type(Core::getInstance()->tox, groupId) == TOX_GROUPCHAT_TYPE_AV;
|
return tox_group_get_type(Core::getInstance()->tox, groupId) == TOX_GROUPCHAT_TYPE_AV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the calls input (microphone) mute state.
|
||||||
|
* @param f The friend to check
|
||||||
|
* @return true when muted, false otherwise
|
||||||
|
*/
|
||||||
|
bool CoreAV::isCallInputMuted(const Friend* f) const
|
||||||
|
{
|
||||||
|
return f && calls.contains(f->getFriendID())
|
||||||
|
? calls[f->getFriendID()].muteMic
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the calls output (speaker) mute state.
|
||||||
|
* @param friendId The friend to check
|
||||||
|
* @return true when muted, false otherwise
|
||||||
|
*/
|
||||||
|
bool CoreAV::isCallOutputMuted(const Friend* f) const
|
||||||
|
{
|
||||||
|
return f && calls.contains(f->getFriendID())
|
||||||
|
? calls[f->getFriendID()].muteVol
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Forces to regenerate each call's audio sources.
|
* @brief Forces to regenerate each call's audio sources.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include "src/core/toxcall.h"
|
#include "src/core/toxcall.h"
|
||||||
#include <tox/toxav.h>
|
#include <tox/toxav.h>
|
||||||
|
|
||||||
|
class Friend;
|
||||||
|
class Group;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class QThread;
|
class QThread;
|
||||||
class CoreVideoSource;
|
class CoreVideoSource;
|
||||||
|
@ -46,8 +48,10 @@ public:
|
||||||
|
|
||||||
const ToxAV* getToxAv() const;
|
const ToxAV* getToxAv() const;
|
||||||
|
|
||||||
bool anyActiveCalls();
|
bool anyActiveCalls() const;
|
||||||
bool isCallVideoEnabled(uint32_t friendNum);
|
bool isCallActive(const Friend* f) const;
|
||||||
|
bool isCallActive(const Group* g) const;
|
||||||
|
bool isCallVideoEnabled(const Friend* f) const;
|
||||||
bool sendCallAudio(uint32_t friendNum, const int16_t *pcm, size_t samples, uint8_t chans, uint32_t rate);
|
bool sendCallAudio(uint32_t friendNum, const int16_t *pcm, size_t samples, uint8_t chans, uint32_t rate);
|
||||||
void sendCallVideo(uint32_t friendNum, std::shared_ptr<VideoFrame> frame);
|
void sendCallVideo(uint32_t friendNum, std::shared_ptr<VideoFrame> frame);
|
||||||
bool sendGroupCallAudio(int groupNum, const int16_t *pcm, size_t samples, uint8_t chans, uint32_t rate);
|
bool sendGroupCallAudio(int groupNum, const int16_t *pcm, size_t samples, uint8_t chans, uint32_t rate);
|
||||||
|
@ -58,16 +62,16 @@ public:
|
||||||
|
|
||||||
void joinGroupCall(int groupNum);
|
void joinGroupCall(int groupNum);
|
||||||
void leaveGroupCall(int groupNum);
|
void leaveGroupCall(int groupNum);
|
||||||
void disableGroupCallMic(int groupNum);
|
void muteCallInput(const Group* g, bool mute);
|
||||||
void disableGroupCallVol(int groupNum);
|
void muteCallOutput(const Group* g, bool mute);
|
||||||
void enableGroupCallMic(int groupNum);
|
bool isGroupCallInputMuted(const Group* g) const;
|
||||||
void enableGroupCallVol(int groupNum);
|
bool isGroupCallOutputMuted(const Group* g) const;
|
||||||
bool isGroupCallMicEnabled(int groupNum) const;
|
|
||||||
bool isGroupCallVolEnabled(int groupNum) const;
|
|
||||||
bool isGroupAvEnabled(int groupNum) const;
|
bool isGroupAvEnabled(int groupNum) const;
|
||||||
|
|
||||||
void micMuteToggle(uint32_t friendNum);
|
bool isCallInputMuted(const Friend* f) const;
|
||||||
void volMuteToggle(uint32_t friendNum);
|
bool isCallOutputMuted(const Friend* f) const;
|
||||||
|
void toggleMuteCallInput(const Friend* f);
|
||||||
|
void toggleMuteCallOutput(const Friend* f);
|
||||||
|
|
||||||
static void groupCallCallback(void* tox, int group, int peer,
|
static void groupCallCallback(void* tox, int group, int peer,
|
||||||
const int16_t* data, unsigned samples,
|
const int16_t* data, unsigned samples,
|
||||||
|
|
|
@ -442,7 +442,7 @@ void ChatForm::onAnswerCallTriggered()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onAvStart(f->getFriendID(), coreav->isCallVideoEnabled(f->getFriendID()));
|
onAvStart(f->getFriendID(), coreav->isCallActive(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onHangupCallTriggered()
|
void ChatForm::onHangupCallTriggered()
|
||||||
|
@ -593,7 +593,7 @@ void ChatForm::onMicMuteToggle()
|
||||||
{
|
{
|
||||||
if (audioInputFlag)
|
if (audioInputFlag)
|
||||||
{
|
{
|
||||||
coreav->micMuteToggle(f->getFriendID());
|
coreav->toggleMuteCallInput(f);
|
||||||
if (micButton->objectName() == "red")
|
if (micButton->objectName() == "red")
|
||||||
{
|
{
|
||||||
micButton->setObjectName("green");
|
micButton->setObjectName("green");
|
||||||
|
@ -613,7 +613,7 @@ void ChatForm::onVolMuteToggle()
|
||||||
{
|
{
|
||||||
if (audioOutputFlag)
|
if (audioOutputFlag)
|
||||||
{
|
{
|
||||||
coreav->volMuteToggle(f->getFriendID());
|
coreav->toggleMuteCallOutput(f);
|
||||||
if (volButton->objectName() == "red")
|
if (volButton->objectName() == "red")
|
||||||
{
|
{
|
||||||
volButton->setObjectName("green");
|
volButton->setObjectName("green");
|
||||||
|
|
|
@ -303,13 +303,13 @@ void GroupChatForm::onMicMuteToggle()
|
||||||
{
|
{
|
||||||
if (micButton->objectName() == "red")
|
if (micButton->objectName() == "red")
|
||||||
{
|
{
|
||||||
Core::getInstance()->getAv()->enableGroupCallMic(group->getGroupId());
|
Core::getInstance()->getAv()->muteCallInput(group, false);
|
||||||
micButton->setObjectName("green");
|
micButton->setObjectName("green");
|
||||||
micButton->setToolTip(tr("Mute microphone"));
|
micButton->setToolTip(tr("Mute microphone"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Core::getInstance()->getAv()->disableGroupCallMic(group->getGroupId());
|
Core::getInstance()->getAv()->muteCallInput(group, true);
|
||||||
micButton->setObjectName("red");
|
micButton->setObjectName("red");
|
||||||
micButton->setToolTip(tr("Unmute microphone"));
|
micButton->setToolTip(tr("Unmute microphone"));
|
||||||
}
|
}
|
||||||
|
@ -324,13 +324,13 @@ void GroupChatForm::onVolMuteToggle()
|
||||||
{
|
{
|
||||||
if (volButton->objectName() == "red")
|
if (volButton->objectName() == "red")
|
||||||
{
|
{
|
||||||
Core::getInstance()->getAv()->enableGroupCallVol(group->getGroupId());
|
Core::getInstance()->getAv()->muteCallOutput(group, false);
|
||||||
volButton->setObjectName("green");
|
volButton->setObjectName("green");
|
||||||
volButton->setToolTip(tr("Mute call"));
|
volButton->setToolTip(tr("Mute call"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Core::getInstance()->getAv()->disableGroupCallVol(group->getGroupId());
|
Core::getInstance()->getAv()->muteCallOutput(group, true);
|
||||||
volButton->setObjectName("red");
|
volButton->setObjectName("red");
|
||||||
volButton->setToolTip(tr("Unmute call"));
|
volButton->setToolTip(tr("Unmute call"));
|
||||||
}
|
}
|
||||||
|
@ -396,9 +396,9 @@ void GroupChatForm::keyPressEvent(QKeyEvent* ev)
|
||||||
// Push to talk (CTRL+P)
|
// Push to talk (CTRL+P)
|
||||||
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall)
|
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall)
|
||||||
{
|
{
|
||||||
if (!Core::getInstance()->getAv()->isGroupCallMicEnabled(group->getGroupId()))
|
if (Core::getInstance()->getAv()->isGroupCallInputMuted(group))
|
||||||
{
|
{
|
||||||
Core::getInstance()->getAv()->enableGroupCallMic(group->getGroupId());
|
Core::getInstance()->getAv()->muteCallInput(group, false);
|
||||||
micButton->setObjectName("green");
|
micButton->setObjectName("green");
|
||||||
micButton->style()->polish(micButton);
|
micButton->style()->polish(micButton);
|
||||||
Style::repolish(micButton);
|
Style::repolish(micButton);
|
||||||
|
@ -414,9 +414,9 @@ void GroupChatForm::keyReleaseEvent(QKeyEvent* ev)
|
||||||
// Push to talk (CTRL+P)
|
// Push to talk (CTRL+P)
|
||||||
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall)
|
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall)
|
||||||
{
|
{
|
||||||
if (Core::getInstance()->getAv()->isGroupCallMicEnabled(group->getGroupId()))
|
if (!Core::getInstance()->getAv()->isGroupCallInputMuted(group))
|
||||||
{
|
{
|
||||||
Core::getInstance()->getAv()->disableGroupCallMic(group->getGroupId());
|
Core::getInstance()->getAv()->muteCallInput(group, true);
|
||||||
micButton->setObjectName("red");
|
micButton->setObjectName("red");
|
||||||
micButton->style()->polish(micButton);
|
micButton->style()->polish(micButton);
|
||||||
Style::repolish(micButton);
|
Style::repolish(micButton);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user