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();
|
||||
}
|
||||
|
||||
const CoreAV *Core::getAv() const
|
||||
{
|
||||
return av;
|
||||
}
|
||||
|
||||
CoreAV *Core::getAv()
|
||||
{
|
||||
return av;
|
||||
|
|
|
@ -47,6 +47,7 @@ class Core : public QObject
|
|||
public:
|
||||
explicit Core(QThread* coreThread, Profile& profile);
|
||||
static Core* getInstance();
|
||||
const CoreAV* getAv() const;
|
||||
CoreAV* getAv();
|
||||
~Core();
|
||||
|
||||
|
@ -88,6 +89,8 @@ public:
|
|||
|
||||
bool isReady();
|
||||
|
||||
void sendFile(uint32_t friendId, QString filename, QString filePath, long long filesize);
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
void reset();
|
||||
|
@ -116,7 +119,6 @@ public slots:
|
|||
int sendAction(uint32_t friendId, const QString& action);
|
||||
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 cancelFileSend(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);
|
||||
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
void disconnected();
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "core.h"
|
||||
#include "coreav.h"
|
||||
#include "src/audio/audio.h"
|
||||
#include "src/friend.h"
|
||||
#include "src/group.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/video/videoframe.h"
|
||||
#include "src/video/corevideosource.h"
|
||||
|
@ -157,19 +159,42 @@ void CoreAV::process()
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Check, that and calls are active now
|
||||
* @return True is any calls are currently active, False otherwise
|
||||
* @note A call about to start is not yet active
|
||||
* @brief Check, if any calls are currently active.
|
||||
* @return true if any calls are currently active, false otherwise
|
||||
* @note A call about to start is not yet active.
|
||||
*/
|
||||
bool CoreAV::anyActiveCalls()
|
||||
bool CoreAV::anyActiveCalls() const
|
||||
{
|
||||
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 calls[friendNum].videoEnabled;
|
||||
return f && calls.contains(f->getFriendID());
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
|
@ -269,7 +294,9 @@ bool CoreAV::cancelCall(uint32_t friendNum)
|
|||
qWarning() << QString("Failed to cancel call with %1").arg(friendNum);
|
||||
return false;
|
||||
}
|
||||
|
||||
calls.remove(friendNum);
|
||||
emit avEnd(friendNum);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -290,7 +317,6 @@ void CoreAV::timeoutCall(uint32_t friendNum)
|
|||
return;
|
||||
}
|
||||
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";
|
||||
}
|
||||
|
||||
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))
|
||||
calls[callId].muteMic = !calls[callId].muteMic;
|
||||
if (f && calls.contains(f->getFriendID()))
|
||||
{
|
||||
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))
|
||||
calls[callId].muteVol = !calls[callId].muteVol;
|
||||
if (f && calls.contains(f->getFriendID()))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool CoreAV::isGroupCallMicEnabled(int groupId) const
|
||||
{
|
||||
return !groupCalls[groupId].muteMic;
|
||||
}
|
||||
|
||||
bool CoreAV::isGroupCallVolEnabled(int groupId) const
|
||||
{
|
||||
return !groupCalls[groupId].muteVol;
|
||||
return g && groupCalls.contains(g->getGroupId())
|
||||
? groupCalls[g->getGroupId()].muteVol
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -539,6 +595,30 @@ bool CoreAV::isGroupAvEnabled(int groupId) const
|
|||
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.
|
||||
*/
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "src/core/toxcall.h"
|
||||
#include <tox/toxav.h>
|
||||
|
||||
class Friend;
|
||||
class Group;
|
||||
class QTimer;
|
||||
class QThread;
|
||||
class CoreVideoSource;
|
||||
|
@ -46,8 +48,10 @@ public:
|
|||
|
||||
const ToxAV* getToxAv() const;
|
||||
|
||||
bool anyActiveCalls();
|
||||
bool isCallVideoEnabled(uint32_t friendNum);
|
||||
bool anyActiveCalls() const;
|
||||
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);
|
||||
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);
|
||||
|
@ -58,16 +62,16 @@ public:
|
|||
|
||||
void joinGroupCall(int groupNum);
|
||||
void leaveGroupCall(int groupNum);
|
||||
void disableGroupCallMic(int groupNum);
|
||||
void disableGroupCallVol(int groupNum);
|
||||
void enableGroupCallMic(int groupNum);
|
||||
void enableGroupCallVol(int groupNum);
|
||||
bool isGroupCallMicEnabled(int groupNum) const;
|
||||
bool isGroupCallVolEnabled(int groupNum) const;
|
||||
void muteCallInput(const Group* g, bool mute);
|
||||
void muteCallOutput(const Group* g, bool mute);
|
||||
bool isGroupCallInputMuted(const Group* g) const;
|
||||
bool isGroupCallOutputMuted(const Group* g) const;
|
||||
bool isGroupAvEnabled(int groupNum) const;
|
||||
|
||||
void micMuteToggle(uint32_t friendNum);
|
||||
void volMuteToggle(uint32_t friendNum);
|
||||
bool isCallInputMuted(const Friend* f) const;
|
||||
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,
|
||||
const int16_t* data, unsigned samples,
|
||||
|
|
|
@ -442,7 +442,7 @@ void ChatForm::onAnswerCallTriggered()
|
|||
return;
|
||||
}
|
||||
|
||||
onAvStart(f->getFriendID(), coreav->isCallVideoEnabled(f->getFriendID()));
|
||||
onAvStart(f->getFriendID(), coreav->isCallActive(f));
|
||||
}
|
||||
|
||||
void ChatForm::onHangupCallTriggered()
|
||||
|
@ -593,7 +593,7 @@ void ChatForm::onMicMuteToggle()
|
|||
{
|
||||
if (audioInputFlag)
|
||||
{
|
||||
coreav->micMuteToggle(f->getFriendID());
|
||||
coreav->toggleMuteCallInput(f);
|
||||
if (micButton->objectName() == "red")
|
||||
{
|
||||
micButton->setObjectName("green");
|
||||
|
@ -613,7 +613,7 @@ void ChatForm::onVolMuteToggle()
|
|||
{
|
||||
if (audioOutputFlag)
|
||||
{
|
||||
coreav->volMuteToggle(f->getFriendID());
|
||||
coreav->toggleMuteCallOutput(f);
|
||||
if (volButton->objectName() == "red")
|
||||
{
|
||||
volButton->setObjectName("green");
|
||||
|
|
|
@ -303,13 +303,13 @@ void GroupChatForm::onMicMuteToggle()
|
|||
{
|
||||
if (micButton->objectName() == "red")
|
||||
{
|
||||
Core::getInstance()->getAv()->enableGroupCallMic(group->getGroupId());
|
||||
Core::getInstance()->getAv()->muteCallInput(group, false);
|
||||
micButton->setObjectName("green");
|
||||
micButton->setToolTip(tr("Mute microphone"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::getInstance()->getAv()->disableGroupCallMic(group->getGroupId());
|
||||
Core::getInstance()->getAv()->muteCallInput(group, true);
|
||||
micButton->setObjectName("red");
|
||||
micButton->setToolTip(tr("Unmute microphone"));
|
||||
}
|
||||
|
@ -324,13 +324,13 @@ void GroupChatForm::onVolMuteToggle()
|
|||
{
|
||||
if (volButton->objectName() == "red")
|
||||
{
|
||||
Core::getInstance()->getAv()->enableGroupCallVol(group->getGroupId());
|
||||
Core::getInstance()->getAv()->muteCallOutput(group, false);
|
||||
volButton->setObjectName("green");
|
||||
volButton->setToolTip(tr("Mute call"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::getInstance()->getAv()->disableGroupCallVol(group->getGroupId());
|
||||
Core::getInstance()->getAv()->muteCallOutput(group, true);
|
||||
volButton->setObjectName("red");
|
||||
volButton->setToolTip(tr("Unmute call"));
|
||||
}
|
||||
|
@ -396,9 +396,9 @@ void GroupChatForm::keyPressEvent(QKeyEvent* ev)
|
|||
// Push to talk (CTRL+P)
|
||||
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->style()->polish(micButton);
|
||||
Style::repolish(micButton);
|
||||
|
@ -414,9 +414,9 @@ void GroupChatForm::keyReleaseEvent(QKeyEvent* ev)
|
|||
// Push to talk (CTRL+P)
|
||||
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->style()->polish(micButton);
|
||||
Style::repolish(micButton);
|
||||
|
|
Loading…
Reference in New Issue
Block a user